public static VarTypeObject resolveVarTypeObject(VarTypeObject objToDeref, Template anonymous, Template resolved)
 {
     if (anonymous == null || resolved == null)
         return objToDeref;
     if (resolved.vtoList.Count != anonymous.vtoList.Count)
         throw new Exception();
     for (int i = 0; i < anonymous.vtoList.Count; i++)
     {
         if (objToDeref.Equals(anonymous.vtoList[i]))
             return resolved.vtoList[i];
     }
     return objToDeref;
 }
Example #2
0
 public static VarTypeObject resolveVarTypeObject(VarTypeObject objToDeref, Template anonymous, Template resolved)
 {
     if (anonymous == null || resolved == null)
     {
         return(objToDeref);
     }
     if (resolved.vtoList.Count != anonymous.vtoList.Count)
     {
         throw new Exception();
     }
     for (int i = 0; i < anonymous.vtoList.Count; i++)
     {
         if (objToDeref.Equals(anonymous.vtoList[i]))
         {
             return(resolved.vtoList[i]);
         }
     }
     return(objToDeref);
 }
Example #3
0
        public void Compile(Project proj)
        {
            ProjectFile = proj;
            //Make sure the build directory exists and create it if needed
            if (!Directory.Exists(proj.Buildfolder))
            {
                Directory.CreateDirectory(proj.Buildfolder);
            }
            if (!Directory.Exists(proj.OutputFolder))
            {
                Directory.CreateDirectory(proj.OutputFolder);
            }

            //Prepare some stuff needed for preprocessing
            List <preprocessFile_IfDefModes> ifdefs  = new List <preprocessFile_IfDefModes>();
            List <PostProcessFile>           ppFiles = new List <PostProcessFile>();

            //do the preprocessing
            preprocessFile(ifdefs, proj.Mainfile, "", ppFiles);
            var ppMainFile = ppFiles[0];

            if (outputFolderCleanup)
            {
                Logger.Instance.log(Logger.LogLevel.VERBOSE, "Cleaning up output dir");
                cleanupRecursive(proj.OutputFolder);
            }

            int errCount = 0;
            //Check the syntax of all files in ppFiles
            //foreach (var it in ppFiles)
            //{
            //    //if (!noPrintOut)
            //    //{
            //    //    var stream = File.Create(proj.Buildfolder + it.Name + ".obj");
            //    //    it.resetPosition();
            //    //    it.FileStream.WriteTo(stream);
            //    //    stream.Flush();
            //    //    stream.Close();
            //    //}
            //    Scanner scanner = new Scanner(it.FileStream);
            //    Base baseObject = new Base();
            //    Parser p = new Parser(scanner, it.FilePath);
            //    Parser.UsedFiles = new List<string>();
            //    p.BaseObject = baseObject;
            //    p.Parse();
            //    if (p.errors.count > 0)
            //    {
            //        errCount += p.errors.count;
            //        Logger.Instance.log(Logger.LogLevel.ERROR, "In file '" + it.Name + "'");
            //    }
            //    if (printOutMode > 0)
            //    {
            //        if (printOutMode == 1 && it == ppMainFile)
            //        {
            //            var stream = File.Create(proj.Buildfolder + it.Name + ".obj");
            //            it.resetPosition();
            //            it.FileStream.WriteTo(stream);
            //            stream.Flush();
            //            stream.Close();
            //        }
            //        if (printOutMode >= 2)
            //        {
            //            var stream = File.Create(proj.Buildfolder + it.Name + ".obj");
            //            it.resetPosition();
            //            it.FileStream.WriteTo(stream);
            //            stream.Flush();
            //            stream.Close();
            //        }
            //    }
            //    it.resetPosition();
            //}
            //if (errCount > 0)
            //{
            //    Logger.Instance.log(Logger.LogLevel.ERROR, "Errors found (" + errCount + "), cannot continue with Translating!");
            //    return;
            //}

            //Read in all internal objects
            Base oosTreeBase = new Base();

            NamespaceResolver.BaseClass = oosTreeBase;
            {
                Parser p;
                p = new Parser(new Scanner(toStream(global::Compiler.Properties.Resources._object)), "");
                Parser.UsedFiles = new List <string>();
                p.BaseObject     = oosTreeBase;
                p.Parse();
                errCount += p.errors.count;
                InternalObjectVarTypes.VT_object.ident.finalize();
                InternalObjectVarTypes.VT_nobject.ident.finalize();


                p = new Parser(new Scanner(toStream(global::Compiler.Properties.Resources.array)), "");
                Parser.UsedFiles = new List <string>();
                p.BaseObject     = oosTreeBase;
                p.Parse();
                errCount += p.errors.count;


                p = new Parser(new Scanner(toStream(global::Compiler.Properties.Resources.vec3)), "");
                Parser.UsedFiles = new List <string>();
                p.BaseObject     = oosTreeBase;
                p.Parse();
                errCount += p.errors.count;
                InternalObjectVarTypes.VT_vec3.ident.finalize();


                p = new Parser(new Scanner(toStream(global::Compiler.Properties.Resources._string)), "");
                Parser.UsedFiles = new List <string>();
                p.BaseObject     = oosTreeBase;
                p.Parse();
                errCount += p.errors.count;
                InternalObjectVarTypes.VT_string.ident.finalize();


                p = new Parser(new Scanner(toStream(global::Compiler.Properties.Resources.script)), "");
                Parser.UsedFiles = new List <string>();
                p.BaseObject     = oosTreeBase;
                p.Parse();
                errCount += p.errors.count;
                InternalObjectVarTypes.VT_script.ident.finalize();


                p = new Parser(new Scanner(toStream(global::Compiler.Properties.Resources.functions)), "");
                Parser.UsedFiles = new List <string>();
                p.BaseObject     = oosTreeBase;
                p.Parse();
                errCount += p.errors.count;


                p = new Parser(new Scanner(toStream(global::Compiler.Properties.Resources.Exception)), "");
                Parser.UsedFiles = new List <string>();
                p.BaseObject     = oosTreeBase;
                p.Parse();
                errCount += p.errors.count;
                InternalObjectVarTypes.VT_Exception.ident.finalize();


                if (errCount > 0)
                {
                    Logger.Instance.log(Logger.LogLevel.ERROR, "Errors found in ressource OOS files (" + errCount + "), cannot continue with Compiling!");
                    return;
                }
            }

            //process the actual file
            Parser parser = new Parser(new Scanner(ppMainFile.FileStream), ppMainFile.FilePath);

            Parser.UsedFiles  = new List <string>();
            parser.BaseObject = oosTreeBase;
            parser.Parse();

            errCount = parser.errors.count;
            if (errCount > 0)
            {
                Logger.Instance.log(Logger.LogLevel.ERROR, "Errors found (" + errCount + "), cannot continue with Compiling!");
                return;
            }
            var preInitFunction = parser.BaseObject.getAllChildrenOf <Function>(true, null, -1, -1, new Type[] { typeof(Namespace), typeof(oosClass) }, (obj) => obj.Name.OriginalValue.Equals("preInit"));

            errCount = 0;
            if (preInitFunction.Count > 1)
            {
                foreach (var it in preInitFunction)
                {
                    errCount++;
                    Logger.Instance.log(Logger.LogLevel.ERROR, ErrorStringResolver.resolve(ErrorStringResolver.LinkerErrorCode.LNK0060, it.Name.Line, it.Name.Pos, it.Name.File));
                }
            }
            else if (preInitFunction.Count == 0)
            {
                var n = new Namespace(parser.BaseObject);
                parser.BaseObject.addChild(parser.BaseObject);
                n.Name = new Ident(n, ProjectFile.Author + "ComGenPreInitNS", 0, 0, "");

                var fnc = new Function(n);
                n.addChild(fnc);
                fnc.Name = new Ident(fnc, "preInit", 0, 0, "");
                preInitFunction.Add(fnc);
            }
            int id         = 0;
            var allClasses = parser.BaseObject.getAllChildrenOf <oosClass>(true, null, -1, -1, new Type[] { typeof(Namespace) }, (obj) => { obj.ID = id++; return(true); });

            id = 0;
            var allInterfaces = parser.BaseObject.getAllChildrenOf <oosInterface>(true, null, -1, -1, new Type[] { typeof(Namespace) }, (obj) => { obj.ID = id++; return(true); });

            if (preInitFunction.Count == 1)
            {
                var template = new Template(null, -1, -1, "");
                template.vtoList.Add(Compiler.InternalObjectVarTypes.VT_object);
                var arrayVto = new VarTypeObject(new Ident(null, "array", -1, -1, ""), template);

                oosClass.GlobalClassRegisterVariable               = new Variable(preInitFunction[0].Parent, -1, -1, "");
                oosClass.GlobalClassRegisterVariable.Name          = new Ident(oosClass.GlobalClassRegisterVariable, "ClassRegisterVariable_____", -1, -1, "");
                oosClass.GlobalClassRegisterVariable.varType       = arrayVto;
                oosClass.GlobalClassRegisterVariable.encapsulation = Encapsulation.Static;

                oosInterface.GlobalInterfaceRegisterVariable               = new Variable(preInitFunction[0].Parent, -1, -1, "");
                oosInterface.GlobalInterfaceRegisterVariable.Name          = new Ident(oosInterface.GlobalInterfaceRegisterVariable, "InterfaceRegisterVariable_____", -1, -1, "");
                oosInterface.GlobalInterfaceRegisterVariable.varType       = arrayVto;
                oosInterface.GlobalInterfaceRegisterVariable.encapsulation = Encapsulation.Static;
            }
            errCount += parser.BaseObject.finalize();
            if (errCount > 0)
            {
                Logger.Instance.log(Logger.LogLevel.ERROR, "Errors found (" + errCount + "), cannot continue with Compiling!");
                return;
            }
            SqfConfigFile configFile = new SqfConfigFile(configFileName);

            oosTreeBase.writeOut(null, configFile);
            if (addFunctionsClass)
            {
                configFile.addParentalClass("CfgFunctions");
            }
            configFile.writeOut(proj.OutputFolder);
            handleRessources();
        }