Skip to content

Commit 7f99a31

Browse files
committed
54: not need isLambda in AstCsToJson
because the lambda decompilation was fixed from inside (see 52)
1 parent 6711987 commit 7f99a31

File tree

1 file changed

+14
-96
lines changed

1 file changed

+14
-96
lines changed

ManualILSpy/ManualILSpy/Extention/AstCsToJson.cs

+14-96
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public partial class AstCsToJsonVisitor : IAstVisitor
3737
Dictionary<string, int> typeReferences = new Dictionary<string, int>();
3838

3939

40-
bool isLambda = false;
40+
4141
public JsonValue LastValue { get; private set; }
4242

4343
public AstCsToJsonVisitor(ITextOutput output)
@@ -135,22 +135,10 @@ JsonValue GetTypeInfoList(List<string> typeInfoList)
135135
}
136136
return typeArr;
137137
}
138-
bool isSuspectLambda = false;
139-
int countLamda = 0;
138+
140139
JsonElement GetIdentifier(Identifier identifier)
141140
{
142-
//TODO: review here
143-
string name = identifier.Name;
144-
if (name[0] == '<' && name[1] == '>')
145-
{
146-
isSuspectLambda = true;
147-
countLamda++;
148-
if (countLamda == 4)
149-
{
150-
151-
}
152-
}
153-
return new JsonElement(name);
141+
return new JsonElement(identifier.Name);
154142
}
155143

156144
JsonValue GetKeyword(TokenRole tokenRole)
@@ -466,18 +454,9 @@ public void VisitDirectionExpression(DirectionExpression directionExpression)
466454
public void VisitIdentifierExpression(IdentifierExpression identifierExpression)
467455
{
468456
JsonValue getIdentifier = GetIdentifier(identifierExpression.IdentifierToken);
469-
if (isLambda)
470-
{
471-
//?
472-
//TODO: review here
473-
Push(getIdentifier);
474-
}
475-
else
476-
{
477-
JsonObject jsonIdenExpr = CreateJsonExpression(identifierExpression);
478-
jsonIdenExpr.AddJsonValue("name", getIdentifier);
479-
Push(jsonIdenExpr);
480-
}
457+
JsonObject jsonIdenExpr = CreateJsonExpression(identifierExpression);
458+
jsonIdenExpr.AddJsonValue("name", getIdentifier);
459+
Push(jsonIdenExpr);
481460
}
482461

483462
public void VisitIndexerExpression(IndexerExpression indexerExpression)
@@ -825,11 +804,10 @@ public void VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration)
825804
{
826805
member.AcceptVisitor(this);
827806
var temp = Pop();
828-
if (temp != null && !isLambda)
807+
if (temp != null)
829808
{
830809
memberList.AddJsonValue(temp);
831810
}
832-
isLambda = false;
833811
}
834812
if (memberList.Count == 0)
835813
{
@@ -838,9 +816,8 @@ public void VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration)
838816
declaration.AddJsonValue("members", memberList);
839817

840818
Push(declaration);
841-
}
842-
843-
Dictionary<string, TypeDeclaration> lambdaClass = new Dictionary<string, TypeDeclaration>();
819+
}
820+
844821
public void VisitTypeDeclaration(TypeDeclaration typeDeclaration)
845822
{
846823
JsonObject declaration = new JsonObject();
@@ -864,18 +841,9 @@ public void VisitTypeDeclaration(TypeDeclaration typeDeclaration)
864841
break;
865842
}
866843
JsonElement identifier = GetIdentifier(typeDeclaration.NameToken);
867-
if (identifier.ElementValue[0] == '<' && identifier.ElementValue[0] == '>')
868-
{
869-
isLambda = true;
870-
}
844+
871845

872-
bool thisTypeIsLamda = false;
873-
if (isLambda)
874-
{
875-
thisTypeIsLamda = true;
876-
lambdaClass[identifier.ElementValue] = typeDeclaration;
877-
isLambda = false;
878-
}
846+
bool thisTypeIsLamda = false;
879847
declaration.AddJsonValue("identifier", identifier);
880848
declaration.AddJsonValue("parameters", GetTypeParameters(typeDeclaration.TypeParameters));
881849
if (typeDeclaration.BaseTypes.Any())
@@ -900,8 +868,7 @@ public void VisitTypeDeclaration(TypeDeclaration typeDeclaration)
900868
{
901869
declaration = null;
902870
}
903-
Push(declaration);
904-
isLambda = false;
871+
Push(declaration);
905872
}
906873

907874
public void VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration)
@@ -1086,59 +1053,10 @@ public void VisitIfElseStatement(IfElseStatement ifElseStatement)
10861053
statement.AddJsonValue("condition", GenExpression(ifElseStatement.Condition));
10871054
statement.AddJsonValue("true-statement", GenStatement(ifElseStatement.TrueStatement));
10881055
statement.AddJsonValue("false-statement", GenStatement(ifElseStatement.FalseStatement));
1089-
//TODO: ckeck lambda
1090-
if (isSuspectLambda)
1091-
{
1092-
1093-
}
1094-
if (isLambda)
1095-
{
1096-
//TODO: review here
1097-
//?
1098-
CreateLamda(statement);
1099-
isLambda = false;
1100-
return;
1101-
}
1102-
1056+
11031057
Push(statement);
11041058
}
1105-
void CreateLamda(JsonObject ifElseNode)
1106-
{
1107-
JsonObject condition = GetValue("condition", ifElseNode);
1108-
JsonObject leftOperand = GetValue("left-operand", condition);
1109-
JsonElement identifier = GetElement("left-operand", leftOperand);
1110-
1111-
JsonObject trueStatement = GetValue("true-statement", ifElseNode);
1112-
JsonArray list = GetArray("statement-list", trueStatement);
1113-
JsonObject statement = (JsonObject)list.ValueList[0];
1114-
JsonObject rigthOperand = GetValue("right-operand", statement);
1115-
JsonObject arguments = GetValue("arguments", rigthOperand);
1116-
JsonElement methodName = GetElement("identifier-name", arguments);
1117-
JsonObject typeInfo = GetValue("type-info", arguments);
1118-
JsonObject memberRef = GetValue("type-info", typeInfo);
1119-
JsonElement memName = GetElement("member-name", memberRef);
1120-
1121-
TypeDeclaration typeDeclare;
1122-
JsonObject lambdaExpression = new JsonObject();
1123-
if (lambdaClass.TryGetValue(memName.ElementValue, out typeDeclare))
1124-
{
1125-
lambdaExpression.Comment = "CreateLamda";
1126-
lambdaExpression.AddJsonValue("expression-type", new JsonElement("lambda-expression"));
1127-
foreach (var member in typeDeclare.Members)
1128-
{
1129-
if (member is MethodDeclaration)
1130-
{
1131-
MethodDeclaration method = (MethodDeclaration)member;
1132-
if (method.Name == methodName.ElementValue)
1133-
{
1134-
lambdaExpression.AddJsonValue("parameters", GetCommaSeparatedList(method.Parameters));
1135-
lambdaExpression.AddJsonValue("body", GenStatement(method.Body));
1136-
}
1137-
}
1138-
}
1139-
Push(lambdaExpression);
1140-
}
1141-
}
1059+
11421060

11431061
JsonObject GetValue(string key, JsonObject obj)
11441062
{

0 commit comments

Comments
 (0)