Skip to content

Commit

Permalink
Move c++ parsing code from slang-cpp-extractor to static library (sha…
Browse files Browse the repository at this point in the history
…der-slang#5675)

* Move c++ parsing code from slang-cpp-extractor to static library

* Format code

* Remove relative includes

---------

Co-authored-by: slangbot <[email protected]>
Co-authored-by: Yong He <[email protected]>
  • Loading branch information
3 people authored Dec 2, 2024
1 parent 7aaf700 commit eaa8dcf
Show file tree
Hide file tree
Showing 22 changed files with 115 additions and 134 deletions.
10 changes: 10 additions & 0 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ generator(
USE_FEWER_WARNINGS
LINK_WITH_PRIVATE
compiler-core
slang-cpp-parser
)
generator(slang-embed)
generator(slang-generate USE_FEWER_WARNINGS)
Expand All @@ -68,6 +69,15 @@ generator(
Threads::Threads
)

slang_add_target(
slang-cpp-parser
STATIC
USE_FEWER_WARNINGS
LINK_WITH_PRIVATE core compiler-core
INCLUDE_DIRECTORIES_PUBLIC .
FOLDER generators
)

#
# Language Server
#
Expand Down
40 changes: 20 additions & 20 deletions tools/slang-cpp-extractor/cpp-extractor-main.cpp
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
// main.cpp

#include "../../source/compiler-core/slang-diagnostic-sink.h"
#include "../../source/compiler-core/slang-doc-extractor.h"
#include "../../source/compiler-core/slang-lexer.h"
#include "../../source/compiler-core/slang-name-convention-util.h"
#include "../../source/compiler-core/slang-name.h"
#include "../../source/compiler-core/slang-source-loc.h"
#include "../../source/core/slang-file-system.h"
#include "../../source/core/slang-io.h"
#include "../../source/core/slang-list.h"
#include "../../source/core/slang-secure-crt.h"
#include "../../source/core/slang-string-slice-pool.h"
#include "../../source/core/slang-string-util.h"
#include "../../source/core/slang-string.h"
#include "../../source/core/slang-writer.h"
#include "diagnostics.h"
#include "file-util.h"
#include "compiler-core/slang-diagnostic-sink.h"
#include "compiler-core/slang-doc-extractor.h"
#include "compiler-core/slang-lexer.h"
#include "compiler-core/slang-name-convention-util.h"
#include "compiler-core/slang-name.h"
#include "compiler-core/slang-source-loc.h"
#include "core/slang-file-system.h"
#include "core/slang-io.h"
#include "core/slang-list.h"
#include "core/slang-secure-crt.h"
#include "core/slang-string-slice-pool.h"
#include "core/slang-string-util.h"
#include "core/slang-string.h"
#include "core/slang-writer.h"
#include "macro-writer.h"
#include "node.h"
#include "options.h"
#include "parser.h"
#include "slang-com-helper.h"
#include "unit-test.h"
#include "slang-cpp-parser/diagnostics.h"
#include "slang-cpp-parser/file-util.h"
#include "slang-cpp-parser/node.h"
#include "slang-cpp-parser/options.h"
#include "slang-cpp-parser/parser.h"
#include "slang-cpp-parser/unit-test.h"

#include <stdio.h>
#include <stdlib.h>
Expand Down
22 changes: 10 additions & 12 deletions tools/slang-cpp-extractor/macro-writer.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
#include "macro-writer.h"

#include "../../source/core/slang-list.h"
#include "../../source/core/slang-string.h"
#include "compiler-core/slang-diagnostic-sink.h"
#include "core/slang-io.h"
#include "core/slang-list.h"
#include "core/slang-string.h"
#include "core/slang-writer.h"
#include "slang-com-helper.h"
// #include "../../source/core/slang-string-util.h"
#include "../../source/compiler-core/slang-diagnostic-sink.h"
#include "../../source/core/slang-io.h"
#include "../../source/core/slang-writer.h"
// #include "../../source/compiler-core/slang-name.h"

#include "diagnostics.h"
#include "file-util.h"
#include "node-tree.h"
#include "options.h"
#include "slang-cpp-parser/diagnostics.h"
#include "slang-cpp-parser/file-util.h"
#include "slang-cpp-parser/node-tree.h"
#include "slang-cpp-parser/options.h"

namespace CppExtract
{
using namespace Slang;
using namespace CppParse;

SLANG_FORCE_INLINE static void _indent(Index indentCount, StringBuilder& out)
{
Expand Down
14 changes: 6 additions & 8 deletions tools/slang-cpp-extractor/macro-writer.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#ifndef CPP_EXTRACT_MACRO_WRITER_H
#define CPP_EXTRACT_MACRO_WRITER_H
#pragma once

#include "../../source/compiler-core/slang-diagnostic-sink.h"
#include "diagnostics.h"
#include "node-tree.h"
#include "options.h"
#include "compiler-core/slang-diagnostic-sink.h"
#include "slang-cpp-parser/diagnostics.h"
#include "slang-cpp-parser/node-tree.h"
#include "slang-cpp-parser/options.h"

namespace CppExtract
{
using namespace Slang;
using namespace CppParse;

/* A class that writes out macros that define type hierarchies, as well as fields of types */
class MacroWriter
Expand Down Expand Up @@ -39,5 +39,3 @@ class MacroWriter
};

} // namespace CppExtract

#endif
17 changes: 0 additions & 17 deletions tools/slang-cpp-extractor/unit-test.h

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// for any arguments.

#ifndef DIAGNOSTIC
#error Need to #define DIAGNOSTIC(...) before including "slang-cpp-extractor-diagnostics-defs.h"
#error Need to #define DIAGNOSTIC(...) before including "slang-cpp-parser/diagnostics-defs.h"
#define DIAGNOSTIC(id, severity, name, messageFormat) /* */
#endif

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "diagnostics.h"

namespace CppExtract
namespace CppParse
{

namespace CPPDiagnostics
Expand All @@ -12,4 +12,4 @@ using namespace Slang;
#include "diagnostic-defs.h"
} // namespace CPPDiagnostics

} // namespace CppExtract
} // namespace CppParse
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#ifndef CPP_EXTRACT_DIAGNOSTICS_H
#define CPP_EXTRACT_DIAGNOSTICS_H
#pragma once

