Changeset a3525c4


Ignore:
Timestamp:
Mar 12, 2024, 4:04:53 PM (3 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
master
Children:
30a1f0c
Parents:
423c0cd
Message:

Some Parser clean-up I did while investigating.

Location:
src/Parser
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    r423c0cd ra3525c4  
    296296        newnode->type->array.dimension = size;
    297297        newnode->type->array.isStatic = isStatic;
    298         if ( newnode->type->array.dimension == nullptr || newnode->type->array.dimension->isExpressionType<ast::ConstantExpr *>() ) {
    299                 newnode->type->array.isVarLen = false;
    300         } else {
    301                 newnode->type->array.isVarLen = true;
    302         } // if
     298        newnode->type->array.isVarLen = size && !size->isExpressionType<ast::ConstantExpr *>();
    303299        return newnode->addQualifiers( qualifiers );
    304300} // DeclarationNode::newArray
  • src/Parser/TypeData.cc

    r423c0cd ra3525c4  
    12911291
    12921292
     1293static ast::Type * buildDefaultType( const TypeData * td ) {
     1294        return ( td ) ? typebuild( td ) : new ast::BasicType( ast::BasicType::SignedInt );
     1295} // buildDefaultType
     1296
     1297
    12931298ast::PointerType * buildPointer( const TypeData * td ) {
    1294         ast::PointerType * pt;
    1295         if ( td->base ) {
    1296                 pt = new ast::PointerType(
    1297                         typebuild( td->base ),
    1298                         buildQualifiers( td )
    1299                 );
    1300         } else {
    1301                 pt = new ast::PointerType(
    1302                         new ast::BasicType( ast::BasicType::SignedInt ),
    1303                         buildQualifiers( td )
    1304                 );
    1305         } // if
    1306         return pt;
     1299        return new ast::PointerType(
     1300                buildDefaultType( td->base ),
     1301                buildQualifiers( td )
     1302        );
    13071303} // buildPointer
    13081304
    13091305
    13101306ast::ArrayType * buildArray( const TypeData * td ) {
    1311         ast::ArrayType * at;
    1312         if ( td->base ) {
    1313                 at = new ast::ArrayType(
    1314                         typebuild( td->base ),
    1315                         maybeBuild( td->array.dimension ),
    1316                         td->array.isVarLen ? ast::VariableLen : ast::FixedLen,
    1317                         td->array.isStatic ? ast::StaticDim : ast::DynamicDim,
    1318                         buildQualifiers( td )
    1319                 );
    1320         } else {
    1321                 at = new ast::ArrayType(
    1322                         new ast::BasicType( ast::BasicType::SignedInt ),
    1323                         maybeBuild( td->array.dimension ),
    1324                         td->array.isVarLen ? ast::VariableLen : ast::FixedLen,
    1325                         td->array.isStatic ? ast::StaticDim : ast::DynamicDim,
    1326                         buildQualifiers( td )
    1327                 );
    1328         } // if
    1329         return at;
     1307        return new ast::ArrayType(
     1308                buildDefaultType( td->base ),
     1309                maybeBuild( td->array.dimension ),
     1310                td->array.isVarLen ? ast::VariableLen : ast::FixedLen,
     1311                td->array.isStatic ? ast::StaticDim : ast::DynamicDim,
     1312                buildQualifiers( td )
     1313        );
    13301314} // buildArray
    13311315
    13321316
    13331317ast::ReferenceType * buildReference( const TypeData * td ) {
    1334         ast::ReferenceType * rt;
    1335         if ( td->base ) {
    1336                 rt = new ast::ReferenceType(
    1337                         typebuild( td->base ),
    1338                         buildQualifiers( td )
    1339                 );
    1340         } else {
    1341                 rt = new ast::ReferenceType(
    1342                         new ast::BasicType( ast::BasicType::SignedInt ),
    1343                         buildQualifiers( td )
    1344                 );
    1345         } // if
    1346         return rt;
     1318        return new ast::ReferenceType(
     1319                buildDefaultType( td->base ),
     1320                buildQualifiers( td )
     1321        );
    13471322} // buildReference
    13481323
Note: See TracChangeset for help on using the changeset viewer.