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