Changeset e48aca8


Ignore:
Timestamp:
Mar 14, 2025, 10:42:12 AM (6 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
master
Children:
a21aaff
Parents:
6f9f338
Message:

Added support for code generation of the CountofExpr. This doesn't do anything to final output but is useful for debugging.

Location:
src/CodeGen
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cpp

    r6f9f338 re48aca8  
    790790}
    791791
     792void CodeGenerator::postvisit( ast::CountofExpr const * expr ) {
     793        assertf( !options.genC, "CountofExpr should not reach code generation." );
     794        extension( expr );
     795        output << "countof(";
     796        if ( auto type = expr->type.as<ast::TypeofType>() ) {
     797                type->expr->accept( *visitor );
     798        } else {
     799                output << genType( expr->type, "", options );
     800        }
     801        output << ")";
     802}
     803
    792804void CodeGenerator::postvisit( ast::UntypedOffsetofExpr const * expr ) {
    793805        assertf( !options.genC, "UntypedOffsetofExpr should not reach code generation." );
  • src/CodeGen/CodeGenerator.hpp

    r6f9f338 re48aca8  
    4242        void previsit( ast::Expr const * );
    4343
    44         void postvisit( ast::StructDecl const * );
    4544        void postvisit( ast::FunctionDecl const * );
    4645        // Yes, there is one visit that does modify the ast.
    4746        ast::ObjectDecl const * postvisit( ast::ObjectDecl const * );
     47        void postvisit( ast::StructDecl const * );
    4848        void postvisit( ast::UnionDecl const * );
    4949        void postvisit( ast::EnumDecl const * );
     
    7373        void postvisit( ast::SizeofExpr const * );
    7474        void postvisit( ast::AlignofExpr const * );
     75        void postvisit( ast::CountofExpr const * );
    7576        void postvisit( ast::UntypedOffsetofExpr const * );
    7677        void postvisit( ast::OffsetofExpr const * );
Note: See TracChangeset for help on using the changeset viewer.