Esempio n. 1
0
 internal TokenInput(PreprocessorContext pp, TokenStream t)
     : base(pp)
 {
     tokens = t;
 }
Esempio n. 2
0
 internal void pushTokenStreamInput(TokenStream ts)
 {
     pushInput(new TokenInput(this, ts));
     ts.Rewind();
 }
Esempio n. 3
0
        ///*
        //* Read the next token from a token stream (not the source stream, but stream used to hold a tokenized macro).
        //*/
        internal int ReadToken(TokenStream pTok, PreprocessorToken ppToken)
        {
            char[] tokenText = buffer.tokenText;
            int ltoken = 0;
            int len = 0;
            int ch;

            ltoken = pTok.lReadByte();
            ppToken.loc = parseContext.getCurrentLoc();
            if (ltoken > 127)
                ltoken += 128;
            switch (ltoken)
            {
                case '#':
                    if (pTok.lReadByte() == '#') {
                        parseContext.requireProfile(ppToken.loc, ~Profile.EsProfile, "token pasting (##)");
                        parseContext.ProfileRequires(ppToken.loc, ~Profile.EsProfile, 130, null, "token pasting (##)");
                        parseContext.Error(ppToken.loc, "token pasting not implemented (internal error)", "##", "");
                        //return CPP_TOKEN_PASTE;
                        return ReadToken(pTok, ppToken);
                    } else
                        pTok.lUnreadByte();
                    break;
                case (int) CppEnums.STRCONSTANT:
                case (int) CppEnums.IDENTIFIER:
                case (int) CppEnums.FLOATCONSTANT:
                case (int) CppEnums.DOUBLECONSTANT:
                case (int) CppEnums.INTCONSTANT:
                case (int) CppEnums.UINTCONSTANT:
                    len = 0;
                ch = pTok.lReadByte ();
                    while (ch != 0)
                    {
                        if (len < PreprocessorToken.maxTokenLength)
                        {
                            tokenText [len] = (char)ch;
                            len++;
                        ch = pTok.lReadByte();
                        } else
                        {
                            parseContext.Error (ppToken.loc, "token too long", "", "");
                            break;
                        }
                    }
                    break;
                default:
                    break;
            }

            // DY RESTRUCTURED CODE
            //tokenText[len] = 0;

            string text = new string (tokenText, 0, len);
            switch (ltoken)
            {
                case (int) CppEnums.IDENTIFIER:
                case (int) CppEnums.STRCONSTANT:
                    ppToken.atom = Symbols.Atoms.LookUpAddString(text);
                    break;
                case (int) CppEnums.FLOATCONSTANT:
                case (int) CppEnums.DOUBLECONSTANT:
                    ppToken.name = text;
                    ppToken.dval = float.Parse(ppToken.name);
                    break;
                case (int) CppEnums.INTCONSTANT:
                case (int) CppEnums.UINTCONSTANT:
                    ppToken.name = text;
                    len = text.Length;
                    if (len > 0 && tokenText[0] == '0') {
                        if (len > 1 && (tokenText[1] == 'x' || tokenText[1] == 'X'))
                            ppToken.ival = Convert.ToInt32(ppToken.name, 16);
                        else
                            ppToken.ival = Convert.ToInt32(ppToken.name, 8);
                    } else
                        ppToken.ival = int.Parse(ppToken.name);
                    break;
                default:
                    break;
            }

            return ltoken;
        }
Esempio n. 4
0
        internal TokenStream PrescanMacroArg(TokenStream a, PreprocessorToken ppToken, bool newLineOkay)
        {
            int token;
            a.Rewind();
            do {
                token = ReadToken(a, ppToken);
                if (token == (int) CppEnums.IDENTIFIER && Symbols.LookUp(ppToken.atom) != null)
                    break;
            } while (token != BasePreprocessorInput.END_OF_INPUT);

            if (token == BasePreprocessorInput.END_OF_INPUT)
                return a;

            TokenStream n = new TokenStream ();
            pushInput(new MarkerInput(this));
            pushTokenStreamInput(a);
            while ((token = scanToken(ref ppToken)) != MarkerInput.marker) {
                if (token == (int) CppEnums.IDENTIFIER && MacroExpand(ppToken.atom, ppToken, false, newLineOkay) != 0)
                    continue;
                Symbols.Atoms.RecordToken(n, token, ppToken);
            }
            popInput();

            return n;
        }