diff --git a/include/amber/amber.h b/include/amber/amber.h index 2b1447568..d7e1d2c65 100644 --- a/include/amber/amber.h +++ b/include/amber/amber.h @@ -105,8 +105,10 @@ class Amber { Amber(); ~Amber(); - /// Parse the given |data| into the |recipe|. - amber::Result Parse(const std::string& data, amber::Recipe* recipe); + /// Parse the given |data| into the |recipe|. Perform validation if + /// |validate| set to true. + amber::Result Parse(const std::string& data, amber::Recipe* recipe, + const bool validate = true); /// Determines whether the engine supports all features required by the /// |recipe|. Modifies the |recipe| by applying some of the |opts| to the diff --git a/src/amber.cc b/src/amber.cc index 183ebacfb..44c2cb0ca 100644 --- a/src/amber.cc +++ b/src/amber.cc @@ -86,7 +86,9 @@ Amber::Amber() = default; Amber::~Amber() = default; -amber::Result Amber::Parse(const std::string& input, amber::Recipe* recipe) { +amber::Result Amber::Parse(const std::string& input, + amber::Recipe* recipe, + const bool validate) { if (!recipe) return Result("Recipe must be provided to Parse."); @@ -96,6 +98,9 @@ amber::Result Amber::Parse(const std::string& input, amber::Recipe* recipe) { else parser = MakeUnique(); + if (!validate) + parser->SkipValidationForTest(); + Result r = parser->Parse(input); if (!r.IsSuccess()) return r; diff --git a/src/amberscript/parser.cc b/src/amberscript/parser.cc index d914b34c7..e2667d229 100644 --- a/src/amberscript/parser.cc +++ b/src/amberscript/parser.cc @@ -123,10 +123,12 @@ Result Parser::Parse(const std::string& data) { // Validate all the pipelines at the end. This allows us to verify the // framebuffer sizes are consistent over pipelines. - for (const auto& pipeline : script_->GetPipelines()) { - Result r = pipeline->Validate(); - if (!r.IsSuccess()) - return r; + if (!skip_validation_for_test_) { + for (const auto& pipeline : script_->GetPipelines()) { + Result r = pipeline->Validate(); + if (!r.IsSuccess()) + return r; + } } return {}; diff --git a/src/amberscript/parser.h b/src/amberscript/parser.h index f5d7b46b7..24c2e9313 100644 --- a/src/amberscript/parser.h +++ b/src/amberscript/parser.h @@ -39,7 +39,12 @@ class Parser : public amber::Parser { // amber::Parser Result Parse(const std::string& data) override; + /// Disables validation after parse. + void SkipValidationForTest() { skip_validation_for_test_ = true; } + private: + bool skip_validation_for_test_ = false; + std::string make_error(const std::string& err); Result ToShaderType(const std::string& str, ShaderType* type); Result ToBufferType(const std::string& str, BufferType* type); diff --git a/src/parser.h b/src/parser.h index 20a17136a..cfc23e5d0 100644 --- a/src/parser.h +++ b/src/parser.h @@ -33,6 +33,9 @@ class Parser { /// completes correctly. virtual Result Parse(const std::string& data) = 0; + /// Disables validation after parse. + virtual void SkipValidationForTest() = 0; + /// Retrieve the script which is generated by the parser. std::unique_ptr