1 // 2 // Copyright 2019 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 7 #ifndef COMPILER_TRANSLATOR_VALIDATEAST_H_ 8 #define COMPILER_TRANSLATOR_VALIDATEAST_H_ 9 10 #include "compiler/translator/BaseTypes.h" 11 #include "compiler/translator/Common.h" 12 13 namespace sh 14 { 15 class TDiagnostics; 16 class TIntermNode; 17 18 // The following options (stored in Compiler) tell the validator what to validate. Some validations 19 // are conditional to certain passes. 20 struct ValidateASTOptions 21 { 22 // TODO: add support for the flags marked with TODO. http://anglebug.com/2733 23 24 // Check that every node always has only one parent, 25 bool validateSingleParent = true; 26 // Check that all symbols reference TVariables that have been declared. 27 bool validateVariableReferences = true; 28 // Whether validateVariableReferences should also include specialization constants. Their 29 // declaration is output after their usage is discovered, so this is disabled until then. 30 bool validateSpecConstReferences = false; 31 // Check that TIntermUnary and TIntermAggregate nodes with a built-in op reference a function 32 // with said op. 33 bool validateBuiltInOps = true; 34 // Check that all EOpCallFunctionInAST have their corresponding function definitions in the AST, 35 // with matching symbol ids. There should also be at least a prototype declaration before the 36 // function is called. 37 bool validateFunctionCall = true; // TODO 38 // Check that there are no null nodes where they are not allowed, for example as children of 39 // TIntermDeclaration or TIntermBlock. 40 bool validateNullNodes = true; 41 // Check that symbols that reference variables have consistent qualifiers and symbol ids with 42 // the variable declaration. For example, references to function out parameters should be 43 // EvqOut. 44 bool validateQualifiers = true; // TODO 45 // Check that variable declarations that can't have initializers don't have initializers 46 // (varyings, uniforms for example). 47 bool validateInitializers = true; // TODO 48 // Check that there is only one TFunction with each function name referenced in the nodes (no 49 // two TFunctions with the same name, taking internal/non-internal namespaces into account). 50 bool validateUniqueFunctions = true; // TODO 51 // Check that references to structs are matched with the corresponding struct declaration. This 52 // is only done for references to structs inside other struct or interface blocks declarations, 53 // as validateVariableReferences already ensures other references to the struct match the 54 // declaration. 55 bool validateStructUsage = true; 56 // Check that expression nodes have the correct type considering their operand(s). 57 bool validateExpressionTypes = true; // TODO 58 // If SeparateDeclarations has been run, check for the absence of multi declarations as well. 59 bool validateMultiDeclarations = false; 60 }; 61 62 // Check for errors and output error messages on the context. 63 // Returns true if there are no errors. 64 bool ValidateAST(TIntermNode *root, TDiagnostics *diagnostics, const ValidateASTOptions &options); 65 66 } // namespace sh 67 68 #endif // COMPILER_TRANSLATOR_VALIDATESWITCH_H_ 69