Commit 1bf517d2 authored by Robert Bradshaw's avatar Robert Bradshaw

C++ parsing simplification, cleanup

parent 7269d7b6
...@@ -89,7 +89,7 @@ def parse_command_line(args): ...@@ -89,7 +89,7 @@ def parse_command_line(args):
options.c_only = 0 options.c_only = 0
options.obj_only = 0 options.obj_only = 0
elif option in ("-+", "--cplus"): elif option in ("-+", "--cplus"):
Options.cplus = options.cplus = 1 options.cplus = 1
elif option == "--embed": elif option == "--embed":
Options.embed = True Options.embed = True
elif option.startswith("-I"): elif option.startswith("-I"):
......
...@@ -4280,7 +4280,7 @@ class NumBinopNode(BinopNode): ...@@ -4280,7 +4280,7 @@ class NumBinopNode(BinopNode):
if type2.is_ptr: if type2.is_ptr:
type2 = type2.base_type type2 = type2.base_type
entry = env.lookup(type1.name) entry = env.lookup(type1.name)
function = entry.type.scope.lookup(self.operators[self.operator]) function = entry.type.scope.lookup("operator%s" % self.operator)
if not function: if not function:
error(self.pos, "'%s' operator not defined for '%s %s %s'" error(self.pos, "'%s' operator not defined for '%s %s %s'"
% (self.operator, type1, self.operator, type2)) % (self.operator, type1, self.operator, type2))
......
...@@ -2593,33 +2593,24 @@ def p_cpp_class_definition(s, pos, ctx): ...@@ -2593,33 +2593,24 @@ def p_cpp_class_definition(s, pos, ctx):
cname = ctx.namespace + "::" + class_name cname = ctx.namespace + "::" + class_name
if s.sy == '.': if s.sy == '.':
error(pos, "Qualified class name not allowed C++ class") error(pos, "Qualified class name not allowed C++ class")
templates = None
if s.sy == '[': if s.sy == '[':
s.next() s.next()
templates = [] templates = [p_ident(s)]
templates.append(s.systring)
s.next()
while s.sy == ',': while s.sy == ',':
s.next() s.next()
templates.append(s.systring) templates.append(p_ident(s))
s.next()
s.expect(']') s.expect(']')
base_classes = [] else:
templates = None
if s.sy == '(': if s.sy == '(':
base_class = True s.next()
while (base_class): base_classes = [p_dotted_name(s, False)[2]]
while s.sy == ',':
s.next() s.next()
base_class_path = [p_ident(s)] base_classes.append(p_dotted_name(s, False)[2])
base_class = False
while s.sy == '.':
s.next()
base_class_path.append(p_ident(s))
base_classes.append(base_class_path)
if s.sy == ',':
base_class = True
base_class_path = []
s.expect(')') s.expect(')')
base_classes = [".".join(path) for path in base_classes] else:
base_classes = []
if s.sy == '[': if s.sy == '[':
error(s.position(), "Name options not allowed for C++ class") error(s.position(), "Name options not allowed for C++ class")
if s.sy == ':': if s.sy == ':':
......
...@@ -311,8 +311,7 @@ class Scope(object): ...@@ -311,8 +311,7 @@ class Scope(object):
if visibility == 'extern': if visibility == 'extern':
warning(pos, "'%s' redeclared " % name, 0) warning(pos, "'%s' redeclared " % name, 0)
elif visibility != 'ignore': elif visibility != 'ignore':
pass error(pos, "'%s' redeclared " % name)
#error(pos, "'%s' redeclared " % name)
entry = Entry(name, cname, type, pos = pos) entry = Entry(name, cname, type, pos = pos)
entry.in_cinclude = self.in_cinclude entry.in_cinclude = self.in_cinclude
if name: if name:
...@@ -464,14 +463,16 @@ class Scope(object): ...@@ -464,14 +463,16 @@ class Scope(object):
if visibility != 'private' and visibility != entry.visibility: if visibility != 'private' and visibility != entry.visibility:
warning(pos, "Function '%s' previously declared as '%s'" % (name, entry.visibility), 1) warning(pos, "Function '%s' previously declared as '%s'" % (name, entry.visibility), 1)
if not entry.type.same_as(type): if not entry.type.same_as(type):
#if visibility == 'extern' and entry.visibility == 'extern': if visibility == 'extern' and entry.visibility == 'extern':
#warning(pos, "Function signature does not match previous declaration", 1) if self.is_cpp():
#entry.type = type temp = self.add_cfunction(name, type, pos, cname, visibility, modifiers)
temp = self.add_cfunction(name, type, pos, cname, visibility, modifiers) entry.overloaded_alternatives.append(temp)
entry.overloaded_alternatives.append(temp) entry = temp
entry = temp else:
#else: warning(pos, "Function signature does not match previous declaration", 1)
#error(pos, "Function signature does not match previous declaration") entry.type = type
else:
error(pos, "Function signature does not match previous declaration")
else: else:
entry = self.add_cfunction(name, type, pos, cname, visibility, modifiers) entry = self.add_cfunction(name, type, pos, cname, visibility, modifiers)
entry.func_cname = cname entry.func_cname = cname
...@@ -485,12 +486,6 @@ class Scope(object): ...@@ -485,12 +486,6 @@ class Scope(object):
entry.is_implemented = True entry.is_implemented = True
if modifiers: if modifiers:
entry.func_modifiers = modifiers entry.func_modifiers = modifiers
#try:
# print entry.name, entry.type, entry.overloaded_alternatives
#except:
# pass
#if len(entry.overloaded_alternatives) > 0:
# print entry.name, entry.type, entry.overloaded_alternatives[0].type
return entry return entry
def add_cfunction(self, name, type, pos, cname, visibility, modifiers): def add_cfunction(self, name, type, pos, cname, visibility, modifiers):
......
...@@ -94,7 +94,8 @@ class TreeVisitor(BasicVisitor): ...@@ -94,7 +94,8 @@ class TreeVisitor(BasicVisitor):
def dump_node(self, node, indent=0): def dump_node(self, node, indent=0):
ignored = list(node.child_attrs) + [u'child_attrs', u'pos', ignored = list(node.child_attrs) + [u'child_attrs', u'pos',
u'gil_message', u'subexprs'] u'gil_message', u'cpp_message',
u'subexprs']
values = [] values = []
pos = node.pos pos = node.pos
if pos: if 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