Mercurial > lcfOS
comparison 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 |
comparison
equal
deleted
inserted
replaced
166:da0087b82fbe | 167:0b5b2ee6b435 |
---|---|
26 elif type(sym) is Assignment: | 26 elif type(sym) is Assignment: |
27 if not equalTypes(sym.lval.typ, sym.rval.typ): | 27 if not equalTypes(sym.lval.typ, sym.rval.typ): |
28 self.diag.error('Cannot assign {0} to {1}'.format(sym.rval.typ, sym.lval.typ), sym.loc) | 28 self.diag.error('Cannot assign {0} to {1}'.format(sym.rval.typ, sym.lval.typ), sym.loc) |
29 elif type(sym) is ReturnStatement: | 29 elif type(sym) is ReturnStatement: |
30 pass | 30 pass |
31 elif type(sym) is ProcedureCall: | 31 elif type(sym) is FunctionCall: |
32 # Check arguments: | |
33 if sym.proc: | 32 if sym.proc: |
34 pass | 33 # Check arguments: |
35 # determine return type: | 34 ngiv = len(sym.args) |
36 sym.typ = sym.proc.typ.returntype | 35 ptypes = sym.proc.typ.parametertypes |
36 nreq = len(ptypes) | |
37 if ngiv != nreq: | |
38 self.diag.error('Function {2}: {0} arguments required, {1} given'.format(nreq, ngiv, sym.proc.name), sym.loc) | |
39 else: | |
40 for a, at in zip(sym.args, ptypes): | |
41 if not equalTypes(a.typ, at): | |
42 self.diag.error('Got {0}, expected {1}'.format(a.typ, at), a.loc) | |
43 # determine return type: | |
44 sym.typ = sym.proc.typ.returntype | |
45 else: | |
46 sym.typ = intType | |
37 elif type(sym) is VariableUse: | 47 elif type(sym) is VariableUse: |
38 if sym.target: | 48 if sym.target: |
39 sym.typ = sym.target.typ | 49 sym.typ = sym.target.typ |
40 else: | 50 else: |
41 sym.typ = intType | 51 sym.typ = intType |