dawn-cmake/src/tint/reader/wgsl/parser_impl_test_helper.h
dan sinclair 0cbf5a922f Pre-parse token list.
This CL updates the parser and lexer to pre-parse the token list and
then the parser works off the list of tokens. This allows the parser to
work with references to the tokens and not have to worry about them
going stale.

For any splittable token a placeholder token is injected after the
token. If the token ends up getting split the placeholder is overwritten
with the new type.

Change-Id: I5a8ccca15d8c14b5027df7dd2734be6753e46fa9
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/97070
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
2022-07-25 16:43:08 +00:00

76 lines
2.4 KiB
C++

// Copyright 2020 The Tint Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SRC_TINT_READER_WGSL_PARSER_IMPL_TEST_HELPER_H_
#define SRC_TINT_READER_WGSL_PARSER_IMPL_TEST_HELPER_H_
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "gtest/gtest.h"
#include "src/tint/reader/wgsl/parser_impl.h"
namespace tint::reader::wgsl {
/// WGSL Parser test class
class ParserImplTest : public testing::Test, public ProgramBuilder {
public:
/// Constructor
ParserImplTest();
~ParserImplTest() override;
/// Retrieves the parser from the helper
/// @param str the string to parse
/// @returns the parser implementation
std::unique_ptr<ParserImpl> parser(const std::string& str) {
auto file = std::make_unique<Source::File>("test.wgsl", str);
auto impl = std::make_unique<ParserImpl>(file.get());
impl->InitializeLex();
files_.emplace_back(std::move(file));
return impl;
}
private:
std::vector<std::unique_ptr<Source::File>> files_;
};
/// WGSL Parser test class with param
template <typename T>
class ParserImplTestWithParam : public testing::TestWithParam<T>, public ProgramBuilder {
public:
/// Constructor
ParserImplTestWithParam() = default;
~ParserImplTestWithParam() override = default;
/// Retrieves the parser from the helper
/// @param str the string to parse
/// @returns the parser implementation
std::unique_ptr<ParserImpl> parser(const std::string& str) {
auto file = std::make_unique<Source::File>("test.wgsl", str);
auto impl = std::make_unique<ParserImpl>(file.get());
impl->InitializeLex();
files_.emplace_back(std::move(file));
return impl;
}
private:
std::vector<std::unique_ptr<Source::File>> files_;
};
} // namespace tint::reader::wgsl
#endif // SRC_TINT_READER_WGSL_PARSER_IMPL_TEST_HELPER_H_