AST - Finished refactoring
(unless I forgot shit)
This commit is contained in:
parent
5f6eee238f
commit
223dd1763d
3 changed files with 49 additions and 67 deletions
53
c-opast.cc
53
c-opast.cc
|
@ -32,13 +32,18 @@ T_RootNode& A_Node::root( ) const noexcept
|
||||||
const_cast< A_Node* >( node ) );
|
const_cast< A_Node* >( node ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void A_Node::replaceChild(
|
void A_Node::replace(
|
||||||
A_Node const& /*child*/ ,
|
A_Node const& node ,
|
||||||
T_OwnPtr< A_Node > /*replacement*/
|
T_OwnPtr< A_Node > replacement
|
||||||
) noexcept
|
) noexcept
|
||||||
{
|
{
|
||||||
fprintf( stderr , "replaceChild called on invalid node\n" );
|
const auto nc{ size( ) };
|
||||||
std::terminate( );
|
for ( auto i = 0u ; i < nc ; i ++ ) {
|
||||||
|
if ( child( i ).get( ) == &node ) {
|
||||||
|
child( i ) = std::move( replacement );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -503,19 +508,6 @@ T_BinaryOperatorNode::T_BinaryOperatorNode(
|
||||||
children_.add( P_ExpressionNode{} );
|
children_.add( P_ExpressionNode{} );
|
||||||
}
|
}
|
||||||
|
|
||||||
void T_BinaryOperatorNode::replaceChild(
|
|
||||||
A_Node const& ch ,
|
|
||||||
T_OwnPtr< A_Node > replacement
|
|
||||||
) noexcept
|
|
||||||
{
|
|
||||||
if ( child( 0 ).get( ) == &ch ) {
|
|
||||||
child( 0 ) = std::move( replacement );
|
|
||||||
} else {
|
|
||||||
assert( child( 1 ).get( ) == &ch );
|
|
||||||
child( 1 ) = std::move( replacement );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*= T_FramebufferInstrNode ===================================================*/
|
/*= T_FramebufferInstrNode ===================================================*/
|
||||||
|
|
||||||
|
@ -629,9 +621,18 @@ T_Optional< T_SRDLocation > T_SamplerInstrNode::setLOD(
|
||||||
if ( lod_ ) {
|
if ( lod_ ) {
|
||||||
return lod_->location;
|
return lod_->location;
|
||||||
}
|
}
|
||||||
lod_ = T_LOD_{ location ,
|
|
||||||
min ? NewOwned< T_ArgumentNode >( *this , std::move( min ) ) : P_ArgumentNode{} ,
|
T_Optional< uint32_t > pMin , pMax;
|
||||||
max ? NewOwned< T_ArgumentNode >( *this , std::move( max ) ) : P_ArgumentNode{} };
|
if ( min ) {
|
||||||
|
pMin = children_.add( NewOwned< T_ArgumentNode >(
|
||||||
|
*this , std::move( min ) ) );
|
||||||
|
}
|
||||||
|
if ( max ) {
|
||||||
|
pMax = children_.add( NewOwned< T_ArgumentNode >(
|
||||||
|
*this , std::move( max ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
lod_ = T_LOD_{ location , pMin , pMax };
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -653,16 +654,6 @@ T_Optional< T_SRDLocation > T_LocalsInstrNode::addVariable(
|
||||||
|
|
||||||
/*= T_CondInstrNode ==========================================================*/
|
/*= T_CondInstrNode ==========================================================*/
|
||||||
|
|
||||||
void T_CondInstrNode::T_Expression::replaceChild(
|
|
||||||
A_Node const& child ,
|
|
||||||
T_OwnPtr< A_Node > replacement ) noexcept
|
|
||||||
{
|
|
||||||
assert( this->child( 0 ).get( ) == &child );
|
|
||||||
this->child( 0 ) = std::move( replacement );
|
|
||||||
}
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
void T_CondInstrNode::handleRemoval(
|
void T_CondInstrNode::handleRemoval(
|
||||||
const uint32_t idx ) noexcept
|
const uint32_t idx ) noexcept
|
||||||
{
|
{
|
||||||
|
|
61
c-opast.hh
61
c-opast.hh
|
@ -107,8 +107,7 @@ class A_Node
|
||||||
const uint32_t index ) noexcept
|
const uint32_t index ) noexcept
|
||||||
{ return children_[ index ]; }
|
{ return children_[ index ]; }
|
||||||
|
|
||||||
virtual void replaceChild(
|
void replace( A_Node const& node ,
|
||||||
A_Node const& child ,
|
|
||||||
T_OwnPtr< A_Node > replacement ) noexcept;
|
T_OwnPtr< A_Node > replacement ) noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -484,10 +483,6 @@ class T_CondInstrNode : public A_InstructionNode
|
||||||
|
|
||||||
void expression( P_ExpressionNode expr ) noexcept
|
void expression( P_ExpressionNode expr ) noexcept
|
||||||
{ assert( expr ); child( 0 ) = std::move( expr ); }
|
{ assert( expr ); child( 0 ) = std::move( expr ); }
|
||||||
|
|
||||||
void replaceChild(
|
|
||||||
A_Node const& child ,
|
|
||||||
T_OwnPtr< A_Node > replacement ) noexcept override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class T_ValuedCase : public A_Node
|
class T_ValuedCase : public A_Node
|
||||||
|
@ -845,8 +840,8 @@ class T_SamplerInstrNode : public A_ResourceDefInstrNode
|
||||||
struct T_LOD_
|
struct T_LOD_
|
||||||
{
|
{
|
||||||
ebcl::T_SRDLocation location;
|
ebcl::T_SRDLocation location;
|
||||||
P_ArgumentNode min;
|
T_Optional< uint32_t > min;
|
||||||
P_ArgumentNode max;
|
T_Optional< uint32_t > max;
|
||||||
};
|
};
|
||||||
|
|
||||||
T_Optional< T_Sampling_ > sampling_;
|
T_Optional< T_Sampling_ > sampling_;
|
||||||
|
@ -888,10 +883,15 @@ class T_SamplerInstrNode : public A_ResourceDefInstrNode
|
||||||
{ return mipmaps_ ? mipmaps_->mode : T_Optional< E_TexSampling >{}; }
|
{ return mipmaps_ ? mipmaps_->mode : T_Optional< E_TexSampling >{}; }
|
||||||
E_TexWrap wrapping( ) const noexcept
|
E_TexWrap wrapping( ) const noexcept
|
||||||
{ return wrapping_ ? wrapping_->mode : E_TexWrap::REPEAT; }
|
{ return wrapping_ ? wrapping_->mode : E_TexWrap::REPEAT; }
|
||||||
|
|
||||||
T_ArgumentNode* minLod( ) const noexcept
|
T_ArgumentNode* minLod( ) const noexcept
|
||||||
{ return lod_ ? lod_->min.get( ) : nullptr; }
|
{ return ( T_ArgumentNode*) ( ( lod_ && lod_->min )
|
||||||
|
? child( *( lod_->min ) ).get( )
|
||||||
|
: nullptr ); }
|
||||||
T_ArgumentNode* maxLod( ) const noexcept
|
T_ArgumentNode* maxLod( ) const noexcept
|
||||||
{ return lod_ ? lod_->max.get( ) : nullptr; }
|
{ return ( T_ArgumentNode*) ( ( lod_ && lod_->max )
|
||||||
|
? child( *( lod_->max ) ).get( )
|
||||||
|
: nullptr ); }
|
||||||
};
|
};
|
||||||
|
|
||||||
// Texture definition
|
// Texture definition
|
||||||
|
@ -899,9 +899,6 @@ class T_TextureInstrNode : public A_ResourceDefInstrNode
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
E_TexType type_;
|
E_TexType type_;
|
||||||
T_Optional< uint32_t > width_;
|
|
||||||
T_Optional< uint32_t > height_;
|
|
||||||
T_Optional< uint32_t > lods_;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
T_TextureInstrNode(
|
T_TextureInstrNode(
|
||||||
|
@ -911,7 +908,11 @@ class T_TextureInstrNode : public A_ResourceDefInstrNode
|
||||||
: A_ResourceDefInstrNode( OP_TEXTURE , parent ,
|
: A_ResourceDefInstrNode( OP_TEXTURE , parent ,
|
||||||
id , E_DataType::TEXTURE ) ,
|
id , E_DataType::TEXTURE ) ,
|
||||||
type_( type )
|
type_( type )
|
||||||
{ }
|
{
|
||||||
|
children_.add( P_ArgumentNode{} );
|
||||||
|
children_.add( P_ArgumentNode{} );
|
||||||
|
children_.add( P_ArgumentNode{} );
|
||||||
|
}
|
||||||
|
|
||||||
E_TexType texType( ) const noexcept
|
E_TexType texType( ) const noexcept
|
||||||
{ return type_; }
|
{ return type_; }
|
||||||
|
@ -919,45 +920,39 @@ class T_TextureInstrNode : public A_ResourceDefInstrNode
|
||||||
void setWidth( P_ExpressionNode width ) noexcept
|
void setWidth( P_ExpressionNode width ) noexcept
|
||||||
{
|
{
|
||||||
if ( width ) {
|
if ( width ) {
|
||||||
auto a{ NewOwned< T_ArgumentNode >(
|
child( 0 ) = NewOwned< T_ArgumentNode >(
|
||||||
*this , std::move( width ) )
|
*this , std::move( width ) );
|
||||||
};
|
|
||||||
width_ = children_.add( std::move( a ) );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setHeight( P_ExpressionNode height ) noexcept
|
void setHeight( P_ExpressionNode height ) noexcept
|
||||||
{
|
{
|
||||||
if ( height ) {
|
if ( height ) {
|
||||||
auto a{ NewOwned< T_ArgumentNode >(
|
child( 1 ) = NewOwned< T_ArgumentNode >(
|
||||||
*this , std::move( height ) )
|
*this , std::move( height ) );
|
||||||
};
|
|
||||||
height_ = children_.add( std::move( a ) );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setLODs( P_ExpressionNode lods ) noexcept
|
void setLODs( P_ExpressionNode lods ) noexcept
|
||||||
{
|
{
|
||||||
if ( lods ) {
|
if ( lods ) {
|
||||||
auto a{ NewOwned< T_ArgumentNode >(
|
child( 2 ) = NewOwned< T_ArgumentNode >(
|
||||||
*this , std::move( lods ) )
|
*this , std::move( lods ) );
|
||||||
};
|
|
||||||
lods_ = children_.add( std::move( a ) );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasWidth( ) const noexcept
|
bool hasWidth( ) const noexcept
|
||||||
{ return bool( width_ ); }
|
{ return bool( child( 0 ) ); }
|
||||||
T_ArgumentNode& width( ) const noexcept
|
T_ArgumentNode& width( ) const noexcept
|
||||||
{ return (T_ArgumentNode&) *child( *width_ ); }
|
{ return (T_ArgumentNode&) *child( 0 ); }
|
||||||
|
|
||||||
bool hasHeight( ) const noexcept
|
bool hasHeight( ) const noexcept
|
||||||
{ return bool( height_ ); }
|
{ return bool( child( 1 ) ); }
|
||||||
T_ArgumentNode& height( ) const noexcept
|
T_ArgumentNode& height( ) const noexcept
|
||||||
{ return (T_ArgumentNode&) *child( *height_ ); }
|
{ return (T_ArgumentNode&) *child( 1 ); }
|
||||||
|
|
||||||
T_ArgumentNode* lods( ) const noexcept
|
T_ArgumentNode* lods( ) const noexcept
|
||||||
{ return lods_ ? (T_ArgumentNode*) child( *lods_ ).get( ) : nullptr; }
|
{ return (T_ArgumentNode*) child( 2 ).get( ); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -1382,10 +1377,6 @@ class T_BinaryOperatorNode : public A_ExpressionNode
|
||||||
{ return (A_ExpressionNode&) *child( 0 ); }
|
{ return (A_ExpressionNode&) *child( 0 ); }
|
||||||
A_ExpressionNode& right( ) const noexcept
|
A_ExpressionNode& right( ) const noexcept
|
||||||
{ return (A_ExpressionNode&) *child( 1 ); }
|
{ return (A_ExpressionNode&) *child( 1 ); }
|
||||||
|
|
||||||
void replaceChild(
|
|
||||||
A_Node const& child ,
|
|
||||||
T_OwnPtr< A_Node > replacement ) noexcept override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1463,7 +1463,7 @@ void CPReplaceWithConstant_(
|
||||||
auto& p{ eid.parent( ) };
|
auto& p{ eid.parent( ) };
|
||||||
auto replacement{ NewOwned< T_ConstantExprNode >( p , value ) };
|
auto replacement{ NewOwned< T_ConstantExprNode >( p , value ) };
|
||||||
replacement->location( ) = eid.location( );
|
replacement->location( ) = eid.location( );
|
||||||
p.replaceChild( eid , std::move( replacement ) );
|
p.replace( eid , std::move( replacement ) );
|
||||||
oData.logger( [&]() {
|
oData.logger( [&]() {
|
||||||
T_StringBuilder sb;
|
T_StringBuilder sb;
|
||||||
sb << "Propagated constant from " << var.name
|
sb << "Propagated constant from " << var.name
|
||||||
|
|
Loading…
Reference in a new issue