Exemplo n.º 1
0
        public static void AddExplicitCastAtPosition(CleanupAstNodeStates states, string typeName, int positionCast)
        {
            var explicitCastList = new List<ParseNode>
                {
                    TokenKind.OpenParen.BuildTokenFromId(),
                    TokenKind.TypeName.BuildTokenFromId(typeName),
                    TokenKind.CloseParen.BuildTokenFromId()
                };

            states.InsertRange(positionCast, explicitCastList);
        }
Exemplo n.º 2
0
        public static void SetRequiredParen(CleanupAstNodeStates states)
        {
            for (var i = 2; i < states.Count; i++)
            {
                var closeToken = states[i];
                if (closeToken.Token != TokenKind.CloseSquared)
                    continue;
                var openToken = states[i];
                if (openToken.Token != TokenKind.OpenSquared)
                    continue;
                closeToken.Token = TokenKind.Comma;
                closeToken.Content = ",";
            }
            for (var i = states.Count - 1; i > 0; i--)
            {
                var openToken = states[i];
                if (openToken.Token != TokenKind.OpenSquared)
                    continue;

                var idToken = states[i - 1];
                if (idToken.Token != TokenKind.Identifier)
                    continue;
                var closeTokenId = states.GetNextMachingTokenKind(TokenKind.CloseSquared, TokenKind.OpenSquared, i);

                var toAdd = new List<ParseNode>();
                for (var addRange = i; addRange <= closeTokenId; addRange++)
                {
                    toAdd.Add(states[addRange].Clone());
                }
                states.InsertRange(i - 1, toAdd);
                i += toAdd.Count;

                closeTokenId = states.GetNextMachingTokenKind(TokenKind.CloseSquared, TokenKind.OpenSquared, i);
                states.RemoveRange(i, closeTokenId);
            }
        }
Exemplo n.º 3
0
        public static void SetRequiredParen(CleanupAstNodeStates states)
        {
            var openSquarePos = states.MappedNodes.GeNextTokenKind(TokenKind.OpenSquared);
            var closeSquarePos = states.MappedNodes.GeNextTokenKind(TokenKind.CloseSquared);
            var commaPos = states.MappedNodes.GeNextTokenKind(TokenKind.Comma);

            if (openSquarePos + 1 == closeSquarePos || openSquarePos + 1 == commaPos)
            {
                states.Insert(openSquarePos + 1, TokenKind.Int.BuildTokenFromId("0"));
                states.Remap();
            }
            if (commaPos + 1 == closeSquarePos)
            {
                states.Insert(commaPos + 1, TokenKind.Int.BuildTokenFromId("0"));
                states.Remap();
            }

            var tokenData = states[0].GetTokenData();
            var typeToken = tokenData.Clone();


            var assignPos = states.GeNextTokenKind(TokenKind.Assign);
            if (assignPos > 0)
            {
                var openSquaredPos = states.GeNextTokenKind(TokenKind.OpenSquared);
                if (openSquaredPos > assignPos)
                    return;
            }
            var nodesToBeAdded = new List<ParseNode>
                {
                    TokenKind.Assign.BuildTokenFromId(),
                    TokenKind.Space.BuildTokenFromId(" "),
                    TokenKind.New.BuildTokenFromId(),
                    TokenKind.Space.BuildTokenFromId(" "),
                    typeToken.BuildTerminalNode(),
                };
            states.InsertRange(2, nodesToBeAdded);

            var countSquared = states.Count(node => node.GetTokenKind() == TokenKind.Comma) + 1;

            var toAdd = BuildSquaresAndCommas(countSquared);
            states.InsertRange(1, toAdd);
        }
Exemplo n.º 4
0
 static void AddExplicitCastToDouble(CleanupAstNodeStates blockStates, int startRange)
 {
     var addTokens = new List<ParseNode>
         {
             TokenKind.OpenParen.BuildTokenFromId(),
             TokenKind.TypeName.BuildTokenFromId("double"),
             TokenKind.CloseParen.BuildTokenFromId(),
         };
     blockStates.InsertRange(startRange, addTokens);
 }
Exemplo n.º 5
0
        static void AddExplicitCastIntToString(CleanupAstNodeStates blockStates, int startRange, bool isFunction)
        {
            int insertPos;
            if (!isFunction)
                insertPos = startRange + 1;
            else
                insertPos = blockStates.GetNextMachingTokenKind(TokenKind.CloseParen, TokenKind.OpenParen, startRange) + 1;
            var addTokens = new List<ParseNode>
                {
                    TokenKind.Dot.BuildTokenFromId(),
                    TokenKind.Identifier.BuildTokenFromId("ConvStr"),
                    TokenKind.OpenParen.BuildTokenFromId(),
                    TokenKind.CloseParen.BuildTokenFromId(),
                };

            blockStates.InsertRange(insertPos, addTokens);
        }
Exemplo n.º 6
0
 void FixCharAsInt(CleanupAstNodeStates states, string value, int constantPosition)
 {
     states[constantPosition].Token = TokenKind.Int;
     states[constantPosition].Content = ((int)value[1]).ConvStr();
     var toAdd = new List<ParseNode>
         {
             TokenKind.OpenParen.BuildTokenFromId(),
             TokenKind.Identifier.BuildTokenFromId(string.Format("/*\'{0}\'*/",value) ),
             TokenKind.CloseParen.BuildTokenFromId(),
         };
     states.InsertRange(constantPosition, toAdd);
 }
Exemplo n.º 7
0
 public static void AddCastCall(CleanupAstNodeStates states, string convFunction, int tokenToInsert)
 {
     var toAdd = new List<ParseNode>
         {
             TokenKind.Dot.BuildTokenFromId(),
             TokenKind.Identifier.BuildTokenFromId(convFunction),
             TokenKind.OpenParen.BuildTokenFromId(),
             TokenKind.CloseParen.BuildTokenFromId(),
         };
     states.InsertRange(tokenToInsert, toAdd);
 }