C++ parsing simplification, cleanup
authorRobert Bradshaw <robertwb@math.washington.edu>
Tue, 15 Dec 2009 10:13:38 +0000 (02:13 -0800)
committerRobert Bradshaw <robertwb@math.washington.edu>
Tue, 15 Dec 2009 10:13:38 +0000 (02:13 -0800)
Cython/Compiler/CmdLine.py
Cython/Compiler/ExprNodes.py
Cython/Compiler/Parsing.py
Cython/Compiler/Symtab.py
Cython/Compiler/Visitor.py

index 8104e9318727f628d155428520bb337ec3143e72..d7b2f23a04936216a614241369596fdf904c6100 100644 (file)
@@ -89,7 +89,7 @@ def parse_command_line(args):
                 options.c_only = 0
                 options.obj_only = 0
             elif option in ("-+", "--cplus"):
-                Options.cplus = options.cplus = 1
+                options.cplus = 1
             elif option == "--embed":
                 Options.embed = True
             elif option.startswith("-I"):
index 96c251c43e76c10aa20eac70cc8a141438d2539e..9ab2b259d11c0e72e9b6ed4b1e868badea17f7f6 100755 (executable)
@@ -4280,7 +4280,7 @@ class NumBinopNode(BinopNode):
         if type2.is_ptr:
             type2 = type2.base_type
         entry = env.lookup(type1.name)
-        function = entry.type.scope.lookup(self.operators[self.operator])
+        function = entry.type.scope.lookup("operator%s" % self.operator)
         if not function:
             error(self.pos, "'%s' operator not defined for '%s %s %s'"
                 % (self.operator, type1, self.operator, type2))
index d5ee2f271b67b43f152a9ba28db8ab5da8f0a283..0e9ab6b221180b53d1ea22ba025b3e0317ce3d67 100644 (file)
@@ -2593,33 +2593,24 @@ def p_cpp_class_definition(s, pos,  ctx):
         cname = ctx.namespace + "::" + class_name
     if s.sy == '.':
         error(pos, "Qualified class name not allowed C++ class")
-    templates = None
     if s.sy == '[':
         s.next()
-        templates = []
-        templates.append(s.systring)
-        s.next()
+        templates = [p_ident(s)]
         while s.sy == ',':
             s.next()
-            templates.append(s.systring)
-            s.next()
+            templates.append(p_ident(s))
         s.expect(']')
-    base_classes = []
+    else:
+        templates = None
     if s.sy == '(':
-        base_class = True
-        while (base_class):
+        s.next()
+        base_classes = [p_dotted_name(s, False)[2]]
+        while s.sy == ',':
             s.next()
-            base_class_path = [p_ident(s)]
-            base_class = False
-            while s.sy == '.':
-                s.next()
-                base_class_path.append(p_ident(s))
-            base_classes.append(base_class_path)
-            if s.sy == ',':
-                base_class = True
-                base_class_path = []
+            base_classes.append(p_dotted_name(s, False)[2])
         s.expect(')')
-        base_classes = [".".join(path) for path in base_classes]
+    else:
+        base_classes = []
     if s.sy == '[':
         error(s.position(), "Name options not allowed for C++ class")
     if s.sy == ':':
index db3eca3f134a8dfa8d4c4b3aea331e0ef3a4ff54..e26f35c88cb3a2229f55caf1dca974befd51d8f3 100644 (file)
@@ -311,8 +311,7 @@ class Scope(object):
             if visibility == 'extern':
                 warning(pos, "'%s' redeclared " % name, 0)
             elif visibility != 'ignore':
-                pass
-                #error(pos, "'%s' redeclared " % name)
+                error(pos, "'%s' redeclared " % name)
         entry = Entry(name, cname, type, pos = pos)
         entry.in_cinclude = self.in_cinclude
         if name:
@@ -464,14 +463,16 @@ class Scope(object):
             if visibility != 'private' and visibility != entry.visibility:
                 warning(pos, "Function '%s' previously declared as '%s'" % (name, entry.visibility), 1)
             if not entry.type.same_as(type):
-                #if visibility == 'extern' and entry.visibility == 'extern':
-                    #warning(pos, "Function signature does not match previous declaration", 1)
-                    #entry.type = type
-                temp = self.add_cfunction(name, type, pos, cname, visibility, modifiers)
-                entry.overloaded_alternatives.append(temp)
-                entry = temp
-                #else:
-                    #error(pos, "Function signature does not match previous declaration")
+                if visibility == 'extern' and entry.visibility == 'extern':
+                    if self.is_cpp():
+                        temp = self.add_cfunction(name, type, pos, cname, visibility, modifiers)
+                        entry.overloaded_alternatives.append(temp)
+                        entry = temp
+                    else:
+                        warning(pos, "Function signature does not match previous declaration", 1)
+                        entry.type = type
+                else:
+                    error(pos, "Function signature does not match previous declaration")
         else:
             entry = self.add_cfunction(name, type, pos, cname, visibility, modifiers)
             entry.func_cname = cname
@@ -485,12 +486,6 @@ class Scope(object):
             entry.is_implemented = True
         if modifiers:
             entry.func_modifiers = modifiers
-        #try:
-        #    print entry.name, entry.type, entry.overloaded_alternatives
-        #except:
-        #    pass
-        #if len(entry.overloaded_alternatives) > 0:
-        #    print entry.name, entry.type, entry.overloaded_alternatives[0].type
         return entry
     
     def add_cfunction(self, name, type, pos, cname, visibility, modifiers):
index c7739f8d6554efb7ecab1007366657e430f8c739..c6add7cbdc0db9e9f21ee2d9689934d5df51b8f1 100644 (file)
@@ -94,7 +94,8 @@ class TreeVisitor(BasicVisitor):
 
     def dump_node(self, node, indent=0):
         ignored = list(node.child_attrs) + [u'child_attrs', u'pos',
-                                            u'gil_message', u'subexprs']
+                                            u'gil_message', u'cpp_message', 
+                                            u'subexprs']
         values = []
         pos = node.pos
         if pos: