Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesLee-Jones committed Jul 15, 2024
1 parent dc93093 commit 6a8d335
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,13 @@ class MutateVisitor : public clang::RecursiveASTVisitor<MutateVisitor> {
// this special case, so that it can be ignored.
bool IsConversionOfEnumToConstructor(const clang::Expr& expr) const;

// It is safe to Dredd's prelude before the first function we encounter in a
// file as Dredd only makes source code modifications inside functions.
// It is safe to put Dredd's prelude before the first function we encounter in
// a file as Dredd only makes source code modifications inside functions.
void UpdateStartLocationOfFirstFunctionInSourceFile();

// TODO(JLJ): Add comment
void AddMutation(std::unique_ptr<Mutation> mutation);

const clang::CompilerInstance* compiler_instance_;
bool optimise_mutations_;

Expand Down
29 changes: 15 additions & 14 deletions src/libdredd/src/mutate_visitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,9 @@ void MutateVisitor::HandleUnaryOperator(clang::UnaryOperator* unary_operator) {
}
}

mutation_tree_path_.back()->AddMutation(
std::make_unique<MutationReplaceUnaryOperator>(
*unary_operator, compiler_instance_->getPreprocessor(),
compiler_instance_->getASTContext()));
AddMutation(std::make_unique<MutationReplaceUnaryOperator>(
*unary_operator, compiler_instance_->getPreprocessor(),
compiler_instance_->getASTContext()));
}

void MutateVisitor::HandleBinaryOperator(
Expand Down Expand Up @@ -405,10 +404,9 @@ void MutateVisitor::HandleBinaryOperator(
return;
}

mutation_tree_path_.back()->AddMutation(
std::make_unique<MutationReplaceBinaryOperator>(
*binary_operator, compiler_instance_->getPreprocessor(),
compiler_instance_->getASTContext()));
AddMutation(std::make_unique<MutationReplaceBinaryOperator>(
*binary_operator, compiler_instance_->getPreprocessor(),
compiler_instance_->getASTContext()));
}

void MutateVisitor::HandleExpr(clang::Expr* expr) {
Expand Down Expand Up @@ -477,7 +475,7 @@ void MutateVisitor::HandleExpr(clang::Expr* expr) {
}
}

mutation_tree_path_.back()->AddMutation(std::make_unique<MutationReplaceExpr>(
AddMutation(std::make_unique<MutationReplaceExpr>(
*expr, compiler_instance_->getPreprocessor(),
compiler_instance_->getASTContext()));
}
Expand Down Expand Up @@ -588,15 +586,18 @@ bool MutateVisitor::TraverseCompoundStmt(clang::CompoundStmt* compound_stmt) {
assert(!enclosing_decls_.empty() &&
"Statements can only be removed if they are nested in some "
"declaration.");
UpdateStartLocationOfFirstFunctionInSourceFile();
mutation_tree_path_.back()->AddMutation(
std::make_unique<MutationRemoveStmt>(
*target_stmt, compiler_instance_->getPreprocessor(),
compiler_instance_->getASTContext()));
AddMutation(std::make_unique<MutationRemoveStmt>(
*target_stmt, compiler_instance_->getPreprocessor(),
compiler_instance_->getASTContext()));
}
return true;
}

void MutateVisitor::AddMutation(std::unique_ptr<Mutation> mutation) {
UpdateStartLocationOfFirstFunctionInSourceFile();
mutation_tree_path_.back()->AddMutation(std::move(mutation));
}

bool MutateVisitor::VisitVarDecl(clang::VarDecl* var_decl) {
var_decl_source_locations_.insert(var_decl->getLocation());
return true;
Expand Down

0 comments on commit 6a8d335

Please sign in to comment.