~ubuntu-branches/ubuntu/maverick/aspectc++/maverick

« back to all changes in this revision

Viewing changes to Puma/gen-release/step1/src/Config.cc

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2008-04-10 17:40:52 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20080410174052-xdnsm7oi8hauyyf1
Tags: 1.0pre4~svn.20080409+dfsg-3
Fix another missing include, this time in Ag++/StdSystem.cc

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include "Puma/StrCol.h"
22
22
#include "Puma/OptsParser.h"
23
23
#include <stdlib.h>
 
24
#include <string.h>
 
25
#include <sstream>
24
26
 
25
27
 
26
28
namespace Puma {
29
31
// print error messages
30
32
 
31
33
#define CONFIG_FILE \
32
 
  _err << sev_error << "in config file `" << file << "': "
 
34
   _err << sev_error << "in config file `" << file << "': "
33
35
 
34
36
#define COMMAND_LINE \
35
 
  _err << sev_error << "at command line: "
 
37
   _err << sev_error << "at command line: "
36
38
 
37
39
#define ERROR_MSG(__mesg) \
38
 
  _err << __mesg << endMessage 
 
40
   _err << __mesg << endMessage 
39
41
 
40
42
#define ERROR__missing(__name) \
41
 
  COMMAND_LINE; \
42
 
  ERROR_MSG ("missing `" << __name << "' for `-A'")
 
43
   COMMAND_LINE; \
 
44
   ERROR_MSG ("missing `" << __name << "' for `-A'")
43
45
 
44
46
#define ERROR__empty(__what,__name) \
45
 
  COMMAND_LINE; \
46
 
