From 8d6f76e3966648d2710cd86cf943bf8520726049 Mon Sep 17 00:00:00 2001 From: Anna Rift Date: Thu, 25 Nov 2021 11:40:08 -0700 Subject: [PATCH] Add positionContext save/restore around recursion into sub computation #27 --- src/ComputationBuilder.cpp | 2 ++ src/ComputationBuilderTest.cpp | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/ComputationBuilder.cpp b/src/ComputationBuilder.cpp index 78b12ec..467f53a 100644 --- a/src/ComputationBuilder.cpp +++ b/src/ComputationBuilder.cpp @@ -110,8 +110,10 @@ void ComputationBuilder::processSingleStmt(clang::Stmt *stmt) { std::string calleeName = calleeDefinition->getNameAsString(); if (!subComputations.count(calleeName)) { // build Computation from calleeDefinition, if we haven't done so already + PositionContext oldContext = *positionContext; auto builder = new ComputationBuilder(); subComputations[calleeName] = builder->buildComputationFromFunction(calleeDefinition); + *positionContext = oldContext; } std::vector callArgStrings; for (unsigned int i = 0; i < asCallExpr->getNumArgs(); ++i) { diff --git a/src/ComputationBuilderTest.cpp b/src/ComputationBuilderTest.cpp index 76bd57a..b064326 100644 --- a/src/ComputationBuilderTest.cpp +++ b/src/ComputationBuilderTest.cpp @@ -307,7 +307,11 @@ TEST_F(ComputationBuilderTest, basic_nesting) { "{[i]->[1,i,1]}", {{"x", "{[i]->[0]}"}}, {{"_iegen_0x", "{[i]->[0]}"}})); - expectedComputation->addStmt(new iegenlib::Stmt("_iegen_0x*=5;", "{[i]: 0<=i[1,i,2]}", {}, {})); + expectedComputation->addStmt(new iegenlib::Stmt("_iegen_0x*=5;", + "{[i]: 0<=i[1,i,2]}", + {{"_iegen_0x", "{[i]->[0]}"}}, + {{"_iegen_0x", "{[i]->[0]}"}})); expectedComputation->addReturnValue("3", false);