Ejemplo n.º 1
0
        public override void CaseAMultiLocalDecl(AMultiLocalDecl node)
        {
            PStm pStm = Util.GetAncestor <PStm>(node);

            if (!(pStm.Parent() is AABlock))
            {
                return;
            }
            AABlock            pBlock   = (AABlock)pStm.Parent();
            List <AALocalDecl> newDecls = new List <AALocalDecl>();

            foreach (AALocalDeclRight right in node.GetLocalDeclRight())
            {
                if (right.GetName() == null)
                {
                    continue;
                }
                if ((right.GetAssignop() == null) != (right.GetInit() == null))
                {
                    continue;
                }
                AALocalDecl localDecl = new AALocalDecl(new APublicVisibilityModifier(), null, null, null,
                                                        node.GetConst() != null
                                                            ? (TConst)node.GetConst().Clone()
                                                            : null,
                                                        (PType)node.GetType().Clone(),
                                                        right.GetName(),
                                                        right.GetInit());
                newDecls.Add(localDecl);
                pBlock.GetStatements().Insert(pBlock.GetStatements().IndexOf(pStm), new ALocalDeclStm(new TSemicolon(";"), localDecl));
            }
            pBlock.RemoveChild(pStm);
            foreach (AALocalDecl localDecl in newDecls)
            {
                localDecl.Apply(this);
            }
        }
Ejemplo n.º 2
0
        public override void OutAShadySAssignmentExp(AShadySAssignmentExp node)
        {
            if (node.GetLocalDeclRight().Count == 1 &&
                ((AALocalDeclRight)node.GetLocalDeclRight()[0]).GetName() == null)
            {
                //Assignment expression

                //an assignment can't be const);
                //An assignment must have a right side
                if (((AALocalDeclRight)node.GetLocalDeclRight()[0]).GetInit() == null ||
                    ((AALocalDeclRight)node.GetLocalDeclRight()[0]).GetAssignop() == null)
                {
                    node.Parent().RemoveChild(node);
                    return;
                }
                ASAssignmentExp exp = new ASAssignmentExp(
                    ((AALocalDeclRight)node.GetLocalDeclRight()[0]).GetAssignop(), node.GetLvalue(),
                    ((AALocalDeclRight)node.GetLocalDeclRight()[0]).GetInit());
                node.ReplaceBy(exp);
                exp.Apply(this);
            }
            else
            {
                //Local decl
                AMultiLocalDecl localDecl = new AMultiLocalDecl(node.GetConst(), LvalueToType(node.GetLvalue(), node.GetPostPointers(), node.GetGenericToken(), node.GetGenericTypes()),
                                                                new ArrayList());
                while (node.GetLocalDeclRight().Count > 0)
                {
                    localDecl.GetLocalDeclRight().Add(node.GetLocalDeclRight()[0]);
                }

                AExpStm       expStm       = Util.GetAncestor <AExpStm>(node);
                ALocalDeclStm localDeclStm = new ALocalDeclStm(expStm.GetToken(), localDecl);
                expStm.ReplaceBy(localDeclStm);
                localDeclStm.Apply(this);
            }
        }