Esempio n. 1
0
        public override void CaseAParenExp(AParenExp node)
        {
            PExp replacer = node.GetExp();

            node.ReplaceBy(replacer);
            replacer.Apply(this);
        }
        private List <PStm> MakeStatements(PExp exp, int line, int pos)
        {
            List <PStm> list = new List <PStm>();

            if (exp is ASimpleInvokeExp)
            {
                list.Add(new AExpStm(new TSemicolon(";", line, pos), exp));
                return(list);
            }
            if (exp is AAssignmentExp)
            {
                list.Add(new AExpStm(new TSemicolon(";", line, pos), exp));
                return(list);
            }
            if (exp is ANonstaticInvokeExp)
            {
                list.Add(new AExpStm(new TSemicolon(";", line, pos), exp));
                return(list);
            }
            if (exp is ABinopExp)
            {
                ABinopExp aExp = (ABinopExp)exp;
                list.AddRange(MakeStatements(aExp.GetLeft(), line, pos));
                list.AddRange(MakeStatements(aExp.GetRight(), line, pos));
                return(list);
            }
            if (exp is AUnopExp)
            {
                AUnopExp aExp = (AUnopExp)exp;
                list.AddRange(MakeStatements(aExp.GetExp(), line, pos));
                return(list);
            }
            if (exp is AParenExp)
            {
                AParenExp aExp = (AParenExp)exp;
                list.AddRange(MakeStatements(aExp.GetExp(), line, pos));
                return(list);
            }
            if (exp is ALvalueExp)
            {
                ALvalueExp aExp   = (ALvalueExp)exp;
                PLvalue    lvalue = aExp.GetLvalue();
                if (lvalue is AStructLvalue)
                {
                    AStructLvalue aLvalue = (AStructLvalue)lvalue;
                    list.AddRange(MakeStatements(aLvalue.GetReceiver(), line, pos));
                    return(list);
                }
                if (lvalue is AArrayLvalue)
                {
                    AArrayLvalue aLvalue = (AArrayLvalue)lvalue;
                    list.AddRange(MakeStatements(aLvalue.GetBase(), line, pos));
                    list.AddRange(MakeStatements(aLvalue.GetIndex(), line, pos));
                    return(list);
                }
            }
            return(list);
        }
Esempio n. 3
0
 bool IsConstant(PExp exp)
 {
     if (exp is ABinopExp)
     {
         ABinopExp aExp = (ABinopExp)exp;
         return(IsConstant(aExp.GetLeft()) && IsConstant(aExp.GetRight()));
     }
     if (exp is AUnopExp)
     {
         AUnopExp aExp = (AUnopExp)exp;
         return(IsConstant(aExp.GetExp()));
     }
     if (exp is AIncDecExp)
     {
         AIncDecExp aExp = (AIncDecExp)exp;
         return(IsConstant(aExp.GetLvalue()));
     }
     if (exp is AIntConstExp || exp is AHexConstExp ||
         exp is AOctalConstExp || exp is AFixedConstExp ||
         exp is AStringConstExp || exp is ACharConstExp ||
         exp is ABooleanConstExp || exp is ANullExp ||
         exp is AAssignmentExp || exp is ADelegateExp)
     {
         return(true);
     }
     if (exp is ASimpleInvokeExp || exp is ANonstaticInvokeExp ||
         exp is ASyncInvokeExp || exp is ANewExp ||
         exp is ADelegateInvokeExp)
     {
         return(false);
     }
     if (exp is ALvalueExp)
     {
         ALvalueExp aExp = (ALvalueExp)exp;
         return(IsConstant(aExp.GetLvalue()));
     }
     if (exp is AParenExp)
     {
         AParenExp aExp = (AParenExp)exp;
         return(IsConstant(aExp.GetExp()));
     }
     if (exp is ACastExp)
     {
         ACastExp aExp = (ACastExp)exp;
         return(IsConstant(aExp.GetExp()));
     }
     if (exp is AIfExp)
     {
         AIfExp aExp = (AIfExp)exp;
         return(IsConstant(aExp.GetCond()) && IsConstant(aExp.GetThen()) && IsConstant(aExp.GetElse()));
     }
     if (exp == null)
     {
         return(false);
     }
     throw new Exception("Unexpected exp. Got " + exp);
 }
Esempio n. 4
0
        public override void OutABinopExp(ABinopExp node)
        {
            if (node.Parent() is ABinopExp || node.Parent() is AUnopExp)
            {
                AParenExp paren = new AParenExp();
                node.ReplaceBy(paren);
                paren.SetExp(node);

                finalTrans.data.ExpTypes[paren] = finalTrans.data.ExpTypes[node];
            }
            base.OutABinopExp(node);
        }
Esempio n. 5
0
 public override void CaseAParenExp(AParenExp node)
 {
     Value += "(";
     base.CaseAParenExp(node);
     Value += ")";
 }
