Skip to content

Commit dffd027

Browse files
committed
Add conversion functions to ClassSymbol
Signed-off-by: Roberto Raggi <[email protected]>
1 parent 7b34f8a commit dffd027

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

src/parser/cxx/scope.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <algorithm>
2828
#include <cassert>
2929
#include <functional>
30+
#include <print>
3031

3132
namespace cxx {
3233

@@ -111,6 +112,14 @@ void Scope::addSymbol(Symbol* symbol) {
111112
symbol->setEnclosingScope(this);
112113
symbols_.push_back(symbol);
113114

115+
if (name_cast<ConversionFunctionId>(symbol->name())) {
116+
if (auto functionSymbol = symbol_cast<FunctionSymbol>(symbol)) {
117+
if (auto classSymbol = symbol_cast<ClassSymbol>(owner_)) {
118+
classSymbol->addConversionFunction(functionSymbol);
119+
}
120+
}
121+
}
122+
114123
if (3 * symbols_.size() >= 2 * buckets_.size()) {
115124
rehash();
116125
} else {

src/parser/cxx/symbols.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,15 @@ auto ClassSymbol::hasBaseClass(
215215
return false;
216216
}
217217

218+
auto ClassSymbol::conversionFunctions() const
219+
-> const std::vector<FunctionSymbol*>& {
220+
return conversionFunctions_;
221+
}
222+
223+
void ClassSymbol::addConversionFunction(FunctionSymbol* conversionFunction) {
224+
conversionFunctions_.push_back(conversionFunction);
225+
}
226+
218227
auto ClassSymbol::declaration() const -> SpecifierAST* { return specifier_; }
219228

220229
void ClassSymbol::setDeclaration(SpecifierAST* specifier) {

src/parser/cxx/symbols.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,11 @@ class ClassSymbol final : public ScopedSymbol {
246246

247247
void addConstructor(FunctionSymbol* constructor);
248248

249+
[[nodiscard]] auto conversionFunctions() const
250+
-> const std::vector<FunctionSymbol*>&;
251+
252+
void addConversionFunction(FunctionSymbol* conversionFunction);
253+
249254
[[nodiscard]] auto isFinal() const -> bool;
250255
void setFinal(bool isFinal);
251256

@@ -316,6 +321,7 @@ class ClassSymbol final : public ScopedSymbol {
316321
private:
317322
std::vector<BaseClassSymbol*> baseClasses_;
318323
std::vector<FunctionSymbol*> constructors_;
324+
std::vector<FunctionSymbol*> conversionFunctions_;
319325
std::unique_ptr<TemplateInfo<ClassSymbol>> templateInfo_;
320326
SpecifierAST* specifier_ = nullptr;
321327
TemplateDeclarationAST* templateDeclaration_ = nullptr;

0 commit comments

Comments
 (0)