Skip to content

Commit

Permalink
Improve attempt logging
Browse files Browse the repository at this point in the history
Prefix removed lines with "-" and added ones with "+"
  • Loading branch information
sgizler committed Oct 3, 2024
1 parent 762efb8 commit 8fff990
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
9 changes: 4 additions & 5 deletions source/OneTimeRewriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class OneTimeRewriter : public SyntaxRewriter<TDerived> {
void removeNode(const T& node, bool isNodeRemovable) {
if (shouldRemove(node, isNodeRemovable)) {
logType<T>();
std::cerr << node.toString() << "\n";
std::cerr << prefixLines(node.toString(), "-") << "\n";
DERIVED->remove(node);
rewritePoint = node.sourceRange();
state = REGISTER_CHILD;
Expand All @@ -124,7 +124,7 @@ class OneTimeRewriter : public SyntaxRewriter<TDerived> {
logType<TParent>();
for (auto item : childList) {
DERIVED->remove(*item);
std::cerr << item->toString();
std::cerr << prefixLines(item->toString(), "-");
}
std::cerr << "\n";
rewritePoint = parent.sourceRange();
Expand All @@ -135,9 +135,8 @@ class OneTimeRewriter : public SyntaxRewriter<TDerived> {
template <typename TOrig, typename TNew>
void replaceNode(const TOrig& originalNode, TNew& newNode) {
logType<TOrig>();
// NOTE: this may look weird in multiline cases
std::cerr << "-" << originalNode.toString() << "\n";
std::cerr << "+" << newNode.toString() << "\n";
std::cerr << prefixLines(originalNode.toString(), "-") << "\n";
std::cerr << prefixLines(newNode.toString(), "+") << "\n";
DERIVED->replace(originalNode, newNode);
rewritePoint = originalNode.sourceRange();
state = REGISTER_CHILD;
Expand Down
2 changes: 1 addition & 1 deletion source/PairRemovers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class PairRemover : public SyntaxRewriter<PairRemover> {
node.sourceRange() == searchedPair.first || node.sourceRange() == searchedPair.second;
if (isNodeRemovable && found && node.sourceRange() != SourceRange::NoLocation) {
logType<T>();
std::cerr << node.toString() << "\n";
std::cerr << prefixLines(node.toString(), "-") << "\n";
remove(node);
}

Expand Down
9 changes: 9 additions & 0 deletions source/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,12 @@ bool test(std::shared_ptr<SyntaxTree>& tree, AttemptStats& info) {
tmpFile << SyntaxPrinter::printFile(*tree);
return test(info);
}

std::string prefixLines(const std::string& str, const std::string& linePrefix) {
std::istringstream sstream(str);
std::string line, out;
while(getline(sstream, line)) {
out += linePrefix + line + '\n';
}
return out;
}
2 changes: 2 additions & 0 deletions source/Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,5 @@ class AttemptStats {

bool test(AttemptStats& stats);
bool test(std::shared_ptr<SyntaxTree>& tree, AttemptStats& info);

std::string prefixLines(const std::string& str, const std::string& linePrefix);

0 comments on commit 8fff990

Please sign in to comment.