12 #define YY_(x) (char *) (x)
17 /* if the member has public scope */
18 bool member_scope_public
= false
;
27 struct sStringVec
*sv
;
28 struct sStringVecVec
*svv
;
33 %token CLASS VISIBILITY
34 %type
<sv
> idf_list idf_list_opt
35 %type
<svv
> idf_comma_list idf_comma_list_opt
41 //problemas: herdar metodos de outras classes....
42 // nao deve pegar metodos private ou protected.... DONE
43 // tratar tipos com mais de uma palavra (char *)
44 // tratar retorno de tipo composto (classe, diferenciar de enum)
45 // quando o método tiver a palavra operator e nao for um operatorX() ele vai ignorar.... DONE
48 CLASS IDF hierarchy_opt
'{' class_body
'}' ';'
50 printf
("ClassName: %s\n", $2->vs
[0].c_str
());
51 string className
= $2->vs
[0].c_str
();
52 for
(int i
=0; i
<$5->vi.size
(); i
++)
54 string type
= $5->vi
[i
].type
;
55 string fooName
= $5->vi
[i
].name
;
56 if
(type
== "Constructor"
57 || fooName
== "" /*caso seja um enum*/
58 //|| fooName.find("operator") != string::npos /*caso seja um operator*/
59 || fooName.substr
(0, strlen
("operator")) == "operator" /*caso seja um operator*/
60 ||
!$5->vi
[i
].isPublic
/* caso nao seja publico */)
63 printf
("int %s_%s(lua_State* L) {\n", className.c_str
(), fooName.c_str
());
64 printf
("\t%s *c = (%s*) lua_touserdata(L, 1);\n", className.c_str
(), className.c_str
());
65 for
(int j
=0; j
<$5->vi
[i
].param.size
(); j
++)
67 string paramType
= $5->vi
[i
].param
[j
].type
;
68 string paramName
= $5->vi
[i
].param
[j
].name
;
69 if
(paramType
=="int" || paramType
=="float" || paramType
=="double")
70 printf
("\t%s %s = luaL_checknumber(L, %d);\n", paramType.c_str
(), paramName.c_str
(), j
+2);
75 printf
("lua_pushboolean(L, ");
76 else if
(type
== "char*")
77 printf
("lua_pushstring(L, ");
78 else
//if(type == "double" || type == "int" || type == "float")
79 printf
("lua_pushnumber(L, ");
80 //problema: enums devem ser tratados com pushnumber mas classes definidas pelo usuário
81 //devem ser tratadas com pushlightuserdata. Como fazer????
83 printf
("c->%s(", fooName.c_str
());
84 for
(int j
=0; j
<$5->vi
[i
].param.size
(); j
++)
87 printf
("%s", $5->vi
[i
].param
[j
].name.c_str
());
91 if
(type
!= "void") printf
(");\n");
96 printf("%s: %s %s( ", $2->vs[0].c_str(), $5->vi[i].type.c_str(), $5->vi[i].name.c_str());
97 for(int j=0; j<$5->vi[i].param.size(); j++)
98 printf("%s %s ", $5->vi[i].param[j].type.c_str(), $5->vi[i].param[j].name.c_str());
106 VISIBILITY
':' class_body
{ $$
= $3; }
107 | function class_body
{ $$
= $2; $$
->vi.push_back
(*$1); }
108 | idf_comma_list
';' class_body
{ $$
= $3; }
109 |
/* empty */ { $$
= new Node
; }
113 ':' VISIBILITY idf_comma_list
118 idf_comma_list
{ $$
= $1; }
119 |
/* empty */ { $$
= new StringVecVec
; }
123 idf_list
{ $$
= new StringVecVec
; $$
->vvs.push_back
($1->vs
); }
124 | idf_comma_list
',' idf_list
{ $$
= $1; $$
->vvs.push_back
($3->vs
); }
128 idf_list
{ $$
= $1; }
129 |
/* empty */ { $$
= new StringVec
; }
133 idf_list IDF
{ $$
= $1; $$
->vs.push_back
($2->vs
[0]); }
138 idf_list
'(' idf_comma_list_opt
')' idf_list_opt function_body
142 if
($1->vs.size
() >= 2) //se nao for construtor/destrutor, vai ter um tipo
143 $$
->type
= $1->vs
[$1->vs.size
()-2];
145 $$
->type
= "Constructor";
146 $$
->name
= $1->vs
[$1->vs.size
()-1];
147 //for(int i=0; i<$1->vs.size(); i++)
148 // printf("%s ", $1->vs[i].c_str());
150 for
(int i
=0; i
<$3->vvs.size
(); i
++)
153 p.type
= $3->vvs
[i
][$3->vvs
[i
].size
()-2];
154 p.name
= $3->vvs
[i
][$3->vvs
[i
].size
()-1];
158 $$
->isPublic
= member_scope_public
;
159 /* This shows what functions are in the data structure
160 printf("%s %s( ", $$->type.c_str(), $$->name.c_str());
161 for(int i=0; i<$$->param.size(); i++)
162 printf("%s %s ", $$->param[i].type.c_str(), $$->param[i].name.c_str());
165 //for(int i=0; i<$3->vvs.size(); i++)
166 // for(int j=0; j<$3->vvs[i].size(); j++)
167 //printf("%s ", $3->vvs[i][j].c_str());
170 | idf_list
'{' '}' ';' { $$
= new Idf
; } // for enum
187 int main
(int argc
, char **argv
)
193 void yyerror(char *s
) {
194 fprintf
(stdout
, "%s\n", s
);