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 ) );
|
||||
}
|
||||
|
||||
void A_Node::replaceChild(
|
||||
A_Node const& /*child*/ ,
|
||||
T_OwnPtr< A_Node > /*replacement*/
|
||||
void A_Node::replace(
|
||||
A_Node const& node ,
|
||||
T_OwnPtr< A_Node > replacement
|
||||
) noexcept
|
||||
{
|
||||
fprintf( stderr , "replaceChild called on invalid node\n" );
|
||||
std::terminate( );
|
||||
const auto nc{ size( ) };
|
||||
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{} );
|
||||
}
|
||||
|
||||
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 ===================================================*/
|
||||
|
||||
|
@ -629,9 +621,18 @@ T_Optional< T_SRDLocation > T_SamplerInstrNode::setLOD(
|
|||
if ( lod_ ) {
|
||||
return lod_->location;
|
||||
}
|
||||
lod_ = T_LOD_{ location ,
|
||||
min ? NewOwned< T_ArgumentNode >( *this , std::move( min ) ) : P_ArgumentNode{} ,
|
||||
max ? NewOwned< T_ArgumentNode >( *this , std::move( max ) ) : P_ArgumentNode{} };
|
||||
|
||||
T_Optional< uint32_t > pMin , pMax;
|
||||
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 {};
|
||||
}
|
||||
|
||||
|
@ -653,16 +654,6 @@ T_Optional< T_SRDLocation > T_LocalsInstrNode::addVariable(
|
|||
|
||||
/*= 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(
|
||||
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
|
||||
{ return children_[ index ]; }
|
||||
|
||||
virtual void replaceChild(
|
||||
A_Node const& child ,
|
||||
void replace( A_Node const& node ,
|
||||
T_OwnPtr< A_Node > replacement ) noexcept;
|
||||
};
|
||||
|
||||
|
@ -484,10 +483,6 @@ class T_CondInstrNode : public A_InstructionNode
|
|||
|
||||
void expression( P_ExpressionNode expr ) noexcept
|
||||
{ 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
|
||||
|
@ -845,8 +840,8 @@ class T_SamplerInstrNode : public A_ResourceDefInstrNode
|
|||
struct T_LOD_
|
||||
{
|
||||
ebcl::T_SRDLocation location;
|
||||
P_ArgumentNode min;
|
||||
P_ArgumentNode max;
|
||||
T_Optional< uint32_t > min;
|
||||
T_Optional< uint32_t > max;
|
||||
};
|
||||
|
||||
T_Optional< T_Sampling_ > sampling_;
|
||||
|
@ -888,10 +883,15 @@ class T_SamplerInstrNode : public A_ResourceDefInstrNode
|
|||
{ return mipmaps_ ? mipmaps_->mode : T_Optional< E_TexSampling >{}; }
|
||||
E_TexWrap wrapping( ) const noexcept
|
||||
{ return wrapping_ ? wrapping_->mode : E_TexWrap::REPEAT; }
|
||||
|
||||
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
|
||||
{ return lod_ ? lod_->max.get( ) : nullptr; }
|
||||
{ return ( T_ArgumentNode*) ( ( lod_ && lod_->max )
|
||||
? child( *( lod_->max ) ).get( )
|
||||
: nullptr ); }
|
||||
};
|
||||
|
||||
// Texture definition
|
||||
|
@ -899,9 +899,6 @@ class T_TextureInstrNode : public A_ResourceDefInstrNode
|
|||
{
|
||||
private:
|
||||
E_TexType type_;
|
||||
T_Optional< uint32_t > width_;
|
||||
T_Optional< uint32_t > height_;
|
||||
T_Optional< uint32_t > lods_;
|
||||
|
||||
public:
|
||||
T_TextureInstrNode(
|
||||
|
@ -911,7 +908,11 @@ class T_TextureInstrNode : public A_ResourceDefInstrNode
|
|||
: A_ResourceDefInstrNode( OP_TEXTURE , parent ,
|
||||
id , E_DataType::TEXTURE ) ,
|
||||
type_( type )
|
||||
{ }
|
||||
{
|
||||
children_.add( P_ArgumentNode{} );
|
||||
children_.add( P_ArgumentNode{} );
|
||||
children_.add( P_ArgumentNode{} );
|
||||
}
|
||||
|
||||
E_TexType texType( ) const noexcept
|
||||
{ return type_; }
|
||||
|
@ -919,45 +920,39 @@ class T_TextureInstrNode : public A_ResourceDefInstrNode
|
|||
void setWidth( P_ExpressionNode width ) noexcept
|
||||
{
|
||||
if ( width ) {
|
||||
auto a{ NewOwned< T_ArgumentNode >(
|
||||
*this , std::move( width ) )
|
||||
};
|
||||
width_ = children_.add( std::move( a ) );
|
||||
child( 0 ) = NewOwned< T_ArgumentNode >(
|
||||
*this , std::move( width ) );
|
||||
}
|
||||
}
|
||||
|
||||
void setHeight( P_ExpressionNode height ) noexcept
|
||||
{
|
||||
if ( height ) {
|
||||
auto a{ NewOwned< T_ArgumentNode >(
|
||||
*this , std::move( height ) )
|
||||
};
|
||||
height_ = children_.add( std::move( a ) );
|
||||
child( 1 ) = NewOwned< T_ArgumentNode >(
|
||||
*this , std::move( height ) );
|
||||
}
|
||||
}
|
||||
|
||||
void setLODs( P_ExpressionNode lods ) noexcept
|
||||
{
|
||||
if ( lods ) {
|
||||
auto a{ NewOwned< T_ArgumentNode >(
|
||||
*this , std::move( lods ) )
|
||||
};
|
||||
lods_ = children_.add( std::move( a ) );
|
||||
child( 2 ) = NewOwned< T_ArgumentNode >(
|
||||
*this , std::move( lods ) );
|
||||
}
|
||||
}
|
||||
|
||||
bool hasWidth( ) const noexcept
|
||||
{ return bool( width_ ); }
|
||||
{ return bool( child( 0 ) ); }
|
||||
T_ArgumentNode& width( ) const noexcept
|
||||
{ return (T_ArgumentNode&) *child( *width_ ); }
|
||||
{ return (T_ArgumentNode&) *child( 0 ); }
|
||||
|
||||
bool hasHeight( ) const noexcept
|
||||
{ return bool( height_ ); }
|
||||
{ return bool( child( 1 ) ); }
|
||||
T_ArgumentNode& height( ) const noexcept
|
||||
{ return (T_ArgumentNode&) *child( *height_ ); }
|
||||
{ return (T_ArgumentNode&) *child( 1 ); }
|
||||
|
||||
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 ); }
|
||||
A_ExpressionNode& right( ) const noexcept
|
||||
{ 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 replacement{ NewOwned< T_ConstantExprNode >( p , value ) };
|
||||
replacement->location( ) = eid.location( );
|
||||
p.replaceChild( eid , std::move( replacement ) );
|
||||
p.replace( eid , std::move( replacement ) );
|
||||
oData.logger( [&]() {
|
||||
T_StringBuilder sb;
|
||||
sb << "Propagated constant from " << var.name
|
||||
|
|
Loading…
Reference in a new issue