Skip to content

Commit

Permalink
Fix a couple bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
novafacing committed Mar 16, 2023
1 parent d57f57a commit e76e4e0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 36 deletions.
1 change: 0 additions & 1 deletion include/Rule2aCheck.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ private:
std::vector<size_t> over_length_lines;
std::vector<size_t> broken_lines;
std::unordered_map<size_t, size_t> indent_map;
size_t indent_level;
std::deque<SourceLocation> opens;
std::deque<SourceLocation> closes;
std::deque<SourceRange> broken_ranges;
Expand Down
46 changes: 14 additions & 32 deletions src/Rule2aCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,6 @@ Rule2aCheck::Rule2aCheck(StringRef Name, ClangTidyContext *Context)
}
}

static bool hasCompoundChildRec(const Stmt *stmt) {
if (dyn_cast<WhileStmt>(stmt) || dyn_cast<DoStmt>(stmt) ||
dyn_cast<ForStmt>(stmt) || dyn_cast<IfStmt>(stmt) ||
dyn_cast<SwitchStmt>(stmt) ||
(dyn_cast<DeclStmt>(stmt) &&
(dyn_cast<RecordDecl>(dyn_cast<DeclStmt>(stmt)->getSingleDecl()) ||
dyn_cast<EnumDecl>(dyn_cast<DeclStmt>(stmt)->getSingleDecl())))) {
return true;
}
if (auto compound = dyn_cast<CompoundStmt>(stmt)) {
return true;
}

for (auto child : stmt->children()) {
return hasCompoundChildRec(child);
}

return false;
}

void Rule2aCheck::registerMatchers(MatchFinder *Finder) {
this->register_relex_matchers(Finder, this);
Finder->addMatcher(recordDecl().bind("record"), this);
Expand Down Expand Up @@ -576,22 +556,24 @@ void Rule2aCheck::onEndOfTranslationUnit(void) {
// << 0 << spc_ct(ws);
}
} else if (breakable) {
if (spc_ct(ws) != indent_amount + INDENT_AMOUNT) {
if (spc_ct(ws) < indent_amount + INDENT_AMOUNT) {
auto errmsg = diag(tok.getLocation(),
"Incorrect indentation level for broken "
"line. Expected %0, got %1")
"line. Expected at least %0, got %1")
<< indent_amount + INDENT_AMOUNT << spc_ct(ws);
if (spc_ct(ws) < indent_amount + INDENT_AMOUNT) {
errmsg << FixItHint::CreateRemoval(SourceRange(
tok.getLocation().getLocWithOffset(
-(indent_amount + INDENT_AMOUNT - spc_ct(ws))),
tok.getLocation()));
} else {
errmsg << FixItHint::CreateInsertion(
errmsg << FixItHint::CreateInsertion(
tok.getLocation(),
std::string(indent_amount + INDENT_AMOUNT - spc_ct(ws), ' '));
}
if (spc_ct(ws) % INDENT_AMOUNT != 0) {
auto errmsg =
diag(
tok.getLocation(),
std::string(indent_amount + INDENT_AMOUNT - spc_ct(ws),
' '));
}
"Indentation of %0 for broken line is not a multiple of %1")
<< spc_ct(ws) << INDENT_AMOUNT;
errmsg << FixItHint::CreateInsertion(
tok.getLocation(),
std::string(INDENT_AMOUNT - (spc_ct(ws) % INDENT_AMOUNT), ' '));
}
} else if (spc_ct(ws) != indent_amount) {
// This error falls under 4.A and is displayed there
Expand Down
26 changes: 23 additions & 3 deletions test/ettest/testcases/regression/tests/rule2b_59_17_crash/hw3.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
#ifndef HW_3_H
#define HW_3_H
#ifndef HW3_H
#define HW3_H

#endif // HW_3_H
#define RECORD_ERROR (1)
#define BAD_DATA (2)
#define NO_DATA_POINTS (3)
#define MAX_PLAYERS (4)
#define NUM_ATTR (5)
#define MAX_NAME_LEN (6)
#define NUM_COLS (7)
#define OK (0)
#define BAD_ROW (8)
#define FILE_WRITE_ERR (9)
#define BAD_RANGE (10)
#define NO_SUCH_DATA (11)
#define BAD_PLAYER (12)
#define IN_PER_CM (13)
#define LB_PER_KG (14)
#define OUT_OF_BOUNDS (15)
#define MAX_UNIT_LEN (16)
#define FILE_READ_ERR (17)
#define NO_ATTEMPTS (18)

#endif // HW3_H

0 comments on commit e76e4e0

Please sign in to comment.