Skip to content

Commit

Permalink
Add filename only to static functions/globals and record decls
Browse files Browse the repository at this point in the history
For non-static functions/globals, it's not required to output the filename,
as the names already are unique.

T45
  • Loading branch information
lfueracker committed Aug 2, 2017
1 parent 53078ba commit fcea18b
Showing 1 changed file with 36 additions and 16 deletions.
52 changes: 36 additions & 16 deletions clang-plugin/clang-hash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -225,16 +225,25 @@ class HashTranslationUnitConsumer : public ASTConsumer {
const bool IsNonExternVariableDeclaration =
isa<VarDecl>(D) && !cast<VarDecl>(D)->hasExternalStorage();

if (IsFunctionDefinition) {// Ignore declarations without definition
if (cast<FunctionDecl>(D)->getStorageClass() == SC_Static)
bool AppendFilename = false;
if (IsFunctionDefinition) { // Ignore declarations without definition
if (cast<FunctionDecl>(D)->getStorageClass() == SC_Static) {
*Terminal << "(\"static function:";
else
AppendFilename = true;
} else {
*Terminal << "(\"function:";
} else if (IsNonExternVariableDeclaration) // Ignore extern variables
*Terminal << "(\"variable:";
else if (isa<RecordDecl>(D))
}
} else if (IsNonExternVariableDeclaration) { // Ignore extern variables
if (cast<VarDecl>(D)->getStorageClass() == SC_Static) {
*Terminal << "(\"static variable:";
AppendFilename = true;
} else {
*Terminal << "(\"variable:";
}
} else if (isa<RecordDecl>(D)) {
*Terminal << "(\"record:";
else
AppendFilename = true;
} else
continue;

if (cast<NamedDecl>(D)->getName() != "") {
Expand All @@ -248,28 +257,39 @@ class HashTranslationUnitConsumer : public ASTConsumer {
->getCanonicalTypeInternal()
.getAsString();
}
// Append the filename to the symbol's name
const auto Filename = CI.getSourceManager().getFilename(D->getLocation());
*Terminal << ":" << (Filename.startswith("./") ? Filename.slice(2, Filename.size()) : Filename);
if (AppendFilename) {
// Append the filename to the symbol's name
const auto Filename = CI.getSourceManager().getFilename(D->getLocation());
*Terminal << ":" << (Filename.startswith("./") ? Filename.slice(2, Filename.size()) : Filename);
}
*Terminal << "\", \"";
*Terminal << Dig.asString();
*Terminal << "\"";

if (IsFunctionDefinition || IsNonExternVariableDeclaration) {
*Terminal << ", [";
for (const auto &SavedCallee : Visitor.DefUseSilo[cast<Decl>(D)]) {
// TODO: also dump records? could be forward-declarated?!
bool AppendFilename = false;
if (isa<FunctionDecl>(SavedCallee)) {
if (cast<FunctionDecl>(SavedCallee)->getStorageClass() == SC_Static)
if (cast<FunctionDecl>(SavedCallee)->getStorageClass() == SC_Static) {
*Terminal << "\"static function:";
else
AppendFilename = true;
} else
*Terminal << "\"function:";
} else {
*Terminal << "\"variable:";
if (cast<VarDecl>(SavedCallee)->getStorageClass() == SC_Static) {
*Terminal << "\"static variable:";
AppendFilename = true;
} else
*Terminal << "\"variable:";
}
*Terminal << cast<NamedDecl>(SavedCallee)->getName();
// Append the filename to the symbol's name
const auto Filename = CI.getSourceManager().getFilename(SavedCallee->getLocation());
*Terminal << ":" << (Filename.startswith("./") ? Filename.slice(2, Filename.size()) : Filename);
if (AppendFilename) {
// Append the filename to the symbol's name
const auto Filename = CI.getSourceManager().getFilename(SavedCallee->getLocation());
*Terminal << ":" << (Filename.startswith("./") ? Filename.slice(2, Filename.size()) : Filename);
}
*Terminal << "\", ";
}
*Terminal << "]";
Expand Down

0 comments on commit fcea18b

Please sign in to comment.