Commit 03cdb738 authored by Robert Bradshaw's avatar Robert Bradshaw

Go back to using nice cnames for identifiers

parent 5449f98b
...@@ -16,12 +16,12 @@ func_prefix = pyrex_prefix + "f_" ...@@ -16,12 +16,12 @@ func_prefix = pyrex_prefix + "f_"
pyfunc_prefix = pyrex_prefix + "pf_" pyfunc_prefix = pyrex_prefix + "pf_"
gstab_prefix = pyrex_prefix + "getsets_" gstab_prefix = pyrex_prefix + "getsets_"
prop_get_prefix = pyrex_prefix + "getprop_" prop_get_prefix = pyrex_prefix + "getprop_"
const_prefix = pyrex_prefix + "k" const_prefix = pyrex_prefix + "k_"
py_const_prefix = pyrex_prefix + "kp_"
label_prefix = pyrex_prefix + "L" label_prefix = pyrex_prefix + "L"
pymethdef_prefix = pyrex_prefix + "mdef_" pymethdef_prefix = pyrex_prefix + "mdef_"
methtab_prefix = pyrex_prefix + "methods_" methtab_prefix = pyrex_prefix + "methods_"
memtab_prefix = pyrex_prefix + "members_" memtab_prefix = pyrex_prefix + "members_"
interned_prefix = pyrex_prefix + "n_"
interned_num_prefix = pyrex_prefix + "int_" interned_num_prefix = pyrex_prefix + "int_"
objstruct_prefix = pyrex_prefix + "obj_" objstruct_prefix = pyrex_prefix + "obj_"
typeptr_prefix = pyrex_prefix + "ptype_" typeptr_prefix = pyrex_prefix + "ptype_"
......
...@@ -17,6 +17,7 @@ import ControlFlow ...@@ -17,6 +17,7 @@ import ControlFlow
import __builtin__ import __builtin__
possible_identifier = re.compile(ur"(?![0-9])\w+$", re.U).match possible_identifier = re.compile(ur"(?![0-9])\w+$", re.U).match
nice_identifier = re.compile('[a-zA-Z0-0_]').match
class Entry: class Entry:
# A symbol table entry in a Scope or ModuleNamespace. # A symbol table entry in a Scope or ModuleNamespace.
...@@ -438,8 +439,11 @@ class Scope: ...@@ -438,8 +439,11 @@ class Scope:
entry = self.declare_var(name, py_object_type, None) entry = self.declare_var(name, py_object_type, None)
return entry return entry
def add_string_const(self, value): def add_string_const(self, value, identifier = False):
# Add an entry for a string constant. # Add an entry for a string constant.
if identifier:
cname = self.new_string_const_cname(value)
else:
cname = self.new_const_cname() cname = self.new_const_cname()
if value.is_unicode: if value.is_unicode:
c_type = PyrexTypes.c_utf8_char_array_type c_type = PyrexTypes.c_utf8_char_array_type
...@@ -462,7 +466,7 @@ class Scope: ...@@ -462,7 +466,7 @@ class Scope:
string_map = genv.string_to_entry string_map = genv.string_to_entry
entry = string_map.get(value) entry = string_map.get(value)
if not entry: if not entry:
entry = self.add_string_const(value) entry = self.add_string_const(value, identifier)
entry.is_identifier = identifier entry.is_identifier = identifier
string_map[value] = entry string_map[value] = entry
return entry return entry
...@@ -475,7 +479,7 @@ class Scope: ...@@ -475,7 +479,7 @@ class Scope:
if entry.pystring_cname: if entry.pystring_cname:
return return
value = entry.init value = entry.init
entry.pystring_cname = entry.cname + "p" entry.pystring_cname = Naming.py_const_prefix + entry.cname[len(Naming.const_prefix):]
self.pystring_entries.append(entry) self.pystring_entries.append(entry)
self.global_scope().all_pystring_entries.append(entry) self.global_scope().all_pystring_entries.append(entry)
if identifier or (identifier is None and possible_identifier(value)): if identifier or (identifier is None and possible_identifier(value)):
...@@ -514,6 +518,13 @@ class Scope: ...@@ -514,6 +518,13 @@ class Scope:
genv.obj_to_entry[obj] = entry genv.obj_to_entry[obj] = entry
return entry return entry
def new_string_const_cname(self, value):
# Create a new globally-unique nice name for a string constant.
if len(value) < 20 and nice_identifier(value):
return "%s%s" % (Naming.const_prefix, value)
else:
return self.global_scope().new_const_cname()
def new_const_cname(self): def new_const_cname(self):
# Create a new globally-unique name for a constant. # Create a new globally-unique name for a constant.
return self.global_scope().new_const_cname() return self.global_scope().new_const_cname()
...@@ -866,7 +877,7 @@ class ModuleScope(Scope): ...@@ -866,7 +877,7 @@ class ModuleScope(Scope):
prefix='' prefix=''
n = self.const_counter n = self.const_counter
self.const_counter = n + 1 self.const_counter = n + 1
return "%s%s_%d" % (Naming.const_prefix, prefix, n) return "%s%s%d" % (Naming.const_prefix, prefix, n)
def use_utility_code(self, new_code): def use_utility_code(self, new_code):
# Add string to list of utility code to be included, # Add string to list of utility code to be included,
...@@ -1123,8 +1134,8 @@ class ClassScope(Scope): ...@@ -1123,8 +1134,8 @@ class ClassScope(Scope):
self.class_name = name self.class_name = name
self.doc = None self.doc = None
def add_string_const(self, value): def add_string_const(self, value, identifier = False):
return self.outer_scope.add_string_const(value) return self.outer_scope.add_string_const(value, identifier)
def lookup(self, name): def lookup(self, name):
if name == "classmethod": if name == "classmethod":
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment