Sarah Mashayekhi | 462dd67 | 2020-03-04 20:51:29 +0000 | [diff] [blame^] | 1 | // Copyright 2020 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_VALIDATOR_IMPL_H_ |
| 16 | #define SRC_VALIDATOR_IMPL_H_ |
| 17 | |
| 18 | #include <string> |
| 19 | |
| 20 | #include "src/ast/module.h" |
| 21 | |
| 22 | namespace tint { |
| 23 | |
| 24 | /// Determines if the module is complete and valid |
| 25 | class ValidatorImpl { |
| 26 | public: |
| 27 | /// Constructor |
| 28 | ValidatorImpl(); |
| 29 | ~ValidatorImpl(); |
| 30 | |
| 31 | /// Runs the validator |
| 32 | /// @param module the module to validate |
| 33 | /// @returns true if the validation was successful |
| 34 | bool Validate(const ast::Module& module); |
| 35 | |
| 36 | /// @returns error messages from the validator |
| 37 | const std::string& error() { return error_; } |
| 38 | |
| 39 | /// @returns true if an error was encountered |
| 40 | bool has_error() const { return error_.size() > 0; } |
| 41 | |
| 42 | /// Sets the error string |
| 43 | /// @param src the source causing the error |
| 44 | /// @param msg the error message |
| 45 | void set_error(const Source& src, const std::string& msg); |
| 46 | |
| 47 | /// Validates v-0001: Only allowed import is "GLSL.std.450" |
| 48 | /// @param module the modele to check imports |
| 49 | /// @returns ture if input complies with v-0001 rule |
| 50 | bool CheckImports(const ast::Module& module); |
| 51 | |
| 52 | private: |
| 53 | std::string error_; |
| 54 | }; |
| 55 | |
| 56 | } // namespace tint |
| 57 | |
| 58 | #endif // SRC_VALIDATOR_IMPL_H_ |