00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef CPPPREPROCESSOR_H
00020 #define CPPPREPROCESSOR_H
00021
00022 #include <dtoolbase.h>
00023
00024 #include "cppManifest.h"
00025 #include "cppToken.h"
00026 #include "cppFile.h"
00027 #include "cppCommentBlock.h"
00028
00029 #include <dSearchPath.h>
00030 #include <vector_string.h>
00031
00032 #include <map>
00033 #include <list>
00034 #include <vector>
00035
00036 class CPPScope;
00037 class CPPTemplateParameterList;
00038 class CPPExpression;
00039
00040
00041
00042
00043
00044
00045
00046 class CPPPreprocessor {
00047 public:
00048 CPPPreprocessor();
00049
00050 void set_verbose(int verbose);
00051 int get_verbose() const;
00052
00053 void copy_filepos(const CPPPreprocessor &other);
00054
00055 CPPFile get_file() const;
00056 int get_line_number() const;
00057 int get_col_number() const;
00058
00059 CPPToken get_next_token();
00060 #ifdef CPP_VERBOSE_LEX
00061 CPPToken get_next_token0();
00062 int _token_index;
00063 #endif
00064
00065 void warning(const string &message, int line = 0, int col = 0,
00066 CPPFile file = CPPFile());
00067 void error(const string &message, int line = 0, int col = 0,
00068 CPPFile file = CPPFile());
00069
00070 CPPCommentBlock *get_comment_before(int line, CPPFile file);
00071
00072 int get_warning_count() const;
00073 int get_error_count() const;
00074
00075 typedef map<string, CPPManifest *> Manifests;
00076 Manifests _manifests;
00077
00078 DSearchPath _include_path;
00079 DSearchPath _system_include_path;
00080
00081 CPPComments _comments;
00082
00083 typedef set<CPPFile> ParsedFiles;
00084 ParsedFiles _parsed_files;
00085
00086 typedef set<string> Includes;
00087 Includes _quote_includes;
00088 Includes _angle_includes;
00089
00090
00091
00092
00093
00094
00095 bool _resolve_identifiers;
00096
00097
00098
00099
00100
00101 int _verbose;
00102
00103 protected:
00104 bool init_cpp(const CPPFile &file);
00105 bool init_const_expr(const string &expr);
00106 bool init_type(const string &type);
00107 bool push_file(const CPPFile &file);
00108 bool push_string(const string &input, bool lock_position);
00109
00110 string expand_manifests(const string &input_expr);
00111 CPPExpression *parse_expr(const string &expr, CPPScope *current_scope,
00112 CPPScope *global_scope);
00113
00114 private:
00115 CPPToken internal_get_next_token();
00116 int skip_whitespace(int c);
00117 int skip_comment(int c);
00118 int skip_c_comment(int c);
00119 int skip_cpp_comment(int c);
00120 int process_directive(int c);
00121
00122 int get_preprocessor_command(int c, string &command);
00123 int get_preprocessor_args(int c, string &args);
00124
00125 void handle_define_directive(const string &args, int first_line,
00126 int first_col, const CPPFile &first_file);
00127 void handle_undef_directive(const string &args, int first_line,
00128 int first_col, const CPPFile &first_file);
00129 void handle_ifdef_directive(const string &args, int first_line,
00130 int first_col, const CPPFile &first_file);
00131 void handle_ifndef_directive(const string &args, int first_line,
00132 int first_col, const CPPFile &first_file);
00133 void handle_if_directive(const string &args, int first_line,
00134 int first_col, const CPPFile &first_file);
00135 void handle_include_directive(const string &args, int first_line,
00136 int first_col, const CPPFile &first_file);
00137 void handle_error_directive(const string &args, int first_line,
00138 int first_col, const CPPFile &first_file);
00139
00140 void skip_false_if_block(bool consider_elifs);
00141
00142 CPPToken get_quoted_char(int c);
00143 CPPToken get_quoted_string(int c);
00144 CPPToken get_identifier(int c);
00145 CPPToken expand_manifest(const CPPManifest *manifest);
00146 void extract_manifest_args(const string &name, int num_args,
00147 vector_string &args);
00148 void expand_defined_function(string &expr, size_t q, size_t &p);
00149 void expand_manifest_inline(string &expr, size_t q, size_t &p,
00150 const CPPManifest *manifest);
00151 void extract_manifest_args_inline(const string &name, int num_args,
00152 vector_string &args,
00153 const string &expr, size_t &p);
00154
00155 CPPToken get_number(int c, int c2 = 0);
00156 static int check_keyword(const string &name);
00157 string scan_quoted(int c);
00158
00159 bool should_ignore_manifest(const CPPManifest *manifest) const;
00160 bool should_ignore_preprocessor() const;
00161
00162 int get();
00163 void unget(int c);
00164
00165 CPPTemplateParameterList *
00166 nested_parse_template_instantiation(CPPTemplateScope *scope);
00167 void skip_to_end_nested();
00168 void skip_to_angle_bracket();
00169
00170 class InputFile {
00171 public:
00172 InputFile();
00173 ~InputFile();
00174
00175 bool open(const CPPFile &file);
00176 bool connect_input(const string &input);
00177 int get();
00178
00179 const CPPManifest *_ignore_manifest;
00180 CPPFile _file;
00181 string _input;
00182 istream *_in;
00183 int _line_number;
00184 int _col_number;
00185 bool _lock_position;
00186 int _prev_last_c;
00187 };
00188
00189
00190
00191 typedef list<InputFile> Files;
00192 Files _files;
00193
00194 enum State {
00195 S_normal, S_eof, S_nested, S_end_nested
00196 };
00197 State _state;
00198 int _paren_nesting;
00199 bool _angle_bracket_found;
00200
00201 bool _start_of_line;
00202 int _unget;
00203
00204 int _last_c;
00205 bool _last_cpp_comment;
00206 bool _save_comments;
00207
00208 vector<CPPToken> _saved_tokens;
00209
00210 int _warning_count;
00211 int _error_count;
00212 };
00213
00214 #endif