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); } }
public override void CaseAMultiLocalDecl(AMultiLocalDecl node) { InAMultiLocalDecl(node); { Object[] temp = new Object[node.GetLocalDeclRight().Count]; node.GetLocalDeclRight().CopyTo(temp, 0); for (int i = temp.Length - 1; i >= 0; i--) { ((PLocalDeclRight)temp[i]).Apply(this); } } if (node.GetType() != null) { node.GetType().Apply(this); } if (node.GetConst() != null) { node.GetConst().Apply(this); } OutAMultiLocalDecl(node); }
public override void OutAShadySAssignmentExp(AShadySAssignmentExp node) { if (node.GetLocalDeclRight().Count == 1 && ((AALocalDeclRight) node.GetLocalDeclRight()[0]).GetName() == null) { //Assignment expression //Cant have any [] or * after first lvalue if (node.GetPostPointers().Count > 0) { Token token; PShadyDynamicOps op = (PShadyDynamicOps)node.GetPostPointers()[0]; if (op is APointerShadyDynamicOps) token = ((APointerShadyDynamicOps) op).GetToken(); else token = ((AArrayShadyDynamicOps)op).GetToken(); errors.Add(new ErrorCollection.Error(token, currentSourceFile, "Didn't expect " + token.Text + " there. Im very confused.")); } if (node.GetGenericToken() != null) errors.Add(new ErrorCollection.Error(node.GetGenericToken(), "What the hell is this? I didn't see that coming. Or maybe I did.. But I don't like it!")); //an assignment can't be const); if (node.GetConst() != null) errors.Add(new ErrorCollection.Error(node.GetConst(), currentSourceFile, "Unexpected const", false)); //An assignment must have a right side if (((AALocalDeclRight) node.GetLocalDeclRight()[0]).GetInit() == null || ((AALocalDeclRight) node.GetLocalDeclRight()[0]).GetAssignop() == null) { Token token = GetToken(node.GetLvalue()); errors.Add(new ErrorCollection.Error(token, currentSourceFile, "Expected assignment", false)); 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); } }
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); } }