- File:
-
- 1 edited
-
src/Validate/ImplementEnumFunc.cpp (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Validate/ImplementEnumFunc.cpp
reb7586e rfc1a3e2 30 30 void genAttrFunctions(); 31 31 void genSuccPredPosn(); 32 //void genSuccPredDecl();32 void genSuccPredDecl(); 33 33 34 34 void appendReturnThis(ast::FunctionDecl* decl) { … … 73 73 const ast::Decl* getDecl() const { return decl; } 74 74 75 // Implement Bounded trait for enum76 void genBoundedFunctions();77 // Implement Serial trait for enum78 void genSerialTraitFuncs();79 80 // Bounded trait81 ast::FunctionDecl* genLowerBoundProto() const;82 ast::FunctionDecl* genUpperBoundProto() const;83 void genLowerBoundBody(ast::FunctionDecl* func) const;84 void genUpperBoundBody(ast::FunctionDecl* func) const;85 86 75 ast::FunctionDecl* genPosnProto() const; 87 76 ast::FunctionDecl* genLabelProto() const; 88 77 ast::FunctionDecl* genValueProto() const; 89 90 // Serial trait91 ast::FunctionDecl* genFromIntProto() const;92 ast::FunctionDecl* genFromInstanceProto() const;93 78 ast::FunctionDecl* genSuccProto() const; 94 79 ast::FunctionDecl* genPredProto() const; 95 96 void genFromIntBody(ast::FunctionDecl *) const;97 void genFromInstanceBody(ast::FunctionDecl *) const;98 ////////////////99 80 100 81 ast::FunctionDecl* genSuccPosProto() const; … … 308 289 309 290 ast::FunctionDecl* EnumAttrFuncGenerator::genPosnProto() const { 310 return genProto(311 "posE",312 {new ast::ObjectDecl(getLocation(), "_i", new ast::EnumInstType(decl))},313 {new ast::ObjectDecl(getLocation(), "_ret",314 new ast::BasicType(ast::BasicKind::UnsignedInt))});291 return genProto( 292 "posE", 293 {new ast::ObjectDecl(getLocation(), "_i", new ast::EnumInstType(decl))}, 294 {new ast::ObjectDecl(getLocation(), "_ret", 295 new ast::BasicType(ast::BasicKind::UnsignedInt))}); 315 296 } 316 297 … … 332 313 } 333 314 334 ast::FunctionDecl* EnumAttrFuncGenerator::genFromIntProto() const {335 return genProto(336 "fromInt",337 {new ast::ObjectDecl(getLocation(), "_i", new ast::BasicType(ast::BasicKind::UnsignedInt))},338 {new ast::ObjectDecl(getLocation(), "_ret", new ast::EnumInstType(decl))}339 );340 }341 342 ast::FunctionDecl* EnumAttrFuncGenerator::genFromInstanceProto() const {343 return genProto(344 "fromInstance",345 {new ast::ObjectDecl(getLocation(), "_i", new ast::EnumInstType(decl))},346 {new ast::ObjectDecl(getLocation(), "_ret", new ast::BasicType(ast::BasicKind::UnsignedInt))}347 );348 }349 350 void EnumAttrFuncGenerator::genFromIntBody(ast::FunctionDecl* func) const {351 auto params = func->params;352 assert( params.size() == 1 );353 auto param = params.front();354 auto castExpr = new ast::CastExpr(355 func->location,356 new ast::VariableExpr(func->location, param),357 new ast::EnumInstType(decl),358 ast::GeneratedFlag::ExplicitCast359 );360 func->stmts = new ast::CompoundStmt(361 func->location, {new ast::ReturnStmt(func->location, castExpr)}362 );363 }364 365 void EnumAttrFuncGenerator::genFromInstanceBody(ast::FunctionDecl* func) const {366 auto params = func->params;367 assert( params.size() == 1 );368 auto param = params.front();369 ast::UntypedExpr* untyped = ast::UntypedExpr::createCall(370 func->location, "posE", { new ast::VariableExpr(func->location, param) });371 func->stmts = new ast::CompoundStmt(372 func->location, {new ast::ReturnStmt(func->location, untyped)}373 );374 }375 376 void EnumAttrFuncGenerator::genSerialTraitFuncs() {377 auto fromIntProto = genFromIntProto();378 produceForwardDecl(fromIntProto);379 genFromIntBody(fromIntProto);380 produceDecl(fromIntProto);381 382 auto fromInstanceProto = genFromInstanceProto();383 produceForwardDecl(fromInstanceProto);384 genFromInstanceBody(fromInstanceProto);385 produceDecl(fromInstanceProto);386 387 auto succProto = genSuccProto();388 auto predProto = genPredProto();389 produceForwardDecl(succProto);390 produceForwardDecl(predProto);391 }392 393 315 ast::FunctionDecl* EnumAttrFuncGenerator::genSuccProto() const { 394 316 return genProto( … … 405 327 {new ast::ObjectDecl(getLocation(), "_ret", 406 328 new ast::EnumInstType(decl))}); 407 }408 409 ast::FunctionDecl* EnumAttrFuncGenerator::genLowerBoundProto() const {410 return genProto("lowerBound", {}, {411 new ast::ObjectDecl(getLocation(), "_i", new ast::EnumInstType(decl))412 });413 }414 415 ast::FunctionDecl* EnumAttrFuncGenerator::genUpperBoundProto() const {416 return genProto("upperBound", {}, {417 new ast::ObjectDecl(getLocation(), "_i", new ast::EnumInstType(decl))418 });419 }420 421 void EnumAttrFuncGenerator::genLowerBoundBody(ast::FunctionDecl* func) const {422 const CodeLocation & loc = func->location;423 auto mem = decl->members.front();424 // auto expr = new ast::QualifiedNameExpr( loc, decl, mem->name );425 // expr->result = new ast::EnumInstType( decl );426 auto expr = new ast::NameExpr( loc, mem->name );427 func->stmts = new ast::CompoundStmt( loc, {new ast::ReturnStmt(loc, expr)});428 }429 430 void EnumAttrFuncGenerator::genUpperBoundBody(ast::FunctionDecl* func) const {431 const CodeLocation & loc = func->location;432 auto mem = decl->members.back();433 auto expr = new ast::NameExpr( loc, mem->name );434 // expr->result = new ast::EnumInstType( decl );435 func->stmts = new ast::CompoundStmt( loc, {new ast::ReturnStmt(loc, expr)});436 }437 438 void EnumAttrFuncGenerator::genBoundedFunctions() {439 ast::FunctionDecl * upperDecl = genUpperBoundProto();440 produceForwardDecl(upperDecl);441 genUpperBoundBody(upperDecl);442 produceDecl(upperDecl);443 444 ast::FunctionDecl * lowerDecl = genLowerBoundProto();445 produceForwardDecl(lowerDecl);446 genLowerBoundBody(lowerDecl);447 produceDecl(lowerDecl);448 329 } 449 330 … … 492 373 func->location, "?[?]", 493 374 {new ast::NameExpr(func->location, arrDecl->name), 494 new ast::CastExpr(495 func->location,496 new ast::VariableExpr( func->location, func->params.front() ),497 new ast::EnumAttrType( new ast::EnumInstType(decl),498 ast::EnumAttribute::Posn))});375 new ast::CastExpr( 376 func->location, 377 new ast::VariableExpr( func->location, func->params.front() ), 378 new ast::EnumAttrType( new ast::EnumInstType(decl), 379 ast::EnumAttribute::Posn))}); 499 380 func->stmts = new ast::CompoundStmt( 500 381 func->location, {new ast::ReturnStmt(func->location, untyped)}); … … 569 450 570 451 void EnumAttrFuncGenerator::genAttrFunctions() { 571 genAttributesDecls(ast::EnumAttribute::Value); 572 genAttributesDecls(ast::EnumAttribute::Label); 573 genAttributesDecls(ast::EnumAttribute::Posn); 574 } 575 576 // void EnumAttrFuncGenerator::genSuccPredDecl() { 577 // auto succProto = genSuccProto(); 578 // auto predProto = genPredProto(); 579 580 // produceForwardDecl(succProto); 581 // produceForwardDecl(predProto); 582 // } 452 if (decl->base) { 453 genAttributesDecls(ast::EnumAttribute::Value); 454 genAttributesDecls(ast::EnumAttribute::Label); 455 genAttributesDecls(ast::EnumAttribute::Posn); 456 } 457 } 458 459 void EnumAttrFuncGenerator::genSuccPredDecl() { 460 if (decl->base) { 461 auto succProto = genSuccProto(); 462 auto predProto = genPredProto(); 463 464 produceForwardDecl(succProto); 465 produceForwardDecl(predProto); 466 } 467 } 583 468 584 469 void EnumAttrFuncGenerator::genSuccPredPosn() { 585 ast::FunctionDecl* succ = genSuccPredFunc(true); 586 ast::FunctionDecl* pred = genSuccPredFunc(false); 587 588 produceDecl(succ); 589 produceDecl(pred); 470 if (decl->base) { 471 ast::FunctionDecl* succ = genSuccPredFunc(true); 472 ast::FunctionDecl* pred = genSuccPredFunc(false); 473 474 produceDecl(succ); 475 produceDecl(pred); 476 } 590 477 } 591 478 … … 595 482 genAttrStandardFuncs(); 596 483 genAttrFunctions(); 597 genSerialTraitFuncs(); 598 genSuccPredPosn(); 599 // problematic 600 genBoundedFunctions(); 484 genSuccPredDecl(); 485 genSuccPredPosn(); // Posn 601 486 // Now export the lists contents. 602 487 decls.splice(decls.end(), forwards);
Note:
See TracChangeset
for help on using the changeset viewer.