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 // Check that all EOpCallFunctionInAST have their corresponding function definitions in the AST, 29 // with matching symbol ids. There should also be at least a prototype declaration before the 30 // function is called. 31 bool validateFunctionCall = true; // TODO 32 // Check that there are no null nodes where they are not allowed, for example as children of 33 // TIntermDeclaration or TIntermBlock. 34 bool validateNullNodes = true; 35 // Check that symbols that reference variables have consistent qualifiers and symbol ids with 36 // the variable declaration. For example, references to function out parameters should be 37 // EvqOut. 38 bool validateQualifiers = true; // TODO 39 // Check that variable declarations that can't have initializers don't have initializers 40 // (varyings, uniforms for example). 41 bool validateInitializers = true; // TODO 42 // Check that there is only one TFunction with each function name referenced in the nodes (no 43 // two TFunctions with the same name, taking internal/non-internal namespaces into account). 44 bool validateUniqueFunctions = true; // TODO 45 // Check that references to structs are matched with the corresponding struct declaration. This 46 // is only done for references to structs inside other struct or interface blocks declarations, 47 // as validateVariableReferences already ensures other references to the struct match the 48 // declaration. 49 bool validateStructUsage = true; 50 // Check that expression nodes have the correct type considering their operand(s). 51 bool validateExpressionTypes = true; // TODO 52 // If SeparateDeclarations has been run, check for the absence of multi declarations as well. 53 bool validateMultiDeclarations = false; 54 }; 55 56 // Check for errors and output error messages on the context. 57 // Returns true if there are no errors. 58 bool ValidateAST(TIntermNode *root, TDiagnostics *diagnostics, const ValidateASTOptions &options); 59 60 } // namespace sh 61 62 #endif // COMPILER_TRANSLATOR_VALIDATESWITCH_H_ 63