2016-07-01 15:22:01 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2017-03-31 17:56:23 +00:00
|
|
|
|
2016-07-01 15:22:01 +00:00
|
|
|
#ifndef SKSL_IRNODE
|
|
|
|
#define SKSL_IRNODE
|
|
|
|
|
2020-09-22 19:05:37 +00:00
|
|
|
#include "src/sksl/SkSLASTNode.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/sksl/SkSLLexer.h"
|
2020-10-07 20:42:04 +00:00
|
|
|
#include "src/sksl/SkSLModifiersPool.h"
|
2019-05-15 19:29:54 +00:00
|
|
|
#include "src/sksl/SkSLString.h"
|
2016-07-01 15:22:01 +00:00
|
|
|
|
2020-09-25 18:31:59 +00:00
|
|
|
#include <algorithm>
|
2020-09-22 19:05:37 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2016-07-01 15:22:01 +00:00
|
|
|
namespace SkSL {
|
|
|
|
|
2020-10-08 09:28:32 +00:00
|
|
|
class Expression;
|
2020-09-30 18:29:56 +00:00
|
|
|
class ExternalValue;
|
2020-10-08 15:45:44 +00:00
|
|
|
class FunctionDeclaration;
|
|
|
|
struct FunctionDefinition;
|
2020-10-08 09:28:32 +00:00
|
|
|
class Statement;
|
2020-10-06 20:14:37 +00:00
|
|
|
class Symbol;
|
2020-09-25 18:31:59 +00:00
|
|
|
class SymbolTable;
|
2020-09-11 16:27:26 +00:00
|
|
|
class Type;
|
2020-10-07 20:42:04 +00:00
|
|
|
class Variable;
|
2020-10-08 10:46:27 +00:00
|
|
|
class VariableReference;
|
2020-09-11 16:27:26 +00:00
|
|
|
|
2016-07-01 15:22:01 +00:00
|
|
|
/**
|
2017-03-31 17:56:23 +00:00
|
|
|
* Represents a node in the intermediate representation (IR) tree. The IR is a fully-resolved
|
2016-07-01 15:22:01 +00:00
|
|
|
* version of the program (all types determined, everything validated), ready for code generation.
|
|
|
|
*/
|
2020-09-11 16:27:26 +00:00
|
|
|
class IRNode {
|
|
|
|
public:
|
2020-09-22 19:05:37 +00:00
|
|
|
virtual ~IRNode();
|
2020-03-31 22:31:46 +00:00
|
|
|
|
2020-09-22 19:05:37 +00:00
|
|
|
IRNode& operator=(const IRNode& other) {
|
|
|
|
// Need to have a copy assignment operator because Type requires it, but can't use the
|
|
|
|
// default version until we finish migrating away from std::unique_ptr children. For now,
|
|
|
|
// just assert that there are no children (we could theoretically clone them, but we never
|
|
|
|
// actually copy nodes containing children).
|
|
|
|
SkASSERT(other.fExpressionChildren.empty());
|
|
|
|
fKind = other.fKind;
|
|
|
|
fOffset = other.fOffset;
|
|
|
|
fData = other.fData;
|
|
|
|
return *this;
|
|
|
|
}
|
2016-07-01 15:22:01 +00:00
|
|
|
|
2017-03-31 17:56:23 +00:00
|
|
|
virtual String description() const = 0;
|
2016-07-01 15:22:01 +00:00
|
|
|
|
2017-09-11 20:50:14 +00:00
|
|
|
// character offset of this element within the program being compiled, for error reporting
|
|
|
|
// purposes
|
2017-09-18 18:10:39 +00:00
|
|
|
int fOffset;
|
2020-09-08 14:22:09 +00:00
|
|
|
|
|
|
|
protected:
|
2020-09-25 18:31:59 +00:00
|
|
|
struct BlockData {
|
|
|
|
std::shared_ptr<SymbolTable> fSymbolTable;
|
|
|
|
// if isScope is false, this is just a group of statements rather than an actual
|
|
|
|
// language-level block. This allows us to pass around multiple statements as if they were a
|
|
|
|
// single unit, with no semantic impact.
|
|
|
|
bool fIsScope;
|
|
|
|
};
|
|
|
|
|
2020-09-28 13:18:15 +00:00
|
|
|
struct BoolLiteralData {
|
|
|
|
const Type* fType;
|
|
|
|
bool fValue;
|
|
|
|
};
|
|
|
|
|
2020-09-29 21:05:54 +00:00
|
|
|
struct EnumData {
|
|
|
|
StringFragment fTypeName;
|
|
|
|
std::shared_ptr<SymbolTable> fSymbols;
|
|
|
|
bool fIsBuiltin;
|
|
|
|
};
|
|
|
|
|
2020-09-30 18:29:56 +00:00
|
|
|
struct ExternalValueData {
|
|
|
|
const Type* fType;
|
|
|
|
const ExternalValue* fValue;
|
|
|
|
};
|
|
|
|
|
2020-10-05 15:49:11 +00:00
|
|
|
struct FieldData {
|
|
|
|
StringFragment fName;
|
|
|
|
const Type* fType;
|
|
|
|
const Variable* fOwner;
|
|
|
|
int fFieldIndex;
|
|
|
|
};
|
|
|
|
|
2020-10-01 16:13:17 +00:00
|
|
|
struct FloatLiteralData {
|
|
|
|
const Type* fType;
|
|
|
|
float fValue;
|
|
|
|
};
|
|
|
|
|
2020-10-05 18:47:09 +00:00
|
|
|
struct ForStatementData {
|
|
|
|
std::shared_ptr<SymbolTable> fSymbolTable;
|
|
|
|
};
|
|
|
|
|
2020-10-05 19:51:52 +00:00
|
|
|
struct FunctionCallData {
|
|
|
|
const Type* fType;
|
|
|
|
const FunctionDeclaration* fFunction;
|
|
|
|
};
|
|
|
|
|
2020-10-08 15:45:44 +00:00
|
|
|
struct FunctionDeclarationData {
|
|
|
|
StringFragment fName;
|
|
|
|
mutable const FunctionDefinition* fDefinition;
|
|
|
|
ModifiersPool::Handle fModifiersHandle;
|
|
|
|
// FIXME after killing fExpressionChildren / fStatementChildren in favor of just fChildren,
|
|
|
|
// the parameters should move into that vector
|
|
|
|
std::vector<Variable*> fParameters;
|
|
|
|
const Type* fReturnType;
|
|
|
|
mutable std::atomic<int> fCallCount;
|
|
|
|
bool fBuiltin;
|
|
|
|
|
|
|
|
FunctionDeclarationData& operator=(const FunctionDeclarationData& other) {
|
|
|
|
fName = other.fName;
|
|
|
|
fDefinition = other.fDefinition;
|
|
|
|
fModifiersHandle = other.fModifiersHandle;
|
|
|
|
fParameters = other.fParameters;
|
|
|
|
fReturnType = other.fReturnType;
|
|
|
|
fCallCount = other.fCallCount.load();
|
|
|
|
fBuiltin = other.fBuiltin;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-10-07 20:47:09 +00:00
|
|
|
struct IfStatementData {
|
|
|
|
bool fIsStatic;
|
|
|
|
};
|
|
|
|
|
2020-09-28 20:27:18 +00:00
|
|
|
struct IntLiteralData {
|
|
|
|
const Type* fType;
|
|
|
|
int64_t fValue;
|
|
|
|
};
|
|
|
|
|
2020-10-08 16:10:12 +00:00
|
|
|
struct SettingData {
|
|
|
|
String fName;
|
|
|
|
const Type* fType;
|
|
|
|
};
|
|
|
|
|
2020-10-05 15:49:11 +00:00
|
|
|
struct SymbolData {
|
|
|
|
StringFragment fName;
|
|
|
|
const Type* fType;
|
|
|
|
};
|
|
|
|
|
2020-10-06 20:14:37 +00:00
|
|
|
struct SymbolAliasData {
|
|
|
|
StringFragment fName;
|
2020-10-07 20:42:04 +00:00
|
|
|
Symbol* fOrigSymbol;
|
2020-10-06 20:14:37 +00:00
|
|
|
};
|
|
|
|
|
2020-09-22 19:05:37 +00:00
|
|
|
struct TypeTokenData {
|
|
|
|
const Type* fType;
|
|
|
|
Token::Kind fToken;
|
|
|
|
};
|
|
|
|
|
2020-10-07 20:42:04 +00:00
|
|
|
struct VariableData {
|
|
|
|
StringFragment fName;
|
|
|
|
const Type* fType;
|
|
|
|
const Expression* fInitialValue = nullptr;
|
|
|
|
ModifiersPool::Handle fModifiersHandle;
|
|
|
|
// Tracks how many sites read from the variable. If this is zero for a non-out variable (or
|
|
|
|
// becomes zero during optimization), the variable is dead and may be eliminated.
|
|
|
|
mutable int16_t fReadCount;
|
|
|
|
// Tracks how many sites write to the variable. If this is zero, the variable is dead and
|
|
|
|
// may be eliminated.
|
|
|
|
mutable int16_t fWriteCount;
|
|
|
|
/*Variable::Storage*/int8_t fStorage;
|
|
|
|
bool fBuiltin;
|
|
|
|
};
|
|
|
|
|
2020-10-08 10:46:27 +00:00
|
|
|
struct VariableReferenceData {
|
|
|
|
const Variable* fVariable;
|
|
|
|
/*VariableReference::RefKind*/int8_t fRefKind;
|
|
|
|
};
|
|
|
|
|
2020-09-22 19:05:37 +00:00
|
|
|
struct NodeData {
|
|
|
|
enum class Kind {
|
2020-09-25 18:31:59 +00:00
|
|
|
kBlock,
|
2020-09-28 13:18:15 +00:00
|
|
|
kBoolLiteral,
|
2020-09-29 21:05:54 +00:00
|
|
|
kEnum,
|
2020-09-30 18:29:56 +00:00
|
|
|
kExternalValue,
|
2020-10-05 15:49:11 +00:00
|
|
|
kField,
|
2020-10-01 16:13:17 +00:00
|
|
|
kFloatLiteral,
|
2020-10-05 18:47:09 +00:00
|
|
|
kForStatement,
|
2020-10-05 19:51:52 +00:00
|
|
|
kFunctionCall,
|
2020-10-08 15:45:44 +00:00
|
|
|
kFunctionDeclaration,
|
2020-10-07 20:47:09 +00:00
|
|
|
kIfStatement,
|
2020-09-28 20:27:18 +00:00
|
|
|
kIntLiteral,
|
2020-10-08 16:10:12 +00:00
|
|
|
kSetting,
|
2020-09-30 14:17:00 +00:00
|
|
|
kString,
|
2020-10-05 15:49:11 +00:00
|
|
|
kSymbol,
|
2020-10-06 20:14:37 +00:00
|
|
|
kSymbolAlias,
|
2020-09-22 19:05:37 +00:00
|
|
|
kType,
|
|
|
|
kTypeToken,
|
2020-10-07 20:42:04 +00:00
|
|
|
kVariable,
|
2020-10-08 10:46:27 +00:00
|
|
|
kVariableReference,
|
2020-09-28 20:27:18 +00:00
|
|
|
} fKind = Kind::kType;
|
|
|
|
// it doesn't really matter what kind we default to, as long as it's a POD type
|
2020-09-22 19:05:37 +00:00
|
|
|
|
2020-09-28 20:27:18 +00:00
|
|
|
union Contents {
|
|
|
|
BlockData fBlock;
|
|
|
|
BoolLiteralData fBoolLiteral;
|
2020-09-29 21:05:54 +00:00
|
|
|
EnumData fEnum;
|
2020-09-30 18:29:56 +00:00
|
|
|
ExternalValueData fExternalValue;
|
2020-10-05 15:49:11 +00:00
|
|
|
FieldData fField;
|
2020-10-01 16:13:17 +00:00
|
|
|
FloatLiteralData fFloatLiteral;
|
2020-10-05 18:47:09 +00:00
|
|
|
ForStatementData fForStatement;
|
2020-10-05 19:51:52 +00:00
|
|
|
FunctionCallData fFunctionCall;
|
2020-10-08 15:45:44 +00:00
|
|
|
FunctionDeclarationData fFunctionDeclaration;
|
2020-10-07 20:47:09 +00:00
|
|
|
IfStatementData fIfStatement;
|
2020-09-28 20:27:18 +00:00
|
|
|
IntLiteralData fIntLiteral;
|
2020-10-08 16:10:12 +00:00
|
|
|
SettingData fSetting;
|
2020-09-30 14:17:00 +00:00
|
|
|
String fString;
|
2020-10-05 15:49:11 +00:00
|
|
|
SymbolData fSymbol;
|
2020-10-06 20:14:37 +00:00
|
|
|
SymbolAliasData fSymbolAlias;
|
2020-09-28 20:27:18 +00:00
|
|
|
const Type* fType;
|
|
|
|
TypeTokenData fTypeToken;
|
2020-10-07 20:42:04 +00:00
|
|
|
VariableData fVariable;
|
2020-10-08 10:46:27 +00:00
|
|
|
VariableReferenceData fVariableReference;
|
2020-09-28 20:27:18 +00:00
|
|
|
|
|
|
|
Contents() {}
|
|
|
|
|
|
|
|
~Contents() {}
|
|
|
|
} fContents;
|
2020-09-22 19:05:37 +00:00
|
|
|
|
2020-09-28 13:18:15 +00:00
|
|
|
NodeData(const BlockData& data)
|
2020-09-25 18:31:59 +00:00
|
|
|
: fKind(Kind::kBlock) {
|
2020-09-28 20:27:18 +00:00
|
|
|
*(new(&fContents) BlockData) = data;
|
2020-09-28 13:18:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NodeData(const BoolLiteralData& data)
|
|
|
|
: fKind(Kind::kBoolLiteral) {
|
2020-09-28 20:27:18 +00:00
|
|
|
*(new(&fContents) BoolLiteralData) = data;
|
|
|
|
}
|
|
|
|
|
2020-09-29 21:05:54 +00:00
|
|
|
NodeData(const EnumData& data)
|
|
|
|
: fKind(Kind::kEnum) {
|
|
|
|
*(new(&fContents) EnumData) = data;
|
|
|
|
}
|
|
|
|
|
2020-09-30 18:29:56 +00:00
|
|
|
NodeData(const ExternalValueData& data)
|
|
|
|
: fKind(Kind::kExternalValue) {
|
|
|
|
*(new(&fContents) ExternalValueData) = data;
|
|
|
|
}
|
|
|
|
|
2020-10-05 15:49:11 +00:00
|
|
|
NodeData(const FieldData& data)
|
|
|
|
: fKind(Kind::kField) {
|
|
|
|
*(new(&fContents) FieldData) = data;
|
|
|
|
}
|
|
|
|
|
2020-10-01 16:13:17 +00:00
|
|
|
NodeData(const FloatLiteralData& data)
|
|
|
|
: fKind(Kind::kFloatLiteral) {
|
|
|
|
*(new(&fContents) FloatLiteralData) = data;
|
|
|
|
}
|
|
|
|
|
2020-10-05 18:47:09 +00:00
|
|
|
NodeData(const ForStatementData& data)
|
|
|
|
: fKind(Kind::kForStatement) {
|
|
|
|
*(new(&fContents) ForStatementData) = data;
|
|
|
|
}
|
|
|
|
|
2020-10-05 19:51:52 +00:00
|
|
|
NodeData(const FunctionCallData& data)
|
|
|
|
: fKind(Kind::kFunctionCall) {
|
|
|
|
*(new(&fContents) FunctionCallData) = data;
|
|
|
|
}
|
|
|
|
|
2020-10-08 15:45:44 +00:00
|
|
|
NodeData(const FunctionDeclarationData& data)
|
|
|
|
: fKind(Kind::kFunctionDeclaration) {
|
|
|
|
*(new(&fContents) FunctionDeclarationData) = data;
|
|
|
|
}
|
|
|
|
|
2020-10-07 20:47:09 +00:00
|
|
|
NodeData(IfStatementData data)
|
|
|
|
: fKind(Kind::kIfStatement) {
|
|
|
|
*(new(&fContents) IfStatementData) = data;
|
|
|
|
}
|
|
|
|
|
2020-09-28 20:27:18 +00:00
|
|
|
NodeData(IntLiteralData data)
|
|
|
|
: fKind(Kind::kIntLiteral) {
|
|
|
|
*(new(&fContents) IntLiteralData) = data;
|
2020-09-25 18:31:59 +00:00
|
|
|
}
|
|
|
|
|
2020-10-08 16:10:12 +00:00
|
|
|
NodeData(const SettingData& data)
|
|
|
|
: fKind(Kind::kSetting) {
|
|
|
|
*(new(&fContents) SettingData) = data;
|
|
|
|
}
|
|
|
|
|
2020-09-30 14:17:00 +00:00
|
|
|
NodeData(const String& data)
|
|
|
|
: fKind(Kind::kString) {
|
|
|
|
*(new(&fContents) String) = data;
|
|
|
|
}
|
|
|
|
|
2020-10-05 15:49:11 +00:00
|
|
|
NodeData(const SymbolData& data)
|
|
|
|
: fKind(Kind::kSymbol) {
|
|
|
|
*(new(&fContents) SymbolData) = data;
|
|
|
|
}
|
|
|
|
|
2020-10-06 20:14:37 +00:00
|
|
|
NodeData(const SymbolAliasData& data)
|
|
|
|
: fKind(Kind::kSymbolAlias) {
|
|
|
|
*(new(&fContents) SymbolAliasData) = data;
|
|
|
|
}
|
|
|
|
|
2020-09-22 19:05:37 +00:00
|
|
|
NodeData(const Type* data)
|
|
|
|
: fKind(Kind::kType) {
|
2020-09-28 20:27:18 +00:00
|
|
|
*(new(&fContents) const Type*) = data;
|
2020-09-22 19:05:37 +00:00
|
|
|
}
|
|
|
|
|
2020-09-28 13:18:15 +00:00
|
|
|
NodeData(const TypeTokenData& data)
|
2020-09-22 19:05:37 +00:00
|
|
|
: fKind(Kind::kTypeToken) {
|
2020-09-28 20:27:18 +00:00
|
|
|
*(new(&fContents) TypeTokenData) = data;
|
|
|
|
}
|
|
|
|
|
2020-10-07 20:42:04 +00:00
|
|
|
NodeData(const VariableData& data)
|
|
|
|
: fKind(Kind::kVariable) {
|
|
|
|
*(new(&fContents) VariableData) = data;
|
|
|
|
}
|
|
|
|
|
2020-10-08 10:46:27 +00:00
|
|
|
NodeData(const VariableReferenceData& data)
|
|
|
|
: fKind(Kind::kVariableReference) {
|
|
|
|
*(new(&fContents) VariableReferenceData) = data;
|
|
|
|
}
|
|
|
|
|
2020-09-28 20:27:18 +00:00
|
|
|
NodeData(const NodeData& other) {
|
|
|
|
*this = other;
|
|
|
|
}
|
|
|
|
|
|
|
|
NodeData& operator=(const NodeData& other) {
|
|
|
|
this->cleanup();
|
|
|
|
fKind = other.fKind;
|
|
|
|
switch (fKind) {
|
|
|
|
case Kind::kBlock:
|
|
|
|
*(new(&fContents) BlockData) = other.fContents.fBlock;
|
|
|
|
break;
|
|
|
|
case Kind::kBoolLiteral:
|
|
|
|
*(new(&fContents) BoolLiteralData) = other.fContents.fBoolLiteral;
|
|
|
|
break;
|
2020-09-29 21:05:54 +00:00
|
|
|
case Kind::kEnum:
|
|
|
|
*(new(&fContents) EnumData) = other.fContents.fEnum;
|
|
|
|
break;
|
2020-09-30 18:29:56 +00:00
|
|
|
case Kind::kExternalValue:
|
|
|
|
*(new(&fContents) ExternalValueData) = other.fContents.fExternalValue;
|
|
|
|
break;
|
2020-10-05 15:49:11 +00:00
|
|
|
case Kind::kField:
|
|
|
|
*(new(&fContents) FieldData) = other.fContents.fField;
|
|
|
|
break;
|
2020-10-01 16:13:17 +00:00
|
|
|
case Kind::kFloatLiteral:
|
|
|
|
*(new(&fContents) FloatLiteralData) = other.fContents.fFloatLiteral;
|
|
|
|
break;
|
2020-10-05 18:47:09 +00:00
|
|
|
case Kind::kForStatement:
|
|
|
|
*(new(&fContents) ForStatementData) = other.fContents.fForStatement;
|
|
|
|
break;
|
2020-10-05 19:51:52 +00:00
|
|
|
case Kind::kFunctionCall:
|
|
|
|
*(new(&fContents) FunctionCallData) = other.fContents.fFunctionCall;
|
|
|
|
break;
|
2020-10-08 15:45:44 +00:00
|
|
|
case Kind::kFunctionDeclaration:
|
|
|
|
*(new(&fContents) FunctionDeclarationData) =
|
|
|
|
other.fContents.fFunctionDeclaration;
|
|
|
|
break;
|
2020-10-07 20:47:09 +00:00
|
|
|
case Kind::kIfStatement:
|
|
|
|
*(new(&fContents) IfStatementData) = other.fContents.fIfStatement;
|
|
|
|
break;
|
2020-09-28 20:27:18 +00:00
|
|
|
case Kind::kIntLiteral:
|
|
|
|
*(new(&fContents) IntLiteralData) = other.fContents.fIntLiteral;
|
|
|
|
break;
|
2020-10-08 16:10:12 +00:00
|
|
|
case Kind::kSetting:
|
|
|
|
*(new(&fContents) SettingData) = other.fContents.fSetting;
|
|
|
|
break;
|
2020-09-30 14:17:00 +00:00
|
|
|
case Kind::kString:
|
|
|
|
*(new(&fContents) String) = other.fContents.fString;
|
|
|
|
break;
|
2020-10-05 15:49:11 +00:00
|
|
|
case Kind::kSymbol:
|
|
|
|
*(new(&fContents) SymbolData) = other.fContents.fSymbol;
|
|
|
|
break;
|
2020-10-06 20:14:37 +00:00
|
|
|
case Kind::kSymbolAlias:
|
|
|
|
*(new(&fContents) SymbolAliasData) = other.fContents.fSymbolAlias;
|
|
|
|
break;
|
2020-09-28 20:27:18 +00:00
|
|
|
case Kind::kType:
|
|
|
|
*(new(&fContents) const Type*) = other.fContents.fType;
|
|
|
|
break;
|
|
|
|
case Kind::kTypeToken:
|
|
|
|
*(new(&fContents) TypeTokenData) = other.fContents.fTypeToken;
|
|
|
|
break;
|
2020-10-07 20:42:04 +00:00
|
|
|
case Kind::kVariable:
|
|
|
|
*(new(&fContents) VariableData) = other.fContents.fVariable;
|
|
|
|
break;
|
2020-10-08 10:46:27 +00:00
|
|
|
case Kind::kVariableReference:
|
|
|
|
*(new(&fContents) VariableReferenceData) = other.fContents.fVariableReference;
|
|
|
|
break;
|
2020-09-28 20:27:18 +00:00
|
|
|
}
|
|
|
|
return *this;
|
2020-09-22 19:05:37 +00:00
|
|
|
}
|
2020-09-25 18:31:59 +00:00
|
|
|
|
|
|
|
~NodeData() {
|
2020-09-28 20:27:18 +00:00
|
|
|
this->cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void cleanup() {
|
2020-09-28 13:18:15 +00:00
|
|
|
switch (fKind) {
|
|
|
|
case Kind::kBlock:
|
2020-09-28 20:27:18 +00:00
|
|
|
fContents.fBlock.~BlockData();
|
2020-09-28 13:18:15 +00:00
|
|
|
break;
|
|
|
|
case Kind::kBoolLiteral:
|
2020-09-28 20:27:18 +00:00
|
|
|
fContents.fBoolLiteral.~BoolLiteralData();
|
|
|
|
break;
|
2020-09-29 21:05:54 +00:00
|
|
|
case Kind::kEnum:
|
|
|
|
fContents.fEnum.~EnumData();
|
|
|
|
break;
|
2020-09-30 18:29:56 +00:00
|
|
|
case Kind::kExternalValue:
|
|
|
|
fContents.fExternalValue.~ExternalValueData();
|
|
|
|
break;
|
2020-10-05 15:49:11 +00:00
|
|
|
case Kind::kField:
|
|
|
|
fContents.fField.~FieldData();
|
|
|
|
break;
|
2020-10-01 16:13:17 +00:00
|
|
|
case Kind::kFloatLiteral:
|
|
|
|
fContents.fFloatLiteral.~FloatLiteralData();
|
|
|
|
break;
|
2020-10-05 18:47:09 +00:00
|
|
|
case Kind::kForStatement:
|
|
|
|
fContents.fForStatement.~ForStatementData();
|
|
|
|
break;
|
2020-10-05 19:51:52 +00:00
|
|
|
case Kind::kFunctionCall:
|
|
|
|
fContents.fFunctionCall.~FunctionCallData();
|
|
|
|
break;
|
2020-10-07 20:47:09 +00:00
|
|
|
case Kind::kIfStatement:
|
|
|
|
fContents.fIfStatement.~IfStatementData();
|
|
|
|
break;
|
2020-10-08 15:45:44 +00:00
|
|
|
case Kind::kFunctionDeclaration:
|
|
|
|
fContents.fFunctionDeclaration.~FunctionDeclarationData();
|
|
|
|
break;
|
2020-09-28 20:27:18 +00:00
|
|
|
case Kind::kIntLiteral:
|
|
|
|
fContents.fIntLiteral.~IntLiteralData();
|
2020-09-28 13:18:15 +00:00
|
|
|
break;
|
2020-10-08 16:10:12 +00:00
|
|
|
case Kind::kSetting:
|
|
|
|
fContents.fSetting.~SettingData();
|
|
|
|
break;
|
2020-09-30 14:17:00 +00:00
|
|
|
case Kind::kString:
|
|
|
|
fContents.fString.~String();
|
|
|
|
break;
|
2020-10-05 15:49:11 +00:00
|
|
|
case Kind::kSymbol:
|
|
|
|
fContents.fSymbol.~SymbolData();
|
|
|
|
break;
|
2020-10-06 20:14:37 +00:00
|
|
|
case Kind::kSymbolAlias:
|
|
|
|
fContents.fSymbolAlias.~SymbolAliasData();
|
|
|
|
break;
|
2020-09-28 13:18:15 +00:00
|
|
|
case Kind::kType:
|
|
|
|
break;
|
|
|
|
case Kind::kTypeToken:
|
2020-09-28 20:27:18 +00:00
|
|
|
fContents.fTypeToken.~TypeTokenData();
|
2020-09-28 13:18:15 +00:00
|
|
|
break;
|
2020-10-07 20:42:04 +00:00
|
|
|
case Kind::kVariable:
|
|
|
|
fContents.fVariable.~VariableData();
|
|
|
|
break;
|
2020-10-08 10:46:27 +00:00
|
|
|
case Kind::kVariableReference:
|
|
|
|
fContents.fVariableReference.~VariableReferenceData();
|
|
|
|
break;
|
2020-09-25 18:31:59 +00:00
|
|
|
}
|
|
|
|
}
|
2020-09-22 19:05:37 +00:00
|
|
|
};
|
|
|
|
|
2020-09-28 13:18:15 +00:00
|
|
|
IRNode(int offset, int kind, const BlockData& data,
|
|
|
|
std::vector<std::unique_ptr<Statement>> stmts);
|
|
|
|
|
|
|
|
IRNode(int offset, int kind, const BoolLiteralData& data);
|
2020-09-25 18:31:59 +00:00
|
|
|
|
2020-09-29 21:05:54 +00:00
|
|
|
IRNode(int offset, int kind, const EnumData& data);
|
|
|
|
|
2020-09-30 18:29:56 +00:00
|
|
|
IRNode(int offset, int kind, const ExternalValueData& data);
|
|
|
|
|
2020-10-05 15:49:11 +00:00
|
|
|
IRNode(int offset, int kind, const FieldData& data);
|
|
|
|
|
2020-10-01 16:13:17 +00:00
|
|
|
IRNode(int offset, int kind, const FloatLiteralData& data);
|
|
|
|
|
2020-10-05 18:47:09 +00:00
|
|
|
IRNode(int offset, int kind, const ForStatementData& data);
|
|
|
|
|
2020-10-05 19:51:52 +00:00
|
|
|
IRNode(int offset, int kind, const FunctionCallData& data);
|
|
|
|
|
2020-10-07 20:47:09 +00:00
|
|
|
IRNode(int offset, int kind, const IfStatementData& data);
|
|
|
|
|
2020-10-08 15:45:44 +00:00
|
|
|
IRNode(int offset, int kind, const FunctionDeclarationData& data);
|
|
|
|
|
2020-10-05 18:47:09 +00:00
|
|
|
IRNode(int offset, int kind, const IntLiteralData& data);
|
|
|
|
|
2020-10-08 16:10:12 +00:00
|
|
|
IRNode(int offset, int kind, const SettingData& data);
|
|
|
|
|
2020-09-30 14:17:00 +00:00
|
|
|
IRNode(int offset, int kind, const String& data);
|
|
|
|
|
2020-10-05 15:49:11 +00:00
|
|
|
IRNode(int offset, int kind, const SymbolData& data);
|
|
|
|
|
2020-10-06 20:14:37 +00:00
|
|
|
IRNode(int offset, int kind, const SymbolAliasData& data);
|
|
|
|
|
2020-09-22 19:05:37 +00:00
|
|
|
IRNode(int offset, int kind, const Type* data = nullptr);
|
|
|
|
|
2020-09-28 13:18:15 +00:00
|
|
|
IRNode(int offset, int kind, const TypeTokenData& data);
|
2020-09-22 19:05:37 +00:00
|
|
|
|
2020-10-07 20:42:04 +00:00
|
|
|
IRNode(int offset, int kind, const VariableData& data);
|
2020-09-22 19:05:37 +00:00
|
|
|
|
2020-10-08 10:46:27 +00:00
|
|
|
IRNode(int offset, int kind, const VariableReferenceData& data);
|
|
|
|
|
2020-09-22 19:05:37 +00:00
|
|
|
Expression& expressionChild(int index) const {
|
2020-09-25 18:31:59 +00:00
|
|
|
SkASSERT(index >= 0 && index < (int) fExpressionChildren.size());
|
2020-09-22 19:05:37 +00:00
|
|
|
return *fExpressionChildren[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<Expression>& expressionPointer(int index) {
|
2020-09-25 18:31:59 +00:00
|
|
|
SkASSERT(index >= 0 && index < (int) fExpressionChildren.size());
|
2020-09-22 19:05:37 +00:00
|
|
|
return fExpressionChildren[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::unique_ptr<Expression>& expressionPointer(int index) const {
|
2020-09-25 18:31:59 +00:00
|
|
|
SkASSERT(index >= 0 && index < (int) fExpressionChildren.size());
|
2020-09-22 19:05:37 +00:00
|
|
|
return fExpressionChildren[index];
|
|
|
|
}
|
|
|
|
|
2020-09-25 18:31:59 +00:00
|
|
|
int expressionChildCount() const {
|
|
|
|
return fExpressionChildren.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Statement& statementChild(int index) const {
|
|
|
|
SkASSERT(index >= 0 && index < (int) fStatementChildren.size());
|
|
|
|
return *fStatementChildren[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<Statement>& statementPointer(int index) {
|
|
|
|
SkASSERT(index >= 0 && index < (int) fStatementChildren.size());
|
|
|
|
return fStatementChildren[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::unique_ptr<Statement>& statementPointer(int index) const {
|
|
|
|
SkASSERT(index >= 0 && index < (int) fStatementChildren.size());
|
|
|
|
return fStatementChildren[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
int statementChildCount() const {
|
|
|
|
return fStatementChildren.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
BlockData& blockData() {
|
|
|
|
SkASSERT(fData.fKind == NodeData::Kind::kBlock);
|
2020-09-28 20:27:18 +00:00
|
|
|
return fData.fContents.fBlock;
|
2020-09-25 18:31:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const BlockData& blockData() const {
|
|
|
|
SkASSERT(fData.fKind == NodeData::Kind::kBlock);
|
2020-09-28 20:27:18 +00:00
|
|
|
return fData.fContents.fBlock;
|
2020-09-25 18:31:59 +00:00
|
|
|
}
|
|
|
|
|
2020-09-28 13:18:15 +00:00
|
|
|
const BoolLiteralData& boolLiteralData() const {
|
|
|
|
SkASSERT(fData.fKind == NodeData::Kind::kBoolLiteral);
|
2020-09-28 20:27:18 +00:00
|
|
|
return fData.fContents.fBoolLiteral;
|
|
|
|
}
|
|
|
|
|
2020-09-29 21:05:54 +00:00
|
|
|
const EnumData& enumData() const {
|
|
|
|
SkASSERT(fData.fKind == NodeData::Kind::kEnum);
|
|
|
|
return fData.fContents.fEnum;
|
|
|
|
}
|
|
|
|
|
2020-09-30 18:29:56 +00:00
|
|
|
const ExternalValueData& externalValueData() const {
|
|
|
|
SkASSERT(fData.fKind == NodeData::Kind::kExternalValue);
|
|
|
|
return fData.fContents.fExternalValue;
|
|
|
|
}
|
|
|
|
|
2020-10-05 15:49:11 +00:00
|
|
|
const FieldData& fieldData() const {
|
|
|
|
SkASSERT(fData.fKind == NodeData::Kind::kField);
|
|
|
|
return fData.fContents.fField;
|
|
|
|
}
|
|
|
|
|
2020-10-01 16:13:17 +00:00
|
|
|
const FloatLiteralData& floatLiteralData() const {
|
|
|
|
SkASSERT(fData.fKind == NodeData::Kind::kFloatLiteral);
|
|
|
|
return fData.fContents.fFloatLiteral;
|
|
|
|
}
|
|
|
|
|
2020-10-05 18:47:09 +00:00
|
|
|
const ForStatementData& forStatementData() const {
|
|
|
|
SkASSERT(fData.fKind == NodeData::Kind::kForStatement);
|
|
|
|
return fData.fContents.fForStatement;
|
|
|
|
}
|
|
|
|
|
2020-10-05 19:51:52 +00:00
|
|
|
const FunctionCallData& functionCallData() const {
|
|
|
|
SkASSERT(fData.fKind == NodeData::Kind::kFunctionCall);
|
|
|
|
return fData.fContents.fFunctionCall;
|
|
|
|
}
|
|
|
|
|
2020-10-08 15:45:44 +00:00
|
|
|
FunctionDeclarationData& functionDeclarationData() {
|
|
|
|
SkASSERT(fData.fKind == NodeData::Kind::kFunctionDeclaration);
|
|
|
|
return fData.fContents.fFunctionDeclaration;
|
|
|
|
}
|
|
|
|
|
2020-10-07 20:47:09 +00:00
|
|
|
const IfStatementData& ifStatementData() const {
|
|
|
|
SkASSERT(fData.fKind == NodeData::Kind::kIfStatement);
|
|
|
|
return fData.fContents.fIfStatement;
|
|
|
|
}
|
|
|
|
|
2020-10-08 15:45:44 +00:00
|
|
|
const FunctionDeclarationData& functionDeclarationData() const {
|
|
|
|
SkASSERT(fData.fKind == NodeData::Kind::kFunctionDeclaration);
|
|
|
|
return fData.fContents.fFunctionDeclaration;
|
|
|
|
}
|
|
|
|
|
2020-09-28 20:27:18 +00:00
|
|
|
const IntLiteralData& intLiteralData() const {
|
|
|
|
SkASSERT(fData.fKind == NodeData::Kind::kIntLiteral);
|
|
|
|
return fData.fContents.fIntLiteral;
|
2020-09-28 13:18:15 +00:00
|
|
|
}
|
|
|
|
|
2020-10-08 16:10:12 +00:00
|
|
|
const SettingData& settingData() const {
|
|
|
|
SkASSERT(fData.fKind == NodeData::Kind::kSetting);
|
|
|
|
return fData.fContents.fSetting;
|
|
|
|
}
|
|
|
|
|
2020-09-30 14:17:00 +00:00
|
|
|
const String& stringData() const {
|
|
|
|
SkASSERT(fData.fKind == NodeData::Kind::kString);
|
|
|
|
return fData.fContents.fString;
|
|
|
|
}
|
|
|
|
|
2020-10-05 15:49:11 +00:00
|
|
|
SymbolData& symbolData() {
|
|
|
|
SkASSERT(fData.fKind == NodeData::Kind::kSymbol);
|
|
|
|
return fData.fContents.fSymbol;
|
|
|
|
}
|
|
|
|
|
|
|
|
const SymbolData& symbolData() const {
|
|
|
|
SkASSERT(fData.fKind == NodeData::Kind::kSymbol);
|
|
|
|
return fData.fContents.fSymbol;
|
|
|
|
}
|
|
|
|
|
2020-10-06 20:14:37 +00:00
|
|
|
const SymbolAliasData& symbolAliasData() const {
|
|
|
|
SkASSERT(fData.fKind == NodeData::Kind::kSymbolAlias);
|
|
|
|
return fData.fContents.fSymbolAlias;
|
|
|
|
}
|
|
|
|
|
2020-09-25 18:31:59 +00:00
|
|
|
const Type* typeData() const {
|
2020-09-22 19:05:37 +00:00
|
|
|
SkASSERT(fData.fKind == NodeData::Kind::kType);
|
2020-09-28 20:27:18 +00:00
|
|
|
return fData.fContents.fType;
|
2020-09-22 19:05:37 +00:00
|
|
|
}
|
|
|
|
|
2020-09-25 18:31:59 +00:00
|
|
|
const TypeTokenData& typeTokenData() const {
|
2020-09-22 19:05:37 +00:00
|
|
|
SkASSERT(fData.fKind == NodeData::Kind::kTypeToken);
|
2020-09-28 20:27:18 +00:00
|
|
|
return fData.fContents.fTypeToken;
|
2020-09-22 19:05:37 +00:00
|
|
|
}
|
|
|
|
|
2020-10-07 20:42:04 +00:00
|
|
|
VariableData& variableData() {
|
|
|
|
SkASSERT(fData.fKind == NodeData::Kind::kVariable);
|
|
|
|
return fData.fContents.fVariable;
|
|
|
|
}
|
|
|
|
|
|
|
|
const VariableData& variableData() const {
|
|
|
|
SkASSERT(fData.fKind == NodeData::Kind::kVariable);
|
|
|
|
return fData.fContents.fVariable;
|
|
|
|
}
|
|
|
|
|
2020-10-08 10:46:27 +00:00
|
|
|
VariableReferenceData& variableReferenceData() {
|
|
|
|
SkASSERT(fData.fKind == NodeData::Kind::kVariableReference);
|
|
|
|
return fData.fContents.fVariableReference;
|
|
|
|
}
|
|
|
|
|
|
|
|
const VariableReferenceData& variableReferenceData() const {
|
|
|
|
SkASSERT(fData.fKind == NodeData::Kind::kVariableReference);
|
|
|
|
return fData.fContents.fVariableReference;
|
|
|
|
}
|
|
|
|
|
2020-09-08 14:22:09 +00:00
|
|
|
int fKind;
|
2020-09-11 16:27:26 +00:00
|
|
|
|
2020-09-22 19:05:37 +00:00
|
|
|
NodeData fData;
|
2020-09-25 18:31:59 +00:00
|
|
|
|
|
|
|
// Needing two separate vectors is a temporary issue. Ideally, we'd just be able to use a single
|
|
|
|
// vector of nodes, but there are various spots where we take pointers to std::unique_ptr<>,
|
|
|
|
// and it isn't safe to pun std::unique_ptr<IRNode> to std::unique_ptr<Statement / Expression>.
|
|
|
|
// And we can't update the call sites to expect std::unique_ptr<IRNode> while there are still
|
|
|
|
// old-style nodes around.
|
|
|
|
// When the transition is finished, we'll be able to drop the unique_ptrs and just handle
|
|
|
|
// <IRNode> directly.
|
|
|
|
std::vector<std::unique_ptr<Expression>> fExpressionChildren;
|
|
|
|
// it's important to keep fStatements defined after (and thus destroyed before) fData,
|
|
|
|
// because destroying statements can modify reference counts in a SymbolTable contained in fData
|
|
|
|
std::vector<std::unique_ptr<Statement>> fStatementChildren;
|
2016-07-01 15:22:01 +00:00
|
|
|
};
|
|
|
|
|
2020-08-06 18:11:56 +00:00
|
|
|
} // namespace SkSL
|
2016-07-01 15:22:01 +00:00
|
|
|
|
|
|
|
#endif
|