diff --git a/Team26/Code26/src/spa/src/query_processing_system/QueryValidator.cpp b/Team26/Code26/src/spa/src/query_processing_system/QueryValidator.cpp index eaaea714..0e504f0d 100644 --- a/Team26/Code26/src/spa/src/query_processing_system/QueryValidator.cpp +++ b/Team26/Code26/src/spa/src/query_processing_system/QueryValidator.cpp @@ -5,7 +5,7 @@ QueryValidator::QueryValidator(Query* query) : query(query) {} void QueryValidator::validateDuplicateDeclarations() { std::unordered_set declaration; for (const auto &d : query->getDeclarations()) { - std::string synonym = d->getSynonym().ident; + std::string synonym = Synonym::getSynonymIdentity(d->getSynonym()); if (declaration.find(synonym) != declaration.end()) { throw SemanticException(QueryValidatorDuplicatedSynonymInDeclaration + synonym); } @@ -44,7 +44,7 @@ std::unordered_set QueryValidator::getDeclarationSynonyms() { std::unordered_set declarationSynonyms; for (auto it = declarations.begin(); it != declarations.end(); ++it) { auto declaration = *it; - std::string declarationSynonym = declaration->getSynonym().ident; + std::string declarationSynonym = Synonym::getSynonymIdentity(declaration->getSynonym()); declarationSynonyms.insert(declarationSynonym); } return declarationSynonyms; diff --git a/Team26/Code26/src/spa/src/query_processing_system/parser/QueryParser.cpp b/Team26/Code26/src/spa/src/query_processing_system/parser/QueryParser.cpp index c2d761c3..b3438d9b 100644 --- a/Team26/Code26/src/spa/src/query_processing_system/parser/QueryParser.cpp +++ b/Team26/Code26/src/spa/src/query_processing_system/parser/QueryParser.cpp @@ -124,7 +124,7 @@ SelectClauseItem QueryParser::parseReturnValue() { std::shared_ptr synonymToken = getNext(); std::unordered_set declaration; for (const auto &d : query->getDeclarations()) { - std::string synonym = d->getSynonym().ident; + std::string synonym = Synonym::getSynonymIdentity(d->getSynonym()); if (declaration.find(synonym) != declaration.end()) { throw SemanticException(QueryValidatorDuplicatedSynonymInDeclaration + synonym); } diff --git a/Team26/Code26/src/spa/src/query_processing_system/parser/SelectClause.cpp b/Team26/Code26/src/spa/src/query_processing_system/parser/SelectClause.cpp index d8c000ca..b5c44a26 100644 --- a/Team26/Code26/src/spa/src/query_processing_system/parser/SelectClause.cpp +++ b/Team26/Code26/src/spa/src/query_processing_system/parser/SelectClause.cpp @@ -50,7 +50,7 @@ std::shared_ptr> SelectClause::getSelectClauseItem std::string SelectClause::getSynonym(SelectClauseItem selectClauseItem) { if (std::holds_alternative>(selectClauseItem)) { std::shared_ptr synonym = std::get>(selectClauseItem); - return synonym->ident; + return synonym->getIdent(); } else { AttributeReference attributeReference = std::get(selectClauseItem); return attributeReference.getSynonym(); @@ -64,7 +64,7 @@ bool SelectClause::isAttribute(SelectClauseItem selectClauseItem) { std::string SelectClause::getString(SelectClauseItem selectClauseItem) { if (std::holds_alternative>(selectClauseItem)) { std::shared_ptr synonym = std::get>(selectClauseItem); - return synonym->ident; + return synonym->getIdent(); } else { AttributeReference attributeReference = std::get(selectClauseItem); return attributeReference.getSynonym() + "." + attributeReference.getAttributeName(); diff --git a/Team26/Code26/src/spa/src/query_processing_system/parser/Synonym.cpp b/Team26/Code26/src/spa/src/query_processing_system/parser/Synonym.cpp index c1ccc9b8..fff90542 100644 --- a/Team26/Code26/src/spa/src/query_processing_system/parser/Synonym.cpp +++ b/Team26/Code26/src/spa/src/query_processing_system/parser/Synonym.cpp @@ -14,3 +14,7 @@ Synonym::Synonym(std::string ident) : ident(ident) {} std::string Synonym::getIdent() const { return ident; } + +std::string Synonym::getSynonymIdentity(const Synonym& synonym) { + return synonym.getIdent(); +} diff --git a/Team26/Code26/src/spa/src/query_processing_system/parser/Synonym.h b/Team26/Code26/src/spa/src/query_processing_system/parser/Synonym.h index b8b55813..0fa35ab6 100644 --- a/Team26/Code26/src/spa/src/query_processing_system/parser/Synonym.h +++ b/Team26/Code26/src/spa/src/query_processing_system/parser/Synonym.h @@ -7,7 +7,20 @@ // synonym : IDENT // IDENT : LETTER ( LETTER | DIGIT )* class Synonym { + private: + /** + * A string which contains the identifier as defined by Basic PQL. + */ + std::string ident; + public: + /** + * Constructor for the Synonym. + * + * @param ident The identifier that is a Synonym. + */ + explicit Synonym(std::string ident); + /** * Compares two Synonym objects. * @@ -25,17 +38,7 @@ class Synonym { */ friend std::ostream& operator << (std::ostream& ostream, const Synonym& synonym); - /** - * A string which contains the identifier as defined by Basic PQL. - */ - std::string ident; - - /** - * Constructor for the Synonym. - * - * @param ident The identifier that is a Synonym. - */ - explicit Synonym(std::string ident); - std::string getIdent() const; + + static std::string getSynonymIdentity(const Synonym& synonym); };