Commit d19358be authored by Danilo Freitas's avatar Danilo Freitas

Start with references

parent dffd0a32
......@@ -476,6 +476,18 @@ class CPtrDeclaratorNode(CDeclaratorNode):
ptr_type = PyrexTypes.c_ptr_type(base_type)
return self.base.analyse(ptr_type, env, nonempty = nonempty)
class CReferenceDeclaratorNode(CDeclaratorNode):
# base CDeclaratorNode
child_attrs = ["base"]
def analyse(self, base_type, env, nonempty = 0):
if base_type.is_pyobject:
error(self.pos,
"Reference base type cannot be a Python object")
ref_type = Pyrextypes.c_ref_type(base_type)
return self.base.analyse(ref_type, env, nonempty = nonempty)
class CArrayDeclaratorNode(CDeclaratorNode):
# base CDeclaratorNode
# dimension ExprNode
......
......@@ -1749,6 +1749,9 @@ def p_c_simple_base_type(s, self_flag, nonempty, templates = None):
if s.sy == 'IDENT' and s.systring in basic_c_type_names:
name = s.systring
s.next()
if s.sy == '&':
s.next()
#TODO (Danilo)
else:
name = 'int'
if s.sy == 'IDENT' and s.systring == 'complex':
......
......@@ -39,6 +39,7 @@ class PyrexType(BaseType):
# is_array boolean Is a C array type
# is_ptr boolean Is a C pointer type
# is_null_ptr boolean Is the type of NULL
# is_reference boolean Is a C reference type
# is_cfunction boolean Is a C function type
# is_struct_or_union boolean Is a C struct or union type
# is_struct boolean Is a C struct type
......@@ -1018,6 +1019,37 @@ class CNullPtrType(CPtrType):
is_null_ptr = 1
class CReferenceType(CType):
is_reference = 1
def __init__(self, base_type):
self.base_type = base_type
def __repr__(self):
return "<CReferenceType %s>" % repr(self.base_type)
def same_as_resolved_type(self, other_type):
return self.base_type.same_as(other_type.base_type)
def declaration_code(self, entity_code,
for_display = 0, dll_linkage = None, pyrex = 0):
#print "CPtrType.declaration_code: pointer to", self.base_type ###
return self.base_type.declaration_code(
"&%s" % entity_code,
for_display, dll_linkage, pyrex)
def assignable_from_resolved_type(self, other_type):
return 0 #TODO (Danilo) implement this
def specialize(self, values):
base_type = self.base_type.specialize(values)
if base_type == self.base_type:
return self
else:
return CReferenceType(base_type)
class CFuncType(CType):
# return_type CType
# args [CFuncTypeArg]
......@@ -1891,6 +1923,15 @@ def c_ptr_type(base_type):
else:
return CPtrType(base_type)
def c_ref_type(base_type):
# Construct a C reference type
if base_type is c_char_type:
return None #TODO (Danilo) create c_char_ref_type
elif base_type is error_type:
return error_type
else:
return CReferenceType(base_type)
def Node_to_type(node, env):
from ExprNodes import NameNode, AttributeNode, StringNode, error
if isinstance(node, StringNode):
......
......@@ -311,7 +311,8 @@ class Scope(object):
if visibility == 'extern':
warning(pos, "'%s' redeclared " % name, 0)
elif visibility != 'ignore':
error(pos, "'%s' redeclared " % name)
pass
#error(pos, "'%s' redeclared " % name)
entry = Entry(name, cname, type, pos = pos)
entry.in_cinclude = self.in_cinclude
if name:
......@@ -463,13 +464,14 @@ class Scope(object):
if visibility != 'private' and visibility != entry.visibility:
warning(pos, "Function '%s' previously declared as '%s'" % (name, entry.visibility), 1)
if not entry.type.same_as(type):
if visibility == 'extern' and entry.visibility == 'extern':
warning(pos, "Function signature does not match previous declaration", 1)
#if visibility == 'extern' and entry.visibility == 'extern':
#warning(pos, "Function signature does not match previous declaration", 1)
#entry.type = type
entry.overloaded_alternatives.append(
self.add_cfunction(name, type, pos, cname, visibility, modifiers))
else:
error(pos, "Function signature does not match previous declaration")
temp = self.add_cfunction(name, type, pos, cname, visibility, modifiers)
entry.overloaded_alternatives.append(temp)
entry = temp
#else:
#error(pos, "Function signature does not match previous declaration")
else:
entry = self.add_cfunction(name, type, pos, cname, visibility, modifiers)
entry.func_cname = cname
......
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