1 | //----------------------------------------------------------- |
---|
2 | // Copyright Christian Arnault LAL-Orsay CNRS |
---|
3 | // arnault@lal.in2p3.fr |
---|
4 | // Modified by garonne@lal.in2p3.fr |
---|
5 | // See the complete license in cmt_license.txt "http://www.cecill.info". |
---|
6 | //----------------------------------------------------------- |
---|
7 | |
---|
8 | #include "cmt_syntax.h" |
---|
9 | #include "cmt.h" |
---|
10 | #include "cmt_symbol.h" |
---|
11 | #include "cmt_constituent.h" |
---|
12 | #include "cmt_pattern.h" |
---|
13 | #include "cmt_error.h" |
---|
14 | #include "cmt_branch.h" |
---|
15 | #include "cmt_error.h" |
---|
16 | #include "cmt_script.h" |
---|
17 | #include "cmt_language.h" |
---|
18 | #include "cmt_project.h" |
---|
19 | #include "cmt_cmtpath_pattern.h" |
---|
20 | |
---|
21 | |
---|
22 | class KwdAction : public Kwd |
---|
23 | { |
---|
24 | public: |
---|
25 | void action (const CmtSystem::cmt_string_vector& words, |
---|
26 | Use* use, |
---|
27 | const cmt_string& file_name, |
---|
28 | int line_number) |
---|
29 | { |
---|
30 | Symbol::action (words, CommandAction, use); |
---|
31 | } |
---|
32 | void action (const CmtSystem::cmt_string_vector& words, |
---|
33 | Project* project, |
---|
34 | const cmt_string& file_name, |
---|
35 | int line_number) |
---|
36 | {} |
---|
37 | }; |
---|
38 | |
---|
39 | class KwdAlias : public Kwd |
---|
40 | { |
---|
41 | public: |
---|
42 | void action (const CmtSystem::cmt_string_vector& words, |
---|
43 | Use* use, |
---|
44 | const cmt_string& file_name, |
---|
45 | int line_number) |
---|
46 | { |
---|
47 | Symbol::action (words, CommandAlias, use); |
---|
48 | } |
---|
49 | void action (const CmtSystem::cmt_string_vector& words, |
---|
50 | Project* project, |
---|
51 | const cmt_string& file_name, |
---|
52 | int line_number) |
---|
53 | {} |
---|
54 | |
---|
55 | }; |
---|
56 | |
---|
57 | class KwdApplication : public Kwd |
---|
58 | { |
---|
59 | public: |
---|
60 | void action (const CmtSystem::cmt_string_vector& words, |
---|
61 | Use* use, |
---|
62 | const cmt_string& file_name, |
---|
63 | int line_number) |
---|
64 | { |
---|
65 | if (use == &(Use::current ())) |
---|
66 | { |
---|
67 | Constituent::action (Application, words); |
---|
68 | } |
---|
69 | } |
---|
70 | |
---|
71 | void action (const CmtSystem::cmt_string_vector& words, |
---|
72 | Project* project, |
---|
73 | const cmt_string& file_name, |
---|
74 | int line_number) |
---|
75 | {} |
---|
76 | |
---|
77 | }; |
---|
78 | |
---|
79 | class KwdApplyPattern : public Kwd |
---|
80 | { |
---|
81 | public: |
---|
82 | void action (const CmtSystem::cmt_string_vector& words, |
---|
83 | Use* use, |
---|
84 | const cmt_string& file_name, |
---|
85 | int line_number) |
---|
86 | { |
---|
87 | ApplyPattern::action (words, use); |
---|
88 | } |
---|
89 | void action (const CmtSystem::cmt_string_vector& words, |
---|
90 | Project* project, |
---|
91 | const cmt_string& file_name, |
---|
92 | int line_number) |
---|
93 | {} |
---|
94 | |
---|
95 | }; |
---|
96 | |
---|
97 | class KwdApplyTag : public Kwd |
---|
98 | { |
---|
99 | public: |
---|
100 | void action (const CmtSystem::cmt_string_vector& words, |
---|
101 | Use* use, |
---|
102 | const cmt_string& file_name, |
---|
103 | int line_number) |
---|
104 | { |
---|
105 | Tag::action_apply (words, use); |
---|
106 | } |
---|
107 | void action (const CmtSystem::cmt_string_vector& words, |
---|
108 | Project* project, |
---|
109 | const cmt_string& file_name, |
---|
110 | int line_number) |
---|
111 | { |
---|
112 | action (words, project->get_use(), file_name, line_number); |
---|
113 | } |
---|
114 | |
---|
115 | }; |
---|
116 | |
---|
117 | //---------------------------------------------------------- |
---|
118 | class KwdAuthor : public Kwd |
---|
119 | { |
---|
120 | public: |
---|
121 | void action (const CmtSystem::cmt_string_vector& words, |
---|
122 | Use* use, |
---|
123 | const cmt_string& file_name, |
---|
124 | int line_number) |
---|
125 | { |
---|
126 | use->author_action (words); |
---|
127 | |
---|
128 | } |
---|
129 | void action (const CmtSystem::cmt_string_vector& words, |
---|
130 | Project* project, |
---|
131 | const cmt_string& file_name, |
---|
132 | int line_number) |
---|
133 | { |
---|
134 | cmt_string author; |
---|
135 | project->project_author_action (words); |
---|
136 | } |
---|
137 | }; |
---|
138 | //---------------------------------------------------------- |
---|
139 | |
---|
140 | |
---|
141 | class KwdBranches : public Kwd |
---|
142 | { |
---|
143 | public: |
---|
144 | void action (const CmtSystem::cmt_string_vector& words, |
---|
145 | Use* use, |
---|
146 | const cmt_string& file_name, |
---|
147 | int line_number) |
---|
148 | { |
---|
149 | if (use == &(Use::current ())) |
---|
150 | { |
---|
151 | Branch::action (words); |
---|
152 | } |
---|
153 | } |
---|
154 | void action (const CmtSystem::cmt_string_vector& words, |
---|
155 | Project* project, |
---|
156 | const cmt_string& file_name, |
---|
157 | int line_number) |
---|
158 | {} |
---|
159 | |
---|
160 | }; |
---|
161 | |
---|
162 | class KwdBuildStrategy : public Kwd |
---|
163 | { |
---|
164 | public: |
---|
165 | bool decode (const cmt_string& w, cmt_string& strategy, cmt_string& value) |
---|
166 | { |
---|
167 | bool result = true; |
---|
168 | |
---|
169 | value = w; |
---|
170 | Symbol::expand(value); |
---|
171 | //cerr <<"# value: "<<value<<endl; |
---|
172 | |
---|
173 | if (value == "prototypes") |
---|
174 | { |
---|
175 | strategy = "BuildPrototypes"; |
---|
176 | } |
---|
177 | else if (value == "no_prototypes") |
---|
178 | { |
---|
179 | strategy = "BuildPrototypes"; |
---|
180 | } |
---|
181 | else if ((value == "with_installarea") || (value == "with_install_area")) |
---|
182 | { |
---|
183 | value = "with_installarea"; |
---|
184 | strategy = "InstallArea"; |
---|
185 | } |
---|
186 | else if ((value == "without_installarea") || (value == "without_install_area")) |
---|
187 | { |
---|
188 | value = "without_installarea"; |
---|
189 | strategy = "InstallArea"; |
---|
190 | } |
---|
191 | else |
---|
192 | { |
---|
193 | result = false; |
---|
194 | } |
---|
195 | |
---|
196 | return (result); |
---|
197 | } |
---|
198 | |
---|
199 | void action (const CmtSystem::cmt_string_vector& words, |
---|
200 | Use* use, |
---|
201 | const cmt_string& file_name, |
---|
202 | int line_number) |
---|
203 | { |
---|
204 | cmt_string cmtpath; |
---|
205 | cmt_string offset; |
---|
206 | |
---|
207 | use->get_cmtpath_and_offset (cmtpath, offset); |
---|
208 | |
---|
209 | Project* p = Project::find_by_cmtpath (cmtpath); |
---|
210 | |
---|
211 | for (int i = 1; i < words.size (); i++) |
---|
212 | { |
---|
213 | const cmt_string& w = words[i]; |
---|
214 | |
---|
215 | cmt_string strategy; |
---|
216 | cmt_string value; |
---|
217 | |
---|
218 | bool in_error = false; |
---|
219 | |
---|
220 | if (decode (w, strategy, value)) |
---|
221 | { |
---|
222 | if (p != 0) p->set_strategy (strategy, value, use->get_package_name ()); |
---|
223 | } |
---|
224 | else |
---|
225 | { |
---|
226 | in_error = true; |
---|
227 | |
---|
228 | CmtError::set (CmtError::syntax_error, "ParseRequirements> bad strategy keyword"); |
---|
229 | } |
---|
230 | } |
---|
231 | } |
---|
232 | |
---|
233 | void action (const CmtSystem::cmt_string_vector& words, |
---|
234 | Project* project, |
---|
235 | const cmt_string& file_name, |
---|
236 | int line_number) |
---|
237 | { |
---|
238 | for (int i = 1; i < words.size (); i++) |
---|
239 | { |
---|
240 | const cmt_string& w = words[i]; |
---|
241 | |
---|
242 | cmt_string strategy; |
---|
243 | cmt_string value; |
---|
244 | |
---|
245 | bool in_error = false; |
---|
246 | |
---|
247 | if (decode (w, strategy, value)) |
---|
248 | { |
---|
249 | if (project != 0) project->set_strategy (strategy, value, ""); |
---|
250 | } |
---|
251 | else |
---|
252 | { |
---|
253 | in_error = true; |
---|
254 | |
---|
255 | CmtError::set (CmtError::syntax_error, "ParseRequirements> bad strategy keyword"); |
---|
256 | } |
---|
257 | } |
---|
258 | } |
---|
259 | }; |
---|
260 | |
---|
261 | class KwdCleanupScript : public Kwd |
---|
262 | { |
---|
263 | public: |
---|
264 | void action (const CmtSystem::cmt_string_vector& words, |
---|
265 | Use* use, |
---|
266 | const cmt_string& file_name, |
---|
267 | int line_number) |
---|
268 | { |
---|
269 | Script::action (words, CleanupScript, use); |
---|
270 | Symbol::action (words, CommandCleanupScript, use); |
---|
271 | } |
---|
272 | void action (const CmtSystem::cmt_string_vector& words, |
---|
273 | Project* project, |
---|
274 | const cmt_string& file_name, |
---|
275 | int line_number) |
---|
276 | {} |
---|
277 | }; |
---|
278 | |
---|
279 | class KwdCmtPathPattern : public Kwd |
---|
280 | { |
---|
281 | public: |
---|
282 | void action (const CmtSystem::cmt_string_vector& words, |
---|
283 | Use* use, |
---|
284 | const cmt_string& /*file_name*/, |
---|
285 | int /*line_number*/) |
---|
286 | { |
---|
287 | CmtPathPattern::action (words, use); |
---|
288 | } |
---|
289 | void action (const CmtSystem::cmt_string_vector& words, |
---|
290 | Project* project, |
---|
291 | const cmt_string& file_name, |
---|
292 | int line_number) |
---|
293 | {} |
---|
294 | |
---|
295 | }; |
---|
296 | |
---|
297 | class KwdCmtPathPatternRevert : public Kwd |
---|
298 | { |
---|
299 | public: |
---|
300 | void action (const CmtSystem::cmt_string_vector& words, |
---|
301 | Use* use, |
---|
302 | const cmt_string& /*file_name*/, |
---|
303 | int /*line_number*/) |
---|
304 | { |
---|
305 | CmtPathPattern::action (words, use, true); |
---|
306 | } |
---|
307 | |
---|
308 | void action (const CmtSystem::cmt_string_vector& words, |
---|
309 | Project* project, |
---|
310 | const cmt_string& file_name, |
---|
311 | int line_number) |
---|
312 | {} |
---|
313 | }; |
---|
314 | |
---|
315 | class KwdContainer : public Kwd |
---|
316 | { |
---|
317 | public: |
---|
318 | void action (const CmtSystem::cmt_string_vector& words, |
---|
319 | Use* use, |
---|
320 | const cmt_string& file_name, |
---|
321 | int line_number) |
---|
322 | { |
---|
323 | } |
---|
324 | |
---|
325 | void action (const CmtSystem::cmt_string_vector& words, |
---|
326 | Project* project, |
---|
327 | const cmt_string& file_name, |
---|
328 | int line_number) |
---|
329 | { |
---|
330 | project->container_action (words[1], words[2]); |
---|
331 | } |
---|
332 | }; |
---|
333 | |
---|
334 | class KwdDocument : public Kwd |
---|
335 | { |
---|
336 | public: |
---|
337 | void action (const CmtSystem::cmt_string_vector& words, |
---|
338 | Use* use, |
---|
339 | const cmt_string& file_name, |
---|
340 | int line_number) |
---|
341 | { |
---|
342 | if (use == &(Use::current ())) |
---|
343 | { |
---|
344 | Constituent::action (Document, words); |
---|
345 | } |
---|
346 | } |
---|
347 | void action (const CmtSystem::cmt_string_vector& words, |
---|
348 | Project* project, |
---|
349 | const cmt_string& file_name, |
---|
350 | int line_number) |
---|
351 | {} |
---|
352 | |
---|
353 | }; |
---|
354 | |
---|
355 | class KwdEndPrivate : public Kwd |
---|
356 | { |
---|
357 | public: |
---|
358 | void action (const CmtSystem::cmt_string_vector& words, |
---|
359 | Use* use, |
---|
360 | const cmt_string& file_name, |
---|
361 | int line_number) |
---|
362 | { |
---|
363 | if (use != &(Use::current ())) |
---|
364 | { |
---|
365 | use->pop_scope_section (); |
---|
366 | } |
---|
367 | } |
---|
368 | void action (const CmtSystem::cmt_string_vector& words, |
---|
369 | Project* project, |
---|
370 | const cmt_string& file_name, |
---|
371 | int line_number) |
---|
372 | {} |
---|
373 | }; |
---|
374 | |
---|
375 | class KwdEndPublic : public Kwd |
---|
376 | { |
---|
377 | public: |
---|
378 | void action (const CmtSystem::cmt_string_vector& words, |
---|
379 | Use* use, |
---|
380 | const cmt_string& file_name, |
---|
381 | int line_number) |
---|
382 | { |
---|
383 | if (use != &(Use::current ())) |
---|
384 | { |
---|
385 | use->pop_scope_section (); |
---|
386 | } |
---|
387 | } |
---|
388 | void action (const CmtSystem::cmt_string_vector& words, |
---|
389 | Project* project, |
---|
390 | const cmt_string& file_name, |
---|
391 | int line_number) |
---|
392 | {} |
---|
393 | }; |
---|
394 | |
---|
395 | class KwdIgnorePattern : public Kwd |
---|
396 | { |
---|
397 | public: |
---|
398 | void action (const CmtSystem::cmt_string_vector& words, |
---|
399 | Use* use, |
---|
400 | const cmt_string& file_name, |
---|
401 | int line_number) |
---|
402 | { |
---|
403 | IgnorePattern::action (words, use); |
---|
404 | } |
---|
405 | void action (const CmtSystem::cmt_string_vector& words, |
---|
406 | Project* project, |
---|
407 | const cmt_string& file_name, |
---|
408 | int line_number) |
---|
409 | {} |
---|
410 | |
---|
411 | }; |
---|
412 | |
---|
413 | class KwdIncludeDirs : public Kwd |
---|
414 | { |
---|
415 | public: |
---|
416 | void action (const CmtSystem::cmt_string_vector& words, |
---|
417 | Use* use, |
---|
418 | const cmt_string& file_name, |
---|
419 | int line_number) |
---|
420 | { |
---|
421 | Include::action (words, use); |
---|
422 | } |
---|
423 | void action (const CmtSystem::cmt_string_vector& words, |
---|
424 | Project* project, |
---|
425 | const cmt_string& file_name, |
---|
426 | int line_number) |
---|
427 | {} |
---|
428 | |
---|
429 | }; |
---|
430 | |
---|
431 | class KwdIncludePath : public Kwd |
---|
432 | { |
---|
433 | public: |
---|
434 | void action (const CmtSystem::cmt_string_vector& words, |
---|
435 | Use* use, |
---|
436 | const cmt_string& file_name, |
---|
437 | int line_number) |
---|
438 | { |
---|
439 | if (words.size () > 1) |
---|
440 | { |
---|
441 | use->set_include_path (words[1]); |
---|
442 | } |
---|
443 | } |
---|
444 | void action (const CmtSystem::cmt_string_vector& words, |
---|
445 | Project* project, |
---|
446 | const cmt_string& file_name, |
---|
447 | int line_number) |
---|
448 | {} |
---|
449 | |
---|
450 | }; |
---|
451 | |
---|
452 | class KwdLanguage : public Kwd |
---|
453 | { |
---|
454 | public: |
---|
455 | void action (const CmtSystem::cmt_string_vector& words, |
---|
456 | Use* use, |
---|
457 | const cmt_string& file_name, |
---|
458 | int line_number) |
---|
459 | { |
---|
460 | Language::action (words); |
---|
461 | } |
---|
462 | void action (const CmtSystem::cmt_string_vector& words, |
---|
463 | Project* project, |
---|
464 | const cmt_string& file_name, |
---|
465 | int line_number) |
---|
466 | {} |
---|
467 | |
---|
468 | }; |
---|
469 | |
---|
470 | class KwdLibrary : public Kwd |
---|
471 | { |
---|
472 | public: |
---|
473 | void action (const CmtSystem::cmt_string_vector& words, |
---|
474 | Use* use, |
---|
475 | const cmt_string& file_name, |
---|
476 | int line_number) |
---|
477 | { |
---|
478 | if (use == &(Use::current ())) |
---|
479 | { |
---|
480 | Constituent::action (Library, words); |
---|
481 | } |
---|
482 | } |
---|
483 | void action (const CmtSystem::cmt_string_vector& words, |
---|
484 | Project* project, |
---|
485 | const cmt_string& file_name, |
---|
486 | int line_number) |
---|
487 | {} |
---|
488 | }; |
---|
489 | |
---|
490 | class KwdMacro : public Kwd |
---|
491 | { |
---|
492 | public: |
---|
493 | void action (const CmtSystem::cmt_string_vector& words, |
---|
494 | Use* use, |
---|
495 | const cmt_string& file_name, |
---|
496 | int line_number) |
---|
497 | { |
---|
498 | Symbol::action (words, CommandMacro, use); |
---|
499 | } |
---|
500 | void action (const CmtSystem::cmt_string_vector& words, |
---|
501 | Project* project, |
---|
502 | const cmt_string& file_name, |
---|
503 | int line_number) |
---|
504 | { |
---|
505 | action (words, project->get_use(), file_name, line_number); |
---|
506 | } |
---|
507 | }; |
---|
508 | |
---|
509 | class KwdMacroPrepend : public Kwd |
---|
510 | { |
---|
511 | public: |
---|
512 | void action (const CmtSystem::cmt_string_vector& words, |
---|
513 | Use* use, |
---|
514 | const cmt_string& file_name, |
---|
515 | int line_number) |
---|
516 | { |
---|
517 | Symbol::action (words, CommandMacroPrepend, use); |
---|
518 | } |
---|
519 | void action (const CmtSystem::cmt_string_vector& words, |
---|
520 | Project* project, |
---|
521 | const cmt_string& file_name, |
---|
522 | int line_number) |
---|
523 | { |
---|
524 | action (words, project->get_use(), file_name, line_number); |
---|
525 | } |
---|
526 | }; |
---|
527 | |
---|
528 | class KwdMacroAppend : public Kwd |
---|
529 | { |
---|
530 | public: |
---|
531 | void action (const CmtSystem::cmt_string_vector& words, |
---|
532 | Use* use, |
---|
533 | const cmt_string& file_name, |
---|
534 | int line_number) |
---|
535 | { |
---|
536 | Symbol::action (words, CommandMacroAppend, use); |
---|
537 | } |
---|
538 | void action (const CmtSystem::cmt_string_vector& words, |
---|
539 | Project* project, |
---|
540 | const cmt_string& file_name, |
---|
541 | int line_number) |
---|
542 | { |
---|
543 | action (words, project->get_use(), file_name, line_number); |
---|
544 | } |
---|
545 | }; |
---|
546 | |
---|
547 | class KwdMacroRemove : public Kwd |
---|
548 | { |
---|
549 | public: |
---|
550 | void action (const CmtSystem::cmt_string_vector& words, |
---|
551 | Use* use, |
---|
552 | const cmt_string& file_name, |
---|
553 | int line_number) |
---|
554 | { |
---|
555 | Symbol::action (words, CommandMacroRemove, use); |
---|
556 | } |
---|
557 | void action (const CmtSystem::cmt_string_vector& words, |
---|
558 | Project* project, |
---|
559 | const cmt_string& file_name, |
---|
560 | int line_number) |
---|
561 | { |
---|
562 | action (words, project->get_use(), file_name, line_number); |
---|
563 | } |
---|
564 | }; |
---|
565 | |
---|
566 | class KwdMacroRemoveRegexp : public Kwd |
---|
567 | { |
---|
568 | public: |
---|
569 | void action (const CmtSystem::cmt_string_vector& words, |
---|
570 | Use* use, |
---|
571 | const cmt_string& file_name, |
---|
572 | int line_number) |
---|
573 | { |
---|
574 | Symbol::action (words, CommandMacroRemoveRegexp, use); |
---|
575 | } |
---|
576 | void action (const CmtSystem::cmt_string_vector& words, |
---|
577 | Project* project, |
---|
578 | const cmt_string& file_name, |
---|
579 | int line_number) |
---|
580 | |
---|
581 | { |
---|
582 | action (words, project->get_use(), file_name, line_number); |
---|
583 | } |
---|
584 | }; |
---|
585 | |
---|
586 | class KwdMacroRemoveAll : public Kwd |
---|
587 | { |
---|
588 | public: |
---|
589 | void action (const CmtSystem::cmt_string_vector& words, |
---|
590 | Use* use, |
---|
591 | const cmt_string& file_name, |
---|
592 | int line_number) |
---|
593 | { |
---|
594 | Symbol::action (words, CommandMacroRemoveAll, use); |
---|
595 | } |
---|
596 | void action (const CmtSystem::cmt_string_vector& words, |
---|
597 | Project* project, |
---|
598 | const cmt_string& file_name, |
---|
599 | int line_number) |
---|
600 | { |
---|
601 | action (words, project->get_use(), file_name, line_number); |
---|
602 | } |
---|
603 | }; |
---|
604 | |
---|
605 | class KwdMacroRemoveAllRegexp : public Kwd |
---|
606 | { |
---|
607 | public: |
---|
608 | void action (const CmtSystem::cmt_string_vector& words, |
---|
609 | Use* use, |
---|
610 | const cmt_string& file_name, |
---|
611 | int line_number) |
---|
612 | { |
---|
613 | Symbol::action (words, CommandMacroRemoveAllRegexp, use); |
---|
614 | } |
---|
615 | void action (const CmtSystem::cmt_string_vector& words, |
---|
616 | Project* project, |
---|
617 | const cmt_string& file_name, |
---|
618 | int line_number) |
---|
619 | { |
---|
620 | action (words, project->get_use(), file_name, line_number); |
---|
621 | } |
---|
622 | }; |
---|
623 | |
---|
624 | class KwdMakeFragment : public Kwd |
---|
625 | { |
---|
626 | public: |
---|
627 | void action (const CmtSystem::cmt_string_vector& words, |
---|
628 | Use* use, |
---|
629 | const cmt_string& file_name, |
---|
630 | int line_number) |
---|
631 | { |
---|
632 | Fragment::action (words, use); |
---|
633 | } |
---|
634 | void action (const CmtSystem::cmt_string_vector& words, |
---|
635 | Project* project, |
---|
636 | const cmt_string& file_name, |
---|
637 | int line_number) |
---|
638 | {} |
---|
639 | }; |
---|
640 | |
---|
641 | class KwdManager : public Kwd |
---|
642 | { |
---|
643 | public: |
---|
644 | void action (const CmtSystem::cmt_string_vector& words, |
---|
645 | Use* use, |
---|
646 | const cmt_string& file_name, |
---|
647 | int line_number) |
---|
648 | { |
---|
649 | use->manager_action (words); |
---|
650 | } |
---|
651 | void action (const CmtSystem::cmt_string_vector& words, |
---|
652 | Project* project, |
---|
653 | const cmt_string& file_name, |
---|
654 | int line_number) |
---|
655 | {} |
---|
656 | }; |
---|
657 | |
---|
658 | class KwdPackage : public Kwd |
---|
659 | { |
---|
660 | public: |
---|
661 | void action (const CmtSystem::cmt_string_vector& words, |
---|
662 | Use* use, |
---|
663 | const cmt_string& file_name, |
---|
664 | int line_number) |
---|
665 | { |
---|
666 | /* |
---|
667 | if (words.size () > 1) |
---|
668 | { |
---|
669 | if (use == &(Use::current())) |
---|
670 | { |
---|
671 | m_current_package = words[1]; |
---|
672 | build_prefix (m_current_package, m_current_prefix); |
---|
673 | |
---|
674 | if ((use->get_package_name () != "") && |
---|
675 | (use->get_package_name () != m_current_package)) |
---|
676 | { |
---|
677 | if (!m_quiet) |
---|
678 | { |
---|
679 | // cerr << "#CMT> package name mismatch in requirements of " << |
---|
680 | // use->get_package_name () << " " << |
---|
681 | // use->version << " line #" << line_number; |
---|
682 | // cerr << " : " << m_current_package << " versus " << |
---|
683 | // use->get_package_name () << endl; |
---|
684 | } |
---|
685 | } |
---|
686 | |
---|
687 | use->set (m_current_package, |
---|
688 | m_current_version, |
---|
689 | m_current_path, |
---|
690 | "", |
---|
691 | ""); |
---|
692 | |
---|
693 | use->change_path (m_current_path); |
---|
694 | use->style = m_current_style; |
---|
695 | } |
---|
696 | } |
---|
697 | */ |
---|
698 | } |
---|
699 | void action (const CmtSystem::cmt_string_vector& words, |
---|
700 | Project* project, |
---|
701 | const cmt_string& file_name, |
---|
702 | int line_number) |
---|
703 | {} |
---|
704 | }; |
---|
705 | |
---|
706 | class KwdPath : public Kwd |
---|
707 | { |
---|
708 | public: |
---|
709 | void action (const CmtSystem::cmt_string_vector& words, |
---|
710 | Use* use, |
---|
711 | const cmt_string& file_name, |
---|
712 | int line_number) |
---|
713 | { |
---|
714 | Symbol::action (words, CommandPath, use); |
---|
715 | } |
---|
716 | void action (const CmtSystem::cmt_string_vector& words, |
---|
717 | Project* project, |
---|
718 | const cmt_string& file_name, |
---|
719 | int line_number) |
---|
720 | {} |
---|
721 | |
---|
722 | }; |
---|
723 | |
---|
724 | class KwdPathAppend : public Kwd |
---|
725 | { |
---|
726 | public: |
---|
727 | void action (const CmtSystem::cmt_string_vector& words, |
---|
728 | Use* use, |
---|
729 | const cmt_string& file_name, |
---|
730 | int line_number) |
---|
731 | { |
---|
732 | Symbol::action (words, CommandPathAppend, use); |
---|
733 | } |
---|
734 | void action (const CmtSystem::cmt_string_vector& words, |
---|
735 | Project* project, |
---|
736 | const cmt_string& file_name, |
---|
737 | int line_number) |
---|
738 | {} |
---|
739 | }; |
---|
740 | |
---|
741 | class KwdPathPrepend : public Kwd |
---|
742 | { |
---|
743 | public: |
---|
744 | void action (const CmtSystem::cmt_string_vector& words, |
---|
745 | Use* use, |
---|
746 | const cmt_string& file_name, |
---|
747 | int line_number) |
---|
748 | { |
---|
749 | Symbol::action (words, CommandPathPrepend, use); |
---|
750 | } |
---|
751 | void action (const CmtSystem::cmt_string_vector& words, |
---|
752 | Project* project, |
---|
753 | const cmt_string& file_name, |
---|
754 | int line_number) |
---|
755 | {} |
---|
756 | }; |
---|
757 | |
---|
758 | class KwdPathRemove : public Kwd |
---|
759 | { |
---|
760 | public: |
---|
761 | void action (const CmtSystem::cmt_string_vector& words, |
---|
762 | Use* use, |
---|
763 | const cmt_string& file_name, |
---|
764 | int line_number) |
---|
765 | { |
---|
766 | Symbol::action (words, CommandPathRemove, use); |
---|
767 | } |
---|
768 | void action (const CmtSystem::cmt_string_vector& words, |
---|
769 | Project* project, |
---|
770 | const cmt_string& file_name, |
---|
771 | int line_number) |
---|
772 | {} |
---|
773 | }; |
---|
774 | |
---|
775 | class KwdPathRemoveRegexp : public Kwd |
---|
776 | { |
---|
777 | public: |
---|
778 | void action (const CmtSystem::cmt_string_vector& words, |
---|
779 | Use* use, |
---|
780 | const cmt_string& file_name, |
---|
781 | int line_number) |
---|
782 | { |
---|
783 | Symbol::action (words, CommandPathRemoveRegexp, use); |
---|
784 | } |
---|
785 | void action (const CmtSystem::cmt_string_vector& words, |
---|
786 | Project* project, |
---|
787 | const cmt_string& file_name, |
---|
788 | int line_number) |
---|
789 | {} |
---|
790 | }; |
---|
791 | |
---|
792 | class KwdPattern : public Kwd |
---|
793 | { |
---|
794 | public: |
---|
795 | void action (const CmtSystem::cmt_string_vector& words, |
---|
796 | Use* use, |
---|
797 | const cmt_string& file_name, |
---|
798 | int line_number) |
---|
799 | { |
---|
800 | Pattern::action (words, use); |
---|
801 | } |
---|
802 | void action (const CmtSystem::cmt_string_vector& words, |
---|
803 | Project* project, |
---|
804 | const cmt_string& file_name, |
---|
805 | int line_number) |
---|
806 | {} |
---|
807 | }; |
---|
808 | |
---|
809 | class KwdPrivate : public Kwd |
---|
810 | { |
---|
811 | public: |
---|
812 | void action (const CmtSystem::cmt_string_vector& words, |
---|
813 | Use* use, |
---|
814 | const cmt_string& file_name, |
---|
815 | int line_number) |
---|
816 | { |
---|
817 | if (use != &(Use::current ())) |
---|
818 | { |
---|
819 | use->push_scope_section (ScopePrivate); |
---|
820 | } |
---|
821 | } |
---|
822 | void action (const CmtSystem::cmt_string_vector& words, |
---|
823 | Project* project, |
---|
824 | const cmt_string& file_name, |
---|
825 | int line_number) |
---|
826 | {} |
---|
827 | }; |
---|
828 | |
---|
829 | class KwdProject : public Kwd |
---|
830 | { |
---|
831 | public: |
---|
832 | void action (const CmtSystem::cmt_string_vector& words, |
---|
833 | Use* use, |
---|
834 | const cmt_string& file_name, |
---|
835 | int line_number) |
---|
836 | { |
---|
837 | } |
---|
838 | |
---|
839 | void action (const CmtSystem::cmt_string_vector& words, |
---|
840 | Project* project, |
---|
841 | const cmt_string& file_name, |
---|
842 | int line_number) |
---|
843 | { |
---|
844 | } |
---|
845 | }; |
---|
846 | |
---|
847 | class KwdPublic : public Kwd |
---|
848 | { |
---|
849 | public: |
---|
850 | void action (const CmtSystem::cmt_string_vector& words, |
---|
851 | Use* use, |
---|
852 | const cmt_string& file_name, |
---|
853 | int line_number) |
---|
854 | { |
---|
855 | if (use != &(Use::current ())) |
---|
856 | { |
---|
857 | use->push_scope_section (ScopePublic); |
---|
858 | } |
---|
859 | } |
---|
860 | void action (const CmtSystem::cmt_string_vector& words, |
---|
861 | Project* project, |
---|
862 | const cmt_string& file_name, |
---|
863 | int line_number) |
---|
864 | {} |
---|
865 | }; |
---|
866 | |
---|
867 | class KwdSet : public Kwd |
---|
868 | { |
---|
869 | public: |
---|
870 | void action (const CmtSystem::cmt_string_vector& words, |
---|
871 | Use* use, |
---|
872 | const cmt_string& file_name, |
---|
873 | int line_number) |
---|
874 | { |
---|
875 | Symbol::action (words, CommandSet, use); |
---|
876 | } |
---|
877 | void action (const CmtSystem::cmt_string_vector& words, |
---|
878 | Project* project, |
---|
879 | const cmt_string& file_name, |
---|
880 | int line_number) |
---|
881 | {} |
---|
882 | }; |
---|
883 | |
---|
884 | class KwdSetAppend : public Kwd |
---|
885 | { |
---|
886 | public: |
---|
887 | void action (const CmtSystem::cmt_string_vector& words, |
---|
888 | Use* use, |
---|
889 | const cmt_string& file_name, |
---|
890 | int line_number) |
---|
891 | { |
---|
892 | Symbol::action (words, CommandSetAppend, use); |
---|
893 | } |
---|
894 | void action (const CmtSystem::cmt_string_vector& words, |
---|
895 | Project* project, |
---|
896 | const cmt_string& file_name, |
---|
897 | int line_number) |
---|
898 | {} |
---|
899 | }; |
---|
900 | |
---|
901 | class KwdSetPrepend : public Kwd |
---|
902 | { |
---|
903 | public: |
---|
904 | void action (const CmtSystem::cmt_string_vector& words, |
---|
905 | Use* use, |
---|
906 | const cmt_string& file_name, |
---|
907 | int line_number) |
---|
908 | { |
---|
909 | Symbol::action (words, CommandSetPrepend, use); |
---|
910 | } |
---|
911 | void action (const CmtSystem::cmt_string_vector& words, |
---|
912 | Project* project, |
---|
913 | const cmt_string& file_name, |
---|
914 | int line_number) |
---|
915 | {} |
---|
916 | }; |
---|
917 | |
---|
918 | class KwdSetRemove : public Kwd |
---|
919 | { |
---|
920 | public: |
---|
921 | void action (const CmtSystem::cmt_string_vector& words, |
---|
922 | Use* use, |
---|
923 | const cmt_string& file_name, |
---|
924 | int line_number) |
---|
925 | { |
---|
926 | Symbol::action (words, CommandSetRemove, use); |
---|
927 | } |
---|
928 | void action (const CmtSystem::cmt_string_vector& words, |
---|
929 | Project* project, |
---|
930 | const cmt_string& file_name, |
---|
931 | int line_number) |
---|
932 | {} |
---|
933 | }; |
---|
934 | |
---|
935 | class KwdSetRemoveRegexp : public Kwd |
---|
936 | { |
---|
937 | public: |
---|
938 | void action (const CmtSystem::cmt_string_vector& words, |
---|
939 | Use* use, |
---|
940 | const cmt_string& file_name, |
---|
941 | int line_number) |
---|
942 | { |
---|
943 | Symbol::action (words, CommandSetRemoveRegexp, use); |
---|
944 | } |
---|
945 | void action (const CmtSystem::cmt_string_vector& words, |
---|
946 | Project* project, |
---|
947 | const cmt_string& file_name, |
---|
948 | int line_number) |
---|
949 | {} |
---|
950 | }; |
---|
951 | |
---|
952 | class KwdSetupScript : public Kwd |
---|
953 | { |
---|
954 | public: |
---|
955 | void action (const CmtSystem::cmt_string_vector& words, |
---|
956 | Use* use, |
---|
957 | const cmt_string& file_name, |
---|
958 | int line_number) |
---|
959 | { |
---|
960 | Script::action (words, SetupScript, use); |
---|
961 | Symbol::action (words, CommandSetupScript, use); |
---|
962 | } |
---|
963 | void action (const CmtSystem::cmt_string_vector& words, |
---|
964 | Project* project, |
---|
965 | const cmt_string& file_name, |
---|
966 | int line_number) |
---|
967 | {} |
---|
968 | }; |
---|
969 | |
---|
970 | class KwdSetupStrategy : public Kwd |
---|
971 | { |
---|
972 | public: |
---|
973 | bool decode (const cmt_string& w, cmt_string& strategy, cmt_string& value) |
---|
974 | { |
---|
975 | bool result = true; |
---|
976 | |
---|
977 | value = w; |
---|
978 | Symbol::expand(value); |
---|
979 | |
---|
980 | |
---|
981 | if (value == "config") |
---|
982 | { |
---|
983 | strategy = "SetupConfig"; |
---|
984 | } |
---|
985 | else if (value == "no_config") |
---|
986 | { |
---|
987 | strategy = "SetupConfig"; |
---|
988 | } |
---|
989 | else if (value == "root") |
---|
990 | { |
---|
991 | strategy = "SetupRoot"; |
---|
992 | } |
---|
993 | else if (value == "no_root") |
---|
994 | { |
---|
995 | strategy = "SetupRoot"; |
---|
996 | } |
---|
997 | else if (value == "cleanup") |
---|
998 | { |
---|
999 | strategy = "SetupCleanup"; |
---|
1000 | } |
---|
1001 | else if (value == "no_cleanup") |
---|
1002 | { |
---|
1003 | strategy = "SetupCleanup"; |
---|
1004 | } |
---|
1005 | else |
---|
1006 | { |
---|
1007 | result = false; |
---|
1008 | } |
---|
1009 | |
---|
1010 | return (result); |
---|
1011 | } |
---|
1012 | |
---|
1013 | void action (const CmtSystem::cmt_string_vector& words, |
---|
1014 | Use* use, |
---|
1015 | const cmt_string& file_name, |
---|
1016 | int line_number) |
---|
1017 | { |
---|
1018 | cmt_string cmtpath; |
---|
1019 | cmt_string offset; |
---|
1020 | |
---|
1021 | use->get_cmtpath_and_offset (cmtpath, offset); |
---|
1022 | |
---|
1023 | Project* p = Project::find_by_cmtpath (cmtpath); |
---|
1024 | |
---|
1025 | for (int i = 1; i < words.size (); i++) |
---|
1026 | { |
---|
1027 | const cmt_string& w = words[i]; |
---|
1028 | |
---|
1029 | cmt_string strategy; |
---|
1030 | cmt_string value; |
---|
1031 | |
---|
1032 | bool in_error = false; |
---|
1033 | |
---|
1034 | if (decode (w, strategy, value)) |
---|
1035 | { |
---|
1036 | if (p != 0) p->set_strategy (strategy, value, use->get_package_name ()); |
---|
1037 | } |
---|
1038 | else |
---|
1039 | { |
---|
1040 | in_error = true; |
---|
1041 | |
---|
1042 | CmtError::set (CmtError::syntax_error, "ParseRequirements> bad strategy keyword"); |
---|
1043 | } |
---|
1044 | } |
---|
1045 | } |
---|
1046 | |
---|
1047 | void action (const CmtSystem::cmt_string_vector& words, |
---|
1048 | Project* project, |
---|
1049 | const cmt_string& file_name, |
---|
1050 | int line_number) |
---|
1051 | { |
---|
1052 | for (int i = 1; i < words.size (); i++) |
---|
1053 | { |
---|
1054 | const cmt_string& w = words[i]; |
---|
1055 | |
---|
1056 | cmt_string strategy; |
---|
1057 | cmt_string value; |
---|
1058 | |
---|
1059 | bool in_error = false; |
---|
1060 | |
---|
1061 | if (decode (w, strategy, value)) |
---|
1062 | { |
---|
1063 | if (project != 0) project->set_strategy (strategy, value, ""); |
---|
1064 | } |
---|
1065 | else |
---|
1066 | { |
---|
1067 | in_error = true; |
---|
1068 | |
---|
1069 | CmtError::set (CmtError::syntax_error, "ParseRequirements> bad strategy keyword"); |
---|
1070 | } |
---|
1071 | } |
---|
1072 | } |
---|
1073 | }; |
---|
1074 | |
---|
1075 | class KwdStructureStrategy : public Kwd |
---|
1076 | { |
---|
1077 | public: |
---|
1078 | bool decode (const cmt_string& w, cmt_string& strategy, cmt_string& value) |
---|
1079 | { |
---|
1080 | bool result = true; |
---|
1081 | |
---|
1082 | value = w; |
---|
1083 | Symbol::expand(value); |
---|
1084 | |
---|
1085 | if (value == "with_version_directory") |
---|
1086 | { |
---|
1087 | strategy = "VersionDirectory"; |
---|
1088 | } |
---|
1089 | else if (value == "without_version_directory") |
---|
1090 | { |
---|
1091 | strategy = "VersionDirectory"; |
---|
1092 | } |
---|
1093 | else |
---|
1094 | { |
---|
1095 | result = false; |
---|
1096 | } |
---|
1097 | |
---|
1098 | return (result); |
---|
1099 | } |
---|
1100 | |
---|
1101 | void action (const CmtSystem::cmt_string_vector& words, |
---|
1102 | Use* use, |
---|
1103 | const cmt_string& file_name, |
---|
1104 | int line_number) |
---|
1105 | { |
---|
1106 | cmt_string cmtpath; |
---|
1107 | cmt_string offset; |
---|
1108 | |
---|
1109 | use->get_cmtpath_and_offset (cmtpath, offset); |
---|
1110 | |
---|
1111 | Project* p = Project::find_by_cmtpath (cmtpath); |
---|
1112 | |
---|
1113 | for (int i = 1; i < words.size (); i++) |
---|
1114 | { |
---|
1115 | const cmt_string& w = words[i]; |
---|
1116 | |
---|
1117 | cmt_string strategy; |
---|
1118 | cmt_string value; |
---|
1119 | |
---|
1120 | bool in_error = false; |
---|
1121 | |
---|
1122 | if (decode (w, strategy, value)) |
---|
1123 | { |
---|
1124 | if (p != 0) p->set_strategy (strategy, value, use->get_package_name ()); |
---|
1125 | } |
---|
1126 | else |
---|
1127 | { |
---|
1128 | in_error = true; |
---|
1129 | |
---|
1130 | CmtError::set (CmtError::syntax_error, "ParseRequirements> bad strategy keyword"); |
---|
1131 | } |
---|
1132 | } |
---|
1133 | } |
---|
1134 | |
---|
1135 | void action (const CmtSystem::cmt_string_vector& words, |
---|
1136 | Project* project, |
---|
1137 | const cmt_string& file_name, |
---|
1138 | int line_number) |
---|
1139 | { |
---|
1140 | for (int i = 1; i < words.size (); i++) |
---|
1141 | { |
---|
1142 | const cmt_string& w = words[i]; |
---|
1143 | |
---|
1144 | cmt_string strategy; |
---|
1145 | cmt_string value; |
---|
1146 | |
---|
1147 | bool in_error = false; |
---|
1148 | |
---|
1149 | if (decode (w, strategy, value)) |
---|
1150 | { |
---|
1151 | if (project != 0) project->set_strategy (strategy, value, ""); |
---|
1152 | } |
---|
1153 | else |
---|
1154 | { |
---|
1155 | in_error = true; |
---|
1156 | |
---|
1157 | CmtError::set (CmtError::syntax_error, "ParseRequirements> bad strategy keyword"); |
---|
1158 | } |
---|
1159 | } |
---|
1160 | } |
---|
1161 | }; |
---|
1162 | |
---|
1163 | class KwdTag : public Kwd |
---|
1164 | { |
---|
1165 | public: |
---|
1166 | void action (const CmtSystem::cmt_string_vector& words, |
---|
1167 | Use* use, |
---|
1168 | const cmt_string& file_name, |
---|
1169 | int line_number) |
---|
1170 | { |
---|
1171 | Tag::action (words, use); |
---|
1172 | } |
---|
1173 | void action (const CmtSystem::cmt_string_vector& words, |
---|
1174 | Project* project, |
---|
1175 | const cmt_string& file_name, |
---|
1176 | int line_number) |
---|
1177 | { |
---|
1178 | action (words, project->get_use(), file_name, line_number); |
---|
1179 | } |
---|
1180 | }; |
---|
1181 | |
---|
1182 | class KwdTagExclude : public Kwd |
---|
1183 | { |
---|
1184 | public: |
---|
1185 | void action (const CmtSystem::cmt_string_vector& words, |
---|
1186 | Use* use, |
---|
1187 | const cmt_string& file_name, |
---|
1188 | int line_number) |
---|
1189 | { |
---|
1190 | Tag::action_exclude (words, use); |
---|
1191 | } |
---|
1192 | void action (const CmtSystem::cmt_string_vector& words, |
---|
1193 | Project* project, |
---|
1194 | const cmt_string& file_name, |
---|
1195 | int line_number) |
---|
1196 | { |
---|
1197 | action (words, project->get_use(), file_name, line_number); |
---|
1198 | } |
---|
1199 | }; |
---|
1200 | |
---|
1201 | class KwdUse : public Kwd |
---|
1202 | { |
---|
1203 | public: |
---|
1204 | void action (const CmtSystem::cmt_string_vector& words, |
---|
1205 | Use* use, |
---|
1206 | const cmt_string& file_name, |
---|
1207 | int line_number) |
---|
1208 | { |
---|
1209 | Use::action (words, use); |
---|
1210 | } |
---|
1211 | |
---|
1212 | void action (const CmtSystem::cmt_string_vector& words, |
---|
1213 | Project* project, |
---|
1214 | const cmt_string& file_name, |
---|
1215 | int line_number) |
---|
1216 | { |
---|
1217 | project->use_action (words[1], words[2]); |
---|
1218 | } |
---|
1219 | }; |
---|
1220 | |
---|
1221 | class KwdVersionStrategy : public Kwd |
---|
1222 | { |
---|
1223 | public: |
---|
1224 | void action (const CmtSystem::cmt_string_vector& words, |
---|
1225 | Use* use, |
---|
1226 | const cmt_string& file_name, |
---|
1227 | int line_number) |
---|
1228 | { |
---|
1229 | cerr << "# Package " << use->get_package_name () << |
---|
1230 | " sets obsolescent version strategy" << endl; |
---|
1231 | } |
---|
1232 | void action (const CmtSystem::cmt_string_vector& words, |
---|
1233 | Project* project, |
---|
1234 | const cmt_string& file_name, |
---|
1235 | int line_number) |
---|
1236 | {} |
---|
1237 | }; |
---|
1238 | |
---|
1239 | class KwdVersion : public Kwd |
---|
1240 | { |
---|
1241 | public: |
---|
1242 | void action (const CmtSystem::cmt_string_vector& words, |
---|
1243 | Use* use, |
---|
1244 | const cmt_string& file_name, |
---|
1245 | int line_number) |
---|
1246 | { |
---|
1247 | } |
---|
1248 | void action (const CmtSystem::cmt_string_vector& words, |
---|
1249 | Project* project, |
---|
1250 | const cmt_string& file_name, |
---|
1251 | int line_number) |
---|
1252 | {} |
---|
1253 | }; |
---|
1254 | |
---|
1255 | class KwdDefault : public Kwd |
---|
1256 | { |
---|
1257 | public: |
---|
1258 | void action (const CmtSystem::cmt_string_vector& words, |
---|
1259 | Use* use, |
---|
1260 | const cmt_string& file_name, |
---|
1261 | int line_number) |
---|
1262 | { |
---|
1263 | /* |
---|
1264 | Unknown keyword : just ignore the line |
---|
1265 | */ |
---|
1266 | if (!Cmt::get_quiet ()) |
---|
1267 | { |
---|
1268 | cerr << "#CMT> bad syntax in requirements of " << use->get_package_name () |
---|
1269 | << " " << use->version << " line #" << line_number; |
---|
1270 | cerr << " [" << words[0] << "...]" << endl; |
---|
1271 | } |
---|
1272 | |
---|
1273 | CmtError::set (CmtError::syntax_error, "ParseRequirements> "); |
---|
1274 | } |
---|
1275 | |
---|
1276 | void action (const CmtSystem::cmt_string_vector& words, |
---|
1277 | Project* project, |
---|
1278 | const cmt_string& file_name, |
---|
1279 | int line_number) |
---|
1280 | {} |
---|
1281 | }; |
---|
1282 | |
---|
1283 | SyntaxParser& SyntaxParser::instance () |
---|
1284 | { |
---|
1285 | static SyntaxParser p; |
---|
1286 | |
---|
1287 | return (p); |
---|
1288 | } |
---|
1289 | |
---|
1290 | /** |
---|
1291 | * Parse the input file, rejecting comments and |
---|
1292 | * rebuilding complete lines (from sections separated by |
---|
1293 | * \ characters. |
---|
1294 | * |
---|
1295 | * Each reformatted line is parsed by filter_line |
---|
1296 | */ |
---|
1297 | void SyntaxParser::parse_requirements (const cmt_string& file_name, Use* use) |
---|
1298 | { |
---|
1299 | SyntaxParser& me = instance (); |
---|
1300 | |
---|
1301 | if (use != 0) |
---|
1302 | { |
---|
1303 | cmt_string buffer; |
---|
1304 | |
---|
1305 | use->fill_standard_macros (buffer); |
---|
1306 | |
---|
1307 | AccessMode saved_current_access = Cmt::get_current_access (); |
---|
1308 | Cmt::set_current_access (UserMode); |
---|
1309 | me.do_parse_text (buffer, "", package_context, use, 0); |
---|
1310 | Cmt::set_current_access (saved_current_access); |
---|
1311 | } |
---|
1312 | |
---|
1313 | // |
---|
1314 | Project* p = use->get_project (); |
---|
1315 | if (p != 0) |
---|
1316 | { |
---|
1317 | Use* p_use = p->get_use(); |
---|
1318 | if (p_use != 0) |
---|
1319 | { |
---|
1320 | //cout << "About to add dependency on project policy package file [" << p_use->get_package_name() << "]" << endl; |
---|
1321 | p_use->add_sub_use (p_use); |
---|
1322 | } |
---|
1323 | } |
---|
1324 | |
---|
1325 | me.do_parse_requirements (file_name, use); |
---|
1326 | |
---|
1327 | if (use != 0) |
---|
1328 | { |
---|
1329 | use->close_scope_sections (); |
---|
1330 | } |
---|
1331 | } |
---|
1332 | |
---|
1333 | /** |
---|
1334 | */ |
---|
1335 | void SyntaxParser::parse_project_file_text (const cmt_string& text, |
---|
1336 | const cmt_string& file_name, |
---|
1337 | Project* project) |
---|
1338 | { |
---|
1339 | SyntaxParser& me = instance (); |
---|
1340 | me.do_parse_text (text, file_name, project_context, 0, project); |
---|
1341 | } |
---|
1342 | |
---|
1343 | /** |
---|
1344 | * Parse a text, rejecting comments and |
---|
1345 | * rebuilding complete lines (from sections separated by |
---|
1346 | * \ characters. |
---|
1347 | * |
---|
1348 | * Each reformatted line is parsed by filter_line |
---|
1349 | */ |
---|
1350 | void SyntaxParser::parse_requirements_text (const cmt_string& text, |
---|
1351 | const cmt_string& file_name, |
---|
1352 | Use* use) |
---|
1353 | { |
---|
1354 | SyntaxParser& me = instance (); |
---|
1355 | |
---|
1356 | /** |
---|
1357 | * |
---|
1358 | * We have to preserve m_current_access since it reflects whether |
---|
1359 | * the current cmt action is run in the context of the current package. |
---|
1360 | * (the opposite is when the cmt command specifies the current package |
---|
1361 | * in its arguments -use=... therefore the pwd is NOT the directory |
---|
1362 | * of the current package) |
---|
1363 | * |
---|
1364 | * m_current_access is Developer when pwd = current |
---|
1365 | * User when pwd != current |
---|
1366 | * |
---|
1367 | * Therefore, as soon as we reach a used package, this must be switched to User |
---|
1368 | * |
---|
1369 | * On the other hand, Cmt::scope reflects the status of the public/private |
---|
1370 | * statements. By default, we are in public context when entering a new requirements |
---|
1371 | * file. |
---|
1372 | * |
---|
1373 | */ |
---|
1374 | |
---|
1375 | AccessMode saved_current_access; |
---|
1376 | |
---|
1377 | saved_current_access = Cmt::get_current_access (); |
---|
1378 | |
---|
1379 | if (use == 0) use = &(Use::current ()); |
---|
1380 | |
---|
1381 | if (use != &(Use::current ())) |
---|
1382 | { |
---|
1383 | if (Cmt::get_debug ()) |
---|
1384 | { |
---|
1385 | cout << "parse_requirements_text> set UserMode" << endl; |
---|
1386 | } |
---|
1387 | |
---|
1388 | Cmt::set_current_access (UserMode); |
---|
1389 | } |
---|
1390 | else |
---|
1391 | { |
---|
1392 | if (Cmt::get_debug ()) |
---|
1393 | { |
---|
1394 | cout << "parse_requirements_text> set DeveloperMode" << endl; |
---|
1395 | } |
---|
1396 | |
---|
1397 | Cmt::set_current_access (DeveloperMode); |
---|
1398 | } |
---|
1399 | |
---|
1400 | me.do_parse_text (text, file_name, package_context, use, 0); |
---|
1401 | |
---|
1402 | Cmt::set_current_access (saved_current_access); |
---|
1403 | } |
---|
1404 | |
---|
1405 | /** |
---|
1406 | * Apply the basic parser to one single line : |
---|
1407 | * |
---|
1408 | * o Append to global text if previous back_slash |
---|
1409 | * o Split into words |
---|
1410 | * o Apply the generic Select operator |
---|
1411 | */ |
---|
1412 | void SyntaxParser::parse_requirements_line (const cmt_string& line, |
---|
1413 | Use* use, |
---|
1414 | const cmt_string& file_name, |
---|
1415 | int line_number) |
---|
1416 | { |
---|
1417 | SyntaxParser& me = instance (); |
---|
1418 | me.do_parse_line (line, file_name, line_number, package_context, use, 0); |
---|
1419 | } |
---|
1420 | |
---|
1421 | SyntaxParser::SyntaxParser () |
---|
1422 | { |
---|
1423 | m_keywords.add ("action", new KwdAction ()); |
---|
1424 | m_keywords.add ("alias", new KwdAlias ()); |
---|
1425 | m_keywords.add ("application", new KwdApplication ()); |
---|
1426 | m_keywords.add ("apply_pattern", new KwdApplyPattern ()); |
---|
1427 | m_keywords.add ("apply_tag", new KwdApplyTag ()); |
---|
1428 | m_keywords.add ("author", new KwdAuthor ()); |
---|
1429 | m_keywords.add ("branches", new KwdBranches ()); |
---|
1430 | m_keywords.add ("build_strategy", new KwdBuildStrategy ()); |
---|
1431 | m_keywords.add ("cleanup_script", new KwdCleanupScript ()); |
---|
1432 | m_keywords.add ("cmtpath_pattern", new KwdCmtPathPattern ()); |
---|
1433 | m_keywords.add ("cmtpath_pattern_reverse", new KwdCmtPathPatternRevert ()); |
---|
1434 | m_keywords.add ("document", new KwdDocument ()); |
---|
1435 | m_keywords.add ("end_private", new KwdEndPrivate ()); |
---|
1436 | m_keywords.add ("end_public", new KwdEndPublic ()); |
---|
1437 | m_keywords.add ("ignore_pattern", new KwdIgnorePattern ()); |
---|
1438 | m_keywords.add ("include_dirs", new KwdIncludeDirs ()); |
---|
1439 | m_keywords.add ("include_path", new KwdIncludePath ()); |
---|
1440 | m_keywords.add ("language", new KwdLanguage ()); |
---|
1441 | m_keywords.add ("library", new KwdLibrary ()); |
---|
1442 | m_keywords.add ("macro", new KwdMacro ()); |
---|
1443 | m_keywords.add ("macro+", new KwdMacroAppend ()); |
---|
1444 | m_keywords.add ("macro_prepend", new KwdMacroPrepend ()); |
---|
1445 | m_keywords.add ("macro_append", new KwdMacroAppend ()); |
---|
1446 | m_keywords.add ("macro_remove", new KwdMacroRemove ()); |
---|
1447 | m_keywords.add ("macro_remove_regexp", new KwdMacroRemoveRegexp ()); |
---|
1448 | m_keywords.add ("macro_remove_all", new KwdMacroRemoveAll ()); |
---|
1449 | m_keywords.add ("macro_remove_all_regexp", new KwdMacroRemoveAllRegexp ()); |
---|
1450 | m_keywords.add ("make_fragment", new KwdMakeFragment ()); |
---|
1451 | m_keywords.add ("manager", new KwdManager ()); |
---|
1452 | m_keywords.add ("package", new KwdPackage ()); |
---|
1453 | m_keywords.add ("path", new KwdPath ()); |
---|
1454 | m_keywords.add ("path_append", new KwdPathAppend ()); |
---|
1455 | m_keywords.add ("path_prepend", new KwdPathPrepend ()); |
---|
1456 | m_keywords.add ("path_remove", new KwdPathRemove ()); |
---|
1457 | m_keywords.add ("path_remove_regexp", new KwdPathRemoveRegexp ()); |
---|
1458 | m_keywords.add ("pattern", new KwdPattern ()); |
---|
1459 | m_keywords.add ("public", new KwdPublic ()); |
---|
1460 | m_keywords.add ("private", new KwdPrivate ()); |
---|
1461 | m_keywords.add ("project", new KwdProject ()); |
---|
1462 | m_keywords.add ("set", new KwdSet ()); |
---|
1463 | m_keywords.add ("set_append", new KwdSetAppend ()); |
---|
1464 | m_keywords.add ("set_prepend", new KwdSetPrepend ()); |
---|
1465 | m_keywords.add ("set_remove", new KwdSetRemove ()); |
---|
1466 | m_keywords.add ("set_remove_regexp", new KwdSetRemoveRegexp ()); |
---|
1467 | m_keywords.add ("setup_script", new KwdSetupScript ()); |
---|
1468 | m_keywords.add ("setup_strategy", new KwdSetupStrategy ()); |
---|
1469 | m_keywords.add ("structure_strategy", new KwdStructureStrategy ()); |
---|
1470 | m_keywords.add ("tag", new KwdTag ()); |
---|
1471 | m_keywords.add ("tag_exclude", new KwdTagExclude ()); |
---|
1472 | m_keywords.add ("use", new KwdUse ()); |
---|
1473 | m_keywords.add ("version_strategy", new KwdVersionStrategy ()); |
---|
1474 | m_keywords.add ("version", new KwdVersion ()); |
---|
1475 | |
---|
1476 | m_project_keywords.add ("author", new KwdAuthor()); |
---|
1477 | //m_project_keywords.add ("apply_tag", new KwdApplyTag ()); |
---|
1478 | m_project_keywords.add ("build_strategy", new KwdBuildStrategy ()); |
---|
1479 | m_project_keywords.add ("container", new KwdContainer ()); |
---|
1480 | // m_project_keywords.add ("macro", new KwdMacro ()); |
---|
1481 | // m_project_keywords.add ("macro+", new KwdMacroAppend ()); |
---|
1482 | // m_project_keywords.add ("macro_prepend", new KwdMacroPrepend ()); |
---|
1483 | // m_project_keywords.add ("macro_append", new KwdMacroAppend ()); |
---|
1484 | //m_project_keywords.add ("macro_remove", new KwdMacroRemove ()); |
---|
1485 | //m_project_keywords.add ("macro_remove_regexp", new KwdMacroRemoveRegexp ()); |
---|
1486 | //m_project_keywords.add ("macro_remove_all", new KwdMacroRemoveAll ()); |
---|
1487 | //m_project_keywords.add ("macro_remove_all_regexp", new KwdMacroRemoveAllRegexp ()); |
---|
1488 | |
---|
1489 | m_project_keywords.add ("project", new KwdProject ()); |
---|
1490 | m_project_keywords.add ("setup_strategy", new KwdSetupStrategy ()); |
---|
1491 | |
---|
1492 | //m_project_keywords.add ("tag", new KwdTag ()); |
---|
1493 | //m_project_keywords.add ("tag_exclude", new KwdTagExclude ()); |
---|
1494 | |
---|
1495 | |
---|
1496 | m_project_keywords.add ("structure_strategy", new KwdStructureStrategy ()); |
---|
1497 | m_project_keywords.add ("use", new KwdUse ()); |
---|
1498 | } |
---|
1499 | |
---|
1500 | void SyntaxParser::do_parse_requirements (const cmt_string& file_name, Use* use) |
---|
1501 | { |
---|
1502 | cmt_string actual_file_name = file_name; |
---|
1503 | cmt_string text; |
---|
1504 | |
---|
1505 | CmtError::clear (); |
---|
1506 | |
---|
1507 | if (!CmtSystem::test_file (actual_file_name)) |
---|
1508 | { |
---|
1509 | actual_file_name = ".."; |
---|
1510 | actual_file_name += CmtSystem::file_separator (); |
---|
1511 | actual_file_name += "cmt"; |
---|
1512 | actual_file_name += CmtSystem::file_separator (); |
---|
1513 | actual_file_name += file_name; |
---|
1514 | |
---|
1515 | if (!CmtSystem::test_file (actual_file_name)) |
---|
1516 | { |
---|
1517 | actual_file_name = ".."; |
---|
1518 | actual_file_name += CmtSystem::file_separator (); |
---|
1519 | actual_file_name += "mgr"; |
---|
1520 | actual_file_name += CmtSystem::file_separator (); |
---|
1521 | actual_file_name += file_name; |
---|
1522 | |
---|
1523 | if (!CmtSystem::test_file (actual_file_name)) |
---|
1524 | { |
---|
1525 | return; |
---|
1526 | } |
---|
1527 | } |
---|
1528 | } |
---|
1529 | |
---|
1530 | text.read (actual_file_name); |
---|
1531 | |
---|
1532 | SyntaxParser::parse_requirements_text (text, actual_file_name, use); |
---|
1533 | } |
---|
1534 | |
---|
1535 | /** |
---|
1536 | * Parse a text, rejecting comments and |
---|
1537 | * rebuilding complete lines (from sections separated by |
---|
1538 | * \ characters. |
---|
1539 | * |
---|
1540 | * Each reformatted line is parsed by filter_line |
---|
1541 | */ |
---|
1542 | void SyntaxParser::do_parse_text (const cmt_string& text, |
---|
1543 | const cmt_string& file_name, |
---|
1544 | ContextType context, |
---|
1545 | Use* use, |
---|
1546 | Project* project) |
---|
1547 | { |
---|
1548 | cmt_string line; |
---|
1549 | int pos; |
---|
1550 | int max_pos; |
---|
1551 | int line_number = 1; |
---|
1552 | |
---|
1553 | if (context == package_context) |
---|
1554 | { |
---|
1555 | if (use == 0) use = &(Use::current ()); |
---|
1556 | } |
---|
1557 | |
---|
1558 | m_filtered_text.erase (0); |
---|
1559 | |
---|
1560 | pos = 0; |
---|
1561 | max_pos = text.size (); |
---|
1562 | |
---|
1563 | for (pos = 0; pos < max_pos;) |
---|
1564 | { |
---|
1565 | int cr = text.find (pos, "\r\n"); |
---|
1566 | int nl = text.find (pos, '\n'); |
---|
1567 | int first = nl; |
---|
1568 | int length = 1; |
---|
1569 | |
---|
1570 | if (cr != cmt_string::npos) |
---|
1571 | { |
---|
1572 | if (nl == cmt_string::npos) |
---|
1573 | { |
---|
1574 | first = cr; |
---|
1575 | length = 2; |
---|
1576 | } |
---|
1577 | else |
---|
1578 | { |
---|
1579 | first = (nl < cr) ? nl : cr; |
---|
1580 | length = (nl < cr) ? 1 : 2; |
---|
1581 | } |
---|
1582 | } |
---|
1583 | |
---|
1584 | if (first == cmt_string::npos) |
---|
1585 | { |
---|
1586 | text.substr (pos, line); |
---|
1587 | pos = max_pos; |
---|
1588 | } |
---|
1589 | else if (first > pos) |
---|
1590 | { |
---|
1591 | text.substr (pos, first - pos, line); |
---|
1592 | pos = first + length; |
---|
1593 | } |
---|
1594 | else |
---|
1595 | { |
---|
1596 | line.erase (0); |
---|
1597 | pos += length; |
---|
1598 | } |
---|
1599 | |
---|
1600 | do_parse_line (line, file_name, line_number, context, use, project); |
---|
1601 | |
---|
1602 | if ((Cmt::get_action () == action_check_configuration) && CmtError::has_pending_error ()) |
---|
1603 | { |
---|
1604 | //break; |
---|
1605 | } |
---|
1606 | |
---|
1607 | line_number++; |
---|
1608 | } |
---|
1609 | } |
---|
1610 | |
---|
1611 | void SyntaxParser::do_parse_line (const cmt_string& line, |
---|
1612 | const cmt_string& file_name, |
---|
1613 | int line_number, |
---|
1614 | ContextType context, |
---|
1615 | Use* use, |
---|
1616 | Project* project) |
---|
1617 | { |
---|
1618 | int length; |
---|
1619 | int nl; |
---|
1620 | int back_slash; |
---|
1621 | cmt_string temp_line = line; |
---|
1622 | |
---|
1623 | if (temp_line.size () == 0) return; |
---|
1624 | if (temp_line[0] == '#') return; |
---|
1625 | |
---|
1626 | nl = temp_line.find_last_of ('\n'); |
---|
1627 | if (nl != cmt_string::npos) temp_line.erase (nl); |
---|
1628 | |
---|
1629 | length = temp_line.size (); |
---|
1630 | if (length == 0) return; |
---|
1631 | |
---|
1632 | // |
---|
1633 | // We scan the line for handling backslashes. |
---|
1634 | // |
---|
1635 | // o Really terminating backslashes (ie those only followed by spaces/tabs |
---|
1636 | // mean continued line |
---|
1637 | // |
---|
1638 | // |
---|
1639 | |
---|
1640 | bool finished = true; |
---|
1641 | |
---|
1642 | length = temp_line.size (); |
---|
1643 | |
---|
1644 | back_slash = temp_line.find_last_of ('\\'); |
---|
1645 | |
---|
1646 | if (back_slash != cmt_string::npos) |
---|
1647 | { |
---|
1648 | // |
---|
1649 | // This is the last backslash |
---|
1650 | // check if there are only space chars after it |
---|
1651 | // |
---|
1652 | |
---|
1653 | bool at_end = true; |
---|
1654 | |
---|
1655 | for (int i = (back_slash + 1); i < length; i++) |
---|
1656 | { |
---|
1657 | char c = temp_line[i]; |
---|
1658 | if ((c != ' ') && (c != '\t')) |
---|
1659 | { |
---|
1660 | at_end = false; |
---|
1661 | break; |
---|
1662 | } |
---|
1663 | } |
---|
1664 | |
---|
1665 | if (at_end) |
---|
1666 | { |
---|
1667 | temp_line.erase (back_slash); |
---|
1668 | finished = false; |
---|
1669 | } |
---|
1670 | else |
---|
1671 | { |
---|
1672 | // This was not a trailing backslash. |
---|
1673 | finished = true; |
---|
1674 | } |
---|
1675 | } |
---|
1676 | |
---|
1677 | m_filtered_text += temp_line; |
---|
1678 | |
---|
1679 | if (!finished) |
---|
1680 | { |
---|
1681 | // We still need to accumulate forthcoming lines |
---|
1682 | // before parsing the resulting text. |
---|
1683 | return; |
---|
1684 | } |
---|
1685 | |
---|
1686 | /* |
---|
1687 | Here a full line (possibly accumulating several lines |
---|
1688 | ended by backslashes) is parsed : |
---|
1689 | |
---|
1690 | o Special characters are filtered now : |
---|
1691 | |
---|
1692 | <cmt:tab/> \t |
---|
1693 | <cmt:cr/> \r |
---|
1694 | <cmt:lf/> \n |
---|
1695 | |
---|
1696 | o Split into words (a word is a string not containing |
---|
1697 | spaces or enclosed in quotes) |
---|
1698 | |
---|
1699 | o Parse the word array (function Select) |
---|
1700 | |
---|
1701 | */ |
---|
1702 | |
---|
1703 | m_filtered_text.replace_all ("<cmt:tab/>", "\t"); |
---|
1704 | m_filtered_text.replace_all ("<cmt:cr/>", "\r"); |
---|
1705 | m_filtered_text.replace_all ("<cmt:lf/>", "\n"); |
---|
1706 | |
---|
1707 | if (Cmt::get_debug ()) |
---|
1708 | { |
---|
1709 | cout << "parse_requirements_line [" << m_filtered_text << "]" << endl; |
---|
1710 | } |
---|
1711 | |
---|
1712 | static CmtSystem::cmt_string_vector words; |
---|
1713 | |
---|
1714 | CmtSystem::split (m_filtered_text, " \t", words); |
---|
1715 | |
---|
1716 | if (words.size () != 0) |
---|
1717 | { |
---|
1718 | switch (context) |
---|
1719 | { |
---|
1720 | case project_context: |
---|
1721 | do_parse_words (words, file_name, line_number, project); |
---|
1722 | break; |
---|
1723 | case package_context: |
---|
1724 | do_parse_words (words, file_name, line_number, use); |
---|
1725 | break; |
---|
1726 | } |
---|
1727 | } |
---|
1728 | |
---|
1729 | m_filtered_text.erase (0); |
---|
1730 | } |
---|
1731 | |
---|
1732 | void SyntaxParser::do_parse_words (const CmtSystem::cmt_string_vector& words, |
---|
1733 | const cmt_string& file_name, |
---|
1734 | int line_number, |
---|
1735 | Use* use) |
---|
1736 | { |
---|
1737 | CmtError::clear (); |
---|
1738 | |
---|
1739 | if (words.size () == 0) return; |
---|
1740 | |
---|
1741 | const cmt_string& command = words[0]; |
---|
1742 | |
---|
1743 | if (command.size () == 0) return; |
---|
1744 | |
---|
1745 | // |
---|
1746 | // First analyze the syntax |
---|
1747 | // |
---|
1748 | |
---|
1749 | Kwd* keyword = m_keywords.find (command); |
---|
1750 | if (keyword == 0) |
---|
1751 | { |
---|
1752 | /* |
---|
1753 | |
---|
1754 | When the first word of the line is not a keyword, it may be an |
---|
1755 | implicit pattern application. |
---|
1756 | |
---|
1757 | */ |
---|
1758 | |
---|
1759 | Pattern* p = Pattern::find (command); |
---|
1760 | if (p == 0) |
---|
1761 | { |
---|
1762 | CmtError::set (CmtError::syntax_error, "ParseRequirements> "); |
---|
1763 | } |
---|
1764 | else |
---|
1765 | { |
---|
1766 | keyword = m_keywords.find ("apply_pattern"); |
---|
1767 | } |
---|
1768 | } |
---|
1769 | |
---|
1770 | if (CmtError::has_pending_error ()) |
---|
1771 | { |
---|
1772 | if (!Cmt::get_quiet ()) |
---|
1773 | { |
---|
1774 | cerr << "#CMT> bad syntax in requirements of " << use->get_package_name () |
---|
1775 | << " " << use->version |
---|
1776 | << " " << use->specified_path |
---|
1777 | << " line #" << line_number; |
---|
1778 | cerr << " [" << command << " ...]" << endl; |
---|
1779 | } |
---|
1780 | |
---|
1781 | return; |
---|
1782 | } |
---|
1783 | |
---|
1784 | // |
---|
1785 | // Then interpret the action |
---|
1786 | // |
---|
1787 | |
---|
1788 | keyword->action (words, use, file_name, line_number); |
---|
1789 | } |
---|
1790 | |
---|
1791 | void SyntaxParser::do_parse_words (const CmtSystem::cmt_string_vector& words, |
---|
1792 | const cmt_string& file_name, |
---|
1793 | int line_number, |
---|
1794 | Project* project) |
---|
1795 | { |
---|
1796 | CmtError::clear (); |
---|
1797 | |
---|
1798 | if (words.size () == 0) return; |
---|
1799 | |
---|
1800 | const cmt_string& command = words[0]; |
---|
1801 | |
---|
1802 | if (command.size () == 0) return; |
---|
1803 | |
---|
1804 | // |
---|
1805 | // First analyze the syntax |
---|
1806 | // |
---|
1807 | |
---|
1808 | Kwd* keyword = m_project_keywords.find (command); |
---|
1809 | if (keyword == 0) |
---|
1810 | { |
---|
1811 | CmtError::set (CmtError::syntax_error, "ParseRequirements> "); |
---|
1812 | } |
---|
1813 | |
---|
1814 | if (CmtError::has_pending_error ()) |
---|
1815 | { |
---|
1816 | if (!Cmt::get_quiet ()) |
---|
1817 | { |
---|
1818 | cerr << "#CMT> bad syntax in project file of " << project->get_name () |
---|
1819 | << " line #" << line_number; |
---|
1820 | cerr << " [" << command << " ...]" << endl; |
---|
1821 | } |
---|
1822 | |
---|
1823 | return; |
---|
1824 | } |
---|
1825 | |
---|
1826 | // |
---|
1827 | // Then interpret the action |
---|
1828 | // |
---|
1829 | |
---|
1830 | keyword->action (words, project, file_name, line_number); |
---|
1831 | } |
---|
1832 | |
---|
1833 | |
---|
1834 | |
---|
1835 | |
---|