Skip to content

Commit

Permalink
Merge pull request #402 from nus-cs3203/chore/fix-code-review
Browse files Browse the repository at this point in the history
Fix QPS code review
  • Loading branch information
shaelynl authored Apr 9, 2023
2 parents 1c6deba + 75b876e commit 9c9fc05
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ QueryValidator::QueryValidator(Query* query) : query(query) {}
void QueryValidator::validateDuplicateDeclarations() {
std::unordered_set<std::string> 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);
}
Expand Down Expand Up @@ -44,7 +44,7 @@ std::unordered_set<std::string> QueryValidator::getDeclarationSynonyms() {
std::unordered_set<std::string> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ SelectClauseItem QueryParser::parseReturnValue() {
std::shared_ptr<Token> synonymToken = getNext();
std::unordered_set<std::string> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ std::shared_ptr<std::vector<SelectClauseItem>> SelectClause::getSelectClauseItem
std::string SelectClause::getSynonym(SelectClauseItem selectClauseItem) {
if (std::holds_alternative<std::shared_ptr<Synonym>>(selectClauseItem)) {
std::shared_ptr<Synonym> synonym = std::get<std::shared_ptr<Synonym>>(selectClauseItem);
return synonym->ident;
return synonym->getIdent();
} else {
AttributeReference attributeReference = std::get<AttributeReference>(selectClauseItem);
return attributeReference.getSynonym();
Expand All @@ -64,7 +64,7 @@ bool SelectClause::isAttribute(SelectClauseItem selectClauseItem) {
std::string SelectClause::getString(SelectClauseItem selectClauseItem) {
if (std::holds_alternative<std::shared_ptr<Synonym>>(selectClauseItem)) {
std::shared_ptr<Synonym> synonym = std::get<std::shared_ptr<Synonym>>(selectClauseItem);
return synonym->ident;
return synonym->getIdent();
} else {
AttributeReference attributeReference = std::get<AttributeReference>(selectClauseItem);
return attributeReference.getSynonym() + "." + attributeReference.getAttributeName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
27 changes: 15 additions & 12 deletions Team26/Code26/src/spa/src/query_processing_system/parser/Synonym.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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);
};

0 comments on commit 9c9fc05

Please sign in to comment.