Skip to content

Commit

Permalink
Problems with signal arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
rmrf committed Jan 4, 2020
1 parent 79e4a96 commit 0f3d92e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
30 changes: 28 additions & 2 deletions src/Matchers.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "PortDecl.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/ASTMatchers/ASTMatchers.h"
#include "clang/ASTMatchers/ASTMatchersMacros.h"
#include "clang/ASTMatchers/ASTMatchersInternal.h"

using namespace clang;
using namespace clang::ast_matchers;
Expand All @@ -21,6 +23,23 @@ auto checkMatch(const std::string &name,
return result.Nodes.getNodeAs<NodeType>(name);
}


/*
AST_MATCHER_P(CXXCtorInitializer, forField,
internal::Matcher<FieldDecl>, InnerMatcher) {
const FieldDecl *NodeAsDecl = Node.getAnyMember();
return (NodeAsDecl != nullptr &&
InnerMatcher.matches(*NodeAsDecl, Finder, Builder));
}
*/

AST_MATCHER(FieldDecl, matchesTypeName) {
auto type_ptr { Node.getType().getTypePtr()};
llvm::outs() << "[[OWN MATCHER]]\n";
type_ptr->dump();
return true;
};

///////////////////////////////////////////////////////////////////////////////
//
// Class InstanceMatcher
Expand Down Expand Up @@ -322,6 +341,7 @@ class PortMatcher : public MatchFinder::MatchCallback {
.bind("sc_stream_out"))
)

// classTemplateSpecializationDecl(hasSpecializedTemplate(classTemplateDecl()))
/*
forEach(fieldDecl(hasType(namedDecl(hasName("sc_in_clk")))).bind("sc_in_clk"),
fieldDecl(hasType(cxxRecordDecl(hasName("sc_in")))).bind("sc_in"),
Expand Down Expand Up @@ -369,8 +389,14 @@ class PortMatcher : public MatchFinder::MatchCallback {
finder.addMatcher(match_stream_in_ports, this);
finder.addMatcher(match_stream_out_ports, this);
*/
finder.addMatcher(match_all_ports, this);
finder.addMatcher(match_non_sc_types, this);
//finder.addMatcher(match_all_ports, this);
//finder.addMatcher(match_non_sc_types, this);


// test own matcher
auto matcher_test = cxxRecordDecl(forEachDescendant(fieldDecl(matchesTypeName()).bind("other_fields")));
finder.addMatcher(matcher_test, this);

}

virtual void run(const MatchFinder::MatchResult &result) {
Expand Down
3 changes: 2 additions & 1 deletion tests/matchers/match-structural.cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ set output dump
#m fieldDecl(hasType(cxxRecordDecl(isDerivedFrom(hasName("sc_signal_inout_if")))))
m cxxRecordDecl(isExpansionInMainFile(), forEach(fieldDecl(hasType(arrayType(hasElementType(unless(builtinType()))))).bind("field")))
#m cxxRecordDecl(forEachDescendant(fieldDecl(hasName("array_signal"))))
m cxxRecordDecl(isExpansionInMainFile(), forEach(fieldDecl(hasType(arrayType()))))

0 comments on commit 0f3d92e

Please sign in to comment.