Exemplo n.º 1
0
        private void PreprocessorCommand(string line, ref int lineNumber, Stack <bool> include, TextReader reader,
                                         IDefineCollection defcol, string currentFile)
        {
            string newLine;

            while (line.EndsWith("/") && (newLine = reader.ReadLine()) != null)
            {
                line = line.Substring(0, line.Length - 1) + newLine.Trim();
            }

            if (line.StartsWith(ifDefined))
            {
            }
            else if (line.StartsWith(ifNotDefined))
            {
            }
            else if (line.StartsWith(ifElse))
            {
            }
            else if (line.StartsWith(ifEnd))
            {
            }
            else if (include.And())
            {
            }
        }
Exemplo n.º 2
0
        private void Preprocess(TextReader reader, StringBuilder output,
                                IDefineCollection defcol, string currentFile, Stack <bool> includeStack)
        {
            int    lineNumber = 1;
            string line;
            bool   blockComment = true;

            while ((line = reader.ReadLine()) != null)
            {
                line = line.Trim();
                if (line.Length > 0)
                {
                    //TOFIX?: Handling comments in unincluded lines is extra work.
                    HandleComments(ref line, ref blockComment);
                    if (line.Length > 0)
                    {
                        if (line[0] == '#')
                        {
                            PreprocessorCommand(line, ref lineNumber, includeStack, reader, defcol, currentFile);
                        }
                        else if (includeStack.And())
                        {
                            ApplyDefines(ref line, lineNumber, currentFile, defcol);
                            output.AppendLine(line);
                        }
                    }
                }
                lineNumber++;
            }

            throw new NotImplementedException();
        }
Exemplo n.º 3
0
        public Preprocessor(ILog messageLog /*, string outputFile*/)
        {
            this.messageLog        = messageLog;
            this.predefined        = new List <string>();
            this.reserved          = new List <string>();
            this.pool              = new Pool();
            this.curLine           = new CurrentLine();
            this.curFile           = new CurrentFile();
            this.blockCommentDepth = 0;
            DefineCollectionOptimized collectionOptimized = new DefineCollectionOptimized();

            collectionOptimized["IsDefined"]     = (IMacro) new IsDefined((IDefineCollection)collectionOptimized);
            collectionOptimized["DeconstVector"] = (IMacro) new DeconstructVector();
            collectionOptimized["ConstVector"]   = (IMacro) new BuildVector();
            collectionOptimized["ToParameters"]  = (IMacro) new VectorToParameter();
            collectionOptimized["Signum"]        = (IMacro) new Signum();
            collectionOptimized["Switch"]        = (IMacro) new Switch();
            collectionOptimized["String"]        = (IMacro) new InsertText();
            collectionOptimized["AddToPool"]     = (IMacro)this.pool;
            collectionOptimized["_line_"]        = (IMacro)this.curLine;
            collectionOptimized["_file_"]        = (IMacro)this.curFile;
            //collectionOptimized["_rom_"] = (IMacro) outputFile;

            this.defCol = (IDefineCollection)collectionOptimized;

            this.include = new Stack <bool>();
            this.include.Push(true);

            this.includeListener = new DummyIncludeListener();

            this.directives = ((IEnumerable <IDirective>) new IDirective[14] {
                (IDirective) new IfDefined(),
                (IDirective) new IfNotDefined(),
                (IDirective) new Define(),
                (IDirective) new DumpPool(),
                (IDirective) new Else(),
                (IDirective) new EndIf(),
                (IDirective) new Include(),
                (IDirective) new IncludeBinary(),
                (IDirective) new Undefine(),
                (IDirective) new IncludeToolEvent(),
                (IDirective) new IncludeToolEventAlias(),
                (IDirective) new IncludeToolBinary(),
                (IDirective) new RunTool(),
                (IDirective) new EasterEgg()
            }).GetDictionary <string, IDirective>();
        }
Exemplo n.º 4
0
 public static void DefineFile(string path, IDefineCollection defCol)
 {
     StreamReader sr = new StreamReader(path);
     while (!sr.EndOfStream)
     {
         string line = sr.ReadLine();
         if (line.Length > 0)
         {
             string[] dividedLine = null;// = line.Split(parameterSplitCharacters, parameterUniterCharacters);
             for (int i = 1; i < dividedLine.Length; i++)
             {
                 defCol.Add(dividedLine[i], dividedLine[0]);
             }
         }
     }
     sr.Close();
 }
Exemplo n.º 5
0
        public static void DefineFile(string path, IDefineCollection defCol)
        {
            StreamReader streamReader = new StreamReader(path);

            while (!streamReader.EndOfStream)
            {
                if (streamReader.ReadLine().Length > 0)
                {
                    string[] strArray = (string[])null;

                    for (int index = 1; index < strArray.Length; ++index)
                    {
                        defCol.Add(strArray [index], strArray [0]);
                    }
                }
            }

            streamReader.Close();
        }
Exemplo n.º 6
0
        public string Process(string path)
        {
            defCol  = new DefineCollection();
            output  = new StringBuilder(1000);
            include = new Stack <bool>();

            string text = File.ReadAllText(path);

            text = ReplaceComments(text);

            include.Push(true);
            using (StringReader reader = new StringReader(text))
            {
                Preprocess(reader, Path.GetFullPath(path));
            }
            output.Replace(';', '\n');

            return(output.ToString());
        }
        public string Process(string path)
        {
            defCol = new DefineCollection();
            output = new StringBuilder(1000);
            include = new Stack<bool>();

            string text = File.ReadAllText(path);

            text = ReplaceComments(text);

            include.Push(true);
            using (StringReader reader = new StringReader(text))
            {
                Preprocess(reader, Path.GetFullPath(path));
            }
            output.Replace(';', '\n');

            return output.ToString();
        }
        public Preprocessor(ILog messageLog)
        {
            this.messageLog = messageLog;
            this.predefined = new List<string>();
            this.reserved = new List<string>();
            this.pool = new Pool();
            this.curLine = new CurrentLine();
            this.curFile = new CurrentFile();
            this.blockCommentDepth = 0;

            var defColOpt = new DefineCollectionOptimized();
            defColOpt["IsDefined"] = new IsDefined(defColOpt);
            defColOpt["DeconstVector"] = new DeconstructVector();
            defColOpt["ConstVector"] = new BuildVector();
            defColOpt["ToParameters"] = new VectorToParameter();
            defColOpt["Signum"] = new Signum();
            defColOpt["Switch"] = new Switch();
            defColOpt["String"] = new InsertText();
            defColOpt["AddToPool"] = pool;
            defColOpt["_line_"] = curLine;
            defColOpt["_file_"] = curFile;
            defCol = defColOpt;

            this.include = new Stack<bool>();
            this.include.Push(true);

            directives = (new IDirective[] {
                new IfDefined(),
                new IfNotDefined(),
                new Define(),
                new DumpPool(),
                new Else(),
                new EndIf(),
                new Include(),
                new IncludeBinary(),
                new Undefine()
            }).GetDictionary<string, IDirective>();
        }
Exemplo n.º 9
0
 public IsDefined(IDefineCollection defCol)
 {
     this.defCol = defCol;
 }
Exemplo n.º 10
0
 private void ApplyDefines(ref string text, int lineNumber, string file, IDefineCollection defCol)
 {
     defCol.ApplyDefines(text, out text);
     text = text.Replace(Preprocessor.lineNumber, lineNumber.ToString());
     text = text.Replace(Preprocessor.fileName, "\"" + file + "\"");
 }
        private void PreprocessorCommand(string line, ref int lineNumber, Stack<bool> include, TextReader reader, 
            IDefineCollection defcol, string currentFile)
        {
            string newLine;
            while (line.EndsWith("/") && (newLine = reader.ReadLine()) != null)
            {
                line = line.Substring(0, line.Length - 1) + newLine.Trim();
            }

            if (line.StartsWith(ifDefined))
            {

            }
            else if (line.StartsWith(ifNotDefined))
            {

            }
            else if (line.StartsWith(ifElse))
            {

            }
            else if (line.StartsWith(ifEnd))
            {

            }
            else if (include.And())
            {

            }
        }
        private void Preprocess(TextReader reader, StringBuilder output, 
            IDefineCollection defcol, string currentFile, Stack<bool> includeStack)
        {
            int lineNumber = 1;
            string line;
            bool blockComment = true;

            while ((line = reader.ReadLine()) != null)
            {
                line = line.Trim();
                if (line.Length > 0)
                {
                    //TOFIX?: Handling comments in unincluded lines is extra work.
                    HandleComments(ref line, ref blockComment);
                    if (line.Length > 0)
                    {
                        if (line[0] == '#')
                        {
                            PreprocessorCommand(line, ref lineNumber, includeStack, reader, defcol, currentFile);
                        }
                        else if (includeStack.And())
                        {
                            ApplyDefines(ref line, lineNumber, currentFile, defcol);
                            output.AppendLine(line);
                        }
                    }
                }
                lineNumber++;
            }

            throw new NotImplementedException();
        }
 private void ApplyDefines(ref string text, int lineNumber, string file, IDefineCollection defCol)
 {
     defCol.ApplyDefines(text, out text);
     text = text.Replace(Preprocessor.lineNumber, lineNumber.ToString());
     text = text.Replace(Preprocessor.fileName, "\"" + file + "\"");
 }