// // Copyright 2002 The ANGLE Project Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. //
// // Definition of the in-memory high-level intermediate representation // of shaders. This is a tree that parser creates. // // Nodes in the tree are defined as a hierarchy of classes derived from // TIntermNode. Each is a node in a tree. There is no preset branching factor; // each node can have it's own type of list of children. //
class TIntermTraverser; class TIntermAggregate; class TIntermBlock; class TIntermGlobalQualifierDeclaration; class TIntermDeclaration; class TIntermFunctionPrototype; class TIntermFunctionDefinition; class TIntermSwizzle; class TIntermBinary; class TIntermUnary; class TIntermConstantUnion; class TIntermTernary; class TIntermIfElse; class TIntermSwitch; class TIntermCase; class TIntermTyped; class TIntermSymbol; class TIntermLoop; class TInfoSink; class TInfoSinkBase; class TIntermBranch; class TIntermPreprocessorDirective;
class TSymbolTable; class TFunction; class TVariable;
// // Base class for the tree nodes // class TIntermNode : angle::NonCopyable
{ public:
POOL_ALLOCATOR_NEW_DELETE
TIntermNode()
{ // TODO: Move this to TSourceLoc constructor // after getting rid of TPublicType.
mLine.first_file = mLine.last_file = 0;
mLine.first_line = mLine.last_line = 0;
} virtual ~TIntermNode() {}
// getConstantValue() returns the constant value that this node represents, if any. It // should only be used after nodes have been replaced with their folded versions returned // from fold(). hasConstantValue() returns true if getConstantValue() will return a value. virtualbool hasConstantValue() const; virtualbool isConstantNullValue() const; virtualconst TConstantUnion *getConstantValue() const;
// True if executing the expression represented by this node affects state, like values of // variables. False if the executing the expression only computes its return value without // affecting state. May return true conservatively. virtualbool hasSideEffects() const = 0;
virtualconst TType &getType() const = 0;
// Derive the precision of the node based on its children's. virtual TPrecision derivePrecision() const; // Set precision of the current node and propagate it to any child node that doesn't have // precision. This should be the case only for TIntermConstantUnion nodes as every other node // would already need to have its precision specified or derived. virtualvoid propagatePrecision(TPrecision precision);
// After every transformation is done and just before outputting the tree (i.e. when the tree // nodes are no longer going to change), the tree is traversed to gather some information to be // stored in the intermediate nodes: // // - Precise-ness, which is set for arithmetic nodes that are involved in the calculation of a // value assigned to a |precise| variable. void setIsPrecise() { mIsPrecise = true; } bool isPrecise() const { return mIsPrecise; }
protected:
TOperator mFlowOp;
TIntermTyped *mExpression; // zero except for "return exp;" statements
private:
TIntermBranch(const TIntermBranch &);
};
// Nodes that correspond to variable symbols in the source code. These may be regular variables or // interface block instances. In declarations that only declare a struct type but no variables, a // TIntermSymbol node with an empty variable is used to store the type. class TIntermSymbol : public TIntermTyped
{ public:
TIntermSymbol(const TVariable *variable);
private:
TIntermSymbol(const TIntermSymbol &) = default; // Note: not deleted, just private! void propagatePrecision(TPrecision precision) override;
const TVariable *const mVariable; // Guaranteed to be non-null
};
// A typed expression that is not just representing a symbol table symbol. class TIntermExpression : public TIntermTyped
{ public:
TIntermExpression(const TType &t);
// Constant folded node. // Note that nodes may be constant folded and not be constant expressions with the EvqConst // qualifier. This happens for example when the following expression is processed: // "true ? 1.0 : non_constant" // Other nodes than TIntermConstantUnion may also be constant expressions. // class TIntermConstantUnion : public TIntermExpression
{ public:
TIntermConstantUnion(const TConstantUnion *unionPointer, const TType &type)
: TIntermExpression(type), mUnionArrayPointer(unionPointer)
{
ASSERT(unionPointer);
}
TIntermConstantUnion(const TIntermConstantUnion &node); // Note: not deleted, just private!
};
// // Intermediate class for node types that hold operators. // class TIntermOperator : public TIntermExpression
{ public:
TOperator getOp() const { return mOp; }
// Node for vector swizzles. class TIntermSwizzle : public TIntermExpression
{ public: // This constructor determines the type of the node based on the operand.
TIntermSwizzle(TIntermTyped *operand, const TVector<int> &swizzleOffsets);
TIntermSwizzle(const TIntermSwizzle &node); // Note: not deleted, just private!
};
// // Nodes for all the basic binary math operators. // class TIntermBinary : public TIntermOperator
{ public: // This constructor determines the type of the binary node based on the operands and op.
TIntermBinary(TOperator op, TIntermTyped *left, TIntermTyped *right); // Comma qualifier depends on the shader version, so use this to create comma nodes: static TIntermBinary *CreateComma(TIntermTyped *left, TIntermTyped *right, int shaderVersion);
// // Nodes that operate on an arbitrary sized set of children. // class TIntermAggregate : public TIntermOperator, public TIntermAggregateBase
{ public: static TIntermAggregate *CreateFunctionCall(const TFunction &func, TIntermSequence *arguments);
// Get the function name to display to the user in an error message. constchar *functionName() const;
protected:
TIntermSequence mArguments;
// If set to true, replace the built-in function call with an emulated one // to work around driver bugs. Only for calls mapped to ops other than EOpCall*. bool mUseEmulatedFunction;
// A list of statements. Either the root node which contains declarations and function definitions, // or a block that can be marked with curly braces {}. class TIntermBlock : public TIntermNode, public TIntermAggregateBase
{ public:
TIntermBlock() : TIntermNode(), mIsTreeRoot(false) {}
TIntermBlock(std::initializer_list<TIntermNode *> stmts);
~TIntermBlock() override {}
// Only intended for initially building the block. void appendStatement(TIntermNode *statement); void insertStatement(size_t insertPosition, TIntermNode *statement);
// Used to distinguish the tree root from the other blocks. When validating the AST, some // validations are not applicable if not run on the entire tree and are thus skipped. bool mIsTreeRoot;
private:
TIntermBlock(const TIntermBlock &);
};
// Function prototype. May be in the AST either as a function prototype declaration or as a part of // a function definition. The type of the node is the function return type. class TIntermFunctionPrototype : public TIntermTyped
{ public:
TIntermFunctionPrototype(const TFunction *function);
~TIntermFunctionPrototype() override {}
// Node for function definitions. The prototype child node stores the function header including // parameters, and the body child node stores the function body. class TIntermFunctionDefinition : public TIntermNode
{ public:
TIntermFunctionDefinition(TIntermFunctionPrototype *prototype, TIntermBlock *body)
: TIntermNode(), mPrototype(prototype), mBody(body)
{
ASSERT(prototype != nullptr);
ASSERT(body != nullptr);
}
// Only intended for initially building the declaration. // The declarator node should be either TIntermSymbol or TIntermBinary with op set to // EOpInitialize. void appendDeclarator(TIntermTyped *declarator);
TIntermDeclaration *deepCopy() const override
{ // Note: This is only useful as support for deepCopy of TIntermBlock and TIntermLoop, but is // not sufficient as it will be redeclaring the same TVariable. If a function body is // duplicated for example, it means that both functions reference the same TVariable pointer // which works, but is technically not correct. In particular, maps with TVariable * as key // can get confused. // // After deepCopy() is issued, ReplaceVariables must be used to replace every declared // variable with a duplicate. This is NOT automatically done when deepCopy-ing TIntermBlock // and TIntermLoop nodes. returnnew TIntermDeclaration(*this);
}
// For ternary operators like a ? b : c. class TIntermTernary : public TIntermExpression
{ public:
TIntermTernary(TIntermTyped *cond, TIntermTyped *trueExpression, TIntermTyped *falseExpression);
class TIntermPreprocessorDirective final : public TIntermNode
{ public: // This could also take an ImmutableString as an argument.
TIntermPreprocessorDirective(PreprocessorDirective directive, ImmutableString command);
~TIntermPreprocessorDirective() final;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.