public VariableDescription(AALocalDecl localDecl, VariableTypes type)
 {
     Name = localDecl.GetName().Text;
     Type = Util.TypeToString(localDecl.GetType());
     switch (type)
     {
         case VariableTypes.LocalVariable:
             PlacementPrefix = "Local";
             break;
         case VariableTypes.Parameter:
             PlacementPrefix = "Parameter";
             break;
         case VariableTypes.StructVariable:
             PlacementPrefix = "Struct field";
             break;
         default:
             PlacementPrefix = "";
             break;
     }
     VariableType = type;
     Const = localDecl.GetConst() != null;
     IsStatic = localDecl.GetStatic() != null;
     Visibility = localDecl.GetVisibilityModifier();
     realType = (PType) localDecl.GetType().Clone();
     init = localDecl.GetInit();
     Line = localDecl.GetName().Line;
     Position = TextPoint.FromCompilerCoords(localDecl.GetName());
 }
        private PStm RemoveVariableStatement(PStm stm, PExp rightSide, int line, int pos)
        {
            if (rightSide != null)
            {
                List <PStm> statements = MakeStatements(rightSide, line, pos);

                if (statements.Count == 0)
                {
                    stm.Parent().RemoveChild(stm);
                }
                else
                {
                    PStm statement;
                    if (statements.Count == 1)
                    {
                        statement = statements[0];
                    }
                    else
                    {
                        statement = new ABlockStm(new TLBrace("{"), new AABlock(statements, new TRBrace("}")));
                    }
                    stm.ReplaceBy(statement);
                    return(statement);
                }
            }
            else
            {
                stm.Parent().RemoveChild(stm);
            }
            return(null);
        }
Exemple #3
0
        public VariableDescription(AALocalDecl localDecl, VariableTypes type)
        {
            Name = localDecl.GetName().Text;
            Type = Util.TypeToString(localDecl.GetType());
            switch (type)
            {
            case VariableTypes.LocalVariable:
                PlacementPrefix = "Local";
                break;

            case VariableTypes.Parameter:
                PlacementPrefix = "Parameter";
                break;

            case VariableTypes.StructVariable:
                PlacementPrefix = "Struct field";
                break;

            default:
                PlacementPrefix = "";
                break;
            }
            VariableType = type;
            Const        = localDecl.GetConst() != null;
            IsStatic     = localDecl.GetStatic() != null;
            Visibility   = localDecl.GetVisibilityModifier();
            realType     = (PType)localDecl.GetType().Clone();
            init         = localDecl.GetInit();
            Line         = localDecl.GetName().Line;
            Position     = TextPoint.FromCompilerCoords(localDecl.GetName());
        }
Exemple #4
0
        public static PExp MakeClone(PExp lvalue, SharedData data)
        {
            PExp clone = (PExp)lvalue.Clone();

            MakeCloneRefferences(clone, lvalue, data);
            return(clone);
        }
Exemple #5
0
        public override void CaseAParenExp(AParenExp node)
        {
            PExp replacer = node.GetExp();

            node.ReplaceBy(replacer);
            replacer.Apply(this);
        }
Exemple #6
0
        public override void CaseATempCastExp(ATempCastExp node)
        {
            //The cast type must be a single identifier
            if (node.GetType() is ALvalueExp)
            {
                ALvalueExp lvalueExp = (ALvalueExp)node.GetType();
                if (lvalueExp.GetLvalue() is AAmbiguousNameLvalue)
                {
                    AAmbiguousNameLvalue ambiguousLvalue = (AAmbiguousNameLvalue)lvalueExp.GetLvalue();
                    if (ambiguousLvalue.GetAmbiguous() is AAName)
                    {
                        AAName simpleName = (AAName)ambiguousLvalue.GetAmbiguous();
                        if (simpleName.GetIdentifier().Count == 1)
                        {
                            ACastExp castExp = new ACastExp(node.GetToken(), new ANamedType(simpleName), node.GetExp());
                            node.ReplaceBy(castExp);
                            castExp.Apply(this);
                            return;
                        }
                    }
                }
            }
            PExp exp = node.GetExp();

            node.ReplaceBy(exp);
            exp.Apply(this);
        }
