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-10-13 15:14:08 +00:00
|
|
|
#include "include/private/SkTArray.h"
|
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-10-08 18:52:24 +00:00
|
|
|
#include <atomic>
|
2020-10-14 17:33:18 +00:00
|
|
|
#include <unordered_set>
|
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-10-09 15:55:40 +00:00
|
|
|
enum class FieldAccessOwnerKind : int8_t;
|
2020-10-09 14:43:45 +00:00
|
|
|
enum class VariableRefKind : int8_t;
|
|
|
|
enum class VariableStorage : int8_t;
|
2020-09-11 16:27:26 +00:00
|
|
|
|
2020-10-13 15:14:08 +00:00
|
|
|
using ExpressionArray = SkSTArray<2, std::unique_ptr<Expression>>;
|
2020-10-13 16:48:21 +00:00
|
|
|
using StatementArray = SkSTArray<2, std::unique_ptr<Statement>>;
|
2020-10-13 15:14:08 +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;
|
2020-10-20 14:23:50 +00:00
|
|
|
bool fIsSharedWithCpp;
|
2020-09-29 21:05:54 +00:00
|
|
|
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-09 15:55:40 +00:00
|
|
|
struct FieldAccessData {
|
|
|
|
const Type* fType;
|
|
|
|
int fFieldIndex;
|
|
|
|
FieldAccessOwnerKind fOwnerKind;
|
|
|
|
};
|
|
|
|
|
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
|
2020-10-13 14:34:18 +00:00
|
|
|
std::vector<const Variable*> fParameters;
|
2020-10-08 15:45:44 +00:00
|
|
|
const Type* fReturnType;
|
|
|
|
bool fBuiltin;
|
|
|
|
|
|
|
|
FunctionDeclarationData& operator=(const FunctionDeclarationData& other) {
|
|
|
|
fName = other.fName;
|
|
|
|
fDefinition = other.fDefinition;
|
|
|
|
fModifiersHandle = other.fModifiersHandle;
|
|
|
|
fParameters = other.fParameters;
|
|
|
|
fReturnType = other.fReturnType;
|
|
|
|
fBuiltin = other.fBuiltin;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-10-14 17:33:18 +00:00
|
|
|
struct FunctionDefinitionData {
|
|
|
|
const FunctionDeclaration* fDeclaration;
|
2020-10-19 19:00:01 +00:00
|
|
|
bool fBuiltin;
|
2020-10-14 17:33:18 +00:00
|
|
|
// We track intrinsic functions we reference so that we can ensure that all of them end up
|
|
|
|
// copied into the final output.
|
|
|
|
std::unordered_set<const FunctionDeclaration*> fReferencedIntrinsics;
|
|
|
|
// This pointer may be null, and even when non-null is not guaranteed to remain valid for
|
|
|
|
// the entire lifespan of this object. The parse tree's lifespan is normally controlled by
|
|
|
|
// IRGenerator, so the IRGenerator being destroyed or being used to compile another file
|
|
|
|
// will invalidate this pointer.
|
|
|
|
const ASTNode* fSource;
|
|
|
|
};
|
|
|
|
|
2020-10-12 15:12:12 +00:00
|
|
|
struct FunctionReferenceData {
|
|
|
|
const Type* fType;
|
|
|
|
std::vector<const FunctionDeclaration*> fFunctions;
|
|
|
|
};
|
|
|
|
|
2020-10-07 20:47:09 +00:00
|
|
|
struct IfStatementData {
|
|
|
|
bool fIsStatic;
|
|
|
|
};
|
|
|
|
|
2020-10-15 14:10:08 +00:00
|
|
|
struct InterfaceBlockData {
|
|
|
|
const Variable* fVariable;
|
|
|
|
String fTypeName;
|
|
|
|
String fInstanceName;
|
|
|
|
std::shared_ptr<SymbolTable> fTypeOwner;
|
|
|
|
};
|
|
|
|
|
2020-09-28 20:27:18 +00:00
|
|
|
struct IntLiteralData {
|
|
|
|
const Type* fType;
|
|
|
|
int64_t fValue;
|
|
|
|
};
|
|
|
|
|
2020-10-09 20:51:18 +00:00
|
|
|
struct InlineMarkerData {
|
|
|
|
const FunctionDeclaration* fFunction;
|
|
|
|
};
|
|
|
|
|
2020-10-13 14:30:20 +00:00
|
|
|
struct ModifiersDeclarationData {
|
|
|
|
ModifiersPool::Handle fModifiersHandle;
|
|
|
|
};
|
|
|
|
|
2020-10-12 20:58:40 +00:00
|
|
|
struct SectionData {
|
|
|
|
String fName;
|
|
|
|
String fArgument;
|
|
|
|
String fText;
|
|
|
|
};
|
|
|
|
|
2020-10-08 16:10:12 +00:00
|
|
|
struct SettingData {
|
|
|
|
String fName;
|
|
|
|
const Type* fType;
|
|
|
|
};
|
|
|
|
|
2020-10-12 20:11:51 +00:00
|
|
|
struct SwizzleData {
|
|
|
|
const Type* fType;
|
|
|
|
std::vector<int> fComponents;
|
|
|
|
};
|
|
|
|
|
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-13 14:34:18 +00:00
|
|
|
const Symbol* fOrigSymbol;
|
2020-10-06 20:14:37 +00:00
|
|
|
};
|
|
|
|
|
2020-10-12 15:12:12 +00:00
|
|
|
struct TypeReferenceData {
|
|
|
|
const Type* fType;
|
|
|
|
const Type* fValue;
|
|
|
|
};
|
|
|
|
|
2020-09-22 19:05:37 +00:00
|
|
|
struct TypeTokenData {
|
|
|
|
const Type* fType;
|
|
|
|
Token::Kind fToken;
|
|
|
|
};
|
|
|
|
|
2020-10-09 20:51:18 +00:00
|
|
|
struct UnresolvedFunctionData {
|
|
|
|
// FIXME move this into the child vector after killing fExpressionChildren /
|
|
|
|
// fStatementChildren
|
|
|
|
std::vector<const FunctionDeclaration*> fFunctions;
|
|
|
|
};
|
|
|
|
|
2020-10-13 17:49:44 +00:00
|
|
|
struct VarDeclarationData {
|
|
|
|
const Type* fBaseType;
|
|
|
|
const Variable* fVar;
|
|
|
|
};
|
|
|
|
|
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;
|
2020-10-09 14:43:45 +00:00
|
|
|
VariableStorage fStorage;
|
2020-10-07 20:42:04 +00:00
|
|
|
bool fBuiltin;
|
|
|
|
};
|
|
|
|
|
2020-10-08 10:46:27 +00:00
|
|
|
struct VariableReferenceData {
|
|
|
|
const Variable* fVariable;
|
2020-10-09 14:43:45 +00:00
|
|
|
VariableRefKind fRefKind;
|
2020-10-08 10:46:27 +00:00
|
|
|
};
|
|
|
|
|
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-09 15:55:40 +00:00
|
|
|
kFieldAccess,
|
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-14 17:33:18 +00:00
|
|
|
kFunctionDefinition,
|
2020-10-12 15:12:12 +00:00
|
|
|
kFunctionReference,
|
2020-10-07 20:47:09 +00:00
|
|
|
kIfStatement,
|
2020-10-09 20:51:18 +00:00
|
|
|
kInlineMarker,
|
2020-10-15 14:10:08 +00:00
|
|
|
kInterfaceBlock,
|
2020-09-28 20:27:18 +00:00
|
|
|
kIntLiteral,
|
2020-10-13 14:30:20 +00:00
|
|
|
kModifiersDeclaration,
|
2020-10-12 20:58:40 +00:00
|
|
|
kSection,
|
2020-10-08 16:10:12 +00:00
|
|
|
kSetting,
|
2020-09-30 14:17:00 +00:00
|
|
|
kString,
|
2020-10-12 20:11:51 +00:00
|
|
|
kSwizzle,
|
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,
|
2020-10-12 15:12:12 +00:00
|
|
|
kTypeReference,
|
2020-09-22 19:05:37 +00:00
|
|
|
kTypeToken,
|
2020-10-09 20:51:18 +00:00
|
|
|
kUnresolvedFunction,
|
2020-10-13 17:49:44 +00:00
|
|
|
kVarDeclaration,
|
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-09 15:55:40 +00:00
|
|
|
FieldAccessData fFieldAccess;
|
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-14 17:33:18 +00:00
|
|
|
FunctionDefinitionData fFunctionDefinition;
|
2020-10-12 15:12:12 +00:00
|
|
|
FunctionReferenceData fFunctionReference;
|
2020-10-07 20:47:09 +00:00
|
|
|
IfStatementData fIfStatement;
|
2020-10-09 20:51:18 +00:00
|
|
|
InlineMarkerData fInlineMarker;
|
2020-10-15 14:10:08 +00:00
|
|
|
InterfaceBlockData fInterfaceBlock;
|
2020-09-28 20:27:18 +00:00
|
|
|
IntLiteralData fIntLiteral;
|
2020-10-13 14:30:20 +00:00
|
|
|
ModifiersDeclarationData fModifiersDeclaration;
|
2020-10-12 20:58:40 +00:00
|
|
|
SectionData fSection;
|
2020-10-08 16:10:12 +00:00
|
|
|
SettingData fSetting;
|
2020-09-30 14:17:00 +00:00
|
|
|
String fString;
|
2020-10-12 20:11:51 +00:00
|
|
|
SwizzleData fSwizzle;
|
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;
|
2020-10-12 15:12:12 +00:00
|
|
|
TypeReferenceData fTypeReference;
|
2020-09-28 20:27:18 +00:00
|
|
|
TypeTokenData fTypeToken;
|
2020-10-09 20:51:18 +00:00
|
|
|
UnresolvedFunctionData fUnresolvedFunction;
|
2020-10-13 17:49:44 +00:00
|
|
|
VarDeclarationData fVarDeclaration;
|
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-09 15:55:40 +00:00
|
|
|
NodeData(const FieldAccessData& data)
|
|
|
|
: fKind(Kind::kFieldAccess) {
|
|
|
|
*(new(&fContents) FieldAccessData) = 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-14 17:33:18 +00:00
|
|
|
NodeData(const FunctionDefinitionData& data)
|
|
|
|
: fKind(Kind::kFunctionDefinition) {
|
|
|
|
*(new(&fContents) FunctionDefinitionData) = data;
|
|
|
|
}
|
|
|
|
|
2020-10-12 15:12:12 +00:00
|
|
|
NodeData(const FunctionReferenceData& data)
|
|
|
|
: fKind(Kind::kFunctionReference) {
|
|
|
|
*(new(&fContents) FunctionReferenceData) = data;
|
|
|
|
}
|
|
|
|
|
2020-10-07 20:47:09 +00:00
|
|
|
NodeData(IfStatementData data)
|
|
|
|
: fKind(Kind::kIfStatement) {
|
|
|
|
*(new(&fContents) IfStatementData) = data;
|
|
|
|
}
|
|
|
|
|
2020-10-09 20:51:18 +00:00
|
|
|
NodeData(InlineMarkerData data)
|
|
|
|
: fKind(Kind::kInlineMarker) {
|
|
|
|
*(new(&fContents) InlineMarkerData) = data;
|
|
|
|
}
|
|
|
|
|
2020-10-15 14:10:08 +00:00
|
|
|
NodeData(InterfaceBlockData data)
|
|
|
|
: fKind(Kind::kInterfaceBlock) {
|
|
|
|
*(new(&fContents) InterfaceBlockData) = 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-13 14:30:20 +00:00
|
|
|
NodeData(ModifiersDeclarationData data)
|
|
|
|
: fKind(Kind::kModifiersDeclaration) {
|
|
|
|
*(new(&fContents) ModifiersDeclarationData) = data;
|
|
|
|
}
|
|
|
|
|
2020-10-12 20:58:40 +00:00
|
|
|
NodeData(const SectionData& data)
|
|
|
|
: fKind(Kind::kSection) {
|
|
|
|
*(new(&fContents) SectionData) = data;
|
|
|
|
}
|
|
|
|
|
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-12 20:11:51 +00:00
|
|
|
NodeData(const SwizzleData& data)
|
|
|
|
: fKind(Kind::kSwizzle) {
|
|
|
|
*(new(&fContents) SwizzleData) = 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-10-12 15:12:12 +00:00
|
|
|
NodeData(const TypeReferenceData& data)
|
|
|
|
: fKind(Kind::kTypeReference) {
|
|
|
|
*(new(&fContents) TypeReferenceData) = data;
|
|
|
|
}
|
|
|
|
|
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-09 20:51:18 +00:00
|
|
|
NodeData(const UnresolvedFunctionData& data)
|
|
|
|
: fKind(Kind::kUnresolvedFunction) {
|
|
|
|
*(new(&fContents) UnresolvedFunctionData) = data;
|
|
|
|
}
|
|
|
|
|
2020-10-13 17:49:44 +00:00
|
|
|
NodeData(const VarDeclarationData& data)
|
|
|
|
: fKind(Kind::kVarDeclaration) {
|
|
|
|
*(new(&fContents) VarDeclarationData) = 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-09 15:55:40 +00:00
|
|
|
case Kind::kFieldAccess:
|
|
|
|
*(new(&fContents) FieldAccessData) = other.fContents.fFieldAccess;
|
|
|
|
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-14 17:33:18 +00:00
|
|
|
case Kind::kFunctionDefinition:
|
|
|
|
*(new(&fContents) FunctionDefinitionData) = other.fContents.fFunctionDefinition;
|
|
|
|
break;
|
2020-10-12 15:12:12 +00:00
|
|
|
case Kind::kFunctionReference:
|
|
|
|
*(new(&fContents) FunctionReferenceData) = other.fContents.fFunctionReference;
|
|
|
|
break;
|
2020-10-07 20:47:09 +00:00
|
|
|
case Kind::kIfStatement:
|
|
|
|
*(new(&fContents) IfStatementData) = other.fContents.fIfStatement;
|
|
|
|
break;
|
2020-10-09 20:51:18 +00:00
|
|
|
case Kind::kInlineMarker:
|
|
|
|
*(new(&fContents) InlineMarkerData) = other.fContents.fInlineMarker;
|
|
|
|
break;
|
2020-10-15 14:10:08 +00:00
|
|
|
case Kind::kInterfaceBlock:
|
|
|
|
*(new(&fContents) InterfaceBlockData) = other.fContents.fInterfaceBlock;
|
|
|
|
break;
|
2020-09-28 20:27:18 +00:00
|
|
|
case Kind::kIntLiteral:
|
|
|
|
*(new(&fContents) IntLiteralData) = other.fContents.fIntLiteral;
|
|
|
|
break;
|
2020-10-13 14:30:20 +00:00
|
|
|
case Kind::kModifiersDeclaration:
|
|
|
|
*(new(&fContents) ModifiersDeclarationData) =
|
|
|
|
other.fContents.fModifiersDeclaration;
|
|
|
|
break;
|
2020-10-12 20:58:40 +00:00
|
|
|
case Kind::kSection:
|
|
|
|
*(new(&fContents) SectionData) = other.fContents.fSection;
|
|
|
|
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-12 20:11:51 +00:00
|
|
|
case Kind::kSwizzle:
|
|
|
|
*(new(&fContents) SwizzleData) = other.fContents.fSwizzle;
|
|
|
|
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;
|
2020-10-12 15:12:12 +00:00
|
|
|
case Kind::kTypeReference:
|
|
|
|
*(new(&fContents) TypeReferenceData) = other.fContents.fTypeReference;
|
|
|
|
break;
|
2020-09-28 20:27:18 +00:00
|
|
|
case Kind::kTypeToken:
|
|
|
|
*(new(&fContents) TypeTokenData) = other.fContents.fTypeToken;
|
|
|
|
break;
|
2020-10-09 20:51:18 +00:00
|
|
|
case Kind::kUnresolvedFunction:
|
|
|
|
*(new(&fContents) UnresolvedFunctionData) = other.fContents.fUnresolvedFunction;
|
|
|
|
break;
|
2020-10-13 17:49:44 +00:00
|
|
|
case Kind::kVarDeclaration:
|
|
|
|
*(new(&fContents) VarDeclarationData) = other.fContents.fVarDeclaration;
|
|
|
|
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-09 15:55:40 +00:00
|
|
|
case Kind::kFieldAccess:
|
|
|
|
fContents.fFieldAccess.~FieldAccessData();
|
|
|
|
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-09 20:51:18 +00:00
|
|
|
case Kind::kFunctionDeclaration:
|
|
|
|
fContents.fFunctionDeclaration.~FunctionDeclarationData();
|
|
|
|
break;
|
2020-10-14 17:33:18 +00:00
|
|
|
case Kind::kFunctionDefinition:
|
|
|
|
fContents.fFunctionDefinition.~FunctionDefinitionData();
|
|
|
|
break;
|
2020-10-12 15:12:12 +00:00
|
|
|
case Kind::kFunctionReference:
|
|
|
|
fContents.fFunctionReference.~FunctionReferenceData();
|
|
|
|
break;
|
2020-10-07 20:47:09 +00:00
|
|
|
case Kind::kIfStatement:
|
|
|
|
fContents.fIfStatement.~IfStatementData();
|
|
|
|
break;
|
2020-10-09 20:51:18 +00:00
|
|
|
case Kind::kInlineMarker:
|
|
|
|
fContents.fInlineMarker.~InlineMarkerData();
|
2020-10-08 15:45:44 +00:00
|
|
|
break;
|
2020-10-15 14:10:08 +00:00
|
|
|
case Kind::kInterfaceBlock:
|
|
|
|
fContents.fInterfaceBlock.~InterfaceBlockData();
|
|
|
|
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-13 14:30:20 +00:00
|
|
|
case Kind::kModifiersDeclaration:
|
|
|
|
fContents.fModifiersDeclaration.~ModifiersDeclarationData();
|
|
|
|
break;
|
2020-10-12 20:58:40 +00:00
|
|
|
case Kind::kSection:
|
|
|
|
fContents.fSection.~SectionData();
|
|
|
|
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-12 20:11:51 +00:00
|
|
|
case Kind::kSwizzle:
|
|
|
|
fContents.fSwizzle.~SwizzleData();
|
|
|
|
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;
|
2020-10-12 15:12:12 +00:00
|
|
|
case Kind::kTypeReference:
|
|
|
|
fContents.fTypeReference.~TypeReferenceData();
|
|
|
|
break;
|
2020-09-28 13:18:15 +00:00
|
|
|
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-09 20:51:18 +00:00
|
|
|
case Kind::kUnresolvedFunction:
|
|
|
|
fContents.fUnresolvedFunction.~UnresolvedFunctionData();
|
|
|
|
break;
|
2020-10-13 17:49:44 +00:00
|
|
|
case Kind::kVarDeclaration:
|
|
|
|
fContents.fVarDeclaration.~VarDeclarationData();
|
|
|
|
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-10-13 16:48:21 +00:00
|
|
|
IRNode(int offset, int kind, const BlockData& data, StatementArray stmts);
|
2020-09-28 13:18:15 +00:00
|
|
|
|
|
|
|
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-09 15:55:40 +00:00
|
|
|
IRNode(int offset, int kind, const FieldAccessData& 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-09 20:51:18 +00:00
|
|
|
IRNode(int offset, int kind, const FunctionDeclarationData& data);
|
|
|
|
|
2020-10-14 17:33:18 +00:00
|
|
|
IRNode(int offset, int kind, const FunctionDefinitionData& data);
|
|
|
|
|
2020-10-12 15:12:12 +00:00
|
|
|
IRNode(int offset, int kind, const FunctionReferenceData& data);
|
|
|
|
|
2020-10-07 20:47:09 +00:00
|
|
|
IRNode(int offset, int kind, const IfStatementData& data);
|
|
|
|
|
2020-10-09 20:51:18 +00:00
|
|
|
IRNode(int offset, int kind, const InlineMarkerData& data);
|
2020-10-08 15:45:44 +00:00
|
|
|
|
2020-10-15 14:10:08 +00:00
|
|
|
IRNode(int offset, int kind, const InterfaceBlockData& data);
|
|
|
|
|
2020-10-05 18:47:09 +00:00
|
|
|
IRNode(int offset, int kind, const IntLiteralData& data);
|
|
|
|
|
2020-10-13 14:30:20 +00:00
|
|
|
IRNode(int offset, int kind, const ModifiersDeclarationData& data);
|
|
|
|
|
2020-10-12 20:58:40 +00:00
|
|
|
IRNode(int offset, int kind, const SectionData& 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-12 20:11:51 +00:00
|
|
|
IRNode(int offset, int kind, const SwizzleData& 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-10-12 15:12:12 +00:00
|
|
|
IRNode(int offset, int kind, const TypeReferenceData& data);
|
|
|
|
|
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-09 20:51:18 +00:00
|
|
|
IRNode(int offset, int kind, const UnresolvedFunctionData& data);
|
|
|
|
|
2020-10-13 17:49:44 +00:00
|
|
|
IRNode(int offset, int kind, const VarDeclarationData& data);
|
|
|
|
|
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-09 15:55:40 +00:00
|
|
|
const FieldAccessData& fieldAccessData() const {
|
|
|
|
SkASSERT(fData.fKind == NodeData::Kind::kFieldAccess);
|
|
|
|
return fData.fContents.fFieldAccess;
|
|
|
|
}
|
|
|
|
|
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-09 20:51:18 +00:00
|
|
|
const FunctionDeclarationData& functionDeclarationData() const {
|
|
|
|
SkASSERT(fData.fKind == NodeData::Kind::kFunctionDeclaration);
|
|
|
|
return fData.fContents.fFunctionDeclaration;
|
|
|
|
}
|
|
|
|
|
2020-10-14 17:33:18 +00:00
|
|
|
FunctionDefinitionData& functionDefinitionData() {
|
|
|
|
SkASSERT(fData.fKind == NodeData::Kind::kFunctionDefinition);
|
|
|
|
return fData.fContents.fFunctionDefinition;
|
|
|
|
}
|
|
|
|
|
|
|
|
const FunctionDefinitionData& functionDefinitionData() const {
|
|
|
|
SkASSERT(fData.fKind == NodeData::Kind::kFunctionDefinition);
|
|
|
|
return fData.fContents.fFunctionDefinition;
|
|
|
|
}
|
|
|
|
|
2020-10-12 15:12:12 +00:00
|
|
|
const FunctionReferenceData& functionReferenceData() const {
|
|
|
|
SkASSERT(fData.fKind == NodeData::Kind::kFunctionReference);
|
|
|
|
return fData.fContents.fFunctionReference;
|
|
|
|
}
|
|
|
|
|
2020-10-07 20:47:09 +00:00
|
|
|
const IfStatementData& ifStatementData() const {
|
|
|
|
SkASSERT(fData.fKind == NodeData::Kind::kIfStatement);
|
|
|
|
return fData.fContents.fIfStatement;
|
|
|
|
}
|
|
|
|
|
2020-10-09 20:51:18 +00:00
|
|
|
const InlineMarkerData& inlineMarkerData() const {
|
|
|
|
SkASSERT(fData.fKind == NodeData::Kind::kInlineMarker);
|
|
|
|
return fData.fContents.fInlineMarker;
|
2020-10-08 15:45:44 +00:00
|
|
|
}
|
|
|
|
|
2020-10-15 14:10:08 +00:00
|
|
|
InterfaceBlockData& interfaceBlockData() {
|
|
|
|
SkASSERT(fData.fKind == NodeData::Kind::kInterfaceBlock);
|
|
|
|
return fData.fContents.fInterfaceBlock;
|
|
|
|
}
|
|
|
|
|
|
|
|
const InterfaceBlockData& interfaceBlockData() const {
|
|
|
|
SkASSERT(fData.fKind == NodeData::Kind::kInterfaceBlock);
|
|
|
|
return fData.fContents.fInterfaceBlock;
|
|
|
|
}
|
|
|
|
|
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-13 14:30:20 +00:00
|
|
|
const ModifiersDeclarationData& modifiersDeclarationData() const {
|
|
|
|
SkASSERT(fData.fKind == NodeData::Kind::kModifiersDeclaration);
|
|
|
|
return fData.fContents.fModifiersDeclaration;
|
|
|
|
}
|
|
|
|
|
2020-10-12 20:58:40 +00:00
|
|
|
const SectionData& sectionData() const {
|
|
|
|
SkASSERT(fData.fKind == NodeData::Kind::kSection);
|
|
|
|
return fData.fContents.fSection;
|
|
|
|
}
|
|
|
|
|
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-12 20:11:51 +00:00
|
|
|
SwizzleData& swizzleData() {
|
|
|
|
SkASSERT(fData.fKind == NodeData::Kind::kSwizzle);
|
|
|
|
return fData.fContents.fSwizzle;
|
|
|
|
}
|
|
|
|
|
|
|
|
const SwizzleData& swizzleData() const {
|
|
|
|
SkASSERT(fData.fKind == NodeData::Kind::kSwizzle);
|
|
|
|
return fData.fContents.fSwizzle;
|
|
|
|
}
|
|
|
|
|
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-10-12 15:12:12 +00:00
|
|
|
const TypeReferenceData& typeReferenceData() const {
|
|
|
|
SkASSERT(fData.fKind == NodeData::Kind::kTypeReference);
|
|
|
|
return fData.fContents.fTypeReference;
|
|
|
|
}
|
|
|
|
|
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-09 20:51:18 +00:00
|
|
|
const UnresolvedFunctionData& unresolvedFunctionData() const {
|
|
|
|
SkASSERT(fData.fKind == NodeData::Kind::kUnresolvedFunction);
|
|
|
|
return fData.fContents.fUnresolvedFunction;
|
|
|
|
}
|
|
|
|
|
2020-10-13 17:49:44 +00:00
|
|
|
VarDeclarationData& varDeclarationData() {
|
|
|
|
SkASSERT(fData.fKind == NodeData::Kind::kVarDeclaration);
|
|
|
|
return fData.fContents.fVarDeclaration;
|
|
|
|
}
|
|
|
|
|
|
|
|
const VarDeclarationData& varDeclarationData() const {
|
|
|
|
SkASSERT(fData.fKind == NodeData::Kind::kVarDeclaration);
|
|
|
|
return fData.fContents.fVarDeclaration;
|
|
|
|
}
|
|
|
|
|
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.
|
2020-10-13 15:14:08 +00:00
|
|
|
ExpressionArray fExpressionChildren;
|
2020-10-13 16:48:21 +00:00
|
|
|
// it's important to keep the statement array defined after (and thus destroyed before) fData,
|
2020-09-25 18:31:59 +00:00
|
|
|
// because destroying statements can modify reference counts in a SymbolTable contained in fData
|
2020-10-13 16:48:21 +00:00
|
|
|
StatementArray 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
|