Skip to content

Commit

Permalink
fix too many local variables for static method
Browse files Browse the repository at this point in the history
  • Loading branch information
yanghuan committed Dec 18, 2019
1 parent 1ca6da2 commit e3da7fc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
3 changes: 2 additions & 1 deletion CSharp.lua/LuaAst/LuaTypeDeclarationSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,9 @@ protected void AddResultTable(LuaKeyValueTableItemSyntax item) {

private void CheckTooManyVariables(bool isLocalOrUpvalues) {
if (!hasTooManyLocalVariables_) {
local_.Variables.Add(LuaIdentifierNameSyntax.MorenManyLocalVarTempTable);
methodList_.Statements.Add(new LuaShortCommentStatement(isLocalOrUpvalues ? " too many local variables (limit is 200)" : "too many upvalues (limit is 60)"));
methodList_.Statements.Add(new LuaLocalVariableDeclaratorSyntax(LuaIdentifierNameSyntax.MorenManyLocalVarTempTable, LuaTableExpression.Empty));
methodList_.Statements.Add(LuaIdentifierNameSyntax.MorenManyLocalVarTempTable.Assignment(LuaTableExpression.Empty));
hasTooManyLocalVariables_ = true;
}
}
Expand Down
30 changes: 19 additions & 11 deletions CSharp.lua/LuaSyntaxNodeTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2860,15 +2860,8 @@ private IMethodSymbol GetDelegateTargetMethodSymbol(CSharpSyntaxNode node) {
}
}

private LuaExpressionSyntax BuildDelegateNameExpression(IMethodSymbol symbol, LuaExpressionSyntax target, LuaExpressionSyntax name, CSharpSyntaxNode node) {
private void CheckDelegateBind(IMethodSymbol symbol, CSharpSyntaxNode node, ref LuaExpressionSyntax nameExpression) {
const int kReturnParameterIndex = int.MaxValue;
LuaExpressionSyntax nameExpression;
if (symbol.IsStatic) {
nameExpression = name;
} else {
nameExpression = new LuaInvocationExpressionSyntax(LuaIdentifierNameSyntax.DelegateMake, target, name);
}

if (symbol.IsGenericMethod) {
var originalDefinition = symbol.OriginalDefinition;
if (!originalDefinition.Equals(symbol)) {
Expand Down Expand Up @@ -2945,18 +2938,21 @@ private LuaExpressionSyntax BuildDelegateNameExpression(IMethodSymbol symbol, Lu
string bindMethodName = LuaIdentifierNameSyntax.DelegateBind.ValueText + placeholders.Count;
var invocationExpression = new LuaInvocationExpressionSyntax(bindMethodName, nameExpression);
invocationExpression.AddArguments(placeholders.Select(i => i.Build(this)));
return invocationExpression;
nameExpression = invocationExpression;
return;
}
} else if (symbol.Parameters.Length == 2) {
if (placeholders.Count == 2) {
if (placeholders[0].TypeParameterIndex == 2 && placeholders[1].TypeParameterIndex == 1) {
string bindMethodName = LuaIdentifierNameSyntax.DelegateBind.ValueText + "2_1";
return new LuaInvocationExpressionSyntax(bindMethodName, nameExpression);
nameExpression = new LuaInvocationExpressionSyntax(bindMethodName, nameExpression);
return;
}
} else if (placeholders.Count == 1) {
if (placeholders.First().TypeParameterIndex == 2) {
string bindMethodName = LuaIdentifierNameSyntax.DelegateBind.ValueText + "0_2";
return new LuaInvocationExpressionSyntax(bindMethodName, nameExpression);
nameExpression = new LuaInvocationExpressionSyntax(bindMethodName, nameExpression);
return;
}
}
}
Expand All @@ -2967,7 +2963,16 @@ private LuaExpressionSyntax BuildDelegateNameExpression(IMethodSymbol symbol, Lu
}
}
}
}

private LuaExpressionSyntax BuildDelegateNameExpression(IMethodSymbol symbol, LuaExpressionSyntax target, LuaExpressionSyntax name, CSharpSyntaxNode node) {
LuaExpressionSyntax nameExpression;
if (symbol.IsStatic) {
nameExpression = name;
} else {
nameExpression = new LuaInvocationExpressionSyntax(LuaIdentifierNameSyntax.DelegateMake, target, name);
}
CheckDelegateBind(symbol, node, ref nameExpression);
return nameExpression;
}

Expand All @@ -2990,6 +2995,9 @@ private LuaExpressionSyntax GetMethodNameExpression(IMethodSymbol symbol, NameSy
}
return new LuaInternalMethodExpressionSyntax(methodName);
}
if (CurTypeSymbol.IsContainsInternalSymbol(symbol) && IsMoreThanLocalVariables(symbol)) {
return LuaIdentifierNameSyntax.MorenManyLocalVarTempTable.MemberAccess(methodName);
}
return methodName;
} else {
if (IsInternalMember(symbol)) {
Expand Down

0 comments on commit e3da7fc

Please sign in to comment.