1 #include "xi-AstNode.h"
3 #include "xi-Template.h"
7 TParamList::TParamList(TParam* t, TParamList* n) : tparam(t), next(n) {}
9 TParamType::TParamType(Type* t) : type(t) {}
10 void TParamType::print(XStr& str) { type->print(str); }
11 void TParamType::genSpec(XStr& str) { type->print(str); }
13 TParamVal::TParamVal(const char* v) : val(v) {}
14 void TParamVal::print(XStr& str) { str << val; }
15 void TParamVal::genSpec(XStr& str) { str << val; }
17 Scope::Scope(const char* name, ConstructList* contents)
18 : name_(name), ConstructList(-1, NULL, contents) {}
20 void Scope::genDecls(XStr& str) {
21 str << "namespace " << name_ << " {\n";
22 AstChildren<Construct>::genDecls(str);
23 str << "} // namespace " << name_ << "\n";
26 void Scope::genDefs(XStr& str) {
27 str << "namespace " << name_ << " {\n";
28 AstChildren<Construct>::genDefs(str);
29 str << "} // namespace " << name_ << "\n";
32 void Scope::genReg(XStr& str) {
33 str << "using namespace " << name_ << ";\n";
34 AstChildren<Construct>::genReg(str);
37 void Scope::genGlobalCode(XStr scope, XStr& decls, XStr& defs) {
38 scope << name_ << "::";
39 AstChildren<Construct>::genGlobalCode(scope, decls, defs);
42 void Scope::print(XStr& str) {
43 str << "namespace " << name_ << "{\n";
44 AstChildren<Construct>::print(str);
45 str << "} // namespace " << name_ << "\n";
48 void Scope::outputClosuresDecl(XStr& str) {
49 str << "namespace " << name_ << " {\n";
50 AstChildren<Construct>::outputClosuresDecl(str);
51 str << "} // namespace " << name_ << "\n";
54 void Scope::outputClosuresDef(XStr& str) {
55 str << "namespace " << name_ << " {\n";
56 AstChildren<Construct>::outputClosuresDef(str);
57 str << "} // namespace " << name_ << "\n";
60 UsingScope::UsingScope(const char* name, bool symbol) : name_(name), symbol_(symbol) {}
61 void UsingScope::genDecls(XStr& str) {
63 if (!symbol_) str << "namespace ";
64 str << name_ << ";\n";
66 void UsingScope::print(XStr& str) {
68 if (!symbol_) str << "namespace ";
69 str << name_ << ";\n";
72 void TEntity::setTemplate(Template* t) { templat = t; }
73 XStr TEntity::tspec(bool printDefault) const {
75 if (templat) templat->genSpec(str, printDefault);
78 XStr TEntity::tvars(void) const {
80 if (templat) templat->genVars(str);
84 TType::TType(Type* t, Type* i) : type(t), init(i) {}
86 TTypeEllipsis::TTypeEllipsis(NamedEllipsisType* t, Type* i) : type(t), init(i) {}
88 TFunc::TFunc(FuncType* t, const char* v) : type(t), init(v) {}
89 void TFunc::print(XStr& str) {
91 if (init) str << "=" << init;
93 void TFunc::genLong(XStr& str, bool printDefault) {
95 if (init && printDefault) str << "=" << init;
97 void TFunc::genShort(XStr& str) { str << type->getBaseName(); }
99 TName::TName(Type* t, const char* n, const char* v) : type(t), name(n), val(v) {}
101 TVarList::TVarList(TVar* v, TVarList* n) : tvar(v), next(n) {}
103 void Template::outputClosuresDecl(XStr& str) {
104 Chare* c = dynamic_cast<Chare*>(entity);
105 if (c) str << c->closuresDecl;
108 void Template::outputClosuresDef(XStr& str) {
109 Chare* c = dynamic_cast<Chare*>(entity);
110 if (c) str << c->closuresDef;
113 void Template::setExtern(int e) {
114 Construct::setExtern(e);
115 entity->setExtern(e);
118 void Template::genVars(XStr& str) {
120 if (tspec) tspec->genShort(str);
124 void Template::genSpec(XStr& str, bool printDefault) {
125 str << generateTemplateSpec(tspec, printDefault);
128 void Template::genDecls(XStr& str) {
129 if (!external && entity) {
130 entity->genDecls(str);
134 void Template::genDefs(XStr& str) {
135 if (!external && entity) entity->genDefs(str);
138 void Template::genGlobalCode(XStr scope, XStr& decls, XStr& defs) {
139 if (!external && entity) entity->genGlobalCode(scope, decls, defs);
142 int Template::genAccels_spe_c_funcBodies(XStr& str) {
144 if (!external && entity) {
145 rtn += entity->genAccels_spe_c_funcBodies(str);
150 void Template::genAccels_spe_c_regFuncs(XStr& str) {
151 if (!external && entity) {
152 entity->genAccels_spe_c_regFuncs(str);
156 void Template::genAccels_spe_c_callInits(XStr& str) {
157 if (!external && entity) {
158 entity->genAccels_spe_c_callInits(str);
162 void Template::genAccels_spe_h_includes(XStr& str) {
163 if (!external && entity) {
164 entity->genAccels_spe_h_includes(str);
168 void Template::genAccels_spe_h_fiCountDefs(XStr& str) {
169 if (!external && entity) {
170 entity->genAccels_spe_h_fiCountDefs(str);
174 void Template::genAccels_ppe_c_regFuncs(XStr& str) {
175 if (!external && entity) {
176 entity->genAccels_ppe_c_regFuncs(str);
180 void Template::preprocess() {
181 if (entity) entity->preprocess();
184 void Template::check() {
185 if (entity) entity->check();
188 void TVarList::genLong(XStr& str, bool printDefault) {
189 if (tvar) tvar->genLong(str, printDefault);
192 next->genLong(str, printDefault);
196 void TVarList::genShort(XStr& str) {
197 if (tvar) tvar->genShort(str);
204 void TType::genLong(XStr& str, bool printDefault) {
206 if (type) type->print(str);
207 if (init && printDefault) {
213 void TType::genShort(XStr& str) {
214 if (type) type->print(str);
217 void TTypeEllipsis::genLong(XStr& str, bool printDefault) {
219 if (type) type->printWithoutEllipsis(str);
220 if (init && printDefault) {
226 void TTypeEllipsis::genShort(XStr& str) {
227 if (type) type->print(str);
230 void TName::genLong(XStr& str, bool printDefault) {
231 if (type) type->print(str);
233 if (val && printDefault) {
238 void TName::genShort(XStr& str) { str << name; }
240 void TParamList::genSpec(XStr& str) {
241 if (tparam) tparam->genSpec(str);
248 void TParamList::print(XStr& str) {
249 if (tparam) tparam->print(str);
256 std::string TParamList::to_string() {
259 return s.get_string();
262 void TType::print(XStr& str) {
271 void TTypeEllipsis::print(XStr& str) {
273 type->printWithoutEllipsis(str);
280 void TName::print(XStr& str) {
289 void TVarList::print(XStr& str) {
297 void Template::print(XStr& str) {
298 if (entity) entity->print(str);