aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sksl/ir
diff options
context:
space:
mode:
authorGravatar msarett <msarett@google.com>2016-07-13 13:18:40 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-07-13 13:18:40 -0700
commite92badc3ffce83668f76fcfa33a49784346cab1e (patch)
tree5c05deb93ca06313ad1916ecaa5f1fe1ebd0ca59 /src/sksl/ir
parent16ef465ea92291b860ee5ea8f3d51d5d3f4f1059 (diff)
Revert of SkSL performance improvements (patchset #6 id:140001 of https://codereview.chromium.org/2131223002/ )
Reason for revert: Valgrind bot failures https://build.chromium.org/p/client.skia/builders/Test-Ubuntu-GCC-ShuttleA-GPU-GTX550Ti-x86_64-Release-Valgrind/builds/1224/steps/test_skia%20on%20Ubuntu/logs/stdio Original issue's description: > SkSL performance improvements (plus a couple of minor warning fixes) > GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2131223002 > > Committed: https://skia.googlesource.com/skia/+/9fd67a1f53809f5eff1210dd107241b450c48acc TBR=benjaminwagner@google.com,egdaniel@google.com,ethannicholas@google.com # Not skipping CQ checks because original CL landed more than 1 days ago. Review-Url: https://codereview.chromium.org/2143323003
Diffstat (limited to 'src/sksl/ir')
-rw-r--r--src/sksl/ir/SkSLBinaryExpression.h2
-rw-r--r--src/sksl/ir/SkSLBlock.h8
-rw-r--r--src/sksl/ir/SkSLBoolLiteral.h2
-rw-r--r--src/sksl/ir/SkSLConstructor.h6
-rw-r--r--src/sksl/ir/SkSLExpression.h4
-rw-r--r--src/sksl/ir/SkSLField.h8
-rw-r--r--src/sksl/ir/SkSLFieldAccess.h4
-rw-r--r--src/sksl/ir/SkSLFloatLiteral.h2
-rw-r--r--src/sksl/ir/SkSLForStatement.h7
-rw-r--r--src/sksl/ir/SkSLFunctionCall.h8
-rw-r--r--src/sksl/ir/SkSLFunctionDeclaration.h27
-rw-r--r--src/sksl/ir/SkSLFunctionDefinition.h8
-rw-r--r--src/sksl/ir/SkSLFunctionReference.h6
-rw-r--r--src/sksl/ir/SkSLIndexExpression.h22
-rw-r--r--src/sksl/ir/SkSLIntLiteral.h2
-rw-r--r--src/sksl/ir/SkSLInterfaceBlock.h16
-rw-r--r--src/sksl/ir/SkSLProgram.h8
-rw-r--r--src/sksl/ir/SkSLSwizzle.h45
-rw-r--r--src/sksl/ir/SkSLSymbolTable.cpp81
-rw-r--r--src/sksl/ir/SkSLSymbolTable.h19
-rw-r--r--src/sksl/ir/SkSLType.cpp310
-rw-r--r--src/sksl/ir/SkSLType.h234
-rw-r--r--src/sksl/ir/SkSLTypeReference.h8
-rw-r--r--src/sksl/ir/SkSLUnresolvedFunction.h6
-rw-r--r--src/sksl/ir/SkSLVarDeclaration.h8
-rw-r--r--src/sksl/ir/SkSLVariable.h17
-rw-r--r--src/sksl/ir/SkSLVariableReference.h10
27 files changed, 426 insertions, 452 deletions
diff --git a/src/sksl/ir/SkSLBinaryExpression.h b/src/sksl/ir/SkSLBinaryExpression.h
index 9ecdbc717c..bd89d6c602 100644
--- a/src/sksl/ir/SkSLBinaryExpression.h
+++ b/src/sksl/ir/SkSLBinaryExpression.h
@@ -18,7 +18,7 @@ namespace SkSL {
*/
struct BinaryExpression : public Expression {
BinaryExpression(Position position, std::unique_ptr<Expression> left, Token::Kind op,
- std::unique_ptr<Expression> right, const Type& type)
+ std::unique_ptr<Expression> right, std::shared_ptr<Type> type)
: INHERITED(position, kBinary_Kind, type)
, fLeft(std::move(left))
, fOperator(op)
diff --git a/src/sksl/ir/SkSLBlock.h b/src/sksl/ir/SkSLBlock.h
index a53d13d169..56ed77a0ba 100644
--- a/src/sksl/ir/SkSLBlock.h
+++ b/src/sksl/ir/SkSLBlock.h
@@ -9,7 +9,6 @@
#define SKSL_BLOCK
#include "SkSLStatement.h"
-#include "SkSLSymbolTable.h"
namespace SkSL {
@@ -17,11 +16,9 @@ namespace SkSL {
* A block of multiple statements functioning as a single statement.
*/
struct Block : public Statement {
- Block(Position position, std::vector<std::unique_ptr<Statement>> statements,
- const std::shared_ptr<SymbolTable> symbols)
+ Block(Position position, std::vector<std::unique_ptr<Statement>> statements)
: INHERITED(position, kBlock_Kind)
- , fStatements(std::move(statements))
- , fSymbols(std::move(symbols)) {}
+ , fStatements(std::move(statements)) {}
std::string description() const override {
std::string result = "{";
@@ -34,7 +31,6 @@ struct Block : public Statement {
}
const std::vector<std::unique_ptr<Statement>> fStatements;
- const std::shared_ptr<SymbolTable> fSymbols;
typedef Statement INHERITED;
};
diff --git a/src/sksl/ir/SkSLBoolLiteral.h b/src/sksl/ir/SkSLBoolLiteral.h
index 31cb817548..3c40e59514 100644
--- a/src/sksl/ir/SkSLBoolLiteral.h
+++ b/src/sksl/ir/SkSLBoolLiteral.h
@@ -17,7 +17,7 @@ namespace SkSL {
*/
struct BoolLiteral : public Expression {
BoolLiteral(Position position, bool value)
- : INHERITED(position, kBoolLiteral_Kind, *kBool_Type)
+ : INHERITED(position, kBoolLiteral_Kind, kBool_Type)
, fValue(value) {}
std::string description() const override {
diff --git a/src/sksl/ir/SkSLConstructor.h b/src/sksl/ir/SkSLConstructor.h
index 0501b651ea..c58da7e5b8 100644
--- a/src/sksl/ir/SkSLConstructor.h
+++ b/src/sksl/ir/SkSLConstructor.h
@@ -16,13 +16,13 @@ namespace SkSL {
* Represents the construction of a compound type, such as "vec2(x, y)".
*/
struct Constructor : public Expression {
- Constructor(Position position, const Type& type,
+ Constructor(Position position, std::shared_ptr<Type> type,
std::vector<std::unique_ptr<Expression>> arguments)
- : INHERITED(position, kConstructor_Kind, type)
+ : INHERITED(position, kConstructor_Kind, std::move(type))
, fArguments(std::move(arguments)) {}
std::string description() const override {
- std::string result = fType.description() + "(";
+ std::string result = fType->description() + "(";
std::string separator = "";
for (size_t i = 0; i < fArguments.size(); i++) {
result += separator;
diff --git a/src/sksl/ir/SkSLExpression.h b/src/sksl/ir/SkSLExpression.h
index 92cb37de77..1e42c7a475 100644
--- a/src/sksl/ir/SkSLExpression.h
+++ b/src/sksl/ir/SkSLExpression.h
@@ -35,7 +35,7 @@ struct Expression : public IRNode {
kTypeReference_Kind,
};
- Expression(Position position, Kind kind, const Type& type)
+ Expression(Position position, Kind kind, std::shared_ptr<Type> type)
: INHERITED(position)
, fKind(kind)
, fType(std::move(type)) {}
@@ -45,7 +45,7 @@ struct Expression : public IRNode {
}
const Kind fKind;
- const Type& fType;
+ const std::shared_ptr<Type> fType;
typedef IRNode INHERITED;
};
diff --git a/src/sksl/ir/SkSLField.h b/src/sksl/ir/SkSLField.h
index a01df2943d..f2b68bc2bc 100644
--- a/src/sksl/ir/SkSLField.h
+++ b/src/sksl/ir/SkSLField.h
@@ -21,16 +21,16 @@ namespace SkSL {
* result of declaring anonymous interface blocks.
*/
struct Field : public Symbol {
- Field(Position position, const Variable& owner, int fieldIndex)
- : INHERITED(position, kField_Kind, owner.fType.fields()[fieldIndex].fName)
+ Field(Position position, std::shared_ptr<Variable> owner, int fieldIndex)
+ : INHERITED(position, kField_Kind, owner->fType->fields()[fieldIndex].fName)
, fOwner(owner)
, fFieldIndex(fieldIndex) {}
virtual std::string description() const override {
- return fOwner.description() + "." + fOwner.fType.fields()[fFieldIndex].fName;
+ return fOwner->description() + "." + fOwner->fType->fields()[fFieldIndex].fName;
}
- const Variable& fOwner;
+ const std::shared_ptr<Variable> fOwner;
const int fFieldIndex;
typedef Symbol INHERITED;
diff --git a/src/sksl/ir/SkSLFieldAccess.h b/src/sksl/ir/SkSLFieldAccess.h
index f09c3a3447..053498e154 100644
--- a/src/sksl/ir/SkSLFieldAccess.h
+++ b/src/sksl/ir/SkSLFieldAccess.h
@@ -18,12 +18,12 @@ namespace SkSL {
*/
struct FieldAccess : public Expression {
FieldAccess(std::unique_ptr<Expression> base, int fieldIndex)
- : INHERITED(base->fPosition, kFieldAccess_Kind, base->fType.fields()[fieldIndex].fType)
+ : INHERITED(base->fPosition, kFieldAccess_Kind, base->fType->fields()[fieldIndex].fType)
, fBase(std::move(base))
, fFieldIndex(fieldIndex) {}
virtual std::string description() const override {
- return fBase->description() + "." + fBase->fType.fields()[fFieldIndex].fName;
+ return fBase->description() + "." + fBase->fType->fields()[fFieldIndex].fName;
}
const std::unique_ptr<Expression> fBase;
diff --git a/src/sksl/ir/SkSLFloatLiteral.h b/src/sksl/ir/SkSLFloatLiteral.h
index 8f5ec43299..deb5b27144 100644
--- a/src/sksl/ir/SkSLFloatLiteral.h
+++ b/src/sksl/ir/SkSLFloatLiteral.h
@@ -17,7 +17,7 @@ namespace SkSL {
*/
struct FloatLiteral : public Expression {
FloatLiteral(Position position, double value)
- : INHERITED(position, kFloatLiteral_Kind, *kFloat_Type)
+ : INHERITED(position, kFloatLiteral_Kind, kFloat_Type)
, fValue(value) {}
virtual std::string description() const override {
diff --git a/src/sksl/ir/SkSLForStatement.h b/src/sksl/ir/SkSLForStatement.h
index 642d15125e..70bb4014c8 100644
--- a/src/sksl/ir/SkSLForStatement.h
+++ b/src/sksl/ir/SkSLForStatement.h
@@ -10,7 +10,6 @@
#include "SkSLExpression.h"
#include "SkSLStatement.h"
-#include "SkSLSymbolTable.h"
namespace SkSL {
@@ -20,13 +19,12 @@ namespace SkSL {
struct ForStatement : public Statement {
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)
+ std::unique_ptr<Statement> statement)
: INHERITED(position, kFor_Kind)
, fInitializer(std::move(initializer))
, fTest(std::move(test))
, fNext(std::move(next))
- , fStatement(std::move(statement))
- , fSymbols(symbols) {}
+ , fStatement(std::move(statement)) {}
std::string description() const override {
std::string result = "for (";
@@ -49,7 +47,6 @@ struct ForStatement : public Statement {
const std::unique_ptr<Expression> fTest;
const std::unique_ptr<Expression> fNext;
const std::unique_ptr<Statement> fStatement;
- const std::shared_ptr<SymbolTable> fSymbols;
typedef Statement INHERITED;
};
diff --git a/src/sksl/ir/SkSLFunctionCall.h b/src/sksl/ir/SkSLFunctionCall.h
index 85dba40f2a..78d2566227 100644
--- a/src/sksl/ir/SkSLFunctionCall.h
+++ b/src/sksl/ir/SkSLFunctionCall.h
@@ -17,14 +17,14 @@ namespace SkSL {
* A function invocation.
*/
struct FunctionCall : public Expression {
- FunctionCall(Position position, const FunctionDeclaration& function,
+ FunctionCall(Position position, std::shared_ptr<FunctionDeclaration> function,
std::vector<std::unique_ptr<Expression>> arguments)
- : INHERITED(position, kFunctionCall_Kind, function.fReturnType)
+ : INHERITED(position, kFunctionCall_Kind, function->fReturnType)
, fFunction(std::move(function))
, fArguments(std::move(arguments)) {}
std::string description() const override {
- std::string result = fFunction.fName + "(";
+ std::string result = fFunction->fName + "(";
std::string separator = "";
for (size_t i = 0; i < fArguments.size(); i++) {
result += separator;
@@ -35,7 +35,7 @@ struct FunctionCall : public Expression {
return result;
}
- const FunctionDeclaration& fFunction;
+ const std::shared_ptr<FunctionDeclaration> fFunction;
const std::vector<std::unique_ptr<Expression>> fArguments;
typedef Expression INHERITED;
diff --git a/src/sksl/ir/SkSLFunctionDeclaration.h b/src/sksl/ir/SkSLFunctionDeclaration.h
index 16a184a6d7..32c23f545e 100644
--- a/src/sksl/ir/SkSLFunctionDeclaration.h
+++ b/src/sksl/ir/SkSLFunctionDeclaration.h
@@ -10,7 +10,6 @@
#include "SkSLModifiers.h"
#include "SkSLSymbol.h"
-#include "SkSLSymbolTable.h"
#include "SkSLType.h"
#include "SkSLVariable.h"
@@ -21,14 +20,15 @@ namespace SkSL {
*/
struct FunctionDeclaration : public Symbol {
FunctionDeclaration(Position position, std::string name,
- std::vector<const Variable*> parameters, const Type& returnType)
+ std::vector<std::shared_ptr<Variable>> parameters,
+ std::shared_ptr<Type> returnType)
: INHERITED(position, kFunctionDeclaration_Kind, std::move(name))
, fDefined(false)
- , fParameters(std::move(parameters))
+ , fParameters(parameters)
, fReturnType(returnType) {}
std::string description() const override {
- std::string result = fReturnType.description() + " " + fName + "(";
+ std::string result = fReturnType->description() + " " + fName + "(";
std::string separator = "";
for (auto p : fParameters) {
result += separator;
@@ -39,24 +39,13 @@ struct FunctionDeclaration : public Symbol {
return result;
}
- bool matches(const FunctionDeclaration& f) const {
- if (fName != f.fName) {
- return false;
- }
- if (fParameters.size() != f.fParameters.size()) {
- return false;
- }
- for (size_t i = 0; i < fParameters.size(); i++) {
- if (fParameters[i]->fType != f.fParameters[i]->fType) {
- return false;
- }
- }
- return true;
+ bool matches(FunctionDeclaration& f) {
+ return fName == f.fName && fParameters == f.fParameters;
}
mutable bool fDefined;
- const std::vector<const Variable*> fParameters;
- const Type& fReturnType;
+ const std::vector<std::shared_ptr<Variable>> fParameters;
+ const std::shared_ptr<Type> fReturnType;
typedef Symbol INHERITED;
};
diff --git a/src/sksl/ir/SkSLFunctionDefinition.h b/src/sksl/ir/SkSLFunctionDefinition.h
index ace27a3ed8..fceb5474cb 100644
--- a/src/sksl/ir/SkSLFunctionDefinition.h
+++ b/src/sksl/ir/SkSLFunctionDefinition.h
@@ -18,17 +18,17 @@ namespace SkSL {
* A function definition (a declaration plus an associated block of code).
*/
struct FunctionDefinition : public ProgramElement {
- FunctionDefinition(Position position, const FunctionDeclaration& declaration,
+ FunctionDefinition(Position position, std::shared_ptr<FunctionDeclaration> declaration,
std::unique_ptr<Block> body)
: INHERITED(position, kFunction_Kind)
- , fDeclaration(declaration)
+ , fDeclaration(std::move(declaration))
, fBody(std::move(body)) {}
std::string description() const override {
- return fDeclaration.description() + " " + fBody->description();
+ return fDeclaration->description() + " " + fBody->description();
}
- const FunctionDeclaration& fDeclaration;
+ const std::shared_ptr<FunctionDeclaration> fDeclaration;
const std::unique_ptr<Block> fBody;
typedef ProgramElement INHERITED;
diff --git a/src/sksl/ir/SkSLFunctionReference.h b/src/sksl/ir/SkSLFunctionReference.h
index 8afcbb1e32..d5cc444000 100644
--- a/src/sksl/ir/SkSLFunctionReference.h
+++ b/src/sksl/ir/SkSLFunctionReference.h
@@ -17,8 +17,8 @@ namespace SkSL {
* always eventually replaced by FunctionCalls in valid programs.
*/
struct FunctionReference : public Expression {
- FunctionReference(Position position, std::vector<const FunctionDeclaration*> function)
- : INHERITED(position, kFunctionReference_Kind, *kInvalid_Type)
+ FunctionReference(Position position, std::vector<std::shared_ptr<FunctionDeclaration>> function)
+ : INHERITED(position, kFunctionReference_Kind, kInvalid_Type)
, fFunctions(function) {}
virtual std::string description() const override {
@@ -26,7 +26,7 @@ struct FunctionReference : public Expression {
return "<function>";
}
- const std::vector<const FunctionDeclaration*> fFunctions;
+ const std::vector<std::shared_ptr<FunctionDeclaration>> fFunctions;
typedef Expression INHERITED;
};
diff --git a/src/sksl/ir/SkSLIndexExpression.h b/src/sksl/ir/SkSLIndexExpression.h
index 78727aa5c5..538c656153 100644
--- a/src/sksl/ir/SkSLIndexExpression.h
+++ b/src/sksl/ir/SkSLIndexExpression.h
@@ -16,21 +16,21 @@ namespace SkSL {
/**
* Given a type, returns the type that will result from extracting an array value from it.
*/
-static const Type& index_type(const Type& type) {
+static std::shared_ptr<Type> index_type(const Type& type) {
if (type.kind() == Type::kMatrix_Kind) {
- if (type.componentType() == *kFloat_Type) {
+ if (type.componentType() == kFloat_Type) {
switch (type.columns()) {
- case 2: return *kVec2_Type;
- case 3: return *kVec3_Type;
- case 4: return *kVec4_Type;
+ case 2: return kVec2_Type;
+ case 3: return kVec3_Type;
+ case 4: return kVec4_Type;
default: ASSERT(false);
}
} else {
- ASSERT(type.componentType() == *kDouble_Type);
+ ASSERT(type.componentType() == kDouble_Type);
switch (type.columns()) {
- case 2: return *kDVec2_Type;
- case 3: return *kDVec3_Type;
- case 4: return *kDVec4_Type;
+ case 2: return kDVec2_Type;
+ case 3: return kDVec3_Type;
+ case 4: return kDVec4_Type;
default: ASSERT(false);
}
}
@@ -43,10 +43,10 @@ static const Type& index_type(const Type& type) {
*/
struct IndexExpression : public Expression {
IndexExpression(std::unique_ptr<Expression> base, std::unique_ptr<Expression> index)
- : INHERITED(base->fPosition, kIndex_Kind, index_type(base->fType))
+ : INHERITED(base->fPosition, kIndex_Kind, index_type(*base->fType))
, fBase(std::move(base))
, fIndex(std::move(index)) {
- ASSERT(fIndex->fType == *kInt_Type);
+ ASSERT(fIndex->fType == kInt_Type);
}
std::string description() const override {
diff --git a/src/sksl/ir/SkSLIntLiteral.h b/src/sksl/ir/SkSLIntLiteral.h
index 63b0069784..80b30d7c05 100644
--- a/src/sksl/ir/SkSLIntLiteral.h
+++ b/src/sksl/ir/SkSLIntLiteral.h
@@ -19,7 +19,7 @@ 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(Position position, int64_t value)
- : INHERITED(position, kIntLiteral_Kind, *kInt_Type)
+ : INHERITED(position, kIntLiteral_Kind, kInt_Type)
, fValue(value) {}
virtual std::string description() const override {
diff --git a/src/sksl/ir/SkSLInterfaceBlock.h b/src/sksl/ir/SkSLInterfaceBlock.h
index f1121ed707..baedb5864c 100644
--- a/src/sksl/ir/SkSLInterfaceBlock.h
+++ b/src/sksl/ir/SkSLInterfaceBlock.h
@@ -24,24 +24,22 @@ namespace SkSL {
* At the IR level, this is represented by a single variable of struct type.
*/
struct InterfaceBlock : public ProgramElement {
- InterfaceBlock(Position position, const Variable& var, std::shared_ptr<SymbolTable> typeOwner)
+ InterfaceBlock(Position position, std::shared_ptr<Variable> var)
: INHERITED(position, kInterfaceBlock_Kind)
- , fVariable(std::move(var))
- , fTypeOwner(typeOwner) {
- ASSERT(fVariable.fType.kind() == Type::kStruct_Kind);
+ , fVariable(std::move(var)) {
+ ASSERT(fVariable->fType->kind() == Type::kStruct_Kind);
}
std::string description() const override {
- std::string result = fVariable.fModifiers.description() + fVariable.fName + " {\n";
- for (size_t i = 0; i < fVariable.fType.fields().size(); i++) {
- result += fVariable.fType.fields()[i].description() + "\n";
+ std::string result = fVariable->fModifiers.description() + fVariable->fName + " {\n";
+ for (size_t i = 0; i < fVariable->fType->fields().size(); i++) {
+ result += fVariable->fType->fields()[i].description() + "\n";
}
result += "};";
return result;
}
- const Variable& fVariable;
- const std::shared_ptr<SymbolTable> fTypeOwner;
+ const std::shared_ptr<Variable> fVariable;
typedef ProgramElement INHERITED;
};
diff --git a/src/sksl/ir/SkSLProgram.h b/src/sksl/ir/SkSLProgram.h
index 205db6e932..5edcfded42 100644
--- a/src/sksl/ir/SkSLProgram.h
+++ b/src/sksl/ir/SkSLProgram.h
@@ -12,7 +12,6 @@
#include <memory>
#include "SkSLProgramElement.h"
-#include "SkSLSymbolTable.h"
namespace SkSL {
@@ -25,16 +24,13 @@ struct Program {
kVertex_Kind
};
- Program(Kind kind, std::vector<std::unique_ptr<ProgramElement>> elements,
- std::shared_ptr<SymbolTable> symbols)
+ Program(Kind kind, std::vector<std::unique_ptr<ProgramElement>> elements)
: fKind(kind)
- , fElements(std::move(elements))
- , fSymbols(symbols) {}
+ , fElements(std::move(elements)) {}
Kind fKind;
std::vector<std::unique_ptr<ProgramElement>> fElements;
- std::shared_ptr<SymbolTable> fSymbols;
};
} // namespace
diff --git a/src/sksl/ir/SkSLSwizzle.h b/src/sksl/ir/SkSLSwizzle.h
index fad71b8114..ce360d1847 100644
--- a/src/sksl/ir/SkSLSwizzle.h
+++ b/src/sksl/ir/SkSLSwizzle.h
@@ -18,40 +18,41 @@ namespace SkSL {
* instance, swizzling a vec3 with two components will result in a vec2. It is possible to swizzle
* with more components than the source vector, as in 'vec2(1).xxxx'.
*/
-static const Type& get_type(Expression& value, size_t count) {
- const Type& base = value.fType.componentType();
+static std::shared_ptr<Type> get_type(Expression& value,
+ size_t count) {
+ std::shared_ptr<Type> base = value.fType->componentType();
if (count == 1) {
return base;
}
- if (base == *kFloat_Type) {
+ if (base == kFloat_Type) {
switch (count) {
- case 2: return *kVec2_Type;
- case 3: return *kVec3_Type;
- case 4: return *kVec4_Type;
+ case 2: return kVec2_Type;
+ case 3: return kVec3_Type;
+ case 4: return kVec4_Type;
}
- } else if (base == *kDouble_Type) {
+ } else if (base == kDouble_Type) {
switch (count) {
- case 2: return *kDVec2_Type;
- case 3: return *kDVec3_Type;
- case 4: return *kDVec4_Type;
+ case 2: return kDVec2_Type;
+ case 3: return kDVec3_Type;
+ case 4: return kDVec4_Type;
}
- } else if (base == *kInt_Type) {
+ } else if (base == kInt_Type) {
switch (count) {
- case 2: return *kIVec2_Type;
- case 3: return *kIVec3_Type;
- case 4: return *kIVec4_Type;
+ case 2: return kIVec2_Type;
+ case 3: return kIVec3_Type;
+ case 4: return kIVec4_Type;
}
- } else if (base == *kUInt_Type) {
+ } else if (base == kUInt_Type) {
switch (count) {
- case 2: return *kUVec2_Type;
- case 3: return *kUVec3_Type;
- case 4: return *kUVec4_Type;
+ case 2: return kUVec2_Type;
+ case 3: return kUVec3_Type;
+ case 4: return kUVec4_Type;
}
- } else if (base == *kBool_Type) {
+ } else if (base == kBool_Type) {
switch (count) {
- case 2: return *kBVec2_Type;
- case 3: return *kBVec3_Type;
- case 4: return *kBVec4_Type;
+ case 2: return kBVec2_Type;
+ case 3: return kBVec3_Type;
+ case 4: return kBVec4_Type;
}
}
ABORT("cannot swizzle %s\n", value.description().c_str());
diff --git a/src/sksl/ir/SkSLSymbolTable.cpp b/src/sksl/ir/SkSLSymbolTable.cpp
index 80e22da009..af83f7a456 100644
--- a/src/sksl/ir/SkSLSymbolTable.cpp
+++ b/src/sksl/ir/SkSLSymbolTable.cpp
@@ -5,23 +5,23 @@
* found in the LICENSE file.
*/
-#include "SkSLSymbolTable.h"
-#include "SkSLUnresolvedFunction.h"
+ #include "SkSLSymbolTable.h"
namespace SkSL {
-std::vector<const FunctionDeclaration*> SymbolTable::GetFunctions(const Symbol& s) {
- switch (s.fKind) {
+std::vector<std::shared_ptr<FunctionDeclaration>> SymbolTable::GetFunctions(
+ const std::shared_ptr<Symbol>& s) {
+ switch (s->fKind) {
case Symbol::kFunctionDeclaration_Kind:
- return { &((FunctionDeclaration&) s) };
+ return { std::static_pointer_cast<FunctionDeclaration>(s) };
case Symbol::kUnresolvedFunction_Kind:
- return ((UnresolvedFunction&) s).fFunctions;
+ return ((UnresolvedFunction&) *s).fFunctions;
default:
return { };
}
}
-const Symbol* SymbolTable::operator[](const std::string& name) {
+std::shared_ptr<Symbol> SymbolTable::operator[](const std::string& name) {
const auto& entry = fSymbols.find(name);
if (entry == fSymbols.end()) {
if (fParent) {
@@ -30,15 +30,15 @@ const Symbol* SymbolTable::operator[](const std::string& name) {
return nullptr;
}
if (fParent) {
- auto functions = GetFunctions(*entry->second);
+ auto functions = GetFunctions(entry->second);
if (functions.size() > 0) {
bool modified = false;
- const Symbol* previous = (*fParent)[name];
+ std::shared_ptr<Symbol> previous = (*fParent)[name];
if (previous) {
- auto previousFunctions = GetFunctions(*previous);
- for (const FunctionDeclaration* prev : previousFunctions) {
+ auto previousFunctions = GetFunctions(previous);
+ for (const std::shared_ptr<FunctionDeclaration>& prev : previousFunctions) {
bool found = false;
- for (const FunctionDeclaration* current : functions) {
+ for (const std::shared_ptr<FunctionDeclaration>& current : functions) {
if (current->matches(*prev)) {
found = true;
break;
@@ -51,7 +51,7 @@ const Symbol* SymbolTable::operator[](const std::string& name) {
}
if (modified) {
ASSERT(functions.size() > 1);
- return this->takeOwnership(new UnresolvedFunction(functions));
+ return std::shared_ptr<Symbol>(new UnresolvedFunction(functions));
}
}
}
@@ -59,42 +59,27 @@ const Symbol* SymbolTable::operator[](const std::string& name) {
return entry->second;
}
-Symbol* SymbolTable::takeOwnership(Symbol* s) {
- fOwnedPointers.push_back(std::unique_ptr<Symbol>(s));
- return s;
-}
-
-void SymbolTable::add(const std::string& name, std::unique_ptr<Symbol> symbol) {
- this->addWithoutOwnership(name, symbol.get());
- fOwnedPointers.push_back(std::move(symbol));
-}
-
-void SymbolTable::addWithoutOwnership(const std::string& name, const Symbol* symbol) {
- const auto& existing = fSymbols.find(name);
- if (existing == fSymbols.end()) {
- fSymbols[name] = symbol;
- } else if (symbol->fKind == Symbol::kFunctionDeclaration_Kind) {
- const Symbol* oldSymbol = existing->second;
- if (oldSymbol->fKind == Symbol::kFunctionDeclaration_Kind) {
- std::vector<const FunctionDeclaration*> functions;
- functions.push_back((const FunctionDeclaration*) oldSymbol);
- functions.push_back((const FunctionDeclaration*) symbol);
- UnresolvedFunction* u = new UnresolvedFunction(std::move(functions));
- fSymbols[name] = u;
- this->takeOwnership(u);
- } else if (oldSymbol->fKind == Symbol::kUnresolvedFunction_Kind) {
- std::vector<const FunctionDeclaration*> functions;
- for (const auto* f : ((UnresolvedFunction&) *oldSymbol).fFunctions) {
- functions.push_back(f);
+void SymbolTable::add(const std::string& name, std::shared_ptr<Symbol> symbol) {
+ const auto& existing = fSymbols.find(name);
+ if (existing == fSymbols.end()) {
+ fSymbols[name] = symbol;
+ } else if (symbol->fKind == Symbol::kFunctionDeclaration_Kind) {
+ const std::shared_ptr<Symbol>& oldSymbol = existing->second;
+ if (oldSymbol->fKind == Symbol::kFunctionDeclaration_Kind) {
+ std::vector<std::shared_ptr<FunctionDeclaration>> functions;
+ functions.push_back(std::static_pointer_cast<FunctionDeclaration>(oldSymbol));
+ functions.push_back(std::static_pointer_cast<FunctionDeclaration>(symbol));
+ fSymbols[name].reset(new UnresolvedFunction(std::move(functions)));
+ } else if (oldSymbol->fKind == Symbol::kUnresolvedFunction_Kind) {
+ std::vector<std::shared_ptr<FunctionDeclaration>> functions;
+ for (const auto& f : ((UnresolvedFunction&) *oldSymbol).fFunctions) {
+ functions.push_back(f);
+ }
+ functions.push_back(std::static_pointer_cast<FunctionDeclaration>(symbol));
+ fSymbols[name].reset(new UnresolvedFunction(std::move(functions)));
}
- functions.push_back((const FunctionDeclaration*) symbol);
- UnresolvedFunction* u = new UnresolvedFunction(std::move(functions));
- fSymbols[name] = u;
- this->takeOwnership(u);
+ } else {
+ fErrorReporter.error(symbol->fPosition, "symbol '" + name + "' was already defined");
}
- } else {
- fErrorReporter.error(symbol->fPosition, "symbol '" + name + "' was already defined");
}
-}
-
} // namespace
diff --git a/src/sksl/ir/SkSLSymbolTable.h b/src/sksl/ir/SkSLSymbolTable.h
index d732023ff0..151475d642 100644
--- a/src/sksl/ir/SkSLSymbolTable.h
+++ b/src/sksl/ir/SkSLSymbolTable.h
@@ -10,14 +10,12 @@
#include <memory>
#include <unordered_map>
-#include <vector>
#include "SkSLErrorReporter.h"
#include "SkSLSymbol.h"
+#include "SkSLUnresolvedFunction.h"
namespace SkSL {
-struct FunctionDeclaration;
-
/**
* Maps identifiers to symbols. Functions, in particular, are mapped to either FunctionDeclaration
* or UnresolvedFunction depending on whether they are overloaded or not.
@@ -31,22 +29,17 @@ public:
: fParent(parent)
, fErrorReporter(errorReporter) {}
- const Symbol* operator[](const std::string& name);
-
- void add(const std::string& name, std::unique_ptr<Symbol> symbol);
+ std::shared_ptr<Symbol> operator[](const std::string& name);
- void addWithoutOwnership(const std::string& name, const Symbol* symbol);
-
- Symbol* takeOwnership(Symbol* s);
+ void add(const std::string& name, std::shared_ptr<Symbol> symbol);
const std::shared_ptr<SymbolTable> fParent;
private:
- static std::vector<const FunctionDeclaration*> GetFunctions(const Symbol& s);
-
- std::vector<std::unique_ptr<Symbol>> fOwnedPointers;
+ static std::vector<std::shared_ptr<FunctionDeclaration>> GetFunctions(
+ const std::shared_ptr<Symbol>& s);
- std::unordered_map<std::string, const Symbol*> fSymbols;
+ std::unordered_map<std::string, std::shared_ptr<Symbol>> fSymbols;
ErrorReporter& fErrorReporter;
};
diff --git a/src/sksl/ir/SkSLType.cpp b/src/sksl/ir/SkSLType.cpp
index 671f40b79d..27cbd39e44 100644
--- a/src/sksl/ir/SkSLType.cpp
+++ b/src/sksl/ir/SkSLType.cpp
@@ -9,26 +9,26 @@
namespace SkSL {
-bool Type::determineCoercionCost(const Type& other, int* outCost) const {
- if (*this == other) {
+bool Type::determineCoercionCost(std::shared_ptr<Type> other, int* outCost) const {
+ if (this == other.get()) {
*outCost = 0;
return true;
}
- if (this->kind() == kVector_Kind && other.kind() == kVector_Kind) {
- if (this->columns() == other.columns()) {
- return this->componentType().determineCoercionCost(other.componentType(), outCost);
+ if (this->kind() == kVector_Kind && other->kind() == kVector_Kind) {
+ if (this->columns() == other->columns()) {
+ return this->componentType()->determineCoercionCost(other->componentType(), outCost);
}
return false;
}
if (this->kind() == kMatrix_Kind) {
- if (this->columns() == other.columns() &&
- this->rows() == other.rows()) {
- return this->componentType().determineCoercionCost(other.componentType(), outCost);
+ if (this->columns() == other->columns() &&
+ this->rows() == other->rows()) {
+ return this->componentType()->determineCoercionCost(other->componentType(), outCost);
}
return false;
}
for (size_t i = 0; i < fCoercibleTypes.size(); i++) {
- if (*fCoercibleTypes[i] == other) {
+ if (fCoercibleTypes[i] == other) {
*outCost = (int) i + 1;
return true;
}
@@ -36,39 +36,39 @@ bool Type::determineCoercionCost(const Type& other, int* outCost) const {
return false;
}
-const Type& Type::toCompound(int columns, int rows) const {
+std::shared_ptr<Type> Type::toCompound(int columns, int rows) {
ASSERT(this->kind() == Type::kScalar_Kind);
if (columns == 1 && rows == 1) {
- return *this;
+ return std::shared_ptr<Type>(this);
}
if (*this == *kFloat_Type) {
switch (rows) {
case 1:
switch (columns) {
- case 2: return *kVec2_Type;
- case 3: return *kVec3_Type;
- case 4: return *kVec4_Type;
+ case 2: return kVec2_Type;
+ case 3: return kVec3_Type;
+ case 4: return kVec4_Type;
default: ABORT("unsupported vector column count (%d)", columns);
}
case 2:
switch (columns) {
- case 2: return *kMat2x2_Type;
- case 3: return *kMat3x2_Type;
- case 4: return *kMat4x2_Type;
+ case 2: return kMat2x2_Type;
+ case 3: return kMat3x2_Type;
+ case 4: return kMat4x2_Type;
default: ABORT("unsupported matrix column count (%d)", columns);
}
case 3:
switch (columns) {
- case 2: return *kMat2x3_Type;
- case 3: return *kMat3x3_Type;
- case 4: return *kMat4x3_Type;
+ case 2: return kMat2x3_Type;
+ case 3: return kMat3x3_Type;
+ case 4: return kMat4x3_Type;
default: ABORT("unsupported matrix column count (%d)", columns);
}
case 4:
switch (columns) {
- case 2: return *kMat2x4_Type;
- case 3: return *kMat3x4_Type;
- case 4: return *kMat4x4_Type;
+ case 2: return kMat2x4_Type;
+ case 3: return kMat3x4_Type;
+ case 4: return kMat4x4_Type;
default: ABORT("unsupported matrix column count (%d)", columns);
}
default: ABORT("unsupported row count (%d)", rows);
@@ -77,30 +77,30 @@ const Type& Type::toCompound(int columns, int rows) const {
switch (rows) {
case 1:
switch (columns) {
- case 2: return *kDVec2_Type;
- case 3: return *kDVec3_Type;
- case 4: return *kDVec4_Type;
+ case 2: return kDVec2_Type;
+ case 3: return kDVec3_Type;
+ case 4: return kDVec4_Type;
default: ABORT("unsupported vector column count (%d)", columns);
}
case 2:
switch (columns) {
- case 2: return *kDMat2x2_Type;
- case 3: return *kDMat3x2_Type;
- case 4: return *kDMat4x2_Type;
+ case 2: return kDMat2x2_Type;
+ case 3: return kDMat3x2_Type;
+ case 4: return kDMat4x2_Type;
default: ABORT("unsupported matrix column count (%d)", columns);
}
case 3:
switch (columns) {
- case 2: return *kDMat2x3_Type;
- case 3: return *kDMat3x3_Type;
- case 4: return *kDMat4x3_Type;
+ case 2: return kDMat2x3_Type;
+ case 3: return kDMat3x3_Type;
+ case 4: return kDMat4x3_Type;
default: ABORT("unsupported matrix column count (%d)", columns);
}
case 4:
switch (columns) {
- case 2: return *kDMat2x4_Type;
- case 3: return *kDMat3x4_Type;
- case 4: return *kDMat4x4_Type;
+ case 2: return kDMat2x4_Type;
+ case 3: return kDMat3x4_Type;
+ case 4: return kDMat4x4_Type;
default: ABORT("unsupported matrix column count (%d)", columns);
}
default: ABORT("unsupported row count (%d)", rows);
@@ -109,9 +109,9 @@ const Type& Type::toCompound(int columns, int rows) const {
switch (rows) {
case 1:
switch (columns) {
- case 2: return *kIVec2_Type;
- case 3: return *kIVec3_Type;
- case 4: return *kIVec4_Type;
+ case 2: return kIVec2_Type;
+ case 3: return kIVec3_Type;
+ case 4: return kIVec4_Type;
default: ABORT("unsupported vector column count (%d)", columns);
}
default: ABORT("unsupported row count (%d)", rows);
@@ -120,9 +120,9 @@ const Type& Type::toCompound(int columns, int rows) const {
switch (rows) {
case 1:
switch (columns) {
- case 2: return *kUVec2_Type;
- case 3: return *kUVec3_Type;
- case 4: return *kUVec4_Type;
+ case 2: return kUVec2_Type;
+ case 3: return kUVec3_Type;
+ case 4: return kUVec4_Type;
default: ABORT("unsupported vector column count (%d)", columns);
}
default: ABORT("unsupported row count (%d)", rows);
@@ -131,118 +131,128 @@ const Type& Type::toCompound(int columns, int rows) const {
ABORT("unsupported scalar_to_compound type %s", this->description().c_str());
}
-const Type* kVoid_Type = new Type("void");
-
-const Type* kDouble_Type = new Type("double", true);
-const Type* kDVec2_Type = new Type("dvec2", *kDouble_Type, 2);
-const Type* kDVec3_Type = new Type("dvec3", *kDouble_Type, 3);
-const Type* kDVec4_Type = new Type("dvec4", *kDouble_Type, 4);
-
-const Type* kFloat_Type = new Type("float", true, { kDouble_Type });
-const Type* kVec2_Type = new Type("vec2", *kFloat_Type, 2);
-const Type* kVec3_Type = new Type("vec3", *kFloat_Type, 3);
-const Type* kVec4_Type = new Type("vec4", *kFloat_Type, 4);
-
-const Type* kUInt_Type = new Type("uint", true, { kFloat_Type, kDouble_Type });
-const Type* kUVec2_Type = new Type("uvec2", *kUInt_Type, 2);
-const Type* kUVec3_Type = new Type("uvec3", *kUInt_Type, 3);
-const Type* kUVec4_Type = new Type("uvec4", *kUInt_Type, 4);
-
-const Type* kInt_Type = new Type("int", true, { kUInt_Type, kFloat_Type, kDouble_Type });
-const Type* kIVec2_Type = new Type("ivec2", *kInt_Type, 2);
-const Type* kIVec3_Type = new Type("ivec3", *kInt_Type, 3);
-const Type* kIVec4_Type = new Type("ivec4", *kInt_Type, 4);
-
-const Type* kBool_Type = new Type("bool", false);
-const Type* kBVec2_Type = new Type("bvec2", *kBool_Type, 2);
-const Type* kBVec3_Type = new Type("bvec3", *kBool_Type, 3);
-const Type* kBVec4_Type = new Type("bvec4", *kBool_Type, 4);
-
-const Type* kMat2x2_Type = new Type("mat2", *kFloat_Type, 2, 2);
-const Type* kMat2x3_Type = new Type("mat2x3", *kFloat_Type, 2, 3);
-const Type* kMat2x4_Type = new Type("mat2x4", *kFloat_Type, 2, 4);
-const Type* kMat3x2_Type = new Type("mat3x2", *kFloat_Type, 3, 2);
-const Type* kMat3x3_Type = new Type("mat3", *kFloat_Type, 3, 3);
-const Type* kMat3x4_Type = new Type("mat3x4", *kFloat_Type, 3, 4);
-const Type* kMat4x2_Type = new Type("mat4x2", *kFloat_Type, 4, 2);
-const Type* kMat4x3_Type = new Type("mat4x3", *kFloat_Type, 4, 3);
-const Type* kMat4x4_Type = new Type("mat4", *kFloat_Type, 4, 4);
-
-const Type* kDMat2x2_Type = new Type("dmat2", *kFloat_Type, 2, 2);
-const Type* kDMat2x3_Type = new Type("dmat2x3", *kFloat_Type, 2, 3);
-const Type* kDMat2x4_Type = new Type("dmat2x4", *kFloat_Type, 2, 4);
-const Type* kDMat3x2_Type = new Type("dmat3x2", *kFloat_Type, 3, 2);
-const Type* kDMat3x3_Type = new Type("dmat3", *kFloat_Type, 3, 3);
-const Type* kDMat3x4_Type = new Type("dmat3x4", *kFloat_Type, 3, 4);
-const Type* kDMat4x2_Type = new Type("dmat4x2", *kFloat_Type, 4, 2);
-const Type* kDMat4x3_Type = new Type("dmat4x3", *kFloat_Type, 4, 3);
-const Type* kDMat4x4_Type = new Type("dmat4", *kFloat_Type, 4, 4);
-
-const Type* kSampler1D_Type = new Type("sampler1D", SpvDim1D, false, false, false, true);
-const Type* kSampler2D_Type = new Type("sampler2D", SpvDim2D, false, false, false, true);
-const Type* kSampler3D_Type = new Type("sampler3D", SpvDim3D, false, false, false, true);
-const Type* kSamplerCube_Type = new Type("samplerCube");
-const Type* kSampler2DRect_Type = new Type("sampler2DRect");
-const Type* kSampler1DArray_Type = new Type("sampler1DArray");
-const Type* kSampler2DArray_Type = new Type("sampler2DArray");
-const Type* kSamplerCubeArray_Type = new Type("samplerCubeArray");
-const Type* kSamplerBuffer_Type = new Type("samplerBuffer");
-const Type* kSampler2DMS_Type = new Type("sampler2DMS");
-const Type* kSampler2DMSArray_Type = new Type("sampler2DMSArray");
-const Type* kSampler1DShadow_Type = new Type("sampler1DShadow");
-const Type* kSampler2DShadow_Type = new Type("sampler2DShadow");
-const Type* kSamplerCubeShadow_Type = new Type("samplerCubeShadow");
-const Type* kSampler2DRectShadow_Type = new Type("sampler2DRectShadow");
-const Type* kSampler1DArrayShadow_Type = new Type("sampler1DArrayShadow");
-const Type* kSampler2DArrayShadow_Type = new Type("sampler2DArrayShadow");
-const Type* kSamplerCubeArrayShadow_Type = new Type("samplerCubeArrayShadow");
-
-static std::vector<const Type*> type(const Type* t) {
+const std::shared_ptr<Type> kVoid_Type(new Type("void"));
+
+const std::shared_ptr<Type> kDouble_Type(new Type("double", true));
+const std::shared_ptr<Type> kDVec2_Type(new Type("dvec2", kDouble_Type, 2));
+const std::shared_ptr<Type> kDVec3_Type(new Type("dvec3", kDouble_Type, 3));
+const std::shared_ptr<Type> kDVec4_Type(new Type("dvec4", kDouble_Type, 4));
+
+const std::shared_ptr<Type> kFloat_Type(new Type("float", true, { kDouble_Type }));
+const std::shared_ptr<Type> kVec2_Type(new Type("vec2", kFloat_Type, 2));
+const std::shared_ptr<Type> kVec3_Type(new Type("vec3", kFloat_Type, 3));
+const std::shared_ptr<Type> kVec4_Type(new Type("vec4", kFloat_Type, 4));
+
+const std::shared_ptr<Type> kUInt_Type(new Type("uint", true, { kFloat_Type, kDouble_Type }));
+const std::shared_ptr<Type> kUVec2_Type(new Type("uvec2", kUInt_Type, 2));
+const std::shared_ptr<Type> kUVec3_Type(new Type("uvec3", kUInt_Type, 3));
+const std::shared_ptr<Type> kUVec4_Type(new Type("uvec4", kUInt_Type, 4));
+
+const std::shared_ptr<Type> kInt_Type(new Type("int", true, { kUInt_Type, kFloat_Type,
+ kDouble_Type }));
+const std::shared_ptr<Type> kIVec2_Type(new Type("ivec2", kInt_Type, 2));
+const std::shared_ptr<Type> kIVec3_Type(new Type("ivec3", kInt_Type, 3));
+const std::shared_ptr<Type> kIVec4_Type(new Type("ivec4", kInt_Type, 4));
+
+const std::shared_ptr<Type> kBool_Type(new Type("bool", false));
+const std::shared_ptr<Type> kBVec2_Type(new Type("bvec2", kBool_Type, 2));
+const std::shared_ptr<Type> kBVec3_Type(new Type("bvec3", kBool_Type, 3));
+const std::shared_ptr<Type> kBVec4_Type(new Type("bvec4", kBool_Type, 4));
+
+const std::shared_ptr<Type> kMat2x2_Type(new Type("mat2", kFloat_Type, 2, 2));
+const std::shared_ptr<Type> kMat2x3_Type(new Type("mat2x3", kFloat_Type, 2, 3));
+const std::shared_ptr<Type> kMat2x4_Type(new Type("mat2x4", kFloat_Type, 2, 4));
+const std::shared_ptr<Type> kMat3x2_Type(new Type("mat3x2", kFloat_Type, 3, 2));
+const std::shared_ptr<Type> kMat3x3_Type(new Type("mat3", kFloat_Type, 3, 3));
+const std::shared_ptr<Type> kMat3x4_Type(new Type("mat3x4", kFloat_Type, 3, 4));
+const std::shared_ptr<Type> kMat4x2_Type(new Type("mat4x2", kFloat_Type, 4, 2));
+const std::shared_ptr<Type> kMat4x3_Type(new Type("mat4x3", kFloat_Type, 4, 3));
+const std::shared_ptr<Type> kMat4x4_Type(new Type("mat4", kFloat_Type, 4, 4));
+
+const std::shared_ptr<Type> kDMat2x2_Type(new Type("dmat2", kFloat_Type, 2, 2));
+const std::shared_ptr<Type> kDMat2x3_Type(new Type("dmat2x3", kFloat_Type, 2, 3));
+const std::shared_ptr<Type> kDMat2x4_Type(new Type("dmat2x4", kFloat_Type, 2, 4));
+const std::shared_ptr<Type> kDMat3x2_Type(new Type("dmat3x2", kFloat_Type, 3, 2));
+const std::shared_ptr<Type> kDMat3x3_Type(new Type("dmat3", kFloat_Type, 3, 3));
+const std::shared_ptr<Type> kDMat3x4_Type(new Type("dmat3x4", kFloat_Type, 3, 4));
+const std::shared_ptr<Type> kDMat4x2_Type(new Type("dmat4x2", kFloat_Type, 4, 2));
+const std::shared_ptr<Type> kDMat4x3_Type(new Type("dmat4x3", kFloat_Type, 4, 3));
+const std::shared_ptr<Type> kDMat4x4_Type(new Type("dmat4", kFloat_Type, 4, 4));
+
+const std::shared_ptr<Type> kSampler1D_Type(new Type("sampler1D", SpvDim1D, false, false, false, true));
+const std::shared_ptr<Type> kSampler2D_Type(new Type("sampler2D", SpvDim2D, false, false, false, true));
+const std::shared_ptr<Type> kSampler3D_Type(new Type("sampler3D", SpvDim3D, false, false, false, true));
+const std::shared_ptr<Type> kSamplerCube_Type(new Type("samplerCube"));
+const std::shared_ptr<Type> kSampler2DRect_Type(new Type("sampler2DRect"));
+const std::shared_ptr<Type> kSampler1DArray_Type(new Type("sampler1DArray"));
+const std::shared_ptr<Type> kSampler2DArray_Type(new Type("sampler2DArray"));
+const std::shared_ptr<Type> kSamplerCubeArray_Type(new Type("samplerCubeArray"));
+const std::shared_ptr<Type> kSamplerBuffer_Type(new Type("samplerBuffer"));
+const std::shared_ptr<Type> kSampler2DMS_Type(new Type("sampler2DMS"));
+const std::shared_ptr<Type> kSampler2DMSArray_Type(new Type("sampler2DMSArray"));
+const std::shared_ptr<Type> kSampler1DShadow_Type(new Type("sampler1DShadow"));
+const std::shared_ptr<Type> kSampler2DShadow_Type(new Type("sampler2DShadow"));
+const std::shared_ptr<Type> kSamplerCubeShadow_Type(new Type("samplerCubeShadow"));
+const std::shared_ptr<Type> kSampler2DRectShadow_Type(new Type("sampler2DRectShadow"));
+const std::shared_ptr<Type> kSampler1DArrayShadow_Type(new Type("sampler1DArrayShadow"));
+const std::shared_ptr<Type> kSampler2DArrayShadow_Type(new Type("sampler2DArrayShadow"));
+const std::shared_ptr<Type> kSamplerCubeArrayShadow_Type(new Type("samplerCubeArrayShadow"));
+
+static std::vector<std::shared_ptr<Type>> type(std::shared_ptr<Type> t) {
return { t, t, t, t };
}
// FIXME figure out what we're supposed to do with the gsampler et al. types
-const Type* kGSampler1D_Type = new Type("$gsampler1D", type(kSampler1D_Type));
-const Type* kGSampler2D_Type = new Type("$gsampler2D", type(kSampler2D_Type));
-const Type* kGSampler3D_Type = new Type("$gsampler3D", type(kSampler3D_Type));
-const Type* kGSamplerCube_Type = new Type("$gsamplerCube", type(kSamplerCube_Type));
-const Type* kGSampler2DRect_Type = new Type("$gsampler2DRect", type(kSampler2DRect_Type));
-const Type* kGSampler1DArray_Type = new Type("$gsampler1DArray", type(kSampler1DArray_Type));
-const Type* kGSampler2DArray_Type = new Type("$gsampler2DArray", type(kSampler2DArray_Type));
-const Type* kGSamplerCubeArray_Type = new Type("$gsamplerCubeArray", type(kSamplerCubeArray_Type));
-const Type* kGSamplerBuffer_Type = new Type("$gsamplerBuffer", type(kSamplerBuffer_Type));
-const Type* kGSampler2DMS_Type = new Type("$gsampler2DMS", type(kSampler2DMS_Type));
-const Type* kGSampler2DMSArray_Type = new Type("$gsampler2DMSArray", type(kSampler2DMSArray_Type));
-const Type* kGSampler2DArrayShadow_Type = new Type("$gsampler2DArrayShadow",
- type(kSampler2DArrayShadow_Type));
-const Type* kGSamplerCubeArrayShadow_Type = new Type("$gsamplerCubeArrayShadow",
- type(kSamplerCubeArrayShadow_Type));
-
-const Type* kGenType_Type = new Type("$genType", { kFloat_Type, kVec2_Type, kVec3_Type,
- kVec4_Type });
-const Type* kGenDType_Type = new Type("$genDType", { kDouble_Type, kDVec2_Type, kDVec3_Type,
- kDVec4_Type });
-const Type* kGenIType_Type = new Type("$genIType", { kInt_Type, kIVec2_Type, kIVec3_Type,
- kIVec4_Type });
-const Type* kGenUType_Type = new Type("$genUType", { kUInt_Type, kUVec2_Type, kUVec3_Type,
- kUVec4_Type });
-const Type* kGenBType_Type = new Type("$genBType", { kBool_Type, kBVec2_Type, kBVec3_Type,
- kBVec4_Type });
-
-const Type* kMat_Type = new Type("$mat");
-
-const Type* kVec_Type = new Type("$vec", { kVec2_Type, kVec2_Type, kVec3_Type, kVec4_Type });
-
-const Type* kGVec_Type = new Type("$gvec");
-const Type* kGVec2_Type = new Type("$gvec2");
-const Type* kGVec3_Type = new Type("$gvec3");
-const Type* kGVec4_Type = new Type("$gvec4", type(kVec4_Type));
-const Type* kDVec_Type = new Type("$dvec");
-const Type* kIVec_Type = new Type("$ivec");
-const Type* kUVec_Type = new Type("$uvec");
-
-const Type* kBVec_Type = new Type("$bvec", { kBVec2_Type, kBVec2_Type, kBVec3_Type, kBVec4_Type });
-
-const Type* kInvalid_Type = new Type("<INVALID>");
+const std::shared_ptr<Type> kGSampler1D_Type(new Type("$gsampler1D", type(kSampler1D_Type)));
+const std::shared_ptr<Type> kGSampler2D_Type(new Type("$gsampler2D", type(kSampler2D_Type)));
+const std::shared_ptr<Type> kGSampler3D_Type(new Type("$gsampler3D", type(kSampler3D_Type)));
+const std::shared_ptr<Type> kGSamplerCube_Type(new Type("$gsamplerCube", type(kSamplerCube_Type)));
+const std::shared_ptr<Type> kGSampler2DRect_Type(new Type("$gsampler2DRect",
+ type(kSampler2DRect_Type)));
+const std::shared_ptr<Type> kGSampler1DArray_Type(new Type("$gsampler1DArray",
+ type(kSampler1DArray_Type)));
+const std::shared_ptr<Type> kGSampler2DArray_Type(new Type("$gsampler2DArray",
+ type(kSampler2DArray_Type)));
+const std::shared_ptr<Type> kGSamplerCubeArray_Type(new Type("$gsamplerCubeArray",
+ type(kSamplerCubeArray_Type)));
+const std::shared_ptr<Type> kGSamplerBuffer_Type(new Type("$gsamplerBuffer",
+ type(kSamplerBuffer_Type)));
+const std::shared_ptr<Type> kGSampler2DMS_Type(new Type("$gsampler2DMS",
+ type(kSampler2DMS_Type)));
+const std::shared_ptr<Type> kGSampler2DMSArray_Type(new Type("$gsampler2DMSArray",
+ type(kSampler2DMSArray_Type)));
+const std::shared_ptr<Type> kGSampler2DArrayShadow_Type(new Type("$gsampler2DArrayShadow",
+ type(kSampler2DArrayShadow_Type)));
+const std::shared_ptr<Type> kGSamplerCubeArrayShadow_Type(new Type("$gsamplerCubeArrayShadow",
+ type(kSamplerCubeArrayShadow_Type)));
+
+const std::shared_ptr<Type> kGenType_Type(new Type("$genType", { kFloat_Type, kVec2_Type,
+ kVec3_Type, kVec4_Type }));
+const std::shared_ptr<Type> kGenDType_Type(new Type("$genDType", { kDouble_Type, kDVec2_Type,
+ kDVec3_Type, kDVec4_Type }));
+const std::shared_ptr<Type> kGenIType_Type(new Type("$genIType", { kInt_Type, kIVec2_Type,
+ kIVec3_Type, kIVec4_Type }));
+const std::shared_ptr<Type> kGenUType_Type(new Type("$genUType", { kUInt_Type, kUVec2_Type,
+ kUVec3_Type, kUVec4_Type }));
+const std::shared_ptr<Type> kGenBType_Type(new Type("$genBType", { kBool_Type, kBVec2_Type,
+ kBVec3_Type, kBVec4_Type }));
+
+const std::shared_ptr<Type> kMat_Type(new Type("$mat"));
+
+const std::shared_ptr<Type> kVec_Type(new Type("$vec", { kVec2_Type, kVec2_Type, kVec3_Type,
+ kVec4_Type }));
+
+const std::shared_ptr<Type> kGVec_Type(new Type("$gvec"));
+const std::shared_ptr<Type> kGVec2_Type(new Type("$gvec2"));
+const std::shared_ptr<Type> kGVec3_Type(new Type("$gvec3"));
+const std::shared_ptr<Type> kGVec4_Type(new Type("$gvec4", type(kVec4_Type)));
+const std::shared_ptr<Type> kDVec_Type(new Type("$dvec"));
+const std::shared_ptr<Type> kIVec_Type(new Type("$ivec"));
+const std::shared_ptr<Type> kUVec_Type(new Type("$uvec"));
+
+const std::shared_ptr<Type> kBVec_Type(new Type("$bvec", { kBVec2_Type, kBVec2_Type,
+ kBVec3_Type, kBVec4_Type }));
+
+const std::shared_ptr<Type> kInvalid_Type(new Type("<INVALID>"));
} // namespace
diff --git a/src/sksl/ir/SkSLType.h b/src/sksl/ir/SkSLType.h
index 8a73b139ba..e17bae68db 100644
--- a/src/sksl/ir/SkSLType.h
+++ b/src/sksl/ir/SkSLType.h
@@ -24,18 +24,18 @@ namespace SkSL {
class Type : public Symbol {
public:
struct Field {
- Field(Modifiers modifiers, std::string name, const Type& type)
+ Field(Modifiers modifiers, std::string name, std::shared_ptr<Type> type)
: fModifiers(modifiers)
, fName(std::move(name))
, fType(std::move(type)) {}
- const std::string description() const {
- return fType.description() + " " + fName + ";";
+ const std::string description() {
+ return fType->description() + " " + fName + ";";
}
const Modifiers fModifiers;
const std::string fName;
- const Type& fType;
+ const std::shared_ptr<Type> fType;
};
enum Kind {
@@ -56,7 +56,7 @@ public:
, fTypeKind(kOther_Kind) {}
// Create a generic type which maps to the listed types.
- Type(std::string name, std::vector<const Type*> types)
+ Type(std::string name, std::vector<std::shared_ptr<Type>> types)
: INHERITED(Position(), kType_Kind, std::move(name))
, fTypeKind(kGeneric_Kind)
, fCoercibleTypes(std::move(types)) {
@@ -78,7 +78,7 @@ public:
, fRows(1) {}
// Create a scalar type which can be coerced to the listed types.
- Type(std::string name, bool isNumber, std::vector<const Type*> coercibleTypes)
+ Type(std::string name, bool isNumber, std::vector<std::shared_ptr<Type>> coercibleTypes)
: INHERITED(Position(), kType_Kind, std::move(name))
, fTypeKind(kScalar_Kind)
, fIsNumber(isNumber)
@@ -87,23 +87,23 @@ public:
, fRows(1) {}
// Create a vector type.
- Type(std::string name, const Type& componentType, int columns)
+ Type(std::string name, std::shared_ptr<Type> componentType, int columns)
: Type(name, kVector_Kind, componentType, columns) {}
// Create a vector or array type.
- Type(std::string name, Kind kind, const Type& componentType, int columns)
+ Type(std::string name, Kind kind, std::shared_ptr<Type> componentType, int columns)
: INHERITED(Position(), kType_Kind, std::move(name))
, fTypeKind(kind)
- , fComponentType(&componentType)
+ , fComponentType(std::move(componentType))
, fColumns(columns)
, fRows(1)
, fDimensions(SpvDim1D) {}
// Create a matrix type.
- Type(std::string name, const Type& componentType, int columns, int rows)
+ Type(std::string name, std::shared_ptr<Type> componentType, int columns, int rows)
: INHERITED(Position(), kType_Kind, std::move(name))
, fTypeKind(kMatrix_Kind)
- , fComponentType(&componentType)
+ , fComponentType(std::move(componentType))
, fColumns(columns)
, fRows(rows)
, fDimensions(SpvDim1D) {}
@@ -153,7 +153,7 @@ public:
* Returns true if an instance of this type can be freely coerced (implicitly converted) to
* another type.
*/
- bool canCoerceTo(const Type& other) const {
+ bool canCoerceTo(std::shared_ptr<Type> other) const {
int cost;
return determineCoercionCost(other, &cost);
}
@@ -164,15 +164,15 @@ public:
* costs. Returns true if a conversion is possible, false otherwise. The value of the out
* parameter is undefined if false is returned.
*/
- bool determineCoercionCost(const Type& other, int* outCost) const;
+ bool determineCoercionCost(std::shared_ptr<Type> other, int* outCost) const;
/**
* For matrices and vectors, returns the type of individual cells (e.g. mat2 has a component
* type of kFloat_Type). For all other types, causes an assertion failure.
*/
- const Type& componentType() const {
+ std::shared_ptr<Type> componentType() const {
ASSERT(fComponentType);
- return *fComponentType;
+ return fComponentType;
}
/**
@@ -195,7 +195,7 @@ public:
return fRows;
}
- const std::vector<Field>& fields() const {
+ std::vector<Field> fields() const {
ASSERT(fTypeKind == kStruct_Kind);
return fFields;
}
@@ -204,7 +204,7 @@ public:
* For generic types, returns the types that this generic type can substitute for. For other
* types, returns a list of other types that this type can be coerced into.
*/
- const std::vector<const Type*>& coercibleTypes() const {
+ std::vector<std::shared_ptr<Type>> coercibleTypes() const {
ASSERT(fCoercibleTypes.size() > 0);
return fCoercibleTypes;
}
@@ -257,7 +257,7 @@ public:
case kStruct_Kind: {
size_t result = 16;
for (size_t i = 0; i < fFields.size(); i++) {
- size_t alignment = fFields[i].fType.alignment();
+ size_t alignment = fFields[i].fType->alignment();
if (alignment > result) {
result = alignment;
}
@@ -300,13 +300,13 @@ public:
case kStruct_Kind: {
size_t total = 0;
for (size_t i = 0; i < fFields.size(); i++) {
- size_t alignment = fFields[i].fType.alignment();
+ size_t alignment = fFields[i].fType->alignment();
if (total % alignment != 0) {
total += alignment - total % alignment;
}
ASSERT(false);
ASSERT(total % alignment == 0);
- total += fFields[i].fType.size();
+ total += fFields[i].fType->size();
}
return total;
}
@@ -319,15 +319,15 @@ public:
* Returns the corresponding vector or matrix type with the specified number of columns and
* rows.
*/
- const Type& toCompound(int columns, int rows) const;
+ std::shared_ptr<Type> toCompound(int columns, int rows);
private:
typedef Symbol INHERITED;
const Kind fTypeKind;
const bool fIsNumber = false;
- const Type* fComponentType = nullptr;
- const std::vector<const Type*> fCoercibleTypes = { };
+ const std::shared_ptr<Type> fComponentType = nullptr;
+ const std::vector<std::shared_ptr<Type>> fCoercibleTypes = { };
const int fColumns = -1;
const int fRows = -1;
const std::vector<Field> fFields = { };
@@ -338,100 +338,100 @@ private:
const bool fIsSampled = false;
};
-extern const Type* kVoid_Type;
-
-extern const Type* kFloat_Type;
-extern const Type* kVec2_Type;
-extern const Type* kVec3_Type;
-extern const Type* kVec4_Type;
-extern const Type* kDouble_Type;
-extern const Type* kDVec2_Type;
-extern const Type* kDVec3_Type;
-extern const Type* kDVec4_Type;
-extern const Type* kInt_Type;
-extern const Type* kIVec2_Type;
-extern const Type* kIVec3_Type;
-extern const Type* kIVec4_Type;
-extern const Type* kUInt_Type;
-extern const Type* kUVec2_Type;
-extern const Type* kUVec3_Type;
-extern const Type* kUVec4_Type;
-extern const Type* kBool_Type;
-extern const Type* kBVec2_Type;
-extern const Type* kBVec3_Type;
-extern const Type* kBVec4_Type;
-
-extern const Type* kMat2x2_Type;
-extern const Type* kMat2x3_Type;
-extern const Type* kMat2x4_Type;
-extern const Type* kMat3x2_Type;
-extern const Type* kMat3x3_Type;
-extern const Type* kMat3x4_Type;
-extern const Type* kMat4x2_Type;
-extern const Type* kMat4x3_Type;
-extern const Type* kMat4x4_Type;
-
-extern const Type* kDMat2x2_Type;
-extern const Type* kDMat2x3_Type;
-extern const Type* kDMat2x4_Type;
-extern const Type* kDMat3x2_Type;
-extern const Type* kDMat3x3_Type;
-extern const Type* kDMat3x4_Type;
-extern const Type* kDMat4x2_Type;
-extern const Type* kDMat4x3_Type;
-extern const Type* kDMat4x4_Type;
-
-extern const Type* kSampler1D_Type;
-extern const Type* kSampler2D_Type;
-extern const Type* kSampler3D_Type;
-extern const Type* kSamplerCube_Type;
-extern const Type* kSampler2DRect_Type;
-extern const Type* kSampler1DArray_Type;
-extern const Type* kSampler2DArray_Type;
-extern const Type* kSamplerCubeArray_Type;
-extern const Type* kSamplerBuffer_Type;
-extern const Type* kSampler2DMS_Type;
-extern const Type* kSampler2DMSArray_Type;
-
-extern const Type* kGSampler1D_Type;
-extern const Type* kGSampler2D_Type;
-extern const Type* kGSampler3D_Type;
-extern const Type* kGSamplerCube_Type;
-extern const Type* kGSampler2DRect_Type;
-extern const Type* kGSampler1DArray_Type;
-extern const Type* kGSampler2DArray_Type;
-extern const Type* kGSamplerCubeArray_Type;
-extern const Type* kGSamplerBuffer_Type;
-extern const Type* kGSampler2DMS_Type;
-extern const Type* kGSampler2DMSArray_Type;
-
-extern const Type* kSampler1DShadow_Type;
-extern const Type* kSampler2DShadow_Type;
-extern const Type* kSamplerCubeShadow_Type;
-extern const Type* kSampler2DRectShadow_Type;
-extern const Type* kSampler1DArrayShadow_Type;
-extern const Type* kSampler2DArrayShadow_Type;
-extern const Type* kSamplerCubeArrayShadow_Type;
-extern const Type* kGSampler2DArrayShadow_Type;
-extern const Type* kGSamplerCubeArrayShadow_Type;
-
-extern const Type* kGenType_Type;
-extern const Type* kGenDType_Type;
-extern const Type* kGenIType_Type;
-extern const Type* kGenUType_Type;
-extern const Type* kGenBType_Type;
-extern const Type* kMat_Type;
-extern const Type* kVec_Type;
-extern const Type* kGVec_Type;
-extern const Type* kGVec2_Type;
-extern const Type* kGVec3_Type;
-extern const Type* kGVec4_Type;
-extern const Type* kDVec_Type;
-extern const Type* kIVec_Type;
-extern const Type* kUVec_Type;
-extern const Type* kBVec_Type;
-
-extern const Type* kInvalid_Type;
+extern const std::shared_ptr<Type> kVoid_Type;
+
+extern const std::shared_ptr<Type> kFloat_Type;
+extern const std::shared_ptr<Type> kVec2_Type;
+extern const std::shared_ptr<Type> kVec3_Type;
+extern const std::shared_ptr<Type> kVec4_Type;
+extern const std::shared_ptr<Type> kDouble_Type;
+extern const std::shared_ptr<Type> kDVec2_Type;
+extern const std::shared_ptr<Type> kDVec3_Type;
+extern const std::shared_ptr<Type> kDVec4_Type;
+extern const std::shared_ptr<Type> kInt_Type;
+extern const std::shared_ptr<Type> kIVec2_Type;
+extern const std::shared_ptr<Type> kIVec3_Type;
+extern const std::shared_ptr<Type> kIVec4_Type;
+extern const std::shared_ptr<Type> kUInt_Type;
+extern const std::shared_ptr<Type> kUVec2_Type;
+extern const std::shared_ptr<Type> kUVec3_Type;
+extern const std::shared_ptr<Type> kUVec4_Type;
+extern const std::shared_ptr<Type> kBool_Type;
+extern const std::shared_ptr<Type> kBVec2_Type;
+extern const std::shared_ptr<Type> kBVec3_Type;
+extern const std::shared_ptr<Type> kBVec4_Type;
+
+extern const std::shared_ptr<Type> kMat2x2_Type;
+extern const std::shared_ptr<Type> kMat2x3_Type;
+extern const std::shared_ptr<Type> kMat2x4_Type;
+extern const std::shared_ptr<Type> kMat3x2_Type;
+extern const std::shared_ptr<Type> kMat3x3_Type;
+extern const std::shared_ptr<Type> kMat3x4_Type;
+extern const std::shared_ptr<Type> kMat4x2_Type;
+extern const std::shared_ptr<Type> kMat4x3_Type;
+extern const std::shared_ptr<Type> kMat4x4_Type;
+
+extern const std::shared_ptr<Type> kDMat2x2_Type;
+extern const std::shared_ptr<Type> kDMat2x3_Type;
+extern const std::shared_ptr<Type> kDMat2x4_Type;
+extern const std::shared_ptr<Type> kDMat3x2_Type;
+extern const std::shared_ptr<Type> kDMat3x3_Type;
+extern const std::shared_ptr<Type> kDMat3x4_Type;
+extern const std::shared_ptr<Type> kDMat4x2_Type;
+extern const std::shared_ptr<Type> kDMat4x3_Type;
+extern const std::shared_ptr<Type> kDMat4x4_Type;
+
+extern const std::shared_ptr<Type> kSampler1D_Type;
+extern const std::shared_ptr<Type> kSampler2D_Type;
+extern const std::shared_ptr<Type> kSampler3D_Type;
+extern const std::shared_ptr<Type> kSamplerCube_Type;
+extern const std::shared_ptr<Type> kSampler2DRect_Type;
+extern const std::shared_ptr<Type> kSampler1DArray_Type;
+extern const std::shared_ptr<Type> kSampler2DArray_Type;
+extern const std::shared_ptr<Type> kSamplerCubeArray_Type;
+extern const std::shared_ptr<Type> kSamplerBuffer_Type;
+extern const std::shared_ptr<Type> kSampler2DMS_Type;
+extern const std::shared_ptr<Type> kSampler2DMSArray_Type;
+
+extern const std::shared_ptr<Type> kGSampler1D_Type;
+extern const std::shared_ptr<Type> kGSampler2D_Type;
+extern const std::shared_ptr<Type> kGSampler3D_Type;
+extern const std::shared_ptr<Type> kGSamplerCube_Type;
+extern const std::shared_ptr<Type> kGSampler2DRect_Type;
+extern const std::shared_ptr<Type> kGSampler1DArray_Type;
+extern const std::shared_ptr<Type> kGSampler2DArray_Type;
+extern const std::shared_ptr<Type> kGSamplerCubeArray_Type;
+extern const std::shared_ptr<Type> kGSamplerBuffer_Type;
+extern const std::shared_ptr<Type> kGSampler2DMS_Type;
+extern const std::shared_ptr<Type> kGSampler2DMSArray_Type;
+
+extern const std::shared_ptr<Type> kSampler1DShadow_Type;
+extern const std::shared_ptr<Type> kSampler2DShadow_Type;
+extern const std::shared_ptr<Type> kSamplerCubeShadow_Type;
+extern const std::shared_ptr<Type> kSampler2DRectShadow_Type;
+extern const std::shared_ptr<Type> kSampler1DArrayShadow_Type;
+extern const std::shared_ptr<Type> kSampler2DArrayShadow_Type;
+extern const std::shared_ptr<Type> kSamplerCubeArrayShadow_Type;
+extern const std::shared_ptr<Type> kGSampler2DArrayShadow_Type;
+extern const std::shared_ptr<Type> kGSamplerCubeArrayShadow_Type;
+
+extern const std::shared_ptr<Type> kGenType_Type;
+extern const std::shared_ptr<Type> kGenDType_Type;
+extern const std::shared_ptr<Type> kGenIType_Type;
+extern const std::shared_ptr<Type> kGenUType_Type;
+extern const std::shared_ptr<Type> kGenBType_Type;
+extern const std::shared_ptr<Type> kMat_Type;
+extern const std::shared_ptr<Type> kVec_Type;
+extern const std::shared_ptr<Type> kGVec_Type;
+extern const std::shared_ptr<Type> kGVec2_Type;
+extern const std::shared_ptr<Type> kGVec3_Type;
+extern const std::shared_ptr<Type> kGVec4_Type;
+extern const std::shared_ptr<Type> kDVec_Type;
+extern const std::shared_ptr<Type> kIVec_Type;
+extern const std::shared_ptr<Type> kUVec_Type;
+extern const std::shared_ptr<Type> kBVec_Type;
+
+extern const std::shared_ptr<Type> kInvalid_Type;
} // namespace
diff --git a/src/sksl/ir/SkSLTypeReference.h b/src/sksl/ir/SkSLTypeReference.h
index 8f2ab4fe0e..5f4990f35d 100644
--- a/src/sksl/ir/SkSLTypeReference.h
+++ b/src/sksl/ir/SkSLTypeReference.h
@@ -17,16 +17,16 @@ namespace SkSL {
* always eventually replaced by Constructors in valid programs.
*/
struct TypeReference : public Expression {
- TypeReference(Position position, const Type& type)
- : INHERITED(position, kTypeReference_Kind, *kInvalid_Type)
- , fValue(type) {}
+ TypeReference(Position position, std::shared_ptr<Type> type)
+ : INHERITED(position, kTypeReference_Kind, kInvalid_Type)
+ , fValue(std::move(type)) {}
std::string description() const override {
ASSERT(false);
return "<type>";
}
- const Type& fValue;
+ const std::shared_ptr<Type> fValue;
typedef Expression INHERITED;
};
diff --git a/src/sksl/ir/SkSLUnresolvedFunction.h b/src/sksl/ir/SkSLUnresolvedFunction.h
index 3a368ad8d3..a6cee0d072 100644
--- a/src/sksl/ir/SkSLUnresolvedFunction.h
+++ b/src/sksl/ir/SkSLUnresolvedFunction.h
@@ -16,21 +16,19 @@ namespace SkSL {
* A symbol representing multiple functions with the same name.
*/
struct UnresolvedFunction : public Symbol {
- UnresolvedFunction(std::vector<const FunctionDeclaration*> funcs)
+ UnresolvedFunction(std::vector<std::shared_ptr<FunctionDeclaration>> funcs)
: INHERITED(Position(), kUnresolvedFunction_Kind, funcs[0]->fName)
, fFunctions(std::move(funcs)) {
-#ifdef DEBUG
for (auto func : funcs) {
ASSERT(func->fName == fName);
}
-#endif
}
virtual std::string description() const override {
return fName;
}
- const std::vector<const FunctionDeclaration*> fFunctions;
+ const std::vector<std::shared_ptr<FunctionDeclaration>> fFunctions;
typedef Symbol INHERITED;
};
diff --git a/src/sksl/ir/SkSLVarDeclaration.h b/src/sksl/ir/SkSLVarDeclaration.h
index b234231b86..400f430e4c 100644
--- a/src/sksl/ir/SkSLVarDeclaration.h
+++ b/src/sksl/ir/SkSLVarDeclaration.h
@@ -20,7 +20,7 @@ namespace SkSL {
* names ['x', 'y', 'z'], sizes of [[], [], [4, 2]], and values of [null, 1, null].
*/
struct VarDeclaration : public ProgramElement {
- VarDeclaration(Position position, std::vector<const Variable*> vars,
+ VarDeclaration(Position position, std::vector<std::shared_ptr<Variable>> vars,
std::vector<std::vector<std::unique_ptr<Expression>>> sizes,
std::vector<std::unique_ptr<Expression>> values)
: INHERITED(position, kVar_Kind)
@@ -30,9 +30,9 @@ struct VarDeclaration : public ProgramElement {
std::string description() const override {
std::string result = fVars[0]->fModifiers.description();
- const Type* baseType = &fVars[0]->fType;
+ std::shared_ptr<Type> baseType = fVars[0]->fType;
while (baseType->kind() == Type::kArray_Kind) {
- baseType = &baseType->componentType();
+ baseType = baseType->componentType();
}
result += baseType->description();
std::string separator = " ";
@@ -55,7 +55,7 @@ struct VarDeclaration : public ProgramElement {
return result;
}
- const std::vector<const Variable*> fVars;
+ const std::vector<std::shared_ptr<Variable>> fVars;
const std::vector<std::vector<std::unique_ptr<Expression>>> fSizes;
const std::vector<std::unique_ptr<Expression>> fValues;
diff --git a/src/sksl/ir/SkSLVariable.h b/src/sksl/ir/SkSLVariable.h
index 39af3093b6..d4ea2c4a43 100644
--- a/src/sksl/ir/SkSLVariable.h
+++ b/src/sksl/ir/SkSLVariable.h
@@ -27,7 +27,7 @@ struct Variable : public Symbol {
kParameter_Storage
};
- Variable(Position position, Modifiers modifiers, std::string name, const Type& type,
+ Variable(Position position, Modifiers modifiers, std::string name, std::shared_ptr<Type> type,
Storage storage)
: INHERITED(position, kVariable_Kind, std::move(name))
, fModifiers(modifiers)
@@ -37,11 +37,12 @@ struct Variable : public Symbol {
, fIsWrittenTo(false) {}
virtual std::string description() const override {
- return fModifiers.description() + fType.fName + " " + fName;
+ return fModifiers.description() + fType->fName + " " + fName;
}
const Modifiers fModifiers;
- const Type& fType;
+ const std::string fValue;
+ const std::shared_ptr<Type> fType;
const Storage fStorage;
mutable bool fIsReadFrom;
@@ -52,4 +53,14 @@ struct Variable : public Symbol {
} // namespace SkSL
+namespace std {
+ template <>
+ struct hash<SkSL::Variable> {
+ public :
+ size_t operator()(const SkSL::Variable &var) const{
+ return hash<std::string>()(var.fName) ^ hash<std::string>()(var.fType->description());
+ }
+ };
+} // namespace std
+
#endif
diff --git a/src/sksl/ir/SkSLVariableReference.h b/src/sksl/ir/SkSLVariableReference.h
index b443da1f22..8499511a1b 100644
--- a/src/sksl/ir/SkSLVariableReference.h
+++ b/src/sksl/ir/SkSLVariableReference.h
@@ -20,15 +20,15 @@ namespace SkSL {
* there is only one Variable 'x', but two VariableReferences to it.
*/
struct VariableReference : public Expression {
- VariableReference(Position position, const Variable& variable)
- : INHERITED(position, kVariableReference_Kind, variable.fType)
- , fVariable(variable) {}
+ VariableReference(Position position, std::shared_ptr<Variable> variable)
+ : INHERITED(position, kVariableReference_Kind, variable->fType)
+ , fVariable(std::move(variable)) {}
std::string description() const override {
- return fVariable.fName;
+ return fVariable->fName;
}
- const Variable& fVariable;
+ const std::shared_ptr<Variable> fVariable;
typedef Expression INHERITED;
};