diff python/testc3.py @ 163:8104fc8b5e90

Added visitor to c3
author Windel Bouwman
date Mon, 18 Mar 2013 20:13:57 +0100
parents d8c735dc31f9
children 598d3888a11c
line wrap: on
line diff
--- a/python/testc3.py	Sun Mar 10 11:36:55 2013 +0100
+++ b/python/testc3.py	Mon Mar 18 20:13:57 2013 +0100
@@ -4,12 +4,16 @@
 testsrc = """package test;
 
 var u32 c, d;
+var double e;
+var int f;
+
+const int A = 1337;
 
 function void test1() 
 {
-    var u32 b;
+    var u32 bdd;
     var int a = 10;
-    b = 20;
+    bd = 20;
     var int buf;
     var int i;
     i = 2;
@@ -41,31 +45,24 @@
 
 """
 
-def printAst(ast, indent=''):
-   print(indent + str(ast))
-   if isinstance(ast, c3.astnodes.Package):
-      for s in ast.scope:
-         printAst(s, indent + '  ')
-   if isinstance(ast, c3.astnodes.Function):
-      for s in ast.scope:
-         printAst(s, indent + '  ')
-   for c in ast.getChildren():
-      printAst(c, indent + '  ')
-
 def c3compile(src, diag):
    print('[0] source:')
-   #print(src)
+   print(src)
    print('[1] parsing')
+   # Structures:
    sema = c3.Semantics(diag)
    p = c3.Parser(sema, diag)
    tc = c3.TypeChecker(diag)
    al = c3.Analyzer(diag)
    cg = c3.CodeGenerator()
+   ap = c3.AstPrinter()
+
    x86gen = x86.X86CodeGen(diag)
    p.parseSource(src)
    ok = len(diag.diags) == 0
    if not ok:
       return
+   al.analyzePackage(sema.mod)
    tc.checkPackage(sema.mod)
    print('{0} errors'.format(len(diag.diags)))
 
@@ -73,6 +70,8 @@
       print('ERROR:')
       ppci.printError(testsrc, d)
    print('[2] ast:')
+   ap.printAst(sema.mod)
+
    #printAst(sema.mod)
 
    ok = len(diag.diags) == 0