support for volatile

This commit is contained in:
Alex Tkachman
2012-01-31 12:21:18 +02:00
parent 2826db7d9a
commit 27425c5851
4 changed files with 37 additions and 0 deletions
@@ -76,6 +76,9 @@ public class PropertyCodegen {
if (!propertyDescriptor.isVar()) {
modifiers |= Opcodes.ACC_FINAL;
}
if(state.getStandardLibrary().isVolatile(propertyDescriptor)) {
modifiers |= Opcodes.ACC_VOLATILE;
}
v.newField(p, modifiers, p.getName(), state.getTypeMapper().mapType(propertyDescriptor.getOutType()).getDescriptor(), null, value);
}
}
+2
View File
@@ -8,6 +8,8 @@ class TypeInfo<out T> {
fun typeinfo<T>() : TypeInfo<T>
fun typeinfo<T>(expression : T) : TypeInfo<T>
annotation class volatile
fun <R> synchronized(lock: Any, block : () -> R) : R
fun Any?.identityEquals(other : Any?) : Boolean // = this === other
@@ -9,6 +9,7 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.JetSemanticServices;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
@@ -61,8 +62,10 @@ public class JetStandardLibrary {
private ClassDescriptor iterableClass;
private ClassDescriptor typeInfoClass;
private ClassDescriptor comparableClass;
private ClassDescriptor volatileClass;
private JetType stringType;
private JetType volatileType;
private JetType nullableStringType;
private JetType charSequenceType;
private JetType nullableCharSequenceType;
@@ -138,6 +141,7 @@ public class JetStandardLibrary {
this.stringClass = (ClassDescriptor) libraryScope.getClassifier("String");
this.charSequenceClass = (ClassDescriptor) libraryScope.getClassifier("CharSequence");
this.arrayClass = (ClassDescriptor) libraryScope.getClassifier("Array");
this.volatileClass = (ClassDescriptor) libraryScope.getClassifier("volatile");
this.iterableClass = (ClassDescriptor) libraryScope.getClassifier("Iterable");
this.comparableClass = (ClassDescriptor) libraryScope.getClassifier("Comparable");
@@ -149,6 +153,7 @@ public class JetStandardLibrary {
this.charSequenceType = new JetTypeImpl(getCharSequence());
this.nullableCharSequenceType = TypeUtils.makeNullable(charSequenceType);
this.nullableStringType = TypeUtils.makeNullable(stringType);
this.volatileType = new JetTypeImpl(getVolatile());
this.tuple0Type = new JetTypeImpl(JetStandardClasses.getTuple(0));
this.nullableTuple0Type = TypeUtils.makeNullable(tuple0Type);
@@ -445,4 +450,22 @@ public class JetStandardLibrary {
return primitiveTypeToNullableArrayJetType.get(primitiveType);
}
public ClassDescriptor getVolatile() {
return volatileClass;
}
public JetType getVolatileType() {
return volatileType;
}
public final boolean isVolatile(PropertyDescriptor descriptor) {
List<AnnotationDescriptor> annotations = descriptor.getOriginal().getAnnotations();
if(annotations != null) {
for(AnnotationDescriptor d: annotations) {
if(d.getType().equals(getVolatileType()))
return true;
}
}
return false;
}
}
@@ -149,6 +149,15 @@ public class PropertyGenTest extends CodegenTestCase {
assertNotNull(aClass.getMethod("getX"));
}
public void testVolatileProperty() throws Exception {
loadText("abstract class Foo { public volatile var x: String = \"\"; }");
System.out.println(generateToText());
final ClassFileFactory codegens = generateClassesInFile();
final Class aClass = loadClass("Foo", codegens);
Field x = aClass.getDeclaredField("x");
assertTrue((x.getModifiers() & Modifier.VOLATILE) != 0);
}
public void testKt257 () throws Exception {
blackBoxFile("regressions/kt257.jet");
// System.out.println(generateToText());