Exemplo n.º 1
0
 void HandleCastOnParameters(ParseNode identifier, TypeParameterTable functionData, int index,
                                     CleanupAstNodeStates states)
 {
     var rightType = _declarations.GetTypeOfName(identifier.GetTokenContent());
     var leftTypeName = functionData[index].TokenList[0].Content;
     if (rightType == null || rightType.TokenList.Count == 0)
         return;
     var rightTypeName = rightType[0].Content;
     if (rightTypeName == leftTypeName)
         return;
     if (rightTypeName == TypeNames.Unknown)
         return;
     if (leftTypeName == TypeNames.Unknown)
         return;
     var conversionTypes = string.Format("{0}={1}", leftTypeName, rightTypeName);
     switch (conversionTypes)
     {
         case "int=double":
             SemanticAnalysisUtils.AddExplicitCastAtPosition(states, leftTypeName, states.IndexOf(identifier));
             break;
         //nothing to do
         case "color=int":
         case "datetime=int":
         case "double=int":
         case "int=datetime":
         case "double=color":
         case "int=color":
         case "color=double":
         case "double=datetime":
             return;
         case "int=bool":
             FixAssignmentInFunction.AddCastCall(states, TypeNames.ToInt, states.IndexOf(identifier) + 1);
             return;
         case "double=bool":
             FixAssignmentInFunction.AddCastCall(states, TypeNames.ToDouble, states.IndexOf(identifier) + 1);
             return;
         case "bool=int":
         case "bool=double":
             FixAssignmentInFunction.AddCastCall(states, TypeNames.ToBool, states.IndexOf(identifier) + 1);
             return;
         case "string=bool":
         case "string=int":
         case "string=double":
             FixAssignmentInFunction.AddCastCall(states, TypeNames.ConvStr, states.IndexOf(identifier) + 1);
             return;
         default:
             return;
     }
 }