@@ -63,7 +63,7 @@ ASTGen::generateDeclAttributes(const Syntax &D, SourceLoc Loc,
63
63
if (auto firstTok = D.getFirstToken ()) {
64
64
auto declLoc = advanceLocBegin (Loc, *firstTok);
65
65
if (hasDeclAttributes (declLoc))
66
- return getDeclAttributes (declLoc);
66
+ return takeDeclAttributes (declLoc);
67
67
}
68
68
return DeclAttributes ();
69
69
}
@@ -234,7 +234,7 @@ Expr *ASTGen::generate(const ExprSyntax &E, const SourceLoc Loc) {
234
234
235
235
auto exprLoc = advanceLocBegin (Loc, E);
236
236
if (hasExpr (exprLoc))
237
- return getExpr (exprLoc);
237
+ return takeExpr (exprLoc);
238
238
239
239
if (auto identifierExpr = E.getAs <IdentifierExprSyntax>())
240
240
result = generate (*identifierExpr, Loc);
@@ -1457,37 +1457,35 @@ TypeRepr *ASTGen::lookupType(TypeSyntax Type) {
1457
1457
}
1458
1458
1459
1459
void ASTGen::addExpr (Expr *E, const SourceLoc Loc) {
1460
- #ifndef NDEBUG
1461
- if (hasExpr (Loc)) {
1462
- bool PrevIsSubExpr = false ;
1463
- Expr *Prev = Exprs.find (Loc)->second ;
1464
- E->forEachChildExpr ([&](Expr *Child) {
1465
- if (Child == Prev)
1466
- PrevIsSubExpr = true ;
1467
- return Child;
1468
- });
1469
- assert (PrevIsSubExpr);
1470
- }
1471
- #endif
1472
- Exprs.insert ({Loc, E});
1460
+ assert (!hasExpr (Loc));
1461
+ Exprs[Loc] = E;
1473
1462
}
1474
1463
1475
1464
bool ASTGen::hasExpr (const SourceLoc Loc) const {
1476
1465
return Exprs.find (Loc) != Exprs.end ();
1477
1466
}
1478
1467
1479
- Expr *ASTGen::getExpr (const SourceLoc Loc) const {
1480
- return Exprs.find (Loc)->second ;
1468
+ Expr *ASTGen::takeExpr (const SourceLoc Loc) {
1469
+ auto I = Exprs.find (Loc);
1470
+ assert (I != Exprs.end ());
1471
+ auto expr = I->second ;
1472
+ Exprs.erase (I);
1473
+ return expr;
1481
1474
}
1482
1475
1483
1476
void ASTGen::addDeclAttributes (DeclAttributes attrs, SourceLoc Loc) {
1484
- ParsedDeclAttrs.insert ({Loc, attrs});
1477
+ assert (!hasDeclAttributes (Loc));
1478
+ ParsedDeclAttrs[Loc] = attrs;
1485
1479
}
1486
1480
1487
1481
bool ASTGen::hasDeclAttributes (SourceLoc Loc) const {
1488
1482
return ParsedDeclAttrs.find (Loc) != ParsedDeclAttrs.end ();
1489
1483
}
1490
1484
1491
- DeclAttributes ASTGen::getDeclAttributes (SourceLoc Loc) const {
1492
- return ParsedDeclAttrs.find (Loc)->second ;
1485
+ DeclAttributes ASTGen::takeDeclAttributes (SourceLoc Loc) {
1486
+ auto I = ParsedDeclAttrs.find (Loc);
1487
+ assert (I != ParsedDeclAttrs.end ());
1488
+ auto attrs = I->second ;
1489
+ ParsedDeclAttrs.erase (I);
1490
+ return attrs;
1493
1491
}
0 commit comments