Changes in / [ca8704f:733074e]
- Location:
- src/AST
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
rca8704f r733074e 10 10 // Created On : Thu May 09 15::37::05 2019 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Tue May 21 15:30:00 201913 // Update Count : 512 // Last Modified On : Fri May 17 16:01:00 2019 13 // Update Count : 4 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 constructor98 // linkage comes from constructor99 decl->extension = node->extension;100 decl->uniqueId = node->uniqueId;101 // storageClasses comes from constructor102 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 constructor112 decl->isDeleted = node->isDeleted;113 // fs comes from constructor114 return nullptr;115 }116 117 95 const ast::DeclWithType * visit( const ast::ObjectDecl * node ) override final { 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 ); 96 (void)node; 97 return nullptr; 129 98 } 130 99 131 100 const ast::DeclWithType * visit( const ast::FunctionDecl * node ) override final { 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 ); 101 (void)node; 102 return nullptr; 103 } 104 105 const ast::Decl * visit( const ast::StructDecl * node ) override final { 106 (void)node; 107 return nullptr; 108 } 109 110 const ast::Decl * visit( const ast::UnionDecl * node ) override final { 111 (void)node; 112 return nullptr; 113 } 114 115 const ast::Decl * visit( const ast::EnumDecl * node ) override final { 116 (void)node; 117 return nullptr; 118 } 119 120 const ast::Decl * visit( const ast::TraitDecl * node ) override final { 121 (void)node; 151 122 return nullptr; 152 123 } 153 124 154 125 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 ); 126 (void)node; 127 return nullptr; 178 128 } 179 129 180 130 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; 197 return nullptr; 198 } 199 200 const ast::Decl * visit( const ast::StructDecl * node ) override final { 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 ); 208 } 209 210 const ast::Decl * visit( const ast::UnionDecl * node ) override final { 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 ); 217 } 218 219 const ast::Decl * visit( const ast::EnumDecl * node ) override final { 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 ); 226 } 227 228 const ast::Decl * visit( const ast::TraitDecl * node ) override final { 229 auto decl = new TraitDecl( 230 node->name, 231 {}, 232 LinkageSpec::Spec( node->linkage.val ) 233 ); 234 return aggregatePostamble( decl, node ); 131 (void)node; 132 return nullptr; 235 133 } 236 134 237 135 const ast::AsmDecl * visit( const ast::AsmDecl * node ) override final { 238 auto decl = new AsmDecl( get<AsmStmt>().accept1( node->stmt ) ); 239 declPostamble( decl, node ); 136 (void)node; 240 137 return nullptr; 241 138 } 242 139 243 140 const ast::StaticAssertDecl * visit( const ast::StaticAssertDecl * node ) override final { 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 ) { 253 stmt->location = node->location; 254 stmt->labels = makeLabelL( stmt, node->labels ); 255 this->node = stmt; 141 (void)node; 256 142 return nullptr; 257 143 } … … 259 145 const ast::CompoundStmt * visit( const ast::CompoundStmt * node ) override final { 260 146 auto stmt = new CompoundStmt( get<Statement>().acceptL( node->kids ) ); 261 stmtPostamble( stmt, node ); 147 stmt->location = node->location; 148 stmt->labels = makeLabelL( stmt, node->labels ); 149 this->node = stmt; 262 150 return nullptr; 263 151 } … … 265 153 const ast::Stmt * visit( const ast::ExprStmt * node ) override final { 266 154 auto stmt = new ExprStmt( get<Expression>().accept1( node->expr ) ); 267 return stmtPostamble( stmt, node ); 155 stmt->location = node->location; 156 stmt->labels = makeLabelL( stmt, node->labels ); 157 this->node = stmt; 158 return nullptr; 268 159 } 269 160 … … 277 168 makeLabelL( nullptr, node->gotoLabels ) // What are these labelling? 278 169 ); 279 return stmtPostamble( stmt, node ); 170 stmt->location = node->location; 171 stmt->labels = makeLabelL( stmt, node->labels ); 172 this->node = stmt; 173 return nullptr; 280 174 } 281 175 282 176 const ast::Stmt * visit( const ast::DirectiveStmt * node ) override final { 283 177 auto stmt = new DirectiveStmt( node->directive ); 284 return stmtPostamble( stmt, node ); 178 stmt->location = node->location; 179 stmt->labels = makeLabelL( stmt, node->labels ); 180 this->node = stmt; 181 return nullptr; 285 182 } 286 183 … … 292 189 get<Statement>().acceptL( node->inits ) 293 190 ); 294 return stmtPostamble( stmt, node ); 191 stmt->location = node->location; 192 stmt->labels = makeLabelL( stmt, node->labels ); 193 this->node = stmt; 194 return nullptr; 295 195 } 296 196 … … 300 200 get<Statement>().acceptL( node->stmts ) 301 201 ); 302 return stmtPostamble( stmt, node ); 202 stmt->location = node->location; 203 stmt->labels = makeLabelL( stmt, node->labels ); 204 this->node = stmt; 205 return nullptr; 303 206 } 304 207 … … 309 212 node->isDefault() 310 213 ); 311 return stmtPostamble( stmt, node ); 214 stmt->location = node->location; 215 stmt->labels = makeLabelL( stmt, node->labels ); 216 this->node = stmt; 217 return nullptr; 312 218 } 313 219 … … 320 226 node->isDoWhile 321 227 ); 322 return stmtPostamble( stmt, node ); 228 stmt->location = node->location; 229 stmt->labels = makeLabelL( stmt, node->labels ); 230 this->node = stmt; 231 return nullptr; 323 232 } 324 233 … … 330 239 get<Statement>().accept1( node->body ) 331 240 ); 332 return stmtPostamble( stmt, node ); 241 stmt->location = node->location; 242 stmt->labels = makeLabelL( stmt, node->labels ); 243 this->node = stmt; 244 return nullptr; 333 245 } 334 246 … … 359 271 stmt->target = makeLabel( stmt, node->target ); 360 272 } 361 return stmtPostamble( stmt, node ); 273 stmt->location = node->location; 274 stmt->labels = makeLabelL( stmt, node->labels ); 275 this->node = stmt; 276 return nullptr; 362 277 } 363 278 364 279 const ast::Stmt * visit( const ast::ReturnStmt * node ) override final { 365 280 auto stmt = new ReturnStmt( get<Expression>().accept1( node->expr ) ); 366 return stmtPostamble( stmt, node ); 281 stmt->location = node->location; 282 stmt->labels = makeLabelL( stmt, node->labels ); 283 this->node = stmt; 284 return nullptr; 367 285 } 368 286 … … 384 302 get<Expression>().accept1( node->target ) 385 303 ); 386 return stmtPostamble( stmt, node ); 304 stmt->location = node->location; 305 stmt->labels = makeLabelL( stmt, node->labels ); 306 this->node = stmt; 307 return nullptr; 387 308 } 388 309 … … 394 315 get<FinallyStmt>().accept1( node->finally ) 395 316 ); 396 return stmtPostamble( stmt, node ); 317 stmt->location = node->location; 318 stmt->labels = makeLabelL( stmt, node->labels ); 319 this->node = stmt; 320 return nullptr; 397 321 } 398 322 … … 415 339 get<Statement>().accept1( node->body ) 416 340 ); 417 return stmtPostamble( stmt, node ); 341 stmt->location = node->location; 342 stmt->labels = makeLabelL( stmt, node->labels ); 343 this->node = stmt; 344 return nullptr; 418 345 } 419 346 420 347 const ast::Stmt * visit( const ast::FinallyStmt * node ) override final { 421 348 auto stmt = new FinallyStmt( get<CompoundStmt>().accept1( node->body ) ); 422 return stmtPostamble( stmt, node ); 349 stmt->location = node->location; 350 stmt->labels = makeLabelL( stmt, node->labels ); 351 this->node = stmt; 352 return nullptr; 423 353 } 424 354 … … 444 374 get<Expression>().accept1( node->orElse.cond ), 445 375 }; 446 return stmtPostamble( stmt, node ); 376 stmt->location = node->location; 377 stmt->labels = makeLabelL( stmt, node->labels ); 378 this->node = stmt; 379 return nullptr; 447 380 } 448 381 … … 452 385 get<Statement>().accept1( node->stmt ) 453 386 ); 454 return stmtPostamble( stmt, node ); 387 stmt->location = node->location; 388 stmt->labels = makeLabelL( stmt, node->labels ); 389 this->node = stmt; 390 return nullptr; 455 391 } 456 392 457 393 const ast::NullStmt * visit( const ast::NullStmt * node ) override final { 458 394 auto stmt = new NullStmt(); 459 stmtPostamble( stmt, node ); 395 stmt->location = node->location; 396 stmt->labels = makeLabelL( stmt, node->labels ); 397 this->node = stmt; 460 398 return nullptr; 461 399 } … … 463 401 const ast::Stmt * visit( const ast::DeclStmt * node ) override final { 464 402 auto stmt = new DeclStmt( get<Declaration>().accept1( node->decl ) ); 465 return stmtPostamble( stmt, node ); 403 stmt->location = node->location; 404 stmt->labels = makeLabelL( stmt, node->labels ); 405 this->node = stmt; 406 return nullptr; 466 407 } 467 408 -
src/AST/Decl.hpp
rca8704f r733074e 329 329 class StaticAssertDecl : public Decl { 330 330 public: 331 ptr<Expr> cond ;331 ptr<Expr> condition; 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 ( condition ), msg( msg ) {}335 : Decl( loc, "", {}, {} ), condition( condition ), msg( msg ) {} 336 336 337 337 const StaticAssertDecl * accept( Visitor &v ) const override { return v.visit( this ); } -
src/AST/Pass.impl.hpp
rca8704f r733074e 596 596 597 597 VISIT( 598 maybe_accept( node, &StaticAssertDecl::cond );599 maybe_accept( node, &StaticAssertDecl::msg );598 maybe_accept( node, &StaticAssertDecl::condition ); 599 maybe_accept( node, &StaticAssertDecl::msg ); 600 600 ) 601 601
Note: See TracChangeset
for help on using the changeset viewer.