[Synopsis-changes] Synopsis/Synopsis/Synopsis/Parser/Cxx Parser.py,NONE,1.1 __init__.py,1.8,1.9

Stefan Seefeld stefan at synopsis.fresco.org
Wed Nov 5 17:36:59 UTC 2003


Update of /cvs/synopsis/Synopsis/Synopsis/Parser/Cxx
In directory frida:/tmp/cvs-serv32648/Synopsis/Parser/Cxx

Modified Files:
	__init__.py 
Added Files:
	Parser.py 
Log Message:
C++ parser fe refactoring to suite the Processor interface

--- NEW FILE: Parser.py ---
# $Id: Parser.py,v 1.1 2003/11/05 17:36:55 stefan Exp $
#
# Copyright (C) 2003 Stefan Seefeld
# All rights reserved.
# Licensed to the public under the terms of the GNU LGPL (>= 2),
# see the file COPYING for details.
#

"""Parser for C++ using OpenC++ for low-level parsing.
This parser is written entirely in C++, and compiled into shared libraries for
use by python.
@see C++/Synopsis
@see C++/SWalker
"""

from Synopsis.Core.Processor import Processor
from Synopsis.Core import AST
import occ

class Parser(Processor):

   cppflags = []
   main_file_only = True
   preprocessor = 'gcc'
   base_path = ''
   extract_tails = True
   syntax_prefix = None
   xref_prefix = None
  
   def process(self, ast, **kwds):
        
      self.__dict__.update(kwds)

      for file in self.input:
         ast = occ.parse(ast, file, [],
                         self.verbose,
                         self.main_file_only,
                         self.base_path,
                         self.preprocessor,
                         self.cppflags,
                         self.extract_tails,
                         self.syntax_prefix,
                         self.xref_prefix)
      output = kwds.get('output')
      if output:
         AST.save(output, ast)
      return ast

Index: __init__.py
===================================================================
RCS file: /cvs/synopsis/Synopsis/Synopsis/Parser/Cxx/__init__.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -p -d -r1.8 -r1.9
--- __init__.py	5 Jul 2003 21:36:19 -0000	1.8
+++ __init__.py	5 Nov 2003 17:36:55 -0000	1.9
@@ -1,17 +1,61 @@
-"""Parser for C++ using OpenC++ for low-level parsing.
-This parser is written entirely in C++, and compiled into shared libraries for
-use by python.
- at see C++/Synopsis
- at see C++/SWalker
-"""
+# $Id$
 #
-# configure for the parser you want here...
+# Copyright (C) 2003 Stefan Seefeld
+# All rights reserved.
+# Licensed to the public under the terms of the GNU LGPL (>= 2),
+# see the file COPYING for details.
 #
+
+from Parser import *
+
 try:
-    from occ import parse, usage
+    import occ
 except:
     import sys
     print sys.exc_type, sys.exc_value
 import emul
+
+def usage():
+    """Prints a usage message"""
+    print """
+  -I<path>                             Specify include path to be used by the preprocessor
+  -D<macro>                            Specify macro to be used by the preprocessor
+  -m                                   Only keep declarations from the main file
+  -b basepath                          Strip basepath from start of filenames"""
+
+def parse(file, extra_files, args, config):
+    # ignore the config, as it is phased out and will be replaced
+    # by the processor interface
+
+    import getopt
+    import occ
+    from Synopsis.Core import AST
+
+    cppflags = []
+    main_file = False
+    basepath = None
+    verbose = False
+    extract_tails = False
+    xref_prefix = None
+    syntax_prefix = None
+    preprocessor = None
+    opts,remainder = getopt.getopt(args, "I:D:mb:vtx:s:g")
+    for o,a in opts:
+        if o == '-I': cppflags.extend(['-I', a])
+        elif o == '-D': cppflags.extend(['-D', a])
+        elif o == '-m': main_file = True
+        elif o == '-b': basepath = a
+        elif o == '-v': verbose = True
+        elif o == '-t': extract_tails = True
+        elif o == '-x': xref_prefix = a
+        elif o == '-s': syntax_prefix = a
+        elif o == '-g': preprocessor = 'gcc'
+        
+    ast = AST.AST()
+    
+    ast = occ.parse(ast, file, [], verbose, main_file, basepath, preprocessor,
+                    cppflags, extract_tails, syntax_prefix, xref_prefix)
+
+    return ast
 
 # THIS-IS-A-PARSER





More information about the Synopsis-changes mailing list