summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorMiguel Garcia <magarcia@epfl.ch>2011-04-08 11:38:48 +0000
committerMiguel Garcia <magarcia@epfl.ch>2011-04-08 11:38:48 +0000
commit4cf60d65bc8f71969d6012182738c6bb31a4c49b (patch)
tree8f8dc7d307829d82d7f8a32934ce58f12bab3dca /src/compiler
parentcaee04079fb8ed40a1458cf24649fad9d80a85c1 (diff)
downloadscala-4cf60d65bc8f71969d6012182738c6bb31a4c49b.tar.gz
scala-4cf60d65bc8f71969d6012182738c6bb31a4c49b.tar.bz2
scala-4cf60d65bc8f71969d6012182738c6bb31a4c49b.zip
[MSIL] handling of volatile fields.
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/scala/tools/nsc/backend/msil/GenMSIL.scala36
1 files changed, 34 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/msil/GenMSIL.scala b/src/compiler/scala/tools/nsc/backend/msil/GenMSIL.scala
index b8e5c50dfd..a38916b8e4 100644
--- a/src/compiler/scala/tools/nsc/backend/msil/GenMSIL.scala
+++ b/src/compiler/scala/tools/nsc/backend/msil/GenMSIL.scala
@@ -15,6 +15,7 @@ import scala.tools.nsc.symtab._
import ch.epfl.lamp.compiler.msil.{Type => MsilType, _}
import ch.epfl.lamp.compiler.msil.emit._
+import ch.epfl.lamp.compiler.msil.util.PECustomMod
abstract class GenMSIL extends SubComponent {
import global._
@@ -250,10 +251,33 @@ abstract class GenMSIL extends SubComponent {
}
}
+ /**
+ * Mutates `member` adding CLR attributes (if any) based on sym.annotations.
+ * Please notice that CLR custom modifiers are a different beast (see customModifiers below)
+ * and thus shouldn't be added by this method.
+ */
def addAttributes(member: ICustomAttributeSetter, annotations: List[AnnotationInfo]) {
+ val attributes = annotations.map(_.atp.typeSymbol).collect {
+ case definitions.TransientAttr => null // TODO this is just an example
+ }
return // TODO: implement at some point
}
-/*
+
+ /**
+ * What's a CLR custom modifier? Intro available as source comments in compiler.msil.CustomModifier.
+ * It's basically a marker associated with a location (think of FieldInfo, ParameterInfo, and PropertyInfo)
+ * and thus that marker (be it optional or required) becomes part of the signature of that location.
+ * Some annotations will become CLR attributes (see addAttributes above), others custom modifiers (this method).
+ */
+ def customModifiers(annotations: List[AnnotationInfo]): Array[CustomModifier] = {
+ annotations.map(_.atp.typeSymbol).collect {
+ case definitions.VolatileAttr => new CustomModifier(true, CustomModifier.VolatileMarker)
+ } toArray
+ }
+
+
+
+ /*
if (settings.debug.value)
log("creating annotations: " + annotations + " for member : " + member)
for (annot@ AnnotationInfo(typ, annArgs, nvPairs) <- annotations ;
@@ -810,6 +834,9 @@ abstract class GenMSIL extends SubComponent {
fields(field) = fInfo
fInfo
}
+ if (fieldInfo.IsVolatile) {
+ mcode.Emit(OpCodes.Volatile)
+ }
if (!fieldInfo.IsLiteral) {
if (loadAddr) {
mcode.Emit(if (isStatic) OpCodes.Ldsflda else OpCodes.Ldflda, fieldInfo)
@@ -1864,7 +1891,12 @@ abstract class GenMSIL extends SubComponent {
log("Adding field: " + sym.fullName)
var attributes = msilFieldFlags(sym)
- val fBuilder = mtype.DefineField(msilName(sym), msilType(sym.tpe), attributes)
+ val fieldTypeWithCustomMods =
+ new PECustomMod(msilType(sym.tpe),
+ customModifiers(sym.annotations))
+ val fBuilder = mtype.DefineField(msilName(sym),
+ fieldTypeWithCustomMods,
+ attributes)
fields(sym) = fBuilder
addAttributes(fBuilder, sym.annotations)
} // all iclass.fields iterated over