source: to-imperative/trunk/compiler/rfp_asail_cpp.rf @ 2043

Last change on this file since 2043 was 2043, checked in by orlov, 14 years ago
  • Improved block extraction from result expressions.
  • Use asail2asail when converting to C++.
  • Remove duplicate declarations after cleanup of blocks

(rfp_asail2asail.Remove-Dupl-Decl).

  • Proper generation of debug info for $iter.
  • Fixed pragma-generation when comments are used.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 17.4 KB
Line 
1// $Source$
2// $Revision: 2043 $
3// $Date: 2006-08-01 17:25:13 +0000 (Tue, 01 Aug 2006) $
4
5$use Apply Arithm Box Class Compare Convert CppMangle List StdIO Table;
6$use "rfpc";
7$use "rfp_helper";
8
9$box Int;
10
11$box Module-Name;
12
13$box Current-Namespace;
14
15$box Current-Func;
16
17$box Current-Trace;
18
19$box Entry;
20
21$box Entry-Name;
22
23$box Const-Exprs;
24
25$table Externs;
26
27$func ASAIL-To-CPP e.body = e.cpp-code;
28
29$func Namespace-Control e.qualifiers = e.namespace-control;
30
31$func Expr-To-CPP (e.ASAIL-Expr-init) e.ASAIL-Expr-rest = e.ASAIL-Expr;
32
33$func Expr-Ref-To-CPP e.ASAIL-Expr-Ref = e.CPP-Expr-Ref;
34
35$func Expr-Int-To-CPP e.ASAIL-Expr-Int = e.CPP-Expr-Int;
36
37$func Step-To-CPP e.step-operators = e.cpp-step-operators;
38
39$func Const-Expr-To-CPP e.ASAIL-const-expr = e.CPP-const-expr;
40
41$func Args-To-CPP (e.prefix) s.Arg-Res-Tag e.ASAIL-Args = e.CPP-Args;
42
43$func Symbol-To-CPP s.RFP-Symbol = e.CPP-String;
44
45$func Name-To-CPP t.name = e.CPP-Name;
46
47$func Cond-To-CPP e.cond = e.CPP-Cond;
48
49$func Infix-To-CPP s.func-for-converting-args-to-cpp s.op e.args = e.cpp-expr;
50
51$func Op-Arg-To-CPP s.op = s.func-for-converting-args-to-cpp;
52
53$func Trace-Enter e.name (e.args) = e.trace;
54$func Trace-Exit  e.name (e.ress) = e.trace;
55$func Trace-Fail  e.name          = e.trace;
56
57$func Extract-Qualifiers t.name = (e.qualifiers) e.name;
58
59
60RFP-ASAIL-To-CPP (e.ModuleName) e.asail =
61  {
62    <Store &Int <Lookup &RFP-Options INT>>;
63    <Store &Int Integer>;
64  },
65  <Store &Module-Name e.ModuleName>,
66  <Store &Current-Namespace /*empty*/>,
67  <Store &Entry (e.ModuleName Main)>,
68  <Store &Entry-Name /*empty*/>,
69  <Store &Const-Exprs /*empty*/>,
70  <RFP-Clear-Table &Externs>,
71  {
72    <ASAIL-To-CPP e.asail> : v.cpp,
73      {
74        <? &Current-Namespace> : v = ('}');;  // close last namespace
75      } :: e.close-namespace,
76      <Store &Current-Namespace /*empty*/>,
77      {
78        <? &Entry-Name> : v.name = ('rfrt::Entry rf_entry (' v.name ');');;
79      } :: e.entry,
80      {
81        <? &Const-Exprs> : v.c-exprs =
82          (/*e.init-consts*/) <? &Const-Exprs> $iter {
83            e.c-exprs : (e.cpp-name (e.value)) e.rest =
84              (e.init-consts (e.cpp-name ' = ' e.value ';')) e.rest;
85          } :: (e.init-consts) e.c-exprs,
86          e.c-exprs : /*empty*/ =
87          <Namespace-Control <? &Module-Name>>
88          ('static void init_ ()\n{' (e.init-consts) '}')
89          ('static AtStart init_registrator_ (&init_);')
90          ('}');;
91      } :: e.init,
92      ('namespace refal\n{')
93      ('using namespace rfrt;')
94      v.cpp e.close-namespace e.init e.entry
95      ('}');;
96  };
97
98ASAIL-To-CPP e.asail, {
99  e.asail : t.item e.rest, t.item : {
100    (s.tag t.name (e.args) (e.ress) e.body),
101      s.tag : \{
102        FUNC  = ('void') /*empty*/;
103        FUNC? = ('boolean') ('return true;');
104      } :: (e.return-type) e.return =
105      <Store &Current-Func t.name>,
106      { <? &Entry> : t.name = <Store &Entry-Name <Rfp2Cpp t.name>>;; },
107      {
108        \{
109          <In-Table? &RFP-Options TRACEALL>;
110          <In-Table? &RFP-Trace t.name>;
111        } =
112          <Intersperse ('.') <Concat t.name>> :: e.name,
113          <Store &Current-Trace e.name (e.ress)>,
114          (<Trace-Enter e.name (e.args)>) (<Trace-Exit e.name (e.ress)>);
115        <Store &Current-Trace /*empty*/>,
116          () ();
117      } :: (e.trace-enter) (e.trace-exit),
118      <Extract-Qualifiers t.name> :: (e.qualifiers) e.name,
119      <Namespace-Control e.qualifiers>
120      ('RF_FUNC (' <Rfp2Cpp e.name> ', '
121            <Args-To-CPP ('RF_ARG ') Vars e.args> ', '
122            <Args-To-CPP ('RF_RES ') Vars e.ress> ')'
123        (e.trace-enter <ASAIL-To-CPP e.body> e.trace-exit)
124       'RF_END');
125    (TRACE t.name) =
126      <Bind &RFP-Trace (t.name) ()>;
127    (IF (e.cond) e.body) =
128      ('if (' <Cond-To-CPP e.cond> ')')
129      ('{' (<ASAIL-To-CPP e.body>) '}');
130    (FOR (e.cont-label) (e.break-label) (e.cond) (e.step) e.body) =
131      {
132        e.cont-label : t =
133          ('{'
134            ('{' (<ASAIL-To-CPP e.body>) '}')
135            (LABEL <Rfp2Cpp (LABEL e.cont-label)> ': {}')
136          '}');
137        ('{' (<ASAIL-To-CPP e.body>) '}');
138      } :: e.body,
139      {
140        e.break-label : t = (LABEL <Rfp2Cpp (LABEL e.break-label)> ': {}');;
141      } :: e.break,
142      ('for ( ; ' <Cond-To-CPP e.cond> '; ' <Step-To-CPP e.step> ')') e.body e.break;
143    (LABEL (e.label) e.body) =
144//      {
145//        e.label : /*empty*/ =
146//          ('{' (<ASAIL-To-CPP e.body>) '}' );
147        ('{' (<ASAIL-To-CPP e.body>) '}')
148        (LABEL <Rfp2Cpp (LABEL e.label)> ': {}');
149//      };
150    (TRY e.body) =
151      ('RF_TRAP') ('{' (<ASAIL-To-CPP e.body>) '}');
152    (CATCH-ERROR e.body) =
153      ('RF_WITH') ('{' (('RF_CLEANUP;') <ASAIL-To-CPP e.body>) '}');
154    RETURN =
155      {
156        <? &Current-Trace> : e.name (e.ress) =
157          <Trace-Exit e.name (e.ress)>;
158        /*empty*/;
159      } :: e.trace-exit,
160      e.trace-exit ('return true;');
161    RETFAIL =
162      {
163        <? &Current-Trace> : e.name (e.ress) =
164          <Trace-Fail e.name>;
165        /*empty*/;
166      } :: e.trace-exit,
167      e.trace-exit ('RF_RETFAIL;');
168    FATAL =
169//      <? &Current-Func> : (e.name),
170      ('RF_FUNC_ERROR (unexpected_fail);');
171    (LSPLIT e.expr (e.min) t.var1 t.var2) =
172      ('RF_lsplit (' <Expr-Ref-To-CPP e.expr> ', ' <Expr-Int-To-CPP e.min> ', '
173      <Rfp2Cpp t.var1> ', ' <Rfp2Cpp t.var2> ');');
174    (RSPLIT e.expr (e.min) t.var1 t.var2) =
175      ('RF_rsplit (' <Expr-Ref-To-CPP e.expr> ', ' <Expr-Int-To-CPP e.min> ', '
176      <Rfp2Cpp t.var1> ', ' <Rfp2Cpp t.var2 > ');');
177    (ASSIGN t.var e.expr) =
178      (<Rfp2Cpp t.var> ' = ' <Expr-To-CPP () e.expr> ';');
179    (DECL s.type t.var) =
180      ('Expr ' <Rfp2Cpp t.var> ';');
181    (INT  t.var e.expr) =
182      ('uintptr_t ' <Rfp2Cpp t.var> ' = ' <Expr-Int-To-CPP e.expr> ';');
183    (EXPR t.var e.expr) =
184      ('Expr ' <Rfp2Cpp t.var> ' (' <Expr-Ref-To-CPP e.expr> ');');
185    (DEREF t.var e.expr (e.pos)) =
186      ('Expr ' <Rfp2Cpp t.var> ' (' <Expr-Ref-To-CPP e.expr> ', '
187      <Expr-Int-To-CPP e.pos> ');');
188    (SUBEXPR t.var e.expr (e.pos) (e.len)) =
189      ('Expr ' <Rfp2Cpp t.var> ' ('
190      <Expr-Ref-To-CPP e.expr> ', ' <Expr-Int-To-CPP e.pos> ', '
191      <Expr-Int-To-CPP e.len> ');');
192    (DROP t.var) =
193      (<Rfp2Cpp t.var> '.drop ();');
194    (CONTINUE t.label) =
195      ('goto ' <Rfp2Cpp (LABEL t.label)> ';');
196    (BREAK t.label) =
197      ('goto ' <Rfp2Cpp (LABEL t.label)> ';');
198    (ERROR e.expr) =
199      ('RF_ERROR (' <Expr-Ref-To-CPP e.expr> ');');
200    (CONSTEXPR s.linkage t.name (e.comment) e.expr) =
201      { s.linkage : LOCAL = 'static ';; } :: e.linkage,
202      {
203        t.name : (STATIC e) = (<? &Module-Name>) t.name;
204        <Extract-Qualifiers t.name>;
205      } :: (e.qualifiers) e.name,
206      <Rfp2Cpp e.name> :: e.cpp-name,
207      <Put &Const-Exprs (e.cpp-name (<Const-Expr-To-CPP e.expr>))>,
208      <Namespace-Control e.qualifiers>
209      (e.linkage 'Expr ' e.cpp-name ';');
210    (OBJ s.linkage s.tag t.name) =
211      { s.linkage : LOCAL = 'static ';; } :: e.linkage,
212      <To-Chars s.tag> : s1 e2,
213      <Extract-Qualifiers t.name> :: (e.qualifiers) e.name,
214      <Rfp2Cpp e.name> :: e.cpp-name,
215      {
216        s.tag : BOX =
217          <Put &Const-Exprs (e.cpp-name
218            ('Expr::create_sym< rftype::NamedObject<rftype::BoxContents> >('
219              'L"'e.name'")'))>;
220//        s.tag : VECTOR =
221//          <Put &Const-Exprs (e.cpp-name
222//            ('Expr::create_sym< rftype::NamedObject<rftype::Vector> >('
223//              'L"'e.name'")'))>;
224        <Put &Const-Exprs (e.cpp-name
225          ('new rftype::StaticObject<rftype::' s1 <To-Lower e2> '>(L"'e.name'")'))>;
226      },
227      <Namespace-Control e.qualifiers>
228      (e.linkage 'Expr ' e.cpp-name ';');
229    (DECL-OBJ t.name) =
230      <Extract-Qualifiers t.name> :: (e.qualifiers) e.name,
231      <Namespace-Control e.qualifiers>
232      ('extern Expr ' <Rfp2Cpp e.name> ';');
233    (DECL-FUNC t.name) =
234      <Extract-Qualifiers t.name> :: (e.qualifiers) e.name,
235      <Namespace-Control e.qualifiers>
236      ('RF_DECL (' <Rfp2Cpp e.name> ');');
237    (EXTERN t.name) =
238      <Bind &Externs (t.name) ()>,
239      <Extract-Qualifiers t.name> :: (e.qualifiers) e.name,
240      <Namespace-Control e.qualifiers>
241      ('RF_DECL (' <Rfp2Cpp e.name> ');');
242    /*
243     * s.call can be CALL or TAILCALL or TAILCALL?
244     */
245    (s.call t.name (e.exprs) (e.ress)) =
246      {
247        # \{ s.call : CALL; }, <? &Current-Trace> : e.full-name (e.ress) =
248          ('if (RF_CALL (' <Name-To-CPP t.name> ', '
249            <Args-To-CPP () Exprs e.exprs> ', ' <Args-To-CPP () Vars e.ress> '))')
250          ('{' (<Trace-Exit e.full-name (e.ress)> ('return true;')) '}')
251          ('else RF_RETFAIL;');
252        {
253          s.call : TAILCALL? = TAILCALL;
254          s.call;
255        } :: s.call,
256          ('RF_' s.call ' (' <Name-To-CPP t.name> ', '
257            <Args-To-CPP () Exprs e.exprs> ', ' <Args-To-CPP () Vars e.ress> ');');
258      };
259  } :: e.cpp-item,
260    e.cpp-item <ASAIL-To-CPP e.rest>;
261  /*empty*/;
262};
263
264/*
265 * Determine type of e.expr - int or Refal.
266 */
267Expr-To-CPP  (e.init) e.expr-all, e.expr-all : {
268  /*empty*/ = <Expr-Ref-To-CPP e.init>;
269//  s.ObjectSymbol e.rest, {
270//    <Int? s.ObjectSymbol> = <Expr-Int-To-CPP e.init e.expr-all>;
271//    <Expr-Ref-To-CPP e.expr-all>;
272//  };   
273  (PAREN e.expr) e.rest = <Expr-Ref-To-CPP e.init e.expr-all>;
274  (EXPR e.expr) e.rest = <Expr-Ref-To-CPP e.init e.expr-all>;
275  (DEREF e.expr) e.rest = <Expr-Ref-To-CPP e.init e.expr-all>;
276  (SUBEXPR e.expr) e.rest = <Expr-Ref-To-CPP e.init e.expr-all>;
277  (LENGTH e.expr) e.rest = <Expr-Int-To-CPP e.init e.expr-all> ;
278  (MAX e.args) e.rest = <Expr-Int-To-CPP e.init e.expr-all>;         
279  (MIN e.args) e.rest = <Expr-Int-To-CPP e.init e.expr-all>;
280  (INFIX s.op e.args) e.rest = <Expr-Int-To-CPP e.init e.expr-all>;
281  (s.var-tag (e.QualifiedName)) e.rest =
282    <Expr-To-CPP (e.init (s.var-tag (e.QualifiedName))) e.rest>;
283};
284
285
286$func Term-Ref-To-CPP e = e;
287
288Expr-Ref-To-CPP {
289  /*empty*/ = 'empty';
290  term = <Term-Ref-To-CPP term>;
291  expr = '(' <Infix-To-CPP &Term-Ref-To-CPP "+" <Paren expr>> ')';
292};
293
294Term-Ref-To-CPP {
295  (PAREN e.expr) =
296    <Expr-Ref-To-CPP e.expr> ' ()';
297  (EXPR e.expr) =
298    'Expr (' <Expr-Ref-To-CPP e.expr> ')';
299  (DEREF e.expr (e.pos)) =
300    'Expr (' <Expr-Ref-To-CPP e.expr> ', ' <Expr-Int-To-CPP e.pos> ')';
301  (SUBEXPR e.expr (e.pos) (e.len)) =
302    'Expr (' <Expr-Ref-To-CPP e.expr> ', '
303        <Expr-Int-To-CPP e.pos>   ', ' <Expr-Int-To-CPP e.len> ')';
304  (REF t.name) = <Name-To-CPP t.name>;
305  ERROR-EXPR = 'err';
306  (STATIC t.name) =
307    <? &Current-Namespace> :: e.namespace,
308    {
309      <? &Module-Name> : e.namespace = /*empty*/;
310      <? &Module-Name>'::';
311    } :: e.prefix,
312    e.prefix <Rfp2Cpp (STATIC t.name)>;
313  (s.var-tag e.ns t.name) = <Rfp2Cpp (s.var-tag e.ns t.name)>;
314};
315
316Expr-Int-To-CPP {
317  /*empty*/ = /*empty*/;
318  s.ObjectSymbol =
319    {
320      <Int? s.ObjectSymbol> = s.ObjectSymbol;
321      $error ("Illegal type int-symbol: " s.ObjectSymbol);
322    };
323  (LENGTH e.expr) =
324    <Expr-Ref-To-CPP e.expr> '.get_len ()';
325  (MAX e.args) =
326    'pxx_max (' <Args-To-CPP () Ints e.args> ')';
327  (MIN e.args) =
328    'pxx_min (' <Args-To-CPP () Ints e.args> ')';
329  (INFIX s.op e.args) =
330    '(' <Infix-To-CPP &Expr-Int-To-CPP s.op e.args> ')';
331  (REF t.name) = <Name-To-CPP t.name>;
332  (s.var-tag t.name) = <Rfp2Cpp (s.var-tag t.name)>;
333  expr = '(' <Infix-To-CPP &Expr-Int-To-CPP "+" <Paren expr>> ')';
334};
335
336Cond-To-CPP {
337  /*empty*/ = /*empty*/;
338  (CALL t.name (e.exprs) (e.ress)) =
339    'RF_CALL (' <Name-To-CPP t.name> ', '
340          <Args-To-CPP () Exprs e.exprs> ', '
341          <Args-To-CPP () Vars e.ress>   ')';
342  (SYMBOL? e.expr (e.pos)) =
343    <Expr-Ref-To-CPP e.expr> '.symbol_at (' <Expr-Int-To-CPP e.pos> ')';
344  (FLAT-SUBEXPR? e.expr (e.pos) (e.len)) =
345    <Expr-Ref-To-CPP e.expr> '.flat_at ('
346      <Expr-Int-To-CPP e.pos> ', ' <Expr-Int-To-CPP e.len> ')';
347  (CHECK-ITER e.expr) =
348    'RF_iter(' <Expr-Ref-To-CPP e.expr> ')';
349  (EQ e.expr1 (e.expr2) (e.pos)) =
350    <Expr-Ref-To-CPP e.expr1> '.eq ('
351      <Expr-Ref-To-CPP e.expr2> ', ' <Expr-Int-To-CPP e.pos> ')';
352  (TERM-EQ e.expr1 (e.expr2) (e.pos)) =
353    <Expr-Ref-To-CPP e.expr1> '.term_eq ('
354      <Expr-Ref-To-CPP e.expr2> ', ' <Expr-Int-To-CPP e.pos> ')';
355  (NOT e.cond) =
356    '!' <Cond-To-CPP e.cond>;
357  (INFIX s.op e.args) =
358    '(' <Infix-To-CPP <Op-Arg-To-CPP s.op> s.op e.args> ')';
359  expr = '(' <Infix-To-CPP &Cond-To-CPP "&&" <Paren expr>> ')';
360};
361
362Infix-To-CPP s.arg2cpp s.op e.args, {
363  e.args : (e.arg) e.rest =
364    <Apply s.arg2cpp e.arg> :: e.arg,
365    <Infix-To-CPP s.arg2cpp s.op e.rest> :: e.rest,
366    {
367      e.arg : v, e.rest : v = e.arg ' ' s.op ' ' e.rest;
368      e.arg e.rest;
369    };;
370};
371
372Op-Arg-To-CPP s.op, {
373  s.op : \{ "&&"; "||"; } =
374    &Cond-To-CPP;
375  s.op : \{ "<"; ">"; "<="; ">="; "=="; "!="; "+"; "-"; "%"; "*"; "/"; } =
376    &Expr-Int-To-CPP;
377};
378 
379Step-To-CPP {
380  /*empty*/ = /*empty*/;
381  (INC-ITER e.expr) = 'RF_iter(' <Expr-Ref-To-CPP e.expr> ')++';
382  (DEC-ITER e.expr) = 'RF_iter(' <Expr-Ref-To-CPP e.expr> ')--';
383};
384
385
386
387$func Const-Expr-Aux e.expr = e.cpp-expr;
388
389Const-Expr-To-CPP {
390  /*empty*/ = 'empty';
391  (SUBEXPR t.name s.pos s.len) = 'Expr (' <Rfp2Cpp t.name> ', ' s.pos ', ' s.len ')';
392                  //FIXME: надо проверять, что s.pos и s.len
393                  //       не превышают допустимых величин.
394                  //       Задавать эти величины опциями.
395  e.expr =
396    <Const-Expr-Aux () e.expr> : {
397      ' + ' e.cpp-expr = e.cpp-expr;
398      e.cpp-expr = e.cpp-expr;
399    };
400};
401
402Const-Expr-Aux (e.accum) e.expr, {
403  e.expr : s.sym e.rest, <Char? s.sym> =
404    <Const-Expr-Aux (e.accum <Symbol-To-CPP s.sym>) e.rest>;
405  e.accum : v =
406    {
407      <Chars-To-Bytes e.accum> : e s.c e,
408        <">" (s.c) (127)> =
409        ' + Char::create_expr ("' e.accum '")' <Const-Expr-Aux () e.expr>;
410      //' + Expr::create_seq<Char> (L"' e.accum '")' <Const-Expr-Aux () e.expr>;
411      ' + Char::create_expr (L"' e.accum '")' <Const-Expr-Aux () e.expr>;
412    };
413  e.expr : t.item e.rest, t.item : {
414    (PAREN e.paren-expr) =
415      ' + (' <Const-Expr-To-CPP e.paren-expr> ') ()';
416    (REF t.name) =
417      ' + ' <Name-To-CPP t.name>;
418//      ' + Expr::create<ObjectRef>(' <Name-To-CPP t.name> ')';
419    (STATIC e) =
420      ' + ' <Rfp2Cpp t.item>;
421    (s.FUNC t.name), s.FUNC : \{ FUNC; FUNC?; } =
422      ' + Expr::create_sym<Func> (' <Name-To-CPP t.name> ')';
423    s.sym, {
424      <Int? s.sym> =
425        ' + Expr::create<' <? &Int> '>("' s.sym '")';
426      <Word? s.sym> =
427        ' + Expr::create<Word>("' <Symbol-To-CPP s.sym> '")';
428    };
429  } :: e.cpp-item =
430    e.cpp-item <Const-Expr-Aux () e.rest>;
431  = /*empty*/;
432};
433
434Symbol-To-CPP s.ObjectSymbol, {
435  <To-Chars s.ObjectSymbol> () $iter {
436    e.symbol : s.char e.rest, s.char : {
437      '\\' = '\\\\';
438      '\n' = '\\n';
439      '\t' = '\\t';
440//        '\v' = '\\v';
441//        '\b' = '\\b';
442      '\r' = '\\r';
443//        '\f' = '\\f';
444      '\"' = '\\"';
445//      '\'' = '\\\'';
446      s = s.char;
447    } :: e.cpp-char,
448    e.rest (e.cpp-symbol e.cpp-char);
449  } :: e.symbol (e.cpp-symbol),
450    e.symbol : /*empty*/ =
451    e.cpp-symbol;
452};
453
454
455
456Args-To-CPP {
457  (v.prefix) Vars /*empty*/  = 'RF_VOID';
458  (        ) Vars /*empty*/  = '/*void*/';
459  (        ) Vars (e.arg)    = <Rfp2Cpp (e.arg)>;
460  (e.prefix) Exprs /*empty*/ = '/*void*/';
461  (e.prefix) Exprs (e.arg)   = <Expr-Ref-To-CPP e.arg>;
462  (e.prefix) s.tag e.args =
463    e.args () $iter {
464      e.args : (e.arg) e.rest =
465        {
466          e.rest : v = ', ';
467          /*empty*/;
468        } :: e.comma,
469        s.tag : {
470          Vars = e.rest (e.cpp-args <Rfp2Cpp (e.arg)> e.comma);
471          Exprs = e.rest (e.cpp-args <Expr-Ref-To-CPP e.arg> e.comma);
472          Ints = e.rest (e.cpp-args <Expr-Int-To-CPP e.arg> e.comma);
473        };
474    } :: e.args (e.cpp-args),
475    e.args : /*empty*/,
476    (e.prefix) s.tag : {
477      t   Exprs = '(' e.cpp-args ')';
478      ( ) Vars  = '(' e.cpp-args ')';
479      (v) Vars  = '(' e.prefix e.cpp-args ';;)';
480      e         = e.prefix e.cpp-args;
481    };
482};
483
484Name-To-CPP t.obj-name =
485  <RFP-Extract-Qualifiers t.obj-name> :: (e.qualifiers) e.name,
486  <? &Current-Namespace> :: e.namespace,
487  {
488    e.qualifiers : e.namespace e.cont = <Rfp2Cpp e.cont e.name>;
489    <Rfp2Cpp (e.qualifiers e.name)>;
490  };
491
492Namespace-Control e.qualifiers =
493  {
494    e.qualifiers : /*empty*/ = <? &Module-Name>;
495    e.qualifiers : () = /*empty*/;
496    e.qualifiers;
497  } :: e.qualifiers,
498  {
499    <? &Current-Namespace> : e.qualifiers;
500    {
501      <? &Current-Namespace> : v = ('}');;
502    } :: e.close-namespace,
503      <Store &Current-Namespace e.qualifiers>,
504      {
505        e.qualifiers : v = ('namespace ' <Rfp2Cpp e.qualifiers> '\n{');;
506      } :: e.open-namespace,
507      e.close-namespace e.open-namespace;
508  };
509
510Trace-Enter e.name (e.args) =
511  e.args 1 () $iter {
512    e.args : t.arg e.rest =
513      {
514        \{ e.rest : v; <">" (s.n) (1)>; } = 'printf("%2d: ", 's.n');';
515        'printf("  : ");';
516      } :: e.num,
517      e.rest <"+" s.n 1>
518      (e.pr-args ('printf ("           argument "); 'e.num' ('<Rfp2Cpp t.arg>').writeln(stdout);'));
519  } :: e.args s.n (e.pr-args),
520  e.args : /*empty*/ =
521  ('printf ("+ %5u: enter >>> 'e.name' <<<\\n", rfrt::stack->get_depth());') e.pr-args;
522
523Trace-Exit e.name (e.args) =
524  e.args 1 () $iter {
525    e.args : t.arg e.rest =
526      {
527        \{ e.rest : v; <">" (s.n) (1)>; } = 'printf("%2d: ", 's.n');';
528        'printf("  : ");';
529      } :: e.num,
530      e.rest <"+" s.n 1>
531      (e.pr-args
532       ('printf ("           result   "); 'e.num' ('<Rfp2Cpp t.arg>').to_Expr().writeln(stdout);'));
533  } :: e.args s.n (e.pr-args),
534  e.args : /*empty*/ =
535  ('printf ("- %5u: exit  >>> 'e.name' <<<\\n", rfrt::stack->get_depth());') e.pr-args;
536
537Trace-Fail e.name =
538  ('printf ("- %5u: fail  >>> 'e.name' <<<\\n", rfrt::stack->get_depth());');
539
540Extract-Qualifiers t.name, {
541  <In-Table? &Externs t.name> =
542    t.name : (e.n),
543    (()) e.n;
544  <RFP-Extract-Qualifiers t.name>;
545};
546
Note: See TracBrowser for help on using the repository browser.