source: to-imperative/trunk/java/refal/refal/plus/CppMangle.rf @ 3989

Last change on this file since 3989 was 3753, checked in by yura, 13 years ago
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.1 KB
Line 
1// $Id: CppMangle.rf 3753 2008-04-20 12:14:31Z orlov $
2
3$use Apply Class Convert List;
4
5$use "cpp_specific";   // import $func? Reserved-Word?;
6            // import $const Namespace-Delimeter;
7
8$const Conv_Table =
9  ('!'    'e')
10  ('?'    'q')
11  ('_'    '')
12  ('-'    'm')
13  ('+'    'p')
14  ('<'    'lt')
15  ('>'    'gt')
16  ('='    'eq')
17  ('*'    'a')
18  ('/'    's')
19  (' '    'sp')
20  ('\\'   'bs')
21  ('|'    'bar')
22  ('~'    'tilde')
23  ('@'    'at')
24  ('#'    'num')
25  ('$'    'dollar')
26  ('%'    'percnt')
27  ('^'    'circ')
28  ('&'    'amp')
29  ('('    'lpar')
30  (')'    'rpar')
31  ('['    'lsqb')
32  (']'    'rsqb')
33  ('{'    'lcub')
34  ('}'    'rcub')
35  ('`'    'grave')
36  ('\''   'apos')
37  ('\"'   'quot')
38  (','    'comma')
39  ('.'    'period')
40  (':'    'colon')
41  (';'    'semi');
42
43
44
45//$func Qualifier2Cpp s.qualifier = e.cpp-namespace;
46$func Qualifier2Cpp e = e;
47
48$func Chars2Cpp e.name = e.cpp_identifier;
49
50//$func A-Char2Cpp s.char = e.char-representation;
51$func A_Char2Cpp e = e;
52
53$func Char_To_Unicode s.char = e.unicode;
54
55
56Rfp2Cpp e.rfp_obj, {
57  e.rfp_obj : \{
58    (s.tag e.ns (e.name s.last)), <IsInt s.last>,
59      s.tag : \{ EVAR = 'e'; VVAR = 'v'; TVAR = 't'; SVAR = 's'; } :: s.t =
60      ('_g's.t e.ns'_') e.name s.last;
61    (VAR  e.ns (e.name)) = ('_v'e.ns'_') e.name;
62    (EVAR e.ns (e.name)) = ('_ve'e.ns'_') e.name;
63    (VVAR e.ns (e.name)) = ('_vv'e.ns'_') e.name;
64    (TVAR e.ns (e.name)) = ('_vt'e.ns'_') e.name;
65    (SVAR e.ns (e.name)) = ('_vs'e.ns'_') 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 : (INT t.var) = <Rfp2Cpp t.var>;
71  e.rfp_obj : {
72    (OBJ e.names) = e.names;
73    (e.names) = e.names;
74    e.names = e.names;
75  } :: e.name =
76    <Chars2Cpp e.name>;
77} :: e.ident,
78  {
79    <Apply &IsReservedWord e.ident> : e = '_r_' e.ident;
80    e.ident;
81  };
82
83Qualifier2Cpp s.qualifier = <Chars2Cpp s.qualifier> &NamespaceDelimeter;
84
85Chars2Cpp e.name = <Map &A_Char2Cpp (<ToChars e.name>)>;
86
87A_Char2Cpp s.char, {
88  <IsDigit s.char> = s.char;
89  <IsLetter s.char>, # \{ '?!' : e s.char e; } = 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  <ToChars 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 &NamespaceDelimeter e.rest = <Chars2Rfp e.qualifier> <Qualifiers2Rfp e.rest>;
126  e.name = <Chars2Rfp e.name>;
127};
128
129Chars2Rfp e.name = <ToWord <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    <IsDigit s.char>;
137    <IsLetter 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.