Esempio n. 6
0
 public override void CaseAParenExp(AParenExp node)
 {
     Write("(");
     node.GetExp().Apply(this);
     Write(")");
 }
Esempio n. 7
0
 private static void MakeCloneRefferences(PExp clone, PExp exp, SharedData data)
 {
     data.ExpTypes[clone] = data.ExpTypes[exp];
     if (exp is AIntConstExp || exp is AHexConstExp || exp is AOctalConstExp ||
         exp is AFixedConstExp || exp is AStringConstExp || exp is ACharConstExp ||
         exp is ABooleanConstExp || exp is ANullExp)
     {
         //No more required
     }
     else if (exp is AIncDecExp)
     {
         AIncDecExp aExp   = (AIncDecExp)exp;
         AIncDecExp aClone = (AIncDecExp)clone;
         MakeCloneRefferences(aClone.GetLvalue(), aExp.GetLvalue(), data);
     }
     else if (exp is ABinopExp)
     {
         ABinopExp aExp   = (ABinopExp)exp;
         ABinopExp aClone = (ABinopExp)clone;
         MakeCloneRefferences(aClone.GetLeft(), aExp.GetLeft(), data);
         MakeCloneRefferences(aClone.GetRight(), aExp.GetRight(), data);
     }
     else if (exp is AUnopExp)
     {
         AUnopExp aExp   = (AUnopExp)exp;
         AUnopExp aClone = (AUnopExp)clone;
         MakeCloneRefferences(aClone.GetExp(), aExp.GetExp(), data);
     }
     else if (exp is ASimpleInvokeExp)
     {
         ASimpleInvokeExp aExp   = (ASimpleInvokeExp)exp;
         ASimpleInvokeExp aClone = (ASimpleInvokeExp)clone;
         data.SimpleMethodLinks[aClone] = data.SimpleMethodLinks[aExp];
         for (int i = 0; i < aExp.GetArgs().Count; i++)
         {
             MakeCloneRefferences((PExp)aClone.GetArgs()[i], (PExp)aExp.GetArgs()[i], data);
         }
     }
     else if (exp is ANonstaticInvokeExp)
     {
         ANonstaticInvokeExp aExp   = (ANonstaticInvokeExp)exp;
         ANonstaticInvokeExp aClone = (ANonstaticInvokeExp)clone;
         data.StructMethodLinks[aClone] = data.StructMethodLinks[aExp];
         for (int i = 0; i < aExp.GetArgs().Count; i++)
         {
             MakeCloneRefferences((PExp)aClone.GetArgs()[i], (PExp)aExp.GetArgs()[i], data);
         }
         MakeCloneRefferences(aClone.GetReceiver(), aExp.GetReceiver(), data);
     }
     else if (exp is ALvalueExp)
     {
         ALvalueExp aExp   = (ALvalueExp)exp;
         ALvalueExp aClone = (ALvalueExp)clone;
         MakeCloneRefferences(aClone.GetLvalue(), aExp.GetLvalue(), data);
     }
     else if (exp is AAssignmentExp)
     {
         AAssignmentExp aExp   = (AAssignmentExp)exp;
         AAssignmentExp aClone = (AAssignmentExp)clone;
         MakeCloneRefferences(aClone.GetLvalue(), aExp.GetLvalue(), data);
         MakeCloneRefferences(aClone.GetExp(), aExp.GetExp(), data);
     }
     else if (exp is AParenExp)
     {
         AParenExp aExp   = (AParenExp)exp;
         AParenExp aClone = (AParenExp)clone;
         MakeCloneRefferences(aClone.GetExp(), aExp.GetExp(), data);
     }
     else if (exp is AStringConstExp)
     {
         AStringConstExp aExp   = (AStringConstExp)exp;
         AStringConstExp aClone = (AStringConstExp)clone;
         if (data.ObfuscatedStrings.ContainsKey(aExp))
         {
             data.ObfuscatedStrings[aClone] = data.ObfuscatedStrings[aExp];
         }
         if (data.StringsDontJoinRight.Contains(aExp))
         {
             data.StringsDontJoinRight.Add(aClone);
         }
     }
     else if (exp is ANewExp)
     {
         ANewExp aExp   = (ANewExp)exp;
         ANewExp aClone = (ANewExp)clone;
         if (data.ConstructorLinks.ContainsKey(aExp))
         {
             data.ConstructorLinks[aClone] = data.ConstructorLinks[aExp];
         }
         MakeCloneRefferences(aClone.GetType(), aExp.GetType(), data);
         for (int i = 0; i < aExp.GetArgs().Count; i++)
         {
             MakeCloneRefferences((PExp)aClone.GetArgs()[i], (PExp)aExp.GetArgs()[i], data);
         }
     }
     else if (exp is ACastExp)
     {
         ACastExp aExp   = (ACastExp)exp;
         ACastExp aClone = (ACastExp)clone;
         MakeCloneRefferences(aClone.GetType(), aExp.GetType(), data);
         MakeCloneRefferences(aClone.GetExp(), aExp.GetExp(), data);
     }
     else if (exp is ADelegateExp)
     {
         ADelegateExp aExp   = (ADelegateExp)exp;
         ADelegateExp aClone = (ADelegateExp)clone;
         if (data.DelegateCreationMethod.ContainsKey(aExp))
         {
             data.DelegateCreationMethod[aClone] = data.DelegateCreationMethod[aExp];
         }
         MakeCloneRefferences(aClone.GetType(), aExp.GetType(), data);
         MakeCloneRefferences(aClone.GetLvalue(), aExp.GetLvalue(), data);
     }
     else if (exp is ADelegateInvokeExp)
     {
         ADelegateInvokeExp aExp   = (ADelegateInvokeExp)exp;
         ADelegateInvokeExp aClone = (ADelegateInvokeExp)clone;
         MakeCloneRefferences(aClone.GetReceiver(), aExp.GetReceiver(), data);
         for (int i = 0; i < aExp.GetArgs().Count; i++)
         {
             MakeCloneRefferences((PExp)aClone.GetArgs()[i], (PExp)aExp.GetArgs()[i], data);
         }
     }
     else if (exp is AIfExp)
     {
         AIfExp aExp   = (AIfExp)exp;
         AIfExp aClone = (AIfExp)clone;
         MakeCloneRefferences(aClone.GetCond(), aExp.GetCond(), data);
         MakeCloneRefferences(aClone.GetThen(), aExp.GetThen(), data);
         MakeCloneRefferences(aClone.GetElse(), aExp.GetElse(), data);
     }
     else
     {
         throw new Exception("Unexpect exp. Got " + exp.GetType());
     }
 }
