Пример #1
0
        public override string outputXML(int level)
        {
            string output = "";

            SimionSrcParser.addIndentation(ref output, level);
            output += "<" + XMLTags.ClassDefinitionNodeTag + " Name=\"" + m_name + "\"";
            if (m_world != null)
            {
                output += " " + XMLTags.worldAttribute + "=\"" + m_world + "\"";
            }
            output += ">\n";

            foreach (string baseClass in m_baseClasses)
            {
                ParameterizedObject baseClassObject = SimionSrcParser.getNamedParamObject(baseClass);
                if (baseClassObject != null)
                {
                    foreach (IParameter param in baseClassObject.parameters)
                    {
                        base.addParameter(param);//output += baseClassObject.outputChildrenXML(level + 1);
                    }
                }
                else
                {
                    Console.WriteLine("Warning." + m_name + " class extends base class " + baseClass
                                      + " but definition has not been found. Ignore if the base class is a template class without any parameters.");
                }
            }
            output += outputChildrenXML(level + 1);
            SimionSrcParser.addIndentation(ref output, level);
            output += "</" + XMLTags.ClassDefinitionNodeTag + ">\n";
            return(output);
        }
Пример #2
0
        static void Main(string[] args)
        {
            SimionSrcParser sourceProcessor = new SimionSrcParser();
            int numargs = args.GetLength(0);
            if (args.GetLength(0) < 1)
            {
                Console.WriteLine("CustomXMLBuilder ERROR: the directory where the source files are wasn't provided");
                return;
            }
            Console.WriteLine("Running SimionSrcParser " + args[0]);
            string dirPath = args[0];

            //Parse .cpp files for constructor and factory definition
            List<string> sourceFiles = new List<string>(Directory.EnumerateFiles(dirPath, "*.cpp", SearchOption.AllDirectories));
            foreach (var file in sourceFiles)
            {
                sourceProcessor.parseSrcFile(file);
            }
            //Parse .h files for enumerated types
            List<string> headerFiles = new List<string>(Directory.EnumerateFiles(dirPath, "*.h", SearchOption.AllDirectories));
            foreach (var file in headerFiles)
            {
                sourceProcessor.parseHeaderFile(file);
            }

            int numErrors = sourceProcessor.postProcess();

            if (numErrors==0)
            {
                sourceProcessor.saveDefinitions("../config/definitions.xml");

                Console.WriteLine("Source code correctly parsed and XML configuration succesfully built. {0} Kbs of code read.", sourceProcessor.numCharsProcessed / 1000);
            }
        }
Пример #3
0
        public string outputXML(int level)
        {
            string output = "";

            SimionSrcParser.addIndentation(ref output, level);
            string typeTag;

            switch (m_type)
            {
            case WorldParser.WorldParameterType.StateVariable: typeTag = XMLTags.stateVarTag; break;

            case WorldParser.WorldParameterType.ActionVariable: typeTag = XMLTags.actionVarTag; break;

            default: typeTag = XMLTags.constantTag; break;
            }
            output += "<" + typeTag + " " + XMLTags.nameAttribute + "=\"" + m_name + "\"";
            if (m_type != WorldParser.WorldParameterType.Constant)
            {
                output += " " + XMLTags.minValueAttribute
                          + "=\"" + m_min + "\" " + XMLTags.maxValueAttribute + "=\"" + m_max + "\" "
                          + XMLTags.unitAttribute + "=\"" + m_unit + "\"/>\n";
            }
            else
            {
                output += "/>\n";
            }
            return(output);
        }
Пример #4
0
        public string outputXML(int level)
        {
            string output = "";

            SimionSrcParser.addIndentation(ref output, level);
            output += "<" + m_xmlTag + " Name=\"" + m_name + "\" Comment=\"" + m_comment + "\" Default=\""
                      + m_default + "\"/>\n";
            return(output);
        }
Пример #5
0
        public string outputXML(int level)
        {
            string output = "";

            SimionSrcParser.addIndentation(ref output, level);
            output += "<" + XMLTags.multiValuedNodeTag + " " + XMLTags.nameAttribute + "=\"" + m_name
                      + "\" " + XMLTags.classAttribute + "=\"" + m_className + "\" " + XMLTags.commentAttribute
                      + "=\"" + m_comment + "\" " + XMLTags.defaultAttribute + "=\"" + m_default + "\"/>\n";
            return(output);
        }
Пример #6
0
        public override string outputXML(int level)
        {
            string output = "";

            SimionSrcParser.addIndentation(ref output, level);
            output += "<" + XMLTags.ClassDefinitionNodeTag + " Name=\"" + m_name + "\">\n";
            output += outputChildrenXML(level + 1);
            SimionSrcParser.addIndentation(ref output, level);
            output += "</" + XMLTags.ClassDefinitionNodeTag + ">\n";
            return(output);
        }
Пример #7
0
        public string outputXML(int level)
        {
            string output = "";

            SimionSrcParser.addIndentation(ref output, level);
            output += "<" + XMLTags.multiValuedNodeTag + " " + XMLTags.nameAttribute + "=\"" + m_name
                      + "\" " + XMLTags.classAttribute + "=\"" + m_className + "-Factory\" " + XMLTags.commentAttribute
                      + "=\"" + m_comment + "\"";
            if (m_bOptional)
            {
                output += " " + XMLTags.optionalAttribute + "=\"True\"";
            }
            output += "/>\n";
            return(output);
        }
Пример #8
0
        public string outputXML(int level)
        {
            string output = "";

            SimionSrcParser.addIndentation(ref output, level);
            output += "<" + XMLTags.choiceNodeTag + " " + XMLTags.nameAttribute + "=\"" + m_name
                      + "\" " + XMLTags.classAttribute + "=\"" + m_className + "\" " + XMLTags.commentAttribute
                      + "=\"" + m_comment + "\">\n";
            foreach (IParameter parameter in m_parameters)
            {
                output += parameter.outputXML(level + 1);
            }
            SimionSrcParser.addIndentation(ref output, level);
            output += "</" + XMLTags.choiceNodeTag + ">\n";
            return(output);
        }
Пример #9
0
        public override string outputXML(int level)
        {
            string output = "";

            SimionSrcParser.addIndentation(ref output, level);
            output += "<" + XMLTags.EnumDefinitionNodeTag + " " + XMLTags.nameAttribute + "=\"" + m_name + "\">\n";
            output += outputChildrenXML(level + 1);
            foreach (string value in m_enumerationValues)
            {
                SimionSrcParser.addIndentation(ref output, level + 1);
                output += "<" + XMLTags.enumNodeTag + ">" + value + "</" + XMLTags.enumNodeTag + ">\n";
            }
            SimionSrcParser.addIndentation(ref output, level);
            output += "</" + XMLTags.EnumDefinitionNodeTag + ">\n";
            return(output);
        }
Пример #10
0
        public string outputXML(int level)
        {
            string output = "";

            SimionSrcParser.addIndentation(ref output, level);
            if (m_type == VarType.StateVariable)
            {
                output += "<" + XMLConfig.stateVarRefTag;
            }
            else
            {
                output += "<" + XMLConfig.actionVarRefTag;
            }
            output += " " + XMLConfig.nameAttribute + "=\"" + m_name + "\" " + XMLConfig.commentAttribute + "=\""
                      + m_comment + "\"/>\n";
            return(output);
        }
Пример #11
0
        static int Main(string[] args)
        {
            //not to read 23.232 as 23232
            Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;

            SimionSrcParser sourceProcessor = new SimionSrcParser();
            int             numargs         = args.GetLength(0);

            if (args.GetLength(0) < 2)
            {
                Console.WriteLine("ERROR. Usage: SimionSrcParser <input-directory> <output-file>");
                return(0);
            }

            string outputFile = args[1];
            string inputDir   = args[0];

            Console.WriteLine("SimionSrcParser: " + args[0] + "->" + args[1]);

            //Parse .cpp files for constructor and factory definition
            List <string> sourceFiles = new List <string>(Directory.EnumerateFiles(inputDir, "*.cpp", SearchOption.AllDirectories));

            foreach (var file in sourceFiles)
            {
                sourceProcessor.parseSrcFile(file);
            }
            //Parse .h files for enumerated types
            List <string> headerFiles = new List <string>(Directory.EnumerateFiles(inputDir, "*.h", SearchOption.AllDirectories));

            foreach (var file in headerFiles)
            {
                sourceProcessor.parseHeaderFile(file);
            }


            int numErrors = sourceProcessor.postProcess();

            if (numErrors == 0)
            {
                sourceProcessor.saveDefinitions(outputFile);

                Console.WriteLine("Source code correctly parsed and XML configuration succesfully built. {0} Kbs of code read.", sourceProcessor.numCharsProcessed / 1000);
            }
            return(0);
        }
Пример #12
0
        public string outputXML(int level)
        {
            string output = "";

            SimionSrcParser.addIndentation(ref output, level);
            output += "<" + XMLTags.branchNodeTag + " " + XMLTags.nameAttribute + "=\"" + m_name
                      + "\" " + XMLTags.classAttribute + "=\"" + m_className + "\" " + XMLTags.commentAttribute
                      + "=\"" + m_comment + "\"";
            if (m_bOptional)
            {
                output += " " + XMLTags.optionalAttribute + "=\"True\"";
            }
            if (m_badgerMetadata != "")
            {
                output += " " + XMLTags.badgerMetadataAttribute + "=\"" + m_badgerMetadata + "\"";
            }
            output += "/>\n";
            return(output);
        }
Пример #13
0
        static int Main(string[] args)
        {
            //not to read 23.232 as 23232
            Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;

            SimionSrcParser sourceProcessor = new SimionSrcParser();
            int             numargs         = args.GetLength(0);

            if (args.GetLength(0) < 1)
            {
                Console.WriteLine("SimionSrcParser ERROR: the directory where the source files are wasn't provided");
                return(0);
            }
            Console.WriteLine("Running SimionSrcParser " + args[0]);
            string dirPath = args[0];


            //Parse .cpp files for constructor and factory definition
            List <string> sourceFiles = new List <string>(Directory.EnumerateFiles(dirPath, "*.cpp", SearchOption.AllDirectories));

            foreach (var file in sourceFiles)
            {
                sourceProcessor.parseSrcFile(file);
            }
            //Parse .h files for enumerated types
            List <string> headerFiles = new List <string>(Directory.EnumerateFiles(dirPath, "*.h", SearchOption.AllDirectories));

            foreach (var file in headerFiles)
            {
                sourceProcessor.parseHeaderFile(file);
            }


            int numErrors = sourceProcessor.postProcess();

            if (numErrors == 0)
            {
                sourceProcessor.saveDefinitions("../config/definitions.xml");

                Console.WriteLine("Source code correctly parsed and XML configuration succesfully built. {0} Kbs of code read.", sourceProcessor.numCharsProcessed / 1000);
            }
            return(0);
        }
Пример #14
0
        static int Main(string[] args)
        {
            //not to read 23.232 as 23232
            Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;

            if (!ParseArguments(args))
            {
                Console.WriteLine("ERROR. Usage: SimionSrcParser lang=[cpp|csharp] source-dir=<dir> [out-defs=<path-to-xml>]");
                return(0);
            }

            //Create the appropriate parser
            SimionSrcParser parser = null;

            parser = new CppSourceParser();

            foreach (string sourceDir in sourceDirectories)
            {
                parser.ParseSourceFilesInDir(sourceDir);
            }

            int numErrors = parser.PostProcess();

            if (numErrors == 0)
            {
                string inputSourceDirectories = "{ ";
                foreach (string sourceDir in sourceDirectories)
                {
                    inputSourceDirectories += sourceDir + "; ";
                }
                inputSourceDirectories += "}";

                if (outDefinitionsFile != null && parser.GetParameterizedObjects() != null)
                {
                    Console.WriteLine("Saving object definitions for Badger: " + inputSourceDirectories + " ->" + outDefinitionsFile);
                    DocumentationExporter.ExportGUIParameters(outDefinitionsFile, parser.GetParameterizedObjects());
                }

                Console.WriteLine("Finished: {0} Kbs of code read.", parser.GetNumBytesProcessed() / 1000);
            }
            return(0);
        }
Пример #15
0
        public string outputXML(int level)
        {
            string output = "";

            SimionSrcParser.addIndentation(ref output, level);
            string className = m_className;

            if (m_type == Type.Factory)
            {
                className += "-Factory";
            }
            output += "<" + XMLTags.choiceElementNodeTag + " " + XMLTags.nameAttribute + "=\"" + m_name
                      + "\" " + XMLTags.classAttribute + "=\"" + className + "\"";
            if (m_badgerMetadata != null)
            {
                output += " " + XMLTags.badgerMetadataAttribute + "=\"" + m_badgerMetadata + "\"";
            }
            output += "/>\n";

            return(output);
        }
Пример #16
0
        public void parse(ParameterizedObject parent, string srcCode)
        {
            string sPattern = @"CHOICE\s*<\s*(\w+)\s*>\(([^,]+),([^,]+),([^,]+),([^;]*);";

            foreach (Match match in Regex.Matches(srcCode, sPattern))
            {
                string className = match.Groups[1].Value.Trim(' ', '"');
                string choiceName = match.Groups[3].Value.Trim(' ', '"');
                string comment = match.Groups[4].Value.Trim(' ', '"');
                string choiceElements, prefix;
                choiceElements = match.Groups[5].Value.Trim(' ', '"', '\t', '\n');
                SimionSrcParser.getEnclosedBody(match.Groups[5].Value.Trim(' ', '"', '\t', '\n'), 0, "{", "}", out choiceElements, out prefix);
                choiceElements = choiceElements.Trim(' ', '"', '\t', '\n');
                ChoiceParameter newChoice = new ChoiceParameter(className, choiceName, comment);

                foreach (ChoiceElementParser choiceElementParser in m_choiceElementParsers)
                {
                    choiceElementParser.parse(choiceElements, newChoice);
                }

                parent.addParameter(newChoice);
            }
        }