~ubuntu-branches/ubuntu/quantal/aspectc++/quantal

« back to all changes in this revision

Viewing changes to Ag++/AGxxConfig.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:
34
34
 
35
35
 
36
36
string AGxxConfig::_gcc_option_arg[] = {
37
 
        "-aux-info","-print-prog-name=",
38
 
        "-idirafter", "-include", "-imacros", "-iprefix",
39
 
        "-iwithprefix", "-iwithprefixbefore", "-isystem",
40
 
        "-B", "-l", "-I", "-L", "-specs=",
41
 
        "-MF", "-MT", "-MQ",
42
 
        "-x",
43
 
        "--param",
44
 
        "-Xlinker", "-u",
45
 
        "-V", "-b",
46
 
        "-G",
47
 
        ""/* terminate with empty string */
 
37
   "-aux-info","-print-prog-name=",
 
38
   "-idirafter", "-imacros", "-iprefix",
 
39
   "-iwithprefix", "-iwithprefixbefore", "-isystem",
 
40
   "-B", "-l", "-I", "-L", "-specs=",
 
41
   "-MF", "-MT", "-MQ",
 
42
   "-x",
 
43
   "--param",
 
44
   "-Xlinker", "-u",
 
45
   "-V", "-b",
 
46
   "-G",
 
47
   ""/* terminate with empty string */
48
48
};
49
49
 
50
50
// options for AC++ Compiler
51
51
static OptsParser::Option options[] = {
52
 
        { AGxxConfig::AGOPT_GEN_CFG, 0, "gen_config",
53
 
                "\t" "Only generate Puma configuration file", OptsParser::AT_NONE },
54
 
        { AGxxConfig::AGOPT_WEAVE, 0, "weave_only",
55
 
                "\t" "Weave only", OptsParser::AT_NONE },
56
 
        { AGxxConfig::AGOPT_COMPILE_ONLY, 'c', NULL,
57
 
                "\t\t" "Compile only", OptsParser::AT_NONE },
58
 
        { AGxxConfig::AGOPT_KEEP_ACC,0, "keep_acc",
59
 
                "\t" "Keep weaved source code files", OptsParser::AT_NONE },
60
 
        { AGxxConfig::AGOPT_CC, 0, "c_compiler",
61
 
                "Path to C++ compiler", OptsParser::AT_MANDATORY },
62
 
        { AGxxConfig::AGOPT_ACC, 0, "ac_compiler",
63
 
                "Path to AspectC++ compiler", OptsParser::AT_MANDATORY },
64
 
  { AGxxConfig::AGOPT_OUTPUT, 'o', "output",
65
 
   "\t" "Name of the output file", OptsParser::AT_MANDATORY },
66
 
        { AGxxConfig::AGOPT_CONFIG_COMMAND,0, "config_command",
67
 
                "Command which prints information about compiler", OptsParser::AT_MANDATORY },
68
 
        { AGxxConfig::AGOPT_X_COMPILER,0, "Xcompiler",
69
 
                "\tIn case of doupt account following options as g++ options", OptsParser::AT_NONE },
70
 
        { AGxxConfig::AGOPT_X_WEAVER,0, "Xweaver",
71
 
                "\t\tIn case of doupt account following options as ac++ options", OptsParser::AT_NONE },
72
 
        { AGxxConfig::AGOPT_HELP, 'h', "help",
73
 
                "\t\t" "Print this help meassage", OptsParser::AT_NONE },
74
 
        { AGxxConfig::AGOPT_VERSION, 0, "version",
75
 
                "\t" "\t" "Version information", OptsParser::AT_NONE },
76
 
        { AGxxConfig::AGOPT_VERBOSE, 'v', "verbose",
77
 
                "Level of verbosity (0-9)", OptsParser::AT_OPTIONAL },
78
 
        { AGxxConfig::ACOPT_INCLUDE_FILES, 'i', "include_files",
79
 
                "Generate manipulated header files", OptsParser::AT_NONE },
80
 
        { AGxxConfig::ACOPT_ASPECT_HEADER, 'a', "aspect_header",
81
 
                "Name of aspect header file or '0'", OptsParser::AT_MANDATORY }, 
82
 
        { AGxxConfig::ACOPT, 'r', "repository",
83
 
                "Name of the project repository", OptsParser::AT_MANDATORY }, 
84
 
        { AGxxConfig::ACOPT, 0, "problem_local_class",
85
 
                "Back-end does not support local classes correctly", OptsParser::AT_NONE }, 
86
 
        { AGxxConfig::ACOPT, 0, "no_problem_local_class",
87
 
                "Back-end supports local classes correctly", OptsParser::AT_NONE },
88
 
        { AGxxConfig::ACOPT, 0, "problem_spec_scope",
89
 
                "Back-end does not support template specialization in non-namespace",OptsParser::AT_NONE }, 
90
 
        { AGxxConfig::ACOPT, 0, "no_problem_spec_scope",
91
 
                "Back-end supports template specialization in non-namespace scope",OptsParser::AT_NONE }, 
92
 
  { AGxxConfig::ACOPT, 0, "warn_deprecated",
93
 
    "\t" "Warn if deprecated syntax is used", OptsParser::AT_NONE },
94
 
  { AGxxConfig::ACOPT, 0, "no_warn_deprecated",
95
 
    "Don't warn if deprecated syntax is used", OptsParser::AT_NONE },
96
 
  { AGxxConfig::ACOPT, 0, "warn_macro",
97
 
    "\t" "Warn if a macro transformation had to be ignored", OptsParser::AT_NONE },
98
 
  { AGxxConfig::ACOPT, 0, "no_warn_macro",
99
 
    "\t" "Don't warn if a macro transformation had to be ignored", OptsParser::AT_NONE },
100
 
        { AGxxConfig::ACOPT, 0,"no_line",
101
 
                "\t\t" "Don't generate #line directives",OptsParser::AT_NONE },
102
 
        { AGxxConfig::ACOPT, 0,"real-instances",
103
 
                "\t" "Perform full template analysis",OptsParser::AT_NONE },
104
 
        { AGxxConfig::ACOPT_PROJ_PATH, 'p', "path", 
105
 
                "\t" "Path to project source", OptsParser::AT_MANDATORY},
106
 
        { AGxxConfig::ACOPT_PROJ_DESTINATION, 'd', "dest", 
107
 
                "\t" "Path to destination for modified include files", OptsParser::AT_MANDATORY},
108
 
        { AGxxConfig::ACOPT_CFG_FILE, 0, "config", 
109
 
                "\t" "Full path to a config file", OptsParser::AT_MANDATORY}, 
110
 
        { AGxxConfig::ACOPT_PRE_INCLUDE, 'I', NULL, 
111
 
                "\t\t" "Add new include path", OptsParser::AT_MANDATORY},
112
 
        { AGxxConfig::ACOPT_PRE_DEFINE, 'D', NULL, 
113
 
                "\t\t" "Define a preprocessor macro", OptsParser::AT_MANDATORY},
114
 
        { AGxxConfig::ACOPT_PRE_UNDEFINE, 'U', NULL, 
115
 
                "\t\t" "Undefine a preprocessor macro", OptsParser::AT_MANDATORY},
116
 
        { AGxxConfig::ACOPT_ALWAYS_INCLUDE, 0, "include", 
117
 
                "\t" "Always include file", OptsParser::AT_MANDATORY},
118
 
  { AGxxConfig::ACOPT, 'k', "keywords",
119
 
   "\t" "Allow AspectC++ keywords in normal project files", OptsParser::AT_NONE},
120
 
        { 0, 0, 0, 0, OptsParser::AT_NONE}
 
52
   { AGxxConfig::AGOPT_GEN_CFG, NULL, "gen_config",
 
53
      "\t" "Only generate Puma configuration file", OptsParser::AT_NONE },
 
54
   { AGxxConfig::AGOPT_WEAVE_ONLY, NULL, "weave_only",
 
55
      "\t" "Weave only", OptsParser::AT_NONE },
 
56
   { AGxxConfig::AGOPT_COMPILE_ONLY, "c", NULL,
 
57
      "\t\t" "Compile only", OptsParser::AT_NONE },
 
58
   { AGxxConfig::AGOPT_KEEP_WOVEN,NULL, "keep_woven",
 
59
      "\t" "Keep woven source code files", OptsParser::AT_NONE },
 
60
   { AGxxConfig::AGOPT_KEEP_WOVEN,NULL, "keep_acc",
 
61
      "\t" "Deprecated. Use keep_woven instead", OptsParser::AT_NONE },
 
62
   { AGxxConfig::AGOPT_CC, NULL, "c_compiler",
 
63
      "Path to C++ compiler", OptsParser::AT_MANDATORY },
 
64
   { AGxxConfig::AGOPT_ACC, NULL, "ac_compiler",
 
65
      "Path to AspectC++ compiler", OptsParser::AT_MANDATORY },
 
66
   { AGxxConfig::AGOPT_OUTPUT, "o", "output",
 
67
      "\t" "Name of the output file", OptsParser::AT_MANDATORY },
 
68
   { AGxxConfig::AGOPT_CONFIG_COMMAND,NULL, "config_command",
 
69
      "Command which prints information about compiler", OptsParser::AT_MANDATORY },
 
70
   { AGxxConfig::AGOPT_X_COMPILER,NULL, "Xcompiler",
 
71
      "\tIn case of doubt account following options as g++ options", OptsParser::AT_NONE },
 
72
   { AGxxConfig::AGOPT_X_WEAVER,NULL, "Xweaver",
 
73
      "\t\tIn case of doubt account following options as ac++ options", OptsParser::AT_NONE },
 
74
   { AGxxConfig::AGOPT_HELP, "h", "help",
 
75
      "\t\t" "Print this help meassage", OptsParser::AT_NONE },
 
76
   { AGxxConfig::AGOPT_VERSION, NULL, "version",
 
77
      "\t" "\t" "Version information", OptsParser::AT_NONE },
 
78
   { AGxxConfig::AGOPT_VERBOSE, "v", "verbose",
 
79
      "Level of verbosity (0-9)", OptsParser::AT_OPTIONAL },
 
80
   { AGxxConfig::ACOPT_INCLUDE_FILES, "i", "include_files",
 
81
      "Generate manipulated header files", OptsParser::AT_NONE },
 
82
   { AGxxConfig::ACOPT_ASPECT_HEADER, "a", "aspect_header",
 
83
      "Name of aspect header file or '0'", OptsParser::AT_MANDATORY }, 
 
84
   { AGxxConfig::ACOPT, "r", "repository",
 
85
      "Name of the project repository", OptsParser::AT_MANDATORY }, 
 
86
   { AGxxConfig::ACOPT, NULL, "problem_local_class",
 
87
      "Back-end does not support local classes correctly", OptsParser::AT_NONE }, 
 
88
   { AGxxConfig::ACOPT, NULL, "no_problem_local_class",
 
89
      "Back-end supports local classes correctly", OptsParser::AT_NONE },
 
90
   { AGxxConfig::ACOPT, NULL, "problem_spec_scope",
 
91
      "Back-end does not support template specialization in non-namespace",OptsParser::AT_NONE }, 
 
92
   { AGxxConfig::ACOPT, NULL, "no_problem_spec_scope",
 
93
      "Back-end supports template specialization in non-namespace scope",OptsParser::AT_NONE }, 
 
94
   { AGxxConfig::ACOPT, NULL, "problem_force_inline",
 
95
      "Back-end does not support forced inlining correctly", OptsParser::AT_NONE }, 
 
96
   { AGxxConfig::ACOPT, NULL, "no_problem_force_inline",
 
97
      "Back-end supports forced inlining correctly", OptsParser::AT_NONE }, 
 
98
   { AGxxConfig::ACOPT, NULL, "warn_deprecated",
 
99
      "\t" "Warn if deprecated syntax is used", OptsParser::AT_NONE },
 
100
   { AGxxConfig::ACOPT, NULL, "no_warn_deprecated",
 
101
      "Don't warn if deprecated syntax is used", OptsParser::AT_NONE },
 
102
   { AGxxConfig::ACOPT, NULL, "warn_macro",
 
103
      "\t" "Warn if a macro transformation had to be ignored", OptsParser::AT_NONE },
 
104
   { AGxxConfig::ACOPT, NULL, "no_warn_macro",
 
105
      "\t" "Don't warn if a macro transformation had to be ignored", OptsParser::AT_NONE },
 
106
   { AGxxConfig::ACOPT, NULL,"no_line",
 
107
      "\t\t" "Don't generate #line directives",OptsParser::AT_NONE },
 
108
   { AGxxConfig::ACOPT, NULL,"real-instances",
 
109
      "\t" "Perform full template analysis",OptsParser::AT_NONE },
 
110
   { AGxxConfig::ACOPT_PROJ_PATH, "p", "path", 
 
111
      "\t" "Path to project source", OptsParser::AT_MANDATORY},
 
112
   { AGxxConfig::ACOPT_PROJ_DESTINATION, "d", "dest", 
 
113
      "\t" "Path to destination for modified include files", OptsParser::AT_MANDATORY},
 
114
   { AGxxConfig::ACOPT_CFG_FILE, NULL, "config", 
 
115
      "\t" "Full path to a config file", OptsParser::AT_MANDATORY}, 
 
116
   { AGxxConfig::ACOPT_PRE_INCLUDE, "I", NULL, 
 
117
      "\t\t" "Add new include path", OptsParser::AT_MANDATORY},
 
118
   { AGxxConfig::ACOPT_PRE_DEFINE, "D", NULL, 
 
119
      "\t\t" "Define a preprocessor macro", OptsParser::AT_MANDATORY},
 
120
   { AGxxConfig::ACOPT_PRE_UNDEFINE, "U", NULL, 
 
121
      "\t\t" "Undefine a preprocessor macro", OptsParser::AT_MANDATORY},
 
122
   { AGxxConfig::ACOPT_ALWAYS_INCLUDE, "include", "include", 
 
123
      "Always include file", OptsParser::AT_MANDATORY},
 
124
   { AGxxConfig::ACOPT, "k", "keywords",
 
125
      "\t" "Allow AspectC++ keywords in normal project files", OptsParser::AT_NONE},
 
126
   { AGxxConfig::ACOPT, NULL, "dynamic",
 
127
      "\t\t" "Prepare generated code for dynamic weaving", OptsParser::AT_NONE },
 
128
   { 0, 0, 0, 0, OptsParser::AT_NONE}
121
129
};
122
130
 
