-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerate_java.cpp
More file actions
135 lines (121 loc) · 3.22 KB
/
generate_java.cpp
File metadata and controls
135 lines (121 loc) · 3.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/* iFeelSmart
*
* Copyright © 2012-2013, iFeelSmart.
*
*
* GNU Lesser General Public License Usage
* This file may be used under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation and
* appearing in the file LICENSE.LGPL included in the packaging of this
* file. Please review the following information to ensure the GNU Lesser
* General Public License version 2.1 requirements will be met:
* http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
*
* File: generate_java.cpp
*
*/
#include "generate_java.h"
#include "Type.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// =================================================
VariableFactory::VariableFactory(const string& base)
:m_base(base),
m_index(0)
{
}
Variable*
VariableFactory::Get(Type* type)
{
char name[100];
sprintf(name, "%s%d", m_base.c_str(), m_index);
m_index++;
Variable* v = new Variable(type, name);
m_vars.push_back(v);
return v;
}
Variable*
VariableFactory::Get(int index)
{
return m_vars[index];
}
// =================================================
string
gather_comments(extra_text_type* extra)
{
string s;
while (extra) {
if (extra->which == SHORT_COMMENT) {
s += extra->data;
}
else if (extra->which == LONG_COMMENT) {
s += "/*";
s += extra->data;
s += "*/";
}
extra = extra->next;
}
return s;
}
string
append(const char* a, const char* b)
{
string s = a;
s += b;
return s;
}
// =================================================
int
generate_java(const string& filename, const string& originalSrc,
interface_type* iface)
{
Class** cl;
if (iface->document_item.item_type == INTERFACE_TYPE_BINDER) {
cl = generate_binder_interface_class(iface);
}
/*else if (iface->document_item.item_type == INTERFACE_TYPE_RPC) {
cl = generate_rpc_interface_class(iface);
}*/
Document* document = new Document;
document->comment = "";
if (iface->package) document->package = iface->package;
document->originalSrc = originalSrc;
int i = 0;
while (cl[i] != 0) {
document->classes.push_back(cl[i]);
i++;
}
// printf("outputting... filename=%s\n", filename.c_str());
FILE* toC;
if (filename == "-") {
toC = stdout;
} else {
/* open file in binary mode to ensure that the tool produces the
* same output on all platforms !!
*/
toC = fopen((filename + ".cpp").c_str(), "wb");
if (toC == NULL) {
fprintf(stderr, "unable to open %s for write\n", filename.c_str());
return 1;
}
}
FILE* toH;
if (filename == "-") {
toH = stdout;
} else {
/* open file in binary mode to ensure that the tool produces the
* same output on all platforms !!
*/
toH = fopen((filename + ".h").c_str(), "wb");
if (toH == NULL) {
fprintf(stderr, "unable to open %s for write\n", filename.c_str());
return 1;
}
}
document->Write(toC, toH);
fclose(toH);
fclose(toC);
return 0;
}