Merge pull request #36230 from ahoppen/pr/ref-count-syntaxdata

[libSyntax] Reference count SyntaxData
This commit is contained in:
Alex Hoppen
2021-03-05 14:31:49 +01:00
committed by GitHub
11 changed files with 85 additions and 110 deletions

View File

@@ -56,8 +56,8 @@ class SyntaxCollection : public Syntax {
friend class Syntax;
private:
static SyntaxData makeData(std::initializer_list<Element> &Elements,
const RC<SyntaxArena> &Arena) {
static RC<const SyntaxData> makeData(std::initializer_list<Element> &Elements,
const RC<SyntaxArena> &Arena) {
std::vector<const RawSyntax *> List;
List.reserve(Elements.size());
for (auto &Elt : Elements)
@@ -68,7 +68,7 @@ private:
}
public:
SyntaxCollection(const SyntaxData Data) : Syntax(Data) {}
SyntaxCollection(const RC<const SyntaxData> &Data) : Syntax(Data) {}
SyntaxCollection(std::initializer_list<Element> list):
SyntaxCollection(SyntaxCollection::makeData(list)) {}
@@ -104,7 +104,7 @@ public:
Element operator[](const size_t Index) const {
assert(Index < size());
assert(!empty());
return Element(*Data.getChild(Index));
return Element(Data->getChild(Index));
}
/// Return a new collection with the given element added to the end.
@@ -118,7 +118,7 @@ public:
auto Raw = RawSyntax::makeAndCalcLength(CollectionKind, NewLayout,
getRaw()->getPresence(),
getRaw()->getArena());
return SyntaxCollection<CollectionKind, Element>(Data.replacingSelf(Raw));
return SyntaxCollection<CollectionKind, Element>(Data->replacingSelf(Raw));
}
/// Return a new collection with an element removed from the end.
@@ -130,7 +130,7 @@ public:
auto Raw = RawSyntax::makeAndCalcLength(CollectionKind, NewLayout,
getRaw()->getPresence(),
getRaw()->getArena());
return SyntaxCollection<CollectionKind, Element>(Data.replacingSelf(Raw));
return SyntaxCollection<CollectionKind, Element>(Data->replacingSelf(Raw));
}
/// Return a new collection with the given element appended to the front.
@@ -143,7 +143,7 @@ public:
auto Raw = RawSyntax::makeAndCalcLength(CollectionKind, NewLayout,
getRaw()->getPresence(),
getRaw()->getArena());
return SyntaxCollection<CollectionKind, Element>(Data.replacingSelf(Raw));
return SyntaxCollection<CollectionKind, Element>(Data->replacingSelf(Raw));
}
/// Return a new collection with an element removed from the end.
@@ -155,7 +155,7 @@ public:
auto Raw = RawSyntax::makeAndCalcLength(CollectionKind, NewLayout,
getRaw()->getPresence(),
getRaw()->getArena());
return SyntaxCollection<CollectionKind, Element>(Data.replacingSelf(Raw));
return SyntaxCollection<CollectionKind, Element>(Data->replacingSelf(Raw));
}
/// Return a new collection with the Element inserted at index i.
@@ -176,7 +176,7 @@ public:
auto Raw = RawSyntax::makeAndCalcLength(CollectionKind, NewLayout,
getRaw()->getPresence(),
getRaw()->getArena());
return SyntaxCollection<CollectionKind, Element>(Data.replacingSelf(Raw));
return SyntaxCollection<CollectionKind, Element>(Data->replacingSelf(Raw));
}
/// Return a new collection with the element removed at index i.
@@ -189,14 +189,14 @@ public:
auto Raw = RawSyntax::makeAndCalcLength(CollectionKind, NewLayout,
getRaw()->getPresence(),
getRaw()->getArena());
return SyntaxCollection<CollectionKind, Element>(Data.replacingSelf(Raw));
return SyntaxCollection<CollectionKind, Element>(Data->replacingSelf(Raw));
}
/// Return an empty syntax collection of this type.
SyntaxCollection<CollectionKind, Element> cleared() const {
auto Raw = RawSyntax::makeAndCalcLength(
CollectionKind, {}, getRaw()->getPresence(), getRaw()->getArena());
return SyntaxCollection<CollectionKind, Element>(Data.replacingSelf(Raw));
return SyntaxCollection<CollectionKind, Element>(Data->replacingSelf(Raw));
}
static bool kindof(SyntaxKind Kind) {