Synopsis - Cross-Reference
File: /src/Synopsis/ASG/Declaration.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_Declaration_hh 9#define _Synopsis_ASG_Declaration_hh 10 11#include <Synopsis/Python/Object.hh> 12#include <Synopsis/ASG/Visitor.hh> 13#include <Synopsis/ASG/TypeId.hh> 14 15namespace Synopsis 16{ 17namespace ASG 18{ 19 20enum Access 21{ 22 DEFAULT = 0, 23 PUBLIC = 1, 24 PROTECTED = 2, 25 PRIVATE = 3 26}; 27 28class Declaration; 29typedef Python::TypedList<Declaration> Declarations; 30} 31 32class SourceFile : public Python::Object 33{ 34public: 35 SourceFile() {} 36 SourceFile(Python::Object const &o) : Python::Object(o) {} 37 std::string name() const { return narrow<std::string>(attr("name"));} 38 std::string abs_name() const { return narrow<std::string>(attr("abs_name"));} 39 bool primary() const { return narrow<bool>(Python::Dict(attr("annotations")).get("primary"));} 40 void set_primary(bool flag) 41 { 42 Python::Dict annotations(attr("annotations")); 43 annotations.set("primary", flag); 44 } 45 Python::List includes() { return attr("includes");} 46 Python::List macro_calls() { return attr("macro_calls");} 47 ASG::Declarations declarations(); 48}; 49 50namespace ASG 51{ 52class Declaration : public Python::Object 53{ 54public: 55 Declaration() {} 56 Declaration(const Python::Object &o, bool check = true) 57 : Python::Object(o) { if (check) assert_type("Declaration");} 58 59 SourceFile file() const { return narrow<SourceFile>(attr("file"));} 60 long line() const { return narrow<long>(attr("line"));} 61 std::string language() const { return narrow<std::string>(attr("language"));} 62 std::string type() const { return narrow<std::string>(attr("type"));} 63 ScopedName name() const { return attr("name");} 64 Python::Dict annotations() { return attr("annotations");} 65 Access accessibility() const 66 { return static_cast<Access>(narrow<long>(attr("accessibility")));} 67 void accessibility(Access a) const 68 { attr("accessibility")(Python::Tuple(static_cast<long>(a)));} 69 70 virtual void accept(Visitor *v) { v->visit_declaration(this);} 71 72 void assert_type(const char *type) { Python::Object::assert_type("Synopsis.ASG", type);} 73}; 74 75//. A Builtin is a node to be used internally. 76//. Right now it's being used to capture comments 77//. at the end of a scope. 78class Builtin : public Declaration 79{ 80public: 81 Builtin() {} 82 Builtin(const Python::Object &o, bool check = true) 83 : Declaration(o, false) { if (check) assert_type("Builtin");} 84 85 virtual void accept(Visitor *v) { v->visit_builtin(this);} 86}; 87 88class Macro : public Declaration 89{ 90public: 91 Macro() {} 92 Macro(const Python::Object &o, bool check = true) 93 : Declaration(o, false) { if (check) assert_type("Macro");} 94 95 Python::List parameters() { return attr("parameters");} 96 std::string text() { return narrow<std::string>(attr("text"));} 97 98 virtual void accept(Visitor *v) { v->visit_macro(this);} 99}; 100 101//. Forward declaration. Currently this has no extra attributes. 102class Forward : public Declaration 103{ 104public: 105 Forward() {} 106 Forward(const Python::Object &o, bool check = true) 107 : Declaration(o, false) { if (check) assert_type("Forward");} 108 109// //. Returns the Template object if this is a template 110// Template template_type() {} 111 112// //. Sets the Template object for this class. NULL means not a template 113// void set_template_type(Types::Template* type); 114 115 virtual void accept(Visitor *v) { v->visit_forward(this);} 116}; 117 118//. Base class for scopes with contained declarations. Each scope has its 119//. own Dictionary of names so far accumulated for this scope. Each scope 120//. also as a complete vector of scopes where name lookup is to proceed if 121//. unsuccessful in this scope. Name lookup is not recursive. 122class Scope : public Declaration 123{ 124public: 125 Scope() {} 126 Scope(const Python::Object &o, bool check = true) 127 : Declaration(o, false) { if (check) assert_type("Scope");} 128 129 Python::List declarations() const { return attr("declarations");} 130 131 virtual void accept(Visitor *v) { v->visit_scope(this);} 132}; 133 134//. Module class 135class Module : public Scope 136{ 137public: 138 Module() {} 139 Module(const Python::Object &o, bool check = true) 140 : Scope(o, false) { if (check) assert_type("Module");} 141 142 virtual void accept(Visitor *v) { v->visit_module(this);} 143}; 144 145//. Inheritance class. This class encapsulates the information about an 146//. inheritance, namely its accessability. Note that classes inherit from 147//. types, not class declarations. As such it's possible to inherit from a 148//. parameterized type, or a declared typedef or class/struct. 149class Inheritance : public Python::Object 150{ 151public: 152 Inheritance() {} 153 Inheritance(const Python::Object &o, bool check = true) 154 : Python::Object(o) { if (check) assert_type("Synopsis.ASG", "Inheritance");} 155 156 //. Returns the Class object this inheritance refers to. The method 157 //. returns a Type since typedefs to classes are preserved to 158 //. enhance readability of the generated docs. Note that the parent 159 //. may also be a non-declaration type, such as vector<int> 160 TypeId parent() const { return attr("parent")();} 161 162 //. Returns the attributes of this inheritance 163 Python::List attributes() const { return attr("attributes")();} 164 165 void accept(Visitor *v) { v->visit_inheritance(this);} 166}; 167 168//. Class class 169class Class : public Scope 170{ 171public: 172 Class() {} 173 Class(const Python::Object &o, bool check = true) 174 : Scope(o, false) { if (check) assert_type("Class");} 175 176 //. Constant version of parents() 177 Python::List parents() const { return attr("parents")();} 178 179 //. Returns the Template object if this is a template 180 Object template_() { return attr("template")();} 181 182 //. Sets the Template object for this class. 183 void set_template(Object type) { attr("set_template")(Python::Tuple(type));} 184 185 virtual void accept(Visitor *v) { v->visit_class(this);} 186}; 187 188//. Typedef declaration 189class Typedef : public Declaration 190{ 191public: 192 Typedef() {} 193 Typedef(const Python::Object &o, bool check = true) 194 : Declaration(o, false) { if (check) assert_type("Typedef");} 195 196 //. Returns the Type object this typedef aliases 197 TypeId alias() const { return attr("alias");} 198 //. Returns true if the Type object was constructed inside the typedef 199 bool constructed() const { return narrow<bool>(attr("constr"));} 200 201 virtual void accept(Visitor *v) { v->visit_typedef(this);} 202}; 203 204//. Enumerator declaration. This is a name with a value in the containing 205//. scope. Enumerators only appear inside Enums via their enumerators() 206//. attribute. 207class Enumerator : public Declaration 208{ 209public: 210 Enumerator() {} 211 Enumerator(const Python::Object &o, bool check = true) 212 : Declaration(o, false) { if (check) assert_type("Enumerator");} 213 214 //. Returns the value of this enumerator 215 std::string value() const { return narrow<std::string>(attr("value"));} 216 217 virtual void accept(Visitor *v) { v->visit_enumerator(this);} 218}; 219 220 221//. This needs to be flexible enough to hold Enumerators and Builtins. 222typedef Python::TypedList<Declaration> Enumerators; 223 224//. Enum declaration. An enum contains multiple enumerators. 225class Enum : public Declaration 226{ 227public: 228 Enum() {} 229 Enum(const Python::Object &o, bool check = true) 230 : Declaration(o, false) { if (check) assert_type("Enum");} 231 232 //. Returns the vector of Enumerators 233 Python::List enumerators() { return attr("enumerators");} 234 235 virtual void accept(Visitor *v) { v->visit_enum(this);} 236}; 237 238//. Variable declaration 239class Variable : public Declaration 240{ 241public: 242 Variable() {} 243 Variable(const Python::Object &o, bool check = true) 244 : Declaration(o, false) { if (check) assert_type("Variable");} 245 246 //. Returns the Type object of this variable 247 TypeId vtype() const { return attr("vtype");} 248 //. Returns true if the Type object was constructed inside the variable 249 bool constructed() const { return attr("constr");} 250 //. Returns the array sizes vector 251 Python::List sizes() const { return attr("sizes");} 252 253 virtual void accept(Visitor *v) { v->visit_variable(this);} 254}; 255 256//. A const is a name with a value and declared type. 257class Const : public Declaration 258{ 259public: 260 Const() {} 261 Const(const Python::Object &o, bool check = true) 262 : Declaration(o, false) { if (check) assert_type("Const");} 263 264 //. Returns the TypeId object of this const 265 TypeId ctype() const { return attr("ctype");} 266 //. Returns the value of this enumerator 267 std::string value() const { return narrow<std::string>(attr("value"));} 268 269 virtual void accept(Visitor *v) { v->visit_const(this);} 270}; 271 272class Parameter : public Python::Object 273{ 274public: 275 Parameter() {} 276 Parameter(const Python::Object &o, bool check = true) 277 : Python::Object(o) { if (check) assert_type("Synopsis.ASG", "Parameter");} 278 279 Modifiers premodifiers() const { return narrow<Modifiers>(attr("premodifiers"));} 280 Modifiers postmodifiers() const { return narrow<Modifiers>(attr("postmodifiers"));} 281 TypeId type() const { return narrow<TypeId>(attr("type"));} 282 std::string name() const { return narrow<std::string>(attr("identifier"));} 283 std::string value() const { return narrow<std::string>(attr("value"));} 284 285 virtual void accept(Visitor *v) { v->visit_parameter(this);} 286}; 287 288//. Function encapsulates a function declaration. Note that names may be 289//. stored in mangled form, and formatters should use real_name() to get 290//. the unmangled version. If this is a function template, use the 291//. template_type() method to get at the template type 292class Function : public Declaration 293{ 294public: 295 typedef Python::TypedList<Parameter> Parameters; 296 297 Function() {} 298 Function(const Python::Object &o, bool check = true) 299 : Declaration(o, false) { if (check) assert_type("Function");} 300 301// //. The type of premodifiers 302// typedef std::vector<std::string> Mods; 303 304 //. Returns the return-type 305 TypeId return_type() const { return attr("return_type");} 306 307 //. Returns the real name of this function 308 ScopedName real_name() const { return attr("real_name");} 309 310 //. Returns the vector of parameters 311 Parameters parameters() const { return attr("parameters");} 312 313 //. Returns the Template object if this is a template 314// Types::Template* template_type() 315// { 316// return m_template; 317// } 318 319 //. Sets the Template object for this class. NULL means not a template 320// void set_template_type(Types::Template* type) 321// { 322// m_template = type; 323// } 324 325 //. Accept the given visitor 326 virtual void accept(Visitor *v) { v->visit_function(this);} 327}; 328 329//. Operations are similar to functions but Not Quite Right 330class Operation : public Function 331{ 332public: 333 Operation() {} 334 Operation(const Python::Object &o, bool check = true) 335 : Function(o, false) { if (check) assert_type("Operation");} 336 337 virtual void accept(Visitor *v) { v->visit_operation(this);} 338}; 339 340} 341 342inline ASG::Declarations SourceFile::declarations() 343{ return narrow<ASG::Declarations>(attr("declarations"));} 344 345} 346 347#endif