Skip to content

Commit 7200d17

Browse files
author
NatureFreshMeat
committed
Implemented String constant
1 parent d317af9 commit 7200d17

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

‎src/main/javascript/10_ClassReader.js‎

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,12 @@ var ClassReader = function(name, bytes)
5353
Logger.debug("Constant pool size: "+constant_pool_size);
5454

5555
varpos=10;
56-
varcp_count=0;
56+
/**
57+
* Constants array
58+
*/
59+
varconstants=newArray();
5760

58-
while(cp_count<constant_pool_size-1)
61+
while(constants.length<constant_pool_size-1)
5962
{
6063
vartag=this.getU1(pos++);
6164
Logger.debug("Tag: "+tag);
@@ -72,36 +75,51 @@ var ClassReader = function(name, bytes)
7275
*/
7376
varstrlen=this.getU2(pos);
7477

78+
pos+=2;
79+
7580
Logger.debug("String constant: "+strlen);
7681

77-
pos+=strlen+2;
82+
varstr="";
83+
for(vari=0;i<strlen;i++)
84+
{
85+
str+=String.fromCharCode(this.getU1(pos+i));
86+
}
87+
88+
Logger.debug(" String: "+str);
89+
90+
constants.push(0);//TODO
91+
pos+=strlen;
7892
}
7993
elseif(tag==3)
8094
{
8195
/*
8296
* 4 bytes Integer: a signed 32-bit two's complement number in big-endian format
8397
*/
98+
constants.push(0);//TODO
8499
pos+=4;
85100
}
86101
elseif(tag==4)
87102
{
88103
/*
89104
* 4 bytes Float: a 32-bit single-precision IEEE 754 floating-point number
90105
*/
106+
constants.push(0);//TODO
91107
pos+=4;
92108
}
93109
elseif(tag==5)
94110
{
95111
/*
96112
* 8 bytes Long: a signed 64-bit two's complement number in big-endian format (takes two slots in the constant pool table)
97113
*/
114+
constants.push(0);//TODO
98115
pos+=8;
99116
}
100117
elseif(tag==6)
101118
{
102119
/*
103120
* 8 bytes Double: a 64-bit double-precision IEEE 754 floating-point number (takes two slots in the constant pool table)
104121
*/
122+
constants.push(0);//TODO
105123
pos+=8;
106124
}
107125
elseif(tag==7)
@@ -111,34 +129,39 @@ var ClassReader = function(name, bytes)
111129
*/
112130
varref=this.getU2(pos);
113131
Logger.debug("Class reference: "+ref);
132+
constants.push(0);//TODO
114133
pos+=2;
115134
}
116135
elseif(tag==8)
117136
{
118137
/*
119138
* 2 bytes String reference: an index within the constant pool to a UTF-8 string
120139
*/
140+
constants.push(0);//TODO
121141
pos+=2;
122142
}
123143
elseif(tag==9)
124144
{
125145
/*
126146
* 4 bytes Field reference: two indexes within the constant pool, the first pointing to a Class reference, the second to a Name and Type descriptor.
127147
*/
148+
constants.push(0);//TODO
128149
pos+=4;
129150
}
130151
elseif(tag==10)
131152
{
132153
/*
133154
* 4 bytes Method reference: two indexes within the constant pool, the first pointing to a Class reference, the second to a Name and Type descriptor.
134155
*/
156+
constants.push(0);//TODO
135157
pos+=4;
136158
}
137159
elseif(tag==11)
138160
{
139161
/*
140162
* 4 bytes Interface method reference: two indexes within the constant pool, the first pointing to a Class reference, the second to a Name and Type descriptor.
141163
*/
164+
constants.push(0);//TODO
142165
pos+=4;
143166
}
144167
elseif(tag==12)
@@ -147,13 +170,15 @@ var ClassReader = function(name, bytes)
147170
* 4 bytes Name and type descriptor: two indexes to UTF-8 strings within the constant pool, the first representing a name (identifier)
148171
* and the second a specially encoded type descriptor.
149172
*/
173+
constants.push(0);//TODO
150174
pos+=4;
151175
}
152176

153-
cp_count++;
154177

155178
}
156179

180+
Logger.debug("Poolsize: "+constants.length);
181+
157182

158183
}
159184

0 commit comments

Comments
(0)