yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Lauro OyenMove c++ parsing code from slang-cpp-extractor to static library (#5675)eaa8dcfcc

master
3.1 KiB101 linesraw
1#pragma once
2
3#include "compiler-core/slang-lexer.h"
4#include "diagnostics.h"
5#include "identifier-lookup.h"
6#include "node.h"
7
8namespace CppParse
9{
10using namespace Slang;
11
12class TypeSet : public RefObject
13{
14public:
15    /// This is the looked up name.
16    UnownedStringSlice
17        m_macroName; ///< The name extracted from the macro SLANG_ABSTRACT_AST_CLASS -> AST
18
19    String m_typeName; ///< The enum type name associated with this type for AST it is ASTNode
20    String m_fileMark; ///< This 'mark' becomes of the output filename
21
22    List<ClassLikeNode*> m_baseTypes; ///< The base types for this type set
23};
24
25class SourceOrigin : public RefObject
26{
27public:
28    void addNode(Node* node)
29    {
30        if (auto classLike = as<ClassLikeNode>(node))
31        {
32            SLANG_ASSERT(classLike->m_origin == nullptr);
33            classLike->m_origin = this;
34        }
35
36        m_nodes.add(node);
37    }
38
39    SourceOrigin(SourceFile* sourceFile, const String& macroOrigin)
40        : m_sourceFile(sourceFile), m_macroOrigin(macroOrigin)
41    {
42    }
43
44    String m_macroOrigin; ///< The macro text is inserted into the macro to identify the origin. It
45                          ///< is based on the filename
46    SourceFile* m_sourceFile; ///< The source file - also holds the path information
47
48    /// All of the nodes defined in this file in the order they were defined
49    /// Note that the same namespace may be listed multiple times.
50    List<RefPtr<Node>> m_nodes;
51};
52
53struct Options;
54class IdentifierLookup;
55
56/* NodeTree holds nodes that have been parsed into a tree rooted on the 'rootNode'.
57Also contains other state associated with or useful to a node tree */
58class NodeTree
59{
60public:
61    friend class Parser;
62    /// Get all of the parsed source origins
63    const List<RefPtr<SourceOrigin>>& getSourceOrigins() const { return m_sourceOrigins; }
64
65    TypeSet* getTypeSet(const UnownedStringSlice& slice);
66    TypeSet* getOrAddTypeSet(const UnownedStringSlice& slice);
67
68    SourceOrigin* addSourceOrigin(SourceFile* sourceFile, const Options& options);
69
70    /// Get all of the type sets
71    const List<RefPtr<TypeSet>>& getTypeSets() const { return m_typeSets; }
72
73    /// Get the root node
74    Node* getRootNode() const { return m_rootNode; }
75
76    /// When parsing we don't lookup all up super types/add derived types. This is because
77    /// we allow files to be processed in any order, so we have to do the type lookup as a separate
78    /// operation
79    SlangResult calcDerivedTypes(DiagnosticSink* sink);
80
81    NodeTree(StringSlicePool* typePool, NamePool* namePool, IdentifierLookup* identifierLookup);
82
83    static String calcMacroOrigin(const String& filePath, const Options& options);
84
85protected:
86    SlangResult _calcDerivedTypesRec(ScopeNode* node, DiagnosticSink* sink);
87
88    StringSlicePool m_typeSetPool;    ///< Pool for type set names
89    List<RefPtr<TypeSet>> m_typeSets; ///< The type sets
90
91    IdentifierLookup* m_identifierLookup;
92    StringSlicePool* m_typePool; ///< Pool for just types
93
94    NamePool* m_namePool;
95
96    RefPtr<ScopeNode> m_rootNode; ///< The root scope
97
98    List<RefPtr<SourceOrigin>> m_sourceOrigins;
99};
100
101} // namespace CppParse