  ERROR_MSG ("no " << __what << " given for `" << __name << "'")
 
47
   COMMAND_LINE; \
 
48
   ERROR_MSG ("no " << __what << " given for `" << __name << "'")
47
49
 
48
50
// options:
49
51
// -A<PREDICATE>(<ANSWER>)                      // Assert a preprocessor predicate.
61
63
// --skip-bodies-all                            // skip parsing function bodies
62
64
// --skip-bodies-tpl                            // skip parsing function bodies of templates
63
65
// --skip-bodies-non-prj                        // skip parsing non-project function bodies
 
66
// --skip-bodies-non-prim                       // skip parsing function bodies in non-primary files
64
67
// --match-expr                                 // parse match expressions
65
68
// --vc                                         // support MS Visual C++ extensions
66
69
// --gnu                                        // support gnu extensions
81
84
// --gnu-if-then-expr
82
85
 
83
86
OptsParser::Option pumaOpts[] = {
84
 
  {Config::PRE_ASSERT, 'A', NULL, "Assert a preprocessor predicate", OptsParser::AT_MANDATORY},
85
 
  {Config::PRE_DEFINE, 'D', NULL, "Define a preprocessor macro", OptsParser::AT_MANDATORY},
86
 
  {Config::PRE_UNDEFINE, 'U', NULL, "Undefine a preprocessor macro", OptsParser::AT_MANDATORY},
87
 
  {Config::PRE_LOCK_MACRO, 0, "lock-macro", "Define an unchangeable preprocessor macro", OptsParser::AT_MANDATORY},
88
 
  {Config::PRE_INCLUDE, 'I', NULL, "Add new include path", OptsParser::AT_MANDATORY},
89
 
  {Config::PROJ_PATH, 'p', "path", "Path to project source", OptsParser::AT_MANDATORY},
90
 
  {Config::PROJ_DESTINATION, 'd', "dest", "Path to destination for modified sources", OptsParser::AT_MANDATORY},
91
 
  {Config::SET_SUFFIX, 's', "suffix", "Set file save suffix", OptsParser::AT_MANDATORY},
92
 
  {Config::SET_EXTENSION, 'e', "extension", "Set the extension for source files", OptsParser::AT_MANDATORY},
93
 
  {Config::SET_WRITE_PROTECTED, 'w', "write-protected", "Add a new write protected path", OptsParser::AT_MANDATORY},
94
 
  {Config::CFG_FILE, 0, "config", "Full path to a config file", OptsParser::AT_MANDATORY},
95
 
  {Config::SET_OPTION, 0, "save-overwrite", "Overwrite old files", OptsParser::AT_NONE},
96
 
  {Config::SET_OPTION, 0, "rename-old", "Rename old files", OptsParser::AT_NONE},
97
 
  {Config::SET_OPTION, 0, "new-suffix", "Append new suffix on old files", OptsParser::AT_NONE},
98
 
  {Config::SET_OPTION, 0, "lang-c", "Input language is C", OptsParser::AT_NONE},
99
 
  {Config::SET_OPTION, 0, "lang-ec++", "Input language is EC++", OptsParser::AT_NONE},
100
 
  {Config::SET_OPTION, 0, "lang-c++", "Input language is C++", OptsParser::AT_NONE},
101
 
  {Config::SET_OPTION, 0, "lang-ac++", "Input language is AC++", OptsParser::AT_NONE},
102
 
  {Config::SET_OPTION, 0, "skip-bodies-all", "Skip parsing function bodies", OptsParser::AT_NONE},
103
 
  {Config::SET_OPTION, 0, "skip-bodies-tpl", "Skip parsing function bodies of templates", OptsParser::AT_NONE},
104
 
  {Config::SET_OPTION, 0, "skip-bodies-non-prj", "Skip parsing non-project function bodies", OptsParser::AT_NONE},
105
 
  {Config::SET_OPTION, 0, "real-instances", "Do real template instantiation", OptsParser::AT_NONE},
106
 
  {Config::SET_OPTION, 0, "match-expr", "Parse match expression", OptsParser::AT_NONE},
107
 
  {Config::SET_OPTION, 0, "gnu-nested-fct", "", OptsParser::AT_NONE},
108
 
  {Config::SET_OPTION, 0, "gnu-condition-scope", "", OptsParser::AT_NONE},
109
 
  {Config::SET_OPTION, 0, "gnu-param-decl", "", OptsParser::AT_NONE},
110
 
  {Config::SET_OPTION, 0, "gnu-fct-decl", "", OptsParser::AT_NONE},
111
 
  {Config::SET_OPTION, 0, "gnu-param-scope", "", OptsParser::AT_NONE},
112
 
  {Config::SET_OPTION, 0, "gnu-default-args", "", OptsParser::AT_NONE},
113
 
  {Config::SET_OPTION, 0, "gnu-extended-asm", "", OptsParser::AT_NONE},
114
 
  {Config::SET_OPTION, 0, "gnu-extended-expr", "", OptsParser::AT_NONE},
115
 
  {Config::SET_OPTION, 0, "gnu-long-long", "", OptsParser::AT_NONE},
116
 
  {Config::SET_OPTION, 0, "gnu-name-scope", "", OptsParser::AT_NONE},
117
 
  {Config::SET_OPTION, 0, "gnu-implicit-int", "", OptsParser::AT_NONE},
118
 
  {Config::SET_OPTION, 0, "gnu-fct-attribute", "", OptsParser::AT_NONE},
119
 
  {Config::SET_OPTION, 0, "gnu-if-then-expr", "", OptsParser::AT_NONE},
120
 
  {Config::SET_OPTION, 0, "gnu-std-hack", "", OptsParser::AT_NONE},
121
 
  {Config::SET_OPTION, 0, "gnu", "Support gnu extensions", OptsParser::AT_NONE},
122
 
  {Config::SET_OPTION, 0, "gnu-2.95", "Support gnu extensions for g++ 2.95", OptsParser::AT_NONE},
123
 
  {Config::SET_OPTION, 0, "vc", "Support Visual C++ extensions", OptsParser::AT_NONE},
124
 
  {Config::SET_OPTION_ARG, 0, "import-handler", "Handler for #import directives", OptsParser::AT_MANDATORY},
125
 
  {Config::SET_OPTION_ARG, 0, "include", "Always include file", OptsParser::AT_MANDATORY},
126
 
  {Config::SET_OPTION_ARG, 0, "size-type", "Internal type for size_t", OptsParser::AT_MANDATORY},
127
 
  {Config::SET_OPTION_ARG, 0, "ptrdiff-type", "Internal type for ptrdiff_t", OptsParser::AT_MANDATORY},
128
 
  {Config::SET_OPTION_ARG, 0, "inhibit-macro", "Prevent a preprocessor macro for being defined", OptsParser::AT_MANDATORY},
129
 
  {0, 0, 0, 0, OptsParser::AT_NONE}
 
87
   {Config::PRE_ASSERT, "A", NULL, "Assert a preprocessor predicate", OptsParser::AT_MANDATORY},
 
88
   {Config::PRE_DEFINE, "D", NULL, "Define a preprocessor macro", OptsParser::AT_MANDATORY},
 
89
   {Config::PRE_UNDEFINE, "U", NULL, "Undefine a preprocessor macro", OptsParser::AT_MANDATORY},
 
90
   {Config::PRE_LOCK_MACRO, 0, "lock-macro", "Define an unchangeable preprocessor macro", OptsParser::AT_MANDATORY},
 
91
   {Config::PRE_INCLUDE, "I", NULL, "Add new include path", OptsParser::AT_MANDATORY},
 
92
   {Config::PROJ_PATH, "p", "path", "Path to project source", OptsParser::AT_MANDATORY},
 
93
   {Config::PROJ_DESTINATION, "d", "dest", "Path to destination for modified sources", OptsParser::AT_MANDATORY},
 
94
   {Config::SET_SUFFIX, "s", "suffix", "Set file save suffix", OptsParser::AT_MANDATORY},
 
95
   {Config::SET_EXTENSION, "e", "extension", "Set the extension for source files", OptsParser::AT_MANDATORY},
 
96
   {Config::SET_WRITE_PROTECTED, "w", "write-protected", "Add a new write protected path", OptsParser::AT_MANDATORY},
 
97
   {Config::CFG_FILE, NULL, "config", "Full path to a config file", OptsParser::AT_MANDATORY},
 
98
   {Config::SET_OPTION, NULL, "save-overwrite", "Overwrite old files", OptsParser::AT_NONE},
 
99
   {Config::SET_OPTION, NULL, "rename-old", "Rename old files", OptsParser::AT_NONE},
 
100
   {Config::SET_OPTION, NULL, "new-suffix", "Append new suffix on old files", OptsParser::AT_NONE},
 
101
   {Config::SET_OPTION, NULL, "lang-c", "Input language is C", OptsParser::AT_NONE},
 
102
   {Config::SET_OPTION, NULL, "lang-ec++", "Input language is EC++", OptsParser::AT_NONE},
 
103
   {Config::SET_OPTION, NULL, "lang-c++", "Input language is C++", OptsParser::AT_NONE},
 
104
   {Config::SET_OPTION, NULL, "lang-ac++", "Input language is AC++", OptsParser::AT_NONE},
 
105
   {Config::SET_OPTION, NULL, "skip-bodies-all", "Skip parsing function bodies", OptsParser::AT_NONE},
 
106
   {Config::SET_OPTION, NULL, "skip-bodies-tpl", "Skip parsing function bodies of templates", OptsParser::AT_NONE},
 
107
   {Config::SET_OPTION, NULL, "skip-bodies-non-prj", "Skip parsing non-project function bodies", OptsParser::AT_NONE},
 
108
   {Config::SET_OPTION, NULL, "skip-bodies-non-prim", "Skip parsing function bodies in non-primary files", OptsParser::AT_NONE},
 
109
   {Config::SET_OPTION, NULL, "real-instances", "Do real template instantiation", OptsParser::AT_NONE},
 
110
   {Config::SET_OPTION, NULL, "match-expr", "Parse match expression", OptsParser::AT_NONE},
 
111
   {Config::SET_OPTION, NULL, "gnu-nested-fct", "", OptsParser::AT_NONE},
 
112
   {Config::SET_OPTION, NULL, "gnu-condition-scope", "", OptsParser::AT_NONE},
 
113
   {Config::SET_OPTION, NULL, "gnu-param-decl", "", OptsParser::AT_NONE},
 
114
   {Config::SET_OPTION, NULL, "gnu-fct-decl", "", OptsParser::AT_NONE},
 
115
   {Config::SET_OPTION, NULL, "gnu-param-scope", "", OptsParser::AT_NONE},
 
116
   {Config::SET_OPTION, NULL, "gnu-default-args", "", OptsParser::AT_NONE},
 
117
   {Config::SET_OPTION, NULL, "gnu-extended-asm", "", OptsParser::AT_NONE},
 
118
   {Config::SET_OPTION, NULL, "gnu-extended-expr", "", OptsParser::AT_NONE},
 
119
   {Config::SET_OPTION, NULL, "gnu-long-long", "", OptsParser::AT_NONE},
 
120
   {Config::SET_OPTION, NULL, "gnu-name-scope", "", OptsParser::AT_NONE},
 
121
   {Config::SET_OPTION, NULL, "gnu-implicit-int", "", OptsParser::AT_NONE},
 
122
   {Config::SET_OPTION, NULL, "gnu-fct-attribute", "", OptsParser::AT_NONE},
 
123
   {Config::SET_OPTION, NULL, "gnu-if-then-expr", "", OptsParser::AT_NONE},
 
124
   {Config::SET_OPTION, NULL, "gnu-std-hack", "", OptsParser::AT_NONE},
 
125
   {Config::SET_OPTION, NULL, "gnu", "Support gnu extensions", OptsParser::AT_NONE},
 
126
   {Config::SET_OPTION, NULL, "gnu-2.95", "Support gnu extensions for g++ 2.95", OptsParser::AT_NONE},
 
127
   {Config::SET_OPTION, NULL, "vc", "Support Visual C++ extensions", OptsParser::AT_NONE},
 
128
   {Config::SET_OPTION_ARG, NULL, "import-handler", "Handler for #import directives", OptsParser::AT_MANDATORY},
 
129
   {Config::SET_OPTION_ARG, NULL, "include", "Always include file", OptsParser::AT_MANDATORY},
 
130
   {Config::SET_OPTION_ARG, NULL, "size-type", "Internal type for size_t", OptsParser::AT_MANDATORY},
 
131
   {Config::SET_OPTION_ARG, NULL, "ptrdiff-type", "Internal type for ptrdiff_t", OptsParser::AT_MANDATORY},
 
132
   {Config::SET_OPTION_ARG, NULL, "inhibit-macro", "Prevent a preprocessor macro for being defined", OptsParser::AT_MANDATORY},
 
133
   {0, 0, 0, 0, OptsParser::AT_NONE}
130
134
};
131
135
 
132
136
 
165
169
 
166
170
  // process the given options
167
171
  while (optp.getOption () != OptsParser::FINISH) {
168
 
    Process (optp);
 
172
    Process (optp, true);
169
173
  }
170
174
}
171
175
 
