Skip to content

Clear templates after using them #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CppHeaderParser/CppHeaderParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2346,6 +2346,10 @@ def _evaluate_method_stack(self):
)
newMethod["parent"] = None
self.functions.append(newMethod)

# Reset template once it has been used
self.curTemplate = None

global parseHistory
parseHistory.append(
{
Expand Down Expand Up @@ -2549,6 +2553,7 @@ def _evaluate_class_stack(self):
self._get_location(self.nameStack),
self.curAccessSpecifier,
)
self.curTemplate = None
newClass["declaration_method"] = self.nameStack[0]
self.classes_order.append(newClass) # good idea to save ordering
self.stack = [] # fixes if class declared with ';' in closing brace
Expand Down
32 changes: 32 additions & 0 deletions test/test_CppHeaderParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3978,5 +3978,37 @@ def test_fn(self):
self.assertEqual("N1::N2", c["namespace"])


class TemplateMustBeCleared(unittest.TestCase):
def setUp(self):
self.cppHeader = CppHeaderParser.CppHeader(
"""
template <int States, int Inputs> class LinearPlantInversionFeedforward {
public:
template <int Outputs>
LinearPlantInversionFeedforward(
const LinearSystem<States, Inputs, Outputs> &plant, units::second_t dt)
: LinearPlantInversionFeedforward(plant.A(), plant.B(), dt) {}
LinearPlantInversionFeedforward(
const Eigen::Matrix<double, States, States> &A,
const Eigen::Matrix<double, States, Inputs> &B, units::second_t dt)
: m_dt(dt) {
DiscretizeAB<States, Inputs>(A, B, dt, &m_A, &m_B);
m_r.setZero();
Reset(m_r);
}
};
""",
"string",
)

def test_fn(self):
c = self.cppHeader.classes["LinearPlantInversionFeedforward"]
self.assertEqual("LinearPlantInversionFeedforward", c["name"])
self.assertEqual("template<int Outputs>", c["methods"]["public"][0]["template"])
self.assertEqual(False, c["methods"]["public"][1]["template"])


if __name__ == "__main__":
unittest.main()
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy