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 16, 2024
1 parent d0e8674 commit f0261de
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 @@ -179,10 +179,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 @@ -368,10 +368,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 @@ -431,10 +430,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 @@ -524,7 +522,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 @@ -638,15 +636,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 f0261de

Please sign in to comment.