Exemple #7
0
        private static List <AALocalDecl> GetAssignedTo(ControlFlowGraph.Node node, SharedData data)
        {
            if (node.Statement is ALocalDeclStm)
            {
                return new List <AALocalDecl>()
                       {
                           (AALocalDecl)((ALocalDeclStm)node.Statement).GetLocalDecl()
                       }
            }
            ;
            PExp exp = node.Expression;

            if (exp != null && exp is AAssignmentExp)
            {
                AAssignmentExp aExp = (AAssignmentExp)exp;

                if (aExp.GetLvalue() is ALocalLvalue)
                {
                    return new List <AALocalDecl>()
                           {
                               data.LocalLinks[(ALocalLvalue)aExp.GetLvalue()]
                           }
                }
                ;
            }
            return(new List <AALocalDecl>());
        }
Exemple #8
0
        public static bool Fold(GalaxyCompiler compiler)
        {
            bool changes = false;

            for (int i = 0; i < compiler.ParsedSourceFiles.Count; i++)
            {
                SourceFileContents file = compiler.ParsedSourceFiles[i];
                foreach (VariableDescription field in file.Fields)
                {
                    if (field.Const)
                    {
                        PExp   init = field.init;
                        string typeStr;
                        if (init == null)
                        {
                            typeStr = null;
                        }
                        else
                        {
                            ConstantFolder folder = new ConstantFolder();
                            field.init.Apply(folder);
                            typeStr = folder.Value;
                        }
                        if (field.initStr != typeStr)
                        {
                            changes       = true;
                            field.initStr = typeStr;
                        }
                    }
                }
            }
            return(changes);
        }
        public override void CaseASimpleInvokeExp(ASimpleInvokeExp node)
        {
            PExp  expNode = (PExp)node;
            PType type    = data.ExpTypes[expNode];

            if (type is APointerType)
            {
                type = new ANamedType(new TIdentifier("string"), null);
            }
            ALocalLvalue local = new ALocalLvalue(new TIdentifier("tempName", 0, 0));
            ALvalueExp   exp   = new ALvalueExp(local);
            PStm         stm   = Util.GetAncestor <PStm>(node);
            AABlock      block = (AABlock)stm.Parent();

            node.ReplaceBy(exp);
            AALocalDecl localDecl = new AALocalDecl(new APublicVisibilityModifier(), null, null, null, null,
                                                    Util.MakeClone(type, data),
                                                    new TIdentifier(varName, 0, 0), expNode);
            ALocalDeclStm newStm = new ALocalDeclStm(new TSemicolon(";"), localDecl);

            block.GetStatements().Insert(block.GetStatements().IndexOf(stm), newStm);
            NewStatements.Add(newStm);

            data.LvalueTypes[local] = type;
            data.ExpTypes[exp]      = type;
            data.LocalLinks[local]  = localDecl;
            //localDecl.Apply(this);
            exp.Apply(this);
            return;
        }
Exemple #10
0
 public long GetValueOf(PExp exp)
 {
     if (mExpTypes.ContainsKey(exp))
     {
         return(mExpTypes[exp].Value);
     }
     return(0);
 }
Exemple #11
0
 public PType GetTypeOf(PExp exp)
 {
     if (mExpTypes.ContainsKey(exp))
     {
         return(mExpTypes[exp].Type);
     }
     return(null);
 }
        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);
        }
Exemple #13
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);
 }
Exemple #14
0
        public ExpressionShell(PExp exp, RuntimeEnvironment env)
        {
            long value;

            if (env.GlobalSearch(exp, out value))
            {
                Value = value;
            }
        }
Exemple #15
0
 public void SetValueOf(PExp exp, long value)
 {
     if (mExpTypes.ContainsKey(exp))
     {
         mExpTypes[exp].Value = value;
     }
     else
     {
         throw new Exception("No such expression in direct scope");
     }
 }
Exemple #16
0
        bool ContainsNewExp(PExp exp)
        {
            if (exp == null)
            {
                return(false);
            }
            NewExpFinder finder = new NewExpFinder();

            exp.Apply(finder);
            return(finder.HasNew);
        }
Exemple #17
0
 public bool Contains(PExp exp)
 {
     if (exp != null)
     {
         return(mExpTypes.ContainsKey(exp));
     }
     else
     {
         return(false);
     }
 }
Exemple #18
0
        public override void CaseAALocalDecl(AALocalDecl node)
        {
            if (node.GetConst() == null)
            {
                return;
            }

            initialLocalDecl = node;

            if (IsConstant(node.GetInit()))
            {
                {
                    List <ALocalLvalue> lvalues = new List <ALocalLvalue>();
                    lvalues.AddRange(data.LocalLinks.Where(link => link.Value == node).Select(link => link.Key));
                    foreach (ALocalLvalue lvalue in lvalues)
                    {
                        PExp parent = (PExp)lvalue.Parent();
                        parent.ReplaceBy(Util.MakeClone(node.GetInit(), data));
                    }
                }
                {
                    List <AStructLvalue> lvalues = new List <AStructLvalue>();
                    lvalues.AddRange(data.StructFieldLinks.Where(link => link.Value == node).Select(link => link.Key));
                    foreach (AStructLvalue lvalue in lvalues)
                    {
                        PExp parent = (PExp)lvalue.Parent();
                        parent.ReplaceBy(Util.MakeClone(node.GetInit(), data));
                    }
                }
                {
                    List <AStructFieldLvalue> lvalues = new List <AStructFieldLvalue>();
                    lvalues.AddRange(
                        data.StructMethodFieldLinks.Where(link => link.Value == node).Select(link => link.Key));
                    foreach (AStructFieldLvalue lvalue in lvalues)
                    {
                        PExp parent = (PExp)lvalue.Parent();
                        parent.ReplaceBy(Util.MakeClone(node.GetInit(), data));
                    }
                }
                if (node.Parent() is ALocalDeclStm)
                {
                    node.Parent().Parent().RemoveChild(node.Parent());
                }
                else
                {
                    node.Parent().RemoveChild(node);
                }
            }


            initialLocalDecl = null;
        }
 public VariableDescription(AFieldDecl fieldDecl)
 {
     Name = fieldDecl.GetName().Text;
     Type = Util.TypeToString(fieldDecl.GetType());
     PlacementPrefix = "Field";
     VariableType = VariableTypes.Field;
     Const = fieldDecl.GetConst() != null;
     IsStatic = fieldDecl.GetStatic() != null;
     Visibility = fieldDecl.GetVisibilityModifier();
     realType = (PType)fieldDecl.GetType().Clone();
     init = fieldDecl.GetInit();
     Line = fieldDecl.GetName().Line;
     Position = TextPoint.FromCompilerCoords(fieldDecl.GetName());
 }
Exemple #20
0
 public VariableDescription(AFieldDecl fieldDecl)
 {
     Name            = fieldDecl.GetName().Text;
     Type            = Util.TypeToString(fieldDecl.GetType());
     PlacementPrefix = "Field";
     VariableType    = VariableTypes.Field;
     Const           = fieldDecl.GetConst() != null;
     IsStatic        = fieldDecl.GetStatic() != null;
     Visibility      = fieldDecl.GetVisibilityModifier();
     realType        = (PType)fieldDecl.GetType().Clone();
     init            = fieldDecl.GetInit();
     Line            = fieldDecl.GetName().Line;
     Position        = TextPoint.FromCompilerCoords(fieldDecl.GetName());
 }
