more signature support

git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@590 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
sjfink 2007-01-18 21:24:06 +00:00
parent df26059e7d
commit 5866177006
7 changed files with 206 additions and 22 deletions

View File

@ -0,0 +1,48 @@
/*******************************************************************************
* Copyright (c) 2006 IBM Corporation.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package com.ibm.wala.types.generics;
public class ArrayTypeSignature extends TypeSignature {
ArrayTypeSignature(String s) {
super(s);
assert(s.charAt(0) == '[');
}
@Override
public boolean isClassTypeSignature() {
return false;
}
@Override
public boolean isTypeVariable() {
return false;
}
public static ArrayTypeSignature make(String s) {
return new ArrayTypeSignature(s);
}
@Override
public boolean isArrayTypeSignature() {
return true;
}
public TypeSignature getContents() {
return TypeSignature.make(rawString().substring(1));
}
@Override
public boolean isBaseType() {
return false;
}
}

View File

@ -0,0 +1,58 @@
/*******************************************************************************
* Copyright (c) 2006 IBM Corporation.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package com.ibm.wala.types.generics;
import com.ibm.wala.types.TypeReference;
public class BaseType extends TypeSignature {
private final TypeReference t;
final static BaseType BOOLEAN = new BaseType(TypeReference.BooleanName.toString(),TypeReference.Boolean);
final static BaseType BYTE = new BaseType(TypeReference.ByteName.toString(),TypeReference.Byte);
final static BaseType SHORT = new BaseType(TypeReference.ShortName.toString(),TypeReference.Short);
final static BaseType INT = new BaseType(TypeReference.IntName.toString(),TypeReference.Int);
final static BaseType LONG = new BaseType(TypeReference.LongName.toString(),TypeReference.Long);
final static BaseType FLOAT = new BaseType(TypeReference.FloatName.toString(),TypeReference.Float);
final static BaseType DOUBLE = new BaseType(TypeReference.DoubleName.toString(),TypeReference.Double);
final static BaseType CHAR = new BaseType(TypeReference.CharName.toString(),TypeReference.Char);
final static BaseType VOID = new BaseType(TypeReference.VoidName.toString(),TypeReference.Void);
private BaseType(String s, TypeReference t) {
super(s);
this.t = t;
}
@Override
public boolean isClassTypeSignature() {
return false;
}
@Override
public boolean isTypeVariable() {
return false;
}
public TypeReference getType() {
return t;
}
@Override
public boolean isArrayTypeSignature() {
return false;
}
@Override
public boolean isBaseType() {
return true;
}
}

View File

@ -48,6 +48,11 @@ public class ClassTypeSignature extends TypeSignature {
public boolean isClassTypeSignature() {
return true;
}
@Override
public boolean isArrayTypeSignature() {
return false;
}
public TypeName getRawName() {
String s = rawString().substring(0,rawString().length()-1);
@ -80,5 +85,10 @@ public class ClassTypeSignature extends TypeSignature {
}
return i;
}
@Override
public boolean isBaseType() {
return false;
}
}

View File

@ -152,7 +152,6 @@ public class FormalTypeParameter extends Signature {
result[j] = it.next();
}
return result;
}
public TypeSignature[] getInterfaceBounds() {

View File

@ -40,5 +40,37 @@ public class MethodTypeSignature extends Signature {
}
return result;
}
public FormalTypeParameter[] getFormalTypeParameters() {
if (rawString().charAt(0) != '<') {
// no formal type parameters
return null;
}
int index = endOfFormalTypeParameters();
String[] args = FormalTypeParameter.parseForFormalTypeParameters(rawString().substring(0,index));
FormalTypeParameter[] result = new FormalTypeParameter[args.length];
for (int i = 0; i < args.length; i++) {
result[i] = FormalTypeParameter.make(args[i]);
}
return result;
}
private int endOfFormalTypeParameters() {
if (rawString().charAt(0) != '<') {
return 0;
}
int i = 1;
int depth = 1;
while (depth > 0) {
if (rawString().charAt(i) == '>') {
depth--;
}
if (rawString().charAt(i) == '<') {
depth++;
}
i++;
}
return i;
}
}

View File

@ -19,7 +19,7 @@ import com.ibm.wala.util.debug.Assertions;
/**
* UNDER CONSTRUCTION.
*
* <verbatim>
* <verbatim>
* TypeSignature:
* FieldTypeSignature
* BaseType (code for a primitive)
@ -31,6 +31,7 @@ import com.ibm.wala.util.debug.Assertions;
*
* TypeVariableSignature:
* T identifier ;
*
* </verbatim>
*
* @author sjfink
@ -44,11 +45,33 @@ public abstract class TypeSignature extends Signature {
public static TypeSignature make(String s) {
assert (s.length() > 0);
if (s.charAt(0) == 'L') {
switch (s.charAt(0)) {
case TypeReference.VoidTypeCode:
Assertions.UNREACHABLE();
return null;
case TypeReference.BooleanTypeCode:
return BaseType.BOOLEAN;
case TypeReference.ByteTypeCode:
return BaseType.BYTE;
case TypeReference.ShortTypeCode:
return BaseType.SHORT;
case TypeReference.IntTypeCode:
return BaseType.INT;
case TypeReference.LongTypeCode:
return BaseType.LONG;
case TypeReference.FloatTypeCode:
return BaseType.FLOAT;
case TypeReference.DoubleTypeCode:
return BaseType.DOUBLE;
case TypeReference.CharTypeCode:
return BaseType.CHAR;
case 'L':
return ClassTypeSignature.makeClassTypeSig(s);
} else if (s.charAt(0) == 'T') {
case 'T':
return TypeVariableSignature.make(s);
} else {
case TypeReference.ArrayTypeCode:
return ArrayTypeSignature.make(s);
default:
Assertions.UNREACHABLE(s);
return null;
}
@ -57,6 +80,10 @@ public abstract class TypeSignature extends Signature {
public abstract boolean isTypeVariable();
public abstract boolean isClassTypeSignature();
public abstract boolean isArrayTypeSignature();
public abstract boolean isBaseType();
/**
* @param typeSigs
@ -100,10 +127,10 @@ public abstract class TypeSignature extends Signature {
int off = i - 1;
int depth = 0;
while (typeSigs.charAt(i++) != ';' || depth > 0) {
if (typeSigs.charAt(i-1) == '<') {
if (typeSigs.charAt(i - 1) == '<') {
depth++;
}
if (typeSigs.charAt(i-1) == '>') {
if (typeSigs.charAt(i - 1) == '>') {
depth--;
}
}
@ -112,16 +139,17 @@ public abstract class TypeSignature extends Signature {
}
case TypeReference.ArrayTypeCode: {
int off = i - 1;
while (typeSigs.charAt(i) == TypeReference.ArrayTypeCode) {
++i;
}
if (typeSigs.charAt(i++) == TypeReference.ClassTypeCode) {
while (typeSigs.charAt(i++) != ';')
;
sigs.add(typeSigs.substring(off, i - off - 1));
} else {
sigs.add(typeSigs.substring(off, i - off));
i++;
int depth = 0;
while (typeSigs.charAt(i++) != ';' || depth > 0) {
if (typeSigs.charAt(i - 1) == '<') {
depth++;
}
if (typeSigs.charAt(i - 1) == '>') {
depth--;
}
}
sigs.add(typeSigs.substring(off, i));
continue;
}
case (byte) 'T': { // type variable
@ -149,4 +177,5 @@ public abstract class TypeSignature extends Signature {
}
}
}
}

View File

@ -10,19 +10,17 @@
*******************************************************************************/
package com.ibm.wala.types.generics;
/**
* TypeVariableSignature:
* T identifier ;
* TypeVariableSignature: T identifier ;
*
* @author sjfink
*
*
*/
public class TypeVariableSignature extends TypeSignature {
private TypeVariableSignature(String s) {
super(s);
assert (s.charAt(s.length()-1) == ';');
assert (s.charAt(s.length() - 1) == ';');
}
public static TypeVariableSignature make(String s) {
@ -39,7 +37,17 @@ public class TypeVariableSignature extends TypeSignature {
return true;
}
@Override
public boolean isArrayTypeSignature() {
return false;
}
public String getIdentifier() {
return rawString().substring(1, rawString().length()-1);
return rawString().substring(1, rawString().length() - 1);
}
@Override
public boolean isBaseType() {
return false;
}
}