Example #1
0
 private List <object> parseInclude(PreprocessorDirective dir)
 {
     if (dir.Operands.Count != 1 && !(dir.Operands[0] is TokenStringLiteral))
     {
         return(new List <object>());
     }
     else
     {
         TokenStringLiteral sl     = dir.Operands[0] as TokenStringLiteral;
         string             source = File.ReadAllText(sl.Value);
         Lexer lex = new Lexer(source);
         lex.Scan();
         Parser parser = new Parser();
         parser.ProcessTokens(lex.TokenList);
         return(parser.instructions);
     }
 }
Example #2
0
        protected override void InnerRun()
        {
            ParseError        parseError;
            List <SourceLine> lines = PreprocessorDirective.RecursiveParse(source.BaseFilename,
                                                                           source.WorkingDirectory, out parseError, BasePrepareLines,
                                                                           source.Machine.UserDefinedDefines, source.Machine.Cache);

            source._lines = lines;

            if (parseError != null)
            {
                InnerEnd(parseError);
            }
            else
            {
                InnerEnd();
            }
        }
Example #3
0
 internal static void preprocessor_directive_active <TDirective>(this TextWriter trapFile,
                                                                 PreprocessorDirective <TDirective> directive, bool isActive)
     where TDirective : DirectiveTriviaSyntax
 {
     trapFile.WriteTuple("preprocessor_directive_active", directive, isActive ? 1 : 0);
 }
Example #4
0
 internal static void preprocessor_directive_compilation <TDirective>(this TextWriter trapFile,
                                                                      PreprocessorDirective <TDirective> directive, Compilation compilation)
     where TDirective : DirectiveTriviaSyntax
 {
     trapFile.WriteTuple("preprocessor_directive_compilation", directive, compilation);
 }
 private void SetPreprocessorDirective(bool enable)
 {
     PreprocessorDirective.Set(directive, !enable, BuildTargetGroup.Android);
     PreprocessorDirective.Set(directive, !enable, BuildTargetGroup.iOS);
 }
Example #6
0
 internal static void preprocessor_directive_location <TDirective>(this TextWriter trapFile,
                                                                   PreprocessorDirective <TDirective> directive, Location location)
     where TDirective : DirectiveTriviaSyntax =>
 trapFile.WriteTuple("preprocessor_directive_location", directive, location);
Example #7
0
        public void ProcessTokens(IList <AbstractToken> tokens)
        {
            position    = 0;
            this.tokens = tokens;
            while (position < tokens.Count)
            {
                while (position < tokens.Count && (peekToken() is TokenEOL))
                {
                    readToken();
                }
                if (position < tokens.Count)
                {
                    if (peekToken(1) is TokenColon && peekToken(0) is TokenIdentifier)
                    {
                        parseLabel();
                    }
                    else if (peekToken() is TokenHash)
                    {
                        readToken();
                        parseSingleDirective();
                    }
                    else
                    {
                        parseSingleInstruction();
                    }
                }
            }
            string        globalScope     = "";
            List <object> newInstructions = new List <object>();

            foreach (object o in this.instructions)
            {
                if (o is Instruction)
                {
                    Instruction ins = o as Instruction;
                    foreach (AbstractToken token in ins.Operands)
                    {
                        if (token is TokenIdentifier)
                        {
                            TokenIdentifier ident = token as TokenIdentifier;
                            if (ident.Value.StartsWith("."))
                            {
                                ident.Value = globalScope + ident.Value;
                            }
                        }
                    }
                }
                else if (o is Label)
                {
                    Label l = o as Label;
                    if (l.Name.StartsWith("."))
                    {
                        l.Name = globalScope + l.Name;
                    }
                    else
                    {
                        globalScope = l.Name;
                    }
                }
                if (o is PreprocessorDirective)
                {
                    PreprocessorDirective dir = o as PreprocessorDirective;
                    switch (dir.Name)
                    {
                    case "include":
                        newInstructions.AddRange(parseInclude(dir));
                        break;
                    }
                }
                else
                {
                    newInstructions.Add(o);
                }
            }

            this.instructions = newInstructions;
        }