Skip to content

Commit

Permalink
Merge pull request #1 from jmachowinski/low_hanging_fruits
Browse files Browse the repository at this point in the history
Low hanging fruits
  • Loading branch information
jmachowinski committed Jul 29, 2014
2 parents 4d2f9ac + 20d7383 commit e39f631
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 50 deletions.
2 changes: 1 addition & 1 deletion lang/tlb/export.cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ namespace
Enum::ValueMap const& values = type.values();
m_stream << "<enum name=\"" << type.getName() << "\" " << emitSourceID() << ">\n";
{ Indent indenter(m_indent);
Enum::ValueMap::const_iterator it, end = values.end();
Enum::ValueMap::const_iterator it;
for (it = values.begin(); it != values.end(); ++it)
m_stream << m_indent << "<value symbol=\"" << it->first << "\" value=\"" << it->second << "\"/>\n";
}
Expand Down
4 changes: 4 additions & 0 deletions tools/tlbBuilder/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ cmake_minimum_required(VERSION 2.8)
# AST-headers... this only clutters up the compiler output with nonsense
add_definitions("-Wno-unused-local-typedefs")

# when compiling inside the rock-framework "Wall" is used. This adds alotta
# more bogus warnings from system-headers...
add_definitions("-Wno-strict-aliasing")

include_directories("/usr/lib/llvm-3.4/include/")

macro(llvm_find_config LLVM_REQUIRED_VERSION)
Expand Down
73 changes: 29 additions & 44 deletions tools/tlbBuilder/Extractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
// tool-template <header-to-look-at> -- <compile-flags-as-usual>
//
// Example:
// ./bin/extractor $ROCK_ROOT/base/types/base/Pose.hpp -- \
// -I$ROCK_ROOT/base/types \
// -I/usr/include/eigen3 \
// -x c++
// ./bin/extractor $ROCK_ROOT/base/types/base/Pose.hpp -- -I$ROCK_ROOT/base/types -I/usr/include/eigen3 -x c++
//
// keep in mind that this particular (not very complicated) example still takes 15seconds to
// complete...
Expand Down Expand Up @@ -48,35 +45,33 @@ namespace {
class TypeDefCallback : public MatchFinder::MatchCallback {
public:


// This routine will get called for each thing that the matchers find.
virtual void run(const MatchFinder::MatchResult &Result) {
virtual void run(const MatchFinder::MatchResult &Result) {

const TypedefType *typeType = Result.Nodes.getNodeAs<TypedefType>("typeDef");
if(typeType)
{
builder.registerTypeDef(typeType);
const TypedefType *T = Result.Nodes.getNodeAs<TypedefType>("typeDef");

if(T) {
builder.registerTypeDef(T);
}
}
}
};

class ToolTemplateCallback : public MatchFinder::MatchCallback {
public:
// This routine will get called for each thing that the matchers find.
virtual void run(const MatchFinder::MatchResult &Result) {
class TypeDeclCallback : public MatchFinder::MatchCallback {
public:

virtual void run(const MatchFinder::MatchResult &Result) {

const TypeDecl *decl = Result.Nodes.getNodeAs<TypeDecl>("match");
const TypeDecl *D = Result.Nodes.getNodeAs<TypeDecl>("typeDecl");

if(decl)
{
builder.registerNamedDecl(decl);
if(D) {

builder.registerNamedDecl(D);
}

const CXXRecordDecl *DD = Result.Nodes.getNodeAs<CXXRecordDecl>("typeDecl");
if (DD) {
builder.registerNamedDecl(DD);
}
}

const CXXRecordDecl *D = Result.Nodes.getNodeAs<CXXRecordDecl>("match");
if (D) {
builder.registerNamedDecl(D);
}
}

};
} // end anonymous namespace
Expand All @@ -91,28 +86,18 @@ int main(int argc, const char **argv) {
// }}}

ast_matchers::MatchFinder Finder;
ToolTemplateCallback Callback;
TypeDefCallback tdCallback;

// AST matching ftw...
//
// the big table: http://clang.llvm.org/docs/LibASTMatchersReference.html

// the "bind" will make the match referencable by the given string in the "run()" mathod of the
// callback

// the "isDefinition()" is needed to reject "Class Name Injection" and forward
// declarations. see https://stackoverflow.com/questions/24761684 and
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/1994/N0444.pdf
TypeDeclCallback typeDeclCallback;
internal::VariadicDynCastAllOfMatcher<Decl, TypeDecl> typeDecl;

DeclarationMatcher matcher = typeDecl().bind("match");

Finder.addMatcher(matcher, &Callback);
Finder.addMatcher(typeDecl().bind("typeDecl"), &typeDeclCallback);

Finder.addMatcher(typedefType().bind("typeDef"), &tdCallback);
TypeDefCallback typeDefCallback;
Finder.addMatcher(typedefType().bind("typeDef"), &typeDefCallback);

Tool.run(newFrontendActionFactory(&Finder));
if (int retval = Tool.run(newFrontendActionFactory(&Finder)) != 0) {
std::cerr << "whoops\n";
return retval;
}

builder.buildRegistry();

Expand Down
4 changes: 1 addition & 3 deletions typelib/typemodel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,7 @@ namespace Typelib

FieldList::const_iterator left_it = m_fields.begin(),
left_end = m_fields.end(),
right_it = right_type.getFields().begin(),
right_end = right_type.getFields().end();
right_it = right_type.getFields().begin();

while (left_it != left_end)
{
Expand Down Expand Up @@ -404,7 +403,6 @@ namespace Typelib
Compound const* other_compound = dynamic_cast<Compound const*>(&other);
if (other_compound)
{
FieldList::const_iterator other_end = other_compound->m_fields.end();
for (FieldList::const_iterator it = m_fields.begin(); it != m_fields.end(); ++it)
{
Field const* other_field = other_compound->getField(it->getName());
Expand Down
1 change: 0 additions & 1 deletion typelib/typename.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ using namespace Typelib;
namespace
{
typedef std::string::value_type NamespaceMarkType;
static const NamespaceMarkType NamespaceMark = '/';
static const char* NamespaceMarkString = "/";

struct NameSeparator : public char_separator<NamespaceMarkType>
Expand Down
2 changes: 1 addition & 1 deletion typelib/utilmm/configset.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void config_set::insert(std::string const& name, std::string const& value)
{ m_values.insert( make_pair(name, value) ); }
void config_set::insert(std::string const& name, std::list<std::string> const& value)
{
list<string>::const_iterator it, end = value.end();
list<string>::const_iterator it;
for (it = value.begin(); it != value.end(); ++it)
insert(name, *it);
}
Expand Down

0 comments on commit e39f631

Please sign in to comment.