Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
Pyston
Commits
404fa0ab
Commit
404fa0ab
authored
Mar 08, 2016
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
starting to get somewhere, though very slowly
parent
d95030ec
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
159 additions
and
6 deletions
+159
-6
Makefile
Makefile
+1
-1
plugins/refcount_checker/CMakeLists.txt
plugins/refcount_checker/CMakeLists.txt
+1
-3
plugins/refcount_checker/refcount_checker.cpp
plugins/refcount_checker/refcount_checker.cpp
+157
-2
No files found.
Makefile
View file @
404fa0ab
...
...
@@ -1077,7 +1077,7 @@ lint_%: %.cpp plugins/clang_linter.so
REFCOUNT_CHECKER_BUILD_PATH
:=
$(CMAKE_DIR_DBG)
/plugins/refcount_checker/llvm/bin/refcount_checker
REFCOUNT_CHECKER_RUN_PATH
:=
$(CMAKE_DIR_DBG)
/llvm/bin/refcount_checker
$(REFCOUNT_CHECKER_
BUILD
_PATH)
:
plugins/refcount_checker/refcount_checker.cpp
$(REFCOUNT_CHECKER_
RUN
_PATH)
:
plugins/refcount_checker/refcount_checker.cpp
$(NINJA)
-C
$(CMAKE_DIR_DBG)
refcount_checker
$(NINJAFLAGS)
cp
$(REFCOUNT_CHECKER_BUILD_PATH)
$(REFCOUNT_CHECKER_RUN_PATH)
...
...
plugins/refcount_checker/CMakeLists.txt
View file @
404fa0ab
...
...
@@ -5,9 +5,7 @@ set(LLVM_LIBRARY_OUTPUT_INTDIR llvm/lib${LLVM_LIBDIR_SUFFIX})
# Pyston addition:
include_directories
(
"
${
DEPS_DIR
}
/llvm-trunk/tools/clang/include"
)
include_directories
(
"
${
CMAKE_BINARY_DIR
}
/llvm/tools/clang/include"
)
if
(
"
${
CMAKE_BUILD_TYPE
}
"
STREQUAL
"Debug"
)
set
(
LIBUNWIND_DEBUG_CFLAGS
"CFLAGS=-O0 -g"
)
endif
()
set
(
CMAKE_CXX_FLAGS_DEBUG
"-O0 -g"
)
# From llvm-trunk/tools/clang/tools/clang-check/CMakeLists.txt
set
(
LLVM_LINK_COMPONENTS
...
...
plugins/refcount_checker/refcount_checker.cpp
View file @
404fa0ab
...
...
@@ -18,6 +18,7 @@
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/Frontend/ASTConsumers.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/FrontendActions.h"
#include "clang/Tooling/CommonOptionsParser.h"
...
...
@@ -40,6 +41,130 @@ static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage);
// A help message for this specific tool can be added afterwards.
static
cl
::
extrahelp
MoreHelp
(
"
\n
More help text..."
);
static
void
dumpSingle
(
DeclContext
*
ctx
)
{
errs
()
<<
ctx
->
getDeclKindName
()
<<
'\n'
;
if
(
ctx
->
isClosure
())
errs
()
<<
"a closure
\n
"
;
if
(
ctx
->
isFunctionOrMethod
())
errs
()
<<
"a function / method
\n
"
;
//if (ctx->isLookupContext()) errs() << "a lookup context\n";
if
(
ctx
->
isFileContext
())
errs
()
<<
"a file context
\n
"
;
if
(
ctx
->
isTranslationUnit
())
errs
()
<<
"a translation unit
\n
"
;
if
(
ctx
->
isRecord
())
errs
()
<<
"a record
\n
"
;
if
(
ctx
->
isNamespace
())
errs
()
<<
"a namespace
\n
"
;
if
(
ctx
->
isStdNamespace
())
errs
()
<<
"a std namespace
\n
"
;
if
(
ctx
->
isInlineNamespace
())
errs
()
<<
"an inline namespace
\n
"
;
if
(
ctx
->
isDependentContext
())
errs
()
<<
"a dependent context
\n
"
;
if
(
ctx
->
isTransparentContext
())
errs
()
<<
"a transparent context
\n
"
;
if
(
ctx
->
isExternCContext
())
errs
()
<<
"an extern-C context
\n
"
;
if
(
ctx
->
isExternCXXContext
())
errs
()
<<
"an extern-C++ context
\n
"
;
//ctx->dumpLookups();
}
static
void
dump
(
DeclContext
*
ctx
)
{
auto
cur
=
ctx
;
while
(
cur
)
{
dumpSingle
(
cur
);
cur
=
cur
->
getParent
();
if
(
cur
)
errs
()
<<
"parent is...
\n
"
;
}
}
namespace
{
class
ASTPrinter
:
public
ASTConsumer
,
public
RecursiveASTVisitor
<
ASTPrinter
>
{
typedef
RecursiveASTVisitor
<
ASTPrinter
>
base
;
public:
ASTPrinter
(
raw_ostream
*
Out
=
nullptr
,
bool
Dump
=
false
,
StringRef
FilterString
=
""
,
bool
DumpLookups
=
false
)
:
Out
(
Out
?
*
Out
:
llvm
::
outs
()),
Dump
(
Dump
),
FilterString
(
FilterString
),
DumpLookups
(
DumpLookups
)
{}
void
HandleTranslationUnit
(
ASTContext
&
Context
)
override
{
TranslationUnitDecl
*
D
=
Context
.
getTranslationUnitDecl
();
if
(
FilterString
.
empty
())
return
print
(
D
);
TraverseDecl
(
D
);
}
bool
shouldWalkTypesOfTypeLocs
()
const
{
return
false
;
}
bool
TraverseDecl
(
Decl
*
D
)
{
if
(
D
&&
filterMatches
(
D
))
{
bool
ShowColors
=
Out
.
has_colors
();
if
(
ShowColors
)
Out
.
changeColor
(
raw_ostream
::
BLUE
);
Out
<<
((
Dump
||
DumpLookups
)
?
"Dumping "
:
"Printing "
)
<<
getName
(
D
)
<<
":
\n
"
;
if
(
ShowColors
)
Out
.
resetColor
();
print
(
D
);
Out
<<
"
\n
"
;
// Don't traverse child nodes to avoid output duplication.
return
true
;
}
return
base
::
TraverseDecl
(
D
);
}
std
::
string
getName
(
Decl
*
D
)
{
if
(
isa
<
NamedDecl
>
(
D
))
return
cast
<
NamedDecl
>
(
D
)
->
getQualifiedNameAsString
();
return
""
;
}
bool
filterMatches
(
Decl
*
D
)
{
return
getName
(
D
).
find
(
FilterString
)
!=
std
::
string
::
npos
;
}
void
print
(
Decl
*
D
)
{
if
(
DumpLookups
)
{
if
(
DeclContext
*
DC
=
dyn_cast
<
DeclContext
>
(
D
))
{
if
(
DC
==
DC
->
getPrimaryContext
())
DC
->
dumpLookups
(
Out
,
Dump
);
else
Out
<<
"Lookup map is in primary DeclContext "
<<
DC
->
getPrimaryContext
()
<<
"
\n
"
;
}
else
Out
<<
"Not a DeclContext
\n
"
;
}
else
if
(
Dump
)
D
->
dump
(
Out
);
else
D
->
print
(
Out
,
/*Indentation=*/
0
,
/*PrintInstantiation=*/
true
);
}
raw_ostream
&
Out
;
bool
Dump
;
std
::
string
FilterString
;
bool
DumpLookups
;
};
class
ASTDeclNodeLister
:
public
ASTConsumer
,
public
RecursiveASTVisitor
<
ASTDeclNodeLister
>
{
public:
ASTDeclNodeLister
(
raw_ostream
*
Out
=
nullptr
)
:
Out
(
Out
?
*
Out
:
llvm
::
outs
())
{}
void
HandleTranslationUnit
(
ASTContext
&
Context
)
override
{
TraverseDecl
(
Context
.
getTranslationUnitDecl
());
}
bool
shouldWalkTypesOfTypeLocs
()
const
{
return
false
;
}
bool
VisitNamedDecl
(
NamedDecl
*
D
)
{
D
->
printQualifiedName
(
Out
);
Out
<<
'\n'
;
return
true
;
}
private:
raw_ostream
&
Out
;
};
static
std
::
unique_ptr
<
ASTPrinter
>
dumper
()
{
return
std
::
unique_ptr
<
ASTPrinter
>
(
new
ASTPrinter
(
&
errs
(),
true
,
""
,
true
));
}
}
// end anonymous namespace
class
MyVisitor
:
public
RecursiveASTVisitor
<
MyVisitor
>
{
private:
ASTContext
*
Context
;
...
...
@@ -51,9 +176,38 @@ public:
virtual
~
MyVisitor
()
{
}
void
checkFunction
(
FunctionDecl
*
func
)
{
//dumper()->TraverseDecl(func);
errs
()
<<
"printing:
\n
"
;
func
->
print
(
errs
());
errs
()
<<
"dumping:
\n
"
;
func
->
dump
(
errs
());
}
virtual
bool
VisitFunctionDecl
(
FunctionDecl
*
func
)
{
errs
()
<<
func
->
getNameInfo
().
getName
()
<<
'\n'
;
return
true
;
if
(
!
func
->
hasBody
())
return
true
/* keep going */
;
auto
filename
=
Context
->
getSourceManager
().
getFilename
(
func
->
getNameInfo
().
getLoc
());
// Filter out functions defined in libraries:
if
(
filename
.
find
(
"include/c++"
)
!=
StringRef
::
npos
)
return
true
;
if
(
filename
.
find
(
"include/x86_64-linux-gnu"
)
!=
StringRef
::
npos
)
return
true
;
if
(
filename
.
find
(
"include/llvm"
)
!=
StringRef
::
npos
)
return
true
;
if
(
filename
.
find
(
"lib/clang"
)
!=
StringRef
::
npos
)
return
true
;
//errs() << filename << '\n';
if
(
func
->
getNameInfo
().
getAsString
()
!=
"firstlineno"
)
return
true
;
checkFunction
(
func
);
return
true
/* keep going */
;
}
};
...
...
@@ -67,6 +221,7 @@ public:
virtual
void
HandleTranslationUnit
(
ASTContext
&
Context
)
{
visitor
.
TraverseDecl
(
Context
.
getTranslationUnitDecl
());
//dumper()->TraverseDecl(Context.getTranslationUnitDecl());
}
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment