Skip to content

Commit eaa8dcf

Browse files
laurooyenslangbotcsyonghe
authored
Move c++ parsing code from slang-cpp-extractor to static library (shader-slang#5675)
* Move c++ parsing code from slang-cpp-extractor to static library * Format code * Remove relative includes --------- Co-authored-by: slangbot <ellieh+slangbot@nvidia.com> Co-authored-by: Yong He <yonghe@outlook.com>
1 parent 7aaf700 commit eaa8dcf

22 files changed

+115
-134
lines changed

tools/CMakeLists.txt

+10
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ generator(
4949
USE_FEWER_WARNINGS
5050
LINK_WITH_PRIVATE
5151
compiler-core
52+
slang-cpp-parser
5253
)
5354
generator(slang-embed)
5455
generator(slang-generate USE_FEWER_WARNINGS)
@@ -68,6 +69,15 @@ generator(
6869
Threads::Threads
6970
)
7071

72+
slang_add_target(
73+
slang-cpp-parser
74+
STATIC
75+
USE_FEWER_WARNINGS
76+
LINK_WITH_PRIVATE core compiler-core
77+
INCLUDE_DIRECTORIES_PUBLIC .
78+
FOLDER generators
79+
)
80+
7181
#
7282
# Language Server
7383
#

tools/slang-cpp-extractor/cpp-extractor-main.cpp

+20-20
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
// main.cpp
22

3-
#include "../../source/compiler-core/slang-diagnostic-sink.h"
4-
#include "../../source/compiler-core/slang-doc-extractor.h"
5-
#include "../../source/compiler-core/slang-lexer.h"
6-
#include "../../source/compiler-core/slang-name-convention-util.h"
7-
#include "../../source/compiler-core/slang-name.h"
8-
#include "../../source/compiler-core/slang-source-loc.h"
9-
#include "../../source/core/slang-file-system.h"
10-
#include "../../source/core/slang-io.h"
11-
#include "../../source/core/slang-list.h"
12-
#include "../../source/core/slang-secure-crt.h"
13-
#include "../../source/core/slang-string-slice-pool.h"
14-
#include "../../source/core/slang-string-util.h"
15-
#include "../../source/core/slang-string.h"
16-
#include "../../source/core/slang-writer.h"
17-
#include "diagnostics.h"
18-
#include "file-util.h"
3+
#include "compiler-core/slang-diagnostic-sink.h"
4+
#include "compiler-core/slang-doc-extractor.h"
5+
#include "compiler-core/slang-lexer.h"
6+
#include "compiler-core/slang-name-convention-util.h"
7+
#include "compiler-core/slang-name.h"
8+
#include "compiler-core/slang-source-loc.h"
9+
#include "core/slang-file-system.h"
10+
#include "core/slang-io.h"
11+
#include "core/slang-list.h"
12+
#include "core/slang-secure-crt.h"
13+
#include "core/slang-string-slice-pool.h"
14+
#include "core/slang-string-util.h"
15+
#include "core/slang-string.h"
16+
#include "core/slang-writer.h"
1917
#include "macro-writer.h"
20-
#include "node.h"
21-
#include "options.h"
22-
#include "parser.h"
2318
#include "slang-com-helper.h"
24-
#include "unit-test.h"
19+
#include "slang-cpp-parser/diagnostics.h"
20+
#include "slang-cpp-parser/file-util.h"
21+
#include "slang-cpp-parser/node.h"
22+
#include "slang-cpp-parser/options.h"
23+
#include "slang-cpp-parser/parser.h"
24+
#include "slang-cpp-parser/unit-test.h"
2525

2626
#include <stdio.h>
2727
#include <stdlib.h>

tools/slang-cpp-extractor/macro-writer.cpp

+10-12
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
#include "macro-writer.h"
22

3-
#include "../../source/core/slang-list.h"
4-
#include "../../source/core/slang-string.h"
3+
#include "compiler-core/slang-diagnostic-sink.h"
4+
#include "core/slang-io.h"
5+
#include "core/slang-list.h"
6+
#include "core/slang-string.h"
7+
#include "core/slang-writer.h"
58
#include "slang-com-helper.h"
6-
// #include "../../source/core/slang-string-util.h"
7-
#include "../../source/compiler-core/slang-diagnostic-sink.h"
8-
#include "../../source/core/slang-io.h"
9-
#include "../../source/core/slang-writer.h"
10-
// #include "../../source/compiler-core/slang-name.h"
11-
12-
#include "diagnostics.h"
13-
#include "file-util.h"
14-
#include "node-tree.h"
15-
#include "options.h"
9+
#include "slang-cpp-parser/diagnostics.h"
10+
#include "slang-cpp-parser/file-util.h"
11+
#include "slang-cpp-parser/node-tree.h"
12+
#include "slang-cpp-parser/options.h"
1613

1714
namespace CppExtract
1815
{
1916
using namespace Slang;
17+
using namespace CppParse;
2018

2119
SLANG_FORCE_INLINE static void _indent(Index indentCount, StringBuilder& out)
2220
{

tools/slang-cpp-extractor/macro-writer.h

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
#ifndef CPP_EXTRACT_MACRO_WRITER_H
2-
#define CPP_EXTRACT_MACRO_WRITER_H
1+
#pragma once
32

4-
#include "../../source/compiler-core/slang-diagnostic-sink.h"
5-
#include "diagnostics.h"
6-
#include "node-tree.h"
7-
#include "options.h"
3+
#include "compiler-core/slang-diagnostic-sink.h"
4+
#include "slang-cpp-parser/diagnostics.h"
5+
#include "slang-cpp-parser/node-tree.h"
6+
#include "slang-cpp-parser/options.h"
87

98
namespace CppExtract
109
{
1110
using namespace Slang;
11+
using namespace CppParse;
1212

1313
/* A class that writes out macros that define type hierarchies, as well as fields of types */
1414
class MacroWriter
@@ -39,5 +39,3 @@ class MacroWriter
3939
};
4040

4141
} // namespace CppExtract
42-
43-
#endif

tools/slang-cpp-extractor/unit-test.h

-17
This file was deleted.

tools/slang-cpp-extractor/diagnostic-defs.h tools/slang-cpp-parser/diagnostic-defs.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// for any arguments.
1515

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

tools/slang-cpp-extractor/diagnostics.cpp tools/slang-cpp-parser/diagnostics.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "diagnostics.h"
22

3-
namespace CppExtract
3+
namespace CppParse
44
{
55

66
namespace CPPDiagnostics
@@ -12,4 +12,4 @@ using namespace Slang;
1212
#include "diagnostic-defs.h"
1313
} // namespace CPPDiagnostics
1414

15-
} // namespace CppExtract
15+
} // namespace CppParse
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
#ifndef CPP_EXTRACT_DIAGNOSTICS_H
2-
#define CPP_EXTRACT_DIAGNOSTICS_H
1+
#pragma once
32

4-
#include "../../source/slang/slang-diagnostics.h"
3+
#include "slang/slang-diagnostics.h"
54

6-
namespace CppExtract
5+
namespace CppParse
76
{
87
using namespace Slang;
98

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

1615
} // namespace CPPDiagnostics
17-
} // namespace CppExtract
18-
19-
#endif
16+
} // namespace CppParse

tools/slang-cpp-extractor/file-util.cpp tools/slang-cpp-parser/file-util.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include "file-util.h"
22

3-
#include "../../source/core/slang-io.h"
3+
#include "core/slang-io.h"
44

5-
namespace CppExtract
5+
namespace CppParse
66
{
77
using namespace Slang;
88

@@ -98,4 +98,4 @@ struct DiagnosticReporter
9898
}
9999
}
100100

101-
} // namespace CppExtract
101+
} // namespace CppParse

tools/slang-cpp-extractor/file-util.h tools/slang-cpp-parser/file-util.h

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
#ifndef CPP_EXTRACT_FILE_UTIL_H
2-
#define CPP_EXTRACT_FILE_UTIL_H
1+
#pragma once
32

43
#include "diagnostics.h"
54

6-
namespace CppExtract
5+
namespace CppParse
76
{
87
using namespace Slang;
98

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

32-
} // namespace CppExtract
33-
34-
#endif
31+
} // namespace CppParse

tools/slang-cpp-extractor/identifier-lookup.cpp tools/slang-cpp-parser/identifier-lookup.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "identifier-lookup.h"
22

3-
namespace CppExtract
3+
namespace CppParse
44
{
55
using namespace Slang;
66

@@ -174,4 +174,4 @@ void IdentifierLookup::initDefault(const UnownedStringSlice& markPrefix)
174174
}
175175
}
176176

177-
} // namespace CppExtract
177+
} // namespace CppParse

tools/slang-cpp-extractor/identifier-lookup.h tools/slang-cpp-parser/identifier-lookup.h

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
#ifndef CPP_EXTRACT_IDENTIFIER_LOOKUP_H
2-
#define CPP_EXTRACT_IDENTIFIER_LOOKUP_H
1+
#pragma once
32

43
#include "diagnostics.h"
54

6-
namespace CppExtract
5+
namespace CppParse
76
{
87
using namespace Slang;
98

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

122-
} // namespace CppExtract
123-
124-
#endif
121+
} // namespace CppParse

tools/slang-cpp-extractor/node-tree.cpp tools/slang-cpp-parser/node-tree.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#include "node-tree.h"
22

3-
#include "../../source/compiler-core/slang-name-convention-util.h"
4-
#include "../../source/core/slang-io.h"
3+
#include "compiler-core/slang-name-convention-util.h"
4+
#include "core/slang-io.h"
55
#include "identifier-lookup.h"
66
#include "options.h"
77

8-
namespace CppExtract
8+
namespace CppParse
99
{
1010
using namespace Slang;
1111

@@ -173,4 +173,4 @@ SlangResult NodeTree::calcDerivedTypes(DiagnosticSink* sink)
173173
}
174174

175175

176-
} // namespace CppExtract
176+
} // namespace CppParse

tools/slang-cpp-extractor/node-tree.h tools/slang-cpp-parser/node-tree.h

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
#ifndef CPP_EXTRACT_NODE_TREE_H
2-
#define CPP_EXTRACT_NODE_TREE_H
1+
#pragma once
32

4-
#include "../../source/compiler-core/slang-lexer.h"
3+
#include "compiler-core/slang-lexer.h"
54
#include "diagnostics.h"
65
#include "identifier-lookup.h"
76
#include "node.h"
87

9-
namespace CppExtract
8+
namespace CppParse
109
{
1110
using namespace Slang;
1211

@@ -99,6 +98,4 @@ class NodeTree
9998
List<RefPtr<SourceOrigin>> m_sourceOrigins;
10099
};
101100

102-
} // namespace CppExtract
103-
104-
#endif
101+
} // namespace CppParse

tools/slang-cpp-extractor/node.cpp tools/slang-cpp-parser/node.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#include "node.h"
22

3-
#include "../../source/core/slang-string-escape-util.h"
4-
#include "../../source/core/slang-string-util.h"
3+
#include "core/slang-string-escape-util.h"
4+
#include "core/slang-string-util.h"
55
#include "file-util.h"
66

7-
namespace CppExtract
7+
namespace CppParse
88
{
99

1010
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Node Impl
@@ -697,4 +697,4 @@ void ClassLikeNode::dump(int indentCount, StringBuilder& out)
697697
out << "}\n";
698698
}
699699

700-
} // namespace CppExtract
700+
} // namespace CppParse

tools/slang-cpp-extractor/node.h tools/slang-cpp-parser/node.h

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
#ifndef CPP_EXTRACT_NODE_H
2-
#define CPP_EXTRACT_NODE_H
1+
#pragma once
32

4-
#include "../../source/compiler-core/slang-doc-extractor.h"
3+
#include "compiler-core/slang-doc-extractor.h"
54
#include "diagnostics.h"
65

7-
namespace CppExtract
6+
namespace CppParse
87
{
98
using namespace Slang;
109

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

423-
} // namespace CppExtract
424-
425-
#endif
422+
} // namespace CppParse

tools/slang-cpp-extractor/options.cpp tools/slang-cpp-parser/options.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include "diagnostics.h"
44

5-
namespace CppExtract
5+
namespace CppParse
66
{
77

88
SlangResult OptionsParser::_parseArgFlag(const char* option, bool& outFlag)
@@ -150,4 +150,4 @@ SlangResult OptionsParser::parse(
150150
return SLANG_OK;
151151
}
152152

153-
} // namespace CppExtract
153+
} // namespace CppParse

tools/slang-cpp-extractor/options.h tools/slang-cpp-parser/options.h

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
#ifndef CPP_EXTRACT_OPTIONS_H
2-
#define CPP_EXTRACT_OPTIONS_H
1+
#pragma once
32

4-
#include "../../source/slang/slang-diagnostics.h"
3+
#include "slang/slang-diagnostics.h"
54

6-
namespace CppExtract
5+
namespace CppParse
76
{
87
using namespace Slang;
98

@@ -61,7 +60,4 @@ struct OptionsParser
6160
DiagnosticSink* m_sink;
6261
};
6362

64-
65-
} // namespace CppExtract
66-
67-
#endif
63+
} // namespace CppParse

0 commit comments

Comments
 (0)