tests/TreeBuilder.vala
[app.Builder.js] / tests / TreeBuilder.vala
index 12b5565..ca414ea 100644 (file)
@@ -1,9 +1,26 @@
 
+// valac TreeBuilder.vala --pkg libvala-0.24 --pkg posix -o /tmp/treebuilder
 
+public class MyReport  : Vala.Report {
+       
+       public override void err (Vala.SourceReference? source, string message) {
+               errors++;
+               if (source == null) {
+                       stderr.printf ("My error: %s\n", message);
+               } else {
+                       stderr.printf ("%s: My error: %s\n", source.to_string (), message);
+               
+                       //Vala.Report.report_source (source);
+                       
+               }
+       }
+       
+
+}
 
 public class TreeBuilder : Vala.CodeVisitor {
        
-       private Vala.CodeContext create_valac_tree (Settings settings) {
+       public Vala.CodeContext create_valac_tree () {
                // init context:
                var context = new Vala.CodeContext ();
                Vala.CodeContext.push (context);
@@ -14,9 +31,9 @@ public class TreeBuilder : Vala.CodeVisitor {
                context.report.enable_warnings = true;
                context.metadata_directories = { };
                context.gir_directories = {};
-
+               context.report = new MyReport();
                
-               context.basedir = realpath (".");
+               context.basedir = Posix.realpath (".");
                
                context.directory = context.basedir;
                
@@ -26,11 +43,54 @@ public class TreeBuilder : Vala.CodeVisitor {
                        context.profile = Vala.Profile.GOBJECT;
                //      context.add_define ("GOBJECT");
                //}
+               //add_depencies (context, settings.packages);
+               //if (reporter.errors > 0) {
+               //      return context;
+               //}
+
+               var source_file = new Vala.SourceFile (
+                       context, 
+                       Vala.SourceFileType.SOURCE, 
+                       "",
+                       "void atest() { 
+                           var x = 1; asdfasdf 
+                           a++;
+                       }"
+                    );
+               //context.add_source_file (testcode);
+
+               
+               //var source_file = new Vala.SourceFile (context, 
+                //               Vala.SourceFileType.SOURCE, 
+                //               "/home/alan/gitlive/app.Builder.js/tests/TreeBuilder.vala");
 
+               //if (source_package == null) {
+               //source_package = register_package (new Package (settings.pkg_name, false, null));
+               //}
+
+               //register_source_file (source_package, source_file);
+
+               context.add_external_package ("glib-2.0");
+               context.add_external_package ("gobject-2.0");
+               context.add_external_package ("libvala-0.24");
+               context.add_external_package ("posix");
+               //if (context.profile == Vala.Profile.GOBJECT) {
+                       // import the GLib namespace by default (namespace of backend-specific standard library)
+                       var ns_ref = new Vala.UsingDirective (new Vala.UnresolvedSymbol (null, "GLib", null));
+                       source_file.add_using_directive (ns_ref);
+                       context.root.add_using_directive (ns_ref);
+               //}
+
+               context.add_source_file (source_file);
+
+               
+               //add_documented_files (context, settings.source_files);
+               
                Vala.Parser parser = new Vala.Parser ();
                parser.parse (context);
-               gir_parser.parse (context);
+               //gir_parser.parse (context);
                if (context.report.get_errors () > 0) {
+                       print("got errors");
                        return context;
                }
 
@@ -41,10 +101,19 @@ public class TreeBuilder : Vala.CodeVisitor {
                if (context.report.get_errors () > 0) {
                        return context;
                }
+               return context;
        }
+//
+       // startpoint:
+       //
 }
 
 int main (string[] args) {
 
        var a = new TreeBuilder();
-       a.create_valac_tree(
\ No newline at end of file
+       a.create_valac_tree();
+       return 0;
+}
+
+