aboutsummaryrefslogtreecommitdiff
path: root/gcc/java/constants.c
diff options
context:
space:
mode:
authorGeoffrey Keating <geoffk@apple.com>2003-01-10 02:22:34 +0000
committerGeoffrey Keating <geoffk@apple.com>2003-01-10 02:22:34 +0000
commit89f8430c66a81a09afcf8399553d0e173863aca4 (patch)
treea3ff2e89f1924fd7ea1d99358736bc8491352747 /gcc/java/constants.c
parent3c1f39471d09625b60dedffabb7756f0f52905cd (diff)
Merge from pch-branch.
git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@61136 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/java/constants.c')
-rw-r--r--gcc/java/constants.c64
1 files changed, 43 insertions, 21 deletions
diff --git a/gcc/java/constants.c b/gcc/java/constants.c
index 11efc2bf0c0..a1872387f18 100644
--- a/gcc/java/constants.c
+++ b/gcc/java/constants.c
@@ -32,6 +32,7 @@ The Free Software Foundation is independent of Sun Microsystems, Inc. */
#include "ggc.h"
static void set_constant_entry (CPool *, int, int, jword);
+static int find_tree_constant (CPool *, int, tree);
static int find_class_or_string_constant (CPool *, int, tree);
static int find_name_and_type_constant (CPool *, tree, tree);
static tree get_tag_node (int);
@@ -49,8 +50,8 @@ set_constant_entry (cpool, index, tag, value)
if (cpool->data == NULL)
{
cpool->capacity = 100;
- cpool->tags = xmalloc (sizeof(uint8) * cpool->capacity);
- cpool->data = xmalloc (sizeof(jword) * cpool->capacity);
+ cpool->tags = ggc_alloc (sizeof(uint8) * cpool->capacity);
+ cpool->data = ggc_alloc (sizeof(union cpool_entry) * cpool->capacity);
cpool->count = 1;
}
if (index >= cpool->capacity)
@@ -58,13 +59,15 @@ set_constant_entry (cpool, index, tag, value)
cpool->capacity *= 2;
if (index >= cpool->capacity)
cpool->capacity = index + 10;
- cpool->tags = xrealloc (cpool->tags, sizeof(uint8) * cpool->capacity);
- cpool->data = xrealloc (cpool->data, sizeof(jword) * cpool->capacity);
+ cpool->tags = ggc_realloc (cpool->tags,
+ sizeof(uint8) * cpool->capacity);
+ cpool->data = ggc_realloc (cpool->data,
+ sizeof(union cpool_entry) * cpool->capacity);
}
if (index >= cpool->count)
cpool->count = index + 1;
cpool->tags[index] = tag;
- cpool->data[index] = value;
+ cpool->data[index].w = value;
}
/* Find (or create) a constant pool entry matching TAG and VALUE. */
@@ -78,7 +81,7 @@ find_constant1 (cpool, tag, value)
int i;
for (i = cpool->count; --i > 0; )
{
- if (cpool->tags[i] == tag && cpool->data[i] == value)
+ if (cpool->tags[i] == tag && cpool->data[i].w == value)
return i;
}
i = cpool->count == 0 ? 1 : cpool->count;
@@ -98,8 +101,8 @@ find_constant2 (cpool, tag, word1, word2)
for (i = cpool->count - 1; --i > 0; )
{
if (cpool->tags[i] == tag
- && cpool->data[i] == word1
- && cpool->data[i+1] == word2)
+ && cpool->data[i].w == word1
+ && cpool->data[i+1].w == word2)
return i;
}
i = cpool->count == 0 ? 1 : cpool->count;
@@ -108,6 +111,25 @@ find_constant2 (cpool, tag, word1, word2)
return i;
}
+static int
+find_tree_constant (cpool, tag, value)
+ CPool *cpool;
+ int tag;
+ tree value;
+{
+ int i;
+ for (i = cpool->count; --i > 0; )
+ {
+ if (cpool->tags[i] == tag && cpool->data[i].t == value)
+ return i;
+ }
+ i = cpool->count == 0 ? 1 : cpool->count;
+ set_constant_entry (cpool, i, tag, 0);
+ cpool->data[i].t = value;
+ return i;
+}
+
+
int
find_utf8_constant (cpool, name)
CPool *cpool;
@@ -115,7 +137,7 @@ find_utf8_constant (cpool, name)
{
if (name == NULL_TREE)
return 0;
- return find_constant1 (cpool, CONSTANT_Utf8, (jword) name);
+ return find_tree_constant (cpool, CONSTANT_Utf8, name);
}
static int
@@ -124,15 +146,15 @@ find_class_or_string_constant (cpool, tag, name)
int tag;
tree name;
{
- int j = find_utf8_constant (cpool, name);
+ jword j = find_utf8_constant (cpool, name);
int i;
for (i = cpool->count; --i > 0; )
{
- if (cpool->tags[i] == tag && cpool->data[i] == (jword) j)
+ if (cpool->tags[i] == tag && cpool->data[i].w == j)
return i;
}
i = cpool->count;
- set_constant_entry (cpool, i, tag, (jword) j);
+ set_constant_entry (cpool, i, tag, j);
return i;
}
@@ -255,7 +277,7 @@ count_constant_pool_bytes (cpool)
break;
case CONSTANT_Utf8:
{
- tree t = (tree) cpool->data[i];
+ tree t = cpool->data[i].t;
int len = IDENTIFIER_LENGTH (t);
size += len + 2;
}
@@ -279,7 +301,7 @@ write_constant_pool (cpool, buffer, length)
{
unsigned char *ptr = buffer;
int i = 1;
- jword *datap = &cpool->data[1];
+ union cpool_entry *datap = &cpool->data[1];
PUT2 (cpool->count);
for ( ; i < cpool->count; i++, datap++)
{
@@ -293,23 +315,23 @@ write_constant_pool (cpool, buffer, length)
case CONSTANT_InterfaceMethodref:
case CONSTANT_Float:
case CONSTANT_Integer:
- PUT4 (*datap);
+ PUT4 (datap->w);
break;
case CONSTANT_Class:
case CONSTANT_String:
- PUT2 (*datap);
+ PUT2 (datap->w);
break;
break;
case CONSTANT_Long:
case CONSTANT_Double:
- PUT4(*datap);
+ PUT4(datap->w);
i++;
datap++;
- PUT4 (*datap);
+ PUT4 (datap->w);
break;
case CONSTANT_Utf8:
{
- tree t = (tree) *datap;
+ tree t = datap->t;
int len = IDENTIFIER_LENGTH (t);
PUT2 (len);
PUTN (IDENTIFIER_POINTER (t), len);
@@ -347,7 +369,7 @@ alloc_name_constant (tag, name)
int tag;
tree name;
{
- return find_constant1 (outgoing_cpool, tag, (jword) name);
+ return find_tree_constant (outgoing_cpool, tag, name);
}
/* Build an identifier for the internal name of reference type TYPE. */
@@ -438,7 +460,7 @@ build_constants_constructor ()
= tree_cons (NULL_TREE, get_tag_node (outgoing_cpool->tags[i]),
tags_list);
data_list
- = tree_cons (NULL_TREE, build_utf8_ref ((tree)outgoing_cpool->data[i]),
+ = tree_cons (NULL_TREE, build_utf8_ref (outgoing_cpool->data[i].t),
data_list);
}
if (outgoing_cpool->count > 0)