diff python/testc3.py @ 150:4ae0e02599de

Added type check start and analyze phase
author Windel Bouwman
date Fri, 01 Mar 2013 16:53:22 +0100
parents 74241ca312cc
children afc8c0207984
line wrap: on
line diff
--- a/python/testc3.py	Fri Mar 01 11:43:52 2013 +0100
+++ b/python/testc3.py	Fri Mar 01 16:53:22 2013 +0100
@@ -1,11 +1,10 @@
-import c3.parser, c3.semantics
+import c3
 from ppci.errors import printError, Diagnostics
 import time
 
 testsrc = """
 package test;
 
-var u32 a ;
 var u32 c, d;
 
 function void test1() 
@@ -13,12 +12,13 @@
     var u32 b;
     var int a = 10;
     b = 20;
-    var int buf;
+    var int88 buf;
     var int i;
     i = 2;
+    zero = i - 2;
     if (i > 1)
     {
-       buf = b + 22 * i - 13 + (55 * 2 *9-2) / 44
+       buf = b + 22 * i - 13 + (55 * 2 *9-2) / 44 - one
     }
 }
 
@@ -28,10 +28,12 @@
    a = 2
 }
 
+var u8 hahaa = 23 * 2;
+
 function int t2(u32 a, u32 b)
 {
    return a + b;
-   a = 2 + 33 - 1;
+   a = 2 + 33 * 1 - 3;
    a = a - 2
 }
 
@@ -42,7 +44,7 @@
    if isinstance(ast, c3.astnodes.Package):
       for s in ast.scope:
          printAst(s, indent + '  ')
-   if isinstance(ast, c3.astnodes.Procedure):
+   if isinstance(ast, c3.astnodes.Function):
       for s in ast.scope:
          printAst(s, indent + '  ')
    for c in ast.getChildren():
@@ -53,15 +55,22 @@
    print(testsrc)
    print('[1] parsing')
    diag = Diagnostics()
-   sema = c3.semantics.Semantics(diag)
-   p = c3.parser.Parser(sema, diag)
+   sema = c3.Semantics(diag)
+   p = c3.Parser(sema, diag)
+   tc = c3.TypeChecker(diag)
+   al = c3.Analyzer(diag)
    t1 = time.time()
    p.parseSource(testsrc)
    t2 = time.time() 
    print('parsetime: {0} [s]'.format(t2 - t1))
+   t2 = time.time() 
+   tc.checkPackage(sema.mod)
+   t3 = time.time() 
+   print('checktime: {0} [s]'.format(t3 - t2))
+   print('{0} errors'.format(len(diag.diags)))
 
    for d in diag.diags:
-      print('ERROR:', d)
+      print('ERROR:')
       printError(testsrc, d)
    print('[2] ast:')
    printAst(sema.mod)