Changes in / [054514d:da60c631]
- Location:
- src
- Files:
-
- 18 edited
-
CodeGen/CodeGenerator.cc (modified) (4 diffs)
-
CodeGen/CodeGenerator.h (modified) (1 diff)
-
Common/PassVisitor.h (modified) (3 diffs)
-
Common/PassVisitor.impl.h (modified) (1 diff)
-
Parser/DeclarationNode.cc (modified) (1 diff)
-
Parser/InitializerNode.cc (modified) (4 diffs)
-
Parser/ParseNode.h (modified) (3 diffs)
-
Parser/parser.yy (modified) (4 diffs)
-
ResolvExpr/AlternativeFinder.cc (modified) (2 diffs)
-
SymTab/Indexer.cc (modified) (3 diffs)
-
SymTab/Mangler.cc (modified) (2 diffs)
-
SynTree/Declaration.cc (modified) (1 diff)
-
SynTree/Declaration.h (modified) (1 diff)
-
SynTree/Expression.cc (modified) (1 diff)
-
SynTree/Expression.h (modified) (1 diff)
-
SynTree/Mutator.h (modified) (1 diff)
-
SynTree/SynTree.h (modified) (1 diff)
-
SynTree/Visitor.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r054514d rda60c631 172 172 // *** Declarations 173 173 void CodeGenerator::postvisit( FunctionDecl * functionDecl ) { 174 // deleted decls should never be used, so don't print them175 if ( functionDecl->isDeleted && genC ) return;176 174 extension( functionDecl ); 177 175 genAttributes( functionDecl->get_attributes() ); … … 187 185 functionDecl->get_statements()->accept( *visitor ); 188 186 } // if 189 if ( functionDecl->isDeleted ) {190 output << " = void";191 }192 187 } 193 188 194 189 void CodeGenerator::postvisit( ObjectDecl * objectDecl ) { 195 // deleted decls should never be used, so don't print them196 if ( objectDecl->isDeleted && genC ) return;197 190 if (objectDecl->get_name().empty() && genC ) { 198 191 // only generate an anonymous name when generating C code, otherwise it clutters the output too much … … 213 206 objectDecl->get_init()->accept( *visitor ); 214 207 } // if 215 if ( objectDecl->isDeleted ) {216 output << " = void";217 }218 208 219 209 if ( objectDecl->get_bitfieldWidth() ) { … … 837 827 expr->expr->accept( *visitor ); 838 828 } 839 840 void CodeGenerator::postvisit( GenericExpr * expr ) {841 assertf( ! genC, "C11 _Generic expressions should not reach code generation." );842 output << "_Generic(";843 expr->control->accept( *visitor );844 output << ", ";845 unsigned int numAssocs = expr->associations.size();846 unsigned int i = 0;847 for ( GenericExpr::Association & assoc : expr->associations ) {848 if (assoc.isDefault) {849 output << "default: ";850 } else {851 output << genType( assoc.type, "", pretty, genC ) << ": ";852 }853 assoc.expr->accept( *visitor );854 if ( i+1 != numAssocs ) {855 output << ", ";856 }857 i++;858 }859 output << ")";860 }861 862 829 863 830 // *** Statements -
src/CodeGen/CodeGenerator.h
r054514d rda60c631 94 94 void postvisit( ConstructorExpr * ); 95 95 void postvisit( DeletedExpr * ); 96 void postvisit( GenericExpr * );97 96 98 97 //*** Statements -
src/Common/PassVisitor.h
r054514d rda60c631 125 125 virtual void visit( InitExpr * initExpr ) override final; 126 126 virtual void visit( DeletedExpr * delExpr ) override final; 127 virtual void visit( GenericExpr * genExpr ) override final;128 127 129 128 virtual void visit( VoidType * basicType ) override final; … … 224 223 virtual Expression * mutate( InitExpr * initExpr ) override final; 225 224 virtual Expression * mutate( DeletedExpr * delExpr ) override final; 226 virtual Expression * mutate( GenericExpr * genExpr ) override final;227 225 228 226 virtual Type * mutate( VoidType * basicType ) override final; … … 313 311 void indexerAddUnionFwd ( UnionDecl * node ) { indexer_impl_addUnionFwd ( pass, 0, node ); } 314 312 void indexerAddTrait ( TraitDecl * node ) { indexer_impl_addTrait ( pass, 0, node ); } 315 void indexerAddWith ( std::list< Expression * > & exprs, BaseSyntaxNode * withStmt ) { indexer_impl_addWith ( pass, 0, exprs, withStmt ); }313 void indexerAddWith ( std::list< Expression * > & exprs, BaseSyntaxNode * withStmt ) { indexer_impl_addWith ( pass, 0, exprs, withStmt ); } 316 314 317 315 -
src/Common/PassVisitor.impl.h
r054514d rda60c631 2073 2073 2074 2074 //-------------------------------------------------------------------------- 2075 // GenericExpr2076 template< typename pass_type >2077 void PassVisitor< pass_type >::visit( GenericExpr * node ) {2078 VISIT_START( node );2079 2080 indexerScopedAccept( node->result, *this );2081 maybeAccept_impl( node->control, *this );2082 for ( GenericExpr::Association & assoc : node->associations ) {2083 indexerScopedAccept( assoc.type, *this );2084 maybeAccept_impl( assoc.expr, *this );2085 }2086 2087 VISIT_END( node );2088 }2089 2090 template< typename pass_type >2091 Expression * PassVisitor< pass_type >::mutate( GenericExpr * node ) {2092 MUTATE_START( node );2093 2094 indexerScopedMutate( node->env, *this );2095 indexerScopedMutate( node->result, *this );2096 maybeMutate_impl( node->control, *this );2097 for ( GenericExpr::Association & assoc : node->associations ) {2098 indexerScopedMutate( assoc.type, *this );2099 maybeMutate_impl( assoc.expr, *this );2100 }2101 2102 MUTATE_END( Expression, node );2103 }2104 2105 //--------------------------------------------------------------------------2106 2075 // VoidType 2107 2076 template< typename pass_type > -
src/Parser/DeclarationNode.cc
r054514d rda60c631 1067 1067 SemanticError( this, "invalid function specifier for " ); 1068 1068 } // if 1069 bool isDelete = initializer && initializer->get_isDelete(); 1070 Declaration * decl = buildDecl( type, name ? *name : string( "" ), storageClasses, maybeBuild< Expression >( bitfieldWidth ), funcSpecs, linkage, asmName, isDelete ? nullptr : maybeBuild< Initializer >(initializer), attributes )->set_extension( extension ); 1071 if ( isDelete ) { 1072 DeclarationWithType * dwt = strict_dynamic_cast<DeclarationWithType *>( decl ); 1073 dwt->isDeleted = true; 1074 } 1075 return decl; 1069 return buildDecl( type, name ? *name : string( "" ), storageClasses, maybeBuild< Expression >( bitfieldWidth ), funcSpecs, linkage, asmName, maybeBuild< Initializer >(initializer), attributes )->set_extension( extension ); 1076 1070 } // if 1077 1071 -
src/Parser/InitializerNode.cc
r054514d rda60c631 27 27 28 28 InitializerNode::InitializerNode( ExpressionNode * _expr, bool aggrp, ExpressionNode * des ) 29 : expr( _expr ), aggregate( aggrp ), designator( des ), kids( nullptr ), maybeConstructed( true ) , isDelete( false ){29 : expr( _expr ), aggregate( aggrp ), designator( des ), kids( nullptr ), maybeConstructed( true ) { 30 30 if ( aggrp ) 31 31 kids = dynamic_cast< InitializerNode * >( get_next() ); … … 36 36 37 37 InitializerNode::InitializerNode( InitializerNode * init, bool aggrp, ExpressionNode * des ) 38 : expr( nullptr ), aggregate( aggrp ), designator( des ), kids( nullptr ), maybeConstructed( true ) , isDelete( false ){38 : expr( nullptr ), aggregate( aggrp ), designator( des ), kids( nullptr ), maybeConstructed( true ) { 39 39 if ( init ) 40 40 set_last( init ); … … 46 46 set_next( nullptr ); 47 47 } // InitializerNode::InitializerNode 48 49 InitializerNode::InitializerNode( bool isDelete ) : expr( nullptr ), aggregate( false ), designator( nullptr ), kids( nullptr ), maybeConstructed( false ), isDelete( isDelete ) {}50 48 51 49 InitializerNode::~InitializerNode() { … … 86 84 87 85 Initializer * InitializerNode::build() const { 88 assertf( ! isDelete, "Should not build delete stmt InitializerNode" );89 86 if ( aggregate ) { 90 87 // steal designators from children -
src/Parser/ParseNode.h
r054514d rda60c631 87 87 InitializerNode( ExpressionNode *, bool aggrp = false, ExpressionNode * des = nullptr ); 88 88 InitializerNode( InitializerNode *, bool aggrp = false, ExpressionNode * des = nullptr ); 89 InitializerNode( bool isDelete );90 89 ~InitializerNode(); 91 90 virtual InitializerNode * clone() const { assert( false ); return nullptr; } … … 98 97 InitializerNode * set_maybeConstructed( bool value ) { maybeConstructed = value; return this; } 99 98 bool get_maybeConstructed() const { return maybeConstructed; } 100 101 bool get_isDelete() const { return isDelete; }102 99 103 100 InitializerNode * next_init() const { return kids; } … … 113 110 InitializerNode * kids; 114 111 bool maybeConstructed; 115 bool isDelete;116 112 }; // InitializerNode 117 113 -
src/Parser/parser.yy
r054514d rda60c631 175 175 bool flag; 176 176 CatchStmt::Kind catch_kind; 177 GenericExpr * genexpr;178 177 } 179 178 … … 260 259 %type<flag> asm_volatile_opt 261 260 %type<en> handler_predicate_opt 262 %type<genexpr> generic_association generic_assoc_list263 261 264 262 // statements … … 503 501 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; } 504 502 | GENERIC '(' assignment_expression ',' generic_assoc_list ')' // C11 505 { 506 // add the missing control expression to the GenericExpr and return it 507 $5->control = maybeMoveBuild<Expression>( $3 ); 508 $$ = new ExpressionNode( $5 ); 509 } 503 { SemanticError( yylloc, "_Generic is currently unimplemented." ); $$ = nullptr; } 510 504 ; 511 505 512 506 generic_assoc_list: // C11 513 generic_association507 | generic_association 514 508 | generic_assoc_list ',' generic_association 515 {516 // steal the association node from the singleton and delete the wrapper517 $1->associations.splice($1->associations.end(), $3->associations);518 delete $3;519 $$ = $1;520 }521 509 ; 522 510 523 511 generic_association: // C11 524 512 type_no_function ':' assignment_expression 525 {526 // create a GenericExpr wrapper with one association pair527 $$ = new GenericExpr( nullptr, { { maybeMoveBuildType($1), maybeMoveBuild<Expression>($3) } } );528 }529 513 | DEFAULT ':' assignment_expression 530 { $$ = new GenericExpr( nullptr, { { maybeMoveBuild<Expression>($3) } } ); }531 514 ; 532 515 … … 2101 2084 { $$ = $2; } 2102 2085 | '=' VOID 2103 { $$ = n ew InitializerNode( true ); }2086 { $$ = nullptr; } 2104 2087 | ATassign initializer 2105 2088 { $$ = $2->set_maybeConstructed( false ); } -
src/ResolvExpr/AlternativeFinder.cc
r054514d rda60c631 97 97 void postvisit( InitExpr * initExpr ); 98 98 void postvisit( DeletedExpr * delExpr ); 99 void postvisit( GenericExpr * genExpr );100 99 101 100 /// Adds alternatives for anonymous members … … 1757 1756 assertf( false, "AlternativeFinder should never see a DeletedExpr." ); 1758 1757 } 1759 1760 void AlternativeFinder::Finder::postvisit( GenericExpr * ) {1761 assertf( false, "_Generic is not yet supported." );1762 }1763 1758 } // namespace ResolvExpr 1764 1759 -
src/SymTab/Indexer.cc
r054514d rda60c631 148 148 for ( auto decl : copy ) { 149 149 if ( FunctionDecl * function = dynamic_cast< FunctionDecl * >( decl.id ) ) { 150 std::list< DeclarationWithType * > & params = function-> type->parameters;150 std::list< DeclarationWithType * > & params = function->get_functionType()->get_parameters(); 151 151 assert( ! params.empty() ); 152 152 // use base type of pointer, so that qualifiers on the pointer type aren't considered. … … 170 170 bool noUserDefinedFunc = ! val.existsUserDefinedFunc; 171 171 bool isUserDefinedFunc = ball.isUserDefinedFunc; 172 bool isAcceptableDefaultCtor = (! val.existsUserDefinedCtor || (! val.existsUserDefinedDefaultCtor && ball.decl.id-> linkage== LinkageSpec::Intrinsic)) && ball.isDefaultCtor; // allow default constructors only when no user-defined constructors exist, except in the case of intrinsics, which require exact overrides172 bool isAcceptableDefaultCtor = (! val.existsUserDefinedCtor || (! val.existsUserDefinedDefaultCtor && ball.decl.id->get_linkage() == LinkageSpec::Intrinsic)) && ball.isDefaultCtor; // allow default constructors only when no user-defined constructors exist, except in the case of intrinsics, which require exact overrides 173 173 bool isAcceptableCopyFunc = ! val.existsUserDefinedCopyFunc && ball.isCopyFunc; // handles copy ctor and assignment operator 174 174 bool isAcceptableDtor = ! val.existsUserDefinedDtor && ball.isDtor; … … 471 471 void Indexer::addId( DeclarationWithType * decl, Expression * baseExpr ) { 472 472 // default handling of conflicts is to raise an error 473 addId( decl, [decl](IdData &, const std::string & msg) { SemanticError( decl, msg ); return true; }, baseExpr , decl->isDeleted ? decl : nullptr);473 addId( decl, [decl](IdData &, const std::string & msg) { SemanticError( decl, msg ); return true; }, baseExpr ); 474 474 } 475 475 -
src/SymTab/Mangler.cc
r054514d rda60c631 225 225 GuardValue( inFunctionType ); 226 226 inFunctionType = true; 227 std::list< Type* > returnTypes = getTypes( functionType-> returnVals);227 std::list< Type* > returnTypes = getTypes( functionType->get_returnVals() ); 228 228 acceptAll( returnTypes, *visitor ); 229 229 mangleName << "_"; 230 std::list< Type* > paramTypes = getTypes( functionType-> parameters);230 std::list< Type* > paramTypes = getTypes( functionType->get_parameters() ); 231 231 acceptAll( paramTypes, *visitor ); 232 232 mangleName << "_"; … … 236 236 printQualifiers( refType ); 237 237 238 mangleName << ( refType-> name.length() + prefix.length() ) << prefix << refType->name;238 mangleName << ( refType->get_name().length() + prefix.length() ) << prefix << refType->get_name(); 239 239 240 240 if ( mangleGenericParams ) { 241 std::list< Expression* >& params = refType-> parameters;241 std::list< Expression* >& params = refType->get_parameters(); 242 242 if ( ! params.empty() ) { 243 243 mangleName << "_"; 244 244 for ( std::list< Expression* >::const_iterator param = params.begin(); param != params.end(); ++param ) { 245 245 TypeExpr *paramType = dynamic_cast< TypeExpr* >( *param ); 246 assertf(paramType, "Aggregate parameters should be type expressions: %s", to CString(*param));247 maybeAccept( paramType-> type, *visitor );246 assertf(paramType, "Aggregate parameters should be type expressions: %s", toString(*param).c_str()); 247 maybeAccept( paramType->get_type(), *visitor ); 248 248 } 249 249 mangleName << "_"; -
src/SynTree/Declaration.cc
r054514d rda60c631 104 104 } 105 105 106 107 106 // Local Variables: // 108 107 // tab-width: 4 // -
src/SynTree/Declaration.h
r054514d rda60c631 84 84 Expression *asmName; 85 85 std::list< Attribute * > attributes; 86 bool isDeleted = false;87 86 88 87 DeclarationWithType( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage, const std::list< Attribute * > & attributes, Type::FuncSpecifiers fs ); -
src/SynTree/Expression.cc
r054514d rda60c631 748 748 } 749 749 750 GenericExpr::Association::Association( Type * type, Expression * expr ) : type( type ), expr( expr ), isDefault( false ) {}751 GenericExpr::Association::Association( Expression * expr ) : type( nullptr ), expr( expr ), isDefault( true ) {}752 GenericExpr::Association::Association( const Association & other ) : type( maybeClone( other.type ) ), expr( maybeClone( other.expr ) ), isDefault( other.isDefault ) {}753 GenericExpr::Association::~Association() {754 delete type;755 delete expr;756 }757 758 GenericExpr::GenericExpr( Expression * control, const std::list<Association> & assoc ) : Expression(), control( control ), associations( assoc ) {}759 GenericExpr::GenericExpr( const GenericExpr & other ) : Expression(other), control( maybeClone( other.control ) ), associations( other.associations ) {760 }761 GenericExpr::~GenericExpr() {762 delete control;763 }764 765 void GenericExpr::print( std::ostream & os, Indenter indent ) const {766 os << "C11 _Generic Expression" << std::endl << indent+1;767 control->print( os, indent+1 );768 os << std::endl << indent+1 << "... with associations: " << std::endl;769 for ( const Association & assoc : associations ) {770 os << indent+1;771 if (assoc.isDefault) {772 os << "... default: ";773 assoc.expr->print( os, indent+1 );774 } else {775 os << "... type: ";776 assoc.type->print( os, indent+1 );777 os << std::endl << indent+1 << "... expression: ";778 assoc.expr->print( os, indent+1 );779 os << std::endl;780 }781 os << std::endl;782 }783 }784 750 785 751 // Local Variables: // -
src/SynTree/Expression.h
r054514d rda60c631 865 865 }; 866 866 867 /// C11 _Generic expression868 class GenericExpr : public Expression {869 public:870 struct Association {871 Type * type = nullptr;872 Expression * expr = nullptr;873 bool isDefault = false;874 875 Association( Type * type, Expression * expr );876 Association( Expression * expr );877 Association( const Association & other );878 Association & operator=( const Association & other ) = delete; // at the moment this isn't used, and I don't want to implement it879 ~Association();880 };881 882 Expression * control;883 std::list<Association> associations;884 885 GenericExpr( Expression * control, const std::list<Association> & assoc );886 GenericExpr( const GenericExpr & other );887 virtual ~GenericExpr();888 889 virtual GenericExpr * clone() const { return new GenericExpr( * this ); }890 virtual void accept( Visitor & v ) { v.visit( this ); }891 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }892 virtual void print( std::ostream & os, Indenter indent = {} ) const;893 };894 895 867 // Local Variables: // 896 868 // tab-width: 4 // -
src/SynTree/Mutator.h
r054514d rda60c631 93 93 virtual Expression * mutate( InitExpr * initExpr ) = 0; 94 94 virtual Expression * mutate( DeletedExpr * delExpr ) = 0; 95 virtual Expression * mutate( GenericExpr * genExpr ) = 0;96 95 97 96 virtual Type * mutate( VoidType * basicType ) = 0; -
src/SynTree/SynTree.h
r054514d rda60c631 101 101 class InitExpr; 102 102 class DeletedExpr; 103 class GenericExpr;104 103 105 104 class Type; -
src/SynTree/Visitor.h
r054514d rda60c631 95 95 virtual void visit( InitExpr * initExpr ) = 0; 96 96 virtual void visit( DeletedExpr * delExpr ) = 0; 97 virtual void visit( GenericExpr * genExpr ) = 0;98 97 99 98 virtual void visit( VoidType * basicType ) = 0;
Note:
See TracChangeset
for help on using the changeset viewer.