Changeset 1f44196 for src/CodeGen


Ignore:
Timestamp:
Nov 29, 2016, 3:30:59 PM (9 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, stuck-waitfor-destruct, with_gc
Children:
8e5724e
Parents:
3a2128f (diff), 9129a84 (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 plg2:software/cfa/cfa-cc

Conflicts:

src/Parser/parser.cc

Location:
src/CodeGen
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r3a2128f r1f44196  
    307307                                                } else {
    308308                                                        // no address-of operator, so must be a pointer - add dereference
     309                                                        // NOTE: if the assertion starts to trigger, check that the application expr isn't being shared.
     310                                                        // Since its arguments are modified here, this assertion most commonly triggers when the application
     311                                                        // is visited multiple times.
    309312                                                        UntypedExpr * newExpr = new UntypedExpr( new NameExpr( "*?" ) );
    310313                                                        newExpr->get_args().push_back( *arg );
    311                                                         assert( (*arg)->get_results().size() == 1 );
    312                                                         Type * type = InitTweak::getPointerBase( (*arg)->get_results().front() );
    313                                                         assert( type );
    314                                                         newExpr->get_results().push_back( type->clone() );
     314                                                        Type * type = InitTweak::getPointerBase( (*arg)->get_result() );
     315                                                        assertf( type, "First argument to a derefence must be a pointer. Ensure that expressions are not being shared." );
     316                                                        newExpr->set_result( type->clone() );
    315317                                                        *arg = newExpr;
    316318                                                } // if
     
    527529                extension( castExpr );
    528530                output << "(";
    529                 if ( castExpr->get_results().empty() ) {
     531                if ( castExpr->get_result()->isVoid() ) {
    530532                        output << "(void)" ;
    531                 } else if ( ! castExpr->get_results().front()->get_isLvalue() ) {
     533                } else if ( ! castExpr->get_result()->get_isLvalue() ) {
    532534                        // at least one result type of cast, but not an lvalue
    533535                        output << "(";
    534                         output << genType( castExpr->get_results().front(), "" );
     536                        output << genType( castExpr->get_result(), "" );
    535537                        output << ")";
    536538                } else {
     
    640642        }
    641643
    642         void CodeGenerator::visit( TupleExpr * tupleExpr ) {}
     644        void CodeGenerator::visit( TupleExpr * tupleExpr ) { assert( false ); }
    643645
    644646        void CodeGenerator::visit( TypeExpr * typeExpr ) {}
     
    654656                asmExpr->get_operand()->accept( *this );
    655657                output << " )";
     658        }
     659
     660        void CodeGenerator::visit( CompoundLiteralExpr *compLitExpr ) {
     661                assert( compLitExpr->get_type() && dynamic_cast< ListInit * > ( compLitExpr->get_initializer() ) );
     662                output << "(" << genType( compLitExpr->get_type(), "" ) << ")";
     663                compLitExpr->get_initializer()->accept( *this );
     664        }
     665
     666        void CodeGenerator::visit( StmtExpr * stmtExpr ) {
     667                std::list< Statement * > & stmts = stmtExpr->get_statements()->get_kids();
     668                output << "({" << std::endl;
     669                cur_indent += CodeGenerator::tabsize;
     670                unsigned int numStmts = stmts.size();
     671                unsigned int i = 0;
     672                for ( Statement * stmt : stmts ) {
     673                        output << indent << printLabels( stmt->get_labels() );
     674                        if ( i+1 == numStmts ) {
     675                                // last statement in a statement expression needs to be handled specially -
     676                                // cannot cast to void, otherwise the expression statement has no value
     677                                if ( ExprStmt * exprStmt = dynamic_cast< ExprStmt * >( stmt ) ) {
     678                                        exprStmt->get_expr()->accept( *this );
     679                                        output << ";" << endl;
     680                                        ++i;
     681                                        break;
     682                                }
     683                        }
     684                        stmt->accept( *this );
     685                        output << endl;
     686                        if ( wantSpacing( stmt ) ) {
     687                                output << endl;
     688                        } // if
     689                        ++i;
     690                }
     691                cur_indent -= CodeGenerator::tabsize;
     692                output << indent << "})";
    656693        }
    657694
  • src/CodeGen/CodeGenerator.h

    r3a2128f r1f44196  
    7070                virtual void visit( ConditionalExpr *conditionalExpr );
    7171                virtual void visit( CommaExpr *commaExpr );
     72                virtual void visit( CompoundLiteralExpr *compLitExpr );
    7273                virtual void visit( TupleExpr *tupleExpr );
    7374                virtual void visit( TypeExpr *typeExpr );
    7475                virtual void visit( AsmExpr * );
     76                virtual void visit( StmtExpr * );
    7577
    7678                //*** Statements
  • src/CodeGen/GenType.cc

    r3a2128f r1f44196  
    227227                        typeString = "_Atomic " + typeString;
    228228                } // if
    229                 if ( type->get_isAttribute() ) {
    230                         typeString = "__attribute(( )) " + typeString;
    231                 } // if
    232229        }
    233230} // namespace CodeGen
Note: See TracChangeset for help on using the changeset viewer.