123
131
void AGxxConfig::usage() const
124
 
 {
 
132
{
125
133
   _err << "usage:  ag++ [options] [file...]" << endMessage
126
 
        << "   options are ..." << endMessage;
 
134
      << "   options are ..." << endMessage;
127
135
   for (int i = 0; options[i].number > 0; i++) {
128
 
     _err << "     ";
129
 
     if (options[i].key)  _err << "-" << options[i].key;
130
 
     if (options[i].key && options[i].name) _err << "|";
131
 
     if (options[i].name) _err << "--" << options[i].name;
132
 
     if (options[i].args) _err << " <arg>";
133
 
     if (options[i].desc) _err << " \t" << options[i].desc;
134
 
     _err << endMessage;
135
 
   }
136
 
 }
137
 
 
138
 
bool AGxxConfig::analyzeGccOpt(OptsParser &op){
139
 
        
140
 
        // option which should be analyzed
141
 
        string opt=op.getOptionName()+op.getArgument();
142
 
        
143
 
        // argument for this option
144
 
        string arg("");
145
 
        
146
 
        //check for -M/-MM option for generating dependency information
147
 
        if (opt.compare("-M") == 0 || opt.compare("-MM") == 0 ){
148
 
                _gen_pumaconfig=false;
149
 
                _weave=false;
150
 
                _link=false;
151
 
                _make_dep=true;
152
 
                _optvec.pushback(opt,OptionItem::OPT_GCC);
153
 
                return true;
154
 
        }
155
 
 
156
 
        // check if option gets an argument
157
 
        for(string* test_str=_gcc_option_arg;test_str->empty()==false;++test_str){
158
 
                if( opt.compare(0,test_str->length(),*test_str) == 0){
159
 
                        
160
 
                        // ok, it gets an argument
161
 
                        // check if the argument is appended to the option name
162
 
                        if ( opt.length() > test_str->length() ){
163
 
                                // extract the argument out of the option name
164
 
                                arg="\""+opt.substr(test_str->length())+"\"";
165
 
                                opt=opt.substr(0,test_str->length());
166
 
                        }else{
167
 
                                // check if there exist another option
168
 
                                if(op.getOption () != OptsParser::FINISH) {
169
 
                                        // check if the next option is an argument (aka NOOPTION)
170
 
                                        if(op.getResult() == OptsParser::NOOPTION){
171
 
                                                arg="\""+op.getArgument()+"\"";
172
 
                                        }else{
173
 
                                                // the next option is NOT an argument 
174
 
                                                _err << sev_error << "G++ Option reqires argument: " ;
175
 
                                                _err <<"'"<<opt.c_str() <<"'"<< endMessage;
176
 
                                                return false;
177
 
                                        }
178
 
                                }else{
179
 
                                        // there is no option anymore
180
 
                                        _err << sev_error << "G++ Option reqires argument: " ;
181
 
                                        _err <<"'"<< opt.c_str() <<"'"<< endMessage;
182
 
                                        return false;
183
 
                                }
184
 
                        }
185
 
                }
186
 
        }
187
 
        _optvec.pushback(opt,arg,OptionItem::OPT_GCC);
188
 
        return true;
189
 
 
190
 
}
191
 
                                        
192
 
 
193
 
 
194
 
bool AGxxConfig::analyze(){
195
 
 
196
 
        
197
 
        // setup default values
198
 
        _gen_pumaconfig=true;
199
 
        _weave=false;
200
 
        _compile=true;
201
 
        _link=true;
202
 
        _make_dep=false;
203
 
        _cc_bin="g++";
204
 
        _verbose =0;
205
 
        _nr_files =0;
206
 
        _keep_acc=false;
207
 
        _gen_includes=false;
208
 
        _x_compiler=false;
209
 
        
210
 
 
211
 
                
212
 
        OptsParser op(_argc,_argv,options);
213
 
 
214
 
        // extract options/filenames out of command line arguments
215
 
        while (op.getOption () != OptsParser::FINISH) {
216
 
                // first parse options which do not interfere with g++
217
 
                // options
218
 
 
219
 
                switch (op.getResult ()) {
220
 
                        
221
 
                        case AGOPT_OUTPUT :
222
 
                                _output_file=op.getArgument();
223
 
                                // we can not push '-o <filename>'
224
 
                                // into the options vector as afterwards the generation of the
225
 
                                // puma.config file fails
226
 
                                continue;
227
 
                        
228
 
                        case AGOPT_COMPILE_ONLY :
229
 
                                _weave=true;
230
 
                                _link=false;
231
 
                                _optvec.pushback("-c",OptionItem::OPT_GCC);
232
 
                                continue;
233
 
                        
234
 
                        case AGOPT_X_COMPILER :
235
 
                                _x_compiler=true;
236
 
                                continue;
237
 
                        
238
 
                        case AGOPT_X_WEAVER :
239
 
                                _x_compiler=false;
240
 
                                continue;
241
 
                        
242
 
                        case ACOPT_CFG_FILE :
243
 
                                _puma_config=op.getArgument();
244
 
                                continue;
245
 
                                
246
 
                        case ACOPT_PRE_DEFINE :
247
 
                                _optvec.pushback("-D","\""+op.getArgument()+"\"",OptionItem::OPT_ACC|OptionItem::OPT_GCC);
248
 
                                continue;
249
 
 
250
 
                        case ACOPT_PRE_UNDEFINE :
251
 
                                _optvec.pushback("-U",op.getArgument(),OptionItem::OPT_ACC|OptionItem::OPT_GCC);
252
 
                                continue;
253
 
                        
254
 
                        case ACOPT_PRE_INCLUDE :
255
 
                                _optvec.pushback("-I","\""+op.getArgument()+"\"",OptionItem::OPT_ACC|OptionItem::OPT_GCC);
256
 
                                continue;
257
 
                        
258
 
                                
259
 
                        // command line arguments which are not accepted as options
260
 
                        // are recognized as filenames
261
 
                        case OptsParser::NOOPTION :
262
 
                                ++_nr_files;
263
 
                                // if file is a c++ file weave it first.
264
 
                                if (regex::regExMatch("^.*\\.((C)|(c)|(cc)|(cp)|(cpp)|(cxx)|(c\\+\\+))$",op.getArgument().c_str()) ){
265
 
                                        if (!_make_dep){
266
 
                                                _weave=true;
267
 
                                        }
268
 
                                        _optvec.pushback(op.getArgument(),OptionItem::OPT_FILE_ACC);
269
 
                                        
270
 
                                        // when calling we have to pass the original path of this 
271
 
                                        // source dir as include path, as the '.acc' file to be 
272
 
                                        // compiled will probably not be generated in the same
273
 
                                        // directory
274
 
                                        string tmpStr=op.getArgument();
275
 
                                        file::stripFilename(tmpStr);
276
 
                                        if (tmpStr.empty()){
277
 
                                                tmpStr =".";
278
 
                                        }
279
 
                                        _optvec.pushback("-I","\""+tmpStr+"\"",OptionItem::OPT_GCC);
280
 
                                }else{
281
 
                                        _optvec.pushback(op.getArgument(),OptionItem::OPT_FILE_GCC);
282
 
                                }
283
 
                                continue;
284
 
 
285
 
                }
286
 
                
287
 
                // if _x_compiler is set to 'true' interprete
288
 
                // options that are not handled within this
289
 
                // 'switch-case' statement as gcc options.
290
 
                if (_x_compiler == true){
291
 
                        if (analyzeGccOpt(op)==false){
292
 
                                return false;
293
 
                        }
294
 
                        continue;
295
 
                }
296
 
 
297
 
                
298
 
                // check if option is manually assigned to the compiler
299
 
                        
300
 
                switch (op.getResult ()) {
301
 
                
302
 
                        case AGOPT_HELP :
303
 
                                usage();
304
 
                                return false;
305
 
                        
306
 
                        case AGOPT_VERSION:
307
 
                                cout << "ag++ " << _VERSION <<"  built: "<<__DATE__<< endl;
308
 
                                return false;
309
 
                        
310
 
                        
311
 
                        case AGOPT_GEN_CFG :
312
 
                                _compile=false;
313
 
                                _link=false;
314
 
                                break;
315
 
                        
316
 
                        case AGOPT_WEAVE :
317
 
                                _weave=true;
318
 
                                _compile=false;
319
 
                                _link=false;
320
 
                                break;
321
 
                        
322
 
                                
323
 
                        case AGOPT_ACC :
324
 
                                _acc_bin=op.getArgument();
325
 
                                break;
326
 
                        
327
 
                        case AGOPT_CC :
328
 
                                _cc_bin=op.getArgument();
329
 
                                break;
330
 
                        
331
 
                        case AGOPT_KEEP_ACC :
332
 
                                _keep_acc=true;
333
 
                                break;
334
 
                                
335
 
                        case AGOPT_CONFIG_COMMAND :
336
 
                                _config_command=op.getArgument();
337
 
                                break;
338
 
                
339
 
                        
340
 
                        case ACOPT: // default handling for Aspect C++ options
341
 
                                _optvec.pushback(op.getOptionName(),op.getArgument(),OptionItem::OPT_ACC);
342
 
                                break;
343
 
                                
344
 
                        case ACOPT_INCLUDE_FILES :
345
 
                                _gen_includes=true;
346
 
                                _weave=true;
347
 
                                _compile=false;
348
 
                                _link=false;
349
 
                                break;
350
 
                        
351
 
                        case AGOPT_VERBOSE :
352
 
                                _optvec.pushback("-v",op.getArgument(),OptionItem::OPT_ACC);
353
 
                                if (op.getArgument().empty ()){
354
 
                                        // -v without number
355
 
                                        _verbose = 1;
356
 
                                }else{
357
 
                                        _verbose = atoi (op.getArgument().c_str());
358
 
                                }
359
 
                                if(_verbose > 6){
360
 
                                        _optvec.pushback("-v",OptionItem::OPT_GCC);
361
 
                                }
362
 
                                break;
363
 
                        
364
 
                        case ACOPT_ASPECT_HEADER :
365
 
                                _ah_files.push_back(op.getArgument());
366
 
                                _optvec.pushback("-a","\""+op.getArgument()+"\"",OptionItem::OPT_ACC);
367
 
                                break;
368
 
                                                                          
369
 
                        case ACOPT_PROJ_PATH :
370
 
                                _proj_path.push_back(op.getArgument());
371
 
                                _optvec.pushback("-p","\""+op.getArgument()+"\"",OptionItem::OPT_ACC);
372
 
                                break;
373
 
                        
374
 
                        case ACOPT_PROJ_DESTINATION :
375
 
                                _dest_path=op.getArgument();
376
 
                                // not pushed into the '_optvec' vector because:
377
 
                                // - destination path is only used in WTP mode
378
 
                                // - WTP mode is only used if --include_files is 
379
 
                                //   specified
380
 
                                break;
381
 
                        
382
 
                        case ACOPT_ALWAYS_INCLUDE :
383
 
                                _dest_path=op.getArgument();
384
 
                                _optvec.pushback("--include","\""+op.getArgument()+"\"",OptionItem::OPT_ACC);
385
 
                                _optvec.pushback("-include","\""+op.getArgument()+"\"",OptionItem::OPT_GCC);
386
 
                                break;
387
 
                        
388
 
 
389
 
                        case OptsParser::NOARG :
390
 
                                _err << sev_error << "Option reqires argument: " ;
391
 
                                _err <<"'"<<op.getOptionName().c_str() <<"'"<< endMessage;
392
 
                                return false;
393
 
                        
394
 
                        case OptsParser::ERR :
395
 
                                _err << sev_error << " Parsing  Options : ";
396
 
                                _err << "unspecified error at " ;
397
 
                                _err <<"'"<<op.getOptionName().c_str() << " " << op.getArgument().c_str() <<"'"<< endMessage;
398
 
                                return false;
399
 
                        
400
 
                        // unknown options are recognized as g++ options
401
 
                        case OptsParser::UNKNOWN :
402
 
                                if (analyzeGccOpt(op)==false){
403
 
                                        return false;
404
 
                                }
405
 
                                break;
406
 
                        
407
 
                        default:
408
 
                                _err << sev_error << " Parsing  Options : ";
409
 
                                _err << "option not handled by Ag++ " ;
410
 
                                _err <<"'"<<op.getOptionName().c_str() << " " << op.getArgument().c_str() <<"'"<< endMessage;
411
 
                                return false;
412
 
                }
413
 
        }
414
 
        
415
 
        
416
 
        
417
 
        // if we are compiling for WIN32 target transform paths to dos 
418
 
        // format, bacause the shell(cmd.exe) can not handle unix 
419
 
        // paths
420
 
        #if defined (WIN32)
421
 
        file::MakeDosPath(_acc_bin);    
422
 
        file::MakeDosPath(_cc_bin);
423
 
        #endif
424
 
 
425
 
        // if path to ac++ was not specified in options.
426
 
        // get it from ARGV[0]
427
 
        if(_acc_bin.empty()){
428
 
                _acc_bin=_argv[0];
429
 
                file::stripFilename(_acc_bin);  
430
 
                _acc_bin.append("ac++");
431
 
        }
432
 
 
433
 
        // if there was no project path specified
434
 
        // take local directory ('.')
435
 
        if(_proj_path.empty()){
436
 
                _proj_path.push_back(".");
437
 
                _optvec.pushback("-p",".",OptionItem::OPT_ACC);
438
 
        }
439
 
 
440
 
        
441
 
        //
442
 
        // Check Constraints
443
 
        //
444
 
        
445
 
        if (_gen_includes==true && _dest_path.empty()){
446
 
                _err << sev_error << "Need to specify a destination path in order "
447
 
                     << "to generate modified include files" << endMessage;
448
 
                return false;
449
 
        }
450
 
 
451
 
        // If weaving should be done check if there are any files in argument string
452
 
        if(_nr_files == 0 && _weave && ! _gen_includes){
453
 
                _err << sev_error << "No files found in arguments" << endMessage;
454
 
                usage();
455
 
                return false;
456
 
        }
457
 
        
458
 
        // If '--weave-only' and '-o' options are used with multiple files 
459
 
        // exit with an error
460
 
        if( (! (_output_file.empty() || _compile) ) && _nr_files > 1 ){
461
 
                _err << sev_error << "Cannot specify -o with --weave_only and multiple compilations"<<endMessage;
462
 
                return false;
463
 
        }
464
 
        
465
 
        // If dependencies should be generated don't weave, compile, or generate a config file
466
 
        if( (_weave || _link || _gen_pumaconfig) && _make_dep ){
467
 
                _err << sev_error << "Invalid selection of options: can't (weave OR link OR generate a config file) AND create dependency information"<<endMessage;
468
 
                usage();
469
 
                return false;
470
 
        }
471
 
return true;
472
 
}
473
 
 
474
 
void AGxxConfig::printOptions(){
475
 
        VerboseMgr vm(cout,_verbose);
476
 
        vm << endvm;
477
 
        vm << endvm;
478
 
        vm << "AG++ Configuration:" << endvm;
479
 
        vm << "  Create puma.config: " << _puma_config.empty() <<endvm;
480
 
        vm << "  Aspect C++ weaver:  " << _acc_bin << endvm;  
481
 
        vm << "  C++ compiler:       " << _cc_bin << endvm;  
482
 
        vm << "  Files:              " << _optvec.getString(OptionItem::OPT_FILE) << endvm;
483
 
        vm << "  Options (G++):      " << _optvec.getString(OptionItem::OPT_GCC) << endvm;
484
 
        vm << "  Options (AC++):     " << _optvec.getString(OptionItem::OPT_ACC) << endvm;
485
 
        vm << "  Options (total):    " << _optvec.getString() << endvm;
486
 
        vm << "  Weave: "<<_weave<<" Compile: "<< _compile<<" Link: "<<_link << endvm;
487
 
        vm << endvm;
488
 
        vm << endvm;
489
 
}
 
136
      _err << "     ";
 
137
      if (options[i].shortName)  _err << "-" << options[i].shortName;
 
138
      if (options[i].shortName && options[i].longName) _err << "|";
 
139
      if (options[i].longName) _err << "--" << options[i].longName;
 
140
      if (options[i].argType != OptsParser::AT_NONE) _err << " <arg>";
 
141
      if (options[i].desc) _err << " \t" << options[i].desc;
 
142
      _err << endMessage;
 
143
   }
 
144
}
 
145
 
 
146
bool AGxxConfig::parseGccOpt(OptsParser &op)
 
147
{
 
148
   
 
149
   // option which should be analyzed
 
150
   string opt=op.getOptionName()+op.getArgument();
 
151
 
 
152
   // argument for this option
 
153
   string arg("");
 
154
 
 
155
   //check for -M/-MM option for generating dependency information
 
156
   if (opt.compare("-M") == 0 || opt.compare("-MM") == 0 ){
 
157
      _make_dep=true;
 
158
      _optvec.pushback(opt,OptionItem::OPT_GCC);
 
159
      return true;
 
160
   }
 
161
 
 
162
   // check if option is in list of gcc options which require an option argument
 
163
   for(string* test_str=_gcc_option_arg;test_str->empty()==false;++test_str){
 
164
      if( opt.compare(0,test_str->length(),*test_str) == 0){
 
165
 
 
166
         // option requires an argument
 
167
 
 
168
         // check if the argument is appended to the option name
 
169
         if ( opt.length() > test_str->length() ){
 
170
            // extract the argument out of the option name
 
171
            arg=" \""+opt.substr(test_str->length())+"\" ";
 
172
            opt=opt.substr(0,test_str->length());
 
173
         }else{
 
174
            // check if there exist another option on command line
 
175
            if(op.getRawOption () != OptsParser::FINISH) {
 
176
               // append argument to string of arguments
 
177
               arg=" \""+op.getArgument()+"\" ";
 
178
            }else{
 
179
               // there is no option anymore
 
180
               _err << sev_error << "G++ Option reqires argument: " ;
 
181
               _err <<"'"<< opt.c_str() <<"'"<< endMessage;
 
182
               return false;
 
183
            }
 
184
         }
 
185
      }
 
186
   }
 
187
   _optvec.pushback(opt,arg,OptionItem::OPT_GCC|OptionItem::OPT_CONFIG);
 
188
   return true;
 
189
 
 
190
}
 
191
 
 
192
 
 
193
 
 
194
bool AGxxConfig::analyze()
 
195
{  
 
196
   bool ret;
 
197
 
 
198
   // setup default values
 
199
   _gen_pumaconfig=true;
 
200
   _weave=false;
 
201
   _compile=false;
 
202
   _link=false;
 
203
   
 
204
   _verbose =0;
 
205
   _nr_files =0;
 
206
 
 
207
   _pumaconfig_tmp=true;
 
208
   _weave_only=false;
 
209
   _keep_woven=false;
 
210
   _gen_includes=false;
 
211
   _cc_bin="g++";
 
212
   _compile_only=false;
 
213
   _make_dep=false;
 
214
   _x_compiler=false;
 
215
   
 
216
 
 
217
   // parse Options received from command line
 
218
   ret = parseOptions();
 
219
   
 
220
   if(ret == true)
 
221
   {
 
222
      // analyze Options received from command line
 
223
      ret = analyzeOptions();
 
224
   }
 
225
 
 
226
   return ret;
 
227
}
 
228
 
 
229
 
 
230
bool AGxxConfig::parseOptions()
 
231
{
 
232
   // use the PUMA option parser for parsing
 
233
   OptsParser op(_argc,_argv,options);
 
234
 
 
235
   // extract options/filenames out of command line arguments
 
236
   while (op.getOption () != OptsParser::FINISH) 
 
237
   {
 
238
      
 
239
      // 
 
240
      // first parse options which do not interfere with g++
 
241
      // options
 
242
      //
 
243
      switch (op.getResult ()) {
 
244
 
 
245
         case AGOPT_OUTPUT :
 
246
            _output_file=op.getArgument();
 
247
            _optvec.pushback("-o"," \""+op.getArgument()+"\" ",(OptionItem::OPT_GCC));
 
248
            continue;
 
249
 
 
250
         case AGOPT_COMPILE_ONLY :
 
251
            _compile_only=true;
 
252
            _optvec.pushback("-c",OptionItem::OPT_GCC);
 
253
            continue;
 
254
 
 
255
         case AGOPT_X_COMPILER :
 
256
            _x_compiler=true;
 
257
            continue;
 
258
 
 
259
         case AGOPT_X_WEAVER :
 
260
            _x_compiler=false;
 
261
            continue;
 
262
 
 
263
         case ACOPT_CFG_FILE :
 
264
            _pumaconfig_file=op.getArgument();
 
265
            _pumaconfig_tmp=false;
 
266
            continue;
 
267
 
 
268
         case ACOPT_PRE_DEFINE :
 
269
            {
 
270
               string tmpStr=op.getArgument();
 
271
               _optvec.pushback("-D"," \""+
 
272
                                str_replace_all(tmpStr,"\"","\\\"")+
 
273
                                "\" ",
 
274
                               (OptionItem::OPT_ACC|OptionItem::OPT_GCC));
 
275
            }
 
276
            continue;
 
277
 
 
278
         case ACOPT_PRE_UNDEFINE :
 
279
            _optvec.pushback("-U"," \""+op.getArgument()+"\" ",
 
280
                  (OptionItem::OPT_ACC|OptionItem::OPT_GCC));
 
281
            continue;
 
282
 
 
283
         case ACOPT_PRE_INCLUDE :
 
284
            _optvec.pushback("-I"," \""+op.getArgument()+"\" ",
 
285
                  (OptionItem::OPT_ACC|OptionItem::OPT_GCC));
 
286
            continue;
 
287
 
 
288
 
 
289
            // command line arguments which are not accepted as options
 
290
            // are recognized as filenames
 
291
         case OptsParser::NOOPTION :
 
292
            ++_nr_files;
 
293
            // if file is a c++ file weave it first.
 
294
            if (regex::regExMatch("^.*\\.((C)|(c)|(cc)|(cp)|(cpp)|(cxx)|(c\\+\\+))$",op.getArgument().c_str()) )
 
295
            {
 
296
               _optvec.pushback(op.getArgument(),(OptionItem::OPT_ACC|OptionItem::OPT_FILE));
 
297
 
 
298
               // when calling we have to pass the original path of this 
 
299
               // source dir as include path, as the '.acc' file to be 
 
300
               // compiled will probably not be generated in the same
 
301
               // directory
 
302
               string tmpStr=op.getArgument();
 
303
               file::stripFilename(tmpStr);
 
304
               if (tmpStr.empty())
 
305
               {
 
306
                  tmpStr =".";
 
307
               }
 
308
               _optvec.pushback("-I"," \""+tmpStr+"\" ",OptionItem::OPT_GCC);
 
309
            }else{
 
310
               _optvec.pushback(op.getArgument(),(OptionItem::OPT_GCC|OptionItem::OPT_FILE));
 
311
            }
 
312
            continue;
 
313
      }
 
314
 
 
315
      // if _x_compiler is set to 'true' interprete
 
316
      // options that are not handled within the previous
 
317
      // 'switch-case' statement as gcc options.
 
318
      if (_x_compiler == true){
 
319
         if (parseGccOpt(op)==false){
 
320
            return false;
 
321
         }
 
322
         continue;
 
323
      }
 
324
 
 
325
 
 
326
      switch (op.getResult ()) {
 
327
 
 
328
         case AGOPT_HELP :
 
329
            usage();
 
330
            return false;
 
331
 
 
332
         case AGOPT_VERSION:
 
333
            cout << "ag++ " << _VERSION <<"  built: "<<__DATE__<< endl;
 
334
            return false;
 
335
 
 
336
 
 
337
         case AGOPT_GEN_CFG :
 
338
            _pumaconfig_tmp=false;
 
339
            break;
 
340
 
 
341
         case AGOPT_WEAVE_ONLY :
 
342
            _weave_only=true;
 
343
            _keep_woven=true;
 
344
            break;
 
345
 
 
346
         case AGOPT_ACC :
 
347
            _acc_bin=op.getArgument();
 
348
            break;
 
349
 
 
350
         case AGOPT_CC :
 
351
            _cc_bin=op.getArgument();
 
352
            break;
 
353
 
 
354
         case AGOPT_KEEP_WOVEN :
 
355
            if(op.getOptionName() == "--keep_acc")
 
356
            {
 
357
               _err << sev_warning << "Usage of --keep_acc is deprecated use --keep_woven instead" << endMessage;
 
358
            }
 
359
            _keep_woven=true;
 
360
            break;
 
361
 
 
362
         case AGOPT_CONFIG_COMMAND :
 
363
            _config_command=op.getArgument();
 
364
            break;
 
365
 
 
366
 
 
367
         case ACOPT: // default handling for Aspect C++ options
 
368
            _optvec.pushback(op.getOptionName(),op.getArgument(),OptionItem::OPT_ACC);
 
369
            break;
 
370
 
 
371
         case ACOPT_INCLUDE_FILES :
 
372
            _gen_includes=true;
 
373
            break;
 
374
 
 
375
         case AGOPT_VERBOSE :
 
376
            _optvec.pushback("-v",op.getArgument(),OptionItem::OPT_ACC);
 
377
            if (op.getArgument().empty ()){
 
378
               // -v without number
 
379
               _verbose = 1;
 
380
            }else{
 
381
               _verbose = atoi (op.getArgument().c_str());
 
382
            }
 
383
            if(_verbose > 6){
 
384
               _optvec.pushback("-v",OptionItem::OPT_GCC);
 
385
            }
 
386
            break;
 
387
 
 
388
         case ACOPT_ASPECT_HEADER :
 
389
            _ah_files.push_back(op.getArgument());
 
390
            _optvec.pushback("-a"," \""+op.getArgument()+"\" ",OptionItem::OPT_ACC);
 
391
            break;
 
392
 
 
393
         case ACOPT_PROJ_PATH :
 
394
            _proj_path.push_back(op.getArgument());
 
395
            _optvec.pushback("-p"," \""+op.getArgument()+"\" ",OptionItem::OPT_ACC);
 
396
            break;
 
397
 
 
398
         case ACOPT_PROJ_DESTINATION :
 
399
            _dest_path=op.getArgument();
 
400
            // not pushed into the '_optvec' vector because:
 
401
            // - destination path is only used in WTP mode
 
402
            // - WTP mode is only used if --include_files is 
 
403
            //   specified
 
404
            break;
 
405
 
 
406
         case ACOPT_ALWAYS_INCLUDE :
 
407
            _dest_path=op.getArgument();
 
408
            _optvec.pushback("--include"," \""+op.getArgument()+"\" ",OptionItem::OPT_ACC);
 
409
            _optvec.pushback("-include"," \""+op.getArgument()+"\" ",OptionItem::OPT_GCC);
 
410
            break;
 
411
 
 
412
 
 
413
         case OptsParser::NOARG :
 
414
            _err << sev_error << "Option reqires argument: " ;
 
415
            _err <<"'"<<op.getOptionName().c_str() <<"'"<< endMessage;
 
416
            return false;
 
417
 
 
418
         case OptsParser::ERR :
 
419
            _err << sev_error << " Parsing  Options : ";
 
420
            _err << "unspecified error at " ;
 
421
            _err <<"'"<<op.getOptionName().c_str() << " " << op.getArgument().c_str() <<"'"<< endMessage;
 
422
            return false;
 
423
 
 
424
            // unknown options are recognized as g++ options
 
425
         case OptsParser::UNKNOWN :
 
426
            if (parseGccOpt(op)==false){
 
427
               return false;
 
428
            }
 
429
            break;
 
430
 
 
431
         default:
 
432
            _err << sev_error << " Parsing  Options : ";
 
433
            _err << "option not handled by Ag++ " ;
 
434
            _err <<"'"<<op.getOptionName().c_str() << " " << op.getArgument().c_str() <<"'"<< endMessage;
 
435
            return false;
 
436
      }
 
437
   }
 
438
   return true;
 
439
}
 
440
 
 
441
 
 
442
bool AGxxConfig::analyzeOptions()
 
443
{
 
444
   // if we are compiling for WIN32 target transform paths to dos 
 
445
   // format, bacause the shell(cmd.exe) can not handle unix 
 
446
   // paths
 
447
#if defined (WIN32)
 
448
   file::MakeDosPath(_acc_bin); 
 
449
   file::MakeDosPath(_cc_bin);
 
450
#endif
 
451
 
 
452
   // if path to ac++ was not specified in options.
 
453
   // get it from ARGV[0]
 
454
   if(_acc_bin.empty())
 
455
   {
 
456
      _acc_bin=_argv[0];
 
457
      file::stripFilename(_acc_bin);    
 
458
      _acc_bin.append("ac++");
 
459
   }
 
460
 
 
461
   // if there was no project path specified
 
462
   // take local directory ('.')
 
463
   if(_proj_path.empty())
 
464
   {
 
465
      _proj_path.push_back(".");
 
466
      _optvec.pushback("-p",".",OptionItem::OPT_ACC);
 
467
   }
 
468
 
 
469
 
 
470
   // check if puma config file shall be generated
 
471
   if (_make_dep == true)
 
472
   {
 
473
      _gen_pumaconfig=false;
 
474
   }
 
475
   
 
476
 
 
477
   // check if source files shall be woven
 
478
   if ((_make_dep == false) && (_nr_files > 0) || (_gen_includes == true))
 
479
   {
 
480
      _weave=true;
 
481
   }
 
482
 
 
483
   // check if source files shall be translated
 
484
   if ((_weave_only == false) && (_gen_includes == false) && (_nr_files > 0))
 
485
   {
 
486
      _compile=true;
 
487
   }
 
488
               
 
489
   // check if source files shall be linked
 
490
   if ((_weave_only == false) && (_gen_includes == false) && (_compile_only == false) && (_make_dep == false) && (_nr_files > 0) )
 
491
   {
 
492
      _link=true;
 
493
   }
 
494
  
 
495
   //
 
496
   // Check Constraints
 
497
   //
 
498
   
 
499
   // if modified include files are NOT created and only a temporary 
 
500
   // puma configuration file is generated ag++ expects some input files
 
501
   if ((_gen_includes==false) && (_pumaconfig_tmp == true) && (_nr_files==0))
 
502
   {
 
503
      _err << sev_error << "No input files"<< endMessage;
 
504
      return false;
 
505
   }
 
506
 
 
507
   // If modified include files are created a destination
 
508
   // path must be specified
 
509
   if (_gen_includes==true && _dest_path.empty())
 
510
   {
 
511
      _err << sev_error << "Need to specify a destination path in order "
 
512
         << "to generate modified include files" << endMessage;
 
513
      return false;
 
514
   }
 
515
 
 
516
   // If '--weave-only' and '-o' options are used with multiple files 
 
517
   // exit with an error
 
518
   if((_weave_only == true)  && (_output_file.empty() == false) && (_nr_files > 1))
 
519
   {
 
520
      _err << sev_error << "Cannot specify -o with --weave_only and multiple compilations"<<endMessage;
 
521
      return false;
 
522
   }
 
523
   
 
524
   return true;
 
525
}
 
526
 
 
527
void AGxxConfig::printOptions()
 
528
{
 
529
   VerboseMgr vm(cout,_verbose);
 
530
   vm << endvm;
 
531
   vm << endvm;
 
532
   vm << "AG++ Configuration:" << endvm;
 
533
   vm << "  Aspect C++ weaver:  " << _acc_bin << endvm;  
 
534
   vm << "  C++ compiler:       " << _cc_bin << endvm;  
 
535
   vm << "  Files:              " << _optvec.getString(OptionItem::OPT_FILE) << endvm;
 
536
   vm << "  Options (G++):      " << _optvec.getString(OptionItem::OPT_GCC,OptionItem::OPT_FILE) << endvm;
 
537
   vm << "  Options (AC++):     " << _optvec.getString(OptionItem::OPT_ACC,OptionItem::OPT_FILE) << endvm;
 
538
   vm << "  Options (total):    " << _optvec.getString() << endvm;
 
539
   vm << "  PumaConfig: " <<_gen_pumaconfig<< " Weave: "<<_weave<<" Compile: "<< _compile<<" Link: "<<_link << endvm;
 
540
   vm << endvm;
 
541
   vm << endvm;
 
542
}
 
543
 
 
544
 
490
545