1 //
2 // Copyright 2012 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 #include "PreprocessorTest.h"
8 #include "compiler/preprocessor/Token.h"
9
10 namespace angle
11 {
12
preprocess(const char * input,std::stringstream * output,pp::Preprocessor * preprocessor)13 void SimplePreprocessorTest::preprocess(const char *input,
14 std::stringstream *output,
15 pp::Preprocessor *preprocessor)
16 {
17 ASSERT_TRUE(preprocessor->init(1, &input, nullptr));
18
19 int line = 1;
20 pp::Token token;
21 do
22 {
23 preprocessor->lex(&token);
24 if (output)
25 {
26 for (; line < token.location.line; ++line)
27 {
28 *output << "\n";
29 }
30 *output << token;
31 }
32 } while (token.type != pp::Token::LAST);
33 }
34
preprocess(const char * input,const pp::PreprocessorSettings & settings)35 void SimplePreprocessorTest::preprocess(const char *input, const pp::PreprocessorSettings &settings)
36 {
37 pp::Preprocessor preprocessor(&mDiagnostics, &mDirectiveHandler, settings);
38 preprocess(input, nullptr, &preprocessor);
39 }
40
preprocess(const char * input)41 void SimplePreprocessorTest::preprocess(const char *input)
42 {
43 preprocess(input, pp::PreprocessorSettings(SH_GLES2_SPEC));
44 }
45
preprocess(const char * input,const char * expected)46 void SimplePreprocessorTest::preprocess(const char *input, const char *expected)
47 {
48 preprocess(input, expected, SH_GLES2_SPEC);
49 }
50
preprocess(const char * input,const char * expected,ShShaderSpec spec)51 void SimplePreprocessorTest::preprocess(const char *input, const char *expected, ShShaderSpec spec)
52 {
53 pp::Preprocessor preprocessor(&mDiagnostics, &mDirectiveHandler,
54 pp::PreprocessorSettings(spec));
55 std::stringstream output;
56 preprocess(input, &output, &preprocessor);
57
58 std::string actual = output.str();
59 EXPECT_STREQ(expected, actual.c_str());
60 }
61
lexSingleToken(const char * input,pp::Token * token)62 void SimplePreprocessorTest::lexSingleToken(const char *input, pp::Token *token)
63 {
64 pp::Preprocessor preprocessor(&mDiagnostics, &mDirectiveHandler,
65 pp::PreprocessorSettings(SH_GLES2_SPEC));
66 ASSERT_TRUE(preprocessor.init(1, &input, nullptr));
67 preprocessor.lex(token);
68 }
69
lexSingleToken(size_t count,const char * const input[],pp::Token * token)70 void SimplePreprocessorTest::lexSingleToken(size_t count,
71 const char *const input[],
72 pp::Token *token)
73 {
74 pp::Preprocessor preprocessor(&mDiagnostics, &mDirectiveHandler,
75 pp::PreprocessorSettings(SH_GLES2_SPEC));
76 ASSERT_TRUE(preprocessor.init(count, input, nullptr));
77 preprocessor.lex(token);
78 }
79
80 } // namespace angle
81