Changeset d807ca28 for src/CodeGen


Ignore:
Timestamp:
May 25, 2018, 5:01:37 PM (6 years ago)
Author:
Rob Schluntz <rschlunt@…>
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, with_gc
Children:
3ed994e
Parents:
2c88368
git-author:
Rob Schluntz <rschlunt@…> (05/25/18 16:59:30)
git-committer:
Rob Schluntz <rschlunt@…> (05/25/18 17:01:37)
Message:

Add AST support for _Generic, along with C codegen

Location:
src/CodeGen
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r2c88368 rd807ca28  
    826826                expr->expr->accept( *visitor );
    827827        }
     828
     829        void CodeGenerator::postvisit( GenericExpr * expr ) {
     830                assertf( ! genC, "C11 _Generic expressions should not reach code generation." );
     831                output << "_Generic(";
     832                expr->control->accept( *visitor );
     833                output << ", ";
     834                unsigned int numAssocs = expr->associations.size();
     835                unsigned int i = 0;
     836                for ( GenericExpr::Association & assoc : expr->associations ) {
     837                        if (assoc.isDefault) {
     838                                output << "default: ";
     839                        } else {
     840                                output << genType( assoc.type, "", pretty, genC ) << ": ";
     841                        }
     842                        assoc.expr->accept( *visitor );
     843                        if ( i+1 != numAssocs ) {
     844                                output << ", ";
     845                        }
     846                        i++;
     847                }
     848                output << ")";
     849        }
     850
    828851
    829852        // *** Statements
  • src/CodeGen/CodeGenerator.h

    r2c88368 rd807ca28  
    9494                void postvisit( ConstructorExpr * );
    9595                void postvisit( DeletedExpr * );
     96                void postvisit( GenericExpr * );
    9697
    9798                //*** Statements
Note: See TracChangeset for help on using the changeset viewer.