Mercurial > lcfOS
diff python/c3/typecheck.py @ 167:0b5b2ee6b435
Added 2 unit tests
author | Windel Bouwman |
---|---|
date | Fri, 22 Mar 2013 17:40:13 +0100 |
parents | da0087b82fbe |
children | 49f1ab80d040 |
line wrap: on
line diff
--- a/python/c3/typecheck.py Fri Mar 22 16:15:31 2013 +0100 +++ b/python/c3/typecheck.py Fri Mar 22 17:40:13 2013 +0100 @@ -28,12 +28,22 @@ self.diag.error('Cannot assign {0} to {1}'.format(sym.rval.typ, sym.lval.typ), sym.loc) elif type(sym) is ReturnStatement: pass - elif type(sym) is ProcedureCall: - # Check arguments: + elif type(sym) is FunctionCall: if sym.proc: - pass - # determine return type: - sym.typ = sym.proc.typ.returntype + # Check arguments: + ngiv = len(sym.args) + ptypes = sym.proc.typ.parametertypes + nreq = len(ptypes) + if ngiv != nreq: + self.diag.error('Function {2}: {0} arguments required, {1} given'.format(nreq, ngiv, sym.proc.name), sym.loc) + else: + for a, at in zip(sym.args, ptypes): + if not equalTypes(a.typ, at): + self.diag.error('Got {0}, expected {1}'.format(a.typ, at), a.loc) + # determine return type: + sym.typ = sym.proc.typ.returntype + else: + sym.typ = intType elif type(sym) is VariableUse: if sym.target: sym.typ = sym.target.typ