public void AddMethod(int i, ScenarioTag.ScriptMethodDefinition scriptMethod) { var modifiers = SyntaxTokenList.Create(Token(SyntaxKind.PublicKeyword)) .Add(Token(SyntaxKind.AsyncKeyword)); TypeSyntax returnType = ParseTypeName("Task"); if (scriptMethod.ReturnType != ScriptDataType.Void) { returnType = GenericName("Task").AddTypeArgumentListArguments(SyntaxUtil.ScriptTypeSyntax(scriptMethod.ReturnType)); } var method = MethodDeclaration( returnType, SyntaxUtil.SanitizeIdentifier(scriptMethod.Description)) .WithModifiers(modifiers); // Push root method body as first scope var block = new StatementBlockContext(); var rootScope = new Scope(scriptMethod.ReturnType, block, block); var retScope = EvaluateNodes(scriptMethod.SyntaxNodeIndex, rootScope); Debug.Assert(rootScope == retScope, "Last scope wasn't the provided root"); methods.Add(method.WithBody(Block(block.GetInnerStatements())) .AddAttributeLists(AttributeList(SeparatedList(new[] { Attribute(IdentifierName(nameof(ScriptMethodAttribute).Replace("Attribute", ""))) .AddArgumentListArguments( AttributeArgument(SyntaxUtil.LiteralExpression(i)), AttributeArgument(MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, IdentifierName(nameof(Lifecycle)), IdentifierName(scriptMethod.Lifecycle.ToString())))) })))); }
public override Symbol VisitStatementBlock([NotNull] StatementBlockContext context) { callStack.Push(StackFrameScope.Local); base.VisitStatementBlock(context); callStack.Pop(); return(null); }