summaryrefslogtreecommitdiffstats
path: root/tools/slang-cpp-extractor
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2020-05-19 15:37:40 -0400
committerGitHub <noreply@github.com>2020-05-19 15:37:40 -0400
commitc54c957d2e647d2f9bfdc0bf31561fca5a02c5df (patch)
tree8b54c10f40a005fdac0d9837254c430a837a0a3f /tools/slang-cpp-extractor
parent1de14312917a0427a7a0858615b65261da60f748 (diff)
Reduce the size of Token (#1349)
* Token size on 64 bits is 24 bytes (from 40). On 32 bits is 16 bytes from 24. * Added hasContent method to Token. Some other small improvements around Token.
Diffstat (limited to 'tools/slang-cpp-extractor')
-rw-r--r--tools/slang-cpp-extractor/slang-cpp-extractor-main.cpp92
1 files changed, 47 insertions, 45 deletions
diff --git a/tools/slang-cpp-extractor/slang-cpp-extractor-main.cpp b/tools/slang-cpp-extractor/slang-cpp-extractor-main.cpp
index 814e7ac0e..5118a3a9b 100644
--- a/tools/slang-cpp-extractor/slang-cpp-extractor-main.cpp
+++ b/tools/slang-cpp-extractor/slang-cpp-extractor-main.cpp
@@ -393,9 +393,11 @@ void Node::addChild(Node* child)
child->m_parentScope = this;
m_children.add(child);
- if (child->m_name.Content.getLength())
+ UnownedStringSlice content = child->m_name.getContent();
+
+ if (content.getLength())
{
- m_childMap.Add(child->m_name.Content, child);
+ m_childMap.Add(content, child);
}
}
@@ -441,10 +443,10 @@ static void _indent(Index indentCount, StringBuilder& out)
void Node::dumpDerived(int indentCount, StringBuilder& out)
{
- if (isClassLike() && m_isReflected && m_name.Content.getLength() > 0)
+ if (isClassLike() && m_isReflected && m_name.hasContent())
{
_indent(indentCount, out);
- out << m_name.Content << "\n";
+ out << m_name.getContent() << "\n";
}
for (Node* derivedType : m_derivedTypes)
@@ -465,9 +467,9 @@ void Node::dump(int indentCount, StringBuilder& out)
}
case Type::Namespace:
{
- if (m_name.Content.getLength())
+ if (m_name.hasContent())
{
- out << "namespace " << m_name.Content << " {\n";
+ out << "namespace " << m_name.getContent() << " {\n";
}
else
{
@@ -486,15 +488,15 @@ void Node::dump(int indentCount, StringBuilder& out)
{
out << " (";
}
- out << m_name.Content;
+ out << m_name.getContent();
if (!m_isReflected)
{
out << ") ";
}
- if (m_super.Content.getLength())
+ if (m_super.hasContent())
{
- out << " : " << m_super.Content;
+ out << " : " << m_super.getContent();
}
out << " {\n";
@@ -510,7 +512,7 @@ void Node::dump(int indentCount, StringBuilder& out)
for (const Field& field : m_fields)
{
_indent(indentCount + 1, out);
- out << field.type << " " << field.name.Content << "\n";
+ out << field.type << " " << field.name.getContent() << "\n";
}
_indent(indentCount, out);
@@ -521,11 +523,11 @@ void Node::calcAbsoluteName(StringBuilder& outName) const
{
if (m_parentScope == nullptr)
{
- if (m_name.Content.getLength() == 0)
+ if (!m_name.hasContent())
{
return;
}
- outName << m_name.Content;
+ outName << m_name.getContent();
}
else
{
@@ -536,7 +538,7 @@ void Node::calcAbsoluteName(StringBuilder& outName) const
}
else
{
- outName << m_name.Content;
+ outName << m_name.getContent();
}
}
}
@@ -850,7 +852,7 @@ bool CPPExtractor::advanceIfToken(TokenType type, Token* outToken)
bool CPPExtractor::advanceIfMarker(Token* outToken)
{
const Token peekToken = m_reader.peekToken();
- if (peekToken.type == TokenType::Identifier && _isMarker(peekToken.Content))
+ if (peekToken.type == TokenType::Identifier && _isMarker(peekToken.getContent()))
{
m_reader.advanceToken();
if (outToken)
@@ -866,7 +868,7 @@ bool CPPExtractor::advanceIfStyle(IdentifierStyle style, Token* outToken)
{
if (m_reader.peekTokenType() == TokenType::Identifier)
{
- IdentifierStyle readStyle = m_identifierLookup->get(m_reader.peekToken().Content);
+ IdentifierStyle readStyle = m_identifierLookup->get(m_reader.peekToken().getContent());
if (readStyle == style)
{
Token token = m_reader.advanceToken();
@@ -900,17 +902,17 @@ SlangResult CPPExtractor::pushNode(Node* node)
m_origin->addNode(node);
}
- if (node->m_name.Content.getLength())
+ if (node->m_name.hasContent())
{
// For anonymous namespace, we should look if we already have one and just reopen that. Doing so will mean will
// find anonymous namespace clashes
- if (Node* foundNode = m_currentNode->findChild(node->m_name.Content))
+ if (Node* foundNode = m_currentNode->findChild(node->m_name.getContent()))
{
if (node->isClassLike())
{
- m_sink->diagnose(m_reader.peekToken(), CPPDiagnostics::typeAlreadyDeclared, node->m_name.Content);
- m_sink->diagnose(foundNode->m_name, CPPDiagnostics::seeDeclarationOf, node->m_name.Content);
+ m_sink->diagnose(m_reader.peekToken(), CPPDiagnostics::typeAlreadyDeclared, node->m_name.getContent());
+ m_sink->diagnose(foundNode->m_name, CPPDiagnostics::seeDeclarationOf, node->m_name.getContent());
return SLANG_FAIL;
}
@@ -1126,9 +1128,9 @@ SlangResult CPPExtractor::_maybeParseNode(Node::Type type)
SLANG_RETURN_ON_FAIL(expect(TokenType::Identifier, &typeNameToken));
SLANG_RETURN_ON_FAIL(expect(TokenType::RParent));
- if (typeNameToken.Content != node->m_name.Content)
+ if (typeNameToken.getContent() != node->m_name.getContent())
{
- m_sink->diagnose(typeNameToken, CPPDiagnostics::typeNameDoesntMatch, node->m_name.Content);
+ m_sink->diagnose(typeNameToken, CPPDiagnostics::typeNameDoesntMatch, node->m_name.getContent());
return SLANG_FAIL;
}
@@ -1256,7 +1258,7 @@ UnownedStringSlice CPPExtractor::_concatTokens(TokenReader::ParsingCursor start)
while (!m_reader.isAtCursor(endCursor))
{
const Token token = m_reader.advanceToken();
- buf << token.Content;
+ buf << token.getContent();
}
return m_typePool->getSlice(m_typePool->add(buf));
@@ -1277,7 +1279,7 @@ SlangResult CPPExtractor::_maybeParseType(UnownedStringSlice& outType, Index& io
return SLANG_FAIL;
}
- const IdentifierStyle style = m_identifierLookup->get(identifierToken.Content);
+ const IdentifierStyle style = m_identifierLookup->get(identifierToken.getContent());
if (hasFlag(style, IdentifierFlag::Keyword))
{
return SLANG_FAIL;
@@ -1536,7 +1538,7 @@ SlangResult CPPExtractor::parse(SourceFile* sourceFile, const Options* options)
{
case TokenType::Identifier:
{
- IdentifierStyle style = m_identifierLookup->get(m_reader.peekToken().Content);
+ IdentifierStyle style = m_identifierLookup->get(m_reader.peekToken().getContent());
switch (style)
{
@@ -1646,7 +1648,7 @@ SlangResult CPPExtractor::_calcDerivedTypesRec(Node* node)
{
if (node->isClassLike() && node->m_baseType == Node::BaseType::None)
{
- if (node->m_super.Content.getLength())
+ if (node->m_super.hasContent())
{
Node* parentScope = node->m_parentScope;
if (parentScope == nullptr)
@@ -1655,12 +1657,12 @@ SlangResult CPPExtractor::_calcDerivedTypesRec(Node* node)
return SLANG_FAIL;
}
- Node* superType = parentScope->findChild(node->m_super.Content);
+ Node* superType = parentScope->findChild(node->m_super.getContent());
if (!superType)
{
if (node->m_isReflected)
{
- m_sink->diagnose(node->m_name, CPPDiagnostics::superTypeNotFound, node->m_name.Content);
+ m_sink->diagnose(node->m_name, CPPDiagnostics::superTypeNotFound, node->m_name.getContent());
return SLANG_FAIL;
}
}
@@ -1668,7 +1670,7 @@ SlangResult CPPExtractor::_calcDerivedTypesRec(Node* node)
{
if (!superType->isClassLike())
{
- m_sink->diagnose(node->m_name, CPPDiagnostics::superTypeNotAType, node->m_name.Content);
+ m_sink->diagnose(node->m_name, CPPDiagnostics::superTypeNotAType, node->m_name.getContent());
return SLANG_FAIL;
}
@@ -1864,12 +1866,12 @@ SlangResult CPPExtractorApp::calcDef(CPPExtractor& extractor, SourceOrigin* orig
{
if (node->isClassLike() && node->m_isReflected)
{
- if (node->m_marker.Content.indexOf(UnownedStringSlice::fromLiteral("ABSTRACT")) >= 0)
+ if (node->m_marker.getContent().indexOf(UnownedStringSlice::fromLiteral("ABSTRACT")) >= 0)
{
out << "ABSTRACT_";
}
- out << "SYNTAX_CLASS(" << node->m_name.Content << ", " << node->m_super.Content << ")\n";
+ out << "SYNTAX_CLASS(" << node->m_name.getContent() << ", " << node->m_super.getContent() << ")\n";
out << "END_SYNTAX_CLASS()\n\n";
}
}
@@ -1909,7 +1911,7 @@ SlangResult CPPExtractorApp::calcChildrenHeader(CPPExtractor& extractor, StringB
node->getReflectedDerivedTypes(derivedTypes);
// Define the derived types
- out << "#define " << m_options.m_prefixMark << "CHILDREN_" << reflectTypeName << "_" << node->m_name.Content << "(x, param)";
+ out << "#define " << m_options.m_prefixMark << "CHILDREN_" << reflectTypeName << "_" << node->m_name.getContent() << "(x, param)";
if (derivedTypes.getCount())
{
@@ -1918,7 +1920,7 @@ SlangResult CPPExtractorApp::calcChildrenHeader(CPPExtractor& extractor, StringB
{
Node* derivedType = derivedTypes[j];
_indent(1, out);
- out << m_options.m_prefixMark << "ALL_" << reflectTypeName << "_" << derivedType->m_name.Content << "(x, param)";
+ out << m_options.m_prefixMark << "ALL_" << reflectTypeName << "_" << derivedType->m_name.getContent() << "(x, param)";
if (j < derivedTypes.getCount() - 1)
{
out << "\\\n";
@@ -1933,16 +1935,16 @@ SlangResult CPPExtractorApp::calcChildrenHeader(CPPExtractor& extractor, StringB
for (Node* node : nodes)
{
// Define the derived types
- out << "#define " << m_options.m_prefixMark << "ALL_" << reflectTypeName << "_" << node->m_name.Content << "(x, param) \\\n";
+ out << "#define " << m_options.m_prefixMark << "ALL_" << reflectTypeName << "_" << node->m_name.getContent() << "(x, param) \\\n";
_indent(1, out);
- out << m_options.m_prefixMark << reflectTypeName << "_" << node->m_name.Content << "(x, param)";
+ out << m_options.m_prefixMark << reflectTypeName << "_" << node->m_name.getContent() << "(x, param)";
// If has derived types output them
if (node->hasReflectedDerivedType())
{
out << " \\\n";
_indent(1, out);
- out << m_options.m_prefixMark << "CHILDREN_" << reflectTypeName << "_" << node->m_name.Content << "(x, param)";
+ out << m_options.m_prefixMark << "CHILDREN_" << reflectTypeName << "_" << node->m_name.getContent() << "(x, param)";
}
out << "\n\n";
}
@@ -1979,7 +1981,7 @@ SlangResult CPPExtractorApp::calcHeader(CPPExtractor& extractor, StringBuilder&
for (Node* scopeNode : baseScopePath)
{
SLANG_ASSERT(scopeNode->m_type == Node::Type::Namespace);
- out << "namespace " << scopeNode->m_name.Content << " {\n";
+ out << "namespace " << scopeNode->m_name.getContent() << " {\n";
}
List<Node*> nodes;
@@ -1998,7 +2000,7 @@ SlangResult CPPExtractorApp::calcHeader(CPPExtractor& extractor, StringBuilder&
// Okay first we are going to output the enum values
const Index depth = node->calcDerivedDepth() - 1;
_indent(depth, out);
- out << node->m_name.Content << " = " << typeIndex << ",\n";
+ out << node->m_name.getContent() << " = " << typeIndex << ",\n";
typeIndex++;
}
@@ -2045,7 +2047,7 @@ SlangResult CPPExtractorApp::calcHeader(CPPExtractor& extractor, StringBuilder&
if (node->m_isReflected)
{
const char* type = (node->m_type == Node::Type::ClassType) ? "class" : "struct";
- out << type << " " << node->m_name.Content << ";\n";
+ out << type << " " << node->m_name.getContent() << ";\n";
}
}
}
@@ -2084,15 +2086,15 @@ SlangResult CPPExtractorApp::calcHeader(CPPExtractor& extractor, StringBuilder&
// Output all of the definitions for each type
for (Node* node : nodes)
{
- out << "#define " << m_options.m_prefixMark << reflectTypeName << "_" << node->m_name.Content << "(x, param) ";
+ out << "#define " << m_options.m_prefixMark << reflectTypeName << "_" << node->m_name.getContent() << "(x, param) ";
// Output the X macro part
_indent(1, out);
- out << "x(" << node->m_name.Content << ", ";
+ out << "x(" << node->m_name.getContent() << ", ";
if (node->m_superNode)
{
- out << node->m_superNode->m_name.Content << ", ";
+ out << node->m_superNode->m_name.getContent() << ", ";
}
else
{
@@ -2107,7 +2109,7 @@ SlangResult CPPExtractorApp::calcHeader(CPPExtractor& extractor, StringBuilder&
Node* lastDerived = node->findLastDerived();
if (lastDerived)
{
- out << lastDerived->m_name.Content << ", ";
+ out << lastDerived->m_name.getContent() << ", ";
}
else
{
@@ -2115,7 +2117,7 @@ SlangResult CPPExtractorApp::calcHeader(CPPExtractor& extractor, StringBuilder&
}
// Output any specifics of the markup
- UnownedStringSlice marker = node->m_marker.Content;
+ UnownedStringSlice marker = node->m_marker.getContent();
// Need to extract the name
if (marker.getLength() > m_options.m_prefixMark.getLength() + m_options.m_postfixMark.getLength())
{
@@ -2148,7 +2150,7 @@ SlangResult CPPExtractorApp::calcHeader(CPPExtractor& extractor, StringBuilder&
for (Index j = baseScopePath.getCount() - 1; j >= 0; j--)
{
Node* scopeNode = baseScopePath[j];
- out << "} // namespace " << scopeNode->m_name.Content << "\n";
+ out << "} // namespace " << scopeNode->m_name.getContent() << "\n";
}
}
@@ -2168,7 +2170,7 @@ SlangResult CPPExtractorApp::calcHeader(CPPExtractor& extractor, StringBuilder&
}
_indent(1, out);
- out << "x(" << node->m_name.Content << ", param) \\\n";
+ out << "x(" << node->m_name.getContent() << ", param) \\\n";
}
out << "/* */\n\n";
}