193
197
}
194
198
 
195
199
 
196
 
bool Config::Process (OptsParser &parser) {
 
200
bool Config::Process (OptsParser &parser, bool unescape) {
197
201
  bool res=true;
198
202
  string arg;
 
203
  if (unescape) {
 
204
    arg = Unescape (parser.getArgument ());
 
205
  } else {
 
206
    arg = parser.getArgument ();
 
207
  }
199
208
        
200
209
  switch (parser.getResult ()) {
201
210
    case PRE_ASSERT:
202
 
      ProcessAssert (parser.getArgument ());
 
211
      ProcessAssert (arg);
203
212
      break;
204
213
    case PRE_DEFINE:
205
 
      ProcessDefine (parser.getArgument ());
 
214
      ProcessDefine (arg);
206
215
      break;
207
216
    case PRE_LOCK_MACRO:
208
 
      ProcessLockMacro (parser.getArgument ());
 
217
      ProcessLockMacro (arg);
209
218
      break;
210
219
    case PRE_UNDEFINE:
211
 
      ProcessUndefine (parser.getArgument ());
 
220
      ProcessUndefine (arg);
212
221
      break;
213
222
    case PRE_INCLUDE:
214
 
      ProcessPathArgument ("-I", parser.getArgument ());
 
223
      ProcessPathArgument ("-I", arg);
215
224
      break;
216
225
    case PROJ_PATH:
217
 
      ProcessPathArgument ("-p", parser.getArgument ());
 
226
      ProcessPathArgument ("-p", arg);
218
227
      break;
219
228
    case PROJ_DESTINATION:
220
 
      ProcessPathArgument ("-d", parser.getArgument ());                        
 
229
      ProcessPathArgument ("-d", arg);                        
221
230
      break;
222
231
    case CFG_FILE:
223
 
      ProcessConfigFile ("--config", parser.getArgument ());
 
232
      ProcessConfigFile ("--config", arg);
224
233
      break;
225
234
    case SET_SUFFIX:
226
 
      ProcessArgument ("-s", parser.getArgument ());
 
235
      ProcessArgument ("-s", arg);
227
236
      break;
228
237
    case SET_EXTENSION:
229
 
      ProcessArgument ("-e", parser.getArgument ());
 
238
      ProcessArgument ("-e", arg);
230
239
      break;
231
240
    case SET_WRITE_PROTECTED:
232
 
      ProcessArgument ("-w", parser.getArgument ());
 
241
      ProcessArgument ("-w", arg);
233
242
      break;
234
243
    case SET_OPTION:
235
244
      //cout << "option: " << parser.getOptionName() << endl;
237
246
      break;
238
247
    case SET_OPTION_ARG:
239
248
      //cout << "option: " << parser.getOptionName() << endl;
240
 
      Add (parser.getOptionName ().c_str (), parser.getArgument ().c_str ());
 
249
      Add (parser.getOptionName ().c_str (), arg.c_str ());
241
250
      break;
242
251
    case OptsParser::UNKNOWN:
243
252
    case OptsParser::NOOPTION:
436
445
}
437
446
 
438
447
 
 
448
string Config::Unescape (const string& arg) {
 
449
  // Replacement rules:
 
450
  // 1. '\' '"' => '"'
 
451
  // 2. '\' '\' => '\' 
 
452
  // 3. '"'     => ''
 
453
  ostringstream res;
 
454
  bool escaped = false;
 
455
  for (string::size_type i = 0; i < arg.length(); i++) {
 
456
    char c = arg[i];
 
457
    if (c == '"') {
 
458
      if (escaped) {
 
459
        escaped = false;
 
460
        res << c;
 
461
      } 
 
462
    } else if (c == '\\') {
 
463
      if (escaped) {
 
464
        escaped = false;
 
465
        res << c;
 
466
      } else {
 
467
        escaped = true;
 
468
      }
 
469
    } else {
 
470
      if (escaped) {
 
471
        escaped = false;
 
472
        res << "\\";
 
473
      }
 
474
      res << c;
 
475
    }
 
476
  }
 
477
  return res.str();
 
478
}
 
479
 
 
480
 
439
481
} // namespace Puma