hlslGrammar.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. //
  2. // Copyright (C) 2016-2018 Google, Inc.
  3. // Copyright (C) 2016 LunarG, Inc.
  4. //
  5. // All rights reserved.
  6. //
  7. // Redistribution and use in source and binary forms, with or without
  8. // modification, are permitted provided that the following conditions
  9. // are met:
  10. //
  11. // Redistributions of source code must retain the above copyright
  12. // notice, this list of conditions and the following disclaimer.
  13. //
  14. // Redistributions in binary form must reproduce the above
  15. // copyright notice, this list of conditions and the following
  16. // disclaimer in the documentation and/or other materials provided
  17. // with the distribution.
  18. //
  19. // Neither the name of Google, Inc., nor the names of its
  20. // contributors may be used to endorse or promote products derived
  21. // from this software without specific prior written permission.
  22. //
  23. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  24. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  25. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  26. // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  27. // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  28. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  29. // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  30. // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  31. // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  32. // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  33. // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  34. // POSSIBILITY OF SUCH DAMAGE.
  35. //
  36. #ifndef HLSLGRAMMAR_H_
  37. #define HLSLGRAMMAR_H_
  38. #include "hlslParseHelper.h"
  39. #include "hlslOpMap.h"
  40. #include "hlslTokenStream.h"
  41. namespace glslang {
  42. class TFunctionDeclarator;
  43. // Should just be the grammar aspect of HLSL.
  44. // Described in more detail in hlslGrammar.cpp.
  45. class HlslGrammar : public HlslTokenStream {
  46. public:
  47. HlslGrammar(HlslScanContext& scanner, HlslParseContext& parseContext)
  48. : HlslTokenStream(scanner), parseContext(parseContext), intermediate(parseContext.intermediate),
  49. typeIdentifiers(false), unitNode(nullptr) { }
  50. virtual ~HlslGrammar() { }
  51. bool parse();
  52. protected:
  53. HlslGrammar();
  54. HlslGrammar& operator=(const HlslGrammar&);
  55. void expected(const char*);
  56. void unimplemented(const char*);
  57. bool acceptIdentifier(HlslToken&);
  58. bool acceptCompilationUnit();
  59. bool acceptDeclarationList(TIntermNode*&);
  60. bool acceptDeclaration(TIntermNode*&);
  61. bool acceptControlDeclaration(TIntermNode*& node);
  62. bool acceptSamplerDeclarationDX9(TType&);
  63. bool acceptSamplerState();
  64. bool acceptFullySpecifiedType(TType&, const TAttributes&);
  65. bool acceptFullySpecifiedType(TType&, TIntermNode*& nodeList, const TAttributes&, bool forbidDeclarators = false);
  66. bool acceptQualifier(TQualifier&);
  67. bool acceptLayoutQualifierList(TQualifier&);
  68. bool acceptType(TType&);
  69. bool acceptType(TType&, TIntermNode*& nodeList);
  70. bool acceptTemplateVecMatBasicType(TBasicType&);
  71. bool acceptVectorTemplateType(TType&);
  72. bool acceptMatrixTemplateType(TType&);
  73. bool acceptTessellationDeclType(TBuiltInVariable&);
  74. bool acceptTessellationPatchTemplateType(TType&);
  75. bool acceptStreamOutTemplateType(TType&, TLayoutGeometry&);
  76. bool acceptOutputPrimitiveGeometry(TLayoutGeometry&);
  77. bool acceptAnnotations(TQualifier&);
  78. bool acceptSamplerTypeDX9(TType &);
  79. bool acceptSamplerType(TType&);
  80. bool acceptTextureType(TType&);
  81. bool acceptSubpassInputType(TType&);
  82. bool acceptStructBufferType(TType&);
  83. bool acceptTextureBufferType(TType&);
  84. bool acceptConstantBufferType(TType&);
  85. bool acceptStruct(TType&, TIntermNode*& nodeList);
  86. bool acceptStructDeclarationList(TTypeList*&, TIntermNode*& nodeList, TVector<TFunctionDeclarator>&);
  87. bool acceptMemberFunctionDefinition(TIntermNode*& nodeList, const TType&, TString& memberName,
  88. TFunctionDeclarator&);
  89. bool acceptFunctionParameters(TFunction&);
  90. bool acceptParameterDeclaration(TFunction&);
  91. bool acceptFunctionDefinition(TFunctionDeclarator&, TIntermNode*& nodeList, TVector<HlslToken>* deferredTokens);
  92. bool acceptFunctionBody(TFunctionDeclarator& declarator, TIntermNode*& nodeList);
  93. bool acceptParenExpression(TIntermTyped*&);
  94. bool acceptExpression(TIntermTyped*&);
  95. bool acceptInitializer(TIntermTyped*&);
  96. bool acceptAssignmentExpression(TIntermTyped*&);
  97. bool acceptConditionalExpression(TIntermTyped*&);
  98. bool acceptBinaryExpression(TIntermTyped*&, PrecedenceLevel);
  99. bool acceptUnaryExpression(TIntermTyped*&);
  100. bool acceptPostfixExpression(TIntermTyped*&);
  101. bool acceptConstructor(TIntermTyped*&);
  102. bool acceptFunctionCall(const TSourceLoc&, TString& name, TIntermTyped*&, TIntermTyped* objectBase);
  103. bool acceptArguments(TFunction*, TIntermTyped*&);
  104. bool acceptLiteral(TIntermTyped*&);
  105. bool acceptSimpleStatement(TIntermNode*&);
  106. bool acceptCompoundStatement(TIntermNode*&);
  107. bool acceptScopedStatement(TIntermNode*&);
  108. bool acceptScopedCompoundStatement(TIntermNode*&);
  109. bool acceptStatement(TIntermNode*&);
  110. bool acceptNestedStatement(TIntermNode*&);
  111. void acceptAttributes(TAttributes&);
  112. bool acceptSelectionStatement(TIntermNode*&, const TAttributes&);
  113. bool acceptSwitchStatement(TIntermNode*&, const TAttributes&);
  114. bool acceptIterationStatement(TIntermNode*&, const TAttributes&);
  115. bool acceptJumpStatement(TIntermNode*&);
  116. bool acceptCaseLabel(TIntermNode*&);
  117. bool acceptDefaultLabel(TIntermNode*&);
  118. void acceptArraySpecifier(TArraySizes*&);
  119. bool acceptPostDecls(TQualifier&);
  120. bool acceptDefaultParameterDeclaration(const TType&, TIntermTyped*&);
  121. bool captureBlockTokens(TVector<HlslToken>& tokens);
  122. const char* getTypeString(EHlslTokenClass tokenClass) const;
  123. HlslParseContext& parseContext; // state of parsing and helper functions for building the intermediate
  124. TIntermediate& intermediate; // the final product, the intermediate representation, includes the AST
  125. bool typeIdentifiers; // shader uses some types as identifiers
  126. TIntermNode* unitNode;
  127. };
  128. } // end namespace glslang
  129. #endif // HLSLGRAMMAR_H_