Esempio n. 1
0
        public PreprocessorContext(ParseContext pc, SymbolLookup symbols)
        {
            Symbols = symbols;
            parseContext = pc;
            inComment = false;

            InitAtomTable();
            InitScanner();

            ifdepth = 0;
            elseSeen = new bool[MAXIFNESTING];
            for (elsetracker = 0; elsetracker < MAXIFNESTING; elsetracker++)
                elseSeen[elsetracker] = false;
            elsetracker = 0;

            inputStack = new Stack<BasePreprocessorInput> ();

            buffer = new StringInputBuffer{ name = new char[StringInputBuffer.MAX_TOKEN_LENGTH], tokenText = new char[StringInputBuffer.MAX_TOKEN_LENGTH]};
        }
Esempio n. 2
0
        ///////////////////////////////////////////////////////////////////////////////////////////////
        /////////////////////////////////// Floating point constants: /////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////////
        /*

        */
        /// <summary>
        ///  Scan a single- or double-precision floating point constant.  Assumes that the scanner
        /// has seen at least one digit, followed by either a decimal '.' or the
        /// letter 'e', or a precision ending (e.g., F or LF).  
        /// </summary>
        /// <returns>The float const.</returns>
        /// <param name="len">Length.</param>
        /// <param name="ch">Ch.</param>
        /// <param name="ppToken">Pp token.</param>
        internal int lFloatConst(StringInputBuffer buffer, int len, int ch, PreprocessorToken ppToken)
        {
            bool HasDecimalOrExponent = false;
            int declen, exp, ExpSign;
            int str_len;
            bool isDouble = false;

            declen = 0;
            exp = 0;

            const int MAX_TOKEN_LENGTH = 1024;

            str_len=len;
            char[] str =  buffer.name;
            if (ch == '.') {
                HasDecimalOrExponent = true;
                str[len++] = (char)ch;
                ch = getChar();
                while (ch >= '0' && ch <= '9')
                {
                    if (len < MAX_TOKEN_LENGTH)
                    {
                        declen++;
                        if (len > 0 || ch != '0') {
                            str[len] = (char)ch;
                            len++;
                            str_len++;
                        }
                        ch = getChar();
                    }
                    else
                    {
                        parseContext.Error( ppToken.loc, "float literal too long", "", "");
                        len = 1;
                        str_len = 1;
                    }
                }
            }

            // Exponent:

            if (ch == 'e' || ch == 'E')
            {
                HasDecimalOrExponent = true;
                if (len >= MAX_TOKEN_LENGTH)
                {
                    parseContext.Error( ppToken.loc, "float literal too long", "", "");
                    len = 1;
                    str_len=1;
                }
                else
                {
                    ExpSign = 1;
                    str[len++] = (char)ch;
                    ch = getChar();
                    if (ch == '+')
                    {
                        str[len++] = (char)ch;
                        ch = getChar();
                    }
                    else if (ch == '-')
                    {
                        ExpSign = -1;
                        str[len++] = (char)ch;
                        ch = getChar();
                    }
                    if (ch >= '0' && ch <= '9')
                    {
                        while (ch >= '0' && ch <= '9')
                        {
                            if (len < MAX_TOKEN_LENGTH)
                            {
                                exp = exp*10 + ch - '0';
                                str[len++] = (char)ch;
                                ch = getChar();
                            }
                            else
                            {
                                parseContext.Error( ppToken.loc, "float literal too long", "", "");
                                len = 1;
                                str_len=1;
                            }
                        }
                    }
                    else
                    {
                        parseContext.Error( ppToken.loc, "bad character in float exponent", "", "");
                    }
                    exp *= ExpSign;
                }
            }

            if (len == 0)
            {
                ppToken.dval = 0.0;
                str = "0.0".ToCharArray();
            }
            else
            {
                if (ch == 'l' || ch == 'L')
                {
                    parseContext.doubleCheck( ppToken.loc, "double floating-point suffix");
                    if (! HasDecimalOrExponent)
                        parseContext.Error( ppToken.loc, "float literal needs a decimal point or exponent", "", "");
                    int ch2 = getChar();
                    if (ch2 != 'f' && ch2 != 'F')
                    {
                        ungetChar();
                        ungetChar();
                    }
                    else
                    {
                        if (len < MAX_TOKEN_LENGTH)
                        {
                            str[len++] = (char)ch;
                            str[len++] = (char)ch2;
                            isDouble = true;
                        }
                        else
                        {
                            parseContext.Error( ppToken.loc, "float literal too long", "", "");
                            len = 1;
                            str_len=1;
                        }
                    }
                }
                else if (ch == 'f' || ch == 'F')
                {
                    parseContext.ProfileRequires( ppToken.loc,  Profile.EsProfile, 300, null, "floating-point suffix");
                    if ((parseContext.messages &  MessageType.RelaxedErrors) == 0)
                        parseContext.ProfileRequires (ppToken.loc, (Profile)~Profile.EsProfile, 120, null, "floating-point suffix");
                    if (! HasDecimalOrExponent)
                        parseContext.Error( ppToken.loc, "float literal needs a decimal point or exponent", "", "");
                    if (len < MAX_TOKEN_LENGTH)
                        str[len++] = (char)ch;
                    else
                    {
                        parseContext.Error( ppToken.loc, "float literal too long", "", "");
                        len = 1;
                        str_len=1;
                    }
                } else
                    ungetChar();

                //str[len]='\0';

                ppToken.dval = Double.Parse(new string(str));
            }

            if (isDouble)
                return (int) CppEnums.DOUBLECONSTANT;
            else
                return (int) CppEnums.FLOATCONSTANT;
        }