Example #1
0
        static void EvaluateAssign(ParseNode node, Dictionary<string, TypeData> variableTypes)
        {
            var states = node.Parent.States;

            var assign = states.MappedNodes.IndexOf(node);
            var leftToken = states[assign - 1].GetTokenData();
            var rightToken = states[assign + 1].GetTokenData();
            if (leftToken.Token != TokenKind.Identifier)
                return;
            if (rightToken.Token != TokenKind.Identifier)
                return;
            var leftVariableName = leftToken.Content;
            var leftExpression = variableTypes.GetTypeOfName(leftVariableName);
            var rightVariableName = rightToken.Content;
            var rightExpression = variableTypes.GetTypeOfName(rightVariableName);
            if (leftExpression.Count == 0 || rightExpression.Count == 0)
                return;
            if (leftExpression.Equals(rightExpression))
                return;
            var leftTypeName = leftExpression[0].Content;
            var rightTypeName = rightExpression[0].Content;

            //we don't handle arrays or other complex types
            if (leftExpression.TokenList.Count != 1 || rightExpression.TokenList.Count != 1)
                return;
            var conversionTypes = string.Format("{0}={1}", leftTypeName, rightTypeName);
            HandleConversions(conversionTypes, states, leftTypeName, assign);
        }
Example #2
0
 static void TryHandleParameter(TypeData[] fnParams, int i,
     CleanupAstNodeStates blockStates,
     int startRange, int endRange,
     Dictionary<string, TypeData> declarations)
 {
     var isFunction = blockStates[startRange + 1].Token == TokenKind.OpenParen;
     var typeArgument = fnParams[i];
     var tmp = typeArgument.Count != 1;
     if (tmp)
         return;
     var argumentType = typeArgument[0].Content;
     if (argumentType == TypeNames.Unknown)
         return;
     var token = blockStates[startRange];
     var typeOfParam = declarations.GetTypeOfName(token.Content);
     if (typeOfParam == null || typeOfParam.Count != 1)
         return;
     var paramType = typeOfParam[0].Content;
     if (paramType == argumentType)
         return;
     if (!isFunction && endRange != startRange)
         return;
     var formatTypes = string.Format("{0}={1}", paramType, argumentType);
     FixArgumentType(blockStates, startRange, isFunction, formatTypes);
 }