Changeset 640b3df for src/Parser


Ignore:
Timestamp:
Feb 21, 2023, 4:24:34 PM (3 years ago)
Author:
caparson <caparson@…>
Branches:
ADT, ast-experimental, master
Children:
257a8f5, ce44c5f
Parents:
1180175 (diff), 9a533ba (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src/Parser
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/DeclarationNode.cc

    r1180175 r640b3df  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Aug  8 17:07:00 2022
    13 // Update Count     : 1185
     12// Last Modified On : Thu Feb 16 14:12:03 2023
     13// Update Count     : 1388
    1414//
    1515
     
    6161        variable.initializer = nullptr;
    6262
    63 //      attr.name = nullptr;
    64         attr.expr = nullptr;
    65         attr.type = nullptr;
    66 
    6763        assert.condition = nullptr;
    6864        assert.message = nullptr;
     
    7066
    7167DeclarationNode::~DeclarationNode() {
    72 //      delete attr.name;
    73         delete attr.expr;
    74         delete attr.type;
    75 
    7668//      delete variable.name;
    7769        delete variable.assertions;
     
    115107        newnode->variable.initializer = maybeClone( variable.initializer );
    116108
    117 //      newnode->attr.name = attr.name ? new string( *attr.name ) : nullptr;
    118         newnode->attr.expr = maybeClone( attr.expr );
    119         newnode->attr.type = maybeClone( attr.type );
    120 
    121109        newnode->assert.condition = maybeClone( assert.condition );
    122110        newnode->assert.message = maybeClone( assert.message );
     
    154142        } // if
    155143
    156         for ( Attribute * attr: reverseIterate( attributes ) ) {
    157                 os << string( indent + 2, ' ' ) << "attr " << attr->name.c_str();
    158         } // for
     144        if ( ! attributes.empty() ) {
     145                os << string( indent + 2, ' ' ) << "with attributes " << endl;
     146                for ( Attribute * attr: reverseIterate( attributes ) ) {
     147                        os << string( indent + 4, ' ' ) << attr->name.c_str() << endl;
     148                } // for
     149        } // if
    159150
    160151        os << endl;
     
    244235        newnode->type = new TypeData( TypeData::Aggregate );
    245236        newnode->type->aggregate.kind = kind;
    246         newnode->type->aggregate.name = name == nullptr ? new string( DeclarationNode::anonymous.newName() ) : name;
     237        newnode->type->aggregate.anon = name == nullptr;
     238        newnode->type->aggregate.name = newnode->type->aggregate.anon ? new string( DeclarationNode::anonymous.newName() ) : name;
    247239        newnode->type->aggregate.actuals = actuals;
    248240        newnode->type->aggregate.fields = fields;
     
    250242        newnode->type->aggregate.tagged = false;
    251243        newnode->type->aggregate.parent = nullptr;
    252         newnode->type->aggregate.anon = name == nullptr;
    253244        return newnode;
    254245} // DeclarationNode::newAggregate
     
    257248        DeclarationNode * newnode = new DeclarationNode;
    258249        newnode->type = new TypeData( TypeData::Enum );
    259         newnode->type->enumeration.name = name == nullptr ? new string( DeclarationNode::anonymous.newName() ) : name;
     250        newnode->type->enumeration.anon = name == nullptr;
     251        newnode->type->enumeration.name = newnode->type->enumeration.anon ? new string( DeclarationNode::anonymous.newName() ) : name;
    260252        newnode->type->enumeration.constants = constants;
    261253        newnode->type->enumeration.body = body;
    262         newnode->type->enumeration.anon = name == nullptr;
    263254        newnode->type->enumeration.typed = typed;
    264255        newnode->type->enumeration.hiding = hiding;
     
    989980        for ( const DeclarationNode * cur = firstNode; cur; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ) ) {
    990981                try {
    991                         bool extracted = false;
    992                         bool anon = false;
     982                        bool extracted = false, anon = false;
     983                        AggregateDecl * unionDecl = nullptr;
     984
    993985                        if ( DeclarationNode * extr = cur->extractAggregate() ) {
    994986                                // handle the case where a structure declaration is contained within an object or type declaration
     987
    995988                                Declaration * decl = extr->build();
    996989                                if ( decl ) {
    997                                         // hoist the structure declaration
     990                                        // Remember the declaration if it is a union aggregate ?
     991                                        unionDecl = dynamic_cast<UnionDecl *>( decl );
     992
    998993                                        decl->location = cur->location;
    999                                         * out++ = decl;
     994                                        *out++ = decl;
    1000995
    1001996                                        // need to remember the cases where a declaration contains an anonymous aggregate definition
     
    1003998                                        assert( extr->type );
    1004999                                        if ( extr->type->kind == TypeData::Aggregate ) {
     1000                                                // typedef struct { int A } B is the only case?
    10051001                                                anon = extr->type->aggregate.anon;
    10061002                                        } else if ( extr->type->kind == TypeData::Enum ) {
    1007                                                 // xxx - is it useful to have an implicit anonymous enum member?
     1003                                                // typedef enum { A } B is the only case?
    10081004                                                anon = extr->type->enumeration.anon;
    10091005                                        }
     
    10141010                        Declaration * decl = cur->build();
    10151011                        if ( decl ) {
     1012                                if ( TypedefDecl * typedefDecl = dynamic_cast<TypedefDecl *>( decl ) ) {
     1013                                        if ( unionDecl ) {                                      // is the typedef alias a union aggregate ?
     1014                                                // This code handles a special issue with the attribute transparent_union.
     1015                                                //
     1016                                                //    typedef union U { int i; } typedef_name __attribute__(( aligned(16) )) __attribute__(( transparent_union ))
     1017                                                //
     1018                                                // Here the attribute aligned goes with the typedef_name, so variables declared of this type are
     1019                                                // aligned.  However, the attribute transparent_union must be moved from the typedef_name to
     1020                                                // alias union U.  Currently, this is the only know attribute that must be moved from typedef to
     1021                                                // alias.
     1022
     1023                                                // If typedef is an alias for a union, then its alias type was hoisted above and remembered.
     1024                                                if ( UnionInstType * unionInstType = dynamic_cast<UnionInstType *>( typedefDecl->base ) ) {
     1025                                                        // Remove all transparent_union attributes from typedef and move to alias union.
     1026                                                        list<Attribute *>::iterator attr;
     1027                                                        for ( attr = unionInstType->attributes.begin(); attr != unionInstType->attributes.end(); ) { // forward order
     1028                                                                if ( (*attr)->name == "transparent_union" || (*attr)->name == "__transparent_union__" ) {
     1029                                                                        list<Attribute *>::iterator cur = attr; // remember current node
     1030                                                                        attr++;                         // advance iterator
     1031                                                                        unionDecl->attributes.emplace_back( *cur ); // move current
     1032                                                                        unionInstType->attributes.erase( cur ); // remove current
     1033                                                                } else {
     1034                                                                        attr++;                         // advance iterator
     1035                                                                } // if
     1036                                                        } // for
     1037                                                } // if
     1038                                        } // if
     1039                                } // if
     1040
    10161041                                // don't include anonymous declaration for named aggregates, but do include them for anonymous aggregates, e.g.:
    10171042                                // struct S {
     
    11761201        assert( type );
    11771202
    1178         if ( attr.expr ) {
    1179                 return new AttrType( buildQualifiers( type ), *name, attr.expr->build(), attributes );
    1180         } else if ( attr.type ) {
    1181                 return new AttrType( buildQualifiers( type ), *name, attr.type->buildType(), attributes );
    1182         } // if
    1183 
    11841203        switch ( type->kind ) {
    11851204          case TypeData::Enum:
  • src/Parser/ExpressionNode.cc

    r1180175 r640b3df  
    1010// Created On       : Sat May 16 13:17:07 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Aug  7 09:18:56 2021
    13 // Update Count     : 1077
     12// Last Modified On : Sat Feb 11 14:49:00 2023
     13// Update Count     : 1079
    1414//
    1515
     
    173173                if ( posn != string::npos ) { Unsigned = true; type = 2; ltype = 4; str.erase( posn, 1 ); goto FINI; }
    174174
    175                 posn = str.rfind( "hh" );                                               // char
     175                posn = str.rfind( "hh" );                                               // signed char
    176176                if ( posn != string::npos ) { type = 1; str.erase( posn, 2 ); goto FINI; }
    177177
    178                 posn = str.rfind( "HH" );                                               // char
     178                posn = str.rfind( "HH" );                                               // signed char
    179179                if ( posn != string::npos ) { type = 1; str.erase( posn, 2 ); goto FINI; }
    180180
     
    592592Expression * build_unary_ptr( OperKinds op, ExpressionNode * expr_node ) {
    593593        list< Expression * > args;
    594         args.push_back(  maybeMoveBuild< Expression >(expr_node) ); // xxx -- this is exactly the same as the val case now, refactor this code.
     594        args.push_back( maybeMoveBuild< Expression >(expr_node) ); // xxx -- this is exactly the same as the val case now, refactor this code.
    595595        return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args );
    596596} // build_unary_ptr
  • src/Parser/ParseNode.h

    r1180175 r640b3df  
    1010// Created On       : Sat May 16 13:28:16 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Nov  2 21:27:07 2022
    13 // Update Count     : 939
     12// Last Modified On : Sun Feb 19 09:02:37 2023
     13// Update Count     : 940
    1414//
    1515
     
    2727#include "Common/SemanticError.h"  // for SemanticError
    2828#include "Common/UniqueName.h"     // for UniqueName
    29 #include "Common/utility.h"        // for maybeClone, maybeBuild
     29#include "Common/utility.h"        // for maybeClone
     30#include "Parser/parserutility.h"  // for maybeBuild
    3031#include "SynTree/LinkageSpec.h"   // for Spec
    3132#include "SynTree/Declaration.h"   // for Aggregate
     
    324325        Variable_t variable;
    325326
    326         struct Attr_t {
    327 //              const std::string * name;
    328                 ExpressionNode * expr;
    329                 DeclarationNode * type;
    330         };
    331         Attr_t attr;
    332 
    333327        struct StaticAssert_t {
    334328                ExpressionNode * condition;
     
    342336
    343337        bool inLine = false;
    344         bool enumInLine = false; 
     338        bool enumInLine = false;
    345339        Type::FuncSpecifiers funcSpecs;
    346340        Type::StorageClasses storageClasses;
  • src/Parser/RunParser.cpp

    r1180175 r640b3df  
    1010// Created On       : Mon Dec 19 11:00:00 2022
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Thr Dec 22 10:18:00 2022
    13 // Update Count     : 1
     12// Last Modified On : Thr Feb 16 10:08:00 2023
     13// Update Count     : 2
    1414//
    1515
     
    2424
    2525// Variables global to the parsing code.
    26 LinkageSpec::Spec linkage = LinkageSpec::Cforall;
     26ast::Linkage::Spec linkage = ast::Linkage::Cforall;
    2727TypedefTable typedefTable;
    2828DeclarationNode * parseTree = nullptr;
    2929
    30 void parse( FILE * input, LinkageSpec::Spec linkage, bool alwaysExit ) {
     30void parse( FILE * input, ast::Linkage::Spec linkage, bool alwaysExit ) {
    3131        extern int yyparse( void );
    3232        extern FILE * yyin;
  • src/Parser/RunParser.hpp

    r1180175 r640b3df  
    1010// Created On       : Mon Dec 19 10:42:00 2022
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Thr Dec 22 10:23:00 2022
    13 // Update Count     : 1
     12// Last Modified On : Thr Feb 16 10:08:00 2023
     13// Update Count     : 2
    1414//
    1515
     
    1818#include <iosfwd>                           // for ostream
    1919
    20 #include "SynTree/LinkageSpec.h"            // for Spec
     20#include "AST/LinkageSpec.hpp"              // for Spec
    2121namespace ast {
    2222        class TranslationUnit;
     
    2929/// The input file is closed when complete. Exits instead of returning on
    3030/// error or if alwaysExit is true.
    31 void parse( FILE * input, LinkageSpec::Spec linkage, bool alwaysExit = false );
     31void parse( FILE * input, ast::Linkage::Spec linkage, bool alwaysExit = false );
    3232
    3333/// Drain the internal accumulator of parsed code and build a translation
  • src/Parser/TypeData.cc

    r1180175 r640b3df  
    1010// Created On       : Sat May 16 15:12:51 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue May 10 22:36:52 2022
    13 // Update Count     : 677
     12// Last Modified On : Sun Feb 19 11:00:46 2023
     13// Update Count     : 679
    1414//
    1515
     
    375375                break;
    376376          case Enum:
    377                 os << "enumeration ";
     377                os << "enumeration " << *enumeration.name << endl;;
    378378                if ( enumeration.constants ) {
    379379                        os << "with constants" << endl;
  • src/Parser/TypeData.h

    r1180175 r640b3df  
    1010// Created On       : Sat May 16 15:18:36 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue May 10 22:18:49 2022
    13 // Update Count     : 203
     12// Last Modified On : Sun Feb 19 09:09:39 2023
     13// Update Count     : 204
    1414//
    1515
     
    3737                bool body;
    3838                bool anon;
    39 
    4039                bool tagged;
    4140                const std::string * parent = nullptr;
  • src/Parser/parser.yy

    r1180175 r640b3df  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Feb  2 21:36:16 2023
    13 // Update Count     : 5865
     12// Last Modified On : Mon Feb 20 11:31:26 2023
     13// Update Count     : 5896
    1414//
    1515
     
    5555#include "Common/utility.h"                                                             // for maybeMoveBuild, maybeBuild, CodeLo...
    5656
    57 #include "SynTree/Attribute.h"     // for Attribute
     57#include "SynTree/Attribute.h"                                                  // for Attribute
    5858
    5959// lex uses __null in a boolean context, it's fine.
     
    19511951                {
    19521952                        typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname, "6" );
    1953                         $$ = $4->addType( $3 )->addQualifiers( $1 )->addTypedef();
     1953                        $$ = $4->addQualifiers( $1 )->addType( $3 )->addTypedef();
    19541954                }
    19551955        | type_specifier TYPEDEF declarator
     
    19611961                {
    19621962                        typedefTable.addToEnclosingScope( *$4->name, TYPEDEFname, "8" );
    1963                         $$ = $4->addQualifiers( $1 )->addTypedef()->addType( $1 );
     1963                        $$ = $4->addQualifiers( $1 )->addType( $1 )->addTypedef();
    19641964                }
    19651965        ;
     
    19831983        | typedef_expression                                                            // deprecated GCC, naming expression type
    19841984        | sue_declaration_specifier
     1985                {
     1986                        assert( $1->type );
     1987                        if ( $1->type->qualifiers.val != 0 ) {
     1988                                SemanticError( yylloc, "Useless type qualifier in empty declaration." ); $$ = nullptr;
     1989                        }
     1990                }
    19851991        ;
    19861992
  • src/Parser/parserutility.h

    r1180175 r640b3df  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // parserutility.h --
     7// parserutility.h -- Collected utilities for the parser.
    88//
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Sat May 16 15:31:46 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 09:32:58 2017
    13 // Update Count     : 4
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Thr Feb 16 12:34:00 2023
     13// Update Count     : 5
    1414//
    1515
     
    2020Expression *notZeroExpr( Expression *orig );
    2121
     22template< typename T, typename U >
     23struct maybeBuild_t {
     24        static T * doit( const U *orig ) {
     25                if ( orig ) {
     26                        return orig->build();
     27                } else {
     28                        return 0;
     29                }
     30        }
     31};
     32
     33template< typename T, typename U >
     34static inline T * maybeBuild( const U *orig ) {
     35        return maybeBuild_t<T,U>::doit(orig);
     36}
     37
     38template< typename T, typename U >
     39static inline T * maybeMoveBuild( const U *orig ) {
     40        T* ret = maybeBuild<T>(orig);
     41        delete orig;
     42        return ret;
     43}
     44
    2245// Local Variables: //
    2346// tab-width: 4 //
Note: See TracChangeset for help on using the changeset viewer.