Esempio n. 8
0
 public static bool ReturnsTheSame(PExp left, PExp right, SharedData data)
 {
     if (left.GetType() != right.GetType())
     {
         return(false);
     }
     if (left is ABinopExp)
     {
         ABinopExp aLeft  = (ABinopExp)left;
         ABinopExp aRight = (ABinopExp)right;
         if (aLeft.GetBinop().GetType() != aRight.GetBinop().GetType())
         {
             return(false);
         }
         return(ReturnsTheSame(aLeft.GetLeft(), aRight.GetLeft(), data) &&
                ReturnsTheSame(aLeft.GetRight(), aRight.GetRight(), data));
     }
     if (left is AUnopExp)
     {
         AUnopExp aLeft  = (AUnopExp)left;
         AUnopExp aRight = (AUnopExp)right;
         if (aLeft.GetUnop().GetType() != aRight.GetUnop().GetType())
         {
             return(false);
         }
         return(ReturnsTheSame(aLeft.GetExp(), aRight.GetExp(), data));
     }
     if (left is AIntConstExp)
     {
         AIntConstExp aLeft  = (AIntConstExp)left;
         AIntConstExp aRight = (AIntConstExp)right;
         return(int.Parse(aLeft.GetIntegerLiteral().Text) == int.Parse(aRight.GetIntegerLiteral().Text));
     }
     if (left is AFixedConstExp)
     {
         AFixedConstExp aLeft  = (AFixedConstExp)left;
         AFixedConstExp aRight = (AFixedConstExp)right;
         return(aLeft.GetFixedLiteral().Text == aRight.GetFixedLiteral().Text);
     }
     if (left is AStringConstExp)
     {
         AStringConstExp aLeft  = (AStringConstExp)left;
         AStringConstExp aRight = (AStringConstExp)right;
         return(aLeft.GetStringLiteral().Text == aRight.GetStringLiteral().Text);
     }
     if (left is ACharConstExp)
     {
         ACharConstExp aLeft  = (ACharConstExp)left;
         ACharConstExp aRight = (ACharConstExp)right;
         return(aLeft.GetCharLiteral().Text == aRight.GetCharLiteral().Text);
     }
     if (left is ABooleanConstExp)
     {
         ABooleanConstExp aLeft  = (ABooleanConstExp)left;
         ABooleanConstExp aRight = (ABooleanConstExp)right;
         return(aLeft.GetBool().GetType() == aRight.GetBool().GetType());
     }
     if (left is ASimpleInvokeExp)
     {
         //A method might not return the same thing each time it is called
         return(false);
     }
     if (left is ALvalueExp)
     {
         ALvalueExp aLeft  = (ALvalueExp)left;
         ALvalueExp aRight = (ALvalueExp)right;
         return(ReturnsTheSame(aLeft.GetLvalue(), aRight.GetLvalue(), data));
     }
     if (left is AParenExp)
     {
         AParenExp aLeft  = (AParenExp)left;
         AParenExp aRight = (AParenExp)right;
         return(ReturnsTheSame(aLeft.GetExp(), aRight.GetExp(), data));
     }
     throw new Exception("Util.ReturnsTheSame. Unexpected type, got " + left.GetType());
 }