MCPcopy Create free account
hub / github.com/NatLabRockies/OpenStudio / printTree

Method printTree

src/modelica/ModelicaFileImpl.cpp:75–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73}
74
75std::string ModelicaFileImpl::printTree() const {
76 std::stringstream ss;
77
78 const std::function<void(antlr4::tree::ParseTree*, antlr4::Parser*, int)> to_s = [&ss, &to_s](antlr4::tree::ParseTree* tree, antlr4::Parser* parser,
79 int indent) {
80 if (!tree) {
81 return;
82 }
83
84 // Print indentation
85 for (int i = 0; i < indent; i++) {
86 ss << " ";
87 }
88
89 // Check if the node is a rule (internal) or a leaf (token)
90 auto* ruleContext = dynamic_cast<antlr4::ParserRuleContext*>(tree);
91 if (ruleContext) {
92 // Internal rule node - print rule name
93 ss << "rule: " << parser->getRuleNames()[ruleContext->getRuleIndex()] << std::endl; // NOLINT
94 } else {
95 // Leaf token node - print actual token text
96 ss << "token: " << tree->getText() << std::endl; // NOLINT
97 }
98
99 // Recursively print children with increased indentation
100 for (auto* child : tree->children) {
101 to_s(child, parser, indent + 1);
102 }
103 };
104
105 to_s(m_modelicaParser->stored_definition(), m_modelicaParser.get(), 0);
106
107 return ss.str();
108}
109
110void ModelicaFileImpl::ensureClassDefinitionCache() {
111 if (!m_classDefinitionsDirty) {

Callers

nothing calls this directly

Calls 4

getRuleIndexMethod · 0.80
getTextMethod · 0.45
getMethod · 0.45
strMethod · 0.45

Tested by

no test coverage detected