本文整理汇总了C#中Galaxy_Editor_2.Compiler.Generated.node.AMethodDecl.Apply方法的典型用法代码示例。如果您正苦于以下问题:C# AMethodDecl.Apply方法的具体用法?C# AMethodDecl.Apply怎么用?C# AMethodDecl.Apply使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Galaxy_Editor_2.Compiler.Generated.node.AMethodDecl
的用法示例。
在下文中一共展示了AMethodDecl.Apply方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Parse
public static bool Parse(AMethodDecl method)
{
StatementRemover remover = new StatementRemover();
method.Apply(remover);
return remover.changedSomething;
}
示例2: CaseAOperatorDecl
public override void CaseAOperatorDecl(AOperatorDecl node)
{
if (node.GetFormals().Count != 2)
errors.Add(new ErrorCollection.Error(node.GetToken(), LocRM.GetString("ErrorText182")));
Token token = null;
if (node.GetOperator() is APlusBinop)
token = ((APlusBinop)node.GetOperator()).GetToken();
else if (node.GetOperator() is AMinusBinop)
token = ((AMinusBinop)node.GetOperator()).GetToken();
else if (node.GetOperator() is ADivideBinop)
token = ((ADivideBinop)node.GetOperator()).GetToken();
else if (node.GetOperator() is ATimesBinop)
token = ((ATimesBinop)node.GetOperator()).GetToken();
else if (node.GetOperator() is AModuloBinop)
token = ((AModuloBinop)node.GetOperator()).GetToken();
else if (node.GetOperator() is AEqBinop)
token = ((AEqBinop)node.GetOperator()).GetToken();
else if (node.GetOperator() is ANeBinop)
token = ((ANeBinop)node.GetOperator()).GetToken();
else if (node.GetOperator() is ALtBinop)
token = ((ALtBinop)node.GetOperator()).GetToken();
else if (node.GetOperator() is ALeBinop)
token = ((ALeBinop)node.GetOperator()).GetToken();
else if (node.GetOperator() is AGtBinop)
token = ((AGtBinop)node.GetOperator()).GetToken();
else if (node.GetOperator() is AGeBinop)
token = ((AGeBinop)node.GetOperator()).GetToken();
else if (node.GetOperator() is AGtBinop)
token = ((AGtBinop)node.GetOperator()).GetToken();
else if (node.GetOperator() is AAndBinop)
token = ((AAndBinop)node.GetOperator()).GetToken();
else if (node.GetOperator() is AOrBinop)
token = ((AOrBinop)node.GetOperator()).GetToken();
else if (node.GetOperator() is AXorBinop)
token = ((AXorBinop)node.GetOperator()).GetToken();
else if (node.GetOperator() is ALBitShiftBinop)
token = ((ALBitShiftBinop)node.GetOperator()).GetToken();
else if (node.GetOperator() is ARBitShiftBinop)
token = ((ARBitShiftBinop)node.GetOperator()).GetToken();
AMethodDecl replacer = new AMethodDecl(node.GetVisibilityModifier(), null, node.GetStatic(), null, null,
null, node.GetReturnType(),
new TIdentifier(token.Text, token.Line, token.Pos), new ArrayList(),
node.GetBlock());
while (node.GetFormals().Count > 0)
replacer.GetFormals().Add(node.GetFormals()[0]);
node.ReplaceBy(replacer);
replacer.Apply(this);
}
示例3: Parser
public Parser(AMethodDecl start)
{
start.Apply(this);
}
示例4: CaseAMethodDecl
//.........这里部分代码省略.........
//If we have an assignment to a local where the stored result is never used, remove the assignment
//Since we changed some statements, rebuild stuff
before.Clear();
after.Clear();
uses.Clear();
intersectingLocals.Clear();
definedLocals.Clear();
renamedLocals.Clear();
assigns.Clear();
changes = false;
//Make uses
setUses = true;
base.CaseAMethodDecl(node);
setUses = false;
//Build a list of what's visible
do
{
changes = false;
base.CaseAMethodDecl(node);
} while (changes);
PStm[] stms = new PStm[before.Keys.Count];
before.Keys.CopyTo(stms, 0);
foreach (PStm stm in stms)
{
if (assigns[stm] != null && //Assignment exp
!after[stm].Contains(assigns[stm]) && //Assignment unused
Util.GetAncestor<AMethodDecl>(assigns[stm]) != null &&
!(stm is ALocalDeclStm))//It is to a local
{
stm.Apply(new MoveMethodDeclsOut(finalTrans.data));
stm.Parent().RemoveChild(stm);
}
}
//Remove foo = foo;
RemoveStupidAssignments assignmentRemover = new RemoveStupidAssignments(finalTrans.data);
node.Apply(assignmentRemover);
//Remove unused local variables
foreach (AALocalDecl local in definedLocals)
{
if (Util.GetAncestor<AAProgram>(local) != null && Util.GetAncestor<AABlock>(local) != null &&
!finalTrans.data.LocalLinks.Where(p => p.Value == local).Any(p => Util.GetAncestor<AAProgram>(p.Key) != null))
local.Parent().Parent().RemoveChild(local.Parent());
}
if (assignmentRemover.RemovedOne)
{
CaseAMethodDecl(node);
return;
}
//If an assignment to a variable is completely local, and that assignment is only used once, put the assignment where it is used
//Since we changed some statements, rebuild stuff
before.Clear();
after.Clear();
uses.Clear();
intersectingLocals.Clear();
definedLocals.Clear();
renamedLocals.Clear();
assigns.Clear();
changes = false;
示例5: CaseAOperatorDecl
public override void CaseAOperatorDecl(AOperatorDecl node)
{
AMethodDecl replacer = new AMethodDecl(node.GetVisibilityModifier(), null, node.GetStatic(), null, null,
null, node.GetReturnType(),
new TIdentifier(""), new ArrayList(),
node.GetBlock());
while (node.GetFormals().Count > 0)
replacer.GetFormals().Add(node.GetFormals()[0]);
node.ReplaceBy(replacer);
replacer.Apply(this);
}
示例6: CaseAConstructorDecl
public override void CaseAConstructorDecl(AConstructorDecl node)
{
AStructDecl str = Util.GetAncestor<AStructDecl>(node);
AEnrichmentDecl enrichment = Util.GetAncestor<AEnrichmentDecl>(node);
AMethodDecl replacer = new AMethodDecl(new APublicVisibilityModifier(), null, null, null, null, null, new AVoidType(new TVoid("void")),
node.GetName(), new ArrayList(), node.GetBlock());
replacer.GetName().Text += "_Constructor";
while (node.GetFormals().Count > 0)
{
replacer.GetFormals().Add(node.GetFormals()[0]);
}
//Move the method outside the struct
AASourceFile file = Util.GetAncestor<AASourceFile>(node);
if (str != null)
str.RemoveChild(node.Parent());
else
enrichment.RemoveChild(node);
int i = file.GetDecl().IndexOf(str ?? (PDecl)enrichment);
file.GetDecl().Insert(i/* + 1*/, replacer);
//Add the struct as a parameter
PType type;
if (str != null)
{
ANamedType structType = new ANamedType(new TIdentifier(str.GetName().Text), null);
finalTrans.data.StructTypeLinks[structType] = str;
type = structType;
}
else
{
type = Util.MakeClone(enrichment.GetType(), finalTrans.data);
}
finalTrans.data.ConstructorMap[node] = replacer;
structFormal = new AALocalDecl(new APublicVisibilityModifier(), null, null, null, null, new APointerType(new TStar("*"), type), new TIdentifier("currentStruct", replacer.GetName().Line, replacer.GetName().Pos), null);
replacer.GetFormals().Add(structFormal);
finalTrans.data.Methods.Add(new SharedData.DeclItem<AMethodDecl>(file, replacer));
//Add return stm
replacer.SetReturnType(new APointerType(new TStar("*"), Util.MakeClone(type, data)));
replacer.Apply(new TransformConstructorReturns(structFormal, data));
//Insert call to base constructor););
if (finalTrans.data.ConstructorBaseLinks.ContainsKey(node))
{
AMethodDecl baseConstructor = finalTrans.data.ConstructorMap[finalTrans.data.ConstructorBaseLinks[node]];
ASimpleInvokeExp invoke = new ASimpleInvokeExp(new TIdentifier(baseConstructor.GetName().Text), new ArrayList());
while (node.GetBaseArgs().Count > 0)
{
invoke.GetArgs().Add(node.GetBaseArgs()[0]);
}
AThisLvalue thisLvalue1 = new AThisLvalue(new TThis("this"));
ALvalueExp thisExp1 = new ALvalueExp(thisLvalue1);
invoke.GetArgs().Add(thisExp1);
AThisLvalue thisLvalue2 = new AThisLvalue(new TThis("this"));
AAssignmentExp assignExp = new AAssignmentExp(new TAssign("="), thisLvalue2, invoke);
ANamedType structType = new ANamedType(new TIdentifier(str.GetName().Text), null);
finalTrans.data.StructTypeLinks[structType] = str;
finalTrans.data.LvalueTypes[thisLvalue1] =
finalTrans.data.LvalueTypes[thisLvalue2] =
finalTrans.data.ExpTypes[thisExp1] =
finalTrans.data.ExpTypes[assignExp] =
finalTrans.data.ExpTypes[invoke] = new APointerType(new TStar("*"), structType);
//finalTrans.data.ExpTypes[invoke] = new AVoidType(new TVoid("void"));
finalTrans.data.SimpleMethodLinks[invoke] = baseConstructor;
((AABlock)replacer.GetBlock()).GetStatements().Insert(0, new AExpStm(new TSemicolon(";"), assignExp));
//Inline if base and current are two different kinds of pointer types (int/string)
AStructDecl baseStruct = null;
AConstructorDecl baseC = finalTrans.data.ConstructorBaseLinks[node];
foreach (KeyValuePair<AStructDecl, List<AConstructorDecl>> pair in finalTrans.data.StructConstructors)
{
bool found = false;
foreach (AConstructorDecl decl in pair.Value)
{
if (baseC == decl)
{
found = true;
break;
}
}
if (found)
{
baseStruct = pair.Key;
break;
}
}
if ((str.GetIntDim() == null) != (baseStruct.GetIntDim() == null))
{
//For the inilining, change the type to the type of the caller
AALocalDecl lastFormal = baseConstructor.GetFormals().OfType<AALocalDecl>().Last();
lastFormal.SetRef(new TRef("ref"));
APointerType oldType = (APointerType) lastFormal.GetType();
structType = new ANamedType(new TIdentifier(str.GetName().Text), null);
//.........这里部分代码省略.........
示例7: IsThisOnLeftSide
//.........这里部分代码省略.........
typeof (ASyncInvokeExp),
typeof(AArrayLvalue),
typeof(APointerLvalue),
typeof(APropertyLvalue),
typeof(AStructLvalue));
if (iParent == null)
return;
if (iParent is AAssignmentExp)
{
AAssignmentExp aParent = (AAssignmentExp) iParent;
if (Util.IsAncestor(node, aParent.GetLvalue()))
{
IsAssignedTo = true;
}
return;
}
if (iParent is ASimpleInvokeExp)
{
ASimpleInvokeExp aParent = (ASimpleInvokeExp) iParent;
AMethodDecl method = data.SimpleMethodLinks[aParent];
if (investigatedMethods.Contains(method))
return;
if (Util.IsAncestor(node, aParent.GetLvalue()))
{
IsAssignedTo = true;
}
return;
}
}
private Node GetClosestNodeOfType(Node node, params Type[] types)
{
if (node == null)
return null;
if (types.Contains(node.GetType()))
return node;
return GetClosestNodeOfType(node.Parent(), types);
}
}*/
public override void CaseADeconstructorDecl(ADeconstructorDecl node)
{
AStructDecl str = Util.GetAncestor<AStructDecl>(node);
AEnrichmentDecl enrichment = Util.GetAncestor<AEnrichmentDecl>(node);
AMethodDecl replacer = new AMethodDecl(new APublicVisibilityModifier(), null, null, null, null, null, new AVoidType(new TVoid("void")),
node.GetName(), new ArrayList(), node.GetBlock());
replacer.GetName().Text += "_Deconstructor";
//Move the method outside the struct
AASourceFile file = Util.GetAncestor<AASourceFile>(node);
if (str != null)
str.RemoveChild(node.Parent());
/*else
enrichment.RemoveChild(node);*/
int i = file.GetDecl().IndexOf(str ?? (PDecl)enrichment);
file.GetDecl().Insert(i/* + 1*/, replacer);
//Add the struct as a parameter
PType type;
if (str != null)
{
ANamedType structType = new ANamedType(new TIdentifier(str.GetName().Text), null);
finalTrans.data.StructTypeLinks[structType] = str;
type = structType;
}
else
{
type = Util.MakeClone(enrichment.GetType(), finalTrans.data);
}
finalTrans.data.DeconstructorMap[node] = replacer;
AALocalDecl structFormal = new AALocalDecl(new APublicVisibilityModifier(), null, null, null, null, new APointerType(new TStar("*"), type), new TIdentifier("currentStruct", replacer.GetName().Line, replacer.GetName().Pos), null);
replacer.GetFormals().Add(structFormal);
finalTrans.data.Methods.Add(new SharedData.DeclItem<AMethodDecl>(file, replacer));
//Call base deconstructor before each return
if (str != null && str.GetBase() != null)
{
AStructDecl baseStruct = data.StructTypeLinks[(ANamedType) str.GetBase()];
if (data.StructDeconstructor.ContainsKey(baseStruct))
{
baseStruct.Apply(this);
replacer.Apply(new CallDeconstructors(baseStruct, structFormal, data));
/*AMethodDecl baseDeconstructor = data.DeconstructorMap[data.StructDeconstructor[baseStruct]];
ALocalLvalue structFormalRef = new ALocalLvalue(new TIdentifier("currentStruct"));
ALvalueExp structFormalRefExp = new ALvalueExp(structFormalRef);
ASimpleInvokeExp invoke = new ASimpleInvokeExp(new TIdentifier("baseDeconstructor"),
new ArrayList() {structFormalRefExp});
AABlock block = (AABlock) replacer.GetBlock();
block.GetStatements().Insert(0, new AExpStm(new TSemicolon(";"), invoke));
data.LocalLinks[structFormalRef] = structFormal;
data.SimpleMethodLinks[invoke] = baseDeconstructor;
data.LvalueTypes[structFormalRef] = data.ExpTypes[structFormalRefExp] = structFormal.GetType();
data.ExpTypes[invoke] = baseDeconstructor.GetReturnType();*/
}
}
this.structFormal = structFormal;
base.CaseAMethodDecl(replacer);
}
示例8: CaseAMethodDecl
public override void CaseAMethodDecl(AMethodDecl node)
{
if (node.GetInline() == null && node.GetTrigger() == null && !(data.ConstructorMap.ContainsValue(node) && !inlineConstructors) && node != finalTrans.mainEntry)
{
CountStatements counter = new CountStatements();
node.Apply(counter);
if (counter.Count <= 2)
{
//Don't inline if it has a recurssive call to itself
FindRecurssiveCall recurssiveCallSearcher = new FindRecurssiveCall(node, data);
node.Apply(recurssiveCallSearcher);
if (!recurssiveCallSearcher.InlinedCallToItself)
{
node.SetInline(new TInline("inline"));
}
}
}
base.CaseAMethodDecl(node);
}