yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
eaa8dcfcc
master
1#pragma once 2 3#include "compiler-core/slang-lexer.h" 4#include "diagnostics.h" 5#include "identifier-lookup.h" 6#include "node-tree.h" 7#include "node.h" 8 9namespace CppParse 10{ 11using namespace Slang ; 12 13class Parser 14{ 15public : 16typedef uint32_t NodeTypeBitType ; 17 18SlangResult expect (TokenType type ,Token * outToken = nullptr ); 19 20bool advanceIfMarker (Token * outToken = nullptr ); 21bool advanceIfToken (TokenType type ,Token * outToken = nullptr ); 22bool advanceIfStyle (IdentifierStyle style ,Token * outToken = nullptr ); 23 24SlangResult pushAnonymousNamespace (); 25SlangResult pushScope (ScopeNode * node ); 26SlangResult consumeToClosingBrace (const Token * openBraceToken = nullptr ); 27SlangResult popScope (); 28 29/// Parse the contents of the source file 30SlangResult parse (SourceOrigin * sourceOrigin ,const Options * options ); 31 32void setKindEnabled (Node ::Kind kind ,bool isEnabled = true); 33bool isTypeEnabled (Node ::Kind kind ) 34 { 35return (m_nodeTypeEnabled & (NodeTypeBitType (1 ) <<int (kind )))!= 0 ; 36 } 37 38void setKindsEnabled (const Node ::Kind * kinds ,Index kindsCount ,bool isEnabled = true); 39 40Parser (NodeTree * nodeTree ,DiagnosticSink * sink ); 41 42protected : 43static Node ::Kind _toNodeKind (IdentifierStyle style ); 44 45bool _isMarker (const UnownedStringSlice & name ); 46 47SlangResult _maybeConsumeScope (); 48 49SlangResult _parsePreDeclare (); 50SlangResult _parseTypeSet (); 51 52SlangResult _maybeParseNode (Node ::Kind kind ); 53SlangResult _maybeParseContained (Node ** outNode ); 54 55SlangResult _parseTypeDef (); 56SlangResult _parseEnum (); 57SlangResult _parseMarker (); 58SlangResult _parseSpecialMacro (); 59 60SlangResult _maybeParseType (List < Token >& outToks ,Token & outName ); 61SlangResult _maybeParseType (UnownedStringSlice & outType ,Token & outName ); 62SlangResult _maybeParseType (Index & ioTemplateDepth ,TokenReader ::ParsingCursor & outCursor ); 63 64SlangResult _parseExpression (List < Token >& outExprTokens ); 65 66SlangResult _maybeParseTemplateArgs (Index & ioTemplateDepth ); 67SlangResult _maybeParseTemplateArg (Index & ioTemplateDepth ); 68 69/// Parse balanced - if a sink is set will report to that sink 70SlangResult _parseBalanced (DiagnosticSink * sink ); 71 72bool _isCtor (); 73 74/// Concatenate all tokens from start to the current position 75UnownedStringSlice _concatTokens (TokenReader ::ParsingCursor start ); 76UnownedStringSlice _concatTokens (const Token * toks ,Index toksCount ); 77 78UnownedStringSlice _concatType ( 79TokenReader ::ParsingCursor start , 80TokenReader ::ParsingCursor nameCursor ); 81 82void _getTypeTokens ( 83TokenReader ::ParsingCursor start , 84TokenReader ::ParsingCursor nameCursor , 85List < Token >& outToks ); 86 87/// Consume what looks like a template definition 88SlangResult _consumeTemplate (); 89SlangResult _maybeConsume (IdentifierStyle style ); 90 91SlangResult _consumeToSync (); 92/// Consumes balanced parens. Will return an error if not matched. Assumes starts on opening ( 93SlangResult _consumeBalancedParens (); 94 95NodeTypeBitType m_nodeTypeEnabled ; 96 97TokenList m_tokenList ; 98TokenReader m_reader ; 99 100List < ScopeNode *> m_scopeStack ; 101 102ScopeNode * m_currentScope ;///< The current scope being processed 103SourceOrigin * m_sourceOrigin ;///< The source origin that all tokens are in 104 105DiagnosticSink * m_sink ;///< Diagnostic sink 106 107NodeTree * m_nodeTree ;///< Shared state between parses. Nodes will be added to this 108 109const Options * m_options ; 110}; 111 112}// namespace CppParse