]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
SourceFile: Introduce SourceFileType enumeration
authorRyan Lortie <desrt@desrt.ca>
Tue, 24 Aug 2010 17:01:39 +0000 (19:01 +0200)
committerJürg Billeter <j@bitron.ch>
Thu, 9 Sep 2010 13:54:17 +0000 (15:54 +0200)
SourceFileType has 2 possible values:
  SOURCE
  PACKAGE

and replaces the CodeWriter.external_package boolean with a new field
called 'file_type'.

codegen/valaccodebasemodule.vala
codegen/valaccodecompiler.vala
codegen/valadovabasemodule.vala
compiler/valacompiler.vala
vala/valaflowanalyzer.vala
vala/valagenieparser.vala
vala/valaparser.vala
vala/valasourcefile.vala
vala/valasymbol.vala
vapigen/valavapicheck.vala
vapigen/valavapigen.vala

index fcfe5c931ac0fc1577c73a12d71cf846d7932f39..8bb281dceea963c7a0d392635578c424e9f391c2 100644 (file)
@@ -417,7 +417,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
                /* we're only interested in non-pkg source files */
                var source_files = context.get_source_files ();
                foreach (SourceFile file in source_files) {
-                       if (!file.external_package) {
+                       if (file.file_type == SourceFileType.SOURCE) {
                                file.accept (this);
                        }
                }
@@ -751,7 +751,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
                        return;
                }
 
-               if (!c.external) {
+               if (c.source_reference.file.file_type != SourceFileType.PACKAGE) {
                        generate_type_declaration (c.type_reference, decl_space);
 
                        c.value.emit (this);
index 6bec31348d23fcc16d17011c07751022e2738659..09ab3d619501e2aed1b08b971bb726836562f9bf 100644 (file)
@@ -105,7 +105,7 @@ public class Vala.CCodeCompiler {
                /* we're only interested in non-pkg source files */
                var source_files = context.get_source_files ();
                foreach (SourceFile file in source_files) {
-                       if (!file.external_package) {
+                       if (file.file_type == SourceFileType.SOURCE) {
                                cmdline += " " + Shell.quote (file.get_csource_filename ());
                        }
                }
@@ -137,7 +137,7 @@ public class Vala.CCodeCompiler {
 
                /* remove generated C source and header files */
                foreach (SourceFile file in source_files) {
-                       if (!file.external_package) {
+                       if (file.file_type == SourceFileType.SOURCE) {
                                if (!context.save_csources) {
                                        FileUtils.unlink (file.get_csource_filename ());
                                }
index de3c3ca575fc16ffd86f8c5a6ce9d8e57333f965..4e3505399f634b15acd3ae230445a0428a824c10 100644 (file)
@@ -292,7 +292,7 @@ public class Vala.DovaBaseModule : CodeGenerator {
                /* we're only interested in non-pkg source files */
                var source_files = context.get_source_files ();
                foreach (SourceFile file in source_files) {
-                       if (!file.external_package) {
+                       if (file.file_type == SourceFileType.SOURCE) {
                                file.accept (this);
                        }
                }
index 0e313a43d83f1b696b005e6f189746553db4d424..49383da49cc5148ead6d445100080ad550885a50 100644 (file)
@@ -151,7 +151,7 @@ class Vala.Compiler {
                        return false;
                }
 
-               context.add_source_file (new SourceFile (context, gir_path, true));
+               context.add_source_file (new SourceFile (context, SourceFileType.PACKAGE, gir_path));
 
                return true;
        }
@@ -170,7 +170,7 @@ class Vala.Compiler {
                
                context.add_package (pkg);
                
-               context.add_source_file (new SourceFile (context, package_path, true));
+               context.add_source_file (new SourceFile (context, SourceFileType.PACKAGE, package_path));
                
                var deps_filename = Path.build_filename (Path.get_dirname (package_path), "%s.deps".printf (pkg));
                if (FileUtils.test (deps_filename, FileTest.EXISTS)) {
@@ -352,7 +352,7 @@ class Vala.Compiler {
                        if (FileUtils.test (source, FileTest.EXISTS)) {
                                var rpath = realpath (source);
                                if (run_output || source.has_suffix (".vala") || source.has_suffix (".gs")) {
-                                       var source_file = new SourceFile (context, rpath);
+                                       var source_file = new SourceFile (context, SourceFileType.SOURCE, rpath);
                                        source_file.relative_filename = source;
 
                                        if (context.profile == Profile.POSIX) {
@@ -374,7 +374,7 @@ class Vala.Compiler {
 
                                        context.add_source_file (source_file);
                                } else if (source.has_suffix (".vapi") || source.has_suffix (".gir")) {
-                                       var source_file = new SourceFile (context, rpath, true);
+                                       var source_file = new SourceFile (context, SourceFileType.PACKAGE, rpath);
                                        source_file.relative_filename = source;
 
                                        context.add_source_file (source_file);
index 74c35f6f73e418ee733c7645443c81366e22df27..5394e86b9a88857a336d58f3f92b148f26c41057 100644 (file)
@@ -108,7 +108,7 @@ public class Vala.FlowAnalyzer : CodeVisitor {
                /* we're only interested in non-pkg source files */
                var source_files = context.get_source_files ();
                foreach (SourceFile file in source_files) {
-                       if (!file.external_package) {
+                       if (file.file_type == SourceFileType.SOURCE) {
                                file.accept (this);
                        }
                }
index 0649c28c08ac0fc7c2e17e2c97b900e96eba3a02..36a8d524038296bdb62770f6820059888bdeeab0 100644 (file)
@@ -2638,7 +2638,7 @@ public class Vala.Genie.Parser : CodeVisitor {
                parse_declarations (cl);
 
                // ensure there is always a default construction method
-               if (!scanner.source_file.external_package
+               if (scanner.source_file.file_type == SourceFileType.SOURCE
                    && cl.default_construction_method == null) {
                        var m = new CreationMethod (cl.name, null, cl.source_reference);
                        m.access = SymbolAccessibility.PUBLIC;
@@ -2751,7 +2751,7 @@ public class Vala.Genie.Parser : CodeVisitor {
                var c = new Constant (id, type, initializer, get_src (begin), comment);
                c.access = get_access (id);
                
-               if (ModifierFlags.EXTERN in flags || scanner.source_file.external_package) {
+               if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) {
                        c.external = true;
                }
                if (ModifierFlags.NEW in flags) {
@@ -2787,7 +2787,7 @@ public class Vala.Genie.Parser : CodeVisitor {
 
                set_attributes (f, attrs);
 
-               if (ModifierFlags.EXTERN in flags || scanner.source_file.external_package) {
+               if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) {
                        f.external = true;
                }
                if (ModifierFlags.NEW in flags) {
@@ -3006,7 +3006,7 @@ public class Vala.Genie.Parser : CodeVisitor {
 
                if (accept_block ()) {
                        method.body = parse_block ();
-               } else if (scanner.source_file.external_package) {
+               } else if (scanner.source_file.file_type == SourceFileType.PACKAGE) {
                        method.external = true;
                }
                return method;
@@ -3054,7 +3054,7 @@ public class Vala.Genie.Parser : CodeVisitor {
                if (ModifierFlags.NEW in flags) {
                        prop.hides = true;
                }
-               if (ModifierFlags.EXTERN in flags || scanner.source_file.external_package) {
+               if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) {
                        prop.external = true;
                }
                
@@ -3136,7 +3136,7 @@ public class Vala.Genie.Parser : CodeVisitor {
                        expect_terminator ();
                }
 
-               if (!prop.is_abstract && !scanner.source_file.external_package) {
+               if (!prop.is_abstract && scanner.source_file.file_type == SourceFileType.SOURCE) {
                        var needs_var = (readonly && (prop.get_accessor != null && prop.get_accessor.body == null));
 
                        if (!needs_var) {
@@ -3318,7 +3318,7 @@ public class Vala.Genie.Parser : CodeVisitor {
                } else {
                        iface.access = get_access (sym.name);
                }
-               if (ModifierFlags.EXTERN in flags || scanner.source_file.external_package) {
+               if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) {
                        iface.external = true;
                }
                set_attributes (iface, attrs);
@@ -3386,7 +3386,7 @@ public class Vala.Genie.Parser : CodeVisitor {
                } else {
                        en.access = get_access (sym.name);
                }
-               if (ModifierFlags.EXTERN in flags || scanner.source_file.external_package) {
+               if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) {
                        en.external = true;
                }
                set_attributes (en, attrs);
@@ -3644,7 +3644,7 @@ public class Vala.Genie.Parser : CodeVisitor {
 
                if (accept_block ()) {
                        method.body = parse_block ();
-               } else if (scanner.source_file.external_package) {
+               } else if (scanner.source_file.file_type == SourceFileType.PACKAGE) {
                        method.external = true;
                }
                
@@ -3705,7 +3705,7 @@ public class Vala.Genie.Parser : CodeVisitor {
                if (!(ModifierFlags.STATIC in flags)) {
                        d.has_target = true;
                }
-               if (ModifierFlags.EXTERN in flags || scanner.source_file.external_package) {
+               if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) {
                        d.external = true;
                }
 
index edc48130eaadeeeff28e7fef75aa5e9fd076b6ec..4de1f23722fd4f3ff64b14b9093ef3f15f1d132a 100644 (file)
@@ -2360,7 +2360,7 @@ public class Vala.Parser : CodeVisitor {
                if (ModifierFlags.ABSTRACT in flags) {
                        cl.is_abstract = true;
                }
-               if (ModifierFlags.EXTERN in flags || scanner.source_file.external_package) {
+               if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) {
                        cl.external = true;
                }
                set_attributes (cl, attrs);
@@ -2374,7 +2374,7 @@ public class Vala.Parser : CodeVisitor {
                parse_declarations (cl);
 
                // ensure there is always a default construction method
-               if (!scanner.source_file.external_package
+               if (scanner.source_file.file_type == SourceFileType.SOURCE
                    && cl.default_construction_method == null) {
                        var m = new CreationMethod (cl.name, null, cl.source_reference);
                        m.access = SymbolAccessibility.PUBLIC;
@@ -2420,7 +2420,7 @@ public class Vala.Parser : CodeVisitor {
 
                var c = new Constant (id, type, initializer, get_src (begin), comment);
                c.access = access;
-               if (ModifierFlags.EXTERN in flags || scanner.source_file.external_package) {
+               if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) {
                        c.external = true;
                }
                if (ModifierFlags.NEW in flags) {
@@ -2456,7 +2456,7 @@ public class Vala.Parser : CodeVisitor {
                    || ModifierFlags.OVERRIDE in flags) {
                        Report.error (f.source_reference, "abstract, virtual, and override modifiers are not applicable to fields");
                }
-               if (ModifierFlags.EXTERN in flags || scanner.source_file.external_package) {
+               if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) {
                        f.external = true;
                }
                if (ModifierFlags.NEW in flags) {
@@ -2626,7 +2626,7 @@ public class Vala.Parser : CodeVisitor {
                }
                if (!accept (TokenType.SEMICOLON)) {
                        method.body = parse_block ();
-               } else if (scanner.source_file.external_package) {
+               } else if (scanner.source_file.file_type == SourceFileType.PACKAGE) {
                        method.external = true;
                }
 
@@ -2673,7 +2673,7 @@ public class Vala.Parser : CodeVisitor {
                if (ModifierFlags.ASYNC in flags) {
                        Report.error (prop.source_reference, "async properties are not supported yet");
                }
-               if (ModifierFlags.EXTERN in flags || scanner.source_file.external_package) {
+               if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) {
                        prop.external = true;
                }
                if (context.profile == Profile.DOVA) {
@@ -2863,7 +2863,7 @@ public class Vala.Parser : CodeVisitor {
                }
                var st = new Struct (sym.name, get_src (begin), comment);
                st.access = access;
-               if (ModifierFlags.EXTERN in flags || scanner.source_file.external_package) {
+               if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) {
                        st.external = true;
                }
                set_attributes (st, attrs);
@@ -2906,7 +2906,7 @@ public class Vala.Parser : CodeVisitor {
                }
                var iface = new Interface (sym.name, get_src (begin), comment);
                iface.access = access;
-               if (ModifierFlags.EXTERN in flags || scanner.source_file.external_package) {
+               if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) {
                        iface.external = true;
                }
                set_attributes (iface, attrs);
@@ -2941,7 +2941,7 @@ public class Vala.Parser : CodeVisitor {
                var sym = parse_symbol_name ();
                var en = new Enum (sym.name, get_src (begin), comment);
                en.access = access;
-               if (ModifierFlags.EXTERN in flags || scanner.source_file.external_package) {
+               if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) {
                        en.external = true;
                }
                set_attributes (en, attrs);
@@ -2997,7 +2997,7 @@ public class Vala.Parser : CodeVisitor {
                var sym = parse_symbol_name ();
                var ed = new ErrorDomain (sym.name, get_src (begin), comment);
                ed.access = access;
-               if (ModifierFlags.EXTERN in flags || scanner.source_file.external_package) {
+               if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) {
                        ed.external = true;
                }
                set_attributes (ed, attrs);
@@ -3243,7 +3243,7 @@ public class Vala.Parser : CodeVisitor {
                set_attributes (method, attrs);
                if (!accept (TokenType.SEMICOLON)) {
                        method.body = parse_block ();
-               } else if (scanner.source_file.external_package) {
+               } else if (scanner.source_file.file_type == SourceFileType.PACKAGE) {
                        method.external = true;
                }
 
@@ -3272,7 +3272,7 @@ public class Vala.Parser : CodeVisitor {
                } else {
                        d.has_target = true;
                }
-               if (ModifierFlags.EXTERN in flags || scanner.source_file.external_package) {
+               if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) {
                        d.external = true;
                }
                foreach (TypeParameter type_param in type_param_list) {
index e58e009d4e08bb4223f4f228762e25acdabe0b83..ff4be85e99873a7ae33334bed404b5b516fa981c 100644 (file)
@@ -40,7 +40,7 @@ public class Vala.SourceFile {
        /**
         * Specifies whether this file is a VAPI package file.
         */
-       public bool external_package { get; set; }
+       public SourceFileType file_type { get; set; }
 
        /**
         *  GIR Namespace for this source file, if it's a VAPI package
@@ -91,10 +91,10 @@ public class Vala.SourceFile {
         * @param pkg      true if this is a VAPI package file
         * @return         newly created source file
         */
-       public SourceFile (CodeContext context, string filename, bool pkg = false, string? content = null) {
-               this.filename = filename;
-               this.external_package = pkg;
+       public SourceFile (CodeContext context, SourceFileType type, string filename, string? content = null) {
                this.context = context;
+               this.file_type = type;
+               this.filename = filename;
                this.content = content;
        }
 
@@ -314,3 +314,7 @@ public class Vala.SourceFile {
        }
 }
 
+public enum SourceFileType {
+       SOURCE,
+       PACKAGE
+}
index 9bea678e05a3b876a9b38c34a65b785cec23024c..0df385de8798c8e0eb34f96d0a0ec13e32be7db7 100644 (file)
@@ -156,7 +156,7 @@ public abstract class Vala.Symbol : CodeNode {
         */
        public bool external_package {
                get {
-                       return (source_reference != null && source_reference.file.external_package);
+                       return (source_reference != null && source_reference.file.file_type == SourceFileType.PACKAGE);
                }
        }
 
index b6fa644687835b40b0329761cd75b5237fff7cf9..daa8776b9a5f9207244409b947e58e5e6a47993d 100644 (file)
@@ -24,8 +24,8 @@ using GLib;
 
 class Vala.VAPICheck : Object {
        public VAPICheck (string gidlname, CodeContext context = new CodeContext ()) {
-               gidl = new SourceFile (context, gidlname);
-               metadata = new SourceFile (context, gidlname.substring (0, gidlname.length - 5) + ".metadata");
+               gidl = new SourceFile (context, SourceFileType.SOURCE, gidlname);
+               metadata = new SourceFile (context, SourceFileType.SOURCE, gidlname.substring (0, gidlname.length - 5) + ".metadata");
                this.context = context;
        }
 
index 403fa89f4a88e04f2ac93f65ce9b787df31b4952..577d5192708bc5422a9a9355b1335688a00a33f6 100644 (file)
@@ -77,7 +77,7 @@ class Vala.VAPIGen : Object {
                
                context.add_package (pkg);
 
-               context.add_source_file (new SourceFile (context, package_path, true));
+               context.add_source_file (new SourceFile (context, SourceFileType.PACKAGE, package_path));
 
                var deps_filename = Path.build_filename (Path.get_dirname (package_path), "%s.deps".printf (pkg));
                if (FileUtils.test (deps_filename, FileTest.EXISTS)) {
@@ -176,7 +176,7 @@ class Vala.VAPIGen : Object {
                
                foreach (string source in sources) {
                        if (FileUtils.test (source, FileTest.EXISTS)) {
-                               context.add_source_file (new SourceFile (context, source, true));
+                               context.add_source_file (new SourceFile (context, SourceFileType.PACKAGE, source));
                        } else {
                                Report.error (null, "%s not found".printf (source));
                        }
@@ -240,7 +240,7 @@ class Vala.VAPIGen : Object {
                        // interface writer ignores external packages
                        foreach (SourceFile file in context.get_source_files ()) {
                                if (!file.filename.has_suffix (".vapi")) {
-                                       file.external_package = false;
+                                       file.file_type = SourceFileType.SOURCE;
                                }
                        }