tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ValidateAST.h (5212B)


      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.  For built-ins, this
     27    // makes sure that the same GLSL built-in uses the same TVariable consistently.
     28    bool validateVariableReferences = true;
     29    // Whether validateVariableReferences should also include specialization constants.  Their
     30    // declaration is output after their usage is discovered, so this is disabled until then.
     31    bool validateSpecConstReferences = false;
     32    // Check that TIntermUnary and TIntermAggregate nodes with a built-in op reference a function
     33    // with said op.
     34    bool validateBuiltInOps = true;
     35    // Check that all EOpCallFunctionInAST have their corresponding function definitions in the AST,
     36    // with matching symbol ids. There should also be at least a prototype declaration before the
     37    // function is called.
     38    bool validateFunctionCall = true;
     39    // Check that EOpCallInternalRawFunction is not used.  This OP is deprecated and needs to be
     40    // removed.  http://anglebug.com/6059
     41    bool validateNoRawFunctionCalls = true;
     42    // Check that there are no null nodes where they are not allowed, for example as children of
     43    // TIntermDeclaration or TIntermBlock.
     44    bool validateNullNodes = true;
     45    // Check that symbols that reference variables have consistent qualifiers and symbol ids with
     46    // the variable declaration.  The following needs to be validated:
     47    //
     48    // Implemented:
     49    //
     50    //  - Function parameters having one of EvqParam* qualifiers.
     51    //  - No const qualifier on opaque function parameters.
     52    //  - gl_ClipDistance, gl_CullDistance and gl_LastFragData are correctly qualified even when
     53    //    redeclared in the shader.
     54    //
     55    // TODO:
     56    //
     57    //  - Function-local variables must have the EvqTemporary qualifier.
     58    //  - Symbol references and declarations have identical qualifiers.
     59    bool validateQualifiers = true;
     60    // Check that every symbol has its precision specified.  That includes variables, block members,
     61    // function parameters and return values.
     62    bool validatePrecision = true;
     63    // Check that variable declarations that can't have initializers don't have initializers
     64    // (varyings, uniforms for example).
     65    bool validateInitializers = true;  // TODO
     66    // Check that there is only one TFunction with each function name referenced in the nodes (no
     67    // two TFunctions with the same name, taking internal/non-internal namespaces into account).
     68    bool validateUniqueFunctions = true;  // TODO
     69    // Check that references to structs are matched with the corresponding struct declaration.
     70    bool validateStructUsage = true;
     71    // Check that expression nodes have the correct type considering their operand(s).  The
     72    // following validation is possible:
     73    //
     74    // Implemented:
     75    //
     76    //  - Binary node that indexes T[] should have type T
     77    //  - Binary nodes with EOpIndexDirect* should have a constant as the right node
     78    //  - Switch nodes should have an integer type in the selector
     79    //
     80    // TODO:
     81    //
     82    //  - Function calls (including built-ins) have the same return type in the node and function.
     83    //  - Unary and binary operators have the correct type based on operands
     84    //  - Swizzle result has same type as the operand except for vector size
     85    //  - Ternary operator has the same type as the operands
     86    //  - Case expressions have the same type as the switch selector
     87    bool validateExpressionTypes = true;
     88    // If SeparateDeclarations has been run, check for the absence of multi declarations as well.
     89    bool validateMultiDeclarations = false;
     90    // If PruneNoOps has been run, check that no statements are ever added after branches in the
     91    // same block.  Those statements would be dead code.
     92    bool validateNoStatementsAfterBranch = false;
     93    // Check that swizzle is not applied to swizzle.  Swizzles of swizzles are folded in
     94    // TIntermSwizzle::fold.
     95    bool validateNoSwizzleOfSwizzle = true;
     96 
     97    // Once set, disallows any further transformations on the tree.  Used before AST post-processing
     98    // which requires that the tree remains unmodified.
     99    bool validateNoMoreTransformations = false;
    100 };
    101 
    102 // Check for errors and output error messages on the context.
    103 // Returns true if there are no errors.
    104 bool ValidateAST(TIntermNode *root, TDiagnostics *diagnostics, const ValidateASTOptions &options);
    105 
    106 }  // namespace sh
    107 
    108 #endif  // COMPILER_TRANSLATOR_VALIDATESWITCH_H_