public override SyntaxNode VisitLocalDeclarationStatement(LocalDeclarationStatementSyntax node) { if (node.Declaration.Variables.Count == 1) { IDSLHandler dsl = null; dsl = ctx_.CreateDSL(node.Declaration.Type.ToString()); if (dsl != null) { if (node.Declaration.Variables.Count != 1) { //td: error return(node); } var variable = node.Declaration.Variables[0]; DSLContext dctx = new DSLContext { MainNode = variable, Surroundings = DSLSurroundings.Code, Assign = false, ExtraMembers = members_ }; Debug.Assert(pending_ == null); pending_ = new ResolveDSLCode(dsl, ctx_, dctx); return(dsl.compile(ctx_, dctx)); } } return(base.VisitLocalDeclarationStatement(node)); }
public override SyntaxNode VisitMethodDeclaration(MethodDeclarationSyntax node) { //handle language constructs string typeName = node.ReturnType.ToString(); switch (typeName) { case "on": return(rewriteEventHandler(node)); case "function": return(rewriteFunction(node, false)); case "method": return(rewriteFunction(node, true)); case "typedef": return(rewriteTypedef(node)); case "": { switch (node.Identifier.ToString()) { case "constructor": return(rewriteConstructor(node)); } break; } } //handle dsls IDSLHandler dsl = null; DSLSurroundings ds = node.Parent is CompilationUnitSyntax ? DSLSurroundings.Global : DSLSurroundings.TypeBody; string id = null; if (!node.ReturnType.IsMissing) { dsl = ctx_.CreateDSL(typeName); id = node.Identifier.ToString(); } else { dsl = ctx_.CreateDSL(node.Identifier.ToString()); } if (dsl != null) { DSLContext dctx = new DSLContext { MainNode = node, Surroundings = ds, Id = id, ExtraMembers = members_ }; return(dsl.compile(ctx_, dctx)); } return(node.WithBody((BlockSyntax)base.Visit(node.Body))); }
private SyntaxNode rewriteInvocation(InvocationExpressionSyntax node, bool assign) { IDSLHandler dsl = ctx_.CreateDSL(node.Expression.ToString()); if (dsl != null) { DSLContext dctx = new DSLContext { MainNode = node, Surroundings = DSLSurroundings.Code, Assign = assign, ExtraMembers = members_ }; Debug.Assert(pending_ == null); pending_ = new ResolveDSLCode(dsl, ctx_, dctx); return(dsl.compile(ctx_, dctx)); } else if (node.ArgumentList.GetDiagnostics().Any()) { return(SyntaxFactory.InvocationExpression(node.Expression, (ArgumentListSyntax)Visit(node.ArgumentList))); } return(node); }