#include "../../source/slang/slang-diagnostics.h"
#include "slang/slang-diagnostics.h"

namespace CppExtract
namespace CppParse
{
using namespace Slang;

Expand All @@ -14,6 +13,4 @@ namespace CPPDiagnostics
#include "diagnostic-defs.h"

} // namespace CPPDiagnostics
} // namespace CppExtract

#endif
} // namespace CppParse
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "file-util.h"

#include "../../source/core/slang-io.h"
#include "core/slang-io.h"

namespace CppExtract
namespace CppParse
{
using namespace Slang;

Expand Down Expand Up @@ -98,4 +98,4 @@ struct DiagnosticReporter
}
}

} // namespace CppExtract
} // namespace CppParse
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#ifndef CPP_EXTRACT_FILE_UTIL_H
#define CPP_EXTRACT_FILE_UTIL_H
#pragma once

#include "diagnostics.h"

namespace CppExtract
namespace CppParse
{
using namespace Slang;

Expand All @@ -29,6 +28,4 @@ struct FileUtil
static void indent(Index indentCount, StringBuilder& out);
};

} // namespace CppExtract

#endif
} // namespace CppParse
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "identifier-lookup.h"

namespace CppExtract
namespace CppParse
{
using namespace Slang;

Expand Down Expand Up @@ -174,4 +174,4 @@ void IdentifierLookup::initDefault(const UnownedStringSlice& markPrefix)
}
}

} // namespace CppExtract
} // namespace CppParse
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#ifndef CPP_EXTRACT_IDENTIFIER_LOOKUP_H
#define CPP_EXTRACT_IDENTIFIER_LOOKUP_H
#pragma once

