src: add some asserts on `super` related things
[nit.git] / src / common_ffi / pkgconfig.nit
index 3addbb5..5306b97 100644 (file)
 module pkgconfig
 
 import c
+private import annotation
 
 redef class ToolContext
-       var pkgconfig_phase: Phase = new PkgconfigPhase(self, null)
+       var pkgconfig_phase: Phase = new PkgconfigPhase(self, [literal_phase])
 end
 
 # Detects the `pkgconfig` annotation on the module declaration only.
@@ -31,7 +32,7 @@ class PkgconfigPhase
        redef fun process_annotated_node(nmoduledecl, nat)
        do
                # Skip if we are not interested
-               if nat.n_atid.n_id.text != "pkgconfig" then return
+               if nat.name != "pkgconfig" then return
 
                # Do some validity checks and print errors if the annotation is used incorrectly
                var modelbuilder = toolcontext.modelbuilder
@@ -49,24 +50,18 @@ class PkgconfigPhase
 
                var pkgs = new Array[String]
                for arg in args do
-                       if not arg isa AExprAtArg then
+                       var pkg = arg.as_string
+                       if pkg == null then
                                modelbuilder.error(nat, "Syntax error: \"pkgconfig\" expects its arguments to be the name of the package as String literals.")
                                return
                        end
 
-                       var expr = arg.n_expr
-                       if not expr isa AStringFormExpr then
-                               modelbuilder.error(nat, "Syntax error: \"pkgconfig\" expects its arguments to be the name of the package as String literals.")
-                               return
-                       end
-
-                       var pkg = expr.collect_text
-                       pkg = pkg.substring(1, pkg.length-2)
                        pkgs.add(pkg)
                end
 
                # retreive module
                var nmodule = nmoduledecl.parent.as(AModule)
+               var mmodule = nmodule.mmodule.as(not null)
 
                # check availability of pkg-config
                var proc_which = new IProcess("which", "pkg-config")
@@ -92,12 +87,12 @@ class PkgconfigPhase
                        # compiler
                        var proc = new IProcess("pkg-config", "--cflags", pkg)
                        var compiler_opts = proc.read_all
-                       nmodule.c_compiler_options = "{nmodule.c_compiler_options} {compiler_opts.replace("\n", " ")}"
+                       mmodule.c_compiler_options = "{mmodule.c_compiler_options} {compiler_opts.replace("\n", " ")}"
 
                        # linker
                        proc = new IProcess("pkg-config", "--libs", pkg)
                        var linker_opts = proc.read_all
-                       nmodule.c_linker_options = "{nmodule.c_linker_options} {linker_opts.replace("\n", " ")}"
+                       mmodule.c_linker_options = "{mmodule.c_linker_options} {linker_opts.replace("\n", " ")}"
                end
 
        end