Changeset 112fe04
- Timestamp:
- May 21, 2019, 3:35:39 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- ca8704f
- Parents:
- e0016a5
- Location:
- src/AST
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
re0016a5 r112fe04 10 10 // Created On : Thu May 09 15::37::05 2019 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri May 17 16:01:00 201913 // Update Count : 412 // Last Modified On : Tue May 21 15:30:00 2019 13 // Update Count : 5 14 14 // 15 15 … … 93 93 94 94 private: 95 void declPostamble( Declaration * decl, const ast::Decl * node ) { 96 decl->location = node->location; 97 // name comes from constructor 98 // linkage comes from constructor 99 decl->extension = node->extension; 100 decl->uniqueId = node->uniqueId; 101 // storageClasses comes from constructor 102 this->node = decl; 103 } 104 105 const ast::DeclWithType * declWithTypePostamble ( 106 DeclarationWithType * decl, const ast::DeclWithType * node ) { 107 declPostamble( decl, node ); 108 decl->mangleName = node->mangleName; 109 decl->scopeLevel = node->scopeLevel; 110 decl->asmName = get<Expression>().accept1( node->asmName ); 111 // attributes comes from constructor 112 decl->isDeleted = node->isDeleted; 113 // fs comes from constructor 114 return nullptr; 115 } 116 95 117 const ast::DeclWithType * visit( const ast::ObjectDecl * node ) override final { 96 (void)node; 97 return nullptr; 118 auto decl = new ObjectDecl( 119 node->name, 120 Type::StorageClasses( node->storage.val ), 121 LinkageSpec::Spec( node->linkage.val ), 122 get<Expression>().accept1( node->bitfieldWidth ), 123 get<Type>().accept1( node->type ), 124 get<Initializer>().accept1( node->init ), 125 get<Attribute>().acceptL( node->attributes ), 126 Type::FuncSpecifiers( node->funcSpec.val ) 127 ); 128 return declWithTypePostamble( decl, node ); 98 129 } 99 130 100 131 const ast::DeclWithType * visit( const ast::FunctionDecl * node ) override final { 101 (void)node; 132 auto decl = new FunctionDecl( 133 node->name, 134 Type::StorageClasses( node->storage.val ), 135 LinkageSpec::Spec( node->linkage.val ), 136 get<FunctionType>().accept1( node->type ), 137 get<CompoundStmt>().accept1( node->stmts ), 138 get<Attribute>().acceptL( node->attributes ), 139 Type::FuncSpecifiers( node->funcSpec.val ) 140 ); 141 decl->withExprs = get<Expression>().acceptL( node->withExprs ); 142 return declWithTypePostamble( decl, node ); 143 } 144 145 // NamedTypeDecl 146 const ast::Decl * namedTypePostamble( NamedTypeDecl * decl, const ast::NamedTypeDecl * node ) { 147 declPostamble( decl, node ); 148 // base comes from constructor 149 decl->parameters = get<TypeDecl>().acceptL( node->params ); 150 decl->assertions = get<DeclarationWithType>().acceptL( node->assertions ); 151 return nullptr; 152 } 153 154 const ast::Decl * visit( const ast::TypeDecl * node ) override final { 155 TypeDecl::Kind kind; 156 switch (node->kind) { 157 case ast::TypeVar::Dtype: 158 kind = TypeDecl::Dtype; 159 break; 160 case ast::TypeVar::Ftype: 161 kind = TypeDecl::Ftype; 162 break; 163 case ast::TypeVar::Ttype: 164 kind = TypeDecl::Ttype; 165 break; 166 default: 167 assertf(false, "Invalid ast::TypeVar::Kind: %d\n", node->kind); 168 }; 169 auto decl = new TypeDecl( 170 node->name, 171 Type::StorageClasses( node->storage.val ), 172 get<Type>().accept1( node->base ), 173 kind, 174 node->sized, 175 get<Type>().accept1( node->init ) 176 ); 177 return namedTypePostamble( decl, node ); 178 } 179 180 const ast::Decl * visit( const ast::TypedefDecl * node ) override final { 181 auto decl = new TypedefDecl( 182 node->name, 183 node->location, 184 Type::StorageClasses( node->storage.val ), 185 get<Type>().accept1( node->base ), 186 LinkageSpec::Spec( node->linkage.val ) 187 ); 188 return namedTypePostamble( decl, node ); 189 } 190 191 const ast::Decl * aggregatePostamble( AggregateDecl * decl, const ast::AggregateDecl * node ) { 192 decl->members = get<Declaration>().acceptL( node->members ); 193 decl->parameters = get<TypeDecl>().acceptL( node->params ); 194 decl->body = node->body; 195 // attributes come from constructor 196 // TODO: Need caching for: decl->parent = node->parent; 102 197 return nullptr; 103 198 } 104 199 105 200 const ast::Decl * visit( const ast::StructDecl * node ) override final { 106 (void)node; 107 return nullptr; 201 auto decl = new StructDecl( 202 node->name, 203 node->kind, 204 get<Attribute>().acceptL( node->attributes ), 205 LinkageSpec::Spec( node->linkage.val ) 206 ); 207 return aggregatePostamble( decl, node ); 108 208 } 109 209 110 210 const ast::Decl * visit( const ast::UnionDecl * node ) override final { 111 (void)node; 112 return nullptr; 211 auto decl = new UnionDecl( 212 node->name, 213 get<Attribute>().acceptL( node->attributes ), 214 LinkageSpec::Spec( node->linkage.val ) 215 ); 216 return aggregatePostamble( decl, node ); 113 217 } 114 218 115 219 const ast::Decl * visit( const ast::EnumDecl * node ) override final { 116 (void)node; 117 return nullptr; 220 auto decl = new EnumDecl( 221 node->name, 222 get<Attribute>().acceptL( node->attributes ), 223 LinkageSpec::Spec( node->linkage.val ) 224 ); 225 return aggregatePostamble( decl, node ); 118 226 } 119 227 120 228 const ast::Decl * visit( const ast::TraitDecl * node ) override final { 121 (void)node; 122 return nullptr; 123 } 124 125 const ast::Decl * visit( const ast::TypeDecl * node ) override final { 126 (void)node; 127 return nullptr; 128 } 129 130 const ast::Decl * visit( const ast::TypedefDecl * node ) override final { 131 (void)node; 132 return nullptr; 229 auto decl = new TraitDecl( 230 node->name, 231 {}, 232 LinkageSpec::Spec( node->linkage.val ) 233 ); 234 return aggregatePostamble( decl, node ); 133 235 } 134 236 135 237 const ast::AsmDecl * visit( const ast::AsmDecl * node ) override final { 136 (void)node; 238 auto decl = new AsmDecl( get<AsmStmt>().accept1( node->stmt ) ); 239 declPostamble( decl, node ); 137 240 return nullptr; 138 241 } 139 242 140 243 const ast::StaticAssertDecl * visit( const ast::StaticAssertDecl * node ) override final { 141 (void)node; 142 return nullptr; 143 } 144 145 const ast::CompoundStmt * visit( const ast::CompoundStmt * node ) override final { 146 auto stmt = new CompoundStmt( get<Statement>().acceptL( node->kids ) ); 244 auto decl = new StaticAssertDecl( 245 get<Expression>().accept1( node->cond ), 246 get<ConstantExpr>().accept1( node->msg ) 247 ); 248 declPostamble( decl, node ); 249 return nullptr; 250 } 251 252 const ast::Stmt * stmtPostamble( Statement * stmt, const ast::Stmt * node ) { 147 253 stmt->location = node->location; 148 254 stmt->labels = makeLabelL( stmt, node->labels ); … … 151 257 } 152 258 259 const ast::CompoundStmt * visit( const ast::CompoundStmt * node ) override final { 260 auto stmt = new CompoundStmt( get<Statement>().acceptL( node->kids ) ); 261 stmtPostamble( stmt, node ); 262 return nullptr; 263 } 264 153 265 const ast::Stmt * visit( const ast::ExprStmt * node ) override final { 154 266 auto stmt = new ExprStmt( get<Expression>().accept1( node->expr ) ); 155 stmt->location = node->location; 156 stmt->labels = makeLabelL( stmt, node->labels ); 157 this->node = stmt; 158 return nullptr; 267 return stmtPostamble( stmt, node ); 159 268 } 160 269 … … 168 277 makeLabelL( nullptr, node->gotoLabels ) // What are these labelling? 169 278 ); 170 stmt->location = node->location; 171 stmt->labels = makeLabelL( stmt, node->labels ); 172 this->node = stmt; 173 return nullptr; 279 return stmtPostamble( stmt, node ); 174 280 } 175 281 176 282 const ast::Stmt * visit( const ast::DirectiveStmt * node ) override final { 177 283 auto stmt = new DirectiveStmt( node->directive ); 178 stmt->location = node->location; 179 stmt->labels = makeLabelL( stmt, node->labels ); 180 this->node = stmt; 181 return nullptr; 284 return stmtPostamble( stmt, node ); 182 285 } 183 286 … … 189 292 get<Statement>().acceptL( node->inits ) 190 293 ); 191 stmt->location = node->location; 192 stmt->labels = makeLabelL( stmt, node->labels ); 193 this->node = stmt; 194 return nullptr; 294 return stmtPostamble( stmt, node ); 195 295 } 196 296 … … 200 300 get<Statement>().acceptL( node->stmts ) 201 301 ); 202 stmt->location = node->location; 203 stmt->labels = makeLabelL( stmt, node->labels ); 204 this->node = stmt; 205 return nullptr; 302 return stmtPostamble( stmt, node ); 206 303 } 207 304 … … 212 309 node->isDefault() 213 310 ); 214 stmt->location = node->location; 215 stmt->labels = makeLabelL( stmt, node->labels ); 216 this->node = stmt; 217 return nullptr; 311 return stmtPostamble( stmt, node ); 218 312 } 219 313 … … 226 320 node->isDoWhile 227 321 ); 228 stmt->location = node->location; 229 stmt->labels = makeLabelL( stmt, node->labels ); 230 this->node = stmt; 231 return nullptr; 322 return stmtPostamble( stmt, node ); 232 323 } 233 324 … … 239 330 get<Statement>().accept1( node->body ) 240 331 ); 241 stmt->location = node->location; 242 stmt->labels = makeLabelL( stmt, node->labels ); 243 this->node = stmt; 244 return nullptr; 332 return stmtPostamble( stmt, node ); 245 333 } 246 334 … … 271 359 stmt->target = makeLabel( stmt, node->target ); 272 360 } 273 stmt->location = node->location; 274 stmt->labels = makeLabelL( stmt, node->labels ); 275 this->node = stmt; 276 return nullptr; 361 return stmtPostamble( stmt, node ); 277 362 } 278 363 279 364 const ast::Stmt * visit( const ast::ReturnStmt * node ) override final { 280 365 auto stmt = new ReturnStmt( get<Expression>().accept1( node->expr ) ); 281 stmt->location = node->location; 282 stmt->labels = makeLabelL( stmt, node->labels ); 283 this->node = stmt; 284 return nullptr; 366 return stmtPostamble( stmt, node ); 285 367 } 286 368 … … 302 384 get<Expression>().accept1( node->target ) 303 385 ); 304 stmt->location = node->location; 305 stmt->labels = makeLabelL( stmt, node->labels ); 306 this->node = stmt; 307 return nullptr; 386 return stmtPostamble( stmt, node ); 308 387 } 309 388 … … 315 394 get<FinallyStmt>().accept1( node->finally ) 316 395 ); 317 stmt->location = node->location; 318 stmt->labels = makeLabelL( stmt, node->labels ); 319 this->node = stmt; 320 return nullptr; 396 return stmtPostamble( stmt, node ); 321 397 } 322 398 … … 339 415 get<Statement>().accept1( node->body ) 340 416 ); 341 stmt->location = node->location; 342 stmt->labels = makeLabelL( stmt, node->labels ); 343 this->node = stmt; 344 return nullptr; 417 return stmtPostamble( stmt, node ); 345 418 } 346 419 347 420 const ast::Stmt * visit( const ast::FinallyStmt * node ) override final { 348 421 auto stmt = new FinallyStmt( get<CompoundStmt>().accept1( node->body ) ); 349 stmt->location = node->location; 350 stmt->labels = makeLabelL( stmt, node->labels ); 351 this->node = stmt; 352 return nullptr; 422 return stmtPostamble( stmt, node ); 353 423 } 354 424 … … 374 444 get<Expression>().accept1( node->orElse.cond ), 375 445 }; 376 stmt->location = node->location; 377 stmt->labels = makeLabelL( stmt, node->labels ); 378 this->node = stmt; 379 return nullptr; 446 return stmtPostamble( stmt, node ); 380 447 } 381 448 … … 385 452 get<Statement>().accept1( node->stmt ) 386 453 ); 387 stmt->location = node->location; 388 stmt->labels = makeLabelL( stmt, node->labels ); 389 this->node = stmt; 390 return nullptr; 454 return stmtPostamble( stmt, node ); 391 455 } 392 456 393 457 const ast::NullStmt * visit( const ast::NullStmt * node ) override final { 394 458 auto stmt = new NullStmt(); 395 stmt->location = node->location; 396 stmt->labels = makeLabelL( stmt, node->labels ); 397 this->node = stmt; 459 stmtPostamble( stmt, node ); 398 460 return nullptr; 399 461 } … … 401 463 const ast::Stmt * visit( const ast::DeclStmt * node ) override final { 402 464 auto stmt = new DeclStmt( get<Declaration>().accept1( node->decl ) ); 403 stmt->location = node->location; 404 stmt->labels = makeLabelL( stmt, node->labels ); 405 this->node = stmt; 406 return nullptr; 465 return stmtPostamble( stmt, node ); 407 466 } 408 467 -
src/AST/Decl.hpp
re0016a5 r112fe04 329 329 class StaticAssertDecl : public Decl { 330 330 public: 331 ptr<Expr> cond ition;331 ptr<Expr> cond; 332 332 ptr<ConstantExpr> msg; // string literal 333 333 334 334 StaticAssertDecl( const CodeLocation & loc, const Expr * condition, const ConstantExpr * msg ) 335 : Decl( loc, "", {}, {} ), cond ition( condition ), msg( msg ) {}335 : Decl( loc, "", {}, {} ), cond( condition ), msg( msg ) {} 336 336 337 337 const StaticAssertDecl * accept( Visitor &v ) const override { return v.visit( this ); } -
src/AST/Pass.impl.hpp
re0016a5 r112fe04 596 596 597 597 VISIT( 598 maybe_accept( node, &StaticAssertDecl::cond ition);599 maybe_accept( node, &StaticAssertDecl::msg 598 maybe_accept( node, &StaticAssertDecl::cond ); 599 maybe_accept( node, &StaticAssertDecl::msg ); 600 600 ) 601 601
Note: See TracChangeset
for help on using the changeset viewer.