mtoc++  1.5
mtoc++: Doxygen filter for MatLab .m files
 All Classes Namespaces Variables Pages
mfilescanner.h
1 #ifndef MFILESCANNER_H_
2 #define MFILESCANNER_H_
3 
4 #include "config.h"
5 
6 #include "confscanner.h"
7 #include <string>
8 #include <vector>
9 #include <map>
10 #include <set>
11 #include <list>
12 #include <sstream>
13 #include <fstream>
14 
15 #ifdef WIN32
16 #include <direct.h>
17 #else
18 extern "C" {
19 #include <unistd.h>
20 #include <errno.h>
21 }
22 #include <climits>
23 #endif
24 
25 // 160 KB
26 #define BUFSIZE 100*16384
27 
28 #define stringify( name ) #name
29 
30 struct RunMode {
31  RunMode() :
32  mode(Normal),
33  methodname(),
34  /* configuration defaults */
35  latex_output(false),
36  print_fields(PRINT_FIELDS),
37  auto_add_fields(AUTO_ADD_FIELDS),
38  auto_add_params(AUTO_ADD_PARAMETERS),
39  auto_add_class_properties(AUTO_ADD_CLASS_PROPERTIES),
40  auto_add_class(AUTO_ADD_CLASSES),
41  copy_typified_field_docu(COPY_TYPIFIED_FIELD_DOCU),
42  remove_first_arg_in_abstract_methods(
43  REMOVE_FIRST_ARG_IN_ABSTRACT_METHODS),
44  parse_of_type(ENABLE_OF_TYPE_PARSING),
45  void_type_in_return_values(VOID_TYPE_IN_RETURN_VALUES),
46  print_return_value_name(PRINT_RETURN_VALUE_NAME),
47  generate_subfunction_documentation(
48  GENERATE_SUBFUNTION_DOCUMENTATION) {
49  }
50 
51  typedef enum {
52  Normal = 0,
53  ParseParams,
54  ParseMethodParams
55  } Mode;
56 
57  Mode mode;
58  std.string methodname;
59  bool latex_output;
60  bool print_fields;
61  bool auto_add_fields;
62  bool auto_add_params;
63  bool auto_add_class_properties;
64  bool auto_add_class;
65  bool copy_typified_field_docu;
66  bool remove_first_arg_in_abstract_methods;
67  bool parse_of_type;
68  bool void_type_in_return_values;
69  int print_return_value_name;
70  bool generate_subfunction_documentation;
71 };
72 
73 typedef enum {
74  Access,
75  SetAccess,
76  GetAccess,
77  ListenAccess,
78  NotifyAccess
79 } MatlabAccessEnum;
80 
81 std.ostream & operator<<(std.ostream & os, MatlabAccessEnum & mae);
82 
83 typedef enum {
84  Public = 0,
85  Protected,
86  Private
87 } AccessEnum;
88 
89 /*extern const char * AccessEnumNames[];*/
90 
91 typedef enum {
92  InClassComment,
93  Header,
94  Method,
95  AtMethod,
96  MethodDeclaration,
97  Property,
98  Event,
99  Enumeration
100 } ClassPart;
101 
102 /*extern const char * ClassPartNames[];*/
103 
104 struct AccessStruct {
105  AccessEnum full;
106  AccessEnum get;
107  AccessEnum set;
108  std.vector<std.pair<MatlabAccessEnum, std.string> > classMemberAccess;
109  MatlabAccessEnum state;
110 
111 public:
112  AccessStruct() :
113  full(Public),
114  get(Public),
115  set(Public),
116  state(Access) {
117  }
118  ;
119 
120  friend std.ostream & operator<<(std.ostream & os, AccessStruct & as);
121 };
122 
123 struct PropParams {
124  bool constant;
125  bool transient;
126  bool dependent;
127  bool hidden;
128  bool setObservable;
129  bool abstr;
130  bool abortSet;
131  bool event;
132 
133  std.string ccprefix() {
134  if (constant)
135  return "static const ";
136  else
137  return "";
138  }
139 
140  std.string print_list() {
141  std.ostringstream oss;
142  char pre = '(';
143  if (constant) {
144  oss << pre << " Constant";
145  pre = ',';
146  }
147  if (transient) {
148  oss << pre << " Transient";
149  pre = ',';
150  }
151  if (dependent) {
152  oss << pre << " Dependent";
153  pre = ',';
154  }
155  if (hidden) {
156  oss << pre << " Hidden";
157  pre = ',';
158  }
159  if (setObservable) {
160  oss << pre << " setObservable";
161  pre = ',';
162  }
163  if (abstr) {
164  oss << pre << " Abstract";
165  pre = ',';
166  }
167  if (pre == ',')
168  oss << " )";
169  return oss.str();
170  }
171 
172 public:
173  PropParams() :
174  constant(false),
175  transient(false),
176  dependent(false),
177  hidden(false),
178  setObservable(false),
179  abstr(false),
180  abortSet(false) {
181  }
182  ;
183 
184  friend std.ostream & operator<<(std.ostream & os, PropParams & pp);
185 };
186 
188  bool dependent;
189  bool setter;
190  bool getter;
191 
192 public:
194  dependent(false),
195  setter(false),
196  getter(false) {
197  }
198  ;
199 };
200 
201 struct MethodParams {
202  bool abstr;
203  bool statical;
204  bool hidden;
205  bool sealed;
206  bool test;
207  bool testMethodSetup;
208  bool testMethodTeardown;
209 
210  std.string ccprefix() {
211  if (statical)
212  return "static ";
213  else if (abstr)
214  return "virtual ";
215  else
216  return "";
217  }
218  std.string ccpostfix() {
219  if (abstr)
220  return " = 0;";
221  else
222  return ";";
223  }
224 
225  std.string print_list() {
226  std.ostringstream oss;
227  char pre = '(';
228  if (abstr) {
229  oss << pre << " Abstract";
230  pre = ',';
231  }
232  if (statical) {
233  oss << pre << " Static";
234  pre = ',';
235  }
236  if (hidden) {
237  oss << pre << " Hidden";
238  pre = ',';
239  }
240  if (sealed) {
241  oss << pre << " Sealed";
242  pre = ',';
243  }
244  if (test) {
245  oss << pre << " Test";
246  pre = ',';
247  }
248  if (testMethodSetup) {
249  oss << pre << " TestMethodSetup";
250  pre = ',';
251  }
252  if (testMethodTeardown) {
253  oss << pre << " TestMethodTeardown";
254  pre = ',';
255  }
256  if (pre == ',')
257  oss << " )";
258  return oss.str();
259 
260  }
261 public:
262  MethodParams() :
263  abstr(false),
264  statical(false),
265  hidden(false),
266  sealed(false),
267  test(false),
268  testMethodSetup(false),
269  testMethodTeardown(false) {
270  }
271  ;
272 
273  friend std.ostream & operator<<(std.ostream & os, MethodParams & mp);
274 };
275 
276 template<class ST>
277 class ordered_map: public std.vector<std.pair<std.string, ST> > {
278 public:
279 
280  typedef std.pair<std.string, ST> item;
281  typedef std.vector<item> base_type;
282  typedef typename base_type.iterator iterator;
283  typedef typename base_type.const_iterator const_iterator;
284 
285 public:
286 
287  ordered_map() :
288  base_type() {
289  }
290  ;
291 
292  ST & operator[](const std.string & key) {
293  iterator it = this->find(key);
294  if (it == this->end()) {
295  this->push_back(make_pair(key, ST()));
296  it = this->end() - 1;
297  }
298  return it->second;
299  }
300 
301  iterator find(const std.string & key) {
302  iterator it = this->begin();
303  for (; it != this->end(); ++it) {
304  if (it->first == key)
305  break;
306  }
307  return it;
308  }
309 };
310 
432 public:
433  typedef std.vector<std.string> DocuBlock;
436  typedef std.map<std.string, DocuBlock> AltDocuList;
437  typedef std.map<std.string, AltDocuList> AltDocuListMap;
438  typedef std.set<std.string> GroupSet;
439 
441 
442 public:
443  MFileScanner(std.istream & fin, std.ostream & fout,
444  const std.string & filename, const std.string & conffilename,
445  RunMode runmode);
446 
447  virtual ~MFileScanner() {
448  delete buf;
449  }
450 
451  int execute();
452 
453  DocuList & getParamList() {
454  return param_list_;
455  }
456 
457  MethodParams & getMethodParams() {
458  return methodparams_;
459  }
460 
461  void end_function();
462 
463 private:
464 
465  void extract_default_argument_of_inputparser(std.string & last_args);
466  void add_access_info(std.string);
467  void add_property_params_info();
468  void add_method_params_info();
469  void end_of_class_doc();
470  std.string access_specifier_string(AccessEnum & access);
471  void print_access_specifier(AccessEnum & access, MethodParams & mp,
472  PropParams & pp);
473  void print_pure_function_synopsis();
474  void print_function_synopsis();
475  void end_of_property_doc();
476  void end_of_enum_doc();
477  void get_typename(const std.string &, std.string &, std.string voidtype =
478  std.string(""));
479  void get_default(const std.string &, std.string &);
480  void handle_param_list_for_varargin();
481  void extract_typen(DocuBlock & db, std.string & typen,
482  bool remove = false);
483  const std.string & extract_default(DocuBlock &, std.string &);
484  void update_method_params(const std.string & methodname);
485 
486  void end_method();
487  void clear_lists();
488  std.string namespace_string();
489 
490  void cout_ingroup();
491  void cout_docuheader(std.string, bool clear = true);
492  void cout_docubody();
493  void cout_docuextra();
494  const std.string & replace_underscore(std.string & s);
495 
496  const std.string & escape_chars(std.string & s);
497 
498  void print_warning(const std.string &);
499  void write_docu_block(const DocuBlock & block);
500 
501  void write_docu_list(const DocuList & list, const std.string & item_text,
502  const AltDocuList & alternative, bool, const std.string separator,
503  const std.string docu_list_name);
504 
505  void write_docu_listmap(const DocuListMap & listmap,
506  const std.string & text, const AltDocuListMap & altlistmap);
507 
508  void debug_output(const std.string & msg, char * p);
509 
510  void postprocess_unused_params(std.string &, DocuList &);
511 
512 private:
513  std.istream & fin_;
514  std.ostream & fout_;
515  const std.string filename_;
516  ConfFileScanner cscan_;
517  std.string fnname_;
518  std.list<std.string> namespaces_;
519  char *buf;
520  int line, col;
521  char *ts, *te;
522  int act, have;
523  int cs;
524  int top;
525  int stack[10];
526  bool opt;
527  bool extra_hold_in_cblock;
528  bool new_syntax_;
529  bool is_voc;
530  DocuListMap required_list_;
531  DocuListMap optional_list_;
532  DocuListMap retval_list_;
533  DocuList param_list_;
534  DocuList return_list_;
535  DocuBlock returnlist_;
536  DocuList *clist_;
537  DocuBlock docuheader_;
538  DocuBlock docubody_;
539  DocuBlock docuextra_;
540  DocuBlock paramlist_;
541  /* AltDocuList param_defaults_;*/
542  std.string cfuncname_;
543  GroupSet groupset_;
544  bool is_script_;
545  bool is_first_function_;
546  bool is_class_;
547  bool is_setter_;
548  bool is_getter_;
549  std.string classname_;
550  std.string.size_type funcindent_;
551  ClassPart class_part_;
552  AccessStruct access_;
553  PropParams propertyparams_;
554  MethodParams methodparams_;
555  std.vector<std.string> property_list_;
556  RunMode runMode_;
557  std.string defaultprop_;
558  std.string dirname_;
559 
560  std.map<std.string, std.string> param_type_map_;
561  bool undoced_prop_;
562  std.map<std.string, PropExtraInformation> specifier_;
563 
564  std.string varargin_parser_candidate_;
565  VararginParserValuesType varargin_parser_values_;
566  std.ostringstream warning_buffer_;
567 
568 };
569 
570 extern const char * AccessEnumNames[];
571 
572 extern const char * ClassPartNames[];
573 
574 /* vim: set et sw=2: */
575 #endif /* MFILESCANNER_H_ */
576