diff options
139 files changed, 1069 insertions, 4556 deletions
@@ -249,7 +249,7 @@ INITIALISATION <!-- Resolve maven dependencies --> <target name="init.maven.jars" depends="init.maven.tasks"> <artifact:dependencies pathId="dependency.classpath" filesetId="dependency.fileset"> - <dependency groupId="org.skife.com.typesafe.config" artifactId="typesafe-config" version="0.3.0"/> + <dependency groupId="com.typesafe" artifactId="config" version="0.4.0"/> </artifact:dependencies> </target> @@ -415,7 +415,7 @@ LOCAL REFERENCE BUILD (LOCKER) classpath="${build-locker.dir}/classes/library" includes="**/*.java" target="1.5" source="1.5"> - <compilerarg line="${javac.args}"/> + <compilerarg line="${javac.args} -XDignore.symbol.file"/> </javac> <!-- NOTE: Potential problem with maximal command line length on Windows (32768 characters for XP, since executed with Java's "exec"). See @@ -643,7 +643,6 @@ QUICK BUILD (QUICK) <uptodate property="quick.lib.available" targetfile="${build-quick.dir}/library.complete"> <srcfiles dir="${src.dir}"> <include name="library/**"/> - <include name="dbc/**"/> <include name="continuations/**"/> <include name="swing/**"/> <include name="actors/**"/> @@ -660,7 +659,7 @@ QUICK BUILD (QUICK) classpath="${build-quick.dir}/classes/library" includes="**/*.java" target="1.5" source="1.5"> - <compilerarg line="${javac.args}"/> + <compilerarg line="${javac.args} -XDignore.symbol.file"/> </javac> <javac srcdir="${src.dir}/actors" @@ -693,15 +692,6 @@ QUICK BUILD (QUICK) destdir="${build-quick.dir}/classes/library" compilerpathref="locker.classpath" params="${scalac.args.quick}" - srcdir="${src.dir}/dbc" - jvmargs="${scalacfork.jvmargs}"> - <include name="**/*.scala"/> - <compilationpath refid="quick.compilation.path"/> - </scalacfork> - <scalacfork - destdir="${build-quick.dir}/classes/library" - compilerpathref="locker.classpath" - params="${scalac.args.quick}" srcdir="${src.dir}/swing" jvmargs="${scalacfork.jvmargs}"> <include name="**/*.scala"/> @@ -1028,17 +1018,11 @@ PACKED QUICK BUILD (PACK) </copy> <jar destfile="${build-pack.dir}/lib/scala-library.jar"> <fileset dir="${build-quick.dir}/classes/library"> - <exclude name="scala/dbc/**"/> <exclude name="scala/swing/**"/> <exclude name="scala/actors/**"/> </fileset> <zipfileset dirmode="755" filemode="644" src="${forkjoin.jar}"/> </jar> - <jar destfile="${build-pack.dir}/lib/scala-dbc.jar"> - <fileset dir="${build-quick.dir}/classes/library"> - <include name="scala/dbc/**"/> - </fileset> - </jar> <jar destfile="${build-pack.dir}/lib/scala-swing.jar"> <fileset dir="${build-quick.dir}/classes/library"> <include name="scala/swing/**"/> @@ -1201,7 +1185,6 @@ BOOTSTRAPPING BUILD (STRAP) <uptodate property="strap.lib.available" targetfile="${build-strap.dir}/library.complete"> <srcfiles dir="${src.dir}"> <include name="library/**"/> - <include name="dbc/**"/> <include name="swing/**"/> <include name="actors/**"/> </srcfiles> @@ -1217,7 +1200,7 @@ BOOTSTRAPPING BUILD (STRAP) classpath="${build-strap.dir}/classes/library" includes="**/*.java" target="1.5" source="1.5"> - <compilerarg line="${javac.args}"/> + <compilerarg line="${javac.args} -XDignore.symbol.file"/> </javac> <javac srcdir="${src.dir}/actors" @@ -1250,15 +1233,6 @@ BOOTSTRAPPING BUILD (STRAP) destdir="${build-strap.dir}/classes/library" compilerpathref="pack.classpath" params="${scalac.args.all}" - srcdir="${src.dir}/dbc" - jvmargs="${scalacfork.jvmargs}"> - <include name="**/*.scala"/> - <compilationpath refid="strap.compilation.path"/> - </scalacfork> - <scalacfork - destdir="${build-strap.dir}/classes/library" - compilerpathref="pack.classpath" - params="${scalac.args.all}" srcdir="${src.dir}/swing" jvmargs="${scalacfork.jvmargs}"> <include name="**/*.scala"/> @@ -1645,7 +1619,6 @@ DOCUMENTATION <doc-uptodate-check name="library" srcdir="${src.dir}"> <source-includes> <include name="library/**"/> - <include name="dbc/**"/> <include name="swing/**"/> <include name="actors/**"/> </source-includes> @@ -2033,9 +2006,6 @@ DISTRIBUTION <fileset dir="${src.dir}/library"/> <fileset dir="${src.dir}/continuations/library"/> </jar> - <jar destfile="${dist.dir}/src/scala-dbc-src.jar"> - <fileset dir="${src.dir}/dbc"/> - </jar> <jar destfile="${dist.dir}/src/scala-swing-src.jar"> <fileset dir="${src.dir}/swing"/> </jar> @@ -2123,7 +2093,6 @@ STABLE REFERENCE (STARR) <fileset dir="${basedir}/src/library"/> <fileset dir="${basedir}/src/swing"/> <fileset dir="${basedir}/src/actors"/> - <fileset dir="${basedir}/src/dbc"/> </jar> </target> @@ -2226,9 +2195,6 @@ POSITIONS <param name="test.srcs" value="${src.dir}/actors"/> </antcall> <antcall target="test.positions.sub" inheritRefs="true"> - <param name="test.srcs" value="${src.dir}/dbc"/> - </antcall> - <antcall target="test.positions.sub" inheritRefs="true"> <param name="test.srcs" value="${src.dir}/swing"/> </antcall> <antcall target="test.positions.sub" inheritRefs="true"> diff --git a/docs/development/scala.dbc/SQLTypes.dot b/docs/development/scala.dbc/SQLTypes.dot deleted file mode 100644 index 77c27cf729..0000000000 --- a/docs/development/scala.dbc/SQLTypes.dot +++ /dev/null @@ -1,48 +0,0 @@ -digraph SQLTypes { - node [shape = record] - DataType [label = "{DataType|nullable: Boolean}"] - StringType [label = "{StringType|maxLength: Int}"] - CharacterStringType [label = "{CharacterStringType|encoding: String}"] - CharacterType [label = "{CharacterType|length: Int}"] - CharacterVaryingType [label = "{CharacterVaryingType|length: Int}"] - CharacterLargeObjectType [label = "CharacterLargeObjectType"] - BinaryStringType [label = "BinaryStringType"] - BinaryType [label = "{BinaryType|length: Int}"] - BinaryVaryingType [label = "{BinaryVaryingType|length: Int}"] - BinaryLargeObjectType [label = "BinaryLargeObjectType"] - BooleanType [label = "BooleanType"] - NumericType [label = "{NumericType|precisionRadix: Int\nprecision: Int}"] - ExactNumericType [label = "{ExactNumericType|scale: Int}"] - ApproximateNumericType [label = "ApproximateNumericType"] - DateTimeType [label = "DateTimeType"] - TimeType [label = "{TimeType|precisionRadix: Int\nsecondScale: Int}"] - TimeWithoutTimezoneType [label = "TimeWithoutTimezoneType"] - TimeWithTimezoneType [label = "TimeWithTimezoneType"] - TimestampType [label = "{TimestampType|precisionRadix: Int\nsecondScale: Int}"] - TimestampWithoutTimezoneType [label = "TimestampWithoutTimezoneType"] - TimestampWithTimezoneType [label = "TimestampWithTimezoneType"] - DateType [label = "DateType"] - IntervalType [label = "{IntervalType|precisionRadix: Int\nsecondScale: Int}"] - StringType -> DataType - BooleanType -> DataType - NumericType -> DataType - DateTimeType -> DataType - IntervalType -> DataType - CharacterStringType -> StringType - BinaryStringType -> StringType - ExactNumericType -> NumericType - ApproximateNumericType -> NumericType - TimeType -> DateTimeType - TimestampType -> DateTimeType - DateType -> DateTimeType - CharacterType -> CharacterStringType - CharacterVaryingType -> CharacterStringType - CharacterLargeObjectType -> CharacterStringType - BinaryType -> BinaryStringType - BinaryVaryingType -> BinaryStringType - BinaryLargeObjectType -> BinaryStringType - TimeWithoutTimezoneType -> TimeType - TimeWithTimezoneType -> TimeType - TimestampWithoutTimezoneType -> TimestampType - TimestampWithTimezoneType -> TimestampType -} diff --git a/lib/scala-compiler.jar.desired.sha1 b/lib/scala-compiler.jar.desired.sha1 index 3d5a0edfd5..7479a1861e 100644 --- a/lib/scala-compiler.jar.desired.sha1 +++ b/lib/scala-compiler.jar.desired.sha1 @@ -1 +1 @@ -52e6cc393c953df8c6cbe710f8d62dce6cd1f671 ?scala-compiler.jar +5d99e65aaa8e00c4815e011a8dfc495cb38bdfcc ?scala-compiler.jar diff --git a/lib/scala-library.jar.desired.sha1 b/lib/scala-library.jar.desired.sha1 index 028ef2fae2..76914369b5 100644 --- a/lib/scala-library.jar.desired.sha1 +++ b/lib/scala-library.jar.desired.sha1 @@ -1 +1 @@ -569b35836872765f0b96a6477d7c37a257cc62e7 ?scala-library.jar +53ddaba2c7d56b360eda1a56c3eef5ec23ef14ca ?scala-library.jar diff --git a/project/Build.scala b/project/Build.scala index 9f73563f8e..25fb31cf5b 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -77,9 +77,9 @@ object ScalaBuild extends Build with Layers { ) // Collections of projects to run 'compile' on. - lazy val compiledProjects = Seq(quickLib, quickComp, continuationsLibrary, actors, swing, dbc, forkjoin, fjbg) + lazy val compiledProjects = Seq(quickLib, quickComp, continuationsLibrary, actors, swing, forkjoin, fjbg) // Collection of projects to 'package' and 'publish' together. - lazy val packagedBinaryProjects = Seq(scalaLibrary, scalaCompiler, swing, dbc, continuationsPlugin, jline, scalap) + lazy val packagedBinaryProjects = Seq(scalaLibrary, scalaCompiler, swing, continuationsPlugin, jline, scalap) lazy val partestRunProjects = Seq(testsuite, continuationsTestsuite) private def epflPomExtra = ( @@ -249,7 +249,6 @@ object ScalaBuild extends Build with Layers { // TODO - Actors + swing separate jars... lazy val dependentProjectSettings = settingOverrides ++ Seq(quickScalaInstance, quickScalaLibraryDependency, addCheaterDependency("scala-library")) lazy val actors = Project("actors", file(".")) settings(dependentProjectSettings:_*) dependsOn(forkjoin % "provided") - lazy val dbc = Project("dbc", file(".")) settings(dependentProjectSettings:_*) // TODO - Remove actors dependency from pom... lazy val swing = Project("swing", file(".")) settings(dependentProjectSettings:_*) dependsOn(actors % "provided") // This project will generate man pages (in man1 and html) for scala. @@ -489,7 +488,7 @@ object ScalaBuild extends Build with Layers { genBin <<= genBinTask(genBinRunner, binDir, fullClasspath in Runtime, false), binDir in genBinQuick <<= baseDirectory apply (_ / "target" / "bin"), // Configure the classpath this way to avoid having .jar files and previous layers on the classpath. - fullClasspath in Runtime in genBinQuick <<= Seq(quickComp,quickLib,scalap,actors,swing,dbc,fjbg,jline,forkjoin).map(classDirectory in Compile in _).join.map(Attributed.blankSeq), + fullClasspath in Runtime in genBinQuick <<= Seq(quickComp,quickLib,scalap,actors,swing,fjbg,jline,forkjoin).map(classDirectory in Compile in _).join.map(Attributed.blankSeq), fullClasspath in Runtime in genBinQuick <++= (fullClasspath in Compile in jline), genBinQuick <<= genBinTask(genBinRunner, binDir in genBinQuick, fullClasspath in Runtime in genBinQuick, true), runManmakerMan <<= runManmakerTask(fullClasspath in Runtime in manmaker, runner in manmaker, "scala.tools.docutil.EmitManPage", "man1", ".1"), @@ -518,10 +517,9 @@ object ScalaBuild extends Build with Layers { }, // Add in some more dependencies makeDistMappings <<= (makeDistMappings, - packageBin in swing in Compile, - packageBin in dbc in Compile) map { + packageBin in swing in Compile) map { (dist, s, d) => - dist ++ Seq(s -> "lib/scala-swing.jar", d -> "lib/scala-dbc.jar") + dist ++ Seq(s -> "lib/scala-swing.jar") }, makeDist <<= (makeDistMappings, baseDirectory, streams) map { (maps, dir, s) => s.log.debug("Map = " + maps.mkString("\n")) diff --git a/src/build/genprod.scala b/src/build/genprod.scala index 6016f6fb92..1ea0bf7b73 100644 --- a/src/build/genprod.scala +++ b/src/build/genprod.scala @@ -578,7 +578,7 @@ class Product(val i: Int) extends Group("Product") with Arity { * otherwise throws an `IndexOutOfBoundsException`. * * @param n number of the projection to be returned - * @return same as `._(n+1)`, for example `productElement(1)` is the same as `._1`. + * @return same as `._(n+1)`, for example `productElement(0)` is the same as `._1`. * @throws IndexOutOfBoundsException */ """ diff --git a/src/build/maven/maven-deploy.xml b/src/build/maven/maven-deploy.xml index 7f8343a84e..ac0f8f745b 100644 --- a/src/build/maven/maven-deploy.xml +++ b/src/build/maven/maven-deploy.xml @@ -112,7 +112,6 @@ <deploy-local name="scala-compiler" version="@{version}" repository="@{repository}" /> <deploy-local-plugin name="continuations" version="@{version}" repository="@{repository}"/> <deploy-local name="scala-actors" version="@{version}" repository="@{repository}" /> - <deploy-local name="scala-dbc" version="@{version}" repository="@{repository}" /> <deploy-local name="scala-swing" version="@{version}" repository="@{repository}"/> <deploy-local name="scalap" version="@{version}" repository="@{repository}"/> <deploy-local name="scala-partest" version="@{version}" repository="@{repository}"/> @@ -171,7 +170,6 @@ </deploy-remote> <deploy-remote name="jline" version="@{version}" repository="@{repository}"/> <deploy-remote name="scala-compiler" version="@{version}" repository="@{repository}" /> - <deploy-remote name="scala-dbc" version="@{version}" repository="@{repository}" /> <deploy-remote name="scala-swing" version="@{version}" repository="@{repository}"/> <deploy-remote name="scala-actors" version="@{version}" repository="@{repository}"/> <deploy-remote name="scalap" version="@{version}" repository="@{repository}"/> @@ -239,7 +237,6 @@ <deploy-remote-signed name="scala-library" version="@{version}" repository="@{repository}"/> <deploy-remote-signed name="jline" version="@{version}" repository="@{repository}"/> <deploy-remote-signed name="scala-compiler" version="@{version}" repository="@{repository}" /> - <deploy-remote-signed name="scala-dbc" version="@{version}" repository="@{repository}" /> <deploy-remote-signed name="scala-swing" version="@{version}" repository="@{repository}"/> <deploy-remote-signed name="scala-actors" version="@{version}" repository="@{repository}"/> <deploy-remote-signed name="scalap" version="@{version}" repository="@{repository}"/> diff --git a/src/build/maven/scala-dbc-pom.xml b/src/build/maven/scala-dbc-pom.xml deleted file mode 100644 index aa3d050c1e..0000000000 --- a/src/build/maven/scala-dbc-pom.xml +++ /dev/null @@ -1,61 +0,0 @@ -<project - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <groupId>org.scala-lang</groupId> - <artifactId>scala-dbc</artifactId> - <packaging>jar</packaging> - <version>@VERSION@</version> - <name>Scala Database Connectivity</name> - <description>Connectivity for your DBs</description> - <url>http://www.scala-lang.org/</url> - <inceptionYear>2002</inceptionYear> - <organization> - <name>LAMP/EPFL</name> - <url>http://lamp.epfl.ch/</url> - </organization> - <licenses> - <license> - <name>BSD-like</name> - <url>http://www.scala-lang.org/downloads/license.html - </url> - <distribution>repo</distribution> - </license> - </licenses> - <scm> - <connection>scm:git:git://github.com/scala/scala.git</connection> - <url>https://github.com/scala/scala.git</url> - </scm> - <issueManagement> - <system>JIRA</system> - <url>https://issues.scala-lang.org/</url> - </issueManagement> - <dependencies> - <dependency> - <groupId>org.scala-lang</groupId> - <artifactId>scala-library</artifactId> - <version>@VERSION@</version> - </dependency> - </dependencies> - <distributionManagement> - <repository> - <id>scala-tools.org</id> - <url>@RELEASE_REPOSITORY@</url> - </repository> - <snapshotRepository> - <id>scala-tools.org</id> - <url>@SNAPSHOT_REPOSITORY@</url> - <uniqueVersion>false</uniqueVersion> - </snapshotRepository> - </distributionManagement> - <developers> - <developer> - <id>lamp</id> - <name>EPFL LAMP</name> - </developer> - <developer> - <id>Typesafe</id> - <name>Typesafe, Inc.</name> - </developer> - </developers> -</project> diff --git a/src/build/maven/scala-library-pom.xml b/src/build/maven/scala-library-pom.xml index c3f8a4531c..e8db512125 100644 --- a/src/build/maven/scala-library-pom.xml +++ b/src/build/maven/scala-library-pom.xml @@ -32,9 +32,9 @@ </issueManagement> <dependencies> <dependency> - <groupId>org.skife.com.typesafe.config</groupId> - <artifactId>typesafe-config</artifactId> - <version>0.3.0</version> + <groupId>com.typesafe</groupId> + <artifactId>config</artifactId> + <version>0.4.0</version> </dependency> </dependencies> <distributionManagement> diff --git a/src/build/pack.xml b/src/build/pack.xml index 3bd4d7a199..f96c6b9799 100644 --- a/src/build/pack.xml +++ b/src/build/pack.xml @@ -137,7 +137,6 @@ MAIN DISTRIBUTION PACKAGING <mvn-copy-lib mvn.artifact.name="jline"/> <mvn-copy-lib mvn.artifact.name="scala-library"/> <mvn-copy-lib mvn.artifact.name="scala-compiler"/> - <mvn-copy-lib mvn.artifact.name="scala-dbc"/> <mvn-copy-lib mvn.artifact.name="scala-swing"/> <mvn-copy-lib mvn.artifact.name="scala-actors"/> <mvn-copy-lib mvn.artifact.name="scala-partest"/> @@ -202,11 +201,9 @@ MAIN DISTRIBUTION PACKAGING basedir="${build-docs.dir}/continuations-plugin"> <include name="**/*"/> </jar> - <!-- TODO - Scala swing, dbc and actors should maybe have thier own jar, but creating it is SLOW. --> + <!-- TODO - Scala swing and actors should maybe have thier own jar, but creating it is SLOW. --> <copy tofile="${dists.dir}/maven/${version.number}/scala-swing/scala-swing-docs.jar" file="${dists.dir}/maven/${version.number}/scala-library/scala-library-docs.jar"/> - <copy tofile="${dists.dir}/maven/${version.number}/scala-dbc/scala-dbc-docs.jar" - file="${dists.dir}/maven/${version.number}/scala-library/scala-library-docs.jar"/> <copy tofile="${dists.dir}/maven/${version.number}/scala-actors/scala-actors-docs.jar" file="${dists.dir}/maven/${version.number}/scala-library/scala-library-docs.jar"/> </target> diff --git a/src/compiler/scala/reflect/internal/Definitions.scala b/src/compiler/scala/reflect/internal/Definitions.scala index 7353e69ab6..24fc7c7cc4 100644 --- a/src/compiler/scala/reflect/internal/Definitions.scala +++ b/src/compiler/scala/reflect/internal/Definitions.scala @@ -15,6 +15,8 @@ import scala.reflect.{ mirror => rm } trait Definitions extends reflect.api.StandardDefinitions { self: SymbolTable => + object definitions extends DefinitionsClass + // [Eugene] find a way to make these non-lazy lazy val ByteTpe = definitions.ByteClass.asType lazy val ShortTpe = definitions.ShortClass.asType @@ -41,34 +43,21 @@ trait Definitions extends reflect.api.StandardDefinitions { */ private type PolyMethodCreator = List[Symbol] => (Option[List[Type]], Type) - private def enterNewClass(owner: Symbol, name: TypeName, parents: List[Type], flags: Long = 0L): Symbol = { + private def enterNewClass(owner: Symbol, name: TypeName, parents: List[Type], flags: Long = 0L): ClassSymbol = { val clazz = owner.newClassSymbol(name, NoPosition, flags) clazz setInfoAndEnter ClassInfoType(parents, newScope, clazz) } - private def newMethod(owner: Symbol, name: TermName, formals: List[Type], restpe: Type, flags: Long = 0L): Symbol = { + private def newMethod(owner: Symbol, name: TermName, formals: List[Type], restpe: Type, flags: Long = 0L): MethodSymbol = { val msym = owner.newMethod(name.encode, NoPosition, flags) val params = msym.newSyntheticValueParams(formals) msym setInfo MethodType(params, restpe) } - private def enterNewMethod(owner: Symbol, name: TermName, formals: List[Type], restpe: Type, flags: Long = 0L): Symbol = + private def enterNewMethod(owner: Symbol, name: TermName, formals: List[Type], restpe: Type, flags: Long = 0L): MethodSymbol = owner.info.decls enter newMethod(owner, name, formals, restpe, flags) // the scala value classes trait ValueClassDefinitions { - self: definitions.type => - - private[Definitions] def valueCache(name: Name) = { - val res = ( - if (name.isTypeName) ScalaPackageClass.info member name - else ScalaPackageClass.info member name suchThat (_ hasFlag MODULE) - ) - if (res eq NoSymbol) - abort("Could not find value classes! This is a catastrophic failure. scala " + scala.util.Properties.versionString) - else res - } - private[Definitions] def valueModuleMethod(className: Name, methodName: Name): Symbol = { - valueCache(className.toTermName).moduleClass.tpe member methodName - } + self: DefinitionsClass => import ClassfileConstants._ @@ -94,6 +83,25 @@ trait Definitions extends reflect.api.StandardDefinitions { tpnme.Unit -> VOID_TAG ) + private def catastrophicFailure() = + abort("Could not find value classes! This is a catastrophic failure. scala " + + scala.util.Properties.versionString) + + private def valueClassSymbol(name: TypeName): ClassSymbol = { + getMember(ScalaPackageClass, name) match { + case x: ClassSymbol => x + case _ => catastrophicFailure() + } + } + private def valueClassCompanion(name: TermName): ModuleSymbol = { + getMember(ScalaPackageClass, name) match { + case x: ModuleSymbol => x + case _ => catastrophicFailure() + } + } + private def valueCompanionMember(className: Name, methodName: TermName): MethodSymbol = + getMemberMethod(valueClassCompanion(className.toTermName).moduleClass, methodName) + private def classesMap[T](f: Name => T) = symbolsMap(ScalaValueClassesNoUnit, f) private def symbolsMap[T](syms: List[Symbol], f: Name => T): Map[Symbol, T] = syms zip (syms map (x => f(x.name))) toMap private def symbolsMapFilt[T](syms: List[Symbol], p: Name => Boolean, f: Name => T) = symbolsMap(syms filter (x => p(x.name)), f) @@ -106,8 +114,8 @@ trait Definitions extends reflect.api.StandardDefinitions { lazy val boxedClass = classesMap(x => getClass(boxedName(x))) lazy val refClass = classesMap(x => getRequiredClass("scala.runtime." + x + "Ref")) lazy val volatileRefClass = classesMap(x => getRequiredClass("scala.runtime.Volatile" + x + "Ref")) - lazy val boxMethod = classesMap(x => valueModuleMethod(x, nme.box)) - lazy val unboxMethod = classesMap(x => valueModuleMethod(x, nme.unbox)) + lazy val boxMethod = classesMap(x => valueCompanionMember(x, nme.box)) + lazy val unboxMethod = classesMap(x => valueCompanionMember(x, nme.unbox)) def isNumericSubClass(sub: Symbol, sup: Symbol) = ( (numericWeight contains sub) @@ -116,27 +124,28 @@ trait Definitions extends reflect.api.StandardDefinitions { ) /** Is symbol a numeric value class? */ - def isNumericValueClass(sym: Symbol): Boolean = - numericWeight contains sym + def isNumericValueClass(sym: Symbol) = ScalaNumericValueClasses contains sym def isGetClass(sym: Symbol) = (sym.name == nme.getClass_) && flattensToEmpty(sym.paramss) - lazy val UnitClass = valueCache(tpnme.Unit) - lazy val ByteClass = valueCache(tpnme.Byte) - lazy val ShortClass = valueCache(tpnme.Short) - lazy val CharClass = valueCache(tpnme.Char) - lazy val IntClass = valueCache(tpnme.Int) - lazy val LongClass = valueCache(tpnme.Long) - lazy val FloatClass = valueCache(tpnme.Float) - lazy val DoubleClass = valueCache(tpnme.Double) - lazy val BooleanClass = valueCache(tpnme.Boolean) + lazy val UnitClass = valueClassSymbol(tpnme.Unit) + lazy val ByteClass = valueClassSymbol(tpnme.Byte) + lazy val ShortClass = valueClassSymbol(tpnme.Short) + lazy val CharClass = valueClassSymbol(tpnme.Char) + lazy val IntClass = valueClassSymbol(tpnme.Int) + lazy val LongClass = valueClassSymbol(tpnme.Long) + lazy val FloatClass = valueClassSymbol(tpnme.Float) + lazy val DoubleClass = valueClassSymbol(tpnme.Double) + lazy val BooleanClass = valueClassSymbol(tpnme.Boolean) lazy val Boolean_and = getMember(BooleanClass, nme.ZAND) lazy val Boolean_or = getMember(BooleanClass, nme.ZOR) lazy val Boolean_not = getMember(BooleanClass, nme.UNARY_!) + lazy val ScalaNumericValueClasses = ScalaValueClasses filterNot Set[Symbol](UnitClass, BooleanClass) + def ScalaValueClassesNoUnit = ScalaValueClasses filterNot (_ eq UnitClass) - def ScalaValueClasses: List[Symbol] = List( + def ScalaValueClasses: List[ClassSymbol] = List( UnitClass, BooleanClass, ByteClass, @@ -148,10 +157,10 @@ trait Definitions extends reflect.api.StandardDefinitions { DoubleClass ) def ScalaValueClassCompanions: List[Symbol] = ScalaValueClasses map (_.companionSymbol) - def ScalaPrimitiveValueClasses: List[Symbol] = ScalaValueClasses + def ScalaPrimitiveValueClasses: List[ClassSymbol] = ScalaValueClasses } - object definitions extends AbsDefinitions with ValueClassDefinitions { + abstract class DefinitionsClass extends AbsDefinitions with ValueClassDefinitions { private var isInitialized = false def isDefinitionsInitialized = isInitialized @@ -207,15 +216,14 @@ trait Definitions extends reflect.api.StandardDefinitions { } // It becomes tricky to create dedicated objects for other symbols because // of initialization order issues. - lazy val JavaLangPackage = getModule(sn.JavaLang) + lazy val JavaLangPackage = getRequiredPackage(sn.JavaLang) lazy val JavaLangPackageClass = JavaLangPackage.moduleClass - lazy val ScalaPackage = getModule(nme.scala_) + lazy val ScalaPackage = getRequiredPackage(nme.scala_) lazy val ScalaPackageClass = ScalaPackage.moduleClass - - lazy val RuntimePackage = getRequiredModule("scala.runtime") + lazy val RuntimePackage = getRequiredPackage("scala.runtime") lazy val RuntimePackageClass = RuntimePackage.moduleClass - lazy val JavaLangEnumClass = getRequiredClass("java.lang.Enum") + lazy val JavaLangEnumClass = requiredClass[java.lang.Enum[_]] // convenient one-argument parameter lists lazy val anyparam = List(AnyClass.tpe) @@ -268,9 +276,9 @@ trait Definitions extends reflect.api.StandardDefinitions { } // top types - lazy val AnyClass = enterNewClass(ScalaPackageClass, tpnme.Any, Nil, ABSTRACT) - lazy val AnyRefClass = newAlias(ScalaPackageClass, tpnme.AnyRef, ObjectClass.tpe) - lazy val ObjectClass = getClass(sn.Object) + lazy val AnyClass = enterNewClass(ScalaPackageClass, tpnme.Any, Nil, ABSTRACT) + lazy val AnyRefClass = newAlias(ScalaPackageClass, tpnme.AnyRef, ObjectClass.tpe) + lazy val ObjectClass = getRequiredClass(sn.Object.toString) // Note: this is not the type alias AnyRef, it's a companion-like // object used by the @specialize annotation. @@ -278,12 +286,13 @@ trait Definitions extends reflect.api.StandardDefinitions { @deprecated("Use AnyRefModule", "2.10.0") def Predef_AnyRef = AnyRefModule - lazy val AnyValClass = ScalaPackageClass.info member tpnme.AnyVal orElse { + lazy val AnyValClass: ClassSymbol = (ScalaPackageClass.info member tpnme.AnyVal orElse { val anyval = enterNewClass(ScalaPackageClass, tpnme.AnyVal, List(AnyClass.tpe, NotNullClass.tpe), ABSTRACT) val av_constr = anyval.newClassConstructor(NoPosition) anyval.info.decls enter av_constr anyval - } + }).asInstanceOf[ClassSymbol] + lazy val AnyVal_getClass = enterNewMethod(AnyValClass, nme.getClass_, Nil, getClassReturnType(AnyValClass.tpe)) // bottom types @@ -308,24 +317,24 @@ trait Definitions extends reflect.api.StandardDefinitions { } // exceptions and other throwables - lazy val ClassCastExceptionClass = getRequiredClass("java.lang.ClassCastException") + lazy val ClassCastExceptionClass = requiredClass[ClassCastException] lazy val IndexOutOfBoundsExceptionClass = getClass(sn.IOOBException) lazy val InvocationTargetExceptionClass = getClass(sn.InvTargetException) - lazy val MatchErrorClass = getRequiredClass("scala.MatchError") - lazy val NonLocalReturnControlClass = getRequiredClass("scala.runtime.NonLocalReturnControl") + lazy val MatchErrorClass = requiredClass[MatchError] + lazy val NonLocalReturnControlClass = requiredClass[scala.runtime.NonLocalReturnControl[_]] lazy val NullPointerExceptionClass = getClass(sn.NPException) lazy val ThrowableClass = getClass(sn.Throwable) - lazy val UninitializedErrorClass = getRequiredClass("scala.UninitializedFieldError") + lazy val UninitializedErrorClass = requiredClass[UninitializedFieldError] // fundamental reference classes - lazy val PartialFunctionClass = getRequiredClass("scala.PartialFunction") + lazy val PartialFunctionClass = requiredClass[PartialFunction[_,_]] lazy val AbstractPartialFunctionClass = getRequiredClass("scala.runtime.AbstractPartialFunction") lazy val SymbolClass = getRequiredClass("scala.Symbol") - lazy val StringClass = getClass(sn.String) + lazy val StringClass = requiredClass[java.lang.String] lazy val StringModule = StringClass.linkedClassOfClass - lazy val ClassClass = getClass(sn.Class) + lazy val ClassClass = getRequiredClass("java.lang.Class") def Class_getMethod = getMember(ClassClass, nme.getMethod_) - lazy val DynamicClass = getRequiredClass("scala.Dynamic") + lazy val DynamicClass = requiredClass[Dynamic] // fundamental modules lazy val SysPackage = getPackageObject("scala.sys") @@ -336,14 +345,14 @@ trait Definitions extends reflect.api.StandardDefinitions { // Those modules and their module classes lazy val UnqualifiedOwners = UnqualifiedModules.toSet ++ UnqualifiedModules.map(_.moduleClass) - lazy val PredefModule: Symbol = getRequiredModule("scala.Predef") + lazy val PredefModule = requiredModule[scala.Predef.type] lazy val PredefModuleClass = PredefModule.moduleClass - def Predef_classOf = getMember(PredefModule, nme.classOf) - def Predef_identity = getMember(PredefModule, nme.identity) - def Predef_conforms = getMember(PredefModule, nme.conforms) + def Predef_classOf = getMember(PredefModule, nme.classOf) + def Predef_identity = getMember(PredefModule, nme.identity) + def Predef_conforms = getMember(PredefModule, nme.conforms) def Predef_wrapRefArray = getMember(PredefModule, nme.wrapRefArray) - def Predef_??? = getMember(PredefModule, nme.???) + def Predef_??? = getMember(PredefModule, nme.???) /** Is `sym` a member of Predef with the given name? * Note: DON't replace this by sym == Predef_conforms/etc, as Predef_conforms is a `def` @@ -356,8 +365,8 @@ trait Definitions extends reflect.api.StandardDefinitions { /** Specialization. */ - lazy val SpecializableModule = getRequiredModule("scala.Specializable") - lazy val GroupOfSpecializable = SpecializableModule.info.member(newTypeName("Group")) + lazy val SpecializableModule = requiredModule[Specializable] + lazy val GroupOfSpecializable = getMember(SpecializableModule, tpnme.Group) lazy val ConsoleModule: Symbol = getRequiredModule("scala.Console") lazy val ScalaRunTimeModule: Symbol = getRequiredModule("scala.runtime.ScalaRunTime") @@ -379,7 +388,7 @@ trait Definitions extends reflect.api.StandardDefinitions { lazy val NotNullClass = getRequiredClass("scala.NotNull") lazy val ScalaNumberClass = getRequiredClass("scala.math.ScalaNumber") lazy val TraitSetterAnnotationClass = getRequiredClass("scala.runtime.TraitSetter") - lazy val DelayedInitClass = getRequiredClass("scala.DelayedInit") + lazy val DelayedInitClass = requiredClass[scala.DelayedInit] def delayedInitMethod = getMember(DelayedInitClass, nme.delayedInit) // a dummy value that communicates that a delayedInit call is compiler-generated // from phase UnCurry to phase Constructors @@ -458,8 +467,8 @@ trait Definitions extends reflect.api.StandardDefinitions { lazy val Array_clone = getMember(ArrayClass, nme.clone_) // reflection / structural types - lazy val SoftReferenceClass = getRequiredClass("java.lang.ref.SoftReference") - lazy val WeakReferenceClass = getRequiredClass("java.lang.ref.WeakReference") + lazy val SoftReferenceClass = requiredClass[java.lang.ref.SoftReference[_]] + lazy val WeakReferenceClass = requiredClass[java.lang.ref.WeakReference[_]] lazy val MethodClass = getClass(sn.MethodAsObject) def methodClass_setAccessible = getMember(MethodClass, nme.setAccessible) lazy val EmptyMethodCacheClass = getRequiredClass("scala.runtime.EmptyMethodCache") @@ -473,22 +482,23 @@ trait Definitions extends reflect.api.StandardDefinitions { def Reflect_mirror = getMember(ReflectPackage, nme.mirror) lazy val ExprClass = getMember(getRequiredClass("scala.reflect.api.Exprs"), tpnme.Expr) - def ExprTree = getMember(ExprClass, nme.tree) - def ExprTpe = getMember(ExprClass, nme.tpe) + def ExprTree = getMemberClass(ExprClass, nme.tree) + def ExprTpe = getMemberClass(ExprClass, nme.tpe) def ExprEval = getMember(ExprClass, nme.eval) def ExprValue = getMember(ExprClass, nme.value) lazy val ExprModule = getMember(getRequiredClass("scala.reflect.api.Exprs"), nme.Expr) - lazy val ClassTagClass = getRequiredClass("scala.reflect.ClassTag") - def ClassTagErasure = getMember(ClassTagClass, nme.erasure) - def ClassTagTpe = getMember(ClassTagClass, nme.tpe) - lazy val ClassTagModule = getRequiredModule("scala.reflect.ClassTag") - lazy val TypeTagsClass = getRequiredClass("scala.reflect.api.TypeTags") - lazy val TypeTagClass = getMember(TypeTagsClass, tpnme.TypeTag) - def TypeTagTpe = getMember(TypeTagClass, nme.tpe) - lazy val TypeTagModule = getMember(TypeTagsClass, nme.TypeTag) - lazy val ConcreteTypeTagClass = getMember(TypeTagsClass, tpnme.ConcreteTypeTag) - lazy val ConcreteTypeTagModule = getMember(TypeTagsClass, nme.ConcreteTypeTag) + lazy val ClassTagModule = requiredModule[scala.reflect.ClassTag[_]] + lazy val ClassTagClass = requiredClass[scala.reflect.ClassTag[_]] + lazy val TypeTagsClass = requiredClass[scala.reflect.api.TypeTags] + lazy val TypeTagClass = getMemberClass(TypeTagsClass, tpnme.TypeTag) + lazy val TypeTagModule = getMemberModule(TypeTagsClass, nme.TypeTag) + lazy val ConcreteTypeTagClass = getMemberClass(TypeTagsClass, tpnme.ConcreteTypeTag) + lazy val ConcreteTypeTagModule = getMemberModule(TypeTagsClass, nme.ConcreteTypeTag) + + def ClassTagErasure = getMemberMethod(ClassTagClass, nme.erasure) + def ClassTagTpe = getMemberMethod(ClassTagClass, nme.tpe) + def TypeTagTpe = getMemberMethod(TypeTagClass, nme.tpe) lazy val MacroContextClass = getRequiredClass("scala.reflect.makro.Context") def MacroContextPrefix = getMember(MacroContextClass, nme.prefix) @@ -497,16 +507,16 @@ trait Definitions extends reflect.api.StandardDefinitions { def MacroContextReify = getMember(MacroContextClass, nme.reify) lazy val MacroImplAnnotation = getRequiredClass("scala.reflect.makro.internal.macroImpl") lazy val MacroInternalPackage = getPackageObject("scala.reflect.makro.internal") - def MacroInternal_materializeClassTag = getMember(MacroInternalPackage, nme.materializeClassTag) - def MacroInternal_materializeTypeTag = getMember(MacroInternalPackage, nme.materializeTypeTag) - def MacroInternal_materializeConcreteTypeTag = getMember(MacroInternalPackage, nme.materializeConcreteTypeTag) + def MacroInternal_materializeClassTag = getMemberMethod(MacroInternalPackage, nme.materializeClassTag) + def MacroInternal_materializeTypeTag = getMemberMethod(MacroInternalPackage, nme.materializeTypeTag) + def MacroInternal_materializeConcreteTypeTag = getMemberMethod(MacroInternalPackage, nme.materializeConcreteTypeTag) lazy val ScalaSignatureAnnotation = getRequiredClass("scala.reflect.ScalaSignature") lazy val ScalaLongSignatureAnnotation = getRequiredClass("scala.reflect.ScalaLongSignature") // Option classes - lazy val OptionClass: Symbol = getRequiredClass("scala.Option") - lazy val SomeClass: Symbol = getRequiredClass("scala.Some") + lazy val OptionClass: Symbol = requiredClass[Option[_]] + lazy val SomeClass: Symbol = requiredClass[Some[_]] lazy val NoneModule: Symbol = getRequiredModule("scala.None") lazy val SomeModule: Symbol = getRequiredModule("scala.Some") @@ -618,13 +628,13 @@ trait Definitions extends reflect.api.StandardDefinitions { } def isTupleType(tp: Type) = isTupleTypeDirect(tp.normalize) - lazy val ProductRootClass: Symbol = getRequiredClass("scala.Product") - def Product_productArity = getMember(ProductRootClass, nme.productArity) - def Product_productElement = getMember(ProductRootClass, nme.productElement) - // def Product_productElementName = getMember(ProductRootClass, nme.productElementName) - def Product_iterator = getMember(ProductRootClass, nme.productIterator) - def Product_productPrefix = getMember(ProductRootClass, nme.productPrefix) - def Product_canEqual = getMember(ProductRootClass, nme.canEqual_) + lazy val ProductRootClass: ClassSymbol = requiredClass[scala.Product] + def Product_productArity = getMemberMethod(ProductRootClass, nme.productArity) + def Product_productElement = getMemberMethod(ProductRootClass, nme.productElement) + def Product_iterator = getMemberMethod(ProductRootClass, nme.productIterator) + def Product_productPrefix = getMemberMethod(ProductRootClass, nme.productPrefix) + def Product_canEqual = getMemberMethod(ProductRootClass, nme.canEqual_) + // def Product_productElementName = getMemberMethod(ProductRootClass, nme.productElementName) def productProj(z:Symbol, j: Int): Symbol = getMember(z, nme.productAccessorName(j)) def productProj(n: Int, j: Int): Symbol = productProj(ProductClass(n), j) @@ -949,7 +959,7 @@ trait Definitions extends reflect.api.StandardDefinitions { // Trying to allow for deprecated locations sym.isAliasType && isMetaAnnotation(sym.info.typeSymbol) ) - lazy val metaAnnotations = Set( + lazy val metaAnnotations = Set[Symbol]( FieldTargetClass, ParamTargetClass, GetterTargetClass, SetterTargetClass, BeanGetterTargetClass, BeanSetterTargetClass @@ -968,31 +978,64 @@ trait Definitions extends reflect.api.StandardDefinitions { def getPackageObject(fullname: String): Symbol = getModule(newTermName(fullname)).info member nme.PACKAGE - def getModule(fullname: Name): Symbol = - getModuleOrClass(fullname.toTermName) + def getModule(fullname: Name): ModuleSymbol = + getModuleOrClass(fullname.toTermName) match { + case x: ModuleSymbol => x + case _ => MissingRequirementError.notFound("object " + fullname) + } - def getClass(fullname: Name): Symbol = { - var result = getModuleOrClass(fullname.toTypeName) - while (result.isAliasType) result = result.info.typeSymbol - result + def getPackage(fullname: Name): PackageSymbol = + getModuleOrClass(fullname.toTermName) match { + case x: PackageSymbol => x + case _ => MissingRequirementError.notFound("package " + fullname) + } + @inline private def wrapMissing(body: => Symbol): Symbol = + try body + catch { case _: MissingRequirementError => NoSymbol } + + private def fatalMissingSymbol(owner: Symbol, name: Name, what: String = "member") = { + throw new FatalError(owner + " does not have a " + what + " " + name) } - def getRequiredModule(fullname: String): Symbol = + @deprecated("Use getClassByName", "2.10.0") + def getClass(fullname: Name): Symbol = getClassByName(fullname) + + def getRequiredPackage(fullname: String): PackageSymbol = + getPackage(newTermNameCached(fullname)) + + def getRequiredModule(fullname: String): ModuleSymbol = getModule(newTermNameCached(fullname)) - def getRequiredClass(fullname: String): Symbol = - getClass(newTypeNameCached(fullname)) + + def requiredClass[T: ClassTag] : ClassSymbol = + getRequiredClass(classTag[T].erasure.getName) + + // TODO: What syntax do we think should work here? Say you have an object + // like scala.Predef. You can't say requiredModule[scala.Predef] since there's + // no accompanying Predef class, and if you say requiredModule[scala.Predef.type] + // the name found via the erasure is scala.Predef$. For now I am + // removing the trailing $, but I think that classTag should have + // a method which returns a usable name, one which doesn't expose this + // detail of the backend. + def requiredModule[T: ClassTag] : ModuleSymbol = + getRequiredModule(classTag[T].erasure.getName stripSuffix "$") + + def getRequiredClass(fullname: String): ClassSymbol = + getClassByName(newTypeNameCached(fullname)) match { + case x: ClassSymbol => x + case _ => MissingRequirementError.notFound("class " + fullname) + } def getClassIfDefined(fullname: String): Symbol = getClassIfDefined(newTypeName(fullname)) + def getClassIfDefined(fullname: Name): Symbol = - try getClass(fullname.toTypeName) - catch { case _: MissingRequirementError => NoSymbol } + wrapMissing(getClass(fullname.toTypeName)) def getModuleIfDefined(fullname: String): Symbol = getModuleIfDefined(newTermName(fullname)) + def getModuleIfDefined(fullname: Name): Symbol = - try getModule(fullname.toTermName) - catch { case _: MissingRequirementError => NoSymbol } + wrapMissing(getModule(fullname.toTermName)) def getLanguageFeature(name: String, owner: Symbol = languageFeatureModule) = getMember(owner, newTypeName(name)) @@ -1020,11 +1063,29 @@ trait Definitions extends reflect.api.StandardDefinitions { val pkg = owner.owner val flatname = nme.flattenedName(owner.name, name) getMember(pkg, flatname) - } else { - throw new FatalError(owner + " does not have a member " + name) + } + else fatalMissingSymbol(owner, name) + } + } + def getMemberModule(owner: Symbol, name: Name): ModuleSymbol = { + getMember(owner, name.toTermName) match { + case x: ModuleSymbol => x + case _ => fatalMissingSymbol(owner, name, "member object") + } + } + def getMemberClass(owner: Symbol, name: Name): ClassSymbol = { + getMember(owner, name.toTypeName) match { + case x: ClassSymbol => x + case _ => fatalMissingSymbol(owner, name, "member class") } } + def getMemberMethod(owner: Symbol, name: Name): MethodSymbol = { + getMember(owner, name.toTermName) match { + case x: MethodSymbol => x + case _ => fatalMissingSymbol(owner, name, "method") + } } + def getMemberIfDefined(owner: Symbol, name: Name): Symbol = owner.info.nonPrivateMember(name) @@ -1033,9 +1094,7 @@ trait Definitions extends reflect.api.StandardDefinitions { * know the method in question is uniquely declared in the given owner. */ def getDecl(owner: Symbol, name: Name): Symbol = { - getDeclIfDefined(owner, name) orElse { - throw new FatalError(owner + " does not have a decl " + name) - } + getDeclIfDefined(owner, name) orElse fatalMissingSymbol(owner, name, "decl") } def getDeclIfDefined(owner: Symbol, name: Name): Symbol = owner.info.nonPrivateDecl(name) @@ -1065,10 +1124,16 @@ trait Definitions extends reflect.api.StandardDefinitions { */ private def getModuleOrClass(path: Name): Symbol = getModuleOrClass(path, path.length) - private def newAlias(owner: Symbol, name: TypeName, alias: Type): Symbol = + private def getClassByName(fullname: Name): Symbol = { + var result = getModuleOrClass(fullname.toTypeName) + while (result.isAliasType) result = result.info.typeSymbol + result + } + + private def newAlias(owner: Symbol, name: TypeName, alias: Type): AliasTypeSymbol = owner.newAliasType(name) setInfoAndEnter alias - private def specialPolyClass(name: TypeName, flags: Long)(parentFn: Symbol => Type): Symbol = { + private def specialPolyClass(name: TypeName, flags: Long)(parentFn: Symbol => Type): ClassSymbol = { val clazz = enterNewClass(ScalaPackageClass, name, Nil) val tparam = clazz.newSyntheticTypeParam("T0", flags) val parents = List(AnyRefClass.tpe, parentFn(tparam)) @@ -1076,7 +1141,7 @@ trait Definitions extends reflect.api.StandardDefinitions { clazz setInfo GenPolyType(List(tparam), ClassInfoType(parents, newScope, clazz)) } - def newPolyMethod(typeParamCount: Int, owner: Symbol, name: TermName, flags: Long)(createFn: PolyMethodCreator): Symbol = { + def newPolyMethod(typeParamCount: Int, owner: Symbol, name: TermName, flags: Long)(createFn: PolyMethodCreator): MethodSymbol = { val msym = owner.newMethod(name.encode, NoPosition, flags) val tparams = msym.newSyntheticTypeParams(typeParamCount) val mtpe = createFn(tparams) match { @@ -1089,16 +1154,16 @@ trait Definitions extends reflect.api.StandardDefinitions { /** T1 means one type parameter. */ - def newT1NullaryMethod(owner: Symbol, name: TermName, flags: Long)(createFn: Symbol => Type): Symbol = { + def newT1NullaryMethod(owner: Symbol, name: TermName, flags: Long)(createFn: Symbol => Type): MethodSymbol = { newPolyMethod(1, owner, name, flags)(tparams => (None, createFn(tparams.head))) } - def newT1NoParamsMethod(owner: Symbol, name: TermName, flags: Long)(createFn: Symbol => Type): Symbol = { + def newT1NoParamsMethod(owner: Symbol, name: TermName, flags: Long)(createFn: Symbol => Type): MethodSymbol = { newPolyMethod(1, owner, name, flags)(tparams => (Some(Nil), createFn(tparams.head))) } - lazy val boxedClassValues = boxedClass.values.toSet - lazy val isUnbox = unboxMethod.values.toSet - lazy val isBox = boxMethod.values.toSet + lazy val boxedClassValues = boxedClass.values.toSet[Symbol] + lazy val isUnbox = unboxMethod.values.toSet[Symbol] + lazy val isBox = boxMethod.values.toSet[Symbol] /** Is symbol a phantom class for which no runtime representation exists? */ lazy val isPhantomClass = Set[Symbol](AnyClass, AnyValClass, NullClass, NothingClass) @@ -1106,8 +1171,7 @@ trait Definitions extends reflect.api.StandardDefinitions { /** Is the symbol that of a parent which is added during parsing? */ lazy val isPossibleSyntheticParent = ProductClass.toSet[Symbol] + ProductRootClass + SerializableClass - lazy val scalaValueClassesSet = ScalaValueClasses.toSet - private lazy val boxedValueClassesSet = boxedClass.values.toSet + BoxedUnitClass + private lazy val boxedValueClassesSet = boxedClass.values.toSet[Symbol] + BoxedUnitClass /** Is symbol a value class? */ def isPrimitiveValueClass(sym: Symbol) = ScalaValueClasses contains sym diff --git a/src/compiler/scala/reflect/internal/NameManglers.scala b/src/compiler/scala/reflect/internal/NameManglers.scala deleted file mode 100644 index ac22017569..0000000000 --- a/src/compiler/scala/reflect/internal/NameManglers.scala +++ /dev/null @@ -1,216 +0,0 @@ -/* NSC -- new Scala compiler - * Copyright 2005-2011 LAMP/EPFL - * @author Martin Odersky - */ - -package scala.reflect -package internal - -import java.security.MessageDigest -import scala.io.Codec -import Chars.isOperatorPart - -/** A trait to encapsulate name mangling. It's intended for the - * values and methods involved in assembling names out of other names, - * and not for simple synthetically named locals. - */ -trait NameManglers { - self: SymbolTable => - - trait NameManglingCommon { - self: CommonNames => - - val MODULE_SUFFIX_STRING = NameTransformer.MODULE_SUFFIX_STRING - val NAME_JOIN_STRING = NameTransformer.NAME_JOIN_STRING - - val MODULE_SUFFIX_NAME: TermName = newTermName(MODULE_SUFFIX_STRING) - val NAME_JOIN_NAME: TermName = newTermName(NAME_JOIN_STRING) - - def flattenedName(segments: Name*): NameType = compactedString(segments mkString NAME_JOIN_STRING) - - /** - * COMPACTIFY - * - * The hashed name has the form (prefix + marker + md5 + marker + suffix), where - * - prefix/suffix.length = MaxNameLength / 4 - * - md5.length = 32 - * - * We obtain the formula: - * - * FileNameLength = 2*(MaxNameLength / 4) + 2.marker.length + 32 + 6 - * - * (+6 for ".class"). MaxNameLength can therefore be computed as follows: - */ - private final val marker = "$$$$" - private final val MaxNameLength = math.min( - settings.maxClassfileName.value - 6, - 2 * (settings.maxClassfileName.value - 6 - 2*marker.length - 32) - ) - private lazy val md5 = MessageDigest.getInstance("MD5") - private def toMD5(s: String, edge: Int) = { - val prefix = s take edge - val suffix = s takeRight edge - - val cs = s.toArray - val bytes = Codec toUTF8 cs - md5 update bytes - val md5chars = md5.digest() map (b => (b & 0xFF).toHexString) mkString - - prefix + marker + md5chars + marker + suffix - } - private def compactedString(s: String) = - if (s.length <= MaxNameLength) s - else toMD5(s, MaxNameLength / 4) - } - - trait TypeNameMangling extends NameManglingCommon { - self: tpnme.type => - - } - - trait TermNameMangling extends NameManglingCommon { - self: nme.type => - - val IMPL_CLASS_SUFFIX = "$class" - val LOCALDUMMY_PREFIX = "<local " // owner of local blocks - val PROTECTED_PREFIX = "protected$" - val PROTECTED_SET_PREFIX = PROTECTED_PREFIX + "set" - val SINGLETON_SUFFIX = ".type" - val SUPER_PREFIX_STRING = "super$" - val TRAIT_SETTER_SEPARATOR_STRING = "$_setter_$" - val SETTER_SUFFIX: TermName = encode("_=") - - @deprecated("Use SPECIALIZED_SUFFIX", "2.10.0") - def SPECIALIZED_SUFFIX_STRING = SPECIALIZED_SUFFIX.toString - @deprecated("Use SPECIALIZED_SUFFIX", "2.10.0") - def SPECIALIZED_SUFFIX_NAME: TermName = SPECIALIZED_SUFFIX.toTermName - - def isConstructorName(name: Name) = name == CONSTRUCTOR || name == MIXIN_CONSTRUCTOR - def isExceptionResultName(name: Name) = name startsWith EXCEPTION_RESULT_PREFIX - def isImplClassName(name: Name) = name endsWith IMPL_CLASS_SUFFIX - def isLocalDummyName(name: Name) = name startsWith LOCALDUMMY_PREFIX - def isLocalName(name: Name) = name endsWith LOCAL_SUFFIX_STRING - def isLoopHeaderLabel(name: Name) = (name startsWith WHILE_PREFIX) || (name startsWith DO_WHILE_PREFIX) - def isProtectedAccessorName(name: Name) = name startsWith PROTECTED_PREFIX - def isSuperAccessorName(name: Name) = name startsWith SUPER_PREFIX_STRING - def isReplWrapperName(name: Name) = name containsName INTERPRETER_IMPORT_WRAPPER - def isSetterName(name: Name) = name endsWith SETTER_SUFFIX - def isTraitSetterName(name: Name) = isSetterName(name) && (name containsName TRAIT_SETTER_SEPARATOR_STRING) - def isSingletonName(name: Name) = name endsWith SINGLETON_SUFFIX - def isModuleName(name: Name) = name endsWith MODULE_SUFFIX_NAME - - def isOpAssignmentName(name: Name) = name match { - case raw.NE | raw.LE | raw.GE | EMPTY => false - case _ => - name.endChar == '=' && name.startChar != '=' && isOperatorPart(name.startChar) - } - - /** The expanded setter name of `name` relative to this class `base` - */ - def expandedSetterName(name: TermName, base: Symbol): TermName = - expandedName(name, base, separator = TRAIT_SETTER_SEPARATOR_STRING) - - /** If `name` is an expandedName name, the original name. - * Otherwise `name` itself. - */ - def originalName(name: Name): Name = { - var i = name.length - while (i >= 2 && !(name(i - 1) == '$' && name(i - 2) == '$')) i -= 1 - if (i >= 2) { - while (i >= 3 && name(i - 3) == '$') i -= 1 - name.subName(i, name.length) - } else name - } - - def unspecializedName(name: Name): Name = ( - if (name endsWith SPECIALIZED_SUFFIX) - name.subName(0, name.lastIndexOf('m') - 1) - else name - ) - - /** Return the original name and the types on which this name - * is specialized. For example, - * {{{ - * splitSpecializedName("foo$mIcD$sp") == ('foo', "I", "D") - * }}} - * `foo$mIcD$sp` is the name of a method specialized on two type - * parameters, the first one belonging to the method itself, on Int, - * and another one belonging to the enclosing class, on Double. - */ - def splitSpecializedName(name: Name): (Name, String, String) = - if (name endsWith SPECIALIZED_SUFFIX) { - val name1 = name dropRight SPECIALIZED_SUFFIX.length - val idxC = name1 lastIndexOf 'c' - val idxM = name1 lastIndexOf 'm' - - (name1.subName(0, idxM - 1), - name1.subName(idxC + 1, name1.length).toString, - name1.subName(idxM + 1, idxC).toString) - } else - (name, "", "") - - def getterName(name: TermName): TermName = if (isLocalName(name)) localToGetter(name) else name - def getterToLocal(name: TermName): TermName = name append LOCAL_SUFFIX_STRING - def getterToSetter(name: TermName): TermName = name append SETTER_SUFFIX - def localToGetter(name: TermName): TermName = name dropRight LOCAL_SUFFIX_STRING.length - - def dropLocalSuffix(name: Name): Name = if (name endsWith ' ') name dropRight 1 else name - - def setterToGetter(name: TermName): TermName = { - val p = name.pos(TRAIT_SETTER_SEPARATOR_STRING) - if (p < name.length) - setterToGetter(name drop (p + TRAIT_SETTER_SEPARATOR_STRING.length)) - else - name.subName(0, name.length - SETTER_SUFFIX.length) - } - - def defaultGetterName(name: Name, pos: Int): TermName = { - val prefix = if (isConstructorName(name)) "init" else name - newTermName(prefix + DEFAULT_GETTER_STRING + pos) - } - def defaultGetterToMethod(name: Name): TermName = { - val p = name.pos(DEFAULT_GETTER_STRING) - if (p < name.length) name.toTermName.subName(0, p) - else name.toTermName - } - - // def anonNumberSuffix(name: Name): Name = { - // ("" + name) lastIndexOf '$' match { - // case -1 => nme.EMPTY - // case idx => - // val s = name drop idx - // if (s.toString forall (_.isDigit)) s - // else nme.EMPTY - // } - // } - - // If the name ends with $nn where nn are - // all digits, strip the $ and the digits. - // Otherwise return the argument. - def stripAnonNumberSuffix(name: Name): Name = { - var pos = name.length - while (pos > 0 && name(pos - 1).isDigit) - pos -= 1 - - if (pos <= 0 || pos == name.length || name(pos - 1) != '$') name - else name.subName(0, pos - 1) - } - - def stripModuleSuffix(name: Name): Name = ( - if (isModuleName(name)) name dropRight MODULE_SUFFIX_STRING.length else name - ) - - def dropSingletonName(name: Name): TypeName = name dropRight SINGLETON_SUFFIX.length toTypeName - def singletonName(name: Name): TypeName = name append SINGLETON_SUFFIX toTypeName - def implClassName(name: Name): TypeName = name append IMPL_CLASS_SUFFIX toTypeName - def interfaceName(implname: Name): TypeName = implname dropRight IMPL_CLASS_SUFFIX.length toTypeName - def localDummyName(clazz: Symbol): TermName = newTermName(LOCALDUMMY_PREFIX + clazz.name + ">") - def superName(name: Name): TermName = newTermName(SUPER_PREFIX_STRING + name) - - /** The name of an accessor for protected symbols. */ - def protName(name: Name): TermName = newTermName(PROTECTED_PREFIX + name) - - /** The name of a setter for protected symbols. Used for inherited Java fields. */ - def protSetterName(name: Name): TermName = newTermName(PROTECTED_SET_PREFIX + name) - } -} diff --git a/src/compiler/scala/reflect/internal/Names.scala b/src/compiler/scala/reflect/internal/Names.scala index d2b55d9d39..dc89b14869 100644 --- a/src/compiler/scala/reflect/internal/Names.scala +++ b/src/compiler/scala/reflect/internal/Names.scala @@ -356,8 +356,10 @@ trait Names extends api.Names { final def endsWith(char: Char): Boolean = len > 0 && endChar == char final def endsWith(name: String): Boolean = endsWith(newTermName(name)) - def dropRight(n: Int) = subName(0, len - n) - def drop(n: Int) = subName(n, len) + def dropRight(n: Int): ThisNameType = subName(0, len - n) + def drop(n: Int): ThisNameType = subName(n, len) + def stripSuffix(suffix: Name): ThisNameType = + if (this endsWith suffix) dropRight(suffix.length) else thisName def indexOf(ch: Char) = { val idx = pos(ch) diff --git a/src/compiler/scala/reflect/internal/Scopes.scala b/src/compiler/scala/reflect/internal/Scopes.scala index ef48d6102f..36e8ebb212 100644 --- a/src/compiler/scala/reflect/internal/Scopes.scala +++ b/src/compiler/scala/reflect/internal/Scopes.scala @@ -113,7 +113,7 @@ trait Scopes extends api.Scopes { self: SymbolTable => * * @param sym ... */ - def enter(sym: Symbol): Symbol = { enter(newScopeEntry(sym, this)); sym } + def enter[T <: Symbol](sym: T): T = { enter(newScopeEntry(sym, this)); sym } /** enter a symbol, asserting that no symbol with same name exists in scope * diff --git a/src/compiler/scala/reflect/internal/StdNames.scala b/src/compiler/scala/reflect/internal/StdNames.scala index c5fe1ecb45..54be83c98f 100644 --- a/src/compiler/scala/reflect/internal/StdNames.scala +++ b/src/compiler/scala/reflect/internal/StdNames.scala @@ -6,27 +6,141 @@ package scala.reflect package internal -import scala.collection.immutable -import NameTransformer.MODULE_SUFFIX_STRING +import java.security.MessageDigest +import Chars.isOperatorPart import annotation.switch import language.implicitConversions +import scala.collection.immutable +import scala.io.Codec -trait StdNames extends NameManglers { self: SymbolTable => +trait StdNames { + self: SymbolTable => def encode(str: String): TermName = newTermNameCached(NameTransformer.encode(str)) implicit def lowerTermNames(n: TermName): String = n.toString - // implicit def stringToTermName(s: String): TermName = newTermName(s) - - /** This should be the first trait in the linearization. */ - trait Keywords { + /** Tensions: would like the keywords to be the very first names entered into the names + * storage so their ids count from 0, which simplifies the parser. Switched to abstract + * classes to avoid all the indirection which is generated with implementation-containing + * traits. Since all these classes use eager vals, that means the constructor with the + * keywords must run first. If it's the top in the superclass chain, then CommonNames + * must inherit from it, which means TypeNames would inherit keywords as well. + * + * Solution: Keywords extends CommonNames and uses early defs to beat the + * CommonNames constructor out of the starting gate. This is its builder. + */ + private class KeywordSetBuilder { private var kws: Set[TermName] = Set() - private def kw(s: String): TermName = { + def apply(s: String): TermName = { val result = newTermNameCached(s) kws = kws + result result } + def result: Set[TermName] = { + val result = kws + kws = null + result + } + } + + private final object compactify extends (String => String) { + val md5 = MessageDigest.getInstance("MD5") + + /** + * COMPACTIFY + * + * The hashed name has the form (prefix + marker + md5 + marker + suffix), where + * - prefix/suffix.length = MaxNameLength / 4 + * - md5.length = 32 + * + * We obtain the formula: + * + * FileNameLength = 2*(MaxNameLength / 4) + 2.marker.length + 32 + 6 + * + * (+6 for ".class"). MaxNameLength can therefore be computed as follows: + */ + val marker = "$$$$" + val MaxNameLength = math.min( + settings.maxClassfileName.value - 6, + 2 * (settings.maxClassfileName.value - 6 - 2*marker.length - 32) + ) + def toMD5(s: String, edge: Int): String = { + val prefix = s take edge + val suffix = s takeRight edge + + val cs = s.toArray + val bytes = Codec toUTF8 cs + md5 update bytes + val md5chars = md5.digest() map (b => (b & 0xFF).toHexString) mkString + + prefix + marker + md5chars + marker + suffix + } + def apply(s: String): String = ( + if (s.length <= MaxNameLength) s + else toMD5(s, MaxNameLength / 4) + ) + } + + abstract class CommonNames { + type NameType <: Name + protected implicit def createNameType(name: String): NameType + + def flattenedName(segments: Name*): NameType = + compactify(segments mkString NAME_JOIN_STRING) + + val MODULE_SUFFIX_STRING: String = NameTransformer.MODULE_SUFFIX_STRING + val NAME_JOIN_STRING: String = NameTransformer.NAME_JOIN_STRING + val SINGLETON_SUFFIX: String = ".type" + + val ANON_CLASS_NAME: NameType = "$anon" + val ANON_FUN_NAME: NameType = "$anonfun" + val EMPTY: NameType = "" + val EMPTY_PACKAGE_NAME: NameType = "<empty>" + val IMPL_CLASS_SUFFIX = "$class" + val IMPORT: NameType = "<import>" + val MODULE_SUFFIX_NAME: NameType = MODULE_SUFFIX_STRING + val MODULE_VAR_SUFFIX: NameType = "$module" + val NAME_JOIN_NAME: NameType = NAME_JOIN_STRING + val PACKAGE: NameType = "package" + val ROOT: NameType = "<root>" + val SPECIALIZED_SUFFIX: NameType = "$sp" + + // value types (and AnyRef) are all used as terms as well + // as (at least) arguments to the @specialize annotation. + final val Boolean: NameType = "Boolean" + final val Byte: NameType = "Byte" + final val Char: NameType = "Char" + final val Double: NameType = "Double" + final val Float: NameType = "Float" + final val Int: NameType = "Int" + final val Long: NameType = "Long" + final val Short: NameType = "Short" + final val Unit: NameType = "Unit" + + final val ScalaValueNames: scala.List[NameType] = + scala.List(Byte, Char, Short, Int, Long, Float, Double, Boolean, Unit) + + // some types whose companions we utilize + final val AnyRef: NameType = "AnyRef" + final val Array: NameType = "Array" + final val List: NameType = "List" + final val Seq: NameType = "Seq" + final val Symbol: NameType = "Symbol" + final val ClassTag: NameType = "ClassTag" + final val TypeTag : NameType = "TypeTag" + final val ConcreteTypeTag: NameType = "ConcreteTypeTag" + + // fictions we use as both types and terms + final val ERROR: NameType = "<error>" + final val NO_NAME: NameType = "<none>" // formerly NOSYMBOL + final val WILDCARD: NameType = "_" + } + + /** This should be the first trait in the linearization. */ + // abstract class Keywords extends CommonNames { + abstract class Keywords extends { + private val kw = new KeywordSetBuilder final val ABSTRACTkw: TermName = kw("abstract") final val CASEkw: TermName = kw("case") @@ -81,66 +195,20 @@ trait StdNames extends NameManglers { self: SymbolTable => final val HASHkw: TermName = kw("#") final val ATkw: TermName = kw("@") - final val keywords = { - val result = kws.toSet - kws = null - result - } - + final val keywords = kw.result + } with CommonNames { final val javaKeywords = new JavaKeywords() } - trait CommonNames /*extends LibraryCommonNames*/ { - - type NameType <: Name - protected implicit def createNameType(name: String): NameType - - val EMPTY: NameType = "" - val ANON_FUN_NAME: NameType = "$anonfun" - val ANON_CLASS_NAME: NameType = "$anon" - val EMPTY_PACKAGE_NAME: NameType = "<empty>" - val IMPORT: NameType = "<import>" - val MODULE_VAR_SUFFIX: NameType = "$module" - val ROOT: NameType = "<root>" - val PACKAGE: NameType = "package" - val SPECIALIZED_SUFFIX: NameType = "$sp" - - // value types (and AnyRef) are all used as terms as well - // as (at least) arguments to the @specialize annotation. - final val Boolean: NameType = "Boolean" - final val Byte: NameType = "Byte" - final val Char: NameType = "Char" - final val Double: NameType = "Double" - final val Float: NameType = "Float" - final val Int: NameType = "Int" - final val Long: NameType = "Long" - final val Short: NameType = "Short" - final val Unit: NameType = "Unit" - - final val ScalaValueNames: scala.List[NameType] = - scala.List(Byte, Char, Short, Int, Long, Float, Double, Boolean, Unit) - - // some types whose companions we utilize - final val AnyRef: NameType = "AnyRef" - final val Array: NameType = "Array" - final val List: NameType = "List" - final val Seq: NameType = "Seq" - final val Symbol: NameType = "Symbol" - final val ClassTag: NameType = "ClassTag" - final val TypeTag : NameType = "TypeTag" - final val ConcreteTypeTag: NameType = "ConcreteTypeTag" - - // fictions we use as both types and terms - final val ERROR: NameType = "<error>" - final val NO_NAME: NameType = "<none>" // formerly NOSYMBOL - final val WILDCARD: NameType = "_" - } + abstract class TypeNames extends Keywords { + type NameType = TypeName + protected implicit def createNameType(name: String): TypeName = newTypeNameCached(name) - trait TypeNames extends CommonNames { final val BYNAME_PARAM_CLASS_NAME: NameType = "<byname>" final val EQUALS_PATTERN_NAME: NameType = "<equals>" final val JAVA_REPEATED_PARAM_CLASS_NAME: NameType = "<repeated...>" final val LOCAL_CHILD: NameType = "<local child>" + final val REFINE_CLASS_NAME: NameType = "<refinement>" final val REPEATED_PARAM_CLASS_NAME: NameType = "<repeated>" final val WILDCARD_STAR: NameType = "_*" @@ -161,7 +229,7 @@ trait StdNames extends NameManglers { self: SymbolTable => final val Annotation: NameType = "Annotation" final val ClassfileAnnotation: NameType = "ClassfileAnnotation" final val Enum: NameType = "Enum" - + final val Group: NameType = "Group" final val Tree: NameType = "Tree" final val TypeTree: NameType = "TypeTree" @@ -189,34 +257,195 @@ trait StdNames extends NameManglers { self: SymbolTable => final val SignatureATTR: NameType = "Signature" final val SourceFileATTR: NameType = "SourceFile" final val SyntheticATTR: NameType = "Synthetic" + + def dropSingletonName(name: Name): TypeName = name dropRight SINGLETON_SUFFIX.length toTypeName + def singletonName(name: Name): TypeName = name append SINGLETON_SUFFIX toTypeName + def implClassName(name: Name): TypeName = name append IMPL_CLASS_SUFFIX toTypeName + def interfaceName(implname: Name): TypeName = implname dropRight IMPL_CLASS_SUFFIX.length toTypeName } - trait TermNames extends Keywords with CommonNames { + abstract class TermNames extends Keywords { + type NameType = TermName + protected implicit def createNameType(name: String): TermName = newTermNameCached(name) + + /** Base strings from which synthetic names are derived. */ + val BITMAP_PREFIX = "bitmap$" + val CHECK_IF_REFUTABLE_STRING = "check$ifrefutable$" + val DEFAULT_GETTER_STRING = "$default$" + val DO_WHILE_PREFIX = "doWhile$" + val EVIDENCE_PARAM_PREFIX = "evidence$" + val EXCEPTION_RESULT_PREFIX = "exceptionResult" + val EXPAND_SEPARATOR_STRING = "$$" + val INTERPRETER_IMPORT_WRAPPER = "$iw" + val INTERPRETER_LINE_PREFIX = "line" + val INTERPRETER_VAR_PREFIX = "res" + val INTERPRETER_WRAPPER_SUFFIX = "$object" + val LOCALDUMMY_PREFIX = "<local " // owner of local blocks + val PROTECTED_PREFIX = "protected$" + val PROTECTED_SET_PREFIX = PROTECTED_PREFIX + "set" + val SUPER_PREFIX_STRING = "super$" + val TRAIT_SETTER_SEPARATOR_STRING = "$_setter_$" + val WHILE_PREFIX = "while$" + // Compiler internal names - val EXPAND_SEPARATOR_STRING = "$$" - - val ANYNAME: NameType = "<anyname>" - val CONSTRUCTOR: NameType = "<init>" - val FAKE_LOCAL_THIS: NameType = "this$" - val INITIALIZER: NameType = CONSTRUCTOR // Is this buying us something? - val LAZY_LOCAL: NameType = "$lzy" - val LOCAL_SUFFIX_STRING = " " - val MIRROR_PREFIX: NameType = "$mr." - val MIRROR_SHORT: NameType = "$mr" - val MIRROR_FREE_PREFIX: NameType = "free$" - val MIRROR_FREE_THIS_SUFFIX: NameType = "$this" - val MIRROR_FREE_VALUE_SUFFIX: NameType = "$value" - val MIRROR_SYMDEF_PREFIX: NameType = "symdef$" - val MIXIN_CONSTRUCTOR: NameType = "$init$" - val MODULE_INSTANCE_FIELD: NameType = NameTransformer.MODULE_INSTANCE_NAME // "MODULE$" - val OUTER: NameType = "$outer" - val OUTER_LOCAL: NameType = OUTER + LOCAL_SUFFIX_STRING // "$outer ", note the space - val OUTER_SYNTH: NameType = "<outer>" // emitted by virtual pattern matcher, replaced by outer accessor in explicitouter - val SELECTOR_DUMMY: NameType = "<unapply-selector>" - val SELF: NameType = "$this" - val SPECIALIZED_INSTANCE: NameType = "specInstance$" - val STAR: NameType = "*" - val THIS: NameType = "_$this" + val ANYNAME: NameType = "<anyname>" + val CONSTRUCTOR: NameType = "<init>" + val FAKE_LOCAL_THIS: NameType = "this$" + val INITIALIZER: NameType = CONSTRUCTOR // Is this buying us something? + val LAZY_LOCAL: NameType = "$lzy" + val LOCAL_SUFFIX_STRING = " " + val MIRROR_FREE_PREFIX: NameType = "free$" + val MIRROR_FREE_THIS_SUFFIX: NameType = "$this" + val MIRROR_FREE_VALUE_SUFFIX: NameType = "$value" + val MIRROR_PREFIX: NameType = "$mr." + val MIRROR_SHORT: NameType = "$mr" + val MIRROR_SYMDEF_PREFIX: NameType = "symdef$" + val MIXIN_CONSTRUCTOR: NameType = "$init$" + val MODULE_INSTANCE_FIELD: NameType = NameTransformer.MODULE_INSTANCE_NAME // "MODULE$" + val OUTER: NameType = "$outer" + val OUTER_LOCAL: NameType = OUTER + LOCAL_SUFFIX_STRING // "$outer ", note the space + val OUTER_SYNTH: NameType = "<outer>" // emitted by virtual pattern matcher, replaced by outer accessor in explicitouter + val SELECTOR_DUMMY: NameType = "<unapply-selector>" + val SELF: NameType = "$this" + val SETTER_SUFFIX: NameType = encode("_=") + val SPECIALIZED_INSTANCE: NameType = "specInstance$" + val STAR: NameType = "*" + val THIS: NameType = "_$this" + + @deprecated("Use SPECIALIZED_SUFFIX", "2.10.0") + def SPECIALIZED_SUFFIX_STRING = SPECIALIZED_SUFFIX.toString + @deprecated("Use SPECIALIZED_SUFFIX", "2.10.0") + def SPECIALIZED_SUFFIX_NAME: TermName = SPECIALIZED_SUFFIX.toTermName + + def isConstructorName(name: Name) = name == CONSTRUCTOR || name == MIXIN_CONSTRUCTOR + def isExceptionResultName(name: Name) = name startsWith EXCEPTION_RESULT_PREFIX + def isImplClassName(name: Name) = name endsWith IMPL_CLASS_SUFFIX + def isLocalDummyName(name: Name) = name startsWith LOCALDUMMY_PREFIX + def isLocalName(name: Name) = name endsWith LOCAL_SUFFIX_STRING + def isLoopHeaderLabel(name: Name) = (name startsWith WHILE_PREFIX) || (name startsWith DO_WHILE_PREFIX) + def isProtectedAccessorName(name: Name) = name startsWith PROTECTED_PREFIX + def isSuperAccessorName(name: Name) = name startsWith SUPER_PREFIX_STRING + def isReplWrapperName(name: Name) = name containsName INTERPRETER_IMPORT_WRAPPER + def isSetterName(name: Name) = name endsWith SETTER_SUFFIX + def isTraitSetterName(name: Name) = isSetterName(name) && (name containsName TRAIT_SETTER_SEPARATOR_STRING) + def isSingletonName(name: Name) = name endsWith SINGLETON_SUFFIX + def isModuleName(name: Name) = name endsWith MODULE_SUFFIX_NAME + + def isOpAssignmentName(name: Name) = name match { + case raw.NE | raw.LE | raw.GE | EMPTY => false + case _ => + name.endChar == '=' && name.startChar != '=' && isOperatorPart(name.startChar) + } + + /** The expanded name of `name` relative to this class `base` with given `separator` + */ + def expandedName(name: TermName, base: Symbol, separator: String = EXPAND_SEPARATOR_STRING): TermName = + newTermNameCached(base.fullName('$') + separator + name) + + /** The expanded setter name of `name` relative to this class `base` + */ + def expandedSetterName(name: TermName, base: Symbol): TermName = + expandedName(name, base, separator = TRAIT_SETTER_SEPARATOR_STRING) + + /** If `name` is an expandedName name, the original name. + * Otherwise `name` itself. + */ + def originalName(name: Name): Name = { + var i = name.length + while (i >= 2 && !(name(i - 1) == '$' && name(i - 2) == '$')) i -= 1 + if (i >= 2) { + while (i >= 3 && name(i - 3) == '$') i -= 1 + name.subName(i, name.length) + } else name + } + + def unspecializedName(name: Name): Name = ( + if (name endsWith SPECIALIZED_SUFFIX) + name.subName(0, name.lastIndexOf('m') - 1) + else name + ) + + /* + def anonNumberSuffix(name: Name): Name = { + ("" + name) lastIndexOf '$' match { + case -1 => nme.EMPTY + case idx => + val s = name drop idx + if (s.toString forall (_.isDigit)) s + else nme.EMPTY + } + } + */ + + /** Return the original name and the types on which this name + * is specialized. For example, + * {{{ + * splitSpecializedName("foo$mIcD$sp") == ('foo', "I", "D") + * }}} + * `foo$mIcD$sp` is the name of a method specialized on two type + * parameters, the first one belonging to the method itself, on Int, + * and another one belonging to the enclosing class, on Double. + */ + def splitSpecializedName(name: Name): (Name, String, String) = + if (name endsWith SPECIALIZED_SUFFIX) { + val name1 = name dropRight SPECIALIZED_SUFFIX.length + val idxC = name1 lastIndexOf 'c' + val idxM = name1 lastIndexOf 'm' + + (name1.subName(0, idxM - 1), + name1.subName(idxC + 1, name1.length).toString, + name1.subName(idxM + 1, idxC).toString) + } else + (name, "", "") + + def getterName(name: TermName): TermName = if (isLocalName(name)) localToGetter(name) else name + def getterToLocal(name: TermName): TermName = name append LOCAL_SUFFIX_STRING + def getterToSetter(name: TermName): TermName = name append SETTER_SUFFIX + def localToGetter(name: TermName): TermName = name dropRight LOCAL_SUFFIX_STRING.length + + def dropLocalSuffix(name: Name): Name = if (name endsWith ' ') name dropRight 1 else name + + def setterToGetter(name: TermName): TermName = { + val p = name.pos(TRAIT_SETTER_SEPARATOR_STRING) + if (p < name.length) + setterToGetter(name drop (p + TRAIT_SETTER_SEPARATOR_STRING.length)) + else + name.subName(0, name.length - SETTER_SUFFIX.length) + } + + def defaultGetterName(name: Name, pos: Int): TermName = { + val prefix = if (isConstructorName(name)) "init" else name + newTermName(prefix + DEFAULT_GETTER_STRING + pos) + } + def defaultGetterToMethod(name: Name): TermName = { + val p = name.pos(DEFAULT_GETTER_STRING) + if (p < name.length) name.toTermName.subName(0, p) + else name.toTermName + } + + // If the name ends with $nn where nn are + // all digits, strip the $ and the digits. + // Otherwise return the argument. + def stripAnonNumberSuffix(name: Name): Name = { + var pos = name.length + while (pos > 0 && name(pos - 1).isDigit) + pos -= 1 + + if (pos <= 0 || pos == name.length || name(pos - 1) != '$') name + else name.subName(0, pos - 1) + } + + def stripModuleSuffix(name: Name): Name = ( + if (isModuleName(name)) name dropRight MODULE_SUFFIX_STRING.length else name + ) + def localDummyName(clazz: Symbol): TermName = newTermName(LOCALDUMMY_PREFIX + clazz.name + ">") + def superName(name: Name): TermName = newTermName(SUPER_PREFIX_STRING + name) + + /** The name of an accessor for protected symbols. */ + def protName(name: Name): TermName = newTermName(PROTECTED_PREFIX + name) + + /** The name of a setter for protected symbols. Used for inherited Java fields. */ + def protSetterName(name: Name): TermName = newTermName(PROTECTED_SET_PREFIX + name) final val Nil: NameType = "Nil" final val Predef: NameType = "Predef" @@ -508,19 +737,11 @@ trait StdNames extends NameManglers { self: SymbolTable => val toInteger: NameType = "toInteger" } - object tpnme extends AbsTypeNames with TypeNames /*with LibraryTypeNames*/ with TypeNameMangling { - type NameType = TypeName - protected implicit def createNameType(name: String): TypeName = newTypeNameCached(name) - - val REFINE_CLASS_NAME: NameType = "<refinement>" - } + object tpnme extends TypeNames with AbsTypeNames { } /** For fully qualified type names. */ object fulltpnme extends TypeNames { - type NameType = TypeName - protected implicit def createNameType(name: String): TypeName = newTypeNameCached(name) - val RuntimeNothing: NameType = "scala.runtime.Nothing$" val RuntimeNull: NameType = "scala.runtime.Null$" val JavaLangEnum: NameType = "java.lang.Enum" @@ -535,18 +756,9 @@ trait StdNames extends NameManglers { self: SymbolTable => val RuntimeNull = toBinary(fulltpnme.RuntimeNull).toTypeName } - object fullnme extends TermNames { - type NameType = TermName - protected implicit def createNameType(name: String): TermName = newTermNameCached(name) - - val MirrorPackage: NameType = "scala.reflect.mirror" - } - val javanme = nme.javaKeywords - object nme extends AbsTermNames with TermNames /*with LibraryTermNames*/ with TermNameMangling { - type NameType = TermName - protected implicit def createNameType(name: String): TermName = newTermNameCached(name) + object nme extends TermNames with AbsTermNames { /** Translate a String into a list of simple TypeNames and TermNames. * In all segments before the last, type/term is determined by whether @@ -586,40 +798,20 @@ trait StdNames extends NameManglers { self: SymbolTable => def newBitmapName(bitmapPrefix: Name, n: Int) = bitmapPrefix append ("" + n) - val BITMAP_PREFIX: String = "bitmap$" val BITMAP_NORMAL: NameType = BITMAP_PREFIX + "" // initialization bitmap for public/protected lazy vals val BITMAP_TRANSIENT: NameType = BITMAP_PREFIX + "trans$" // initialization bitmap for transient lazy vals val BITMAP_PRIVATE: NameType = BITMAP_PREFIX + "priv$" // initialization bitmap for private lazy vals val BITMAP_CHECKINIT: NameType = BITMAP_PREFIX + "init$" // initialization bitmap for checkinit values val BITMAP_CHECKINIT_TRANSIENT: NameType = BITMAP_PREFIX + "inittrans$" // initialization bitmap for transient checkinit values - /** The expanded name of `name` relative to this class `base` with given `separator` - */ - def expandedName(name: TermName, base: Symbol, separator: String = EXPAND_SEPARATOR_STRING): TermName = - newTermNameCached(base.fullName('$') + separator + name) - def isModuleVarName(name: Name): Boolean = stripAnonNumberSuffix(name) endsWith MODULE_VAR_SUFFIX def moduleVarName(name: TermName): TermName = newTermNameCached("" + name + MODULE_VAR_SUFFIX) - val ROOTPKG: TermName = "_root_" - - /** Base strings from which synthetic names are derived. */ - val CHECK_IF_REFUTABLE_STRING = "check$ifrefutable$" - val DEFAULT_GETTER_STRING = "$default$" - val DO_WHILE_PREFIX = "doWhile$" - val EQEQ_LOCAL_VAR_STRING = "eqEqTemp$" - val EVIDENCE_PARAM_PREFIX = "evidence$" - val EXCEPTION_RESULT_PREFIX = "exceptionResult" - val INTERPRETER_IMPORT_WRAPPER = "$iw" - val INTERPRETER_LINE_PREFIX = "line" - val INTERPRETER_VAR_PREFIX = "res" - val INTERPRETER_WRAPPER_SUFFIX = "$object" - val WHILE_PREFIX = "while$" - - val EQEQ_LOCAL_VAR: TermName = newTermName(EQEQ_LOCAL_VAR_STRING) + val ROOTPKG: TermName = "_root_" + val EQEQ_LOCAL_VAR: TermName = "eqEqTemp$" def getCause = sn.GetCause def getClass_ = sn.GetClass @@ -783,6 +975,11 @@ trait StdNames extends NameManglers { self: SymbolTable => case 22 => nme._22 case _ => newTermName("_" + j) } + + @deprecated("Use a method in tpnme", "2.10.0") def dropSingletonName(name: Name): TypeName = tpnme.dropSingletonName(name) + @deprecated("Use a method in tpnme", "2.10.0") def singletonName(name: Name): TypeName = tpnme.singletonName(name) + @deprecated("Use a method in tpnme", "2.10.0") def implClassName(name: Name): TypeName = tpnme.implClassName(name) + @deprecated("Use a method in tpnme", "2.10.0") def interfaceName(implname: Name): TypeName = tpnme.interfaceName(implname) } abstract class SymbolNames { @@ -816,12 +1013,7 @@ trait StdNames extends NameManglers { self: SymbolTable => } class JavaKeywords { - private var kws: Set[TermName] = Set() - private def kw(s: String): TermName = { - val result = newTermNameCached(s) - kws = kws + result - result - } + private val kw = new KeywordSetBuilder final val ABSTRACTkw: TermName = kw("abstract") final val ASSERTkw: TermName = kw("assert") @@ -874,11 +1066,7 @@ trait StdNames extends NameManglers { self: SymbolTable => final val VOLATILEkw: TermName = kw("volatile") final val WHILEkw: TermName = kw("while") - final val keywords = { - val result = kws.toSet - kws = null - result - } + final val keywords = kw.result } private abstract class JavaNames extends SymbolNames { diff --git a/src/compiler/scala/reflect/internal/Symbols.scala b/src/compiler/scala/reflect/internal/Symbols.scala index c9ac929edf..380ceb4bc7 100644 --- a/src/compiler/scala/reflect/internal/Symbols.scala +++ b/src/compiler/scala/reflect/internal/Symbols.scala @@ -232,7 +232,7 @@ trait Symbols extends api.Symbols { self: SymbolTable => newTermSymbol(name, pos, PARAM | newFlags) /** Create local dummy for template (owner of local blocks) */ - final def newLocalDummy(pos: Position) = + final def newLocalDummy(pos: Position): TermSymbol = newTermSymbol(nme.localDummyName(this), pos) setInfo NoType final def newMethod(name: TermName, pos: Position = NoPosition, newFlags: Long = 0L): MethodSymbol = createMethodSymbol(name, pos, METHOD | newFlags) @@ -240,15 +240,15 @@ trait Symbols extends api.Symbols { self: SymbolTable => newMethod(name, pos, LABEL) /** Propagates ConstrFlags (JAVA, specifically) from owner to constructor. */ - final def newConstructor(pos: Position, newFlags: Long = 0L) = + final def newConstructor(pos: Position, newFlags: Long = 0L): MethodSymbol = newMethod(nme.CONSTRUCTOR, pos, getFlag(ConstrFlags) | newFlags) /** Static constructor with info set. */ - def newStaticConstructor(pos: Position) = + def newStaticConstructor(pos: Position): MethodSymbol = newConstructor(pos, STATIC) setInfo UnitClass.tpe /** Instance constructor with info set. */ - def newClassConstructor(pos: Position) = + def newClassConstructor(pos: Position): MethodSymbol = newConstructor(pos) setInfo MethodType(Nil, this.tpe) def newLinkedModule(clazz: Symbol, newFlags: Long = 0L): ModuleSymbol = { @@ -266,10 +266,10 @@ trait Symbols extends api.Symbols { self: SymbolTable => newModule(name, pos, PackageFlags | newFlags) } - final def newThisSym(name: TermName = nme.this_, pos: Position = NoPosition) = + final def newThisSym(name: TermName = nme.this_, pos: Position = NoPosition): TermSymbol = newTermSymbol(name, pos, SYNTHETIC) - final def newImport(pos: Position) = + final def newImport(pos: Position): TermSymbol = newTermSymbol(nme.IMPORT, pos) final def newModuleSymbol(name: TermName, pos: Position = NoPosition, newFlags: Long = 0L): ModuleSymbol = @@ -299,45 +299,45 @@ trait Symbols extends api.Symbols { self: SymbolTable => * * pre.memberType(m) */ - final def newOverloaded(pre: Type, alternatives: List[Symbol]): Symbol = ( + final def newOverloaded(pre: Type, alternatives: List[Symbol]): TermSymbol = ( newTermSymbol(alternatives.head.name.toTermName, alternatives.head.pos, OVERLOADED) setInfo OverloadedType(pre, alternatives) ) - final def newErrorValue(name: TermName) = + final def newErrorValue(name: TermName): TermSymbol = newTermSymbol(name, pos, SYNTHETIC | IS_ERROR) setInfo ErrorType /** Symbol of a type definition type T = ... */ - final def newAliasType(name: TypeName, pos: Position = NoPosition, newFlags: Long = 0L): Symbol = + final def newAliasType(name: TypeName, pos: Position = NoPosition, newFlags: Long = 0L): AliasTypeSymbol = createAliasTypeSymbol(name, pos, newFlags) /** Symbol of an abstract type type T >: ... <: ... */ - final def newAbstractType(name: TypeName, pos: Position = NoPosition, newFlags: Long = 0L): Symbol = + final def newAbstractType(name: TypeName, pos: Position = NoPosition, newFlags: Long = 0L): AbstractTypeSymbol = createAbstractTypeSymbol(name, pos, DEFERRED | newFlags) /** Symbol of a type parameter */ - final def newTypeParameter(name: TypeName, pos: Position = NoPosition, newFlags: Long = 0L) = + final def newTypeParameter(name: TypeName, pos: Position = NoPosition, newFlags: Long = 0L): TypeSymbol = newAbstractType(name, pos, PARAM | newFlags) /** Symbol of an existential type T forSome { ... } */ - final def newExistential(name: TypeName, pos: Position = NoPosition, newFlags: Long = 0L): Symbol = + final def newExistential(name: TypeName, pos: Position = NoPosition, newFlags: Long = 0L): TypeSymbol = newAbstractType(name, pos, EXISTENTIAL | newFlags) /** Synthetic value parameters when parameter symbols are not available */ - final def newSyntheticValueParamss(argtypess: List[List[Type]]): List[List[Symbol]] = { + final def newSyntheticValueParamss(argtypess: List[List[Type]]): List[List[TermSymbol]] = { var cnt = 0 def freshName() = { cnt += 1; nme.syntheticParamName(cnt) } mmap(argtypess)(tp => newValueParameter(freshName(), owner.pos.focus, SYNTHETIC) setInfo tp) } - def newSyntheticTypeParam(): Symbol = newSyntheticTypeParam("T0", 0L) - def newSyntheticTypeParam(name: String, newFlags: Long): Symbol = newTypeParameter(newTypeName(name), NoPosition, newFlags) setInfo TypeBounds.empty - def newSyntheticTypeParams(num: Int): List[Symbol] = (0 until num).toList map (n => newSyntheticTypeParam("T" + n, 0L)) + def newSyntheticTypeParam(): TypeSymbol = newSyntheticTypeParam("T0", 0L) + def newSyntheticTypeParam(name: String, newFlags: Long): TypeSymbol = newTypeParameter(newTypeName(name), NoPosition, newFlags) setInfo TypeBounds.empty + def newSyntheticTypeParams(num: Int): List[TypeSymbol] = (0 until num).toList map (n => newSyntheticTypeParam("T" + n, 0L)) /** Create a new existential type skolem with this symbol its owner, * based on the given symbol and origin. @@ -352,13 +352,13 @@ trait Symbols extends api.Symbols { self: SymbolTable => def newGADTSkolem(name: TypeName, origin: Symbol, info: Type): TypeSkolem = newTypeSkolemSymbol(name, origin, origin.pos, origin.flags & ~(EXISTENTIAL | PARAM) | CASEACCESSOR | SYNTHETIC) setInfo info - final def freshExistential(suffix: String): Symbol = + final def freshExistential(suffix: String): TypeSymbol = newExistential(freshExistentialName(suffix), pos) /** Synthetic value parameters when parameter symbols are not available. * Calling this method multiple times will re-use the same parameter names. */ - final def newSyntheticValueParams(argtypes: List[Type]): List[Symbol] = + final def newSyntheticValueParams(argtypes: List[Type]): List[TermSymbol] = newSyntheticValueParamss(List(argtypes)).head /** Synthetic value parameter when parameter symbol is not available. @@ -372,27 +372,27 @@ trait Symbols extends api.Symbols { self: SymbolTable => * with name `T` in its typeParams list. While type checking the parameters, result type and * body of the method, there's a local copy of `T` which is a TypeSkolem. */ - final def newTypeSkolem: Symbol = + final def newTypeSkolem: TypeSkolem = owner.newTypeSkolemSymbol(name.toTypeName, this, pos, flags) - final def newClass(name: TypeName, pos: Position = NoPosition, newFlags: Long = 0L) = + final def newClass(name: TypeName, pos: Position = NoPosition, newFlags: Long = 0L): ClassSymbol = newClassSymbol(name, pos, newFlags) /** A new class with its info set to a ClassInfoType with given scope and parents. */ - def newClassWithInfo(name: TypeName, parents: List[Type], scope: Scope, pos: Position = NoPosition, newFlags: Long = 0L) = { + def newClassWithInfo(name: TypeName, parents: List[Type], scope: Scope, pos: Position = NoPosition, newFlags: Long = 0L): ClassSymbol = { val clazz = newClass(name, pos, newFlags) clazz setInfo ClassInfoType(parents, scope, clazz) } - final def newErrorClass(name: TypeName) = + final def newErrorClass(name: TypeName): ClassSymbol = newClassWithInfo(name, Nil, new ErrorScope(this), pos, SYNTHETIC | IS_ERROR) - final def newModuleClass(name: TypeName, pos: Position = NoPosition, newFlags: Long = 0L) = + final def newModuleClass(name: TypeName, pos: Position = NoPosition, newFlags: Long = 0L): ModuleClassSymbol = newModuleClassSymbol(name, pos, newFlags | MODULE) - final def newAnonymousFunctionClass(pos: Position = NoPosition, newFlags: Long = 0L) = + final def newAnonymousFunctionClass(pos: Position = NoPosition, newFlags: Long = 0L): ClassSymbol = newClassSymbol(tpnme.ANON_FUN_NAME, pos, FINAL | SYNTHETIC | newFlags) - final def newAnonymousFunctionValue(pos: Position, newFlags: Long = 0L) = + final def newAnonymousFunctionValue(pos: Position, newFlags: Long = 0L): TermSymbol = newTermSymbol(nme.ANON_FUN_NAME, pos, SYNTHETIC | newFlags) setInfo NoType def newImplClass(name: TypeName, pos: Position = NoPosition, newFlags: Long = 0L): ClassSymbol = { @@ -402,11 +402,12 @@ trait Symbols extends api.Symbols { self: SymbolTable => /** Refinement types P { val x: String; type T <: Number } * also have symbols, they are refinementClasses */ - final def newRefinementClass(pos: Position) = createRefinementClassSymbol(pos, 0L) + final def newRefinementClass(pos: Position): RefinementClassSymbol = + createRefinementClassSymbol(pos, 0L) /** Create a new getter for current symbol (which must be a field) */ - final def newGetter: Symbol = ( + final def newGetter: MethodSymbol = ( owner.newMethod(nme.getterName(name.toTermName), NoPosition, getterFlags(flags)) setPrivateWithin privateWithin setInfo MethodType(Nil, tpe) @@ -1654,7 +1655,7 @@ trait Symbols extends api.Symbols { self: SymbolTable => * symbol with the same owner, and the name of this symbol with $class * appended to it. */ - final def implClass: Symbol = owner.info.decl(nme.implClassName(name)) + final def implClass: Symbol = owner.info.decl(tpnme.implClassName(name)) /** The class that is logically an outer class of given `clazz`. * This is the enclosing class, except for classes defined locally to constructors, @@ -2242,13 +2243,13 @@ trait Symbols extends api.Symbols { self: SymbolTable => /** String representation of existentially bound variable */ def existentialToString = if (isSingletonExistential && !settings.debug.value) - "val " + nme.dropSingletonName(name) + ": " + dropSingletonType(info.bounds.hi) + "val " + tpnme.dropSingletonName(name) + ": " + dropSingletonType(info.bounds.hi) else defString } /** A class for term symbols */ class TermSymbol protected[Symbols] (initOwner: Symbol, initPos: Position, initName: TermName) - extends Symbol(initOwner, initPos, initName) { + extends Symbol(initOwner, initPos, initName) with TermSymbolApi { private[this] var _referenced: Symbol = NoSymbol privateWithin = NoSymbol @@ -2417,7 +2418,7 @@ trait Symbols extends api.Symbols { self: SymbolTable => /** A class for module symbols */ class ModuleSymbol protected[Symbols] (initOwner: Symbol, initPos: Position, initName: TermName) - extends TermSymbol(initOwner, initPos, initName) with DistinguishingFlag { + extends TermSymbol(initOwner, initPos, initName) with DistinguishingFlag with ModuleSymbolApi { def distinguishingFlag = MODULE private var flatname: TermName = null @@ -2442,14 +2443,14 @@ trait Symbols extends api.Symbols { self: SymbolTable => } class PackageSymbol protected[Symbols] (owner0: Symbol, pos0: Position, name0: TermName) - extends ModuleSymbol(owner0, pos0, name0) with DistinguishingFlag { + extends ModuleSymbol(owner0, pos0, name0) with DistinguishingFlag with PackageSymbolApi { override def distinguishingFlag = super.distinguishingFlag | PACKAGE override def isPackage = true } /** A class for method symbols */ class MethodSymbol protected[Symbols] (initOwner: Symbol, initPos: Position, initName: TermName) - extends TermSymbol(initOwner, initPos, initName) with DistinguishingFlag { + extends TermSymbol(initOwner, initPos, initName) with DistinguishingFlag with MethodSymbolApi { def distinguishingFlag = METHOD // MethodSymbols pick up MODULE when trait-owned object accessors are cloned // during mixin composition. @@ -2511,7 +2512,7 @@ trait Symbols extends api.Symbols { self: SymbolTable => * of this class. Classes are instances of a subclass. */ abstract class TypeSymbol protected[Symbols] (initOwner: Symbol, initPos: Position, initName: TypeName) - extends Symbol(initOwner, initPos, initName) { + extends Symbol(initOwner, initPos, initName) with TypeSymbolApi { privateWithin = NoSymbol private[this] var _rawname: TypeName = initName @@ -2712,7 +2713,7 @@ trait Symbols extends api.Symbols { self: SymbolTable => /** A class for class symbols */ class ClassSymbol protected[Symbols] (initOwner: Symbol, initPos: Position, initName: TypeName) - extends TypeSymbol(initOwner, initPos, initName) { + extends TypeSymbol(initOwner, initPos, initName) with ClassSymbolApi { type TypeOfClonedSymbol = ClassSymbol private[this] var flatname: TypeName = _ @@ -2759,7 +2760,7 @@ trait Symbols extends api.Symbols { self: SymbolTable => override def toInterface: Symbol = ( if (isImplClass) { if (phase.next.erasedTypes) lastParent - else owner.info.decl(nme.interfaceName(name)) + else owner.info.decl(tpnme.interfaceName(name)) } else super.toInterface ) diff --git a/src/compiler/scala/reflect/internal/TreeGen.scala b/src/compiler/scala/reflect/internal/TreeGen.scala index 1a374b6e59..f30ec67c7e 100644 --- a/src/compiler/scala/reflect/internal/TreeGen.scala +++ b/src/compiler/scala/reflect/internal/TreeGen.scala @@ -48,6 +48,9 @@ abstract class TreeGen extends api.AbsTreeGen { def mkMethodCall(target: Tree, targs: List[Type], args: List[Tree]): Tree = Apply(mkTypeApply(target, targs map TypeTree), args) + def mkNullaryCall(method: Symbol, targs: List[Type]): Tree = + mkTypeApply(mkAttributedRef(method), targs map TypeTree) + /** Builds a reference to value whose type is given stable prefix. * The type must be suitable for this. For example, it * must not be a TypeRef pointing to an abstract type variable. diff --git a/src/compiler/scala/reflect/internal/Types.scala b/src/compiler/scala/reflect/internal/Types.scala index 7115cafc33..32b09eddeb 100644 --- a/src/compiler/scala/reflect/internal/Types.scala +++ b/src/compiler/scala/reflect/internal/Types.scala @@ -2310,7 +2310,7 @@ trait Types extends api.Types { self: SymbolTable => else if (sym.isPackageClass || sym.isPackageObjectOrClass) sym.skipPackageObject.fullName + "." else if (isStable && nme.isSingletonName(sym.name)) - nme.dropSingletonName(sym.name) + "." + tpnme.dropSingletonName(sym.name) + "." else super.prefixString ) diff --git a/src/compiler/scala/reflect/internal/pickling/UnPickler.scala b/src/compiler/scala/reflect/internal/pickling/UnPickler.scala index f89aa9bf5c..eb4bae78d0 100644 --- a/src/compiler/scala/reflect/internal/pickling/UnPickler.scala +++ b/src/compiler/scala/reflect/internal/pickling/UnPickler.scala @@ -816,16 +816,10 @@ abstract class UnPickler /*extends reflect.generic.UnPickler*/ { throw new RuntimeException("malformed Scala signature of " + classRoot.name + " at " + readIndex + "; " + msg) protected def errorMissingRequirement(name: Name, owner: Symbol): Symbol = - missingHook(owner, name) orElse { - val what = if (name.isTypeName) "type" else "value" - MissingRequirementError.notFound( - "while unpickling %s, reference %s %s of %s/%s/%s".format( - filename, - what, name.decode, owner.tpe.widen, - owner.tpe.typeSymbol.ownerChain, - owner.info.members.mkString("\n ", "\n ", "")) - ) - } + missingHook(owner, name) orElse MissingRequirementError.notFound( + "bad reference while unpickling %s: %s not found in %s".format( + filename, name.longString, owner.tpe.widen) + ) def inferMethodAlternative(fun: Tree, argtpes: List[Type], restpe: Type) {} // can't do it; need a compiler for that. diff --git a/src/compiler/scala/reflect/makro/runtime/Reifiers.scala b/src/compiler/scala/reflect/makro/runtime/Reifiers.scala index 7c96b568bd..d9a89d0e6d 100644 --- a/src/compiler/scala/reflect/makro/runtime/Reifiers.scala +++ b/src/compiler/scala/reflect/makro/runtime/Reifiers.scala @@ -12,6 +12,37 @@ trait Reifiers { import mirror._ import definitions._ + private lazy val ClassTagModule = ClassTagClass.companionSymbol + + // [Eugene] imho this logic should be moved into `erasure` + private def calculateTagErasure(tpe: Type) = tpe match { + case tpe if tpe.typeSymbol.isDerivedValueClass => tpe // [Eugene to Martin] is this correct? + case ConstantType(value) => tpe.widen.erasure + case _ => + // [Eugene] magikz. needs review + // necessary to deal with erasures of HK types, typeConstructor won't work + tpe.erasure.normalize match { + // we don't want undets in the result + case PolyType(undets, underlying) => existentialAbstraction(undets, underlying) + case result => result + } + } + private def classTagFromArgument(tpe: Type, arg: Tree) = { + gen.mkMethodCall(ClassTagModule, nme.apply, List(tpe), List(arg)) + // val factory = TypeApply(Select(Ident(ClassTagModule), nme.apply), List(TypeTree(tpe))) + // Apply(factory, List(typeArg)) + } + private def classTagFromErasure(tpe: Type) = { + val erasure = calculateTagErasure(tpe) + classTagFromArgument(tpe, gen.mkNullaryCall(Predef_classOf, List(erasure))) + // val targ = TypeApply(Select(Ident(PredefModule), nme.classOf), List(TypeTree(erasure))) + // classTagFromArgument(tpe, targ) + } + private def typetagIsSynthetic(tree: Tree) = tree match { + case Block(_, _) => true + case _ => tree exists (_ hasSymbolWhich Set(TypeTagModule, ConcreteTypeTagModule)) + } + lazy val reflectMirrorPrefix: Tree = { // [Eugene] how do I typecheck this without undergoing this tiresome (and, in general, incorrect) procedure? val prefix: Tree = Select(Select(Ident(definitions.ScalaPackage), newTermName("reflect")), newTermName("mirror")) @@ -26,40 +57,36 @@ trait Reifiers { reifyTopLevel(prefix, tpe, dontSpliceAtTopLevel, requireConcreteTypeTag) def reifyErasure(tpe: Type): Tree = { - val positionBearer = enclosingMacros.find(c => c.macroApplication.pos != NoPosition).map(_.macroApplication).getOrElse(EmptyTree).asInstanceOf[Tree] - val typetagInScope = callsiteTyper.context.withMacrosDisabled(callsiteTyper.resolveTypeTag(positionBearer, singleType(Reflect_mirror.owner.thisPrefix, Reflect_mirror), tpe, full = true)) - def typetagIsSynthetic(tree: Tree) = tree.isInstanceOf[Block] || (tree exists (sub => sub.symbol == TypeTagModule || sub.symbol == ConcreteTypeTagModule)) + val positionBearer = (enclosingMacros.find(_.macroApplication.pos != NoPosition) match { + case None => EmptyTree + case Some(m) => m.macroApplication + }).asInstanceOf[Tree] + + val typetagInScope = callsiteTyper.context.withMacrosDisabled( + callsiteTyper.resolveTypeTag( + positionBearer, + singleType(Reflect_mirror.owner.thisPrefix, Reflect_mirror), + tpe, + full = true + ) + ) typetagInScope match { case success if !success.isEmpty && !typetagIsSynthetic(success) => - val factory = TypeApply(Select(Ident(ClassTagModule), nme.apply), List(TypeTree(tpe))) - Apply(factory, List(typetagInScope)) + classTagFromArgument(tpe, typetagInScope) case _ => if (tpe.typeSymbol == ArrayClass) { val componentTpe = tpe.typeArguments(0) val componentTag = callsiteTyper.resolveClassTag(positionBearer, componentTpe) Select(componentTag, nme.wrap) - } else { - // [Eugene] what's the intended behavior? there's no spec on ClassManifests - // for example, should we ban Array[T] or should we tag them with Array[AnyRef]? - // if its the latter, what should be the result of tagging Array[T] where T <: Int? - if (tpe.isSpliceable) throw new ReificationError(enclosingPosition, "tpe %s is an unresolved spliceable type".format(tpe)) - // [Eugene] imho this logic should be moved into `erasure` - var erasure = tpe match { - case tpe if tpe.typeSymbol.isDerivedValueClass => tpe // [Eugene to Martin] is this correct? - case ConstantType(value) => tpe.widen.erasure - case _ => { - // [Eugene] magikz. needs review - var result = tpe.erasure.normalize // necessary to deal with erasures of HK types, typeConstructor won't work - result = result match { - case PolyType(undets, underlying) => existentialAbstraction(undets, underlying) // we don't want undets in the result - case _ => result - } - result - } - } - val factory = TypeApply(Select(Ident(ClassTagModule), nme.apply), List(TypeTree(tpe))) - Apply(factory, List(TypeApply(Select(Ident(PredefModule), nme.classOf), List(TypeTree(erasure))))) } + // [Eugene] what's the intended behavior? there's no spec on ClassManifests + // for example, should we ban Array[T] or should we tag them with Array[AnyRef]? + // if its the latter, what should be the result of tagging Array[T] where T <: Int? + else if (tpe.isSpliceable) { + throw new ReificationError(enclosingPosition, + "tpe %s is an unresolved spliceable type".format(tpe)) + } + else classTagFromErasure(tpe) } } diff --git a/src/compiler/scala/reflect/runtime/SynchronizedOps.scala b/src/compiler/scala/reflect/runtime/SynchronizedOps.scala index dd806beb2a..907c0dd369 100644 --- a/src/compiler/scala/reflect/runtime/SynchronizedOps.scala +++ b/src/compiler/scala/reflect/runtime/SynchronizedOps.scala @@ -39,7 +39,7 @@ trait SynchronizedOps extends internal.SymbolTable trait SynchronizedScope extends Scope { override def isEmpty: Boolean = synchronized { super.isEmpty } override def size: Int = synchronized { super.size } - override def enter(sym: Symbol) = synchronized { super.enter(sym) } + override def enter[T <: Symbol](sym: T): T = synchronized { super.enter(sym) } override def rehash(sym: Symbol, newname: Name) = synchronized { super.rehash(sym, newname) } override def unlink(e: ScopeEntry) = synchronized { super.unlink(e) } override def unlink(sym: Symbol) = synchronized { super.unlink(sym) } diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala index f9cef385dc..8c6c927640 100644 --- a/src/compiler/scala/tools/nsc/Global.scala +++ b/src/compiler/scala/tools/nsc/Global.scala @@ -1531,7 +1531,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter) extends Symb /** We resolve the class/object ambiguity by passing a type/term name. */ def showDef(fullName: Name, declsOnly: Boolean, ph: Phase) = { - val boringOwners = Set(definitions.AnyClass, definitions.AnyRefClass, definitions.ObjectClass) + val boringOwners = Set[Symbol](definitions.AnyClass, definitions.AnyRefClass, definitions.ObjectClass) def phased[T](body: => T): T = afterPhase(ph)(body) def boringMember(sym: Symbol) = boringOwners(sym.owner) def symString(sym: Symbol) = if (sym.isTerm) sym.defString else sym.toString diff --git a/src/compiler/scala/tools/nsc/ast/parser/SymbolicXMLBuilder.scala b/src/compiler/scala/tools/nsc/ast/parser/SymbolicXMLBuilder.scala index 0f2a3e0395..b0204c5971 100755 --- a/src/compiler/scala/tools/nsc/ast/parser/SymbolicXMLBuilder.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/SymbolicXMLBuilder.scala @@ -30,7 +30,7 @@ abstract class SymbolicXMLBuilder(p: Parsers#Parser, preserveWS: Boolean) { private[parser] var isPattern: Boolean = _ - private trait XMLTypeNames extends TypeNames { + private object xmltypes extends TypeNames { val _Comment: NameType = "Comment" val _Elem: NameType = "Elem" val _EntityRef: NameType = "EntityRef" @@ -45,7 +45,7 @@ abstract class SymbolicXMLBuilder(p: Parsers#Parser, preserveWS: Boolean) { val _UnprefixedAttribute: NameType = "UnprefixedAttribute" } - private trait XMLTermNames extends TermNames { + private object xmlterms extends TermNames { val _Null: NameType = "Null" val __Elem: NameType = "Elem" val __Text: NameType = "Text" @@ -57,15 +57,6 @@ abstract class SymbolicXMLBuilder(p: Parsers#Parser, preserveWS: Boolean) { val _xml: NameType = "xml" } - private object xmltypes extends XMLTypeNames { - type NameType = TypeName - implicit def createNameType(name: String): TypeName = newTypeNameCached(name) - } - private object xmlterms extends XMLTermNames { - type NameType = TermName - implicit def createNameType(name: String): TermName = newTermNameCached(name) - } - import xmltypes.{_Comment, _Elem, _EntityRef, _Group, _MetaData, _NamespaceBinding, _NodeBuffer, _PrefixedAttribute, _ProcInstr, _Text, _Unparsed, _UnprefixedAttribute} diff --git a/src/compiler/scala/tools/nsc/backend/icode/TypeKinds.scala b/src/compiler/scala/tools/nsc/backend/icode/TypeKinds.scala index f61f78ebb2..1ec2cf017a 100644 --- a/src/compiler/scala/tools/nsc/backend/icode/TypeKinds.scala +++ b/src/compiler/scala/tools/nsc/backend/icode/TypeKinds.scala @@ -420,7 +420,7 @@ trait TypeKinds { self: ICodes => // between "object PackratParsers$class" and "trait PackratParsers" if (sym.isImplClass) { // pos/spec-List.scala is the sole failure if we don't check for NoSymbol - val traitSym = sym.owner.info.decl(nme.interfaceName(sym.name)) + val traitSym = sym.owner.info.decl(tpnme.interfaceName(sym.name)) if (traitSym != NoSymbol) return REFERENCE(traitSym) } diff --git a/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala b/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala index 124a7509e8..a6728654cd 100644 --- a/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala +++ b/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala @@ -42,7 +42,7 @@ class ModelFactory(val global: Global, val settings: doc.Settings) { memberSym.isOmittablePrefix || (closestPackage(memberSym) == closestPackage(templateSym)) } - private lazy val noSubclassCache = Set(AnyClass, AnyRefClass, ObjectClass) + private lazy val noSubclassCache = Set[Symbol](AnyClass, AnyRefClass, ObjectClass) /** */ def makeModel: Option[Universe] = { @@ -675,7 +675,7 @@ class ModelFactory(val global: Global, val settings: doc.Settings) { } /* Refined types */ case RefinedType(parents, defs) => - val ignoreParents = Set(AnyClass, ObjectClass) + val ignoreParents = Set[Symbol](AnyClass, ObjectClass) val filtParents = parents filterNot (x => ignoreParents(x.typeSymbol)) match { case Nil => parents case ps => ps diff --git a/src/compiler/scala/tools/nsc/interpreter/IMain.scala b/src/compiler/scala/tools/nsc/interpreter/IMain.scala index bfcfa5f2b9..923fc867a9 100644 --- a/src/compiler/scala/tools/nsc/interpreter/IMain.scala +++ b/src/compiler/scala/tools/nsc/interpreter/IMain.scala @@ -196,8 +196,9 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends import global._ import definitions.{ - ScalaPackage, JavaLangPackage, PredefModule, RootClass, - getClassIfDefined, getModuleIfDefined, getRequiredModule, getRequiredClass + ScalaPackage, JavaLangPackage, RootClass, + getClassIfDefined, getModuleIfDefined, getRequiredModule, getRequiredClass, + termMember, typeMember } private implicit def privateTreeOps(t: Tree): List[Tree] = { @@ -806,9 +807,9 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends */ def resolvePathToSymbol(accessPath: String): Symbol = { val readRoot = getRequiredModule(readPath) // the outermost wrapper - (accessPath split '.').foldLeft(readRoot) { (sym, name) => - if (name == "") sym else - afterTyper(sym.info member newTermName(name)) + (accessPath split '.').foldLeft(readRoot: Symbol) { + case (sym, "") => sym + case (sym, name) => afterTyper(termMember(sym, name)) } } /** We get a bunch of repeated warnings for reasons I haven't diff --git a/src/compiler/scala/tools/nsc/matching/MatchSupport.scala b/src/compiler/scala/tools/nsc/matching/MatchSupport.scala index 249f754e8f..72e6f32af1 100644 --- a/src/compiler/scala/tools/nsc/matching/MatchSupport.scala +++ b/src/compiler/scala/tools/nsc/matching/MatchSupport.scala @@ -31,7 +31,7 @@ trait MatchSupport extends ast.TreeDSL { self: ParallelMatching => object Types { import definitions._ - val subrangeTypes = Set(ByteClass, ShortClass, CharClass, IntClass) + val subrangeTypes = Set[Symbol](ByteClass, ShortClass, CharClass, IntClass) implicit class RichType(undecodedTpe: Type) { def tpe = decodedEqualsType(undecodedTpe) diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ICodeReader.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ICodeReader.scala index 775a7a9d38..862a3ffdc7 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/ICodeReader.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/ICodeReader.scala @@ -165,7 +165,7 @@ abstract class ICodeReader extends ClassfileParser { else if (name == fulltpnme.RuntimeNull) definitions.NullClass else if (nme.isImplClassName(name)) { - val iface = definitions.getClass(nme.interfaceName(name)) + val iface = definitions.getClass(tpnme.interfaceName(name)) log("forcing " + iface.owner + " at phase: " + phase + " impl: " + iface.implClass) iface.owner.info // force the mixin type-transformer definitions.getClass(name) diff --git a/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala b/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala index 5a11926048..3581f1b923 100644 --- a/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala +++ b/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala @@ -66,7 +66,7 @@ abstract class AddInterfaces extends InfoTransform { self: Erasure => private def newImplClass(iface: Symbol): Symbol = { val inClass = iface.owner.isClass - val implName = nme.implClassName(iface.name) + val implName = tpnme.implClassName(iface.name) val implFlags = (iface.flags & ~(INTERFACE | lateINTERFACE)) | IMPLCLASS val impl0 = ( diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala index 5e61359a25..45dacd5c14 100644 --- a/src/compiler/scala/tools/nsc/transform/Erasure.scala +++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala @@ -992,7 +992,7 @@ abstract class Erasure extends AddInterfaces } // Rewrite 5.getClass to ScalaRunTime.anyValClass(5) else if (isPrimitiveValueClass(qual.tpe.typeSymbol)) - global.typer.typed(gen.mkRuntimeCall(nme.anyValClass, List(qual))) + global.typer.typed(gen.mkRuntimeCall(nme.anyValClass, List(qual, typer.resolveClassTag(tree, qual.tpe.widen)))) else tree diff --git a/src/compiler/scala/tools/nsc/transform/LambdaLift.scala b/src/compiler/scala/tools/nsc/transform/LambdaLift.scala index 6bddfe8d57..618a1cbba4 100644 --- a/src/compiler/scala/tools/nsc/transform/LambdaLift.scala +++ b/src/compiler/scala/tools/nsc/transform/LambdaLift.scala @@ -159,7 +159,7 @@ abstract class LambdaLift extends InfoTransform { // for that failure. There should be exactly one method for any given // entity which always gives the right answer. if (sym.isImplClass) - localImplClasses((sym.owner, nme.interfaceName(sym.name))) = sym + localImplClasses((sym.owner, tpnme.interfaceName(sym.name))) = sym else { renamable addEntry sym if (sym.isTrait) @@ -229,7 +229,7 @@ abstract class LambdaLift extends InfoTransform { def renameTrait(traitSym: Symbol, implSym: Symbol) { val originalImplName = implSym.name renameSym(traitSym) - implSym setName nme.implClassName(traitSym.name) + implSym setName tpnme.implClassName(traitSym.name) debuglog("renaming impl class in step with %s: %s => %s".format(traitSym, originalImplName, implSym.name)) } diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala index 651120db4f..f8da6a462d 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala @@ -1121,10 +1121,10 @@ trait Implicits { } // these should be lazy, otherwise we wouldn't be able to compile scala-library with starr - private val TagSymbols = Set(ClassTagClass, TypeTagClass, ConcreteTypeTagClass) - private val TagMaterializers = Map( - ClassTagClass -> MacroInternal_materializeClassTag, - TypeTagClass -> MacroInternal_materializeTypeTag, + private val TagSymbols = Set[Symbol](ClassTagClass, TypeTagClass, ConcreteTypeTagClass) + private val TagMaterializers = Map[Symbol, MethodSymbol]( + ClassTagClass -> MacroInternal_materializeClassTag, + TypeTagClass -> MacroInternal_materializeTypeTag, ConcreteTypeTagClass -> MacroInternal_materializeConcreteTypeTag ) @@ -1140,27 +1140,34 @@ trait Implicits { failure(arg, "failed to typecheck the materialized typetag: %n%s".format(ex.msg), ex.pos) } - val prefix = (tagClass, pre) match { - // ClassTags only exist for scala.reflect.mirror, so their materializer doesn't care about prefixes - case (ClassTagClass, _) => - gen.mkAttributedRef(Reflect_mirror) setType singleType(Reflect_mirror.owner.thisPrefix, Reflect_mirror) - // [Eugene to Martin] this is the crux of the interaction between implicits and reifiers - // here we need to turn a (supposedly path-dependent) type into a tree that will be used as a prefix - // I'm not sure if I've done this right - please, review - case (_, SingleType(prePre, preSym)) => - gen.mkAttributedRef(prePre, preSym) setType pre - // necessary only to compile typetags used inside the Universe cake - case (_, ThisType(thisSym)) => - gen.mkAttributedThis(thisSym) - case _ => - // if ``pre'' is not a PDT, e.g. if someone wrote - // implicitly[scala.reflect.makro.Context#TypeTag[Int]] - // then we need to fail, because we don't know the prefix to use during type reification - return failure(tp, "tag error: unsupported prefix type %s (%s)".format(pre, pre.kind)) - } - + val prefix = ( + // ClassTags only exist for scala.reflect.mirror, so their materializer + // doesn't care about prefixes + if (tagClass eq ClassTagClass) ( + gen.mkAttributedRef(Reflect_mirror) + setType singleType(Reflect_mirror.owner.thisPrefix, Reflect_mirror) + ) + else pre match { + // [Eugene to Martin] this is the crux of the interaction between + // implicits and reifiers here we need to turn a (supposedly + // path-dependent) type into a tree that will be used as a prefix I'm + // not sure if I've done this right - please, review + case SingleType(prePre, preSym) => + gen.mkAttributedRef(prePre, preSym) setType pre + // necessary only to compile typetags used inside the Universe cake + case ThisType(thisSym) => + gen.mkAttributedThis(thisSym) + case _ => + // if ``pre'' is not a PDT, e.g. if someone wrote + // implicitly[scala.reflect.makro.Context#TypeTag[Int]] + // then we need to fail, because we don't know the prefix to use during type reification + return failure(tp, "tag error: unsupported prefix type %s (%s)".format(pre, pre.kind)) + } + ) // todo. migrate hardcoded materialization in Implicits to corresponding implicit macros - var materializer = atPos(pos.focus)(Apply(TypeApply(Ident(TagMaterializers(tagClass)), List(TypeTree(tp))), List(prefix))) + var materializer = atPos(pos.focus)( + gen.mkMethodCall(TagMaterializers(tagClass), List(tp), List(prefix)) + ) if (settings.XlogImplicits.value) println("materializing requested %s.%s[%s] using %s".format(pre, tagClass.name, tp, materializer)) if (context.macrosEnabled) success(materializer) else failure(materializer, "macros are disabled") @@ -1169,8 +1176,8 @@ trait Implicits { /** The manifest corresponding to type `pt`, provided `pt` is an instance of Manifest. */ private def implicitTagOrOfExpectedType(pt: Type): SearchResult = pt.dealias match { - case TypeRef(pre, sym, args) if TagSymbols(sym) => - tagOfType(pre, args.head, sym) + case TypeRef(pre, sym, arg :: Nil) if TagSymbols(sym) => + tagOfType(pre, arg, sym) case tp@TypeRef(_, sym, _) if sym.isAbstractType => implicitTagOrOfExpectedType(tp.bounds.lo) // #3977: use tp (==pt.dealias), not pt (if pt is a type alias, pt.bounds.lo == pt) case _ => diff --git a/src/compiler/scala/tools/nsc/typechecker/Macros.scala b/src/compiler/scala/tools/nsc/typechecker/Macros.scala index da32e638d3..9b4dd09c98 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Macros.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Macros.scala @@ -427,7 +427,7 @@ trait Macros { self: Analyzer => var actparamss = macroImpl.paramss actparamss = transformTypeTagEvidenceParams(actparamss, (param, tparam) => None) - val rettpe = if (ddef.tpt.tpe != null) ddef.tpt.tpe else computeMacroDefTypeFromMacroImpl(ddef, macroDef, macroImpl) + val rettpe = if (!ddef.tpt.isEmpty) typer.typedType(ddef.tpt).tpe else computeMacroDefTypeFromMacroImpl(ddef, macroDef, macroImpl) val (reqparamsss0, reqres0) = macroImplSigs(macroDef, ddef.tparams, ddef.vparamss, rettpe) var reqparamsss = reqparamsss0 @@ -1020,7 +1020,7 @@ trait Macros { self: Analyzer => private def Failure(expandee: Tree) = Other(expandee) private def fail(typer: Typer, expandee: Tree, msg: String = null) = { if (macroDebug || macroCopypaste) { - var msg1 = if (msg contains "exception during macro expansion") msg.split(EOL).drop(1).headOption.getOrElse("?") else msg + var msg1 = if (msg != null && (msg contains "exception during macro expansion")) msg.split(EOL).drop(1).headOption.getOrElse("?") else msg if (macroDebug) println("macro expansion has failed: %s".format(msg1)) } val pos = if (expandee.pos != NoPosition) expandee.pos else openMacros.find(c => c.expandee.pos != NoPosition).map(_.expandee.pos).getOrElse(NoPosition) diff --git a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala index 43cbea83ff..d327d9c397 100644 --- a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala +++ b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala @@ -134,7 +134,7 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT // otherwise lead to either a compiler crash or runtime failure. private lazy val isDisallowed = { import definitions._ - Set(Any_isInstanceOf, Object_isInstanceOf, Any_asInstanceOf, Object_asInstanceOf, Object_==, Object_!=, Object_##) + Set[Symbol](Any_isInstanceOf, Object_isInstanceOf, Any_asInstanceOf, Object_asInstanceOf, Object_==, Object_!=, Object_##) } override def transform(tree: Tree): Tree = { diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 9a59d8f28a..54be9c9a87 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -3322,7 +3322,7 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser { val typeParams: List[Symbol] = rawSyms map { sym => val name = sym.name match { case x: TypeName => x - case x => nme.singletonName(x) + case x => tpnme.singletonName(x) } val bound = allBounds(sym) val sowner = if (isRawParameter(sym)) context.owner else sym.owner diff --git a/src/dbc/scala/dbc/DataType.scala b/src/dbc/scala/dbc/DataType.scala deleted file mode 100644 index 677621e0c0..0000000000 --- a/src/dbc/scala/dbc/DataType.scala +++ /dev/null @@ -1,69 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc; - - -/** An ISO-9075:2003 (SQL) data type. Mappings between SQL types and - * database specific types should be provided by the database driver. - */ -@deprecated(DbcIsDeprecated, "2.9.0") abstract class DataType { - - /** Tests whether this datatype is equivalent to another. Usually, two - * types are defined as equivalent if they are equal. Two types can be - * equivalent without being equal if values of those types will be - * encoded in the same native Scala type. - */ - def isEquivalent(datatype: DataType): Boolean; - - /** Tests whether this datatype is equivalent or a subtype of another - * datatype. Type <code>A</code> is said to be subtype of type - * <code>B</code> if any value of type <code>A</code> can be - * represented as a value of type <code>B</code>. - */ - def isSubtypeOf(datatype: DataType): Boolean; - - /** The native Scala type in which values of this SQL type will be - * encoded. - */ - type NativeType <: Any; - - /** The native Scala type in which values of this SQL type will be - * encoded. This must point to the same type as <code>NativeType</code>. - */ - def nativeTypeId: DataType.Id; - - /** Whether the value can take the null value, None when this property is - * unknown. - */ - def nullable: Option[Boolean] = None; - - /** The SQL name of the type */ - def sqlString: String = "UNDEFINED DATA TYPE" - -} - -@deprecated(DbcIsDeprecated, "2.9.0") object DataType { - - type Id = Int; - - val OBJECT : Id = 10; - val BOOLEAN : Id = 20; - val BYTE : Id = 30; - val SHORT : Id = 31; - val INT : Id = 32; - val LONG : Id = 33; - val BIG_INTEGER: Id = 34; - val BIG_DECIMAL: Id = 35; - val FLOAT : Id = 40; - val DOUBLE : Id = 41; - val STRING : Id = 50; - -} diff --git a/src/dbc/scala/dbc/Database.scala b/src/dbc/scala/dbc/Database.scala deleted file mode 100644 index 60e16367e8..0000000000 --- a/src/dbc/scala/dbc/Database.scala +++ /dev/null @@ -1,187 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc - - -import java.sql._ - -/** A link to a database. The <code>Database</code> abstract class must - * be specialised for every different DBMS. - * - * @author Gilles Dubochet - */ -@deprecated(DbcIsDeprecated, "2.9.0") case class Database(dbms: Vendor) { - - class Closed extends Exception {} - - /** A lock used for operations that need to be atomic for this database - * instance. */ - private val lock: scala.concurrent.Lock = new scala.concurrent.Lock() - - /** The vendor of the DBMS that contains this database. */ - private val vendor: Vendor = dbms - - /** The Database connections available to use. */ - private var availableConnections: List[Connection] = Nil - - /** The connections that are currently in use. */ - private var usedConnections: List[Connection] = Nil - - /** Whether the database no longer accepts new connections. */ - private var closing: Boolean = false; - - /** Retrieves a connection from the available connection pool or creates - * a new one. - * - * @return A connection that can be used to access the database. - */ - private def getConnection: Connection = { - if (closing) { - throw new Closed; - } else { - availableConnections match { - case Nil => { - lock.acquire; - val connection = vendor.getConnection; - usedConnections = connection :: usedConnections; - lock.release; - connection - } - case connection :: cs => { - lock.acquire; - availableConnections = cs; - usedConnections = connection :: usedConnections; - lock.release; - connection; - } - } - } - } - - /** Closes a connection to this database. A closed connection might - * also return to the available connection pool if the latter is depleted. - * - * @param connection The connection that should be closed. - */ - private def closeConnection(connection: Connection): Unit = { - if (closing) { - connection.close() - } else { - lock.acquire - usedConnections = usedConnections.filterNot(e => (e.equals(connection))); - if (availableConnections.length < vendor.retainedConnections) - availableConnections = connection :: availableConnections - else - connection.close() - lock.release - } - } - - /** .. - */ - def close() { - closing = true - for (conn <- availableConnections) conn.close() - } - - /** Executes a statement that returns a relation on this database. - * - * @param relationStatement The statement to execute. - * @return The relation returned by the database for this statement. - */ - def executeStatement(relationStatement: statement.Relation): result.Relation = - executeStatement(relationStatement, false); - - /** Executes a statement that returns a relation on this database. - * - * @param relationStatement The statement to execute. - * @param debug Whether debugging information should be printed on the console. - * @return The relation returned by the database for this statement. - */ - def executeStatement(relationStatement: statement.Relation, - debug: Boolean): result.Relation = - new scala.dbc.result.Relation { - val statement = relationStatement - if (debug) Console.println("## " + statement.sqlString) - private val connection = getConnection - val sqlResult = connection.createStatement().executeQuery(statement.sqlString) - closeConnection(connection) - statement.typeCheck(this) - } - - /** Executes a statement that updates the state of the database. - * @param statusStatement The statement to execute. - * @return The status of the database after the statement has been executed. */ - def executeStatement(statusStatement: statement.Status): result.Status[Unit] = - executeStatement(statusStatement, false); - - /** Executes a statement that updates the state of the database. - * - * @param statusStatement The statement to execute. - * @param debug Whether debugging information should be printed on the console. - * @return The status of the database after the statement has been executed. - */ - def executeStatement(statusStatement: statement.Status, - debug: Boolean): result.Status[Unit] = - new scala.dbc.result.Status[Unit] { - val statement = statusStatement; - if (debug) Console.println("## " + statement.sqlString); - def result = () - private val connection = getConnection; - val jdbcStatement: java.sql.Statement = connection.createStatement(); - jdbcStatement.execute(statement.sqlString); - val touchedCount = Some(jdbcStatement.getUpdateCount()); - closeConnection(connection); - } - - /** Executes a list of statements or other operations inside a transaction. - * Only statements are protected in a transaction, other Scala code is not. - * - * @param transactionStatement The transaction to execute as a closure. - * @return The status of the database after the transaction has been executed. - */ - def executeStatement[ResultType](transactionStatement: statement.Transaction[ResultType]): result.Status[ResultType] = - executeStatement(transactionStatement, false); - - /** Executes a list of statements or other operations inside a transaction. - * Only statements are protected in a transaction, other Scala code is not. - * - * @param transactionStatement The transaction to execute as a closure. - * @param debug Whether debugging information should be printed on the console. - * @return The status of the database after the transaction has been executed. - */ - def executeStatement[ResultType](transactionStatement: statement.Transaction[ResultType], debug: Boolean): result.Status[ResultType] = { - new scala.dbc.result.Status[ResultType] { - val touchedCount = None - val statement = transactionStatement - private val connection = getConnection - connection.setAutoCommit(false) - val jdbcStatement: java.sql.Statement = connection.createStatement(); - if (debug) Console.println("## " + transactionStatement.sqlStartString); - jdbcStatement.execute(transactionStatement.sqlStartString); - val result: ResultType = try { - val buffer = transactionStatement.transactionBody(Database.this); - if (debug) Console.println("## " + transactionStatement.sqlCommitString); - jdbcStatement.execute(transactionStatement.sqlCommitString); - buffer - } catch { - case e: Throwable => { - if (debug) Console.println("## " + transactionStatement.sqlAbortString); - jdbcStatement.execute(transactionStatement.sqlAbortString); - throw e - } - } - connection.setAutoCommit(true) - closeConnection(connection) - } - } - -} diff --git a/src/dbc/scala/dbc/Syntax.scala b/src/dbc/scala/dbc/Syntax.scala deleted file mode 100644 index 85cd1c1a1d..0000000000 --- a/src/dbc/scala/dbc/Syntax.scala +++ /dev/null @@ -1,47 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc; - - -import java.math.{BigDecimal, BigInteger}; - - -/** This class .. - * - */ -@deprecated(DbcIsDeprecated, "2.9.0") object Syntax { - - import syntax.DataTypeUtil; - - /* Data types */ - def boolean = DataTypeUtil.boolean; - def tinyint = DataTypeUtil.tinyint; - def smallint = DataTypeUtil.smallint; - def integer = DataTypeUtil.integer; - def bigint = DataTypeUtil.bigint; - def real = DataTypeUtil.real; - - def numeric(precision: Int) = DataTypeUtil.numeric(precision); - def numeric(precision: Int, scale: Int) = DataTypeUtil.numeric(precision, scale); - - def doublePrecision = DataTypeUtil.doublePrecision; - def character(length: Int) = DataTypeUtil.character(length); - def characterVarying(length: Int) = DataTypeUtil.characterVarying(length); - def characterLargeObject = DataTypeUtil.characterLargeObject; - - /* Statements */ - //def select - - /* Other stuff */ - def database (server: String, username: String, password: String): dbc.Database = - syntax.Database.database(server, username, password); - -} diff --git a/src/dbc/scala/dbc/Utilities.scala b/src/dbc/scala/dbc/Utilities.scala deleted file mode 100644 index c37b1bb98d..0000000000 --- a/src/dbc/scala/dbc/Utilities.scala +++ /dev/null @@ -1,28 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc; - - -/** An object offering transformation methods (views) on various values. - * This object's members must be visible in an expression to use value - * auto-conversion. - */ -@deprecated(DbcIsDeprecated, "2.9.0") object Utilities { - - implicit def constantToValue (obj: statement.expression.Constant): Value = - obj.constantValue; - - implicit def valueToConstant (obj: Value): statement.expression.Constant = - new statement.expression.Constant { - val constantValue = obj; - } - -} diff --git a/src/dbc/scala/dbc/Value.scala b/src/dbc/scala/dbc/Value.scala deleted file mode 100644 index a502f51cb5..0000000000 --- a/src/dbc/scala/dbc/Value.scala +++ /dev/null @@ -1,27 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc; - - -/** A SQL-99 value of any type. */ -@deprecated(DbcIsDeprecated, "2.9.0") abstract class Value { - - /** The SQL-99 type of the value. */ - val dataType: DataType; - - type NativeType = dataType.type#NativeType; - - val nativeValue: NativeType; - - /** A SQL-99 compliant string representation of the value. */ - def sqlString: String; - -} diff --git a/src/dbc/scala/dbc/Vendor.scala b/src/dbc/scala/dbc/Vendor.scala deleted file mode 100644 index 68f6102526..0000000000 --- a/src/dbc/scala/dbc/Vendor.scala +++ /dev/null @@ -1,41 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc; - - -import java.sql.{Connection, Driver}; - - -/** This class .. - */ -@deprecated(DbcIsDeprecated, "2.9.0") abstract class Vendor { - - def nativeDriverClass: Class[_]; - def uri: java.net.URI; - def user: String; - def pass: String; - def nativeProperties: java.util.Properties = { - val properties = new java.util.Properties(); - properties.setProperty("user", user); - properties.setProperty("password", pass); - properties - } - - def retainedConnections: Int; - - def getConnection: Connection = { - val driver = nativeDriverClass.newInstance().asInstanceOf[Driver]; - driver.connect(uri.toString(),nativeProperties) - } - - def urlProtocolString: String; - -} diff --git a/src/dbc/scala/dbc/datatype/ApproximateNumeric.scala b/src/dbc/scala/dbc/datatype/ApproximateNumeric.scala deleted file mode 100644 index 31752e18c7..0000000000 --- a/src/dbc/scala/dbc/datatype/ApproximateNumeric.scala +++ /dev/null @@ -1,57 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package datatype; - - -/** A type category for all SQL types that store varying-precision - * numbers. - */ -@deprecated(DbcIsDeprecated, "2.9.0") abstract class ApproximateNumeric[Type] ( - override val nativeTypeId: DataType.Id -) extends datatype.Numeric[Type](nativeTypeId) { - - def isEquivalent(datatype: DataType) = datatype match { - case dt: ApproximateNumeric[_] => - (nativeTypeId == dt.nativeTypeId && - precisionRadix == dt.precisionRadix && - precision == dt.precision && - signed == dt.signed) - case _ => - false - } - - def isSubtypeOf (datatype:DataType) = datatype match { - case dt:ApproximateNumeric[_] => - (nativeTypeId == dt.nativeTypeId && - precisionRadix == dt.precisionRadix && - precision <= dt.precision && - signed == dt.signed) - case _ => - false - } - - /** A SQL-99 compliant string representation of the type. - * <h3>Compatibility notice</h3> This method assumes that a real - * uses 32 bits and a double 64. This is not defined in the - * standard but is usually the case. - */ - override def sqlString: java.lang.String = Tuple2(precisionRadix,precision) match { - case Tuple2(2,64) => "REAL" - case Tuple2(2,128) => "DOUBLE PRECISION" - case Tuple2(2,p) => - throw exception.UnsupportedFeature("SQL-99 does not support an approximate numeric type with a binary defined precision other than 16, 32 and 64 bits"); - case Tuple2(10,p) => "FLOAT (" + p.toString() + ")" - case Tuple2(pr,_) => - throw exception.UnsupportedFeature("SQL-99 does not support the precision of an approximate numeric type to be defined in a radix other than 2 or 10"); - } - -} diff --git a/src/dbc/scala/dbc/datatype/Boolean.scala b/src/dbc/scala/dbc/datatype/Boolean.scala deleted file mode 100644 index 4a32ce98f1..0000000000 --- a/src/dbc/scala/dbc/datatype/Boolean.scala +++ /dev/null @@ -1,31 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package datatype; - - -/** The SQL type for a truth value. */ -@deprecated(DbcIsDeprecated, "2.9.0") class Boolean extends DataType { - - def isEquivalent (datatype:DataType) = datatype match { - case dt:Boolean => true - case _ => false - } - - def isSubtypeOf (datatype:DataType) = isEquivalent(datatype); - - type NativeType = scala.Boolean; - val nativeTypeId = DataType.BOOLEAN; - - /** A SQL-99 compliant string representation of the type. */ - override def sqlString: java.lang.String = "BOOLEAN"; - -} diff --git a/src/dbc/scala/dbc/datatype/Character.scala b/src/dbc/scala/dbc/datatype/Character.scala deleted file mode 100644 index 02dec06281..0000000000 --- a/src/dbc/scala/dbc/datatype/Character.scala +++ /dev/null @@ -1,40 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package datatype; - - -/** A SQL type for a string of characters of arbitrary length with - * arbitrary character set. - */ -@deprecated(DbcIsDeprecated, "2.9.0") abstract class Character extends CharacterString { - - def isEquivalent(datatype: DataType) = datatype match { - case dt: Character => - length == dt.length && encoding == dt.encoding - case _ => - false - } - - def isSubtypeOf(datatype: DataType) = datatype match { - case dt: Character => - length >= dt.length && encoding == dt.encoding - case _ => - false - } - - /** The length of the string defined in characters. */ - def length: Int; - - /** A SQL-99 compliant string representation of the type. */ - override def sqlString: java.lang.String = "CHARACTER (" + length.toString() + ")"; - -} diff --git a/src/dbc/scala/dbc/datatype/CharacterLargeObject.scala b/src/dbc/scala/dbc/datatype/CharacterLargeObject.scala deleted file mode 100644 index 2c7ef64d66..0000000000 --- a/src/dbc/scala/dbc/datatype/CharacterLargeObject.scala +++ /dev/null @@ -1,31 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package datatype; - - -/** A SQL type for an unbounded length string of characters with arbitrary - * character set. */ -@deprecated(DbcIsDeprecated, "2.9.0") class CharacterLargeObject extends CharacterString { - - def isEquivalent (datatype:DataType) = datatype match { - case dt:CharacterLargeObject => { - encoding == dt.encoding - } - case _ => false - } - - def isSubtypeOf (datatype:DataType) = isEquivalent(datatype); - - /** A SQL-99 compliant string representation of the type. */ - override def sqlString: java.lang.String = "CHARACTER LARGE OBJECT"; - -} diff --git a/src/dbc/scala/dbc/datatype/CharacterString.scala b/src/dbc/scala/dbc/datatype/CharacterString.scala deleted file mode 100644 index 54d6e0111f..0000000000 --- a/src/dbc/scala/dbc/datatype/CharacterString.scala +++ /dev/null @@ -1,24 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package datatype; - - -/** A type category for all SQL types that store strings of characters. */ -@deprecated(DbcIsDeprecated, "2.9.0") abstract class CharacterString extends String { - - type NativeType = java.lang.String; - val nativeTypeId = DataType.STRING; - - /** The name of the character set in which the string is encoded. */ - def encoding: Option[java.lang.String] = None; - -} diff --git a/src/dbc/scala/dbc/datatype/CharacterVarying.scala b/src/dbc/scala/dbc/datatype/CharacterVarying.scala deleted file mode 100644 index 9df487579f..0000000000 --- a/src/dbc/scala/dbc/datatype/CharacterVarying.scala +++ /dev/null @@ -1,41 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package datatype; - - -/** A SQL type for a varying length string of characters with arbitrary - * maximal length and arbitrary character set. - */ -@deprecated(DbcIsDeprecated, "2.9.0") abstract class CharacterVarying extends CharacterString { - - def isEquivalent(datatype: DataType) = datatype match { - case dt: CharacterVarying => - length == dt.length && encoding == dt.encoding - case _ => - false - } - - def isSubtypeOf(datatype: DataType) = datatype match { - case dt: CharacterVarying => - length >= dt.length && encoding == dt.encoding - case _ => - false - } - - /** The maximal length of the string defined in characters. */ - def length: Int; - - /** A SQL-99 compliant string representation of the type. */ - override def sqlString: java.lang.String = - "CHARACTER VARYING (" + length.toString() + ")"; - -} diff --git a/src/dbc/scala/dbc/datatype/ExactNumeric.scala b/src/dbc/scala/dbc/datatype/ExactNumeric.scala deleted file mode 100644 index a578846977..0000000000 --- a/src/dbc/scala/dbc/datatype/ExactNumeric.scala +++ /dev/null @@ -1,65 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package datatype; - - -/** A type category for all SQL types that store constant-precision - * numbers. - */ -@deprecated(DbcIsDeprecated, "2.9.0") abstract class ExactNumeric[Type]( - override val nativeTypeId: DataType.Id -) extends datatype.Numeric[Type](nativeTypeId) { - - def isEquivalent(datatype: DataType) = datatype match { - case dt: ExactNumeric[_] => - (nativeTypeId == dt.nativeTypeId && - precisionRadix == dt.precisionRadix && - precision == dt.precision && - scale == dt.scale && - signed == dt.signed) - case _ => - false - } - - def isSubtypeOf(datatype: DataType) = datatype match { - case dt: ExactNumeric[_] => - (nativeTypeId == dt.nativeTypeId && - precisionRadix == dt.precisionRadix && - precision <= dt.precision && - scale <= dt.scale && - signed == dt.signed) - case _ => - false - } - - /** The number of digits used after the decimal point. */ - def scale: Int; - - /** A SQL-99 compliant string representation of the type. - * <h3>Compatibility notice</h3> This method assumes that an integer - * uses 32 bits, a small 16 and a big 64. This is not defined in the - * standard but is usually the case. - */ - override def sqlString: java.lang.String = Tuple3(precisionRadix,precision,scale) match { - case Tuple3(2,16,0) => "SMALLINT" - case Tuple3(2,32,0) => "INTEGER" - case Tuple3(2,64,0) => "BIGINT" - case Tuple3(2,java.lang.Integer.MAX_VALUE,0) => "BIGINT" - case Tuple3(2,p,s) => - throw exception.UnsupportedFeature("SQL-99 does not support an exact numeric type with a binary defined precision other than 16, 32 and 64 bits"); - case Tuple3(10,p,0) => "NUMERIC (" + p.toString() + ")" - case Tuple3(10,p,s) => "NUMERIC (" + p.toString() + ", " + s.toString() + ")" - case Tuple3(pr,_,_) => - throw exception.UnsupportedFeature("SQL-99 does not support the precision of an exact numeric type to be defined in a radix other than 2 or 10"); - } - -} diff --git a/src/dbc/scala/dbc/datatype/Factory.scala b/src/dbc/scala/dbc/datatype/Factory.scala deleted file mode 100644 index bb9b3f5b61..0000000000 --- a/src/dbc/scala/dbc/datatype/Factory.scala +++ /dev/null @@ -1,250 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package datatype; - - -import java.sql.Types._; -import java.math.BigInteger; -import java.math.BigDecimal; - -@deprecated(DbcIsDeprecated, "2.9.0") object Factory { - - final val java_lang_Integer_SIZE = 32; - final val java_lang_Long_SIZE = 64; - - /** Returns a nullable property formatted as a boolean option */ - def isNullable (metadata:java.sql.ResultSetMetaData, index:Int): Option[scala.Boolean] = - metadata.isNullable(index) match { - case java.sql.ResultSetMetaData.columnNoNulls => Some(false); - case java.sql.ResultSetMetaData.columnNullable => Some(true); - case java.sql.ResultSetMetaData.columnNullableUnknown => None; - } - - /** Returns the binary precision for an integer field. This should only be - * used to find precision for integer numbers. It assumes that - * bytes cannot be used partially (result % 8 = 0). */ - def bytePrecision (precision:Int, signed:scala.Boolean, safe:scala.Boolean): Int = { - val decimalPrecision = precision + (if (safe) 1 else 0); - Pair(signed,decimalPrecision) match { - case Pair(_,0) => java.lang.Integer.MAX_VALUE // That's a bit of a hack. - case Pair(_,dp) if (dp <= 3) => 8 - case Pair(_,dp) if (dp <= 5) => 16 - case Pair(true,dp) if (dp <= 7) => 24 - case Pair(false,dp) if (dp <= 8) => 24 - case Pair(_,dp) if (dp <= 10) => 32 - case Pair(true,dp) if (dp <= 12) => 40 - case Pair(false,dp) if (dp <= 13) => 40 - case Pair(_,dp) if (dp <= 15) => 48 - case Pair(_,dp) if (dp <= 17) => 56 - case Pair(true,dp) if (dp <= 19) => 64 - case Pair(false,dp) if (dp <= 20) => 64 - case Pair(_,dp) if (dp <= 22) => 72 - case Pair(true,dp) if (dp <= 24) => 80 - case Pair(false,dp) if (dp <= 25) => 80 - case Pair(_,dp) if (dp <= 27) => 88 - case Pair(_,dp) if (dp <= 29) => 96 - case Pair(_,dp) if (dp <= 32) => 104 - case Pair(_,dp) if (dp <= 34) => 112 - case Pair(true,dp) if (dp <= 36) => 120 - case Pair(false,dp) if (dp <= 37) => 120 - case Pair(_,dp) if (dp <= 39) => 128 - case _ => java.lang.Integer.MAX_VALUE - } - } - - def create (metadata:java.sql.ResultSetMetaData, index:Int): DataType = { - metadata.getColumnType(index) match { - /* Boolean data types. */ - case BOOLEAN => new datatype.Boolean { - override val nullable = isNullable(metadata,index); - } - case BIT => new datatype.Boolean { - override val nullable = isNullable(metadata,index); - } - /* Fixed precision numeric data types. */ - case DECIMAL => { - Pair(bytePrecision(metadata.getPrecision(index),metadata.isSigned(index),true),metadata.getScale(index) == 0) match { - case Pair(bp,true) if (bp <= java_lang_Integer_SIZE) => - new datatype.ExactNumeric[Int](DataType.INT) { - override val nullable = isNullable(metadata,index); - val precisionRadix = 10; - val precision = metadata.getPrecision(index); - val signed = metadata.isSigned(index); - val scale = metadata.getScale(index); - } - case Pair(bp,true) if (bp <= java_lang_Long_SIZE) => - new datatype.ExactNumeric[Long](DataType.LONG) { - override val nullable = isNullable(metadata,index); - val precisionRadix = 10; - val precision = metadata.getPrecision(index); - val signed = metadata.isSigned(index); - val scale = metadata.getScale(index); - } - case Pair(_,true) => - new datatype.ExactNumeric[BigInteger](DataType.BIG_INTEGER) { - override val nullable = isNullable(metadata,index); - val precisionRadix = 10; - val precision = metadata.getPrecision(index); - val signed = metadata.isSigned(index); - val scale = metadata.getScale(index); - } - case Pair(_,false) => - new datatype.ExactNumeric[BigDecimal](DataType.BIG_DECIMAL) { - override val nullable = isNullable(metadata,index); - val precisionRadix = 10; - val precision = metadata.getPrecision(index); - val signed = metadata.isSigned(index); - val scale = metadata.getScale(index); - } - } - } - case NUMERIC => { - Pair(bytePrecision(metadata.getPrecision(index),metadata.isSigned(index),true),metadata.getScale(index) == 0) match { - case Pair(bp,true) if (bp <= java_lang_Integer_SIZE) => - new datatype.ExactNumeric[Int](DataType.INT) { - override val nullable = isNullable(metadata,index); - val precisionRadix = 10; - val precision = metadata.getPrecision(index); - val signed = metadata.isSigned(index); - val scale = metadata.getScale(index); - } - case Pair(bp,true) if (bp <= java_lang_Long_SIZE) => - new datatype.ExactNumeric[Long](DataType.LONG) { - override val nullable = isNullable(metadata,index); - val precisionRadix = 10; - val precision = metadata.getPrecision(index); - val signed = metadata.isSigned(index); - val scale = metadata.getScale(index); - } - case Pair(_,true) => - new datatype.ExactNumeric[BigInteger](DataType.BIG_INTEGER) { - override val nullable = isNullable(metadata,index); - val precisionRadix = 10; - val precision = metadata.getPrecision(index); - val signed = metadata.isSigned(index); - val scale = metadata.getScale(index); - } - case Pair(_,false) => - new datatype.ExactNumeric[BigDecimal](DataType.BIG_DECIMAL) { - override val nullable = isNullable(metadata,index); - val precisionRadix = 10; - val precision = metadata.getPrecision(index); - val signed = metadata.isSigned(index); - val scale = metadata.getScale(index); - } - } - } - /* Fixed precision integer data types. */ - case BIGINT => - new datatype.ExactNumeric[Long](DataType.LONG) { - override val nullable = isNullable(metadata,index); - val precisionRadix = 2; - val precision = 64; - val signed = metadata.isSigned(index); - val scale = 0; - } - case INTEGER => - new datatype.ExactNumeric[Int](DataType.INT) { - override val nullable = isNullable(metadata,index); - val precisionRadix = 2; - val precision = 32; - val signed = metadata.isSigned(index); - val scale = 0; - } - case SMALLINT => - new datatype.ExactNumeric[Short](DataType.SHORT) { - override val nullable = isNullable(metadata,index); - val precisionRadix = 2; - val precision = 16; - val signed = metadata.isSigned(index); - val scale = 0; - } - case TINYINT => - new datatype.ExactNumeric[Byte](DataType.BYTE) { - override val nullable = isNullable(metadata,index); - val precisionRadix = 2; - val precision = 8; - val signed = metadata.isSigned(index); - val scale = 0; - } - /* Floating point numeric data types. */ - case REAL => - new datatype.ApproximateNumeric[Float](DataType.FLOAT) { - override val nullable = isNullable(metadata,index); - val precisionRadix = 2; - val precision = 64; - val signed = metadata.isSigned(index); - } - case DOUBLE => - new datatype.ApproximateNumeric[Double](DataType.DOUBLE) { - override val nullable = isNullable(metadata,index); - val precisionRadix = 2; - val precision = 128; - val signed = metadata.isSigned(index); - } - case FLOAT => - new datatype.ApproximateNumeric[Double](DataType.DOUBLE) { - override val nullable = isNullable(metadata,index); - val precisionRadix = 2; - val precision = 128; - val signed = metadata.isSigned(index); - } - /* Character string data types. */ - case CHAR => new datatype.Character { - override val nullable = isNullable(metadata,index); - val length = metadata.getColumnDisplaySize(index); - } - case CLOB => new datatype.CharacterLargeObject { - override val nullable = isNullable(metadata,index); - } - case LONGVARCHAR => { - if (metadata.getColumnDisplaySize(index) >= 0) - new datatype.CharacterVarying { - override val nullable = isNullable(metadata,index); - def length = metadata.getColumnDisplaySize(index); - } - else // A PostgreSQL Hack - new datatype.CharacterLargeObject { - override val nullable = isNullable(metadata,index); - } - } - case VARCHAR => { - if (metadata.getColumnDisplaySize(index) >= 0) - new datatype.CharacterVarying { - override val nullable = isNullable(metadata,index); - def length = metadata.getColumnDisplaySize(index); - } - else // A PostgreSQL Hack - new datatype.CharacterLargeObject { - override val nullable = isNullable(metadata,index); - } - } - /* Undefined cases. */ - case OTHER => new datatype.Unknown { - override val nullable = isNullable(metadata, index); - } - /* Unsupported data types. */ - case REF | ARRAY | STRUCT => - sys.error ("I don't support composite data types yet."); - case DATALINK | DISTINCT | JAVA_OBJECT | NULL => - sys.error ("I won't support strange data types."); - /* Unsupported binary string data types. */ - case BINARY | BLOB | LONGVARBINARY | VARBINARY => - sys.error ("I don't support binary string data types yet."); - /* Unsupported date and time data types. */ - case DATE | TIME | TIMESTAMP => - sys.error ("I don't support date and time data types yet."); - /* Default case */ - case x => sys.error ("I don't know about this ("+metadata.getColumnTypeName(index)+") JDBC type.") - } - } -} diff --git a/src/dbc/scala/dbc/datatype/Numeric.scala b/src/dbc/scala/dbc/datatype/Numeric.scala deleted file mode 100644 index c13f454dde..0000000000 --- a/src/dbc/scala/dbc/datatype/Numeric.scala +++ /dev/null @@ -1,32 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package datatype; - - -/** A type category for all SQL types that store numbers. */ -@deprecated(DbcIsDeprecated, "2.9.0") abstract class Numeric[Type](_nativeTypeId: DataType.Id) extends DataType { - - type NativeType = Type; - val nativeTypeId = _nativeTypeId; - - /** The radix in which the precision (and scale when appliable) is defined. - * ISO-9075 only allows 2 and 10 for this value. - */ - def precisionRadix: Int; - - /** The number of significant digits for that number. */ - def precision: Int; - - /** Whether the number is signed or not. */ - def signed: scala.Boolean; - -} diff --git a/src/dbc/scala/dbc/datatype/String.scala b/src/dbc/scala/dbc/datatype/String.scala deleted file mode 100644 index 291504f777..0000000000 --- a/src/dbc/scala/dbc/datatype/String.scala +++ /dev/null @@ -1,24 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package datatype; - - -/** A type category for all SQL types that store strings of elements. - */ -@deprecated(DbcIsDeprecated, "2.9.0") abstract class String extends DataType { - - /** The maximal possible length of the string defined in characters. - * This is an implementation-specific value. - */ - def maxLength: Option[Int] = None; - -} diff --git a/src/dbc/scala/dbc/datatype/Unknown.scala b/src/dbc/scala/dbc/datatype/Unknown.scala deleted file mode 100644 index 14a33c6be9..0000000000 --- a/src/dbc/scala/dbc/datatype/Unknown.scala +++ /dev/null @@ -1,34 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package datatype; - - -/** The SQL type for a truth value. */ -@deprecated(DbcIsDeprecated, "2.9.0") class Unknown extends DataType { - - def isEquivalent(datatype: DataType) = datatype match { - case dt: Unknown => - nativeTypeId == dt.nativeTypeId - case _ => - false - } - - def isSubtypeOf(datatype: DataType) = true; - - type NativeType = AnyRef; - val nativeTypeId = DataType.OBJECT; - - /** A SQL-99 compliant string representation of the type. */ - override def sqlString: java.lang.String = - sys.error("The 'UNKNOWN' data type cannot be represented."); - -} diff --git a/src/dbc/scala/dbc/exception/IncompatibleSchema.scala b/src/dbc/scala/dbc/exception/IncompatibleSchema.scala deleted file mode 100644 index c8d53bbf1a..0000000000 --- a/src/dbc/scala/dbc/exception/IncompatibleSchema.scala +++ /dev/null @@ -1,19 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package exception - - -/** A type category for all SQL types that store constant-precision numbers. */ -@deprecated(DbcIsDeprecated, "2.9.0") case class IncompatibleSchema ( - expectedSchema: List[DataType], - foundSchema: List[DataType] -) extends Exception; diff --git a/src/dbc/scala/dbc/exception/UnsupportedFeature.scala b/src/dbc/scala/dbc/exception/UnsupportedFeature.scala deleted file mode 100644 index dd6f904077..0000000000 --- a/src/dbc/scala/dbc/exception/UnsupportedFeature.scala +++ /dev/null @@ -1,16 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package exception - - -/** A type category for all SQL types that store constant-precision numbers. */ -@deprecated(DbcIsDeprecated, "2.9.0") case class UnsupportedFeature (msg: String) extends Exception; diff --git a/src/dbc/scala/dbc/package.scala b/src/dbc/scala/dbc/package.scala deleted file mode 100644 index b1552e11d3..0000000000 --- a/src/dbc/scala/dbc/package.scala +++ /dev/null @@ -1,6 +0,0 @@ -package scala - -package object dbc { - final val DbcIsDeprecated = - "scala.dbc will be removed after version 2.9. Use an active sql library such as scalaquery instead." -}
\ No newline at end of file diff --git a/src/dbc/scala/dbc/result/Field.scala b/src/dbc/scala/dbc/result/Field.scala deleted file mode 100644 index cd3309bb14..0000000000 --- a/src/dbc/scala/dbc/result/Field.scala +++ /dev/null @@ -1,63 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package result - - -import scala.dbc.datatype._ -import scala.dbc.value._ - -/** An ISO-9075:2003 (SQL) table field. */ -@deprecated(DbcIsDeprecated, "2.9.0") abstract class Field { - - /** The content (value) of the field. The type of this value is undefined, - * transformation into a useful type will be done by an automatic view - * function defined in the field object. - */ - def content: Value - - final def value[Type <: Value]: Type = - content.asInstanceOf[Type] - - final def exactNumericValue[NativeType] = - content.asInstanceOf[dbc.value.ExactNumeric[NativeType]] - - final def approximateNumericValue[NativeType] = - content.asInstanceOf[dbc.value.ApproximateNumeric[NativeType]] - - final def booleanValue = - content.asInstanceOf[dbc.value.Boolean] - - final def characterValue = - content.asInstanceOf[dbc.value.Character] - - final def characterLargeObjectValue = - content.asInstanceOf[dbc.value.CharacterLargeObject] - - final def characterVaryingValue = - content.asInstanceOf[dbc.value.CharacterVarying] - - final def unknownValue = - content.asInstanceOf[dbc.value.Unknown] - - /** The tuple that contains this field. */ - def originatingTuple: Tuple - - /** The field metadata attached to this field. */ - def metadata: FieldMetadata - -} - -@deprecated(DbcIsDeprecated, "2.9.0") object Field { - - implicit def fieldToValue (field: Field): Value = field.content - -} diff --git a/src/dbc/scala/dbc/result/FieldMetadata.scala b/src/dbc/scala/dbc/result/FieldMetadata.scala deleted file mode 100644 index 3c2de297d0..0000000000 --- a/src/dbc/scala/dbc/result/FieldMetadata.scala +++ /dev/null @@ -1,40 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package result - - -/** The class <code>FieldMetadata</cocde> provides informations attached to - * a field about its content and its relationship to the originating database. - */ -@deprecated(DbcIsDeprecated, "2.9.0") abstract class FieldMetadata { - - /** The name of the field. */ - def name: String - - /** The index of the field in the tuple. */ - def index: Int - - /** The expected type of the field. This information is used for automatic - * transformation of the field value into a usable type. - */ - def datatype: DataType - - /** The name of the catalog in the database from which the field originates */ - def catalog: String - - /** The name of the schema in the database from which the field originates */ - def schema: String - - /** The name of the table in the database from which the field originates */ - def table: String - -} diff --git a/src/dbc/scala/dbc/result/Relation.scala b/src/dbc/scala/dbc/result/Relation.scala deleted file mode 100644 index 98d653d61e..0000000000 --- a/src/dbc/scala/dbc/result/Relation.scala +++ /dev/null @@ -1,84 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package result - - -/** An ISO-9075:2003 (SQL) table. This is equivalent to a relation in the - * relational model. */ -@deprecated(DbcIsDeprecated, "2.9.0") abstract class Relation -extends collection.AbstractIterable[Tuple] - with Iterable[Tuple] { - - /** The statement that generated this relation. */ - def statement: scala.dbc.statement.Relation - - /** A JDBC result containing this relation. */ - protected def sqlResult: java.sql.ResultSet - - /** A JDBC metadata object attached to the relation. */ - protected def sqlMetadata: java.sql.ResultSetMetaData = sqlResult.getMetaData() - - /** Metadata about all fields in a tuple of the relation. */ - def metadata: List[FieldMetadata] = - for (count <- List.range(1, sqlMetadata.getColumnCount()+1)) yield - new FieldMetadata { - val name: String = sqlMetadata.getColumnName(count) - val index: Int = count - val datatype: DataType = dbc.datatype.Factory.create(sqlMetadata,count) - val catalog: String = sqlMetadata.getCatalogName(count) - val schema: String = sqlMetadata.getSchemaName(count) - val table: String = sqlMetadata.getTableName(count) - } - - /** Metadata about the field at the given index. If there is no such - * field <code>None</code> is returned instead. */ - def metadataFor (index:Int): Option[FieldMetadata] = { - val meta = metadata - if (meta.length > index) - Some(meta(index)) - else - None - } - - /** Metadata about the field with the given column name. If there is no - * such field, <code>None</code> is returned instead. */ - def metadataFor (name:String): Option[FieldMetadata] = - metadata.find(f=>(f.name==name)); - - /** An iterator on the tuples of the relation. - * <h3>Caution</h3> A Relation only has one single iterator, due to limitations - * in DBMS. This means that if this method is called multiple times, all returned - * iterators will share the same state. */ - def iterator: Iterator[Tuple] = new collection.AbstractIterator[Tuple] { - protected val result: java.sql.ResultSet = Relation.this.sqlResult - def hasNext: Boolean = resultNext - private var resultNext = result.next() - def next: Tuple = { - if (resultNext) { - val newTuple = new Tuple { - val me = this - val originatingRelation = Relation.this - val fields: List[Field] = for (fieldMetadata <- metadata) yield - new Field { - val metadata = fieldMetadata - val content = dbc.value.Factory.create(result,metadata.index,metadata.datatype) - val originatingTuple = me - } - } - resultNext = result.next() - newTuple - } - else sys.error("next on empty iterator") - } - } - -} diff --git a/src/dbc/scala/dbc/result/Status.scala b/src/dbc/scala/dbc/result/Status.scala deleted file mode 100644 index d3152a58ab..0000000000 --- a/src/dbc/scala/dbc/result/Status.scala +++ /dev/null @@ -1,28 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package result; - - -import scala.dbc.datatype._; - -/** An object containing the status of a query */ -@deprecated(DbcIsDeprecated, "2.9.0") abstract class Status[ResultType] { - - /** The statement that generated this status result. */ - def statement: scala.dbc.statement.Statement; - - /** The number of elements modified or added by this statement. */ - def touchedCount: Option[Int]; - - def result: ResultType; - -} diff --git a/src/dbc/scala/dbc/result/Tuple.scala b/src/dbc/scala/dbc/result/Tuple.scala deleted file mode 100644 index 80ab5c22aa..0000000000 --- a/src/dbc/scala/dbc/result/Tuple.scala +++ /dev/null @@ -1,42 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package result; - - -/** An ISO-9075:2003 (SQL) table row. This is equivalent to a tuple in the relational model. */ -@deprecated(DbcIsDeprecated, "2.9.0") abstract class Tuple { - - /** All the fields contained in the tuple. */ - def fields: List[Field]; - - /** The relation that contains the tuple. */ - def originatingRelation: Relation; - - /** The field at the given index. If there is no such field (that is the index is out of bounds), <code>None</code> is returned instead. */ - def apply (index:Int): Field = - try { - fields(index) - } catch { - case e => - throw new java.lang.IndexOutOfBoundsException("Field at index "+index+" does not exist in relation"); - } - - /** The field with the given column name. If there is no such field, <code>None</code> is returned instead. */ - def apply (name:String): Field = { - def findField (fields: List[Field], name:String): Field = fields match { - case Nil => throw new java.lang.IndexOutOfBoundsException("Field '"+name+"' does not exist in relation") - case field :: _ if (field.metadata.name == name) => field - case field :: fields => findField (fields, name) - } - findField (fields, name); - } -} diff --git a/src/dbc/scala/dbc/statement/AccessMode.scala b/src/dbc/scala/dbc/statement/AccessMode.scala deleted file mode 100644 index 885e0012f2..0000000000 --- a/src/dbc/scala/dbc/statement/AccessMode.scala +++ /dev/null @@ -1,26 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package statement - - -@deprecated(DbcIsDeprecated, "2.9.0") abstract class AccessMode { - def sqlString: String -} - -@deprecated(DbcIsDeprecated, "2.9.0") object AccessMode { - case object ReadOnly extends AccessMode { - def sqlString = "READ ONLY" - } - case object ReadWrite extends AccessMode { - def sqlString = "READ WRITE" - } -} diff --git a/src/dbc/scala/dbc/statement/DerivedColumn.scala b/src/dbc/scala/dbc/statement/DerivedColumn.scala deleted file mode 100644 index ae05df986a..0000000000 --- a/src/dbc/scala/dbc/statement/DerivedColumn.scala +++ /dev/null @@ -1,38 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package statement - - -@deprecated(DbcIsDeprecated, "2.9.0") abstract class DerivedColumn { - - /** The value for the column. This value can be of any type but must be - * calculated from fields that appear in a relation that takes part - * in the query. - */ - def valueExpression: Expression - - /** A new name for this field. This name must be unique for the query in - * which the column takes part. - */ - def asClause: Option[String] - - /** A SQL-99 compliant string representation of the derived column - * sub-statement. This only has a meaning inside a select statement. - */ - def sqlString: String = - valueExpression.sqlInnerString + - (asClause match { - case None => "" - case Some(ac) => " AS " + ac - }) - -} diff --git a/src/dbc/scala/dbc/statement/Expression.scala b/src/dbc/scala/dbc/statement/Expression.scala deleted file mode 100644 index c2da91e9ef..0000000000 --- a/src/dbc/scala/dbc/statement/Expression.scala +++ /dev/null @@ -1,28 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package statement - - -/** An expression that calculates some value from fields. */ -@deprecated(DbcIsDeprecated, "2.9.0") abstract class Expression extends Relation { - - def fieldTypes: List[DataType] = Nil - - /** A SQL-99 compliant string representation of the expression. */ - def sqlString: String = "SELECT " + sqlInnerString - - /** A SQL-99 compliant string representation of the relation sub- - * statement. This only has a meaning inside another statement. - */ - def sqlInnerString: String - -} diff --git a/src/dbc/scala/dbc/statement/Insert.scala b/src/dbc/scala/dbc/statement/Insert.scala deleted file mode 100644 index 189ccec54f..0000000000 --- a/src/dbc/scala/dbc/statement/Insert.scala +++ /dev/null @@ -1,31 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package statement - - -import scala.dbc.statement.expression._ - -/** An insertion of values into a table. */ -@deprecated(DbcIsDeprecated, "2.9.0") case class Insert(insertionTarget: String, insertionData: InsertionData) - extends Status { - - /** A SQL-99 compliant string representation of the select statement. */ - def sqlString: String = - "INSERT INTO " + insertionTarget + " " + insertionData.sqlString - - /** The name of the table where the data should be added. */ - //def insertionTarget: String - - /** The data that will be added tot he table. */ - //def insertionData: InsertionData - -} diff --git a/src/dbc/scala/dbc/statement/InsertionData.scala b/src/dbc/scala/dbc/statement/InsertionData.scala deleted file mode 100644 index e91ad7efe6..0000000000 --- a/src/dbc/scala/dbc/statement/InsertionData.scala +++ /dev/null @@ -1,40 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package statement - - -import scala.dbc.statement.expression._ - -/** Data to be inserted into a table in an <code>Insert</code>. */ -@deprecated(DbcIsDeprecated, "2.9.0") abstract class InsertionData { - def sqlString: String -} - -@deprecated(DbcIsDeprecated, "2.9.0") object InsertionData { - /** Insertion of data resulting from a query on the database. */ - @deprecated(DbcIsDeprecated, "2.9.0") case class Subquery(query: Relation) extends InsertionData { - def sqlString = query.sqlString - } - /** Insertion of data as explicitly defined values. */ - @deprecated(DbcIsDeprecated, "2.9.0") case class Constructor( - columnNames: Option[List[String]], - columnValues: List[Expression] - ) extends InsertionData { - def sqlString = - (columnNames match { - case None => "" - case Some(cn) => cn.mkString(" (",", ",")") - }) + - " VALUES" + - columnValues.map(e => e.sqlInnerString).mkString(" (",", ",")") - } -} diff --git a/src/dbc/scala/dbc/statement/IsolationLevel.scala b/src/dbc/scala/dbc/statement/IsolationLevel.scala deleted file mode 100644 index b31614c3dd..0000000000 --- a/src/dbc/scala/dbc/statement/IsolationLevel.scala +++ /dev/null @@ -1,32 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package statement - - -@deprecated(DbcIsDeprecated, "2.9.0") abstract class IsolationLevel { - def sqlString: String -} - -@deprecated(DbcIsDeprecated, "2.9.0") object IsolationLevel { - case object ReadUncommitted extends IsolationLevel { - def sqlString = "ISOLATION LEVEL READ UNCOMMITTED" - } - case object ReadCommitted extends IsolationLevel { - def sqlString = "ISOLATION LEVEL READ COMMITTED" - } - case object RepeatableRead extends IsolationLevel { - def sqlString = "ISOLATION LEVEL REPEATABLE READ" - } - case object Serializable extends IsolationLevel { - def sqlString = "ISOLATION LEVEL SERIALIZABLE" - } -} diff --git a/src/dbc/scala/dbc/statement/JoinType.scala b/src/dbc/scala/dbc/statement/JoinType.scala deleted file mode 100644 index 698612b10d..0000000000 --- a/src/dbc/scala/dbc/statement/JoinType.scala +++ /dev/null @@ -1,56 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package statement - - -/** A join behaviour in a <code>Jointure</code>. */ -@deprecated(DbcIsDeprecated, "2.9.0") abstract class JoinType { - /** A SQL-99 string representation of the join behaviour. */ - def sqlString: String -} - -@deprecated(DbcIsDeprecated, "2.9.0") object JoinType { - - /** A join behaviour where a joined tuple is created only when a - * corresponding tuple exists in both original relations. - */ - case object Inner extends JoinType { - val sqlString = "INNER JOIN" - } - - /** A join behaviour family where a joined tuple is created even when a - * tuple has no corresponding tuple in the other relation. The fields - * populated by values of the other tuple will receive the NULL value. - */ - abstract class Outer extends JoinType - - object Outer { - /** An outer join behaviour where there will be at least on tuple for - * every tuple in the left relation. - */ - case object Left extends Outer { - val sqlString = "LEFT OUTER JOIN" - } - /** An outer join behaviour where there will be at least on tuple for - * every tuple in the right relation. - */ - case object Right extends Outer { - val sqlString = "RIGHT OUTER JOIN" - } - /** An outer join behaviour where there will be at least on tuple for - * every tuple in both right and left relations. - */ - case object Full extends Outer { - val sqlString = "FULL OUTER JOIN" - } - } -} diff --git a/src/dbc/scala/dbc/statement/Jointure.scala b/src/dbc/scala/dbc/statement/Jointure.scala deleted file mode 100644 index 74c871cc3e..0000000000 --- a/src/dbc/scala/dbc/statement/Jointure.scala +++ /dev/null @@ -1,45 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package statement - - -/** A jointure between two relations. */ -@deprecated(DbcIsDeprecated, "2.9.0") abstract class Jointure extends Relation { - - /** The relation on the left part of the join. */ - def leftRelation: Relation - - /** The relation on the right part of the join. */ - def rightRelation: Relation - - /** The type of the jointure. */ - def joinType: JoinType - - /** The condition on which the jointure needs be done. */ - def joinCondition: Option[Expression] - - /** A SQL-99 compliant string representation of the relation statement. */ - def sqlString: String = "SELECT * FROM " + sqlInnerString - - /** A SQL-99 compliant string representation of the relation sub- - * statement. This only has a meaning inside a query. - */ - def sqlInnerString: String = - leftRelation.sqlInnerString + " " + - joinType.sqlString + " " + - rightRelation.sqlInnerString + - (joinCondition match { - case Some(jc) => jc.sqlString - case None => "" - }) - -} diff --git a/src/dbc/scala/dbc/statement/Relation.scala b/src/dbc/scala/dbc/statement/Relation.scala deleted file mode 100644 index 787707ee82..0000000000 --- a/src/dbc/scala/dbc/statement/Relation.scala +++ /dev/null @@ -1,55 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package statement; - - -/** A statement that returns a relation. */ -@deprecated(DbcIsDeprecated, "2.9.0") abstract class Relation extends Statement { - - def isCompatibleType: (DataType,DataType)=>Boolean = - ((dt,wdt)=>dt.isSubtypeOf(wdt)); - - def typeCheck (relation: result.Relation): Unit = { - val sameType: Boolean = ( - relation.metadata.length == fieldTypes.length && - (relation.metadata.zip(fieldTypes).forall({case Pair(field,expectedType) => - isCompatibleType(field.datatype, expectedType)})) - ); - if (!sameType) - throw new exception.IncompatibleSchema(fieldTypes,relation.metadata.map(field=>field.datatype)); - } - - def fieldTypes: List[DataType]; - - def sqlTypeString: String = - if (fieldTypes.isEmpty) - "UNTYPED" - else - fieldTypes.map(dt=>dt.sqlString).mkString("RELATION (",", ",")"); - - /** A SQL-99 compliant string representation of the statement. */ - def sqlString: String; - - /** A SQL-99 compliant string representation of the relation sub- - * statement. This only has a meaning inside another statement. */ - def sqlInnerString: String; - - /** Executes the statement on the given database. */ - def execute (database: scala.dbc.Database): scala.dbc.result.Relation = { - database.executeStatement(this); - } - - def execute (database:scala.dbc.Database, debug:Boolean): scala.dbc.result.Relation = { - database.executeStatement(this,debug); - } - -} diff --git a/src/dbc/scala/dbc/statement/Select.scala b/src/dbc/scala/dbc/statement/Select.scala deleted file mode 100644 index a9ca0212ed..0000000000 --- a/src/dbc/scala/dbc/statement/Select.scala +++ /dev/null @@ -1,99 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package statement - - -/** A statement that when executed on a database will return a relation. - * The returned relation will be a subset of a table in the database or - * a jointure between such subsets. */ -@deprecated(DbcIsDeprecated, "2.9.0") abstract class Select extends Relation { - - /** Defines if duplicated tuples should be removed from the returned - * relation. <h3>Compatibility notice</h3> Some DBMS (PostgreSQL) allow - * uniqueness constrains on an arbitrary field instead of the entire - * tuple. */ - def setQuantifier: Option[SetQuantifier] - - /** Defines the output fields that a tuple in the returned relation will - * contain, and their content with respect to the tables in the - * database. If the fields are not specified (that is the list is - * empty), all possible input fields will be returned. <h3>Compatibility - * notice</h3> SQL's qualified asterisk select sublist is not - * available. */ - def selectList: List[DerivedColumn] - - /** Defines the relations from which the query will obtain its data.*/ - def fromClause: List[Relation] - - /** Defines condition that must be true in the returned relation's tuples. - * This value expression must return a boolean or boolean-compatible - * value. This condition is applied before any GROUP BY clause. - */ - def whereClause: Option[Expression] - - /** Defines the grouping of the returned relation's tuples. One tuple is - * returned for every group. The value of <code>selectList</code> must - * use aggregate functions for calculation. - */ - def groupByClause: Option[List[Expression]] - - /** Defines conditions that must be true in the returned relation's tuples. - * The value expression must return a boolean can only refer to fields - * that are grouped or to any field from inside an aggregate function. - */ - def havingClause: Option[Expression] - - /* def windowClause: Option[_]; */ - - /** A SQL-99 compliant string representation of the select statement. */ - def sqlString: String = ( - "SELECT" + - (setQuantifier match { - case None => "" - case Some(sq) => " " + sq.sqlString - }) + - (selectList match { - case Nil => " *" - case _ => (" " + selectList.tail.foldLeft(selectList.head.sqlString) - ((name:String, dc:DerivedColumn) => name + ", " + dc.sqlString)) - }) + - (fromClause match { - case Nil => sys.error("Empty from clause is not allowed") - case _ => (" FROM " + fromClause.tail.foldLeft(fromClause.head.sqlInnerString) - ((name:String, rel:Relation) => name + ", " + rel.sqlInnerString)) - }) + - (whereClause match { - case None => "" - case Some(expr) => " WHERE " + expr.sqlInnerString - }) + - (groupByClause match { - case None => "" - case Some(gbl) => gbl match { - case Nil => sys.error("Empty group by clause is not allowed") - case _ => - (" GROUP BY " + - gbl.tail.foldLeft(gbl.head.sqlInnerString) - ((name:String, gb) => name + ", " + gb.sqlInnerString)) - } - }) + - (havingClause match { - case None => "" - case Some(expr) => " HAVING " + expr.sqlString - }) - ); - - /** A SQL-99 compliant string representation of the relation sub- - * statement. This only has a meaning inside a query. - */ - def sqlInnerString: String = "("+sqlString+")" - -} diff --git a/src/dbc/scala/dbc/statement/SetClause.scala b/src/dbc/scala/dbc/statement/SetClause.scala deleted file mode 100644 index 3af509c026..0000000000 --- a/src/dbc/scala/dbc/statement/SetClause.scala +++ /dev/null @@ -1,21 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package statement - - -import scala.dbc.statement.expression._ - -/** Data to be inserted into a table in an <code>Insert</code>. */ -@deprecated(DbcIsDeprecated, "2.9.0") case class SetClause(name: String, expr: Expression) { - val value: Pair[String,Expression] = (name, expr) - def sqlString: String = value._1 + " = " + value._2.sqlInnerString -} diff --git a/src/dbc/scala/dbc/statement/SetQuantifier.scala b/src/dbc/scala/dbc/statement/SetQuantifier.scala deleted file mode 100644 index 77a4b79b8d..0000000000 --- a/src/dbc/scala/dbc/statement/SetQuantifier.scala +++ /dev/null @@ -1,38 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package statement - - -/** A set quantifier that defines the collection type of a relation. */ -@deprecated(DbcIsDeprecated, "2.9.0") abstract class SetQuantifier { - /** A SQL-99 compliant string representation of the set quantifier. */ - def sqlString: String -} - -@deprecated(DbcIsDeprecated, "2.9.0") object SetQuantifier { - - /** A set quantifier that defines a relation as being a bag. That means - * that duplicates are allowed. - */ - case object AllTuples extends SetQuantifier { - /** A SQL-99 compliant string representation of the set quantifier. */ - def sqlString: String = "ALL" - } - - /** A set quantifier that defines a relation as being a set. That means - * that duplicates are not allowed and will be pruned. - */ - case object DistinctTuples extends SetQuantifier { - /** A SQL-99 compliant string representation of the set quantifier. */ - def sqlString: String = "DISTINCT" - } -} diff --git a/src/dbc/scala/dbc/statement/Statement.scala b/src/dbc/scala/dbc/statement/Statement.scala deleted file mode 100644 index fc5374262d..0000000000 --- a/src/dbc/scala/dbc/statement/Statement.scala +++ /dev/null @@ -1,16 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package statement - - -/** An ISO-9075:2003 (SQL) statement. */ -@deprecated(DbcIsDeprecated, "2.9.0") abstract class Statement diff --git a/src/dbc/scala/dbc/statement/Status.scala b/src/dbc/scala/dbc/statement/Status.scala deleted file mode 100644 index 0ce64b978d..0000000000 --- a/src/dbc/scala/dbc/statement/Status.scala +++ /dev/null @@ -1,32 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package statement - -import scala.dbc.Database -import scala.dbc.result - -/** A statement that changes the status of the database. */ -@deprecated(DbcIsDeprecated, "2.9.0") abstract class Status extends Statement { - - /** A SQL-99 compliant string representation of the statement. */ - def sqlString: String - - /** Executes the statement on the given database. */ - def execute(database: Database): result.Status[Unit] = { - database.executeStatement(this) - } - - def execute(database: Database, debug: Boolean): result.Status[Unit] = { - database.executeStatement(this, debug) - } - -} diff --git a/src/dbc/scala/dbc/statement/Table.scala b/src/dbc/scala/dbc/statement/Table.scala deleted file mode 100644 index e729f801a3..0000000000 --- a/src/dbc/scala/dbc/statement/Table.scala +++ /dev/null @@ -1,38 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package statement - - -/** A reference to a table in the database. - * @author Gilles Dubochet - * @version 1.0 */ -@deprecated(DbcIsDeprecated, "2.9.0") abstract class Table extends Relation { - - /** The name of the table in the database. */ - def tableName: String - - /** The name that the table will be called in the enclosing statement. */ - def tableRename: Option[String] - - /** A SQL-99 compliant string representation of the relation statement. */ - def sqlString: String = "SELECT * FROM " + tableName - - /** A SQL-99 compliant string representation of the relation sub- - * statement. This only has a meaning inside a query. */ - def sqlInnerString: String = - tableName + - (tableRename match { - case None => "" - case Some(rename) => " AS " + rename - }) - -} diff --git a/src/dbc/scala/dbc/statement/Transaction.scala b/src/dbc/scala/dbc/statement/Transaction.scala deleted file mode 100644 index 1740dae3f9..0000000000 --- a/src/dbc/scala/dbc/statement/Transaction.scala +++ /dev/null @@ -1,55 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package statement; - - -/** A statement that changes the status of the database. */ -@deprecated(DbcIsDeprecated, "2.9.0") case class Transaction [ResultType] ( - transactionBody: (scala.dbc.Database=>ResultType), - accessMode: Option[AccessMode], - isolationLevel: Option[IsolationLevel] -) extends Statement { - - /** A SQL-99 compliant string representation of the statement. */ - def sqlStartString: String = ( - "START TRANSACTION" + - (Pair(accessMode,isolationLevel) match { - case Pair(None,None) => "" - case Pair(Some(am),None) => " " + am.sqlString - case Pair(None,Some(il)) => " " + il.sqlString - case Pair(Some(am),Some(il)) => " " + am.sqlString + ", " + il.sqlString - }) - ); - - def sqlCommitString: String = { - "COMMIT" - } - - def sqlAbortString: String = { - "ROLLBACK" - } - - //def transactionBody: (()=>Unit); - - //def accessMode: Option[AccessMode]; - - //def isolationLevel: Option[IsolationLevel]; - - def execute (database: scala.dbc.Database): scala.dbc.result.Status[ResultType] = { - database.executeStatement(this); - } - - def execute (database: scala.dbc.Database, debug: Boolean): scala.dbc.result.Status[ResultType] = { - database.executeStatement(this,debug); - } - -} diff --git a/src/dbc/scala/dbc/statement/Update.scala b/src/dbc/scala/dbc/statement/Update.scala deleted file mode 100644 index 836549a4be..0000000000 --- a/src/dbc/scala/dbc/statement/Update.scala +++ /dev/null @@ -1,47 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package statement; - - -import scala.dbc.statement.expression._; - -/** An update of the state of a table. */ -@deprecated(DbcIsDeprecated, "2.9.0") case class Update ( - updateTarget: String, - setClauses: List[SetClause], - whereClause: Option[Expression] -) extends Status { - - - /** A SQL-99 compliant string representation of the select statement. */ - def sqlString: String = ( - "UPDATE " + - updateTarget + - " SET " + setClauses.map(sc=>sc.sqlString).mkString("",", ","") + - (whereClause match { - case None => "" - case Some(expr) => " WHERE " + expr.sqlString - }) - ); - - /** The name of the table that should be updated. */ - //def updateTarget: String; - - /** The data that will be added tot he table. */ - //def setClauses: List[SetClause]; - - /** Defines condition that must be true in the tuples that will be updated. - * This value expression must return a boolean or boolean-compatible - * value. */ - //def whereClause: Option[scala.dbc.statement.expression.Expression]; - -} diff --git a/src/dbc/scala/dbc/statement/expression/Aggregate.scala b/src/dbc/scala/dbc/statement/expression/Aggregate.scala deleted file mode 100644 index c42bffe20e..0000000000 --- a/src/dbc/scala/dbc/statement/expression/Aggregate.scala +++ /dev/null @@ -1,35 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package statement -package expression - - -@deprecated(DbcIsDeprecated, "2.9.0") abstract class Aggregate extends Expression { - - def aggregateName: String; - - def setFunction: SetFunction; - - def filterClause: Option[Expression]; - - /** A SQL-99 compliant string representation of the relation sub- - * statement. This only has a meaning inside another statement. */ - def sqlInnerString: String = ( - aggregateName + - "(" + setFunction.sqlString + ")" + - (filterClause match { - case None => "" - case Some(fc) => " FILTER (WHERE " + fc.sqlString + ")" - }) - ) - -} diff --git a/src/dbc/scala/dbc/statement/expression/BinaryOperator.scala b/src/dbc/scala/dbc/statement/expression/BinaryOperator.scala deleted file mode 100644 index 32f016dbf6..0000000000 --- a/src/dbc/scala/dbc/statement/expression/BinaryOperator.scala +++ /dev/null @@ -1,33 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package statement -package expression; - - -@deprecated(DbcIsDeprecated, "2.9.0") abstract class BinaryOperator extends Expression { - - /** The name of the operator. */ - def operator: String; - - /** The expression applied on the left of the operator. */ - def leftOperand: Expression; - - /** The expression applied on the right of the operator. */ - def rightOperand: Expression; - - /** A SQL-99 compliant string representation of the relation sub- - * statement. This only has a meaning inside another statement. */ - def sqlInnerString: String = { - leftOperand.sqlInnerString + " " + operator + " " + rightOperand.sqlInnerString - } - -} diff --git a/src/dbc/scala/dbc/statement/expression/Constant.scala b/src/dbc/scala/dbc/statement/expression/Constant.scala deleted file mode 100644 index 70ec7819dc..0000000000 --- a/src/dbc/scala/dbc/statement/expression/Constant.scala +++ /dev/null @@ -1,23 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package statement -package expression; - - -@deprecated(DbcIsDeprecated, "2.9.0") abstract class Constant extends Expression { - /** A SQL-99 compliant string representation of the relation sub- - * statement. This only has a meaning inside another statement. */ - def sqlInnerString: String = constantValue.sqlString; - - /** The value of the constant. */ - def constantValue: Value; -} diff --git a/src/dbc/scala/dbc/statement/expression/Default.scala b/src/dbc/scala/dbc/statement/expression/Default.scala deleted file mode 100644 index 78204d0172..0000000000 --- a/src/dbc/scala/dbc/statement/expression/Default.scala +++ /dev/null @@ -1,22 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package statement -package expression; - - -case object Default extends Expression { - - /** A SQL-99 compliant string representation of the relation sub- - * statement. This only has a meaning inside another statement. */ - def sqlInnerString: String = "DEFAULT"; - -} diff --git a/src/dbc/scala/dbc/statement/expression/Field.scala b/src/dbc/scala/dbc/statement/expression/Field.scala deleted file mode 100644 index 9a90903a99..0000000000 --- a/src/dbc/scala/dbc/statement/expression/Field.scala +++ /dev/null @@ -1,40 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package statement -package expression; - - -@deprecated(DbcIsDeprecated, "2.9.0") abstract class Field extends Expression { - - /** The name of the schema in the database where the field is located. */ - def schemaName: Option[String] = None; - - /** The name of the table in the database where the field is located. */ - def tableName: Option[String]; - - /** The name of the field in the database. */ - def fieldName: String; - - /** A SQL-99 compliant string representation of the relation sub- - * statement. This only has a meaning inside another statement. */ - def sqlInnerString: String = ( - (schemaName match { - case None => "" - case Some(sn) => sn + "." - }) + - (tableName match { - case None => "" - case Some(tn) => tn + "." - }) + fieldName - ) - -} diff --git a/src/dbc/scala/dbc/statement/expression/FunctionCall.scala b/src/dbc/scala/dbc/statement/expression/FunctionCall.scala deleted file mode 100644 index 962cf209b9..0000000000 --- a/src/dbc/scala/dbc/statement/expression/FunctionCall.scala +++ /dev/null @@ -1,33 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package statement -package expression; - - -@deprecated(DbcIsDeprecated, "2.9.0") case class FunctionCall ( - functionName: String, - arguments: List[Expression] -) extends Expression { - - /** A SQL-99 compliant string representation of the relation sub- - * statement. This only has a meaning inside another statement. */ - def sqlInnerString: String = { - functionName + "(" + arguments.mkString("",", ","") + ")" - } - - /** The name of the function to call. */ - //def functionName: String; - - /** A list of all argument expressions to pass to the function, in order. */ - //def arguments: List[Expression]; - -} diff --git a/src/dbc/scala/dbc/statement/expression/Select.scala b/src/dbc/scala/dbc/statement/expression/Select.scala deleted file mode 100644 index 7a6a4a21c4..0000000000 --- a/src/dbc/scala/dbc/statement/expression/Select.scala +++ /dev/null @@ -1,28 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package statement -package expression; - - -@deprecated(DbcIsDeprecated, "2.9.0") abstract class Select extends Expression { - - /** The actual select statement */ - def selectStatement: statement.Select; - - /** A SQL-99 compliant string representation of the expression. */ - override def sqlString: String = selectStatement.sqlString; - - /** A SQL-99 compliant string representation of the relation sub- - * statement. This only has a meaning inside another statement. */ - def sqlInnerString: String = "("+selectStatement.sqlString+")"; - -} diff --git a/src/dbc/scala/dbc/statement/expression/SetFunction.scala b/src/dbc/scala/dbc/statement/expression/SetFunction.scala deleted file mode 100644 index 060b2236f2..0000000000 --- a/src/dbc/scala/dbc/statement/expression/SetFunction.scala +++ /dev/null @@ -1,40 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package statement -package expression; - - -@deprecated(DbcIsDeprecated, "2.9.0") abstract class SetFunction { - /** A SQL-99 compliant string representation of the set quantifier. */ - def sqlString: String; -} - -@deprecated(DbcIsDeprecated, "2.9.0") object SetFunction { - abstract class Asterisk extends SetFunction { - def sqlString = "(*)"; - } - abstract class General extends SetFunction { - def setQuantifier: Option[SetQuantifier]; - def valueExpression: Expression; - def sqlString = ( - "(" + - (setQuantifier match { - case None => "" - case Some(sq) => sq.sqlString + " " - }) + - valueExpression.sqlString + ")" - ); - } - abstract class Binary extends SetFunction { - def sqlString = sys.error("Binary set function is not supported yet."); - } -} diff --git a/src/dbc/scala/dbc/statement/expression/TypeCast.scala b/src/dbc/scala/dbc/statement/expression/TypeCast.scala deleted file mode 100644 index dbb8dc1b4d..0000000000 --- a/src/dbc/scala/dbc/statement/expression/TypeCast.scala +++ /dev/null @@ -1,32 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package statement -package expression; - - -@deprecated(DbcIsDeprecated, "2.9.0") case class TypeCast ( - expression: Expression, - castType: DataType -) extends Expression { - - /** A SQL-99 compliant string representation of the relation sub- - * statement. This only has a meaning inside another statement. */ - def sqlInnerString: String = { - "CAST (" + expression.sqlInnerString + " AS " + castType.sqlString + ")"; - } - - /** The expression that will be casted. */ - //def expression: Expression; - - /** The type to which to cast. */ - //def castType: scala.dbc.datatype.DataType; -} diff --git a/src/dbc/scala/dbc/statement/expression/UnaryOperator.scala b/src/dbc/scala/dbc/statement/expression/UnaryOperator.scala deleted file mode 100644 index 4172c451fb..0000000000 --- a/src/dbc/scala/dbc/statement/expression/UnaryOperator.scala +++ /dev/null @@ -1,33 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package statement -package expression; - - -@deprecated(DbcIsDeprecated, "2.9.0") abstract class UnaryOperator extends Expression { - - /** The name of the operator */ - def operator: String; - - /** Whether the operator comes before the operand or not. */ - def operatorIsLeft: Boolean; - - /** The operand applied to the operator. */ - def operand: Expression; - - /** A SQL-99 compliant string representation of the relation sub- - * statement. This only has a meaning inside another statement. */ - def sqlInnerString: String = operatorIsLeft match { - case true => operator + " " + operand.sqlInnerString; - case false => operand.sqlInnerString + " " + operator; - } -} diff --git a/src/dbc/scala/dbc/syntax/DataTypeUtil.scala b/src/dbc/scala/dbc/syntax/DataTypeUtil.scala deleted file mode 100644 index a0ebd1713e..0000000000 --- a/src/dbc/scala/dbc/syntax/DataTypeUtil.scala +++ /dev/null @@ -1,98 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package syntax; - - -import java.math.BigDecimal; -import java.math.BigInteger; - -@deprecated(DbcIsDeprecated, "2.9.0") object DataTypeUtil { - - final val java_lang_Integer_SIZE = 32; - final val java_lang_Long_SIZE = 64; - - def boolean = new datatype.Boolean; - def tinyint = new datatype.ExactNumeric[Byte](dbc.DataType.BYTE) { - val precisionRadix = 2; - val precision = 8; - val signed = true; - val scale = 0; - } - def smallint = new datatype.ExactNumeric[Short](dbc.DataType.SHORT) { - val precisionRadix = 2; - val precision = 16; - val signed = true; - val scale = 0; - } - def integer = new datatype.ExactNumeric[Int](dbc.DataType.INT) { - val precisionRadix = 2; - val precision = 32; - val signed = true; - val scale = 0; - } - def bigint = new datatype.ExactNumeric[Long](dbc.DataType.LONG) { - val precisionRadix = 2; - val precision = 64; - val signed = true; - val scale = 0; - } - def numeric (_precision:Int): DataType = numeric(_precision,0); - def numeric (_precision:Int, _scale:Int): DataType = - Pair(datatype.Factory.bytePrecision(_precision,true,true),_scale == 0) match { - case Pair(bp,true) if (bp <= java_lang_Integer_SIZE) => - new datatype.ExactNumeric[Int](DataType.INT) { - val precisionRadix = 10; - val precision = _precision; - val signed = true; - val scale = 0; - } - case Pair(bp,true) if (bp <= java_lang_Long_SIZE) => - new datatype.ExactNumeric[Long](DataType.LONG) { - val precisionRadix = 10; - val precision = _precision; - val signed = true; - val scale = 0; - } - case Pair(_,true) => - new datatype.ExactNumeric[BigInteger](DataType.BIG_INTEGER) { - val precisionRadix = 10; - val precision = _precision; - val signed = true; - val scale = 0; - } - case Pair(_,false) => - new datatype.ExactNumeric[BigDecimal](DataType.BIG_DECIMAL) { - val precisionRadix = 10; - val precision = _precision; - val signed = true; - val scale = _scale; - } - } - def real = new datatype.ApproximateNumeric[Float](DataType.FLOAT) { - val precisionRadix = 2; - val precision = 64; - val signed = true; - } - def doublePrecision = new datatype.ApproximateNumeric[Double](DataType.DOUBLE) { - val precisionRadix = 2; - val precision = 128; - val signed = true; - } - def character (_length: Int) = new datatype.Character { - val length = _length; - } - def characterVarying (_length: Int) = new datatype.CharacterVarying { - def length = _length; - } - def characterLargeObject = new datatype.CharacterLargeObject; - -} diff --git a/src/dbc/scala/dbc/syntax/Database.scala b/src/dbc/scala/dbc/syntax/Database.scala deleted file mode 100644 index 4357fb7d4c..0000000000 --- a/src/dbc/scala/dbc/syntax/Database.scala +++ /dev/null @@ -1,33 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package syntax; - - -import java.net.URI; - -@deprecated(DbcIsDeprecated, "2.9.0") object Database { - - def database (server:String, username:String, password:String): dbc.Database = { - val uri = new URI(server); - // Java 1.5 if (uri.toString().contains("postgres")) { - if (uri.toString().indexOf("postgres") != -1) { - new dbc.Database(new vendor.PostgreSQL { - val uri = new URI(server); - val user = username; - val pass = password; - }) - } else { - throw new Exception("No DBMS vendor support could be found for the given URI"); - } - } - -} diff --git a/src/dbc/scala/dbc/syntax/Statement.scala b/src/dbc/scala/dbc/syntax/Statement.scala deleted file mode 100644 index baccbfaa64..0000000000 --- a/src/dbc/scala/dbc/syntax/Statement.scala +++ /dev/null @@ -1,274 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package syntax; - - -import java.math.BigDecimal; -import java.math.BigInteger; - -import StatementExpression._; - -/* - -ASSUMPTIONS: - -IMPROVABLE: -For type safety, all types must be defined. If one is missing, none is taken into account. -It is possible to redefine many types or renamings for a field, in that case, - only the last one is taken into account ("a" as "b" as "c" of boolean as "e" of integer - is equivalent to "a" as "e" of integer). - -FIXED: - -*/ - -@deprecated(DbcIsDeprecated, "2.9.0") object Statement { - - // SELECT ZYGOTE ... - - def select: SelectZygote = new SelectZygote { - val setQuantifier = None; - } - def selectBag: SelectZygote = new SelectZygote { - val setQuantifier = Some(statement.SetQuantifier.AllTuples); - } - def selectSet: SelectZygote = new SelectZygote { - val setQuantifier = Some(statement.SetQuantifier.DistinctTuples); - } - - abstract class SelectZygote { - def setQuantifier: Option[statement.SetQuantifier]; - def fields (sdc:SelectDerivedColumns): SelectOf = new SelectOf { - val setQuantifier = SelectZygote.this.setQuantifier; - val selectList = sdc.selectList; - val selectTypes = sdc.selectTypes; - } - } - - abstract class SelectDerivedField { - def fieldValue: StatementField; - def fieldRename: Option[String] = {val x = None; x} - def fieldType: Option[dbc.DataType] = {val x = None; x} - def as (rename:String): SelectDerivedField = new SelectDerivedField { - val fieldValue = SelectDerivedField.this.fieldValue; - override val fieldRename = Some(rename); - override val fieldType = SelectDerivedField.this.fieldType; - } - def of (datatype:dbc.DataType): SelectDerivedField = new SelectDerivedField { - val fieldValue = SelectDerivedField.this.fieldValue; - override val fieldRename = SelectDerivedField.this.fieldRename; - override val fieldType = Some(datatype); - } - } - - implicit def statementFieldToSelectDerivedField (fv:StatementField): SelectDerivedField = new SelectDerivedField { - val fieldValue = fv; - } - - implicit def stringToSelectDerivedField (fv:String): SelectDerivedField = new SelectDerivedField { - val fieldValue: StatementField = StatementExpression.stringToStatementField(fv); - } - - abstract class SelectDerivedColumns { - def selectList: List[statement.DerivedColumn]; - def selectTypes: List[DataType]; - def and (sdc:SelectDerivedColumns): SelectDerivedColumns = new SelectDerivedColumns { - val selectList = SelectDerivedColumns.this.selectList ::: sdc.selectList; - val selectTypes = - if (SelectDerivedColumns.this.selectTypes.isEmpty | sdc.selectTypes.isEmpty) - Nil - else - SelectDerivedColumns.this.selectTypes ::: sdc.selectTypes; - } - } - - implicit def selectDerivedFieldToSelectDerivedColumns (sdf:SelectDerivedField): SelectDerivedColumns = new SelectDerivedColumns { - val selectList = List(new statement.DerivedColumn { - val valueExpression = sdf.fieldValue.toStatement; - val asClause = sdf.fieldRename; - }); - val selectTypes = if (sdf.fieldType.isEmpty) Nil else List(sdf.fieldType.get); - } - - implicit def stringToSelectDerivedColumns (sdfs:String): SelectDerivedColumns = { - val sdf: SelectDerivedField = sdfs; - selectDerivedFieldToSelectDerivedColumns(sdf); - } - - // SELECT OF ... - - abstract class SelectOf { - def setQuantifier: Option[statement.SetQuantifier]; - def selectList: List[statement.DerivedColumn]; - def selectTypes: List[DataType]; - def from (sst:SelectSourceTables): SelectBeyond = new SelectBeyond { - val setQuantifier = SelectOf.this.setQuantifier; - val selectList = SelectOf.this.selectList; - val selectTypes = SelectOf.this.selectTypes; - val fromClause = sst.fromClause; - val whereClause = None; - val groupByClause = None; - val havingClause = None; - } - } - - abstract class SelectSourceTable { - def fromRelation: statement.Relation; - def innerJoin (sst: SelectSourceTable): SelectSourceTable = new SelectSourceTable { - val fromRelation = new statement.Jointure { - val leftRelation = SelectSourceTable.this.fromRelation; - val rightRelation = sst.fromRelation; - val joinType = statement.JoinType.Inner; - val joinCondition = None; - val fieldTypes = leftRelation.fieldTypes ::: rightRelation.fieldTypes; - } - } - def leftOuterJoin (sst: SelectSourceTable): SelectSourceTable = new SelectSourceTable { - val fromRelation = new statement.Jointure { - val leftRelation = SelectSourceTable.this.fromRelation; - val rightRelation = sst.fromRelation; - val joinType = statement.JoinType.Outer.Left; - val joinCondition = None; - val fieldTypes = leftRelation.fieldTypes ::: rightRelation.fieldTypes; - } - } - def rightOuterJoin (sst: SelectSourceTable): SelectSourceTable = new SelectSourceTable { - val fromRelation = new statement.Jointure { - val leftRelation = SelectSourceTable.this.fromRelation; - val rightRelation = sst.fromRelation; - val joinType = statement.JoinType.Outer.Right; - val joinCondition = None; - val fieldTypes = leftRelation.fieldTypes ::: rightRelation.fieldTypes; - } - } - def fullOuterJoin (sst: SelectSourceTable): SelectSourceTable = new SelectSourceTable { - val fromRelation = new statement.Jointure { - val leftRelation = SelectSourceTable.this.fromRelation; - val rightRelation = sst.fromRelation; - val joinType = statement.JoinType.Outer.Full; - val joinCondition = None; - val fieldTypes = leftRelation.fieldTypes ::: rightRelation.fieldTypes; - } - } - } - - implicit def stringToSelectSourceTable (sct:String): SelectSourceTable = new SelectSourceTable { - val fromRelation = new statement.Table { - val tableName = sct; - val tableRename = None; - val fieldTypes = Nil; - } - } - - implicit def selectToSelectSourceTable (sct:statement.Select): SelectSourceTable = new SelectSourceTable { - val fromRelation = sct; - } - - abstract class SelectSourceTables { - def fromClause: List[statement.Relation]; - def join (sct:SelectSourceTable): SelectSourceTables = new SelectSourceTables { - val fromClause = SelectSourceTables.this.fromClause ::: List(sct.fromRelation); - } - } - - implicit def stringToSelectSourceTables (sct:String): SelectSourceTables = new SelectSourceTables { - val fromClause = List(new statement.Table { - val tableName = sct; - val tableRename = None; - val fieldTypes = Nil; - }); - } - - implicit def selectToSelectSourceTables (sct:statement.Select): SelectSourceTables = new SelectSourceTables { - val fromClause = List(sct); - } - - implicit def selectSourceTableToSelectSourceTables (sct:SelectSourceTable): SelectSourceTables = new SelectSourceTables { - val fromClause = List(sct.fromRelation); - } - - // SELECT BEYOND ... - - abstract class SelectBeyond { - def setQuantifier: Option[statement.SetQuantifier]; - def selectList: List[statement.DerivedColumn]; - def selectTypes: List[DataType]; - def fromClause: List[statement.Relation]; - def whereClause: Option[statement.Expression]; - def groupByClause: Option[List[statement.Expression]]; - def havingClause: Option[statement.Expression]; - def where (se:StatementExpression): SelectBeyond = new SelectBeyond { - val setQuantifier = SelectBeyond.this.setQuantifier; - val selectList = SelectBeyond.this.selectList; - val selectTypes = SelectBeyond.this.selectTypes; - val fromClause = SelectBeyond.this.fromClause; - val whereClause = Some(se.toStatement); - val groupByClause = SelectBeyond.this.groupByClause; - val havingClause = SelectBeyond.this.havingClause; - } - def groupBy (sgb:SelectGroupBy): SelectBeyond = new SelectBeyond { - val setQuantifier = SelectBeyond.this.setQuantifier; - val selectList = SelectBeyond.this.selectList; - val selectTypes = SelectBeyond.this.selectTypes; - val fromClause = SelectBeyond.this.fromClause; - val whereClause = SelectBeyond.this.whereClause; - val groupByClause = Some(sgb.groupByClause); - val havingClause = SelectBeyond.this.havingClause; - } - def having (se:StatementExpression): SelectBeyond = new SelectBeyond { - val setQuantifier = SelectBeyond.this.setQuantifier; - val selectList = SelectBeyond.this.selectList; - val selectTypes = SelectBeyond.this.selectTypes; - val fromClause = SelectBeyond.this.fromClause; - val whereClause = SelectBeyond.this.whereClause; - val groupByClause = SelectBeyond.this.groupByClause; - val havingClause = Some(se.toStatement); - } - } - - implicit def selectBeyondToStatementSelect (sb:SelectBeyond): statement.Select = new statement.Select { - val setQuantifier = sb.setQuantifier; - val selectList = sb.selectList; - val fromClause = sb.fromClause; - val whereClause = sb.whereClause; - val groupByClause = sb.groupByClause; - val havingClause = sb.havingClause; - val fieldTypes = sb.selectTypes; - } - - abstract class SelectGroupBy { - def groupByClause: List[statement.Expression]; - def then (se:StatementExpression): SelectGroupBy = new SelectGroupBy { - val groupByClause = - SelectGroupBy.this.groupByClause ::: List(se.toStatement); - } - def then (se:String): SelectGroupBy = new SelectGroupBy { - val groupByClause = - SelectGroupBy.this.groupByClause ::: List(new statement.expression.Field { - val tableName = None; - val fieldName = se; - }); - } - } - - implicit def statementExpressionToSelectGroupBy (se:StatementExpression): SelectGroupBy = new SelectGroupBy { - val groupByClause = List(se.toStatement); - } - - implicit def stringToSelectGroupBy (se:String): SelectGroupBy = new SelectGroupBy { - val groupByClause = List(new statement.expression.Field { - val tableName = None; - val fieldName = se; - }); - } - -} diff --git a/src/dbc/scala/dbc/syntax/StatementExpression.scala b/src/dbc/scala/dbc/syntax/StatementExpression.scala deleted file mode 100644 index 65bb0947f7..0000000000 --- a/src/dbc/scala/dbc/syntax/StatementExpression.scala +++ /dev/null @@ -1,221 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package syntax; - - -import java.math.BigDecimal; -import java.math.BigInteger; - -@deprecated(DbcIsDeprecated, "2.9.0") abstract class StatementExpression { - - def toStatement: statement.Expression; - - def and (se:StatementExpression): StatementExpression = new StatementExpression { - val toStatement = new statement.expression.BinaryOperator { - val operator = "AND"; - val leftOperand = StatementExpression.this.toStatement; - val rightOperand = se.toStatement; - } - } - def or (se:StatementExpression): StatementExpression = new StatementExpression { - val toStatement = new statement.expression.BinaryOperator { - val operator = "OR"; - val leftOperand = StatementExpression.this.toStatement; - val rightOperand = se.toStatement; - } - } - def == (se:StatementExpression): StatementExpression = new StatementExpression { - val toStatement = new statement.expression.BinaryOperator { - val operator = "="; - val leftOperand = StatementExpression.this.toStatement; - val rightOperand = se.toStatement; - } - } - def < (se:StatementExpression): StatementExpression = new StatementExpression { - val toStatement = new statement.expression.BinaryOperator { - val operator = "<"; - val leftOperand = StatementExpression.this.toStatement; - val rightOperand = se.toStatement; - } - } - def > (se:StatementExpression): StatementExpression = new StatementExpression { - val toStatement = new statement.expression.BinaryOperator { - val operator = ">"; - val leftOperand = StatementExpression.this.toStatement; - val rightOperand = se.toStatement; - } - } - def <= (se:StatementExpression): StatementExpression = new StatementExpression { - val toStatement = new statement.expression.BinaryOperator { - val operator = "<="; - val leftOperand = StatementExpression.this.toStatement; - val rightOperand = se.toStatement; - } - } - def >= (se:StatementExpression): StatementExpression = new StatementExpression { - val toStatement = new statement.expression.BinaryOperator { - val operator = ">="; - val leftOperand = StatementExpression.this.toStatement; - val rightOperand = se.toStatement; - } - } - def <> (se:StatementExpression): StatementExpression = new StatementExpression { - val toStatement = new statement.expression.BinaryOperator { - val operator = "<>"; - val leftOperand = StatementExpression.this.toStatement; - val rightOperand = se.toStatement; - } - } - def isNull: StatementExpression = new StatementExpression { - val toStatement = new statement.expression.UnaryOperator { - val operator = "IS NULL"; - val operatorIsLeft = false; - val operand = StatementExpression.this.toStatement; - } - } - def isNotNull: StatementExpression = new StatementExpression { - val toStatement = new statement.expression.UnaryOperator { - val operator = "IS NOT NULL"; - val operatorIsLeft = false; - val operand = StatementExpression.this.toStatement; - } - } - def + (se:StatementExpression): StatementExpression = new StatementExpression { - val toStatement = new statement.expression.BinaryOperator { - val operator = "+"; - val leftOperand = StatementExpression.this.toStatement; - val rightOperand = se.toStatement; - } - } - def - (se:StatementExpression): StatementExpression = new StatementExpression { - val toStatement = new statement.expression.BinaryOperator { - val operator = "-"; - val leftOperand = StatementExpression.this.toStatement; - val rightOperand = se.toStatement; - } - } - def * (se:StatementExpression): StatementExpression = new StatementExpression { - val toStatement = new statement.expression.BinaryOperator { - val operator = "*"; - val leftOperand = StatementExpression.this.toStatement; - val rightOperand = se.toStatement; - } - } - def / (se:StatementExpression): StatementExpression = new StatementExpression { - val toStatement = new statement.expression.BinaryOperator { - val operator = "/"; - val leftOperand = StatementExpression.this.toStatement; - val rightOperand = se.toStatement; - } - } - def % (se:StatementExpression): StatementExpression = new StatementExpression { - val toStatement = new statement.expression.BinaryOperator { - val operator = "%"; - val leftOperand = StatementExpression.this.toStatement; - val rightOperand = se.toStatement; - } - } - def ^ (se:StatementExpression): StatementExpression = new StatementExpression { - val toStatement = new statement.expression.BinaryOperator { - val operator = "^"; - val leftOperand = StatementExpression.this.toStatement; - val rightOperand = se.toStatement; - } - } - def not : StatementExpression = new StatementExpression { - val toStatement = new statement.expression.UnaryOperator { - val operator = "!"; - val operatorIsLeft = false; - val operand = StatementExpression.this.toStatement; - } - } - def || (se:StatementExpression): StatementExpression = new StatementExpression { - val toStatement = new statement.expression.BinaryOperator { - val operator = "||"; - val leftOperand = StatementExpression.this.toStatement; - val rightOperand = se.toStatement; - } - } - def like (se:StatementExpression): StatementExpression = new StatementExpression { - val toStatement = new statement.expression.BinaryOperator { - val operator = "LIKE"; - val leftOperand = StatementExpression.this.toStatement; - val rightOperand = se.toStatement; - } - } - def similar (se:StatementExpression): StatementExpression = new StatementExpression { - val toStatement = new statement.expression.BinaryOperator { - val operator = "SIMILAR"; - val leftOperand = StatementExpression.this.toStatement; - val rightOperand = se.toStatement; - } - } - def in (se:statement.Select): StatementExpression = new StatementExpression { - val toStatement = new statement.expression.BinaryOperator { - val operator = "IN"; - val leftOperand = StatementExpression.this.toStatement; - val rightOperand = new statement.expression.Select { - val selectStatement = se; - }; - } - } - -} - -@deprecated(DbcIsDeprecated, "2.9.0") object StatementExpression { - - def not (se:StatementExpression): StatementExpression = new StatementExpression { - val toStatement = new statement.expression.UnaryOperator { - val operator = "NOT"; - val operatorIsLeft = true; - val operand = se.toStatement; - } - } - def abs (se:StatementExpression): StatementExpression = new StatementExpression { - val toStatement = new statement.expression.UnaryOperator { - val operator = "@"; - val operatorIsLeft = true; - val operand = se.toStatement; - } - } - def exists (se:statement.Select): StatementExpression = new StatementExpression { - val toStatement = new statement.expression.UnaryOperator { - val operator = "EXISTS"; - val operatorIsLeft = true; - val operand = new statement.expression.Select { - val selectStatement = se; - }; - } - } - - abstract class StatementField extends StatementExpression { - def fieldName: String; - def tableName: Option[String] = None; - def in (tn:String): StatementField = new StatementField { - val fieldName = StatementField.this.fieldName; - override val tableName = Some(tn); - } - def toStatement: statement.expression.Field = new statement.expression.Field { - override val schemaName = None; - val tableName = StatementField.this.tableName; - val fieldName = StatementField.this.fieldName; - } - } - - implicit def stringToStatementField (ef:String): StatementField = new StatementField { - val fieldName = ef; - } - - - - -} diff --git a/src/dbc/scala/dbc/value/ApproximateNumeric.scala b/src/dbc/scala/dbc/value/ApproximateNumeric.scala deleted file mode 100644 index fa47d8815b..0000000000 --- a/src/dbc/scala/dbc/value/ApproximateNumeric.scala +++ /dev/null @@ -1,28 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package value; - - -@deprecated(DbcIsDeprecated, "2.9.0") abstract class ApproximateNumeric [Type] extends Value { - - val dataType: datatype.ApproximateNumeric[Type]; - - def sqlString = nativeValue.toString(); - - } - -@deprecated(DbcIsDeprecated, "2.9.0") object ApproximateNumeric { - - implicit def approximateNumericToFloar (obj:value.ApproximateNumeric[Float]): Float = obj.nativeValue; - implicit def approximateNumericToDouble (obj:value.ApproximateNumeric[Double]): Double = obj.nativeValue; - -} diff --git a/src/dbc/scala/dbc/value/Boolean.scala b/src/dbc/scala/dbc/value/Boolean.scala deleted file mode 100644 index 5221ce2328..0000000000 --- a/src/dbc/scala/dbc/value/Boolean.scala +++ /dev/null @@ -1,27 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package value; - - -@deprecated(DbcIsDeprecated, "2.9.0") abstract class Boolean extends Value { - - val dataType: datatype.Boolean; - - def sqlString = if (nativeValue) "TRUE" else "FALSE"; - -} - -@deprecated(DbcIsDeprecated, "2.9.0") object Boolean { - - implicit def booleanToBoolean (obj:value.Boolean): scala.Boolean = obj.nativeValue; - -} diff --git a/src/dbc/scala/dbc/value/Character.scala b/src/dbc/scala/dbc/value/Character.scala deleted file mode 100644 index 4ff983c591..0000000000 --- a/src/dbc/scala/dbc/value/Character.scala +++ /dev/null @@ -1,35 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package value; - - -/** A SQL-99 value of type character string. */ -@deprecated(DbcIsDeprecated, "2.9.0") abstract class Character extends Value { - - override val dataType: datatype.Character; - - /** An SQL-99 compliant string representation of the value. */ - def sqlString: String = { - "'" + nativeValue + "'" - } - -} - -/** An object offering transformation methods (views) on the value. - * This object must be visible in an expression to use value auto- - * conversion. */ -@deprecated(DbcIsDeprecated, "2.9.0") object Character { - - /** A character string value as a native string. */ - implicit def characterToString (obj:value.Character): String = obj.nativeValue; - -} diff --git a/src/dbc/scala/dbc/value/CharacterLargeObject.scala b/src/dbc/scala/dbc/value/CharacterLargeObject.scala deleted file mode 100644 index b9e81eb3af..0000000000 --- a/src/dbc/scala/dbc/value/CharacterLargeObject.scala +++ /dev/null @@ -1,35 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package value; - - -/** A SQL-99 value of type character large object. */ -@deprecated(DbcIsDeprecated, "2.9.0") abstract class CharacterLargeObject extends Value { - - override val dataType: datatype.CharacterLargeObject; - - /** An SQL-99 compliant string representation of the value. */ - def sqlString: String = { - "'" + nativeValue + "'" - } - -} - -/** An object offering transformation methods (views) on the value. - * This object must be visible in an expression to use value auto- - * conversion. */ -@deprecated(DbcIsDeprecated, "2.9.0") object CharacterLargeObject { - - /** A character large object value as a native string. */ - implicit def characterLargeObjectToString (obj:value.CharacterLargeObject): String = obj.nativeValue; - -} diff --git a/src/dbc/scala/dbc/value/CharacterVarying.scala b/src/dbc/scala/dbc/value/CharacterVarying.scala deleted file mode 100644 index 72e7d06362..0000000000 --- a/src/dbc/scala/dbc/value/CharacterVarying.scala +++ /dev/null @@ -1,35 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package value; - - -/** A SQL-99 value of type character varying string. */ -@deprecated(DbcIsDeprecated, "2.9.0") abstract class CharacterVarying extends Value { - - override val dataType: datatype.CharacterVarying; - - /** An SQL-99 compliant string representation of the value. */ - def sqlString: String = { - "'" + nativeValue + "'" - } - -} - -/** An object offering transformation methods (views) on the value. - * This object must be visible in an expression to use value auto- - * conversion. */ -@deprecated(DbcIsDeprecated, "2.9.0") object CharacterVarying { - - /** A character varying string value as a native string. */ - implicit def characterVaryingToString (obj:value.CharacterVarying): String = obj.nativeValue; - -} diff --git a/src/dbc/scala/dbc/value/Conversion.scala b/src/dbc/scala/dbc/value/Conversion.scala deleted file mode 100644 index c9297e37db..0000000000 --- a/src/dbc/scala/dbc/value/Conversion.scala +++ /dev/null @@ -1,156 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package value; - -import java.math._; - -@deprecated(DbcIsDeprecated, "2.9.0") object Conversion { - - class Illegal (msg:String) extends Exception(msg); - - implicit def view1 (value:Value): Byte = { - if (value.dataType.nativeTypeId == DataType.BYTE) { - val v = value.asInstanceOf[dbc.value.ExactNumeric[Byte]]; - v.nativeValue - } else { - throw new Illegal("Cannot convert value to byte: "+value) - } - } - - implicit def view2 (value:Value): Short = { - if (value.dataType.nativeTypeId == DataType.BYTE) { - val v = value.asInstanceOf[dbc.value.ExactNumeric[Byte]]; - v.nativeValue.toShort - } else if (value.dataType.nativeTypeId == DataType.SHORT) { - val v = value.asInstanceOf[dbc.value.ExactNumeric[Short]]; - v.nativeValue - } else { - throw new Illegal("Cannot convert value to short: "+value) - } - } - - implicit def view3 (value:Value): Int = { - if (value.dataType.nativeTypeId == DataType.BYTE) { - val v = value.asInstanceOf[dbc.value.ExactNumeric[Byte]]; - v.nativeValue.toInt - } else if (value.dataType.nativeTypeId == DataType.SHORT) { - val v = value.asInstanceOf[dbc.value.ExactNumeric[Short]]; - v.nativeValue.toInt - } else if (value.dataType.nativeTypeId == DataType.INT) { - val v = value.asInstanceOf[dbc.value.ExactNumeric[Int]]; - v.nativeValue - } else { - throw new Illegal("Cannot convert value to int: "+value) - } - } - - implicit def view4 (value:Value): Long = { - if (value.dataType.nativeTypeId == DataType.BYTE) { - val v = value.asInstanceOf[dbc.value.ExactNumeric[Byte]]; - v.nativeValue.toLong - } else if (value.dataType.nativeTypeId == DataType.SHORT) { - val v = value.asInstanceOf[dbc.value.ExactNumeric[Short]]; - v.nativeValue.toLong - } else if (value.dataType.nativeTypeId == DataType.INT) { - val v = value.asInstanceOf[dbc.value.ExactNumeric[Int]]; - v.nativeValue.toLong - } else if (value.dataType.nativeTypeId == DataType.LONG) { - val v = value.asInstanceOf[dbc.value.ExactNumeric[Long]]; - v.nativeValue - } else { - throw new Illegal("Cannot convert value to long: "+value) - } - } - - implicit def view5 (value:Value): BigInteger = { - if (value.dataType.nativeTypeId == DataType.BYTE) { - val v = value.asInstanceOf[dbc.value.ExactNumeric[Byte]]; - new BigInteger(v.nativeValue.toString(),10) - } else if (value.dataType.nativeTypeId == DataType.SHORT) { - val v = value.asInstanceOf[dbc.value.ExactNumeric[Short]]; - new BigInteger(v.nativeValue.toString(),10) - } else if (value.dataType.nativeTypeId == DataType.INT) { - val v = value.asInstanceOf[dbc.value.ExactNumeric[Int]]; - new BigInteger(v.nativeValue.toString(),10) - } else if (value.dataType.nativeTypeId == DataType.LONG) { - val v = value.asInstanceOf[dbc.value.ExactNumeric[Long]]; - new BigInteger(v.nativeValue.toString(),10) - } else if (value.dataType.nativeTypeId == DataType.BIG_INTEGER) { - val v = value.asInstanceOf[dbc.value.ExactNumeric[BigInteger]]; - v.nativeValue - } else { - throw new Illegal("Cannot convert value to big integer: "+value) - } - } - - implicit def view6 (value:Value): BigDecimal = { - if (value.dataType.nativeTypeId == DataType.BYTE) { - val v = value.asInstanceOf[dbc.value.ExactNumeric[Byte]]; - new BigDecimal(v.nativeValue.toString()) - } else if (value.dataType.nativeTypeId == DataType.SHORT) { - val v = value.asInstanceOf[dbc.value.ExactNumeric[Short]]; - new BigDecimal(v.nativeValue.toString()) - } else if (value.dataType.nativeTypeId == DataType.INT) { - val v = value.asInstanceOf[dbc.value.ExactNumeric[Int]]; - new BigDecimal(v.nativeValue.toString()) - } else if (value.dataType.nativeTypeId == DataType.LONG) { - val v = value.asInstanceOf[dbc.value.ExactNumeric[Long]]; - new BigDecimal(v.nativeValue.toString()) - } else if (value.dataType.nativeTypeId == DataType.BIG_INTEGER) { - val v = value.asInstanceOf[dbc.value.ExactNumeric[BigInteger]]; - new BigDecimal(v.nativeValue) - } else if (value.dataType.nativeTypeId == DataType.BIG_DECIMAL) { - val v = value.asInstanceOf[dbc.value.ExactNumeric[BigDecimal]]; - v.nativeValue - } else { - throw new Illegal("Cannot convert value to big decimal: "+value) - } - } - - implicit def view7 (value:Value): Float = { - if (value.dataType.nativeTypeId == DataType.FLOAT) { - val v = value.asInstanceOf[dbc.value.ApproximateNumeric[Float]]; - v.nativeValue - } else { - throw new Illegal("Cannot convert value to float: "+value) - } - } - - implicit def view8 (value:Value): Double = { - if (value.dataType.nativeTypeId == DataType.FLOAT) { - val v = value.asInstanceOf[dbc.value.ApproximateNumeric[Float]]; - v.nativeValue.toFloat - } else if (value.dataType.nativeTypeId == DataType.DOUBLE) { - val v = value.asInstanceOf[dbc.value.ApproximateNumeric[Double]]; - v.nativeValue - } else { - throw new Illegal("Cannot convert value to double: "+value) - } - } - - implicit def view9 (value:Value): scala.Boolean = { - if (value.dataType.nativeTypeId == DataType.BOOLEAN) { - val v = value.asInstanceOf[dbc.value.Boolean]; - v.nativeValue - } else { - throw new Illegal("Cannot convert value to boolean: "+value) - } - } - - implicit def view10 (value:Value): String = value match { - case v:dbc.value.Character => v.nativeValue; - case v:dbc.value.CharacterLargeObject => v.nativeValue; - case v:dbc.value.CharacterVarying => v.nativeValue; - case _ => throw new Illegal("Cannot convert value to string") - } - -} diff --git a/src/dbc/scala/dbc/value/ExactNumeric.scala b/src/dbc/scala/dbc/value/ExactNumeric.scala deleted file mode 100644 index 7cd8b89a8c..0000000000 --- a/src/dbc/scala/dbc/value/ExactNumeric.scala +++ /dev/null @@ -1,35 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package value; - - -import java.math.BigInteger; -import java.math.BigDecimal; - -@deprecated(DbcIsDeprecated, "2.9.0") abstract class ExactNumeric [Type] extends Value { - - val dataType: datatype.ExactNumeric[Type]; - - def sqlString = nativeValue.toString(); - -} - -@deprecated(DbcIsDeprecated, "2.9.0") object ExactNumeric { - - implicit def exactNumericToByte (obj:value.ExactNumeric[Byte]): Byte = obj.nativeValue; - implicit def exactNumericToShort (obj:value.ExactNumeric[Short]): Short = obj.nativeValue; - implicit def exactNumericToInt (obj:value.ExactNumeric[Int]): Int = obj.nativeValue; - implicit def exactNumericToLong (obj:value.ExactNumeric[Long]): Long = obj.nativeValue; - implicit def exactNumericToBigInteger (obj:value.ExactNumeric[BigInteger]): BigInteger = obj.nativeValue; - implicit def exactNumericToBigDecimal (obj:value.ExactNumeric[BigDecimal]): BigDecimal = obj.nativeValue; - -} diff --git a/src/dbc/scala/dbc/value/Factory.scala b/src/dbc/scala/dbc/value/Factory.scala deleted file mode 100644 index 2d6101f6de..0000000000 --- a/src/dbc/scala/dbc/value/Factory.scala +++ /dev/null @@ -1,95 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package value; - - -import java.math.BigInteger; -import java.math.BigDecimal; - -@deprecated(DbcIsDeprecated, "2.9.0") object Factory { - - def create (result: java.sql.ResultSet, index: Int, expectedDataType: DataType): Value = { - expectedDataType.nativeTypeId match { - case DataType.OBJECT => - new value.Unknown { - val dataType = expectedDataType.asInstanceOf[datatype.Unknown]; - val nativeValue: AnyRef = result.getObject(index); - } - case DataType.STRING => { - expectedDataType match { - case t:datatype.Character => - new value.Character { - val dataType = t; - val nativeValue: String = result.getString(index); - } - case t:datatype.CharacterVarying => - new value.CharacterVarying { - val dataType = t; - val nativeValue: String = result.getString(index); - } - case t:datatype.CharacterLargeObject => - new value.CharacterLargeObject { - val dataType = t; - val nativeValue: String = result.getString(index); - } - } - } - case DataType.BOOLEAN => - new value.Boolean { - val dataType = expectedDataType.asInstanceOf[datatype.Boolean]; - val nativeValue: scala.Boolean = result.getBoolean(index); - } - case DataType.FLOAT => - new value.ApproximateNumeric[Float] { - val dataType = expectedDataType.asInstanceOf[datatype.ApproximateNumeric[Float]]; - val nativeValue: Float = result.getFloat(index); - } - case DataType.DOUBLE => - new value.ApproximateNumeric[Double] { - val dataType = expectedDataType.asInstanceOf[datatype.ApproximateNumeric[Double]]; - val nativeValue: Double = result.getDouble(index); - } - case DataType.BYTE => - new value.ExactNumeric[Byte] { - val dataType = expectedDataType.asInstanceOf[datatype.ExactNumeric[Byte]]; - val nativeValue: Byte = result.getByte(index); - } - case DataType.SHORT => - new value.ExactNumeric[Short] { - val dataType = expectedDataType.asInstanceOf[datatype.ExactNumeric[Short]]; - val nativeValue: Short = result.getShort(index); - } - case DataType.INT => - new value.ExactNumeric[Int] { - val dataType = expectedDataType.asInstanceOf[datatype.ExactNumeric[Int]]; - val nativeValue: Int = result.getInt(index); - } - case DataType.LONG => - new value.ExactNumeric[Long] { - val dataType = expectedDataType.asInstanceOf[datatype.ExactNumeric[Long]]; - val nativeValue:Long = result.getLong(index); - } - case DataType.BIG_INTEGER => - new value.ExactNumeric[BigInteger] { - val dataType = expectedDataType.asInstanceOf[datatype.ExactNumeric[BigInteger]]; - val nativeValue: BigInteger = result.getBigDecimal(index).unscaledValue(); - } - case DataType.BIG_DECIMAL => - new value.ExactNumeric[BigDecimal] { - val dataType = expectedDataType.asInstanceOf[datatype.ExactNumeric[BigDecimal]]; - val nativeValue: BigDecimal = result.getBigDecimal(index); - } - - } - } - -} diff --git a/src/dbc/scala/dbc/value/Unknown.scala b/src/dbc/scala/dbc/value/Unknown.scala deleted file mode 100644 index 89764a5831..0000000000 --- a/src/dbc/scala/dbc/value/Unknown.scala +++ /dev/null @@ -1,27 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package value; - - -@deprecated(DbcIsDeprecated, "2.9.0") abstract class Unknown extends Value { - - val dataType: datatype.Unknown; - - def sqlString = sys.error("An 'ANY' value cannot be represented."); - -} - -@deprecated(DbcIsDeprecated, "2.9.0") object UnknownType { - - def view (obj:value.Unknown): AnyRef = obj.nativeValue; - -} diff --git a/src/dbc/scala/dbc/vendor/PostgreSQL.scala b/src/dbc/scala/dbc/vendor/PostgreSQL.scala deleted file mode 100644 index ac528d5f82..0000000000 --- a/src/dbc/scala/dbc/vendor/PostgreSQL.scala +++ /dev/null @@ -1,29 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - - - -package scala.dbc -package vendor; - - -import compat.Platform - -@deprecated(DbcIsDeprecated, "2.9.0") abstract class PostgreSQL extends Vendor { - - def uri:java.net.URI; - def user:String; - def pass:String; - - val retainedConnections = 5; - - val nativeDriverClass = Platform.getClassForName("org.postgresql.Driver"); - - val urlProtocolString = "jdbc:postgresql:" - -} diff --git a/src/intellij/dbc.iml.SAMPLE b/src/intellij/dbc.iml.SAMPLE index 5a6df4cfaa..d2647cfb26 100644 --- a/src/intellij/dbc.iml.SAMPLE +++ b/src/intellij/dbc.iml.SAMPLE @@ -12,9 +12,6 @@ </component> <component name="NewModuleRootManager" inherit-compiler-output="true"> <exclude-output /> - <content url="file://$MODULE_DIR$/../dbc"> - <sourceFolder url="file://$MODULE_DIR$/../dbc" isTestSource="false" /> - </content> <orderEntry type="inheritedJdk" /> <orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="module" module-name="library" /> diff --git a/src/intellij/scala-lang.ipr.SAMPLE b/src/intellij/scala-lang.ipr.SAMPLE index 93b6285cfb..94a9329dd6 100644 --- a/src/intellij/scala-lang.ipr.SAMPLE +++ b/src/intellij/scala-lang.ipr.SAMPLE @@ -197,7 +197,6 @@ <modules> <module fileurl="file://$PROJECT_DIR$/actors.iml" filepath="$PROJECT_DIR$/actors.iml" /> <module fileurl="file://$PROJECT_DIR$/compiler.iml" filepath="$PROJECT_DIR$/compiler.iml" /> - <module fileurl="file://$PROJECT_DIR$/dbc.iml" filepath="$PROJECT_DIR$/dbc.iml" /> <module fileurl="file://$PROJECT_DIR$/library.iml" filepath="$PROJECT_DIR$/library.iml" /> <module fileurl="file://$PROJECT_DIR$/manual.iml" filepath="$PROJECT_DIR$/manual.iml" /> <module fileurl="file://$PROJECT_DIR$/partest.iml" filepath="$PROJECT_DIR$/partest.iml" /> diff --git a/src/library/scala/Product1.scala b/src/library/scala/Product1.scala index d268b35f60..edd095c5c6 100644 --- a/src/library/scala/Product1.scala +++ b/src/library/scala/Product1.scala @@ -28,7 +28,7 @@ trait Product1[@specialized(Int, Long, Double) +T1] extends Any with Product { * otherwise throws an `IndexOutOfBoundsException`. * * @param n number of the projection to be returned - * @return same as `._(n+1)`, for example `productElement(1)` is the same as `._1`. + * @return same as `._(n+1)`, for example `productElement(0)` is the same as `._1`. * @throws IndexOutOfBoundsException */ diff --git a/src/library/scala/Product10.scala b/src/library/scala/Product10.scala index cae9e5a664..8daefde699 100644 --- a/src/library/scala/Product10.scala +++ b/src/library/scala/Product10.scala @@ -28,7 +28,7 @@ trait Product10[+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9, +T10] extends Any w * otherwise throws an `IndexOutOfBoundsException`. * * @param n number of the projection to be returned - * @return same as `._(n+1)`, for example `productElement(1)` is the same as `._1`. + * @return same as `._(n+1)`, for example `productElement(0)` is the same as `._1`. * @throws IndexOutOfBoundsException */ diff --git a/src/library/scala/Product11.scala b/src/library/scala/Product11.scala index 0647b28414..90b4e8013e 100644 --- a/src/library/scala/Product11.scala +++ b/src/library/scala/Product11.scala @@ -28,7 +28,7 @@ trait Product11[+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9, +T10, +T11] extends * otherwise throws an `IndexOutOfBoundsException`. * * @param n number of the projection to be returned - * @return same as `._(n+1)`, for example `productElement(1)` is the same as `._1`. + * @return same as `._(n+1)`, for example `productElement(0)` is the same as `._1`. * @throws IndexOutOfBoundsException */ diff --git a/src/library/scala/Product12.scala b/src/library/scala/Product12.scala index a080aafa7a..d5997ea05a 100644 --- a/src/library/scala/Product12.scala +++ b/src/library/scala/Product12.scala @@ -28,7 +28,7 @@ trait Product12[+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9, +T10, +T11, +T12] e * otherwise throws an `IndexOutOfBoundsException`. * * @param n number of the projection to be returned - * @return same as `._(n+1)`, for example `productElement(1)` is the same as `._1`. + * @return same as `._(n+1)`, for example `productElement(0)` is the same as `._1`. * @throws IndexOutOfBoundsException */ diff --git a/src/library/scala/Product13.scala b/src/library/scala/Product13.scala index 425aebf3e7..db8e0f3722 100644 --- a/src/library/scala/Product13.scala +++ b/src/library/scala/Product13.scala @@ -28,7 +28,7 @@ trait Product13[+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9, +T10, +T11, +T12, + * otherwise throws an `IndexOutOfBoundsException`. * * @param n number of the projection to be returned - * @return same as `._(n+1)`, for example `productElement(1)` is the same as `._1`. + * @return same as `._(n+1)`, for example `productElement(0)` is the same as `._1`. * @throws IndexOutOfBoundsException */ diff --git a/src/library/scala/Product14.scala b/src/library/scala/Product14.scala index 3d7e4896ef..113c07e8c4 100644 --- a/src/library/scala/Product14.scala +++ b/src/library/scala/Product14.scala @@ -28,7 +28,7 @@ trait Product14[+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9, +T10, +T11, +T12, + * otherwise throws an `IndexOutOfBoundsException`. * * @param n number of the projection to be returned - * @return same as `._(n+1)`, for example `productElement(1)` is the same as `._1`. + * @return same as `._(n+1)`, for example `productElement(0)` is the same as `._1`. * @throws IndexOutOfBoundsException */ diff --git a/src/library/scala/Product15.scala b/src/library/scala/Product15.scala index 7bca7a2a1b..a6ad9c7594 100644 --- a/src/library/scala/Product15.scala +++ b/src/library/scala/Product15.scala @@ -28,7 +28,7 @@ trait Product15[+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9, +T10, +T11, +T12, + * otherwise throws an `IndexOutOfBoundsException`. * * @param n number of the projection to be returned - * @return same as `._(n+1)`, for example `productElement(1)` is the same as `._1`. + * @return same as `._(n+1)`, for example `productElement(0)` is the same as `._1`. * @throws IndexOutOfBoundsException */ diff --git a/src/library/scala/Product16.scala b/src/library/scala/Product16.scala index c5042cbc90..cbf47ece94 100644 --- a/src/library/scala/Product16.scala +++ b/src/library/scala/Product16.scala @@ -28,7 +28,7 @@ trait Product16[+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9, +T10, +T11, +T12, + * otherwise throws an `IndexOutOfBoundsException`. * * @param n number of the projection to be returned - * @return same as `._(n+1)`, for example `productElement(1)` is the same as `._1`. + * @return same as `._(n+1)`, for example `productElement(0)` is the same as `._1`. * @throws IndexOutOfBoundsException */ diff --git a/src/library/scala/Product17.scala b/src/library/scala/Product17.scala index b5651ec712..f56836bfd8 100644 --- a/src/library/scala/Product17.scala +++ b/src/library/scala/Product17.scala @@ -28,7 +28,7 @@ trait Product17[+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9, +T10, +T11, +T12, + * otherwise throws an `IndexOutOfBoundsException`. * * @param n number of the projection to be returned - * @return same as `._(n+1)`, for example `productElement(1)` is the same as `._1`. + * @return same as `._(n+1)`, for example `productElement(0)` is the same as `._1`. * @throws IndexOutOfBoundsException */ diff --git a/src/library/scala/Product18.scala b/src/library/scala/Product18.scala index 088a48ae32..5b86bcff65 100644 --- a/src/library/scala/Product18.scala +++ b/src/library/scala/Product18.scala @@ -28,7 +28,7 @@ trait Product18[+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9, +T10, +T11, +T12, + * otherwise throws an `IndexOutOfBoundsException`. * * @param n number of the projection to be returned - * @return same as `._(n+1)`, for example `productElement(1)` is the same as `._1`. + * @return same as `._(n+1)`, for example `productElement(0)` is the same as `._1`. * @throws IndexOutOfBoundsException */ diff --git a/src/library/scala/Product19.scala b/src/library/scala/Product19.scala index 4f4a98c6a0..ed4bf36c93 100644 --- a/src/library/scala/Product19.scala +++ b/src/library/scala/Product19.scala @@ -28,7 +28,7 @@ trait Product19[+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9, +T10, +T11, +T12, + * otherwise throws an `IndexOutOfBoundsException`. * * @param n number of the projection to be returned - * @return same as `._(n+1)`, for example `productElement(1)` is the same as `._1`. + * @return same as `._(n+1)`, for example `productElement(0)` is the same as `._1`. * @throws IndexOutOfBoundsException */ diff --git a/src/library/scala/Product2.scala b/src/library/scala/Product2.scala index eb67e5d46e..e27e54eff9 100644 --- a/src/library/scala/Product2.scala +++ b/src/library/scala/Product2.scala @@ -28,7 +28,7 @@ trait Product2[@specialized(Int, Long, Double) +T1, @specialized(Int, Long, Doub * otherwise throws an `IndexOutOfBoundsException`. * * @param n number of the projection to be returned - * @return same as `._(n+1)`, for example `productElement(1)` is the same as `._1`. + * @return same as `._(n+1)`, for example `productElement(0)` is the same as `._1`. * @throws IndexOutOfBoundsException */ diff --git a/src/library/scala/Product20.scala b/src/library/scala/Product20.scala index 80f63f1bb4..47437a20af 100644 --- a/src/library/scala/Product20.scala +++ b/src/library/scala/Product20.scala @@ -28,7 +28,7 @@ trait Product20[+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9, +T10, +T11, +T12, + * otherwise throws an `IndexOutOfBoundsException`. * * @param n number of the projection to be returned - * @return same as `._(n+1)`, for example `productElement(1)` is the same as `._1`. + * @return same as `._(n+1)`, for example `productElement(0)` is the same as `._1`. * @throws IndexOutOfBoundsException */ diff --git a/src/library/scala/Product21.scala b/src/library/scala/Product21.scala index 7056844271..319d2725c0 100644 --- a/src/library/scala/Product21.scala +++ b/src/library/scala/Product21.scala @@ -28,7 +28,7 @@ trait Product21[+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9, +T10, +T11, +T12, + * otherwise throws an `IndexOutOfBoundsException`. * * @param n number of the projection to be returned - * @return same as `._(n+1)`, for example `productElement(1)` is the same as `._1`. + * @return same as `._(n+1)`, for example `productElement(0)` is the same as `._1`. * @throws IndexOutOfBoundsException */ diff --git a/src/library/scala/Product22.scala b/src/library/scala/Product22.scala index 05e95f92dd..6ab3737acd 100644 --- a/src/library/scala/Product22.scala +++ b/src/library/scala/Product22.scala @@ -28,7 +28,7 @@ trait Product22[+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9, +T10, +T11, +T12, + * otherwise throws an `IndexOutOfBoundsException`. * * @param n number of the projection to be returned - * @return same as `._(n+1)`, for example `productElement(1)` is the same as `._1`. + * @return same as `._(n+1)`, for example `productElement(0)` is the same as `._1`. * @throws IndexOutOfBoundsException */ diff --git a/src/library/scala/Product3.scala b/src/library/scala/Product3.scala index 91556bb962..1cfbd7956b 100644 --- a/src/library/scala/Product3.scala +++ b/src/library/scala/Product3.scala @@ -28,7 +28,7 @@ trait Product3[+T1, +T2, +T3] extends Any with Product { * otherwise throws an `IndexOutOfBoundsException`. * * @param n number of the projection to be returned - * @return same as `._(n+1)`, for example `productElement(1)` is the same as `._1`. + * @return same as `._(n+1)`, for example `productElement(0)` is the same as `._1`. * @throws IndexOutOfBoundsException */ diff --git a/src/library/scala/Product4.scala b/src/library/scala/Product4.scala index 1f9070c155..843571fd60 100644 --- a/src/library/scala/Product4.scala +++ b/src/library/scala/Product4.scala @@ -28,7 +28,7 @@ trait Product4[+T1, +T2, +T3, +T4] extends Any with Product { * otherwise throws an `IndexOutOfBoundsException`. * * @param n number of the projection to be returned - * @return same as `._(n+1)`, for example `productElement(1)` is the same as `._1`. + * @return same as `._(n+1)`, for example `productElement(0)` is the same as `._1`. * @throws IndexOutOfBoundsException */ diff --git a/src/library/scala/Product5.scala b/src/library/scala/Product5.scala index 52dd284f55..df73bba3dd 100644 --- a/src/library/scala/Product5.scala +++ b/src/library/scala/Product5.scala @@ -28,7 +28,7 @@ trait Product5[+T1, +T2, +T3, +T4, +T5] extends Any with Product { * otherwise throws an `IndexOutOfBoundsException`. * * @param n number of the projection to be returned - * @return same as `._(n+1)`, for example `productElement(1)` is the same as `._1`. + * @return same as `._(n+1)`, for example `productElement(0)` is the same as `._1`. * @throws IndexOutOfBoundsException */ diff --git a/src/library/scala/Product6.scala b/src/library/scala/Product6.scala index 9624bdbe3e..36906ca54e 100644 --- a/src/library/scala/Product6.scala +++ b/src/library/scala/Product6.scala @@ -28,7 +28,7 @@ trait Product6[+T1, +T2, +T3, +T4, +T5, +T6] extends Any with Product { * otherwise throws an `IndexOutOfBoundsException`. * * @param n number of the projection to be returned - * @return same as `._(n+1)`, for example `productElement(1)` is the same as `._1`. + * @return same as `._(n+1)`, for example `productElement(0)` is the same as `._1`. * @throws IndexOutOfBoundsException */ diff --git a/src/library/scala/Product7.scala b/src/library/scala/Product7.scala index 36d4b149db..e7b2c13ad1 100644 --- a/src/library/scala/Product7.scala +++ b/src/library/scala/Product7.scala @@ -28,7 +28,7 @@ trait Product7[+T1, +T2, +T3, +T4, +T5, +T6, +T7] extends Any with Product { * otherwise throws an `IndexOutOfBoundsException`. * * @param n number of the projection to be returned - * @return same as `._(n+1)`, for example `productElement(1)` is the same as `._1`. + * @return same as `._(n+1)`, for example `productElement(0)` is the same as `._1`. * @throws IndexOutOfBoundsException */ diff --git a/src/library/scala/Product8.scala b/src/library/scala/Product8.scala index 28c78f9c89..916e57ec39 100644 --- a/src/library/scala/Product8.scala +++ b/src/library/scala/Product8.scala @@ -28,7 +28,7 @@ trait Product8[+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8] extends Any with Product * otherwise throws an `IndexOutOfBoundsException`. * * @param n number of the projection to be returned - * @return same as `._(n+1)`, for example `productElement(1)` is the same as `._1`. + * @return same as `._(n+1)`, for example `productElement(0)` is the same as `._1`. * @throws IndexOutOfBoundsException */ diff --git a/src/library/scala/Product9.scala b/src/library/scala/Product9.scala index d69c550abe..d5e72edc0b 100644 --- a/src/library/scala/Product9.scala +++ b/src/library/scala/Product9.scala @@ -28,7 +28,7 @@ trait Product9[+T1, +T2, +T3, +T4, +T5, +T6, +T7, +T8, +T9] extends Any with Pro * otherwise throws an `IndexOutOfBoundsException`. * * @param n number of the projection to be returned - * @return same as `._(n+1)`, for example `productElement(1)` is the same as `._1`. + * @return same as `._(n+1)`, for example `productElement(0)` is the same as `._1`. * @throws IndexOutOfBoundsException */ diff --git a/src/library/scala/collection/GenTraversableLike.scala b/src/library/scala/collection/GenTraversableLike.scala index fd03e0f446..4500a849b1 100644 --- a/src/library/scala/collection/GenTraversableLike.scala +++ b/src/library/scala/collection/GenTraversableLike.scala @@ -91,7 +91,7 @@ trait GenTraversableLike[+A, +Repr] extends Any with GenTraversableOnce[A] with */ def scan[B >: A, That](z: B)(op: (B, B) => B)(implicit cbf: CanBuildFrom[Repr, B, That]): That - /** Produces a collection containing cummulative results of applying the + /** Produces a collection containing cumulative results of applying the * operator going left to right. * * $willNotTerminateInf @@ -106,8 +106,8 @@ trait GenTraversableLike[+A, +Repr] extends Any with GenTraversableOnce[A] with */ def scanLeft[B, That](z: B)(op: (B, A) => B)(implicit bf: CanBuildFrom[Repr, B, That]): That - /** Produces a collection containing cummulative results of applying the operator going right to left. - * The head of the collection is the last cummulative result. + /** Produces a collection containing cumulative results of applying the operator going right to left. + * The head of the collection is the last cumulative result. * $willNotTerminateInf * $orderDependent * diff --git a/src/library/scala/reflect/ClassTag.scala b/src/library/scala/reflect/ClassTag.scala index 06960a5478..142025f600 100644 --- a/src/library/scala/reflect/ClassTag.scala +++ b/src/library/scala/reflect/ClassTag.scala @@ -39,7 +39,11 @@ abstract case class ClassTag[T](erasure: jClass[_]) extends ArrayTag[T] { /** Produces a `ClassTag` that knows how to build `Array[Array[T]]` */ def wrap: ClassTag[Array[T]] = { - val arrayClazz = java.lang.reflect.Array.newInstance(erasure, 0).getClass.asInstanceOf[jClass[Array[T]]] + // newInstance throws an exception if the erasure is Void.TYPE + // see SI-5680 + val arrayClazz = + if (erasure == java.lang.Void.TYPE) classOf[Array[Unit]] + else java.lang.reflect.Array.newInstance(erasure, 0).getClass.asInstanceOf[jClass[Array[T]]] ClassTag[Array[T]](arrayClazz) } @@ -123,6 +127,9 @@ object ClassTag { implicit def toDeprecatedClassManifestApis[T](ctag: ClassTag[T]): DeprecatedClassManifestApis[T] = new DeprecatedClassManifestApis[T](ctag) + @deprecated("Use apply instead", "2.10.0") + def fromClass[T](clazz: jClass[T]): ClassManifest[T] = apply(clazz) + /** Manifest for the singleton type `value.type'. */ @deprecated("Manifests aka type tags now support arbitrary types. Build a manifest directly from the type instead", "2.10.0") def singleType[T <: AnyRef](value: AnyRef): Manifest[T] = ??? diff --git a/src/library/scala/reflect/DummyMirror.scala b/src/library/scala/reflect/DummyMirror.scala index 9607621928..dd4791e57c 100644 --- a/src/library/scala/reflect/DummyMirror.scala +++ b/src/library/scala/reflect/DummyMirror.scala @@ -192,70 +192,70 @@ class DummyMirror(cl: ClassLoader) extends api.Mirror { val UnitTpe: Type = DummyType val definitions: AbsDefinitions = DummyDefinitions object DummyDefinitions extends AbsDefinitions { - def AnyClass: Symbol = DummySymbol - def AnyRefClass: Symbol = DummySymbol - def AnyValClass: Symbol = DummySymbol - def ArrayClass: Symbol = DummySymbol - def ArrayModule: Symbol = DummySymbol - def ArrayModule_overloadedApply: Symbol = DummySymbol - def Array_apply: Symbol = DummySymbol - def Array_clone: Symbol = DummySymbol - def Array_length: Symbol = DummySymbol - def Array_update: Symbol = DummySymbol - def BooleanClass: Symbol = DummySymbol - def ByNameParamClass: Symbol = DummySymbol - def ByteClass: Symbol = DummySymbol - def CharClass: Symbol = DummySymbol - def ClassClass: Symbol = DummySymbol - def ClassTagClass: Symbol = DummySymbol - def ClassTagModule: Symbol = DummySymbol - def ConcreteTypeTagClass: Symbol = DummySymbol - def ConcreteTypeTagModule: Symbol = DummySymbol - def ConsClass: Symbol = DummySymbol - def DoubleClass: Symbol = DummySymbol - def EmptyPackage: Symbol = DummySymbol - def EmptyPackageClass: Symbol = DummySymbol - def FloatClass: Symbol = DummySymbol + def ByNameParamClass = ??? + def JavaRepeatedParamClass = ??? + def RepeatedParamClass = ??? + def AnyClass = ??? + def AnyRefClass = ??? + def AnyValClass = ??? + def ArrayClass = ??? + def ArrayModule = ??? + def ArrayModule_overloadedApply = ??? + def Array_apply = ??? + def Array_clone = ??? + def Array_length = ??? + def Array_update = ??? + def BooleanClass = ??? + def ByteClass = ??? + def CharClass = ??? + def ClassClass = ??? + def ClassTagClass = ??? + def ClassTagModule = ??? + def ConcreteTypeTagClass = ??? + def ConcreteTypeTagModule = ??? + def ConsClass = ??? + def DoubleClass = ??? + def EmptyPackage = ??? + def EmptyPackageClass = ??? + def FloatClass = ??? def FunctionClass: Array[Symbol] = Array() - def IntClass: Symbol = DummySymbol - def IterableClass: Symbol = DummySymbol - def IteratorClass: Symbol = DummySymbol - def IteratorModule: Symbol = DummySymbol - def Iterator_apply: Symbol = DummySymbol - def JavaLangPackage: Symbol = DummySymbol - def JavaLangPackageClass: Symbol = DummySymbol - def JavaRepeatedParamClass: Symbol = DummySymbol - def ListClass: Symbol = DummySymbol - def ListModule: Symbol = DummySymbol - def List_apply: Symbol = DummySymbol - def LongClass: Symbol = DummySymbol - def NilModule: Symbol = DummySymbol - def NoneModule: Symbol = DummySymbol - def NothingClass: Symbol = DummySymbol - def NullClass: Symbol = DummySymbol - def ObjectClass: Symbol = DummySymbol - def OptionClass: Symbol = DummySymbol - def PredefModule: Symbol = DummySymbol + def IntClass = ??? + def IterableClass = ??? + def IteratorClass = ??? + def IteratorModule = ??? + def Iterator_apply = ??? + def JavaLangPackage = ??? + def JavaLangPackageClass = ??? + def ListClass = ??? + def ListModule = ??? + def List_apply = ??? + def LongClass = ??? + def NilModule = ??? + def NoneModule = ??? + def NothingClass = ??? + def NullClass = ??? + def ObjectClass = ??? + def OptionClass = ??? + def PredefModule = ??? def ProductClass: Array[Symbol] = Array() - def RepeatedParamClass: Symbol = DummySymbol - def RootClass: Symbol = DummySymbol - def RootPackage: Symbol = DummySymbol - def ScalaPackage: Symbol = DummySymbol - def ScalaPackageClass: Symbol = DummySymbol - def ScalaPrimitiveValueClasses: List[Symbol] = List() - def SeqClass: Symbol = DummySymbol - def SeqModule: Symbol = DummySymbol - def ShortClass: Symbol = DummySymbol - def SomeClass: Symbol = DummySymbol - def SomeModule: Symbol = DummySymbol - def StringBuilderClass: Symbol = DummySymbol - def StringClass: Symbol = DummySymbol - def SymbolClass: Symbol = DummySymbol - def TraversableClass: Symbol = DummySymbol + def RootClass = ??? + def RootPackage = ??? + def ScalaPackage = ??? + def ScalaPackageClass = ??? + def ScalaPrimitiveValueClasses = Nil + def SeqClass = ??? + def SeqModule = ??? + def ShortClass = ??? + def SomeClass = ??? + def SomeModule = ??? + def StringBuilderClass = ??? + def StringClass = ??? + def SymbolClass = ??? + def TraversableClass = ??? def TupleClass: Array[Symbol] = Array() - def TypeTagClass: Symbol = DummySymbol - def TypeTagModule: Symbol = DummySymbol - def UnitClass: Symbol = DummySymbol + def TypeTagClass = ??? + def TypeTagModule = ??? + def UnitClass = ??? def isNumericValueClass(sym: Symbol): Boolean = notSupported() def isPrimitiveValueClass(sym: Symbol): Boolean = notSupported() def vmClassType(arg: Type): Type = DummyType @@ -382,10 +382,6 @@ class DummyMirror(cl: ClassLoader) extends api.Mirror { def setterToGetter(name: TermName): TermName = notSupported() def defaultGetterName(name: Name, pos: Int): TermName = notSupported() def defaultGetterToMethod(name: Name): TermName = notSupported() - def dropSingletonName(name: Name): TypeName = notSupported() - def singletonName(name: Name): TypeName = notSupported() - def implClassName(name: Name): TypeName = notSupported() - def interfaceName(implname: Name): TypeName = notSupported() def localDummyName(clazz: Symbol): TermName = notSupported() def superName(name: Name): TermName = notSupported() } @@ -411,11 +407,16 @@ class DummyMirror(cl: ClassLoader) extends api.Mirror { val LOCAL_CHILD: TypeName = DummyName val REPEATED_PARAM_CLASS_NAME: TypeName = DummyName val WILDCARD_STAR: TypeName = DummyName + + def dropSingletonName(name: Name): TypeName = notSupported() + def singletonName(name: Name): TypeName = notSupported() + def implClassName(name: Name): TypeName = notSupported() + def interfaceName(implname: Name): TypeName = notSupported() } // Members declared in scala.reflect.api.Symbols type Symbol = DummySymbol.type - val NoSymbol: Symbol = DummySymbol + val NoSymbol = ??? object DummySymbol extends AbsSymbol { this: Symbol => @@ -477,19 +478,19 @@ class DummyMirror(cl: ClassLoader) extends api.Mirror { // type TreeGen = DummyTreeGen.type // [Eugene] cannot compile if uncomment this val gen: TreeGen{val global: DummyMirror.this.type} = DummyTreeGen.asInstanceOf[TreeGen{val global: DummyMirror.this.type}] def modifiersFromInternalFlags(flags: Long,privateWithin: Name,annotations: List[Tree]): Modifiers = DummyModifiers - def newFreeExistential(name: String,info: Type,value: => Any,flags: Long,origin: String): Symbol = DummySymbol - def newFreeTerm(name: String,info: Type,value: => Any,flags: Long,origin: String): Symbol = DummySymbol - def newFreeType(name: String,info: Type,value: => Any,flags: Long,origin: String): Symbol = DummySymbol - def selectOverloadedMethod(owner: Symbol,name: String,index: Int): Symbol = DummySymbol - def selectOverloadedMethodIfDefined(owner: Symbol,name: String,index: Int): Symbol = DummySymbol - def selectTerm(owner: Symbol,name: String): Symbol = DummySymbol - def selectTermIfDefined(owner: Symbol,name: String): Symbol = DummySymbol - def selectType(owner: Symbol,name: String): Symbol = DummySymbol - def selectTypeIfDefined(owner: Symbol,name: String): Symbol = DummySymbol - def staticClass(fullName: String): Symbol = DummySymbol - def staticClassIfDefined(fullName: String): Symbol = DummySymbol - def staticModule(fullName: String): Symbol = DummySymbol - def staticModuleIfDefined(fullName: String): Symbol = DummySymbol + def newFreeExistential(name: String,info: Type,value: => Any,flags: Long,origin: String) = ??? + def newFreeTerm(name: String,info: Type,value: => Any,flags: Long,origin: String) = ??? + def newFreeType(name: String,info: Type,value: => Any,flags: Long,origin: String) = ??? + def selectOverloadedMethod(owner: Symbol,name: String,index: Int) = ??? + def selectOverloadedMethodIfDefined(owner: Symbol,name: String,index: Int) = ??? + def selectTerm(owner: Symbol,name: String) = ??? + def selectTermIfDefined(owner: Symbol,name: String) = ??? + def selectType(owner: Symbol,name: String) = ??? + def selectTypeIfDefined(owner: Symbol,name: String) = ??? + def staticClass(fullName: String) = ??? + def staticClassIfDefined(fullName: String) = ??? + def staticModule(fullName: String) = ??? + def staticModuleIfDefined(fullName: String) = ??? def thisModuleType(fullName: String): Type = DummyType object DummyTreeGen extends AbsTreeGen { val global: Universe = DummyMirror.this diff --git a/src/library/scala/reflect/TagMaterialization.scala b/src/library/scala/reflect/TagMaterialization.scala index a7237223f1..e8d4571228 100644 --- a/src/library/scala/reflect/TagMaterialization.scala +++ b/src/library/scala/reflect/TagMaterialization.scala @@ -9,6 +9,10 @@ import language.implicitConversions // Oh how much I'd love to implement this now, but I have to postpone this until we have a solution for type inference /** This object is required by the compiler and <b>should not be used in client code</b>. */ + + /** !!! Some of this code is copy-pasted four places. This situation + * should be resolved ASAP. + */ object TagMaterialization { def materializeClassTag[T: c.TypeTag](c: Context): c.Expr[ClassTag[T]] = { import c.mirror._ diff --git a/src/library/scala/reflect/api/StandardDefinitions.scala b/src/library/scala/reflect/api/StandardDefinitions.scala index e457bb73e0..21f7c9283b 100755 --- a/src/library/scala/reflect/api/StandardDefinitions.scala +++ b/src/library/scala/reflect/api/StandardDefinitions.scala @@ -6,7 +6,8 @@ package scala.reflect package api -trait StandardDefinitions { self: Universe => +trait StandardTypes { + self: Universe => val ByteTpe: Type val ShortTpe: Type @@ -17,110 +18,119 @@ trait StandardDefinitions { self: Universe => val DoubleTpe: Type val BooleanTpe: Type val UnitTpe: Type + val AnyTpe: Type - val ObjectTpe: Type val AnyValTpe: Type val AnyRefTpe: Type + val ObjectTpe: Type + val NothingTpe: Type val NullTpe: Type val StringTpe: Type +} + +trait StandardDefinitions extends StandardTypes { + self: Universe => val definitions: AbsDefinitions - abstract class AbsDefinitions { - // packages - def RootPackage: Symbol - def RootClass: Symbol - def EmptyPackage: Symbol + // I intend to pull everything in here out of the public API. + trait AbsDefinitionsInternal { + def ArrayModule: Symbol + def ArrayModule_overloadedApply: Symbol + def Array_apply: Symbol + def Array_clone: Symbol + def Array_length: Symbol + def Array_update: Symbol + def ByNameParamClass: Symbol + def ClassTagModule: Symbol + def ConcreteTypeTagModule: Symbol + def ConsClass: Symbol def EmptyPackageClass: Symbol - def ScalaPackage: Symbol - def ScalaPackageClass: Symbol - def JavaLangPackage: Symbol + def FunctionClass : Array[Symbol] + def IterableClass: Symbol + def IteratorClass: Symbol + def IteratorModule: Symbol + def Iterator_apply: Symbol def JavaLangPackageClass: Symbol + def JavaRepeatedParamClass: Symbol + def ListModule: Symbol + def List_apply: Symbol + def NilModule: Symbol + def NoneModule: Symbol + def OptionClass: Symbol + def ProductClass : Array[Symbol] + def RepeatedParamClass: Symbol + def ScalaPackageClass: Symbol + def SeqClass: Symbol + def SeqModule: Symbol + def SomeClass: Symbol + def SomeModule: Symbol + def StringBuilderClass: Symbol + def SymbolClass : Symbol + def TraversableClass: Symbol + def TupleClass : Array[Symbol] + def TypeTagModule: Symbol + def ScalaPrimitiveValueClasses: List[ClassSymbol] + } + + trait AbsDefinitions extends AbsDefinitionsInternal { + // packages + def RootClass: ClassSymbol + def RootPackage: PackageSymbol + def EmptyPackage: PackageSymbol + def ScalaPackage: PackageSymbol + def JavaLangPackage: PackageSymbol // top types - def AnyClass : Symbol - def AnyValClass: Symbol - def AnyRefClass: Symbol - def ObjectClass: Symbol + def AnyClass : ClassSymbol + def AnyValClass: ClassSymbol + def ObjectClass: ClassSymbol + def AnyRefClass: TypeSymbol // bottom types - def NullClass : Symbol - def NothingClass: Symbol + def NullClass : ClassSymbol + def NothingClass: ClassSymbol // the scala value classes - def UnitClass : Symbol - def ByteClass : Symbol - def ShortClass : Symbol - def CharClass : Symbol - def IntClass : Symbol - def LongClass : Symbol - def FloatClass : Symbol - def DoubleClass : Symbol - def BooleanClass: Symbol - def ScalaPrimitiveValueClasses: List[Symbol] - - // fundamental reference classes - def SymbolClass : Symbol - def StringClass : Symbol - def ClassClass : Symbol - - // product, tuple, function - def TupleClass : Array[Symbol] - def ProductClass : Array[Symbol] - def FunctionClass : Array[Symbol] - - // Option classes - def OptionClass: Symbol - def SomeClass: Symbol - def NoneModule: Symbol - def SomeModule: Symbol + def UnitClass : ClassSymbol + def ByteClass : ClassSymbol + def ShortClass : ClassSymbol + def CharClass : ClassSymbol + def IntClass : ClassSymbol + def LongClass : ClassSymbol + def FloatClass : ClassSymbol + def DoubleClass : ClassSymbol + def BooleanClass: ClassSymbol + + // some special classes + def StringClass : ClassSymbol + def ClassClass : ClassSymbol + def ArrayClass: ClassSymbol // collections classes - def ConsClass: Symbol - def IterableClass: Symbol - def IteratorClass: Symbol - def ListClass: Symbol - def SeqClass: Symbol - def StringBuilderClass: Symbol - def TraversableClass: Symbol + def ListClass: ClassSymbol + def ListModule: ModuleSymbol // collections modules - def PredefModule: Symbol - def ListModule: Symbol - def List_apply: Symbol - def NilModule: Symbol - def SeqModule: Symbol - def IteratorModule: Symbol - def Iterator_apply: Symbol - - // arrays and their members - def ArrayModule: Symbol - def ArrayModule_overloadedApply: Symbol - def ArrayClass: Symbol - def Array_apply: Symbol - def Array_update: Symbol - def Array_length: Symbol - def Array_clone: Symbol - - // special parameter types - def ByNameParamClass: Symbol - def JavaRepeatedParamClass: Symbol - def RepeatedParamClass: Symbol + def PredefModule: ModuleSymbol // type tags - def ClassTagClass: Symbol - def ClassTagModule: Symbol - def TypeTagClass: Symbol - def TypeTagModule: Symbol - def ConcreteTypeTagClass: Symbol - def ConcreteTypeTagModule: Symbol + def ClassTagClass: ClassSymbol + def TypeTagClass: ClassSymbol + def ConcreteTypeTagClass: ClassSymbol /** Given a type T, returns the type corresponding to the VM's * representation: ClassClass's type constructor applied to `arg`. */ def vmClassType(arg: Type): Type // !!! better name? - // [Eugene] we already have arg.erasure, right? + // [Eugene] we already have arg.erasure, right? + // + // [Paul] You misunderstand the method (it could be better named). + // Given List[String], it returns java.lang.Class[List[String]] + // (or the .Net equivalent), not the erasure of List[String]. + // See def ClassType in definitions - that's what it was called before, + // and obviously that name has to go. /** The string representation used by the given type in the VM. */ diff --git a/src/library/scala/reflect/api/StandardNames.scala b/src/library/scala/reflect/api/StandardNames.scala index d39d44dd86..60c64f947a 100644 --- a/src/library/scala/reflect/api/StandardNames.scala +++ b/src/library/scala/reflect/api/StandardNames.scala @@ -1,49 +1,64 @@ /* NSC -- new Scala compiler - * Copyright 2005-2011 LAMP/EPFL - * @author Martin Odersky - */ +* Copyright 2005-2011 LAMP/EPFL +* @author Martin Odersky +*/ package scala.reflect package api -trait StandardNames { self: Universe => +trait StandardNames { + self: Universe => - abstract class AbsNames { + val nme: AbsTermNames + val tpnme: AbsTypeNames + + trait AbsNames { type NameType <: Name - val EMPTY: NameType - val ANON_FUN_NAME: NameType val ANON_CLASS_NAME: NameType + val ANON_FUN_NAME: NameType + val EMPTY: NameType val EMPTY_PACKAGE_NAME: NameType + val ERROR: NameType val IMPORT: NameType val MODULE_VAR_SUFFIX: NameType - val ROOT: NameType + val NO_NAME: NameType val PACKAGE: NameType + val ROOT: NameType val SPECIALIZED_SUFFIX: NameType - - val ERROR: NameType - val NO_NAME: NameType val WILDCARD: NameType def flattenedName(segments: Name*): NameType } - val nme: AbsTermNames - - abstract class AbsTermNames extends AbsNames { + trait AbsTermNames extends AbsNames { val EXPAND_SEPARATOR_STRING: String + val IMPL_CLASS_SUFFIX: String + val INTERPRETER_IMPORT_WRAPPER: String + val INTERPRETER_LINE_PREFIX: String + val INTERPRETER_VAR_PREFIX: String + val INTERPRETER_WRAPPER_SUFFIX: String + val LOCALDUMMY_PREFIX: String + val LOCAL_SUFFIX_STRING: String + val MODULE_SUFFIX_NAME: TermName + val NAME_JOIN_NAME: TermName + val PROTECTED_PREFIX: String + val PROTECTED_SET_PREFIX: String + val SETTER_SUFFIX: TermName + val SINGLETON_SUFFIX: String + val SUPER_PREFIX_STRING: String + val TRAIT_SETTER_SEPARATOR_STRING: String val ANYNAME: TermName val CONSTRUCTOR: TermName val FAKE_LOCAL_THIS: TermName val INITIALIZER: TermName val LAZY_LOCAL: TermName - val LOCAL_SUFFIX_STRING: String - val MIRROR_PREFIX: TermName - val MIRROR_SHORT: TermName val MIRROR_FREE_PREFIX: TermName val MIRROR_FREE_THIS_SUFFIX: TermName val MIRROR_FREE_VALUE_SUFFIX: TermName + val MIRROR_PREFIX: TermName + val MIRROR_SHORT: TermName val MIRROR_SYMDEF_PREFIX: TermName val MIXIN_CONSTRUCTOR: TermName val MODULE_INSTANCE_FIELD: TermName @@ -62,11 +77,6 @@ trait StandardNames { self: Universe => val BITMAP_CHECKINIT: TermName val BITMAP_CHECKINIT_TRANSIENT: TermName - val INTERPRETER_IMPORT_WRAPPER: String - val INTERPRETER_LINE_PREFIX: String - val INTERPRETER_VAR_PREFIX: String - val INTERPRETER_WRAPPER_SUFFIX: String - val ROOTPKG: TermName val ADD: TermName @@ -93,77 +103,62 @@ trait StandardNames { self: Universe => val ZAND: TermName val ZOR: TermName - // [Eugene] this doesn't compile. why?! - val UNARY_~ : TermName - val UNARY_+ : TermName - val UNARY_- : TermName - val UNARY_! : TermName + val UNARY_~ : TermName + val UNARY_+ : TermName + val UNARY_- : TermName + val UNARY_! : TermName - // [Eugene] this doesn't compile. why?! val ??? : TermName - val MODULE_SUFFIX_NAME: TermName - val NAME_JOIN_NAME: TermName - val IMPL_CLASS_SUFFIX: String - val LOCALDUMMY_PREFIX: String - val PROTECTED_PREFIX: String - val PROTECTED_SET_PREFIX: String - val SINGLETON_SUFFIX: String - val SUPER_PREFIX_STRING: String - val TRAIT_SETTER_SEPARATOR_STRING: String - val SETTER_SUFFIX: TermName - def isConstructorName(name: Name): Boolean def isExceptionResultName(name: Name): Boolean def isImplClassName(name: Name): Boolean def isLocalDummyName(name: Name): Boolean def isLocalName(name: Name): Boolean def isLoopHeaderLabel(name: Name): Boolean + def isModuleName(name: Name): Boolean + def isOpAssignmentName(name: Name): Boolean def isProtectedAccessorName(name: Name): Boolean - def isSuperAccessorName(name: Name): Boolean def isReplWrapperName(name: Name): Boolean def isSetterName(name: Name): Boolean - def isTraitSetterName(name: Name): Boolean def isSingletonName(name: Name): Boolean - def isModuleName(name: Name): Boolean - def isOpAssignmentName(name: Name): Boolean - - def segments(name: String, assumeTerm: Boolean): List[Name] - def originalName(name: Name): Name - def stripModuleSuffix(name: Name): Name - def unspecializedName(name: Name): Name - def splitSpecializedName(name: Name): (Name, String, String) - def dropLocalSuffix(name: Name): Name + def isSuperAccessorName(name: Name): Boolean + def isTraitSetterName(name: Name): Boolean - def expandedName(name: TermName, base: Symbol, separator: String = EXPAND_SEPARATOR_STRING): TermName + def defaultGetterName(name: Name, pos: Int): TermName + def defaultGetterToMethod(name: Name): TermName + def expandedName(name: TermName, base: Symbol, separator: String): TermName def expandedSetterName(name: TermName, base: Symbol): TermName - def protName(name: Name): TermName - def protSetterName(name: Name): TermName def getterName(name: TermName): TermName def getterToLocal(name: TermName): TermName def getterToSetter(name: TermName): TermName + def localDummyName(clazz: Symbol): TermName def localToGetter(name: TermName): TermName + def protName(name: Name): TermName + def protSetterName(name: Name): TermName def setterToGetter(name: TermName): TermName - def defaultGetterName(name: Name, pos: Int): TermName - def defaultGetterToMethod(name: Name): TermName - - def dropSingletonName(name: Name): TypeName - def singletonName(name: Name): TypeName - def implClassName(name: Name): TypeName - def interfaceName(implname: Name): TypeName - def localDummyName(clazz: Symbol): TermName def superName(name: Name): TermName - } - val tpnme: AbsTypeNames + def dropLocalSuffix(name: Name): Name + def originalName(name: Name): Name + def stripModuleSuffix(name: Name): Name + def unspecializedName(name: Name): Name + def segments(name: String, assumeTerm: Boolean): List[Name] + def splitSpecializedName(name: Name): (Name, String, String) + } - abstract class AbsTypeNames extends AbsNames { - val REFINE_CLASS_NAME: TypeName + trait AbsTypeNames extends AbsNames { val BYNAME_PARAM_CLASS_NAME: TypeName val EQUALS_PATTERN_NAME: TypeName val JAVA_REPEATED_PARAM_CLASS_NAME: TypeName val LOCAL_CHILD: TypeName + val REFINE_CLASS_NAME: TypeName val REPEATED_PARAM_CLASS_NAME: TypeName val WILDCARD_STAR: TypeName + + def dropSingletonName(name: Name): TypeName + def implClassName(name: Name): TypeName + def interfaceName(implname: Name): TypeName + def singletonName(name: Name): TypeName } } diff --git a/src/library/scala/reflect/api/Symbols.scala b/src/library/scala/reflect/api/Symbols.scala index d9293888d9..767246a294 100755 --- a/src/library/scala/reflect/api/Symbols.scala +++ b/src/library/scala/reflect/api/Symbols.scala @@ -4,8 +4,101 @@ package api trait Symbols { self: Universe => type Symbol >: Null <: AbsSymbol + type TypeSymbol <: Symbol with TypeSymbolApi + type TermSymbol <: Symbol with TermSymbolApi + type MethodSymbol <: TermSymbol with MethodSymbolApi + type ModuleSymbol <: TermSymbol with ModuleSymbolApi + type PackageSymbol <: ModuleSymbol with PackageSymbolApi + type ClassSymbol <: TypeSymbol with ClassSymbolApi - abstract class AbsSymbol { this: Symbol => + val NoSymbol: Symbol + + trait TypeSymbolApi { + self: TypeSymbol => + + def name: TypeName + } + trait TermSymbolApi { + self: TermSymbol => + + def name: TermName + } + trait MethodSymbolApi extends TermSymbolApi { + self: MethodSymbol => + } + trait ClassSymbolApi extends TypeSymbolApi { + self: ClassSymbol => + } + trait ModuleSymbolApi extends TermSymbolApi { + self: ModuleSymbol => + } + trait PackageSymbolApi extends ModuleSymbolApi { + self: PackageSymbol => + } + + // I intend to pull everything in here out of the public API. + trait AbsSymbolInternal { + this: Symbol => + + /** A fresh symbol with given name `name`, position `pos` and flags `flags` that has + * the current symbol as its owner. + */ + def newNestedSymbol(name: Name, pos: Position, flags: Long, isClass: Boolean): Symbol + // needed by LiftCode !!! not enough reason to have in the api + + /** Low-level operation to set the symbol's flags + * @return the symbol itself + */ + def setInternalFlags(flags: Long): this.type + // needed by LiftCode !!! not enough reason to have in the api + + /** Set symbol's type signature to given type + * @return the symbol itself + */ + def setTypeSignature(tpe: Type): this.type + // needed by LiftCode !!! not enough reason to have in the api + + /** Set symbol's annotations to given annotations `annots`. + */ + def setAnnotations(annots: AnnotationInfo*): this.type + // needed by LiftCode !!! not enough reason to have in the api + + /** Does this symbol represent the definition of a skolem? + * Skolems are used during typechecking to represent type parameters viewed from inside their scopes. + * If yes, `isType` is also guaranteed to be true. + */ + def isSkolem : Boolean + + /** Does this symbol represent a free type captured by reification? + */ + // needed for ones who wish to inspect reified trees + def isFreeType : Boolean + + /** The type signature of this symbol. + * Note if the symbol is a member of a class, one almost always is interested + * in `typeSignatureIn` with a site type instead. + */ + def typeSignature: Type // !!! Since one should almost never use this, let's give it a different name. + + /** A type reference that refers to this type symbol + * Note if symbol is a member of a class, one almost always is interested + * in `asTypeIn` with a site type instead. + * + * Example: Given a class declaration `class C[T] { ... } `, that generates a symbol + * `C`. Then `C.asType` is the type `C[T]`. + * + * By contrast, `C.typeSignature` would be a type signature of form + * `PolyType(ClassInfoType(...))` that describes type parameters, value + * parameters, parent types, and members of `C`. + */ + def asType: Type // !!! Same as typeSignature. + + /** The kind of this symbol; used for debugging */ + def kind: String + } + + trait AbsSymbol extends AbsSymbolInternal { + this: Symbol => /** The position of this symbol */ @@ -177,22 +270,11 @@ trait Symbols { self: Universe => */ def isAbstractType : Boolean - /** Does this symbol represent the definition of a skolem? - * Skolems are used during typechecking to represent type parameters viewed from inside their scopes. - * If yes, `isType` is also guaranteed to be true. - */ - def isSkolem : Boolean - /** Does this symbol represent an existentially bound type? * If yes, `isType` is also guaranteed to be true. */ def isExistential : Boolean - /** Does this symbol represent a free type captured by reification? - */ - // needed for ones who wish to inspect reified trees - def isFreeType : Boolean - /** Is the type parameter represented by this symbol contravariant? */ def isContravariant : Boolean @@ -205,29 +287,10 @@ trait Symbols { self: Universe => */ def isErroneous : Boolean - /** The type signature of this symbol. - * Note if the symbol is a member of a class, one almost always is interested - * in `typeSignatureIn` with a site type instead. - */ - def typeSignature: Type // !!! Since one should almost never use this, let's give it a different name. - /** The type signature of this symbol seen as a member of given type `site`. */ def typeSignatureIn(site: Type): Type - /** A type reference that refers to this type symbol - * Note if symbol is a member of a class, one almost always is interested - * in `asTypeIn` with a site type instead. - * - * Example: Given a class declaration `class C[T] { ... } `, that generates a symbol - * `C`. Then `C.asType` is the type `C[T]`. - * - * By contrast, `C.typeSignature` would be a type signature of form - * `PolyType(ClassInfoType(...))` that describes type parameters, value - * parameters, parent types, and members of `C`. - */ - def asType: Type // !!! Same as typeSignature. - /** A type reference that refers to this type symbol seen * as a member of given type `site`. */ @@ -255,29 +318,5 @@ trait Symbols { self: Universe => def alternatives: List[Symbol] def resolveOverloaded(pre: Type = NoPrefix, targs: Seq[Type] = List(), actuals: Seq[Type]): Symbol - - /** A fresh symbol with given name `name`, position `pos` and flags `flags` that has - * the current symbol as its owner. - */ - def newNestedSymbol(name: Name, pos: Position, flags: Long, isClass: Boolean): Symbol // needed by LiftCode !!! not enough reason to have in the api - - /** Low-level operation to set the symbol's flags - * @return the symbol itself - */ - def setInternalFlags(flags: Long): this.type // needed by LiftCode !!! not enough reason to have in the api - - /** Set symbol's type signature to given type - * @return the symbol itself - */ - def setTypeSignature(tpe: Type): this.type // needed by LiftCode !!! not enough reason to have in the api - - /** Set symbol's annotations to given annotations `annots`. - */ - def setAnnotations(annots: AnnotationInfo*): this.type // needed by LiftCode !!! not enough reason to have in the api - - /** The kind of this symbol; used for debugging */ - def kind: String } - - val NoSymbol: Symbol } diff --git a/src/library/scala/runtime/ScalaRunTime.scala b/src/library/scala/runtime/ScalaRunTime.scala index 7a932c21bc..d2adc26d66 100644 --- a/src/library/scala/runtime/ScalaRunTime.scala +++ b/src/library/scala/runtime/ScalaRunTime.scala @@ -51,17 +51,8 @@ object ScalaRunTime { * e.g. classOf[int], not classOf[java.lang.Integer]. The compiler * rewrites expressions like 5.getClass to come here. */ - def anyValClass[T <: AnyVal](value: T): Class[T] = (value match { - case x: Byte => java.lang.Byte.TYPE - case x: Short => java.lang.Short.TYPE - case x: Char => java.lang.Character.TYPE - case x: Int => java.lang.Integer.TYPE - case x: Long => java.lang.Long.TYPE - case x: Float => java.lang.Float.TYPE - case x: Double => java.lang.Double.TYPE - case x: Boolean => java.lang.Boolean.TYPE - case x: Unit => java.lang.Void.TYPE - }).asInstanceOf[Class[T]] + def anyValClass[T <: AnyVal : ClassManifest](value: T): Class[T] = + classManifest[T].erasure.asInstanceOf[Class[T]] /** Retrieve generic array element */ def array_apply(xs: AnyRef, idx: Int): Any = xs match { diff --git a/src/partest/scala/tools/partest/nest/ConsoleRunner.scala b/src/partest/scala/tools/partest/nest/ConsoleRunner.scala index 85060ad633..fb3cab52c4 100644 --- a/src/partest/scala/tools/partest/nest/ConsoleRunner.scala +++ b/src/partest/scala/tools/partest/nest/ConsoleRunner.scala @@ -213,7 +213,12 @@ class ConsoleRunner extends DirectRunner { * @return (success count, failure count) */ def testCheckAll(enabledSets: List[TestSet]): (Int, Int) = { - def kindOf(f: File) = (srcDir relativize Path(f).toCanonical).segments.head + def kindOf(f: File) = { + (srcDir relativize Path(f).toCanonical).segments match { + case (".." :: "scaladoc" :: xs) => xs.head + case xs => xs.head + } + } val (valid, invalid) = testFiles partition (x => testSetKinds contains kindOf(x)) invalid foreach (x => NestUI.failure( diff --git a/test/files/neg/t5689.check b/test/files/neg/t5689.check new file mode 100644 index 0000000000..f286d08cfa --- /dev/null +++ b/test/files/neg/t5689.check @@ -0,0 +1,7 @@ +t5689.scala:4: error: macro implementation has wrong shape:
+ required: (c: scala.reflect.makro.Context)(i: c.Expr[Double]): c.Expr[String]
+ found : (c: scala.reflect.makro.Context)(i: c.Expr[Double]): c.Expr[Int]
+type mismatch for return type : c.Expr[String] does not conform to c.Expr[Int]
+ def returnsString(i: Double): String = macro returnsIntImpl
+ ^
+one error found
diff --git a/test/files/neg/t5689.flags b/test/files/neg/t5689.flags new file mode 100644 index 0000000000..cd66464f2f --- /dev/null +++ b/test/files/neg/t5689.flags @@ -0,0 +1 @@ +-language:experimental.macros
\ No newline at end of file diff --git a/test/files/neg/t5689.scala b/test/files/neg/t5689.scala new file mode 100644 index 0000000000..ef7a45b364 --- /dev/null +++ b/test/files/neg/t5689.scala @@ -0,0 +1,6 @@ +import scala.reflect.makro.Context + +object Macros { + def returnsString(i: Double): String = macro returnsIntImpl + def returnsIntImpl(c: Context)(i: c.Expr[Double]): c.Expr[Int] = ??? +} diff --git a/test/files/run/t5680.check b/test/files/run/t5680.check new file mode 100644 index 0000000000..9fec3b6505 --- /dev/null +++ b/test/files/run/t5680.check @@ -0,0 +1,3 @@ +[Lscala.runtime.BoxedUnit
+()
+()
diff --git a/test/files/run/t5680.scala b/test/files/run/t5680.scala new file mode 100644 index 0000000000..f61cbd6e20 --- /dev/null +++ b/test/files/run/t5680.scala @@ -0,0 +1,7 @@ +object Test extends App { + val x = Array[Unit]((), ()) + println(x.toString.substring(0, x.toString.indexOf(";"))) + println(x(0)) + x(1) = () + println(x(1)) +}
\ No newline at end of file |