Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cython
Commits
03cdb738
Commit
03cdb738
authored
Jun 06, 2008
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Go back to using nice cnames for identifiers
parent
5449f98b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
9 deletions
+20
-9
Cython/Compiler/Naming.py
Cython/Compiler/Naming.py
+2
-2
Cython/Compiler/Symtab.py
Cython/Compiler/Symtab.py
+18
-7
No files found.
Cython/Compiler/Naming.py
View file @
03cdb738
...
...
@@ -16,12 +16,12 @@ func_prefix = pyrex_prefix + "f_"
pyfunc_prefix
=
pyrex_prefix
+
"pf_"
gstab_prefix
=
pyrex_prefix
+
"getsets_"
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"
pymethdef_prefix
=
pyrex_prefix
+
"mdef_"
methtab_prefix
=
pyrex_prefix
+
"methods_"
memtab_prefix
=
pyrex_prefix
+
"members_"
interned_prefix
=
pyrex_prefix
+
"n_"
interned_num_prefix
=
pyrex_prefix
+
"int_"
objstruct_prefix
=
pyrex_prefix
+
"obj_"
typeptr_prefix
=
pyrex_prefix
+
"ptype_"
...
...
Cython/Compiler/Symtab.py
View file @
03cdb738
...
...
@@ -17,6 +17,7 @@ import ControlFlow
import
__builtin__
possible_identifier
=
re
.
compile
(
ur"(?![0-9])\
w+$
", re.U).match
nice_identifier = re.compile('[a-zA-Z0-0_]').match
class Entry:
# A symbol table entry in a Scope or ModuleNamespace.
...
...
@@ -438,8 +439,11 @@ class Scope:
entry = self.declare_var(name, py_object_type, None)
return entry
def add_string_const(self, value):
def add_string_const(self, value
, identifier = False
):
# Add an entry for a string constant.
if identifier:
cname = self.new_string_const_cname(value)
else:
cname = self.new_const_cname()
if value.is_unicode:
c_type = PyrexTypes.c_utf8_char_array_type
...
...
@@ -462,7 +466,7 @@ class Scope:
string_map = genv.string_to_entry
entry = string_map.get(value)
if not entry:
entry = self.add_string_const(value)
entry = self.add_string_const(value
, identifier
)
entry.is_identifier = identifier
string_map[value] = entry
return entry
...
...
@@ -475,7 +479,7 @@ class Scope:
if entry.pystring_cname:
return
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.global_scope().all_pystring_entries.append(entry)
if identifier or (identifier is None and possible_identifier(value)):
...
...
@@ -514,6 +518,13 @@ class Scope:
genv.obj_to_entry[obj] = 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):
# Create a new globally-unique name for a constant.
return self.global_scope().new_const_cname()
...
...
@@ -866,7 +877,7 @@ class ModuleScope(Scope):
prefix=''
n = self.const_counter
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):
# Add string to list of utility code to be included,
...
...
@@ -1123,8 +1134,8 @@ class ClassScope(Scope):
self.class_name = name
self.doc = None
def add_string_const(self, value):
return self.outer_scope.add_string_const(value)
def add_string_const(self, value
, identifier = False
):
return self.outer_scope.add_string_const(value
, identifier
)
def lookup(self, name):
if name == "classmethod":
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment