Commit fe23440a authored by rmrf's avatar rmrf
Browse files

Clean up the code formatting.

Begin upgrading to c++11 standard and use of auto.
parent 406d4ac8
#ifndef _FIND_TYPE_H_
#define _FIND_TYPE_H_
#include<set>
#include<vector>
#include <set>
#include <vector>
#include <string>
#include "clang/AST/DeclCXX.h"
#include "llvm/Support/raw_ostream.h"
......@@ -10,150 +10,117 @@
#include "clang/AST/DeclTemplate.h"
#include "clang/AST/Type.h"
#include <iostream>
namespace scpar {
using namespace clang;
using namespace std;
class FindTemplateTypes:public RecursiveASTVisitor < FindTemplateTypes > {
// This class is going to find the arguments from templates
class FindTemplateTypes : public RecursiveASTVisitor < FindTemplateTypes > {
public:
/// Typedefs
typedef vector < pair < string, const Type *> >vector_t;
typedef pair < string, const Type *>kvVector_t;
typedef vector < pair < string, const Type *> >argVectorType;
typedef vector < pair < string, const Type *> > type_vector_t;
typedef vector < pair < string, const Type *> > argVectorType;
// Constructor
FindTemplateTypes() { }
FindTemplateTypes (
) {
}
/// Copy constructor
FindTemplateTypes (const FindTemplateTypes & rhs ) {
/// Copy constructor
FindTemplateTypes( const FindTemplateTypes &rhs ) {
copy (rhs._templateTypes.begin (), rhs._templateTypes.end (),
back_inserter (_templateTypes)
);
} string getTemplateType (
) {
string s;
for (vector_t::iterator mit = _templateTypes.begin ();
mit != _templateTypes.end (); mit++)
{
if (mit != _templateTypes.begin ())
{
s += "<";
}
s += mit->first;
if (mit != _templateTypes.begin ())
{
s += ">";
}
}
return s;
}
vector_t Enumerate (const Type * type
) {
_templateTypes.clear ();
if (!type)
{
return _templateTypes;
}
TraverseType (QualType (type, 0));
return _templateTypes;
}
bool VisitType (Type * type
) {
QualType q = type->getCanonicalTypeInternal ();
// _os << "\n###### Type: " << q.getAsString() << " \n" ;
if (type->isBuiltinType ())
{
_templateTypes.push_back (pair < string,
const Type * >(q.getAsString (), type)
);
return true;
}
CXXRecordDecl *crType = type->getAsCXXRecordDecl ();
if (crType != NULL)
{
IdentifierInfo *info = crType->getIdentifier ();
if (info != NULL)
{
_templateTypes.push_back (pair < string,
const Type * >(info->getNameStart (),
type)
);
}
}
return true;
}
bool VisitIntegerLiteral (IntegerLiteral * l
) {
//_os << "\n####### IntegerLiteral: " << l->getValue().toString(10,true) << "\n";
//_os << "== type ptr: " << l->getType().getTypePtr() << "\n";
//_os << "== type name: " << l->getType().getAsString() << "\n";
_templateTypes.push_back (pair < string,
const Type *
>(l->getValue ().toString (10, true),
l->getType ().getTypePtr ()));
return true;
}
vector_t getTemplateArgumentsType (
) {
return _templateTypes;
}
void printTemplateArguments (llvm::raw_ostream & os, int tabn = 0)
{
for (vector_t::iterator mit = _templateTypes.begin ();
mit != _templateTypes.end (); mit++)
{
for (int i = 0; i < tabn; i++)
{
os << " ";
}
os << "- " << mit->first << ", type ptr: " << mit->second;
os << "\n";
}
}
vector < string > getTemplateArguments ()
{
vector < string > args;
for (vector_t::iterator mit = _templateTypes.begin ();
mit != _templateTypes.end (); mit++)
{
if (mit->first == "sc_in" || mit->first == "sc_out"
|| mit->first == "sc_inout")
{
break;
}
args.push_back (mit->first);
// _os << "\n:>> " << mit->first << ", type ptr: " << mit->second;
}
return args;
}
unsigned int size (
) {
return _templateTypes.size ();
}
private:
vector_t _templateTypes;
};
back_inserter (_templateTypes) );
}
string getTemplateType() {
string s{};
// type_vector_t::iterator
for (auto mit = _templateTypes.begin (); mit != _templateTypes.end (); ++mit) {
if (mit != _templateTypes.begin()) {
s += "<";
}
s += mit->first;
if (mit != _templateTypes.begin()) {
s += ">";
}
}
return s;
}
type_vector_t Enumerate( const Type *type ) {
_templateTypes.clear();
if ( !type ) {
return _templateTypes;
}
TraverseType( QualType (type, 0) );
return _templateTypes;
}
bool VisitType( Type *type ) {
QualType q{type->getCanonicalTypeInternal()};
// cout << "\n###### Type: " << q.getAsString() << " \n" ;
if ( type->isBuiltinType() ) {
_templateTypes.push_back( pair < string, const Type * >(q.getAsString(), type) );
return true;
}
CXXRecordDecl *p_cxx_record{type->getAsCXXRecordDecl()};
if ( p_cxx_record != nullptr ) {
IdentifierInfo *info{p_cxx_record->getIdentifier()};
if ( info != nullptr ) {
_templateTypes.push_back(pair < string, const Type * >(info->getNameStart(), type) );
}
}
return true;
}
bool VisitIntegerLiteral( IntegerLiteral *l ) {
//_os << "\n####### IntegerLiteral: " << l->getValue().toString(10,true) << "\n";
//_os << "== type ptr: " << l->getType().getTypePtr() << "\n";
//_os << "== type name: " << l->getType().getAsString() << "\n";
_templateTypes.push_back (pair < string, const Type * >(l->getValue ().toString (10, true),
l->getType().getTypePtr()));
return true;
}
type_vector_t getTemplateArgumentsType() {
return _templateTypes;
}
void printTemplateArguments( llvm::raw_ostream &os, int tabn = 0 ) {
// type_vector_t::iterator
for (auto mit = _templateTypes.begin(); mit != _templateTypes.end(); mit++) {
for ( auto i{0}; i < tabn; ++i) {
os << " ";
}
os << "- " << mit->first << ", type ptr: " << mit->second;
os << "\n";
}
}
vector < string > getTemplateArguments() {
vector < string > args;
// type_vector_t::iterator
for ( auto mit = _templateTypes.begin(); mit != _templateTypes.end(); ++mit ) {
if ( mit->first == "sc_in" || mit->first == "sc_out" || mit->first == "sc_inout" ) {
break;
}
args.push_back(mit->first);
}
return args;
}
size_t size() {
return _templateTypes.size();
}
private:
type_vector_t _templateTypes;
};
}
#endif
......@@ -345,7 +345,9 @@ void ModuleDecl::dumpPorts(raw_ostream & os, int tabn)
for (ModuleDecl::portMapType::iterator mit = _iports.begin();
mit != _iports.end(); mit++) {
os << "Print Port\n" << mit->first << "\n";
mit->second->dump(os, tabn);
os << "End print\n";
os << "\n ";
}
os << "\n";
......
......@@ -21,30 +21,28 @@ namespace scpar {
class ModuleDecl {
public:
typedef pair < string, Signal * >signalPairType;
typedef map < string, Signal * >signalMapType;
typedef pair < string, Signal * > signalPairType;
typedef map < string, Signal * > signalMapType;
typedef pair < string, PortDecl * >portPairType;
typedef map < string, PortDecl * >portMapType;
typedef pair < string, PortDecl * > portPairType;
typedef map < string, PortDecl * > portMapType;
typedef pair <string, InterfaceDecl *>interfacePairType;
typedef pair <string, InterfaceDecl *> interfacePairType;
typedef map <string, InterfaceDecl *> interfaceMapType;
typedef pair < string, ProcessDecl * >processPairType;
typedef map < string, ProcessDecl * >processMapType;
typedef pair < string, ProcessDecl * > processPairType;
typedef map < string, ProcessDecl * > processMapType;
typedef pair < string, string > moduleProcessPairType;
typedef vector<string> instanceName;
typedef pair<string, string> portSignalPairType;
typedef map<string, string> portSignalMapType;
// Why is this a not a Type?
typedef vector<string> instanceName;
public:
ModuleDecl();
ModuleDecl();
ModuleDecl(const string &, CXXRecordDecl *);
~ModuleDecl();
......@@ -57,8 +55,6 @@ namespace scpar {
void addOutputInterfaces(FindTLMInterfaces::interfaceType);
void addInputOutputInterfaces(FindTLMInterfaces::interfaceType);
void addProcess(FindEntryFunctions::entryFunctionVectorType *);
void addInstances(vector<string>);
void addSignalBinding(map<string, string>);
void setModuleName(const string &);
......
#include <string>
//#include <string>
#include "PortDecl.h"
#include "FindTemplateTypes.h"
using namespace scpar;
using namespace std;
PortDecl::~PortDecl()
{
if (_templateType != NULL) {
PortDecl::~PortDecl() {
if ( _templateType != nullptr ) {
delete _templateType;
}
}
PortDecl::PortDecl():
_name("NONE"), _templateType(NULL)
{
PortDecl::PortDecl():_name{"NONE"}, _templateType{nullptr} {
}
PortDecl::PortDecl(const string & name, FindTemplateTypes * tt)
:_name(name), _templateType(tt)
{
PortDecl::PortDecl(const string &name, FindTemplateTypes *tt):_name{name}, _templateType{tt} {
}
PortDecl::PortDecl(const PortDecl & from)
{
PortDecl::PortDecl(const PortDecl &from) {
_name = from._name;
// This is necessary to allow FindPorts to go out of scope.
_templateType = new FindTemplateTypes(*from._templateType);
}
void PortDecl::setModuleName(const string & name)
{
void PortDecl::setModuleName(const string &name) {
_name = name;
}
string PortDecl::getName()
{
string PortDecl::getName() const {
return _name;
}
FindTemplateTypes *PortDecl::getTemplateType()
{
FindTemplateTypes *PortDecl::getTemplateType() {
return _templateType;
}
void PortDecl::dump(raw_ostream & os, int tabn)
{
for (int i = 0; i < tabn; i++) {
void PortDecl::dump(raw_ostream & os, int tabn) {
for ( auto i = 0; i < tabn; ++i ) {
os << " ";
}
os << "PortDecl " << this << " '" << _name << "' FindTemplateTypes " <<
......
#ifndef _PORT_DECL_H_
#define _PORT_DECL_H_
#include "clang/AST/DeclCXX.h"
#include <string>
#include <map>
#include "clang/AST/DeclCXX.h"
#include "FindTemplateTypes.h"
namespace scpar {
......@@ -22,7 +23,7 @@ namespace scpar {
void setModuleName(const string &);
/// Get parameters
string getName();
string getName() const;
FindTemplateTypes *getTemplateType();
// Print
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment