public override void CaseANonstaticInvokeExp(ANonstaticInvokeExp node) { node.GetReceiver().Apply(this); node.GetDotType().Apply(this); Value += node.GetName().Text + "("; bool first = true; foreach (PExp arg in node.GetArgs()) { if (!first) { Value += ", "; } else { first = false; } arg.Apply(this); } Value += ")"; }
public override void CaseANonstaticInvokeExp(ANonstaticInvokeExp node) { PExp reciever = node.GetReceiver(); PType type = finalTrans.data.ExpTypes[reciever]; //If the reciever is not a var, put it in a new var. if (!(reciever is ALvalueExp)) { AALocalDecl localDecl = new AALocalDecl(new APublicVisibilityModifier(), null, null, null, null, Util.MakeClone(type, data), new TIdentifier("nonstaticInvokeVar"), reciever); ALocalLvalue localRef = new ALocalLvalue(new TIdentifier("nonstaticInvokeVar")); ALvalueExp localRefExp = new ALvalueExp(localRef); node.SetReceiver(localRefExp); PStm pStm = Util.GetAncestor <PStm>(node); AABlock pBlock = (AABlock)pStm.Parent(); pBlock.GetStatements().Insert(pBlock.GetStatements().IndexOf(pStm), new ALocalDeclStm(new TSemicolon(";"), localDecl)); reciever = localRefExp; data.LvalueTypes[localRef] = data.ExpTypes[localRefExp] = type; data.LocalLinks[localRef] = localDecl; localDecl.Apply(this); } if (type is ANamedType && finalTrans.data.StructTypeLinks.ContainsKey((ANamedType)type)) { //ANamedType type = (ANamedType) finalTrans.data.ExpTypes[reciever]; if (finalTrans.data.StructTypeLinks[(ANamedType)type].GetClassToken() != null) { //Pass the pointer ALvalueExp lvalueExp = (ALvalueExp)reciever; APointerLvalue pointerLvalue = (APointerLvalue)lvalueExp.GetLvalue(); reciever = pointerLvalue.GetBase(); } AMethodDecl method = finalTrans.data.StructMethodLinks[node]; ASimpleInvokeExp simpleInvoke = new ASimpleInvokeExp(); simpleInvoke.SetName(node.GetName()); PExp[] exps = new PExp[node.GetArgs().Count]; node.GetArgs().CopyTo(exps, 0); foreach (PExp exp in exps) { simpleInvoke.GetArgs().Add(exp); } simpleInvoke.GetArgs().Add(reciever); node.ReplaceBy(simpleInvoke); finalTrans.data.SimpleMethodLinks[simpleInvoke] = method; finalTrans.data.StructMethodLinks.Remove(node); finalTrans.data.ExpTypes[simpleInvoke] = method.GetReturnType(); finalTrans.data.ExpTypes.Remove(node); simpleInvoke.Apply(this); } else {//Enrichment /*AEnrichmentDecl enrichment = finalTrans.data.EnrichmentTypeLinks[type]; * * foreach (AEnrichmentDecl enrichmentDecl in finalTrans.data.Enrichments) * { * if (Util.IsVisible(node, enrichmentDecl) && * Util.IsDeclVisible(enrichmentDecl, Util.GetAncestor<AASourceFile>(node)) && * Util.TypesEqual(type, enrichmentDecl.GetType(), finalTrans.data)) * { * enrichment = enrichmentDecl; * break; * } * } * if (enrichment == null) * { * finalTrans.errors.Add(new ErrorCollection.Error(node.GetName(), "TransFormMethodDecls.NonStaticInvoke: Expected enrichment - this is a bug. It should have been caught earlier")); * throw new ParserException(node.GetName(), ""); * }*/ AMethodDecl method = finalTrans.data.StructMethodLinks[node]; ASimpleInvokeExp simpleInvoke = new ASimpleInvokeExp(); simpleInvoke.SetName(node.GetName()); PExp[] exps = new PExp[node.GetArgs().Count]; node.GetArgs().CopyTo(exps, 0); foreach (PExp exp in exps) { simpleInvoke.GetArgs().Add(exp); } simpleInvoke.GetArgs().Add(reciever); node.ReplaceBy(simpleInvoke); finalTrans.data.SimpleMethodLinks[simpleInvoke] = method; finalTrans.data.StructMethodLinks.Remove(node); finalTrans.data.ExpTypes[simpleInvoke] = method.GetReturnType(); finalTrans.data.ExpTypes.Remove(node); simpleInvoke.Apply(this); } }
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()); } }