00001
00002
00003 #ifndef annotator_h
00004 #define annotator_h
00005
00006 #include "ptree_visitor.h"
00007 #include "paranoid_visitor.h"
00008 #include "type_rep.h"
00009
00010
00011
00012
00013
00014
00015 class Source;
00016 class Symbol_table;
00017 class Abstract_scope;
00018 class Block_scope;
00025 #define HACK_EXPLICIT(typespec, storagespec) \
00026 if (typespec->Eq("explicit")) { \
00027 storagespec = Ptree::Snoc(storagespec, typespec); \
00028 typespec = 0; \
00029 }
00030
00031 typedef int Annotator_RT;
00032
00033 class Annotator : public Paranoid_visitor<Annotator_RT> {
00034 Abstract_scope* current_scope;
00035 Block_scope* current_block;
00036 Ptree* output;
00037 public:
00038
00039 public:
00040
00041 Annotator(Source* s, Abstract_scope* scope);
00042
00043 Annotator(Source* s, Block_scope* scope);
00044
00050 Annotator_RT visit_name_declaration(Ptree* storagespec, Ptree* typespec, Ptree* decllist);
00051
00052 Annotator_RT visit_function(Ptree* storagespec, Ptree* typespec, PtreeDeclarator* decl, PtreeBlock* block);
00053
00054 Annotator_RT visit_templatedecl(PtreeTemplateDecl* p);
00055
00056
00057 Annotator_RT visit_linkagespec(PtreeLinkageSpec* p);
00058
00059 Annotator_RT visit_brace(PtreeBrace* p);
00060
00061 Annotator_RT visit_typedef(PtreeTypedef* p);
00062
00064 Annotator_RT visit_type_declaration(Ptree* storagespec, Ptree* typespec);
00065
00069 Annotator_RT visit_accessspec(PtreeAccessSpec* p);
00070
00071 Annotator_RT visit_namespacespec(PtreeNamespaceSpec* p);
00072
00073 Annotator_RT visit_nonleaf(NonLeaf* p);
00074
00075 Annotator_RT visit_using(PtreeUsing* p);
00076
00077
00078 void visit_stmt_or_block(Ptree* p);
00079
00081 Annotator_RT visit_block(PtreeBlock* p);
00082
00083 Annotator_RT visit_do(PtreeDoStatement* p);
00084
00085 Annotator_RT visit_while(PtreeWhileStatement* p);
00086
00087 Annotator_RT visit_if(PtreeIfStatement* p);
00088
00090 Annotator_RT visit_exprstatement(PtreeExprStatement* p);
00091
00092 Annotator_RT visit_for(PtreeForStatement* p);
00093
00094 Annotator_RT visit_return(PtreeReturnStatement* p);
00095
00096
00097 Annotator_RT visit_switch(PtreeSwitchStatement* p);
00098
00099 Annotator_RT visit_label(PtreeLabelStatement* lbl);
00100
00101 Annotator_RT visit_default(PtreeDefaultStatement* lbl);
00102
00103 Annotator_RT visit_case(PtreeCaseStatement* c);
00104
00105 Annotator_RT visit_goto(PtreeGotoStatement* g);
00106
00107 Annotator_RT visit_continue(PtreeContinueStatement* c);
00108
00109 Annotator_RT visit_break(PtreeBreakStatement* b);
00110
00111
00112
00116 void process_pending();
00117
00119 void add_output(Ptree* node);
00120
00122 void add_output_list(Ptree* nodes);
00123
00125 Ptree* get_output() const;
00126
00128 PtreeBlock* get_output_as_block() const;
00129
00131 bool is_code() const;
00132 };
00133
00134
00135
00136
00137
00138
00139
00141 inline Ptree*
00142 Annotator::get_output() const
00143 {
00144 return output;
00145 }
00146
00147
00149 inline bool
00150 Annotator::is_code() const
00151 {
00152 return current_block;
00153 }
00154
00155 #endif // annotator_h