aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sksl/ast
diff options
context:
space:
mode:
authorGravatar Ethan Nicholas <ethannicholas@google.com>2017-09-11 16:33:48 +0000
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-09-11 16:34:02 +0000
commit358515491a0d6891e6a709688a30ad087df1beb1 (patch)
treece64223230053df7db85c94b848ad526e64269cd /src/sksl/ast
parentc576e93d174f3106e072a2f506bca3990b541265 (diff)
Revert "Switch to the new SkSL lexer."
This reverts commit c576e93d174f3106e072a2f506bca3990b541265. Reason for revert: ASAN failures Original change's description: > Switch to the new SkSL lexer. > > This completely replaces flex with a new in-house lexical analyzer generator, > which we have done for performance and memory usage reasons. Flex requires us > to copy strings every time we need the text of a token, whereas this new lexer > allows us to handle strings as a (non-null-terminated) pointer and length > everywhere, eliminating most string copies. > > Bug: skia: > Change-Id: I2add26efc9e20cb699520e82abcf713af3968aca > Reviewed-on: https://skia-review.googlesource.com/39780 > Reviewed-by: Brian Salomon <bsalomon@google.com> > Commit-Queue: Ethan Nicholas <ethannicholas@google.com> TBR=bsalomon@google.com,ethannicholas@google.com Change-Id: If27b750a5f696d06a6bcffed12fe9f0598e084a6 No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: skia: Reviewed-on: https://skia-review.googlesource.com/44881 Reviewed-by: Ethan Nicholas <ethannicholas@google.com> Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Diffstat (limited to 'src/sksl/ast')
-rw-r--r--src/sksl/ast/SkSLASTBinaryExpression.h7
-rw-r--r--src/sksl/ast/SkSLASTBlock.h4
-rw-r--r--src/sksl/ast/SkSLASTBoolLiteral.h4
-rw-r--r--src/sksl/ast/SkSLASTBreakStatement.h4
-rw-r--r--src/sksl/ast/SkSLASTCallSuffix.h4
-rw-r--r--src/sksl/ast/SkSLASTContinueStatement.h4
-rw-r--r--src/sksl/ast/SkSLASTDeclaration.h4
-rw-r--r--src/sksl/ast/SkSLASTDiscardStatement.h4
-rw-r--r--src/sksl/ast/SkSLASTDoStatement.h4
-rw-r--r--src/sksl/ast/SkSLASTExpression.h4
-rw-r--r--src/sksl/ast/SkSLASTExpressionStatement.h2
-rw-r--r--src/sksl/ast/SkSLASTExtension.h4
-rw-r--r--src/sksl/ast/SkSLASTFieldSuffix.h8
-rw-r--r--src/sksl/ast/SkSLASTFloatLiteral.h4
-rw-r--r--src/sksl/ast/SkSLASTForStatement.h4
-rw-r--r--src/sksl/ast/SkSLASTFunction.h10
-rw-r--r--src/sksl/ast/SkSLASTIdentifier.h10
-rw-r--r--src/sksl/ast/SkSLASTIfStatement.h4
-rw-r--r--src/sksl/ast/SkSLASTIndexSuffix.h6
-rw-r--r--src/sksl/ast/SkSLASTIntLiteral.h4
-rw-r--r--src/sksl/ast/SkSLASTInterfaceBlock.h18
-rw-r--r--src/sksl/ast/SkSLASTModifiersDeclaration.h2
-rw-r--r--src/sksl/ast/SkSLASTParameter.h10
-rw-r--r--src/sksl/ast/SkSLASTPositionNode.h8
-rw-r--r--src/sksl/ast/SkSLASTPrecision.h4
-rw-r--r--src/sksl/ast/SkSLASTPrefixExpression.h7
-rw-r--r--src/sksl/ast/SkSLASTReturnStatement.h4
-rw-r--r--src/sksl/ast/SkSLASTSection.h4
-rw-r--r--src/sksl/ast/SkSLASTStatement.h4
-rw-r--r--src/sksl/ast/SkSLASTSuffix.h4
-rw-r--r--src/sksl/ast/SkSLASTSuffixExpression.h2
-rw-r--r--src/sksl/ast/SkSLASTSwitchCase.h4
-rw-r--r--src/sksl/ast/SkSLASTSwitchStatement.h4
-rw-r--r--src/sksl/ast/SkSLASTTernaryExpression.h2
-rw-r--r--src/sksl/ast/SkSLASTType.h8
-rw-r--r--src/sksl/ast/SkSLASTVarDeclaration.h8
-rw-r--r--src/sksl/ast/SkSLASTVarDeclarationStatement.h2
-rw-r--r--src/sksl/ast/SkSLASTWhileStatement.h4
38 files changed, 97 insertions, 101 deletions
diff --git a/src/sksl/ast/SkSLASTBinaryExpression.h b/src/sksl/ast/SkSLASTBinaryExpression.h
index c2f7b749a5..9a24970262 100644
--- a/src/sksl/ast/SkSLASTBinaryExpression.h
+++ b/src/sksl/ast/SkSLASTBinaryExpression.h
@@ -9,8 +9,7 @@
#define SKSL_ASTBINARYEXPRESSION
#include "SkSLASTExpression.h"
-#include "../SkSLCompiler.h"
-#include "../SkSLLexer.h"
+#include "../SkSLToken.h"
namespace SkSL {
@@ -20,13 +19,13 @@ namespace SkSL {
struct ASTBinaryExpression : public ASTExpression {
ASTBinaryExpression(std::unique_ptr<ASTExpression> left, Token op,
std::unique_ptr<ASTExpression> right)
- : INHERITED(op.fOffset, kBinary_Kind)
+ : INHERITED(op.fPosition, kBinary_Kind)
, fLeft(std::move(left))
, fOperator(op.fKind)
, fRight(std::move(right)) {}
String description() const override {
- return "(" + fLeft->description() + " " + Compiler::OperatorName(fOperator) + " " +
+ return "(" + fLeft->description() + " " + Token::OperatorName(fOperator) + " " +
fRight->description() + ")";
}
diff --git a/src/sksl/ast/SkSLASTBlock.h b/src/sksl/ast/SkSLASTBlock.h
index df01f62a15..37c0e81a95 100644
--- a/src/sksl/ast/SkSLASTBlock.h
+++ b/src/sksl/ast/SkSLASTBlock.h
@@ -16,8 +16,8 @@ namespace SkSL {
* Represents a curly-braced block of statements.
*/
struct ASTBlock : public ASTStatement {
- ASTBlock(int offset, std::vector<std::unique_ptr<ASTStatement>> statements)
- : INHERITED(offset, kBlock_Kind)
+ ASTBlock(Position position, std::vector<std::unique_ptr<ASTStatement>> statements)
+ : INHERITED(position, kBlock_Kind)
, fStatements(std::move(statements)) {}
String description() const override {
diff --git a/src/sksl/ast/SkSLASTBoolLiteral.h b/src/sksl/ast/SkSLASTBoolLiteral.h
index 6782d36e7e..48e916eed5 100644
--- a/src/sksl/ast/SkSLASTBoolLiteral.h
+++ b/src/sksl/ast/SkSLASTBoolLiteral.h
@@ -16,8 +16,8 @@ namespace SkSL {
* Represents "true" or "false".
*/
struct ASTBoolLiteral : public ASTExpression {
- ASTBoolLiteral(int offset, bool value)
- : INHERITED(offset, kBool_Kind)
+ ASTBoolLiteral(Position position, bool value)
+ : INHERITED(position, kBool_Kind)
, fValue(value) {}
String description() const override {
diff --git a/src/sksl/ast/SkSLASTBreakStatement.h b/src/sksl/ast/SkSLASTBreakStatement.h
index 2937dae447..079ee76d20 100644
--- a/src/sksl/ast/SkSLASTBreakStatement.h
+++ b/src/sksl/ast/SkSLASTBreakStatement.h
@@ -16,8 +16,8 @@ namespace SkSL {
* A 'break' statement.
*/
struct ASTBreakStatement : public ASTStatement {
- ASTBreakStatement(int offset)
- : INHERITED(offset, kBreak_Kind) {}
+ ASTBreakStatement(Position position)
+ : INHERITED(position, kBreak_Kind) {}
String description() const override {
return String("break;");
diff --git a/src/sksl/ast/SkSLASTCallSuffix.h b/src/sksl/ast/SkSLASTCallSuffix.h
index 316a0ae7cc..3ba3f0e60f 100644
--- a/src/sksl/ast/SkSLASTCallSuffix.h
+++ b/src/sksl/ast/SkSLASTCallSuffix.h
@@ -17,8 +17,8 @@ namespace SkSL {
* A parenthesized list of arguments following an expression, indicating a function call.
*/
struct ASTCallSuffix : public ASTSuffix {
- ASTCallSuffix(int offset, std::vector<std::unique_ptr<ASTExpression>> arguments)
- : INHERITED(offset, ASTSuffix::kCall_Kind)
+ ASTCallSuffix(Position position, std::vector<std::unique_ptr<ASTExpression>> arguments)
+ : INHERITED(position, ASTSuffix::kCall_Kind)
, fArguments(std::move(arguments)) {}
String description() const override {
diff --git a/src/sksl/ast/SkSLASTContinueStatement.h b/src/sksl/ast/SkSLASTContinueStatement.h
index 30b2dae4ec..fdfce8598d 100644
--- a/src/sksl/ast/SkSLASTContinueStatement.h
+++ b/src/sksl/ast/SkSLASTContinueStatement.h
@@ -16,8 +16,8 @@ namespace SkSL {
* A 'continue' statement.
*/
struct ASTContinueStatement : public ASTStatement {
- ASTContinueStatement(int offset)
- : INHERITED(offset, kContinue_Kind) {}
+ ASTContinueStatement(Position position)
+ : INHERITED(position, kContinue_Kind) {}
String description() const override {
return String("continue;");
diff --git a/src/sksl/ast/SkSLASTDeclaration.h b/src/sksl/ast/SkSLASTDeclaration.h
index 53aa65f6f2..873c6b2208 100644
--- a/src/sksl/ast/SkSLASTDeclaration.h
+++ b/src/sksl/ast/SkSLASTDeclaration.h
@@ -26,8 +26,8 @@ struct ASTDeclaration : public ASTPositionNode {
kSection_Kind
};
- ASTDeclaration(int offset, Kind kind)
- : INHERITED(offset)
+ ASTDeclaration(Position position, Kind kind)
+ : INHERITED(position)
, fKind(kind) {}
Kind fKind;
diff --git a/src/sksl/ast/SkSLASTDiscardStatement.h b/src/sksl/ast/SkSLASTDiscardStatement.h
index 083c3f82d7..dcf6b15e64 100644
--- a/src/sksl/ast/SkSLASTDiscardStatement.h
+++ b/src/sksl/ast/SkSLASTDiscardStatement.h
@@ -16,8 +16,8 @@ namespace SkSL {
* A 'discard' statement.
*/
struct ASTDiscardStatement : public ASTStatement {
- ASTDiscardStatement(int offset)
- : INHERITED(offset, kDiscard_Kind) {}
+ ASTDiscardStatement(Position position)
+ : INHERITED(position, kDiscard_Kind) {}
String description() const override {
return String("discard;");
diff --git a/src/sksl/ast/SkSLASTDoStatement.h b/src/sksl/ast/SkSLASTDoStatement.h
index 36324e3685..fc97d9e142 100644
--- a/src/sksl/ast/SkSLASTDoStatement.h
+++ b/src/sksl/ast/SkSLASTDoStatement.h
@@ -16,9 +16,9 @@ namespace SkSL {
* A 'do' loop.
*/
struct ASTDoStatement : public ASTStatement {
- ASTDoStatement(int offset, std::unique_ptr<ASTStatement> statement,
+ ASTDoStatement(Position position, std::unique_ptr<ASTStatement> statement,
std::unique_ptr<ASTExpression> test)
- : INHERITED(offset, kDo_Kind)
+ : INHERITED(position, kDo_Kind)
, fStatement(std::move(statement))
, fTest(std::move(test)) {}
diff --git a/src/sksl/ast/SkSLASTExpression.h b/src/sksl/ast/SkSLASTExpression.h
index 0d8ddc781f..11815aef84 100644
--- a/src/sksl/ast/SkSLASTExpression.h
+++ b/src/sksl/ast/SkSLASTExpression.h
@@ -27,8 +27,8 @@ struct ASTExpression : public ASTPositionNode {
kTernary_Kind
};
- ASTExpression(int offset, Kind kind)
- : INHERITED(offset)
+ ASTExpression(Position position, Kind kind)
+ : INHERITED(position)
, fKind(kind) {}
const Kind fKind;
diff --git a/src/sksl/ast/SkSLASTExpressionStatement.h b/src/sksl/ast/SkSLASTExpressionStatement.h
index 14f087f57c..398a16a23a 100644
--- a/src/sksl/ast/SkSLASTExpressionStatement.h
+++ b/src/sksl/ast/SkSLASTExpressionStatement.h
@@ -17,7 +17,7 @@ namespace SkSL {
*/
struct ASTExpressionStatement : public ASTStatement {
ASTExpressionStatement(std::unique_ptr<ASTExpression> expression)
- : INHERITED(expression->fOffset, kExpression_Kind)
+ : INHERITED(expression->fPosition, kExpression_Kind)
, fExpression(std::move(expression)) {}
String description() const override {
diff --git a/src/sksl/ast/SkSLASTExtension.h b/src/sksl/ast/SkSLASTExtension.h
index c394b1d4d0..a6fde0694c 100644
--- a/src/sksl/ast/SkSLASTExtension.h
+++ b/src/sksl/ast/SkSLASTExtension.h
@@ -16,8 +16,8 @@ namespace SkSL {
* An extension declaration.
*/
struct ASTExtension : public ASTDeclaration {
- ASTExtension(int offset, String name)
- : INHERITED(offset, kExtension_Kind)
+ ASTExtension(Position position, String name)
+ : INHERITED(position, kExtension_Kind)
, fName(std::move(name)) {}
String description() const override {
diff --git a/src/sksl/ast/SkSLASTFieldSuffix.h b/src/sksl/ast/SkSLASTFieldSuffix.h
index b29ddf3bda..bde1e4aec5 100644
--- a/src/sksl/ast/SkSLASTFieldSuffix.h
+++ b/src/sksl/ast/SkSLASTFieldSuffix.h
@@ -17,15 +17,15 @@ namespace SkSL {
* actually vector swizzle (which looks the same to the parser).
*/
struct ASTFieldSuffix : public ASTSuffix {
- ASTFieldSuffix(int offset, StringFragment field)
- : INHERITED(offset, ASTSuffix::kField_Kind)
- , fField(field) {}
+ ASTFieldSuffix(Position position, String field)
+ : INHERITED(position, ASTSuffix::kField_Kind)
+ , fField(std::move(field)) {}
String description() const override {
return "." + fField;
}
- StringFragment fField;
+ String fField;
typedef ASTSuffix INHERITED;
};
diff --git a/src/sksl/ast/SkSLASTFloatLiteral.h b/src/sksl/ast/SkSLASTFloatLiteral.h
index 6e63b4e4ca..15fe836049 100644
--- a/src/sksl/ast/SkSLASTFloatLiteral.h
+++ b/src/sksl/ast/SkSLASTFloatLiteral.h
@@ -16,8 +16,8 @@ namespace SkSL {
* A literal floating point number.
*/
struct ASTFloatLiteral : public ASTExpression {
- ASTFloatLiteral(int offset, double value)
- : INHERITED(offset, kFloat_Kind)
+ ASTFloatLiteral(Position position, double value)
+ : INHERITED(position, kFloat_Kind)
, fValue(value) {}
String description() const override {
diff --git a/src/sksl/ast/SkSLASTForStatement.h b/src/sksl/ast/SkSLASTForStatement.h
index 713f9522f7..326713eb62 100644
--- a/src/sksl/ast/SkSLASTForStatement.h
+++ b/src/sksl/ast/SkSLASTForStatement.h
@@ -16,10 +16,10 @@ namespace SkSL {
* A 'for' loop.
*/
struct ASTForStatement : public ASTStatement {
- ASTForStatement(int offset, std::unique_ptr<ASTStatement> initializer,
+ ASTForStatement(Position position, std::unique_ptr<ASTStatement> initializer,
std::unique_ptr<ASTExpression> test, std::unique_ptr<ASTExpression> next,
std::unique_ptr<ASTStatement> statement)
- : INHERITED(offset, kFor_Kind)
+ : INHERITED(position, kFor_Kind)
, fInitializer(std::move(initializer))
, fTest(std::move(test))
, fNext(std::move(next))
diff --git a/src/sksl/ast/SkSLASTFunction.h b/src/sksl/ast/SkSLASTFunction.h
index 4fa2482d8b..36d8a3af9f 100644
--- a/src/sksl/ast/SkSLASTFunction.h
+++ b/src/sksl/ast/SkSLASTFunction.h
@@ -19,13 +19,13 @@ namespace SkSL {
* A function declaration or definition. The fBody field will be null for declarations.
*/
struct ASTFunction : public ASTDeclaration {
- ASTFunction(int offset, Modifiers modifiers, std::unique_ptr<ASTType> returnType,
- StringFragment name, std::vector<std::unique_ptr<ASTParameter>> parameters,
+ ASTFunction(Position position, Modifiers modifiers, std::unique_ptr<ASTType> returnType,
+ String name, std::vector<std::unique_ptr<ASTParameter>> parameters,
std::unique_ptr<ASTBlock> body)
- : INHERITED(offset, kFunction_Kind)
+ : INHERITED(position, kFunction_Kind)
, fModifiers(modifiers)
, fReturnType(std::move(returnType))
- , fName(name)
+ , fName(std::move(name))
, fParameters(std::move(parameters))
, fBody(std::move(body)) {}
@@ -47,7 +47,7 @@ struct ASTFunction : public ASTDeclaration {
const Modifiers fModifiers;
const std::unique_ptr<ASTType> fReturnType;
- const StringFragment fName;
+ const String fName;
const std::vector<std::unique_ptr<ASTParameter>> fParameters;
const std::unique_ptr<ASTBlock> fBody;
diff --git a/src/sksl/ast/SkSLASTIdentifier.h b/src/sksl/ast/SkSLASTIdentifier.h
index a84370ec3f..016123cf8c 100644
--- a/src/sksl/ast/SkSLASTIdentifier.h
+++ b/src/sksl/ast/SkSLASTIdentifier.h
@@ -16,15 +16,15 @@ namespace SkSL {
* An identifier in an expression context.
*/
struct ASTIdentifier : public ASTExpression {
- ASTIdentifier(int offset, StringFragment text)
- : INHERITED(offset, kIdentifier_Kind)
- , fText(text) {}
+ ASTIdentifier(Position position, String text)
+ : INHERITED(position, kIdentifier_Kind)
+ , fText(std::move(text)) {}
String description() const override {
- return String(fText);
+ return fText;
}
- const StringFragment fText;
+ const String fText;
typedef ASTExpression INHERITED;
};
diff --git a/src/sksl/ast/SkSLASTIfStatement.h b/src/sksl/ast/SkSLASTIfStatement.h
index 85b1239e0b..2752b2b750 100644
--- a/src/sksl/ast/SkSLASTIfStatement.h
+++ b/src/sksl/ast/SkSLASTIfStatement.h
@@ -16,9 +16,9 @@ namespace SkSL {
* An 'if' statement.
*/
struct ASTIfStatement : public ASTStatement {
- ASTIfStatement(int offset, bool isStatic, std::unique_ptr<ASTExpression> test,
+ ASTIfStatement(Position position, bool isStatic, std::unique_ptr<ASTExpression> test,
std::unique_ptr<ASTStatement> ifTrue, std::unique_ptr<ASTStatement> ifFalse)
- : INHERITED(offset, kIf_Kind)
+ : INHERITED(position, kIf_Kind)
, fIsStatic(isStatic)
, fTest(std::move(test))
, fIfTrue(std::move(ifTrue))
diff --git a/src/sksl/ast/SkSLASTIndexSuffix.h b/src/sksl/ast/SkSLASTIndexSuffix.h
index cb19e549ef..31142e3685 100644
--- a/src/sksl/ast/SkSLASTIndexSuffix.h
+++ b/src/sksl/ast/SkSLASTIndexSuffix.h
@@ -18,12 +18,12 @@ namespace SkSL {
* 'float[](5, 6)' are represented with a null fExpression.
*/
struct ASTIndexSuffix : public ASTSuffix {
- ASTIndexSuffix(int offset)
- : INHERITED(offset, ASTSuffix::kIndex_Kind)
+ ASTIndexSuffix(Position position)
+ : INHERITED(position, ASTSuffix::kIndex_Kind)
, fExpression(nullptr) {}
ASTIndexSuffix(std::unique_ptr<ASTExpression> expression)
- : INHERITED(expression ? expression->fOffset : -1, ASTSuffix::kIndex_Kind)
+ : INHERITED(expression ? expression->fPosition : Position(), ASTSuffix::kIndex_Kind)
, fExpression(std::move(expression)) {}
String description() const override {
diff --git a/src/sksl/ast/SkSLASTIntLiteral.h b/src/sksl/ast/SkSLASTIntLiteral.h
index 927537b250..fe04347fd8 100644
--- a/src/sksl/ast/SkSLASTIntLiteral.h
+++ b/src/sksl/ast/SkSLASTIntLiteral.h
@@ -17,8 +17,8 @@ namespace SkSL {
* appear as a unary minus being applied to an integer literal.
*/
struct ASTIntLiteral : public ASTExpression {
- ASTIntLiteral(int offset, uint64_t value)
- : INHERITED(offset, kInt_Kind)
+ ASTIntLiteral(Position position, uint64_t value)
+ : INHERITED(position, kInt_Kind)
, fValue(value) {}
String description() const override {
diff --git a/src/sksl/ast/SkSLASTInterfaceBlock.h b/src/sksl/ast/SkSLASTInterfaceBlock.h
index d445ae0398..f111f73e18 100644
--- a/src/sksl/ast/SkSLASTInterfaceBlock.h
+++ b/src/sksl/ast/SkSLASTInterfaceBlock.h
@@ -23,17 +23,17 @@ namespace SkSL {
*/
struct ASTInterfaceBlock : public ASTDeclaration {
// valueName is empty when it was not present in the source
- ASTInterfaceBlock(int offset,
+ ASTInterfaceBlock(Position position,
Modifiers modifiers,
- StringFragment typeName,
+ String typeName,
std::vector<std::unique_ptr<ASTVarDeclarations>> declarations,
- StringFragment instanceName,
+ String instanceName,
std::vector<std::unique_ptr<ASTExpression>> sizes)
- : INHERITED(offset, kInterfaceBlock_Kind)
+ : INHERITED(position, kInterfaceBlock_Kind)
, fModifiers(modifiers)
- , fTypeName(typeName)
+ , fTypeName(std::move(typeName))
, fDeclarations(std::move(declarations))
- , fInstanceName(instanceName)
+ , fInstanceName(std::move(instanceName))
, fSizes(std::move(sizes)) {}
String description() const override {
@@ -42,7 +42,7 @@ struct ASTInterfaceBlock : public ASTDeclaration {
result += fDeclarations[i]->description() + "\n";
}
result += "}";
- if (fInstanceName.fLength) {
+ if (fInstanceName.size()) {
result += " " + fInstanceName;
for (const auto& size : fSizes) {
result += "[";
@@ -56,9 +56,9 @@ struct ASTInterfaceBlock : public ASTDeclaration {
}
const Modifiers fModifiers;
- const StringFragment fTypeName;
+ const String fTypeName;
const std::vector<std::unique_ptr<ASTVarDeclarations>> fDeclarations;
- const StringFragment fInstanceName;
+ const String fInstanceName;
const std::vector<std::unique_ptr<ASTExpression>> fSizes;
typedef ASTDeclaration INHERITED;
diff --git a/src/sksl/ast/SkSLASTModifiersDeclaration.h b/src/sksl/ast/SkSLASTModifiersDeclaration.h
index 5269cd54d4..ba07f168b2 100644
--- a/src/sksl/ast/SkSLASTModifiersDeclaration.h
+++ b/src/sksl/ast/SkSLASTModifiersDeclaration.h
@@ -20,7 +20,7 @@ namespace SkSL {
*/
struct ASTModifiersDeclaration : public ASTDeclaration {
ASTModifiersDeclaration(Modifiers modifiers)
- : INHERITED(-1, kModifiers_Kind)
+ : INHERITED(Position(), kModifiers_Kind)
, fModifiers(modifiers) {}
String description() const {
diff --git a/src/sksl/ast/SkSLASTParameter.h b/src/sksl/ast/SkSLASTParameter.h
index 965e374540..01227c637e 100644
--- a/src/sksl/ast/SkSLASTParameter.h
+++ b/src/sksl/ast/SkSLASTParameter.h
@@ -20,12 +20,12 @@ namespace SkSL {
struct ASTParameter : public ASTPositionNode {
// 'sizes' is a list of the array sizes appearing on a parameter, in source order.
// e.g. int x[3][1] would have sizes [3, 1].
- ASTParameter(int offset, Modifiers modifiers, std::unique_ptr<ASTType> type,
- StringFragment name, std::vector<int> sizes)
- : INHERITED(offset)
+ ASTParameter(Position position, Modifiers modifiers, std::unique_ptr<ASTType> type,
+ String name, std::vector<int> sizes)
+ : INHERITED(position)
, fModifiers(modifiers)
, fType(std::move(type))
- , fName(name)
+ , fName(std::move(name))
, fSizes(std::move(sizes)) {}
String description() const override {
@@ -38,7 +38,7 @@ struct ASTParameter : public ASTPositionNode {
const Modifiers fModifiers;
const std::unique_ptr<ASTType> fType;
- const StringFragment fName;
+ const String fName;
const std::vector<int> fSizes;
typedef ASTPositionNode INHERITED;
diff --git a/src/sksl/ast/SkSLASTPositionNode.h b/src/sksl/ast/SkSLASTPositionNode.h
index b8f22a765b..cc435c486c 100644
--- a/src/sksl/ast/SkSLASTPositionNode.h
+++ b/src/sksl/ast/SkSLASTPositionNode.h
@@ -17,12 +17,10 @@ namespace SkSL {
* An AST node with an associated position in the source.
*/
struct ASTPositionNode : public ASTNode {
- ASTPositionNode(int offset)
- : fOffset(offset) {}
+ ASTPositionNode(Position position)
+ : fPosition(position) {}
- // character offset of this element within the program being compiled, for error reporting
- // purposes
- const int fOffset;
+ const Position fPosition;
};
} // namespace
diff --git a/src/sksl/ast/SkSLASTPrecision.h b/src/sksl/ast/SkSLASTPrecision.h
index 0b81ca3887..4b50ed3979 100644
--- a/src/sksl/ast/SkSLASTPrecision.h
+++ b/src/sksl/ast/SkSLASTPrecision.h
@@ -18,8 +18,8 @@ namespace SkSL {
*/
struct ASTPrecision : public ASTDeclaration {
// FIXME handle the type
- ASTPrecision(int offset, Modifiers::Flag precision)
- : INHERITED(offset, kPrecision_Kind)
+ ASTPrecision(Position position, Modifiers::Flag precision)
+ : INHERITED(position, kPrecision_Kind)
, fPrecision(precision) {}
String description() const {
diff --git a/src/sksl/ast/SkSLASTPrefixExpression.h b/src/sksl/ast/SkSLASTPrefixExpression.h
index 0403a2f172..08e50f7bf1 100644
--- a/src/sksl/ast/SkSLASTPrefixExpression.h
+++ b/src/sksl/ast/SkSLASTPrefixExpression.h
@@ -9,8 +9,7 @@
#define SKSL_ASTPREFIXEXPRESSION
#include "SkSLASTExpression.h"
-#include "../SkSLCompiler.h"
-#include "../SkSLLexer.h"
+#include "../SkSLToken.h"
namespace SkSL {
@@ -19,12 +18,12 @@ namespace SkSL {
*/
struct ASTPrefixExpression : public ASTExpression {
ASTPrefixExpression(Token op, std::unique_ptr<ASTExpression> operand)
- : INHERITED(op.fOffset, kPrefix_Kind)
+ : INHERITED(op.fPosition, kPrefix_Kind)
, fOperator(op.fKind)
, fOperand(std::move(operand)) {}
String description() const override {
- return Compiler::OperatorName(fOperator) + fOperand->description();
+ return Token::OperatorName(fOperator) + fOperand->description();
}
const Token::Kind fOperator;
diff --git a/src/sksl/ast/SkSLASTReturnStatement.h b/src/sksl/ast/SkSLASTReturnStatement.h
index 489658a78b..6762eb3f90 100644
--- a/src/sksl/ast/SkSLASTReturnStatement.h
+++ b/src/sksl/ast/SkSLASTReturnStatement.h
@@ -17,8 +17,8 @@ namespace SkSL {
*/
struct ASTReturnStatement : public ASTStatement {
// expression may be null
- ASTReturnStatement(int offset, std::unique_ptr<ASTExpression> expression)
- : INHERITED(offset, kReturn_Kind)
+ ASTReturnStatement(Position position, std::unique_ptr<ASTExpression> expression)
+ : INHERITED(position, kReturn_Kind)
, fExpression(std::move(expression)) {}
String description() const override {
diff --git a/src/sksl/ast/SkSLASTSection.h b/src/sksl/ast/SkSLASTSection.h
index 6c1f8eefa2..d0887e20fe 100644
--- a/src/sksl/ast/SkSLASTSection.h
+++ b/src/sksl/ast/SkSLASTSection.h
@@ -16,8 +16,8 @@ namespace SkSL {
* A section declaration (e.g. @body { body code here })..
*/
struct ASTSection : public ASTDeclaration {
- ASTSection(int offset, String name, String arg, String text)
- : INHERITED(offset, kSection_Kind)
+ ASTSection(Position position, String name, String arg, String text)
+ : INHERITED(position, kSection_Kind)
, fName(std::move(name))
, fArgument(std::move(arg))
, fText(std::move(text)) {}
diff --git a/src/sksl/ast/SkSLASTStatement.h b/src/sksl/ast/SkSLASTStatement.h
index c22a2fbb0a..1989a1fce6 100644
--- a/src/sksl/ast/SkSLASTStatement.h
+++ b/src/sksl/ast/SkSLASTStatement.h
@@ -33,8 +33,8 @@ struct ASTStatement : public ASTPositionNode {
kDiscard_Kind
};
- ASTStatement(int offset, Kind kind)
- : INHERITED(offset)
+ ASTStatement(Position position, Kind kind)
+ : INHERITED(position)
, fKind(kind) {}
Kind fKind;
diff --git a/src/sksl/ast/SkSLASTSuffix.h b/src/sksl/ast/SkSLASTSuffix.h
index 898855c478..f06c6fd362 100644
--- a/src/sksl/ast/SkSLASTSuffix.h
+++ b/src/sksl/ast/SkSLASTSuffix.h
@@ -26,8 +26,8 @@ struct ASTSuffix : public ASTPositionNode {
kPostDecrement_Kind
};
- ASTSuffix(int offset, Kind kind)
- : INHERITED(offset)
+ ASTSuffix(Position position, Kind kind)
+ : INHERITED(position)
, fKind(kind) {}
String description() const override {
diff --git a/src/sksl/ast/SkSLASTSuffixExpression.h b/src/sksl/ast/SkSLASTSuffixExpression.h
index 31cddb29d1..2cff9a865f 100644
--- a/src/sksl/ast/SkSLASTSuffixExpression.h
+++ b/src/sksl/ast/SkSLASTSuffixExpression.h
@@ -18,7 +18,7 @@ namespace SkSL {
*/
struct ASTSuffixExpression : public ASTExpression {
ASTSuffixExpression(std::unique_ptr<ASTExpression> base, std::unique_ptr<ASTSuffix> suffix)
- : INHERITED(base->fOffset, kSuffix_Kind)
+ : INHERITED(base->fPosition, kSuffix_Kind)
, fBase(std::move(base))
, fSuffix(std::move(suffix)) {}
diff --git a/src/sksl/ast/SkSLASTSwitchCase.h b/src/sksl/ast/SkSLASTSwitchCase.h
index 221e2128ed..405013a6a7 100644
--- a/src/sksl/ast/SkSLASTSwitchCase.h
+++ b/src/sksl/ast/SkSLASTSwitchCase.h
@@ -17,9 +17,9 @@ namespace SkSL {
*/
struct ASTSwitchCase : public ASTStatement {
// a null value means "default:"
- ASTSwitchCase(int offset, std::unique_ptr<ASTExpression> value,
+ ASTSwitchCase(Position position, std::unique_ptr<ASTExpression> value,
std::vector<std::unique_ptr<ASTStatement>> statements)
- : INHERITED(offset, kSwitch_Kind)
+ : INHERITED(position, kSwitch_Kind)
, fValue(std::move(value))
, fStatements(std::move(statements)) {}
diff --git a/src/sksl/ast/SkSLASTSwitchStatement.h b/src/sksl/ast/SkSLASTSwitchStatement.h
index 3bee0a4728..ecd0a6755d 100644
--- a/src/sksl/ast/SkSLASTSwitchStatement.h
+++ b/src/sksl/ast/SkSLASTSwitchStatement.h
@@ -17,9 +17,9 @@ namespace SkSL {
* A 'switch' statement.
*/
struct ASTSwitchStatement : public ASTStatement {
- ASTSwitchStatement(int offset, bool isStatic, std::unique_ptr<ASTExpression> value,
+ ASTSwitchStatement(Position position, bool isStatic, std::unique_ptr<ASTExpression> value,
std::vector<std::unique_ptr<ASTSwitchCase>> cases)
- : INHERITED(offset, kSwitch_Kind)
+ : INHERITED(position, kSwitch_Kind)
, fIsStatic(isStatic)
, fValue(std::move(value))
, fCases(std::move(cases)) {}
diff --git a/src/sksl/ast/SkSLASTTernaryExpression.h b/src/sksl/ast/SkSLASTTernaryExpression.h
index 35795e9f12..07c92975e0 100644
--- a/src/sksl/ast/SkSLASTTernaryExpression.h
+++ b/src/sksl/ast/SkSLASTTernaryExpression.h
@@ -19,7 +19,7 @@ struct ASTTernaryExpression : public ASTExpression {
ASTTernaryExpression(std::unique_ptr<ASTExpression> test,
std::unique_ptr<ASTExpression> ifTrue,
std::unique_ptr<ASTExpression> ifFalse)
- : INHERITED(test->fOffset, kTernary_Kind)
+ : INHERITED(test->fPosition, kTernary_Kind)
, fTest(std::move(test))
, fIfTrue(std::move(ifTrue))
, fIfFalse(std::move(ifFalse)) {}
diff --git a/src/sksl/ast/SkSLASTType.h b/src/sksl/ast/SkSLASTType.h
index 44fd95bdc7..57a8025b7b 100644
--- a/src/sksl/ast/SkSLASTType.h
+++ b/src/sksl/ast/SkSLASTType.h
@@ -21,9 +21,9 @@ struct ASTType : public ASTPositionNode {
kStruct_Kind
};
- ASTType(int offset, StringFragment name, Kind kind, std::vector<int> sizes)
- : INHERITED(offset)
- , fName(name)
+ ASTType(Position position, String name, Kind kind, std::vector<int> sizes)
+ : INHERITED(position)
+ , fName(std::move(name))
, fKind(kind)
, fSizes(std::move(sizes)) {}
@@ -31,7 +31,7 @@ struct ASTType : public ASTPositionNode {
return fName;
}
- const StringFragment fName;
+ const String fName;
const Kind fKind;
diff --git a/src/sksl/ast/SkSLASTVarDeclaration.h b/src/sksl/ast/SkSLASTVarDeclaration.h
index 38c9104865..2dcb9787ea 100644
--- a/src/sksl/ast/SkSLASTVarDeclaration.h
+++ b/src/sksl/ast/SkSLASTVarDeclaration.h
@@ -22,7 +22,7 @@ namespace SkSL {
* instances.
*/
struct ASTVarDeclaration {
- ASTVarDeclaration(StringFragment name,
+ ASTVarDeclaration(const String name,
std::vector<std::unique_ptr<ASTExpression>> sizes,
std::unique_ptr<ASTExpression> value)
: fName(name)
@@ -30,7 +30,7 @@ struct ASTVarDeclaration {
, fValue(std::move(value)) {}
String description() const {
- String result(fName);
+ String result = fName;
for (const auto& size : fSizes) {
if (size) {
result += "[" + size->description() + "]";
@@ -44,7 +44,7 @@ struct ASTVarDeclaration {
return result;
}
- StringFragment fName;
+ String fName;
// array sizes, if any. e.g. 'foo[3][]' has sizes [3, null]
std::vector<std::unique_ptr<ASTExpression>> fSizes;
@@ -60,7 +60,7 @@ struct ASTVarDeclarations : public ASTDeclaration {
ASTVarDeclarations(Modifiers modifiers,
std::unique_ptr<ASTType> type,
std::vector<ASTVarDeclaration> vars)
- : INHERITED(type->fOffset, kVar_Kind)
+ : INHERITED(type->fPosition, kVar_Kind)
, fModifiers(modifiers)
, fType(std::move(type))
, fVars(std::move(vars)) {}
diff --git a/src/sksl/ast/SkSLASTVarDeclarationStatement.h b/src/sksl/ast/SkSLASTVarDeclarationStatement.h
index 8ec5bf6789..c3a4069ba0 100644
--- a/src/sksl/ast/SkSLASTVarDeclarationStatement.h
+++ b/src/sksl/ast/SkSLASTVarDeclarationStatement.h
@@ -18,7 +18,7 @@ namespace SkSL {
*/
struct ASTVarDeclarationStatement : public ASTStatement {
ASTVarDeclarationStatement(std::unique_ptr<ASTVarDeclarations> decl)
- : INHERITED(decl->fOffset, kVarDeclaration_Kind)
+ : INHERITED(decl->fPosition, kVarDeclaration_Kind)
, fDeclarations(std::move(decl)) {}
String description() const override {
diff --git a/src/sksl/ast/SkSLASTWhileStatement.h b/src/sksl/ast/SkSLASTWhileStatement.h
index c0da0afb7d..e63c50293a 100644
--- a/src/sksl/ast/SkSLASTWhileStatement.h
+++ b/src/sksl/ast/SkSLASTWhileStatement.h
@@ -16,9 +16,9 @@ namespace SkSL {
* A 'while' statement.
*/
struct ASTWhileStatement : public ASTStatement {
- ASTWhileStatement(int offset, std::unique_ptr<ASTExpression> test,
+ ASTWhileStatement(Position position, std::unique_ptr<ASTExpression> test,
std::unique_ptr<ASTStatement> statement)
- : INHERITED(offset, kWhile_Kind)
+ : INHERITED(position, kWhile_Kind)
, fTest(std::move(test))
, fStatement(std::move(statement)) {}