Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Most of the cruft of earlier designs should be eliminated by this commit. - Moves deduction system out of main - Splits Types.h/cpp into FuncCalls and FuncEntries - Removes Debugging printfs, such that in quiet mode no debugging information should be seen - Removes unneeded header includes; As a side effect the header-include test is now only subjected to stl headers and not llvm headers, making it run considerably faster (though it may miss some edge cases)
- Loading branch information
1 parent
ee91509
commit c3a26bb
Showing
12 changed files
with
293 additions
and
218 deletions.
There are no files selected for viewing
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
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,155 @@ | ||
#include "Deductions.h" | ||
#include "Errors.h" | ||
#include "GraphBuilder.h" | ||
#include "FuncCalls.h" | ||
#include "FuncEntries.h" | ||
#include "TranslationUnit.h" | ||
|
||
#include <clang/AST/Decl.h> | ||
#include <clang/AST/Expr.h> | ||
#include <clang/Frontend/TextDiagnosticPrinter.h> | ||
#include <string> | ||
#include <vector> | ||
#include <cstdio> | ||
|
||
#pragma clang diagnostic ignored "-Wc++11-extensions" | ||
|
||
typedef CallPair Deduction; | ||
class DeductionsImpl | ||
{ | ||
public: | ||
void print_path(std::string func, GraphBuilder *gb); | ||
int length(void) const; | ||
void print(void) const; | ||
bool rt(std::string fname) const; | ||
void deduce(Deduction d); | ||
void perform_deductions(GraphBuilder *gb); | ||
void find_all(GraphBuilder *gb); | ||
int find_inconsistent(GraphBuilder *gb); | ||
std::vector<Deduction> d_list; | ||
}; | ||
|
||
Deductions::Deductions(GraphBuilder *gb) | ||
:impl(new DeductionsImpl) | ||
{ | ||
impl->find_all(gb); | ||
} | ||
|
||
Deductions::~Deductions(void) | ||
{ | ||
delete impl; | ||
} | ||
|
||
void Deductions::print(void) | ||
{ | ||
impl->print(); | ||
} | ||
|
||
int Deductions::find_inconsistent(GraphBuilder *gb) | ||
{ | ||
return impl->find_inconsistent(gb); | ||
} | ||
|
||
void DeductionsImpl::print_path(std::string func, GraphBuilder *gb) | ||
{ | ||
for(Deduction d: d_list) { | ||
if(d.second == func) { | ||
clang::DiagnosticsEngine *diag = d.TU->getDiagEng(); | ||
if(d.CE) { | ||
std::string str = d.CE->getDirectCallee()->getQualifiedNameAsString(); | ||
diag->Report(d.CE->getLocStart(), error_realtime_saftey_trace) << str; | ||
} else | ||
diag->Report(error_realtime_safety_class) << d.second << d.first; | ||
|
||
print_path(d.first, gb); | ||
return; | ||
} | ||
} | ||
|
||
FuncEntry f = gb->getFunctions()[func]; | ||
clang::DiagnosticsEngine *diag = f.TU->getDiagEng(); | ||
diag->Report(f.FDECL->getLocation(), error_realtime_saftey_trace_end) << f.FDECL->getQualifiedNameAsString(); | ||
} | ||
|
||
int DeductionsImpl::length(void) const | ||
{ | ||
return d_list.size(); | ||
} | ||
|
||
void DeductionsImpl::print(void) const | ||
{ | ||
for(Deduction d: d_list) | ||
printf("%30s :=> %30s\n", d.first.c_str(), d.second.c_str()); | ||
} | ||
|
||
bool DeductionsImpl::rt(std::string fname) const | ||
{ | ||
for(Deduction d: d_list) | ||
if(d.second == fname) | ||
return true; | ||
return false; | ||
} | ||
|
||
void DeductionsImpl::deduce(Deduction d) | ||
{ | ||
d_list.push_back(d); | ||
} | ||
|
||
void DeductionsImpl::perform_deductions(GraphBuilder *gb) | ||
{ | ||
FuncEntries &entries = gb->getFunctions(); | ||
for(auto pair:entries) { | ||
FuncEntry e = pair.second; | ||
if(!e.realtime_p() && !rt(e.name)) | ||
continue; | ||
|
||
//Deduce all children must be realtime | ||
for(CallPair c:gb->getCalls()) { | ||
if(c.first == e.name && !entries[c.second].realtime_p() | ||
&& !rt(c.second)) | ||
deduce(c); | ||
} | ||
} | ||
} | ||
|
||
void DeductionsImpl::find_all(GraphBuilder *gb) | ||
{ | ||
int len = 0; | ||
do { | ||
len = length(); | ||
perform_deductions(gb); | ||
} while(len != length()); | ||
} | ||
|
||
int DeductionsImpl::find_inconsistent(GraphBuilder *gb) | ||
{ | ||
int result = 0; //aka all is safe | ||
for(auto pair: gb->getFunctions()) { | ||
FuncEntry e = pair.second; | ||
if(e.not_realtime_p() && rt(e.name)) { | ||
clang::DiagnosticsEngine *diag = e.TU->getDiagEng(); | ||
diag->Report(e.FDECL->getLocation(), error_realtime_saftey_violation) | ||
<< e.FDECL->getQualifiedNameAsString(); | ||
|
||
print_path(e.name, gb); | ||
result |= 2; | ||
} | ||
if(!e.defined_p() && !e.realtime_p() && rt(e.name)) { | ||
//Check for function calls [virtual methods] | ||
for(auto call : gb->getCalls()) | ||
if(call.first==e.name) | ||
goto next; | ||
|
||
clang::DiagnosticsEngine *diag = e.TU->getDiagEng(); | ||
diag->Report(e.FDECL->getLocation(), warnn_realtime_saftey_unknown) | ||
<< e.FDECL->getQualifiedNameAsString(); | ||
|
||
print_path(e.name, gb); | ||
result |= 1; | ||
} | ||
next: | ||
; | ||
} | ||
return result; | ||
} | ||
|
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,13 @@ | ||
class GraphBuilder; | ||
|
||
class Deductions | ||
{ | ||
public: | ||
Deductions(GraphBuilder *gb); | ||
~Deductions(void); | ||
void print(void); | ||
int find_inconsistent(GraphBuilder *gb); | ||
private: | ||
class DeductionsImpl *impl; | ||
}; | ||
|
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 @@ | ||
#include "FuncCalls.h" | ||
#include <cstdio> | ||
|
||
#pragma clang diagnostic ignored "-Wc++11-extensions" | ||
|
||
struct FuncCallsImpl | ||
{ | ||
std::set<CallPair> cpair; | ||
}; | ||
|
||
FuncCalls::FuncCalls(void) | ||
{ | ||
impl = new FuncCallsImpl; | ||
} | ||
|
||
FuncCalls::~FuncCalls(void) | ||
{ | ||
delete impl; | ||
} | ||
|
||
void FuncCalls::add(std::string f1, std::string f2, class TranslationUnit *tu, class clang::CallExpr *ce) | ||
{ | ||
impl->cpair.insert(CallPair(f1,f2,tu,ce)); | ||
} | ||
|
||
void FuncCalls::print(void) const | ||
{ | ||
for(CallPair c:impl->cpair) | ||
printf("%30s :=> %30s\n", c.first.c_str(), c.second.c_str()); | ||
} | ||
|
||
typedef std::set<CallPair>::iterator sitr; | ||
|
||
sitr FuncCalls::begin(void) | ||
{ | ||
return impl->cpair.begin(); | ||
} | ||
|
||
sitr FuncCalls::end(void) | ||
{ | ||
return impl->cpair.end(); | ||
} |
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,37 @@ | ||
#include <utility> | ||
#include <string> | ||
#include <set> | ||
|
||
namespace clang | ||
{ | ||
class CallExpr; | ||
} | ||
|
||
class CallPair : public std::pair<std::string,std::string> | ||
{ | ||
public: | ||
CallPair(void) | ||
:std::pair<std::string,std::string>("",""),TU(NULL), CE(NULL) | ||
{} | ||
|
||
CallPair(std::string a, std::string b, class TranslationUnit *tu, class clang::CallExpr *ce) | ||
:std::pair<std::string,std::string>(a,b),TU(tu), CE(ce) | ||
{} | ||
class TranslationUnit *TU; | ||
class clang::CallExpr *CE; | ||
}; | ||
|
||
class FuncCalls | ||
{ | ||
public: | ||
FuncCalls(void); | ||
~FuncCalls(void); | ||
|
||
void print(void) const; | ||
void add(std::string f1, std::string f2, class TranslationUnit *tu, class clang::CallExpr *ce); | ||
typedef std::set<CallPair>::iterator sitr; | ||
sitr begin(void); | ||
sitr end(void); | ||
private: | ||
struct FuncCallsImpl *impl; | ||
}; |
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
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
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
Oops, something went wrong.