-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Customize clang diagnostic handling. (#1707)
* Cutomize clang diagnostic handling. * Removed code that was commented out.
- Loading branch information
Showing
3 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
trick_source/codegen/Interface_Code_Gen/ICGDiagnosticConsumer.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include <iostream> | ||
#include "clang/Basic/SourceManager.h" | ||
#include "clang/Basic/SourceLocation.h" | ||
|
||
#include "ICGDiagnosticConsumer.hh" | ||
#include "HeaderSearchDirs.hh" | ||
#include "Utilities.hh" | ||
|
||
|
||
ICGDiagnosticConsumer::ICGDiagnosticConsumer(llvm::raw_ostream &os, clang::DiagnosticOptions *diags, clang::CompilerInstance &in_ci, HeaderSearchDirs &in_hsd) | ||
: clang::TextDiagnosticPrinter(os, diags), ci(in_ci), hsd(in_hsd) { | ||
error_in_user_code = false; | ||
}; | ||
ICGDiagnosticConsumer::~ICGDiagnosticConsumer() { | ||
|
||
}; | ||
|
||
|
||
/** | ||
* @details | ||
* -# Check the diagnostic level to see if an error is from user code. | ||
* -# Terminate the build if yes, continue otherwise. | ||
*/ | ||
void ICGDiagnosticConsumer::HandleDiagnostic(clang::DiagnosticsEngine::Level DiagLevel, const clang::Diagnostic &Info) { | ||
// Use TextDiagnosticPrinter to handle diagnostic if the code is user code. | ||
// Otherwise use base DiagnosticConsumer to handle diagnostic for system code. | ||
if (isInUserCode(ci , Info.getLocation(), hsd)) { | ||
// Parent class implementation for handling diagnostic | ||
clang::TextDiagnosticPrinter::HandleDiagnostic(DiagLevel, Info); | ||
|
||
// Flag it if an error is from user code | ||
if (DiagLevel == clang::DiagnosticsEngine::Level::Fatal || DiagLevel == clang::DiagnosticsEngine::Level::Error) { | ||
error_in_user_code = true; | ||
} | ||
} else { | ||
// Base class implementation for handling diagnostic | ||
clang::DiagnosticConsumer::HandleDiagnostic(DiagLevel, Info); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
trick_source/codegen/Interface_Code_Gen/ICGDiagnosticConsumer.hh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#ifndef ICG_DIAGNOSTICCONSUMER_HH | ||
#define ICG_DIAGNOSTICCONSUMER_HH | ||
|
||
#include "llvm/Support/raw_ostream.h" | ||
#include "clang/Basic/Diagnostic.h" | ||
#include "clang/Frontend/CompilerInstance.h" | ||
#include "clang/Frontend/TextDiagnosticPrinter.h" | ||
|
||
|
||
class HeaderSearchDirs; | ||
|
||
/** | ||
This class is passed to the clang parser as a DiagnosticConsumer. | ||
It will terminate the trick build if an error found is from user code. | ||
@date May 2024 | ||
*/ | ||
|
||
|
||
class ICGDiagnosticConsumer : public clang::TextDiagnosticPrinter { | ||
public: | ||
ICGDiagnosticConsumer(llvm::raw_ostream &os, clang::DiagnosticOptions *diags, clang::CompilerInstance &in_ci, HeaderSearchDirs &in_hsd); | ||
~ICGDiagnosticConsumer() override; | ||
|
||
void HandleDiagnostic(clang::DiagnosticsEngine::Level DiagLevel, | ||
const clang::Diagnostic &Info) override; | ||
|
||
/** Flag for if any error found in user code. */ | ||
bool error_in_user_code; | ||
|
||
protected: | ||
/** The compiler instance. */ | ||
clang::CompilerInstance &ci ; | ||
|
||
/** The header search directories. */ | ||
HeaderSearchDirs &hsd ; | ||
|
||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters