Advertisement
RaWRCoder

Crystal Script piece

Jun 24th, 2014
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.10 KB | None | 0 0
  1. private BaseValue handleOperatorPlus(BaseValue op1, BaseValue op2, out bool err)
  2. {
  3.     //Ошибки пока нет))
  4.     err = false;
  5.  
  6.     //Нам суют какое-то сложное дермецо?
  7.     if (!op1.IsSimpleValue || !op2.IsSimpleValue)
  8.     {
  9.         //Правда здесь еще могут быть enumы
  10.         if (op1.IsEnum && op2.IsEnum)
  11.         {
  12.             var a = (EnumValue) op1;
  13.             var b = (EnumValue) op2;
  14.  
  15.             //Если у правого операнда другой тип - нам насрать. Один фиг все кастуется в целые числа
  16.             return new EnumValue(a.Value + b.Value, a.ActualType);
  17.         }
  18.         if (op1.IsEnum && op2.IsInteger)
  19.         {
  20.             var a = (EnumValue)op1;
  21.             var b = (IntegerValue)op2;
  22.             return new EnumValue(a.Value + b.Value, a.ActualType);
  23.         }
  24.         if (op2.IsEnum && op1.IsInteger)
  25.         {
  26.             var a = (EnumValue)op2;
  27.             var b = (IntegerValue)op1;
  28.             return new EnumValue(a.Value + b.Value, a.ActualType);
  29.         }
  30.  
  31.         //Пользователь не дружит с головой. Или испытывает синтаксический анализатор
  32.         err = true;
  33.         Error.PostRuntime(
  34.             Error.RT_WRONG_ARGUMENTS,
  35.             Error.Make_RT_WRONG_ARGUMENTS("+", op1.IsSimpleValue ? 2 : 1, "<simple-type>"),
  36.             CurrentFile);
  37.         return null;//динахуй!
  38.     }
  39.  
  40.     //Целочисленное сложение
  41.     if (op1.IsInteger && op2.IsInteger)
  42.     {
  43.         var a = (IntegerValue)op1;
  44.         var b = (IntegerValue)op2;
  45.         return new IntegerValue(a.Value + b.Value);
  46.     }
  47.     //float + int (вещественное сложение)
  48.     if (op1.IsFloat && op2.IsInteger)
  49.     {
  50.         var a = (FloatValue)op1;
  51.         var b = (IntegerValue)op2;
  52.         return new FloatValue(a.Value + b.Value);
  53.     }
  54.     //(вещественное сложение)
  55.     if (op2.IsFloat && op1.IsInteger)
  56.     {
  57.         var a = (FloatValue)op2;
  58.         var b = (IntegerValue)op1;
  59.         return new FloatValue(a.Value + b.Value);
  60.     }
  61.     //(вещественное сложение)
  62.     if (op1.IsFloat && op2.IsFloat)
  63.     {
  64.         var a = (FloatValue)op1;
  65.         var b = (FloatValue)op2;
  66.         return new FloatValue(a.Value + b.Value);
  67.     }
  68.     //string + ? (конкатенация строк)
  69.     if (op1.IsString)
  70.     {
  71.         var a = (StringValue)op1;
  72.         StringValue b;
  73.         if (op2.IsString)
  74.             b = (StringValue) op2;
  75.         else if (op2.IsInteger)
  76.             b = (StringValue)DefaultCasts.Cast_Int_to_String(op2);
  77.         else if (op2.IsFloat)
  78.             b = (StringValue)DefaultCasts.Cast_Float_to_String(op2);
  79.         else if (op2.ActualType.SimpleType == ESimpleType.Type)
  80.             b = (StringValue) DefaultCasts.Cast_Type_to_String(op2);
  81.         else if (op2.ActualType.SimpleType == ESimpleType.Bool)
  82.             b = (StringValue)DefaultCasts.Cast_Bool_to_String(op2);
  83.         else
  84.         {
  85.             //О-оу. пользователь чудит
  86.             err = true;
  87.             Error.PostRuntime(
  88.                 Error.RT_WRONG_ARGUMENTS,
  89.                 Error.Make_RT_WRONG_ARGUMENTS("+", 2, "<simple-type, convertable to string>"),
  90.                 CurrentFile);
  91.             return null;//Убейся апстену
  92.         }
  93.         return new StringValue(a.Value + b.Value);
  94.     }
  95.     //(конкатенация строк)
  96.     if (op2.IsString)
  97.     {
  98.         var a = (StringValue)op2;
  99.         StringValue b;
  100.         if (op1.IsInteger)
  101.             b = (StringValue)DefaultCasts.Cast_Int_to_String(op1);
  102.         else if (op1.IsFloat)
  103.             b = (StringValue)DefaultCasts.Cast_Float_to_String(op1);
  104.         else if (op1.ActualType.SimpleType == ESimpleType.Type)
  105.             b = (StringValue)DefaultCasts.Cast_Type_to_String(op1);
  106.         else if (op1.ActualType.SimpleType == ESimpleType.Bool)
  107.             b = (StringValue)DefaultCasts.Cast_Bool_to_String(op1);
  108.         else
  109.         {
  110.             //Опять какое то гавно суют :((
  111.             err = true;
  112.             Error.PostRuntime(
  113.                 Error.RT_WRONG_ARGUMENTS,
  114.                 Error.Make_RT_WRONG_ARGUMENTS("+", 1, "<simple-type, convertable to string>"),
  115.                 CurrentFile);
  116.             return null;
  117.         }
  118.         return new StringValue(a.Value + b.Value);
  119.     }
  120.  
  121.     //ЛОЛШТО? bool + type? type + undefined? Очевидно, пользователь поехавший.
  122.     err = true;
  123.     Error.PostRuntime(
  124.         Error.RT_WRONG_ARGUMENTS,//Error.RT_USER_IS_DUMBASS,
  125.         Error.Make_RT_WRONG_ARGUMENTS("+", 1, "<simple-type>"),
  126.         CurrentFile);
  127.     return null;//засосите, бля
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement