Skip to content

Commit cefca61

Browse files
committed
out-of-line method declarations
1 parent a69f85b commit cefca61

File tree

2 files changed

+161
-105
lines changed

2 files changed

+161
-105
lines changed

common/ast/metadata.h

Lines changed: 87 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -326,32 +326,20 @@ class ListTypeSpec {
326326
public:
327327
ListTypeSpec() = default;
328328

329-
ListTypeSpec(const ListTypeSpec& rhs)
330-
: elem_type_(std::make_unique<TypeSpec>(rhs.elem_type())) {}
331-
ListTypeSpec& operator=(const ListTypeSpec& rhs) {
332-
elem_type_ = std::make_unique<TypeSpec>(rhs.elem_type());
333-
return *this;
334-
}
329+
ListTypeSpec(const ListTypeSpec& rhs);
330+
ListTypeSpec& operator=(const ListTypeSpec& rhs);
335331
ListTypeSpec(ListTypeSpec&& rhs) = default;
336332
ListTypeSpec& operator=(ListTypeSpec&& rhs) = default;
337333

338-
explicit ListTypeSpec(std::unique_ptr<TypeSpec> elem_type)
339-
: elem_type_(std::move(elem_type)) {}
334+
explicit ListTypeSpec(std::unique_ptr<TypeSpec> elem_type);
340335

341-
void set_elem_type(std::unique_ptr<TypeSpec> elem_type) {
342-
elem_type_ = std::move(elem_type);
343-
}
336+
void set_elem_type(std::unique_ptr<TypeSpec> elem_type);
344337

345338
bool has_elem_type() const { return elem_type_ != nullptr; }
346339

347340
const TypeSpec& elem_type() const;
348341

349-
TypeSpec& mutable_elem_type() {
350-
if (elem_type_ == nullptr) {
351-
elem_type_ = std::make_unique<TypeSpec>();
352-
}
353-
return *elem_type_;
354-
}
342+
TypeSpec& mutable_elem_type();
355343

356344
bool operator==(const ListTypeSpec& other) const;
357345

@@ -365,28 +353,16 @@ class MapTypeSpec {
365353
public:
366354
MapTypeSpec() = default;
367355
MapTypeSpec(std::unique_ptr<TypeSpec> key_type,
368-
std::unique_ptr<TypeSpec> value_type)
369-
: key_type_(std::move(key_type)), value_type_(std::move(value_type)) {}
370-
371-
MapTypeSpec(const MapTypeSpec& rhs)
372-
: key_type_(std::make_unique<TypeSpec>(rhs.key_type())),
373-
value_type_(std::make_unique<TypeSpec>(rhs.value_type())) {}
374-
MapTypeSpec& operator=(const MapTypeSpec& rhs) {
375-
key_type_ = std::make_unique<TypeSpec>(rhs.key_type());
376-
value_type_ = std::make_unique<TypeSpec>(rhs.value_type());
356+
std::unique_ptr<TypeSpec> value_type);
377357

378-
return *this;
379-
}
358+
MapTypeSpec(const MapTypeSpec& rhs);
359+
MapTypeSpec& operator=(const MapTypeSpec& rhs);
380360
MapTypeSpec(MapTypeSpec&& rhs) = default;
381361
MapTypeSpec& operator=(MapTypeSpec&& rhs) = default;
382362

383-
void set_key_type(std::unique_ptr<TypeSpec> key_type) {
384-
key_type_ = std::move(key_type);
385-
}
363+
void set_key_type(std::unique_ptr<TypeSpec> key_type);
386364

387-
void set_value_type(std::unique_ptr<TypeSpec> value_type) {
388-
value_type_ = std::move(value_type);
389-
}
365+
void set_value_type(std::unique_ptr<TypeSpec> value_type);
390366

391367
bool has_key_type() const { return key_type_ != nullptr; }
392368

@@ -398,19 +374,9 @@ class MapTypeSpec {
398374

399375
bool operator==(const MapTypeSpec& other) const;
400376

401-
TypeSpec& mutable_key_type() {
402-
if (key_type_ == nullptr) {
403-
key_type_ = std::make_unique<TypeSpec>();
404-
}
405-
return *key_type_;
406-
}
377+
TypeSpec& mutable_key_type();
407378

408-
TypeSpec& mutable_value_type() {
409-
if (value_type_ == nullptr) {
410-
value_type_ = std::make_unique<TypeSpec>();
411-
}
412-
return *value_type_;
413-
}
379+
TypeSpec& mutable_value_type();
414380

415381
private:
416382
// The type of the key.
@@ -435,22 +401,15 @@ class FunctionTypeSpec {
435401
FunctionTypeSpec(FunctionTypeSpec&&) = default;
436402
FunctionTypeSpec& operator=(FunctionTypeSpec&&) = default;
437403

438-
void set_result_type(std::unique_ptr<TypeSpec> result_type) {
439-
result_type_ = std::move(result_type);
440-
}
404+
void set_result_type(std::unique_ptr<TypeSpec> result_type);
441405

442406
void set_arg_types(std::vector<TypeSpec> arg_types);
443407

444408
bool has_result_type() const { return result_type_ != nullptr; }
445409

446410
const TypeSpec& result_type() const;
447411

448-
TypeSpec& mutable_result_type() {
449-
if (result_type_ == nullptr) {
450-
result_type_ = std::make_unique<TypeSpec>();
451-
}
452-
return *result_type_;
453-
}
412+
TypeSpec& mutable_result_type();
454413

455414
const std::vector<TypeSpec>& arg_types() const { return arg_types_; }
456415

@@ -850,6 +809,79 @@ class Reference {
850809
absl::optional<Constant> value_;
851810
};
852811

812+
////////////////////////////////////////////////////////////////////////
813+
// Out-of-line method declarations
814+
////////////////////////////////////////////////////////////////////////
815+
816+
inline ListTypeSpec::ListTypeSpec(const ListTypeSpec& rhs)
817+
: elem_type_(std::make_unique<TypeSpec>(rhs.elem_type())) {}
818+
819+
inline ListTypeSpec& ListTypeSpec::operator=(const ListTypeSpec& rhs) {
820+
elem_type_ = std::make_unique<TypeSpec>(rhs.elem_type());
821+
return *this;
822+
}
823+
824+
inline ListTypeSpec::ListTypeSpec(std::unique_ptr<TypeSpec> elem_type)
825+
: elem_type_(std::move(elem_type)) {}
826+
827+
inline void ListTypeSpec::set_elem_type(std::unique_ptr<TypeSpec> elem_type) {
828+
elem_type_ = std::move(elem_type);
829+
}
830+
831+
inline TypeSpec& ListTypeSpec::mutable_elem_type() {
832+
if (elem_type_ == nullptr) {
833+
elem_type_ = std::make_unique<TypeSpec>();
834+
}
835+
return *elem_type_;
836+
}
837+
838+
inline MapTypeSpec::MapTypeSpec(std::unique_ptr<TypeSpec> key_type,
839+
std::unique_ptr<TypeSpec> value_type)
840+
: key_type_(std::move(key_type)), value_type_(std::move(value_type)) {}
841+
842+
inline MapTypeSpec::MapTypeSpec(const MapTypeSpec& rhs)
843+
: key_type_(std::make_unique<TypeSpec>(rhs.key_type())),
844+
value_type_(std::make_unique<TypeSpec>(rhs.value_type())) {}
845+
846+
inline MapTypeSpec& MapTypeSpec::operator=(const MapTypeSpec& rhs) {
847+
key_type_ = std::make_unique<TypeSpec>(rhs.key_type());
848+
value_type_ = std::make_unique<TypeSpec>(rhs.value_type());
849+
return *this;
850+
}
851+
852+
inline void MapTypeSpec::set_key_type(std::unique_ptr<TypeSpec> key_type) {
853+
key_type_ = std::move(key_type);
854+
}
855+
856+
inline void MapTypeSpec::set_value_type(std::unique_ptr<TypeSpec> value_type) {
857+
value_type_ = std::move(value_type);
858+
}
859+
860+
inline TypeSpec& MapTypeSpec::mutable_key_type() {
861+
if (key_type_ == nullptr) {
862+
key_type_ = std::make_unique<TypeSpec>();
863+
}
864+
return *key_type_;
865+
}
866+
867+
inline TypeSpec& MapTypeSpec::mutable_value_type() {
868+
if (value_type_ == nullptr) {
869+
value_type_ = std::make_unique<TypeSpec>();
870+
}
871+
return *value_type_;
872+
}
873+
874+
inline void FunctionTypeSpec::set_result_type(std::unique_ptr<TypeSpec> result_type) {
875+
result_type_ = std::move(result_type);
876+
}
877+
878+
inline TypeSpec& FunctionTypeSpec::mutable_result_type() {
879+
if (result_type_ == nullptr) {
880+
result_type_ = std::make_unique<TypeSpec>();
881+
}
882+
return *result_type_;
883+
}
884+
853885
////////////////////////////////////////////////////////////////////////
854886
// Implementation details
855887
////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)