Working stl vector.
authorRobert Bradshaw <robertwb@math.washington.edu>
Sun, 16 Aug 2009 01:36:50 +0000 (18:36 -0700)
committerRobert Bradshaw <robertwb@math.washington.edu>
Sun, 16 Aug 2009 01:36:50 +0000 (18:36 -0700)
Cython/Compiler/Nodes.py
Cython/Compiler/Parsing.py
Cython/Compiler/PyrexTypes.py
Cython/Compiler/Symtab.py

index 4377db7e83f4c606667514c96f83fb61212bd178..ff316178d2de3d8b1208ea495c4303894a4eef7f 100644 (file)
@@ -944,7 +944,7 @@ class CppClassNode(CStructOrUnionDefNode):
     def analyse_declarations(self, env):
         scope = None
         if len(self.attributes) != 0:
-            scope = CppClassScope(self.name)
+            scope = CppClassScope(self.name, env)
         else:
             self.attributes = None
         base_class_types = []
@@ -968,7 +968,7 @@ class CppClassNode(CStructOrUnionDefNode):
             if self.in_pxd and not env.in_cinclude:
                 self.entry.defined_in_pxd = 1
             for attr in self.attributes:
-                attr.analyse_declarations(env, scope) 
+                attr.analyse_declarations(scope)
 
 class CEnumDefNode(StatNode):
     #  name           string or None
index 173133a309669d3f3f28aa3da9915005cb16727b..6e7044f584017b37fbc0918b30e1b594a1d1c2c5 100644 (file)
@@ -2602,8 +2602,6 @@ def p_cpp_class_definition(s, pos,  ctx):
             s.next()
         s.expect(']')
     base_classes = []
-    objstruct_name = None
-    typeobj_name = None
     if s.sy == '(':
         base_class = True
         while (base_class):
@@ -2626,7 +2624,7 @@ def p_cpp_class_definition(s, pos,  ctx):
         s.expect('NEWLINE')
         s.expect_indent()
         attributes = []
-        body_ctx = Ctx()
+        body_ctx = Ctx(visibility = ctx.visibility)
         body_ctx.templates = templates
         while s.sy != 'DEDENT':
             if s.sy != 'pass':
index 017e7010772fae1cbd8b7e20392b83172440955c..01fba6a5890f52fc2d51073c45cecbff649c460e 100755 (executable)
@@ -1242,7 +1242,23 @@ class CFuncType(CType):
     def signature_cast_string(self):
         s = self.declaration_code("(*)", with_calling_convention=False)
         return '(%s)' % s
-
+    
+    def specialize(self, values):
+        if self.templates is None:
+            new_templates = None
+        else:
+            new_templates = [v.specialize(values) for v in self.templates]
+        return CFuncType(self.return_type.specialize(values),
+                             [arg.specialize(values) for arg in self.args],
+                             has_varargs = 0,
+                             exception_value = self.exception_value,
+                             exception_check = self.exception_check,
+                             calling_convention = self.calling_convention,
+                             nogil = self.nogil,
+                             with_gil = self.with_gil,
+                             is_overridable = self.is_overridable,
+                             optional_arg_count = self.optional_arg_count,
+                             templates = new_templates)
 
 class CFuncTypeArg(object):
     #  name       string
@@ -1266,6 +1282,9 @@ class CFuncTypeArg(object):
     
     def declaration_code(self, for_display = 0):
         return self.type.declaration_code(self.cname, for_display)
+    
+    def specialize(self, values):
+        return CFuncTypeArg(self.name, self.type.specialize(values), self.pos, self.cname)
 
 
 class CStructOrUnionType(CType):
@@ -1736,9 +1755,12 @@ modifiers_and_name_to_type = {
 }
 
 def is_promotion(type, other_type):
-    return (type.is_int and type.is_int and type.signed == other_type.signed) \
-                    or (type.is_float and other_type.is_float) \
-                    or (type.is_enum and other_type.is_int)
+    if type.is_numeric and other_type.is_numeric:
+        return (type.is_int and type.is_int and type.signed == other_type.signed) \
+                        or (type.is_float and other_type.is_float) \
+                        or (type.is_enum and other_type.is_int)
+    else:
+        return False
 
 def best_match(args, functions, pos):
     actual_nargs = len(args)
index 9fc15ef37cf5d6d22102d46b91dda0b15c5d8307..543879344fb7249df6fd7920b7e6f0d0290269bf 100644 (file)
@@ -1137,7 +1137,11 @@ class ModuleScope(Scope):
                     entry.type.scope = scope
                     self.type_entries.append(entry)
         if not scope and not entry.type.scope:
-            entry.type.scope = CppClassScope(name)
+            entry.type.scope = CppClassScope(name, self)
+        if templates is not None:
+            for T in templates:
+                template_entry = entry.type.scope.declare(T.name, T.name, T, None, 'extern')
+                template_entry.is_type = 1
         
         def declare_inherited_attributes(entry, base_classes):
             for base_class in base_classes:
@@ -1604,8 +1608,9 @@ class CppClassScope(Scope):
     #  Namespace of a C++ class.
     inherited_var_entries = []
     
-    def __init__(self, name="?"):
-        Scope.__init__(self, name, None, None)
+    def __init__(self, name, outer_scope):
+        Scope.__init__(self, name, outer_scope, None)
+        self.directives = outer_scope.directives
 
     def declare_var(self, name, type, pos, 
             cname = None, visibility = 'extern', is_cdef = 0, allow_pyobject = 0):
@@ -1622,11 +1627,6 @@ class CppClassScope(Scope):
                 "C++ class member cannot be a Python object")
         return entry
 
-    def declare_cfunction(self, name, type, pos, 
-                          cname = None, visibility = 'extern', defining = 0,
-                          api = 0, in_pxd = 0, modifiers = ()):
-        entry = self.declare_var(name, type, pos, cname, visibility)
-
     def declare_inherited_cpp_attributes(self, base_scope):
         # Declare entries for all the C++ attributes of an
         # inherited type, with cnames modified appropriately
@@ -1644,7 +1644,7 @@ class CppClassScope(Scope):
             entry.is_inherited = 1
     
     def specialize(self, values):
-        scope = CppClassScope()
+        scope = CppClassScope(self.name, self.outer_scope)
         for entry in self.entries.values():
             scope.declare_var(entry.name,
                                 entry.type.specialize(values),