1 // Copyright 2021 The Tint Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef SRC_AST_DISABLE_VALIDATION_DECORATION_H_ 16 #define SRC_AST_DISABLE_VALIDATION_DECORATION_H_ 17 18 #include <string> 19 20 #include "src/ast/internal_decoration.h" 21 22 namespace tint { 23 namespace ast { 24 25 /// Enumerator of validation features that can be disabled with a 26 /// DisableValidationDecoration decoration. 27 enum class DisabledValidation { 28 /// When applied to a function, the validator will not complain there is no 29 /// body to a function. 30 kFunctionHasNoBody, 31 /// When applied to a module-scoped variable, the validator will not complain 32 /// if two resource variables have the same binding points. 33 kBindingPointCollision, 34 /// When applied to a variable, the validator will not complain about the 35 /// declared storage class. 36 kIgnoreStorageClass, 37 /// When applied to an entry-point function parameter, the validator will not 38 /// check for entry IO decorations. 39 kEntryPointParameter, 40 /// When applied to a function parameter, the validator will not 41 /// check if parameter type is constructible 42 kIgnoreConstructibleFunctionParameter, 43 /// When applied to a member decoration, a stride decoration may be applied to 44 /// non-array types. 45 kIgnoreStrideDecoration, 46 /// When applied to a pointer function parameter, the validator will not 47 /// require a function call argument passed for that parameter to have a 48 /// certain form. 49 kIgnoreInvalidPointerArgument, 50 }; 51 52 /// An internal decoration used to tell the validator to ignore specific 53 /// violations. Typically generated by transforms that need to produce ASTs that 54 /// would otherwise cause validation errors. 55 class DisableValidationDecoration 56 : public Castable<DisableValidationDecoration, InternalDecoration> { 57 public: 58 /// Constructor 59 /// @param program_id the identifier of the program that owns this node 60 /// @param validation the validation to disable 61 explicit DisableValidationDecoration(ProgramID program_id, 62 DisabledValidation validation); 63 64 /// Destructor 65 ~DisableValidationDecoration() override; 66 67 /// @return a short description of the internal decoration which will be 68 /// displayed in WGSL as `[[internal(<name>)]]` (but is not parsable). 69 std::string InternalName() const override; 70 71 /// Performs a deep clone of this object using the CloneContext `ctx`. 72 /// @param ctx the clone context 73 /// @return the newly cloned object 74 const DisableValidationDecoration* Clone(CloneContext* ctx) const override; 75 76 /// The validation that this decoration disables 77 const DisabledValidation validation; 78 }; 79 80 } // namespace ast 81 } // namespace tint 82 83 #endif // SRC_AST_DISABLE_VALIDATION_DECORATION_H_ 84