cython-devel

changeset 903:6a8548429322

Dissallow non-extern redeclarations.
author Robert Bradshaw <robertwb@math.washington.edu>
date Sat Aug 02 17:40:02 2008 -0700 (5 years ago)
parents 19282c553659
children 8b22ff3db9f7
files Cython/Compiler/Symtab.py
line diff
1.1 --- a/Cython/Compiler/Symtab.py Sat Aug 02 17:16:52 2008 -0700 1.2 +++ b/Cython/Compiler/Symtab.py Sat Aug 02 17:40:02 2008 -0700 1.3 @@ -261,7 +261,7 @@ 1.4 # Return the module-level scope containing this scope. 1.5 return self.outer_scope.builtin_scope() 1.6 1.7 - def declare(self, name, cname, type, pos): 1.8 + def declare(self, name, cname, type, pos, visibility): 1.9 # Create new entry, and add to dictionary if 1.10 # name is not None. Reports a warning if already 1.11 # declared. 1.12 @@ -270,13 +270,17 @@ 1.13 warning(pos, "'%s' is a reserved name in C." % cname, -1) 1.14 dict = self.entries 1.15 if name and dict.has_key(name): 1.16 - warning(pos, "'%s' redeclared " % name, 0) 1.17 + if visibility == 'extern': 1.18 + warning(pos, "'%s' redeclared " % name, 0) 1.19 + else: 1.20 + error(pos, "'%s' redeclared " % name) 1.21 entry = Entry(name, cname, type, pos = pos) 1.22 entry.in_cinclude = self.in_cinclude 1.23 if name: 1.24 entry.qualified_name = self.qualify_name(name) 1.25 dict[name] = entry 1.26 entry.scope = self 1.27 + entry.visibility = visibility 1.28 return entry 1.29 1.30 def qualify_name(self, name): 1.31 @@ -289,7 +293,7 @@ 1.32 cname = name 1.33 else: 1.34 cname = self.mangle(Naming.enum_prefix, name) 1.35 - entry = self.declare(name, cname, type, pos) 1.36 + entry = self.declare(name, cname, type, pos, 'private') 1.37 entry.is_const = 1 1.38 entry.value = value 1.39 return entry 1.40 @@ -299,8 +303,7 @@ 1.41 # Add an entry for a type definition. 1.42 if not cname: 1.43 cname = name 1.44 - entry = self.declare(name, cname, type, pos) 1.45 - entry.visibility = visibility 1.46 + entry = self.declare(name, cname, type, pos, visibility) 1.47 entry.is_type = 1 1.48 if defining: 1.49 self.type_entries.append(entry) 1.50 @@ -384,9 +387,8 @@ 1.51 cname = name 1.52 else: 1.53 cname = self.mangle(Naming.var_prefix, name) 1.54 - entry = self.declare(name, cname, type, pos) 1.55 + entry = self.declare(name, cname, type, pos, visibility) 1.56 entry.is_variable = 1 1.57 - entry.visibility = visibility 1.58 self.control_flow.set_state((), (name, 'initalized'), False) 1.59 return entry 1.60 1.61 @@ -415,8 +417,11 @@ 1.62 if visibility != 'private' and visibility != entry.visibility: 1.63 warning(pos, "Function '%s' previously declared as '%s'" % (name, entry.visibility), 1) 1.64 if not entry.type.same_as(type): 1.65 - warning(pos, "Function signature does not match previous declaration", 1) 1.66 - entry.type = type 1.67 + if visibility == 'extern' and entry.visibility == 'extern': 1.68 + warning(pos, "Function signature does not match previous declaration", 1) 1.69 + entry.type = type 1.70 + else: 1.71 + error(pos, "Function signature does not match previous declaration") 1.72 else: 1.73 if not cname: 1.74 if api or visibility != 'private': 1.75 @@ -435,9 +440,8 @@ 1.76 1.77 def add_cfunction(self, name, type, pos, cname, visibility): 1.78 # Add a C function entry without giving it a func_cname. 1.79 - entry = self.declare(name, cname, type, pos) 1.80 + entry = self.declare(name, cname, type, pos, visibility) 1.81 entry.is_cfunction = 1 1.82 - entry.visibility = visibility 1.83 self.cfunc_entries.append(entry) 1.84 return entry 1.85 1.86 @@ -648,7 +652,7 @@ 1.87 Scope.__init__(self, Options.pre_import, None, None) 1.88 1.89 def declare_builtin(self, name, pos): 1.90 - entry = self.declare(name, name, py_object_type, pos) 1.91 + entry = self.declare(name, name, py_object_type, pos, 'private') 1.92 entry.is_variable = True 1.93 entry.is_pyglobal = True 1.94 return entry 1.95 @@ -819,7 +823,7 @@ 1.96 for entry in self.cached_builtins: 1.97 if entry.name == name: 1.98 return entry 1.99 - entry = self.declare(None, None, py_object_type, pos) 1.100 + entry = self.declare(None, None, py_object_type, pos, 'private') 1.101 if Options.cache_builtins: 1.102 entry.is_builtin = 1 1.103 entry.is_const = 1 1.104 @@ -1135,7 +1139,7 @@ 1.105 def declare_arg(self, name, type, pos): 1.106 # Add an entry for an argument of a function. 1.107 cname = self.mangle(Naming.var_prefix, name) 1.108 - entry = self.declare(name, cname, type, pos) 1.109 + entry = self.declare(name, cname, type, pos, 'private') 1.110 entry.is_variable = 1 1.111 if type.is_pyobject: 1.112 entry.init = "0" 1.113 @@ -1208,7 +1212,7 @@ 1.114 cname = name 1.115 if type.is_cfunction: 1.116 type = PyrexTypes.CPtrType(type) 1.117 - entry = self.declare(name, cname, type, pos) 1.118 + entry = self.declare(name, cname, type, pos, visibility) 1.119 entry.is_variable = 1 1.120 self.var_entries.append(entry) 1.121 if type.is_pyobject and not allow_pyobject: 1.122 @@ -1340,8 +1344,7 @@ 1.123 % name) 1.124 if not cname: 1.125 cname = name 1.126 - entry = self.declare(name, cname, type, pos) 1.127 - entry.visibility = visibility 1.128 + entry = self.declare(name, cname, type, pos, visibility) 1.129 entry.is_variable = 1 1.130 self.var_entries.append(entry) 1.131 if type.is_pyobject: 1.132 @@ -1382,7 +1385,7 @@ 1.133 warning(pos, "__new__ method of extension type will change semantics " 1.134 "in a future version of Pyrex and Cython. Use __cinit__ instead.") 1.135 name = Utils.EncodedString("__cinit__") 1.136 - entry = self.declare_var(name, py_object_type, pos) 1.137 + entry = self.declare_var(name, py_object_type, pos, visibility='extern') 1.138 special_sig = get_special_method_signature(name) 1.139 if special_sig: 1.140 # Special methods get put in the method table with a particular 1.141 @@ -1459,7 +1462,7 @@ 1.142 def declare_property(self, name, doc, pos): 1.143 entry = self.lookup_here(name) 1.144 if entry is None: 1.145 - entry = self.declare(name, name, py_object_type, pos) 1.146 + entry = self.declare(name, name, py_object_type, pos, 'private') 1.147 entry.is_property = 1 1.148 entry.doc = doc 1.149 entry.scope = PropertyScope(name, 1.150 @@ -1477,7 +1480,7 @@ 1.151 for base_entry in \ 1.152 base_scope.inherited_var_entries + base_scope.var_entries: 1.153 entry = self.declare(base_entry.name, adapt(base_entry.cname), 1.154 - base_entry.type, None) 1.155 + base_entry.type, None, 'private') 1.156 entry.is_variable = 1 1.157 self.inherited_var_entries.append(entry) 1.158 for base_entry in base_scope.cfunc_entries: 1.159 @@ -1502,7 +1505,7 @@ 1.160 # Add an entry for a method. 1.161 signature = get_property_accessor_signature(name) 1.162 if signature: 1.163 - entry = self.declare(name, name, py_object_type, pos) 1.164 + entry = self.declare(name, name, py_object_type, pos, 'private') 1.165 entry.is_special = 1 1.166 entry.signature = signature 1.167 return entry