source: to-imperative/trunk/compiler/rfp_mangle.rf @ 1095

Last change on this file since 1095 was 1095, checked in by orlov, 17 years ago
  • Labels are prefixed with '_' to distinguish them from typical namespaces.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.9 KB
Line 
1// $Source$
2// $Revision: 1095 $
3// $Date: 2003-08-05 13:30:23 +0000 (Tue, 05 Aug 2003) $
4
5$use Class Convert;
6
7$use "rfp_list";
8
9$use "reserved-c++";  // import $func? Reserved-Word?;
10
11$const Conv-Table =
12  ('!'    'e')
13  ('?'    'q')
14  ('_'    '')
15  ('-'    'm')
16  ('+'    'p')
17  ('<'    'lt')
18  ('>'    'gt')
19  ('='    'eq')
20  ('*'    'a')
21  ('/'    's')
22  (' '    'sp')
23  ('\\'   'bs')
24  ('|'    'bar')
25  ('~'    'tilde')
26  ('@'    'at')
27  ('#'    'num')
28  ('$'    'dollar')
29  ('%'    'percnt')
30  ('^'    'circ')
31  ('&'    'amp')
32  ('('    'lpar')
33  (')'    'rpar')
34  ('['    'lsqb')
35  (']'    'rsqb')
36  ('{'    'lcub')
37  ('}'    'rcub')
38  ('`'    'grave')
39  ('\''   'apos')
40  ('\"'   'quot')
41  (','    'comma')
42  ('.'    'period')
43  (':'    'colon')
44  (';'    'semi');
45
46
47
48//$func Qualifier2Cpp s.qualifier = e.cpp-namespace;
49$func Qualifier2Cpp e = e;
50
51$func Chars2Cpp e.name = e.cpp-identifier;
52
53//$func A-Char2Cpp s.char = e.char-representation;
54$func A-Char2Cpp e = e;
55
56$func Char-To-Unicode s.char = e.unicode;
57
58
59Rfp2Cpp e.rfp-obj, {
60  e.rfp-obj : \{
61    (VAR (e.name)) = ('_v_') e.name;
62    (EVAR (e.name)) = ('_ve_') e.name;
63    (VVAR (e.name)) = ('_vv_') e.name;
64    (TVAR (e.name)) = ('_vt_') e.name;
65    (SVAR (e.name)) = ('_vs_') e.name;
66    (STATIC (e.name)) = ('_c_') e.name;
67    (LABEL (e.name)) = ('_') e.name;
68  } :: (e.prefix) e.name =
69    e.prefix <Chars2Cpp e.name>;
70  e.rfp-obj : {
71    (OBJ e.names) = e.names;
72    (e.names) = e.names;
73    e.names = e.names;
74  } : e.qualifiers s.name =
75    <Map &Qualifier2Cpp (e.qualifiers)> <Chars2Cpp s.name>;
76  = /*empty*/;
77} :: e.ident,
78  {
79    <Reserved-Word? e.ident> = '_r_' e.ident;
80    e.ident;
81  };
82
83Qualifier2Cpp s.qualifier = <Chars2Cpp s.qualifier> '::';
84
85Chars2Cpp e.name = <Map &A-Char2Cpp (<To-Chars e.name>)>;
86
87A-Char2Cpp s.char, {
88  <Digit? s.char> = s.char;
89  <Letter? s.char>, # \{ s.char : '?'; } = s.char;
90  &Conv-Table : e (s.char e.code) e = '_' e.code '_';
91  '_' <Char-To-Unicode s.char> '_';
92};
93
94Char-To-Unicode {
95//  '\a' = '07';
96  '\b' = '08';
97  '\t' = '09';
98  '\n' = '0A';
99  '\v' = '0B';
100  '\f' = '0C';
101  '\r' = '0D';
102};
103
104
105$func? Qualifiers2Rfp e.qualifiers = e.words;
106
107$func? Chars2Rfp e.name = s.word;
108
109$func? Codes2Rfp e.codes = e.chars;
110
111
112Cpp2Rfp e.ident =
113  <To-Chars e.ident> : {
114    '_r_' e.name = e.name;
115    e.name = e.name;
116  } : \{
117    '_ve_' e.name = (EVAR (<Chars2Rfp e.name>));
118    '_vv_' e.name = (VVAR (<Chars2Rfp e.name>));
119    '_vt_' e.name = (TVAR (<Chars2Rfp e.name>));
120    '_vs_' e.name = (SVAR (<Chars2Rfp e.name>));
121    e.name = <Qualifiers2Rfp e.name>;
122  };
123
124Qualifiers2Rfp {
125  e.qualifier '::' e.rest = <Chars2Rfp e.qualifier> <Qualifiers2Rfp e.rest>;
126  e.name = <Chars2Rfp e.name>;
127};
128
129Chars2Rfp e.name = <To-Word <Codes2Rfp e.name>>;
130
131Codes2Rfp {
132  '_' e.code '_' e.rest =
133    &Conv-Table : e (s.char e.code) e =
134    s.char <Codes2Rfp e.rest>;
135  s.char e.rest = \{
136    <Digit? s.char>;
137    <Letter? s.char>, # \{ s.char : '?'; };
138  } =
139    s.char <Codes2Rfp e.rest>;
140  /*empty*/ = /*empty*/;
141};
142
Note: See TracBrowser for help on using the repository browser.