@@ -1443,16 +1443,78 @@ class IfConfigDecl : public Decl {
1443
1443
return D->getKind () == DeclKind::IfConfig;
1444
1444
}
1445
1445
};
1446
-
1446
+
1447
+ // / A declaration name, which may comprise one or more identifier pieces.
1448
+ class ValueName {
1449
+ // Either a single identifier piece stored inline, or a reference to an array
1450
+ // of identifier pieces owned by the ASTContext.
1451
+ llvm::PointerUnion<Identifier, Identifier*> First;
1452
+ // The size of a referenced component array, or zero if the identifier is
1453
+ // stored in-line.
1454
+ unsigned Count;
1455
+
1456
+ public:
1457
+ // / Build a null name.
1458
+ ValueName () : First(Identifier()), Count(0 ) {}
1459
+
1460
+ // / Build a simple value name with one component.
1461
+ /* implicit*/ ValueName(Identifier simpleName)
1462
+ : First(simpleName), Count(0 ) {}
1463
+
1464
+ // / Build a compound value name.
1465
+ explicit ValueName (MutableArrayRef<Identifier> components)
1466
+ : First(components.data()), Count(components.size())
1467
+ {
1468
+ assert (Count > 0 && " must have at least one name component" );
1469
+ }
1470
+
1471
+ // / Get the first name component. This is the name that is looked up in
1472
+ // / "C-style" property accesses, such as 'foo.bar' or 'foo.bar(1, 2)'.
1473
+ // /
1474
+ // / TODO: Eventually compound names should not return a name here.
1475
+ Identifier getSimpleName () const {
1476
+ if (Count)
1477
+ return *First.get <Identifier*>();
1478
+
1479
+ return First.get <Identifier>();
1480
+ }
1481
+
1482
+ // / Get the components array.
1483
+ ArrayRef<Identifier> getComponents () const {
1484
+ if (Count)
1485
+ return {First.get <Identifier*>(), Count};
1486
+ auto name = First.get <Identifier>();
1487
+ if (name.get ())
1488
+ return name;
1489
+ return {};
1490
+ }
1491
+
1492
+ explicit operator bool () const {
1493
+ if (Count)
1494
+ return true ;
1495
+ return First.get <Identifier>().get ();
1496
+ }
1497
+
1498
+ // / True if this is a simple one-component name.
1499
+ bool isSimpleName () const {
1500
+ return Count <= 1 ;
1501
+ }
1502
+
1503
+ // / True if this name is an operator.
1504
+ bool isOperator () const {
1505
+ return isSimpleName () && getSimpleName ().isOperator ();
1506
+ }
1507
+ };
1508
+
1447
1509
// / ValueDecl - All named decls that are values in the language. These can
1448
1510
// / have a type, etc.
1449
1511
class ValueDecl : public Decl {
1450
- Identifier Name;
1512
+ ValueName Name;
1451
1513
SourceLoc NameLoc;
1452
1514
Type Ty;
1453
1515
1454
1516
protected:
1455
- ValueDecl (DeclKind K, DeclContext *DC, Identifier name, SourceLoc NameLoc)
1517
+ ValueDecl (DeclKind K, DeclContext *DC, ValueName name, SourceLoc NameLoc)
1456
1518
: Decl(K, DC), Name(name), NameLoc(NameLoc) {
1457
1519
ValueDeclBits.ConformsToProtocolRequrement = false ;
1458
1520
}
@@ -1466,10 +1528,14 @@ class ValueDecl : public Decl {
1466
1528
// / swift code.
1467
1529
bool isDefinition () const ;
1468
1530
1469
- bool hasName () const { return !Name.empty (); }
1470
- Identifier getName () const { return Name; }
1531
+ bool hasName () const { return bool (Name); }
1532
+ // / TODO: Rename to getSimpleName?
1533
+ Identifier getName () const { return Name.getSimpleName (); }
1471
1534
bool isOperator () const { return Name.isOperator (); }
1472
-
1535
+ // / TODO: Rename to getName?
1536
+ ValueName getFullName () const { return Name; }
1537
+
1538
+
1473
1539
SourceLoc getNameLoc () const { return NameLoc; }
1474
1540
SourceLoc getLoc () const { return NameLoc; }
1475
1541
0 commit comments