Commit 63eabf72 authored by Stefan Behnel's avatar Stefan Behnel

make imported names behave like identifiers, too

parent c5da19ce
...@@ -284,7 +284,7 @@ def p_call(s, function): ...@@ -284,7 +284,7 @@ def p_call(s, function):
s.error("Expected an identifier before '='", s.error("Expected an identifier before '='",
pos = arg.pos) pos = arg.pos)
encoded_name = Utils.EncodedString(arg.name) encoded_name = Utils.EncodedString(arg.name)
keyword = ExprNodes.KeywordNameNode(arg.pos, keyword = ExprNodes.IdentifierStringNode(arg.pos,
value = encoded_name) value = encoded_name)
arg = p_simple_expr(s) arg = p_simple_expr(s)
keyword_args.append((keyword, arg)) keyword_args.append((keyword, arg))
...@@ -926,8 +926,8 @@ def p_import_statement(s): ...@@ -926,8 +926,8 @@ def p_import_statement(s):
lhs = ExprNodes.NameNode(pos, lhs = ExprNodes.NameNode(pos,
name = as_name or target_name), name = as_name or target_name),
rhs = ExprNodes.ImportNode(pos, rhs = ExprNodes.ImportNode(pos,
module_name = ExprNodes.StringNode(pos, module_name = ExprNodes.IdentifierStringNode(
value = dotted_name), pos, value = dotted_name),
name_list = name_list)) name_list = name_list))
stats.append(stat) stats.append(stat)
return Nodes.StatListNode(pos, stats = stats) return Nodes.StatListNode(pos, stats = stats)
...@@ -974,9 +974,8 @@ def p_from_import_statement(s, first_statement = 0): ...@@ -974,9 +974,8 @@ def p_from_import_statement(s, first_statement = 0):
items = [] items = []
for (name_pos, name, as_name) in imported_names: for (name_pos, name, as_name) in imported_names:
encoded_name = Utils.EncodedString(name) encoded_name = Utils.EncodedString(name)
encoded_name.encoding = s.source_encoding
imported_name_strings.append( imported_name_strings.append(
ExprNodes.StringNode(name_pos, value = encoded_name)) ExprNodes.IdentifierStringNode(name_pos, value = encoded_name))
items.append( items.append(
(name, (name,
ExprNodes.NameNode(name_pos, ExprNodes.NameNode(name_pos,
...@@ -984,11 +983,9 @@ def p_from_import_statement(s, first_statement = 0): ...@@ -984,11 +983,9 @@ def p_from_import_statement(s, first_statement = 0):
import_list = ExprNodes.ListNode( import_list = ExprNodes.ListNode(
imported_names[0][0], args = imported_name_strings) imported_names[0][0], args = imported_name_strings)
dotted_name = Utils.EncodedString(dotted_name) dotted_name = Utils.EncodedString(dotted_name)
dotted_name.encoding = s.source_encoding
return Nodes.FromImportStatNode(pos, return Nodes.FromImportStatNode(pos,
module = ExprNodes.ImportNode(dotted_name_pos, module = ExprNodes.ImportNode(dotted_name_pos,
module_name = ExprNodes.StringNode(dotted_name_pos, module_name = ExprNodes.IdentifierStringNode(pos, value = dotted_name),
value = dotted_name),
name_list = import_list), name_list = import_list),
items = items) items = items)
......
...@@ -464,7 +464,7 @@ class Scope: ...@@ -464,7 +464,7 @@ class Scope:
string_map[value] = entry string_map[value] = entry
return entry return entry
def add_py_string(self, entry): def add_py_string(self, entry, identifier = None):
# If not already done, allocate a C name for a Python version of # If not already done, allocate a C name for a Python version of
# a string literal, and add it to the list of Python strings to # a string literal, and add it to the list of Python strings to
# be created at module init time. If the string resembles a # be created at module init time. If the string resembles a
...@@ -475,7 +475,7 @@ class Scope: ...@@ -475,7 +475,7 @@ class Scope:
entry.pystring_cname = entry.cname + "p" entry.pystring_cname = entry.cname + "p"
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 possible_identifier(value): if identifier or (identifier is None and possible_identifier(value)):
entry.is_interned = 1 entry.is_interned = 1
self.global_scope().new_interned_string_entries.append(entry) self.global_scope().new_interned_string_entries.append(entry)
...@@ -751,7 +751,7 @@ class ModuleScope(Scope): ...@@ -751,7 +751,7 @@ class ModuleScope(Scope):
def intern_identifier(self, name): def intern_identifier(self, name):
string_entry = self.get_string_const(name, identifier = True) string_entry = self.get_string_const(name, identifier = True)
self.add_py_string(string_entry) self.add_py_string(string_entry, identifier = 1)
return string_entry.pystring_cname return string_entry.pystring_cname
def find_module(self, module_name, pos): def find_module(self, module_name, pos):
......
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