AST building #2

Merged
TopchetoEU merged 74 commits from TopchetoEU/ast-building into master 2022-10-28 11:58:03 +00:00
2 changed files with 18 additions and 14 deletions
Showing only changes of commit 1c552c2c5c - Show all commits

View File

@ -14,21 +14,16 @@ namespace ppc::lang {
located_t(Args ...args): T(args...), location(location_t::NONE) { }
};
struct namespace_name_t {
std::vector<std::string> segments;
bool is_empty() const { return segments.empty(); }
auto begin() { return segments.begin(); }
auto end() { return segments.end(); }
struct namespace_name_t : public std::vector<std::string> {
using base = std::vector<std::string>;
bool operator ==(const namespace_name_t &other) const;
const std::string &operator[](size_t i) const { return segments[i]; }
bool operator !=(const namespace_name_t &other) const;
std::string to_string() const;
namespace_name_t() { }
namespace_name_t(std::initializer_list<std::string> segments): segments(segments.begin(), segments.end()) { }
namespace_name_t(std::initializer_list<std::string> segments): base(segments.begin(), segments.end()) { }
};
bool is_identifier_valid(messages::msg_stack_t &msg_stack, ppc::location_t location, const std::string &name);

View File

@ -6,19 +6,28 @@ namespace ppc::lang {
std::string namespace_name_t::to_string() const {
std::stringstream res;
for (size_t i = 0; i < segments.size(); i++) {
for (size_t i = 0; i < size(); i++) {
if (i != 0) res << "::";
res << segments[i];
res << (*this)[i];
}
return res.str();
}
bool namespace_name_t::operator==(const namespace_name_t &other) const {
if (other.segments.size() != segments.size()) return false;
if (other.size() != size()) return false;
for (size_t i = 0; i < segments.size(); i++) {
if (other[i] != segments[i]) return false;
for (size_t i = 0; i < size(); i++) {
if (other[i] != (*this)[i]) return false;
}
return true;
}
bool namespace_name_t::operator!=(const namespace_name_t &other) const {
if (other.size() != size()) return true;
for (size_t i = 0; i < size(); i++) {
if (other[i] == (*this)[i]) return false;
}
return true;