Exemple #21
0
        public override void CaseAVarDecl(AVarDecl node)
        {
            // check: variable initializer is a InitExp
            PExp exp = node.GetInit();

            if (exp != null)
            {
                if (exp.GetType() != typeof(AInitExp))
                {
                    Error.Fatal(ErrorType.InvalidInitializer, node.GetName());
                }
            }
            base.CaseAVarDecl(node);
        }
        private int FoldInt(PExp exp, ref bool valid)
        {
            if (!valid) return -1;
            if (exp is AIntConstExp)
            {
                return int.Parse(((AIntConstExp) exp).GetIntegerLiteral().Text);
            }
            if (exp is ABinopExp)
            {
                ABinopExp aExp = (ABinopExp)exp;
                int left = FoldInt(aExp.GetLeft(), ref valid);
                int right = FoldInt(aExp.GetLeft(), ref valid);
                if (!valid) return -1;
                PBinop binop = aExp.GetBinop();
                if (binop is APlusBinop)
                    return left + right;
                if (binop is AMinusBinop)
                    return left - right;
                if (binop is ATimesBinop)
                    return left * right;
                if ((binop is AModuloBinop || binop is ADivideBinop) && right == 0)
                {
                    Token token = binop is AModuloBinop
                                      ? (Token)((AModuloBinop) binop).GetToken()
                                      : ((ADivideBinop) binop).GetToken();
                    errors.Add(new ErrorCollection.Error(token, LocRM.GetString("ErrorText57")));
                    throw new ParserException(null, null);
                }
                if (binop is AModuloBinop)
                    return left % right;
                if (binop is ADivideBinop)
                    return left / right;
                if (binop is AAndBinop)
                    return left & right;
                if (binop is AOrBinop)
                    return left | right;
                if (binop is AXorBinop)
                    return left ^ right;
                if (binop is ALBitShiftBinop)
                    return left << right;
                if (binop is ARBitShiftBinop)
                    return left >> right;
            }
            if (exp is ALvalueExp)
                return FoldInt(((ALvalueExp) exp).GetLvalue(), ref valid);

            valid = false;
            return -1;
        }
