Hash :
26e355b8
Author :
Date :
2015-08-14T14:16:19
Add full support for line continuation in the preprocessor
Re-landing earlier change with constant signedness fixed (was causing
build issues on Linux).
Line continuation in ESSL 3.00 needs to be processed before tokenization,
since tokens can span the line continuation. On the other hand, ANGLE's
tokenizer keeps track of line numbers, and whenever a line continuation
appears the line number still needs to be incremented by one, just like
on a regular newline.
That's why line continuation is now implemented as follows: when the
shader strings are concatenated in Input, they are also checked for line
continuation. Whenever line continuation is encountered, the string
is cut before that point. When the tokenizer asks for more input, the
string starting from the character after line continuation is passed
to it, and the line number is incremented from Input. This way the
tokenizer can parse tokens that span multiple lines - it never sees the
line continuation - but still keeps track of the line number correctly.
Relevant spec is in ESSL 3.00 section 3.2 "Source strings".
Support for line continuation also applies to ESSL 1.00. ESSL 3.00
spec section 1.5 says that line continuation support is mandated when
an ESSL 1.00 shader is used with the OpenGL ES 3.0 API, and is optional
when ESSL 1.00 is used with the OpenGL ES 2.0 API.
TEST=dEQP-GLES3.functional.shaders.preprocessor.line_continuation.*
(all pass),
angle_unittests
BUG=angleproject:1125
Change-Id: Ic086aacac53cd75bf93c0fda782416501d2f842b
Reviewed-on: https://chromium-review.googlesource.com/294200
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Tested-by: Olli Etuaho <oetuaho@nvidia.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
//
// Copyright (c) 2011 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#ifndef COMPILER_PREPROCESSOR_INPUT_H_
#define COMPILER_PREPROCESSOR_INPUT_H_
#include <stddef.h>
#include <vector>
namespace pp
{
// Holds and reads input for Lexer.
class Input
{
public:
Input();
Input(size_t count, const char *const string[], const int length[]);
size_t count() const
{
return mCount;
}
const char *string(size_t index) const
{
return mString[index];
}
size_t length(size_t index) const
{
return mLength[index];
}
size_t read(char *buf, size_t maxSize, int *lineNo);
struct Location
{
size_t sIndex; // String index;
size_t cIndex; // Char index.
Location()
: sIndex(0),
cIndex(0)
{
}
};
const Location &readLoc() const { return mReadLoc; }
private:
// Skip a character and return the next character after the one that was skipped.
// Return nullptr if data runs out.
const char *skipChar();
// Input.
size_t mCount;
const char * const *mString;
std::vector<size_t> mLength;
Location mReadLoc;
};
} // namespace pp
#endif // COMPILER_PREPROCESSOR_INPUT_H_