#include "diagnostics.h"

namespace CppExtract
namespace CppParse
{
using namespace Slang;

Expand Down Expand Up @@ -119,6 +118,4 @@ SLANG_FORCE_INLINE bool hasFlag(IdentifierStyle style, IdentifierFlag::Enum flag
return (getFlags(style) & flag) != 0;
}

} // namespace CppExtract

#endif
} // namespace CppParse
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "node-tree.h"

#include "../../source/compiler-core/slang-name-convention-util.h"
#include "../../source/core/slang-io.h"
#include "compiler-core/slang-name-convention-util.h"
#include "core/slang-io.h"
#include "identifier-lookup.h"
#include "options.h"

namespace CppExtract
namespace CppParse
{
using namespace Slang;

Expand Down Expand Up @@ -173,4 +173,4 @@ SlangResult NodeTree::calcDerivedTypes(DiagnosticSink* sink)
}


} // namespace CppExtract
} // namespace CppParse
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#ifndef CPP_EXTRACT_NODE_TREE_H
#define CPP_EXTRACT_NODE_TREE_H
#pragma once

#include "../../source/compiler-core/slang-lexer.h"
#include "compiler-core/slang-lexer.h"
#include "diagnostics.h"
#include "identifier-lookup.h"
#include "node.h"

namespace CppExtract
namespace CppParse
{
using namespace Slang;

Expand Down Expand Up @@ -99,6 +98,4 @@ class NodeTree
List<RefPtr<SourceOrigin>> m_sourceOrigins;
};

} // namespace CppExtract

#endif
} // namespace CppParse
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "node.h"

#include "../../source/core/slang-string-escape-util.h"
#include "../../source/core/slang-string-util.h"
#include "core/slang-string-escape-util.h"
#include "core/slang-string-util.h"
#include "file-util.h"

namespace CppExtract
namespace CppParse
{

// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Node Impl
Expand Down Expand Up @@ -697,4 +697,4 @@ void ClassLikeNode::dump(int indentCount, StringBuilder& out)
out << "}\n";
}

} // namespace CppExtract
} // namespace CppParse
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#ifndef CPP_EXTRACT_NODE_H
#define CPP_EXTRACT_NODE_H
#pragma once

#include "../../source/compiler-core/slang-doc-extractor.h"
#include "compiler-core/slang-doc-extractor.h"
#include "diagnostics.h"

namespace CppExtract
namespace CppParse
{
using namespace Slang;

Expand Down Expand Up @@ -420,6 +419,4 @@ T* as(Node* node)
return (node && T::isOfKind(node->m_kind)) ? static_cast<T*>(node) : nullptr;
}

} // namespace CppExtract

#endif
} // namespace CppParse
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "diagnostics.h"

namespace CppExtract
namespace CppParse
{

SlangResult OptionsParser::_parseArgFlag(const char* option, bool& outFlag)
Expand Down Expand Up @@ -150,4 +150,4 @@ SlangResult OptionsParser::parse(
return SLANG_OK;
}

} // namespace CppExtract
} // namespace CppParse
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#ifndef CPP_EXTRACT_OPTIONS_H
#define CPP_EXTRACT_OPTIONS_H
#pragma once

#include "../../source/slang/slang-diagnostics.h"
#include "slang/slang-diagnostics.h"

namespace CppExtract
namespace CppParse
{
using namespace Slang;

Expand Down Expand Up @@ -61,7 +60,4 @@ struct OptionsParser
DiagnosticSink* m_sink;
};


} // namespace CppExtract

#endif
} // namespace CppParse
Loading

0 comments on commit eaa8dcf

Please sign in to comment.