Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
X
xcap-capability-linux
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xcap
xcap-capability-linux
Commits
4f442454
Commit
4f442454
authored
Aug 27, 2015
by
Sarah Spall
Committed by
Vikram Narayanan
Oct 25, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
replace a single file with new ones for readability
parent
96be47d2
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
679 additions
and
437 deletions
+679
-437
tools/lcd/idl/code_gen/client.cpp
tools/lcd/idl/code_gen/client.cpp
+65
-0
tools/lcd/idl/code_gen/helper.cpp
tools/lcd/idl/code_gen/helper.cpp
+306
-0
tools/lcd/idl/code_gen/marshal.cpp
tools/lcd/idl/code_gen/marshal.cpp
+101
-0
tools/lcd/idl/code_gen/server.cpp
tools/lcd/idl/code_gen/server.cpp
+82
-437
tools/lcd/idl/code_gen/unmarshal.cpp
tools/lcd/idl/code_gen/unmarshal.cpp
+125
-0
No files found.
tools/lcd/idl/code_gen/client.cpp
0 → 100644
View file @
4f442454
#include "ccst.h"
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
CCSTFile
*
generate_client_header
(
File
*
f
)
{
}
CCSTFile
*
generate_client_source
(
File
*
f
)
{
std
::
vector
<
CCSTExDeclaration
*>
definitions
;
CCSTFile
*
c_file
=
new
CCSTFile
(
definitions
);
return
c_file
;
}
CCSTCompoundStatement
*
create_caller_body
(
Rpc
*
r
)
{
std
::
vector
<
CCSTDeclaration
*>
declarations
;
std
::
vector
<
CCSTStatement
*>
statements
;
std
::
vector
<
Parameter
*>
params
=
r
->
parameters
();
for
(
std
::
vector
<
Parameter
*>::
iterator
it
=
params
.
begin
();
it
!=
params
.
end
();
it
++
)
{
Parameter
*
p
=
(
Parameter
*
)
*
it
;
statements
.
push_back
(
marshal_parameter
(
p
));
}
// implicit returns
std
::
vector
<
Marshal_type
*>
implicit_ret_info
=
r
->
implicit_ret_marshal_info
();
for
(
std
::
vector
<
Marshal_type
*>::
iterator
it
=
implicit_ret_info
.
begin
();
it
!=
implicit_ret_info
.
end
();
it
++
)
{
Marshal_type
*
mt
=
*
it
;
UnmarshalTypeVisitor
*
visitor
=
new
UnmarshalTypeVisitor
();
statements
.
push_back
(
mt
->
accept
(
visitor
));
}
if
(
r
->
explicit_return_type
()
->
num
()
!=
5
)
{
// not void
Marshal_type
*
ret_info
=
r
->
explicit_ret_marshal_info
();
CCSTPointer
*
p
=
0x0
;
if
(
r
->
explicit_return_type
()
->
num
()
==
3
)
{
p
=
new
CCSTPointer
();
}
std
::
vector
<
CCSTDecSpecifier
*>
ret_type
=
type
(
r
->
explicit_return_type
());
UnmarshalTypeVisitor
*
visitor
=
new
UnmarshalTypeVisitor
();
ret_info
->
accept
(
visitor
);
statements
.
push_back
(
new
CCSTReturn
(
adfads
));
}
else
{
statements
.
push_back
(
new
CCSTReturn
());
}
return
new
CCSTCompoundstatement
(
declarations
,
statements
);
}
tools/lcd/idl/code_gen/helper.cpp
0 → 100644
View file @
4f442454
#include "ccst.h"
CCSTExDeclaration
*
construct_enum
(
File
*
f
)
{
const
char
*
enum_name
=
"todo"
;
CCSTEnumeratorList
*
el
=
construct_enumlist
(
f
->
rpc_defs
());
CCSTEnumSpecifier
*
e
=
new
CCSTEnumSpecifier
(
enum_name
,
el
);
std
::
vector
<
CCSTDecSpecifier
*>
tmp
;
// = new std::vector<CCSTDecSpecifier*>();
tmp
.
push_back
(
e
);
std
::
vector
<
CCSTInitDeclarator
*>
empty
;
CCSTDeclaration
*
declaration
=
new
CCSTDeclaration
(
tmp
,
empty
);
return
declaration
;
}
const
char
*
construct_enum_name
()
{
return
"todo"
;
}
CCSTEnumeratorList
*
construct_enumlist
(
std
::
vector
<
Rpc
*>
rps
)
{
// list of functions to put in enum.
std
::
vector
<
CCSTEnumerator
*>*
list
=
new
std
::
vector
<
CCSTEnumerator
*>
();
for
(
std
::
vector
<
Rpc
*>::
iterator
it
=
rps
.
begin
();
it
!=
rps
.
end
();
it
++
)
{
Rpc
*
r
=
*
it
;
char
*
upper_name
=
string_to_upper
(
r
->
name
());
char
*
enum_name
=
(
char
*
)
malloc
((
sizeof
(
upper_name
)
+
9
+
1
)
*
sizeof
(
char
));
sprintf
(
enum_name
,
"%s_CALLEE_T"
,
upper_name
);
list
->
push_back
(
new
CCSTEnumerator
(
enum_name
));
}
CCSTEnumeratorList
*
enum_list
=
new
CCSTEnumeratorList
(
list
);
return
enum_list
;
}
char
*
string_to_upper
(
char
*
str
)
{
char
*
ret
=
(
char
*
)
malloc
((
sizeof
(
str
)
+
1
)
*
sizeof
(
char
));
int
i
;
for
(
i
=
0
;
i
<
sizeof
(
str
);
i
++
)
{
char
tmp
=
str
[
i
];
ret
[
i
]
=
toupper
(
tmp
);
}
ret
[
i
]
=
'\0'
;
return
ret
;
}
Type
*
get_non_pointer_type
(
PointerType
*
p
)
{
Assert
(
p
->
type
()
!=
0x0
,
"Error: pointer to null
\n
"
);
if
(
p
->
type
()
->
num
()
!=
3
)
return
p
->
type
();
PointerType
*
pt
=
dynamic_cast
<
PointerType
*>
(
p
->
type
());
return
get_non_pointer_type
(
pt
);
}
int
count_nested_pointer
(
Type
*
p
)
{
if
(
p
->
num
()
!=
3
)
return
0
;
else
{
PointerType
*
tmp
=
dynamic_cast
<
PointerType
*>
(
p
);
return
1
+
count_nested_pointer
(
tmp
->
type
());
}
}
/* creates a pointer, or pointer to pointer, etc*/
/* may need to be changed if want to do something like
* int * const name
* int * volatile name
*/
CCSTPointer
*
create_pointer
(
int
p_count
)
{
if
(
p_count
==
0
)
return
0x0
;
if
(
p_count
==
1
)
return
new
CCSTPointer
();
return
new
CCSTPointer
(
create_pointer
(
p_count
-
1
));
}
/* Creates a function definition
* from a function declaration
* and a body
*/
CCSTFuncDef
*
create_function_definition
(
CCSTDeclaration
*
function_declaration
,
CCSTCompoundStatement
*
body
)
{
Assert
(
function_declaration
->
decs_
.
size
()
==
1
,
"Error: More than one initializer/declarator in function declaration"
);
CCSTDeclarator
*
func
=
dynamic_cast
<
CCSTDeclarator
*>
(
function_declaration
->
decs_
.
at
(
0
));
Assert
(
func
!=
0
,
"Error: dynamic cast from CCSTInitDeclarator to CCSTDeclarator has failed!"
);
std
::
vector
<
CCSTDeclaration
*>
decs
;
// not sure what this is for. unnecessary?
return
new
CCSTFuncDef
(
function_declaration
->
specifier_
,
func
,
decs
,
body
);
}
CCSTParamTypeList
*
create_parameter_list
()
{
}
/* creates a function declaration
* from an rpc, not callee
*/
CCSTDeclaration
*
create_function_declaration
(
Rpc
*
r
)
{
std
::
vector
<
CCSTDecSpecifier
*>
specifier
=
type
(
r
->
explicit_return_type
());
std
::
vector
<
CCSTInitDeclarator
*>
func
;
// = new std::vector<CCSTInitDeclarator*>(); // pointer name, params
int
pointer_count
=
count_nested_pointer
(
r
->
explicit_return_type
());
CCSTPointer
*
p
=
create_pointer
(
pointer_count
);
CCSTDirectDecId
*
name
=
new
CCSTDirectDecId
(
r
->
name
());
CCSTParamTypeList
*
param_list
=
create_parameter_list
();
CCSTDirectDecParamTypeList
*
name_params
=
new
CCSTDirectDecParamTypeList
(
name
,
param_list
);
func
.
push_back
(
new
CCSTDeclarator
(
p
,
name_params
));
return
new
CCSTDeclaration
(
specifier
,
func
);
}
std
::
vector
<
CCSTDecSpecifier
*>
type
(
Type
*
t
)
{
std
::
vector
<
CCSTDecSpecifier
*>
specifier
;
switch
(
t
->
num
())
{
case
2
:
// int type case
{
IntegerType
*
it
=
dynamic_cast
<
IntegerType
*>
(
t
);
Assert
(
it
!=
0x0
,
"Error: dynamic cast failed!
\n
"
);
switch
(
it
->
int_type
())
{
case
pt_char_t
:
{
specifier
.
push_back
(
new
CCSTSimpleTypeSpecifier
(
char_t
));
break
;
}
case
pt_short_t
:
{
specifier
.
push_back
(
new
CCSTSimpleTypeSpecifier
(
short_t
));
break
;
}
case
pt_int_t
:
{
specifier
.
push_back
(
new
CCSTSimpleTypeSpecifier
(
int_t
));
break
;
}
case
pt_long_t
:
{
specifier
.
push_back
(
new
CCSTSimpleTypeSpecifier
(
long_t
));
break
;
}
case
pt_longlong_t
:
{
specifier
.
push_back
(
new
CCSTSimpleTypeSpecifier
(
long_t
));
specifier
.
push_back
(
new
CCSTSimpleTypeSpecifier
(
long_t
));
break
;
}
case
pt_capability_t
:
{
specifier
.
push_back
(
new
CCSTTypedefName
(
"capability_t"
));
break
;
}
default:
{
Assert
(
1
==
0
,
"Error: unknown type
\n
"
);
}
}
return
specifier
;
}
case
4
:
// struct
{
ProjectionType
*
pt
=
dynamic_cast
<
ProjectionType
*>
(
t
);
Assert
(
pt
!=
0x0
,
"Error: dynamic cast failed!
\n
"
);
specifier
.
push_back
(
new
CCSTStructUnionSpecifier
(
struct_t
,
pt
->
real_type
()));
return
specifier
;
}
case
3
:
{
PointerType
*
pt
=
dynamic_cast
<
PointerType
*>
(
t
);
Assert
(
pt
!=
0x0
,
"Error: dynamic cast failed!
\n
"
);
return
type
(
pt
->
type
());
}
default:
{
Assert
(
1
==
0
,
"Error: Not a struct or integer type.
\n
"
);
}
}
}
CCSTTypeName
*
type_cast
(
Type
*
t
)
{
printf
(
"in type+cast
\n
"
);
CCSTAbstDeclarator
*
pointers
=
0x0
;
std
::
vector
<
CCSTSpecifierQual
*>
spec_quals
;
if
(
t
==
0x0
)
printf
(
"t is null
\n
"
);
if
(
t
->
num
()
==
3
)
{
printf
(
"type cast pointer
\n
"
);
// do pointer stuff....
pointers
=
new
CCSTAbstDeclarator
(
create_pointer
(
count_nested_pointer
(
t
))
,
0x0
);
PointerType
*
p
=
dynamic_cast
<
PointerType
*>
(
t
);
t
=
get_non_pointer_type
(
p
);
// get first non pointer, write function for this
}
printf
(
"in type castttt
\n
"
);
switch
(
t
->
num
())
{
case
1
:
// typedef
{
Typedef
*
td
=
dynamic_cast
<
Typedef
*>
(
t
);
const
char
*
name
=
td
->
alias
();
spec_quals
.
push_back
(
new
CCSTTypedefName
(
name
)
);
break
;
}
case
2
:
// integer
{
IntegerType
*
it
=
dynamic_cast
<
IntegerType
*>
(
t
);
spec_quals
=
integer_type_cast
(
it
);
break
;
}
case
4
:
// projection
{
printf
(
"here in type cast
\n
"
);
ProjectionType
*
pt
=
dynamic_cast
<
ProjectionType
*>
(
t
);
const
char
*
name
=
pt
->
real_type
();
printf
(
"projection name: %s
\n
"
,
name
);
spec_quals
.
push_back
(
new
CCSTStructUnionSpecifier
(
struct_t
,
name
)
);
break
;
}
case
5
:
// void
{
// does this even happen?
printf
(
"Warning: casting something as void
\n
"
);
spec_quals
.
push_back
(
new
CCSTSimpleTypeSpecifier
(
void_t
)
);
break
;
}
default:
{
Assert
(
1
==
0
,
"Error: Should never get here
\n
"
);
}
}
return
new
CCSTTypeName
(
spec_quals
,
pointers
);
}
std
::
vector
<
CCSTSpecifierQual
*>
integer_type_cast
(
IntegerType
*
it
)
{
std
::
vector
<
CCSTSpecifierQual
*>
spec_quals
;
if
(
it
->
is_unsigned
())
{
spec_quals
.
push_back
(
new
CCSTSimpleTypeSpecifier
(
unsigned_t
));
}
switch
(
it
->
int_type
())
{
case
pt_char_t
:
{
spec_quals
.
push_back
(
new
CCSTSimpleTypeSpecifier
(
char_t
));
break
;
}
case
pt_short_t
:
{
spec_quals
.
push_back
(
new
CCSTSimpleTypeSpecifier
(
short_t
));
break
;
}
case
pt_int_t
:
{
spec_quals
.
push_back
(
new
CCSTSimpleTypeSpecifier
(
int_t
));
break
;
}
case
pt_long_t
:
{
spec_quals
.
push_back
(
new
CCSTSimpleTypeSpecifier
(
long_t
));
break
;
}
case
pt_longlong_t
:
{
spec_quals
.
push_back
(
new
CCSTSimpleTypeSpecifier
(
long_t
));
spec_quals
.
push_back
(
new
CCSTSimpleTypeSpecifier
(
long_t
));
break
;
}
case
pt_capability_t
:
{
spec_quals
.
push_back
(
new
CCSTTypedefName
(
"capability_t"
));
break
;
}
default:
{
printf
(
"todo
\n
"
);
}
}
return
spec_quals
;
}
tools/lcd/idl/code_gen/marshal.cpp
0 → 100644
View file @
4f442454
#include "ccst.h"
/* driver function */
CCSTCompoundStatement
*
marshal_parameter
(
Parameter
*
p
)
{
MarshalTypeVisitor
*
visitor
=
new
MarshalTypeVisitor
();
return
p
->
get_marshal_info
()
->
accept
(
visitor
);
}
CCSTCompoundStatement
*
MarshalTypeVisitor
::
visit
(
Marshal_projection
*
data
)
{
ProjectionType
*
pt
=
dynamic_cast
<
ProjectionType
*>
(
data
->
get_type
());
Assert
(
pt
!=
0x0
,
"Error: Expected ProjectionType got something else.
\n
"
);
std
::
vector
<
CCSTDeclaration
*>
comp_declarations
;
std
::
vector
<
CCSTStatement
*>
comp_statements
;
std
::
vector
<
Marshal_type
*>
fields
=
data
->
fields
();
for
(
std
::
vector
<
Marshal_type
*>::
iterator
it
=
fields
.
begin
();
it
!=
fields
.
end
();
it
++
)
{
Marshal_type
*
mt
=
*
it
;
std
::
vector
<
CCSTDecSpecifier
*>
type_specifier
=
type
(
mt
->
get_type
());
std
::
vector
<
CCSTInitDeclarator
*>
init_decs
;
if
(
mt
->
get_type
()
->
num
()
==
3
)
{
printf
(
"MDAASDFSADFSA1 is %s
\n
"
,
mt
->
get_name
());
init_decs
.
push_back
(
new
CCSTInitDeclarator
(
new
CCSTDeclarator
(
new
CCSTPointer
()
,
new
CCSTDirectDecId
(
mt
->
get_name
()))
,
new
CCSTInitializer
(
new
CCSTPostFixExprAccess
(
new
CCSTPrimaryExprId
(
data
->
get_name
()),
object_access_t
,
mt
->
get_name
()))));
}
else
{
printf
(
"MTMTMTMTM2 is %s
\n
"
,
mt
->
get_name
());
init_decs
.
push_back
(
new
CCSTInitDeclarator
(
new
CCSTDeclarator
(
0x0
,
new
CCSTDirectDecId
(
mt
->
get_name
()))
,
new
CCSTInitializer
(
new
CCSTPostFixExprAccess
(
new
CCSTPrimaryExprId
(
data
->
get_name
()),
object_access_t
,
mt
->
get_name
()))));
}
comp_declarations
.
push_back
(
new
CCSTDeclaration
(
type_specifier
,
init_decs
));
comp_statements
.
push_back
(
mt
->
accept
(
this
));
}
return
new
CCSTCompoundStatement
(
comp_declarations
,
comp_statements
);
}
CCSTCompoundStatement
*
MarshalTypeVisitor
::
visit
(
Marshal_integer
*
data
)
{
IntegerType
*
t
=
dynamic_cast
<
IntegerType
*>
(
data
->
get_type
());
Assert
(
t
!=
0x0
,
"Error: expected IntegerType got something else.
\n
"
);
std
::
vector
<
CCSTDeclaration
*>
comp_declarations
;
std
::
vector
<
CCSTStatement
*>
comp_statements
;
std
::
vector
<
CCSTAssignExpr
*>
args
;
std
::
vector
<
CCSTSpecifierQual
*>
spec_quals
;
spec_quals
.
push_back
(
new
CCSTSimpleTypeSpecifier
(
long_t
));
spec_quals
.
push_back
(
new
CCSTSimpleTypeSpecifier
(
long_t
));
args
.
push_back
(
new
CCSTCastExpr
(
new
CCSTTypeName
(
spec_quals
,
0x0
)
,
new
CCSTPrimaryExprId
(
data
->
get_name
())));
CCSTPostFixExprAssnExpr
*
func_call
=
new
CCSTPostFixExprAssnExpr
(
new
CCSTPrimaryExprId
(
store_register_mapping
(
data
->
get_register
()))
,
args
);
comp_statements
.
push_back
(
new
CCSTExprStatement
(
func_call
));
return
new
CCSTCompoundStatement
(
comp_declarations
,
comp_statements
);
}
CCSTCompoundStatement
*
MarshalTypeVisitor
::
visit
(
Marshal_void
*
data
)
{
}
CCSTCompoundStatement
*
MarshalTypeVisitor
::
visit
(
Marshal_typedef
*
data
)
{
}
CCSTCompoundStatement
*
MarshalTypeVisitor
::
visit
(
Marshal_pointer
*
data
)
{
PointerType
*
t
=
dynamic_cast
<
PointerType
*>
(
data
->
get_type
());
Assert
(
t
!=
0x0
,
"Error: expected PointerType got something else.
\n
"
);
Marshal_type
*
pointer_to
=
data
->
get_m_type
();
const
char
*
name
=
pointer_to
->
get_name
();
std
::
vector
<
CCSTDeclaration
*>
comp_declarations
;
std
::
vector
<
CCSTStatement
*>
comp_statements
;
std
::
vector
<
CCSTDecSpecifier
*>
ds
=
type
(
pointer_to
->
get_type
());
std
::
vector
<
CCSTInitDeclarator
*>
id
;
id
.
push_back
(
new
CCSTInitDeclarator
(
new
CCSTDeclarator
(
0x0
,
new
CCSTDirectDecId
(
name
))
,
new
CCSTInitializer
(
new
CCSTUnaryExprCastExpr
(
new
CCSTUnaryOp
(
unary_mult_t
)
,
new
CCSTPrimaryExprId
(
data
->
get_name
())
)
)
));
comp_declarations
.
push_back
(
new
CCSTDeclaration
(
ds
,
id
));
comp_statements
.
push_back
(
pointer_to
->
accept
(
this
));
return
new
CCSTCompoundStatement
(
comp_declarations
,
comp_statements
);
}
tools/lcd/idl/
ast_to_ccst
.cpp
→
tools/lcd/idl/
code_gen/server
.cpp
View file @
4f442454
#include "ccst.h"
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
/* example
#ifndef LCD_PROTOTYPE_MANUFACTURER_IDL_H
#define LCD_PROTOTYPE_MANUFACTURER_IDL_H
enum manufacturer_interface_enum {
MANUFACTURER_MK_ENGINE,
MANUFACTURER_MK_AUTOMOBILE,
MANUFACTURER_FREE_ENGINE,
MANUFACTURER_FREE_AUTOMOBILE,
MANUFACTURER_DIE,
};
Locations of manufacturer's boot cptrs
#define MANUFACTURER_DEALER_INTERFACE_CAP 31
#endif
*/
/* producing:
declaration --> declaration-specifier --> type-specifier --> enum-specifier
enum-specifier: enum id { enumerator-list };
enumerator-list = enumerator
| enumerator-list , enumerator
enumerator = id
| id = constant-expression
*/
CCSTFile
*
generate_server_header
(
File
*
file
)
{
// #ifndef
// #define
// #endif
// enum-specifier: enum id
std
::
vector
<
CCSTExDeclaration
*>
definitions
;
// = new std::vector<CCSTExDeclaration*>();
// check if there are rpcs
if
(
!
file
->
rpc_defs
().
empty
())
{
printf
(
"rpc not empty
\n
"
);
definitions
.
push_back
(
construct_enum
(
file
));
// function callee function declarations
std
::
vector
<
Rpc
*>
rpcs
=
file
->
rpc_defs
();
for
(
std
::
vector
<
Rpc
*>::
iterator
it
=
rpcs
.
begin
();
it
!=
rpcs
.
end
();
it
++
)
{
definitions
.
push_back
(
construct_callee_declaration
((
Rpc
*
)
*
it
));
}
}
definitions
.
push_back
(
create_dispatch_function_declaration
());
CCSTFile
*
c_file
=
new
CCSTFile
(
definitions
);
return
c_file
;
}
CCSTDeclaration
*
construct_callee_declaration
(
Rpc
*
r
)
{
std
::
vector
<
CCSTDecSpecifier
*>
specifier
;
// = new std::vector<CCSTDecSpecifier*>();
specifier
.
push_back
(
new
CCSTSimpleTypeSpecifier
(
int_t
));
char
*
callee_name
=
(
char
*
)
malloc
((
strlen
(
r
->
name
())
+
strlen
(
"_callee"
)
+
1
)
*
sizeof
(
char
));
sprintf
(
callee_name
,
"%s%s"
,
r
->
name
(),
"_callee"
);
CCSTDirectDecId
*
id
=
new
CCSTDirectDecId
(
callee_name
);
std
::
vector
<
CCSTDecSpecifier
*>
*
s
=
new
std
::
vector
<
CCSTDecSpecifier
*>
();
s
->
push_back
(
new
CCSTSimpleTypeSpecifier
(
void_t
));
CCSTParamDeclaration
*
parameter
=
new
CCSTParamDeclaration
(
s
);
std
::
vector
<
CCSTParamDeclaration
*>
p_decs
;
// = new std::vector<CCSTParamDeclaration*>();
p_decs
.
push_back
(
parameter
);
CCSTParamList
*
param_list
=
new
CCSTParamList
(
p_decs
);
CCSTDirectDecParamTypeList
*
params
=
new
CCSTDirectDecParamTypeList
(
id
,
param_list
);
CCSTDeclarator
*
declarator
=
new
CCSTDeclarator
(
NULL
,
params
);
std
::
vector
<
CCSTInitDeclarator
*>
init_declarator
;
// = new std::vector<CCSTInitDeclarator*>();
init_declarator
.
push_back
(
declarator
);
CCSTDeclaration
*
func_declaration
=
new
CCSTDeclaration
(
specifier
,
init_declarator
);
return
func_declaration
;
}
CCSTExDeclaration
*
construct_enum
(
File
*
f
)
{
const
char
*
enum_name
=
"todo"
;
CCSTEnumeratorList
*
el
=
construct_enumlist
(
f
->
rpc_defs
());
CCSTEnumSpecifier
*
e
=
new
CCSTEnumSpecifier
(
enum_name
,
el
);
std
::
vector
<
CCSTDecSpecifier
*>
tmp
;
// = new std::vector<CCSTDecSpecifier*>();
tmp
.
push_back
(
e
);
std
::
vector
<
CCSTInitDeclarator
*>
empty
;
CCSTDeclaration
*
declaration
=
new
CCSTDeclaration
(
tmp
,
empty
);
return
declaration
;
}
const
char
*
construct_enum_name
()
{
return
"todo"
;
}
CCSTEnumeratorList
*
construct_enumlist
(
std
::
vector
<
Rpc
*>
rps
)
{
// list of functions to put in enum.
std
::
vector
<
CCSTEnumerator
*>*
list
=
new
std
::
vector
<
CCSTEnumerator
*>
();
for
(
std
::
vector
<
Rpc
*>::
iterator
it
=
rps
.
begin
();
it
!=
rps
.
end
();
it
++
)
{
Rpc
*
r
=
*
it
;
char
*
upper_name
=
string_to_upper
(
r
->
name
());
char
*
enum_name
=
(
char
*
)
malloc
((
sizeof
(
upper_name
)
+
9
+
1
)
*
sizeof
(
char
));
sprintf
(
enum_name
,
"%s_CALLEE_T"
,
upper_name
);
list
->
push_back
(
new
CCSTEnumerator
(
enum_name
));
}
CCSTEnumeratorList
*
enum_list
=
new
CCSTEnumeratorList
(
list
);
return
enum_list
;
}
char
*
string_to_upper
(
char
*
str
)
{
char
*
ret
=
(
char
*
)
malloc
((
sizeof
(
str
)
+
1
)
*
sizeof
(
char
));
int
i
;
for
(
i
=
0
;
i
<
sizeof
(
str
);
i
++
)
{
char
tmp
=
str
[
i
];
ret
[
i
]
=
toupper
(
tmp
);
}
ret
[
i
]
=
'\0'
;
return
ret
;
}
/* ServerCCSTSourceVisitor */
CCSTFile
*
generate_server_source
(
File
*
file
)
{
printf
(
"In generate_server_source
\n
"
);
// <function-definition> is CCSTFuncDef
// CCSTDecSpecifier* is <type-specifier> is CCSTTypeSpecifier
// <declarator> is CCSTDeclarator
// <declaration> what is this for is CCSTDeclaration
// <compound-statement> is CCSTCompoundStatement
// CCSTDeclaration for body
// CCSTStatement for body
// see notes in notebook
/*
std::vector<CCSTExDeclaration*> defs;
CCSTFuncDef* exec_loop = create_exec_loop(file->rpc_defs());
defs.push_back(exec_loop);
return new CCSTFile(defs);
*/