diff options
author | Ethan Nicholas <ethannicholas@google.com> | 2017-09-11 16:33:48 +0000 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-09-11 16:34:02 +0000 |
commit | 358515491a0d6891e6a709688a30ad087df1beb1 (patch) | |
tree | ce64223230053df7db85c94b848ad526e64269cd /src/sksl/ir | |
parent | c576e93d174f3106e072a2f506bca3990b541265 (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/ir')
49 files changed, 148 insertions, 184 deletions
diff --git a/src/sksl/ir/SkSLBinaryExpression.h b/src/sksl/ir/SkSLBinaryExpression.h index c26994edf2..789db5783b 100644 --- a/src/sksl/ir/SkSLBinaryExpression.h +++ b/src/sksl/ir/SkSLBinaryExpression.h @@ -11,7 +11,7 @@ #include "SkSLExpression.h" #include "SkSLExpression.h" #include "../SkSLIRGenerator.h" -#include "../SkSLLexer.h" +#include "../SkSLToken.h" namespace SkSL { @@ -19,9 +19,9 @@ namespace SkSL { * A binary operation. */ struct BinaryExpression : public Expression { - BinaryExpression(int offset, std::unique_ptr<Expression> left, Token::Kind op, + BinaryExpression(Position position, std::unique_ptr<Expression> left, Token::Kind op, std::unique_ptr<Expression> right, const Type& type) - : INHERITED(offset, kBinary_Kind, type) + : INHERITED(position, kBinary_Kind, type) , fLeft(std::move(left)) , fOperator(op) , fRight(std::move(right)) {} @@ -34,12 +34,12 @@ struct BinaryExpression : public Expression { } bool hasSideEffects() const override { - return Compiler::IsAssignment(fOperator) || fLeft->hasSideEffects() || + return Token::IsAssignment(fOperator) || fLeft->hasSideEffects() || fRight->hasSideEffects(); } String description() const override { - return "(" + fLeft->description() + " " + Compiler::OperatorName(fOperator) + " " + + return "(" + fLeft->description() + " " + Token::OperatorName(fOperator) + " " + fRight->description() + ")"; } diff --git a/src/sksl/ir/SkSLBlock.h b/src/sksl/ir/SkSLBlock.h index af1975396e..bcd4bb1b59 100644 --- a/src/sksl/ir/SkSLBlock.h +++ b/src/sksl/ir/SkSLBlock.h @@ -17,9 +17,9 @@ namespace SkSL { * A block of multiple statements functioning as a single statement. */ struct Block : public Statement { - Block(int offset, std::vector<std::unique_ptr<Statement>> statements, + Block(Position position, std::vector<std::unique_ptr<Statement>> statements, const std::shared_ptr<SymbolTable> symbols = nullptr) - : INHERITED(offset, kBlock_Kind) + : INHERITED(position, kBlock_Kind) , fSymbols(std::move(symbols)) , fStatements(std::move(statements)) {} diff --git a/src/sksl/ir/SkSLBoolLiteral.h b/src/sksl/ir/SkSLBoolLiteral.h index 9a69f0f138..a4151b8b35 100644 --- a/src/sksl/ir/SkSLBoolLiteral.h +++ b/src/sksl/ir/SkSLBoolLiteral.h @@ -17,8 +17,8 @@ namespace SkSL { * Represents 'true' or 'false'. */ struct BoolLiteral : public Expression { - BoolLiteral(const Context& context, int offset, bool value) - : INHERITED(offset, kBoolLiteral_Kind, *context.fBool_Type) + BoolLiteral(const Context& context, Position position, bool value) + : INHERITED(position, kBoolLiteral_Kind, *context.fBool_Type) , fValue(value) {} String description() const override { diff --git a/src/sksl/ir/SkSLBreakStatement.h b/src/sksl/ir/SkSLBreakStatement.h index da392f5960..f6edc558e5 100644 --- a/src/sksl/ir/SkSLBreakStatement.h +++ b/src/sksl/ir/SkSLBreakStatement.h @@ -17,8 +17,8 @@ namespace SkSL { * A 'break' statement. */ struct BreakStatement : public Statement { - BreakStatement(int offset) - : INHERITED(offset, kBreak_Kind) {} + BreakStatement(Position position) + : INHERITED(position, kBreak_Kind) {} String description() const override { return String("break;"); diff --git a/src/sksl/ir/SkSLConstructor.h b/src/sksl/ir/SkSLConstructor.h index 32fc0fb2e7..beed0f702d 100644 --- a/src/sksl/ir/SkSLConstructor.h +++ b/src/sksl/ir/SkSLConstructor.h @@ -16,7 +16,7 @@ namespace SkSL { /** - * Represents the construction of a compound type, such as "float2(x, y)". + * Represents the construction of a compound type, such as "float2x, y)". * * Vector constructors will always consist of either exactly 1 scalar, or a collection of vectors * and scalars totalling exactly the right number of scalar components. @@ -25,8 +25,9 @@ namespace SkSL { * collection of vectors and scalars totalling exactly the right number of scalar components. */ struct Constructor : public Expression { - Constructor(int offset, const Type& type, std::vector<std::unique_ptr<Expression>> arguments) - : INHERITED(offset, kConstructor_Kind, type) + Constructor(Position position, const Type& type, + std::vector<std::unique_ptr<Expression>> arguments) + : INHERITED(position, kConstructor_Kind, type) , fArguments(std::move(arguments)) {} std::unique_ptr<Expression> constantPropagate(const IRGenerator& irGenerator, @@ -36,13 +37,13 @@ struct Constructor : public Expression { // promote float(1) to 1.0 int64_t intValue = ((IntLiteral&) *fArguments[0]).fValue; return std::unique_ptr<Expression>(new FloatLiteral(irGenerator.fContext, - fOffset, + fPosition, intValue)); } else if (fType == *irGenerator.fContext.fUInt_Type) { // promote uint(1) to 1u int64_t intValue = ((IntLiteral&) *fArguments[0]).fValue; return std::unique_ptr<Expression>(new IntLiteral(irGenerator.fContext, - fOffset, + fPosition, intValue, &fType)); } @@ -95,8 +96,8 @@ struct Constructor : public Expression { // a constant scalar constructor should have been collapsed down to the appropriate // literal ASSERT(fType.kind() == Type::kMatrix_Kind); - const FloatLiteral fzero(context, -1, 0); - const IntLiteral izero(context, -1, 0); + const FloatLiteral fzero(context, Position(), 0); + const IntLiteral izero(context, Position(), 0); const Expression* zero; if (fType.componentType() == *context.fFloat_Type) { zero = &fzero; diff --git a/src/sksl/ir/SkSLContinueStatement.h b/src/sksl/ir/SkSLContinueStatement.h index 6ed40c404f..3f5bc1d4bb 100644 --- a/src/sksl/ir/SkSLContinueStatement.h +++ b/src/sksl/ir/SkSLContinueStatement.h @@ -17,8 +17,8 @@ namespace SkSL { * A 'continue' statement. */ struct ContinueStatement : public Statement { - ContinueStatement(int offset) - : INHERITED(offset, kContinue_Kind) {} + ContinueStatement(Position position) + : INHERITED(position, kContinue_Kind) {} String description() const override { return String("continue;"); diff --git a/src/sksl/ir/SkSLDiscardStatement.h b/src/sksl/ir/SkSLDiscardStatement.h index b62530e6f3..62124668ee 100644 --- a/src/sksl/ir/SkSLDiscardStatement.h +++ b/src/sksl/ir/SkSLDiscardStatement.h @@ -17,8 +17,8 @@ namespace SkSL { * A 'discard' statement. */ struct DiscardStatement : public Statement { - DiscardStatement(int offset) - : INHERITED(offset, kDiscard_Kind) {} + DiscardStatement(Position position) + : INHERITED(position, kDiscard_Kind) {} String description() const override { return String("discard;"); diff --git a/src/sksl/ir/SkSLDoStatement.h b/src/sksl/ir/SkSLDoStatement.h index 3abec550eb..f1ecd9a8bf 100644 --- a/src/sksl/ir/SkSLDoStatement.h +++ b/src/sksl/ir/SkSLDoStatement.h @@ -17,9 +17,9 @@ namespace SkSL { * A 'do' statement. */ struct DoStatement : public Statement { - DoStatement(int offset, std::unique_ptr<Statement> statement, + DoStatement(Position position, std::unique_ptr<Statement> statement, std::unique_ptr<Expression> test) - : INHERITED(offset, kDo_Kind) + : INHERITED(position, kDo_Kind) , fStatement(std::move(statement)) , fTest(std::move(test)) {} diff --git a/src/sksl/ir/SkSLExpression.h b/src/sksl/ir/SkSLExpression.h index 555e66061d..286610f078 100644 --- a/src/sksl/ir/SkSLExpression.h +++ b/src/sksl/ir/SkSLExpression.h @@ -44,8 +44,8 @@ struct Expression : public IRNode { kDefined_Kind }; - Expression(int offset, Kind kind, const Type& type) - : INHERITED(offset) + Expression(Position position, Kind kind, const Type& type) + : INHERITED(position) , fKind(kind) , fType(std::move(type)) {} diff --git a/src/sksl/ir/SkSLExpressionStatement.h b/src/sksl/ir/SkSLExpressionStatement.h index 215763b8fd..d1ab8e9ed9 100644 --- a/src/sksl/ir/SkSLExpressionStatement.h +++ b/src/sksl/ir/SkSLExpressionStatement.h @@ -18,7 +18,7 @@ namespace SkSL { */ struct ExpressionStatement : public Statement { ExpressionStatement(std::unique_ptr<Expression> expression) - : INHERITED(expression->fOffset, kExpression_Kind) + : INHERITED(expression->fPosition, kExpression_Kind) , fExpression(std::move(expression)) {} String description() const override { diff --git a/src/sksl/ir/SkSLExtension.h b/src/sksl/ir/SkSLExtension.h index b5a48b94ab..70dc6b3eaf 100644 --- a/src/sksl/ir/SkSLExtension.h +++ b/src/sksl/ir/SkSLExtension.h @@ -16,8 +16,8 @@ namespace SkSL { * An extension declaration. */ struct Extension : public ProgramElement { - Extension(int offset, String name) - : INHERITED(offset, kExtension_Kind) + Extension(Position position, String name) + : INHERITED(position, kExtension_Kind) , fName(std::move(name)) {} String description() const override { diff --git a/src/sksl/ir/SkSLField.h b/src/sksl/ir/SkSLField.h index fe2af7fa6e..abea730da1 100644 --- a/src/sksl/ir/SkSLField.h +++ b/src/sksl/ir/SkSLField.h @@ -22,8 +22,8 @@ namespace SkSL { * result of declaring anonymous interface blocks. */ struct Field : public Symbol { - Field(int offset, const Variable& owner, int fieldIndex) - : INHERITED(offset, kField_Kind, owner.fType.fields()[fieldIndex].fName) + Field(Position position, const Variable& owner, int fieldIndex) + : INHERITED(position, kField_Kind, owner.fType.fields()[fieldIndex].fName) , fOwner(owner) , fFieldIndex(fieldIndex) {} diff --git a/src/sksl/ir/SkSLFieldAccess.h b/src/sksl/ir/SkSLFieldAccess.h index 0f66dec5a4..e0a335f528 100644 --- a/src/sksl/ir/SkSLFieldAccess.h +++ b/src/sksl/ir/SkSLFieldAccess.h @@ -26,7 +26,7 @@ struct FieldAccess : public Expression { FieldAccess(std::unique_ptr<Expression> base, int fieldIndex, OwnerKind ownerKind = kDefault_OwnerKind) - : INHERITED(base->fOffset, kFieldAccess_Kind, *base->fType.fields()[fieldIndex].fType) + : INHERITED(base->fPosition, kFieldAccess_Kind, *base->fType.fields()[fieldIndex].fType) , fBase(std::move(base)) , fFieldIndex(fieldIndex) , fOwnerKind(ownerKind) {} diff --git a/src/sksl/ir/SkSLFloatLiteral.h b/src/sksl/ir/SkSLFloatLiteral.h index e6a3062f36..21a485fb0a 100644 --- a/src/sksl/ir/SkSLFloatLiteral.h +++ b/src/sksl/ir/SkSLFloatLiteral.h @@ -17,9 +17,9 @@ namespace SkSL { * A literal floating point number. */ struct FloatLiteral : public Expression { - FloatLiteral(const Context& context, int offset, double value, + FloatLiteral(const Context& context, Position position, double value, const Type* type = nullptr) - : INHERITED(offset, kFloatLiteral_Kind, type ? *type : *context.fFloat_Type) + : INHERITED(position, kFloatLiteral_Kind, type ? *type : *context.fFloat_Type) , fValue(value) {} String description() const override { diff --git a/src/sksl/ir/SkSLForStatement.h b/src/sksl/ir/SkSLForStatement.h index 6896ceb902..ca3e6cfb7a 100644 --- a/src/sksl/ir/SkSLForStatement.h +++ b/src/sksl/ir/SkSLForStatement.h @@ -18,10 +18,10 @@ namespace SkSL { * A 'for' statement. */ struct ForStatement : public Statement { - ForStatement(int offset, std::unique_ptr<Statement> initializer, + ForStatement(Position position, std::unique_ptr<Statement> initializer, std::unique_ptr<Expression> test, std::unique_ptr<Expression> next, std::unique_ptr<Statement> statement, std::shared_ptr<SymbolTable> symbols) - : INHERITED(offset, kFor_Kind) + : INHERITED(position, kFor_Kind) , fSymbols(symbols) , fInitializer(std::move(initializer)) , fTest(std::move(test)) diff --git a/src/sksl/ir/SkSLFunctionCall.h b/src/sksl/ir/SkSLFunctionCall.h index 115281d63d..44f8c7ed5a 100644 --- a/src/sksl/ir/SkSLFunctionCall.h +++ b/src/sksl/ir/SkSLFunctionCall.h @@ -17,9 +17,9 @@ namespace SkSL { * A function invocation. */ struct FunctionCall : public Expression { - FunctionCall(int offset, const Type& type, const FunctionDeclaration& function, + FunctionCall(Position position, const Type& type, const FunctionDeclaration& function, std::vector<std::unique_ptr<Expression>> arguments) - : INHERITED(offset, kFunctionCall_Kind, type) + : INHERITED(position, kFunctionCall_Kind, type) , fFunction(std::move(function)) , fArguments(std::move(arguments)) {} @@ -33,7 +33,7 @@ struct FunctionCall : public Expression { } String description() const override { - String result = String(fFunction.fName) + "("; + String result = fFunction.fName + "("; String separator; for (size_t i = 0; i < fArguments.size(); i++) { result += separator; diff --git a/src/sksl/ir/SkSLFunctionDeclaration.h b/src/sksl/ir/SkSLFunctionDeclaration.h index d0f9d240d7..64236d3980 100644 --- a/src/sksl/ir/SkSLFunctionDeclaration.h +++ b/src/sksl/ir/SkSLFunctionDeclaration.h @@ -21,9 +21,9 @@ namespace SkSL { * A function declaration (not a definition -- does not contain a body). */ struct FunctionDeclaration : public Symbol { - FunctionDeclaration(int offset, Modifiers modifiers, StringFragment name, + FunctionDeclaration(Position position, Modifiers modifiers, String name, std::vector<const Variable*> parameters, const Type& returnType) - : INHERITED(offset, kFunctionDeclaration_Kind, std::move(name)) + : INHERITED(position, kFunctionDeclaration_Kind, std::move(name)) , fDefined(false) , fBuiltin(false) , fModifiers(modifiers) diff --git a/src/sksl/ir/SkSLFunctionDefinition.h b/src/sksl/ir/SkSLFunctionDefinition.h index e0dabc5791..0277db1f07 100644 --- a/src/sksl/ir/SkSLFunctionDefinition.h +++ b/src/sksl/ir/SkSLFunctionDefinition.h @@ -18,9 +18,9 @@ namespace SkSL { * A function definition (a declaration plus an associated block of code). */ struct FunctionDefinition : public ProgramElement { - FunctionDefinition(int offset, const FunctionDeclaration& declaration, + FunctionDefinition(Position position, const FunctionDeclaration& declaration, std::unique_ptr<Statement> body) - : INHERITED(offset, kFunction_Kind) + : INHERITED(position, kFunction_Kind) , fDeclaration(declaration) , fBody(std::move(body)) {} diff --git a/src/sksl/ir/SkSLFunctionReference.h b/src/sksl/ir/SkSLFunctionReference.h index 58831c5e99..ee761c2639 100644 --- a/src/sksl/ir/SkSLFunctionReference.h +++ b/src/sksl/ir/SkSLFunctionReference.h @@ -19,9 +19,9 @@ namespace SkSL { * always eventually replaced by FunctionCalls in valid programs. */ struct FunctionReference : public Expression { - FunctionReference(const Context& context, int offset, + FunctionReference(const Context& context, Position position, std::vector<const FunctionDeclaration*> function) - : INHERITED(offset, kFunctionReference_Kind, *context.fInvalid_Type) + : INHERITED(position, kFunctionReference_Kind, *context.fInvalid_Type) , fFunctions(function) {} bool hasSideEffects() const override { diff --git a/src/sksl/ir/SkSLIRNode.h b/src/sksl/ir/SkSLIRNode.h index 5ada50607e..139be32f44 100644 --- a/src/sksl/ir/SkSLIRNode.h +++ b/src/sksl/ir/SkSLIRNode.h @@ -8,7 +8,7 @@ #ifndef SKSL_IRNODE #define SKSL_IRNODE -#include "../SkSLLexer.h" +#include "../SkSLPosition.h" namespace SkSL { @@ -17,16 +17,14 @@ namespace SkSL { * version of the program (all types determined, everything validated), ready for code generation. */ struct IRNode { - IRNode(int offset) - : fOffset(offset) {} + IRNode(Position position) + : fPosition(position) {} virtual ~IRNode() {} virtual String description() const = 0; - // 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/ir/SkSLIfStatement.h b/src/sksl/ir/SkSLIfStatement.h index 4c2ca0b1fa..b09c10ee95 100644 --- a/src/sksl/ir/SkSLIfStatement.h +++ b/src/sksl/ir/SkSLIfStatement.h @@ -17,9 +17,9 @@ namespace SkSL { * An 'if' statement. */ struct IfStatement : public Statement { - IfStatement(int offset, bool isStatic, std::unique_ptr<Expression> test, + IfStatement(Position position, bool isStatic, std::unique_ptr<Expression> test, std::unique_ptr<Statement> ifTrue, std::unique_ptr<Statement> ifFalse) - : INHERITED(offset, kIf_Kind) + : INHERITED(position, kIf_Kind) , fIsStatic(isStatic) , fTest(std::move(test)) , fIfTrue(std::move(ifTrue)) diff --git a/src/sksl/ir/SkSLIndexExpression.h b/src/sksl/ir/SkSLIndexExpression.h index 2daf1b552a..c305365049 100644 --- a/src/sksl/ir/SkSLIndexExpression.h +++ b/src/sksl/ir/SkSLIndexExpression.h @@ -45,7 +45,7 @@ static const Type& index_type(const Context& context, const Type& type) { struct IndexExpression : public Expression { IndexExpression(const Context& context, std::unique_ptr<Expression> base, std::unique_ptr<Expression> index) - : INHERITED(base->fOffset, kIndex_Kind, index_type(context, base->fType)) + : INHERITED(base->fPosition, kIndex_Kind, index_type(context, base->fType)) , fBase(std::move(base)) , fIndex(std::move(index)) { ASSERT(fIndex->fType == *context.fInt_Type || fIndex->fType == *context.fUInt_Type); diff --git a/src/sksl/ir/SkSLIntLiteral.h b/src/sksl/ir/SkSLIntLiteral.h index da2b4082de..6199f96610 100644 --- a/src/sksl/ir/SkSLIntLiteral.h +++ b/src/sksl/ir/SkSLIntLiteral.h @@ -19,8 +19,8 @@ namespace SkSL { struct IntLiteral : public Expression { // FIXME: we will need to revisit this if/when we add full support for both signed and unsigned // 64-bit integers, but for right now an int64_t will hold every value we care about - IntLiteral(const Context& context, int offset, int64_t value, const Type* type = nullptr) - : INHERITED(offset, kIntLiteral_Kind, type ? *type : *context.fInt_Type) + IntLiteral(const Context& context, Position position, int64_t value, const Type* type = nullptr) + : INHERITED(position, kIntLiteral_Kind, type ? *type : *context.fInt_Type) , fValue(value) {} String description() const override { diff --git a/src/sksl/ir/SkSLInterfaceBlock.h b/src/sksl/ir/SkSLInterfaceBlock.h index 03986b87cd..a28a6a1b54 100644 --- a/src/sksl/ir/SkSLInterfaceBlock.h +++ b/src/sksl/ir/SkSLInterfaceBlock.h @@ -25,10 +25,10 @@ namespace SkSL { * At the IR level, this is represented by a single variable of struct type. */ struct InterfaceBlock : public ProgramElement { - InterfaceBlock(int offset, const Variable* var, String typeName, String instanceName, + InterfaceBlock(Position position, const Variable* var, String typeName, String instanceName, std::vector<std::unique_ptr<Expression>> sizes, std::shared_ptr<SymbolTable> typeOwner) - : INHERITED(offset, kInterfaceBlock_Kind) + : INHERITED(position, kInterfaceBlock_Kind) , fVariable(*var) , fTypeName(std::move(typeName)) , fInstanceName(std::move(instanceName)) diff --git a/src/sksl/ir/SkSLModifiersDeclaration.h b/src/sksl/ir/SkSLModifiersDeclaration.h index 5c9608f02f..a0ce74852d 100644 --- a/src/sksl/ir/SkSLModifiersDeclaration.h +++ b/src/sksl/ir/SkSLModifiersDeclaration.h @@ -20,7 +20,7 @@ namespace SkSL { */ struct ModifiersDeclaration : public ProgramElement { ModifiersDeclaration(Modifiers modifiers) - : INHERITED(-1, kModifiers_Kind) + : INHERITED(Position(), kModifiers_Kind) , fModifiers(modifiers) {} String description() const { diff --git a/src/sksl/ir/SkSLNop.h b/src/sksl/ir/SkSLNop.h index e7aae9b7b8..5ebea40583 100644 --- a/src/sksl/ir/SkSLNop.h +++ b/src/sksl/ir/SkSLNop.h @@ -18,7 +18,7 @@ namespace SkSL { */ struct Nop : public Statement { Nop() - : INHERITED(-1, kNop_Kind) {} + : INHERITED(Position(), kNop_Kind) {} virtual bool isEmpty() const override { return true; diff --git a/src/sksl/ir/SkSLPostfixExpression.h b/src/sksl/ir/SkSLPostfixExpression.h index c53f1de507..e02555db70 100644 --- a/src/sksl/ir/SkSLPostfixExpression.h +++ b/src/sksl/ir/SkSLPostfixExpression.h @@ -9,7 +9,7 @@ #define SKSL_POSTFIXEXPRESSION #include "SkSLExpression.h" -#include "SkSLLexer.h" +#include "SkSLToken.h" namespace SkSL { @@ -18,7 +18,7 @@ namespace SkSL { */ struct PostfixExpression : public Expression { PostfixExpression(std::unique_ptr<Expression> operand, Token::Kind op) - : INHERITED(operand->fOffset, kPostfix_Kind, operand->fType) + : INHERITED(operand->fPosition, kPostfix_Kind, operand->fType) , fOperand(std::move(operand)) , fOperator(op) {} @@ -27,7 +27,7 @@ struct PostfixExpression : public Expression { } String description() const override { - return fOperand->description() + Compiler::OperatorName(fOperator); + return fOperand->description() + Token::OperatorName(fOperator); } std::unique_ptr<Expression> fOperand; diff --git a/src/sksl/ir/SkSLPrefixExpression.h b/src/sksl/ir/SkSLPrefixExpression.h index d5d97b2517..5ac84c66b1 100644 --- a/src/sksl/ir/SkSLPrefixExpression.h +++ b/src/sksl/ir/SkSLPrefixExpression.h @@ -11,7 +11,7 @@ #include "SkSLExpression.h" #include "SkSLFloatLiteral.h" #include "SkSLIRGenerator.h" -#include "SkSLLexer.h" +#include "SkSLToken.h" namespace SkSL { @@ -20,7 +20,7 @@ namespace SkSL { */ struct PrefixExpression : public Expression { PrefixExpression(Token::Kind op, std::unique_ptr<Expression> operand) - : INHERITED(operand->fOffset, kPrefix_Kind, operand->fType) + : INHERITED(operand->fPosition, kPrefix_Kind, operand->fType) , fOperand(std::move(operand)) , fOperator(op) {} @@ -38,7 +38,7 @@ struct PrefixExpression : public Expression { if (fOperand->fKind == Expression::kFloatLiteral_Kind) { return std::unique_ptr<Expression>(new FloatLiteral( irGenerator.fContext, - fOffset, + Position(), -((FloatLiteral&) *fOperand).fValue)); } @@ -46,7 +46,7 @@ struct PrefixExpression : public Expression { } String description() const override { - return Compiler::OperatorName(fOperator) + fOperand->description(); + return Token::OperatorName(fOperator) + fOperand->description(); } std::unique_ptr<Expression> fOperand; diff --git a/src/sksl/ir/SkSLProgram.h b/src/sksl/ir/SkSLProgram.h index 639e09b16a..a3eeaa3612 100644 --- a/src/sksl/ir/SkSLProgram.h +++ b/src/sksl/ir/SkSLProgram.h @@ -39,15 +39,15 @@ struct Program { : fKind(kInt_Kind) , fValue(i) {} - std::unique_ptr<Expression> literal(const Context& context, int offset) const { + std::unique_ptr<Expression> literal(const Context& context, Position position) const { switch (fKind) { case Program::Settings::Value::kBool_Kind: return std::unique_ptr<Expression>(new BoolLiteral(context, - offset, + position, fValue)); case Program::Settings::Value::kInt_Kind: return std::unique_ptr<Expression>(new IntLiteral(context, - offset, + position, fValue)); default: ASSERT(false); @@ -103,7 +103,6 @@ struct Program { }; Program(Kind kind, - std::unique_ptr<String> source, Settings settings, Modifiers::Flag defaultPrecision, Context* context, @@ -111,7 +110,6 @@ struct Program { std::shared_ptr<SymbolTable> symbols, Inputs inputs) : fKind(kind) - , fSource(std::move(source)) , fSettings(settings) , fDefaultPrecision(defaultPrecision) , fContext(context) @@ -120,7 +118,6 @@ struct Program { , fInputs(inputs) {} Kind fKind; - std::unique_ptr<String> fSource; Settings fSettings; // FIXME handle different types; currently it assumes this is for floats Modifiers::Flag fDefaultPrecision; diff --git a/src/sksl/ir/SkSLProgramElement.h b/src/sksl/ir/SkSLProgramElement.h index 4a3566d287..1e2bb48641 100644 --- a/src/sksl/ir/SkSLProgramElement.h +++ b/src/sksl/ir/SkSLProgramElement.h @@ -25,8 +25,8 @@ struct ProgramElement : public IRNode { kSection_Kind }; - ProgramElement(int offset, Kind kind) - : INHERITED(offset) + ProgramElement(Position position, Kind kind) + : INHERITED(position) , fKind(kind) {} Kind fKind; diff --git a/src/sksl/ir/SkSLReturnStatement.h b/src/sksl/ir/SkSLReturnStatement.h index 1b479b8097..841db94669 100644 --- a/src/sksl/ir/SkSLReturnStatement.h +++ b/src/sksl/ir/SkSLReturnStatement.h @@ -17,11 +17,11 @@ namespace SkSL { * A 'return' statement. */ struct ReturnStatement : public Statement { - ReturnStatement(int offset) - : INHERITED(offset, kReturn_Kind) {} + ReturnStatement(Position position) + : INHERITED(position, kReturn_Kind) {} ReturnStatement(std::unique_ptr<Expression> expression) - : INHERITED(expression->fOffset, kReturn_Kind) + : INHERITED(expression->fPosition, kReturn_Kind) , fExpression(std::move(expression)) {} String description() const override { diff --git a/src/sksl/ir/SkSLSection.h b/src/sksl/ir/SkSLSection.h index 96c257b1f8..f9815b1caa 100644 --- a/src/sksl/ir/SkSLSection.h +++ b/src/sksl/ir/SkSLSection.h @@ -16,8 +16,8 @@ namespace SkSL { * A section declaration (e.g. @body { body code here }).. */ struct Section : public ProgramElement { - Section(int offset, String name, String arg, String text) - : INHERITED(offset, kSection_Kind) + Section(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/ir/SkSLSetting.h b/src/sksl/ir/SkSLSetting.h index f479ad167b..995fcf55bf 100644 --- a/src/sksl/ir/SkSLSetting.h +++ b/src/sksl/ir/SkSLSetting.h @@ -18,8 +18,8 @@ namespace SkSL { * collapsed down to their constant representations during the compilation process. */ struct Setting : public Expression { - Setting(int offset, String name, std::unique_ptr<Expression> value) - : INHERITED(offset, kSetting_Kind, value->fType) + Setting(Position position, String name, std::unique_ptr<Expression> value) + : INHERITED(position, kSetting_Kind, value->fType) , fName(std::move(name)) , fValue(std::move(value)) { ASSERT(fValue->isConstant()); diff --git a/src/sksl/ir/SkSLStatement.h b/src/sksl/ir/SkSLStatement.h index a116cc1c4c..1bc524451b 100644 --- a/src/sksl/ir/SkSLStatement.h +++ b/src/sksl/ir/SkSLStatement.h @@ -35,8 +35,8 @@ struct Statement : public IRNode { kWhile_Kind }; - Statement(int offset, Kind kind) - : INHERITED(offset) + Statement(Position position, Kind kind) + : INHERITED(position) , fKind(kind) {} virtual bool isEmpty() const { diff --git a/src/sksl/ir/SkSLSwitchCase.h b/src/sksl/ir/SkSLSwitchCase.h index c33224bdbb..8043f2e787 100644 --- a/src/sksl/ir/SkSLSwitchCase.h +++ b/src/sksl/ir/SkSLSwitchCase.h @@ -17,9 +17,9 @@ namespace SkSL { * A single case of a 'switch' statement. */ struct SwitchCase : public Statement { - SwitchCase(int offset, std::unique_ptr<Expression> value, + SwitchCase(Position position, std::unique_ptr<Expression> value, std::vector<std::unique_ptr<Statement>> statements) - : INHERITED(offset, kSwitch_Kind) + : INHERITED(position, kSwitch_Kind) , fValue(std::move(value)) , fStatements(std::move(statements)) {} diff --git a/src/sksl/ir/SkSLSwitchStatement.h b/src/sksl/ir/SkSLSwitchStatement.h index 68d0ef02df..dec5b749a5 100644 --- a/src/sksl/ir/SkSLSwitchStatement.h +++ b/src/sksl/ir/SkSLSwitchStatement.h @@ -17,10 +17,10 @@ namespace SkSL { * A 'switch' statement. */ struct SwitchStatement : public Statement { - SwitchStatement(int offset, bool isStatic, std::unique_ptr<Expression> value, + SwitchStatement(Position position, bool isStatic, std::unique_ptr<Expression> value, std::vector<std::unique_ptr<SwitchCase>> cases, const std::shared_ptr<SymbolTable> symbols) - : INHERITED(offset, kSwitch_Kind) + : INHERITED(position, kSwitch_Kind) , fIsStatic(isStatic) , fValue(std::move(value)) , fSymbols(std::move(symbols)) diff --git a/src/sksl/ir/SkSLSwizzle.h b/src/sksl/ir/SkSLSwizzle.h index 3256ef211a..9d7ca37bdc 100644 --- a/src/sksl/ir/SkSLSwizzle.h +++ b/src/sksl/ir/SkSLSwizzle.h @@ -65,7 +65,7 @@ static const Type& get_type(const Context& context, Expression& value, size_t co */ struct Swizzle : public Expression { Swizzle(const Context& context, std::unique_ptr<Expression> base, std::vector<int> components) - : INHERITED(base->fOffset, kSwizzle_Kind, get_type(context, *base, components.size())) + : INHERITED(base->fPosition, kSwizzle_Kind, get_type(context, *base, components.size())) , fBase(std::move(base)) , fComponents(std::move(components)) { ASSERT(fComponents.size() >= 1 && fComponents.size() <= 4); @@ -80,13 +80,13 @@ struct Swizzle : public Expression { ASSERT(fComponents.size() == 1); int64_t value = ((Constructor&) *fBase).getIVecComponent(fComponents[0]); return std::unique_ptr<Expression>(new IntLiteral(irGenerator.fContext, - -1, - value)); + Position(), + value)); } else if (fType == *irGenerator.fContext.fFloat_Type) { ASSERT(fComponents.size() == 1); double value = ((Constructor&) *fBase).getFVecComponent(fComponents[0]); return std::unique_ptr<Expression>(new FloatLiteral(irGenerator.fContext, - -1, + Position(), value)); } } diff --git a/src/sksl/ir/SkSLSymbol.h b/src/sksl/ir/SkSLSymbol.h index f4c675319b..e883ea7555 100644 --- a/src/sksl/ir/SkSLSymbol.h +++ b/src/sksl/ir/SkSLSymbol.h @@ -24,13 +24,13 @@ struct Symbol : public IRNode { kField_Kind }; - Symbol(int offset, Kind kind, StringFragment name) - : INHERITED(offset) + Symbol(Position position, Kind kind, String name) + : INHERITED(position) , fKind(kind) - , fName(name) {} + , fName(std::move(name)) {} const Kind fKind; - StringFragment fName; + const String fName; typedef IRNode INHERITED; }; diff --git a/src/sksl/ir/SkSLSymbolTable.cpp b/src/sksl/ir/SkSLSymbolTable.cpp index 40e8e66c9f..4d39e8bc9d 100644 --- a/src/sksl/ir/SkSLSymbolTable.cpp +++ b/src/sksl/ir/SkSLSymbolTable.cpp @@ -21,7 +21,7 @@ std::vector<const FunctionDeclaration*> SymbolTable::GetFunctions(const Symbol& } } -const Symbol* SymbolTable::operator[](StringFragment name) { +const Symbol* SymbolTable::operator[](const String& name) { const auto& entry = fSymbols.find(name); if (entry == fSymbols.end()) { if (fParent) { @@ -64,12 +64,12 @@ Symbol* SymbolTable::takeOwnership(Symbol* s) { return s; } -void SymbolTable::add(StringFragment name, std::unique_ptr<Symbol> symbol) { +void SymbolTable::add(const String& name, std::unique_ptr<Symbol> symbol) { this->addWithoutOwnership(name, symbol.get()); fOwnedPointers.push_back(std::move(symbol)); } -void SymbolTable::addWithoutOwnership(StringFragment name, const Symbol* symbol) { +void SymbolTable::addWithoutOwnership(const String& name, const Symbol* symbol) { const auto& existing = fSymbols.find(name); if (existing == fSymbols.end()) { fSymbols[name] = symbol; @@ -93,7 +93,7 @@ void SymbolTable::addWithoutOwnership(StringFragment name, const Symbol* symbol) this->takeOwnership(u); } } else { - fErrorReporter.error(symbol->fOffset, "symbol '" + name + "' was already defined"); + fErrorReporter.error(symbol->fPosition, "symbol '" + name + "' was already defined"); } } diff --git a/src/sksl/ir/SkSLSymbolTable.h b/src/sksl/ir/SkSLSymbolTable.h index 241631db80..6bafef259d 100644 --- a/src/sksl/ir/SkSLSymbolTable.h +++ b/src/sksl/ir/SkSLSymbolTable.h @@ -31,11 +31,11 @@ public: : fParent(parent) , fErrorReporter(*errorReporter) {} - const Symbol* operator[](StringFragment name); + const Symbol* operator[](const String& name); - void add(StringFragment name, std::unique_ptr<Symbol> symbol); + void add(const String& name, std::unique_ptr<Symbol> symbol); - void addWithoutOwnership(StringFragment name, const Symbol* symbol); + void addWithoutOwnership(const String& name, const Symbol* symbol); Symbol* takeOwnership(Symbol* s); @@ -48,7 +48,7 @@ private: std::vector<std::unique_ptr<Symbol>> fOwnedPointers; - std::unordered_map<StringFragment, const Symbol*> fSymbols; + std::unordered_map<String, const Symbol*> fSymbols; ErrorReporter& fErrorReporter; }; diff --git a/src/sksl/ir/SkSLTernaryExpression.h b/src/sksl/ir/SkSLTernaryExpression.h index 282a3221db..567af56e8e 100644 --- a/src/sksl/ir/SkSLTernaryExpression.h +++ b/src/sksl/ir/SkSLTernaryExpression.h @@ -17,9 +17,9 @@ namespace SkSL { * A ternary expression (test ? ifTrue : ifFalse). */ struct TernaryExpression : public Expression { - TernaryExpression(int offset, std::unique_ptr<Expression> test, + TernaryExpression(Position position, std::unique_ptr<Expression> test, std::unique_ptr<Expression> ifTrue, std::unique_ptr<Expression> ifFalse) - : INHERITED(offset, kTernary_Kind, ifTrue->fType) + : INHERITED(position, kTernary_Kind, ifTrue->fType) , fTest(std::move(test)) , fIfTrue(std::move(ifTrue)) , fIfFalse(std::move(ifFalse)) { diff --git a/src/sksl/ir/SkSLType.h b/src/sksl/ir/SkSLType.h index b0474216c1..6ea4c5694c 100644 --- a/src/sksl/ir/SkSLType.h +++ b/src/sksl/ir/SkSLType.h @@ -27,9 +27,9 @@ class Context; class Type : public Symbol { public: struct Field { - Field(Modifiers modifiers, StringFragment name, const Type* type) + Field(Modifiers modifiers, String name, const Type* type) : fModifiers(modifiers) - , fName(name) + , fName(std::move(name)) , fType(std::move(type)) {} const String description() const { @@ -37,7 +37,7 @@ public: } Modifiers fModifiers; - StringFragment fName; + String fName; const Type* fType; }; @@ -62,60 +62,40 @@ public: // Create an "other" (special) type with the given name. These types cannot be directly // referenced from user code. Type(String name) - : INHERITED(-1, kType_Kind, StringFragment()) - , fNameString(std::move(name)) + : INHERITED(Position(), kType_Kind, std::move(name)) , fTypeKind(kOther_Kind) - , fNumberKind(kNonnumeric_NumberKind) { - fName.fChars = fNameString.c_str(); - fName.fLength = fNameString.size(); - } + , fNumberKind(kNonnumeric_NumberKind) {} // Create a generic type which maps to the listed types. Type(String name, std::vector<const Type*> types) - : INHERITED(-1, kType_Kind, StringFragment()) - , fNameString(std::move(name)) + : INHERITED(Position(), kType_Kind, std::move(name)) , fTypeKind(kGeneric_Kind) , fNumberKind(kNonnumeric_NumberKind) - , fCoercibleTypes(std::move(types)) { - fName.fChars = fNameString.c_str(); - fName.fLength = fNameString.size(); - } + , fCoercibleTypes(std::move(types)) {} // Create a struct type with the given fields. - Type(int offset, String name, std::vector<Field> fields) - : INHERITED(offset, kType_Kind, StringFragment()) - , fNameString(std::move(name)) + Type(Position position, String name, std::vector<Field> fields) + : INHERITED(position, kType_Kind, std::move(name)) , fTypeKind(kStruct_Kind) , fNumberKind(kNonnumeric_NumberKind) - , fFields(std::move(fields)) { - fName.fChars = fNameString.c_str(); - fName.fLength = fNameString.size(); - } + , fFields(std::move(fields)) {} // Create a scalar type. Type(String name, NumberKind numberKind) - : INHERITED(-1, kType_Kind, StringFragment()) - , fNameString(std::move(name)) + : INHERITED(Position(), kType_Kind, std::move(name)) , fTypeKind(kScalar_Kind) , fNumberKind(numberKind) , fColumns(1) - , fRows(1) { - fName.fChars = fNameString.c_str(); - fName.fLength = fNameString.size(); - } + , fRows(1) {} // Create a scalar type which can be coerced to the listed types. Type(String name, NumberKind numberKind, std::vector<const Type*> coercibleTypes) - : INHERITED(-1, kType_Kind, StringFragment()) - , fNameString(std::move(name)) + : INHERITED(Position(), kType_Kind, std::move(name)) , fTypeKind(kScalar_Kind) , fNumberKind(numberKind) , fCoercibleTypes(std::move(coercibleTypes)) , fColumns(1) - , fRows(1) { - fName.fChars = fNameString.c_str(); - fName.fLength = fNameString.size(); - } + , fRows(1) {} // Create a vector type. Type(String name, const Type& componentType, int columns) @@ -123,54 +103,42 @@ public: // Create a vector or array type. Type(String name, Kind kind, const Type& componentType, int columns) - : INHERITED(-1, kType_Kind, StringFragment()) - , fNameString(std::move(name)) + : INHERITED(Position(), kType_Kind, std::move(name)) , fTypeKind(kind) , fNumberKind(kNonnumeric_NumberKind) , fComponentType(&componentType) , fColumns(columns) , fRows(1) - , fDimensions(SpvDim1D) { - fName.fChars = fNameString.c_str(); - fName.fLength = fNameString.size(); - } + , fDimensions(SpvDim1D) {} // Create a matrix type. Type(String name, const Type& componentType, int columns, int rows) - : INHERITED(-1, kType_Kind, StringFragment()) - , fNameString(std::move(name)) + : INHERITED(Position(), kType_Kind, std::move(name)) , fTypeKind(kMatrix_Kind) , fNumberKind(kNonnumeric_NumberKind) , fComponentType(&componentType) , fColumns(columns) , fRows(rows) - , fDimensions(SpvDim1D) { - fName.fChars = fNameString.c_str(); - fName.fLength = fNameString.size(); - } + , fDimensions(SpvDim1D) {} // Create a sampler type. Type(String name, SpvDim_ dimensions, bool isDepth, bool isArrayed, bool isMultisampled, bool isSampled) - : INHERITED(-1, kType_Kind, StringFragment()) - , fNameString(std::move(name)) + : INHERITED(Position(), kType_Kind, std::move(name)) , fTypeKind(kSampler_Kind) , fNumberKind(kNonnumeric_NumberKind) , fDimensions(dimensions) , fIsDepth(isDepth) , fIsArrayed(isArrayed) , fIsMultisampled(isMultisampled) - , fIsSampled(isSampled) { - fName.fChars = fNameString.c_str(); - fName.fLength = fNameString.size(); - } + , fIsSampled(isSampled) {} const String& name() const { - return fNameString; + return fName; } String description() const override { - return fNameString; + return fName; } bool operator==(const Type& other) const { @@ -315,7 +283,6 @@ public: private: typedef Symbol INHERITED; - const String fNameString; const Kind fTypeKind; // always kNonnumeric_NumberKind for non-scalar values const NumberKind fNumberKind; diff --git a/src/sksl/ir/SkSLTypeReference.h b/src/sksl/ir/SkSLTypeReference.h index f7065b7c3f..eae19897c7 100644 --- a/src/sksl/ir/SkSLTypeReference.h +++ b/src/sksl/ir/SkSLTypeReference.h @@ -18,8 +18,8 @@ namespace SkSL { * always eventually replaced by Constructors in valid programs. */ struct TypeReference : public Expression { - TypeReference(const Context& context, int offset, const Type& type) - : INHERITED(offset, kTypeReference_Kind, *context.fInvalid_Type) + TypeReference(const Context& context, Position position, const Type& type) + : INHERITED(position, kTypeReference_Kind, *context.fInvalid_Type) , fValue(type) {} bool hasSideEffects() const override { @@ -27,7 +27,7 @@ struct TypeReference : public Expression { } String description() const override { - return String(fValue.fName); + return fValue.name(); } const Type& fValue; diff --git a/src/sksl/ir/SkSLUnresolvedFunction.h b/src/sksl/ir/SkSLUnresolvedFunction.h index 62035da3a3..b222bc3053 100644 --- a/src/sksl/ir/SkSLUnresolvedFunction.h +++ b/src/sksl/ir/SkSLUnresolvedFunction.h @@ -17,7 +17,7 @@ namespace SkSL { */ struct UnresolvedFunction : public Symbol { UnresolvedFunction(std::vector<const FunctionDeclaration*> funcs) - : INHERITED(-1, kUnresolvedFunction_Kind, funcs[0]->fName) + : INHERITED(Position(), kUnresolvedFunction_Kind, funcs[0]->fName) , fFunctions(std::move(funcs)) { #ifdef DEBUG for (auto func : funcs) { diff --git a/src/sksl/ir/SkSLVarDeclarations.h b/src/sksl/ir/SkSLVarDeclarations.h index 707715f6dc..1eda87e979 100644 --- a/src/sksl/ir/SkSLVarDeclarations.h +++ b/src/sksl/ir/SkSLVarDeclarations.h @@ -24,7 +24,7 @@ struct VarDeclaration : public Statement { VarDeclaration(const Variable* var, std::vector<std::unique_ptr<Expression>> sizes, std::unique_ptr<Expression> value) - : INHERITED(var->fOffset, Statement::kVarDeclaration_Kind) + : INHERITED(var->fPosition, Statement::kVarDeclaration_Kind) , fVar(var) , fSizes(std::move(sizes)) , fValue(std::move(value)) {} @@ -55,9 +55,9 @@ struct VarDeclaration : public Statement { * A variable declaration statement, which may consist of one or more individual variables. */ struct VarDeclarations : public ProgramElement { - VarDeclarations(int offset, const Type* baseType, + VarDeclarations(Position position, const Type* baseType, std::vector<std::unique_ptr<VarDeclaration>> vars) - : INHERITED(offset, kVar_Kind) + : INHERITED(position, kVar_Kind) , fBaseType(*baseType) { for (auto& var : vars) { fVars.push_back(std::unique_ptr<Statement>(var.release())); diff --git a/src/sksl/ir/SkSLVarDeclarationsStatement.h b/src/sksl/ir/SkSLVarDeclarationsStatement.h index 0258e66c6e..a6a95a9c08 100644 --- a/src/sksl/ir/SkSLVarDeclarationsStatement.h +++ b/src/sksl/ir/SkSLVarDeclarationsStatement.h @@ -18,7 +18,7 @@ namespace SkSL { */ struct VarDeclarationsStatement : public Statement { VarDeclarationsStatement(std::unique_ptr<VarDeclarations> decl) - : INHERITED(decl->fOffset, kVarDeclarations_Kind) + : INHERITED(decl->fPosition, kVarDeclarations_Kind) , fDeclaration(std::move(decl)) {} bool isEmpty() const override { diff --git a/src/sksl/ir/SkSLVariable.h b/src/sksl/ir/SkSLVariable.h index 536d1e6b6d..05bba20a83 100644 --- a/src/sksl/ir/SkSLVariable.h +++ b/src/sksl/ir/SkSLVariable.h @@ -27,9 +27,9 @@ struct Variable : public Symbol { kParameter_Storage }; - Variable(int offset, Modifiers modifiers, StringFragment name, const Type& type, + Variable(Position position, Modifiers modifiers, String name, const Type& type, Storage storage) - : INHERITED(offset, kVariable_Kind, name) + : INHERITED(position, kVariable_Kind, std::move(name)) , fModifiers(modifiers) , fType(type) , fStorage(storage) diff --git a/src/sksl/ir/SkSLVariableReference.h b/src/sksl/ir/SkSLVariableReference.h index 54917b0431..ba17437e24 100644 --- a/src/sksl/ir/SkSLVariableReference.h +++ b/src/sksl/ir/SkSLVariableReference.h @@ -32,8 +32,8 @@ struct VariableReference : public Expression { kReadWrite_RefKind }; - VariableReference(int offset, const Variable& variable, RefKind refKind = kRead_RefKind) - : INHERITED(offset, kVariableReference_Kind, variable.fType) + VariableReference(Position position, const Variable& variable, RefKind refKind = kRead_RefKind) + : INHERITED(position, kVariableReference_Kind, variable.fType) , fVariable(variable) , fRefKind(refKind) { if (refKind != kRead_RefKind) { @@ -83,17 +83,18 @@ struct VariableReference : public Expression { ASSERT(expr->isConstant()); switch (expr->fKind) { case Expression::kIntLiteral_Kind: - return std::unique_ptr<Expression>(new IntLiteral(irGenerator.fContext, - -1, - ((IntLiteral*) expr)->fValue)); + return std::unique_ptr<Expression>(new IntLiteral( + irGenerator.fContext, + Position(), + ((IntLiteral*) expr)->fValue)); case Expression::kFloatLiteral_Kind: return std::unique_ptr<Expression>(new FloatLiteral( - irGenerator.fContext, - -1, - ((FloatLiteral*) expr)->fValue)); + irGenerator.fContext, + Position(), + ((FloatLiteral*) expr)->fValue)); case Expression::kBoolLiteral_Kind: return std::unique_ptr<Expression>(new BoolLiteral(irGenerator.fContext, - -1, + Position(), ((BoolLiteral*) expr)->fValue)); case Expression::kConstructor_Kind: { const Constructor* c = (const Constructor*) expr; @@ -101,12 +102,12 @@ struct VariableReference : public Expression { for (const auto& arg : c->fArguments) { args.push_back(copy_constant(irGenerator, arg.get())); } - return std::unique_ptr<Expression>(new Constructor(-1, c->fType, + return std::unique_ptr<Expression>(new Constructor(Position(), c->fType, std::move(args))); } case Expression::kSetting_Kind: { const Setting* s = (const Setting*) expr; - return std::unique_ptr<Expression>(new Setting(-1, s->fName, + return std::unique_ptr<Expression>(new Setting(Position(), s->fName, copy_constant(irGenerator, s->fValue.get()))); } diff --git a/src/sksl/ir/SkSLWhileStatement.h b/src/sksl/ir/SkSLWhileStatement.h index aed6494999..6df1619a56 100644 --- a/src/sksl/ir/SkSLWhileStatement.h +++ b/src/sksl/ir/SkSLWhileStatement.h @@ -17,9 +17,9 @@ namespace SkSL { * A 'while' loop. */ struct WhileStatement : public Statement { - WhileStatement(int offset, std::unique_ptr<Expression> test, + WhileStatement(Position position, std::unique_ptr<Expression> test, std::unique_ptr<Statement> statement) - : INHERITED(offset, kWhile_Kind) + : INHERITED(position, kWhile_Kind) , fTest(std::move(test)) , fStatement(std::move(statement)) {} |