From 8aa0dcff397a6dbb1c262588e45110a6f673f6f9 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Sun, 9 Jul 2017 18:38:46 -0700 Subject: Fix up scoping for cross-compiled `main()` body The earier changes to add sequence statements and change how the `isBuildingStmt` logic in lowering works doesn't work for this logic, which assumes it can just set `isBuildingStmt` and be sure that decls will go into the right place. --- source/slang/lower.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'source') diff --git a/source/slang/lower.cpp b/source/slang/lower.cpp index 55dabb826..60f86ad17 100644 --- a/source/slang/lower.cpp +++ b/source/slang/lower.cpp @@ -1714,10 +1714,14 @@ struct LoweringVisitor if (loweredEntryPointFunc->getName() == "main") loweredEntryPointFunc->Name.Content = "main_"; + RefPtr bodyStmt = new BlockStmt(); + bodyStmt->scopeDecl = new ScopeDecl(); + // We will want to generate declarations into the body of our new `main()` LoweringVisitor subVisitor = *this; subVisitor.isBuildingStmt = true; subVisitor.stmtBeingBuilt = nullptr; + subVisitor.parentDecl = bodyStmt->scopeDecl; // The parameters of the entry-point function will be translated to // both a local variable (for passing to/from the entry point func), @@ -1839,7 +1843,9 @@ struct LoweringVisitor VaryingParameterDirection::Output); } - mainDecl->Body = subVisitor.stmtBeingBuilt; + bodyStmt->body = subVisitor.stmtBeingBuilt; + + mainDecl->Body = bodyStmt; // Once we are done building the body, we append our new declaration to the program. -- cgit v1.2.3