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