summaryrefslogtreecommitdiffstats
path: root/tools/slang-cpp-extractor/node.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2022-03-15 10:45:24 -0400
committerGitHub <noreply@github.com>2022-03-15 10:45:24 -0400
commit8533dd2344d8be040a992a86f23e7cf696d59c4a (patch)
tree9121a5a5fa98eb4f5101421341142616ac703ba8 /tools/slang-cpp-extractor/node.cpp
parent06d04ab5e63ad43d7ad9de3fbc4c8ed64b13265a (diff)
C++ extractor callable support (#2159)
* #include an absolute path didn't work - because paths were taken to always be relative. * Split doc extractor such that can be used in C++ extractor. * Compiles. Update the stdlib docs. * Fix issue on release builds. * Add support for extracting documentation to C++ extractor. * Dump out markup. Make enum value backing type take tokens. * Node::Type -> Node::Kind * More improvements around Node::Type -> Node::Kind * Support for parsing callable types. * Fix issue params for callable, and default value for variable. * Add support for static. * Improve handling parsing of contained types. * Small improvements around template consumption. * Improve dumping with markup/static. * Small improvements around reflection. * Add more flexible handling of markers. Allow reflection without markers.
Diffstat (limited to 'tools/slang-cpp-extractor/node.cpp')
-rw-r--r--tools/slang-cpp-extractor/node.cpp80
1 files changed, 70 insertions, 10 deletions
diff --git a/tools/slang-cpp-extractor/node.cpp b/tools/slang-cpp-extractor/node.cpp
index 2074b7c41..3fbbf9c56 100644
--- a/tools/slang-cpp-extractor/node.cpp
+++ b/tools/slang-cpp-extractor/node.cpp
@@ -294,7 +294,7 @@ ScopeNode* ScopeNode::getAnonymousNamespace()
return m_anonymousNamespace;
}
-void ScopeNode::addChild(Node* child)
+void ScopeNode::addChildIgnoringName(Node* child)
{
SLANG_ASSERT(child->m_parentScope == nullptr);
// Can't add anonymous namespace this way - should be added via getAnonymousNamespace
@@ -302,6 +302,11 @@ void ScopeNode::addChild(Node* child)
child->m_parentScope = this;
m_children.add(child);
+}
+
+void ScopeNode::addChild(Node* child)
+{
+ addChildIgnoringName(child);
if (child->m_name.hasContent())
{
@@ -316,9 +321,6 @@ Node* ScopeNode::findChild(const UnownedStringSlice& name) const
{
return *nodePtr;
}
-
-
-
return nullptr;
}
@@ -377,8 +379,7 @@ static bool _needsSpace(const Token& prevTok, const Token& tok)
auto loc = tok.getLoc();
auto prevContent = prevTok.getContent();
- auto content = tok.getContent();
-
+
if (prevLoc + prevContent.getLength() == loc)
{
return false;
@@ -494,17 +495,76 @@ void EnumNode::dump(int indent, StringBuilder& out)
out << "}\n";
}
+/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!! CallableNode !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
+
+void CallableNode::dump(int indent, StringBuilder& out)
+{
+ if (!isReflected())
+ {
+ return;
+ }
+
+ dumpMarkup(indent, out);
+
+ _indent(indent, out);
+
+ if (m_isStatic)
+ {
+ out << "static ";
+ }
+ if (m_isVirtual)
+ {
+ out << "virtual ";
+ }
+
+ out << m_returnType << " ";
+ out << m_name.getContent() << "(";
+
+ const Index count = m_params.getCount();
+ for (Index i = 0; i < count; ++i)
+ {
+ if (i > 0)
+ {
+ out << ", ";
+ }
+
+ const auto& param = m_params[i];
+ out << param.m_type;
+ if (param.m_name.type == TokenType::Identifier)
+ {
+ out << " " << param.m_name.getContent();
+ }
+ }
+
+ out << ")";
+
+ if (m_isPure)
+ {
+ out << " = 0";
+ }
+
+ out << "\n";
+}
+
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! FieldNode !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
void FieldNode::dump(int indent, StringBuilder& out)
{
- if (isReflected())
+ if (!isReflected())
{
- dumpMarkup(indent, out);
+ return;
+ }
- _indent(indent, out);
- out << m_fieldType << " " << m_name.getContent() << "\n";
+ dumpMarkup(indent, out);
+
+ _indent(indent, out);
+
+ if (m_isStatic)
+ {
+ out << "static ";
}
+
+ out << m_fieldType << " " << m_name.getContent() << "\n";
}
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ClassLikeNode !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */