Parser - Clean-up in AST node definitions
This commit is contained in:
parent
7abf50ae61
commit
d944ff80f3
3 changed files with 362 additions and 314 deletions
40
opast.cc
40
opast.cc
|
@ -258,6 +258,46 @@ A_Node* opast::ASTVisitorBrowser(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*= E_DataType ===============================================================*/
|
||||||
|
|
||||||
|
T_StringBuilder& opast::operator<<(
|
||||||
|
T_StringBuilder& sb ,
|
||||||
|
const E_DataType dt )
|
||||||
|
{
|
||||||
|
switch ( dt ) {
|
||||||
|
case E_DataType::UNKNOWN:
|
||||||
|
sb << "unknown";
|
||||||
|
return sb;
|
||||||
|
case E_DataType::BUILTIN:
|
||||||
|
sb << "built-in variable";
|
||||||
|
return sb;
|
||||||
|
case E_DataType::VARIABLE:
|
||||||
|
sb << "variable";
|
||||||
|
return sb;
|
||||||
|
case E_DataType::FRAMEBUFFER:
|
||||||
|
sb << "framebuffer";
|
||||||
|
return sb;
|
||||||
|
case E_DataType::INPUT:
|
||||||
|
sb << "input";
|
||||||
|
return sb;
|
||||||
|
case E_DataType::PIPELINE:
|
||||||
|
sb << "pipeline";
|
||||||
|
return sb;
|
||||||
|
case E_DataType::PROGRAM:
|
||||||
|
sb << "program";
|
||||||
|
return sb;
|
||||||
|
case E_DataType::SAMPLER:
|
||||||
|
sb << "sampler";
|
||||||
|
return sb;
|
||||||
|
case E_DataType::TEXTURE:
|
||||||
|
sb << "texture";
|
||||||
|
return sb;
|
||||||
|
}
|
||||||
|
|
||||||
|
sb << "*unknown data type*";
|
||||||
|
return sb;
|
||||||
|
}
|
||||||
|
|
||||||
/*= A_FuncNode ===============================================================*/
|
/*= A_FuncNode ===============================================================*/
|
||||||
|
|
||||||
A_FuncNode::A_FuncNode(
|
A_FuncNode::A_FuncNode(
|
||||||
|
|
628
opast.hh
628
opast.hh
|
@ -7,6 +7,9 @@ namespace opast {
|
||||||
|
|
||||||
using namespace ebcl;
|
using namespace ebcl;
|
||||||
|
|
||||||
|
|
||||||
|
/*= BASE CLASS FOR AST NODES ===================================================*/
|
||||||
|
|
||||||
class T_RootNode;
|
class T_RootNode;
|
||||||
|
|
||||||
class A_Node
|
class A_Node
|
||||||
|
@ -91,7 +94,22 @@ extern A_Node* ASTVisitorBrowser(
|
||||||
A_Node& node ,
|
A_Node& node ,
|
||||||
const uint32_t child ) noexcept;
|
const uint32_t child ) noexcept;
|
||||||
|
|
||||||
/*============================================================================*/
|
// Data types
|
||||||
|
enum class E_DataType {
|
||||||
|
UNKNOWN ,
|
||||||
|
BUILTIN ,
|
||||||
|
VARIABLE ,
|
||||||
|
FRAMEBUFFER ,
|
||||||
|
INPUT ,
|
||||||
|
PIPELINE ,
|
||||||
|
PROGRAM ,
|
||||||
|
SAMPLER ,
|
||||||
|
TEXTURE ,
|
||||||
|
};
|
||||||
|
M_LSHIFT_OP( T_StringBuilder , E_DataType );
|
||||||
|
|
||||||
|
|
||||||
|
/*= BASE STRUCTURES FOR INSTRUCTIONS =========================================*/
|
||||||
|
|
||||||
// Some instructions are restricted to either the initialisation code or the
|
// Some instructions are restricted to either the initialisation code or the
|
||||||
// frame code.
|
// frame code.
|
||||||
|
@ -124,7 +142,6 @@ class A_InstructionNode : public A_Node
|
||||||
{ return restriction_; }
|
{ return restriction_; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Nodes that store lists of instructions
|
// Nodes that store lists of instructions
|
||||||
class T_InstrListNode : public A_Node
|
class T_InstrListNode : public A_Node
|
||||||
{
|
{
|
||||||
|
@ -157,7 +174,21 @@ template<
|
||||||
return (IType&) *instructions_.last( );
|
return (IType&) *instructions_.last( );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
// Base class for expressions
|
||||||
|
class A_ExpressionNode : public A_Node
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
A_ExpressionNode( E_Type type ,
|
||||||
|
A_Node& parent ) noexcept
|
||||||
|
: A_Node( type , &parent )
|
||||||
|
{ }
|
||||||
|
};
|
||||||
|
using P_ExpressionNode = T_OwnPtr< A_ExpressionNode >;
|
||||||
|
|
||||||
|
|
||||||
|
/*= FUNCTIONS AND ROOT NODES =================================================*/
|
||||||
|
|
||||||
// Function-like nodes
|
// Function-like nodes
|
||||||
class A_FuncNode : public A_Node
|
class A_FuncNode : public A_Node
|
||||||
|
@ -188,6 +219,8 @@ class A_FuncNode : public A_Node
|
||||||
};
|
};
|
||||||
using P_InstrListNode = T_OwnPtr< T_InstrListNode >;
|
using P_InstrListNode = T_OwnPtr< T_InstrListNode >;
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
// Root node, keeps track of the whole tree and related data (function table,
|
// Root node, keeps track of the whole tree and related data (function table,
|
||||||
// assets...)
|
// assets...)
|
||||||
class T_RootNode : public A_Node
|
class T_RootNode : public A_Node
|
||||||
|
@ -278,20 +311,8 @@ class T_FuncNode : public A_FuncNode
|
||||||
{ return argNames_.size( ); }
|
{ return argNames_.size( ); }
|
||||||
};
|
};
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
// Base class for expressions
|
/*= GENERAL / FLOW CONTROL INSTRUCTIONS ========================================*/
|
||||||
class A_ExpressionNode : public A_Node
|
|
||||||
{
|
|
||||||
protected:
|
|
||||||
A_ExpressionNode( E_Type type ,
|
|
||||||
A_Node& parent ) noexcept
|
|
||||||
: A_Node( type , &parent )
|
|
||||||
{ }
|
|
||||||
};
|
|
||||||
using P_ExpressionNode = T_OwnPtr< A_ExpressionNode >;
|
|
||||||
|
|
||||||
/*============================================================================*/
|
|
||||||
|
|
||||||
// Function call
|
// Function call
|
||||||
class T_CallInstrNode : public A_InstructionNode
|
class T_CallInstrNode : public A_InstructionNode
|
||||||
|
@ -327,28 +348,6 @@ class T_CallInstrNode : public A_InstructionNode
|
||||||
{ return *arguments_[ index ]; }
|
{ return *arguments_[ index ]; }
|
||||||
};
|
};
|
||||||
|
|
||||||
// Clear instruction
|
|
||||||
class T_ClearInstrNode : public A_InstructionNode
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
T_StaticArray< P_ExpressionNode , 4 > components_;
|
|
||||||
|
|
||||||
public:
|
|
||||||
T_ClearInstrNode( T_InstrListNode& parent ) noexcept
|
|
||||||
: A_InstructionNode( OP_CLEAR , parent ,
|
|
||||||
E_InstrRestriction::INIT )
|
|
||||||
{ }
|
|
||||||
|
|
||||||
void addComponent( P_ExpressionNode expr ) noexcept
|
|
||||||
{ if ( expr ) { components_.add( std::move( expr ) ); } }
|
|
||||||
|
|
||||||
uint32_t components( ) const noexcept
|
|
||||||
{ return components_.size( ); }
|
|
||||||
|
|
||||||
A_ExpressionNode& component( const uint32_t index ) const noexcept
|
|
||||||
{ return *components_[ index ]; }
|
|
||||||
};
|
|
||||||
|
|
||||||
// Conditional instruction
|
// Conditional instruction
|
||||||
class T_CondInstrNode : public A_InstructionNode
|
class T_CondInstrNode : public A_InstructionNode
|
||||||
{
|
{
|
||||||
|
@ -395,8 +394,98 @@ class T_CondInstrNode : public A_InstructionNode
|
||||||
{ return *defaultCase_; }
|
{ return *defaultCase_; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Local variable declarations
|
||||||
|
class T_LocalsInstrNode : public A_InstructionNode
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
T_AutoArray< T_String , 8 > vars_;
|
||||||
|
T_AutoArray< T_SRDLocation , 8 > varLocs_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
T_LocalsInstrNode( T_InstrListNode& parent ) noexcept
|
||||||
|
: A_InstructionNode( OP_LOCALS , parent )
|
||||||
|
{ }
|
||||||
|
|
||||||
|
bool addVariable( T_SRDToken const& token ) noexcept;
|
||||||
|
|
||||||
|
uint32_t variables( ) const noexcept
|
||||||
|
{ return vars_.size( ); }
|
||||||
|
|
||||||
|
T_String const& varName(
|
||||||
|
const uint32_t index ) const noexcept
|
||||||
|
{ return vars_[ index ]; }
|
||||||
|
|
||||||
|
T_SRDLocation const& varLocation(
|
||||||
|
const uint32_t index ) const noexcept
|
||||||
|
{ return varLocs_[ index ]; }
|
||||||
|
};
|
||||||
|
|
||||||
|
// Setting a global variable
|
||||||
|
class T_SetInstrNode : public A_InstructionNode
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
T_String id_;
|
||||||
|
T_SRDLocation idLocation_;
|
||||||
|
P_ExpressionNode expression_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
T_SetInstrNode( T_InstrListNode& parent ,
|
||||||
|
T_SRDToken const& idToken ) noexcept
|
||||||
|
: A_InstructionNode( OP_SET , parent ) ,
|
||||||
|
id_( idToken.stringValue( ) ) ,
|
||||||
|
idLocation_( idToken.location( ) )
|
||||||
|
{ }
|
||||||
|
|
||||||
|
T_String const& id( ) const noexcept
|
||||||
|
{ return id_; }
|
||||||
|
T_SRDLocation const& idLocation( ) const noexcept
|
||||||
|
{ return idLocation_; }
|
||||||
|
|
||||||
|
void setExpression( P_ExpressionNode expression ) noexcept
|
||||||
|
{ expression_ = std::move( expression ); }
|
||||||
|
bool hasExpression( ) const noexcept
|
||||||
|
{ return bool( expression_ ); }
|
||||||
|
A_ExpressionNode& expression( ) const noexcept
|
||||||
|
{ return *expression_; }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*= RESOURCE DEFINITION INSTRUCTIONS =========================================*/
|
||||||
|
|
||||||
|
// Base class
|
||||||
|
class A_ResourceDefInstrNode : public A_InstructionNode
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
T_String id_;
|
||||||
|
T_SRDLocation idLocation_;
|
||||||
|
E_DataType dataType_;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
A_ResourceDefInstrNode(
|
||||||
|
const E_Type type ,
|
||||||
|
T_InstrListNode& parent ,
|
||||||
|
T_SRDToken const& identifier ,
|
||||||
|
const E_DataType dataType ) noexcept
|
||||||
|
: A_InstructionNode( type , parent , E_InstrRestriction::FRAME ) ,
|
||||||
|
id_( identifier.stringValue( ) ) ,
|
||||||
|
idLocation_( identifier.location( ) ) ,
|
||||||
|
dataType_( dataType )
|
||||||
|
{ }
|
||||||
|
|
||||||
|
public:
|
||||||
|
T_String const& id( ) const noexcept
|
||||||
|
{ return id_; }
|
||||||
|
T_SRDLocation const& idLocation( ) const noexcept
|
||||||
|
{ return idLocation_; }
|
||||||
|
|
||||||
|
E_DataType dataType( ) const noexcept
|
||||||
|
{ return dataType_; }
|
||||||
|
};
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
// Framebuffer definition instruction
|
// Framebuffer definition instruction
|
||||||
class T_FramebufferInstrNode : public A_InstructionNode
|
class T_FramebufferInstrNode : public A_ResourceDefInstrNode
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
struct T_Attachment_
|
struct T_Attachment_
|
||||||
|
@ -406,9 +495,6 @@ class T_FramebufferInstrNode : public A_InstructionNode
|
||||||
T_SRDLocation location;
|
T_SRDLocation location;
|
||||||
};
|
};
|
||||||
|
|
||||||
T_String idFramebuffer_;
|
|
||||||
T_SRDLocation locFramebuffer_;
|
|
||||||
|
|
||||||
T_AutoArray< T_Attachment_ , 8 > colorAttachments_;
|
T_AutoArray< T_Attachment_ , 8 > colorAttachments_;
|
||||||
T_Optional< T_Attachment_ > depthAttachment_;
|
T_Optional< T_Attachment_ > depthAttachment_;
|
||||||
|
|
||||||
|
@ -417,20 +503,12 @@ class T_FramebufferInstrNode : public A_InstructionNode
|
||||||
public:
|
public:
|
||||||
T_FramebufferInstrNode( T_InstrListNode& parent ,
|
T_FramebufferInstrNode( T_InstrListNode& parent ,
|
||||||
T_SRDToken const& identifier ) noexcept
|
T_SRDToken const& identifier ) noexcept
|
||||||
: A_InstructionNode( OP_FRAMEBUFFER , parent , E_InstrRestriction::FRAME ) ,
|
: A_ResourceDefInstrNode( OP_FRAMEBUFFER , parent ,
|
||||||
idFramebuffer_( identifier.stringValue( ) ) ,
|
identifier , E_DataType::FRAMEBUFFER )
|
||||||
locFramebuffer_( identifier.location( ) )
|
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
T_String const& id( ) const noexcept
|
|
||||||
{ return idFramebuffer_; }
|
|
||||||
T_SRDLocation const& idLocation( ) const noexcept
|
|
||||||
{ return locFramebuffer_; }
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
|
||||||
|
|
||||||
bool addColorAttachment( T_SRDToken const& id ,
|
bool addColorAttachment( T_SRDToken const& id ,
|
||||||
P_ExpressionNode lod = {} ) noexcept;
|
P_ExpressionNode lod = {} ) noexcept;
|
||||||
|
|
||||||
|
@ -465,85 +543,205 @@ class T_FramebufferInstrNode : public A_InstructionNode
|
||||||
{ return depthAttachment_->location; }
|
{ return depthAttachment_->location; }
|
||||||
};
|
};
|
||||||
|
|
||||||
// Fullscreen quad instruction
|
|
||||||
class T_FullscreenInstrNode : public A_InstructionNode
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
T_FullscreenInstrNode( T_InstrListNode& parent ) noexcept
|
|
||||||
: A_InstructionNode( OP_FULLSCREEN , parent , E_InstrRestriction::INIT )
|
|
||||||
{ }
|
|
||||||
};
|
|
||||||
|
|
||||||
// Input declaration
|
// Input declaration
|
||||||
class T_InputInstrNode : public A_InstructionNode
|
class T_InputInstrNode : public A_ResourceDefInstrNode
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
T_String name_;
|
|
||||||
T_SRDLocation nameLocation_;
|
|
||||||
float defValue_;
|
float defValue_;
|
||||||
T_SRDLocation dvLocation_;
|
T_SRDLocation dvLocation_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
T_InputInstrNode( T_InstrListNode& parent ,
|
T_InputInstrNode( T_InstrListNode& parent ,
|
||||||
T_SRDToken const& tName ) noexcept
|
T_SRDToken const& tName ) noexcept
|
||||||
: A_InstructionNode( OP_INPUT , parent , E_InstrRestriction::FRAME ) ,
|
: A_ResourceDefInstrNode( OP_INPUT , parent ,
|
||||||
name_( tName.stringValue( ) ) , nameLocation_( tName.location( ) )
|
tName , E_DataType::INPUT )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
T_InputInstrNode( T_InstrListNode& parent ,
|
T_InputInstrNode( T_InstrListNode& parent ,
|
||||||
T_SRDToken const& tName ,
|
T_SRDToken const& tName ,
|
||||||
T_SRDToken const& tDefault ) noexcept
|
T_SRDToken const& tDefault ) noexcept
|
||||||
: A_InstructionNode( OP_INPUT , parent , E_InstrRestriction::FRAME ) ,
|
: A_ResourceDefInstrNode( OP_INPUT , parent ,
|
||||||
name_( tName.stringValue( ) ) , nameLocation_( tName.location( ) ) ,
|
tName , E_DataType::INPUT ) ,
|
||||||
defValue_( tDefault.floatValue( ) ) , dvLocation_( tDefault.location( ) )
|
defValue_( tDefault.floatValue( ) ) , dvLocation_( tDefault.location( ) )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
T_String const& name( ) const noexcept
|
|
||||||
{ return name_; }
|
|
||||||
T_SRDLocation const& nameLocation( ) const noexcept
|
|
||||||
{ return nameLocation_; }
|
|
||||||
|
|
||||||
float defValue( ) const noexcept
|
float defValue( ) const noexcept
|
||||||
{ return defValue_; }
|
{ return defValue_; }
|
||||||
T_SRDLocation const& defValueLocation( ) const noexcept
|
T_SRDLocation const& defValueLocation( ) const noexcept
|
||||||
{ return dvLocation_; }
|
{ return dvLocation_; }
|
||||||
};
|
};
|
||||||
|
|
||||||
// Local variable declarations
|
// Pipeline declaration instruction
|
||||||
class T_LocalsInstrNode : public A_InstructionNode
|
class T_PipelineInstrNode : public A_ResourceDefInstrNode
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
T_AutoArray< T_String , 8 > vars_;
|
T_StaticArray< T_String , 6 > pids_;
|
||||||
T_AutoArray< T_SRDLocation , 8 > varLocs_;
|
T_StaticArray< T_SRDLocation , 6 > pidLocations_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
T_LocalsInstrNode( T_InstrListNode& parent ) noexcept
|
T_PipelineInstrNode(
|
||||||
: A_InstructionNode( OP_LOCALS , parent )
|
T_InstrListNode& parent ,
|
||||||
|
T_SRDToken const& idToken ) noexcept
|
||||||
|
: A_ResourceDefInstrNode( OP_PIPELINE , parent ,
|
||||||
|
idToken , E_DataType::PIPELINE )
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
bool addVariable( T_SRDToken const& token ) noexcept;
|
// Add a program identifier. The token is assumed to be a valid word,
|
||||||
|
// and the list of programs is assumed not to be full. If the identifer
|
||||||
|
// is already in the pipeline's list, the location of the first
|
||||||
|
// occurrence will be returned.
|
||||||
|
T_Optional< T_SRDLocation > addProgram(
|
||||||
|
T_SRDToken const& pidToken ) noexcept;
|
||||||
|
|
||||||
uint32_t variables( ) const noexcept
|
uint32_t size( ) const noexcept
|
||||||
{ return vars_.size( ); }
|
{ return pids_.size( ); }
|
||||||
|
|
||||||
T_String const& varName(
|
T_String const& program( const uint32_t index ) const noexcept
|
||||||
const uint32_t index ) const noexcept
|
{ return pids_[ index ]; }
|
||||||
{ return vars_[ index ]; }
|
T_SRDLocation const& pLocation( const uint32_t index ) const noexcept
|
||||||
|
{ return pidLocations_[ index ]; }
|
||||||
T_SRDLocation const& varLocation(
|
|
||||||
const uint32_t index ) const noexcept
|
|
||||||
{ return varLocs_[ index ]; }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Main output selection
|
// Program loader instruction
|
||||||
class T_MainOutputInstrNode : public A_InstructionNode
|
class T_ProgramInstrNode : public A_ResourceDefInstrNode
|
||||||
{
|
{
|
||||||
|
private:
|
||||||
|
T_String path_;
|
||||||
|
T_SRDLocation pathLocation_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
T_MainOutputInstrNode( T_InstrListNode& parent ) noexcept
|
T_ProgramInstrNode(
|
||||||
: A_InstructionNode( OP_MAINOUT , parent , E_InstrRestriction::INIT )
|
T_InstrListNode& parent ,
|
||||||
|
T_SRDToken const& idToken ,
|
||||||
|
T_SRDToken const& pathToken ) noexcept
|
||||||
|
: A_ResourceDefInstrNode( OP_PROGRAM , parent ,
|
||||||
|
idToken , E_DataType::PROGRAM ) ,
|
||||||
|
path_( pathToken.stringValue( ) ) ,
|
||||||
|
pathLocation_( pathToken.location( ) )
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
T_String const& path( ) const noexcept
|
||||||
|
{ return path_; }
|
||||||
|
T_SRDLocation const& pathLocation( ) const noexcept
|
||||||
|
{ return pathLocation_; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Sampler definition
|
||||||
|
class T_SamplerInstrNode : public A_ResourceDefInstrNode
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
struct T_Sampling_
|
||||||
|
{
|
||||||
|
T_SRDLocation location;
|
||||||
|
E_TexSampling mode;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct T_Mipmaps_
|
||||||
|
{
|
||||||
|
T_SRDLocation location;
|
||||||
|
T_Optional< E_TexSampling > mode;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct T_Wrapping_
|
||||||
|
{
|
||||||
|
T_SRDLocation location;
|
||||||
|
E_TexWrap mode;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct T_LOD_
|
||||||
|
{
|
||||||
|
T_SRDLocation location;
|
||||||
|
P_ExpressionNode min;
|
||||||
|
P_ExpressionNode max;
|
||||||
|
};
|
||||||
|
|
||||||
|
T_Optional< T_Sampling_ > sampling_;
|
||||||
|
T_Optional< T_Mipmaps_ > mipmaps_;
|
||||||
|
T_Optional< T_Wrapping_ > wrapping_;
|
||||||
|
T_Optional< T_LOD_ > lod_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
T_SamplerInstrNode(
|
||||||
|
T_InstrListNode& parent ,
|
||||||
|
T_SRDToken const& id ) noexcept
|
||||||
|
: A_ResourceDefInstrNode( OP_SAMPLER , parent ,
|
||||||
|
id , E_DataType::SAMPLER )
|
||||||
|
{ }
|
||||||
|
|
||||||
|
// Attempt to set sampling mode, mipmap mode, wrapping mode or
|
||||||
|
// LOD minimal/maximal, returning the location of the previous
|
||||||
|
// definition if there was one.
|
||||||
|
T_Optional< T_SRDLocation > setSampling(
|
||||||
|
E_TexSampling mode ,
|
||||||
|
T_SRDLocation const& location ) noexcept;
|
||||||
|
T_Optional< T_SRDLocation > setMipmapSampling(
|
||||||
|
E_TexSampling mode ,
|
||||||
|
T_SRDLocation const& location ) noexcept;
|
||||||
|
T_Optional< T_SRDLocation > setNoMipmap(
|
||||||
|
T_SRDLocation const& location ) noexcept;
|
||||||
|
T_Optional< T_SRDLocation > setWrapping(
|
||||||
|
E_TexWrap mode ,
|
||||||
|
T_SRDLocation const& location ) noexcept;
|
||||||
|
T_Optional< T_SRDLocation > setLOD(
|
||||||
|
T_SRDLocation const& location ,
|
||||||
|
P_ExpressionNode min ,
|
||||||
|
P_ExpressionNode max ) noexcept;
|
||||||
|
|
||||||
|
// Get either the defined values or the defaults
|
||||||
|
E_TexSampling sampling( ) const noexcept
|
||||||
|
{ return sampling_ ? sampling_->mode : E_TexSampling::NEAREST; }
|
||||||
|
T_Optional< E_TexSampling > mipmap( ) const noexcept
|
||||||
|
{ return mipmaps_ ? mipmaps_->mode : T_Optional< E_TexSampling >{}; }
|
||||||
|
E_TexWrap wrapping( ) const noexcept
|
||||||
|
{ return wrapping_ ? wrapping_->mode : E_TexWrap::REPEAT; }
|
||||||
|
A_ExpressionNode* minLod( ) const noexcept
|
||||||
|
{ return lod_ ? lod_->min.get( ) : nullptr; }
|
||||||
|
A_ExpressionNode* maxLod( ) const noexcept
|
||||||
|
{ return lod_ ? lod_->max.get( ) : nullptr; }
|
||||||
|
};
|
||||||
|
|
||||||
|
// Texture definition
|
||||||
|
class T_TextureInstrNode : public A_ResourceDefInstrNode
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
E_TexType type_;
|
||||||
|
P_ExpressionNode width_;
|
||||||
|
P_ExpressionNode height_;
|
||||||
|
P_ExpressionNode lods_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
T_TextureInstrNode(
|
||||||
|
T_InstrListNode& parent ,
|
||||||
|
T_SRDToken const& id ,
|
||||||
|
E_TexType type ) noexcept
|
||||||
|
: A_ResourceDefInstrNode( OP_TEXTURE , parent ,
|
||||||
|
id , E_DataType::TEXTURE ) ,
|
||||||
|
type_( type )
|
||||||
|
{ }
|
||||||
|
|
||||||
|
void setWidth( P_ExpressionNode width ) noexcept
|
||||||
|
{ width_ = std::move( width ); }
|
||||||
|
bool hasWidth( ) const noexcept
|
||||||
|
{ return bool( width_ ); }
|
||||||
|
A_ExpressionNode& width( ) const noexcept
|
||||||
|
{ return *width_; }
|
||||||
|
|
||||||
|
void setHeight( P_ExpressionNode height ) noexcept
|
||||||
|
{ height_ = std::move( height ); }
|
||||||
|
bool hasHeight( ) const noexcept
|
||||||
|
{ return bool( height_ ); }
|
||||||
|
A_ExpressionNode& height( ) const noexcept
|
||||||
|
{ return *height_; }
|
||||||
|
|
||||||
|
void setLODs( P_ExpressionNode lods ) noexcept
|
||||||
|
{ lods_ = std::move( lods ); }
|
||||||
|
A_ExpressionNode* lods( ) const noexcept
|
||||||
|
{ return lods_.get( ); }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*= TOOL CONTROL INSTRUCTIONS ==================================================*/
|
||||||
|
|
||||||
// Output debugging
|
// Output debugging
|
||||||
class T_OutputDebugInstrNode : public A_InstructionNode
|
class T_OutputDebugInstrNode : public A_InstructionNode
|
||||||
{
|
{
|
||||||
|
@ -579,52 +777,6 @@ class T_OutputDebugInstrNode : public A_InstructionNode
|
||||||
{ return locDescription_; }
|
{ return locDescription_; }
|
||||||
};
|
};
|
||||||
|
|
||||||
// Pipeline declaration instruction
|
|
||||||
class T_PipelineInstrNode : public A_InstructionNode
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
T_String id_;
|
|
||||||
T_SRDLocation idLocation_;
|
|
||||||
T_StaticArray< T_String , 6 > pids_;
|
|
||||||
T_StaticArray< T_SRDLocation , 6 > pidLocations_;
|
|
||||||
|
|
||||||
public:
|
|
||||||
T_PipelineInstrNode(
|
|
||||||
T_InstrListNode& parent ,
|
|
||||||
T_SRDToken const& idToken ) noexcept
|
|
||||||
: A_InstructionNode( OP_PIPELINE , parent , E_InstrRestriction::FRAME ) ,
|
|
||||||
id_( idToken.stringValue( ) ) ,
|
|
||||||
idLocation_( idToken.location( ) )
|
|
||||||
{ }
|
|
||||||
|
|
||||||
explicit T_PipelineInstrNode(
|
|
||||||
T_InstrListNode& parent ) noexcept
|
|
||||||
: A_InstructionNode( OP_PIPELINE , parent , E_InstrRestriction::FRAME ) ,
|
|
||||||
id_( "*invalid*" ) ,
|
|
||||||
idLocation_{ }
|
|
||||||
{ }
|
|
||||||
|
|
||||||
T_String const& id( ) const noexcept
|
|
||||||
{ return id_; }
|
|
||||||
T_SRDLocation const& idLocation( ) const noexcept
|
|
||||||
{ return idLocation_; }
|
|
||||||
|
|
||||||
// Add a program identifier. The token is assumed to be a valid word,
|
|
||||||
// and the list of programs is assumed not to be full. If the identifer
|
|
||||||
// is already in the pipeline's list, the location of the first
|
|
||||||
// occurrence will be returned.
|
|
||||||
T_Optional< T_SRDLocation > addProgram(
|
|
||||||
T_SRDToken const& pidToken ) noexcept;
|
|
||||||
|
|
||||||
uint32_t size( ) const noexcept
|
|
||||||
{ return pids_.size( ); }
|
|
||||||
|
|
||||||
T_String const& program( const uint32_t index ) const noexcept
|
|
||||||
{ return pids_[ index ]; }
|
|
||||||
T_SRDLocation const& pLocation( const uint32_t index ) const noexcept
|
|
||||||
{ return pidLocations_[ index ]; }
|
|
||||||
};
|
|
||||||
|
|
||||||
// Profiling instruction
|
// Profiling instruction
|
||||||
class T_ProfileInstrNode : public A_InstructionNode
|
class T_ProfileInstrNode : public A_InstructionNode
|
||||||
{
|
{
|
||||||
|
@ -650,189 +802,47 @@ class T_ProfileInstrNode : public A_InstructionNode
|
||||||
{ return instructions_; }
|
{ return instructions_; }
|
||||||
};
|
};
|
||||||
|
|
||||||
// Program loader instruction
|
|
||||||
class T_ProgramInstrNode : public A_InstructionNode
|
/*= RENDERING INSTRUCTIONS =====================================================*/
|
||||||
|
|
||||||
|
// Clear instruction
|
||||||
|
class T_ClearInstrNode : public A_InstructionNode
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
T_String id_;
|
T_StaticArray< P_ExpressionNode , 4 > components_;
|
||||||
T_SRDLocation idLocation_;
|
|
||||||
T_String path_;
|
|
||||||
T_SRDLocation pathLocation_;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
T_ProgramInstrNode(
|
T_ClearInstrNode( T_InstrListNode& parent ) noexcept
|
||||||
T_InstrListNode& parent ,
|
: A_InstructionNode( OP_CLEAR , parent ,
|
||||||
T_SRDToken const& idToken ,
|
E_InstrRestriction::INIT )
|
||||||
T_SRDToken const& pathToken ) noexcept
|
|
||||||
: A_InstructionNode( OP_PROGRAM , parent , E_InstrRestriction::FRAME ) ,
|
|
||||||
id_( idToken.stringValue( ) ) ,
|
|
||||||
idLocation_( idToken.location( ) ) ,
|
|
||||||
path_( pathToken.stringValue( ) ) ,
|
|
||||||
pathLocation_( pathToken.location( ) )
|
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
T_String const& id( ) const noexcept
|
void addComponent( P_ExpressionNode expr ) noexcept
|
||||||
{ return id_; }
|
{ if ( expr ) { components_.add( std::move( expr ) ); } }
|
||||||
T_SRDLocation const& idLocation( ) const noexcept
|
|
||||||
{ return idLocation_; }
|
uint32_t components( ) const noexcept
|
||||||
|
{ return components_.size( ); }
|
||||||
|
|
||||||
|
A_ExpressionNode& component( const uint32_t index ) const noexcept
|
||||||
|
{ return *components_[ index ]; }
|
||||||
};
|
};
|
||||||
|
|
||||||
// Sampler definition
|
// Fullscreen quad instruction
|
||||||
class T_SamplerInstrNode : public A_InstructionNode
|
class T_FullscreenInstrNode : public A_InstructionNode
|
||||||
{
|
{
|
||||||
private:
|
|
||||||
struct T_Sampling_
|
|
||||||
{
|
|
||||||
T_SRDLocation location;
|
|
||||||
E_TexSampling mode;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct T_Mipmaps_
|
|
||||||
{
|
|
||||||
T_SRDLocation location;
|
|
||||||
T_Optional< E_TexSampling > mode;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct T_Wrapping_
|
|
||||||
{
|
|
||||||
T_SRDLocation location;
|
|
||||||
E_TexWrap mode;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct T_LOD_
|
|
||||||
{
|
|
||||||
T_SRDLocation location;
|
|
||||||
P_ExpressionNode min;
|
|
||||||
P_ExpressionNode max;
|
|
||||||
};
|
|
||||||
|
|
||||||
T_String id_;
|
|
||||||
T_SRDLocation idLocation_;
|
|
||||||
|
|
||||||
T_Optional< T_Sampling_ > sampling_;
|
|
||||||
T_Optional< T_Mipmaps_ > mipmaps_;
|
|
||||||
T_Optional< T_Wrapping_ > wrapping_;
|
|
||||||
T_Optional< T_LOD_ > lod_;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
T_SamplerInstrNode(
|
T_FullscreenInstrNode( T_InstrListNode& parent ) noexcept
|
||||||
T_InstrListNode& parent ,
|
: A_InstructionNode( OP_FULLSCREEN , parent , E_InstrRestriction::INIT )
|
||||||
T_SRDToken const& id ) noexcept
|
|
||||||
: A_InstructionNode( OP_SAMPLER , parent ) ,
|
|
||||||
id_( id.stringValue( ) ) ,
|
|
||||||
idLocation_( id.location( ) )
|
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
T_String const& id( ) const noexcept
|
|
||||||
{ return id_; }
|
|
||||||
T_SRDLocation const& idLocation( ) const noexcept
|
|
||||||
{ return idLocation_; }
|
|
||||||
|
|
||||||
// Attempt to set sampling mode, mipmap mode, wrapping mode or
|
|
||||||
// LOD minimal/maximal, returning the location of the previous
|
|
||||||
// definition if there was one.
|
|
||||||
T_Optional< T_SRDLocation > setSampling(
|
|
||||||
E_TexSampling mode ,
|
|
||||||
T_SRDLocation const& location ) noexcept;
|
|
||||||
T_Optional< T_SRDLocation > setMipmapSampling(
|
|
||||||
E_TexSampling mode ,
|
|
||||||
T_SRDLocation const& location ) noexcept;
|
|
||||||
T_Optional< T_SRDLocation > setNoMipmap(
|
|
||||||
T_SRDLocation const& location ) noexcept;
|
|
||||||
T_Optional< T_SRDLocation > setWrapping(
|
|
||||||
E_TexWrap mode ,
|
|
||||||
T_SRDLocation const& location ) noexcept;
|
|
||||||
T_Optional< T_SRDLocation > setLOD(
|
|
||||||
T_SRDLocation const& location ,
|
|
||||||
P_ExpressionNode min ,
|
|
||||||
P_ExpressionNode max ) noexcept;
|
|
||||||
|
|
||||||
// Get either the defined values or the defaults
|
|
||||||
E_TexSampling sampling( ) const noexcept
|
|
||||||
{ return sampling_ ? sampling_->mode : E_TexSampling::NEAREST; }
|
|
||||||
T_Optional< E_TexSampling > mipmap( ) const noexcept
|
|
||||||
{ return mipmaps_ ? mipmaps_->mode : T_Optional< E_TexSampling >{}; }
|
|
||||||
E_TexWrap wrapping( ) const noexcept
|
|
||||||
{ return wrapping_ ? wrapping_->mode : E_TexWrap::REPEAT; }
|
|
||||||
A_ExpressionNode* minLod( ) const noexcept
|
|
||||||
{ return lod_ ? lod_->min.get( ) : nullptr; }
|
|
||||||
A_ExpressionNode* maxLod( ) const noexcept
|
|
||||||
{ return lod_ ? lod_->max.get( ) : nullptr; }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Setting a global variable
|
// Main output selection
|
||||||
class T_SetInstrNode : public A_InstructionNode
|
class T_MainOutputInstrNode : public A_InstructionNode
|
||||||
{
|
{
|
||||||
private:
|
|
||||||
T_String id_;
|
|
||||||
T_SRDLocation idLocation_;
|
|
||||||
P_ExpressionNode expression_;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
T_SetInstrNode( T_InstrListNode& parent ,
|
T_MainOutputInstrNode( T_InstrListNode& parent ) noexcept
|
||||||
T_SRDToken const& idToken ) noexcept
|
: A_InstructionNode( OP_MAINOUT , parent , E_InstrRestriction::INIT )
|
||||||
: A_InstructionNode( OP_SET , parent ) ,
|
|
||||||
id_( idToken.stringValue( ) ) ,
|
|
||||||
idLocation_( idToken.location( ) )
|
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
T_String const& id( ) const noexcept
|
|
||||||
{ return id_; }
|
|
||||||
T_SRDLocation const& idLocation( ) const noexcept
|
|
||||||
{ return idLocation_; }
|
|
||||||
|
|
||||||
void setExpression( P_ExpressionNode expression ) noexcept
|
|
||||||
{ expression_ = std::move( expression ); }
|
|
||||||
bool hasExpression( ) const noexcept
|
|
||||||
{ return bool( expression_ ); }
|
|
||||||
A_ExpressionNode& expression( ) const noexcept
|
|
||||||
{ return *expression_; }
|
|
||||||
};
|
|
||||||
|
|
||||||
// Texture definition
|
|
||||||
class T_TextureInstrNode : public A_InstructionNode
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
T_String id_;
|
|
||||||
T_SRDLocation idLocation_;
|
|
||||||
E_TexType type_;
|
|
||||||
P_ExpressionNode width_;
|
|
||||||
P_ExpressionNode height_;
|
|
||||||
P_ExpressionNode lods_;
|
|
||||||
|
|
||||||
public:
|
|
||||||
T_TextureInstrNode(
|
|
||||||
T_InstrListNode& parent ,
|
|
||||||
T_SRDToken const& id ,
|
|
||||||
E_TexType type ) noexcept
|
|
||||||
: A_InstructionNode( OP_TEXTURE , parent , E_InstrRestriction::FRAME ) ,
|
|
||||||
id_( id.stringValue( ) ) , idLocation_( id.location( ) ) ,
|
|
||||||
type_( type )
|
|
||||||
{ }
|
|
||||||
|
|
||||||
T_String const& id( ) const noexcept
|
|
||||||
{ return id_; }
|
|
||||||
T_SRDLocation const& idLocation( ) const noexcept
|
|
||||||
{ return idLocation_; }
|
|
||||||
|
|
||||||
void setWidth( P_ExpressionNode width ) noexcept
|
|
||||||
{ width_ = std::move( width ); }
|
|
||||||
bool hasWidth( ) const noexcept
|
|
||||||
{ return bool( width_ ); }
|
|
||||||
A_ExpressionNode& width( ) const noexcept
|
|
||||||
{ return *width_; }
|
|
||||||
|
|
||||||
void setHeight( P_ExpressionNode height ) noexcept
|
|
||||||
{ height_ = std::move( height ); }
|
|
||||||
bool hasHeight( ) const noexcept
|
|
||||||
{ return bool( height_ ); }
|
|
||||||
A_ExpressionNode& height( ) const noexcept
|
|
||||||
{ return *height_; }
|
|
||||||
|
|
||||||
void setLODs( P_ExpressionNode lods ) noexcept
|
|
||||||
{ lods_ = std::move( lods ); }
|
|
||||||
A_ExpressionNode* lods( ) const noexcept
|
|
||||||
{ return lods_.get( ); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Uniform setting instruction
|
// Uniform setting instruction
|
||||||
|
@ -975,7 +985,8 @@ class T_ViewportInstrNode : public A_InstructionNode
|
||||||
{ return *parameters_[ int( p ) ]; }
|
{ return *parameters_[ int( p ) ]; }
|
||||||
};
|
};
|
||||||
|
|
||||||
/*============================================================================*/
|
|
||||||
|
/*= EXPRESSIONS ==============================================================*/
|
||||||
|
|
||||||
// A constant value
|
// A constant value
|
||||||
class T_ConstantExprNode : public A_ExpressionNode
|
class T_ConstantExprNode : public A_ExpressionNode
|
||||||
|
@ -1138,7 +1149,8 @@ class T_BinaryOperatorNode : public A_ExpressionNode
|
||||||
{ return *right_; }
|
{ return *right_; }
|
||||||
};
|
};
|
||||||
|
|
||||||
/*============================================================================*/
|
|
||||||
|
/*= PARSER ===================================================================*/
|
||||||
|
|
||||||
class T_Parser : public A_PrivateImplementation
|
class T_Parser : public A_PrivateImplementation
|
||||||
{
|
{
|
||||||
|
|
|
@ -795,14 +795,10 @@ M_INSTR_( Pipeline )
|
||||||
const bool validId( input[ 1 ].type( ) == E_SRDTokenType::WORD );
|
const bool validId( input[ 1 ].type( ) == E_SRDTokenType::WORD );
|
||||||
if ( !validId ) {
|
if ( !validId ) {
|
||||||
errors.addNew( "pipeline identifier expected" , input[ 1 ].location( ) );
|
errors.addNew( "pipeline identifier expected" , input[ 1 ].location( ) );
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
T_PipelineInstrNode& pipeline{ ([&instructions,&input,validId]( ) -> T_PipelineInstrNode& {
|
auto& pipeline{ instructions.add< T_PipelineInstrNode >( input[ 0 ] ) };
|
||||||
if ( validId ) {
|
|
||||||
return instructions.add< T_PipelineInstrNode >( input[ 0 ] );
|
|
||||||
}
|
|
||||||
return instructions.add< T_PipelineInstrNode >( );
|
|
||||||
})() };
|
|
||||||
pipeline.location( ) = input[ 0 ].location( );
|
pipeline.location( ) = input[ 0 ].location( );
|
||||||
|
|
||||||
const auto nMax{ std::min( input.size( ) , 8u ) };
|
const auto nMax{ std::min( input.size( ) , 8u ) };
|
||||||
|
|
Loading…
Reference in a new issue