Exemple #1
0
 public override void CaseAFixedConstExp(AFixedConstExp node)
 {
     Value += node.GetFixedLiteral().Text;
 }
Exemple #2
0
 public override void CaseAFixedConstExp(AFixedConstExp node)
 {
     Write(node.GetFixedLiteral().Text);
 }
Exemple #3
0
        public override void DefaultIn(Node node)
        {
            if (!canMerge)
            {
                return;
            }
            if (node is AMethodDecl)
            {
                //First node - no need to fetch
                if (((AMethodDecl)node).GetFormals().Count != ((AMethodDecl)otherNode).GetFormals().Count)
                {
                    canMerge = false;
                }
                return;
            }
            //Fetch corrosponding other node
            int index = 0;
            GetChildTypeIndex getChildTypeIndex = new GetChildTypeIndex()
            {
                Parent = node.Parent(), Child = node
            };

            node.Parent().Apply(getChildTypeIndex);
            index = getChildTypeIndex.Index;
            GetChildTypeByIndex getChildTypeByIndex = new GetChildTypeByIndex()
            {
                Child = node, Index = index, Parent = otherNode
            };

            otherNode.Apply(getChildTypeByIndex);
            otherNode = getChildTypeByIndex.Child;

            if (otherNode.GetType() != node.GetType())
            {
                canMerge = false;
                return;
            }

            if (node is AALocalDecl)
            {
                locals.Add((AALocalDecl)node);
                otherLocals.Add((AALocalDecl)otherNode);
                return;
            }

            if (node is ANamedType)
            {
                ANamedType aNode  = (ANamedType)node;
                ANamedType aOther = (ANamedType)otherNode;
                if (data.StructTypeLinks.ContainsKey(aNode) != data.StructTypeLinks.ContainsKey(aOther))
                {
                    canMerge = false;
                    return;
                }
                if (data.StructTypeLinks.ContainsKey(aNode) && data.StructTypeLinks[aNode] != data.StructTypeLinks[aOther])
                {
                    canMerge = false;
                }
                if (!data.StructTypeLinks.ContainsKey(aNode) && aNode.IsSame(aOther, true))//aNode.GetName().Text != aOther.GetName().Text)
                {
                    canMerge = false;
                }
                if (aNode.IsPrimitive() && !aOther.IsPrimitive(aNode.AsIdentifierString()))
                {
                    canMerge = false;
                }
                return;
            }

            if (node is AABlock)
            {
                AABlock aNode  = (AABlock)node;
                AABlock aOther = (AABlock)otherNode;
                if (aNode.GetStatements().Count != aOther.GetStatements().Count)
                {
                    canMerge = false;
                }
                return;
            }

            if (node is AIntConstExp)
            {
                AIntConstExp aNode  = (AIntConstExp)node;
                AIntConstExp aOther = (AIntConstExp)otherNode;
                if (aNode.GetIntegerLiteral().Text != aOther.GetIntegerLiteral().Text)
                {
                    canMerge = false;
                }
                return;
            }

            if (node is AFixedConstExp)
            {
                AFixedConstExp aNode  = (AFixedConstExp)node;
                AFixedConstExp aOther = (AFixedConstExp)otherNode;
                if (aNode.GetFixedLiteral().Text != aOther.GetFixedLiteral().Text)
                {
                    canMerge = false;
                }
                return;
            }

            if (node is AStringConstExp)
            {
                AStringConstExp aNode  = (AStringConstExp)node;
                AStringConstExp aOther = (AStringConstExp)otherNode;
                if (aNode.GetStringLiteral().Text != aOther.GetStringLiteral().Text)
                {
                    canMerge = false;
                }
                return;
            }

            if (node is ACharConstExp)
            {
                ACharConstExp aNode  = (ACharConstExp)node;
                ACharConstExp aOther = (ACharConstExp)otherNode;
                if (aNode.GetCharLiteral().Text != aOther.GetCharLiteral().Text)
                {
                    canMerge = false;
                }
                return;
            }

            if (node is ASimpleInvokeExp)
            {
                ASimpleInvokeExp aNode  = (ASimpleInvokeExp)node;
                ASimpleInvokeExp aOther = (ASimpleInvokeExp)otherNode;
                if (data.SimpleMethodLinks[aNode] != data.SimpleMethodLinks[aOther] &&
                    !(data.SimpleMethodLinks[aNode] == Util.GetAncestor <AMethodDecl>(aNode) &&
                      data.SimpleMethodLinks[aOther] == Util.GetAncestor <AMethodDecl>(aOther)))
                {
                    canMerge = false;
                }
                return;
            }

            if (node is ALocalLvalue)
            {
                ALocalLvalue aNode  = (ALocalLvalue)node;
                ALocalLvalue aOther = (ALocalLvalue)otherNode;
                if (locals.IndexOf(data.LocalLinks[aNode]) != otherLocals.IndexOf(data.LocalLinks[aOther]))
                {
                    canMerge = false;
                }
                return;
            }

            if (node is AFieldLvalue)
            {
                AFieldLvalue aNode  = (AFieldLvalue)node;
                AFieldLvalue aOther = (AFieldLvalue)otherNode;
                if (data.FieldLinks[aNode] != data.FieldLinks[aOther])
                {
                    canMerge = false;
                }
                return;
            }

            if (node is AStructLvalue)
            {
                AStructLvalue aNode  = (AStructLvalue)node;
                AStructLvalue aOther = (AStructLvalue)otherNode;
                if (data.StructFieldLinks[aNode] != data.StructFieldLinks[aOther])
                {
                    canMerge = false;
                }
                return;
            }
        }
Exemple #4
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());
 }