Exemple #23
0
        public bool GlobalSearch(PExp exp, out long value)
        {
            value = 0;
            Scope result = GlobalSearch(mGlobalScope, exp);

            if (result != null)
            {
                value = result.GetValueOf(exp);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #24
0
        private PExp Combine(PExp left, List <string> strings)
        {
            AStringConstExp right = new AStringConstExp(new TStringLiteral("\"" + strings[0] + "\""));

            strings.RemoveAt(0);
            ABinopExp binop = new ABinopExp(left, new APlusBinop(new TPlus("+")), right);

            data.StringsDontJoinRight.Add(right);
            data.ExpTypes[right]     =
                data.ExpTypes[binop] = new ANamedType(new TIdentifier("string"), null);
            if (strings.Count > 0)
            {
                return(Combine(binop, strings));
            }
            return(binop);
        }
Exemple #25
0
 private Scope GlobalSearch(Scope current, PExp exp)
 {
     if (current.Contains(exp))
     {
         return(current);
     }
     foreach (Scope s in current.SubScopes)
     {
         Scope result = GlobalSearch(s, exp);
         if (result != null)
         {
             return(result);
         }
     }
     return(null);
 }
 private static PLvalue GetSomeLvalue(PExp exp)
 {
     if (exp is AParenExp)
     {
         return(GetSomeLvalue(((AParenExp)exp).GetExp()));
     }
     if (exp is ALvalueExp)
     {
         return(((ALvalueExp)exp).GetLvalue());
     }
     if (exp is AAssignmentExp)
     {
         return(((AAssignmentExp)exp).GetLvalue());
     }
     return(null);
 }
Exemple #27
0
        public void Add(APortDecl port)
        {
            PExp exp = port.GetAdress();

            if (Contains(exp))
            {
                long        adress = GetValueOf(exp);
                Declaration tv     = new Declaration(port, port.GetType(), adress, port.GetName().Text);
                mNamedTypes.Add(port, tv);
                mLookupTable.Add(port.GetName().Text, tv);
            }
            else
            {
                throw new ScopeFailure("Unresolved port address");
            }
        }
Exemple #28
0
            private void MoveOut(PExp exp, PType type)
            {
                PStm    pStm   = Util.GetAncestor <PStm>(exp);
                AABlock pBlock = (AABlock)pStm.Parent();

                ALocalLvalue lvalue    = new ALocalLvalue(new TIdentifier("gppVar"));
                ALvalueExp   lvalueExp = new ALvalueExp(lvalue);

                exp.ReplaceBy(lvalueExp);
                AALocalDecl decl = new AALocalDecl(new APublicVisibilityModifier(), null, null, null, null, Util.MakeClone(type, data), new TIdentifier("gppVar"), exp);

                pBlock.GetStatements().Insert(pBlock.GetStatements().IndexOf(pStm), new ALocalDeclStm(new TSemicolon(";"), decl));

                data.LvalueTypes[lvalue]     =
                    data.ExpTypes[lvalueExp] = decl.GetType();
                data.LocalLinks[lvalue]      = decl;
            }
Exemple #29
0
        public override void DefaultIn(Node node)
        {
            if (node is PExp)
            {
                PExp exp = (PExp)node;
                if (finalTrans.data.ExpTypes[exp] is ANamedType)
                {
                    ANamedType type = (ANamedType)finalTrans.data.ExpTypes[exp];
                    if (finalTrans.data.StructTypeLinks.ContainsKey(type))
                    {
                        AStructDecl strDecl = finalTrans.data.StructTypeLinks[type];
                        if (strDecl.GetLocals().Cast <PLocalDecl>().Select(decl => decl is AALocalDecl).Count() == 0)
                        {
                            if (node.Parent() is AAssignmentExp)
                            {
                                node = node.Parent().Parent();
                            }
                            MoveMethodDeclsOut mover = new MoveMethodDeclsOut("removedStructVar", finalTrans.data);
                            node.Apply(mover);
                            foreach (PStm pStm in mover.NewStatements)
                            {
                                pStm.Apply(this);
                            }
                            node.Parent().RemoveChild(node);

                            if (node.Parent() is ABinopExp)
                            {
                                ABinopExp        parent = (ABinopExp)node.Parent();
                                ABooleanConstExp replacer;
                                if (parent.GetBinop() is ANeBinop || parent.GetBinop() is AGtBinop || parent.GetBinop() is ALtBinop)
                                {
                                    replacer = new ABooleanConstExp(new AFalseBool());
                                }
                                else
                                {
                                    replacer = new ABooleanConstExp(new ATrueBool());
                                }
                                finalTrans.data.ExpTypes[replacer] = new ANamedType(new TIdentifier("bool"), null);
                                parent.ReplaceBy(replacer);
                            }
                        }
                    }
                }
            }
        }
 static bool IsConst(PExp exp, out bool value)
 {
     if (exp is ABooleanConstExp)
     {
         value = ((ABooleanConstExp)exp).GetBool() is ATrueBool;
         return true;
     }
     if (exp is AIntConstExp)
     {
         value = ((AIntConstExp)exp).GetIntegerLiteral().Text != "0";
         return true;
     }
     if (exp is ANullExp)
     {
         value = false;
         return true;
     }
     value = false;
     return false;
 }
Exemple #31
0
        public override void CaseAPortDecl(APortDecl node)
        {
            // Check: adress is a integer constant
            if (node.GetAdress().GetType() != typeof(AIntConstExp))
            {
                Error.Fatal(ErrorType.InvalidAdress, node.GetName());
            }

            // check: variable initializer is a InitExp
            PExp exp = node.GetInit();

            if (exp != null)
            {
                if (exp.GetType() != typeof(AInitExp))
                {
                    Error.Fatal(ErrorType.InvalidInitializer, node.GetName());
                }
            }
            base.CaseAPortDecl(node);
        }
 static bool IsConst(PExp exp, out bool value)
 {
     if (exp is ABooleanConstExp)
     {
         value = ((ABooleanConstExp)exp).GetBool() is ATrueBool;
         return(true);
     }
     if (exp is AIntConstExp)
     {
         value = ((AIntConstExp)exp).GetIntegerLiteral().Text != "0";
         return(true);
     }
     if (exp is ANullExp)
     {
         value = false;
         return(true);
     }
     value = false;
     return(false);
 }
Exemple #33
0
        public override void CaseASimpleInvokeExp(ASimpleInvokeExp node)
        {
            AMethodDecl target = data.SimpleMethodLinks[node];

            for (int i = 0; i < node.GetArgs().Count; i++)
            {
                PExp arg = (PExp)node.GetArgs()[i];
                currentLocal = null;
                arg.Apply(this);
                if (currentLocal != null && target.GetFormals().Cast <AALocalDecl>().ToList()[i].GetRef() != null)
                {
                    ALocalLvalue local = currentLocal;
                    target.Apply(this);
                    if (target.GetFormals().Cast <AALocalDecl>().ToList()[i].GetRef() != null)
                    {
                        AALocalDecl decl = data.LocalLinks[local];
                        NeededRefs[Util.GetAncestor <AMethodDecl>(node)].Add(decl);
                    }
                }
            }
        }
Exemple #34
0
        public static void CalculateLiveVariables(ControlFlowGraph cfg, SharedData data)
        {
            //First, generate lists of what is used in each node
            Dictionary <ControlFlowGraph.Node, List <AALocalDecl> > usedVars = new Dictionary <ControlFlowGraph.Node, List <AALocalDecl> >();

            foreach (ControlFlowGraph.Node node in cfg.Nodes)
            {
                node.LiveVariables.Clear();

                PExp exp = node.Expression;
                if (exp == null)
                {
                    usedVars[node] = new List <AALocalDecl>();
                }
                else
                {
                    GetUsedVariables variableFinder = new GetUsedVariables(data);
                    exp.Apply(variableFinder);
                    usedVars[node] = variableFinder.UsedLocals;
                }
            }


            bool changed = true;

            while (changed)
            {
                changed = false;
                foreach (ControlFlowGraph.Node node in cfg.Nodes)
                {
                    int count = node.LiveVariables.Count;
                    Join(node);
                    node.LiveVariables.Subtract(GetAssignedTo(node, data));
                    node.LiveVariables.Union(usedVars[node]);
                    changed |= count != node.LiveVariables.Count;
                }
            }
        }
 public AExpStm(
         TSemicolon _token_,
         PExp _exp_
 )
 {
     SetToken(_token_);
     SetExp(_exp_);
 }
 internal override void RemoveChild(Node child)
 {
     if (_token_ == child)
     {
         _token_ = null;
         return;
     }
     if (_exp_ == child)
     {
         _exp_ = null;
         return;
     }
 }
 internal override void RemoveChild(Node child)
 {
     if (_token_ == child)
     {
         _token_ = null;
         return;
     }
     if (_dimention_ == child)
     {
         _dimention_ = null;
         return;
     }
     if (_int_dim_ == child)
     {
         _int_dim_ = null;
         return;
     }
     if (_end_token_ == child)
     {
         _end_token_ = null;
         return;
     }
     if (_type_ == child)
     {
         _type_ = null;
         return;
     }
     if (_decl_.Contains(child))
     {
         _decl_.Remove(child);
         return;
     }
 }
        public void SetCondition(PExp node)
        {
            if (_condition_ != null)
            {
                _condition_.Parent(null);
            }

            if (node != null)
            {
                if (node.Parent() != null)
                {
                    node.Parent().RemoveChild(node);
                }

                node.Parent(this);
            }

            _condition_ = node;
        }
        public void SetInit(PExp node)
        {
            if (_init_ != null)
            {
                _init_.Parent(null);
            }

            if (node != null)
            {
                if (node.Parent() != null)
                {
                    node.Parent().RemoveChild(node);
                }

                node.Parent(this);
            }

            _init_ = node;
        }
 public AIfThenStm(
         TLParen _token_,
         PExp _condition_,
         PStm _body_
 )
 {
     SetToken(_token_);
     SetCondition(_condition_);
     SetBody(_body_);
 }
 internal override void RemoveChild(Node child)
 {
     if (_token_ == child)
     {
         _token_ = null;
         return;
     }
     if (_cond_ == child)
     {
         _cond_ = null;
         return;
     }
     if (_then_ == child)
     {
         _then_ = null;
         return;
     }
     if (_else_ == child)
     {
         _else_ = null;
         return;
     }
 }
        public void SetElse(PExp node)
        {
            if (_else_ != null)
            {
                _else_.Parent(null);
            }

            if (node != null)
            {
                if (node.Parent() != null)
                {
                    node.Parent().RemoveChild(node);
                }

                node.Parent(this);
            }

            _else_ = node;
        }
 internal override void RemoveChild(Node child)
 {
     if (_token_ == child)
     {
         _token_ = null;
         return;
     }
     if (_init_ == child)
     {
         _init_ = null;
         return;
     }
     if (_cond_ == child)
     {
         _cond_ = null;
         return;
     }
     if (_update_ == child)
     {
         _update_ = null;
         return;
     }
     if (_body_ == child)
     {
         _body_ = null;
         return;
     }
 }
 public AForStm(
         TLParen _token_,
         PStm _init_,
         PExp _cond_,
         PStm _update_,
         PStm _body_
 )
 {
     SetToken(_token_);
     SetInit(_init_);
     SetCond(_cond_);
     SetUpdate(_update_);
     SetBody(_body_);
 }
 public AFieldDecl(
         PVisibilityModifier _visibility_modifier_,
         TStatic _static_,
         TConst _const_,
         PType _type_,
         TIdentifier _name_,
         PExp _init_
 )
 {
     SetVisibilityModifier(_visibility_modifier_);
     SetStatic(_static_);
     SetConst(_const_);
     SetType(_type_);
     SetName(_name_);
     SetInit(_init_);
 }
 internal override void RemoveChild(Node child)
 {
     if (_name_ == child)
     {
         _name_ = null;
         return;
     }
     if (_value_ == child)
     {
         _value_ = null;
         return;
     }
 }
 internal override void RemoveChild(Node child)
 {
     if (_visibility_modifier_ == child)
     {
         _visibility_modifier_ = null;
         return;
     }
     if (_static_ == child)
     {
         _static_ = null;
         return;
     }
     if (_ref_ == child)
     {
         _ref_ = null;
         return;
     }
     if (_out_ == child)
     {
         _out_ = null;
         return;
     }
     if (_const_ == child)
     {
         _const_ = null;
         return;
     }
     if (_type_ == child)
     {
         _type_ = null;
         return;
     }
     if (_name_ == child)
     {
         _name_ = null;
         return;
     }
     if (_init_ == child)
     {
         _init_ = null;
         return;
     }
 }
 public ACastExp(
         TLParen _token_,
         PType _type_,
         PExp _exp_
 )
 {
     SetToken(_token_);
     SetType(_type_);
     SetExp(_exp_);
 }
 public AIfExp(
         TQuestionmark _token_,
         PExp _cond_,
         PExp _then_,
         PExp _else_
 )
 {
     SetToken(_token_);
     SetCond(_cond_);
     SetThen(_then_);
     SetElse(_else_);
 }
 public AALocalDecl(
         PVisibilityModifier _visibility_modifier_,
         TStatic _static_,
         TRef _ref_,
         TOut _out_,
         TConst _const_,
         PType _type_,
         TIdentifier _name_,
         PExp _init_
 )
 {
     SetVisibilityModifier(_visibility_modifier_);
     SetStatic(_static_);
     SetRef(_ref_);
     SetOut(_out_);
     SetConst(_const_);
     SetType(_type_);
     SetName(_name_);
     SetInit(_init_);
 }
        public void SetThen(PExp node)
        {
            if (_then_ != null)
            {
                _then_.Parent(null);
            }

            if (node != null)
            {
                if (node.Parent() != null)
                {
                    node.Parent().RemoveChild(node);
                }

                node.Parent(this);
            }

            _then_ = node;
        }
 public ADelegateInvokeExp(
         TIdentifier _token_,
         PExp _receiver_,
         IList _args_
 )
 {
     SetToken(_token_);
     SetReceiver(_receiver_);
     this._args_ = new TypedList(new Args_Cast(this));
     this._args_.Clear();
     this._args_.AddAll(_args_);
 }
 public AIfThenElseStm(
         TLParen _token_,
         PExp _condition_,
         PStm _then_body_,
         PStm _else_body_
 )
 {
     SetToken(_token_);
     SetCondition(_condition_);
     SetThenBody(_then_body_);
     SetElseBody(_else_body_);
 }
        public void SetReceiver(PExp node)
        {
            if (_receiver_ != null)
            {
                _receiver_.Parent(null);
            }

            if (node != null)
            {
                if (node.Parent() != null)
                {
                    node.Parent().RemoveChild(node);
                }

                node.Parent(this);
            }

            _receiver_ = node;
        }
 public AALocalDeclRight(
         TIdentifier _name_,
         PAssignop _assignop_,
         PExp _init_
 )
 {
     SetName(_name_);
     SetAssignop(_assignop_);
     SetInit(_init_);
 }
 internal override void RemoveChild(Node child)
 {
     if (_token_ == child)
     {
         _token_ = null;
         return;
     }
     if (_receiver_ == child)
     {
         _receiver_ = null;
         return;
     }
     if (_args_.Contains(child))
     {
         _args_.Remove(child);
         return;
     }
 }
 internal override void RemoveChild(Node child)
 {
     if (_token_ == child)
     {
         _token_ = null;
         return;
     }
     if (_condition_ == child)
     {
         _condition_ = null;
         return;
     }
     if (_body_ == child)
     {
         _body_ = null;
         return;
     }
 }
 public ADeleteStm(
         TDelete _token_,
         PExp _exp_
 )
 {
     SetToken(_token_);
     SetExp(_exp_);
 }
            private void MoveOut(PExp exp, PType type)
            {
                PStm pStm = Util.GetAncestor<PStm>(exp);
                AABlock pBlock = (AABlock)pStm.Parent();

                ALocalLvalue lvalue = new ALocalLvalue(new TIdentifier("gppVar"));
                ALvalueExp lvalueExp = new ALvalueExp(lvalue);
                exp.ReplaceBy(lvalueExp);
                AALocalDecl decl = new AALocalDecl(new APublicVisibilityModifier(), null, null, null, null, Util.MakeClone(type, data), new TIdentifier("gppVar"), exp);
                pBlock.GetStatements().Insert(pBlock.GetStatements().IndexOf(pStm), new ALocalDeclStm(new TSemicolon(";"), decl));

                data.LvalueTypes[lvalue] =
                    data.ExpTypes[lvalueExp] = decl.GetType();
                data.LocalLinks[lvalue] = decl;
            }
 public AEnrichmentDecl(
         TEnrichment _token_,
         PExp _dimention_,
         TIntegerLiteral _int_dim_,
         TRBrace _end_token_,
         PType _type_,
         IList _decl_
 )
 {
     SetToken(_token_);
     SetDimention(_dimention_);
     SetIntDim(_int_dim_);
     SetEndToken(_end_token_);
     SetType(_type_);
     this._decl_ = new TypedList(new Decl_Cast(this));
     this._decl_.Clear();
     this._decl_.AddAll(_decl_);
 }