diff options
author | Matthias Zenger <mzenger@gmail.com> | 2003-11-11 13:21:09 +0000 |
---|---|---|
committer | Matthias Zenger <mzenger@gmail.com> | 2003-11-11 13:21:09 +0000 |
commit | 2521f5270d8599a6407588cd3ab92143c77bc827 (patch) | |
tree | 1c84600ef4c627d56c24f090c6ab3fba3a8f4c76 /sources/scalac/symtab/classfile/AttributeParser.java | |
parent | 6a5131fc32787d2d4865918a4fb1e480bfc14f8f (diff) | |
download | scala-2521f5270d8599a6407588cd3ab92143c77bc827.tar.gz scala-2521f5270d8599a6407588cd3ab92143c77bc827.tar.bz2 scala-2521f5270d8599a6407588cd3ab92143c77bc827.zip |
Added support for | in algebraic patterns;
Added support for reading ConstantValue attributes;
Diffstat (limited to 'sources/scalac/symtab/classfile/AttributeParser.java')
-rw-r--r-- | sources/scalac/symtab/classfile/AttributeParser.java | 56 |
1 files changed, 49 insertions, 7 deletions
diff --git a/sources/scalac/symtab/classfile/AttributeParser.java b/sources/scalac/symtab/classfile/AttributeParser.java index 7de745ee1f..3e1ac9da20 100644 --- a/sources/scalac/symtab/classfile/AttributeParser.java +++ b/sources/scalac/symtab/classfile/AttributeParser.java @@ -34,6 +34,8 @@ public class AttributeParser implements ClassfileConstants { this.parser = parser; } + /** convert an attribute name into an attribute id + */ public int nameToId(Name name) { if (name == SOURCEFILE_N) return SOURCEFILE_ATTR; @@ -62,6 +64,9 @@ public class AttributeParser implements ClassfileConstants { return BAD_ATTR; } + /** read all attributes associated with symbol 'sym' which are + * contained in 'attrs'. + */ public Symbol readAttributes(Symbol def, Type type, int attrs) { char nattr = in.nextChar(); for (int i = 0; i < nattr; i++) { @@ -79,6 +84,8 @@ public class AttributeParser implements ClassfileConstants { return def; } + /** read a single attribute 'attr' for symbol 'sym' with type 'type'. + */ public void readAttribute(Symbol sym, Type type, int attr, int attrLen) { switch (attr) { // class attributes @@ -93,9 +100,9 @@ public class AttributeParser implements ClassfileConstants { Name name = (Name)pool.readPool(in.nextChar()); int flags = in.nextChar(); if (name != null) { - inner.owner(outer); - inner.mangled(name); - inner.flags = flags; + // inner.owner(outer); + // inner.mangled(name); + // inner.flags = flags; } } */ in.skip(attrLen); @@ -126,9 +133,9 @@ public class AttributeParser implements ClassfileConstants { sym.flags |= Modifiers.DEPRECATED; return; case CONSTANT_VALUE_ATTR: - // Type ctype = (Type)reader.readPool(in.nextChar()); - // def.type = types.coerce(ctype, def.type); - in.skip(attrLen); + Object constVal = pool.readPool(in.nextChar()); + //System.out.println(sym.owner() + "." + sym + ": " + constVal + " of type " + constantType(type, constVal)); + sym.setFirstInfo(constantType(type, constVal)); return; case META_ATTR: //System.out.println("parsing meta data for " + sym); @@ -152,10 +159,45 @@ public class AttributeParser implements ClassfileConstants { } } + /** return the constant type for the given constant. + */ + Type constantType(Type base, Object value) { + if (base.symbol() == parser.global.definitions.BYTE_CLASS) + value = new Byte(((Number)value).byteValue()); + if (base.symbol() == parser.global.definitions.CHAR_CLASS) + value = new Character((char)((Number)value).intValue()); + if (base.symbol() == parser.global.definitions.SHORT_CLASS) + value = new Short(((Number)value).shortValue()); + return Type.ConstantType(base, value); + } + + /** return the type of a given constant. + */ + Type typeOfValue(Object value) { + if (value instanceof Character) + return parser.make.charType(); + else if (value instanceof Integer) + return parser.make.intType(); + else if (value instanceof Long) + return parser.make.longType(); + else if (value instanceof Float) + return parser.make.floatType(); + else if (value instanceof Double) + return parser.make.doubleType(); + else if (value instanceof String) + return parser.global.definitions.JAVA_STRING_CLASS.typeConstructor(); + else if (value instanceof Boolean) + return parser.make.booleanType(); + else + throw new ApplicationError("unknown constant type"); + } + Scope tvars = new Scope(); + /** a parser class for parsing meta type information in classfiles + * generated by pico. + */ class MetaParser { - Symbol owner; StringTokenizer scanner; Type defaultType; |