systemc-clang 2.0.0
Parsing SystemC constructs
Loading...
Searching...
No Matches
Utility.h
Go to the documentation of this file.
1//===-- src/Utility.h - systec-clang class definition -------*- C++ -*-===//
2//
3// systemc-clang: SystemC Parser
4//
5// This file is distributed under the University of Illinois License.
6// See LICENSE.mkd for details.
7//
8//===----------------------------------------------------------------------===//
13//===----------------------------------------------------------------------===//
14#ifndef _UTILITY_H_
15#define _UTILITY_H_
16
17#include "clang/AST/DeclCXX.h"
18#include "clang/AST/PrettyPrinter.h"
19#include "clang/Basic/SourceManager.h"
20#include "llvm/Support/raw_ostream.h"
21#include <string>
22
23namespace systemc_clang {
24using namespace clang;
25using namespace std;
26class Utility {
27public:
29 /*
30 void tabit (llvm::raw_ostream &, int tabn);
31 string strip (string, string);
32
33 template < typename vec > vec removeDuplicate (vec);
34 template < typename vec, typename element > bool isElementPresent (vec,
35 element); template < typename element > string getArgumentName (element *);
36 */
37 void tabit(raw_ostream &os, int tabn) {
38 for (int i = 0; i < tabn; i++) {
39 os << " ";
40 }
41 }
42
43 string strip(string s, string sub) {
44 // sub has "struct "
45 size_t pos = s.find(sub);
46
47 if (pos == string::npos) {
48 return s;
49 }
50
51 return s.erase(pos, sub.length());
52 }
53
54 template <typename vec> vec removeDuplicate(vec vecInput) {
55 for (unsigned int i = 0; i < vecInput.size(); i++) {
56 for (unsigned int j = 0; j < vecInput.size(); j++) {
57 if (i != j && vecInput.at(i) == vecInput.at(j)) {
58 vecInput.erase(vecInput.begin() + j);
59 }
60 }
61 }
62 return vecInput;
63 }
64
65 template <typename vec, typename element>
66 bool isElementPresent(vec vecInput, element elemInput) {
67 for (unsigned int i = 0; i < vecInput.size(); i++) {
68 if (elemInput == vecInput.at(i)) {
69 return true;
70 }
71 }
72 return false;
73 }
74
75 template <typename expressionArg> string getArgumentName(expressionArg *exp) {
76 if (exp == NULL) {
77 return string("NULL");
78 }
79
80 clang::LangOptions LangOpts;
81 LangOpts.CPlusPlus = true;
82 clang::PrintingPolicy Policy(LangOpts);
83
84 string TypeS;
85
86 llvm::raw_string_ostream s(TypeS);
87
88 exp->printPretty(s, 0, Policy);
89
90 return s.str();
91 }
92
93};
94} // namespace systemc_clang
95#endif
vec removeDuplicate(vec vecInput)
Definition Utility.h:54
string strip(string s, string sub)
Definition Utility.h:43
string getArgumentName(expressionArg *exp)
Definition Utility.h:75
bool isElementPresent(vec vecInput, element elemInput)
Definition Utility.h:66
void tabit(raw_ostream &os, int tabn)
Definition Utility.h:37
Clang forward declarations.
Definition FindArgument.h:6