Example #1
0
        private SortedDictionary <int, Tuple <int, IMacro, string[]> > FindMacros(StringBuilder s)
        {
            var replace =
                new SortedDictionary <int, Tuple <int, IMacro, string[]> >(
                    ReverseComparer <int> .Default
                    );

            StringBuilder macroName = new StringBuilder();

            for (int i = 0; i < s.Length;)
            {
                if (DefineCollectionOptimized.IsValidCharacter(s[i]))
                {
                    macroName.Append(s[i]);
                    i++;
                }
                else
                {
                    if (macroName.Length > 0)
                    {
                        GetMacroData(s, replace, ref i, macroName.ToString());
                        macroName.Clear();
                    }
                    else
                    {
                        i++;
                    }
                }
            }
            int last = s.Length;

            GetMacroData(s, replace, ref last, macroName.ToString());
            return(replace);
        }
Example #2
0
        private SortedDictionary <int, Tuple <int, IMacro, string[]> > FindMacros(StringBuilder s)
        {
            SortedDictionary <int, Tuple <int, IMacro, string[]> > replace = new SortedDictionary <int, Tuple <int, IMacro, string[]> >(ReverseComparer <int> .Default);
            StringBuilder stringBuilder = new StringBuilder();
            int           i             = 0;
            bool          inQuotes      = false;

            while (i < s.Length)
            {
                if (s[i] == '"')
                {
                    inQuotes = !inQuotes;
                    ++i;
                }
                else if (inQuotes || DefineCollectionOptimized.IsValidCharacter(s[i]))
                {
                    stringBuilder.Append(s[i]);
                    ++i;
                }
                else if (stringBuilder.Length > 0)
                {
                    this.GetMacroData(s, replace, ref i, stringBuilder.ToString());
                    stringBuilder.Clear();
                }
                else
                {
                    ++i;
                }
            }
            int length = s.Length;

            this.GetMacroData(s, replace, ref length, stringBuilder.ToString());
            return(replace);
        }
        private void FindString(string s, IDictionary <int, string> containedOriginals, string toFind)
        {
            int index = s.IndexOf(toFind);

            while (index >= 0)// && index + original.Length < s.Length && s[index - 1]
            {
                bool can1;
                if (index > 0)
                {
                    char c = s[index - 1];
                    can1 = !DefineCollectionOptimized.IsValidCharacter(c);
                }
                else
                {
                    can1 = true; //in the beginning of the line
                }
                bool can2;
                if (index + toFind.Length < s.Length)
                {
                    char c = s[index + toFind.Length];
                    can2 = !DefineCollectionOptimized.IsValidCharacter(c);
                }
                else
                {
                    can2 = true; //in the end of the line
                }
                if (can1 && can2 && !containedOriginals.ContainsKey(index))
                {
                    containedOriginals[index] = toFind;
                    break;
                }
                index = s.IndexOf(toFind, index + 1);
            }
        }
 private void FindString(string s, IDictionary <int, string> containedOriginals, string toFind)
 {
     for (int key = s.IndexOf(toFind); key >= 0; key = s.IndexOf(toFind, key + 1))
     {
         if ((key <= 0 || !DefineCollectionOptimized.IsValidCharacter(s[key - 1])) && (key + toFind.Length >= s.Length || !DefineCollectionOptimized.IsValidCharacter(s[key + toFind.Length])) && !containedOriginals.ContainsKey(key))
         {
             containedOriginals[key] = toFind;
             break;
         }
     }
 }
Example #5
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>();
        }
        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>();
        }