1 //@copyright_begin 2 // ================================================================ 3 // Copyright Notice 4 // Copyright (C) 1998-2004 by Joe Linoff 5 // 6 // Permission is hereby granted, free of charge, to any person obtaining 7 // a copy of this software and associated documentation files (the 8 // "Software"), to deal in the Software without restriction, including 9 // without limitation the rights to use, copy, modify, merge, publish, 10 // distribute, sublicense, and/or sell copies of the Software, and to 11 // permit persons to whom the Software is furnished to do so, subject to 12 // the following conditions: 13 // 14 // The above copyright notice and this permission notice shall be 15 // included in all copies or substantial portions of the Software. 16 // 17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 // IN NO EVENT SHALL JOE LINOFF BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 // OTHER DEALINGS IN THE SOFTWARE. 24 // 25 // Comments and suggestions are always welcome. 26 // Please report bugs to http://ccdoc.sourceforge.net/ccdoc 27 // ================================================================ 28 //@copyright_end 29 30 // MULTIPLE INCLUSION GUARD 31 #ifndef ccdoc_statement_h 32 #define ccdoc_statement_h 33 34 /** 35 * This variable allows the header version 36 * to be queried at runtime. 37 */ 38 namespace { 39 char ccdoc_types_h_rcsid[] = "$Id: statement.h,v 1.8 2004/09/30 04:16:07 jlinoff Exp $"; 40 } 41 42 #include "strmgr.h" 43 #include <iostream> 44 #include <vector> 45 #include <string> 46 47 namespace ccdoc { 48 namespace statement { 49 // ================================================================ 50 //@{ 51 // Statement base object. 52 // @author Joe Linoff 53 // @version $Id: statement.h,v 1.8 2004/09/30 04:16:07 jlinoff Exp $ 54 //@} 55 // ================================================================ 56 class base { 57 public: 58 typedef vector<const char*> cstrs_t; 59 typedef vector<const char*>::iterator cstrs_itr_t; 60 typedef vector<const char*>::const_iterator cstrs_citr_t; 61 typedef vector<const char*>::reverse_iterator cstrs_ritr_t; 62 public: 63 typedef vector<ccdoc::statement::base*> stmts_t; 64 typedef vector<ccdoc::statement::base*>::iterator stmts_itr_t; 65 typedef vector<ccdoc::statement::base*>::const_iterator stmts_citr_t; 66 typedef vector<ccdoc::statement::base*>::reverse_iterator stmts_ritr_t; 67 public: 68 typedef vector<string> strs_t; 69 typedef vector<string>::iterator strs_itr_t; 70 typedef vector<string>::const_iterator strs_citr_t; 71 typedef vector<string>::reverse_iterator strs_ritr_t; 72 public: 73 typedef vector<vector<string> > strss_t; 74 typedef vector<vector<string> >::iterator strss_itr_t; 75 typedef vector<vector<string> >::const_iterator strss_citr_t; 76 typedef vector<vector<string> >::reverse_iterator strss_ritr_t; 77 public: 78 enum TYPE 79 { 80 STMT_IGNORE, 81 STMT_ATTRIBUTE, // a class variable 82 STMT_ATTRIBUTE_FUNCTION, // a class variable 83 STMT_ENUM, 84 STMT_EXTERN, 85 STMT_FRIEND_CLASS, 86 STMT_FRIEND_FUNCTION, 87 STMT_FUNCTION, 88 STMT_FUNCTION_OPERATOR, 89 STMT_CLASS_BEGIN, 90 STMT_CLASS_END, 91 STMT_COMMENT_PKGDOC, 92 STMT_COMMENT_PKGDOC_URL, 93 STMT_COMMENT_PREFIX, 94 STMT_COMMENT_SUFFIX, 95 STMT_MACRODEF_0_0, // No args, no tokens: #define a 96 STMT_MACRODEF_0_1, // No args, 1 token: #define a b 97 STMT_MACRODEF_0_N, // No args, n tokens: #define a b+c 98 STMT_MACRODEF_N_N, // N args, n tokens: #define a(x,y,z) x+y+z 99 STMT_MACROINST_FUNCTION, 100 STMT_MACROINST_VARIABLE, 101 STMT_METHOD, 102 STMT_METHOD_CONSTRUCTOR, 103 STMT_METHOD_DESTRUCTOR, 104 STMT_METHOD_OPERATOR, 105 STMT_NAMESPACE_BEGIN, 106 STMT_NAMESPACE_END, 107 STMT_PACKAGE, 108 STMT_STRUCT_BEGIN, 109 STMT_STRUCT_END, 110 STMT_TYPEDEF_FUNCTION, 111 STMT_TYPEDEF_VARIABLE, 112 STMT_UNION_BEGIN, 113 STMT_UNION_END, 114 STMT_VARIABLE, 115 STMT_VARIABLE_FUNCTION 116 }; 117 enum ACCESS 118 { 119 STMT_PUBLIC, 120 STMT_PROTECTED, 121 STMT_PRIVATE 122 }; 123 public: 124 base(); 125 base(const base& x); 126 ~base(); 127 base& operator=(const base& x); 128 void clear(); 129 public: get_access()130 ACCESS get_access() const {return m_access;} set_access(ACCESS t)131 void set_access(ACCESS t) {m_access=t;} get_terse_access_name()132 const char* get_terse_access_name() const {return get_terse_access_name(m_access);} 133 static const char* get_terse_access_name(ACCESS t); 134 static ACCESS get_terse_access(const string&); get_access_name()135 const char* get_access_name() const {return get_access_name(m_access);} 136 static const char* get_access_name(ACCESS t); 137 public: get_type()138 TYPE get_type() const {return m_type;} set_type(TYPE t)139 void set_type(TYPE t) {m_type=t;} get_terse_type_name()140 const char* get_terse_type_name() const {return get_terse_type_name(m_type);} 141 static const char* get_terse_type_name(TYPE t); 142 static TYPE get_terse_type(const string&); get_type_name()143 const char* get_type_name() const {return get_type_name(m_type);} 144 static const char* get_type_name(TYPE t); 145 public: 146 /** 147 * The full type name in lower case. 148 * @returns The full type name in lower case. 149 */ get_type_name1()150 const char* get_type_name1() const {return get_type_name1(m_type);} 151 static const char* get_type_name1(TYPE t); 152 /** 153 * Get the full type name with static prepended. 154 * @returns The full type name in lower case with static 155 * pre-pended if m_static is true. 156 */ 157 string get_type_name2() const; 158 public: 159 base* get_matching_begin() const; 160 private: 161 base* get_matching_begin(TYPE) const; 162 public: 163 unsigned get_depth() const; 164 unsigned get_depth_no_pkgs() const; 165 public: get_tag()166 unsigned get_tag() const {return m_tag;} set_tag(unsigned x)167 void set_tag(unsigned x) {m_tag = x;} 168 public: get_lineno()169 unsigned get_lineno() const {return m_lineno;} set_lineno(unsigned x)170 void set_lineno(unsigned x) {m_lineno = x;} 171 public: get_file()172 const char* get_file() const {return m_file;} 173 void set_file(const char* fn); set_file(const string & fn)174 void set_file(const string& fn) {set_file(fn.c_str());} 175 public: get_extern()176 const char* get_extern() const {return m_extern;} 177 void set_extern(const char* x); set_extern(const string & x)178 void set_extern(const string& x) {set_extern(x.c_str());} 179 public: get_id()180 const char* get_id() const {return m_id;} 181 void get_hier_id(string&) const; 182 void get_hier_id_no_pkgs(string&) const; 183 void set_id(const char* id); 184 void set_id(const string& id); 185 public: get_static()186 bool get_static() const {return m_static;} set_static(bool f)187 void set_static(bool f) {m_static=f;} 188 public: get_template()189 bool get_template() const {return m_template;} set_template(bool f)190 void set_template(bool f) {m_template=f;} 191 public: 192 void get_parents(stmts_t& parents) const; 193 void get_parents_no_pkgs(stmts_t& parents) const; get_parent()194 base* get_parent() const {return m_parent;} 195 void set_parent(base* parent); 196 public: get_comment()197 base* get_comment() const {return m_comment;} set_comment(base * comment)198 void set_comment(base* comment) {m_comment=comment;} 199 public: 200 void get_all_children(stmts_t& children) const; get_children()201 stmts_t& get_children() {return m_children;} 202 base* get_child_by_id(const char*) const; 203 base* get_child_by_id(const string&) const; 204 base* get_child_by_id_type(const char*,TYPE t) const; 205 base* get_child_by_id_type(const string&,TYPE t) const; 206 bool find_child(base*) const; 207 void add_child(base*); 208 void remove_child(base*); 209 bool get_children_by_id(stmts_t&,const char*); 210 bool get_children_by_id(stmts_t&,const string&); 211 public: 212 void insert_before(base*); 213 void insert_after(base*); 214 public: get_tokens()215 const cstrs_t& get_tokens() const {return m_tokens;} 216 void set_tokens(strs_t& vec); add_token(const string & str)217 void add_token(const string& str) {add_token(str.c_str());} 218 void add_token(const char* str); 219 public: set_next(base * next)220 void set_next(base* next) {m_next=next;} get_next()221 base* get_next() const {return m_next;} 222 public: 223 /** 224 * Sort the children for fast access. 225 */ 226 void sort_children(); 227 private: 228 stmts_itr_t search(const char*); 229 stmts_itr_t search(const string&); 230 public: 231 void debug_dump(const char* prefix); 232 public: 233 /** 234 * Report whether this statement has an id that is a macro name 235 * that should be ignored (as specified by the -rptmac1 switch). 236 * This method exists here because it can be used in phase 1 or 237 * phase 3. 238 * @param id The macro id. 239 * @returns True if this macro s/b ignored or false otherwise. 240 */ 241 bool is_rptmac1_id() const; 242 /** 243 * Report whether this id is a macro name that should 244 * be ignored (as specified by the -rptmac1 switch). 245 * This method exists here because it can be used 246 * in phase 1 or phase 3. 247 * @param id The macro id. 248 * @returns True if this macro s/b ignored or false otherwise. 249 */ 250 static bool is_rptmac1_id(const char* id); 251 public: 252 static strmgr& get_strmgr(); 253 private: 254 const char* set_string(const char*); 255 private: 256 stmts_t m_children; 257 base* m_comment; 258 const char* m_file; 259 const char* m_id; 260 const char* m_extern; 261 unsigned m_lineno; 262 base* m_parent; 263 cstrs_t m_tokens; 264 TYPE m_type; 265 ACCESS m_access; 266 unsigned m_tag; 267 bool m_sorted; 268 bool m_static; 269 bool m_template; 270 base* m_next; 271 }; 272 // ================================================================ 273 //@{ 274 // Statement comment object. 275 // @author Joe Linoff 276 // @version $Id: statement.h,v 1.8 2004/09/30 04:16:07 jlinoff Exp $ 277 //@} 278 // ================================================================ 279 class comment { 280 public: 281 //@{ 282 // Default constructor. 283 //@} 284 comment(); 285 //@{ 286 // Statement based constructor. 287 // The fields are filled from the statement tokens. 288 // @param comment The comment statement. 289 // If the comment is NULL, the object will have no 290 // entries. 291 //@} 292 comment(base* stmt); 293 //@{ 294 // Destructor. 295 //@} 296 ~comment(); 297 public: 298 void set(const base::cstrs_t& tokens); 299 private: 300 bool set_scalar(string& token, 301 base::cstrs_citr_t& i, 302 base::cstrs_citr_t& e, 303 const char* match=0); 304 bool set(string& token, 305 base::cstrs_citr_t& i, 306 base::cstrs_citr_t& e, 307 const char* match=0); 308 bool set(base::strs_t& vec, 309 base::cstrs_citr_t& i, 310 base::cstrs_citr_t& e, 311 const char* match); 312 bool set(base::strss_t& vec, 313 base::cstrs_citr_t& i, 314 base::cstrs_citr_t& e, 315 const char* match, 316 const char* match1); 317 public: 318 void get(base::strs_t& tokens); 319 private: 320 void get(base::strs_t& tokens, 321 const base::strs_t& vec, 322 const char* type); 323 void get(base::strs_t& tokens, 324 base::strss_t& vecvec, 325 const char* type); 326 public: 327 bool empty() const; 328 void clear(); 329 public: 330 void add_author (const string& name); 331 void add_deprecated (const string& name); 332 void add_new_exception (const string& name); 333 void add_new_exception (const string& name,const string& desc); 334 void add_exception_desc (const string& desc); 335 void add_file (const string& name); 336 void add_lineno (const string& name); 337 void add_long_desc (const string& desc); 338 void add_new_param (const string& name); 339 void add_new_param (const string& name,const string& desc); 340 void add_param_desc (const string& desc); 341 void add_pkg (const string& desc); 342 void add_pkgdoc (const string& desc); 343 void add_pkgdoc_tid (const string& desc); 344 void add_returns (const string& desc); 345 void add_new_see (const string& name); 346 void add_new_see (const string& name,const string& desc); 347 void add_see_desc (const string& desc); 348 void add_short_desc (const string& desc); 349 void add_todo (const string& desc); 350 /** 351 * Set the version for the @since directive. 352 * @param version The since version string. 353 * @since r24 354 */ 355 void add_since (const string& version); 356 void add_source (const string& name); 357 void add_version (const string& name); add_suffix(bool f)358 void add_suffix (bool f ) {m_suffix=f;} 359 public: get_authors()360 const base::strs_t& get_authors() const {return m_authors;} get_deprecated()361 const base::strs_t& get_deprecated() const {return m_deprecated;} get_exceptions()362 const base::strss_t& get_exceptions() const {return m_exceptions;} get_file()363 const string& get_file() const {return m_file;} get_lineno()364 const string& get_lineno() const {return m_lineno;} get_long_desc()365 const base::strs_t& get_long_desc() const {return m_long_desc;} get_params()366 const base::strss_t& get_params() const {return m_params;} get_pkg()367 const base::strs_t& get_pkg() const {return m_pkg;} get_pkgdoc()368 const base::strs_t& get_pkgdoc() const {return m_pkgdoc;} get_returns()369 const base::strs_t& get_returns() const {return m_returns;} get_sees()370 const base::strss_t& get_sees() const {return m_sees;} get_short_desc()371 const base::strs_t& get_short_desc() const {return m_short_desc;} get_todo()372 const base::strs_t& get_todo() const {return m_todo;} 373 /** 374 * Get the version for the @since directive. 375 * @returns The since string. 376 * @since r24 377 */ get_since()378 const string& get_since() const {return m_since;} get_source()379 const string& get_source() const {return m_source;} get_version()380 const string& get_version() const {return m_version;} get_suffix()381 bool get_suffix() const {return m_suffix;} 382 public: 383 const string& get_pkgdoc_url() const; 384 const string& get_pkgdoc_tid() const; 385 private: 386 base* m_stmt; // Issue 0053 387 base::strs_t m_authors; 388 base::strs_t m_deprecated; 389 base::strss_t m_exceptions; 390 string m_file; 391 string m_lineno; 392 base::strs_t m_long_desc; 393 base::strss_t m_params; 394 base::strs_t m_pkg; 395 base::strs_t m_pkgdoc; 396 base::strs_t m_returns; 397 base::strss_t m_sees; 398 base::strs_t m_short_desc; 399 string m_since; 400 string m_source; 401 base::strs_t m_todo; // Issue 0120 402 string m_version; 403 bool m_suffix; 404 }; 405 } 406 } 407 408 #endif 409 410