Synopsis - Cross-Reference
File: /src/Synopsis/ASG/ASGKit.hh1// 2// Copyright (C) 2004 Stefan Seefeld 3// All rights reserved. 4// Licensed to the public under the terms of the GNU LGPL (>= 2), 5// see the file COPYING for details. 6// 7 8#ifndef _Synopsis_ASG_ASGKit_hh 9#define _Synopsis_ASG_ASGKit_hh 10 11#include <Synopsis/Python/Kit.hh> 12#include <Synopsis/ASG/IR.hh> 13#include <Synopsis/ASG/TypeId.hh> 14#include <Synopsis/ASG/DeclaredTypeId.hh> 15#include <Synopsis/ASG/SourceFile.hh> 16#include <Synopsis/ASG/Declaration.hh> 17 18namespace Synopsis 19{ 20class IRKit : public Python::Kit 21{ 22public: 23 IRKit() : Python::Kit("Synopsis.IR") {} 24 25 IR create_ir() { return create<IR>("IR");} 26}; 27 28class QNameKit : public Python::Kit 29{ 30public: 31 QNameKit() : Python::Kit("Synopsis.QualifiedName") {} 32 Object create_qname(ScopedName const &name) 33 { return create<Object>("QualifiedCxxName", Python::Tuple(name));} 34}; 35 36namespace ASG 37{ 38// basically a factory for all ASG types 39class ASGKit : public Python::Kit 40{ 41public: 42 ASGKit(std::string const &lang) : Python::Kit("Synopsis.ASG"), language_(lang) {} 43 44 TypeId create_type_id() 45 { return create<TypeId>("TypeId", Python::Tuple(language_));} 46 47 NamedTypeId create_named_type_id(ScopedName const &name) 48 { 49 Python::Object qname = qname_kit_.create_qname(name); 50 return create<NamedTypeId>("NamedTypeId", Python::Tuple(language_, qname)); 51 } 52 53 BuiltinTypeId create_builtin_type_id(const ScopedName &name) 54 { 55 Python::Object qname = qname_kit_.create_qname(name); 56 return create<BuiltinTypeId>("BuiltinTypeId", Python::Tuple(language_, qname)); 57 } 58 59 DependentTypeId create_dependent_type_id(const ScopedName &name) 60 { 61 Python::Object qname = qname_kit_.create_qname(name); 62 return create<DependentTypeId>("DependentTypeId", Python::Tuple(language_, qname)); 63 } 64 65 UnknownTypeId create_unknown_type_id(const ScopedName &name) 66 { 67 Python::Object qname = qname_kit_.create_qname(name); 68 return create<UnknownTypeId>("UnknownTypeId", Python::Tuple(language_, qname)); 69 } 70 71 DeclaredTypeId create_declared_type_id(ScopedName const &name, 72 Declaration const &decl) 73 { 74 Python::Object qname = qname_kit_.create_qname(name); 75 return create<DeclaredTypeId>("DeclaredTypeId", Python::Tuple(language_, qname, decl)); 76 } 77 78 TemplateId create_template_id(const ScopedName &name, 79 const Declaration &decl, const Python::List ¶ms) 80 { 81 Python::Object qname = qname_kit_.create_qname(name); 82 return create<TemplateId>("TemplateId", Python::Tuple(language_, qname, decl, params)); 83 } 84 85 ModifierTypeId create_modifier_type_id(const TypeId &alias, 86 const Modifiers &pre, const Modifiers &post) 87 { return create<ModifierTypeId>("ModifierTypeId", Python::Tuple(language_, alias, pre, post));} 88 89 ArrayTypeId create_array_type_id(const TypeId &alias, 90 const Python::TypedList<int> &sizes) 91 { return create<ArrayTypeId>("ArrayTypeId", Python::Tuple(language_, alias, sizes));} 92 93 ParametrizedTypeId create_parametrized_id(const TemplateId &t, 94 const Python::List ¶ms) 95 { return create<ParametrizedTypeId>("ParametrizedTypeId", Python::Tuple(language_, t, params));} 96 97 FunctionTypeId create_function_type_id(const TypeId &retn, 98 const Modifiers &pre, const TypeIdList ¶ms) 99 { return create<FunctionTypeId>("FunctionTypeId", Python::Tuple(language_, retn, pre, params));} 100 101 Declaration create_declaration(const SourceFile &sf, long line, 102 const char *type, const ScopedName &name) 103 { 104 Python::Object qname = qname_kit_.create_qname(name); 105 return create<Declaration>("Declaration", Python::Tuple(sf, line, type, qname)); 106 } 107 108 Builtin create_builtin(const SourceFile &file, int line, 109 const std::string &type, const ScopedName &name) 110 { 111 Python::Object qname = qname_kit_.create_qname(name); 112 return create<Builtin>("Builtin", Python::Tuple(file, line, type, qname)); 113 } 114 115 Macro create_macro(SourceFile &sf, long line, 116 const ScopedName &name, const Python::List ¶meters, 117 const std::string &text) 118 { 119 Python::Object qname = qname_kit_.create_qname(name); 120 return create<Macro>("Macro", Python::Tuple(sf, line, "macro", 121 qname, parameters, text)); 122 } 123 124 Forward create_forward(const SourceFile &file, int line, 125 const std::string &type, const ScopedName &name) 126 { 127 Python::Object qname = qname_kit_.create_qname(name); 128 return create<Forward>("Forward", Python::Tuple(file, line, type, qname)); 129 } 130 131 Scope create_scope(const SourceFile &file, int line, 132 const std::string &type, const ScopedName &name) 133 { 134 Python::Object qname = qname_kit_.create_qname(name); 135 return create<Scope>("Scope", Python::Tuple(file, line, type, qname)); 136 } 137 138 Synopsis::ASG::Module 139 create_module(const SourceFile &file, int line, 140 const std::string &type, const ScopedName &name) 141 { 142 Python::Object qname = qname_kit_.create_qname(name); 143 return create<Synopsis::ASG::Module>("Module", Python::Tuple(file, line, type, qname)); 144 } 145 146 Inheritance create_inheritance(const TypeId &parent, 147 const Python::List &attributes) 148 { return create<Inheritance>("Inheritance", Python::Tuple(parent, attributes));} 149 150 Class create_class(const SourceFile &file, int line, 151 const std::string &type, const ScopedName &name) 152 { 153 Python::Object qname = qname_kit_.create_qname(name); 154 return create<Class>("Class", Python::Tuple(file, line, type, qname)); 155 } 156 157 Typedef create_typedef(const SourceFile &file, int line, 158 const std::string &type, const ScopedName &name, 159 const TypeId &alias, bool constr) 160 { 161 Python::Object qname = qname_kit_.create_qname(name); 162 return create<Typedef>("Typedef", Python::Tuple(file, line, type, qname, alias, constr)); 163 } 164 165 Enumerator create_enumerator(const SourceFile &file, int line, 166 const ScopedName &name, const std::string &value) 167 { 168 Python::Object qname = qname_kit_.create_qname(name); 169 return create<Enumerator>("Enumerator", Python::Tuple(file, line, qname, value)); 170 } 171 172 Enum create_enum(const SourceFile &file, int line, 173 const ScopedName &name, const Enumerators &values) 174 { 175 Python::Object qname = qname_kit_.create_qname(name); 176 return create<Enum>("Enum", Python::Tuple(file, line, qname, values)); 177 } 178 179 Variable create_variable(const SourceFile &file, int line, 180 const std::string &type, const ScopedName &name, 181 const TypeId &vtype, bool constr) 182 { 183 Python::Object qname = qname_kit_.create_qname(name); 184 return create<Variable>("Variable", Python::Tuple(file, line, type, qname, vtype, constr)); 185 } 186 187 Const create_const(const SourceFile &file, int line, 188 const std::string &type, const ScopedName &name, 189 const TypeId &ctype, const std::string &value) 190 { 191 Python::Object qname = qname_kit_.create_qname(name); 192 return create<Const>("Const", Python::Tuple(file, line, type, qname, ctype, value)); 193 } 194 195 Parameter create_parameter(const Modifiers &pre, const TypeId &type, const Modifiers &post, 196 const std::string &name, const std::string &value) 197 { return create<Parameter>("Parameter", Python::Tuple(pre, type, post, name, value));} 198 199 Function create_function(const SourceFile &file, int line, 200 const std::string &type, const Modifiers &pre, 201 const TypeId &ret, const Modifiers &post, 202 const ScopedName &name, const std::string &realname) 203 { 204 Python::Object qname = qname_kit_.create_qname(name); 205 return create<Function>("Function", Python::Tuple(file, line, type, pre, ret, post, 206 qname, realname)); 207 } 208 209 Operation create_operation(const SourceFile &file, int line, 210 const std::string &type, const Modifiers &pre, 211 const TypeId &ret, const Modifiers &post, 212 const ScopedName &name, const std::string &realname) 213 { 214 Python::Object qname = qname_kit_.create_qname(name); 215 return create<Operation>("Operation", Python::Tuple(file, line, type, pre, ret, post, 216 qname, realname)); 217 } 218private: 219 QNameKit qname_kit_; 220 std::string language_; 221}; 222} 223 224class SourceFileKit : public Python::Kit 225{ 226public: 227 SourceFileKit(std::string const &lang) : Python::Kit("Synopsis.SourceFile"), lang_(lang) {} 228 SourceFile create_source_file(const std::string &name, 229 const std::string &longname) 230 { return create<SourceFile>("SourceFile", Python::Tuple(name, longname, lang_));} 231 232 Include create_include(const SourceFile &sf, const std::string &name, 233 bool is_macro, bool is_next) 234 { return create<Include>("Include", Python::Tuple(sf, name, is_macro, is_next));} 235 236 MacroCall create_macro_call(const std::string &name, 237 int start_line, int start_col, int end_line, int end_col, 238 int e_start_line, int e_start_col, int e_end_line, int e_end_col) 239 { return create<MacroCall>("MacroCall", 240 Python::Tuple(name, 241 Python::Tuple(start_line, start_col), 242 Python::Tuple(end_line, end_col), 243 Python::Tuple(e_start_line, e_start_col), 244 Python::Tuple(e_end_line, e_end_col)));} 245private: 246 std::string lang_; 247}; 248 249} 250 251#endif