summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitattributes6
-rw-r--r--.mailmap6
-rw-r--r--META-INF/MANIFEST.MF7
-rw-r--r--README.rst1
-rw-r--r--build.detach.xml186
-rw-r--r--build.examples.xml29
-rw-r--r--build.number4
-rw-r--r--build.number.maven2
-rw-r--r--build.xml162
-rw-r--r--lib/fjbg.jar.desired.sha11
-rw-r--r--lib/msil.jar.desired.sha11
-rw-r--r--lib/scala-compiler-src.jar.desired.sha12
-rw-r--r--lib/scala-compiler.jar.desired.sha12
-rw-r--r--lib/scala-library-src.jar.desired.sha12
-rw-r--r--lib/scala-library.jar.desired.sha12
-rw-r--r--lib/scala-reflect-src.jar.desired.sha12
-rw-r--r--lib/scala-reflect.jar.desired.sha12
-rw-r--r--project/Build.scala40
-rw-r--r--project/Layers.scala14
-rw-r--r--project/Packaging.scala2
-rw-r--r--project/ShaResolve.scala1
-rw-r--r--project/Testing.scala10
-rw-r--r--src/actors/scala/actors/Future.scala2
-rw-r--r--src/asm/scala/tools/asm/AnnotationVisitor.java66
-rw-r--r--src/asm/scala/tools/asm/AnnotationWriter.java58
-rw-r--r--src/asm/scala/tools/asm/Attribute.java193
-rw-r--r--src/asm/scala/tools/asm/ByteVector.java49
-rw-r--r--src/asm/scala/tools/asm/ClassReader.java2980
-rw-r--r--src/asm/scala/tools/asm/ClassVisitor.java233
-rw-r--r--src/asm/scala/tools/asm/ClassWriter.java499
-rw-r--r--src/asm/scala/tools/asm/Context.java110
-rw-r--r--src/asm/scala/tools/asm/FieldVisitor.java34
-rw-r--r--src/asm/scala/tools/asm/FieldWriter.java72
-rw-r--r--src/asm/scala/tools/asm/Frame.java1024
-rw-r--r--src/asm/scala/tools/asm/Handle.java48
-rw-r--r--src/asm/scala/tools/asm/Handler.java9
-rw-r--r--src/asm/scala/tools/asm/Item.java162
-rw-r--r--src/asm/scala/tools/asm/Label.java135
-rw-r--r--src/asm/scala/tools/asm/MethodVisitor.java516
-rw-r--r--src/asm/scala/tools/asm/MethodWriter.java1165
-rw-r--r--src/asm/scala/tools/asm/Type.java254
-rw-r--r--src/asm/scala/tools/asm/signature/SignatureReader.java181
-rw-r--r--src/asm/scala/tools/asm/signature/SignatureVisitor.java51
-rw-r--r--src/asm/scala/tools/asm/signature/SignatureWriter.java2
-rw-r--r--src/asm/scala/tools/asm/tree/AbstractInsnNode.java30
-rw-r--r--src/asm/scala/tools/asm/tree/AnnotationNode.java55
-rw-r--r--src/asm/scala/tools/asm/tree/ClassNode.java102
-rw-r--r--src/asm/scala/tools/asm/tree/FieldInsnNode.java34
-rw-r--r--src/asm/scala/tools/asm/tree/FieldNode.java104
-rw-r--r--src/asm/scala/tools/asm/tree/FrameNode.java121
-rw-r--r--src/asm/scala/tools/asm/tree/IincInsnNode.java8
-rw-r--r--src/asm/scala/tools/asm/tree/InnerClassNode.java42
-rw-r--r--src/asm/scala/tools/asm/tree/InsnList.java120
-rw-r--r--src/asm/scala/tools/asm/tree/InsnNode.java33
-rw-r--r--src/asm/scala/tools/asm/tree/IntInsnNode.java13
-rw-r--r--src/asm/scala/tools/asm/tree/InvokeDynamicInsnNode.java22
-rw-r--r--src/asm/scala/tools/asm/tree/JumpInsnNode.java25
-rw-r--r--src/asm/scala/tools/asm/tree/LabelNode.java2
-rw-r--r--src/asm/scala/tools/asm/tree/LdcInsnNode.java11
-rw-r--r--src/asm/scala/tools/asm/tree/LineNumberNode.java8
-rw-r--r--src/asm/scala/tools/asm/tree/LocalVariableNode.java45
-rw-r--r--src/asm/scala/tools/asm/tree/LookupSwitchInsnNode.java21
-rw-r--r--src/asm/scala/tools/asm/tree/MethodInsnNode.java38
-rw-r--r--src/asm/scala/tools/asm/tree/MethodNode.java236
-rw-r--r--src/asm/scala/tools/asm/tree/MultiANewArrayInsnNode.java10
-rw-r--r--src/asm/scala/tools/asm/tree/TableSwitchInsnNode.java30
-rw-r--r--src/asm/scala/tools/asm/tree/TryCatchBlockNode.java32
-rw-r--r--src/asm/scala/tools/asm/tree/TypeInsnNode.java19
-rw-r--r--src/asm/scala/tools/asm/tree/VarInsnNode.java21
-rw-r--r--src/asm/scala/tools/asm/tree/analysis/Analyzer.java160
-rw-r--r--src/asm/scala/tools/asm/tree/analysis/AnalyzerException.java11
-rw-r--r--src/asm/scala/tools/asm/tree/analysis/BasicInterpreter.java483
-rw-r--r--src/asm/scala/tools/asm/tree/analysis/BasicValue.java9
-rw-r--r--src/asm/scala/tools/asm/tree/analysis/BasicVerifier.java598
-rw-r--r--src/asm/scala/tools/asm/tree/analysis/Frame.java854
-rw-r--r--src/asm/scala/tools/asm/tree/analysis/Interpreter.java110
-rw-r--r--src/asm/scala/tools/asm/tree/analysis/SimpleVerifier.java119
-rw-r--r--src/asm/scala/tools/asm/tree/analysis/SourceInterpreter.java148
-rw-r--r--src/asm/scala/tools/asm/tree/analysis/SourceValue.java8
-rw-r--r--src/asm/scala/tools/asm/tree/analysis/Subroutine.java9
-rw-r--r--src/asm/scala/tools/asm/util/ASMifiable.java13
-rw-r--r--src/asm/scala/tools/asm/util/ASMifier.java485
-rw-r--r--src/asm/scala/tools/asm/util/CheckAnnotationAdapter.java28
-rw-r--r--src/asm/scala/tools/asm/util/CheckClassAdapter.java587
-rw-r--r--src/asm/scala/tools/asm/util/CheckFieldAdapter.java23
-rw-r--r--src/asm/scala/tools/asm/util/CheckMethodAdapter.java937
-rw-r--r--src/asm/scala/tools/asm/util/CheckSignatureAdapter.java57
-rw-r--r--src/asm/scala/tools/asm/util/Printer.java316
-rw-r--r--src/asm/scala/tools/asm/util/SignatureChecker.java47
-rw-r--r--src/asm/scala/tools/asm/util/Textifiable.java8
-rw-r--r--src/asm/scala/tools/asm/util/Textifier.java446
-rw-r--r--src/asm/scala/tools/asm/util/TraceAnnotationVisitor.java23
-rw-r--r--src/asm/scala/tools/asm/util/TraceClassVisitor.java159
-rw-r--r--src/asm/scala/tools/asm/util/TraceFieldVisitor.java10
-rw-r--r--src/asm/scala/tools/asm/util/TraceMethodVisitor.java89
-rw-r--r--src/asm/scala/tools/asm/util/TraceSignatureVisitor.java59
-rw-r--r--src/compiler/scala/reflect/macros/runtime/Enclosures.scala1
-rw-r--r--src/compiler/scala/reflect/macros/runtime/ExprUtils.scala1
-rw-r--r--src/compiler/scala/reflect/reify/Errors.scala6
-rw-r--r--src/compiler/scala/reflect/reify/Phases.scala5
-rw-r--r--src/compiler/scala/reflect/reify/Reifier.scala2
-rw-r--r--src/compiler/scala/reflect/reify/States.scala1
-rw-r--r--src/compiler/scala/reflect/reify/Taggers.scala1
-rw-r--r--src/compiler/scala/reflect/reify/codegen/GenAnnotationInfos.scala3
-rw-r--r--src/compiler/scala/reflect/reify/codegen/GenNames.scala3
-rw-r--r--src/compiler/scala/reflect/reify/codegen/GenPositions.scala3
-rw-r--r--src/compiler/scala/reflect/reify/codegen/GenSymbols.scala9
-rw-r--r--src/compiler/scala/reflect/reify/codegen/GenTrees.scala6
-rw-r--r--src/compiler/scala/reflect/reify/codegen/GenTypes.scala1
-rw-r--r--src/compiler/scala/reflect/reify/codegen/GenUtils.scala60
-rw-r--r--src/compiler/scala/reflect/reify/package.scala9
-rw-r--r--src/compiler/scala/reflect/reify/phases/Calculate.scala1
-rw-r--r--src/compiler/scala/reflect/reify/phases/Metalevels.scala7
-rw-r--r--src/compiler/scala/reflect/reify/phases/Reify.scala4
-rw-r--r--src/compiler/scala/reflect/reify/phases/Reshape.scala20
-rw-r--r--src/compiler/scala/reflect/reify/utils/Extractors.scala4
-rw-r--r--src/compiler/scala/reflect/reify/utils/NodePrinters.scala12
-rw-r--r--src/compiler/scala/reflect/reify/utils/SymbolTables.scala16
-rw-r--r--src/compiler/scala/tools/ant/Pack200Task.scala4
-rw-r--r--src/compiler/scala/tools/ant/Scalac.scala21
-rw-r--r--src/compiler/scala/tools/ant/sabbus/ScalacFork.scala5
-rw-r--r--src/compiler/scala/tools/ant/sabbus/Settings.scala2
-rw-r--r--src/compiler/scala/tools/ant/sabbus/TaskArgs.scala2
-rw-r--r--src/compiler/scala/tools/ant/templates/tool-unix.tmpl3
-rw-r--r--src/compiler/scala/tools/cmd/CommandLine.scala2
-rw-r--r--src/compiler/scala/tools/cmd/FromString.scala11
-rw-r--r--src/compiler/scala/tools/cmd/Reference.scala3
-rw-r--r--src/compiler/scala/tools/cmd/gen/CodegenSpec.scala2
-rw-r--r--src/compiler/scala/tools/nsc/CompilationUnits.scala27
-rw-r--r--src/compiler/scala/tools/nsc/CompileClient.scala1
-rw-r--r--src/compiler/scala/tools/nsc/CompileServer.scala9
-rw-r--r--src/compiler/scala/tools/nsc/CompileSocket.scala6
-rw-r--r--src/compiler/scala/tools/nsc/CompilerCommand.scala6
-rw-r--r--src/compiler/scala/tools/nsc/CompilerRun.scala21
-rw-r--r--src/compiler/scala/tools/nsc/Driver.scala8
-rw-r--r--src/compiler/scala/tools/nsc/GenericRunnerSettings.scala3
-rw-r--r--src/compiler/scala/tools/nsc/Global.scala377
-rw-r--r--src/compiler/scala/tools/nsc/Main.scala12
-rw-r--r--src/compiler/scala/tools/nsc/MainBench.scala16
-rw-r--r--src/compiler/scala/tools/nsc/MainGenericRunner.scala2
-rw-r--r--src/compiler/scala/tools/nsc/ObjectRunner.scala6
-rw-r--r--src/compiler/scala/tools/nsc/OfflineCompilerCommand.scala4
-rw-r--r--src/compiler/scala/tools/nsc/PhaseAssembly.scala14
-rw-r--r--src/compiler/scala/tools/nsc/Phases.scala3
-rw-r--r--src/compiler/scala/tools/nsc/Properties.scala4
-rw-r--r--src/compiler/scala/tools/nsc/ScalaDoc.scala9
-rw-r--r--src/compiler/scala/tools/nsc/ScriptRunner.scala14
-rw-r--r--src/compiler/scala/tools/nsc/SubComponent.scala4
-rwxr-xr-xsrc/compiler/scala/tools/nsc/ast/DocComments.scala7
-rw-r--r--src/compiler/scala/tools/nsc/ast/Positions.scala2
-rw-r--r--src/compiler/scala/tools/nsc/ast/Printers.scala81
-rw-r--r--src/compiler/scala/tools/nsc/ast/TreeBrowsers.scala7
-rw-r--r--src/compiler/scala/tools/nsc/ast/TreeDSL.scala85
-rw-r--r--src/compiler/scala/tools/nsc/ast/TreeGen.scala126
-rw-r--r--src/compiler/scala/tools/nsc/ast/TreeInfo.scala9
-rw-r--r--src/compiler/scala/tools/nsc/ast/Trees.scala17
-rwxr-xr-xsrc/compiler/scala/tools/nsc/ast/parser/MarkupParsers.scala20
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/Parsers.scala81
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/Scanners.scala59
-rwxr-xr-xsrc/compiler/scala/tools/nsc/ast/parser/SymbolicXMLBuilder.scala1
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/Tokens.scala38
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala29
-rw-r--r--src/compiler/scala/tools/nsc/backend/JavaPlatform.scala7
-rw-r--r--src/compiler/scala/tools/nsc/backend/MSILPlatform.scala69
-rw-r--r--src/compiler/scala/tools/nsc/backend/ScalaPrimitives.scala3
-rw-r--r--src/compiler/scala/tools/nsc/backend/WorklistAlgorithm.scala5
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/BasicBlocks.scala38
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/ExceptionHandlers.scala11
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/GenICode.scala409
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/ICodeCheckers.scala26
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/ICodes.scala8
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/Linearizers.scala139
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/Members.scala30
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/Opcodes.scala90
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/Primitives.scala13
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/Printers.scala4
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/Repository.scala11
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/TypeKinds.scala15
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/TypeStacks.scala12
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/analysis/CopyPropagation.scala30
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/analysis/DataFlowAnalysis.scala13
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/analysis/ReachingDefinitions.scala6
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/analysis/TypeFlowAnalysis.scala62
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/BytecodeWriters.scala38
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala114
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/GenAndroid.scala62
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala1921
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/GenJVMASM.scala4
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/GenJVMUtil.scala142
-rw-r--r--src/compiler/scala/tools/nsc/backend/msil/GenMSIL.scala2358
-rw-r--r--src/compiler/scala/tools/nsc/backend/opt/ClosureElimination.scala11
-rw-r--r--src/compiler/scala/tools/nsc/backend/opt/DeadCodeElimination.scala8
-rw-r--r--src/compiler/scala/tools/nsc/backend/opt/InlineExceptionHandlers.scala1
-rw-r--r--src/compiler/scala/tools/nsc/backend/opt/Inliners.scala24
-rw-r--r--src/compiler/scala/tools/nsc/dependencies/Changes.scala8
-rw-r--r--src/compiler/scala/tools/nsc/dependencies/DependencyAnalysis.scala9
-rw-r--r--src/compiler/scala/tools/nsc/doc/DocFactory.scala4
-rw-r--r--src/compiler/scala/tools/nsc/doc/Settings.scala2
-rw-r--r--src/compiler/scala/tools/nsc/doc/Uncompilable.scala2
-rwxr-xr-xsrc/compiler/scala/tools/nsc/doc/base/CommentFactoryBase.scala25
-rwxr-xr-xsrc/compiler/scala/tools/nsc/doc/base/comment/Body.scala2
-rw-r--r--src/compiler/scala/tools/nsc/doc/base/comment/Comment.scala3
-rw-r--r--src/compiler/scala/tools/nsc/doc/html/HtmlPage.scala2
-rw-r--r--src/compiler/scala/tools/nsc/doc/html/Page.scala6
-rw-r--r--src/compiler/scala/tools/nsc/doc/html/SyntaxHigh.scala2
-rw-r--r--src/compiler/scala/tools/nsc/doc/html/page/Index.scala2
-rw-r--r--src/compiler/scala/tools/nsc/doc/html/page/IndexScript.scala1
-rw-r--r--src/compiler/scala/tools/nsc/doc/html/page/Source.scala3
-rw-r--r--src/compiler/scala/tools/nsc/doc/html/page/Template.scala5
-rw-r--r--src/compiler/scala/tools/nsc/doc/html/page/diagram/DotDiagramGenerator.scala7
-rw-r--r--src/compiler/scala/tools/nsc/doc/html/page/diagram/DotRunner.scala7
-rw-r--r--src/compiler/scala/tools/nsc/doc/model/Entity.scala30
-rwxr-xr-xsrc/compiler/scala/tools/nsc/doc/model/IndexModelFactory.scala2
-rw-r--r--src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala185
-rw-r--r--src/compiler/scala/tools/nsc/doc/model/ModelFactoryImplicitSupport.scala102
-rw-r--r--src/compiler/scala/tools/nsc/doc/model/ModelFactoryTypeSupport.scala11
-rwxr-xr-xsrc/compiler/scala/tools/nsc/doc/model/TreeFactory.scala4
-rw-r--r--src/compiler/scala/tools/nsc/doc/model/diagram/Diagram.scala11
-rw-r--r--src/compiler/scala/tools/nsc/doc/model/diagram/DiagramDirectiveParser.scala6
-rw-r--r--src/compiler/scala/tools/nsc/doc/model/diagram/DiagramFactory.scala3
-rw-r--r--src/compiler/scala/tools/nsc/interactive/BuildManager.scala10
-rw-r--r--src/compiler/scala/tools/nsc/interactive/CompilerControl.scala2
-rw-r--r--src/compiler/scala/tools/nsc/interactive/ContextTrees.scala1
-rw-r--r--src/compiler/scala/tools/nsc/interactive/Global.scala52
-rw-r--r--src/compiler/scala/tools/nsc/interactive/Picklers.scala8
-rw-r--r--src/compiler/scala/tools/nsc/interactive/REPL.scala6
-rw-r--r--src/compiler/scala/tools/nsc/interactive/RangePositions.scala3
-rw-r--r--src/compiler/scala/tools/nsc/interactive/RefinedBuildManager.scala9
-rw-r--r--src/compiler/scala/tools/nsc/interactive/SimpleBuildManager.scala3
-rw-r--r--src/compiler/scala/tools/nsc/interactive/tests/InteractiveTest.scala10
-rw-r--r--src/compiler/scala/tools/nsc/interactive/tests/InteractiveTestSettings.scala7
-rw-r--r--src/compiler/scala/tools/nsc/interactive/tests/core/CoreTestDefs.scala6
-rw-r--r--src/compiler/scala/tools/nsc/interactive/tests/core/PresentationCompilerInstance.scala1
-rw-r--r--src/compiler/scala/tools/nsc/interactive/tests/core/PresentationCompilerTestDef.scala3
-rw-r--r--src/compiler/scala/tools/nsc/interactive/tests/core/SourcesCollector.scala4
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/AbstractFileClassLoader.scala23
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/ByteCode.scala21
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/CodeHandlers.scala50
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/CommandLine.scala1
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/Completion.scala2
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/CompletionAware.scala30
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/CompletionOutput.scala1
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/ConsoleReaderHelper.scala7
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/Delimited.scala3
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/ExprTyper.scala16
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/ILoop.scala362
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/ILoopInit.scala125
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/IMain.scala516
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/ISettings.scala11
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/Imports.scala80
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/InteractiveReader.scala10
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/JLineCompletion.scala32
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/JLineReader.scala10
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/Logger.scala4
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/LoopCommands.scala21
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/MemberHandlers.scala63
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/NamedParam.scala4
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/Naming.scala13
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/Parsed.scala9
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/Phased.scala23
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/Power.scala136
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/ReplConfig.scala12
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/ReplDir.scala48
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/ReplGlobal.scala1
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/ReplProps.scala4
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/ReplStrings.scala3
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/ReplVals.scala1
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/RichClass.scala5
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/SimpleReader.scala5
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/TypeStrings.scala21
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/package.scala110
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/session/History.scala6
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/session/SimpleHistory.scala6
-rw-r--r--src/compiler/scala/tools/nsc/io/Fileish.scala33
-rw-r--r--src/compiler/scala/tools/nsc/io/Jar.scala16
-rw-r--r--src/compiler/scala/tools/nsc/io/Lexer.scala4
-rw-r--r--src/compiler/scala/tools/nsc/io/MsilFile.scala18
-rw-r--r--src/compiler/scala/tools/nsc/io/Pickler.scala83
-rw-r--r--src/compiler/scala/tools/nsc/io/Replayer.scala2
-rw-r--r--src/compiler/scala/tools/nsc/io/Socket.scala5
-rw-r--r--src/compiler/scala/tools/nsc/io/SourceReader.scala5
-rw-r--r--src/compiler/scala/tools/nsc/io/package.scala17
-rw-r--r--src/compiler/scala/tools/nsc/javac/JavaParsers.scala61
-rw-r--r--src/compiler/scala/tools/nsc/javac/JavaScanners.scala37
-rw-r--r--src/compiler/scala/tools/nsc/javac/JavaTokens.scala6
-rw-r--r--src/compiler/scala/tools/nsc/matching/MatchSupport.scala23
-rw-r--r--src/compiler/scala/tools/nsc/matching/Matrix.scala29
-rw-r--r--src/compiler/scala/tools/nsc/matching/MatrixAdditions.scala4
-rw-r--r--src/compiler/scala/tools/nsc/matching/ParallelMatching.scala11
-rw-r--r--src/compiler/scala/tools/nsc/matching/PatternBindings.scala11
-rw-r--r--src/compiler/scala/tools/nsc/matching/Patterns.scala44
-rw-r--r--src/compiler/scala/tools/nsc/plugins/Plugin.scala7
-rw-r--r--src/compiler/scala/tools/nsc/plugins/PluginDescription.scala4
-rw-r--r--src/compiler/scala/tools/nsc/reporters/AbstractReporter.scala6
-rw-r--r--src/compiler/scala/tools/nsc/reporters/ConsoleReporter.scala9
-rw-r--r--src/compiler/scala/tools/nsc/reporters/Reporter.scala1
-rw-r--r--src/compiler/scala/tools/nsc/scratchpad/Mixer.scala3
-rw-r--r--src/compiler/scala/tools/nsc/scratchpad/SourceInserter.scala2
-rw-r--r--src/compiler/scala/tools/nsc/settings/AbsSettings.scala13
-rw-r--r--src/compiler/scala/tools/nsc/settings/AdvancedScalaSettings.scala77
-rw-r--r--src/compiler/scala/tools/nsc/settings/AestheticSettings.scala39
-rw-r--r--src/compiler/scala/tools/nsc/settings/FscSettings.scala2
-rw-r--r--src/compiler/scala/tools/nsc/settings/MutableSettings.scala46
-rw-r--r--src/compiler/scala/tools/nsc/settings/ScalaSettings.scala15
-rw-r--r--src/compiler/scala/tools/nsc/settings/StandardScalaSettings.scala8
-rw-r--r--src/compiler/scala/tools/nsc/settings/Warnings.scala19
-rw-r--r--src/compiler/scala/tools/nsc/symtab/BrowsingLoaders.scala3
-rw-r--r--src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala25
-rw-r--r--src/compiler/scala/tools/nsc/symtab/SymbolTrackers.scala8
-rw-r--r--src/compiler/scala/tools/nsc/symtab/classfile/AbstractFileReader.scala7
-rw-r--r--src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala83
-rw-r--r--src/compiler/scala/tools/nsc/symtab/classfile/ICodeReader.scala30
-rw-r--r--src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala180
-rw-r--r--src/compiler/scala/tools/nsc/symtab/clr/CLRTypes.scala137
-rw-r--r--src/compiler/scala/tools/nsc/symtab/clr/TypeParser.scala850
-rw-r--r--src/compiler/scala/tools/nsc/transform/AddInterfaces.scala14
-rw-r--r--src/compiler/scala/tools/nsc/transform/CleanUp.scala91
-rw-r--r--src/compiler/scala/tools/nsc/transform/Constructors.scala15
-rw-r--r--src/compiler/scala/tools/nsc/transform/Erasure.scala125
-rw-r--r--src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala31
-rw-r--r--src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala195
-rw-r--r--src/compiler/scala/tools/nsc/transform/Flatten.scala24
-rw-r--r--src/compiler/scala/tools/nsc/transform/InfoTransform.scala4
-rw-r--r--src/compiler/scala/tools/nsc/transform/InlineErasure.scala10
-rw-r--r--src/compiler/scala/tools/nsc/transform/LambdaLift.scala6
-rw-r--r--src/compiler/scala/tools/nsc/transform/LazyVals.scala20
-rw-r--r--src/compiler/scala/tools/nsc/transform/Mixin.scala133
-rw-r--r--src/compiler/scala/tools/nsc/transform/OverridingPairs.scala4
-rw-r--r--src/compiler/scala/tools/nsc/transform/PostErasure.scala6
-rw-r--r--src/compiler/scala/tools/nsc/transform/SampleTransform.scala5
-rw-r--r--src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala376
-rw-r--r--src/compiler/scala/tools/nsc/transform/TailCalls.scala8
-rw-r--r--src/compiler/scala/tools/nsc/transform/TypingTransformers.scala4
-rw-r--r--src/compiler/scala/tools/nsc/transform/UnCurry.scala78
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Analyzer.scala17
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Checkable.scala20
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/ConstantFolder.scala5
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala31
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Contexts.scala427
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/DestructureTypes.scala15
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Duplicators.scala112
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala17
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Implicits.scala27
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Infer.scala537
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Macros.scala96
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala105
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Modes.scala1
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Namers.scala125
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala11
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala155
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/RefChecks.scala208
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala20
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala21
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Tags.scala2
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/TreeCheckers.scala23
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala127
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala1209
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Unapplies.scala12
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Variances.scala6
-rw-r--r--src/compiler/scala/tools/nsc/util/ClassPath.scala43
-rw-r--r--src/compiler/scala/tools/nsc/util/CommandLineParser.scala5
-rw-r--r--src/compiler/scala/tools/nsc/util/Exceptional.scala2
-rw-r--r--src/compiler/scala/tools/nsc/util/FreshNameCreator.scala5
-rw-r--r--src/compiler/scala/tools/nsc/util/JavaCharArrayReader.scala57
-rw-r--r--src/compiler/scala/tools/nsc/util/MsilClassPath.scala169
-rw-r--r--src/compiler/scala/tools/nsc/util/ScalaClassLoader.scala44
-rw-r--r--src/compiler/scala/tools/nsc/util/ShowPickled.scala3
-rw-r--r--src/compiler/scala/tools/nsc/util/SimpleTracer.scala3
-rw-r--r--src/compiler/scala/tools/nsc/util/WorkScheduler.scala6
-rw-r--r--src/compiler/scala/tools/nsc/util/package.scala32
-rw-r--r--src/compiler/scala/tools/reflect/MacroImplementations.scala3
-rw-r--r--src/compiler/scala/tools/reflect/ReflectMain.scala3
-rw-r--r--src/compiler/scala/tools/reflect/StdTags.scala1
-rw-r--r--src/compiler/scala/tools/reflect/ToolBoxFactory.scala72
-rw-r--r--src/compiler/scala/tools/reflect/package.scala1
-rw-r--r--src/compiler/scala/tools/util/Javap.scala491
-rw-r--r--src/compiler/scala/tools/util/PathResolver.scala24
-rw-r--r--src/continuations/library/scala/util/continuations/ControlContext.scala4
-rw-r--r--src/continuations/library/scala/util/continuations/package.scala8
-rw-r--r--src/continuations/plugin/scala/tools/selectivecps/CPSAnnotationChecker.scala4
-rw-r--r--src/continuations/plugin/scala/tools/selectivecps/CPSUtils.scala5
-rw-r--r--src/continuations/plugin/scala/tools/selectivecps/SelectiveANFTransform.scala13
-rw-r--r--src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSPlugin.scala5
-rw-r--r--src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSTransform.scala19
-rw-r--r--src/detach/library/scala/remoting/Channel.scala190
-rw-r--r--src/detach/library/scala/remoting/Debug.scala27
-rw-r--r--src/detach/library/scala/remoting/ServerChannel.scala68
-rw-r--r--src/detach/library/scala/remoting/detach.scala49
-rw-r--r--src/detach/library/scala/runtime/RemoteRef.scala182
-rw-r--r--src/detach/library/scala/runtime/remoting/Debug.scala85
-rw-r--r--src/detach/library/scala/runtime/remoting/RegistryDelegate.scala192
-rw-r--r--src/detach/library/scala/runtime/remoting/RemoteBooleanRef.scala51
-rw-r--r--src/detach/library/scala/runtime/remoting/RemoteByteRef.scala51
-rw-r--r--src/detach/library/scala/runtime/remoting/RemoteCharRef.scala51
-rw-r--r--src/detach/library/scala/runtime/remoting/RemoteDoubleRef.scala50
-rw-r--r--src/detach/library/scala/runtime/remoting/RemoteFloatRef.scala50
-rw-r--r--src/detach/library/scala/runtime/remoting/RemoteGC.scala66
-rw-r--r--src/detach/library/scala/runtime/remoting/RemoteIntRef.scala51
-rw-r--r--src/detach/library/scala/runtime/remoting/RemoteLongRef.scala51
-rw-r--r--src/detach/library/scala/runtime/remoting/RemoteObjectRef.scala51
-rw-r--r--src/detach/library/scala/runtime/remoting/RemoteShortRef.scala50
-rw-r--r--src/detach/plugin/scala/tools/detach/Detach.scala1190
-rw-r--r--src/detach/plugin/scala/tools/detach/DetachPlugin.scala41
-rw-r--r--src/detach/plugin/scalac-plugin.xml4
-rw-r--r--src/eclipse/README.md2
-rw-r--r--src/eclipse/fjbg/.classpath7
-rw-r--r--src/eclipse/fjbg/.project30
-rw-r--r--src/eclipse/partest/.classpath1
-rw-r--r--src/eclipse/scala-compiler/.classpath2
-rw-r--r--src/eclipse/scalap/.classpath1
-rw-r--r--src/fjbg/ch/epfl/lamp/fjbg/FJBGContext.java195
-rw-r--r--src/fjbg/ch/epfl/lamp/fjbg/JAccessFlags.java35
-rw-r--r--src/fjbg/ch/epfl/lamp/fjbg/JArrayType.java62
-rw-r--r--src/fjbg/ch/epfl/lamp/fjbg/JAttribute.java84
-rw-r--r--src/fjbg/ch/epfl/lamp/fjbg/JAttributeFactory.java101
-rw-r--r--src/fjbg/ch/epfl/lamp/fjbg/JClass.java420
-rw-r--r--src/fjbg/ch/epfl/lamp/fjbg/JCode.java1308
-rw-r--r--src/fjbg/ch/epfl/lamp/fjbg/JCodeAttribute.java125
-rw-r--r--src/fjbg/ch/epfl/lamp/fjbg/JCodeIterator.java377
-rw-r--r--src/fjbg/ch/epfl/lamp/fjbg/JConstantPool.java771
-rw-r--r--src/fjbg/ch/epfl/lamp/fjbg/JConstantValueAttribute.java69
-rw-r--r--src/fjbg/ch/epfl/lamp/fjbg/JEnclosingMethodAttribute.java83
-rw-r--r--src/fjbg/ch/epfl/lamp/fjbg/JExceptionsAttribute.java90
-rw-r--r--src/fjbg/ch/epfl/lamp/fjbg/JExtendedCode.java667
-rw-r--r--src/fjbg/ch/epfl/lamp/fjbg/JField.java62
-rw-r--r--src/fjbg/ch/epfl/lamp/fjbg/JFieldOrMethod.java138
-rw-r--r--src/fjbg/ch/epfl/lamp/fjbg/JInnerClassesAttribute.java201
-rw-r--r--src/fjbg/ch/epfl/lamp/fjbg/JLabel.java30
-rw-r--r--src/fjbg/ch/epfl/lamp/fjbg/JLineNumberTableAttribute.java121
-rw-r--r--src/fjbg/ch/epfl/lamp/fjbg/JLocalVariable.java42
-rw-r--r--src/fjbg/ch/epfl/lamp/fjbg/JLocalVariableTableAttribute.java167
-rw-r--r--src/fjbg/ch/epfl/lamp/fjbg/JMember.java109
-rw-r--r--src/fjbg/ch/epfl/lamp/fjbg/JMethod.java199
-rw-r--r--src/fjbg/ch/epfl/lamp/fjbg/JMethodType.java87
-rw-r--r--src/fjbg/ch/epfl/lamp/fjbg/JObjectType.java65
-rw-r--r--src/fjbg/ch/epfl/lamp/fjbg/JOpcode.java1267
-rw-r--r--src/fjbg/ch/epfl/lamp/fjbg/JOtherAttribute.java77
-rw-r--r--src/fjbg/ch/epfl/lamp/fjbg/JReferenceType.java19
-rw-r--r--src/fjbg/ch/epfl/lamp/fjbg/JSourceFileAttribute.java69
-rw-r--r--src/fjbg/ch/epfl/lamp/fjbg/JStackMapTableAttribute.java282
-rw-r--r--src/fjbg/ch/epfl/lamp/fjbg/JType.java316
-rw-r--r--src/fjbg/ch/epfl/lamp/fjbg/Main.java131
-rw-r--r--src/fjbg/ch/epfl/lamp/util/ByteArray.java145
-rw-r--r--src/intellij/compiler.iml.SAMPLE2
-rw-r--r--src/intellij/fjbg.iml.SAMPLE12
-rw-r--r--src/intellij/msil.iml.SAMPLE24
-rw-r--r--src/intellij/scala-lang.ipr.SAMPLE3
-rw-r--r--src/intellij/test.iml.SAMPLE2
-rw-r--r--src/library/scala/Application.scala79
-rw-r--r--src/library/scala/Array.scala10
-rw-r--r--src/library/scala/Option.scala11
-rw-r--r--src/library/scala/SerialVersionUID.scala2
-rw-r--r--src/library/scala/UninitializedFieldError.scala6
-rw-r--r--src/library/scala/collection/BitSetLike.scala1
-rw-r--r--src/library/scala/collection/DefaultMap.scala6
-rw-r--r--src/library/scala/collection/GenIterableLike.scala2
-rw-r--r--src/library/scala/collection/GenIterableView.scala7
-rw-r--r--src/library/scala/collection/GenIterableViewLike.scala7
-rw-r--r--src/library/scala/collection/GenSeqView.scala7
-rw-r--r--src/library/scala/collection/GenTraversableOnce.scala5
-rw-r--r--src/library/scala/collection/GenTraversableView.scala7
-rw-r--r--src/library/scala/collection/GenTraversableViewLike.scala2
-rw-r--r--src/library/scala/collection/IndexedSeq.scala3
-rw-r--r--src/library/scala/collection/IndexedSeqLike.scala2
-rw-r--r--src/library/scala/collection/Iterable.scala1
-rw-r--r--src/library/scala/collection/IterableProxy.scala2
-rw-r--r--src/library/scala/collection/IterableViewLike.scala1
-rw-r--r--src/library/scala/collection/Iterator.scala2
-rw-r--r--src/library/scala/collection/JavaConversions.scala37
-rwxr-xr-xsrc/library/scala/collection/JavaConverters.scala35
-rw-r--r--src/library/scala/collection/LinearSeqLike.scala4
-rwxr-xr-xsrc/library/scala/collection/LinearSeqOptimized.scala8
-rw-r--r--src/library/scala/collection/MapProxyLike.scala2
-rw-r--r--src/library/scala/collection/Searching.scala116
-rw-r--r--src/library/scala/collection/SeqLike.scala12
-rw-r--r--src/library/scala/collection/SeqProxyLike.scala2
-rw-r--r--src/library/scala/collection/SeqViewLike.scala1
-rw-r--r--src/library/scala/collection/Sequentializable.scala.disabled10
-rw-r--r--src/library/scala/collection/SetProxyLike.scala3
-rw-r--r--src/library/scala/collection/Traversable.scala4
-rw-r--r--src/library/scala/collection/TraversableLike.scala6
-rw-r--r--src/library/scala/collection/TraversableOnce.scala8
-rw-r--r--src/library/scala/collection/TraversableView.scala1
-rw-r--r--src/library/scala/collection/TraversableViewLike.scala5
-rw-r--r--src/library/scala/collection/concurrent/TrieMap.scala6
-rw-r--r--src/library/scala/collection/convert/Decorators.scala2
-rw-r--r--src/library/scala/collection/generic/GenTraversableFactory.scala1
-rw-r--r--src/library/scala/collection/generic/IsSeqLike.scala57
-rw-r--r--src/library/scala/collection/generic/IterableForwarder.scala5
-rw-r--r--src/library/scala/collection/generic/SeqForwarder.scala2
-rwxr-xr-xsrc/library/scala/collection/immutable/DefaultMap.scala4
-rw-r--r--src/library/scala/collection/immutable/GenIterable.scala.disabled37
-rw-r--r--src/library/scala/collection/immutable/GenMap.scala.disabled36
-rw-r--r--src/library/scala/collection/immutable/GenSeq.scala.disabled49
-rw-r--r--src/library/scala/collection/immutable/GenSet.scala.disabled43
-rw-r--r--src/library/scala/collection/immutable/GenTraversable.scala.disabled41
-rw-r--r--src/library/scala/collection/immutable/HashMap.scala3
-rw-r--r--src/library/scala/collection/immutable/IndexedSeq.scala1
-rw-r--r--src/library/scala/collection/immutable/List.scala281
-rw-r--r--src/library/scala/collection/immutable/LongMap.scala2
-rw-r--r--src/library/scala/collection/immutable/NumericRange.scala32
-rw-r--r--src/library/scala/collection/immutable/Range.scala1
-rw-r--r--src/library/scala/collection/immutable/RedBlackTree.scala22
-rw-r--r--src/library/scala/collection/immutable/Stream.scala58
-rw-r--r--src/library/scala/collection/immutable/StringLike.scala10
-rw-r--r--src/library/scala/collection/immutable/StringOps.scala2
-rw-r--r--src/library/scala/collection/immutable/TrieIterator.scala1
-rw-r--r--src/library/scala/collection/immutable/Vector.scala25
-rw-r--r--src/library/scala/collection/mutable/ArrayBuilder.scala3
-rw-r--r--src/library/scala/collection/mutable/ArrayLike.scala3
-rw-r--r--src/library/scala/collection/mutable/BufferProxy.scala3
-rw-r--r--src/library/scala/collection/mutable/FlatHashTable.scala2
-rw-r--r--src/library/scala/collection/mutable/GenIterable.scala.disabled37
-rw-r--r--src/library/scala/collection/mutable/GenMap.scala.disabled40
-rw-r--r--src/library/scala/collection/mutable/GenSeq.scala.disabled44
-rw-r--r--src/library/scala/collection/mutable/GenSet.scala.disabled46
-rw-r--r--src/library/scala/collection/mutable/GenTraversable.scala.disabled38
-rw-r--r--src/library/scala/collection/mutable/IndexedSeqLike.scala3
-rwxr-xr-xsrc/library/scala/collection/mutable/IndexedSeqOptimized.scala3
-rw-r--r--src/library/scala/collection/mutable/IndexedSeqView.scala2
-rw-r--r--src/library/scala/collection/mutable/LinkedListLike.scala3
-rw-r--r--src/library/scala/collection/mutable/ListBuffer.scala41
-rw-r--r--src/library/scala/collection/mutable/MapLike.scala4
-rw-r--r--src/library/scala/collection/mutable/SeqLike.scala1
-rw-r--r--src/library/scala/collection/mutable/SetBuilder.scala3
-rw-r--r--src/library/scala/collection/mutable/SetLike.scala2
-rw-r--r--src/library/scala/collection/mutable/SynchronizedPriorityQueue.scala8
-rw-r--r--src/library/scala/collection/mutable/SynchronizedQueue.scala2
-rw-r--r--src/library/scala/collection/mutable/SynchronizedSet.scala2
-rw-r--r--src/library/scala/collection/mutable/WrappedArrayBuilder.scala1
-rw-r--r--src/library/scala/collection/parallel/ParIterable.scala1
-rw-r--r--src/library/scala/collection/parallel/ParIterableLike.scala75
-rw-r--r--src/library/scala/collection/parallel/ParSeq.scala3
-rw-r--r--src/library/scala/collection/parallel/ParSeqView.scala3
-rw-r--r--src/library/scala/collection/parallel/ParSet.scala6
-rw-r--r--src/library/scala/collection/parallel/ParSetLike.scala8
-rw-r--r--src/library/scala/collection/parallel/RemainsIterator.scala3
-rw-r--r--src/library/scala/collection/parallel/Tasks.scala11
-rw-r--r--src/library/scala/collection/parallel/immutable/ParIterable.scala2
-rw-r--r--src/library/scala/collection/parallel/immutable/ParNumericRange.scala.disabled128
-rw-r--r--src/library/scala/collection/parallel/immutable/ParSeq.scala3
-rw-r--r--src/library/scala/collection/parallel/immutable/ParSet.scala1
-rw-r--r--src/library/scala/collection/parallel/mutable/ParArray.scala15
-rw-r--r--src/library/scala/collection/parallel/mutable/ParFlatHashTable.scala10
-rw-r--r--src/library/scala/collection/parallel/mutable/ParHashMap.scala23
-rw-r--r--src/library/scala/collection/parallel/mutable/ParHashSet.scala9
-rw-r--r--src/library/scala/collection/parallel/mutable/ParHashTable.scala2
-rw-r--r--src/library/scala/collection/parallel/mutable/ParIterable.scala2
-rw-r--r--src/library/scala/collection/parallel/mutable/ParMapLike.scala3
-rw-r--r--src/library/scala/collection/parallel/mutable/ParSeq.scala6
-rw-r--r--src/library/scala/collection/parallel/mutable/ParSet.scala5
-rw-r--r--src/library/scala/collection/parallel/mutable/ParSetLike.scala6
-rw-r--r--src/library/scala/collection/parallel/mutable/ResizableParArrayCombiner.scala2
-rw-r--r--src/library/scala/collection/script/Message.scala2
-rw-r--r--src/library/scala/concurrent/FutureTaskRunner.scala2
-rw-r--r--src/library/scala/concurrent/JavaConversions.scala4
-rw-r--r--src/library/scala/concurrent/impl/Future.scala2
-rw-r--r--src/library/scala/io/Position.scala8
-rw-r--r--src/library/scala/math/BigDecimal.scala6
-rw-r--r--src/library/scala/math/BigInt.scala6
-rw-r--r--src/library/scala/math/ScalaNumericConversions.scala2
-rw-r--r--src/library/scala/package.scala6
-rw-r--r--src/library/scala/parallel/package.scala.disabled178
-rw-r--r--src/library/scala/runtime/ScalaRunTime.scala3
-rw-r--r--src/library/scala/sys/SystemProperties.scala1
-rw-r--r--src/library/scala/util/automata/WordBerrySethi.scala4
-rw-r--r--src/library/scala/util/matching/Regex.scala100
-rw-r--r--src/library/scala/util/parsing/combinator/JavaTokenParsers.scala7
-rw-r--r--src/library/scala/util/parsing/combinator/PackratParsers.scala1
-rw-r--r--src/library/scala/util/parsing/combinator/lexical/Scanners.scala3
-rw-r--r--src/library/scala/util/parsing/combinator/lexical/StdLexical.scala2
-rw-r--r--src/library/scala/util/parsing/combinator/testing/Tester.scala1
-rw-r--r--src/library/scala/util/parsing/input/OffsetPosition.scala2
-rw-r--r--src/library/scala/util/parsing/json/JSON.scala3
-rw-r--r--src/library/scala/util/parsing/json/Lexer.scala1
-rw-r--r--src/library/scala/util/parsing/json/Parser.scala1
-rwxr-xr-xsrc/library/scala/xml/Elem.scala2
-rwxr-xr-xsrc/library/scala/xml/Node.scala10
-rw-r--r--src/library/scala/xml/NodeSeq.scala5
-rwxr-xr-xsrc/library/scala/xml/PrettyPrinter.scala1
-rwxr-xr-xsrc/library/scala/xml/XML.scala2
-rw-r--r--src/library/scala/xml/dtd/DocType.scala8
-rw-r--r--src/library/scala/xml/dtd/ElementValidator.scala2
-rw-r--r--src/library/scala/xml/dtd/ExternalID.scala11
-rw-r--r--src/library/scala/xml/factory/XMLLoader.scala2
-rw-r--r--src/library/scala/xml/include/sax/EncodingHeuristics.scala2
-rw-r--r--src/library/scala/xml/include/sax/XIncludeFilter.scala2
-rw-r--r--src/library/scala/xml/include/sax/XIncluder.scala2
-rwxr-xr-xsrc/library/scala/xml/parsing/MarkupParser.scala10
-rw-r--r--src/library/scala/xml/parsing/MarkupParserCommon.scala1
-rw-r--r--src/library/scala/xml/persistent/SetStorage.scala6
-rw-r--r--src/library/scala/xml/transform/RewriteRule.scala4
-rw-r--r--src/manual/scala/man1/scalac.scala24
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/Assembly.java253
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/AssemblyName.java96
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/Attribute.java654
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/BindingFlags.java169
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/CallingConventions.java75
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/ConstructedType.java48
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/ConstructorInfo.java54
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/CustomAttributeProvider.java82
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/CustomModifier.java45
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/EventAttributes.java32
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/EventInfo.java58
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/FieldAttributes.java119
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/FieldInfo.java141
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/GenericParamAndConstraints.java40
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/HasCustomModifiers.java9
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/ICustomAttributeProvider.java57
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/MemberInfo.java47
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/MemberTypes.java81
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/MethodAttributes.java158
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/MethodBase.java198
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/MethodImplAttributes.java116
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/MethodInfo.java69
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/Module.java155
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/PEAssembly.java69
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/PEFile.java941
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/PEModule.java456
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/PEType.java419
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/ParameterAttributes.java72
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/ParameterInfo.java76
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/PrimitiveType.java62
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/PropertyAttributes.java45
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/PropertyInfo.java104
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/Type.java1142
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/TypeAttributes.java190
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/Version.java71
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/emit/AssemblyBuilder.scala125
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/emit/ConstructorBuilder.scala64
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/emit/FieldBuilder.scala60
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/emit/ICustomAttributeSetter.scala18
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/emit/ILGenerator.scala539
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/emit/ILPrinterVisitor.scala861
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/emit/Label.scala148
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/emit/LocalBuilder.scala44
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/emit/MethodBuilder.scala70
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/emit/ModuleBuilder.scala136
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/emit/MultipleFilesILPrinterVisitor.scala137
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/emit/OpCode.scala1948
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/emit/OpCodes.scala1205
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/emit/ParameterBuilder.scala44
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/emit/SingleFileILPrinterVisitor.scala93
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/emit/TypeBuilder.scala261
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/emit/Visitable.scala24
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/emit/Visitor.scala58
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/tests/CustomAttributesTest.java31
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/tests/JavaTypeTest.java18
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/tests/MembersTest.java100
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/tests/TableDump.java311
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/tests/Test.java92
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/util/PECustomMod.java23
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/util/PESection.java57
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/util/PEStream.java199
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/util/Signature.java129
-rw-r--r--src/msil/ch/epfl/lamp/compiler/msil/util/Table.java1859
-rw-r--r--src/partest/scala/tools/partest/CompilerTest.scala5
-rw-r--r--src/partest/scala/tools/partest/PartestDefaults.scala2
-rw-r--r--src/partest/scala/tools/partest/PartestTask.scala2
-rw-r--r--src/partest/scala/tools/partest/ScaladocModelTest.scala4
-rw-r--r--src/partest/scala/tools/partest/SecurityTest.scala13
-rw-r--r--src/partest/scala/tools/partest/TestUtil.scala10
-rw-r--r--src/partest/scala/tools/partest/instrumented/Instrumentation.scala1
-rw-r--r--src/partest/scala/tools/partest/javaagent/ASMTransformer.java13
-rw-r--r--src/partest/scala/tools/partest/javaagent/ProfilerVisitor.java13
-rw-r--r--src/partest/scala/tools/partest/javaagent/ProfilingAgent.java2
-rw-r--r--src/partest/scala/tools/partest/nest/CompileManager.scala1
-rw-r--r--src/partest/scala/tools/partest/nest/ConsoleFileManager.scala25
-rw-r--r--src/partest/scala/tools/partest/nest/ConsoleRunner.scala14
-rw-r--r--src/partest/scala/tools/partest/nest/DirectRunner.scala1
-rw-r--r--src/partest/scala/tools/partest/nest/FileManager.scala7
-rw-r--r--src/partest/scala/tools/partest/nest/NestUI.scala10
-rw-r--r--src/partest/scala/tools/partest/nest/PathSettings.scala1
-rw-r--r--src/partest/scala/tools/partest/nest/ReflectiveRunner.scala13
-rw-r--r--src/partest/scala/tools/partest/nest/RunnerManager.scala43
-rw-r--r--src/partest/scala/tools/partest/nest/RunnerUtils.scala29
-rw-r--r--src/partest/scala/tools/partest/package.scala10
-rw-r--r--src/partest/scala/tools/partest/utils/PrintMgr.scala52
-rw-r--r--src/reflect/scala/reflect/api/Printers.scala2
-rw-r--r--src/reflect/scala/reflect/internal/AnnotationInfos.scala11
-rw-r--r--src/reflect/scala/reflect/internal/BaseTypeSeqs.scala4
-rw-r--r--src/reflect/scala/reflect/internal/BuildUtils.scala2
-rw-r--r--src/reflect/scala/reflect/internal/ClassfileConstants.scala11
-rw-r--r--src/reflect/scala/reflect/internal/Definitions.scala252
-rw-r--r--src/reflect/scala/reflect/internal/ExistentialsAndSkolems.scala1
-rw-r--r--src/reflect/scala/reflect/internal/Flags.scala19
-rw-r--r--src/reflect/scala/reflect/internal/HasFlags.scala5
-rw-r--r--src/reflect/scala/reflect/internal/Importers.scala9
-rw-r--r--src/reflect/scala/reflect/internal/Mirrors.scala24
-rw-r--r--src/reflect/scala/reflect/internal/Names.scala79
-rw-r--r--src/reflect/scala/reflect/internal/Printers.scala12
-rw-r--r--src/reflect/scala/reflect/internal/Scopes.scala119
-rw-r--r--src/reflect/scala/reflect/internal/StdNames.scala237
-rw-r--r--src/reflect/scala/reflect/internal/SymbolTable.scala44
-rw-r--r--src/reflect/scala/reflect/internal/Symbols.scala426
-rw-r--r--src/reflect/scala/reflect/internal/TreeGen.scala47
-rw-r--r--src/reflect/scala/reflect/internal/TreeInfo.scala125
-rw-r--r--src/reflect/scala/reflect/internal/Trees.scala31
-rw-r--r--src/reflect/scala/reflect/internal/TypeDebugging.scala3
-rw-r--r--src/reflect/scala/reflect/internal/Types.scala1198
-rw-r--r--src/reflect/scala/reflect/internal/pickling/PickleBuffer.scala20
-rw-r--r--src/reflect/scala/reflect/internal/pickling/PickleFormat.scala5
-rw-r--r--src/reflect/scala/reflect/internal/pickling/UnPickler.scala34
-rw-r--r--src/reflect/scala/reflect/internal/settings/MutableSettings.scala1
-rw-r--r--src/reflect/scala/reflect/internal/transform/Erasure.scala4
-rw-r--r--src/reflect/scala/reflect/internal/util/Collections.scala30
-rw-r--r--src/reflect/scala/reflect/internal/util/HashSet.scala2
-rw-r--r--src/reflect/scala/reflect/internal/util/Origins.scala2
-rw-r--r--src/reflect/scala/reflect/internal/util/Position.scala2
-rw-r--r--src/reflect/scala/reflect/internal/util/Set.scala2
-rw-r--r--src/reflect/scala/reflect/internal/util/SourceFile.scala6
-rw-r--r--src/reflect/scala/reflect/internal/util/Statistics.scala1
-rw-r--r--src/reflect/scala/reflect/internal/util/StringOps.scala40
-rw-r--r--src/reflect/scala/reflect/internal/util/TableDef.scala6
-rw-r--r--src/reflect/scala/reflect/internal/util/TraceSymbolActivity.scala40
-rw-r--r--src/reflect/scala/reflect/internal/util/WeakHashSet.scala3
-rw-r--r--src/reflect/scala/reflect/internal/util/package.scala31
-rw-r--r--src/reflect/scala/reflect/io/AbstractFile.scala43
-rw-r--r--src/reflect/scala/reflect/io/Directory.scala15
-rw-r--r--src/reflect/scala/reflect/io/File.scala84
-rw-r--r--src/reflect/scala/reflect/io/Path.scala49
-rw-r--r--src/reflect/scala/reflect/io/PlainFile.scala20
-rw-r--r--src/reflect/scala/reflect/io/Streamable.scala8
-rw-r--r--src/reflect/scala/reflect/io/VirtualDirectory.scala4
-rw-r--r--src/reflect/scala/reflect/io/VirtualFile.scala14
-rw-r--r--src/reflect/scala/reflect/io/ZipArchive.scala7
-rw-r--r--src/reflect/scala/reflect/macros/TreeBuilder.scala1
-rw-r--r--src/reflect/scala/reflect/macros/Universe.scala4
-rw-r--r--src/reflect/scala/reflect/runtime/JavaMirrors.scala42
-rw-r--r--src/reflect/scala/reflect/runtime/JavaUniverse.scala10
-rw-r--r--src/reflect/scala/reflect/runtime/Settings.scala1
-rw-r--r--src/reflect/scala/reflect/runtime/SymbolLoaders.scala4
-rw-r--r--src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala6
-rw-r--r--src/reflect/scala/reflect/runtime/package.scala2
-rw-r--r--src/scalacheck/org/scalacheck/Commands.scala5
-rw-r--r--src/scalap/scala/tools/scalap/Arguments.scala2
-rw-r--r--src/scalap/scala/tools/scalap/scalax/rules/Rule.scala2
-rw-r--r--src/scalap/scala/tools/scalap/scalax/rules/scalasig/ScalaSig.scala52
-rw-r--r--src/scalap/scala/tools/scalap/scalax/rules/scalasig/ScalaSigPrinter.scala9
-rw-r--r--src/scalap/scala/tools/scalap/scalax/rules/scalasig/Type.scala1
-rw-r--r--src/swing/scala/swing/Button.scala3
-rw-r--r--src/swing/scala/swing/ButtonGroup.scala4
-rw-r--r--src/swing/scala/swing/ComboBox.scala2
-rw-r--r--src/swing/scala/swing/EditorPane.scala3
-rw-r--r--src/swing/scala/swing/Font.scala.disabled70
-rw-r--r--src/swing/scala/swing/FormattedTextField.scala4
-rw-r--r--src/swing/scala/swing/ListView.scala2
-rw-r--r--src/swing/scala/swing/MainFrame.scala4
-rw-r--r--src/swing/scala/swing/PasswordField.scala4
-rw-r--r--src/swing/scala/swing/ProgressBar.scala4
-rw-r--r--src/swing/scala/swing/Reactions.scala2
-rw-r--r--src/swing/scala/swing/SplitPane.scala3
-rw-r--r--src/swing/scala/swing/SwingActor.scala4
-rw-r--r--src/swing/scala/swing/TabbedPane.scala3
-rw-r--r--src/swing/scala/swing/TextArea.scala4
-rw-r--r--src/swing/scala/swing/TextComponent.scala3
-rw-r--r--src/swing/scala/swing/ToggleButton.scala3
-rw-r--r--src/swing/scala/swing/Window.scala3
-rw-r--r--test/attic/files/cli/test1/Main.check.j9vm54
-rw-r--r--test/attic/files/cli/test1/Main.check.java6
-rw-r--r--test/attic/files/cli/test1/Main.check.java56
-rw-r--r--test/attic/files/cli/test1/Main.check.java5_api19
-rw-r--r--test/attic/files/cli/test1/Main.check.java5_j94
-rw-r--r--test/attic/files/cli/test1/Main.check.javac19
-rw-r--r--test/attic/files/cli/test1/Main.check.javac524
-rw-r--r--test/attic/files/cli/test1/Main.check.javac629
-rw-r--r--test/attic/files/cli/test1/Main.check.jikes3
-rw-r--r--test/attic/files/cli/test1/Main.check.jikes53
-rw-r--r--test/attic/files/cli/test1/Main.check.scala24
-rw-r--r--test/attic/files/cli/test1/Main.check.scala_api33
-rw-r--r--test/attic/files/cli/test1/Main.check.scala_j915
-rw-r--r--test/attic/files/cli/test1/Main.check.scalac63
-rw-r--r--test/attic/files/cli/test1/Main.check.scalaint45
-rw-r--r--test/attic/files/cli/test1/Main.java8
-rw-r--r--test/attic/files/cli/test1/Main.scala8
-rw-r--r--test/attic/files/cli/test2/Main.check.j9vm54
-rw-r--r--test/attic/files/cli/test2/Main.check.java6
-rw-r--r--test/attic/files/cli/test2/Main.check.java56
-rw-r--r--test/attic/files/cli/test2/Main.check.java5_api24
-rw-r--r--test/attic/files/cli/test2/Main.check.java5_j936
-rw-r--r--test/attic/files/cli/test2/Main.check.javac27
-rw-r--r--test/attic/files/cli/test2/Main.check.javac528
-rw-r--r--test/attic/files/cli/test2/Main.check.javac633
-rw-r--r--test/attic/files/cli/test2/Main.check.jikes9
-rw-r--r--test/attic/files/cli/test2/Main.check.jikes59
-rw-r--r--test/attic/files/cli/test2/Main.check.scala24
-rw-r--r--test/attic/files/cli/test2/Main.check.scala_api37
-rw-r--r--test/attic/files/cli/test2/Main.check.scala_j915
-rw-r--r--test/attic/files/cli/test2/Main.check.scalac63
-rw-r--r--test/attic/files/cli/test2/Main.check.scalaint45
-rw-r--r--test/attic/files/cli/test2/Main.java8
-rw-r--r--test/attic/files/cli/test2/Main.scala8
-rw-r--r--test/attic/files/cli/test3/Main.check.j9vm55
-rw-r--r--test/attic/files/cli/test3/Main.check.java10
-rw-r--r--test/attic/files/cli/test3/Main.check.java510
-rw-r--r--test/attic/files/cli/test3/Main.check.java5_api29
-rw-r--r--test/attic/files/cli/test3/Main.check.java5_j936
-rw-r--r--test/attic/files/cli/test3/Main.check.javac33
-rw-r--r--test/attic/files/cli/test3/Main.check.javac531
-rw-r--r--test/attic/files/cli/test3/Main.check.javac636
-rw-r--r--test/attic/files/cli/test3/Main.check.jikes14
-rw-r--r--test/attic/files/cli/test3/Main.check.jikes514
-rw-r--r--test/attic/files/cli/test3/Main.check.scala28
-rw-r--r--test/attic/files/cli/test3/Main.check.scala_api41
-rw-r--r--test/attic/files/cli/test3/Main.check.scala_j919
-rw-r--r--test/attic/files/cli/test3/Main.check.scalac63
-rw-r--r--test/attic/files/cli/test3/Main.check.scalaint48
-rw-r--r--test/attic/files/cli/test3/Main.java10
-rw-r--r--test/attic/files/cli/test3/Main.scala10
-rw-r--r--test/disabled/buildmanager/overloaded_1/A.scala (renamed from test/files/disabled/A.scala)0
-rw-r--r--test/disabled/buildmanager/overloaded_1/overloaded_1.check (renamed from test/files/disabled/overloaded_1.check)0
-rw-r--r--test/disabled/buildmanager/overloaded_1/overloaded_1.test (renamed from test/files/disabled/overloaded_1.test)0
-rw-r--r--test/disabled/buildmanager/t4245/A.scala (renamed from test/files/disabled/t4245/A.scala)0
-rw-r--r--test/disabled/buildmanager/t4245/t4245.check (renamed from test/files/disabled/t4245/t4245.check)0
-rw-r--r--test/disabled/buildmanager/t4245/t4245.test (renamed from test/files/disabled/t4245/t4245.test)0
-rw-r--r--test/disabled/presentation/akka.flags4
-rw-r--r--test/disabled/presentation/simple-tests.opts4
-rw-r--r--test/disabled/run/t4146.scala (renamed from test/files/run/t4146.scala)2
-rw-r--r--test/files/ant/imported.xml5
-rw-r--r--test/files/bench/equality/eqeq.eqlog84
-rw-r--r--test/files/continuations-run/implicit-infer-annotations.check5
-rw-r--r--test/files/continuations-run/implicit-infer-annotations.scala59
-rw-r--r--test/files/detach-neg/det_bar.check4
-rw-r--r--test/files/detach-neg/det_bar.scala13
-rw-r--r--test/files/detach-run/actor-run.check5
-rw-r--r--test/files/detach-run/actor/Client.scala54
-rw-r--r--test/files/detach-run/actor/Server.scala27
-rw-r--r--test/files/detach-run/actor/ServerConsole.scala75
-rw-r--r--test/files/detach-run/actor/actor.flags1
-rw-r--r--test/files/detach-run/actor/actor.scala157
-rw-r--r--test/files/detach-run/actor/java.policy25
-rw-r--r--test/files/detach-run/basic-run.check5
-rw-r--r--test/files/detach-run/basic/Client.scala48
-rw-r--r--test/files/detach-run/basic/Server.scala22
-rw-r--r--test/files/detach-run/basic/ServerConsole.scala83
-rw-r--r--test/files/detach-run/basic/basic.flags1
-rw-r--r--test/files/detach-run/basic/basic.scala169
-rw-r--r--test/files/detach-run/basic/java.policy26
-rw-r--r--test/files/instrumented/t6611.check1
-rw-r--r--test/files/instrumented/t6611.scala35
-rw-r--r--test/files/jvm/t1143-2/t1143-2.scala26
-rw-r--r--test/files/jvm/t1143.scala12
-rw-r--r--test/files/jvm/t1342/SI.scala2
-rw-r--r--test/files/jvm/t1600.scala3
-rw-r--r--test/files/jvm/t2163/t2163.java (renamed from test/files/jvm/ticket2163/ticket2163.java)4
-rw-r--r--test/files/jvm/t2163/t2163.scala5
-rw-r--r--test/files/jvm/t2470.cmds3
-rw-r--r--test/files/jvm/t2570/Test.scala2
-rw-r--r--test/files/jvm/t3003.cmds2
-rw-r--r--test/files/jvm/t3415/HelloWorld.scala2
-rw-r--r--test/files/jvm/t4283/AbstractFoo.java (renamed from test/files/jvm/ticket4283/AbstractFoo.java)0
-rw-r--r--test/files/jvm/t4283/ScalaBipp.scala (renamed from test/files/jvm/ticket4283/ScalaBipp.scala)0
-rw-r--r--test/files/jvm/t4283/Test.scala (renamed from test/files/jvm/ticket4283/Test.scala)0
-rw-r--r--test/files/jvm/ticket2163/ticket2163.scala5
-rw-r--r--test/files/jvm/typerep.scala26
-rw-r--r--test/files/jvm/xmlattr.scala7
-rw-r--r--test/files/lib/jsoup-1.3.1.jar.desired.sha11
-rw-r--r--test/files/neg/abstract-inaccessible.check10
-rw-r--r--test/files/neg/ambiguous-float-dots.check23
-rw-r--r--test/files/neg/array-not-seq.check13
-rw-r--r--test/files/neg/array-not-seq.flags1
-rw-r--r--test/files/neg/array-not-seq.scala26
-rw-r--r--test/files/neg/case-collision.check10
-rw-r--r--test/files/neg/catch-all.check13
-rw-r--r--test/files/neg/check-dead.check12
-rw-r--r--test/files/neg/checksensible.check70
-rw-r--r--test/files/neg/classmanifests_new_deprecations.check24
-rw-r--r--test/files/neg/cycle-bounds.check4
-rw-r--r--test/files/neg/cycle-bounds.flags1
-rw-r--r--test/files/neg/cycle-bounds.scala5
-rw-r--r--test/files/neg/dbldef.check4
-rw-r--r--test/files/neg/exhausting.check16
-rw-r--r--test/files/neg/gadts1.check7
-rw-r--r--test/files/neg/import-precedence.check19
-rw-r--r--test/files/neg/import-precedence.scala68
-rw-r--r--test/files/neg/lubs.check9
-rw-r--r--test/files/neg/macro-deprecate-idents.check38
-rw-r--r--test/files/neg/main1.check14
-rw-r--r--test/files/neg/migration28.check4
-rw-r--r--test/files/neg/names-defaults-neg-warn.check8
-rw-r--r--test/files/neg/newpat_unreachable.check18
-rw-r--r--test/files/neg/nonlocal-warning.check10
-rw-r--r--test/files/neg/nonlocal-warning.flags (renamed from test/pending/pos/t4649.flags)0
-rw-r--r--test/files/neg/nonlocal-warning.scala18
-rw-r--r--test/files/neg/nullary-override.check4
-rw-r--r--test/files/neg/overloaded-implicit.check8
-rw-r--r--test/files/neg/overloaded-implicit.flags2
-rw-r--r--test/files/neg/package-ob-case.check4
-rw-r--r--test/files/neg/patmat-type-check.check17
-rw-r--r--test/files/neg/patmatexhaust.check24
-rw-r--r--test/files/neg/permanent-blindness.check10
-rw-r--r--test/files/neg/sealed-final-neg.check4
-rw-r--r--test/files/neg/sealed-final-neg.flags1
-rw-r--r--test/files/neg/sealed-final-neg.scala41
-rw-r--r--test/files/neg/sealed-java-enums.check4
-rw-r--r--test/files/neg/serialversionuid-not-const.check10
-rw-r--r--test/files/neg/serialversionuid-not-const.scala16
-rw-r--r--test/files/neg/stmt-expr-discard.check8
-rw-r--r--test/files/neg/switch.check8
-rw-r--r--test/files/neg/t1224.check2
-rw-r--r--test/files/neg/t1224.flags1
-rw-r--r--test/files/neg/t2442.check8
-rw-r--r--test/files/neg/t2796.check4
-rw-r--r--test/files/neg/t2968.check10
-rw-r--r--test/files/neg/t2968.scala26
-rw-r--r--test/files/neg/t2968b.check4
-rw-r--r--test/files/neg/t2968b.scala7
-rw-r--r--test/files/neg/t3098.check4
-rw-r--r--test/files/neg/t3160ambiguous.check7
-rw-r--r--test/files/neg/t3160ambiguous.scala15
-rw-r--r--test/files/neg/t3224.check28
-rwxr-xr-xtest/files/neg/t3224.scala48
-rw-r--r--test/files/neg/t3234.check6
-rw-r--r--test/files/neg/t3234.flags2
-rw-r--r--test/files/neg/t3683a.check4
-rw-r--r--test/files/neg/t4302.check4
-rw-r--r--test/files/neg/t4440.check12
-rw-r--r--test/files/neg/t4537.check4
-rw-r--r--test/files/neg/t4537/c.scala8
-rw-r--r--test/files/neg/t4691_exhaust_extractor.check10
-rw-r--r--test/files/neg/t4749.check16
-rw-r--r--test/files/neg/t4762.check8
-rw-r--r--test/files/neg/t4851.check18
-rw-r--r--test/files/neg/t5353.check4
-rw-r--r--test/files/neg/t5353.scala3
-rw-r--r--test/files/neg/t5426.check12
-rw-r--r--test/files/neg/t5663-badwarneq.check18
-rw-r--r--test/files/neg/t5692a.check2
-rw-r--r--test/files/neg/t5692b.check2
-rw-r--r--test/files/neg/t5762.check12
-rw-r--r--test/files/neg/t5830.check8
-rw-r--r--test/files/neg/t6011.check10
-rw-r--r--test/files/neg/t6048.check12
-rw-r--r--test/files/neg/t6162-inheritance.check16
-rw-r--r--test/files/neg/t6162-overriding.check8
-rw-r--r--test/files/neg/t6264.check4
-rw-r--r--test/files/neg/t6276.check16
-rw-r--r--test/files/neg/t6355.check4
-rw-r--r--test/files/neg/t6355.scala13
-rw-r--r--test/files/neg/t6406-regextract.check6
-rw-r--r--test/files/neg/t6406-regextract.flags1
-rw-r--r--test/files/neg/t6406-regextract.scala5
-rw-r--r--test/files/neg/t6426.check7
-rw-r--r--test/files/neg/t6426.scala5
-rw-r--r--test/files/neg/t6567.check9
-rw-r--r--test/files/neg/t6567.flags1
-rw-r--r--test/files/neg/t6567.scala11
-rw-r--r--test/files/neg/unchecked-abstract.check20
-rw-r--r--test/files/neg/unchecked-impossible.check8
-rw-r--r--test/files/neg/unchecked-knowable.check8
-rw-r--r--test/files/neg/unchecked-refinement.check12
-rw-r--r--test/files/neg/unchecked-suppress.check10
-rw-r--r--test/files/neg/unchecked.check16
-rw-r--r--test/files/neg/unchecked2.check32
-rw-r--r--test/files/neg/unchecked3.check31
-rw-r--r--test/files/neg/unit-returns-value.check14
-rw-r--r--test/files/neg/unit-returns-value.scala23
-rw-r--r--test/files/neg/virtpatmat_reach_null.check4
-rw-r--r--test/files/neg/virtpatmat_reach_sealed_unsealed.check12
-rw-r--r--test/files/neg/virtpatmat_unreach_select.check4
-rw-r--r--test/files/neg/warn-inferred-any.check12
-rw-r--r--test/files/neg/warn-inferred-any.flags1
-rw-r--r--test/files/neg/warn-inferred-any.scala19
-rw-r--r--test/files/neg/warn-unused-imports.check44
-rw-r--r--test/files/neg/warn-unused-imports.flags1
-rw-r--r--test/files/neg/warn-unused-imports.scala125
-rw-r--r--test/files/neg/warn-unused-privates.check63
-rw-r--r--test/files/neg/warn-unused-privates.flags1
-rw-r--r--test/files/neg/warn-unused-privates.scala105
-rw-r--r--test/files/pos/annotations.scala2
-rw-r--r--test/files/pos/attributes.scala2
-rw-r--r--test/files/pos/chang/Test.scala2
-rw-r--r--test/files/pos/cycle-jsoup.flags1
-rw-r--r--test/files/pos/cycle-jsoup.scala5
-rw-r--r--test/files/pos/cycle.flags1
-rw-r--r--test/files/pos/cycle/J_1.java16
-rw-r--r--test/files/pos/cycle/X_2.scala3
-rw-r--r--test/files/pos/exhaust_2.scala (renamed from test/pending/pos/exhaust_2.scala)0
-rw-r--r--test/files/pos/liftcode_polymorphic.scala2
-rw-r--r--test/files/pos/no-widen-locals.scala (renamed from test/pending/pos/no-widen-locals.scala)0
-rw-r--r--test/files/pos/sealed-final.flags1
-rw-r--r--test/files/pos/sealed-final.scala14
-rw-r--r--test/files/pos/spec-annotations.scala2
-rw-r--r--test/files/pos/super.cmds2
-rw-r--r--test/files/pos/t0851.scala14
-rw-r--r--test/files/pos/t0872.scala8
-rw-r--r--test/files/pos/t1029.cmds2
-rw-r--r--test/files/pos/t1107a.scala (renamed from test/files/pos/t1107.scala)0
-rw-r--r--test/files/pos/t1203a.scala (renamed from test/files/pos/t1203.scala)0
-rw-r--r--test/files/pos/t1230/S.scala2
-rw-r--r--test/files/pos/t1231/S.scala2
-rw-r--r--test/files/pos/t1385.scala4
-rw-r--r--test/files/pos/t1751/A1_2.scala (renamed from test/pending/pos/t1751/A1_2.scala)0
-rw-r--r--test/files/pos/t1751/A2_1.scala (renamed from test/pending/pos/t1751/A2_1.scala)0
-rw-r--r--test/files/pos/t1751/SuiteClasses.java (renamed from test/pending/pos/t1751/SuiteClasses.java)0
-rw-r--r--test/files/pos/t1782/Ann.java (renamed from test/pending/pos/t1782/Ann.java)0
-rw-r--r--test/files/pos/t1782/Days.java (renamed from test/pending/pos/t1782/Days.java)0
-rw-r--r--test/files/pos/t1782/ImplementedBy.java (renamed from test/pending/pos/t1782/ImplementedBy.java)0
-rw-r--r--test/files/pos/t1782/Test_1.scala (renamed from test/pending/pos/t1782/Test_1.scala)0
-rw-r--r--test/files/pos/t1942.cmds2
-rw-r--r--test/files/pos/t2464.cmds3
-rw-r--r--test/files/pos/t2726.cmds2
-rw-r--r--test/files/pos/t294/Ann.java (renamed from test/pending/pos/t294/Ann.java)0
-rw-r--r--test/files/pos/t294/Ann2.java (renamed from test/pending/pos/t294/Ann2.java)0
-rw-r--r--test/files/pos/t294/Test_1.scala (renamed from test/pending/pos/t294/Test_1.scala)0
-rw-r--r--test/files/pos/t294/Test_2.scala (renamed from test/pending/pos/t294/Test_2.scala)0
-rw-r--r--test/files/pos/t3160.scala6
-rw-r--r--test/files/pos/t3577.scala29
-rw-r--r--test/files/pos/t4649.flags1
-rw-r--r--test/files/pos/t4649.scala (renamed from test/pending/pos/t4649.scala)0
-rw-r--r--test/files/pos/t4744.flags1
-rw-r--r--test/files/pos/t4744/Bar.scala1
-rw-r--r--test/files/pos/t4744/Foo.java1
-rw-r--r--test/files/pos/t4786.scala (renamed from test/pending/pos/t4786.scala)0
-rw-r--r--test/files/pos/t5130.scala46
-rw-r--r--test/files/pos/t5399a.scala (renamed from test/pending/pos/t5399a.scala)0
-rw-r--r--test/files/pos/t5604b/T_1.scala6
-rw-r--r--test/files/pos/t5604b/T_2.scala6
-rw-r--r--test/files/pos/t5604b/Test_1.scala7
-rw-r--r--test/files/pos/t5604b/Test_2.scala7
-rw-r--r--test/files/pos/t5604b/pack_1.scala5
-rw-r--r--test/files/pos/t5606.scala (renamed from test/pending/pos/t5606.scala)0
-rw-r--r--test/files/pos/t5639/Bar.scala (renamed from test/pending/pos/t5639/Bar.scala)0
-rw-r--r--test/files/pos/t5639/Foo.scala (renamed from test/pending/pos/t5639/Foo.scala)0
-rw-r--r--test/files/pos/t5809.scala3
-rw-r--r--test/files/pos/t5858.scala3
-rw-r--r--test/files/pos/t5859.scala15
-rw-r--r--test/files/pos/t6072.scala3
-rw-r--r--test/files/pos/t6301.scala9
-rw-r--r--test/files/pos/t640.scala4
-rw-r--r--test/files/pos/t6447.scala18
-rw-r--r--test/files/pos/t6482.scala11
-rw-r--r--test/files/pos/t6595.flags1
-rw-r--r--test/files/pos/t6595.scala18
-rw-r--r--test/files/pos/t6664.scala4
-rw-r--r--test/files/pos/t6664b.scala5
-rw-r--r--test/files/pos/t715.cmds2
-rw-r--r--test/files/pos/t715/meredith_1.scala58
-rw-r--r--test/files/pos/t715/runner_2.scala2
-rw-r--r--test/files/pos/ticket2251.scala14
-rw-r--r--test/files/presentation/ide-bug-1000531.check2
-rw-r--r--test/files/run/collection-stacks.check14
-rw-r--r--test/files/run/collection-stacks.scala38
-rw-r--r--test/files/run/compiler-asSeenFrom.scala18
-rw-r--r--test/files/run/constant-type.check8
-rw-r--r--test/files/run/constant-type.scala8
-rw-r--r--test/files/run/deeps.check87
-rw-r--r--test/files/run/deeps.scala114
-rw-r--r--test/files/run/existentials-in-compiler.scala2
-rw-r--r--test/files/run/lub-visibility.check2
-rw-r--r--test/files/run/no-pickle-skolems.check1
-rw-r--r--test/files/run/no-pickle-skolems/Source_1.scala5
-rw-r--r--test/files/run/no-pickle-skolems/Test_2.scala37
-rw-r--r--test/files/run/parserJavaIdent.check26
-rw-r--r--test/files/run/parserJavaIdent.scala26
-rw-r--r--test/files/run/reify_implicits-new.check (renamed from test/pending/run/reify_implicits-new.check)0
-rw-r--r--test/files/run/reify_implicits-new.scala (renamed from test/pending/run/reify_implicits-new.scala)0
-rw-r--r--test/files/run/reify_implicits-old.check (renamed from test/pending/run/reify_implicits-old.check)0
-rw-r--r--test/files/run/reify_implicits-old.scala (renamed from test/pending/run/reify_implicits-old.scala)0
-rw-r--r--test/files/run/reify_newimpl_11.check6
-rw-r--r--test/files/run/reify_newimpl_13.check6
-rw-r--r--test/files/run/reify_newimpl_19.check6
-rw-r--r--test/files/run/repl-colon-type.check4
-rw-r--r--test/files/run/repl-out-dir.check53
-rw-r--r--test/files/run/repl-out-dir.scala13
-rw-r--r--test/files/run/search.check6
-rw-r--r--test/files/run/search.scala14
-rw-r--r--test/files/run/settings-parse.check566
-rw-r--r--test/files/run/settings-parse.scala27
-rw-r--r--test/files/run/shortClass.check10
-rw-r--r--test/files/run/shortClass.scala24
-rw-r--r--test/files/run/streams.check1
-rw-r--r--test/files/run/streams.scala5
-rw-r--r--test/files/run/t0091.check1
-rw-r--r--test/files/run/t0091.scala15
-rw-r--r--test/files/run/t1500.scala2
-rw-r--r--test/files/run/t1501.scala2
-rw-r--r--test/files/run/t2251.check1
-rw-r--r--test/files/run/t2251.scala19
-rw-r--r--test/files/run/t2251b.check11
-rw-r--r--test/files/run/t2251b.scala48
-rw-r--r--test/files/run/t2318.check (renamed from test/pending/run/t2318.check)0
-rw-r--r--test/files/run/t2318.scala (renamed from test/pending/run/t2318.scala)3
-rw-r--r--test/files/run/t2418.check1
-rw-r--r--test/files/run/t2418.scala10
-rw-r--r--test/files/run/t2886.check4
-rw-r--r--test/files/run/t3038d.scala4
-rw-r--r--test/files/run/t3667.check3
-rw-r--r--test/files/run/t3667.scala35
-rw-r--r--test/files/run/t3897.check (renamed from test/pending/run/t3897.check)0
-rw-r--r--test/files/run/t3897/J_2.java (renamed from test/pending/run/t3897/J_2.java)0
-rw-r--r--test/files/run/t3897/a_1.scala (renamed from test/pending/run/t3897/a_1.scala)0
-rw-r--r--test/files/run/t3897/a_2.scala (renamed from test/pending/run/t3897/a_2.scala)0
-rw-r--r--test/files/run/t4023.check21
-rw-r--r--test/files/run/t4023.scala23
-rw-r--r--test/files/run/t4047.scala2
-rw-r--r--test/files/run/t4537.check1
-rw-r--r--test/files/run/t4537/a.scala (renamed from test/files/neg/t4537/a.scala)4
-rw-r--r--test/files/run/t4537/b.scala (renamed from test/files/neg/t4537/b.scala)4
-rw-r--r--test/files/run/t4537/c.scala8
-rw-r--r--test/files/run/t4537/d.scala6
-rw-r--r--test/files/run/t4729.check4
-rw-r--r--test/files/run/t4729/J_1.java4
-rw-r--r--test/files/run/t4729/S_2.scala29
-rw-r--r--test/files/run/t4935.flags2
-rw-r--r--test/files/run/t4996.check4
-rw-r--r--test/files/run/t4996.scala47
-rw-r--r--test/files/run/t5293-map.scala (renamed from test/pending/run/t5293-map.scala)0
-rw-r--r--test/files/run/t5293.scala (renamed from test/pending/run/t5293.scala)0
-rw-r--r--test/files/run/t5374.check3
-rw-r--r--test/files/run/t5374.scala46
-rw-r--r--test/files/run/t5418.check (renamed from test/pending/run/t5418.check)0
-rw-r--r--test/files/run/t5418.scala (renamed from test/pending/run/t5418.scala)0
-rw-r--r--test/files/run/t5604.check8
-rw-r--r--test/files/run/t5604.scala50
-rw-r--r--test/files/run/t5610a.check (renamed from test/pending/run/t5610a.check)0
-rw-r--r--test/files/run/t5610a.scala (renamed from test/pending/run/t5610a.scala)0
-rw-r--r--test/files/run/t6028.check20
-rw-r--r--test/files/run/t6064.scala9
-rw-r--r--test/files/run/t6150.scala8
-rw-r--r--test/files/run/t6154.check1
-rw-r--r--test/files/run/t6154.scala10
-rw-r--r--test/files/run/t6206.check4
-rw-r--r--test/files/run/t6206.scala37
-rw-r--r--test/files/run/t6223.check2
-rw-r--r--test/files/run/t6223.scala2
-rw-r--r--test/files/run/t6288.check2
-rw-r--r--test/files/run/t6381.check17
-rw-r--r--test/files/run/t6381.scala13
-rw-r--r--test/files/run/t6406-regextract.check4
-rw-r--r--test/files/run/t6406-regextract.scala30
-rw-r--r--test/files/run/t6448.check32
-rw-r--r--test/files/run/t6448.scala61
-rw-r--r--test/files/run/t6467.scala20
-rw-r--r--test/files/run/t6584.check8
-rw-r--r--test/files/run/t6584.scala16
-rw-r--r--test/files/run/t6611.scala61
-rw-r--r--test/files/run/t6637.check1
-rw-r--r--test/files/run/t6637.scala8
-rw-r--r--test/files/run/t6745-2.scala22
-rw-r--r--test/flaky/pos/t2868.cmds3
-rwxr-xr-xtest/partest8
-rw-r--r--test/pending/jvm/cf-attributes.scala26
-rw-r--r--test/pending/pos/overloading-boundaries.scala37
-rw-r--r--test/pending/pos/t1751.cmds3
-rw-r--r--test/pending/pos/t1782.cmds2
-rw-r--r--test/pending/pos/t1832.scala10
-rw-r--r--test/pending/pos/t294.cmds3
-rw-r--r--test/pending/pos/t4612.scala15
-rw-r--r--test/pending/pos/t4695/T_1.scala4
-rw-r--r--test/pending/pos/t4695/T_2.scala4
-rw-r--r--test/pending/pos/t4717.scala7
-rw-r--r--test/pending/pos/t5082.scala8
-rw-r--r--test/pending/pos/t5259.scala14
-rw-r--r--test/pending/pos/t5399.scala8
-rw-r--r--test/pending/pos/t5626.scala12
-rw-r--r--test/pending/pos/t5654.scala4
-rw-r--r--test/pending/pos/t5877.scala5
-rw-r--r--test/pending/pos/t5954/T_1.scala8
-rw-r--r--test/pending/pos/t5954/T_2.scala8
-rw-r--r--test/pending/pos/t5954/T_3.scala8
-rw-r--r--test/pending/pos/t6225.scala11
-rw-r--r--test/pending/pos/z1720.scala16
-rw-r--r--test/postreview.py2540
-rwxr-xr-xtest/review44
-rw-r--r--test/scaladoc/resources/links.scala2
-rw-r--r--test/scaladoc/run/links.scala2
-rw-r--r--test/scaladoc/scalacheck/HtmlFactoryTest.scala2
-rwxr-xr-xtools/binary-repo-lib.sh2
-rwxr-xr-xtools/buildcp2
-rwxr-xr-xtools/make-release-notes49
-rw-r--r--tools/make-release-notes.scala129
-rwxr-xr-xtools/partest-ack71
-rwxr-xr-xtools/strapcp3
1174 files changed, 17025 insertions, 55774 deletions
diff --git a/.gitattributes b/.gitattributes
index 958b0b9f28..ac98781b3d 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1,10 +1,16 @@
+# fallback on built-in heuristics
+# this must be first so later entries will override it
+* text=auto
+
# These files are text and should be normalized (convert crlf => lf)
*.c text
*.check text
*.css text
+*.flags text
*.html text
*.java text
*.js text
+*.policy text
*.sbt text
*.scala text
*.sh text
diff --git a/.mailmap b/.mailmap
index 49d5dc6629..1b33a40de9 100644
--- a/.mailmap
+++ b/.mailmap
@@ -1,8 +1,8 @@
+Aleksandar Prokopec <aleksandar.prokopec@epfl.ch>
Aleksandar Prokopec <aleksandar@aleksandar-Latitude-E6500.(none)>
-Aleksandar Prokopec <aleksandar@htpc.(none)>
Aleksandar Prokopec <aleksandar@htpc-axel22.(none)>
+Aleksandar Prokopec <aleksandar@htpc.(none)>
Aleksandar Prokopec <aleksandar@lampmac14.epfl.ch>
-Aleksandar Prokopec <aleksandar.prokopec@epfl.ch>
Antonio Cunei <antonio.cunei@typesafe.com>
Caoyuan Deng <dcaoyuan@epfl.ch>
Chris Hodapp <clhodapp1@gmail.com>
@@ -10,6 +10,7 @@ Chris James <chrisJames@epfl.ch>
Christopher Vogt <vogt@epfl.ch>
Damien Obristi <damien.obrist@gmail.com>
Daniel C. Sobral <dcs@dcs-132-CK-NF79.(none)>
+Daniel C. Sobral <dcs@dcs-132-CK-NF79.(none)>
Ilya Sergei <ilyas@epfl.ch>
Ingo Maier <ingoem@gmail.com>
Kenji Yoshida <6b656e6a69@gmail.com>
@@ -19,6 +20,7 @@ Nada Amin <amin@epfl.ch>
Nada Amin <nada.amin@epfl.ch>
Natallie Baikevich <lu-a-jalla@ya.ru>
Pavel Pavlov <pavel.e.pavlov@gmail.com>
+Pavel Pavlov <pavel.e.pavlov@gmail.com>
Philipp Haller <philipp.haller@typesafe.com>
Roland Kuhn <rk@rkuhn.info>
Rüdiger Klaehn <rklaehn@gmail.com>
diff --git a/META-INF/MANIFEST.MF b/META-INF/MANIFEST.MF
index 28a70d2879..4dd69827c3 100644
--- a/META-INF/MANIFEST.MF
+++ b/META-INF/MANIFEST.MF
@@ -7,9 +7,7 @@ Eclipse-LazyStart: true
Bundle-ClassPath:
.,
bin,
- lib/fjbg.jar,
lib/jline.jar,
- lib/msil.jar
Export-Package:
scala.tools.nsc,
scala.tools.nsc.ast,
@@ -47,11 +45,6 @@ Export-Package:
scala.reflect.runtime,
scala.reflect.internal.transform,
scala.reflect.api,
- ch.epfl.lamp.compiler.msil,
- ch.epfl.lamp.compiler.msil.emit,
- ch.epfl.lamp.compiler.msil.util,
- ch.epfl.lamp.fjbg,
- ch.epfl.lamp.util
Require-Bundle:
org.apache.ant,
org.scala-ide.scala.library
diff --git a/README.rst b/README.rst
index 72c4b6028b..7a1ed1dcf4 100644
--- a/README.rst
+++ b/README.rst
@@ -18,7 +18,6 @@ build script or user-created if needed. This is not a complete listing. ::
+--dist/ The destination folder for Scala distributions.
+--docs/ Documentation and sample code.
+--lib/ Pre-compiled libraries for the build.
- | +--fjbg.jar The Java byte-code generation library.
| +--scala-compiler.jar The stable reference ('starr') compiler jar
| +--scala-library.jar The stable reference ('starr') library jar
| +--scala-library-src.jar A snapshot of the source used to build starr.
diff --git a/build.detach.xml b/build.detach.xml
deleted file mode 100644
index 132c812a26..0000000000
--- a/build.detach.xml
+++ /dev/null
@@ -1,186 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<project name="sabbus" default="build">
-
- <description>
-SuperSabbus for Scala detach plugin.
- </description>
-
- <echo level="info" message="Running SABBUS for ${ant.project.name}..."/>
-
-<!-- ===========================================================================
-END-USER TARGETS
-============================================================================ -->
-
- <target name="build" depends="pack.done"
- description="Builds the Scala detach plugin."/>
-
- <target name="clean" depends="quick.clean">
- </target>
-
- <target name="all.clean" depends="quick.clean, pack.clean">
- </target>
-
-<!-- ===========================================================================
-PROPERTIES
-============================================================================ -->
-
- <property environment="env"/>
- <!-- Prevents system classpath from being used -->
- <property name="build.sysclasspath" value="ignore"/>
-
- <!-- Defines the repository layout -->
- <property name="lib.dir" value="${basedir}/lib"/>
- <property name="src.dir" value="${basedir}/src"/>
- <property name="partest.dir" value="${basedir}/test"/>
-
- <!-- Loads custom properties definitions -->
- <property file="${basedir}/build.properties"/>
-
- <!-- Sets location of build folders -->
- <property name="build.dir" value="${basedir}/build"/>
- <property name="build-quick.dir" value="${build.dir}/quick"/>
- <property name="build-pack.dir" value="${build.dir}/pack"/>
-
- <!-- if ANT_OPTS is already set by the environment, it will be unaltered,
- but if it is unset it will take this default value. -->
- <property name="env.ANT_OPTS" value="-Xms1024M -Xmx1024M -Xss1M -XX:MaxPermSize=128M -XX:+UseParallelGC" />
-
- <property
- name="scalacfork.jvmargs"
- value="${env.ANT_OPTS}"/>
-
- <property name="scalac.args.quick" value="-deprecation"/>
- <property name="scalac.args.optimise" value=""/>
-
- <!-- Setting-up Ant contrib tasks -->
- <taskdef resource="net/sf/antcontrib/antlib.xml" classpath="${lib.dir}/ant/ant-contrib.jar"/>
-
-<!-- ===========================================================================
-QUICK BUILD (QUICK)
-============================================================================ -->
-
- <target name="quick.clean">
- <delete includeemptydirs="yes" quiet="yes" failonerror="no">
- <fileset dir="${build-quick.dir}/classes/detach-library"/>
- <fileset dir="${build-quick.dir}/classes/detach-plugin"/>
- </delete>
- </target>
-
- <target name="quick.done">
- <stopwatch name="quick.done.timer"/>
- <path id="quick.classpath">
- <pathelement location="${build-quick.dir}/classes/library"/>
- <pathelement location="${build-quick.dir}/classes/compiler"/>
- <pathelement location="${lib.dir}/fjbg.jar"/>
- <pathelement location="${lib.dir}/msil.jar"/>
- <pathelement location="${lib.dir}/forkjoin.jar"/>
- <pathelement location="${ant.home}/lib/ant.jar"/>
- </path>
- <taskdef
- resource="scala/tools/ant/sabbus/antlib.xml"
- classpathref="quick.classpath"
- />
- <mkdir dir="${build-quick.dir}/classes/detach-plugin"/>
- <scalacfork
- destdir="${build-quick.dir}/classes/detach-plugin"
- compilerpathref="quick.classpath"
- params="${scalac.args.quick}"
- srcdir="${src.dir}/detach/plugin"
- jvmargs="${scalacfork.jvmargs}">
- <include name="**/*.scala"/>
- <compilationpath>
- <pathelement location="${build-quick.dir}/classes/library"/>
- <pathelement location="${build-quick.dir}/classes/compiler"/>
- <pathelement location="${build-quick.dir}/classes/detach-plugin"/>
- <pathelement location="${lib.dir}/forkjoin.jar"/>
- </compilationpath>
- </scalacfork>
- <copy
- file="${src.dir}/detach/plugin/scalac-plugin.xml"
- todir="${build-quick.dir}/classes/detach-plugin"
- />
- <mkdir dir="${build-quick.dir}/classes/detach-library"/>
- <scalacfork
- destdir="${build-quick.dir}/classes/detach-library"
- compilerpathref="quick.classpath"
- params="${scalac.args.quick}"
- srcdir="${src.dir}/detach/library"
- jvmargs="${scalacfork.jvmargs}">
- <include name="**/*.scala"/>
- <compilationpath>
- <pathelement location="${build-quick.dir}/classes/library"/>
- <pathelement location="${lib.dir}/forkjoin.jar"/>
- </compilationpath>
- </scalacfork>
- <touch file="${build-quick.dir}/plugins.complete" verbose="no"/>
- <stopwatch name="quick.done.timer" action="total"/>
- </target>
-
-<!-- ===========================================================================
-PACKED QUICK BUILD (PACK)
-============================================================================ -->
-
- <target name="pack.start" depends="quick.done"/>
-
- <target name="pack.pre-lib" depends="pack.start">
- <uptodate
- property="pack.lib.available"
- targetfile="${build-pack.dir}/lib/scala-detach.jar"
- srcfile="${build-quick.dir}/plugins.complete"/>
- </target>
-
- <target name="pack.lib" depends="pack.pre-lib" unless="pack.lib.available">
- <mkdir dir="${build-pack.dir}/misc/scala-devel/plugins"/>
- <jar destfile="${build-pack.dir}/misc/scala-devel/plugins/detach.jar">
- <fileset dir="${build-quick.dir}/classes/detach-plugin"/>
- </jar>
- <mkdir dir="${build-pack.dir}/lib"/>
- <jar destfile="${build-pack.dir}/lib/scala-detach.jar">
- <fileset dir="${build-quick.dir}/classes/detach-library">
- <include name="scala/**"/>
- </fileset>
- </jar>
- </target>
-
- <target name="pack.done" depends="pack.lib">
- <path id="pack.classpath">
- <pathelement location="${build-pack.dir}/lib/scala-library.jar"/>
- <pathelement location="${build-pack.dir}/lib/scala-compiler.jar"/>
- <pathelement location="${build-pack.dir}/lib/scala-detach.jar"/>
- <pathelement location="${build-pack.dir}/lib/scala-partest.jar"/>
- <pathelement location="${build-pack.dir}/lib/scalap.jar"/>
- <pathelement location="${ant.home}/lib/ant.jar"/>
- <pathelement location="${lib.dir}/jline.jar"/>
- </path>
- <taskdef resource="scala/tools/ant/antlib.xml" classpathref="pack.classpath"/>
- <taskdef resource="scala/tools/partest/antlib.xml" classpathref="pack.classpath"/>
- </target>
-
- <target name="pack.clean">
- <delete includeemptydirs="yes" quiet="yes" failonerror="no">
- <fileset dir="${build-pack.dir}/lib" includes="scala-detach.jar"/>
- <fileset dir="${build-pack.dir}/misc/scala-devel/plugins" includes="detach.jar"/>
- </delete>
- </target>
-
-<!-- ===========================================================================
-TEST SUITE
-============================================================================ -->
-
- <target name="test.suite" depends="pack.done">
- <property name="partest.srcdir" value="files" />
- <partest showlog="yes" erroronfailed="yes" javacmd="${java.home}/bin/java"
- timeout="2400000"
- srcdir="${partest.srcdir}"
- scalacopts="${scalac.args.optimise} -Xpluginsdir ${build-pack.dir}/misc/scala-devel/plugins -Xplugin-require:detach -P:detach:enable">
- <compilationpath>
- <path refid="pack.classpath"/>
- <fileset dir="${partest.dir}/files/lib" includes="*.jar" />
- </compilationpath>
- <negtests dir="${partest.dir}/${partest.srcdir}/detach-neg" includes="*.scala"/>
- <runtests dir="${partest.dir}/${partest.srcdir}/detach-run" includes="*.scala"/>
- </partest>
- </target>
-
-</project>
diff --git a/build.examples.xml b/build.examples.xml
index 62210d5ece..82432121ca 100644
--- a/build.examples.xml
+++ b/build.examples.xml
@@ -28,10 +28,6 @@ PROPERTIES
<!-- Location of pre-compiled libraries properties -->
<property name="scala.lib.jar" value="${lib.dir}/scala-library.jar"/>
<property name="scala.comp.jar" value="${lib.dir}/scala-compiler.jar"/>
- <property name="fjbg.name" value="fjbg.jar"/>
- <property name="fjbg.jar" value="${lib.dir}/${fjbg.name}"/>
- <property name="msil.name" value="msil.jar"/>
- <property name="msil.jar" value="${lib.dir}/${msil.name}"/>
<property name="ant.jar" value="${ant.home}/lib/ant.jar"/>
<property name="ant-contrib.jar" value="${lib.dir}/ant/ant-contrib.jar"/>
<!-- -->
@@ -59,7 +55,7 @@ INITIALISATION
<fail message="Scala library in '${lib.dir}/' is not available">
<condition><not><and>
<available
- classname="scala.Predef"
+ classname="scala.Predef"
classpath="${scala.lib.jar}"
/>
<available
@@ -81,24 +77,6 @@ INITIALISATION
/>
</not></condition>
</fail>
- <echo level="verbose" message="fjbg.jar=${fjbg.jar}"/>
- <fail message="FJBG library in '${lib.dir}/' is not available">
- <condition><not>
- <available
- classname="ch.epfl.lamp.fjbg.JCode"
- classpath="${fjbg.jar}"
- />
- </not></condition>
- </fail>
- <echo level="verbose" message="msil.jar=${msil.jar}"/>
- <fail message="MSIL library in '${lib.dir}/' is not available">
- <condition><not>
- <available
- classname="ch.epfl.lamp.compiler.msil.MemberInfo"
- classpath="${msil.jar}"
- />
- </not></condition>
- </fail>
<echo level="verbose" message="ant.jar=${ant.jar}"/>
<echo level="verbose" message="ant-contrib.jar=${ant-contrib.jar}"/>
<fail message="Additional Ant tasks in '${lib.dir}/' is not available">
@@ -110,14 +88,9 @@ INITIALISATION
</not></condition>
</fail>
<!-- Creating class-pathes -->
- <path id="common.classpath">
- <pathelement location="${fjbg.jar}"/>
- <pathelement location="${msil.jar}"/>
- </path>
<path id="scala.classpath">
<pathelement location="${scala.lib.jar}"/>
<pathelement location="${scala.comp.jar}"/>
- <path refid="common.classpath"/>
</path>
<!-- Creating boot-level tasks -->
<taskdef resource="net/sf/antcontrib/antlib.xml">
diff --git a/build.number b/build.number
index f28886751b..51674b6915 100644
--- a/build.number
+++ b/build.number
@@ -1,7 +1,7 @@
#Tue Sep 11 19:21:09 CEST 2007
version.major=2
-version.minor=10
-version.patch=1
+version.minor=11
+version.patch=0
# This is the -N part of a version. if it's 0, it's dropped from maven versions.
version.bnum=0
diff --git a/build.number.maven b/build.number.maven
index eed9f3897c..a8da54397d 100644
--- a/build.number.maven
+++ b/build.number.maven
@@ -1,3 +1,3 @@
version.major=2
-version.minor=10
+version.minor=11
version.patch=0
diff --git a/build.xml b/build.xml
index 6a7422a3d9..6048f0f3fa 100644
--- a/build.xml
+++ b/build.xml
@@ -203,7 +203,6 @@ PROPERTIES
<!-- Sets location of pre-compiled libraries -->
<property name="lib.starr.jar" value="${lib.dir}/scala-library.jar"/>
- <property name="msil.starr.jar" value="${lib.dir}/msil.jar"/>
<property name="reflect.starr.jar" value="${lib.dir}/scala-reflect.jar"/>
<property name="comp.starr.jar" value="${lib.dir}/scala-compiler.jar"/>
<property name="jline.jar" value="${lib.dir}/jline.jar"/>
@@ -461,9 +460,7 @@ INITIALISATION
<!-- Libraries only used for STARR -->
<path id="starr.dep.libs">
<fileset dir="${lib.dir}">
- <include name="fjbg.jar"/>
<include name="forkjoin.jar"/>
- <include name="msil.jar"/>
</fileset>
</path>
<!-- Auxiliary libs placed on every classpath. -->
@@ -593,57 +590,10 @@ LOCAL DEPENDENCY (FORKJOIN)
</target>
<!-- ===========================================================================
-LOCAL DEPENDENCY (FJBG)
-============================================================================ -->
-
- <target name="fjbg.init" depends="init">
- <uptodate property="fjbg.available" targetfile="${build-libs.dir}/fjbg.complete">
- <srcfiles dir="${src.dir}/fjbg">
- <include name="**/*.java"/>
- <include name="**/*.scala"/>
- </srcfiles>
- </uptodate>
- </target>
-
- <target name="fjbg.lib" depends="fjbg.init" unless="fjbg.available">
- <stopwatch name="fjbg.lib.timer" />
- <mkdir dir="${build-libs.dir}/classes/fjbg"/>
- <javac
- srcdir="${src.dir}/fjbg"
- destdir="${build-libs.dir}/classes/fjbg"
- classpath="${build-libs.dir}/classes/fjbg"
- includes="**/*.java"
- debug="true"
- target="1.6" source="1.4">
- <compilerarg line="${javac.args} -XDignore.symbol.file"/>
- </javac>
- <touch file="${build-libs.dir}/fjbg.complete" verbose="no"/>
- <stopwatch name="fjbg.lib.timer" action="total"/>
- </target>
-
- <target name="fjbg.pack" depends="fjbg.lib">
- <jar destfile="${build-libs.dir}/fjbg.jar">
- <fileset dir="${build-libs.dir}/classes/fjbg"/>
- </jar>
- </target>
-
- <target name="fjbg.done" depends="fjbg.pack">
- <!-- TODO - jar or classfiles? -->
- <path id="fjbg.classpath">
- <pathelement location="${build-libs.dir}/classes/fjbg"/>
- </path>
- </target>
-
- <target name="fjbg.clean" depends="init">
- <delete dir="${build-libs.dir}/classes/fjbg" includeemptydirs="yes" quiet="yes" failonerror="no"/>
- <delete file="${build-libs.dir}/fjbg.complete" quiet="yes" failonerror="no"/>
- </target>
-
-<!-- ===========================================================================
LOCAL REFERENCE BUILD (LOCKER)
============================================================================ -->
- <target name="locker.start" depends="asm.done, forkjoin.done, fjbg.done">
+ <target name="locker.start" depends="asm.done, forkjoin.done">
<condition property="locker.available">
<available file="${build-locker.dir}/all.complete"/>
</condition>
@@ -669,9 +619,6 @@ LOCAL REFERENCE BUILD (LOCKER)
<pathelement location="${build-locker.dir}/classes/library"/>
</classpath>
</javac>
- <!-- NOTE: Potential problem with maximal command line length on Windows
- (32768 characters for XP, since executed with Java's "exec"). See
- src/build/msil.xml in msil branch for more details. -->
<scalacfork
destdir="${build-locker.dir}/classes/library"
compilerpathref="starr.classpath"
@@ -761,43 +708,6 @@ LOCAL REFERENCE BUILD (LOCKER)
<target name="locker.comp" depends="locker.pre-comp" if="locker.comp.needed">
<stopwatch name="locker.comp.timer"/>
<mkdir dir="${build-locker.dir}/classes/compiler"/>
- <if>
- <equals arg1="${fastlocker}" arg2="true" />
- <then>
- <!-- Fastlocker build: don't compile MSIL, use its starr version.... -->
- <property name="locker.comp.msil" value="${msil.starr.jar}"/>
- </then>
- <else>
- <!-- Regular build: Compile MSIL inside of locker.... -->
- <javac
- srcdir="${src.dir}/msil"
- destdir="${build-locker.dir}/classes/compiler"
- classpath="${build-locker.dir}/classes/compiler"
- includes="**/*.java"
- excludes="**/tests/**"
- debug="true"
- target="1.6" source="1.4">
- <compilerarg line="${javac.args}"/>
- </javac>
- <scalacfork
- destdir="${build-locker.dir}/classes/compiler"
- compilerpathref="starr.classpath"
- params="${scalac.args.all}"
- srcdir="${src.dir}/msil"
- jvmargs="${scalacfork.jvmargs}">
- <include name="**/*.scala"/>
- <compilationpath>
- <pathelement location="${build-locker.dir}/classes/library"/>
- <pathelement location="${build-locker.dir}/classes/reflect"/>
- <pathelement location="${build-locker.dir}/classes/compiler"/>
- <path refid="fjbg.classpath"/>
- <path refid="aux.libs"/>
- <pathelement location="${jline.jar}"/>
- </compilationpath>
- </scalacfork>
- <property name="locker.comp.msil" value="${build-locker.dir}/classes/compiler"/>
- </else>
- </if>
<scalacfork
destdir="${build-locker.dir}/classes/compiler"
compilerpathref="starr.classpath"
@@ -809,10 +719,8 @@ LOCAL REFERENCE BUILD (LOCKER)
<pathelement location="${build-locker.dir}/classes/library"/>
<pathelement location="${build-locker.dir}/classes/reflect"/>
<pathelement location="${build-locker.dir}/classes/compiler"/>
- <path refid="fjbg.classpath"/>
<path refid="aux.libs"/>
<path refid="asm.classpath"/>
- <pathelement location="${locker.comp.msil}" />
<pathelement location="${jline.jar}"/>
</compilationpath>
</scalacfork>
@@ -845,7 +753,6 @@ LOCAL REFERENCE BUILD (LOCKER)
<pathelement location="${build-locker.dir}/classes/library"/>
<pathelement location="${build-locker.dir}/classes/reflect"/>
<pathelement location="${build-locker.dir}/classes/compiler"/>
- <path refid="fjbg.classpath"/>
<path refid="forkjoin.classpath"/>
<path refid="asm.classpath"/>
<path refid="aux.libs"/>
@@ -855,7 +762,6 @@ LOCAL REFERENCE BUILD (LOCKER)
<pathelement location="${build-quick.dir}/classes/library"/>
<pathelement location="${build-quick.dir}/classes/reflect"/>
<pathelement location="${build-quick.dir}/classes/compiler"/>
- <path refid="fjbg.classpath"/>
<path refid="forkjoin.classpath"/>
<path refid="asm.classpath"/>
<path refid="aux.libs"/>
@@ -953,7 +859,6 @@ PACKED LOCKER BUILD (PALO)
<jar destfile="${build-palo.dir}/lib/scala-compiler.jar" manifest="${basedir}/META-INF/MANIFEST.MF">
<fileset dir="${build-locker.dir}/classes/compiler"/>
<fileset dir="${build-asm.dir}/classes/"/>
- <fileset dir="${build-libs.dir}/classes/fjbg"/>
</jar>
<copy file="${jline.jar}" toDir="${build-palo.dir}/lib"/>
</target>
@@ -1163,33 +1068,6 @@ QUICK BUILD (QUICK)
<target name="quick.comp" depends="quick.pre-comp" unless="quick.comp.available">
<stopwatch name="quick.comp.timer"/>
<mkdir dir="${build-quick.dir}/classes/compiler"/>
- <!-- Compile MSIL inside of quick.... -->
- <javac
- srcdir="${src.dir}/msil"
- destdir="${build-quick.dir}/classes/compiler"
- classpath="${build-quick.dir}/classes/compiler"
- includes="**/*.java"
- excludes="**/tests/**"
- debug="true"
- target="1.6" source="1.4">
- <compilerarg line="${javac.args}"/>
- </javac>
- <scalacfork
- destdir="${build-quick.dir}/classes/compiler"
- compilerpathref="locker.classpath"
- params="${scalac.args.all}"
- srcdir="${src.dir}/msil"
- jvmargs="${scalacfork.jvmargs}">
- <include name="**/*.scala"/>
- <compilationpath>
- <pathelement location="${build-quick.dir}/classes/library"/>
- <pathelement location="${build-quick.dir}/classes/reflect"/>
- <pathelement location="${build-quick.dir}/classes/compiler"/>
- <path refid="fjbg.classpath"/>
- <path refid="aux.libs"/>
- <pathelement location="${jline.jar}"/>
- </compilationpath>
- </scalacfork>
<scalacfork
destdir="${build-quick.dir}/classes/compiler"
compilerpathref="locker.classpath"
@@ -1203,7 +1081,6 @@ QUICK BUILD (QUICK)
<pathelement location="${build-quick.dir}/classes/compiler"/>
<path refid="aux.libs"/>
<path refid="forkjoin.classpath"/>
- <path refid="fjbg.classpath"/>
<path refid="asm.classpath"/>
<pathelement location="${jline.jar}"/>
</compilationpath>
@@ -1254,7 +1131,6 @@ QUICK BUILD (QUICK)
<pathelement location="${build-quick.dir}/classes/compiler"/>
<pathelement location="${build-quick.dir}/classes/continuations-plugin"/>
<path refid="forkjoin.classpath"/>
- <path refid="fjbg.classpath"/>
<path refid="aux.libs"/>
</compilationpath>
</scalacfork>
@@ -1376,7 +1252,6 @@ QUICK BUILD (QUICK)
<pathelement location="${build-quick.dir}/classes/partest"/>
<pathelement location="${ant.jar}"/>
<path refid="forkjoin.classpath"/>
- <path refid="fjbg.classpath"/>
<pathelement location="${scalacheck.jar}"/>
</compilationpath>
</scalacfork>
@@ -1406,7 +1281,6 @@ QUICK BUILD (QUICK)
<pathelement location="${build-quick.dir}/classes/compiler"/>
<pathelement location="${build-quick.dir}/classes/scalap"/>
<path refid="forkjoin.classpath"/>
- <path refid="fjbg.classpath"/>
<path refid="aux.libs"/>
<path refid="asm.classpath"/>
<pathelement location="${jline.jar}"/>
@@ -1533,7 +1407,6 @@ PACKED QUICK BUILD (PACK)
<jar destfile="${build-pack.dir}/lib/scala-compiler.jar" manifest="${build-pack.dir}/META-INF/MANIFEST.MF">
<fileset dir="${build-quick.dir}/classes/compiler"/>
<fileset dir="${build-asm.dir}/classes"/>
- <fileset dir="${build-libs.dir}/classes/fjbg"/>
</jar>
<copy file="${jline.jar}" toDir="${build-pack.dir}/lib"/>
<copy todir="${build-pack.dir}/lib">
@@ -1945,33 +1818,6 @@ BOOTSTRAPPING BUILD (STRAP)
<target name="strap.comp" depends="strap.pre-comp" unless="strap.comp.available">
<stopwatch name="strap.comp.timer"/>
<mkdir dir="${build-strap.dir}/classes/compiler"/>
- <!-- Compile MSIL inside of strap.... -->
- <javac
- srcdir="${src.dir}/msil"
- destdir="${build-strap.dir}/classes/compiler"
- classpath="${build-strap.dir}/classes/compiler"
- includes="**/*.java"
- excludes="**/tests/**"
- debug="true"
- target="1.6" source="1.4">
- <compilerarg line="${javac.args}"/>
- </javac>
- <scalacfork
- destdir="${build-strap.dir}/classes/compiler"
- compilerpathref="pack.classpath"
- params="${scalac.args.all}"
- srcdir="${src.dir}/msil"
- jvmargs="${scalacfork.jvmargs}">
- <include name="**/*.scala"/>
- <compilationpath>
- <pathelement location="${build-strap.dir}/classes/library"/>
- <pathelement location="${build-strap.dir}/classes/reflect"/>
- <pathelement location="${build-strap.dir}/classes/compiler"/>
- <path refid="fjbg.classpath"/>
- <path refid="aux.libs"/>
- <pathelement location="${jline.jar}"/>
- </compilationpath>
- </scalacfork>
<scalacfork
destdir="${build-strap.dir}/classes/compiler"
compilerpathref="pack.classpath"
@@ -1985,7 +1831,6 @@ BOOTSTRAPPING BUILD (STRAP)
<pathelement location="${build-strap.dir}/classes/compiler"/>
<path refid="aux.libs"/>
<path refid="forkjoin.classpath"/>
- <path refid="fjbg.classpath"/>
<path refid="asm.classpath"/>
<pathelement location="${jline.jar}"/>
</compilationpath>
@@ -2036,7 +1881,6 @@ BOOTSTRAPPING BUILD (STRAP)
<pathelement location="${build-strap.dir}/classes/compiler"/>
<pathelement location="${build-strap.dir}/classes/continuations-plugin"/>
<path refid="forkjoin.classpath"/>
- <path refid="fjbg.classpath"/>
<path refid="aux.libs"/>
</compilationpath>
</scalacfork>
@@ -2168,7 +2012,7 @@ BOOTSTRAPPING BUILD (STRAP)
</target>
<!-- ===========================================================================
-LIBRARIES (Forkjoin, FJBG, ASM)
+LIBRARIES (Forkjoin, ASM)
============================================================================ -->
@@ -2881,8 +2725,6 @@ STABLE REFERENCE (STARR)
<jar destfile="${basedir}/lib/scala-compiler-src.jar">
<fileset dir="${basedir}/src/compiler"/>
<fileset dir="${basedir}/src/asm"/>
- <fileset dir="${basedir}/src/fjbg"/>
- <fileset dir="${basedir}/src/msil"/>
</jar>
</target>
diff --git a/lib/fjbg.jar.desired.sha1 b/lib/fjbg.jar.desired.sha1
deleted file mode 100644
index 6f3ccc77bd..0000000000
--- a/lib/fjbg.jar.desired.sha1
+++ /dev/null
@@ -1 +0,0 @@
-8acc87f222210b4a5eb2675477602fc1759e7684 *fjbg.jar
diff --git a/lib/msil.jar.desired.sha1 b/lib/msil.jar.desired.sha1
deleted file mode 100644
index 9396b273ab..0000000000
--- a/lib/msil.jar.desired.sha1
+++ /dev/null
@@ -1 +0,0 @@
-d48cb950ceded82a5e0ffae8ef2c68d0923ed00c *msil.jar
diff --git a/lib/scala-compiler-src.jar.desired.sha1 b/lib/scala-compiler-src.jar.desired.sha1
index 082d86ff67..768602d1cc 100644
--- a/lib/scala-compiler-src.jar.desired.sha1
+++ b/lib/scala-compiler-src.jar.desired.sha1
@@ -1 +1 @@
-cfa3ee21f76cd5c115bd3bc070a3b401587bafb5 ?scala-compiler-src.jar
+7372c94d194f8337998a0afa9e5ee9d3394748bf ?scala-compiler-src.jar
diff --git a/lib/scala-compiler.jar.desired.sha1 b/lib/scala-compiler.jar.desired.sha1
index bb39b4d6a6..7b604eb027 100644
--- a/lib/scala-compiler.jar.desired.sha1
+++ b/lib/scala-compiler.jar.desired.sha1
@@ -1 +1 @@
-d54b99f215d4d42b3f0b3489fbb1081270700992 ?scala-compiler.jar
+44aa635da7fb0b7f19d9e5d89bc25893df7b6b21 ?scala-compiler.jar
diff --git a/lib/scala-library-src.jar.desired.sha1 b/lib/scala-library-src.jar.desired.sha1
index cd42c23291..e9bdba2e02 100644
--- a/lib/scala-library-src.jar.desired.sha1
+++ b/lib/scala-library-src.jar.desired.sha1
@@ -1 +1 @@
-8bdac1cdd60b73ff7e12fd2b556355fa10343e2d ?scala-library-src.jar
+2deb25c6b47e7dd6f7519d131d607e6e874ef763 ?scala-library-src.jar
diff --git a/lib/scala-library.jar.desired.sha1 b/lib/scala-library.jar.desired.sha1
index 6bdeaa903b..4dc4cb88c7 100644
--- a/lib/scala-library.jar.desired.sha1
+++ b/lib/scala-library.jar.desired.sha1
@@ -1 +1 @@
-1e0e39fae15b42e85998740511ec5a3830e26243 ?scala-library.jar
+a31ad1eb7109119873ca8bfe2db00f5c9858d8bc ?scala-library.jar
diff --git a/lib/scala-reflect-src.jar.desired.sha1 b/lib/scala-reflect-src.jar.desired.sha1
index d630c938f2..21b08dc5ad 100644
--- a/lib/scala-reflect-src.jar.desired.sha1
+++ b/lib/scala-reflect-src.jar.desired.sha1
@@ -1 +1 @@
-d229f4c91ea8ab1a81559b5803efd9b0b1632f0b ?scala-reflect-src.jar
+11596221c2a2ecc346b4478e7d630c269c69b888 ?scala-reflect-src.jar
diff --git a/lib/scala-reflect.jar.desired.sha1 b/lib/scala-reflect.jar.desired.sha1
index a5d6701749..b2da327618 100644
--- a/lib/scala-reflect.jar.desired.sha1
+++ b/lib/scala-reflect.jar.desired.sha1
@@ -1 +1 @@
-288f47dbe1002653e030fd25ca500b9ffe1ebd64 ?scala-reflect.jar
+b3420811aed2fb7cfcf25ebd26700a1e7847bf93 ?scala-reflect.jar
diff --git a/project/Build.scala b/project/Build.scala
index a50a572d54..efa8a7a038 100644
--- a/project/Build.scala
+++ b/project/Build.scala
@@ -11,7 +11,7 @@ object ScalaBuild extends Build with Layers with Packaging with Testing {
override lazy val settings = super.settings ++ Versions.settings ++ Seq(
autoScalaLibrary := false,
resolvers += Resolver.url(
- "Typesafe nightlies",
+ "Typesafe nightlies",
url("https://typesafe.artifactoryonline.com/typesafe/ivy-snapshots/")
)(Resolver.ivyStylePatterns),
resolvers ++= Seq(
@@ -21,14 +21,14 @@ object ScalaBuild extends Build with Layers with Packaging with Testing {
organization := "org.scala-lang",
version <<= Versions.mavenVersion,
pomExtra := epflPomExtra
- )
+ )
// Collections of projects to run 'compile' on.
- lazy val compiledProjects = Seq(quickLib, quickComp, continuationsLibrary, actors, swing, forkjoin, fjbg)
+ lazy val compiledProjects = Seq(quickLib, quickComp, continuationsLibrary, actors, swing, forkjoin)
// Collection of projects to 'package' and 'publish' together.
lazy val packagedBinaryProjects = Seq(scalaLibrary, scalaCompiler, swing, actors, continuationsPlugin, jline, scalap)
lazy val partestRunProjects = Seq(testsuite, continuationsTestsuite)
-
+
private def epflPomExtra = (
<xml:group>
<inceptionYear>2002</inceptionYear>
@@ -47,7 +47,7 @@ object ScalaBuild extends Build with Layers with Packaging with Testing {
</issueManagement>
</xml:group>
)
-
+
// Settings used to make sure publishing goes smoothly.
def publishSettings: Seq[Setting[_]] = Seq(
ivyScala ~= ((is: Option[IvyScala]) => is.map(_.copy(checkExplicit = false))),
@@ -82,7 +82,7 @@ object ScalaBuild extends Build with Layers with Packaging with Testing {
makeExplodedDist <<= (makeExplodedDist in scaladist).identity,
// Note: We override unmanagedSources so that ~ compile will look at all these sources, then run our aggregated compile...
unmanagedSourceDirectories in Compile <<= baseDirectory apply (_ / "src") apply { dir =>
- Seq("library/scala","actors","compiler","fjbg","swing","continuations/library","forkjoin") map (dir / _)
+ Seq("library/scala","actors","compiler","swing","continuations/library","forkjoin") map (dir / _)
},
// TODO - Make exported products == makeDist so we can use this when creating a *real* distribution.
commands += Release.pushStarr
@@ -91,7 +91,7 @@ object ScalaBuild extends Build with Layers with Packaging with Testing {
lazy val aaa_root = Project("scala", file(".")) settings(projectSettings: _*) settings(ShaResolve.settings: _*)
// External dependencies used for various projects
- lazy val externalDeps: Setting[_] = libraryDependencies <<= (sbtVersion)(v =>
+ lazy val externalDeps: Setting[_] = libraryDependencies <<= (sbtVersion)(v =>
Seq(
"org.apache.ant" % "ant" % "1.8.2",
"org.scala-sbt" % "compiler-interface" % v % "provided"
@@ -132,9 +132,7 @@ object ScalaBuild extends Build with Layers with Packaging with Testing {
// Jline nested project. Compile this sucker once and be done.
lazy val jline = Project("jline", file("src/jline"))
- // Fast Java Bytecode Generator (nested in every scala-compiler.jar)
- lazy val fjbg = Project("fjbg", file(".")) settings(settingOverrides : _*)
- // Our wrapped version of msil.
+ // Our wrapped version of asm.
lazy val asm = Project("asm", file(".")) settings(settingOverrides : _*)
// Forkjoin backport
lazy val forkjoin = Project("forkjoin", file(".")) settings(settingOverrides : _*)
@@ -175,9 +173,9 @@ object ScalaBuild extends Build with Layers with Packaging with Testing {
// --------------------------------------------------------------
// Projects dependent on layered compilation (quick)
// --------------------------------------------------------------
- def addCheaterDependency(projectName: String): Setting[_] =
- pomPostProcess <<= (version, organization, pomPostProcess) apply { (v,o,k) =>
- val dependency: scala.xml.Node =
+ def addCheaterDependency(projectName: String): Setting[_] =
+ pomPostProcess <<= (version, organization, pomPostProcess) apply { (v,o,k) =>
+ val dependency: scala.xml.Node =
<dependency>
<groupId>{o}</groupId>
<artifactid>{projectName}</artifactid>
@@ -193,10 +191,10 @@ object ScalaBuild extends Build with Layers with Packaging with Testing {
case n: scala.xml.Elem if n.label == "dependencies" => n
} isEmpty)
// TODO - Keep namespace on project...
- k andThen {
+ k andThen {
case n @ <project>{ nested@_*}</project> if hasDependencies(n) =>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">{nested}<dependencies>{dependency}</dependencies></project>
- case <project>{ nested@_*}</project> =>
+ case <project>{ nested@_*}</project> =>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">{ nested map fixDependencies }</project>
}
}
@@ -205,7 +203,7 @@ object ScalaBuild extends Build with Layers with Packaging with Testing {
lazy val dependentProjectSettings = settingOverrides ++ Seq(quickScalaInstance, quickScalaLibraryDependency, addCheaterDependency("scala-library"))
lazy val actors = Project("scala-actors", file(".")) settings(dependentProjectSettings:_*) dependsOn(forkjoin % "provided")
lazy val swing = Project("scala-swing", file(".")) settings(dependentProjectSettings:_*) dependsOn(actors % "provided")
- // This project will generate man pages (in man1 and html) for scala.
+ // This project will generate man pages (in man1 and html) for scala.
lazy val manmakerSettings: Seq[Setting[_]] = dependentProjectSettings :+ externalDeps
lazy val manmaker = Project("manual", file(".")) settings(manmakerSettings:_*)
@@ -234,7 +232,7 @@ object ScalaBuild extends Build with Layers with Packaging with Testing {
lazy val continuationsPlugin = Project("continuations-plugin", file(".")) settings(continuationsPluginSettings:_*)
lazy val continuationsLibrarySettings = dependentProjectSettings ++ Seq(
scalaSource in Compile <<= baseDirectory(_ / "src/continuations/library/"),
- scalacOptions in Compile <++= (exportedProducts in Compile in continuationsPlugin) map {
+ scalacOptions in Compile <++= (exportedProducts in Compile in continuationsPlugin) map {
case Seq(cpDir) => Seq("-Xplugin-require:continuations", "-P:continuations:enable", "-Xplugin:"+cpDir.data.getAbsolutePath)
}
)
@@ -283,7 +281,7 @@ object ScalaBuild extends Build with Layers with Packaging with Testing {
// --------------------------------------------------------------
// Real Compiler Artifact
// --------------------------------------------------------------
- lazy val packageScalaBinTask = Seq(quickComp, fjbg, asm).map(p => products in p in Compile).join.map(_.flatten).map(productTaskToMapping)
+ lazy val packageScalaBinTask = Seq(quickComp, asm).map(p => products in p in Compile).join.map(_.flatten).map(productTaskToMapping)
lazy val scalaBinArtifactSettings : Seq[Setting[_]] = inConfig(Compile)(Defaults.packageTasks(packageBin, packageScalaBinTask)) ++ Seq(
name := "scala-compiler",
crossPaths := false,
@@ -297,11 +295,11 @@ object ScalaBuild extends Build with Layers with Packaging with Testing {
lazy val scalaCompiler = Project("scala-compiler", file(".")) settings(publishSettings:_*) settings(scalaBinArtifactSettings:_*) dependsOn(scalaReflect)
lazy val fullQuickScalaReference = makeScalaReference("pack", scalaLibrary, scalaReflect, scalaCompiler)
-
+
// --------------------------------------------------------------
// Generating Documentation.
// --------------------------------------------------------------
-
+
// TODO - Migrate this into the dist project.
// Scaladocs
lazy val documentationSettings: Seq[Setting[_]] = dependentProjectSettings ++ Seq(
@@ -331,6 +329,6 @@ object ScalaBuild extends Build with Layers with Packaging with Testing {
lazy val documentation = (
Project("documentation", file("."))
settings (documentationSettings: _*)
- dependsOn(quickLib, quickComp, actors, fjbg, forkjoin, swing, continuationsLibrary)
+ dependsOn(quickLib, quickComp, actors, forkjoin, swing, continuationsLibrary)
)
}
diff --git a/project/Layers.scala b/project/Layers.scala
index 35cc79c130..6c939d0ff7 100644
--- a/project/Layers.scala
+++ b/project/Layers.scala
@@ -13,8 +13,6 @@ trait Layers extends Build {
def jline: Project
/** Reference to forkjoin library */
def forkjoin: Project
- /** Reference to Fast-Java-Bytecode-Generator library */
- def fjbg: Project
/** Reference to the ASM wrapped project. */
def asm: Project
/** A setting that adds some external dependencies. */
@@ -23,7 +21,7 @@ trait Layers extends Build {
def aaa_root: Project
/** Creates a reference Scala version that can be used to build other projects. This takes in the raw
- * library, compiler and fjbg libraries as well as a string representing the layer name (used for compiling the compile-interface).
+ * library, compiler as well as a string representing the layer name (used for compiling the compile-interface).
*/
def makeScalaReference(layer: String, library: Project, reflect: Project, compiler: Project) =
scalaInstance <<= (appConfiguration in library,
@@ -31,10 +29,9 @@ trait Layers extends Build {
(exportedProducts in library in Compile),
(exportedProducts in reflect in Compile),
(exportedProducts in compiler in Compile),
- (exportedProducts in fjbg in Compile),
(fullClasspath in jline in Runtime),
(exportedProducts in asm in Runtime)) map {
- (app, version: String, lib: Classpath, reflect: Classpath, comp: Classpath, fjbg: Classpath, jline: Classpath, asm: Classpath) =>
+ (app, version: String, lib: Classpath, reflect: Classpath, comp: Classpath, jline: Classpath, asm: Classpath) =>
val launcher = app.provider.scalaProvider.launcher
(lib,comp) match {
case (Seq(libraryJar), Seq(compilerJar)) =>
@@ -43,14 +40,14 @@ trait Layers extends Build {
libraryJar.data,
compilerJar.data,
launcher,
- ((fjbg.files ++ jline.files ++ asm.files ++ reflect.files):_*))
+ ((jline.files ++ asm.files ++ reflect.files):_*))
case _ => error("Cannot build a ScalaReference with more than one classpath element")
}
}
/** Creates a "layer" of Scala compilation. That is, this will build the next version of Scala from a previous version.
* Returns the library project and compiler project from the next layer.
- * Note: The library and compiler are not *complete* in the sense that they are missing things like "actors" and "fjbg".
+ * Note: The library and compiler are not *complete* in the sense that they are missing things like "actors".
*/
def makeLayer(layer: String, referenceScala: Setting[Task[ScalaInstance]], autoLock: Boolean = false) : (Project, Project, Project) = {
val autoLockSettings: Seq[Setting[_]] =
@@ -96,7 +93,6 @@ trait Layers extends Build {
version := layer,
scalaSource in Compile <<= (baseDirectory) apply (_ / "src" / "compiler"),
resourceDirectory in Compile <<= baseDirectory apply (_ / "src" / "compiler"),
- unmanagedSourceDirectories in Compile <+= (baseDirectory) apply (_ / "src" / "msil"),
defaultExcludes := ("tests"),
defaultExcludes in unmanagedResources := "*.scala",
resourceGenerators in Compile <+= (resourceManaged, Versions.scalaVersions, skip in Compile, streams) map Versions.generateVersionPropertiesFile("compiler.properties"),
@@ -108,7 +104,7 @@ trait Layers extends Build {
dirs.descendentsExcept( ("*.xml" | "*.html" | "*.gif" | "*.png" | "*.js" | "*.css" | "*.tmpl" | "*.swf" | "*.properties" | "*.txt"),"*.scala").get
},
// TODO - Use depends on *and* SBT's magic dependency mechanisms...
- unmanagedClasspath in Compile <<= Seq(forkjoin, library, reflect, fjbg, jline, asm).map(exportedProducts in Compile in _).join.map(_.flatten),
+ unmanagedClasspath in Compile <<= Seq(forkjoin, library, reflect, jline, asm).map(exportedProducts in Compile in _).join.map(_.flatten),
externalDeps,
referenceScala
)
diff --git a/project/Packaging.scala b/project/Packaging.scala
index eb4e69f99e..6cb51a10a6 100644
--- a/project/Packaging.scala
+++ b/project/Packaging.scala
@@ -19,7 +19,7 @@ trait Packaging { self: ScalaBuild.type =>
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,fjbg,jline,forkjoin).map(classDirectory in Compile in _).join.map(Attributed.blankSeq),
+ fullClasspath in Runtime in genBinQuick <<= Seq(quickComp,quickLib,scalap,actors,swing,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"),
diff --git a/project/ShaResolve.scala b/project/ShaResolve.scala
index cea2b2d6cc..e5b25a29cf 100644
--- a/project/ShaResolve.scala
+++ b/project/ShaResolve.scala
@@ -105,6 +105,7 @@ object ShaResolve {
def parseShaFile(file: File): (File, String) =
IO.read(file).split("\\s") match {
case Array(sha, filename) if filename.startsWith("?") => (new File(file.getParentFile, filename.drop(1)), sha)
+ case Array(sha, filename) if filename.startsWith("*") => (new File(file.getParentFile, filename.drop(1)), sha)
case Array(sha, filename) => (new File(file.getParentFile, filename), sha)
case _ => error(file.getAbsolutePath + " is an invalid sha file")
}
diff --git a/project/Testing.scala b/project/Testing.scala
index 5de72116a3..5b4135a31a 100644
--- a/project/Testing.scala
+++ b/project/Testing.scala
@@ -17,7 +17,7 @@ trait Testing { self: ScalaBuild.type =>
autoScalaLibrary := false
)
lazy val continuationsTestsuiteSettings: Seq[Setting[_]] = testsuiteSettings ++ Seq(
- scalacOptions in Test <++= (exportedProducts in Compile in continuationsPlugin) map {
+ scalacOptions in Test <++= (exportedProducts in Compile in continuationsPlugin) map {
case Seq(cpDir) => Seq("-Xplugin-require:continuations", "-P:continuations:enable", "-Xplugin:"+cpDir.data.getAbsolutePath)
},
partestDirs <<= baseDirectory apply { bd =>
@@ -27,14 +27,14 @@ trait Testing { self: ScalaBuild.type =>
}
)
val testsuite = (
- Project("testsuite", file("."))
+ Project("testsuite", file("."))
settings (testsuiteSettings:_*)
- dependsOn (scalaLibrary, scalaCompiler, fjbg, partest, scalacheck)
+ dependsOn (scalaLibrary, scalaCompiler, partest, scalacheck)
)
val continuationsTestsuite = (
Project("continuations-testsuite", file("."))
- settings (continuationsTestsuiteSettings:_*)
- dependsOn (partest, scalaLibrary, scalaCompiler, fjbg)
+ settings (continuationsTestsuiteSettings:_*)
+ dependsOn (partest, scalaLibrary, scalaCompiler)
)
}
diff --git a/src/actors/scala/actors/Future.scala b/src/actors/scala/actors/Future.scala
index 3037f82141..1abd7b160e 100644
--- a/src/actors/scala/actors/Future.scala
+++ b/src/actors/scala/actors/Future.scala
@@ -174,7 +174,7 @@ object Futures {
* or timeout + `System.currentTimeMillis()` is negative.
*/
def awaitAll(timeout: Long, fts: Future[Any]*): List[Option[Any]] = {
- var resultsMap: scala.collection.mutable.Map[Int, Option[Any]] = new scala.collection.mutable.HashMap[Int, Option[Any]]
+ val resultsMap: scala.collection.mutable.Map[Int, Option[Any]] = new scala.collection.mutable.HashMap[Int, Option[Any]]
var cnt = 0
val mappedFts = fts.map(ft =>
diff --git a/src/asm/scala/tools/asm/AnnotationVisitor.java b/src/asm/scala/tools/asm/AnnotationVisitor.java
index b96e730a73..c806ca71e8 100644
--- a/src/asm/scala/tools/asm/AnnotationVisitor.java
+++ b/src/asm/scala/tools/asm/AnnotationVisitor.java
@@ -54,8 +54,9 @@ public abstract class AnnotationVisitor {
/**
* Constructs a new {@link AnnotationVisitor}.
*
- * @param api the ASM API version implemented by this visitor. Must be one
- * of {@link Opcodes#ASM4}.
+ * @param api
+ * the ASM API version implemented by this visitor. Must be one
+ * of {@link Opcodes#ASM4}.
*/
public AnnotationVisitor(final int api) {
this(api, null);
@@ -64,15 +65,17 @@ public abstract class AnnotationVisitor {
/**
* Constructs a new {@link AnnotationVisitor}.
*
- * @param api the ASM API version implemented by this visitor. Must be one
- * of {@link Opcodes#ASM4}.
- * @param av the annotation visitor to which this visitor must delegate
- * method calls. May be null.
+ * @param api
+ * the ASM API version implemented by this visitor. Must be one
+ * of {@link Opcodes#ASM4}.
+ * @param av
+ * the annotation visitor to which this visitor must delegate
+ * method calls. May be null.
*/
public AnnotationVisitor(final int api, final AnnotationVisitor av) {
- /*if (api != Opcodes.ASM4) {
+ if (api != Opcodes.ASM4) {
throw new IllegalArgumentException();
- }*/
+ }
this.api = api;
this.av = av;
}
@@ -80,14 +83,17 @@ public abstract class AnnotationVisitor {
/**
* Visits a primitive value of the annotation.
*
- * @param name the value name.
- * @param value the actual value, whose type must be {@link Byte},
- * {@link Boolean}, {@link Character}, {@link Short}, {@link Integer}
- * , {@link Long}, {@link Float}, {@link Double}, {@link String} or
- * {@link Type} or OBJECT or ARRAY sort. This value can also be an
- * array of byte, boolean, short, char, int, long, float or double
- * values (this is equivalent to using {@link #visitArray visitArray}
- * and visiting each array element in turn, but is more convenient).
+ * @param name
+ * the value name.
+ * @param value
+ * the actual value, whose type must be {@link Byte},
+ * {@link Boolean}, {@link Character}, {@link Short},
+ * {@link Integer} , {@link Long}, {@link Float}, {@link Double},
+ * {@link String} or {@link Type} or OBJECT or ARRAY sort. This
+ * value can also be an array of byte, boolean, short, char, int,
+ * long, float or double values (this is equivalent to using
+ * {@link #visitArray visitArray} and visiting each array element
+ * in turn, but is more convenient).
*/
public void visit(String name, Object value) {
if (av != null) {
@@ -98,9 +104,12 @@ public abstract class AnnotationVisitor {
/**
* Visits an enumeration value of the annotation.
*
- * @param name the value name.
- * @param desc the class descriptor of the enumeration class.
- * @param value the actual enumeration value.
+ * @param name
+ * the value name.
+ * @param desc
+ * the class descriptor of the enumeration class.
+ * @param value
+ * the actual enumeration value.
*/
public void visitEnum(String name, String desc, String value) {
if (av != null) {
@@ -111,12 +120,14 @@ public abstract class AnnotationVisitor {
/**
* Visits a nested annotation value of the annotation.
*
- * @param name the value name.
- * @param desc the class descriptor of the nested annotation class.
+ * @param name
+ * the value name.
+ * @param desc
+ * the class descriptor of the nested annotation class.
* @return a visitor to visit the actual nested annotation value, or
- * <tt>null</tt> if this visitor is not interested in visiting
- * this nested annotation. <i>The nested annotation value must be
- * fully visited before calling other methods on this annotation
+ * <tt>null</tt> if this visitor is not interested in visiting this
+ * nested annotation. <i>The nested annotation value must be fully
+ * visited before calling other methods on this annotation
* visitor</i>.
*/
public AnnotationVisitor visitAnnotation(String name, String desc) {
@@ -132,10 +143,11 @@ public abstract class AnnotationVisitor {
* can be passed as value to {@link #visit visit}. This is what
* {@link ClassReader} does.
*
- * @param name the value name.
+ * @param name
+ * the value name.
* @return a visitor to visit the actual array value elements, or
- * <tt>null</tt> if this visitor is not interested in visiting
- * these values. The 'name' parameters passed to the methods of this
+ * <tt>null</tt> if this visitor is not interested in visiting these
+ * values. The 'name' parameters passed to the methods of this
* visitor are ignored. <i>All the array values must be visited
* before calling other methods on this annotation visitor</i>.
*/
diff --git a/src/asm/scala/tools/asm/AnnotationWriter.java b/src/asm/scala/tools/asm/AnnotationWriter.java
index e530780249..8eb5b2ef48 100644
--- a/src/asm/scala/tools/asm/AnnotationWriter.java
+++ b/src/asm/scala/tools/asm/AnnotationWriter.java
@@ -90,20 +90,20 @@ final class AnnotationWriter extends AnnotationVisitor {
/**
* Constructs a new {@link AnnotationWriter}.
*
- * @param cw the class writer to which this annotation must be added.
- * @param named <tt>true<tt> if values are named, <tt>false</tt> otherwise.
- * @param bv where the annotation values must be stored.
- * @param parent where the number of annotation values must be stored.
- * @param offset where in <tt>parent</tt> the number of annotation values must
- * be stored.
+ * @param cw
+ * the class writer to which this annotation must be added.
+ * @param named
+ * <tt>true<tt> if values are named, <tt>false</tt> otherwise.
+ * @param bv
+ * where the annotation values must be stored.
+ * @param parent
+ * where the number of annotation values must be stored.
+ * @param offset
+ * where in <tt>parent</tt> the number of annotation values must
+ * be stored.
*/
- AnnotationWriter(
- final ClassWriter cw,
- final boolean named,
- final ByteVector bv,
- final ByteVector parent,
- final int offset)
- {
+ AnnotationWriter(final ClassWriter cw, final boolean named,
+ final ByteVector bv, final ByteVector parent, final int offset) {
super(Opcodes.ASM4);
this.cw = cw;
this.named = named;
@@ -190,11 +190,8 @@ final class AnnotationWriter extends AnnotationVisitor {
}
@Override
- public void visitEnum(
- final String name,
- final String desc,
- final String value)
- {
+ public void visitEnum(final String name, final String desc,
+ final String value) {
++size;
if (named) {
bv.putShort(cw.newUTF8(name));
@@ -203,10 +200,8 @@ final class AnnotationWriter extends AnnotationVisitor {
}
@Override
- public AnnotationVisitor visitAnnotation(
- final String name,
- final String desc)
- {
+ public AnnotationVisitor visitAnnotation(final String name,
+ final String desc) {
++size;
if (named) {
bv.putShort(cw.newUTF8(name));
@@ -259,7 +254,8 @@ final class AnnotationWriter extends AnnotationVisitor {
* Puts the annotations of this annotation writer list into the given byte
* vector.
*
- * @param out where the annotations must be put.
+ * @param out
+ * where the annotations must be put.
*/
void put(final ByteVector out) {
int n = 0;
@@ -286,15 +282,15 @@ final class AnnotationWriter extends AnnotationVisitor {
/**
* Puts the given annotation lists into the given byte vector.
*
- * @param panns an array of annotation writer lists.
- * @param off index of the first annotation to be written.
- * @param out where the annotations must be put.
+ * @param panns
+ * an array of annotation writer lists.
+ * @param off
+ * index of the first annotation to be written.
+ * @param out
+ * where the annotations must be put.
*/
- static void put(
- final AnnotationWriter[] panns,
- final int off,
- final ByteVector out)
- {
+ static void put(final AnnotationWriter[] panns, final int off,
+ final ByteVector out) {
int size = 1 + 2 * (panns.length - off);
for (int i = off; i < panns.length; ++i) {
size += panns[i] == null ? 0 : panns[i].getSize();
diff --git a/src/asm/scala/tools/asm/Attribute.java b/src/asm/scala/tools/asm/Attribute.java
index 408f21ce1e..ac40a758a2 100644
--- a/src/asm/scala/tools/asm/Attribute.java
+++ b/src/asm/scala/tools/asm/Attribute.java
@@ -55,7 +55,8 @@ public class Attribute {
/**
* Constructs a new empty attribute.
*
- * @param type the type of the attribute.
+ * @param type
+ * the type of the attribute.
*/
protected Attribute(final String type) {
this.type = type;
@@ -91,39 +92,39 @@ public class Attribute {
}
/**
- * Reads a {@link #type type} attribute. This method must return a <i>new</i>
- * {@link Attribute} object, of type {@link #type type}, corresponding to
- * the <tt>len</tt> bytes starting at the given offset, in the given class
- * reader.
+ * Reads a {@link #type type} attribute. This method must return a
+ * <i>new</i> {@link Attribute} object, of type {@link #type type},
+ * corresponding to the <tt>len</tt> bytes starting at the given offset, in
+ * the given class reader.
*
- * @param cr the class that contains the attribute to be read.
- * @param off index of the first byte of the attribute's content in {@link
- * ClassReader#b cr.b}. The 6 attribute header bytes, containing the
- * type and the length of the attribute, are not taken into account
- * here.
- * @param len the length of the attribute's content.
- * @param buf buffer to be used to call
- * {@link ClassReader#readUTF8 readUTF8},
- * {@link ClassReader#readClass(int,char[]) readClass} or
- * {@link ClassReader#readConst readConst}.
- * @param codeOff index of the first byte of code's attribute content in
- * {@link ClassReader#b cr.b}, or -1 if the attribute to be read is
- * not a code attribute. The 6 attribute header bytes, containing the
- * type and the length of the attribute, are not taken into account
- * here.
- * @param labels the labels of the method's code, or <tt>null</tt> if the
- * attribute to be read is not a code attribute.
+ * @param cr
+ * the class that contains the attribute to be read.
+ * @param off
+ * index of the first byte of the attribute's content in
+ * {@link ClassReader#b cr.b}. The 6 attribute header bytes,
+ * containing the type and the length of the attribute, are not
+ * taken into account here.
+ * @param len
+ * the length of the attribute's content.
+ * @param buf
+ * buffer to be used to call {@link ClassReader#readUTF8
+ * readUTF8}, {@link ClassReader#readClass(int,char[]) readClass}
+ * or {@link ClassReader#readConst readConst}.
+ * @param codeOff
+ * index of the first byte of code's attribute content in
+ * {@link ClassReader#b cr.b}, or -1 if the attribute to be read
+ * is not a code attribute. The 6 attribute header bytes,
+ * containing the type and the length of the attribute, are not
+ * taken into account here.
+ * @param labels
+ * the labels of the method's code, or <tt>null</tt> if the
+ * attribute to be read is not a code attribute.
* @return a <i>new</i> {@link Attribute} object corresponding to the given
* bytes.
*/
- protected Attribute read(
- final ClassReader cr,
- final int off,
- final int len,
- final char[] buf,
- final int codeOff,
- final Label[] labels)
- {
+ protected Attribute read(final ClassReader cr, final int off,
+ final int len, final char[] buf, final int codeOff,
+ final Label[] labels) {
Attribute attr = new Attribute(type);
attr.value = new byte[len];
System.arraycopy(cr.b, off, attr.value, 0, len);
@@ -133,30 +134,30 @@ public class Attribute {
/**
* Returns the byte array form of this attribute.
*
- * @param cw the class to which this attribute must be added. This parameter
- * can be used to add to the constant pool of this class the items
- * that corresponds to this attribute.
- * @param code the bytecode of the method corresponding to this code
- * attribute, or <tt>null</tt> if this attribute is not a code
- * attributes.
- * @param len the length of the bytecode of the method corresponding to this
- * code attribute, or <tt>null</tt> if this attribute is not a code
- * attribute.
- * @param maxStack the maximum stack size of the method corresponding to
- * this code attribute, or -1 if this attribute is not a code
- * attribute.
- * @param maxLocals the maximum number of local variables of the method
- * corresponding to this code attribute, or -1 if this attribute is
- * not a code attribute.
+ * @param cw
+ * the class to which this attribute must be added. This
+ * parameter can be used to add to the constant pool of this
+ * class the items that corresponds to this attribute.
+ * @param code
+ * the bytecode of the method corresponding to this code
+ * attribute, or <tt>null</tt> if this attribute is not a code
+ * attributes.
+ * @param len
+ * the length of the bytecode of the method corresponding to this
+ * code attribute, or <tt>null</tt> if this attribute is not a
+ * code attribute.
+ * @param maxStack
+ * the maximum stack size of the method corresponding to this
+ * code attribute, or -1 if this attribute is not a code
+ * attribute.
+ * @param maxLocals
+ * the maximum number of local variables of the method
+ * corresponding to this code attribute, or -1 if this attribute
+ * is not a code attribute.
* @return the byte array form of this attribute.
*/
- protected ByteVector write(
- final ClassWriter cw,
- final byte[] code,
- final int len,
- final int maxStack,
- final int maxLocals)
- {
+ protected ByteVector write(final ClassWriter cw, final byte[] code,
+ final int len, final int maxStack, final int maxLocals) {
ByteVector v = new ByteVector();
v.data = value;
v.length = value.length;
@@ -181,30 +182,30 @@ public class Attribute {
/**
* Returns the size of all the attributes in this attribute list.
*
- * @param cw the class writer to be used to convert the attributes into byte
- * arrays, with the {@link #write write} method.
- * @param code the bytecode of the method corresponding to these code
- * attributes, or <tt>null</tt> if these attributes are not code
- * attributes.
- * @param len the length of the bytecode of the method corresponding to
- * these code attributes, or <tt>null</tt> if these attributes are
- * not code attributes.
- * @param maxStack the maximum stack size of the method corresponding to
- * these code attributes, or -1 if these attributes are not code
- * attributes.
- * @param maxLocals the maximum number of local variables of the method
- * corresponding to these code attributes, or -1 if these attributes
- * are not code attributes.
+ * @param cw
+ * the class writer to be used to convert the attributes into
+ * byte arrays, with the {@link #write write} method.
+ * @param code
+ * the bytecode of the method corresponding to these code
+ * attributes, or <tt>null</tt> if these attributes are not code
+ * attributes.
+ * @param len
+ * the length of the bytecode of the method corresponding to
+ * these code attributes, or <tt>null</tt> if these attributes
+ * are not code attributes.
+ * @param maxStack
+ * the maximum stack size of the method corresponding to these
+ * code attributes, or -1 if these attributes are not code
+ * attributes.
+ * @param maxLocals
+ * the maximum number of local variables of the method
+ * corresponding to these code attributes, or -1 if these
+ * attributes are not code attributes.
* @return the size of all the attributes in this attribute list. This size
* includes the size of the attribute headers.
*/
- final int getSize(
- final ClassWriter cw,
- final byte[] code,
- final int len,
- final int maxStack,
- final int maxLocals)
- {
+ final int getSize(final ClassWriter cw, final byte[] code, final int len,
+ final int maxStack, final int maxLocals) {
Attribute attr = this;
int size = 0;
while (attr != null) {
@@ -219,30 +220,30 @@ public class Attribute {
* Writes all the attributes of this attribute list in the given byte
* vector.
*
- * @param cw the class writer to be used to convert the attributes into byte
- * arrays, with the {@link #write write} method.
- * @param code the bytecode of the method corresponding to these code
- * attributes, or <tt>null</tt> if these attributes are not code
- * attributes.
- * @param len the length of the bytecode of the method corresponding to
- * these code attributes, or <tt>null</tt> if these attributes are
- * not code attributes.
- * @param maxStack the maximum stack size of the method corresponding to
- * these code attributes, or -1 if these attributes are not code
- * attributes.
- * @param maxLocals the maximum number of local variables of the method
- * corresponding to these code attributes, or -1 if these attributes
- * are not code attributes.
- * @param out where the attributes must be written.
+ * @param cw
+ * the class writer to be used to convert the attributes into
+ * byte arrays, with the {@link #write write} method.
+ * @param code
+ * the bytecode of the method corresponding to these code
+ * attributes, or <tt>null</tt> if these attributes are not code
+ * attributes.
+ * @param len
+ * the length of the bytecode of the method corresponding to
+ * these code attributes, or <tt>null</tt> if these attributes
+ * are not code attributes.
+ * @param maxStack
+ * the maximum stack size of the method corresponding to these
+ * code attributes, or -1 if these attributes are not code
+ * attributes.
+ * @param maxLocals
+ * the maximum number of local variables of the method
+ * corresponding to these code attributes, or -1 if these
+ * attributes are not code attributes.
+ * @param out
+ * where the attributes must be written.
*/
- final void put(
- final ClassWriter cw,
- final byte[] code,
- final int len,
- final int maxStack,
- final int maxLocals,
- final ByteVector out)
- {
+ final void put(final ClassWriter cw, final byte[] code, final int len,
+ final int maxStack, final int maxLocals, final ByteVector out) {
Attribute attr = this;
while (attr != null) {
ByteVector b = attr.write(cw, code, len, maxStack, maxLocals);
diff --git a/src/asm/scala/tools/asm/ByteVector.java b/src/asm/scala/tools/asm/ByteVector.java
index 5081f0184b..2bc63eb384 100644
--- a/src/asm/scala/tools/asm/ByteVector.java
+++ b/src/asm/scala/tools/asm/ByteVector.java
@@ -59,7 +59,8 @@ public class ByteVector {
* Constructs a new {@link ByteVector ByteVector} with the given initial
* size.
*
- * @param initialSize the initial size of the byte vector to be constructed.
+ * @param initialSize
+ * the initial size of the byte vector to be constructed.
*/
public ByteVector(final int initialSize) {
data = new byte[initialSize];
@@ -69,7 +70,8 @@ public class ByteVector {
* Puts a byte into this byte vector. The byte vector is automatically
* enlarged if necessary.
*
- * @param b a byte.
+ * @param b
+ * a byte.
* @return this byte vector.
*/
public ByteVector putByte(final int b) {
@@ -86,8 +88,10 @@ public class ByteVector {
* Puts two bytes into this byte vector. The byte vector is automatically
* enlarged if necessary.
*
- * @param b1 a byte.
- * @param b2 another byte.
+ * @param b1
+ * a byte.
+ * @param b2
+ * another byte.
* @return this byte vector.
*/
ByteVector put11(final int b1, final int b2) {
@@ -106,7 +110,8 @@ public class ByteVector {
* Puts a short into this byte vector. The byte vector is automatically
* enlarged if necessary.
*
- * @param s a short.
+ * @param s
+ * a short.
* @return this byte vector.
*/
public ByteVector putShort(final int s) {
@@ -125,8 +130,10 @@ public class ByteVector {
* Puts a byte and a short into this byte vector. The byte vector is
* automatically enlarged if necessary.
*
- * @param b a byte.
- * @param s a short.
+ * @param b
+ * a byte.
+ * @param s
+ * a short.
* @return this byte vector.
*/
ByteVector put12(final int b, final int s) {
@@ -146,7 +153,8 @@ public class ByteVector {
* Puts an int into this byte vector. The byte vector is automatically
* enlarged if necessary.
*
- * @param i an int.
+ * @param i
+ * an int.
* @return this byte vector.
*/
public ByteVector putInt(final int i) {
@@ -167,7 +175,8 @@ public class ByteVector {
* Puts a long into this byte vector. The byte vector is automatically
* enlarged if necessary.
*
- * @param l a long.
+ * @param l
+ * a long.
* @return this byte vector.
*/
public ByteVector putLong(final long l) {
@@ -194,7 +203,8 @@ public class ByteVector {
* Puts an UTF8 string into this byte vector. The byte vector is
* automatically enlarged if necessary.
*
- * @param s a String.
+ * @param s
+ * a String.
* @return this byte vector.
*/
public ByteVector putUTF8(final String s) {
@@ -259,14 +269,16 @@ public class ByteVector {
* Puts an array of bytes into this byte vector. The byte vector is
* automatically enlarged if necessary.
*
- * @param b an array of bytes. May be <tt>null</tt> to put <tt>len</tt>
- * null bytes into this byte vector.
- * @param off index of the fist byte of b that must be copied.
- * @param len number of bytes of b that must be copied.
+ * @param b
+ * an array of bytes. May be <tt>null</tt> to put <tt>len</tt>
+ * null bytes into this byte vector.
+ * @param off
+ * index of the fist byte of b that must be copied.
+ * @param len
+ * number of bytes of b that must be copied.
* @return this byte vector.
*/
- public ByteVector putByteArray(final byte[] b, final int off, final int len)
- {
+ public ByteVector putByteArray(final byte[] b, final int off, final int len) {
if (length + len > data.length) {
enlarge(len);
}
@@ -280,8 +292,9 @@ public class ByteVector {
/**
* Enlarge this byte vector so that it can receive n more bytes.
*
- * @param size number of additional bytes that this byte vector should be
- * able to receive.
+ * @param size
+ * number of additional bytes that this byte vector should be
+ * able to receive.
*/
private void enlarge(final int size) {
int length1 = 2 * data.length;
diff --git a/src/asm/scala/tools/asm/ClassReader.java b/src/asm/scala/tools/asm/ClassReader.java
index f3287d41ae..cc655c1b62 100644
--- a/src/asm/scala/tools/asm/ClassReader.java
+++ b/src/asm/scala/tools/asm/ClassReader.java
@@ -112,9 +112,8 @@ public class ClassReader {
public final byte[] b;
/**
- * The start index of each constant pool item in {@link #b b}, plus one.
- * The one byte offset skips the constant pool item tag that indicates its
- * type.
+ * The start index of each constant pool item in {@link #b b}, plus one. The
+ * one byte offset skips the constant pool item tag that indicates its type.
*/
private final int[] items;
@@ -147,7 +146,8 @@ public class ClassReader {
/**
* Constructs a new {@link ClassReader} object.
*
- * @param b the bytecode of the class to be read.
+ * @param b
+ * the bytecode of the class to be read.
*/
public ClassReader(final byte[] b) {
this(b, 0, b.length);
@@ -156,14 +156,17 @@ public class ClassReader {
/**
* Constructs a new {@link ClassReader} object.
*
- * @param b the bytecode of the class to be read.
- * @param off the start offset of the class data.
- * @param len the length of the class data.
+ * @param b
+ * the bytecode of the class to be read.
+ * @param off
+ * the start offset of the class data.
+ * @param len
+ * the length of the class data.
*/
public ClassReader(final byte[] b, final int off, final int len) {
this.b = b;
// checks the class version
- if (readShort(6) > Opcodes.V1_7) {
+ if (readShort(off + 6) > Opcodes.V1_7) {
throw new IllegalArgumentException();
}
// parses the constant pool
@@ -176,35 +179,35 @@ public class ClassReader {
items[i] = index + 1;
int size;
switch (b[index]) {
- case ClassWriter.FIELD:
- case ClassWriter.METH:
- case ClassWriter.IMETH:
- case ClassWriter.INT:
- case ClassWriter.FLOAT:
- case ClassWriter.NAME_TYPE:
- case ClassWriter.INDY:
- size = 5;
- break;
- case ClassWriter.LONG:
- case ClassWriter.DOUBLE:
- size = 9;
- ++i;
- break;
- case ClassWriter.UTF8:
- size = 3 + readUnsignedShort(index + 1);
- if (size > max) {
- max = size;
- }
- break;
- case ClassWriter.HANDLE:
- size = 4;
- break;
- // case ClassWriter.CLASS:
- // case ClassWriter.STR:
- // case ClassWriter.MTYPE
- default:
- size = 3;
- break;
+ case ClassWriter.FIELD:
+ case ClassWriter.METH:
+ case ClassWriter.IMETH:
+ case ClassWriter.INT:
+ case ClassWriter.FLOAT:
+ case ClassWriter.NAME_TYPE:
+ case ClassWriter.INDY:
+ size = 5;
+ break;
+ case ClassWriter.LONG:
+ case ClassWriter.DOUBLE:
+ size = 9;
+ ++i;
+ break;
+ case ClassWriter.UTF8:
+ size = 3 + readUnsignedShort(index + 1);
+ if (size > max) {
+ max = size;
+ }
+ break;
+ case ClassWriter.HANDLE:
+ size = 4;
+ break;
+ // case ClassWriter.CLASS:
+ // case ClassWriter.STR:
+ // case ClassWriter.MTYPE
+ default:
+ size = 3;
+ break;
}
index += size;
}
@@ -249,8 +252,7 @@ public class ClassReader {
* @see ClassVisitor#visit(int, int, String, String, String, String[])
*/
public String getSuperName() {
- int n = items[readUnsignedShort(header + 4)];
- return n == 0 ? null : readUTF8(n, new char[maxStringLength]);
+ return readClass(header + 4, new char[maxStringLength]);
}
/**
@@ -280,7 +282,8 @@ public class ClassReader {
* Copies the constant pool data into the given {@link ClassWriter}. Should
* be called before the {@link #accept(ClassVisitor,int)} method.
*
- * @param classWriter the {@link ClassWriter} to copy constant pool into.
+ * @param classWriter
+ * the {@link ClassWriter} to copy constant pool into.
*/
void copyPool(final ClassWriter classWriter) {
char[] buf = new char[maxStringLength];
@@ -292,82 +295,63 @@ public class ClassReader {
Item item = new Item(i);
int nameType;
switch (tag) {
- case ClassWriter.FIELD:
- case ClassWriter.METH:
- case ClassWriter.IMETH:
- nameType = items[readUnsignedShort(index + 2)];
- item.set(tag,
- readClass(index, buf),
- readUTF8(nameType, buf),
- readUTF8(nameType + 2, buf));
- break;
-
- case ClassWriter.INT:
- item.set(readInt(index));
- break;
-
- case ClassWriter.FLOAT:
- item.set(Float.intBitsToFloat(readInt(index)));
- break;
-
- case ClassWriter.NAME_TYPE:
- item.set(tag,
- readUTF8(index, buf),
- readUTF8(index + 2, buf),
- null);
- break;
-
- case ClassWriter.LONG:
- item.set(readLong(index));
- ++i;
- break;
-
- case ClassWriter.DOUBLE:
- item.set(Double.longBitsToDouble(readLong(index)));
- ++i;
- break;
-
- case ClassWriter.UTF8: {
- String s = strings[i];
- if (s == null) {
- index = items[i];
- s = strings[i] = readUTF(index + 2,
- readUnsignedShort(index),
- buf);
- }
- item.set(tag, s, null, null);
+ case ClassWriter.FIELD:
+ case ClassWriter.METH:
+ case ClassWriter.IMETH:
+ nameType = items[readUnsignedShort(index + 2)];
+ item.set(tag, readClass(index, buf), readUTF8(nameType, buf),
+ readUTF8(nameType + 2, buf));
+ break;
+ case ClassWriter.INT:
+ item.set(readInt(index));
+ break;
+ case ClassWriter.FLOAT:
+ item.set(Float.intBitsToFloat(readInt(index)));
+ break;
+ case ClassWriter.NAME_TYPE:
+ item.set(tag, readUTF8(index, buf), readUTF8(index + 2, buf),
+ null);
+ break;
+ case ClassWriter.LONG:
+ item.set(readLong(index));
+ ++i;
+ break;
+ case ClassWriter.DOUBLE:
+ item.set(Double.longBitsToDouble(readLong(index)));
+ ++i;
+ break;
+ case ClassWriter.UTF8: {
+ String s = strings[i];
+ if (s == null) {
+ index = items[i];
+ s = strings[i] = readUTF(index + 2,
+ readUnsignedShort(index), buf);
}
- break;
-
- case ClassWriter.HANDLE: {
- int fieldOrMethodRef = items[readUnsignedShort(index + 1)];
- nameType = items[readUnsignedShort(fieldOrMethodRef + 2)];
- item.set(ClassWriter.HANDLE_BASE + readByte(index),
- readClass(fieldOrMethodRef, buf),
- readUTF8(nameType, buf),
- readUTF8(nameType + 2, buf));
-
+ item.set(tag, s, null, null);
+ break;
+ }
+ case ClassWriter.HANDLE: {
+ int fieldOrMethodRef = items[readUnsignedShort(index + 1)];
+ nameType = items[readUnsignedShort(fieldOrMethodRef + 2)];
+ item.set(ClassWriter.HANDLE_BASE + readByte(index),
+ readClass(fieldOrMethodRef, buf),
+ readUTF8(nameType, buf), readUTF8(nameType + 2, buf));
+ break;
+ }
+ case ClassWriter.INDY:
+ if (classWriter.bootstrapMethods == null) {
+ copyBootstrapMethods(classWriter, items2, buf);
}
- break;
-
-
- case ClassWriter.INDY:
- if (classWriter.bootstrapMethods == null) {
- copyBootstrapMethods(classWriter, items2, buf);
- }
- nameType = items[readUnsignedShort(index + 2)];
- item.set(readUTF8(nameType, buf),
- readUTF8(nameType + 2, buf),
- readUnsignedShort(index));
- break;
-
-
- // case ClassWriter.STR:
- // case ClassWriter.CLASS:
- // case ClassWriter.MTYPE
- default:
- item.set(tag, readUTF8(index, buf), null, null);
- break;
+ nameType = items[readUnsignedShort(index + 2)];
+ item.set(readUTF8(nameType, buf), readUTF8(nameType + 2, buf),
+ readUnsignedShort(index));
+ break;
+ // case ClassWriter.STR:
+ // case ClassWriter.CLASS:
+ // case ClassWriter.MTYPE
+ default:
+ item.set(tag, readUTF8(index, buf), null, null);
+ break;
}
int index2 = item.hashCode % items2.length;
@@ -382,77 +366,59 @@ public class ClassReader {
classWriter.index = ll;
}
- private void copyBootstrapMethods(ClassWriter classWriter, Item[] items2, char[] buf) {
- int i, j, k, u, v;
-
- // skip class header
- v = header;
- v += 8 + (readUnsignedShort(v + 6) << 1);
-
- // skips fields and methods
- i = readUnsignedShort(v);
- v += 2;
- for (; i > 0; --i) {
- j = readUnsignedShort(v + 6);
- v += 8;
- for (; j > 0; --j) {
- v += 6 + readInt(v + 2);
+ /**
+ * Copies the bootstrap method data into the given {@link ClassWriter}.
+ * Should be called before the {@link #accept(ClassVisitor,int)} method.
+ *
+ * @param classWriter
+ * the {@link ClassWriter} to copy bootstrap methods into.
+ */
+ private void copyBootstrapMethods(final ClassWriter classWriter,
+ final Item[] items, final char[] c) {
+ // finds the "BootstrapMethods" attribute
+ int u = getAttributes();
+ boolean found = false;
+ for (int i = readUnsignedShort(u); i > 0; --i) {
+ String attrName = readUTF8(u + 2, c);
+ if ("BootstrapMethods".equals(attrName)) {
+ found = true;
+ break;
}
+ u += 6 + readInt(u + 4);
}
- i = readUnsignedShort(v);
- v += 2;
- for (; i > 0; --i) {
- j = readUnsignedShort(v + 6);
- v += 8;
- for (; j > 0; --j) {
- v += 6 + readInt(v + 2);
- }
+ if (!found) {
+ return;
}
-
- // read class attributes
- i = readUnsignedShort(v);
- v += 2;
- for (; i > 0; --i) {
- String attrName = readUTF8(v, buf);
- int size = readInt(v + 2);
- if ("BootstrapMethods".equals(attrName)) {
- int boostrapMethodCount = readUnsignedShort(v + 6);
- int x = v + 8;
- for (j = 0; j < boostrapMethodCount; j++) {
- int hashCode = readConst(readUnsignedShort(x), buf).hashCode();
- k = readUnsignedShort(x + 2);
- u = x + 4;
- for(; k > 0; --k) {
- hashCode ^= readConst(readUnsignedShort(u), buf).hashCode();
- u += 2;
- }
- Item item = new Item(j);
- item.set(x - v - 8, hashCode & 0x7FFFFFFF);
-
- int index2 = item.hashCode % items2.length;
- item.next = items2[index2];
- items2[index2] = item;
-
- x = u;
- }
-
- classWriter.bootstrapMethodsCount = boostrapMethodCount;
- ByteVector bootstrapMethods = new ByteVector(size + 62);
- bootstrapMethods.putByteArray(b, v + 8, size - 2);
- classWriter.bootstrapMethods = bootstrapMethods;
- return;
+ // copies the bootstrap methods in the class writer
+ int boostrapMethodCount = readUnsignedShort(u + 8);
+ for (int j = 0, v = u + 10; j < boostrapMethodCount; j++) {
+ int position = v - u - 10;
+ int hashCode = readConst(readUnsignedShort(v), c).hashCode();
+ for (int k = readUnsignedShort(v + 2); k > 0; --k) {
+ hashCode ^= readConst(readUnsignedShort(v + 4), c).hashCode();
+ v += 2;
}
- v += 6 + size;
+ v += 4;
+ Item item = new Item(j);
+ item.set(position, hashCode & 0x7FFFFFFF);
+ int index = item.hashCode % items.length;
+ item.next = items[index];
+ items[index] = item;
}
-
- // we are in trouble !!!
+ int attrSize = readInt(u + 4);
+ ByteVector bootstrapMethods = new ByteVector(attrSize + 62);
+ bootstrapMethods.putByteArray(b, u + 10, attrSize - 2);
+ classWriter.bootstrapMethodsCount = boostrapMethodCount;
+ classWriter.bootstrapMethods = bootstrapMethods;
}
/**
* Constructs a new {@link ClassReader} object.
*
- * @param is an input stream from which to read the class.
- * @throws IOException if a problem occurs during reading.
+ * @param is
+ * an input stream from which to read the class.
+ * @throws IOException
+ * if a problem occurs during reading.
*/
public ClassReader(final InputStream is) throws IOException {
this(readClass(is, false));
@@ -461,25 +427,30 @@ public class ClassReader {
/**
* Constructs a new {@link ClassReader} object.
*
- * @param name the binary qualified name of the class to be read.
- * @throws IOException if an exception occurs during reading.
+ * @param name
+ * the binary qualified name of the class to be read.
+ * @throws IOException
+ * if an exception occurs during reading.
*/
public ClassReader(final String name) throws IOException {
- this(readClass(ClassLoader.getSystemResourceAsStream(name.replace('.', '/')
- + ".class"), true));
+ this(readClass(
+ ClassLoader.getSystemResourceAsStream(name.replace('.', '/')
+ + ".class"), true));
}
/**
* Reads the bytecode of a class.
*
- * @param is an input stream from which to read the class.
- * @param close true to close the input stream after reading.
+ * @param is
+ * an input stream from which to read the class.
+ * @param close
+ * true to close the input stream after reading.
* @return the bytecode read from the given input stream.
- * @throws IOException if a problem occurs during reading.
+ * @throws IOException
+ * if a problem occurs during reading.
*/
private static byte[] readClass(final InputStream is, boolean close)
- throws IOException
- {
+ throws IOException {
if (is == null) {
throw new IOException("Class not found");
}
@@ -520,14 +491,16 @@ public class ClassReader {
// ------------------------------------------------------------------------
/**
- * Makes the given visitor visit the Java class of this {@link ClassReader}.
- * This class is the one specified in the constructor (see
+ * Makes the given visitor visit the Java class of this {@link ClassReader}
+ * . This class is the one specified in the constructor (see
* {@link #ClassReader(byte[]) ClassReader}).
*
- * @param classVisitor the visitor that must visit this class.
- * @param flags option flags that can be used to modify the default behavior
- * of this class. See {@link #SKIP_DEBUG}, {@link #EXPAND_FRAMES},
- * {@link #SKIP_FRAMES}, {@link #SKIP_CODE}.
+ * @param classVisitor
+ * the visitor that must visit this class.
+ * @param flags
+ * option flags that can be used to modify the default behavior
+ * of this class. See {@link #SKIP_DEBUG}, {@link #EXPAND_FRAMES}
+ * , {@link #SKIP_FRAMES}, {@link #SKIP_CODE}.
*/
public void accept(final ClassVisitor classVisitor, final int flags) {
accept(classVisitor, new Attribute[0], flags);
@@ -538,1117 +511,923 @@ public class ClassReader {
* This class is the one specified in the constructor (see
* {@link #ClassReader(byte[]) ClassReader}).
*
- * @param classVisitor the visitor that must visit this class.
- * @param attrs prototypes of the attributes that must be parsed during the
- * visit of the class. Any attribute whose type is not equal to the
- * type of one the prototypes will not be parsed: its byte array
- * value will be passed unchanged to the ClassWriter. <i>This may
- * corrupt it if this value contains references to the constant pool,
- * or has syntactic or semantic links with a class element that has
- * been transformed by a class adapter between the reader and the
- * writer</i>.
- * @param flags option flags that can be used to modify the default behavior
- * of this class. See {@link #SKIP_DEBUG}, {@link #EXPAND_FRAMES},
- * {@link #SKIP_FRAMES}, {@link #SKIP_CODE}.
+ * @param classVisitor
+ * the visitor that must visit this class.
+ * @param attrs
+ * prototypes of the attributes that must be parsed during the
+ * visit of the class. Any attribute whose type is not equal to
+ * the type of one the prototypes will not be parsed: its byte
+ * array value will be passed unchanged to the ClassWriter.
+ * <i>This may corrupt it if this value contains references to
+ * the constant pool, or has syntactic or semantic links with a
+ * class element that has been transformed by a class adapter
+ * between the reader and the writer</i>.
+ * @param flags
+ * option flags that can be used to modify the default behavior
+ * of this class. See {@link #SKIP_DEBUG}, {@link #EXPAND_FRAMES}
+ * , {@link #SKIP_FRAMES}, {@link #SKIP_CODE}.
*/
- public void accept(
- final ClassVisitor classVisitor,
- final Attribute[] attrs,
- final int flags)
- {
- byte[] b = this.b; // the bytecode array
+ public void accept(final ClassVisitor classVisitor,
+ final Attribute[] attrs, final int flags) {
+ int u = header; // current offset in the class file
char[] c = new char[maxStringLength]; // buffer used to read strings
- int i, j, k; // loop variables
- int u, v, w; // indexes in b
- Attribute attr;
-
- int access;
- String name;
- String desc;
- String attrName;
- String signature;
- int anns = 0;
- int ianns = 0;
- Attribute cattrs = null;
-
- // visits the header
- u = header;
- access = readUnsignedShort(u);
- name = readClass(u + 2, c);
- v = items[readUnsignedShort(u + 4)];
- String superClassName = v == 0 ? null : readUTF8(v, c);
- String[] implementedItfs = new String[readUnsignedShort(u + 6)];
- w = 0;
+
+ Context context = new Context();
+ context.attrs = attrs;
+ context.flags = flags;
+ context.buffer = c;
+
+ // reads the class declaration
+ int access = readUnsignedShort(u);
+ String name = readClass(u + 2, c);
+ String superClass = readClass(u + 4, c);
+ String[] interfaces = new String[readUnsignedShort(u + 6)];
u += 8;
- for (i = 0; i < implementedItfs.length; ++i) {
- implementedItfs[i] = readClass(u, c);
+ for (int i = 0; i < interfaces.length; ++i) {
+ interfaces[i] = readClass(u, c);
u += 2;
}
- boolean skipCode = (flags & SKIP_CODE) != 0;
- boolean skipDebug = (flags & SKIP_DEBUG) != 0;
- boolean unzip = (flags & EXPAND_FRAMES) != 0;
-
- // skips fields and methods
- v = u;
- i = readUnsignedShort(v);
- v += 2;
- for (; i > 0; --i) {
- j = readUnsignedShort(v + 6);
- v += 8;
- for (; j > 0; --j) {
- v += 6 + readInt(v + 2);
- }
- }
- i = readUnsignedShort(v);
- v += 2;
- for (; i > 0; --i) {
- j = readUnsignedShort(v + 6);
- v += 8;
- for (; j > 0; --j) {
- v += 6 + readInt(v + 2);
- }
- }
- // reads the class's attributes
- signature = null;
+ // reads the class attributes
+ String signature = null;
String sourceFile = null;
String sourceDebug = null;
String enclosingOwner = null;
String enclosingName = null;
String enclosingDesc = null;
- int[] bootstrapMethods = null; // start indexed of the bsms
+ int anns = 0;
+ int ianns = 0;
+ int innerClasses = 0;
+ Attribute attributes = null;
- i = readUnsignedShort(v);
- v += 2;
- for (; i > 0; --i) {
- attrName = readUTF8(v, c);
+ u = getAttributes();
+ for (int i = readUnsignedShort(u); i > 0; --i) {
+ String attrName = readUTF8(u + 2, c);
// tests are sorted in decreasing frequency order
// (based on frequencies observed on typical classes)
if ("SourceFile".equals(attrName)) {
- sourceFile = readUTF8(v + 6, c);
+ sourceFile = readUTF8(u + 8, c);
} else if ("InnerClasses".equals(attrName)) {
- w = v + 6;
+ innerClasses = u + 8;
} else if ("EnclosingMethod".equals(attrName)) {
- enclosingOwner = readClass(v + 6, c);
- int item = readUnsignedShort(v + 8);
+ enclosingOwner = readClass(u + 8, c);
+ int item = readUnsignedShort(u + 10);
if (item != 0) {
enclosingName = readUTF8(items[item], c);
enclosingDesc = readUTF8(items[item] + 2, c);
}
} else if (SIGNATURES && "Signature".equals(attrName)) {
- signature = readUTF8(v + 6, c);
- } else if (ANNOTATIONS && "RuntimeVisibleAnnotations".equals(attrName)) {
- anns = v + 6;
+ signature = readUTF8(u + 8, c);
+ } else if (ANNOTATIONS
+ && "RuntimeVisibleAnnotations".equals(attrName)) {
+ anns = u + 8;
} else if ("Deprecated".equals(attrName)) {
access |= Opcodes.ACC_DEPRECATED;
} else if ("Synthetic".equals(attrName)) {
- access |= Opcodes.ACC_SYNTHETIC | ClassWriter.ACC_SYNTHETIC_ATTRIBUTE;
+ access |= Opcodes.ACC_SYNTHETIC
+ | ClassWriter.ACC_SYNTHETIC_ATTRIBUTE;
} else if ("SourceDebugExtension".equals(attrName)) {
- int len = readInt(v + 2);
- sourceDebug = readUTF(v + 6, len, new char[len]);
- } else if (ANNOTATIONS && "RuntimeInvisibleAnnotations".equals(attrName)) {
- ianns = v + 6;
+ int len = readInt(u + 4);
+ sourceDebug = readUTF(u + 8, len, new char[len]);
+ } else if (ANNOTATIONS
+ && "RuntimeInvisibleAnnotations".equals(attrName)) {
+ ianns = u + 8;
} else if ("BootstrapMethods".equals(attrName)) {
- int boostrapMethodCount = readUnsignedShort(v + 6);
- bootstrapMethods = new int[boostrapMethodCount];
- int x = v + 8;
- for (j = 0; j < boostrapMethodCount; j++) {
- bootstrapMethods[j] = x;
- x += 2 + readUnsignedShort(x + 2) << 1;
+ int[] bootstrapMethods = new int[readUnsignedShort(u + 8)];
+ for (int j = 0, v = u + 10; j < bootstrapMethods.length; j++) {
+ bootstrapMethods[j] = v;
+ v += 2 + readUnsignedShort(v + 2) << 1;
}
+ context.bootstrapMethods = bootstrapMethods;
} else {
- attr = readAttribute(attrs,
- attrName,
- v + 6,
- readInt(v + 2),
- c,
- -1,
- null);
+ Attribute attr = readAttribute(attrs, attrName, u + 8,
+ readInt(u + 4), c, -1, null);
if (attr != null) {
- attr.next = cattrs;
- cattrs = attr;
+ attr.next = attributes;
+ attributes = attr;
}
}
- v += 6 + readInt(v + 2);
+ u += 6 + readInt(u + 4);
}
- // calls the visit method
- classVisitor.visit(readInt(4),
- access,
- name,
- signature,
- superClassName,
- implementedItfs);
-
- // calls the visitSource method
- if (!skipDebug && (sourceFile != null || sourceDebug != null)) {
+
+ // visits the class declaration
+ classVisitor.visit(readInt(items[1] - 7), access, name, signature,
+ superClass, interfaces);
+
+ // visits the source and debug info
+ if ((flags & SKIP_DEBUG) == 0
+ && (sourceFile != null || sourceDebug != null)) {
classVisitor.visitSource(sourceFile, sourceDebug);
}
- // calls the visitOuterClass method
+ // visits the outer class
if (enclosingOwner != null) {
- classVisitor.visitOuterClass(enclosingOwner,
- enclosingName,
+ classVisitor.visitOuterClass(enclosingOwner, enclosingName,
enclosingDesc);
}
// visits the class annotations
- if (ANNOTATIONS) {
- for (i = 1; i >= 0; --i) {
- v = i == 0 ? ianns : anns;
- if (v != 0) {
- j = readUnsignedShort(v);
- v += 2;
- for (; j > 0; --j) {
- v = readAnnotationValues(v + 2,
- c,
- true,
- classVisitor.visitAnnotation(readUTF8(v, c), i != 0));
- }
- }
+ if (ANNOTATIONS && anns != 0) {
+ for (int i = readUnsignedShort(anns), v = anns + 2; i > 0; --i) {
+ v = readAnnotationValues(v + 2, c, true,
+ classVisitor.visitAnnotation(readUTF8(v, c), true));
+ }
+ }
+ if (ANNOTATIONS && ianns != 0) {
+ for (int i = readUnsignedShort(ianns), v = ianns + 2; i > 0; --i) {
+ v = readAnnotationValues(v + 2, c, true,
+ classVisitor.visitAnnotation(readUTF8(v, c), false));
}
}
- // visits the class attributes
- while (cattrs != null) {
- attr = cattrs.next;
- cattrs.next = null;
- classVisitor.visitAttribute(cattrs);
- cattrs = attr;
+ // visits the attributes
+ while (attributes != null) {
+ Attribute attr = attributes.next;
+ attributes.next = null;
+ classVisitor.visitAttribute(attributes);
+ attributes = attr;
}
- // calls the visitInnerClass method
- if (w != 0) {
- i = readUnsignedShort(w);
- w += 2;
- for (; i > 0; --i) {
- classVisitor.visitInnerClass(readUnsignedShort(w) == 0
- ? null
- : readClass(w, c), readUnsignedShort(w + 2) == 0
- ? null
- : readClass(w + 2, c), readUnsignedShort(w + 4) == 0
- ? null
- : readUTF8(w + 4, c), readUnsignedShort(w + 6));
- w += 8;
+ // visits the inner classes
+ if (innerClasses != 0) {
+ int v = innerClasses + 2;
+ for (int i = readUnsignedShort(innerClasses); i > 0; --i) {
+ classVisitor.visitInnerClass(readClass(v, c),
+ readClass(v + 2, c), readUTF8(v + 4, c),
+ readUnsignedShort(v + 6));
+ v += 8;
}
}
- // visits the fields
- i = readUnsignedShort(u);
+ // visits the fields and methods
+ u = header + 10 + 2 * interfaces.length;
+ for (int i = readUnsignedShort(u - 2); i > 0; --i) {
+ u = readField(classVisitor, context, u);
+ }
u += 2;
- for (; i > 0; --i) {
- access = readUnsignedShort(u);
- name = readUTF8(u + 2, c);
- desc = readUTF8(u + 4, c);
- // visits the field's attributes and looks for a ConstantValue
- // attribute
- int fieldValueItem = 0;
- signature = null;
- anns = 0;
- ianns = 0;
- cattrs = null;
-
- j = readUnsignedShort(u + 6);
- u += 8;
- for (; j > 0; --j) {
- attrName = readUTF8(u, c);
- // tests are sorted in decreasing frequency order
- // (based on frequencies observed on typical classes)
- if ("ConstantValue".equals(attrName)) {
- fieldValueItem = readUnsignedShort(u + 6);
- } else if (SIGNATURES && "Signature".equals(attrName)) {
- signature = readUTF8(u + 6, c);
- } else if ("Deprecated".equals(attrName)) {
- access |= Opcodes.ACC_DEPRECATED;
- } else if ("Synthetic".equals(attrName)) {
- access |= Opcodes.ACC_SYNTHETIC | ClassWriter.ACC_SYNTHETIC_ATTRIBUTE;
- } else if (ANNOTATIONS && "RuntimeVisibleAnnotations".equals(attrName)) {
- anns = u + 6;
- } else if (ANNOTATIONS && "RuntimeInvisibleAnnotations".equals(attrName)) {
- ianns = u + 6;
- } else {
- attr = readAttribute(attrs,
- attrName,
- u + 6,
- readInt(u + 2),
- c,
- -1,
- null);
- if (attr != null) {
- attr.next = cattrs;
- cattrs = attr;
- }
+ for (int i = readUnsignedShort(u - 2); i > 0; --i) {
+ u = readMethod(classVisitor, context, u);
+ }
+
+ // visits the end of the class
+ classVisitor.visitEnd();
+ }
+
+ /**
+ * Reads a field and makes the given visitor visit it.
+ *
+ * @param classVisitor
+ * the visitor that must visit the field.
+ * @param context
+ * information about the class being parsed.
+ * @param u
+ * the start offset of the field in the class file.
+ * @return the offset of the first byte following the field in the class.
+ */
+ private int readField(final ClassVisitor classVisitor,
+ final Context context, int u) {
+ // reads the field declaration
+ char[] c = context.buffer;
+ int access = readUnsignedShort(u);
+ String name = readUTF8(u + 2, c);
+ String desc = readUTF8(u + 4, c);
+ u += 6;
+
+ // reads the field attributes
+ String signature = null;
+ int anns = 0;
+ int ianns = 0;
+ Object value = null;
+ Attribute attributes = null;
+
+ for (int i = readUnsignedShort(u); i > 0; --i) {
+ String attrName = readUTF8(u + 2, c);
+ // tests are sorted in decreasing frequency order
+ // (based on frequencies observed on typical classes)
+ if ("ConstantValue".equals(attrName)) {
+ int item = readUnsignedShort(u + 8);
+ value = item == 0 ? null : readConst(item, c);
+ } else if (SIGNATURES && "Signature".equals(attrName)) {
+ signature = readUTF8(u + 8, c);
+ } else if ("Deprecated".equals(attrName)) {
+ access |= Opcodes.ACC_DEPRECATED;
+ } else if ("Synthetic".equals(attrName)) {
+ access |= Opcodes.ACC_SYNTHETIC
+ | ClassWriter.ACC_SYNTHETIC_ATTRIBUTE;
+ } else if (ANNOTATIONS
+ && "RuntimeVisibleAnnotations".equals(attrName)) {
+ anns = u + 8;
+ } else if (ANNOTATIONS
+ && "RuntimeInvisibleAnnotations".equals(attrName)) {
+ ianns = u + 8;
+ } else {
+ Attribute attr = readAttribute(context.attrs, attrName, u + 8,
+ readInt(u + 4), c, -1, null);
+ if (attr != null) {
+ attr.next = attributes;
+ attributes = attr;
}
- u += 6 + readInt(u + 2);
}
- // visits the field
- FieldVisitor fv = classVisitor.visitField(access,
- name,
- desc,
- signature,
- fieldValueItem == 0 ? null : readConst(fieldValueItem, c));
- // visits the field annotations and attributes
- if (fv != null) {
- if (ANNOTATIONS) {
- for (j = 1; j >= 0; --j) {
- v = j == 0 ? ianns : anns;
- if (v != 0) {
- k = readUnsignedShort(v);
- v += 2;
- for (; k > 0; --k) {
- v = readAnnotationValues(v + 2,
- c,
- true,
- fv.visitAnnotation(readUTF8(v, c), j != 0));
- }
- }
- }
- }
- while (cattrs != null) {
- attr = cattrs.next;
- cattrs.next = null;
- fv.visitAttribute(cattrs);
- cattrs = attr;
- }
- fv.visitEnd();
+ u += 6 + readInt(u + 4);
+ }
+ u += 2;
+
+ // visits the field declaration
+ FieldVisitor fv = classVisitor.visitField(access, name, desc,
+ signature, value);
+ if (fv == null) {
+ return u;
+ }
+
+ // visits the field annotations
+ if (ANNOTATIONS && anns != 0) {
+ for (int i = readUnsignedShort(anns), v = anns + 2; i > 0; --i) {
+ v = readAnnotationValues(v + 2, c, true,
+ fv.visitAnnotation(readUTF8(v, c), true));
+ }
+ }
+ if (ANNOTATIONS && ianns != 0) {
+ for (int i = readUnsignedShort(ianns), v = ianns + 2; i > 0; --i) {
+ v = readAnnotationValues(v + 2, c, true,
+ fv.visitAnnotation(readUTF8(v, c), false));
}
}
- // visits the methods
- i = readUnsignedShort(u);
- u += 2;
- for (; i > 0; --i) {
- int u0 = u + 6;
- access = readUnsignedShort(u);
- name = readUTF8(u + 2, c);
- desc = readUTF8(u + 4, c);
- signature = null;
- anns = 0;
- ianns = 0;
- int dann = 0;
- int mpanns = 0;
- int impanns = 0;
- cattrs = null;
- v = 0;
- w = 0;
-
- // looks for Code and Exceptions attributes
- j = readUnsignedShort(u + 6);
- u += 8;
- for (; j > 0; --j) {
- attrName = readUTF8(u, c);
- int attrSize = readInt(u + 2);
- u += 6;
- // tests are sorted in decreasing frequency order
- // (based on frequencies observed on typical classes)
- if ("Code".equals(attrName)) {
- if (!skipCode) {
- v = u;
- }
- } else if ("Exceptions".equals(attrName)) {
- w = u;
- } else if (SIGNATURES && "Signature".equals(attrName)) {
- signature = readUTF8(u, c);
- } else if ("Deprecated".equals(attrName)) {
- access |= Opcodes.ACC_DEPRECATED;
- } else if (ANNOTATIONS && "RuntimeVisibleAnnotations".equals(attrName)) {
- anns = u;
- } else if (ANNOTATIONS && "AnnotationDefault".equals(attrName)) {
- dann = u;
- } else if ("Synthetic".equals(attrName)) {
- access |= Opcodes.ACC_SYNTHETIC | ClassWriter.ACC_SYNTHETIC_ATTRIBUTE;
- } else if (ANNOTATIONS && "RuntimeInvisibleAnnotations".equals(attrName)) {
- ianns = u;
- } else if (ANNOTATIONS && "RuntimeVisibleParameterAnnotations".equals(attrName))
- {
- mpanns = u;
- } else if (ANNOTATIONS && "RuntimeInvisibleParameterAnnotations".equals(attrName))
- {
- impanns = u;
- } else {
- attr = readAttribute(attrs,
- attrName,
- u,
- attrSize,
- c,
- -1,
- null);
- if (attr != null) {
- attr.next = cattrs;
- cattrs = attr;
- }
+ // visits the field attributes
+ while (attributes != null) {
+ Attribute attr = attributes.next;
+ attributes.next = null;
+ fv.visitAttribute(attributes);
+ attributes = attr;
+ }
+
+ // visits the end of the field
+ fv.visitEnd();
+
+ return u;
+ }
+
+ /**
+ * Reads a method and makes the given visitor visit it.
+ *
+ * @param classVisitor
+ * the visitor that must visit the method.
+ * @param context
+ * information about the class being parsed.
+ * @param u
+ * the start offset of the method in the class file.
+ * @return the offset of the first byte following the method in the class.
+ */
+ private int readMethod(final ClassVisitor classVisitor,
+ final Context context, int u) {
+ // reads the method declaration
+ char[] c = context.buffer;
+ int access = readUnsignedShort(u);
+ String name = readUTF8(u + 2, c);
+ String desc = readUTF8(u + 4, c);
+ u += 6;
+
+ // reads the method attributes
+ int code = 0;
+ int exception = 0;
+ String[] exceptions = null;
+ String signature = null;
+ int anns = 0;
+ int ianns = 0;
+ int dann = 0;
+ int mpanns = 0;
+ int impanns = 0;
+ int firstAttribute = u;
+ Attribute attributes = null;
+
+ for (int i = readUnsignedShort(u); i > 0; --i) {
+ String attrName = readUTF8(u + 2, c);
+ // tests are sorted in decreasing frequency order
+ // (based on frequencies observed on typical classes)
+ if ("Code".equals(attrName)) {
+ if ((context.flags & SKIP_CODE) == 0) {
+ code = u + 8;
}
- u += attrSize;
- }
- // reads declared exceptions
- String[] exceptions;
- if (w == 0) {
- exceptions = null;
+ } else if ("Exceptions".equals(attrName)) {
+ exceptions = new String[readUnsignedShort(u + 8)];
+ exception = u + 10;
+ for (int j = 0; j < exceptions.length; ++j) {
+ exceptions[j] = readClass(exception, c);
+ exception += 2;
+ }
+ } else if (SIGNATURES && "Signature".equals(attrName)) {
+ signature = readUTF8(u + 8, c);
+ } else if ("Deprecated".equals(attrName)) {
+ access |= Opcodes.ACC_DEPRECATED;
+ } else if (ANNOTATIONS
+ && "RuntimeVisibleAnnotations".equals(attrName)) {
+ anns = u + 8;
+ } else if (ANNOTATIONS && "AnnotationDefault".equals(attrName)) {
+ dann = u + 8;
+ } else if ("Synthetic".equals(attrName)) {
+ access |= Opcodes.ACC_SYNTHETIC
+ | ClassWriter.ACC_SYNTHETIC_ATTRIBUTE;
+ } else if (ANNOTATIONS
+ && "RuntimeInvisibleAnnotations".equals(attrName)) {
+ ianns = u + 8;
+ } else if (ANNOTATIONS
+ && "RuntimeVisibleParameterAnnotations".equals(attrName)) {
+ mpanns = u + 8;
+ } else if (ANNOTATIONS
+ && "RuntimeInvisibleParameterAnnotations".equals(attrName)) {
+ impanns = u + 8;
} else {
- exceptions = new String[readUnsignedShort(w)];
- w += 2;
- for (j = 0; j < exceptions.length; ++j) {
- exceptions[j] = readClass(w, c);
- w += 2;
+ Attribute attr = readAttribute(context.attrs, attrName, u + 8,
+ readInt(u + 4), c, -1, null);
+ if (attr != null) {
+ attr.next = attributes;
+ attributes = attr;
}
}
+ u += 6 + readInt(u + 4);
+ }
+ u += 2;
- // visits the method's code, if any
- MethodVisitor mv = classVisitor.visitMethod(access,
- name,
- desc,
- signature,
- exceptions);
+ // visits the method declaration
+ MethodVisitor mv = classVisitor.visitMethod(access, name, desc,
+ signature, exceptions);
+ if (mv == null) {
+ return u;
+ }
- if (mv != null) {
- /*
- * if the returned MethodVisitor is in fact a MethodWriter, it
- * means there is no method adapter between the reader and the
- * writer. If, in addition, the writer's constant pool was
- * copied from this reader (mw.cw.cr == this), and the signature
- * and exceptions of the method have not been changed, then it
- * is possible to skip all visit events and just copy the
- * original code of the method to the writer (the access, name
- * and descriptor can have been changed, this is not important
- * since they are not copied as is from the reader).
- */
- if (WRITER && mv instanceof MethodWriter) {
- MethodWriter mw = (MethodWriter) mv;
- if (mw.cw.cr == this) {
- if (signature == mw.signature) {
- boolean sameExceptions = false;
- if (exceptions == null) {
- sameExceptions = mw.exceptionCount == 0;
- } else {
- if (exceptions.length == mw.exceptionCount) {
- sameExceptions = true;
- for (j = exceptions.length - 1; j >= 0; --j)
- {
- w -= 2;
- if (mw.exceptions[j] != readUnsignedShort(w))
- {
- sameExceptions = false;
- break;
- }
- }
- }
- }
- if (sameExceptions) {
- /*
- * we do not copy directly the code into
- * MethodWriter to save a byte array copy
- * operation. The real copy will be done in
- * ClassWriter.toByteArray().
- */
- mw.classReaderOffset = u0;
- mw.classReaderLength = u - u0;
- continue;
- }
+ /*
+ * if the returned MethodVisitor is in fact a MethodWriter, it means
+ * there is no method adapter between the reader and the writer. If, in
+ * addition, the writer's constant pool was copied from this reader
+ * (mw.cw.cr == this), and the signature and exceptions of the method
+ * have not been changed, then it is possible to skip all visit events
+ * and just copy the original code of the method to the writer (the
+ * access, name and descriptor can have been changed, this is not
+ * important since they are not copied as is from the reader).
+ */
+ if (WRITER && mv instanceof MethodWriter) {
+ MethodWriter mw = (MethodWriter) mv;
+ if (mw.cw.cr == this && signature == mw.signature) {
+ boolean sameExceptions = false;
+ if (exceptions == null) {
+ sameExceptions = mw.exceptionCount == 0;
+ } else if (exceptions.length == mw.exceptionCount) {
+ sameExceptions = true;
+ for (int j = exceptions.length - 1; j >= 0; --j) {
+ exception -= 2;
+ if (mw.exceptions[j] != readUnsignedShort(exception)) {
+ sameExceptions = false;
+ break;
}
}
}
-
- if (ANNOTATIONS && dann != 0) {
- AnnotationVisitor dv = mv.visitAnnotationDefault();
- readAnnotationValue(dann, c, null, dv);
- if (dv != null) {
- dv.visitEnd();
- }
- }
- if (ANNOTATIONS) {
- for (j = 1; j >= 0; --j) {
- w = j == 0 ? ianns : anns;
- if (w != 0) {
- k = readUnsignedShort(w);
- w += 2;
- for (; k > 0; --k) {
- w = readAnnotationValues(w + 2,
- c,
- true,
- mv.visitAnnotation(readUTF8(w, c), j != 0));
- }
- }
- }
+ if (sameExceptions) {
+ /*
+ * we do not copy directly the code into MethodWriter to
+ * save a byte array copy operation. The real copy will be
+ * done in ClassWriter.toByteArray().
+ */
+ mw.classReaderOffset = firstAttribute;
+ mw.classReaderLength = u - firstAttribute;
+ return u;
}
- if (ANNOTATIONS && mpanns != 0) {
- readParameterAnnotations(mpanns, desc, c, true, mv);
+ }
+ }
+
+ // visits the method annotations
+ if (ANNOTATIONS && dann != 0) {
+ AnnotationVisitor dv = mv.visitAnnotationDefault();
+ readAnnotationValue(dann, c, null, dv);
+ if (dv != null) {
+ dv.visitEnd();
+ }
+ }
+ if (ANNOTATIONS && anns != 0) {
+ for (int i = readUnsignedShort(anns), v = anns + 2; i > 0; --i) {
+ v = readAnnotationValues(v + 2, c, true,
+ mv.visitAnnotation(readUTF8(v, c), true));
+ }
+ }
+ if (ANNOTATIONS && ianns != 0) {
+ for (int i = readUnsignedShort(ianns), v = ianns + 2; i > 0; --i) {
+ v = readAnnotationValues(v + 2, c, true,
+ mv.visitAnnotation(readUTF8(v, c), false));
+ }
+ }
+ if (ANNOTATIONS && mpanns != 0) {
+ readParameterAnnotations(mpanns, desc, c, true, mv);
+ }
+ if (ANNOTATIONS && impanns != 0) {
+ readParameterAnnotations(impanns, desc, c, false, mv);
+ }
+
+ // visits the method attributes
+ while (attributes != null) {
+ Attribute attr = attributes.next;
+ attributes.next = null;
+ mv.visitAttribute(attributes);
+ attributes = attr;
+ }
+
+ // visits the method code
+ if (code != 0) {
+ context.access = access;
+ context.name = name;
+ context.desc = desc;
+ mv.visitCode();
+ readCode(mv, context, code);
+ }
+
+ // visits the end of the method
+ mv.visitEnd();
+
+ return u;
+ }
+
+ /**
+ * Reads the bytecode of a method and makes the given visitor visit it.
+ *
+ * @param mv
+ * the visitor that must visit the method's code.
+ * @param context
+ * information about the class being parsed.
+ * @param u
+ * the start offset of the code attribute in the class file.
+ */
+ private void readCode(final MethodVisitor mv, final Context context, int u) {
+ // reads the header
+ byte[] b = this.b;
+ char[] c = context.buffer;
+ int maxStack = readUnsignedShort(u);
+ int maxLocals = readUnsignedShort(u + 2);
+ int codeLength = readInt(u + 4);
+ u += 8;
+
+ // reads the bytecode to find the labels
+ int codeStart = u;
+ int codeEnd = u + codeLength;
+ Label[] labels = new Label[codeLength + 2];
+ readLabel(codeLength + 1, labels);
+ while (u < codeEnd) {
+ int offset = u - codeStart;
+ int opcode = b[u] & 0xFF;
+ switch (ClassWriter.TYPE[opcode]) {
+ case ClassWriter.NOARG_INSN:
+ case ClassWriter.IMPLVAR_INSN:
+ u += 1;
+ break;
+ case ClassWriter.LABEL_INSN:
+ readLabel(offset + readShort(u + 1), labels);
+ u += 3;
+ break;
+ case ClassWriter.LABELW_INSN:
+ readLabel(offset + readInt(u + 1), labels);
+ u += 5;
+ break;
+ case ClassWriter.WIDE_INSN:
+ opcode = b[u + 1] & 0xFF;
+ if (opcode == Opcodes.IINC) {
+ u += 6;
+ } else {
+ u += 4;
}
- if (ANNOTATIONS && impanns != 0) {
- readParameterAnnotations(impanns, desc, c, false, mv);
+ break;
+ case ClassWriter.TABL_INSN:
+ // skips 0 to 3 padding bytes
+ u = u + 4 - (offset & 3);
+ // reads instruction
+ readLabel(offset + readInt(u), labels);
+ for (int i = readInt(u + 8) - readInt(u + 4) + 1; i > 0; --i) {
+ readLabel(offset + readInt(u + 12), labels);
+ u += 4;
}
- while (cattrs != null) {
- attr = cattrs.next;
- cattrs.next = null;
- mv.visitAttribute(cattrs);
- cattrs = attr;
+ u += 12;
+ break;
+ case ClassWriter.LOOK_INSN:
+ // skips 0 to 3 padding bytes
+ u = u + 4 - (offset & 3);
+ // reads instruction
+ readLabel(offset + readInt(u), labels);
+ for (int i = readInt(u + 4); i > 0; --i) {
+ readLabel(offset + readInt(u + 12), labels);
+ u += 8;
}
+ u += 8;
+ break;
+ case ClassWriter.VAR_INSN:
+ case ClassWriter.SBYTE_INSN:
+ case ClassWriter.LDC_INSN:
+ u += 2;
+ break;
+ case ClassWriter.SHORT_INSN:
+ case ClassWriter.LDCW_INSN:
+ case ClassWriter.FIELDORMETH_INSN:
+ case ClassWriter.TYPE_INSN:
+ case ClassWriter.IINC_INSN:
+ u += 3;
+ break;
+ case ClassWriter.ITFMETH_INSN:
+ case ClassWriter.INDYMETH_INSN:
+ u += 5;
+ break;
+ // case MANA_INSN:
+ default:
+ u += 4;
+ break;
}
+ }
- if (mv != null && v != 0) {
- int maxStack = readUnsignedShort(v);
- int maxLocals = readUnsignedShort(v + 2);
- int codeLength = readInt(v + 4);
- v += 8;
+ // reads the try catch entries to find the labels, and also visits them
+ for (int i = readUnsignedShort(u); i > 0; --i) {
+ Label start = readLabel(readUnsignedShort(u + 2), labels);
+ Label end = readLabel(readUnsignedShort(u + 4), labels);
+ Label handler = readLabel(readUnsignedShort(u + 6), labels);
+ String type = readUTF8(items[readUnsignedShort(u + 8)], c);
+ mv.visitTryCatchBlock(start, end, handler, type);
+ u += 8;
+ }
+ u += 2;
- int codeStart = v;
- int codeEnd = v + codeLength;
-
- mv.visitCode();
-
- // 1st phase: finds the labels
- int label;
- Label[] labels = new Label[codeLength + 2];
- readLabel(codeLength + 1, labels);
- while (v < codeEnd) {
- w = v - codeStart;
- int opcode = b[v] & 0xFF;
- switch (ClassWriter.TYPE[opcode]) {
- case ClassWriter.NOARG_INSN:
- case ClassWriter.IMPLVAR_INSN:
- v += 1;
- break;
- case ClassWriter.LABEL_INSN:
- readLabel(w + readShort(v + 1), labels);
- v += 3;
- break;
- case ClassWriter.LABELW_INSN:
- readLabel(w + readInt(v + 1), labels);
- v += 5;
- break;
- case ClassWriter.WIDE_INSN:
- opcode = b[v + 1] & 0xFF;
- if (opcode == Opcodes.IINC) {
- v += 6;
- } else {
- v += 4;
- }
- break;
- case ClassWriter.TABL_INSN:
- // skips 0 to 3 padding bytes*
- v = v + 4 - (w & 3);
- // reads instruction
- readLabel(w + readInt(v), labels);
- j = readInt(v + 8) - readInt(v + 4) + 1;
- v += 12;
- for (; j > 0; --j) {
- readLabel(w + readInt(v), labels);
- v += 4;
- }
- break;
- case ClassWriter.LOOK_INSN:
- // skips 0 to 3 padding bytes*
- v = v + 4 - (w & 3);
- // reads instruction
- readLabel(w + readInt(v), labels);
- j = readInt(v + 4);
- v += 8;
- for (; j > 0; --j) {
- readLabel(w + readInt(v + 4), labels);
- v += 8;
- }
- break;
- case ClassWriter.VAR_INSN:
- case ClassWriter.SBYTE_INSN:
- case ClassWriter.LDC_INSN:
- v += 2;
- break;
- case ClassWriter.SHORT_INSN:
- case ClassWriter.LDCW_INSN:
- case ClassWriter.FIELDORMETH_INSN:
- case ClassWriter.TYPE_INSN:
- case ClassWriter.IINC_INSN:
- v += 3;
- break;
- case ClassWriter.ITFMETH_INSN:
- case ClassWriter.INDYMETH_INSN:
- v += 5;
- break;
- // case MANA_INSN:
- default:
- v += 4;
- break;
- }
- }
- // parses the try catch entries
- j = readUnsignedShort(v);
- v += 2;
- for (; j > 0; --j) {
- Label start = readLabel(readUnsignedShort(v), labels);
- Label end = readLabel(readUnsignedShort(v + 2), labels);
- Label handler = readLabel(readUnsignedShort(v + 4), labels);
- int type = readUnsignedShort(v + 6);
- if (type == 0) {
- mv.visitTryCatchBlock(start, end, handler, null);
- } else {
- mv.visitTryCatchBlock(start,
- end,
- handler,
- readUTF8(items[type], c));
- }
- v += 8;
- }
- // parses the local variable, line number tables, and code
- // attributes
- int varTable = 0;
- int varTypeTable = 0;
- int stackMap = 0;
- int stackMapSize = 0;
- int frameCount = 0;
- int frameMode = 0;
- int frameOffset = 0;
- int frameLocalCount = 0;
- int frameLocalDiff = 0;
- int frameStackCount = 0;
- Object[] frameLocal = null;
- Object[] frameStack = null;
- boolean zip = true;
- cattrs = null;
- j = readUnsignedShort(v);
- v += 2;
- for (; j > 0; --j) {
- attrName = readUTF8(v, c);
- if ("LocalVariableTable".equals(attrName)) {
- if (!skipDebug) {
- varTable = v + 6;
- k = readUnsignedShort(v + 6);
- w = v + 8;
- for (; k > 0; --k) {
- label = readUnsignedShort(w);
- if (labels[label] == null) {
- readLabel(label, labels).status |= Label.DEBUG;
- }
- label += readUnsignedShort(w + 2);
- if (labels[label] == null) {
- readLabel(label, labels).status |= Label.DEBUG;
- }
- w += 10;
- }
- }
- } else if ("LocalVariableTypeTable".equals(attrName)) {
- varTypeTable = v + 6;
- } else if ("LineNumberTable".equals(attrName)) {
- if (!skipDebug) {
- k = readUnsignedShort(v + 6);
- w = v + 8;
- for (; k > 0; --k) {
- label = readUnsignedShort(w);
- if (labels[label] == null) {
- readLabel(label, labels).status |= Label.DEBUG;
- }
- labels[label].line = readUnsignedShort(w + 2);
- w += 4;
- }
- }
- } else if (FRAMES && "StackMapTable".equals(attrName)) {
- if ((flags & SKIP_FRAMES) == 0) {
- stackMap = v + 8;
- stackMapSize = readInt(v + 2);
- frameCount = readUnsignedShort(v + 6);
+ // reads the code attributes
+ int varTable = 0;
+ int varTypeTable = 0;
+ boolean zip = true;
+ boolean unzip = (context.flags & EXPAND_FRAMES) != 0;
+ int stackMap = 0;
+ int stackMapSize = 0;
+ int frameCount = 0;
+ Context frame = null;
+ Attribute attributes = null;
+
+ for (int i = readUnsignedShort(u); i > 0; --i) {
+ String attrName = readUTF8(u + 2, c);
+ if ("LocalVariableTable".equals(attrName)) {
+ if ((context.flags & SKIP_DEBUG) == 0) {
+ varTable = u + 8;
+ for (int j = readUnsignedShort(u + 8), v = u; j > 0; --j) {
+ int label = readUnsignedShort(v + 10);
+ if (labels[label] == null) {
+ readLabel(label, labels).status |= Label.DEBUG;
}
- /*
- * here we do not extract the labels corresponding to
- * the attribute content. This would require a full
- * parsing of the attribute, which would need to be
- * repeated in the second phase (see below). Instead the
- * content of the attribute is read one frame at a time
- * (i.e. after a frame has been visited, the next frame
- * is read), and the labels it contains are also
- * extracted one frame at a time. Thanks to the ordering
- * of frames, having only a "one frame lookahead" is not
- * a problem, i.e. it is not possible to see an offset
- * smaller than the offset of the current insn and for
- * which no Label exist.
- */
- /*
- * This is not true for UNINITIALIZED type offsets. We
- * solve this by parsing the stack map table without a
- * full decoding (see below).
- */
- } else if (FRAMES && "StackMap".equals(attrName)) {
- if ((flags & SKIP_FRAMES) == 0) {
- stackMap = v + 8;
- stackMapSize = readInt(v + 2);
- frameCount = readUnsignedShort(v + 6);
- zip = false;
- }
- /*
- * IMPORTANT! here we assume that the frames are
- * ordered, as in the StackMapTable attribute, although
- * this is not guaranteed by the attribute format.
- */
- } else {
- for (k = 0; k < attrs.length; ++k) {
- if (attrs[k].type.equals(attrName)) {
- attr = attrs[k].read(this,
- v + 6,
- readInt(v + 2),
- c,
- codeStart - 8,
- labels);
- if (attr != null) {
- attr.next = cattrs;
- cattrs = attr;
- }
- }
+ label += readUnsignedShort(v + 12);
+ if (labels[label] == null) {
+ readLabel(label, labels).status |= Label.DEBUG;
}
+ v += 10;
}
- v += 6 + readInt(v + 2);
}
-
- // 2nd phase: visits each instruction
- if (FRAMES && stackMap != 0) {
- // creates the very first (implicit) frame from the method
- // descriptor
- frameLocal = new Object[maxLocals];
- frameStack = new Object[maxStack];
- if (unzip) {
- int local = 0;
- if ((access & Opcodes.ACC_STATIC) == 0) {
- if ("<init>".equals(name)) {
- frameLocal[local++] = Opcodes.UNINITIALIZED_THIS;
- } else {
- frameLocal[local++] = readClass(header + 2, c);
- }
- }
- j = 1;
- loop: while (true) {
- k = j;
- switch (desc.charAt(j++)) {
- case 'Z':
- case 'C':
- case 'B':
- case 'S':
- case 'I':
- frameLocal[local++] = Opcodes.INTEGER;
- break;
- case 'F':
- frameLocal[local++] = Opcodes.FLOAT;
- break;
- case 'J':
- frameLocal[local++] = Opcodes.LONG;
- break;
- case 'D':
- frameLocal[local++] = Opcodes.DOUBLE;
- break;
- case '[':
- while (desc.charAt(j) == '[') {
- ++j;
- }
- if (desc.charAt(j) == 'L') {
- ++j;
- while (desc.charAt(j) != ';') {
- ++j;
- }
- }
- frameLocal[local++] = desc.substring(k, ++j);
- break;
- case 'L':
- while (desc.charAt(j) != ';') {
- ++j;
- }
- frameLocal[local++] = desc.substring(k + 1,
- j++);
- break;
- default:
- break loop;
- }
+ } else if ("LocalVariableTypeTable".equals(attrName)) {
+ varTypeTable = u + 8;
+ } else if ("LineNumberTable".equals(attrName)) {
+ if ((context.flags & SKIP_DEBUG) == 0) {
+ for (int j = readUnsignedShort(u + 8), v = u; j > 0; --j) {
+ int label = readUnsignedShort(v + 10);
+ if (labels[label] == null) {
+ readLabel(label, labels).status |= Label.DEBUG;
}
- frameLocalCount = local;
+ labels[label].line = readUnsignedShort(v + 12);
+ v += 4;
}
- /*
- * for the first explicit frame the offset is not
- * offset_delta + 1 but only offset_delta; setting the
- * implicit frame offset to -1 allow the use of the
- * "offset_delta + 1" rule in all cases
- */
- frameOffset = -1;
- /*
- * Finds labels for UNINITIALIZED frame types. Instead of
- * decoding each element of the stack map table, we look
- * for 3 consecutive bytes that "look like" an UNINITIALIZED
- * type (tag 8, offset within code bounds, NEW instruction
- * at this offset). We may find false positives (i.e. not
- * real UNINITIALIZED types), but this should be rare, and
- * the only consequence will be the creation of an unneeded
- * label. This is better than creating a label for each NEW
- * instruction, and faster than fully decoding the whole
- * stack map table.
- */
- for (j = stackMap; j < stackMap + stackMapSize - 2; ++j) {
- if (b[j] == 8) { // UNINITIALIZED FRAME TYPE
- k = readUnsignedShort(j + 1);
- if (k >= 0 && k < codeLength) { // potential offset
- if ((b[codeStart + k] & 0xFF) == Opcodes.NEW) { // NEW at this offset
- readLabel(k, labels);
- }
- }
+ }
+ } else if (FRAMES && "StackMapTable".equals(attrName)) {
+ if ((context.flags & SKIP_FRAMES) == 0) {
+ stackMap = u + 10;
+ stackMapSize = readInt(u + 4);
+ frameCount = readUnsignedShort(u + 8);
+ }
+ /*
+ * here we do not extract the labels corresponding to the
+ * attribute content. This would require a full parsing of the
+ * attribute, which would need to be repeated in the second
+ * phase (see below). Instead the content of the attribute is
+ * read one frame at a time (i.e. after a frame has been
+ * visited, the next frame is read), and the labels it contains
+ * are also extracted one frame at a time. Thanks to the
+ * ordering of frames, having only a "one frame lookahead" is
+ * not a problem, i.e. it is not possible to see an offset
+ * smaller than the offset of the current insn and for which no
+ * Label exist.
+ */
+ /*
+ * This is not true for UNINITIALIZED type offsets. We solve
+ * this by parsing the stack map table without a full decoding
+ * (see below).
+ */
+ } else if (FRAMES && "StackMap".equals(attrName)) {
+ if ((context.flags & SKIP_FRAMES) == 0) {
+ zip = false;
+ stackMap = u + 10;
+ stackMapSize = readInt(u + 4);
+ frameCount = readUnsignedShort(u + 8);
+ }
+ /*
+ * IMPORTANT! here we assume that the frames are ordered, as in
+ * the StackMapTable attribute, although this is not guaranteed
+ * by the attribute format.
+ */
+ } else {
+ for (int j = 0; j < context.attrs.length; ++j) {
+ if (context.attrs[j].type.equals(attrName)) {
+ Attribute attr = context.attrs[j].read(this, u + 8,
+ readInt(u + 4), c, codeStart - 8, labels);
+ if (attr != null) {
+ attr.next = attributes;
+ attributes = attr;
}
}
}
- v = codeStart;
- Label l;
- while (v < codeEnd) {
- w = v - codeStart;
-
- l = labels[w];
- if (l != null) {
- mv.visitLabel(l);
- if (!skipDebug && l.line > 0) {
- mv.visitLineNumber(l.line, l);
+ }
+ u += 6 + readInt(u + 4);
+ }
+ u += 2;
+
+ // generates the first (implicit) stack map frame
+ if (FRAMES && stackMap != 0) {
+ /*
+ * for the first explicit frame the offset is not offset_delta + 1
+ * but only offset_delta; setting the implicit frame offset to -1
+ * allow the use of the "offset_delta + 1" rule in all cases
+ */
+ frame = context;
+ frame.offset = -1;
+ frame.mode = 0;
+ frame.localCount = 0;
+ frame.localDiff = 0;
+ frame.stackCount = 0;
+ frame.local = new Object[maxLocals];
+ frame.stack = new Object[maxStack];
+ if (unzip) {
+ getImplicitFrame(context);
+ }
+ /*
+ * Finds labels for UNINITIALIZED frame types. Instead of decoding
+ * each element of the stack map table, we look for 3 consecutive
+ * bytes that "look like" an UNINITIALIZED type (tag 8, offset
+ * within code bounds, NEW instruction at this offset). We may find
+ * false positives (i.e. not real UNINITIALIZED types), but this
+ * should be rare, and the only consequence will be the creation of
+ * an unneeded label. This is better than creating a label for each
+ * NEW instruction, and faster than fully decoding the whole stack
+ * map table.
+ */
+ for (int i = stackMap; i < stackMap + stackMapSize - 2; ++i) {
+ if (b[i] == 8) { // UNINITIALIZED FRAME TYPE
+ int v = readUnsignedShort(i + 1);
+ if (v >= 0 && v < codeLength) {
+ if ((b[codeStart + v] & 0xFF) == Opcodes.NEW) {
+ readLabel(v, labels);
}
}
+ }
+ }
+ }
- while (FRAMES && frameLocal != null
- && (frameOffset == w || frameOffset == -1))
- {
- // if there is a frame for this offset,
- // makes the visitor visit it,
- // and reads the next frame if there is one.
- if (!zip || unzip) {
- mv.visitFrame(Opcodes.F_NEW,
- frameLocalCount,
- frameLocal,
- frameStackCount,
- frameStack);
- } else if (frameOffset != -1) {
- mv.visitFrame(frameMode,
- frameLocalDiff,
- frameLocal,
- frameStackCount,
- frameStack);
- }
+ // visits the instructions
+ u = codeStart;
+ while (u < codeEnd) {
+ int offset = u - codeStart;
+
+ // visits the label and line number for this offset, if any
+ Label l = labels[offset];
+ if (l != null) {
+ mv.visitLabel(l);
+ if ((context.flags & SKIP_DEBUG) == 0 && l.line > 0) {
+ mv.visitLineNumber(l.line, l);
+ }
+ }
- if (frameCount > 0) {
- int tag, delta, n;
- if (zip) {
- tag = b[stackMap++] & 0xFF;
- } else {
- tag = MethodWriter.FULL_FRAME;
- frameOffset = -1;
- }
- frameLocalDiff = 0;
- if (tag < MethodWriter.SAME_LOCALS_1_STACK_ITEM_FRAME)
- {
- delta = tag;
- frameMode = Opcodes.F_SAME;
- frameStackCount = 0;
- } else if (tag < MethodWriter.RESERVED) {
- delta = tag
- - MethodWriter.SAME_LOCALS_1_STACK_ITEM_FRAME;
- stackMap = readFrameType(frameStack,
- 0,
- stackMap,
- c,
- labels);
- frameMode = Opcodes.F_SAME1;
- frameStackCount = 1;
- } else {
- delta = readUnsignedShort(stackMap);
- stackMap += 2;
- if (tag == MethodWriter.SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED)
- {
- stackMap = readFrameType(frameStack,
- 0,
- stackMap,
- c,
- labels);
- frameMode = Opcodes.F_SAME1;
- frameStackCount = 1;
- } else if (tag >= MethodWriter.CHOP_FRAME
- && tag < MethodWriter.SAME_FRAME_EXTENDED)
- {
- frameMode = Opcodes.F_CHOP;
- frameLocalDiff = MethodWriter.SAME_FRAME_EXTENDED
- - tag;
- frameLocalCount -= frameLocalDiff;
- frameStackCount = 0;
- } else if (tag == MethodWriter.SAME_FRAME_EXTENDED)
- {
- frameMode = Opcodes.F_SAME;
- frameStackCount = 0;
- } else if (tag < MethodWriter.FULL_FRAME) {
- j = unzip ? frameLocalCount : 0;
- for (k = tag
- - MethodWriter.SAME_FRAME_EXTENDED; k > 0; k--)
- {
- stackMap = readFrameType(frameLocal,
- j++,
- stackMap,
- c,
- labels);
- }
- frameMode = Opcodes.F_APPEND;
- frameLocalDiff = tag
- - MethodWriter.SAME_FRAME_EXTENDED;
- frameLocalCount += frameLocalDiff;
- frameStackCount = 0;
- } else { // if (tag == FULL_FRAME) {
- frameMode = Opcodes.F_FULL;
- n = frameLocalDiff = frameLocalCount = readUnsignedShort(stackMap);
- stackMap += 2;
- for (j = 0; n > 0; n--) {
- stackMap = readFrameType(frameLocal,
- j++,
- stackMap,
- c,
- labels);
- }
- n = frameStackCount = readUnsignedShort(stackMap);
- stackMap += 2;
- for (j = 0; n > 0; n--) {
- stackMap = readFrameType(frameStack,
- j++,
- stackMap,
- c,
- labels);
- }
- }
- }
- frameOffset += delta + 1;
- readLabel(frameOffset, labels);
-
- --frameCount;
- } else {
- frameLocal = null;
- }
+ // visits the frame for this offset, if any
+ while (FRAMES && frame != null
+ && (frame.offset == offset || frame.offset == -1)) {
+ // if there is a frame for this offset, makes the visitor visit
+ // it, and reads the next frame if there is one.
+ if (frame.offset != -1) {
+ if (!zip || unzip) {
+ mv.visitFrame(Opcodes.F_NEW, frame.localCount,
+ frame.local, frame.stackCount, frame.stack);
+ } else {
+ mv.visitFrame(frame.mode, frame.localDiff, frame.local,
+ frame.stackCount, frame.stack);
}
+ }
+ if (frameCount > 0) {
+ stackMap = readFrame(stackMap, zip, unzip, labels, frame);
+ --frameCount;
+ } else {
+ frame = null;
+ }
+ }
- int opcode = b[v] & 0xFF;
- switch (ClassWriter.TYPE[opcode]) {
- case ClassWriter.NOARG_INSN:
- mv.visitInsn(opcode);
- v += 1;
- break;
- case ClassWriter.IMPLVAR_INSN:
- if (opcode > Opcodes.ISTORE) {
- opcode -= 59; // ISTORE_0
- mv.visitVarInsn(Opcodes.ISTORE + (opcode >> 2),
- opcode & 0x3);
- } else {
- opcode -= 26; // ILOAD_0
- mv.visitVarInsn(Opcodes.ILOAD + (opcode >> 2),
- opcode & 0x3);
- }
- v += 1;
- break;
- case ClassWriter.LABEL_INSN:
- mv.visitJumpInsn(opcode, labels[w
- + readShort(v + 1)]);
- v += 3;
- break;
- case ClassWriter.LABELW_INSN:
- mv.visitJumpInsn(opcode - 33, labels[w
- + readInt(v + 1)]);
- v += 5;
- break;
- case ClassWriter.WIDE_INSN:
- opcode = b[v + 1] & 0xFF;
- if (opcode == Opcodes.IINC) {
- mv.visitIincInsn(readUnsignedShort(v + 2),
- readShort(v + 4));
- v += 6;
- } else {
- mv.visitVarInsn(opcode,
- readUnsignedShort(v + 2));
- v += 4;
- }
- break;
- case ClassWriter.TABL_INSN:
- // skips 0 to 3 padding bytes
- v = v + 4 - (w & 3);
- // reads instruction
- label = w + readInt(v);
- int min = readInt(v + 4);
- int max = readInt(v + 8);
- v += 12;
- Label[] table = new Label[max - min + 1];
- for (j = 0; j < table.length; ++j) {
- table[j] = labels[w + readInt(v)];
- v += 4;
- }
- mv.visitTableSwitchInsn(min,
- max,
- labels[label],
- table);
- break;
- case ClassWriter.LOOK_INSN:
- // skips 0 to 3 padding bytes
- v = v + 4 - (w & 3);
- // reads instruction
- label = w + readInt(v);
- j = readInt(v + 4);
- v += 8;
- int[] keys = new int[j];
- Label[] values = new Label[j];
- for (j = 0; j < keys.length; ++j) {
- keys[j] = readInt(v);
- values[j] = labels[w + readInt(v + 4)];
- v += 8;
- }
- mv.visitLookupSwitchInsn(labels[label],
- keys,
- values);
- break;
- case ClassWriter.VAR_INSN:
- mv.visitVarInsn(opcode, b[v + 1] & 0xFF);
- v += 2;
- break;
- case ClassWriter.SBYTE_INSN:
- mv.visitIntInsn(opcode, b[v + 1]);
- v += 2;
- break;
- case ClassWriter.SHORT_INSN:
- mv.visitIntInsn(opcode, readShort(v + 1));
- v += 3;
- break;
- case ClassWriter.LDC_INSN:
- mv.visitLdcInsn(readConst(b[v + 1] & 0xFF, c));
- v += 2;
- break;
- case ClassWriter.LDCW_INSN:
- mv.visitLdcInsn(readConst(readUnsignedShort(v + 1),
- c));
- v += 3;
- break;
- case ClassWriter.FIELDORMETH_INSN:
- case ClassWriter.ITFMETH_INSN: {
- int cpIndex = items[readUnsignedShort(v + 1)];
- String iowner = readClass(cpIndex, c);
- cpIndex = items[readUnsignedShort(cpIndex + 2)];
- String iname = readUTF8(cpIndex, c);
- String idesc = readUTF8(cpIndex + 2, c);
- if (opcode < Opcodes.INVOKEVIRTUAL) {
- mv.visitFieldInsn(opcode, iowner, iname, idesc);
- } else {
- mv.visitMethodInsn(opcode, iowner, iname, idesc);
- }
- if (opcode == Opcodes.INVOKEINTERFACE) {
- v += 5;
- } else {
- v += 3;
- }
- break;
- }
- case ClassWriter.INDYMETH_INSN: {
- int cpIndex = items[readUnsignedShort(v + 1)];
- int bsmIndex = bootstrapMethods[readUnsignedShort(cpIndex)];
- cpIndex = items[readUnsignedShort(cpIndex + 2)];
- String iname = readUTF8(cpIndex, c);
- String idesc = readUTF8(cpIndex + 2, c);
-
- int mhIndex = readUnsignedShort(bsmIndex);
- Handle bsm = (Handle) readConst(mhIndex, c);
- int bsmArgCount = readUnsignedShort(bsmIndex + 2);
- Object[] bsmArgs = new Object[bsmArgCount];
- bsmIndex += 4;
- for(int a = 0; a < bsmArgCount; a++) {
- int argIndex = readUnsignedShort(bsmIndex);
- bsmArgs[a] = readConst(argIndex, c);
- bsmIndex += 2;
- }
- mv.visitInvokeDynamicInsn(iname, idesc, bsm, bsmArgs);
-
- v += 5;
- break;
- }
- case ClassWriter.TYPE_INSN:
- mv.visitTypeInsn(opcode, readClass(v + 1, c));
- v += 3;
- break;
- case ClassWriter.IINC_INSN:
- mv.visitIincInsn(b[v + 1] & 0xFF, b[v + 2]);
- v += 3;
- break;
- // case MANA_INSN:
- default:
- mv.visitMultiANewArrayInsn(readClass(v + 1, c),
- b[v + 3] & 0xFF);
- v += 4;
- break;
- }
+ // visits the instruction at this offset
+ int opcode = b[u] & 0xFF;
+ switch (ClassWriter.TYPE[opcode]) {
+ case ClassWriter.NOARG_INSN:
+ mv.visitInsn(opcode);
+ u += 1;
+ break;
+ case ClassWriter.IMPLVAR_INSN:
+ if (opcode > Opcodes.ISTORE) {
+ opcode -= 59; // ISTORE_0
+ mv.visitVarInsn(Opcodes.ISTORE + (opcode >> 2),
+ opcode & 0x3);
+ } else {
+ opcode -= 26; // ILOAD_0
+ mv.visitVarInsn(Opcodes.ILOAD + (opcode >> 2), opcode & 0x3);
}
- l = labels[codeEnd - codeStart];
- if (l != null) {
- mv.visitLabel(l);
+ u += 1;
+ break;
+ case ClassWriter.LABEL_INSN:
+ mv.visitJumpInsn(opcode, labels[offset + readShort(u + 1)]);
+ u += 3;
+ break;
+ case ClassWriter.LABELW_INSN:
+ mv.visitJumpInsn(opcode - 33, labels[offset + readInt(u + 1)]);
+ u += 5;
+ break;
+ case ClassWriter.WIDE_INSN:
+ opcode = b[u + 1] & 0xFF;
+ if (opcode == Opcodes.IINC) {
+ mv.visitIincInsn(readUnsignedShort(u + 2), readShort(u + 4));
+ u += 6;
+ } else {
+ mv.visitVarInsn(opcode, readUnsignedShort(u + 2));
+ u += 4;
}
- // visits the local variable tables
- if (!skipDebug && varTable != 0) {
- int[] typeTable = null;
- if (varTypeTable != 0) {
- k = readUnsignedShort(varTypeTable) * 3;
- w = varTypeTable + 2;
- typeTable = new int[k];
- while (k > 0) {
- typeTable[--k] = w + 6; // signature
- typeTable[--k] = readUnsignedShort(w + 8); // index
- typeTable[--k] = readUnsignedShort(w); // start
- w += 10;
- }
- }
- k = readUnsignedShort(varTable);
- w = varTable + 2;
- for (; k > 0; --k) {
- int start = readUnsignedShort(w);
- int length = readUnsignedShort(w + 2);
- int index = readUnsignedShort(w + 8);
- String vsignature = null;
- if (typeTable != null) {
- for (int a = 0; a < typeTable.length; a += 3) {
- if (typeTable[a] == start
- && typeTable[a + 1] == index)
- {
- vsignature = readUTF8(typeTable[a + 2], c);
- break;
- }
- }
- }
- mv.visitLocalVariable(readUTF8(w + 4, c),
- readUTF8(w + 6, c),
- vsignature,
- labels[start],
- labels[start + length],
- index);
- w += 10;
- }
+ break;
+ case ClassWriter.TABL_INSN: {
+ // skips 0 to 3 padding bytes
+ u = u + 4 - (offset & 3);
+ // reads instruction
+ int label = offset + readInt(u);
+ int min = readInt(u + 4);
+ int max = readInt(u + 8);
+ Label[] table = new Label[max - min + 1];
+ u += 12;
+ for (int i = 0; i < table.length; ++i) {
+ table[i] = labels[offset + readInt(u)];
+ u += 4;
+ }
+ mv.visitTableSwitchInsn(min, max, labels[label], table);
+ break;
+ }
+ case ClassWriter.LOOK_INSN: {
+ // skips 0 to 3 padding bytes
+ u = u + 4 - (offset & 3);
+ // reads instruction
+ int label = offset + readInt(u);
+ int len = readInt(u + 4);
+ int[] keys = new int[len];
+ Label[] values = new Label[len];
+ u += 8;
+ for (int i = 0; i < len; ++i) {
+ keys[i] = readInt(u);
+ values[i] = labels[offset + readInt(u + 4)];
+ u += 8;
+ }
+ mv.visitLookupSwitchInsn(labels[label], keys, values);
+ break;
+ }
+ case ClassWriter.VAR_INSN:
+ mv.visitVarInsn(opcode, b[u + 1] & 0xFF);
+ u += 2;
+ break;
+ case ClassWriter.SBYTE_INSN:
+ mv.visitIntInsn(opcode, b[u + 1]);
+ u += 2;
+ break;
+ case ClassWriter.SHORT_INSN:
+ mv.visitIntInsn(opcode, readShort(u + 1));
+ u += 3;
+ break;
+ case ClassWriter.LDC_INSN:
+ mv.visitLdcInsn(readConst(b[u + 1] & 0xFF, c));
+ u += 2;
+ break;
+ case ClassWriter.LDCW_INSN:
+ mv.visitLdcInsn(readConst(readUnsignedShort(u + 1), c));
+ u += 3;
+ break;
+ case ClassWriter.FIELDORMETH_INSN:
+ case ClassWriter.ITFMETH_INSN: {
+ int cpIndex = items[readUnsignedShort(u + 1)];
+ String iowner = readClass(cpIndex, c);
+ cpIndex = items[readUnsignedShort(cpIndex + 2)];
+ String iname = readUTF8(cpIndex, c);
+ String idesc = readUTF8(cpIndex + 2, c);
+ if (opcode < Opcodes.INVOKEVIRTUAL) {
+ mv.visitFieldInsn(opcode, iowner, iname, idesc);
+ } else {
+ mv.visitMethodInsn(opcode, iowner, iname, idesc);
}
- // visits the other attributes
- while (cattrs != null) {
- attr = cattrs.next;
- cattrs.next = null;
- mv.visitAttribute(cattrs);
- cattrs = attr;
+ if (opcode == Opcodes.INVOKEINTERFACE) {
+ u += 5;
+ } else {
+ u += 3;
}
- // visits the max stack and max locals values
- mv.visitMaxs(maxStack, maxLocals);
+ break;
}
+ case ClassWriter.INDYMETH_INSN: {
+ int cpIndex = items[readUnsignedShort(u + 1)];
+ int bsmIndex = context.bootstrapMethods[readUnsignedShort(cpIndex)];
+ Handle bsm = (Handle) readConst(readUnsignedShort(bsmIndex), c);
+ int bsmArgCount = readUnsignedShort(bsmIndex + 2);
+ Object[] bsmArgs = new Object[bsmArgCount];
+ bsmIndex += 4;
+ for (int i = 0; i < bsmArgCount; i++) {
+ bsmArgs[i] = readConst(readUnsignedShort(bsmIndex), c);
+ bsmIndex += 2;
+ }
+ cpIndex = items[readUnsignedShort(cpIndex + 2)];
+ String iname = readUTF8(cpIndex, c);
+ String idesc = readUTF8(cpIndex + 2, c);
+ mv.visitInvokeDynamicInsn(iname, idesc, bsm, bsmArgs);
+ u += 5;
+ break;
+ }
+ case ClassWriter.TYPE_INSN:
+ mv.visitTypeInsn(opcode, readClass(u + 1, c));
+ u += 3;
+ break;
+ case ClassWriter.IINC_INSN:
+ mv.visitIincInsn(b[u + 1] & 0xFF, b[u + 2]);
+ u += 3;
+ break;
+ // case MANA_INSN:
+ default:
+ mv.visitMultiANewArrayInsn(readClass(u + 1, c), b[u + 3] & 0xFF);
+ u += 4;
+ break;
+ }
+ }
+ if (labels[codeLength] != null) {
+ mv.visitLabel(labels[codeLength]);
+ }
- if (mv != null) {
- mv.visitEnd();
+ // visits the local variable tables
+ if ((context.flags & SKIP_DEBUG) == 0 && varTable != 0) {
+ int[] typeTable = null;
+ if (varTypeTable != 0) {
+ u = varTypeTable + 2;
+ typeTable = new int[readUnsignedShort(varTypeTable) * 3];
+ for (int i = typeTable.length; i > 0;) {
+ typeTable[--i] = u + 6; // signature
+ typeTable[--i] = readUnsignedShort(u + 8); // index
+ typeTable[--i] = readUnsignedShort(u); // start
+ u += 10;
+ }
+ }
+ u = varTable + 2;
+ for (int i = readUnsignedShort(varTable); i > 0; --i) {
+ int start = readUnsignedShort(u);
+ int length = readUnsignedShort(u + 2);
+ int index = readUnsignedShort(u + 8);
+ String vsignature = null;
+ if (typeTable != null) {
+ for (int j = 0; j < typeTable.length; j += 3) {
+ if (typeTable[j] == start && typeTable[j + 1] == index) {
+ vsignature = readUTF8(typeTable[j + 2], c);
+ break;
+ }
+ }
+ }
+ mv.visitLocalVariable(readUTF8(u + 4, c), readUTF8(u + 6, c),
+ vsignature, labels[start], labels[start + length],
+ index);
+ u += 10;
}
}
- // visits the end of the class
- classVisitor.visitEnd();
+ // visits the code attributes
+ while (attributes != null) {
+ Attribute attr = attributes.next;
+ attributes.next = null;
+ mv.visitAttribute(attributes);
+ attributes = attr;
+ }
+
+ // visits the max stack and max locals values
+ mv.visitMaxs(maxStack, maxLocals);
}
/**
* Reads parameter annotations and makes the given visitor visit them.
*
- * @param v start offset in {@link #b b} of the annotations to be read.
- * @param desc the method descriptor.
- * @param buf buffer to be used to call {@link #readUTF8 readUTF8},
- * {@link #readClass(int,char[]) readClass} or
- * {@link #readConst readConst}.
- * @param visible <tt>true</tt> if the annotations to be read are visible
- * at runtime.
- * @param mv the visitor that must visit the annotations.
+ * @param v
+ * start offset in {@link #b b} of the annotations to be read.
+ * @param desc
+ * the method descriptor.
+ * @param buf
+ * buffer to be used to call {@link #readUTF8 readUTF8},
+ * {@link #readClass(int,char[]) readClass} or {@link #readConst
+ * readConst}.
+ * @param visible
+ * <tt>true</tt> if the annotations to be read are visible at
+ * runtime.
+ * @param mv
+ * the visitor that must visit the annotations.
*/
- private void readParameterAnnotations(
- int v,
- final String desc,
- final char[] buf,
- final boolean visible,
- final MethodVisitor mv)
- {
+ private void readParameterAnnotations(int v, final String desc,
+ final char[] buf, final boolean visible, final MethodVisitor mv) {
int i;
int n = b[v++] & 0xFF;
// workaround for a bug in javac (javac compiler generates a parameter
@@ -1679,21 +1458,22 @@ public class ClassReader {
/**
* Reads the values of an annotation and makes the given visitor visit them.
*
- * @param v the start offset in {@link #b b} of the values to be read
- * (including the unsigned short that gives the number of values).
- * @param buf buffer to be used to call {@link #readUTF8 readUTF8},
- * {@link #readClass(int,char[]) readClass} or
- * {@link #readConst readConst}.
- * @param named if the annotation values are named or not.
- * @param av the visitor that must visit the values.
+ * @param v
+ * the start offset in {@link #b b} of the values to be read
+ * (including the unsigned short that gives the number of
+ * values).
+ * @param buf
+ * buffer to be used to call {@link #readUTF8 readUTF8},
+ * {@link #readClass(int,char[]) readClass} or {@link #readConst
+ * readConst}.
+ * @param named
+ * if the annotation values are named or not.
+ * @param av
+ * the visitor that must visit the values.
* @return the end offset of the annotation values.
*/
- private int readAnnotationValues(
- int v,
- final char[] buf,
- final boolean named,
- final AnnotationVisitor av)
- {
+ private int readAnnotationValues(int v, final char[] buf,
+ final boolean named, final AnnotationVisitor av) {
int i = readUnsignedShort(v);
v += 2;
if (named) {
@@ -1714,210 +1494,371 @@ public class ClassReader {
/**
* Reads a value of an annotation and makes the given visitor visit it.
*
- * @param v the start offset in {@link #b b} of the value to be read (<i>not
- * including the value name constant pool index</i>).
- * @param buf buffer to be used to call {@link #readUTF8 readUTF8},
- * {@link #readClass(int,char[]) readClass} or
- * {@link #readConst readConst}.
- * @param name the name of the value to be read.
- * @param av the visitor that must visit the value.
+ * @param v
+ * the start offset in {@link #b b} of the value to be read
+ * (<i>not including the value name constant pool index</i>).
+ * @param buf
+ * buffer to be used to call {@link #readUTF8 readUTF8},
+ * {@link #readClass(int,char[]) readClass} or {@link #readConst
+ * readConst}.
+ * @param name
+ * the name of the value to be read.
+ * @param av
+ * the visitor that must visit the value.
* @return the end offset of the annotation value.
*/
- private int readAnnotationValue(
- int v,
- final char[] buf,
- final String name,
- final AnnotationVisitor av)
- {
+ private int readAnnotationValue(int v, final char[] buf, final String name,
+ final AnnotationVisitor av) {
int i;
if (av == null) {
switch (b[v] & 0xFF) {
- case 'e': // enum_const_value
- return v + 5;
- case '@': // annotation_value
- return readAnnotationValues(v + 3, buf, true, null);
- case '[': // array_value
- return readAnnotationValues(v + 1, buf, false, null);
- default:
- return v + 3;
+ case 'e': // enum_const_value
+ return v + 5;
+ case '@': // annotation_value
+ return readAnnotationValues(v + 3, buf, true, null);
+ case '[': // array_value
+ return readAnnotationValues(v + 1, buf, false, null);
+ default:
+ return v + 3;
}
}
switch (b[v++] & 0xFF) {
- case 'I': // pointer to CONSTANT_Integer
- case 'J': // pointer to CONSTANT_Long
- case 'F': // pointer to CONSTANT_Float
- case 'D': // pointer to CONSTANT_Double
- av.visit(name, readConst(readUnsignedShort(v), buf));
- v += 2;
- break;
- case 'B': // pointer to CONSTANT_Byte
- av.visit(name,
- new Byte((byte) readInt(items[readUnsignedShort(v)])));
- v += 2;
- break;
- case 'Z': // pointer to CONSTANT_Boolean
- av.visit(name, readInt(items[readUnsignedShort(v)]) == 0
- ? Boolean.FALSE
- : Boolean.TRUE);
- v += 2;
- break;
- case 'S': // pointer to CONSTANT_Short
- av.visit(name,
- new Short((short) readInt(items[readUnsignedShort(v)])));
- v += 2;
+ case 'I': // pointer to CONSTANT_Integer
+ case 'J': // pointer to CONSTANT_Long
+ case 'F': // pointer to CONSTANT_Float
+ case 'D': // pointer to CONSTANT_Double
+ av.visit(name, readConst(readUnsignedShort(v), buf));
+ v += 2;
+ break;
+ case 'B': // pointer to CONSTANT_Byte
+ av.visit(name,
+ new Byte((byte) readInt(items[readUnsignedShort(v)])));
+ v += 2;
+ break;
+ case 'Z': // pointer to CONSTANT_Boolean
+ av.visit(name,
+ readInt(items[readUnsignedShort(v)]) == 0 ? Boolean.FALSE
+ : Boolean.TRUE);
+ v += 2;
+ break;
+ case 'S': // pointer to CONSTANT_Short
+ av.visit(name, new Short(
+ (short) readInt(items[readUnsignedShort(v)])));
+ v += 2;
+ break;
+ case 'C': // pointer to CONSTANT_Char
+ av.visit(name, new Character(
+ (char) readInt(items[readUnsignedShort(v)])));
+ v += 2;
+ break;
+ case 's': // pointer to CONSTANT_Utf8
+ av.visit(name, readUTF8(v, buf));
+ v += 2;
+ break;
+ case 'e': // enum_const_value
+ av.visitEnum(name, readUTF8(v, buf), readUTF8(v + 2, buf));
+ v += 4;
+ break;
+ case 'c': // class_info
+ av.visit(name, Type.getType(readUTF8(v, buf)));
+ v += 2;
+ break;
+ case '@': // annotation_value
+ v = readAnnotationValues(v + 2, buf, true,
+ av.visitAnnotation(name, readUTF8(v, buf)));
+ break;
+ case '[': // array_value
+ int size = readUnsignedShort(v);
+ v += 2;
+ if (size == 0) {
+ return readAnnotationValues(v - 2, buf, false,
+ av.visitArray(name));
+ }
+ switch (this.b[v++] & 0xFF) {
+ case 'B':
+ byte[] bv = new byte[size];
+ for (i = 0; i < size; i++) {
+ bv[i] = (byte) readInt(items[readUnsignedShort(v)]);
+ v += 3;
+ }
+ av.visit(name, bv);
+ --v;
break;
- case 'C': // pointer to CONSTANT_Char
- av.visit(name,
- new Character((char) readInt(items[readUnsignedShort(v)])));
- v += 2;
+ case 'Z':
+ boolean[] zv = new boolean[size];
+ for (i = 0; i < size; i++) {
+ zv[i] = readInt(items[readUnsignedShort(v)]) != 0;
+ v += 3;
+ }
+ av.visit(name, zv);
+ --v;
break;
- case 's': // pointer to CONSTANT_Utf8
- av.visit(name, readUTF8(v, buf));
- v += 2;
+ case 'S':
+ short[] sv = new short[size];
+ for (i = 0; i < size; i++) {
+ sv[i] = (short) readInt(items[readUnsignedShort(v)]);
+ v += 3;
+ }
+ av.visit(name, sv);
+ --v;
break;
- case 'e': // enum_const_value
- av.visitEnum(name, readUTF8(v, buf), readUTF8(v + 2, buf));
- v += 4;
+ case 'C':
+ char[] cv = new char[size];
+ for (i = 0; i < size; i++) {
+ cv[i] = (char) readInt(items[readUnsignedShort(v)]);
+ v += 3;
+ }
+ av.visit(name, cv);
+ --v;
break;
- case 'c': // class_info
- av.visit(name, Type.getType(readUTF8(v, buf)));
- v += 2;
+ case 'I':
+ int[] iv = new int[size];
+ for (i = 0; i < size; i++) {
+ iv[i] = readInt(items[readUnsignedShort(v)]);
+ v += 3;
+ }
+ av.visit(name, iv);
+ --v;
break;
- case '@': // annotation_value
- v = readAnnotationValues(v + 2,
- buf,
- true,
- av.visitAnnotation(name, readUTF8(v, buf)));
+ case 'J':
+ long[] lv = new long[size];
+ for (i = 0; i < size; i++) {
+ lv[i] = readLong(items[readUnsignedShort(v)]);
+ v += 3;
+ }
+ av.visit(name, lv);
+ --v;
break;
- case '[': // array_value
- int size = readUnsignedShort(v);
- v += 2;
- if (size == 0) {
- return readAnnotationValues(v - 2,
- buf,
- false,
- av.visitArray(name));
+ case 'F':
+ float[] fv = new float[size];
+ for (i = 0; i < size; i++) {
+ fv[i] = Float
+ .intBitsToFloat(readInt(items[readUnsignedShort(v)]));
+ v += 3;
}
- switch (this.b[v++] & 0xFF) {
- case 'B':
- byte[] bv = new byte[size];
- for (i = 0; i < size; i++) {
- bv[i] = (byte) readInt(items[readUnsignedShort(v)]);
- v += 3;
- }
- av.visit(name, bv);
- --v;
- break;
- case 'Z':
- boolean[] zv = new boolean[size];
- for (i = 0; i < size; i++) {
- zv[i] = readInt(items[readUnsignedShort(v)]) != 0;
- v += 3;
- }
- av.visit(name, zv);
- --v;
- break;
- case 'S':
- short[] sv = new short[size];
- for (i = 0; i < size; i++) {
- sv[i] = (short) readInt(items[readUnsignedShort(v)]);
- v += 3;
- }
- av.visit(name, sv);
- --v;
- break;
- case 'C':
- char[] cv = new char[size];
- for (i = 0; i < size; i++) {
- cv[i] = (char) readInt(items[readUnsignedShort(v)]);
- v += 3;
- }
- av.visit(name, cv);
- --v;
- break;
- case 'I':
- int[] iv = new int[size];
- for (i = 0; i < size; i++) {
- iv[i] = readInt(items[readUnsignedShort(v)]);
- v += 3;
- }
- av.visit(name, iv);
- --v;
- break;
- case 'J':
- long[] lv = new long[size];
- for (i = 0; i < size; i++) {
- lv[i] = readLong(items[readUnsignedShort(v)]);
- v += 3;
- }
- av.visit(name, lv);
- --v;
- break;
- case 'F':
- float[] fv = new float[size];
- for (i = 0; i < size; i++) {
- fv[i] = Float.intBitsToFloat(readInt(items[readUnsignedShort(v)]));
- v += 3;
- }
- av.visit(name, fv);
- --v;
- break;
- case 'D':
- double[] dv = new double[size];
- for (i = 0; i < size; i++) {
- dv[i] = Double.longBitsToDouble(readLong(items[readUnsignedShort(v)]));
- v += 3;
- }
- av.visit(name, dv);
- --v;
- break;
- default:
- v = readAnnotationValues(v - 3,
- buf,
- false,
- av.visitArray(name));
+ av.visit(name, fv);
+ --v;
+ break;
+ case 'D':
+ double[] dv = new double[size];
+ for (i = 0; i < size; i++) {
+ dv[i] = Double
+ .longBitsToDouble(readLong(items[readUnsignedShort(v)]));
+ v += 3;
}
+ av.visit(name, dv);
+ --v;
+ break;
+ default:
+ v = readAnnotationValues(v - 3, buf, false, av.visitArray(name));
+ }
}
return v;
}
- private int readFrameType(
- final Object[] frame,
- final int index,
- int v,
- final char[] buf,
- final Label[] labels)
- {
- int type = b[v++] & 0xFF;
- switch (type) {
- case 0:
- frame[index] = Opcodes.TOP;
- break;
- case 1:
- frame[index] = Opcodes.INTEGER;
- break;
- case 2:
- frame[index] = Opcodes.FLOAT;
+ /**
+ * Computes the implicit frame of the method currently being parsed (as
+ * defined in the given {@link Context}) and stores it in the given context.
+ *
+ * @param frame
+ * information about the class being parsed.
+ */
+ private void getImplicitFrame(final Context frame) {
+ String desc = frame.desc;
+ Object[] locals = frame.local;
+ int local = 0;
+ if ((frame.access & Opcodes.ACC_STATIC) == 0) {
+ if ("<init>".equals(frame.name)) {
+ locals[local++] = Opcodes.UNINITIALIZED_THIS;
+ } else {
+ locals[local++] = readClass(header + 2, frame.buffer);
+ }
+ }
+ int i = 1;
+ loop: while (true) {
+ int j = i;
+ switch (desc.charAt(i++)) {
+ case 'Z':
+ case 'C':
+ case 'B':
+ case 'S':
+ case 'I':
+ locals[local++] = Opcodes.INTEGER;
break;
- case 3:
- frame[index] = Opcodes.DOUBLE;
+ case 'F':
+ locals[local++] = Opcodes.FLOAT;
break;
- case 4:
- frame[index] = Opcodes.LONG;
+ case 'J':
+ locals[local++] = Opcodes.LONG;
break;
- case 5:
- frame[index] = Opcodes.NULL;
+ case 'D':
+ locals[local++] = Opcodes.DOUBLE;
break;
- case 6:
- frame[index] = Opcodes.UNINITIALIZED_THIS;
+ case '[':
+ while (desc.charAt(i) == '[') {
+ ++i;
+ }
+ if (desc.charAt(i) == 'L') {
+ ++i;
+ while (desc.charAt(i) != ';') {
+ ++i;
+ }
+ }
+ locals[local++] = desc.substring(j, ++i);
break;
- case 7: // Object
- frame[index] = readClass(v, buf);
- v += 2;
+ case 'L':
+ while (desc.charAt(i) != ';') {
+ ++i;
+ }
+ locals[local++] = desc.substring(j + 1, i++);
break;
- default: // Uninitialized
- frame[index] = readLabel(readUnsignedShort(v), labels);
- v += 2;
+ default:
+ break loop;
+ }
+ }
+ frame.localCount = local;
+ }
+
+ /**
+ * Reads a stack map frame and stores the result in the given
+ * {@link Context} object.
+ *
+ * @param stackMap
+ * the start offset of a stack map frame in the class file.
+ * @param zip
+ * if the stack map frame at stackMap is compressed or not.
+ * @param unzip
+ * if the stack map frame must be uncompressed.
+ * @param labels
+ * the labels of the method currently being parsed, indexed by
+ * their offset. A new label for the parsed stack map frame is
+ * stored in this array if it does not already exist.
+ * @param frame
+ * where the parsed stack map frame must be stored.
+ * @return the offset of the first byte following the parsed frame.
+ */
+ private int readFrame(int stackMap, boolean zip, boolean unzip,
+ Label[] labels, Context frame) {
+ char[] c = frame.buffer;
+ int tag;
+ int delta;
+ if (zip) {
+ tag = b[stackMap++] & 0xFF;
+ } else {
+ tag = MethodWriter.FULL_FRAME;
+ frame.offset = -1;
+ }
+ frame.localDiff = 0;
+ if (tag < MethodWriter.SAME_LOCALS_1_STACK_ITEM_FRAME) {
+ delta = tag;
+ frame.mode = Opcodes.F_SAME;
+ frame.stackCount = 0;
+ } else if (tag < MethodWriter.RESERVED) {
+ delta = tag - MethodWriter.SAME_LOCALS_1_STACK_ITEM_FRAME;
+ stackMap = readFrameType(frame.stack, 0, stackMap, c, labels);
+ frame.mode = Opcodes.F_SAME1;
+ frame.stackCount = 1;
+ } else {
+ delta = readUnsignedShort(stackMap);
+ stackMap += 2;
+ if (tag == MethodWriter.SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED) {
+ stackMap = readFrameType(frame.stack, 0, stackMap, c, labels);
+ frame.mode = Opcodes.F_SAME1;
+ frame.stackCount = 1;
+ } else if (tag >= MethodWriter.CHOP_FRAME
+ && tag < MethodWriter.SAME_FRAME_EXTENDED) {
+ frame.mode = Opcodes.F_CHOP;
+ frame.localDiff = MethodWriter.SAME_FRAME_EXTENDED - tag;
+ frame.localCount -= frame.localDiff;
+ frame.stackCount = 0;
+ } else if (tag == MethodWriter.SAME_FRAME_EXTENDED) {
+ frame.mode = Opcodes.F_SAME;
+ frame.stackCount = 0;
+ } else if (tag < MethodWriter.FULL_FRAME) {
+ int local = unzip ? frame.localCount : 0;
+ for (int i = tag - MethodWriter.SAME_FRAME_EXTENDED; i > 0; i--) {
+ stackMap = readFrameType(frame.local, local++, stackMap, c,
+ labels);
+ }
+ frame.mode = Opcodes.F_APPEND;
+ frame.localDiff = tag - MethodWriter.SAME_FRAME_EXTENDED;
+ frame.localCount += frame.localDiff;
+ frame.stackCount = 0;
+ } else { // if (tag == FULL_FRAME) {
+ frame.mode = Opcodes.F_FULL;
+ int n = readUnsignedShort(stackMap);
+ stackMap += 2;
+ frame.localDiff = n;
+ frame.localCount = n;
+ for (int local = 0; n > 0; n--) {
+ stackMap = readFrameType(frame.local, local++, stackMap, c,
+ labels);
+ }
+ n = readUnsignedShort(stackMap);
+ stackMap += 2;
+ frame.stackCount = n;
+ for (int stack = 0; n > 0; n--) {
+ stackMap = readFrameType(frame.stack, stack++, stackMap, c,
+ labels);
+ }
+ }
+ }
+ frame.offset += delta + 1;
+ readLabel(frame.offset, labels);
+ return stackMap;
+ }
+
+ /**
+ * Reads a stack map frame type and stores it at the given index in the
+ * given array.
+ *
+ * @param frame
+ * the array where the parsed type must be stored.
+ * @param index
+ * the index in 'frame' where the parsed type must be stored.
+ * @param v
+ * the start offset of the stack map frame type to read.
+ * @param buf
+ * a buffer to read strings.
+ * @param labels
+ * the labels of the method currently being parsed, indexed by
+ * their offset. If the parsed type is an Uninitialized type, a
+ * new label for the corresponding NEW instruction is stored in
+ * this array if it does not already exist.
+ * @return the offset of the first byte after the parsed type.
+ */
+ private int readFrameType(final Object[] frame, final int index, int v,
+ final char[] buf, final Label[] labels) {
+ int type = b[v++] & 0xFF;
+ switch (type) {
+ case 0:
+ frame[index] = Opcodes.TOP;
+ break;
+ case 1:
+ frame[index] = Opcodes.INTEGER;
+ break;
+ case 2:
+ frame[index] = Opcodes.FLOAT;
+ break;
+ case 3:
+ frame[index] = Opcodes.DOUBLE;
+ break;
+ case 4:
+ frame[index] = Opcodes.LONG;
+ break;
+ case 5:
+ frame[index] = Opcodes.NULL;
+ break;
+ case 6:
+ frame[index] = Opcodes.UNINITIALIZED_THIS;
+ break;
+ case 7: // Object
+ frame[index] = readClass(v, buf);
+ v += 2;
+ break;
+ default: // Uninitialized
+ frame[index] = readLabel(readUnsignedShort(v), labels);
+ v += 2;
}
return v;
}
@@ -1927,10 +1868,12 @@ public class ClassReader {
* implementation of this method creates a label for the given offset if it
* has not been already created.
*
- * @param offset a bytecode offset in a method.
- * @param labels the already created labels, indexed by their offset. If a
- * label already exists for offset this method must not create a new
- * one. Otherwise it must store the new label in this array.
+ * @param offset
+ * a bytecode offset in a method.
+ * @param labels
+ * the already created labels, indexed by their offset. If a
+ * label already exists for offset this method must not create a
+ * new one. Otherwise it must store the new label in this array.
* @return a non null Label, which must be equal to labels[offset].
*/
protected Label readLabel(int offset, Label[] labels) {
@@ -1941,39 +1884,67 @@ public class ClassReader {
}
/**
+ * Returns the start index of the attribute_info structure of this class.
+ *
+ * @return the start index of the attribute_info structure of this class.
+ */
+ private int getAttributes() {
+ // skips the header
+ int u = header + 8 + readUnsignedShort(header + 6) * 2;
+ // skips fields and methods
+ for (int i = readUnsignedShort(u); i > 0; --i) {
+ for (int j = readUnsignedShort(u + 8); j > 0; --j) {
+ u += 6 + readInt(u + 12);
+ }
+ u += 8;
+ }
+ u += 2;
+ for (int i = readUnsignedShort(u); i > 0; --i) {
+ for (int j = readUnsignedShort(u + 8); j > 0; --j) {
+ u += 6 + readInt(u + 12);
+ }
+ u += 8;
+ }
+ // the attribute_info structure starts just after the methods
+ return u + 2;
+ }
+
+ /**
* Reads an attribute in {@link #b b}.
*
- * @param attrs prototypes of the attributes that must be parsed during the
- * visit of the class. Any attribute whose type is not equal to the
- * type of one the prototypes is ignored (i.e. an empty
- * {@link Attribute} instance is returned).
- * @param type the type of the attribute.
- * @param off index of the first byte of the attribute's content in
- * {@link #b b}. The 6 attribute header bytes, containing the type
- * and the length of the attribute, are not taken into account here
- * (they have already been read).
- * @param len the length of the attribute's content.
- * @param buf buffer to be used to call {@link #readUTF8 readUTF8},
- * {@link #readClass(int,char[]) readClass} or
- * {@link #readConst readConst}.
- * @param codeOff index of the first byte of code's attribute content in
- * {@link #b b}, or -1 if the attribute to be read is not a code
- * attribute. The 6 attribute header bytes, containing the type and
- * the length of the attribute, are not taken into account here.
- * @param labels the labels of the method's code, or <tt>null</tt> if the
- * attribute to be read is not a code attribute.
+ * @param attrs
+ * prototypes of the attributes that must be parsed during the
+ * visit of the class. Any attribute whose type is not equal to
+ * the type of one the prototypes is ignored (i.e. an empty
+ * {@link Attribute} instance is returned).
+ * @param type
+ * the type of the attribute.
+ * @param off
+ * index of the first byte of the attribute's content in
+ * {@link #b b}. The 6 attribute header bytes, containing the
+ * type and the length of the attribute, are not taken into
+ * account here (they have already been read).
+ * @param len
+ * the length of the attribute's content.
+ * @param buf
+ * buffer to be used to call {@link #readUTF8 readUTF8},
+ * {@link #readClass(int,char[]) readClass} or {@link #readConst
+ * readConst}.
+ * @param codeOff
+ * index of the first byte of code's attribute content in
+ * {@link #b b}, or -1 if the attribute to be read is not a code
+ * attribute. The 6 attribute header bytes, containing the type
+ * and the length of the attribute, are not taken into account
+ * here.
+ * @param labels
+ * the labels of the method's code, or <tt>null</tt> if the
+ * attribute to be read is not a code attribute.
* @return the attribute that has been read, or <tt>null</tt> to skip this
* attribute.
*/
- private Attribute readAttribute(
- final Attribute[] attrs,
- final String type,
- final int off,
- final int len,
- final char[] buf,
- final int codeOff,
- final Label[] labels)
- {
+ private Attribute readAttribute(final Attribute[] attrs, final String type,
+ final int off, final int len, final char[] buf, final int codeOff,
+ final Label[] labels) {
for (int i = 0; i < attrs.length; ++i) {
if (attrs[i].type.equals(type)) {
return attrs[i].read(this, off, len, buf, codeOff, labels);
@@ -1987,9 +1958,9 @@ public class ClassReader {
// ------------------------------------------------------------------------
/**
- * Returns the number of constant pool items in {@link #b b}.
+ * Returns the number of constant pool items in {@link #b b}.
*
- * @return the number of constant pool items in {@link #b b}.
+ * @return the number of constant pool items in {@link #b b}.
*/
public int getItemCount() {
return items.length;
@@ -2000,7 +1971,8 @@ public class ClassReader {
* one. <i>This method is intended for {@link Attribute} sub classes, and is
* normally not needed by class generators or adapters.</i>
*
- * @param item the index a constant pool item.
+ * @param item
+ * the index a constant pool item.
* @return the start index of the constant pool item in {@link #b b}, plus
* one.
*/
@@ -2024,7 +1996,8 @@ public class ClassReader {
* {@link Attribute} sub classes, and is normally not needed by class
* generators or adapters.</i>
*
- * @param index the start index of the value to be read in {@link #b b}.
+ * @param index
+ * the start index of the value to be read in {@link #b b}.
* @return the read value.
*/
public int readByte(final int index) {
@@ -2032,11 +2005,12 @@ public class ClassReader {
}
/**
- * Reads an unsigned short value in {@link #b b}. <i>This method is
- * intended for {@link Attribute} sub classes, and is normally not needed by
- * class generators or adapters.</i>
+ * Reads an unsigned short value in {@link #b b}. <i>This method is intended
+ * for {@link Attribute} sub classes, and is normally not needed by class
+ * generators or adapters.</i>
*
- * @param index the start index of the value to be read in {@link #b b}.
+ * @param index
+ * the start index of the value to be read in {@link #b b}.
* @return the read value.
*/
public int readUnsignedShort(final int index) {
@@ -2049,7 +2023,8 @@ public class ClassReader {
* for {@link Attribute} sub classes, and is normally not needed by class
* generators or adapters.</i>
*
- * @param index the start index of the value to be read in {@link #b b}.
+ * @param index
+ * the start index of the value to be read in {@link #b b}.
* @return the read value.
*/
public short readShort(final int index) {
@@ -2062,7 +2037,8 @@ public class ClassReader {
* {@link Attribute} sub classes, and is normally not needed by class
* generators or adapters.</i>
*
- * @param index the start index of the value to be read in {@link #b b}.
+ * @param index
+ * the start index of the value to be read in {@link #b b}.
* @return the read value.
*/
public int readInt(final int index) {
@@ -2072,11 +2048,12 @@ public class ClassReader {
}
/**
- * Reads a signed long value in {@link #b b}. <i>This method is intended
- * for {@link Attribute} sub classes, and is normally not needed by class
+ * Reads a signed long value in {@link #b b}. <i>This method is intended for
+ * {@link Attribute} sub classes, and is normally not needed by class
* generators or adapters.</i>
*
- * @param index the start index of the value to be read in {@link #b b}.
+ * @param index
+ * the start index of the value to be read in {@link #b b}.
* @return the read value.
*/
public long readLong(final int index) {
@@ -2090,14 +2067,19 @@ public class ClassReader {
* is intended for {@link Attribute} sub classes, and is normally not needed
* by class generators or adapters.</i>
*
- * @param index the start index of an unsigned short value in {@link #b b},
- * whose value is the index of an UTF8 constant pool item.
- * @param buf buffer to be used to read the item. This buffer must be
- * sufficiently large. It is not automatically resized.
+ * @param index
+ * the start index of an unsigned short value in {@link #b b},
+ * whose value is the index of an UTF8 constant pool item.
+ * @param buf
+ * buffer to be used to read the item. This buffer must be
+ * sufficiently large. It is not automatically resized.
* @return the String corresponding to the specified UTF8 item.
*/
public String readUTF8(int index, final char[] buf) {
int item = readUnsignedShort(index);
+ if (index == 0 || item == 0) {
+ return null;
+ }
String s = strings[item];
if (s != null) {
return s;
@@ -2109,10 +2091,13 @@ public class ClassReader {
/**
* Reads UTF8 string in {@link #b b}.
*
- * @param index start offset of the UTF8 string to be read.
- * @param utfLen length of the UTF8 string to be read.
- * @param buf buffer to be used to read the string. This buffer must be
- * sufficiently large. It is not automatically resized.
+ * @param index
+ * start offset of the UTF8 string to be read.
+ * @param utfLen
+ * length of the UTF8 string to be read.
+ * @param buf
+ * buffer to be used to read the string. This buffer must be
+ * sufficiently large. It is not automatically resized.
* @return the String corresponding to the specified UTF8 string.
*/
private String readUTF(int index, final int utfLen, final char[] buf) {
@@ -2125,28 +2110,28 @@ public class ClassReader {
while (index < endIndex) {
c = b[index++];
switch (st) {
- case 0:
- c = c & 0xFF;
- if (c < 0x80) { // 0xxxxxxx
- buf[strLen++] = (char) c;
- } else if (c < 0xE0 && c > 0xBF) { // 110x xxxx 10xx xxxx
- cc = (char) (c & 0x1F);
- st = 1;
- } else { // 1110 xxxx 10xx xxxx 10xx xxxx
- cc = (char) (c & 0x0F);
- st = 2;
- }
- break;
+ case 0:
+ c = c & 0xFF;
+ if (c < 0x80) { // 0xxxxxxx
+ buf[strLen++] = (char) c;
+ } else if (c < 0xE0 && c > 0xBF) { // 110x xxxx 10xx xxxx
+ cc = (char) (c & 0x1F);
+ st = 1;
+ } else { // 1110 xxxx 10xx xxxx 10xx xxxx
+ cc = (char) (c & 0x0F);
+ st = 2;
+ }
+ break;
- case 1: // byte 2 of 2-byte char or byte 3 of 3-byte char
- buf[strLen++] = (char) ((cc << 6) | (c & 0x3F));
- st = 0;
- break;
+ case 1: // byte 2 of 2-byte char or byte 3 of 3-byte char
+ buf[strLen++] = (char) ((cc << 6) | (c & 0x3F));
+ st = 0;
+ break;
- case 2: // byte 2 of 3-byte char
- cc = (char) ((cc << 6) | (c & 0x3F));
- st = 1;
- break;
+ case 2: // byte 2 of 3-byte char
+ cc = (char) ((cc << 6) | (c & 0x3F));
+ st = 1;
+ break;
}
}
return new String(buf, 0, strLen);
@@ -2157,10 +2142,12 @@ public class ClassReader {
* intended for {@link Attribute} sub classes, and is normally not needed by
* class generators or adapters.</i>
*
- * @param index the start index of an unsigned short value in {@link #b b},
- * whose value is the index of a class constant pool item.
- * @param buf buffer to be used to read the item. This buffer must be
- * sufficiently large. It is not automatically resized.
+ * @param index
+ * the start index of an unsigned short value in {@link #b b},
+ * whose value is the index of a class constant pool item.
+ * @param buf
+ * buffer to be used to read the item. This buffer must be
+ * sufficiently large. It is not automatically resized.
* @return the String corresponding to the specified class item.
*/
public String readClass(final int index, final char[] buf) {
@@ -2175,9 +2162,11 @@ public class ClassReader {
* method is intended for {@link Attribute} sub classes, and is normally not
* needed by class generators or adapters.</i>
*
- * @param item the index of a constant pool item.
- * @param buf buffer to be used to read the item. This buffer must be
- * sufficiently large. It is not automatically resized.
+ * @param item
+ * the index of a constant pool item.
+ * @param buf
+ * buffer to be used to read the item. This buffer must be
+ * sufficiently large. It is not automatically resized.
* @return the {@link Integer}, {@link Float}, {@link Long}, {@link Double},
* {@link String}, {@link Type} or {@link Handle} corresponding to
* the given constant pool item.
@@ -2185,32 +2174,29 @@ public class ClassReader {
public Object readConst(final int item, final char[] buf) {
int index = items[item];
switch (b[index - 1]) {
- case ClassWriter.INT:
- return new Integer(readInt(index));
- case ClassWriter.FLOAT:
- return new Float(Float.intBitsToFloat(readInt(index)));
- case ClassWriter.LONG:
- return new Long(readLong(index));
- case ClassWriter.DOUBLE:
- return new Double(Double.longBitsToDouble(readLong(index)));
- case ClassWriter.CLASS:
- return Type.getObjectType(readUTF8(index, buf));
- case ClassWriter.STR:
- return readUTF8(index, buf);
- case ClassWriter.MTYPE:
- return Type.getMethodType(readUTF8(index, buf));
-
- //case ClassWriter.HANDLE_BASE + [1..9]:
- default: {
- int tag = readByte(index);
- int[] items = this.items;
- int cpIndex = items[readUnsignedShort(index + 1)];
- String owner = readClass(cpIndex, buf);
- cpIndex = items[readUnsignedShort(cpIndex + 2)];
- String name = readUTF8(cpIndex, buf);
- String desc = readUTF8(cpIndex + 2, buf);
- return new Handle(tag, owner, name, desc);
- }
+ case ClassWriter.INT:
+ return new Integer(readInt(index));
+ case ClassWriter.FLOAT:
+ return new Float(Float.intBitsToFloat(readInt(index)));
+ case ClassWriter.LONG:
+ return new Long(readLong(index));
+ case ClassWriter.DOUBLE:
+ return new Double(Double.longBitsToDouble(readLong(index)));
+ case ClassWriter.CLASS:
+ return Type.getObjectType(readUTF8(index, buf));
+ case ClassWriter.STR:
+ return readUTF8(index, buf);
+ case ClassWriter.MTYPE:
+ return Type.getMethodType(readUTF8(index, buf));
+ default: // case ClassWriter.HANDLE_BASE + [1..9]:
+ int tag = readByte(index);
+ int[] items = this.items;
+ int cpIndex = items[readUnsignedShort(index + 1)];
+ String owner = readClass(cpIndex, buf);
+ cpIndex = items[readUnsignedShort(cpIndex + 2)];
+ String name = readUTF8(cpIndex, buf);
+ String desc = readUTF8(cpIndex + 2, buf);
+ return new Handle(tag, owner, name, desc);
}
}
}
diff --git a/src/asm/scala/tools/asm/ClassVisitor.java b/src/asm/scala/tools/asm/ClassVisitor.java
index ae38ae0ab9..3fc364d5e5 100644
--- a/src/asm/scala/tools/asm/ClassVisitor.java
+++ b/src/asm/scala/tools/asm/ClassVisitor.java
@@ -30,11 +30,11 @@
package scala.tools.asm;
/**
- * A visitor to visit a Java class. The methods of this class must be called
- * in the following order: <tt>visit</tt> [ <tt>visitSource</tt> ] [
+ * A visitor to visit a Java class. The methods of this class must be called in
+ * the following order: <tt>visit</tt> [ <tt>visitSource</tt> ] [
* <tt>visitOuterClass</tt> ] ( <tt>visitAnnotation</tt> |
- * <tt>visitAttribute</tt> )* ( <tt>visitInnerClass</tt> |
- * <tt>visitField</tt> | <tt>visitMethod</tt> )* <tt>visitEnd</tt>.
+ * <tt>visitAttribute</tt> )* ( <tt>visitInnerClass</tt> | <tt>visitField</tt> |
+ * <tt>visitMethod</tt> )* <tt>visitEnd</tt>.
*
* @author Eric Bruneton
*/
@@ -55,8 +55,9 @@ public abstract class ClassVisitor {
/**
* Constructs a new {@link ClassVisitor}.
*
- * @param api the ASM API version implemented by this visitor. Must be one
- * of {@link Opcodes#ASM4}.
+ * @param api
+ * the ASM API version implemented by this visitor. Must be one
+ * of {@link Opcodes#ASM4}.
*/
public ClassVisitor(final int api) {
this(api, null);
@@ -65,15 +66,17 @@ public abstract class ClassVisitor {
/**
* Constructs a new {@link ClassVisitor}.
*
- * @param api the ASM API version implemented by this visitor. Must be one
- * of {@link Opcodes#ASM4}.
- * @param cv the class visitor to which this visitor must delegate method
- * calls. May be null.
+ * @param api
+ * the ASM API version implemented by this visitor. Must be one
+ * of {@link Opcodes#ASM4}.
+ * @param cv
+ * the class visitor to which this visitor must delegate method
+ * calls. May be null.
*/
public ClassVisitor(final int api, final ClassVisitor cv) {
- /*if (api != Opcodes.ASM4) {
+ if (api != Opcodes.ASM4) {
throw new IllegalArgumentException();
- }*/
+ }
this.api = api;
this.cv = cv;
}
@@ -81,30 +84,30 @@ public abstract class ClassVisitor {
/**
* Visits the header of the class.
*
- * @param version the class version.
- * @param access the class's access flags (see {@link Opcodes}). This
- * parameter also indicates if the class is deprecated.
- * @param name the internal name of the class (see
- * {@link Type#getInternalName() getInternalName}).
- * @param signature the signature of this class. May be <tt>null</tt> if
- * the class is not a generic one, and does not extend or implement
- * generic classes or interfaces.
- * @param superName the internal of name of the super class (see
- * {@link Type#getInternalName() getInternalName}). For interfaces,
- * the super class is {@link Object}. May be <tt>null</tt>, but
- * only for the {@link Object} class.
- * @param interfaces the internal names of the class's interfaces (see
- * {@link Type#getInternalName() getInternalName}). May be
- * <tt>null</tt>.
+ * @param version
+ * the class version.
+ * @param access
+ * the class's access flags (see {@link Opcodes}). This parameter
+ * also indicates if the class is deprecated.
+ * @param name
+ * the internal name of the class (see
+ * {@link Type#getInternalName() getInternalName}).
+ * @param signature
+ * the signature of this class. May be <tt>null</tt> if the class
+ * is not a generic one, and does not extend or implement generic
+ * classes or interfaces.
+ * @param superName
+ * the internal of name of the super class (see
+ * {@link Type#getInternalName() getInternalName}). For
+ * interfaces, the super class is {@link Object}. May be
+ * <tt>null</tt>, but only for the {@link Object} class.
+ * @param interfaces
+ * the internal names of the class's interfaces (see
+ * {@link Type#getInternalName() getInternalName}). May be
+ * <tt>null</tt>.
*/
- public void visit(
- int version,
- int access,
- String name,
- String signature,
- String superName,
- String[] interfaces)
- {
+ public void visit(int version, int access, String name, String signature,
+ String superName, String[] interfaces) {
if (cv != null) {
cv.visit(version, access, name, signature, superName, interfaces);
}
@@ -113,11 +116,13 @@ public abstract class ClassVisitor {
/**
* Visits the source of the class.
*
- * @param source the name of the source file from which the class was
- * compiled. May be <tt>null</tt>.
- * @param debug additional debug information to compute the correspondance
- * between source and compiled elements of the class. May be
- * <tt>null</tt>.
+ * @param source
+ * the name of the source file from which the class was compiled.
+ * May be <tt>null</tt>.
+ * @param debug
+ * additional debug information to compute the correspondance
+ * between source and compiled elements of the class. May be
+ * <tt>null</tt>.
*/
public void visitSource(String source, String debug) {
if (cv != null) {
@@ -129,16 +134,19 @@ public abstract class ClassVisitor {
* Visits the enclosing class of the class. This method must be called only
* if the class has an enclosing class.
*
- * @param owner internal name of the enclosing class of the class.
- * @param name the name of the method that contains the class, or
- * <tt>null</tt> if the class is not enclosed in a method of its
- * enclosing class.
- * @param desc the descriptor of the method that contains the class, or
- * <tt>null</tt> if the class is not enclosed in a method of its
- * enclosing class.
+ * @param owner
+ * internal name of the enclosing class of the class.
+ * @param name
+ * the name of the method that contains the class, or
+ * <tt>null</tt> if the class is not enclosed in a method of its
+ * enclosing class.
+ * @param desc
+ * the descriptor of the method that contains the class, or
+ * <tt>null</tt> if the class is not enclosed in a method of its
+ * enclosing class.
*/
public void visitOuterClass(String owner, String name, String desc) {
- if (cv != null) {
+ if (cv != null) {
cv.visitOuterClass(owner, name, desc);
}
}
@@ -146,8 +154,10 @@ public abstract class ClassVisitor {
/**
* Visits an annotation of the class.
*
- * @param desc the class descriptor of the annotation class.
- * @param visible <tt>true</tt> if the annotation is visible at runtime.
+ * @param desc
+ * the class descriptor of the annotation class.
+ * @param visible
+ * <tt>true</tt> if the annotation is visible at runtime.
* @return a visitor to visit the annotation values, or <tt>null</tt> if
* this visitor is not interested in visiting this annotation.
*/
@@ -161,7 +171,8 @@ public abstract class ClassVisitor {
/**
* Visits a non standard attribute of the class.
*
- * @param attr an attribute.
+ * @param attr
+ * an attribute.
*/
public void visitAttribute(Attribute attr) {
if (cv != null) {
@@ -173,23 +184,22 @@ public abstract class ClassVisitor {
* Visits information about an inner class. This inner class is not
* necessarily a member of the class being visited.
*
- * @param name the internal name of an inner class (see
- * {@link Type#getInternalName() getInternalName}).
- * @param outerName the internal name of the class to which the inner class
- * belongs (see {@link Type#getInternalName() getInternalName}). May
- * be <tt>null</tt> for not member classes.
- * @param innerName the (simple) name of the inner class inside its
- * enclosing class. May be <tt>null</tt> for anonymous inner
- * classes.
- * @param access the access flags of the inner class as originally declared
- * in the enclosing class.
+ * @param name
+ * the internal name of an inner class (see
+ * {@link Type#getInternalName() getInternalName}).
+ * @param outerName
+ * the internal name of the class to which the inner class
+ * belongs (see {@link Type#getInternalName() getInternalName}).
+ * May be <tt>null</tt> for not member classes.
+ * @param innerName
+ * the (simple) name of the inner class inside its enclosing
+ * class. May be <tt>null</tt> for anonymous inner classes.
+ * @param access
+ * the access flags of the inner class as originally declared in
+ * the enclosing class.
*/
- public void visitInnerClass(
- String name,
- String outerName,
- String innerName,
- int access)
- {
+ public void visitInnerClass(String name, String outerName,
+ String innerName, int access) {
if (cv != null) {
cv.visitInnerClass(name, outerName, innerName, access);
}
@@ -198,33 +208,32 @@ public abstract class ClassVisitor {
/**
* Visits a field of the class.
*
- * @param access the field's access flags (see {@link Opcodes}). This
- * parameter also indicates if the field is synthetic and/or
- * deprecated.
- * @param name the field's name.
- * @param desc the field's descriptor (see {@link Type Type}).
- * @param signature the field's signature. May be <tt>null</tt> if the
- * field's type does not use generic types.
- * @param value the field's initial value. This parameter, which may be
- * <tt>null</tt> if the field does not have an initial value, must
- * be an {@link Integer}, a {@link Float}, a {@link Long}, a
- * {@link Double} or a {@link String} (for <tt>int</tt>,
- * <tt>float</tt>, <tt>long</tt> or <tt>String</tt> fields
- * respectively). <i>This parameter is only used for static fields</i>.
- * Its value is ignored for non static fields, which must be
- * initialized through bytecode instructions in constructors or
- * methods.
+ * @param access
+ * the field's access flags (see {@link Opcodes}). This parameter
+ * also indicates if the field is synthetic and/or deprecated.
+ * @param name
+ * the field's name.
+ * @param desc
+ * the field's descriptor (see {@link Type Type}).
+ * @param signature
+ * the field's signature. May be <tt>null</tt> if the field's
+ * type does not use generic types.
+ * @param value
+ * the field's initial value. This parameter, which may be
+ * <tt>null</tt> if the field does not have an initial value,
+ * must be an {@link Integer}, a {@link Float}, a {@link Long}, a
+ * {@link Double} or a {@link String} (for <tt>int</tt>,
+ * <tt>float</tt>, <tt>long</tt> or <tt>String</tt> fields
+ * respectively). <i>This parameter is only used for static
+ * fields</i>. Its value is ignored for non static fields, which
+ * must be initialized through bytecode instructions in
+ * constructors or methods.
* @return a visitor to visit field annotations and attributes, or
- * <tt>null</tt> if this class visitor is not interested in
- * visiting these annotations and attributes.
+ * <tt>null</tt> if this class visitor is not interested in visiting
+ * these annotations and attributes.
*/
- public FieldVisitor visitField(
- int access,
- String name,
- String desc,
- String signature,
- Object value)
- {
+ public FieldVisitor visitField(int access, String name, String desc,
+ String signature, Object value) {
if (cv != null) {
return cv.visitField(access, name, desc, signature, value);
}
@@ -233,31 +242,31 @@ public abstract class ClassVisitor {
/**
* Visits a method of the class. This method <i>must</i> return a new
- * {@link MethodVisitor} instance (or <tt>null</tt>) each time it is
- * called, i.e., it should not return a previously returned visitor.
+ * {@link MethodVisitor} instance (or <tt>null</tt>) each time it is called,
+ * i.e., it should not return a previously returned visitor.
*
- * @param access the method's access flags (see {@link Opcodes}). This
- * parameter also indicates if the method is synthetic and/or
- * deprecated.
- * @param name the method's name.
- * @param desc the method's descriptor (see {@link Type Type}).
- * @param signature the method's signature. May be <tt>null</tt> if the
- * method parameters, return type and exceptions do not use generic
- * types.
- * @param exceptions the internal names of the method's exception classes
- * (see {@link Type#getInternalName() getInternalName}). May be
- * <tt>null</tt>.
+ * @param access
+ * the method's access flags (see {@link Opcodes}). This
+ * parameter also indicates if the method is synthetic and/or
+ * deprecated.
+ * @param name
+ * the method's name.
+ * @param desc
+ * the method's descriptor (see {@link Type Type}).
+ * @param signature
+ * the method's signature. May be <tt>null</tt> if the method
+ * parameters, return type and exceptions do not use generic
+ * types.
+ * @param exceptions
+ * the internal names of the method's exception classes (see
+ * {@link Type#getInternalName() getInternalName}). May be
+ * <tt>null</tt>.
* @return an object to visit the byte code of the method, or <tt>null</tt>
* if this class visitor is not interested in visiting the code of
* this method.
*/
- public MethodVisitor visitMethod(
- int access,
- String name,
- String desc,
- String signature,
- String[] exceptions)
- {
+ public MethodVisitor visitMethod(int access, String name, String desc,
+ String signature, String[] exceptions) {
if (cv != null) {
return cv.visitMethod(access, name, desc, signature, exceptions);
}
diff --git a/src/asm/scala/tools/asm/ClassWriter.java b/src/asm/scala/tools/asm/ClassWriter.java
index c7a0736b51..93ed7313c7 100644
--- a/src/asm/scala/tools/asm/ClassWriter.java
+++ b/src/asm/scala/tools/asm/ClassWriter.java
@@ -66,12 +66,18 @@ public class ClassWriter extends ClassVisitor {
public static final int COMPUTE_FRAMES = 2;
/**
- * Pseudo access flag to distinguish between the synthetic attribute and
- * the synthetic access flag.
+ * Pseudo access flag to distinguish between the synthetic attribute and the
+ * synthetic access flag.
*/
static final int ACC_SYNTHETIC_ATTRIBUTE = 0x40000;
/**
+ * Factor to convert from ACC_SYNTHETIC_ATTRIBUTE to Opcode.ACC_SYNTHETIC.
+ */
+ static final int TO_ACC_SYNTHETIC = ACC_SYNTHETIC_ATTRIBUTE
+ / Opcodes.ACC_SYNTHETIC;
+
+ /**
* The type of instructions without any argument.
*/
static final int NOARG_INSN = 0;
@@ -238,8 +244,8 @@ public class ClassWriter extends ClassVisitor {
/**
* The base value for all CONSTANT_MethodHandle constant pool items.
- * Internally, ASM store the 9 variations of CONSTANT_MethodHandle into
- * 9 different items.
+ * Internally, ASM store the 9 variations of CONSTANT_MethodHandle into 9
+ * different items.
*/
static final int HANDLE_BASE = 20;
@@ -266,9 +272,8 @@ public class ClassWriter extends ClassVisitor {
static final int TYPE_MERGED = 32;
/**
- * The type of BootstrapMethods items. These items are stored in a
- * special class attribute named BootstrapMethods and
- * not in the constant pool.
+ * The type of BootstrapMethods items. These items are stored in a special
+ * class attribute named BootstrapMethods and not in the constant pool.
*/
static final int BSM = 33;
@@ -327,10 +332,10 @@ public class ClassWriter extends ClassVisitor {
* necessarily be stored in the constant pool. This type table is used by
* the control flow and data flow analysis algorithm used to compute stack
* map frames from scratch. This array associates to each index <tt>i</tt>
- * the Item whose index is <tt>i</tt>. All Item objects stored in this
- * array are also stored in the {@link #items} hash table. These two arrays
- * allow to retrieve an Item from its index or, conversely, to get the index
- * of an Item from its value. Each Item stores an internal name in its
+ * the Item whose index is <tt>i</tt>. All Item objects stored in this array
+ * are also stored in the {@link #items} hash table. These two arrays allow
+ * to retrieve an Item from its index or, conversely, to get the index of an
+ * Item from its value. Each Item stores an internal name in its
* {@link Item#strVal1} field.
*/
Item[] typeTable;
@@ -439,16 +444,16 @@ public class ClassWriter extends ClassVisitor {
/**
* The fields of this class. These fields are stored in a linked list of
* {@link FieldWriter} objects, linked to each other by their
- * {@link FieldWriter#fv} field. This field stores the first element of
- * this list.
+ * {@link FieldWriter#fv} field. This field stores the first element of this
+ * list.
*/
FieldWriter firstField;
/**
* The fields of this class. These fields are stored in a linked list of
* {@link FieldWriter} objects, linked to each other by their
- * {@link FieldWriter#fv} field. This field stores the last element of
- * this list.
+ * {@link FieldWriter#fv} field. This field stores the last element of this
+ * list.
*/
FieldWriter lastField;
@@ -463,8 +468,8 @@ public class ClassWriter extends ClassVisitor {
/**
* The methods of this class. These methods are stored in a linked list of
* {@link MethodWriter} objects, linked to each other by their
- * {@link MethodWriter#mv} field. This field stores the last element of
- * this list.
+ * {@link MethodWriter#mv} field. This field stores the last element of this
+ * list.
*/
MethodWriter lastMethod;
@@ -584,8 +589,10 @@ public class ClassWriter extends ClassVisitor {
/**
* Constructs a new {@link ClassWriter} object.
*
- * @param flags option flags that can be used to modify the default behavior
- * of this class. See {@link #COMPUTE_MAXS}, {@link #COMPUTE_FRAMES}.
+ * @param flags
+ * option flags that can be used to modify the default behavior
+ * of this class. See {@link #COMPUTE_MAXS},
+ * {@link #COMPUTE_FRAMES}.
*/
public ClassWriter(final int flags) {
super(Opcodes.ASM4);
@@ -606,26 +613,32 @@ public class ClassWriter extends ClassVisitor {
* "mostly add" bytecode transformations. These optimizations are the
* following:
*
- * <ul> <li>The constant pool from the original class is copied as is in the
- * new class, which saves time. New constant pool entries will be added at
- * the end if necessary, but unused constant pool entries <i>won't be
- * removed</i>.</li> <li>Methods that are not transformed are copied as is
- * in the new class, directly from the original class bytecode (i.e. without
- * emitting visit events for all the method instructions), which saves a
- * <i>lot</i> of time. Untransformed methods are detected by the fact that
- * the {@link ClassReader} receives {@link MethodVisitor} objects that come
- * from a {@link ClassWriter} (and not from any other {@link ClassVisitor}
- * instance).</li> </ul>
+ * <ul>
+ * <li>The constant pool from the original class is copied as is in the new
+ * class, which saves time. New constant pool entries will be added at the
+ * end if necessary, but unused constant pool entries <i>won't be
+ * removed</i>.</li>
+ * <li>Methods that are not transformed are copied as is in the new class,
+ * directly from the original class bytecode (i.e. without emitting visit
+ * events for all the method instructions), which saves a <i>lot</i> of
+ * time. Untransformed methods are detected by the fact that the
+ * {@link ClassReader} receives {@link MethodVisitor} objects that come from
+ * a {@link ClassWriter} (and not from any other {@link ClassVisitor}
+ * instance).</li>
+ * </ul>
*
- * @param classReader the {@link ClassReader} used to read the original
- * class. It will be used to copy the entire constant pool from the
- * original class and also to copy other fragments of original
- * bytecode where applicable.
- * @param flags option flags that can be used to modify the default behavior
- * of this class. <i>These option flags do not affect methods that
- * are copied as is in the new class. This means that the maximum
- * stack size nor the stack frames will be computed for these
- * methods</i>. See {@link #COMPUTE_MAXS}, {@link #COMPUTE_FRAMES}.
+ * @param classReader
+ * the {@link ClassReader} used to read the original class. It
+ * will be used to copy the entire constant pool from the
+ * original class and also to copy other fragments of original
+ * bytecode where applicable.
+ * @param flags
+ * option flags that can be used to modify the default behavior
+ * of this class. <i>These option flags do not affect methods
+ * that are copied as is in the new class. This means that the
+ * maximum stack size nor the stack frames will be computed for
+ * these methods</i>. See {@link #COMPUTE_MAXS},
+ * {@link #COMPUTE_FRAMES}.
*/
public ClassWriter(final ClassReader classReader, final int flags) {
this(flags);
@@ -638,14 +651,9 @@ public class ClassWriter extends ClassVisitor {
// ------------------------------------------------------------------------
@Override
- public final void visit(
- final int version,
- final int access,
- final String name,
- final String signature,
- final String superName,
- final String[] interfaces)
- {
+ public final void visit(final int version, final int access,
+ final String name, final String signature, final String superName,
+ final String[] interfaces) {
this.version = version;
this.access = access;
this.name = newClass(name);
@@ -674,11 +682,8 @@ public class ClassWriter extends ClassVisitor {
}
@Override
- public final void visitOuterClass(
- final String owner,
- final String name,
- final String desc)
- {
+ public final void visitOuterClass(final String owner, final String name,
+ final String desc) {
enclosingMethodOwner = newClass(owner);
if (name != null && desc != null) {
enclosingMethod = newNameType(name, desc);
@@ -686,10 +691,8 @@ public class ClassWriter extends ClassVisitor {
}
@Override
- public final AnnotationVisitor visitAnnotation(
- final String desc,
- final boolean visible)
- {
+ public final AnnotationVisitor visitAnnotation(final String desc,
+ final boolean visible) {
if (!ClassReader.ANNOTATIONS) {
return null;
}
@@ -714,12 +717,8 @@ public class ClassWriter extends ClassVisitor {
}
@Override
- public final void visitInnerClass(
- final String name,
- final String outerName,
- final String innerName,
- final int access)
- {
+ public final void visitInnerClass(final String name,
+ final String outerName, final String innerName, final int access) {
if (innerClasses == null) {
innerClasses = new ByteVector();
}
@@ -731,32 +730,16 @@ public class ClassWriter extends ClassVisitor {
}
@Override
- public final FieldVisitor visitField(
- final int access,
- final String name,
- final String desc,
- final String signature,
- final Object value)
- {
+ public final FieldVisitor visitField(final int access, final String name,
+ final String desc, final String signature, final Object value) {
return new FieldWriter(this, access, name, desc, signature, value);
}
@Override
- public final MethodVisitor visitMethod(
- final int access,
- final String name,
- final String desc,
- final String signature,
- final String[] exceptions)
- {
- return new MethodWriter(this,
- access,
- name,
- desc,
- signature,
- exceptions,
- computeMaxs,
- computeFrames);
+ public final MethodVisitor visitMethod(final int access, final String name,
+ final String desc, final String signature, final String[] exceptions) {
+ return new MethodWriter(this, access, name, desc, signature,
+ exceptions, computeMaxs, computeFrames);
}
@Override
@@ -773,7 +756,7 @@ public class ClassWriter extends ClassVisitor {
* @return the bytecode of the class that was build with this class writer.
*/
public byte[] toByteArray() {
- if (index > Short.MAX_VALUE) {
+ if (index > 0xFFFF) {
throw new RuntimeException("Class file too large!");
}
// computes the real size of the bytecode of this class
@@ -793,8 +776,9 @@ public class ClassWriter extends ClassVisitor {
mb = (MethodWriter) mb.mv;
}
int attributeCount = 0;
- if (bootstrapMethods != null) { // we put it as first argument in order
- // to improve a bit ClassReader.copyBootstrapMethods
+ if (bootstrapMethods != null) {
+ // we put it as first attribute in order to improve a bit
+ // ClassReader.copyBootstrapMethods
++attributeCount;
size += 8 + bootstrapMethods.length;
newUTF8("BootstrapMethods");
@@ -824,12 +808,13 @@ public class ClassWriter extends ClassVisitor {
size += 6;
newUTF8("Deprecated");
}
- if ((access & Opcodes.ACC_SYNTHETIC) != 0
- && ((version & 0xFFFF) < Opcodes.V1_5 || (access & ACC_SYNTHETIC_ATTRIBUTE) != 0))
- {
- ++attributeCount;
- size += 6;
- newUTF8("Synthetic");
+ if ((access & Opcodes.ACC_SYNTHETIC) != 0) {
+ if ((version & 0xFFFF) < Opcodes.V1_5
+ || (access & ACC_SYNTHETIC_ATTRIBUTE) != 0) {
+ ++attributeCount;
+ size += 6;
+ newUTF8("Synthetic");
+ }
}
if (innerClasses != null) {
++attributeCount;
@@ -856,9 +841,8 @@ public class ClassWriter extends ClassVisitor {
ByteVector out = new ByteVector(size);
out.putInt(0xCAFEBABE).putInt(version);
out.putShort(index).putByteArray(pool.data, 0, pool.length);
- int mask = Opcodes.ACC_DEPRECATED
- | ClassWriter.ACC_SYNTHETIC_ATTRIBUTE
- | ((access & ClassWriter.ACC_SYNTHETIC_ATTRIBUTE) / (ClassWriter.ACC_SYNTHETIC_ATTRIBUTE / Opcodes.ACC_SYNTHETIC));
+ int mask = Opcodes.ACC_DEPRECATED | ACC_SYNTHETIC_ATTRIBUTE
+ | ((access & ACC_SYNTHETIC_ATTRIBUTE) / TO_ACC_SYNTHETIC);
out.putShort(access & ~mask).putShort(name).putShort(superName);
out.putShort(interfaceCount);
for (int i = 0; i < interfaceCount; ++i) {
@@ -877,9 +861,10 @@ public class ClassWriter extends ClassVisitor {
mb = (MethodWriter) mb.mv;
}
out.putShort(attributeCount);
- if (bootstrapMethods != null) { // should be the first class attribute ?
+ if (bootstrapMethods != null) {
out.putShort(newUTF8("BootstrapMethods"));
- out.putInt(bootstrapMethods.length + 2).putShort(bootstrapMethodsCount);
+ out.putInt(bootstrapMethods.length + 2).putShort(
+ bootstrapMethodsCount);
out.putByteArray(bootstrapMethods.data, 0, bootstrapMethods.length);
}
if (ClassReader.SIGNATURES && signature != 0) {
@@ -900,10 +885,11 @@ public class ClassWriter extends ClassVisitor {
if ((access & Opcodes.ACC_DEPRECATED) != 0) {
out.putShort(newUTF8("Deprecated")).putInt(0);
}
- if ((access & Opcodes.ACC_SYNTHETIC) != 0
- && ((version & 0xFFFF) < Opcodes.V1_5 || (access & ACC_SYNTHETIC_ATTRIBUTE) != 0))
- {
- out.putShort(newUTF8("Synthetic")).putInt(0);
+ if ((access & Opcodes.ACC_SYNTHETIC) != 0) {
+ if ((version & 0xFFFF) < Opcodes.V1_5
+ || (access & ACC_SYNTHETIC_ATTRIBUTE) != 0) {
+ out.putShort(newUTF8("Synthetic")).putInt(0);
+ }
}
if (innerClasses != null) {
out.putShort(newUTF8("InnerClasses"));
@@ -937,10 +923,11 @@ public class ClassWriter extends ClassVisitor {
* Adds a number or string constant to the constant pool of the class being
* build. Does nothing if the constant pool already contains a similar item.
*
- * @param cst the value of the constant to be added to the constant pool.
- * This parameter must be an {@link Integer}, a {@link Float}, a
- * {@link Long}, a {@link Double}, a {@link String} or a
- * {@link Type}.
+ * @param cst
+ * the value of the constant to be added to the constant pool.
+ * This parameter must be an {@link Integer}, a {@link Float}, a
+ * {@link Long}, a {@link Double}, a {@link String} or a
+ * {@link Type}.
* @return a new or already existing constant item with the given value.
*/
Item newConstItem(final Object cst) {
@@ -973,12 +960,12 @@ public class ClassWriter extends ClassVisitor {
} else if (cst instanceof Type) {
Type t = (Type) cst;
int s = t.getSort();
- if (s == Type.ARRAY) {
- return newClassItem(t.getDescriptor());
- } else if (s == Type.OBJECT) {
+ if (s == Type.OBJECT) {
return newClassItem(t.getInternalName());
- } else { // s == Type.METHOD
+ } else if (s == Type.METHOD) {
return newMethodTypeItem(t.getDescriptor());
+ } else { // s == primitive type or array
+ return newClassItem(t.getDescriptor());
}
} else if (cst instanceof Handle) {
Handle h = (Handle) cst;
@@ -994,9 +981,10 @@ public class ClassWriter extends ClassVisitor {
* <i>This method is intended for {@link Attribute} sub classes, and is
* normally not needed by class generators or adapters.</i>
*
- * @param cst the value of the constant to be added to the constant pool.
- * This parameter must be an {@link Integer}, a {@link Float}, a
- * {@link Long}, a {@link Double} or a {@link String}.
+ * @param cst
+ * the value of the constant to be added to the constant pool.
+ * This parameter must be an {@link Integer}, a {@link Float}, a
+ * {@link Long}, a {@link Double} or a {@link String}.
* @return the index of a new or already existing constant item with the
* given value.
*/
@@ -1010,7 +998,8 @@ public class ClassWriter extends ClassVisitor {
* method is intended for {@link Attribute} sub classes, and is normally not
* needed by class generators or adapters.</i>
*
- * @param value the String value.
+ * @param value
+ * the String value.
* @return the index of a new or already existing UTF8 item.
*/
public int newUTF8(final String value) {
@@ -1030,7 +1019,8 @@ public class ClassWriter extends ClassVisitor {
* <i>This method is intended for {@link Attribute} sub classes, and is
* normally not needed by class generators or adapters.</i>
*
- * @param value the internal name of the class.
+ * @param value
+ * the internal name of the class.
* @return a new or already existing class reference item.
*/
Item newClassItem(final String value) {
@@ -1050,7 +1040,8 @@ public class ClassWriter extends ClassVisitor {
* <i>This method is intended for {@link Attribute} sub classes, and is
* normally not needed by class generators or adapters.</i>
*
- * @param value the internal name of the class.
+ * @param value
+ * the internal name of the class.
* @return the index of a new or already existing class reference item.
*/
public int newClass(final String value) {
@@ -1063,7 +1054,8 @@ public class ClassWriter extends ClassVisitor {
* <i>This method is intended for {@link Attribute} sub classes, and is
* normally not needed by class generators or adapters.</i>
*
- * @param methodDesc method descriptor of the method type.
+ * @param methodDesc
+ * method descriptor of the method type.
* @return a new or already existing method type reference item.
*/
Item newMethodTypeItem(final String methodDesc) {
@@ -1083,7 +1075,8 @@ public class ClassWriter extends ClassVisitor {
* <i>This method is intended for {@link Attribute} sub classes, and is
* normally not needed by class generators or adapters.</i>
*
- * @param methodDesc method descriptor of the method type.
+ * @param methodDesc
+ * method descriptor of the method type.
* @return the index of a new or already existing method type reference
* item.
*/
@@ -1097,33 +1090,34 @@ public class ClassWriter extends ClassVisitor {
* intended for {@link Attribute} sub classes, and is normally not needed by
* class generators or adapters.</i>
*
- * @param tag the kind of this handle. Must be {@link Opcodes#H_GETFIELD},
- * {@link Opcodes#H_GETSTATIC}, {@link Opcodes#H_PUTFIELD},
- * {@link Opcodes#H_PUTSTATIC}, {@link Opcodes#H_INVOKEVIRTUAL},
- * {@link Opcodes#H_INVOKESTATIC}, {@link Opcodes#H_INVOKESPECIAL},
- * {@link Opcodes#H_NEWINVOKESPECIAL} or
- * {@link Opcodes#H_INVOKEINTERFACE}.
- * @param owner the internal name of the field or method owner class.
- * @param name the name of the field or method.
- * @param desc the descriptor of the field or method.
+ * @param tag
+ * the kind of this handle. Must be {@link Opcodes#H_GETFIELD},
+ * {@link Opcodes#H_GETSTATIC}, {@link Opcodes#H_PUTFIELD},
+ * {@link Opcodes#H_PUTSTATIC}, {@link Opcodes#H_INVOKEVIRTUAL},
+ * {@link Opcodes#H_INVOKESTATIC},
+ * {@link Opcodes#H_INVOKESPECIAL},
+ * {@link Opcodes#H_NEWINVOKESPECIAL} or
+ * {@link Opcodes#H_INVOKEINTERFACE}.
+ * @param owner
+ * the internal name of the field or method owner class.
+ * @param name
+ * the name of the field or method.
+ * @param desc
+ * the descriptor of the field or method.
* @return a new or an already existing method type reference item.
*/
- Item newHandleItem(
- final int tag,
- final String owner,
- final String name,
- final String desc)
- {
+ Item newHandleItem(final int tag, final String owner, final String name,
+ final String desc) {
key4.set(HANDLE_BASE + tag, owner, name, desc);
Item result = get(key4);
if (result == null) {
if (tag <= Opcodes.H_PUTSTATIC) {
put112(HANDLE, tag, newField(owner, name, desc));
} else {
- put112(HANDLE, tag, newMethod(owner,
- name,
- desc,
- tag == Opcodes.H_INVOKEINTERFACE));
+ put112(HANDLE,
+ tag,
+ newMethod(owner, name, desc,
+ tag == Opcodes.H_INVOKEINTERFACE));
}
result = new Item(index++, key4);
put(result);
@@ -1132,29 +1126,30 @@ public class ClassWriter extends ClassVisitor {
}
/**
- * Adds a handle to the constant pool of the class being
- * build. Does nothing if the constant pool already contains a similar item.
- * <i>This method is intended for {@link Attribute} sub classes, and is
- * normally not needed by class generators or adapters.</i>
+ * Adds a handle to the constant pool of the class being build. Does nothing
+ * if the constant pool already contains a similar item. <i>This method is
+ * intended for {@link Attribute} sub classes, and is normally not needed by
+ * class generators or adapters.</i>
*
- * @param tag the kind of this handle. Must be {@link Opcodes#H_GETFIELD},
- * {@link Opcodes#H_GETSTATIC}, {@link Opcodes#H_PUTFIELD},
- * {@link Opcodes#H_PUTSTATIC}, {@link Opcodes#H_INVOKEVIRTUAL},
- * {@link Opcodes#H_INVOKESTATIC}, {@link Opcodes#H_INVOKESPECIAL},
- * {@link Opcodes#H_NEWINVOKESPECIAL} or
- * {@link Opcodes#H_INVOKEINTERFACE}.
- * @param owner the internal name of the field or method owner class.
- * @param name the name of the field or method.
- * @param desc the descriptor of the field or method.
+ * @param tag
+ * the kind of this handle. Must be {@link Opcodes#H_GETFIELD},
+ * {@link Opcodes#H_GETSTATIC}, {@link Opcodes#H_PUTFIELD},
+ * {@link Opcodes#H_PUTSTATIC}, {@link Opcodes#H_INVOKEVIRTUAL},
+ * {@link Opcodes#H_INVOKESTATIC},
+ * {@link Opcodes#H_INVOKESPECIAL},
+ * {@link Opcodes#H_NEWINVOKESPECIAL} or
+ * {@link Opcodes#H_INVOKEINTERFACE}.
+ * @param owner
+ * the internal name of the field or method owner class.
+ * @param name
+ * the name of the field or method.
+ * @param desc
+ * the descriptor of the field or method.
* @return the index of a new or already existing method type reference
* item.
*/
- public int newHandle(
- final int tag,
- final String owner,
- final String name,
- final String desc)
- {
+ public int newHandle(final int tag, final String owner, final String name,
+ final String desc) {
return newHandleItem(tag, owner, name, desc).index;
}
@@ -1164,19 +1159,19 @@ public class ClassWriter extends ClassVisitor {
* <i>This method is intended for {@link Attribute} sub classes, and is
* normally not needed by class generators or adapters.</i>
*
- * @param name name of the invoked method.
- * @param desc descriptor of the invoke method.
- * @param bsm the bootstrap method.
- * @param bsmArgs the bootstrap method constant arguments.
+ * @param name
+ * name of the invoked method.
+ * @param desc
+ * descriptor of the invoke method.
+ * @param bsm
+ * the bootstrap method.
+ * @param bsmArgs
+ * the bootstrap method constant arguments.
*
* @return a new or an already existing invokedynamic type reference item.
*/
- Item newInvokeDynamicItem(
- final String name,
- final String desc,
- final Handle bsm,
- final Object... bsmArgs)
- {
+ Item newInvokeDynamicItem(final String name, final String desc,
+ final Handle bsm, final Object... bsmArgs) {
// cache for performance
ByteVector bootstrapMethods = this.bootstrapMethods;
if (bootstrapMethods == null) {
@@ -1186,9 +1181,7 @@ public class ClassWriter extends ClassVisitor {
int position = bootstrapMethods.length; // record current position
int hashCode = bsm.hashCode();
- bootstrapMethods.putShort(newHandle(bsm.tag,
- bsm.owner,
- bsm.name,
+ bootstrapMethods.putShort(newHandle(bsm.tag, bsm.owner, bsm.name,
bsm.desc));
int argsLength = bsmArgs.length;
@@ -1250,20 +1243,20 @@ public class ClassWriter extends ClassVisitor {
* <i>This method is intended for {@link Attribute} sub classes, and is
* normally not needed by class generators or adapters.</i>
*
- * @param name name of the invoked method.
- * @param desc descriptor of the invoke method.
- * @param bsm the bootstrap method.
- * @param bsmArgs the bootstrap method constant arguments.
+ * @param name
+ * name of the invoked method.
+ * @param desc
+ * descriptor of the invoke method.
+ * @param bsm
+ * the bootstrap method.
+ * @param bsmArgs
+ * the bootstrap method constant arguments.
*
- * @return the index of a new or already existing invokedynamic
- * reference item.
- */
- public int newInvokeDynamic(
- final String name,
- final String desc,
- final Handle bsm,
- final Object... bsmArgs)
- {
+ * @return the index of a new or already existing invokedynamic reference
+ * item.
+ */
+ public int newInvokeDynamic(final String name, final String desc,
+ final Handle bsm, final Object... bsmArgs) {
return newInvokeDynamicItem(name, desc, bsm, bsmArgs).index;
}
@@ -1271,13 +1264,15 @@ public class ClassWriter extends ClassVisitor {
* Adds a field reference to the constant pool of the class being build.
* Does nothing if the constant pool already contains a similar item.
*
- * @param owner the internal name of the field's owner class.
- * @param name the field's name.
- * @param desc the field's descriptor.
+ * @param owner
+ * the internal name of the field's owner class.
+ * @param name
+ * the field's name.
+ * @param desc
+ * the field's descriptor.
* @return a new or already existing field reference item.
*/
- Item newFieldItem(final String owner, final String name, final String desc)
- {
+ Item newFieldItem(final String owner, final String name, final String desc) {
key3.set(FIELD, owner, name, desc);
Item result = get(key3);
if (result == null) {
@@ -1294,13 +1289,15 @@ public class ClassWriter extends ClassVisitor {
* <i>This method is intended for {@link Attribute} sub classes, and is
* normally not needed by class generators or adapters.</i>
*
- * @param owner the internal name of the field's owner class.
- * @param name the field's name.
- * @param desc the field's descriptor.
+ * @param owner
+ * the internal name of the field's owner class.
+ * @param name
+ * the field's name.
+ * @param desc
+ * the field's descriptor.
* @return the index of a new or already existing field reference item.
*/
- public int newField(final String owner, final String name, final String desc)
- {
+ public int newField(final String owner, final String name, final String desc) {
return newFieldItem(owner, name, desc).index;
}
@@ -1308,18 +1305,18 @@ public class ClassWriter extends ClassVisitor {
* Adds a method reference to the constant pool of the class being build.
* Does nothing if the constant pool already contains a similar item.
*
- * @param owner the internal name of the method's owner class.
- * @param name the method's name.
- * @param desc the method's descriptor.
- * @param itf <tt>true</tt> if <tt>owner</tt> is an interface.
+ * @param owner
+ * the internal name of the method's owner class.
+ * @param name
+ * the method's name.
+ * @param desc
+ * the method's descriptor.
+ * @param itf
+ * <tt>true</tt> if <tt>owner</tt> is an interface.
* @return a new or already existing method reference item.
*/
- Item newMethodItem(
- final String owner,
- final String name,
- final String desc,
- final boolean itf)
- {
+ Item newMethodItem(final String owner, final String name,
+ final String desc, final boolean itf) {
int type = itf ? IMETH : METH;
key3.set(type, owner, name, desc);
Item result = get(key3);
@@ -1337,18 +1334,18 @@ public class ClassWriter extends ClassVisitor {
* <i>This method is intended for {@link Attribute} sub classes, and is
* normally not needed by class generators or adapters.</i>
*
- * @param owner the internal name of the method's owner class.
- * @param name the method's name.
- * @param desc the method's descriptor.
- * @param itf <tt>true</tt> if <tt>owner</tt> is an interface.
+ * @param owner
+ * the internal name of the method's owner class.
+ * @param name
+ * the method's name.
+ * @param desc
+ * the method's descriptor.
+ * @param itf
+ * <tt>true</tt> if <tt>owner</tt> is an interface.
* @return the index of a new or already existing method reference item.
*/
- public int newMethod(
- final String owner,
- final String name,
- final String desc,
- final boolean itf)
- {
+ public int newMethod(final String owner, final String name,
+ final String desc, final boolean itf) {
return newMethodItem(owner, name, desc, itf).index;
}
@@ -1356,7 +1353,8 @@ public class ClassWriter extends ClassVisitor {
* Adds an integer to the constant pool of the class being build. Does
* nothing if the constant pool already contains a similar item.
*
- * @param value the int value.
+ * @param value
+ * the int value.
* @return a new or already existing int item.
*/
Item newInteger(final int value) {
@@ -1374,7 +1372,8 @@ public class ClassWriter extends ClassVisitor {
* Adds a float to the constant pool of the class being build. Does nothing
* if the constant pool already contains a similar item.
*
- * @param value the float value.
+ * @param value
+ * the float value.
* @return a new or already existing float item.
*/
Item newFloat(final float value) {
@@ -1392,7 +1391,8 @@ public class ClassWriter extends ClassVisitor {
* Adds a long to the constant pool of the class being build. Does nothing
* if the constant pool already contains a similar item.
*
- * @param value the long value.
+ * @param value
+ * the long value.
* @return a new or already existing long item.
*/
Item newLong(final long value) {
@@ -1411,7 +1411,8 @@ public class ClassWriter extends ClassVisitor {
* Adds a double to the constant pool of the class being build. Does nothing
* if the constant pool already contains a similar item.
*
- * @param value the double value.
+ * @param value
+ * the double value.
* @return a new or already existing double item.
*/
Item newDouble(final double value) {
@@ -1430,7 +1431,8 @@ public class ClassWriter extends ClassVisitor {
* Adds a string to the constant pool of the class being build. Does nothing
* if the constant pool already contains a similar item.
*
- * @param value the String value.
+ * @param value
+ * the String value.
* @return a new or already existing string item.
*/
private Item newString(final String value) {
@@ -1450,8 +1452,10 @@ public class ClassWriter extends ClassVisitor {
* method is intended for {@link Attribute} sub classes, and is normally not
* needed by class generators or adapters.</i>
*
- * @param name a name.
- * @param desc a type descriptor.
+ * @param name
+ * a name.
+ * @param desc
+ * a type descriptor.
* @return the index of a new or already existing name and type item.
*/
public int newNameType(final String name, final String desc) {
@@ -1462,8 +1466,10 @@ public class ClassWriter extends ClassVisitor {
* Adds a name and type to the constant pool of the class being build. Does
* nothing if the constant pool already contains a similar item.
*
- * @param name a name.
- * @param desc a type descriptor.
+ * @param name
+ * a name.
+ * @param desc
+ * a type descriptor.
* @return a new or already existing name and type item.
*/
Item newNameTypeItem(final String name, final String desc) {
@@ -1481,7 +1487,8 @@ public class ClassWriter extends ClassVisitor {
* Adds the given internal name to {@link #typeTable} and returns its index.
* Does nothing if the type table already contains this internal name.
*
- * @param type the internal name to be added to the type table.
+ * @param type
+ * the internal name to be added to the type table.
* @return the index of this internal name in the type table.
*/
int addType(final String type) {
@@ -1498,9 +1505,11 @@ public class ClassWriter extends ClassVisitor {
* index. This method is used for UNINITIALIZED types, made of an internal
* name and a bytecode offset.
*
- * @param type the internal name to be added to the type table.
- * @param offset the bytecode offset of the NEW instruction that created
- * this UNINITIALIZED type value.
+ * @param type
+ * the internal name to be added to the type table.
+ * @param offset
+ * the bytecode offset of the NEW instruction that created this
+ * UNINITIALIZED type value.
* @return the index of this internal name in the type table.
*/
int addUninitializedType(final String type, final int offset) {
@@ -1518,7 +1527,8 @@ public class ClassWriter extends ClassVisitor {
/**
* Adds the given Item to {@link #typeTable}.
*
- * @param item the value to be added to the type table.
+ * @param item
+ * the value to be added to the type table.
* @return the added Item, which a new Item instance with the same value as
* the given Item.
*/
@@ -1544,8 +1554,10 @@ public class ClassWriter extends ClassVisitor {
* {@link #items} hash table to speedup future calls with the same
* parameters.
*
- * @param type1 index of an internal name in {@link #typeTable}.
- * @param type2 index of an internal name in {@link #typeTable}.
+ * @param type1
+ * index of an internal name in {@link #typeTable}.
+ * @param type2
+ * index of an internal name in {@link #typeTable}.
* @return the index of the common super type of the two given types.
*/
int getMergedType(final int type1, final int type2) {
@@ -1572,13 +1584,14 @@ public class ClassWriter extends ClassVisitor {
* that is currently being generated by this ClassWriter, which can of
* course not be loaded since it is under construction.
*
- * @param type1 the internal name of a class.
- * @param type2 the internal name of another class.
+ * @param type1
+ * the internal name of a class.
+ * @param type2
+ * the internal name of another class.
* @return the internal name of the common super class of the two given
* classes.
*/
- protected String getCommonSuperClass(final String type1, final String type2)
- {
+ protected String getCommonSuperClass(final String type1, final String type2) {
Class<?> c, d;
ClassLoader classLoader = getClass().getClassLoader();
try {
@@ -1607,7 +1620,8 @@ public class ClassWriter extends ClassVisitor {
* Returns the constant pool's hash table item which is equal to the given
* item.
*
- * @param key a constant pool item.
+ * @param key
+ * a constant pool item.
* @return the constant pool's hash table item which is equal to the given
* item, or <tt>null</tt> if there is no such item.
*/
@@ -1623,7 +1637,8 @@ public class ClassWriter extends ClassVisitor {
* Puts the given item in the constant pool's hash table. The hash table
* <i>must</i> not already contains this item.
*
- * @param i the item to be added to the constant pool's hash table.
+ * @param i
+ * the item to be added to the constant pool's hash table.
*/
private void put(final Item i) {
if (index + typeCount > threshold) {
@@ -1651,9 +1666,12 @@ public class ClassWriter extends ClassVisitor {
/**
* Puts one byte and two shorts into the constant pool.
*
- * @param b a byte.
- * @param s1 a short.
- * @param s2 another short.
+ * @param b
+ * a byte.
+ * @param s1
+ * a short.
+ * @param s2
+ * another short.
*/
private void put122(final int b, final int s1, final int s2) {
pool.put12(b, s1).putShort(s2);
@@ -1662,9 +1680,12 @@ public class ClassWriter extends ClassVisitor {
/**
* Puts two bytes and one short into the constant pool.
*
- * @param b1 a byte.
- * @param b2 another byte.
- * @param s a short.
+ * @param b1
+ * a byte.
+ * @param b2
+ * another byte.
+ * @param s
+ * a short.
*/
private void put112(final int b1, final int b2, final int s) {
pool.put11(b1, b2).putShort(s);
diff --git a/src/asm/scala/tools/asm/Context.java b/src/asm/scala/tools/asm/Context.java
new file mode 100644
index 0000000000..7b3a2ad9dd
--- /dev/null
+++ b/src/asm/scala/tools/asm/Context.java
@@ -0,0 +1,110 @@
+/***
+ * ASM: a very small and fast Java bytecode manipulation framework
+ * Copyright (c) 2000-2011 INRIA, France Telecom
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package scala.tools.asm;
+
+/**
+ * Information about a class being parsed in a {@link ClassReader}.
+ *
+ * @author Eric Bruneton
+ */
+class Context {
+
+ /**
+ * Prototypes of the attributes that must be parsed for this class.
+ */
+ Attribute[] attrs;
+
+ /**
+ * The {@link ClassReader} option flags for the parsing of this class.
+ */
+ int flags;
+
+ /**
+ * The buffer used to read strings.
+ */
+ char[] buffer;
+
+ /**
+ * The start index of each bootstrap method.
+ */
+ int[] bootstrapMethods;
+
+ /**
+ * The access flags of the method currently being parsed.
+ */
+ int access;
+
+ /**
+ * The name of the method currently being parsed.
+ */
+ String name;
+
+ /**
+ * The descriptor of the method currently being parsed.
+ */
+ String desc;
+
+ /**
+ * The offset of the latest stack map frame that has been parsed.
+ */
+ int offset;
+
+ /**
+ * The encoding of the latest stack map frame that has been parsed.
+ */
+ int mode;
+
+ /**
+ * The number of locals in the latest stack map frame that has been parsed.
+ */
+ int localCount;
+
+ /**
+ * The number locals in the latest stack map frame that has been parsed,
+ * minus the number of locals in the previous frame.
+ */
+ int localDiff;
+
+ /**
+ * The local values of the latest stack map frame that has been parsed.
+ */
+ Object[] local;
+
+ /**
+ * The stack size of the latest stack map frame that has been parsed.
+ */
+ int stackCount;
+
+ /**
+ * The stack values of the latest stack map frame that has been parsed.
+ */
+ Object[] stack;
+}
diff --git a/src/asm/scala/tools/asm/FieldVisitor.java b/src/asm/scala/tools/asm/FieldVisitor.java
index 9ac0f6236f..9171f331e5 100644
--- a/src/asm/scala/tools/asm/FieldVisitor.java
+++ b/src/asm/scala/tools/asm/FieldVisitor.java
@@ -30,9 +30,9 @@
package scala.tools.asm;
/**
- * A visitor to visit a Java field. The methods of this class must be called
- * in the following order: ( <tt>visitAnnotation</tt> |
- * <tt>visitAttribute</tt> )* <tt>visitEnd</tt>.
+ * A visitor to visit a Java field. The methods of this class must be called in
+ * the following order: ( <tt>visitAnnotation</tt> | <tt>visitAttribute</tt> )*
+ * <tt>visitEnd</tt>.
*
* @author Eric Bruneton
*/
@@ -53,8 +53,9 @@ public abstract class FieldVisitor {
/**
* Constructs a new {@link FieldVisitor}.
*
- * @param api the ASM API version implemented by this visitor. Must be one
- * of {@link Opcodes#ASM4}.
+ * @param api
+ * the ASM API version implemented by this visitor. Must be one
+ * of {@link Opcodes#ASM4}.
*/
public FieldVisitor(final int api) {
this(api, null);
@@ -63,15 +64,17 @@ public abstract class FieldVisitor {
/**
* Constructs a new {@link FieldVisitor}.
*
- * @param api the ASM API version implemented by this visitor. Must be one
- * of {@link Opcodes#ASM4}.
- * @param fv the field visitor to which this visitor must delegate method
- * calls. May be null.
+ * @param api
+ * the ASM API version implemented by this visitor. Must be one
+ * of {@link Opcodes#ASM4}.
+ * @param fv
+ * the field visitor to which this visitor must delegate method
+ * calls. May be null.
*/
public FieldVisitor(final int api, final FieldVisitor fv) {
- /*if (api != Opcodes.ASM4) {
+ if (api != Opcodes.ASM4) {
throw new IllegalArgumentException();
- }*/
+ }
this.api = api;
this.fv = fv;
}
@@ -79,8 +82,10 @@ public abstract class FieldVisitor {
/**
* Visits an annotation of the field.
*
- * @param desc the class descriptor of the annotation class.
- * @param visible <tt>true</tt> if the annotation is visible at runtime.
+ * @param desc
+ * the class descriptor of the annotation class.
+ * @param visible
+ * <tt>true</tt> if the annotation is visible at runtime.
* @return a visitor to visit the annotation values, or <tt>null</tt> if
* this visitor is not interested in visiting this annotation.
*/
@@ -94,7 +99,8 @@ public abstract class FieldVisitor {
/**
* Visits a non standard attribute of the field.
*
- * @param attr an attribute.
+ * @param attr
+ * an attribute.
*/
public void visitAttribute(Attribute attr) {
if (fv != null) {
diff --git a/src/asm/scala/tools/asm/FieldWriter.java b/src/asm/scala/tools/asm/FieldWriter.java
index 45ef6d0df3..02c6059b91 100644
--- a/src/asm/scala/tools/asm/FieldWriter.java
+++ b/src/asm/scala/tools/asm/FieldWriter.java
@@ -92,21 +92,21 @@ final class FieldWriter extends FieldVisitor {
/**
* Constructs a new {@link FieldWriter}.
*
- * @param cw the class writer to which this field must be added.
- * @param access the field's access flags (see {@link Opcodes}).
- * @param name the field's name.
- * @param desc the field's descriptor (see {@link Type}).
- * @param signature the field's signature. May be <tt>null</tt>.
- * @param value the field's constant value. May be <tt>null</tt>.
+ * @param cw
+ * the class writer to which this field must be added.
+ * @param access
+ * the field's access flags (see {@link Opcodes}).
+ * @param name
+ * the field's name.
+ * @param desc
+ * the field's descriptor (see {@link Type}).
+ * @param signature
+ * the field's signature. May be <tt>null</tt>.
+ * @param value
+ * the field's constant value. May be <tt>null</tt>.
*/
- FieldWriter(
- final ClassWriter cw,
- final int access,
- final String name,
- final String desc,
- final String signature,
- final Object value)
- {
+ FieldWriter(final ClassWriter cw, final int access, final String name,
+ final String desc, final String signature, final Object value) {
super(Opcodes.ASM4);
if (cw.firstField == null) {
cw.firstField = this;
@@ -131,10 +131,8 @@ final class FieldWriter extends FieldVisitor {
// ------------------------------------------------------------------------
@Override
- public AnnotationVisitor visitAnnotation(
- final String desc,
- final boolean visible)
- {
+ public AnnotationVisitor visitAnnotation(final String desc,
+ final boolean visible) {
if (!ClassReader.ANNOTATIONS) {
return null;
}
@@ -177,11 +175,12 @@ final class FieldWriter extends FieldVisitor {
cw.newUTF8("ConstantValue");
size += 8;
}
- if ((access & Opcodes.ACC_SYNTHETIC) != 0
- && ((cw.version & 0xFFFF) < Opcodes.V1_5 || (access & ClassWriter.ACC_SYNTHETIC_ATTRIBUTE) != 0))
- {
- cw.newUTF8("Synthetic");
- size += 6;
+ if ((access & Opcodes.ACC_SYNTHETIC) != 0) {
+ if ((cw.version & 0xFFFF) < Opcodes.V1_5
+ || (access & ClassWriter.ACC_SYNTHETIC_ATTRIBUTE) != 0) {
+ cw.newUTF8("Synthetic");
+ size += 6;
+ }
}
if ((access & Opcodes.ACC_DEPRECATED) != 0) {
cw.newUTF8("Deprecated");
@@ -208,21 +207,23 @@ final class FieldWriter extends FieldVisitor {
/**
* Puts the content of this field into the given byte vector.
*
- * @param out where the content of this field must be put.
+ * @param out
+ * where the content of this field must be put.
*/
void put(final ByteVector out) {
- int mask = Opcodes.ACC_DEPRECATED
- | ClassWriter.ACC_SYNTHETIC_ATTRIBUTE
- | ((access & ClassWriter.ACC_SYNTHETIC_ATTRIBUTE) / (ClassWriter.ACC_SYNTHETIC_ATTRIBUTE / Opcodes.ACC_SYNTHETIC));
+ final int FACTOR = ClassWriter.TO_ACC_SYNTHETIC;
+ int mask = Opcodes.ACC_DEPRECATED | ClassWriter.ACC_SYNTHETIC_ATTRIBUTE
+ | ((access & ClassWriter.ACC_SYNTHETIC_ATTRIBUTE) / FACTOR);
out.putShort(access & ~mask).putShort(name).putShort(desc);
int attributeCount = 0;
if (value != 0) {
++attributeCount;
}
- if ((access & Opcodes.ACC_SYNTHETIC) != 0
- && ((cw.version & 0xFFFF) < Opcodes.V1_5 || (access & ClassWriter.ACC_SYNTHETIC_ATTRIBUTE) != 0))
- {
- ++attributeCount;
+ if ((access & Opcodes.ACC_SYNTHETIC) != 0) {
+ if ((cw.version & 0xFFFF) < Opcodes.V1_5
+ || (access & ClassWriter.ACC_SYNTHETIC_ATTRIBUTE) != 0) {
+ ++attributeCount;
+ }
}
if ((access & Opcodes.ACC_DEPRECATED) != 0) {
++attributeCount;
@@ -244,10 +245,11 @@ final class FieldWriter extends FieldVisitor {
out.putShort(cw.newUTF8("ConstantValue"));
out.putInt(2).putShort(value);
}
- if ((access & Opcodes.ACC_SYNTHETIC) != 0
- && ((cw.version & 0xFFFF) < Opcodes.V1_5 || (access & ClassWriter.ACC_SYNTHETIC_ATTRIBUTE) != 0))
- {
- out.putShort(cw.newUTF8("Synthetic")).putInt(0);
+ if ((access & Opcodes.ACC_SYNTHETIC) != 0) {
+ if ((cw.version & 0xFFFF) < Opcodes.V1_5
+ || (access & ClassWriter.ACC_SYNTHETIC_ATTRIBUTE) != 0) {
+ out.putShort(cw.newUTF8("Synthetic")).putInt(0);
+ }
}
if ((access & Opcodes.ACC_DEPRECATED) != 0) {
out.putShort(cw.newUTF8("Deprecated")).putInt(0);
diff --git a/src/asm/scala/tools/asm/Frame.java b/src/asm/scala/tools/asm/Frame.java
index 387b56796d..bcc3e8450b 100644
--- a/src/asm/scala/tools/asm/Frame.java
+++ b/src/asm/scala/tools/asm/Frame.java
@@ -80,13 +80,13 @@ final class Frame {
* table contains only internal type names (array type descriptors are
* forbidden - dimensions must be represented through the DIM field).
*
- * The LONG and DOUBLE types are always represented by using two slots (LONG +
- * TOP or DOUBLE + TOP), for local variable types as well as in the operand
- * stack. This is necessary to be able to simulate DUPx_y instructions,
- * whose effect would be dependent on the actual type values if types were
- * always represented by a single slot in the stack (and this is not
- * possible, since actual type values are not always known - cf LOCAL and
- * STACK type kinds).
+ * The LONG and DOUBLE types are always represented by using two slots (LONG
+ * + TOP or DOUBLE + TOP), for local variable types as well as in the
+ * operand stack. This is necessary to be able to simulate DUPx_y
+ * instructions, whose effect would be dependent on the actual type values
+ * if types were always represented by a single slot in the stack (and this
+ * is not possible, since actual type values are not always known - cf LOCAL
+ * and STACK type kinds).
*/
/**
@@ -117,9 +117,9 @@ final class Frame {
/**
* Flag used for LOCAL and STACK types. Indicates that if this type happens
* to be a long or double type (during the computations of input frames),
- * then it must be set to TOP because the second word of this value has
- * been reused to store other data in the basic block. Hence the first word
- * no longer stores a valid long or double value.
+ * then it must be set to TOP because the second word of this value has been
+ * reused to store other data in the basic block. Hence the first word no
+ * longer stores a valid long or double value.
*/
static final int TOP_IF_LONG_OR_DOUBLE = 0x800000;
@@ -523,7 +523,8 @@ final class Frame {
/**
* Returns the output frame local variable type at the given index.
*
- * @param local the index of the local that must be returned.
+ * @param local
+ * the index of the local that must be returned.
* @return the output frame local variable type at the given index.
*/
private int get(final int local) {
@@ -545,8 +546,10 @@ final class Frame {
/**
* Sets the output frame local variable type at the given index.
*
- * @param local the index of the local that must be set.
- * @param type the value of the local that must be set.
+ * @param local
+ * the index of the local that must be set.
+ * @param type
+ * the value of the local that must be set.
*/
private void set(final int local, final int type) {
// creates and/or resizes the output local variables array if necessary
@@ -566,7 +569,8 @@ final class Frame {
/**
* Pushes a new type onto the output frame stack.
*
- * @param type the type that must be pushed.
+ * @param type
+ * the type that must be pushed.
*/
private void push(final int type) {
// creates and/or resizes the output stack array if necessary
@@ -591,10 +595,12 @@ final class Frame {
/**
* Pushes a new type onto the output frame stack.
*
- * @param cw the ClassWriter to which this label belongs.
- * @param desc the descriptor of the type to be pushed. Can also be a method
- * descriptor (in this case this method pushes its return type onto
- * the output frame stack).
+ * @param cw
+ * the ClassWriter to which this label belongs.
+ * @param desc
+ * the descriptor of the type to be pushed. Can also be a method
+ * descriptor (in this case this method pushes its return type
+ * onto the output frame stack).
*/
private void push(final ClassWriter cw, final String desc) {
int type = type(cw, desc);
@@ -609,72 +615,74 @@ final class Frame {
/**
* Returns the int encoding of the given type.
*
- * @param cw the ClassWriter to which this label belongs.
- * @param desc a type descriptor.
+ * @param cw
+ * the ClassWriter to which this label belongs.
+ * @param desc
+ * a type descriptor.
* @return the int encoding of the given type.
*/
private static int type(final ClassWriter cw, final String desc) {
String t;
int index = desc.charAt(0) == '(' ? desc.indexOf(')') + 1 : 0;
switch (desc.charAt(index)) {
- case 'V':
- return 0;
+ case 'V':
+ return 0;
+ case 'Z':
+ case 'C':
+ case 'B':
+ case 'S':
+ case 'I':
+ return INTEGER;
+ case 'F':
+ return FLOAT;
+ case 'J':
+ return LONG;
+ case 'D':
+ return DOUBLE;
+ case 'L':
+ // stores the internal name, not the descriptor!
+ t = desc.substring(index + 1, desc.length() - 1);
+ return OBJECT | cw.addType(t);
+ // case '[':
+ default:
+ // extracts the dimensions and the element type
+ int data;
+ int dims = index + 1;
+ while (desc.charAt(dims) == '[') {
+ ++dims;
+ }
+ switch (desc.charAt(dims)) {
case 'Z':
+ data = BOOLEAN;
+ break;
case 'C':
+ data = CHAR;
+ break;
case 'B':
+ data = BYTE;
+ break;
case 'S':
+ data = SHORT;
+ break;
case 'I':
- return INTEGER;
+ data = INTEGER;
+ break;
case 'F':
- return FLOAT;
+ data = FLOAT;
+ break;
case 'J':
- return LONG;
+ data = LONG;
+ break;
case 'D':
- return DOUBLE;
- case 'L':
- // stores the internal name, not the descriptor!
- t = desc.substring(index + 1, desc.length() - 1);
- return OBJECT | cw.addType(t);
- // case '[':
+ data = DOUBLE;
+ break;
+ // case 'L':
default:
- // extracts the dimensions and the element type
- int data;
- int dims = index + 1;
- while (desc.charAt(dims) == '[') {
- ++dims;
- }
- switch (desc.charAt(dims)) {
- case 'Z':
- data = BOOLEAN;
- break;
- case 'C':
- data = CHAR;
- break;
- case 'B':
- data = BYTE;
- break;
- case 'S':
- data = SHORT;
- break;
- case 'I':
- data = INTEGER;
- break;
- case 'F':
- data = FLOAT;
- break;
- case 'J':
- data = LONG;
- break;
- case 'D':
- data = DOUBLE;
- break;
- // case 'L':
- default:
- // stores the internal name, not the descriptor
- t = desc.substring(dims + 1, desc.length() - 1);
- data = OBJECT | cw.addType(t);
- }
- return (dims - index) << 28 | data;
+ // stores the internal name, not the descriptor
+ t = desc.substring(dims + 1, desc.length() - 1);
+ data = OBJECT | cw.addType(t);
+ }
+ return (dims - index) << 28 | data;
}
}
@@ -695,7 +703,8 @@ final class Frame {
/**
* Pops the given number of types from the output frame stack.
*
- * @param elements the number of types that must be popped.
+ * @param elements
+ * the number of types that must be popped.
*/
private void pop(final int elements) {
if (outputStackTop >= elements) {
@@ -712,9 +721,10 @@ final class Frame {
/**
* Pops a type from the output frame stack.
*
- * @param desc the descriptor of the type to be popped. Can also be a method
- * descriptor (in this case this method pops the types corresponding
- * to the method arguments).
+ * @param desc
+ * the descriptor of the type to be popped. Can also be a method
+ * descriptor (in this case this method pops the types
+ * corresponding to the method arguments).
*/
private void pop(final String desc) {
char c = desc.charAt(0);
@@ -731,7 +741,8 @@ final class Frame {
* Adds a new type to the list of types on which a constructor is invoked in
* the basic block.
*
- * @param var a type on a which a constructor is invoked.
+ * @param var
+ * a type on a which a constructor is invoked.
*/
private void init(final int var) {
// creates and/or resizes the initializations array if necessary
@@ -752,8 +763,10 @@ final class Frame {
* Replaces the given type with the appropriate type if it is one of the
* types on which a constructor is invoked in the basic block.
*
- * @param cw the ClassWriter to which this label belongs.
- * @param t a type
+ * @param cw
+ * the ClassWriter to which this label belongs.
+ * @param t
+ * a type
* @return t or, if t is one of the types on which a constructor is invoked
* in the basic block, the type corresponding to this constructor.
*/
@@ -787,17 +800,17 @@ final class Frame {
* Initializes the input frame of the first basic block from the method
* descriptor.
*
- * @param cw the ClassWriter to which this label belongs.
- * @param access the access flags of the method to which this label belongs.
- * @param args the formal parameter types of this method.
- * @param maxLocals the maximum number of local variables of this method.
+ * @param cw
+ * the ClassWriter to which this label belongs.
+ * @param access
+ * the access flags of the method to which this label belongs.
+ * @param args
+ * the formal parameter types of this method.
+ * @param maxLocals
+ * the maximum number of local variables of this method.
*/
- void initInputFrame(
- final ClassWriter cw,
- final int access,
- final Type[] args,
- final int maxLocals)
- {
+ void initInputFrame(final ClassWriter cw, final int access,
+ final Type[] args, final int maxLocals) {
inputLocals = new int[maxLocals];
inputStack = new int[0];
int i = 0;
@@ -823,435 +836,435 @@ final class Frame {
/**
* Simulates the action of the given instruction on the output stack frame.
*
- * @param opcode the opcode of the instruction.
- * @param arg the operand of the instruction, if any.
- * @param cw the class writer to which this label belongs.
- * @param item the operand of the instructions, if any.
+ * @param opcode
+ * the opcode of the instruction.
+ * @param arg
+ * the operand of the instruction, if any.
+ * @param cw
+ * the class writer to which this label belongs.
+ * @param item
+ * the operand of the instructions, if any.
*/
- void execute(
- final int opcode,
- final int arg,
- final ClassWriter cw,
- final Item item)
- {
+ void execute(final int opcode, final int arg, final ClassWriter cw,
+ final Item item) {
int t1, t2, t3, t4;
switch (opcode) {
- case Opcodes.NOP:
- case Opcodes.INEG:
- case Opcodes.LNEG:
- case Opcodes.FNEG:
- case Opcodes.DNEG:
- case Opcodes.I2B:
- case Opcodes.I2C:
- case Opcodes.I2S:
- case Opcodes.GOTO:
- case Opcodes.RETURN:
- break;
- case Opcodes.ACONST_NULL:
- push(NULL);
- break;
- case Opcodes.ICONST_M1:
- case Opcodes.ICONST_0:
- case Opcodes.ICONST_1:
- case Opcodes.ICONST_2:
- case Opcodes.ICONST_3:
- case Opcodes.ICONST_4:
- case Opcodes.ICONST_5:
- case Opcodes.BIPUSH:
- case Opcodes.SIPUSH:
- case Opcodes.ILOAD:
+ case Opcodes.NOP:
+ case Opcodes.INEG:
+ case Opcodes.LNEG:
+ case Opcodes.FNEG:
+ case Opcodes.DNEG:
+ case Opcodes.I2B:
+ case Opcodes.I2C:
+ case Opcodes.I2S:
+ case Opcodes.GOTO:
+ case Opcodes.RETURN:
+ break;
+ case Opcodes.ACONST_NULL:
+ push(NULL);
+ break;
+ case Opcodes.ICONST_M1:
+ case Opcodes.ICONST_0:
+ case Opcodes.ICONST_1:
+ case Opcodes.ICONST_2:
+ case Opcodes.ICONST_3:
+ case Opcodes.ICONST_4:
+ case Opcodes.ICONST_5:
+ case Opcodes.BIPUSH:
+ case Opcodes.SIPUSH:
+ case Opcodes.ILOAD:
+ push(INTEGER);
+ break;
+ case Opcodes.LCONST_0:
+ case Opcodes.LCONST_1:
+ case Opcodes.LLOAD:
+ push(LONG);
+ push(TOP);
+ break;
+ case Opcodes.FCONST_0:
+ case Opcodes.FCONST_1:
+ case Opcodes.FCONST_2:
+ case Opcodes.FLOAD:
+ push(FLOAT);
+ break;
+ case Opcodes.DCONST_0:
+ case Opcodes.DCONST_1:
+ case Opcodes.DLOAD:
+ push(DOUBLE);
+ push(TOP);
+ break;
+ case Opcodes.LDC:
+ switch (item.type) {
+ case ClassWriter.INT:
push(INTEGER);
break;
- case Opcodes.LCONST_0:
- case Opcodes.LCONST_1:
- case Opcodes.LLOAD:
+ case ClassWriter.LONG:
push(LONG);
push(TOP);
break;
- case Opcodes.FCONST_0:
- case Opcodes.FCONST_1:
- case Opcodes.FCONST_2:
- case Opcodes.FLOAD:
+ case ClassWriter.FLOAT:
push(FLOAT);
break;
- case Opcodes.DCONST_0:
- case Opcodes.DCONST_1:
- case Opcodes.DLOAD:
+ case ClassWriter.DOUBLE:
push(DOUBLE);
push(TOP);
break;
- case Opcodes.LDC:
- switch (item.type) {
- case ClassWriter.INT:
- push(INTEGER);
- break;
- case ClassWriter.LONG:
- push(LONG);
- push(TOP);
- break;
- case ClassWriter.FLOAT:
- push(FLOAT);
- break;
- case ClassWriter.DOUBLE:
- push(DOUBLE);
- push(TOP);
- break;
- case ClassWriter.CLASS:
- push(OBJECT | cw.addType("java/lang/Class"));
- break;
- case ClassWriter.STR:
- push(OBJECT | cw.addType("java/lang/String"));
- break;
- case ClassWriter.MTYPE:
- push(OBJECT | cw.addType("java/lang/invoke/MethodType"));
- break;
- // case ClassWriter.HANDLE_BASE + [1..9]:
- default:
- push(OBJECT | cw.addType("java/lang/invoke/MethodHandle"));
- }
- break;
- case Opcodes.ALOAD:
- push(get(arg));
- break;
- case Opcodes.IALOAD:
- case Opcodes.BALOAD:
- case Opcodes.CALOAD:
- case Opcodes.SALOAD:
- pop(2);
- push(INTEGER);
- break;
- case Opcodes.LALOAD:
- case Opcodes.D2L:
- pop(2);
- push(LONG);
- push(TOP);
+ case ClassWriter.CLASS:
+ push(OBJECT | cw.addType("java/lang/Class"));
break;
- case Opcodes.FALOAD:
- pop(2);
- push(FLOAT);
+ case ClassWriter.STR:
+ push(OBJECT | cw.addType("java/lang/String"));
break;
- case Opcodes.DALOAD:
- case Opcodes.L2D:
- pop(2);
- push(DOUBLE);
- push(TOP);
+ case ClassWriter.MTYPE:
+ push(OBJECT | cw.addType("java/lang/invoke/MethodType"));
break;
- case Opcodes.AALOAD:
- pop(1);
- t1 = pop();
- push(ELEMENT_OF + t1);
- break;
- case Opcodes.ISTORE:
- case Opcodes.FSTORE:
- case Opcodes.ASTORE:
- t1 = pop();
- set(arg, t1);
- if (arg > 0) {
- t2 = get(arg - 1);
- // if t2 is of kind STACK or LOCAL we cannot know its size!
- if (t2 == LONG || t2 == DOUBLE) {
- set(arg - 1, TOP);
- } else if ((t2 & KIND) != BASE) {
- set(arg - 1, t2 | TOP_IF_LONG_OR_DOUBLE);
- }
+ // case ClassWriter.HANDLE_BASE + [1..9]:
+ default:
+ push(OBJECT | cw.addType("java/lang/invoke/MethodHandle"));
+ }
+ break;
+ case Opcodes.ALOAD:
+ push(get(arg));
+ break;
+ case Opcodes.IALOAD:
+ case Opcodes.BALOAD:
+ case Opcodes.CALOAD:
+ case Opcodes.SALOAD:
+ pop(2);
+ push(INTEGER);
+ break;
+ case Opcodes.LALOAD:
+ case Opcodes.D2L:
+ pop(2);
+ push(LONG);
+ push(TOP);
+ break;
+ case Opcodes.FALOAD:
+ pop(2);
+ push(FLOAT);
+ break;
+ case Opcodes.DALOAD:
+ case Opcodes.L2D:
+ pop(2);
+ push(DOUBLE);
+ push(TOP);
+ break;
+ case Opcodes.AALOAD:
+ pop(1);
+ t1 = pop();
+ push(ELEMENT_OF + t1);
+ break;
+ case Opcodes.ISTORE:
+ case Opcodes.FSTORE:
+ case Opcodes.ASTORE:
+ t1 = pop();
+ set(arg, t1);
+ if (arg > 0) {
+ t2 = get(arg - 1);
+ // if t2 is of kind STACK or LOCAL we cannot know its size!
+ if (t2 == LONG || t2 == DOUBLE) {
+ set(arg - 1, TOP);
+ } else if ((t2 & KIND) != BASE) {
+ set(arg - 1, t2 | TOP_IF_LONG_OR_DOUBLE);
}
- break;
- case Opcodes.LSTORE:
- case Opcodes.DSTORE:
- pop(1);
- t1 = pop();
- set(arg, t1);
- set(arg + 1, TOP);
- if (arg > 0) {
- t2 = get(arg - 1);
- // if t2 is of kind STACK or LOCAL we cannot know its size!
- if (t2 == LONG || t2 == DOUBLE) {
- set(arg - 1, TOP);
- } else if ((t2 & KIND) != BASE) {
- set(arg - 1, t2 | TOP_IF_LONG_OR_DOUBLE);
- }
+ }
+ break;
+ case Opcodes.LSTORE:
+ case Opcodes.DSTORE:
+ pop(1);
+ t1 = pop();
+ set(arg, t1);
+ set(arg + 1, TOP);
+ if (arg > 0) {
+ t2 = get(arg - 1);
+ // if t2 is of kind STACK or LOCAL we cannot know its size!
+ if (t2 == LONG || t2 == DOUBLE) {
+ set(arg - 1, TOP);
+ } else if ((t2 & KIND) != BASE) {
+ set(arg - 1, t2 | TOP_IF_LONG_OR_DOUBLE);
}
- break;
- case Opcodes.IASTORE:
- case Opcodes.BASTORE:
- case Opcodes.CASTORE:
- case Opcodes.SASTORE:
- case Opcodes.FASTORE:
- case Opcodes.AASTORE:
- pop(3);
- break;
- case Opcodes.LASTORE:
- case Opcodes.DASTORE:
- pop(4);
- break;
- case Opcodes.POP:
- case Opcodes.IFEQ:
- case Opcodes.IFNE:
- case Opcodes.IFLT:
- case Opcodes.IFGE:
- case Opcodes.IFGT:
- case Opcodes.IFLE:
- case Opcodes.IRETURN:
- case Opcodes.FRETURN:
- case Opcodes.ARETURN:
- case Opcodes.TABLESWITCH:
- case Opcodes.LOOKUPSWITCH:
- case Opcodes.ATHROW:
- case Opcodes.MONITORENTER:
- case Opcodes.MONITOREXIT:
- case Opcodes.IFNULL:
- case Opcodes.IFNONNULL:
- pop(1);
- break;
- case Opcodes.POP2:
- case Opcodes.IF_ICMPEQ:
- case Opcodes.IF_ICMPNE:
- case Opcodes.IF_ICMPLT:
- case Opcodes.IF_ICMPGE:
- case Opcodes.IF_ICMPGT:
- case Opcodes.IF_ICMPLE:
- case Opcodes.IF_ACMPEQ:
- case Opcodes.IF_ACMPNE:
- case Opcodes.LRETURN:
- case Opcodes.DRETURN:
- pop(2);
- break;
- case Opcodes.DUP:
- t1 = pop();
- push(t1);
- push(t1);
- break;
- case Opcodes.DUP_X1:
- t1 = pop();
- t2 = pop();
- push(t1);
- push(t2);
- push(t1);
- break;
- case Opcodes.DUP_X2:
- t1 = pop();
- t2 = pop();
- t3 = pop();
- push(t1);
- push(t3);
- push(t2);
- push(t1);
- break;
- case Opcodes.DUP2:
- t1 = pop();
- t2 = pop();
- push(t2);
- push(t1);
- push(t2);
- push(t1);
- break;
- case Opcodes.DUP2_X1:
- t1 = pop();
- t2 = pop();
- t3 = pop();
- push(t2);
- push(t1);
- push(t3);
- push(t2);
- push(t1);
- break;
- case Opcodes.DUP2_X2:
- t1 = pop();
- t2 = pop();
- t3 = pop();
- t4 = pop();
- push(t2);
- push(t1);
- push(t4);
- push(t3);
- push(t2);
- push(t1);
- break;
- case Opcodes.SWAP:
+ }
+ break;
+ case Opcodes.IASTORE:
+ case Opcodes.BASTORE:
+ case Opcodes.CASTORE:
+ case Opcodes.SASTORE:
+ case Opcodes.FASTORE:
+ case Opcodes.AASTORE:
+ pop(3);
+ break;
+ case Opcodes.LASTORE:
+ case Opcodes.DASTORE:
+ pop(4);
+ break;
+ case Opcodes.POP:
+ case Opcodes.IFEQ:
+ case Opcodes.IFNE:
+ case Opcodes.IFLT:
+ case Opcodes.IFGE:
+ case Opcodes.IFGT:
+ case Opcodes.IFLE:
+ case Opcodes.IRETURN:
+ case Opcodes.FRETURN:
+ case Opcodes.ARETURN:
+ case Opcodes.TABLESWITCH:
+ case Opcodes.LOOKUPSWITCH:
+ case Opcodes.ATHROW:
+ case Opcodes.MONITORENTER:
+ case Opcodes.MONITOREXIT:
+ case Opcodes.IFNULL:
+ case Opcodes.IFNONNULL:
+ pop(1);
+ break;
+ case Opcodes.POP2:
+ case Opcodes.IF_ICMPEQ:
+ case Opcodes.IF_ICMPNE:
+ case Opcodes.IF_ICMPLT:
+ case Opcodes.IF_ICMPGE:
+ case Opcodes.IF_ICMPGT:
+ case Opcodes.IF_ICMPLE:
+ case Opcodes.IF_ACMPEQ:
+ case Opcodes.IF_ACMPNE:
+ case Opcodes.LRETURN:
+ case Opcodes.DRETURN:
+ pop(2);
+ break;
+ case Opcodes.DUP:
+ t1 = pop();
+ push(t1);
+ push(t1);
+ break;
+ case Opcodes.DUP_X1:
+ t1 = pop();
+ t2 = pop();
+ push(t1);
+ push(t2);
+ push(t1);
+ break;
+ case Opcodes.DUP_X2:
+ t1 = pop();
+ t2 = pop();
+ t3 = pop();
+ push(t1);
+ push(t3);
+ push(t2);
+ push(t1);
+ break;
+ case Opcodes.DUP2:
+ t1 = pop();
+ t2 = pop();
+ push(t2);
+ push(t1);
+ push(t2);
+ push(t1);
+ break;
+ case Opcodes.DUP2_X1:
+ t1 = pop();
+ t2 = pop();
+ t3 = pop();
+ push(t2);
+ push(t1);
+ push(t3);
+ push(t2);
+ push(t1);
+ break;
+ case Opcodes.DUP2_X2:
+ t1 = pop();
+ t2 = pop();
+ t3 = pop();
+ t4 = pop();
+ push(t2);
+ push(t1);
+ push(t4);
+ push(t3);
+ push(t2);
+ push(t1);
+ break;
+ case Opcodes.SWAP:
+ t1 = pop();
+ t2 = pop();
+ push(t1);
+ push(t2);
+ break;
+ case Opcodes.IADD:
+ case Opcodes.ISUB:
+ case Opcodes.IMUL:
+ case Opcodes.IDIV:
+ case Opcodes.IREM:
+ case Opcodes.IAND:
+ case Opcodes.IOR:
+ case Opcodes.IXOR:
+ case Opcodes.ISHL:
+ case Opcodes.ISHR:
+ case Opcodes.IUSHR:
+ case Opcodes.L2I:
+ case Opcodes.D2I:
+ case Opcodes.FCMPL:
+ case Opcodes.FCMPG:
+ pop(2);
+ push(INTEGER);
+ break;
+ case Opcodes.LADD:
+ case Opcodes.LSUB:
+ case Opcodes.LMUL:
+ case Opcodes.LDIV:
+ case Opcodes.LREM:
+ case Opcodes.LAND:
+ case Opcodes.LOR:
+ case Opcodes.LXOR:
+ pop(4);
+ push(LONG);
+ push(TOP);
+ break;
+ case Opcodes.FADD:
+ case Opcodes.FSUB:
+ case Opcodes.FMUL:
+ case Opcodes.FDIV:
+ case Opcodes.FREM:
+ case Opcodes.L2F:
+ case Opcodes.D2F:
+ pop(2);
+ push(FLOAT);
+ break;
+ case Opcodes.DADD:
+ case Opcodes.DSUB:
+ case Opcodes.DMUL:
+ case Opcodes.DDIV:
+ case Opcodes.DREM:
+ pop(4);
+ push(DOUBLE);
+ push(TOP);
+ break;
+ case Opcodes.LSHL:
+ case Opcodes.LSHR:
+ case Opcodes.LUSHR:
+ pop(3);
+ push(LONG);
+ push(TOP);
+ break;
+ case Opcodes.IINC:
+ set(arg, INTEGER);
+ break;
+ case Opcodes.I2L:
+ case Opcodes.F2L:
+ pop(1);
+ push(LONG);
+ push(TOP);
+ break;
+ case Opcodes.I2F:
+ pop(1);
+ push(FLOAT);
+ break;
+ case Opcodes.I2D:
+ case Opcodes.F2D:
+ pop(1);
+ push(DOUBLE);
+ push(TOP);
+ break;
+ case Opcodes.F2I:
+ case Opcodes.ARRAYLENGTH:
+ case Opcodes.INSTANCEOF:
+ pop(1);
+ push(INTEGER);
+ break;
+ case Opcodes.LCMP:
+ case Opcodes.DCMPL:
+ case Opcodes.DCMPG:
+ pop(4);
+ push(INTEGER);
+ break;
+ case Opcodes.JSR:
+ case Opcodes.RET:
+ throw new RuntimeException(
+ "JSR/RET are not supported with computeFrames option");
+ case Opcodes.GETSTATIC:
+ push(cw, item.strVal3);
+ break;
+ case Opcodes.PUTSTATIC:
+ pop(item.strVal3);
+ break;
+ case Opcodes.GETFIELD:
+ pop(1);
+ push(cw, item.strVal3);
+ break;
+ case Opcodes.PUTFIELD:
+ pop(item.strVal3);
+ pop();
+ break;
+ case Opcodes.INVOKEVIRTUAL:
+ case Opcodes.INVOKESPECIAL:
+ case Opcodes.INVOKESTATIC:
+ case Opcodes.INVOKEINTERFACE:
+ pop(item.strVal3);
+ if (opcode != Opcodes.INVOKESTATIC) {
t1 = pop();
- t2 = pop();
- push(t1);
- push(t2);
- break;
- case Opcodes.IADD:
- case Opcodes.ISUB:
- case Opcodes.IMUL:
- case Opcodes.IDIV:
- case Opcodes.IREM:
- case Opcodes.IAND:
- case Opcodes.IOR:
- case Opcodes.IXOR:
- case Opcodes.ISHL:
- case Opcodes.ISHR:
- case Opcodes.IUSHR:
- case Opcodes.L2I:
- case Opcodes.D2I:
- case Opcodes.FCMPL:
- case Opcodes.FCMPG:
- pop(2);
- push(INTEGER);
- break;
- case Opcodes.LADD:
- case Opcodes.LSUB:
- case Opcodes.LMUL:
- case Opcodes.LDIV:
- case Opcodes.LREM:
- case Opcodes.LAND:
- case Opcodes.LOR:
- case Opcodes.LXOR:
- pop(4);
- push(LONG);
- push(TOP);
- break;
- case Opcodes.FADD:
- case Opcodes.FSUB:
- case Opcodes.FMUL:
- case Opcodes.FDIV:
- case Opcodes.FREM:
- case Opcodes.L2F:
- case Opcodes.D2F:
- pop(2);
- push(FLOAT);
- break;
- case Opcodes.DADD:
- case Opcodes.DSUB:
- case Opcodes.DMUL:
- case Opcodes.DDIV:
- case Opcodes.DREM:
- pop(4);
- push(DOUBLE);
- push(TOP);
- break;
- case Opcodes.LSHL:
- case Opcodes.LSHR:
- case Opcodes.LUSHR:
- pop(3);
- push(LONG);
- push(TOP);
- break;
- case Opcodes.IINC:
- set(arg, INTEGER);
- break;
- case Opcodes.I2L:
- case Opcodes.F2L:
- pop(1);
- push(LONG);
- push(TOP);
- break;
- case Opcodes.I2F:
- pop(1);
- push(FLOAT);
- break;
- case Opcodes.I2D:
- case Opcodes.F2D:
- pop(1);
- push(DOUBLE);
- push(TOP);
- break;
- case Opcodes.F2I:
- case Opcodes.ARRAYLENGTH:
- case Opcodes.INSTANCEOF:
- pop(1);
- push(INTEGER);
- break;
- case Opcodes.LCMP:
- case Opcodes.DCMPL:
- case Opcodes.DCMPG:
- pop(4);
- push(INTEGER);
- break;
- case Opcodes.JSR:
- case Opcodes.RET:
- throw new RuntimeException("JSR/RET are not supported with computeFrames option");
- case Opcodes.GETSTATIC:
- push(cw, item.strVal3);
- break;
- case Opcodes.PUTSTATIC:
- pop(item.strVal3);
- break;
- case Opcodes.GETFIELD:
- pop(1);
- push(cw, item.strVal3);
- break;
- case Opcodes.PUTFIELD:
- pop(item.strVal3);
- pop();
- break;
- case Opcodes.INVOKEVIRTUAL:
- case Opcodes.INVOKESPECIAL:
- case Opcodes.INVOKESTATIC:
- case Opcodes.INVOKEINTERFACE:
- pop(item.strVal3);
- if (opcode != Opcodes.INVOKESTATIC) {
- t1 = pop();
- if (opcode == Opcodes.INVOKESPECIAL
- && item.strVal2.charAt(0) == '<')
- {
- init(t1);
- }
+ if (opcode == Opcodes.INVOKESPECIAL
+ && item.strVal2.charAt(0) == '<') {
+ init(t1);
}
- push(cw, item.strVal3);
+ }
+ push(cw, item.strVal3);
+ break;
+ case Opcodes.INVOKEDYNAMIC:
+ pop(item.strVal2);
+ push(cw, item.strVal2);
+ break;
+ case Opcodes.NEW:
+ push(UNINITIALIZED | cw.addUninitializedType(item.strVal1, arg));
+ break;
+ case Opcodes.NEWARRAY:
+ pop();
+ switch (arg) {
+ case Opcodes.T_BOOLEAN:
+ push(ARRAY_OF | BOOLEAN);
break;
- case Opcodes.INVOKEDYNAMIC:
- pop(item.strVal2);
- push(cw, item.strVal2);
+ case Opcodes.T_CHAR:
+ push(ARRAY_OF | CHAR);
break;
- case Opcodes.NEW:
- push(UNINITIALIZED | cw.addUninitializedType(item.strVal1, arg));
+ case Opcodes.T_BYTE:
+ push(ARRAY_OF | BYTE);
break;
- case Opcodes.NEWARRAY:
- pop();
- switch (arg) {
- case Opcodes.T_BOOLEAN:
- push(ARRAY_OF | BOOLEAN);
- break;
- case Opcodes.T_CHAR:
- push(ARRAY_OF | CHAR);
- break;
- case Opcodes.T_BYTE:
- push(ARRAY_OF | BYTE);
- break;
- case Opcodes.T_SHORT:
- push(ARRAY_OF | SHORT);
- break;
- case Opcodes.T_INT:
- push(ARRAY_OF | INTEGER);
- break;
- case Opcodes.T_FLOAT:
- push(ARRAY_OF | FLOAT);
- break;
- case Opcodes.T_DOUBLE:
- push(ARRAY_OF | DOUBLE);
- break;
- // case Opcodes.T_LONG:
- default:
- push(ARRAY_OF | LONG);
- break;
- }
+ case Opcodes.T_SHORT:
+ push(ARRAY_OF | SHORT);
break;
- case Opcodes.ANEWARRAY:
- String s = item.strVal1;
- pop();
- if (s.charAt(0) == '[') {
- push(cw, '[' + s);
- } else {
- push(ARRAY_OF | OBJECT | cw.addType(s));
- }
+ case Opcodes.T_INT:
+ push(ARRAY_OF | INTEGER);
break;
- case Opcodes.CHECKCAST:
- s = item.strVal1;
- pop();
- if (s.charAt(0) == '[') {
- push(cw, s);
- } else {
- push(OBJECT | cw.addType(s));
- }
+ case Opcodes.T_FLOAT:
+ push(ARRAY_OF | FLOAT);
break;
- // case Opcodes.MULTIANEWARRAY:
+ case Opcodes.T_DOUBLE:
+ push(ARRAY_OF | DOUBLE);
+ break;
+ // case Opcodes.T_LONG:
default:
- pop(arg);
- push(cw, item.strVal1);
+ push(ARRAY_OF | LONG);
break;
+ }
+ break;
+ case Opcodes.ANEWARRAY:
+ String s = item.strVal1;
+ pop();
+ if (s.charAt(0) == '[') {
+ push(cw, '[' + s);
+ } else {
+ push(ARRAY_OF | OBJECT | cw.addType(s));
+ }
+ break;
+ case Opcodes.CHECKCAST:
+ s = item.strVal1;
+ pop();
+ if (s.charAt(0) == '[') {
+ push(cw, s);
+ } else {
+ push(OBJECT | cw.addType(s));
+ }
+ break;
+ // case Opcodes.MULTIANEWARRAY:
+ default:
+ pop(arg);
+ push(cw, item.strVal1);
+ break;
}
}
@@ -1260,10 +1273,13 @@ final class Frame {
* frames of this basic block. Returns <tt>true</tt> if the input frame of
* the given label has been changed by this operation.
*
- * @param cw the ClassWriter to which this label belongs.
- * @param frame the basic block whose input frame must be updated.
- * @param edge the kind of the {@link Edge} between this label and 'label'.
- * See {@link Edge#info}.
+ * @param cw
+ * the ClassWriter to which this label belongs.
+ * @param frame
+ * the basic block whose input frame must be updated.
+ * @param edge
+ * the kind of the {@link Edge} between this label and 'label'.
+ * See {@link Edge#info}.
* @return <tt>true</tt> if the input frame of the given label has been
* changed by this operation.
*/
@@ -1294,7 +1310,8 @@ final class Frame {
} else {
t = dim + inputStack[nStack - (s & VALUE)];
}
- if ((s & TOP_IF_LONG_OR_DOUBLE) != 0 && (t == LONG || t == DOUBLE)) {
+ if ((s & TOP_IF_LONG_OR_DOUBLE) != 0
+ && (t == LONG || t == DOUBLE)) {
t = TOP;
}
}
@@ -1346,7 +1363,8 @@ final class Frame {
} else {
t = dim + inputStack[nStack - (s & VALUE)];
}
- if ((s & TOP_IF_LONG_OR_DOUBLE) != 0 && (t == LONG || t == DOUBLE)) {
+ if ((s & TOP_IF_LONG_OR_DOUBLE) != 0
+ && (t == LONG || t == DOUBLE)) {
t = TOP;
}
}
@@ -1363,19 +1381,19 @@ final class Frame {
* type. Returns <tt>true</tt> if the type array has been modified by this
* operation.
*
- * @param cw the ClassWriter to which this label belongs.
- * @param t the type with which the type array element must be merged.
- * @param types an array of types.
- * @param index the index of the type that must be merged in 'types'.
+ * @param cw
+ * the ClassWriter to which this label belongs.
+ * @param t
+ * the type with which the type array element must be merged.
+ * @param types
+ * an array of types.
+ * @param index
+ * the index of the type that must be merged in 'types'.
* @return <tt>true</tt> if the type array has been modified by this
* operation.
*/
- private static boolean merge(
- final ClassWriter cw,
- int t,
- final int[] types,
- final int index)
- {
+ private static boolean merge(final ClassWriter cw, int t,
+ final int[] types, final int index) {
int u = types[index];
if (u == t) {
// if the types are equal, merge(u,t)=u, so there is no change
diff --git a/src/asm/scala/tools/asm/Handle.java b/src/asm/scala/tools/asm/Handle.java
index be8f334192..5dd06a54b9 100644
--- a/src/asm/scala/tools/asm/Handle.java
+++ b/src/asm/scala/tools/asm/Handle.java
@@ -66,18 +66,23 @@ public final class Handle {
/**
* Constructs a new field or method handle.
*
- * @param tag the kind of field or method designated by this Handle. Must be
- * {@link Opcodes#H_GETFIELD}, {@link Opcodes#H_GETSTATIC},
- * {@link Opcodes#H_PUTFIELD}, {@link Opcodes#H_PUTSTATIC},
- * {@link Opcodes#H_INVOKEVIRTUAL}, {@link Opcodes#H_INVOKESTATIC},
- * {@link Opcodes#H_INVOKESPECIAL},
- * {@link Opcodes#H_NEWINVOKESPECIAL} or
- * {@link Opcodes#H_INVOKEINTERFACE}.
- * @param owner the internal name of the field or method designed by this
- * handle.
- * @param name the name of the field or method designated by this handle.
- * @param desc the descriptor of the field or method designated by this
- * handle.
+ * @param tag
+ * the kind of field or method designated by this Handle. Must be
+ * {@link Opcodes#H_GETFIELD}, {@link Opcodes#H_GETSTATIC},
+ * {@link Opcodes#H_PUTFIELD}, {@link Opcodes#H_PUTSTATIC},
+ * {@link Opcodes#H_INVOKEVIRTUAL},
+ * {@link Opcodes#H_INVOKESTATIC},
+ * {@link Opcodes#H_INVOKESPECIAL},
+ * {@link Opcodes#H_NEWINVOKESPECIAL} or
+ * {@link Opcodes#H_INVOKEINTERFACE}.
+ * @param owner
+ * the internal name of the field or method designed by this
+ * handle.
+ * @param name
+ * the name of the field or method designated by this handle.
+ * @param desc
+ * the descriptor of the field or method designated by this
+ * handle.
*/
public Handle(int tag, String owner, String name, String desc) {
this.tag = tag;
@@ -101,11 +106,9 @@ public final class Handle {
}
/**
- * Returns the internal name of the field or method designed by this
- * handle.
+ * Returns the internal name of the field or method designed by this handle.
*
- * @return the internal name of the field or method designed by this
- * handle.
+ * @return the internal name of the field or method designed by this handle.
*/
public String getOwner() {
return owner;
@@ -138,8 +141,8 @@ public final class Handle {
return false;
}
Handle h = (Handle) obj;
- return tag == h.tag && owner.equals(h.owner)
- && name.equals(h.name) && desc.equals(h.desc);
+ return tag == h.tag && owner.equals(h.owner) && name.equals(h.name)
+ && desc.equals(h.desc);
}
@Override
@@ -149,8 +152,13 @@ public final class Handle {
/**
* Returns the textual representation of this handle. The textual
- * representation is: <pre>owner '.' name desc ' ' '(' tag ')'</pre>. As
- * this format is unambiguous, it can be parsed if necessary.
+ * representation is:
+ *
+ * <pre>
+ * owner '.' name desc ' ' '(' tag ')'
+ * </pre>
+ *
+ * . As this format is unambiguous, it can be parsed if necessary.
*/
@Override
public String toString() {
diff --git a/src/asm/scala/tools/asm/Handler.java b/src/asm/scala/tools/asm/Handler.java
index 9e92bb98be..a06cb8152a 100644
--- a/src/asm/scala/tools/asm/Handler.java
+++ b/src/asm/scala/tools/asm/Handler.java
@@ -72,9 +72,12 @@ class Handler {
* Removes the range between start and end from the given exception
* handlers.
*
- * @param h an exception handler list.
- * @param start the start of the range to be removed.
- * @param end the end of the range to be removed. Maybe null.
+ * @param h
+ * an exception handler list.
+ * @param start
+ * the start of the range to be removed.
+ * @param end
+ * the end of the range to be removed. Maybe null.
* @return the exception handler list with the start-end range removed.
*/
static Handler remove(Handler h, Label start, Label end) {
diff --git a/src/asm/scala/tools/asm/Item.java b/src/asm/scala/tools/asm/Item.java
index 021a0b11d3..94195a1082 100644
--- a/src/asm/scala/tools/asm/Item.java
+++ b/src/asm/scala/tools/asm/Item.java
@@ -53,8 +53,8 @@ final class Item {
* {@link ClassWriter#METH}, {@link ClassWriter#IMETH},
* {@link ClassWriter#MTYPE}, {@link ClassWriter#INDY}.
*
- * MethodHandle constant 9 variations are stored using a range
- * of 9 values from {@link ClassWriter#HANDLE_BASE} + 1 to
+ * MethodHandle constant 9 variations are stored using a range of 9 values
+ * from {@link ClassWriter#HANDLE_BASE} + 1 to
* {@link ClassWriter#HANDLE_BASE} + 9.
*
* Special Item types are used for Items that are stored in the ClassWriter
@@ -115,7 +115,8 @@ final class Item {
* Constructs an uninitialized {@link Item} for constant pool element at
* given position.
*
- * @param index index of the item to be constructed.
+ * @param index
+ * index of the item to be constructed.
*/
Item(final int index) {
this.index = index;
@@ -124,8 +125,10 @@ final class Item {
/**
* Constructs a copy of the given item.
*
- * @param index index of the item to be constructed.
- * @param i the item that must be copied into the item to be constructed.
+ * @param index
+ * index of the item to be constructed.
+ * @param i
+ * the item that must be copied into the item to be constructed.
*/
Item(final int index, final Item i) {
this.index = index;
@@ -141,7 +144,8 @@ final class Item {
/**
* Sets this item to an integer item.
*
- * @param intVal the value of this item.
+ * @param intVal
+ * the value of this item.
*/
void set(final int intVal) {
this.type = ClassWriter.INT;
@@ -152,7 +156,8 @@ final class Item {
/**
* Sets this item to a long item.
*
- * @param longVal the value of this item.
+ * @param longVal
+ * the value of this item.
*/
void set(final long longVal) {
this.type = ClassWriter.LONG;
@@ -163,7 +168,8 @@ final class Item {
/**
* Sets this item to a float item.
*
- * @param floatVal the value of this item.
+ * @param floatVal
+ * the value of this item.
*/
void set(final float floatVal) {
this.type = ClassWriter.FLOAT;
@@ -174,7 +180,8 @@ final class Item {
/**
* Sets this item to a double item.
*
- * @param doubleVal the value of this item.
+ * @param doubleVal
+ * the value of this item.
*/
void set(final double doubleVal) {
this.type = ClassWriter.DOUBLE;
@@ -185,49 +192,53 @@ final class Item {
/**
* Sets this item to an item that do not hold a primitive value.
*
- * @param type the type of this item.
- * @param strVal1 first part of the value of this item.
- * @param strVal2 second part of the value of this item.
- * @param strVal3 third part of the value of this item.
+ * @param type
+ * the type of this item.
+ * @param strVal1
+ * first part of the value of this item.
+ * @param strVal2
+ * second part of the value of this item.
+ * @param strVal3
+ * third part of the value of this item.
*/
- void set(
- final int type,
- final String strVal1,
- final String strVal2,
- final String strVal3)
- {
+ void set(final int type, final String strVal1, final String strVal2,
+ final String strVal3) {
this.type = type;
this.strVal1 = strVal1;
this.strVal2 = strVal2;
this.strVal3 = strVal3;
switch (type) {
- case ClassWriter.UTF8:
- case ClassWriter.STR:
- case ClassWriter.CLASS:
- case ClassWriter.MTYPE:
- case ClassWriter.TYPE_NORMAL:
- hashCode = 0x7FFFFFFF & (type + strVal1.hashCode());
- return;
- case ClassWriter.NAME_TYPE:
- hashCode = 0x7FFFFFFF & (type + strVal1.hashCode()
- * strVal2.hashCode());
- return;
- // ClassWriter.FIELD:
- // ClassWriter.METH:
- // ClassWriter.IMETH:
- // ClassWriter.HANDLE_BASE + 1..9
- default:
- hashCode = 0x7FFFFFFF & (type + strVal1.hashCode()
- * strVal2.hashCode() * strVal3.hashCode());
+ case ClassWriter.UTF8:
+ case ClassWriter.STR:
+ case ClassWriter.CLASS:
+ case ClassWriter.MTYPE:
+ case ClassWriter.TYPE_NORMAL:
+ hashCode = 0x7FFFFFFF & (type + strVal1.hashCode());
+ return;
+ case ClassWriter.NAME_TYPE: {
+ hashCode = 0x7FFFFFFF & (type + strVal1.hashCode()
+ * strVal2.hashCode());
+ return;
+ }
+ // ClassWriter.FIELD:
+ // ClassWriter.METH:
+ // ClassWriter.IMETH:
+ // ClassWriter.HANDLE_BASE + 1..9
+ default:
+ hashCode = 0x7FFFFFFF & (type + strVal1.hashCode()
+ * strVal2.hashCode() * strVal3.hashCode());
}
}
/**
* Sets the item to an InvokeDynamic item.
*
- * @param name invokedynamic's name.
- * @param desc invokedynamic's desc.
- * @param bsmIndex zero based index into the class attribute BootrapMethods.
+ * @param name
+ * invokedynamic's name.
+ * @param desc
+ * invokedynamic's desc.
+ * @param bsmIndex
+ * zero based index into the class attribute BootrapMethods.
*/
void set(String name, String desc, int bsmIndex) {
this.type = ClassWriter.INDY;
@@ -241,10 +252,12 @@ final class Item {
/**
* Sets the item to a BootstrapMethod item.
*
- * @param position position in byte in the class attribute BootrapMethods.
- * @param hashCode hashcode of the item. This hashcode is processed from
- * the hashcode of the bootstrap method and the hashcode of
- * all bootstrap arguments.
+ * @param position
+ * position in byte in the class attribute BootrapMethods.
+ * @param hashCode
+ * hashcode of the item. This hashcode is processed from the
+ * hashcode of the bootstrap method and the hashcode of all
+ * bootstrap arguments.
*/
void set(int position, int hashCode) {
this.type = ClassWriter.BSM;
@@ -256,41 +269,42 @@ final class Item {
* Indicates if the given item is equal to this one. <i>This method assumes
* that the two items have the same {@link #type}</i>.
*
- * @param i the item to be compared to this one. Both items must have the
- * same {@link #type}.
+ * @param i
+ * the item to be compared to this one. Both items must have the
+ * same {@link #type}.
* @return <tt>true</tt> if the given item if equal to this one,
* <tt>false</tt> otherwise.
*/
boolean isEqualTo(final Item i) {
switch (type) {
- case ClassWriter.UTF8:
- case ClassWriter.STR:
- case ClassWriter.CLASS:
- case ClassWriter.MTYPE:
- case ClassWriter.TYPE_NORMAL:
- return i.strVal1.equals(strVal1);
- case ClassWriter.TYPE_MERGED:
- case ClassWriter.LONG:
- case ClassWriter.DOUBLE:
- return i.longVal == longVal;
- case ClassWriter.INT:
- case ClassWriter.FLOAT:
- return i.intVal == intVal;
- case ClassWriter.TYPE_UNINIT:
- return i.intVal == intVal && i.strVal1.equals(strVal1);
- case ClassWriter.NAME_TYPE:
- return i.strVal1.equals(strVal1) && i.strVal2.equals(strVal2);
- case ClassWriter.INDY:
- return i.longVal == longVal && i.strVal1.equals(strVal1)
- && i.strVal2.equals(strVal2);
-
- // case ClassWriter.FIELD:
- // case ClassWriter.METH:
- // case ClassWriter.IMETH:
- // case ClassWriter.HANDLE_BASE + 1..9
- default:
- return i.strVal1.equals(strVal1) && i.strVal2.equals(strVal2)
- && i.strVal3.equals(strVal3);
+ case ClassWriter.UTF8:
+ case ClassWriter.STR:
+ case ClassWriter.CLASS:
+ case ClassWriter.MTYPE:
+ case ClassWriter.TYPE_NORMAL:
+ return i.strVal1.equals(strVal1);
+ case ClassWriter.TYPE_MERGED:
+ case ClassWriter.LONG:
+ case ClassWriter.DOUBLE:
+ return i.longVal == longVal;
+ case ClassWriter.INT:
+ case ClassWriter.FLOAT:
+ return i.intVal == intVal;
+ case ClassWriter.TYPE_UNINIT:
+ return i.intVal == intVal && i.strVal1.equals(strVal1);
+ case ClassWriter.NAME_TYPE:
+ return i.strVal1.equals(strVal1) && i.strVal2.equals(strVal2);
+ case ClassWriter.INDY: {
+ return i.longVal == longVal && i.strVal1.equals(strVal1)
+ && i.strVal2.equals(strVal2);
+ }
+ // case ClassWriter.FIELD:
+ // case ClassWriter.METH:
+ // case ClassWriter.IMETH:
+ // case ClassWriter.HANDLE_BASE + 1..9
+ default:
+ return i.strVal1.equals(strVal1) && i.strVal2.equals(strVal2)
+ && i.strVal3.equals(strVal3);
}
}
diff --git a/src/asm/scala/tools/asm/Label.java b/src/asm/scala/tools/asm/Label.java
index 712c7f251f..5d5529ce74 100644
--- a/src/asm/scala/tools/asm/Label.java
+++ b/src/asm/scala/tools/asm/Label.java
@@ -32,9 +32,9 @@ package scala.tools.asm;
/**
* A label represents a position in the bytecode of a method. Labels are used
* for jump, goto, and switch instructions, and for try catch blocks. A label
- * designates the <i>instruction</i> that is just after. Note however that
- * there can be other elements between a label and the instruction it
- * designates (such as other labels, stack map frames, line numbers, etc.).
+ * designates the <i>instruction</i> that is just after. Note however that there
+ * can be other elements between a label and the instruction it designates (such
+ * as other labels, stack map frames, line numbers, etc.).
*
* @author Eric Bruneton
*/
@@ -110,8 +110,8 @@ public class Label {
/**
* Field used to associate user information to a label. Warning: this field
* is used by the ASM tree package. In order to use it with the ASM tree
- * package you must override the {@link
- * org.objectweb.asm.tree.MethodNode#getLabelNode} method.
+ * package you must override the
+ * {@link scala.tools.asm.tree.MethodNode#getLabelNode} method.
*/
public Object info;
@@ -154,7 +154,7 @@ public class Label {
* indicates if this reference uses 2 or 4 bytes, and its absolute value
* gives the position of the bytecode instruction. This array is also used
* as a bitset to store the subroutines to which a basic block belongs. This
- * information is needed in {@linked MethodWriter#visitMaxs}, after all
+ * information is needed in {@linked MethodWriter#visitMaxs}, after all
* forward references have been resolved. Hence the same array can be used
* for both purposes without problems.
*/
@@ -177,11 +177,11 @@ public class Label {
* state of the local variables and the operand stack at the end of each
* basic block, called the "output frame", <i>relatively</i> to the frame
* state at the beginning of the basic block, which is called the "input
- * frame", and which is <i>unknown</i> during this step. The second step,
- * in {@link MethodWriter#visitMaxs}, is a fix point algorithm that
- * computes information about the input frame of each basic block, from the
- * input state of the first basic block (known from the method signature),
- * and by the using the previously computed relative output frames.
+ * frame", and which is <i>unknown</i> during this step. The second step, in
+ * {@link MethodWriter#visitMaxs}, is a fix point algorithm that computes
+ * information about the input frame of each basic block, from the input
+ * state of the first basic block (known from the method signature), and by
+ * the using the previously computed relative output frames.
*
* The algorithm used to compute the maximum stack size only computes the
* relative output and absolute input stack heights, while the algorithm
@@ -266,11 +266,13 @@ public class Label {
* generators or adapters.</i>
*
* @return the offset corresponding to this label.
- * @throws IllegalStateException if this label is not resolved yet.
+ * @throws IllegalStateException
+ * if this label is not resolved yet.
*/
public int getOffset() {
if ((status & RESOLVED) == 0) {
- throw new IllegalStateException("Label offset position has not been resolved yet");
+ throw new IllegalStateException(
+ "Label offset position has not been resolved yet");
}
return position;
}
@@ -281,21 +283,21 @@ public class Label {
* directly. Otherwise, a null offset is written and a new forward reference
* is declared for this label.
*
- * @param owner the code writer that calls this method.
- * @param out the bytecode of the method.
- * @param source the position of first byte of the bytecode instruction that
- * contains this label.
- * @param wideOffset <tt>true</tt> if the reference must be stored in 4
- * bytes, or <tt>false</tt> if it must be stored with 2 bytes.
- * @throws IllegalArgumentException if this label has not been created by
- * the given code writer.
- */
- void put(
- final MethodWriter owner,
- final ByteVector out,
- final int source,
- final boolean wideOffset)
- {
+ * @param owner
+ * the code writer that calls this method.
+ * @param out
+ * the bytecode of the method.
+ * @param source
+ * the position of first byte of the bytecode instruction that
+ * contains this label.
+ * @param wideOffset
+ * <tt>true</tt> if the reference must be stored in 4 bytes, or
+ * <tt>false</tt> if it must be stored with 2 bytes.
+ * @throws IllegalArgumentException
+ * if this label has not been created by the given code writer.
+ */
+ void put(final MethodWriter owner, final ByteVector out, final int source,
+ final boolean wideOffset) {
if ((status & RESOLVED) == 0) {
if (wideOffset) {
addReference(-1 - source, out.length);
@@ -319,25 +321,21 @@ public class Label {
* yet. For backward references, the offset of the reference can be, and
* must be, computed and stored directly.
*
- * @param sourcePosition the position of the referencing instruction. This
- * position will be used to compute the offset of this forward
- * reference.
- * @param referencePosition the position where the offset for this forward
- * reference must be stored.
- */
- private void addReference(
- final int sourcePosition,
- final int referencePosition)
- {
+ * @param sourcePosition
+ * the position of the referencing instruction. This position
+ * will be used to compute the offset of this forward reference.
+ * @param referencePosition
+ * the position where the offset for this forward reference must
+ * be stored.
+ */
+ private void addReference(final int sourcePosition,
+ final int referencePosition) {
if (srcAndRefPositions == null) {
srcAndRefPositions = new int[6];
}
if (referenceCount >= srcAndRefPositions.length) {
int[] a = new int[srcAndRefPositions.length + 6];
- System.arraycopy(srcAndRefPositions,
- 0,
- a,
- 0,
+ System.arraycopy(srcAndRefPositions, 0, a, 0,
srcAndRefPositions.length);
srcAndRefPositions = a;
}
@@ -351,9 +349,12 @@ public class Label {
* position becomes known. This method fills in the blanks that where left
* in the bytecode by each forward reference previously added to this label.
*
- * @param owner the code writer that calls this method.
- * @param position the position of this label in the bytecode.
- * @param data the bytecode of the method.
+ * @param owner
+ * the code writer that calls this method.
+ * @param position
+ * the position of this label in the bytecode.
+ * @param data
+ * the bytecode of the method.
* @return <tt>true</tt> if a blank that was left for this label was to
* small to store the offset. In such a case the corresponding jump
* instruction is replaced with a pseudo instruction (using unused
@@ -361,14 +362,12 @@ public class Label {
* instructions will need to be replaced with true instructions with
* wider offsets (4 bytes instead of 2). This is done in
* {@link MethodWriter#resizeInstructions}.
- * @throws IllegalArgumentException if this label has already been resolved,
- * or if it has not been created by the given code writer.
- */
- boolean resolve(
- final MethodWriter owner,
- final int position,
- final byte[] data)
- {
+ * @throws IllegalArgumentException
+ * if this label has already been resolved, or if it has not
+ * been created by the given code writer.
+ */
+ boolean resolve(final MethodWriter owner, final int position,
+ final byte[] data) {
boolean needUpdate = false;
this.status |= RESOLVED;
this.position = position;
@@ -431,7 +430,8 @@ public class Label {
/**
* Returns true is this basic block belongs to the given subroutine.
*
- * @param id a subroutine id.
+ * @param id
+ * a subroutine id.
* @return true is this basic block belongs to the given subroutine.
*/
boolean inSubroutine(final long id) {
@@ -445,7 +445,8 @@ public class Label {
* Returns true if this basic block and the given one belong to a common
* subroutine.
*
- * @param block another basic block.
+ * @param block
+ * another basic block.
* @return true if this basic block and the given one belong to a common
* subroutine.
*/
@@ -464,8 +465,10 @@ public class Label {
/**
* Marks this basic block as belonging to the given subroutine.
*
- * @param id a subroutine id.
- * @param nbSubroutines the total number of subroutines in the method.
+ * @param id
+ * a subroutine id.
+ * @param nbSubroutines
+ * the total number of subroutines in the method.
*/
void addToSubroutine(final long id, final int nbSubroutines) {
if ((status & VISITED) == 0) {
@@ -481,14 +484,16 @@ public class Label {
* flow graph to find all the blocks that are reachable from the current
* block WITHOUT following any JSR target.
*
- * @param JSR a JSR block that jumps to this subroutine. If this JSR is not
- * null it is added to the successor of the RET blocks found in the
- * subroutine.
- * @param id the id of this subroutine.
- * @param nbSubroutines the total number of subroutines in the method.
- */
- void visitSubroutine(final Label JSR, final long id, final int nbSubroutines)
- {
+ * @param JSR
+ * a JSR block that jumps to this subroutine. If this JSR is not
+ * null it is added to the successor of the RET blocks found in
+ * the subroutine.
+ * @param id
+ * the id of this subroutine.
+ * @param nbSubroutines
+ * the total number of subroutines in the method.
+ */
+ void visitSubroutine(final Label JSR, final long id, final int nbSubroutines) {
// user managed stack of labels, to avoid using a recursive method
// (recursivity can lead to stack overflow with very large methods)
Label stack = this;
diff --git a/src/asm/scala/tools/asm/MethodVisitor.java b/src/asm/scala/tools/asm/MethodVisitor.java
index a8a859a6a9..e43ca97823 100644
--- a/src/asm/scala/tools/asm/MethodVisitor.java
+++ b/src/asm/scala/tools/asm/MethodVisitor.java
@@ -30,19 +30,19 @@
package scala.tools.asm;
/**
- * A visitor to visit a Java method. The methods of this class must be
- * called in the following order: [ <tt>visitAnnotationDefault</tt> ] (
+ * A visitor to visit a Java method. The methods of this class must be called in
+ * the following order: [ <tt>visitAnnotationDefault</tt> ] (
* <tt>visitAnnotation</tt> | <tt>visitParameterAnnotation</tt> |
* <tt>visitAttribute</tt> )* [ <tt>visitCode</tt> ( <tt>visitFrame</tt> |
- * <tt>visit</tt><i>X</i>Insn</tt> | <tt>visitLabel</tt> | <tt>visitTryCatchBlock</tt> |
- * <tt>visitLocalVariable</tt> | <tt>visitLineNumber</tt> )* <tt>visitMaxs</tt> ]
- * <tt>visitEnd</tt>. In addition, the <tt>visit</tt><i>X</i>Insn</tt>
- * and <tt>visitLabel</tt> methods must be called in the sequential order of
- * the bytecode instructions of the visited code, <tt>visitTryCatchBlock</tt>
- * must be called <i>before</i> the labels passed as arguments have been
- * visited, and the <tt>visitLocalVariable</tt> and <tt>visitLineNumber</tt>
- * methods must be called <i>after</i> the labels passed as arguments have been
- * visited.
+ * <tt>visit</tt><i>X</i>Insn</tt> | <tt>visitLabel</tt> |
+ * <tt>visitTryCatchBlock</tt> | <tt>visitLocalVariable</tt> |
+ * <tt>visitLineNumber</tt> )* <tt>visitMaxs</tt> ] <tt>visitEnd</tt>. In
+ * addition, the <tt>visit</tt><i>X</i>Insn</tt> and <tt>visitLabel</tt> methods
+ * must be called in the sequential order of the bytecode instructions of the
+ * visited code, <tt>visitTryCatchBlock</tt> must be called <i>before</i> the
+ * labels passed as arguments have been visited, and the
+ * <tt>visitLocalVariable</tt> and <tt>visitLineNumber</tt> methods must be
+ * called <i>after</i> the labels passed as arguments have been visited.
*
* @author Eric Bruneton
*/
@@ -63,8 +63,9 @@ public abstract class MethodVisitor {
/**
* Constructs a new {@link MethodVisitor}.
*
- * @param api the ASM API version implemented by this visitor. Must be one
- * of {@link Opcodes#ASM4}.
+ * @param api
+ * the ASM API version implemented by this visitor. Must be one
+ * of {@link Opcodes#ASM4}.
*/
public MethodVisitor(final int api) {
this(api, null);
@@ -73,15 +74,17 @@ public abstract class MethodVisitor {
/**
* Constructs a new {@link MethodVisitor}.
*
- * @param api the ASM API version implemented by this visitor. Must be one
- * of {@link Opcodes#ASM4}.
- * @param mv the method visitor to which this visitor must delegate method
- * calls. May be null.
+ * @param api
+ * the ASM API version implemented by this visitor. Must be one
+ * of {@link Opcodes#ASM4}.
+ * @param mv
+ * the method visitor to which this visitor must delegate method
+ * calls. May be null.
*/
public MethodVisitor(final int api, final MethodVisitor mv) {
- /*if (api != Opcodes.ASM4) {
+ if (api != Opcodes.ASM4) {
throw new IllegalArgumentException();
- }*/
+ }
this.api = api;
this.mv = mv;
}
@@ -94,8 +97,8 @@ public abstract class MethodVisitor {
* Visits the default value of this annotation interface method.
*
* @return a visitor to the visit the actual default value of this
- * annotation interface method, or <tt>null</tt> if this visitor
- * is not interested in visiting this default value. The 'name'
+ * annotation interface method, or <tt>null</tt> if this visitor is
+ * not interested in visiting this default value. The 'name'
* parameters passed to the methods of this annotation visitor are
* ignored. Moreover, exacly one visit method must be called on this
* annotation visitor, followed by visitEnd.
@@ -110,8 +113,10 @@ public abstract class MethodVisitor {
/**
* Visits an annotation of this method.
*
- * @param desc the class descriptor of the annotation class.
- * @param visible <tt>true</tt> if the annotation is visible at runtime.
+ * @param desc
+ * the class descriptor of the annotation class.
+ * @param visible
+ * <tt>true</tt> if the annotation is visible at runtime.
* @return a visitor to visit the annotation values, or <tt>null</tt> if
* this visitor is not interested in visiting this annotation.
*/
@@ -125,17 +130,17 @@ public abstract class MethodVisitor {
/**
* Visits an annotation of a parameter this method.
*
- * @param parameter the parameter index.
- * @param desc the class descriptor of the annotation class.
- * @param visible <tt>true</tt> if the annotation is visible at runtime.
+ * @param parameter
+ * the parameter index.
+ * @param desc
+ * the class descriptor of the annotation class.
+ * @param visible
+ * <tt>true</tt> if the annotation is visible at runtime.
* @return a visitor to visit the annotation values, or <tt>null</tt> if
* this visitor is not interested in visiting this annotation.
*/
- public AnnotationVisitor visitParameterAnnotation(
- int parameter,
- String desc,
- boolean visible)
- {
+ public AnnotationVisitor visitParameterAnnotation(int parameter,
+ String desc, boolean visible) {
if (mv != null) {
return mv.visitParameterAnnotation(parameter, desc, visible);
}
@@ -145,7 +150,8 @@ public abstract class MethodVisitor {
/**
* Visits a non standard attribute of this method.
*
- * @param attr an attribute.
+ * @param attr
+ * an attribute.
*/
public void visitAttribute(Attribute attr) {
if (mv != null) {
@@ -169,57 +175,74 @@ public abstract class MethodVisitor {
* such as GOTO or THROW, that is the target of a jump instruction, or that
* starts an exception handler block. The visited types must describe the
* values of the local variables and of the operand stack elements <i>just
- * before</i> <b>i</b> is executed. <br> <br> (*) this is mandatory only
- * for classes whose version is greater than or equal to
- * {@link Opcodes#V1_6 V1_6}. <br> <br> Packed frames are basically
- * "deltas" from the state of the previous frame (very first frame is
- * implicitly defined by the method's parameters and access flags): <ul>
+ * before</i> <b>i</b> is executed.<br>
+ * <br>
+ * (*) this is mandatory only for classes whose version is greater than or
+ * equal to {@link Opcodes#V1_6 V1_6}. <br>
+ * <br>
+ * The frames of a method must be given either in expanded form, or in
+ * compressed form (all frames must use the same format, i.e. you must not
+ * mix expanded and compressed frames within a single method):
+ * <ul>
+ * <li>In expanded form, all frames must have the F_NEW type.</li>
+ * <li>In compressed form, frames are basically "deltas" from the state of
+ * the previous frame:
+ * <ul>
* <li>{@link Opcodes#F_SAME} representing frame with exactly the same
- * locals as the previous frame and with the empty stack.</li> <li>{@link Opcodes#F_SAME1}
- * representing frame with exactly the same locals as the previous frame and
- * with single value on the stack (<code>nStack</code> is 1 and
- * <code>stack[0]</code> contains value for the type of the stack item).</li>
+ * locals as the previous frame and with the empty stack.</li>
+ * <li>{@link Opcodes#F_SAME1} representing frame with exactly the same
+ * locals as the previous frame and with single value on the stack (
+ * <code>nStack</code> is 1 and <code>stack[0]</code> contains value for the
+ * type of the stack item).</li>
* <li>{@link Opcodes#F_APPEND} representing frame with current locals are
* the same as the locals in the previous frame, except that additional
* locals are defined (<code>nLocal</code> is 1, 2 or 3 and
* <code>local</code> elements contains values representing added types).</li>
- * <li>{@link Opcodes#F_CHOP} representing frame with current locals are
- * the same as the locals in the previous frame, except that the last 1-3
- * locals are absent and with the empty stack (<code>nLocals</code> is 1,
- * 2 or 3). </li> <li>{@link Opcodes#F_FULL} representing complete frame
- * data.</li> </li> </ul>
+ * <li>{@link Opcodes#F_CHOP} representing frame with current locals are the
+ * same as the locals in the previous frame, except that the last 1-3 locals
+ * are absent and with the empty stack (<code>nLocals</code> is 1, 2 or 3).</li>
+ * <li>{@link Opcodes#F_FULL} representing complete frame data.</li></li>
+ * </ul>
+ * </ul> <br>
+ * In both cases the first frame, corresponding to the method's parameters
+ * and access flags, is implicit and must not be visited. Also, it is
+ * illegal to visit two or more frames for the same code location (i.e., at
+ * least one instruction must be visited between two calls to visitFrame).
*
- * @param type the type of this stack map frame. Must be
- * {@link Opcodes#F_NEW} for expanded frames, or
- * {@link Opcodes#F_FULL}, {@link Opcodes#F_APPEND},
- * {@link Opcodes#F_CHOP}, {@link Opcodes#F_SAME} or
- * {@link Opcodes#F_APPEND}, {@link Opcodes#F_SAME1} for compressed
- * frames.
- * @param nLocal the number of local variables in the visited frame.
- * @param local the local variable types in this frame. This array must not
- * be modified. Primitive types are represented by
- * {@link Opcodes#TOP}, {@link Opcodes#INTEGER},
- * {@link Opcodes#FLOAT}, {@link Opcodes#LONG},
- * {@link Opcodes#DOUBLE},{@link Opcodes#NULL} or
- * {@link Opcodes#UNINITIALIZED_THIS} (long and double are
- * represented by a single element). Reference types are represented
- * by String objects (representing internal names), and uninitialized
- * types by Label objects (this label designates the NEW instruction
- * that created this uninitialized value).
- * @param nStack the number of operand stack elements in the visited frame.
- * @param stack the operand stack types in this frame. This array must not
- * be modified. Its content has the same format as the "local" array.
- * @throws IllegalStateException if a frame is visited just after another
- * one, without any instruction between the two (unless this frame
- * is a Opcodes#F_SAME frame, in which case it is silently ignored).
+ * @param type
+ * the type of this stack map frame. Must be
+ * {@link Opcodes#F_NEW} for expanded frames, or
+ * {@link Opcodes#F_FULL}, {@link Opcodes#F_APPEND},
+ * {@link Opcodes#F_CHOP}, {@link Opcodes#F_SAME} or
+ * {@link Opcodes#F_APPEND}, {@link Opcodes#F_SAME1} for
+ * compressed frames.
+ * @param nLocal
+ * the number of local variables in the visited frame.
+ * @param local
+ * the local variable types in this frame. This array must not be
+ * modified. Primitive types are represented by
+ * {@link Opcodes#TOP}, {@link Opcodes#INTEGER},
+ * {@link Opcodes#FLOAT}, {@link Opcodes#LONG},
+ * {@link Opcodes#DOUBLE},{@link Opcodes#NULL} or
+ * {@link Opcodes#UNINITIALIZED_THIS} (long and double are
+ * represented by a single element). Reference types are
+ * represented by String objects (representing internal names),
+ * and uninitialized types by Label objects (this label
+ * designates the NEW instruction that created this uninitialized
+ * value).
+ * @param nStack
+ * the number of operand stack elements in the visited frame.
+ * @param stack
+ * the operand stack types in this frame. This array must not be
+ * modified. Its content has the same format as the "local"
+ * array.
+ * @throws IllegalStateException
+ * if a frame is visited just after another one, without any
+ * instruction between the two (unless this frame is a
+ * Opcodes#F_SAME frame, in which case it is silently ignored).
*/
- public void visitFrame(
- int type,
- int nLocal,
- Object[] local,
- int nStack,
- Object[] stack)
- {
+ public void visitFrame(int type, int nLocal, Object[] local, int nStack,
+ Object[] stack) {
if (mv != null) {
mv.visitFrame(type, nLocal, local, nStack, stack);
}
@@ -232,20 +255,22 @@ public abstract class MethodVisitor {
/**
* Visits a zero operand instruction.
*
- * @param opcode the opcode of the instruction to be visited. This opcode is
- * either NOP, ACONST_NULL, ICONST_M1, ICONST_0, ICONST_1, ICONST_2,
- * ICONST_3, ICONST_4, ICONST_5, LCONST_0, LCONST_1, FCONST_0,
- * FCONST_1, FCONST_2, DCONST_0, DCONST_1, IALOAD, LALOAD, FALOAD,
- * DALOAD, AALOAD, BALOAD, CALOAD, SALOAD, IASTORE, LASTORE, FASTORE,
- * DASTORE, AASTORE, BASTORE, CASTORE, SASTORE, POP, POP2, DUP,
- * DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, SWAP, IADD, LADD, FADD,
- * DADD, ISUB, LSUB, FSUB, DSUB, IMUL, LMUL, FMUL, DMUL, IDIV, LDIV,
- * FDIV, DDIV, IREM, LREM, FREM, DREM, INEG, LNEG, FNEG, DNEG, ISHL,
- * LSHL, ISHR, LSHR, IUSHR, LUSHR, IAND, LAND, IOR, LOR, IXOR, LXOR,
- * I2L, I2F, I2D, L2I, L2F, L2D, F2I, F2L, F2D, D2I, D2L, D2F, I2B,
- * I2C, I2S, LCMP, FCMPL, FCMPG, DCMPL, DCMPG, IRETURN, LRETURN,
- * FRETURN, DRETURN, ARETURN, RETURN, ARRAYLENGTH, ATHROW,
- * MONITORENTER, or MONITOREXIT.
+ * @param opcode
+ * the opcode of the instruction to be visited. This opcode is
+ * either NOP, ACONST_NULL, ICONST_M1, ICONST_0, ICONST_1,
+ * ICONST_2, ICONST_3, ICONST_4, ICONST_5, LCONST_0, LCONST_1,
+ * FCONST_0, FCONST_1, FCONST_2, DCONST_0, DCONST_1, IALOAD,
+ * LALOAD, FALOAD, DALOAD, AALOAD, BALOAD, CALOAD, SALOAD,
+ * IASTORE, LASTORE, FASTORE, DASTORE, AASTORE, BASTORE, CASTORE,
+ * SASTORE, POP, POP2, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1,
+ * DUP2_X2, SWAP, IADD, LADD, FADD, DADD, ISUB, LSUB, FSUB, DSUB,
+ * IMUL, LMUL, FMUL, DMUL, IDIV, LDIV, FDIV, DDIV, IREM, LREM,
+ * FREM, DREM, INEG, LNEG, FNEG, DNEG, ISHL, LSHL, ISHR, LSHR,
+ * IUSHR, LUSHR, IAND, LAND, IOR, LOR, IXOR, LXOR, I2L, I2F, I2D,
+ * L2I, L2F, L2D, F2I, F2L, F2D, D2I, D2L, D2F, I2B, I2C, I2S,
+ * LCMP, FCMPL, FCMPG, DCMPL, DCMPG, IRETURN, LRETURN, FRETURN,
+ * DRETURN, ARETURN, RETURN, ARRAYLENGTH, ATHROW, MONITORENTER,
+ * or MONITOREXIT.
*/
public void visitInsn(int opcode) {
if (mv != null) {
@@ -256,17 +281,20 @@ public abstract class MethodVisitor {
/**
* Visits an instruction with a single int operand.
*
- * @param opcode the opcode of the instruction to be visited. This opcode is
- * either BIPUSH, SIPUSH or NEWARRAY.
- * @param operand the operand of the instruction to be visited.<br> When
- * opcode is BIPUSH, operand value should be between Byte.MIN_VALUE
- * and Byte.MAX_VALUE.<br> When opcode is SIPUSH, operand value
- * should be between Short.MIN_VALUE and Short.MAX_VALUE.<br> When
- * opcode is NEWARRAY, operand value should be one of
- * {@link Opcodes#T_BOOLEAN}, {@link Opcodes#T_CHAR},
- * {@link Opcodes#T_FLOAT}, {@link Opcodes#T_DOUBLE},
- * {@link Opcodes#T_BYTE}, {@link Opcodes#T_SHORT},
- * {@link Opcodes#T_INT} or {@link Opcodes#T_LONG}.
+ * @param opcode
+ * the opcode of the instruction to be visited. This opcode is
+ * either BIPUSH, SIPUSH or NEWARRAY.
+ * @param operand
+ * the operand of the instruction to be visited.<br>
+ * When opcode is BIPUSH, operand value should be between
+ * Byte.MIN_VALUE and Byte.MAX_VALUE.<br>
+ * When opcode is SIPUSH, operand value should be between
+ * Short.MIN_VALUE and Short.MAX_VALUE.<br>
+ * When opcode is NEWARRAY, operand value should be one of
+ * {@link Opcodes#T_BOOLEAN}, {@link Opcodes#T_CHAR},
+ * {@link Opcodes#T_FLOAT}, {@link Opcodes#T_DOUBLE},
+ * {@link Opcodes#T_BYTE}, {@link Opcodes#T_SHORT},
+ * {@link Opcodes#T_INT} or {@link Opcodes#T_LONG}.
*/
public void visitIntInsn(int opcode, int operand) {
if (mv != null) {
@@ -278,11 +306,13 @@ public abstract class MethodVisitor {
* Visits a local variable instruction. A local variable instruction is an
* instruction that loads or stores the value of a local variable.
*
- * @param opcode the opcode of the local variable instruction to be visited.
- * This opcode is either ILOAD, LLOAD, FLOAD, DLOAD, ALOAD, ISTORE,
- * LSTORE, FSTORE, DSTORE, ASTORE or RET.
- * @param var the operand of the instruction to be visited. This operand is
- * the index of a local variable.
+ * @param opcode
+ * the opcode of the local variable instruction to be visited.
+ * This opcode is either ILOAD, LLOAD, FLOAD, DLOAD, ALOAD,
+ * ISTORE, LSTORE, FSTORE, DSTORE, ASTORE or RET.
+ * @param var
+ * the operand of the instruction to be visited. This operand is
+ * the index of a local variable.
*/
public void visitVarInsn(int opcode, int var) {
if (mv != null) {
@@ -294,11 +324,13 @@ public abstract class MethodVisitor {
* Visits a type instruction. A type instruction is an instruction that
* takes the internal name of a class as parameter.
*
- * @param opcode the opcode of the type instruction to be visited. This
- * opcode is either NEW, ANEWARRAY, CHECKCAST or INSTANCEOF.
- * @param type the operand of the instruction to be visited. This operand
- * must be the internal name of an object or array class (see {@link
- * Type#getInternalName() getInternalName}).
+ * @param opcode
+ * the opcode of the type instruction to be visited. This opcode
+ * is either NEW, ANEWARRAY, CHECKCAST or INSTANCEOF.
+ * @param type
+ * the operand of the instruction to be visited. This operand
+ * must be the internal name of an object or array class (see
+ * {@link Type#getInternalName() getInternalName}).
*/
public void visitTypeInsn(int opcode, String type) {
if (mv != null) {
@@ -310,14 +342,19 @@ public abstract class MethodVisitor {
* Visits a field instruction. A field instruction is an instruction that
* loads or stores the value of a field of an object.
*
- * @param opcode the opcode of the type instruction to be visited. This
- * opcode is either GETSTATIC, PUTSTATIC, GETFIELD or PUTFIELD.
- * @param owner the internal name of the field's owner class (see {@link
- * Type#getInternalName() getInternalName}).
- * @param name the field's name.
- * @param desc the field's descriptor (see {@link Type Type}).
+ * @param opcode
+ * the opcode of the type instruction to be visited. This opcode
+ * is either GETSTATIC, PUTSTATIC, GETFIELD or PUTFIELD.
+ * @param owner
+ * the internal name of the field's owner class (see
+ * {@link Type#getInternalName() getInternalName}).
+ * @param name
+ * the field's name.
+ * @param desc
+ * the field's descriptor (see {@link Type Type}).
*/
- public void visitFieldInsn(int opcode, String owner, String name, String desc) {
+ public void visitFieldInsn(int opcode, String owner, String name,
+ String desc) {
if (mv != null) {
mv.visitFieldInsn(opcode, owner, name, desc);
}
@@ -327,15 +364,20 @@ public abstract class MethodVisitor {
* Visits a method instruction. A method instruction is an instruction that
* invokes a method.
*
- * @param opcode the opcode of the type instruction to be visited. This
- * opcode is either INVOKEVIRTUAL, INVOKESPECIAL, INVOKESTATIC
- * or INVOKEINTERFACE.
- * @param owner the internal name of the method's owner class (see {@link
- * Type#getInternalName() getInternalName}).
- * @param name the method's name.
- * @param desc the method's descriptor (see {@link Type Type}).
+ * @param opcode
+ * the opcode of the type instruction to be visited. This opcode
+ * is either INVOKEVIRTUAL, INVOKESPECIAL, INVOKESTATIC or
+ * INVOKEINTERFACE.
+ * @param owner
+ * the internal name of the method's owner class (see
+ * {@link Type#getInternalName() getInternalName}).
+ * @param name
+ * the method's name.
+ * @param desc
+ * the method's descriptor (see {@link Type Type}).
*/
- public void visitMethodInsn(int opcode, String owner, String name, String desc) {
+ public void visitMethodInsn(int opcode, String owner, String name,
+ String desc) {
if (mv != null) {
mv.visitMethodInsn(opcode, owner, name, desc);
}
@@ -344,16 +386,21 @@ public abstract class MethodVisitor {
/**
* Visits an invokedynamic instruction.
*
- * @param name the method's name.
- * @param desc the method's descriptor (see {@link Type Type}).
- * @param bsm the bootstrap method.
- * @param bsmArgs the bootstrap method constant arguments. Each argument
- * must be an {@link Integer}, {@link Float}, {@link Long},
- * {@link Double}, {@link String}, {@link Type} or {@link Handle}
- * value. This method is allowed to modify the content of the array
- * so a caller should expect that this array may change.
+ * @param name
+ * the method's name.
+ * @param desc
+ * the method's descriptor (see {@link Type Type}).
+ * @param bsm
+ * the bootstrap method.
+ * @param bsmArgs
+ * the bootstrap method constant arguments. Each argument must be
+ * an {@link Integer}, {@link Float}, {@link Long},
+ * {@link Double}, {@link String}, {@link Type} or {@link Handle}
+ * value. This method is allowed to modify the content of the
+ * array so a caller should expect that this array may change.
*/
- public void visitInvokeDynamicInsn(String name, String desc, Handle bsm, Object... bsmArgs) {
+ public void visitInvokeDynamicInsn(String name, String desc, Handle bsm,
+ Object... bsmArgs) {
if (mv != null) {
mv.visitInvokeDynamicInsn(name, desc, bsm, bsmArgs);
}
@@ -363,13 +410,15 @@ public abstract class MethodVisitor {
* Visits a jump instruction. A jump instruction is an instruction that may
* jump to another instruction.
*
- * @param opcode the opcode of the type instruction to be visited. This
- * opcode is either IFEQ, IFNE, IFLT, IFGE, IFGT, IFLE, IF_ICMPEQ,
- * IF_ICMPNE, IF_ICMPLT, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ACMPEQ,
- * IF_ACMPNE, GOTO, JSR, IFNULL or IFNONNULL.
- * @param label the operand of the instruction to be visited. This operand
- * is a label that designates the instruction to which the jump
- * instruction may jump.
+ * @param opcode
+ * the opcode of the type instruction to be visited. This opcode
+ * is either IFEQ, IFNE, IFLT, IFGE, IFGT, IFLE, IF_ICMPEQ,
+ * IF_ICMPNE, IF_ICMPLT, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE,
+ * IF_ACMPEQ, IF_ACMPNE, GOTO, JSR, IFNULL or IFNONNULL.
+ * @param label
+ * the operand of the instruction to be visited. This operand is
+ * a label that designates the instruction to which the jump
+ * instruction may jump.
*/
public void visitJumpInsn(int opcode, Label label) {
if (mv != null) {
@@ -381,7 +430,8 @@ public abstract class MethodVisitor {
* Visits a label. A label designates the instruction that will be visited
* just after it.
*
- * @param label a {@link Label Label} object.
+ * @param label
+ * a {@link Label Label} object.
*/
public void visitLabel(Label label) {
if (mv != null) {
@@ -398,41 +448,44 @@ public abstract class MethodVisitor {
* future versions of the Java Virtual Machine. To easily detect new
* constant types, implementations of this method should check for
* unexpected constant types, like this:
+ *
* <pre>
* if (cst instanceof Integer) {
- * // ...
+ * // ...
* } else if (cst instanceof Float) {
- * // ...
+ * // ...
* } else if (cst instanceof Long) {
- * // ...
- * } else if (cst instanceof Double) {
- * // ...
- * } else if (cst instanceof String) {
- * // ...
- * } else if (cst instanceof Type) {
- * int sort = ((Type) cst).getSort();
- * if (sort == Type.OBJECT) {
* // ...
- * } else if (sort == Type.ARRAY) {
+ * } else if (cst instanceof Double) {
* // ...
- * } else if (sort == Type.METHOD) {
+ * } else if (cst instanceof String) {
* // ...
- * } else {
- * // throw an exception
- * }
+ * } else if (cst instanceof Type) {
+ * int sort = ((Type) cst).getSort();
+ * if (sort == Type.OBJECT) {
+ * // ...
+ * } else if (sort == Type.ARRAY) {
+ * // ...
+ * } else if (sort == Type.METHOD) {
+ * // ...
+ * } else {
+ * // throw an exception
+ * }
* } else if (cst instanceof Handle) {
- * // ...
+ * // ...
* } else {
- * // throw an exception
- * }</pre>
+ * // throw an exception
+ * }
+ * </pre>
*
- * @param cst the constant to be loaded on the stack. This parameter must be
- * a non null {@link Integer}, a {@link Float}, a {@link Long}, a
- * {@link Double}, a {@link String}, a {@link Type} of OBJECT or ARRAY
- * sort for <tt>.class</tt> constants, for classes whose version is
- * 49.0, a {@link Type} of METHOD sort or a {@link Handle} for
- * MethodType and MethodHandle constants, for classes whose version
- * is 51.0.
+ * @param cst
+ * the constant to be loaded on the stack. This parameter must be
+ * a non null {@link Integer}, a {@link Float}, a {@link Long}, a
+ * {@link Double}, a {@link String}, a {@link Type} of OBJECT or
+ * ARRAY sort for <tt>.class</tt> constants, for classes whose
+ * version is 49.0, a {@link Type} of METHOD sort or a
+ * {@link Handle} for MethodType and MethodHandle constants, for
+ * classes whose version is 51.0.
*/
public void visitLdcInsn(Object cst) {
if (mv != null) {
@@ -443,8 +496,10 @@ public abstract class MethodVisitor {
/**
* Visits an IINC instruction.
*
- * @param var index of the local variable to be incremented.
- * @param increment amount to increment the local variable by.
+ * @param var
+ * index of the local variable to be incremented.
+ * @param increment
+ * amount to increment the local variable by.
*/
public void visitIincInsn(int var, int increment) {
if (mv != null) {
@@ -455,13 +510,18 @@ public abstract class MethodVisitor {
/**
* Visits a TABLESWITCH instruction.
*
- * @param min the minimum key value.
- * @param max the maximum key value.
- * @param dflt beginning of the default handler block.
- * @param labels beginnings of the handler blocks. <tt>labels[i]</tt> is
- * the beginning of the handler block for the <tt>min + i</tt> key.
+ * @param min
+ * the minimum key value.
+ * @param max
+ * the maximum key value.
+ * @param dflt
+ * beginning of the default handler block.
+ * @param labels
+ * beginnings of the handler blocks. <tt>labels[i]</tt> is the
+ * beginning of the handler block for the <tt>min + i</tt> key.
*/
- public void visitTableSwitchInsn(int min, int max, Label dflt, Label... labels) {
+ public void visitTableSwitchInsn(int min, int max, Label dflt,
+ Label... labels) {
if (mv != null) {
mv.visitTableSwitchInsn(min, max, dflt, labels);
}
@@ -470,10 +530,13 @@ public abstract class MethodVisitor {
/**
* Visits a LOOKUPSWITCH instruction.
*
- * @param dflt beginning of the default handler block.
- * @param keys the values of the keys.
- * @param labels beginnings of the handler blocks. <tt>labels[i]</tt> is
- * the beginning of the handler block for the <tt>keys[i]</tt> key.
+ * @param dflt
+ * beginning of the default handler block.
+ * @param keys
+ * the values of the keys.
+ * @param labels
+ * beginnings of the handler blocks. <tt>labels[i]</tt> is the
+ * beginning of the handler block for the <tt>keys[i]</tt> key.
*/
public void visitLookupSwitchInsn(Label dflt, int[] keys, Label[] labels) {
if (mv != null) {
@@ -484,8 +547,10 @@ public abstract class MethodVisitor {
/**
* Visits a MULTIANEWARRAY instruction.
*
- * @param desc an array type descriptor (see {@link Type Type}).
- * @param dims number of dimensions of the array to allocate.
+ * @param desc
+ * an array type descriptor (see {@link Type Type}).
+ * @param dims
+ * number of dimensions of the array to allocate.
*/
public void visitMultiANewArrayInsn(String desc, int dims) {
if (mv != null) {
@@ -500,17 +565,22 @@ public abstract class MethodVisitor {
/**
* Visits a try catch block.
*
- * @param start beginning of the exception handler's scope (inclusive).
- * @param end end of the exception handler's scope (exclusive).
- * @param handler beginning of the exception handler's code.
- * @param type internal name of the type of exceptions handled by the
- * handler, or <tt>null</tt> to catch any exceptions (for "finally"
- * blocks).
- * @throws IllegalArgumentException if one of the labels has already been
- * visited by this visitor (by the {@link #visitLabel visitLabel}
- * method).
+ * @param start
+ * beginning of the exception handler's scope (inclusive).
+ * @param end
+ * end of the exception handler's scope (exclusive).
+ * @param handler
+ * beginning of the exception handler's code.
+ * @param type
+ * internal name of the type of exceptions handled by the
+ * handler, or <tt>null</tt> to catch any exceptions (for
+ * "finally" blocks).
+ * @throws IllegalArgumentException
+ * if one of the labels has already been visited by this visitor
+ * (by the {@link #visitLabel visitLabel} method).
*/
- public void visitTryCatchBlock(Label start, Label end, Label handler, String type) {
+ public void visitTryCatchBlock(Label start, Label end, Label handler,
+ String type) {
if (mv != null) {
mv.visitTryCatchBlock(start, end, handler, type);
}
@@ -519,28 +589,28 @@ public abstract class MethodVisitor {
/**
* Visits a local variable declaration.
*
- * @param name the name of a local variable.
- * @param desc the type descriptor of this local variable.
- * @param signature the type signature of this local variable. May be
- * <tt>null</tt> if the local variable type does not use generic
- * types.
- * @param start the first instruction corresponding to the scope of this
- * local variable (inclusive).
- * @param end the last instruction corresponding to the scope of this local
- * variable (exclusive).
- * @param index the local variable's index.
- * @throws IllegalArgumentException if one of the labels has not already
- * been visited by this visitor (by the
- * {@link #visitLabel visitLabel} method).
+ * @param name
+ * the name of a local variable.
+ * @param desc
+ * the type descriptor of this local variable.
+ * @param signature
+ * the type signature of this local variable. May be
+ * <tt>null</tt> if the local variable type does not use generic
+ * types.
+ * @param start
+ * the first instruction corresponding to the scope of this local
+ * variable (inclusive).
+ * @param end
+ * the last instruction corresponding to the scope of this local
+ * variable (exclusive).
+ * @param index
+ * the local variable's index.
+ * @throws IllegalArgumentException
+ * if one of the labels has not already been visited by this
+ * visitor (by the {@link #visitLabel visitLabel} method).
*/
- public void visitLocalVariable(
- String name,
- String desc,
- String signature,
- Label start,
- Label end,
- int index)
- {
+ public void visitLocalVariable(String name, String desc, String signature,
+ Label start, Label end, int index) {
if (mv != null) {
mv.visitLocalVariable(name, desc, signature, start, end, index);
}
@@ -549,12 +619,14 @@ public abstract class MethodVisitor {
/**
* Visits a line number declaration.
*
- * @param line a line number. This number refers to the source file from
- * which the class was compiled.
- * @param start the first instruction corresponding to this line number.
- * @throws IllegalArgumentException if <tt>start</tt> has not already been
- * visited by this visitor (by the {@link #visitLabel visitLabel}
- * method).
+ * @param line
+ * a line number. This number refers to the source file from
+ * which the class was compiled.
+ * @param start
+ * the first instruction corresponding to this line number.
+ * @throws IllegalArgumentException
+ * if <tt>start</tt> has not already been visited by this
+ * visitor (by the {@link #visitLabel visitLabel} method).
*/
public void visitLineNumber(int line, Label start) {
if (mv != null) {
@@ -566,8 +638,10 @@ public abstract class MethodVisitor {
* Visits the maximum stack size and the maximum number of local variables
* of the method.
*
- * @param maxStack maximum stack size of the method.
- * @param maxLocals maximum number of local variables for the method.
+ * @param maxStack
+ * maximum stack size of the method.
+ * @param maxLocals
+ * maximum number of local variables for the method.
*/
public void visitMaxs(int maxStack, int maxLocals) {
if (mv != null) {
diff --git a/src/asm/scala/tools/asm/MethodWriter.java b/src/asm/scala/tools/asm/MethodWriter.java
index 321bacb6fc..f5fbd1e74f 100644
--- a/src/asm/scala/tools/asm/MethodWriter.java
+++ b/src/asm/scala/tools/asm/MethodWriter.java
@@ -42,7 +42,7 @@ class MethodWriter extends MethodVisitor {
/**
* Pseudo access flag used to denote constructors.
*/
- static final int ACC_CONSTRUCTOR = 262144;
+ static final int ACC_CONSTRUCTOR = 0x80000;
/**
* Frame has exactly the same locals as the previous stack map frame and
@@ -229,7 +229,7 @@ class MethodWriter extends MethodVisitor {
private int maxLocals;
/**
- * Number of local variables in the current stack map frame.
+ * Number of local variables in the current stack map frame.
*/
private int currentLocals;
@@ -257,11 +257,6 @@ class MethodWriter extends MethodVisitor {
private int[] previousFrame;
/**
- * Index of the next element to be added in {@link #frame}.
- */
- private int frameIndex;
-
- /**
* The current stack map frame. The first element contains the offset of the
* instruction to which the frame corresponds, the second element is the
* number of locals and the third one is the number of stack elements. The
@@ -357,7 +352,8 @@ class MethodWriter extends MethodVisitor {
* A list of labels. This list is the list of basic blocks in the method,
* i.e. a list of Label objects linked to each other by their
* {@link Label#successor} field, in the order they are visited by
- * {@link MethodVisitor#visitLabel}, and starting with the first basic block.
+ * {@link MethodVisitor#visitLabel}, and starting with the first basic
+ * block.
*/
private Label labels;
@@ -396,28 +392,30 @@ class MethodWriter extends MethodVisitor {
/**
* Constructs a new {@link MethodWriter}.
*
- * @param cw the class writer in which the method must be added.
- * @param access the method's access flags (see {@link Opcodes}).
- * @param name the method's name.
- * @param desc the method's descriptor (see {@link Type}).
- * @param signature the method's signature. May be <tt>null</tt>.
- * @param exceptions the internal names of the method's exceptions. May be
- * <tt>null</tt>.
- * @param computeMaxs <tt>true</tt> if the maximum stack size and number
- * of local variables must be automatically computed.
- * @param computeFrames <tt>true</tt> if the stack map tables must be
- * recomputed from scratch.
- */
- MethodWriter(
- final ClassWriter cw,
- final int access,
- final String name,
- final String desc,
- final String signature,
- final String[] exceptions,
- final boolean computeMaxs,
- final boolean computeFrames)
- {
+ * @param cw
+ * the class writer in which the method must be added.
+ * @param access
+ * the method's access flags (see {@link Opcodes}).
+ * @param name
+ * the method's name.
+ * @param desc
+ * the method's descriptor (see {@link Type}).
+ * @param signature
+ * the method's signature. May be <tt>null</tt>.
+ * @param exceptions
+ * the internal names of the method's exceptions. May be
+ * <tt>null</tt>.
+ * @param computeMaxs
+ * <tt>true</tt> if the maximum stack size and number of local
+ * variables must be automatically computed.
+ * @param computeFrames
+ * <tt>true</tt> if the stack map tables must be recomputed from
+ * scratch.
+ */
+ MethodWriter(final ClassWriter cw, final int access, final String name,
+ final String desc, final String signature,
+ final String[] exceptions, final boolean computeMaxs,
+ final boolean computeFrames) {
super(Opcodes.ASM4);
if (cw.firstMethod == null) {
cw.firstMethod = this;
@@ -427,6 +425,9 @@ class MethodWriter extends MethodVisitor {
cw.lastMethod = this;
this.cw = cw;
this.access = access;
+ if ("<init>".equals(name)) {
+ this.access |= ACC_CONSTRUCTOR;
+ }
this.name = cw.newUTF8(name);
this.desc = cw.newUTF8(desc);
this.descriptor = desc;
@@ -442,9 +443,6 @@ class MethodWriter extends MethodVisitor {
}
this.compute = computeFrames ? FRAMES : (computeMaxs ? MAXS : NOTHING);
if (computeMaxs || computeFrames) {
- if (computeFrames && "<init>".equals(name)) {
- this.access |= ACC_CONSTRUCTOR;
- }
// updates maxLocals
int size = Type.getArgumentsAndReturnSizes(descriptor) >> 2;
if ((access & Opcodes.ACC_STATIC) != 0) {
@@ -473,10 +471,8 @@ class MethodWriter extends MethodVisitor {
}
@Override
- public AnnotationVisitor visitAnnotation(
- final String desc,
- final boolean visible)
- {
+ public AnnotationVisitor visitAnnotation(final String desc,
+ final boolean visible) {
if (!ClassReader.ANNOTATIONS) {
return null;
}
@@ -495,11 +491,8 @@ class MethodWriter extends MethodVisitor {
}
@Override
- public AnnotationVisitor visitParameterAnnotation(
- final int parameter,
- final String desc,
- final boolean visible)
- {
+ public AnnotationVisitor visitParameterAnnotation(final int parameter,
+ final String desc, final boolean visible) {
if (!ClassReader.ANNOTATIONS) {
return null;
}
@@ -545,20 +538,18 @@ class MethodWriter extends MethodVisitor {
}
@Override
- public void visitFrame(
- final int type,
- final int nLocal,
- final Object[] local,
- final int nStack,
- final Object[] stack)
- {
+ public void visitFrame(final int type, final int nLocal,
+ final Object[] local, final int nStack, final Object[] stack) {
if (!ClassReader.FRAMES || compute == FRAMES) {
return;
}
if (type == Opcodes.F_NEW) {
+ if (previousFrame == null) {
+ visitImplicitFirstFrame();
+ }
currentLocals = nLocal;
- startFrame(code.length, nLocal, nStack);
+ int frameIndex = startFrame(code.length, nLocal, nStack);
for (int i = 0; i < nLocal; ++i) {
if (local[i] instanceof String) {
frame[frameIndex++] = Frame.OBJECT
@@ -601,48 +592,44 @@ class MethodWriter extends MethodVisitor {
}
switch (type) {
- case Opcodes.F_FULL:
- currentLocals = nLocal;
- stackMap.putByte(FULL_FRAME)
- .putShort(delta)
- .putShort(nLocal);
- for (int i = 0; i < nLocal; ++i) {
- writeFrameType(local[i]);
- }
- stackMap.putShort(nStack);
- for (int i = 0; i < nStack; ++i) {
- writeFrameType(stack[i]);
- }
- break;
- case Opcodes.F_APPEND:
- currentLocals += nLocal;
- stackMap.putByte(SAME_FRAME_EXTENDED + nLocal)
- .putShort(delta);
- for (int i = 0; i < nLocal; ++i) {
- writeFrameType(local[i]);
- }
- break;
- case Opcodes.F_CHOP:
- currentLocals -= nLocal;
- stackMap.putByte(SAME_FRAME_EXTENDED - nLocal)
+ case Opcodes.F_FULL:
+ currentLocals = nLocal;
+ stackMap.putByte(FULL_FRAME).putShort(delta).putShort(nLocal);
+ for (int i = 0; i < nLocal; ++i) {
+ writeFrameType(local[i]);
+ }
+ stackMap.putShort(nStack);
+ for (int i = 0; i < nStack; ++i) {
+ writeFrameType(stack[i]);
+ }
+ break;
+ case Opcodes.F_APPEND:
+ currentLocals += nLocal;
+ stackMap.putByte(SAME_FRAME_EXTENDED + nLocal).putShort(delta);
+ for (int i = 0; i < nLocal; ++i) {
+ writeFrameType(local[i]);
+ }
+ break;
+ case Opcodes.F_CHOP:
+ currentLocals -= nLocal;
+ stackMap.putByte(SAME_FRAME_EXTENDED - nLocal).putShort(delta);
+ break;
+ case Opcodes.F_SAME:
+ if (delta < 64) {
+ stackMap.putByte(delta);
+ } else {
+ stackMap.putByte(SAME_FRAME_EXTENDED).putShort(delta);
+ }
+ break;
+ case Opcodes.F_SAME1:
+ if (delta < 64) {
+ stackMap.putByte(SAME_LOCALS_1_STACK_ITEM_FRAME + delta);
+ } else {
+ stackMap.putByte(SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED)
.putShort(delta);
- break;
- case Opcodes.F_SAME:
- if (delta < 64) {
- stackMap.putByte(delta);
- } else {
- stackMap.putByte(SAME_FRAME_EXTENDED).putShort(delta);
- }
- break;
- case Opcodes.F_SAME1:
- if (delta < 64) {
- stackMap.putByte(SAME_LOCALS_1_STACK_ITEM_FRAME + delta);
- } else {
- stackMap.putByte(SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED)
- .putShort(delta);
- }
- writeFrameType(stack[0]);
- break;
+ }
+ writeFrameType(stack[0]);
+ break;
}
previousFrameOffset = code.length;
@@ -672,8 +659,7 @@ class MethodWriter extends MethodVisitor {
}
// if opcode == ATHROW or xRETURN, ends current block (no successor)
if ((opcode >= Opcodes.IRETURN && opcode <= Opcodes.RETURN)
- || opcode == Opcodes.ATHROW)
- {
+ || opcode == Opcodes.ATHROW) {
noSuccessor();
}
}
@@ -731,8 +717,7 @@ class MethodWriter extends MethodVisitor {
// updates max locals
int n;
if (opcode == Opcodes.LLOAD || opcode == Opcodes.DLOAD
- || opcode == Opcodes.LSTORE || opcode == Opcodes.DSTORE)
- {
+ || opcode == Opcodes.LSTORE || opcode == Opcodes.DSTORE) {
n = var + 2;
} else {
n = var + 1;
@@ -784,12 +769,8 @@ class MethodWriter extends MethodVisitor {
}
@Override
- public void visitFieldInsn(
- final int opcode,
- final String owner,
- final String name,
- final String desc)
- {
+ public void visitFieldInsn(final int opcode, final String owner,
+ final String name, final String desc) {
Item i = cw.newFieldItem(owner, name, desc);
// Label currentBlock = this.currentBlock;
if (currentBlock != null) {
@@ -800,19 +781,19 @@ class MethodWriter extends MethodVisitor {
// computes the stack size variation
char c = desc.charAt(0);
switch (opcode) {
- case Opcodes.GETSTATIC:
- size = stackSize + (c == 'D' || c == 'J' ? 2 : 1);
- break;
- case Opcodes.PUTSTATIC:
- size = stackSize + (c == 'D' || c == 'J' ? -2 : -1);
- break;
- case Opcodes.GETFIELD:
- size = stackSize + (c == 'D' || c == 'J' ? 1 : 0);
- break;
- // case Constants.PUTFIELD:
- default:
- size = stackSize + (c == 'D' || c == 'J' ? -3 : -2);
- break;
+ case Opcodes.GETSTATIC:
+ size = stackSize + (c == 'D' || c == 'J' ? 2 : 1);
+ break;
+ case Opcodes.PUTSTATIC:
+ size = stackSize + (c == 'D' || c == 'J' ? -2 : -1);
+ break;
+ case Opcodes.GETFIELD:
+ size = stackSize + (c == 'D' || c == 'J' ? 1 : 0);
+ break;
+ // case Constants.PUTFIELD:
+ default:
+ size = stackSize + (c == 'D' || c == 'J' ? -3 : -2);
+ break;
}
// updates current and max stack sizes
if (size > maxStackSize) {
@@ -826,12 +807,8 @@ class MethodWriter extends MethodVisitor {
}
@Override
- public void visitMethodInsn(
- final int opcode,
- final String owner,
- final String name,
- final String desc)
- {
+ public void visitMethodInsn(final int opcode, final String owner,
+ final String name, final String desc) {
boolean itf = opcode == Opcodes.INVOKEINTERFACE;
Item i = cw.newMethodItem(owner, name, desc, itf);
int argSize = i.intVal;
@@ -882,12 +859,8 @@ class MethodWriter extends MethodVisitor {
}
@Override
- public void visitInvokeDynamicInsn(
- final String name,
- final String desc,
- final Handle bsm,
- final Object... bsmArgs)
- {
+ public void visitInvokeDynamicInsn(final String name, final String desc,
+ final Handle bsm, final Object... bsmArgs) {
Item i = cw.newInvokeDynamicItem(name, desc, bsm, bsmArgs);
int argSize = i.intVal;
// Label currentBlock = this.currentBlock;
@@ -967,8 +940,7 @@ class MethodWriter extends MethodVisitor {
}
// adds the instruction to the bytecode of the method
if ((label.status & Label.RESOLVED) != 0
- && label.position - code.length < Short.MIN_VALUE)
- {
+ && label.position - code.length < Short.MIN_VALUE) {
/*
* case of a backward jump with an offset < -32768. In this case we
* automatically replace GOTO with GOTO_W, JSR with JSR_W and IFxxx
@@ -986,8 +958,7 @@ class MethodWriter extends MethodVisitor {
if (nextInsn != null) {
nextInsn.status |= Label.TARGET;
}
- code.putByte(opcode <= 166
- ? ((opcode + 1) ^ 1) - 1
+ code.putByte(opcode <= 166 ? ((opcode + 1) ^ 1) - 1
: opcode ^ 1);
code.putShort(8); // jump offset
code.putByte(200); // GOTO_W
@@ -1082,8 +1053,7 @@ class MethodWriter extends MethodVisitor {
} else {
int size;
// computes the stack size variation
- if (i.type == ClassWriter.LONG || i.type == ClassWriter.DOUBLE)
- {
+ if (i.type == ClassWriter.LONG || i.type == ClassWriter.DOUBLE) {
size = stackSize + 2;
} else {
size = stackSize + 1;
@@ -1122,8 +1092,7 @@ class MethodWriter extends MethodVisitor {
}
// adds the instruction to the bytecode of the method
if ((var > 255) || (increment > 127) || (increment < -128)) {
- code.putByte(196 /* WIDE */)
- .put12(Opcodes.IINC, var)
+ code.putByte(196 /* WIDE */).put12(Opcodes.IINC, var)
.putShort(increment);
} else {
code.putByte(Opcodes.IINC).put11(var, increment);
@@ -1131,12 +1100,8 @@ class MethodWriter extends MethodVisitor {
}
@Override
- public void visitTableSwitchInsn(
- final int min,
- final int max,
- final Label dflt,
- final Label... labels)
- {
+ public void visitTableSwitchInsn(final int min, final int max,
+ final Label dflt, final Label... labels) {
// adds the instruction to the bytecode of the method
int source = code.length;
code.putByte(Opcodes.TABLESWITCH);
@@ -1151,11 +1116,8 @@ class MethodWriter extends MethodVisitor {
}
@Override
- public void visitLookupSwitchInsn(
- final Label dflt,
- final int[] keys,
- final Label[] labels)
- {
+ public void visitLookupSwitchInsn(final Label dflt, final int[] keys,
+ final Label[] labels) {
// adds the instruction to the bytecode of the method
int source = code.length;
code.putByte(Opcodes.LOOKUPSWITCH);
@@ -1214,12 +1176,8 @@ class MethodWriter extends MethodVisitor {
}
@Override
- public void visitTryCatchBlock(
- final Label start,
- final Label end,
- final Label handler,
- final String type)
- {
+ public void visitTryCatchBlock(final Label start, final Label end,
+ final Label handler, final String type) {
++handlerCount;
Handler h = new Handler();
h.start = start;
@@ -1236,14 +1194,9 @@ class MethodWriter extends MethodVisitor {
}
@Override
- public void visitLocalVariable(
- final String name,
- final String desc,
- final String signature,
- final Label start,
- final Label end,
- final int index)
- {
+ public void visitLocalVariable(final String name, final String desc,
+ final String signature, final Label start, final Label end,
+ final int index) {
if (signature != null) {
if (localVarType == null) {
localVarType = new ByteVector();
@@ -1251,8 +1204,7 @@ class MethodWriter extends MethodVisitor {
++localVarTypeCount;
localVarType.putShort(start.position)
.putShort(end.position - start.position)
- .putShort(cw.newUTF8(name))
- .putShort(cw.newUTF8(signature))
+ .putShort(cw.newUTF8(name)).putShort(cw.newUTF8(signature))
.putShort(index);
}
if (localVar == null) {
@@ -1261,8 +1213,7 @@ class MethodWriter extends MethodVisitor {
++localVarCount;
localVar.putShort(start.position)
.putShort(end.position - start.position)
- .putShort(cw.newUTF8(name))
- .putShort(cw.newUTF8(desc))
+ .putShort(cw.newUTF8(name)).putShort(cw.newUTF8(desc))
.putShort(index);
if (compute != NOTHING) {
// updates max locals
@@ -1294,8 +1245,7 @@ class MethodWriter extends MethodVisitor {
Label h = handler.handler.getFirst();
Label e = handler.end.getFirst();
// computes the kind of the edges to 'h'
- String t = handler.desc == null
- ? "java/lang/Throwable"
+ String t = handler.desc == null ? "java/lang/Throwable"
: handler.desc;
int kind = Frame.OBJECT | cw.addType(t);
// h is an exception handler
@@ -1382,11 +1332,12 @@ class MethodWriter extends MethodVisitor {
}
code.data[end] = (byte) Opcodes.ATHROW;
// emits a frame for this unreachable block
- startFrame(start, 0, 1);
- frame[frameIndex++] = Frame.OBJECT
+ int frameIndex = startFrame(start, 0, 1);
+ frame[frameIndex] = Frame.OBJECT
| cw.addType("java/lang/Throwable");
endFrame();
- // removes the start-end range from the exception handlers
+ // removes the start-end range from the exception
+ // handlers
firstHandler = Handler.remove(firstHandler, l, k);
}
}
@@ -1535,8 +1486,10 @@ class MethodWriter extends MethodVisitor {
/**
* Adds a successor to the {@link #currentBlock currentBlock} block.
*
- * @param info information about the control flow edge to be added.
- * @param successor the successor block to be added to the current block.
+ * @param info
+ * information about the control flow edge to be added.
+ * @param successor
+ * the successor block to be added to the current block.
*/
private void addSuccessor(final int info, final Label successor) {
// creates and initializes an Edge object...
@@ -1573,7 +1526,8 @@ class MethodWriter extends MethodVisitor {
/**
* Visits a frame that has been computed from scratch.
*
- * @param f the frame that must be visited.
+ * @param f
+ * the frame that must be visited.
*/
private void visitFrame(final Frame f) {
int i, t;
@@ -1606,7 +1560,7 @@ class MethodWriter extends MethodVisitor {
}
}
// visits the frame and its content
- startFrame(f.owner.position, nLocal, nStack);
+ int frameIndex = startFrame(f.owner.position, nLocal, nStack);
for (i = 0; nLocal > 0; ++i, --nLocal) {
t = locals[i];
frame[frameIndex++] = t;
@@ -1625,15 +1579,78 @@ class MethodWriter extends MethodVisitor {
}
/**
+ * Visit the implicit first frame of this method.
+ */
+ private void visitImplicitFirstFrame() {
+ // There can be at most descriptor.length() + 1 locals
+ int frameIndex = startFrame(0, descriptor.length() + 1, 0);
+ if ((access & Opcodes.ACC_STATIC) == 0) {
+ if ((access & ACC_CONSTRUCTOR) == 0) {
+ frame[frameIndex++] = Frame.OBJECT | cw.addType(cw.thisName);
+ } else {
+ frame[frameIndex++] = 6; // Opcodes.UNINITIALIZED_THIS;
+ }
+ }
+ int i = 1;
+ loop: while (true) {
+ int j = i;
+ switch (descriptor.charAt(i++)) {
+ case 'Z':
+ case 'C':
+ case 'B':
+ case 'S':
+ case 'I':
+ frame[frameIndex++] = 1; // Opcodes.INTEGER;
+ break;
+ case 'F':
+ frame[frameIndex++] = 2; // Opcodes.FLOAT;
+ break;
+ case 'J':
+ frame[frameIndex++] = 4; // Opcodes.LONG;
+ break;
+ case 'D':
+ frame[frameIndex++] = 3; // Opcodes.DOUBLE;
+ break;
+ case '[':
+ while (descriptor.charAt(i) == '[') {
+ ++i;
+ }
+ if (descriptor.charAt(i) == 'L') {
+ ++i;
+ while (descriptor.charAt(i) != ';') {
+ ++i;
+ }
+ }
+ frame[frameIndex++] = Frame.OBJECT
+ | cw.addType(descriptor.substring(j, ++i));
+ break;
+ case 'L':
+ while (descriptor.charAt(i) != ';') {
+ ++i;
+ }
+ frame[frameIndex++] = Frame.OBJECT
+ | cw.addType(descriptor.substring(j + 1, i++));
+ break;
+ default:
+ break loop;
+ }
+ }
+ frame[1] = frameIndex - 3;
+ endFrame();
+ }
+
+ /**
* Starts the visit of a stack map frame.
*
- * @param offset the offset of the instruction to which the frame
- * corresponds.
- * @param nLocal the number of local variables in the frame.
- * @param nStack the number of stack elements in the frame.
- */
- private void startFrame(final int offset, final int nLocal, final int nStack)
- {
+ * @param offset
+ * the offset of the instruction to which the frame corresponds.
+ * @param nLocal
+ * the number of local variables in the frame.
+ * @param nStack
+ * the number of stack elements in the frame.
+ * @return the index of the next element to be written in this frame.
+ */
+ private int startFrame(final int offset, final int nLocal, final int nStack) {
int n = 3 + nLocal + nStack;
if (frame == null || frame.length < n) {
frame = new int[n];
@@ -1641,7 +1658,7 @@ class MethodWriter extends MethodVisitor {
frame[0] = offset;
frame[1] = nLocal;
frame[2] = nStack;
- frameIndex = 3;
+ return 3;
}
/**
@@ -1686,24 +1703,23 @@ class MethodWriter extends MethodVisitor {
if (cstackSize == 0) {
k = clocalsSize - localsSize;
switch (k) {
- case -3:
- case -2:
- case -1:
- type = CHOP_FRAME;
- localsSize = clocalsSize;
- break;
- case 0:
- type = delta < 64 ? SAME_FRAME : SAME_FRAME_EXTENDED;
- break;
- case 1:
- case 2:
- case 3:
- type = APPEND_FRAME;
- break;
+ case -3:
+ case -2:
+ case -1:
+ type = CHOP_FRAME;
+ localsSize = clocalsSize;
+ break;
+ case 0:
+ type = delta < 64 ? SAME_FRAME : SAME_FRAME_EXTENDED;
+ break;
+ case 1:
+ case 2:
+ case 3:
+ type = APPEND_FRAME;
+ break;
}
} else if (clocalsSize == localsSize && cstackSize == 1) {
- type = delta < 63
- ? SAME_LOCALS_1_STACK_ITEM_FRAME
+ type = delta < 63 ? SAME_LOCALS_1_STACK_ITEM_FRAME
: SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED;
}
if (type != FULL_FRAME) {
@@ -1718,36 +1734,34 @@ class MethodWriter extends MethodVisitor {
}
}
switch (type) {
- case SAME_FRAME:
- stackMap.putByte(delta);
- break;
- case SAME_LOCALS_1_STACK_ITEM_FRAME:
- stackMap.putByte(SAME_LOCALS_1_STACK_ITEM_FRAME + delta);
- writeFrameTypes(3 + clocalsSize, 4 + clocalsSize);
- break;
- case SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED:
- stackMap.putByte(SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED)
- .putShort(delta);
- writeFrameTypes(3 + clocalsSize, 4 + clocalsSize);
- break;
- case SAME_FRAME_EXTENDED:
- stackMap.putByte(SAME_FRAME_EXTENDED).putShort(delta);
- break;
- case CHOP_FRAME:
- stackMap.putByte(SAME_FRAME_EXTENDED + k).putShort(delta);
- break;
- case APPEND_FRAME:
- stackMap.putByte(SAME_FRAME_EXTENDED + k).putShort(delta);
- writeFrameTypes(3 + localsSize, 3 + clocalsSize);
- break;
- // case FULL_FRAME:
- default:
- stackMap.putByte(FULL_FRAME)
- .putShort(delta)
- .putShort(clocalsSize);
- writeFrameTypes(3, 3 + clocalsSize);
- stackMap.putShort(cstackSize);
- writeFrameTypes(3 + clocalsSize, 3 + clocalsSize + cstackSize);
+ case SAME_FRAME:
+ stackMap.putByte(delta);
+ break;
+ case SAME_LOCALS_1_STACK_ITEM_FRAME:
+ stackMap.putByte(SAME_LOCALS_1_STACK_ITEM_FRAME + delta);
+ writeFrameTypes(3 + clocalsSize, 4 + clocalsSize);
+ break;
+ case SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED:
+ stackMap.putByte(SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED).putShort(
+ delta);
+ writeFrameTypes(3 + clocalsSize, 4 + clocalsSize);
+ break;
+ case SAME_FRAME_EXTENDED:
+ stackMap.putByte(SAME_FRAME_EXTENDED).putShort(delta);
+ break;
+ case CHOP_FRAME:
+ stackMap.putByte(SAME_FRAME_EXTENDED + k).putShort(delta);
+ break;
+ case APPEND_FRAME:
+ stackMap.putByte(SAME_FRAME_EXTENDED + k).putShort(delta);
+ writeFrameTypes(3 + localsSize, 3 + clocalsSize);
+ break;
+ // case FULL_FRAME:
+ default:
+ stackMap.putByte(FULL_FRAME).putShort(delta).putShort(clocalsSize);
+ writeFrameTypes(3, 3 + clocalsSize);
+ stackMap.putShort(cstackSize);
+ writeFrameTypes(3 + clocalsSize, 3 + clocalsSize + cstackSize);
}
}
@@ -1757,8 +1771,10 @@ class MethodWriter extends MethodVisitor {
* in {@link Label} to the format used in StackMapTable attributes. In
* particular, it converts type table indexes to constant pool indexes.
*
- * @param start index of the first type in {@link #frame} to write.
- * @param end index of last type in {@link #frame} to write (exclusive).
+ * @param start
+ * index of the first type in {@link #frame} to write.
+ * @param end
+ * index of last type in {@link #frame} to write (exclusive).
*/
private void writeFrameTypes(final int start, final int end) {
for (int i = start; i < end; ++i) {
@@ -1767,15 +1783,15 @@ class MethodWriter extends MethodVisitor {
if (d == 0) {
int v = t & Frame.BASE_VALUE;
switch (t & Frame.BASE_KIND) {
- case Frame.OBJECT:
- stackMap.putByte(7)
- .putShort(cw.newClass(cw.typeTable[v].strVal1));
- break;
- case Frame.UNINITIALIZED:
- stackMap.putByte(8).putShort(cw.typeTable[v].intVal);
- break;
- default:
- stackMap.putByte(v);
+ case Frame.OBJECT:
+ stackMap.putByte(7).putShort(
+ cw.newClass(cw.typeTable[v].strVal1));
+ break;
+ case Frame.UNINITIALIZED:
+ stackMap.putByte(8).putShort(cw.typeTable[v].intVal);
+ break;
+ default:
+ stackMap.putByte(v);
}
} else {
StringBuffer buf = new StringBuffer();
@@ -1789,29 +1805,29 @@ class MethodWriter extends MethodVisitor {
buf.append(';');
} else {
switch (t & 0xF) {
- case 1:
- buf.append('I');
- break;
- case 2:
- buf.append('F');
- break;
- case 3:
- buf.append('D');
- break;
- case 9:
- buf.append('Z');
- break;
- case 10:
- buf.append('B');
- break;
- case 11:
- buf.append('C');
- break;
- case 12:
- buf.append('S');
- break;
- default:
- buf.append('J');
+ case 1:
+ buf.append('I');
+ break;
+ case 2:
+ buf.append('F');
+ break;
+ case 3:
+ buf.append('D');
+ break;
+ case 9:
+ buf.append('Z');
+ break;
+ case 10:
+ buf.append('B');
+ break;
+ case 11:
+ buf.append('C');
+ break;
+ case 12:
+ buf.append('S');
+ break;
+ default:
+ buf.append('J');
}
}
stackMap.putByte(7).putShort(cw.newClass(buf.toString()));
@@ -1875,10 +1891,7 @@ class MethodWriter extends MethodVisitor {
size += 8 + stackMap.length;
}
if (cattrs != null) {
- size += cattrs.getSize(cw,
- code.data,
- code.length,
- maxStack,
+ size += cattrs.getSize(cw, code.data, code.length, maxStack,
maxLocals);
}
}
@@ -1886,11 +1899,12 @@ class MethodWriter extends MethodVisitor {
cw.newUTF8("Exceptions");
size += 8 + 2 * exceptionCount;
}
- if ((access & Opcodes.ACC_SYNTHETIC) != 0
- && ((cw.version & 0xFFFF) < Opcodes.V1_5 || (access & ClassWriter.ACC_SYNTHETIC_ATTRIBUTE) != 0))
- {
- cw.newUTF8("Synthetic");
- size += 6;
+ if ((access & Opcodes.ACC_SYNTHETIC) != 0) {
+ if ((cw.version & 0xFFFF) < Opcodes.V1_5
+ || (access & ClassWriter.ACC_SYNTHETIC_ATTRIBUTE) != 0) {
+ cw.newUTF8("Synthetic");
+ size += 6;
+ }
}
if ((access & Opcodes.ACC_DEPRECATED) != 0) {
cw.newUTF8("Deprecated");
@@ -1936,13 +1950,15 @@ class MethodWriter extends MethodVisitor {
/**
* Puts the bytecode of this method in the given byte vector.
*
- * @param out the byte vector into which the bytecode of this method must be
- * copied.
+ * @param out
+ * the byte vector into which the bytecode of this method must be
+ * copied.
*/
final void put(final ByteVector out) {
- int mask = Opcodes.ACC_DEPRECATED
+ final int FACTOR = ClassWriter.TO_ACC_SYNTHETIC;
+ int mask = ACC_CONSTRUCTOR | Opcodes.ACC_DEPRECATED
| ClassWriter.ACC_SYNTHETIC_ATTRIBUTE
- | ((access & ClassWriter.ACC_SYNTHETIC_ATTRIBUTE) / (ClassWriter.ACC_SYNTHETIC_ATTRIBUTE / Opcodes.ACC_SYNTHETIC));
+ | ((access & ClassWriter.ACC_SYNTHETIC_ATTRIBUTE) / FACTOR);
out.putShort(access & ~mask).putShort(name).putShort(desc);
if (classReaderOffset != 0) {
out.putByteArray(cw.cr.b, classReaderOffset, classReaderLength);
@@ -1955,10 +1971,11 @@ class MethodWriter extends MethodVisitor {
if (exceptionCount > 0) {
++attributeCount;
}
- if ((access & Opcodes.ACC_SYNTHETIC) != 0
- && ((cw.version & 0xFFFF) < Opcodes.V1_5 || (access & ClassWriter.ACC_SYNTHETIC_ATTRIBUTE) != 0))
- {
- ++attributeCount;
+ if ((access & Opcodes.ACC_SYNTHETIC) != 0) {
+ if ((cw.version & 0xFFFF) < Opcodes.V1_5
+ || (access & ClassWriter.ACC_SYNTHETIC_ATTRIBUTE) != 0) {
+ ++attributeCount;
+ }
}
if ((access & Opcodes.ACC_DEPRECATED) != 0) {
++attributeCount;
@@ -2000,10 +2017,7 @@ class MethodWriter extends MethodVisitor {
size += 8 + stackMap.length;
}
if (cattrs != null) {
- size += cattrs.getSize(cw,
- code.data,
- code.length,
- maxStack,
+ size += cattrs.getSize(cw, code.data, code.length, maxStack,
maxLocals);
}
out.putShort(cw.newUTF8("Code")).putInt(size);
@@ -2013,10 +2027,8 @@ class MethodWriter extends MethodVisitor {
if (handlerCount > 0) {
Handler h = firstHandler;
while (h != null) {
- out.putShort(h.start.position)
- .putShort(h.end.position)
- .putShort(h.handler.position)
- .putShort(h.type);
+ out.putShort(h.start.position).putShort(h.end.position)
+ .putShort(h.handler.position).putShort(h.type);
h = h.next;
}
}
@@ -2063,24 +2075,24 @@ class MethodWriter extends MethodVisitor {
}
}
if (exceptionCount > 0) {
- out.putShort(cw.newUTF8("Exceptions"))
- .putInt(2 * exceptionCount + 2);
+ out.putShort(cw.newUTF8("Exceptions")).putInt(
+ 2 * exceptionCount + 2);
out.putShort(exceptionCount);
for (int i = 0; i < exceptionCount; ++i) {
out.putShort(exceptions[i]);
}
}
- if ((access & Opcodes.ACC_SYNTHETIC) != 0
- && ((cw.version & 0xFFFF) < Opcodes.V1_5 || (access & ClassWriter.ACC_SYNTHETIC_ATTRIBUTE) != 0))
- {
- out.putShort(cw.newUTF8("Synthetic")).putInt(0);
+ if ((access & Opcodes.ACC_SYNTHETIC) != 0) {
+ if ((cw.version & 0xFFFF) < Opcodes.V1_5
+ || (access & ClassWriter.ACC_SYNTHETIC_ATTRIBUTE) != 0) {
+ out.putShort(cw.newUTF8("Synthetic")).putInt(0);
+ }
}
if ((access & Opcodes.ACC_DEPRECATED) != 0) {
out.putShort(cw.newUTF8("Deprecated")).putInt(0);
}
if (ClassReader.SIGNATURES && signature != null) {
- out.putShort(cw.newUTF8("Signature"))
- .putInt(2)
+ out.putShort(cw.newUTF8("Signature")).putInt(2)
.putShort(cw.newUTF8(signature));
}
if (ClassReader.ANNOTATIONS && annd != null) {
@@ -2123,10 +2135,12 @@ class MethodWriter extends MethodVisitor {
* 32768, in which case IFEQ 32766 must be replaced with IFNEQ 8 GOTO_W
* 32765. This, in turn, may require to increase the size of another jump
* instruction, and so on... All these operations are handled automatically
- * by this method. <p> <i>This method must be called after all the method
- * that is being built has been visited</i>. In particular, the
- * {@link Label Label} objects used to construct the method are no longer
- * valid after this method has been called.
+ * by this method.
+ * <p>
+ * <i>This method must be called after all the method that is being built
+ * has been visited</i>. In particular, the {@link Label Label} objects used
+ * to construct the method are no longer valid after this method has been
+ * called.
*/
private void resizeInstructions() {
byte[] b = code.data; // bytecode of the method
@@ -2176,158 +2190,14 @@ class MethodWriter extends MethodVisitor {
int insert = 0; // bytes to be added after this instruction
switch (ClassWriter.TYPE[opcode]) {
- case ClassWriter.NOARG_INSN:
- case ClassWriter.IMPLVAR_INSN:
- u += 1;
- break;
- case ClassWriter.LABEL_INSN:
- if (opcode > 201) {
- // converts temporary opcodes 202 to 217, 218 and
- // 219 to IFEQ ... JSR (inclusive), IFNULL and
- // IFNONNULL
- opcode = opcode < 218 ? opcode - 49 : opcode - 20;
- label = u + readUnsignedShort(b, u + 1);
- } else {
- label = u + readShort(b, u + 1);
- }
- newOffset = getNewOffset(allIndexes, allSizes, u, label);
- if (newOffset < Short.MIN_VALUE
- || newOffset > Short.MAX_VALUE)
- {
- if (!resize[u]) {
- if (opcode == Opcodes.GOTO
- || opcode == Opcodes.JSR)
- {
- // two additional bytes will be required to
- // replace this GOTO or JSR instruction with
- // a GOTO_W or a JSR_W
- insert = 2;
- } else {
- // five additional bytes will be required to
- // replace this IFxxx <l> instruction with
- // IFNOTxxx <l'> GOTO_W <l>, where IFNOTxxx
- // is the "opposite" opcode of IFxxx (i.e.,
- // IFNE for IFEQ) and where <l'> designates
- // the instruction just after the GOTO_W.
- insert = 5;
- }
- resize[u] = true;
- }
- }
- u += 3;
- break;
- case ClassWriter.LABELW_INSN:
- u += 5;
- break;
- case ClassWriter.TABL_INSN:
- if (state == 1) {
- // true number of bytes to be added (or removed)
- // from this instruction = (future number of padding
- // bytes - current number of padding byte) -
- // previously over estimated variation =
- // = ((3 - newOffset%4) - (3 - u%4)) - u%4
- // = (-newOffset%4 + u%4) - u%4
- // = -(newOffset & 3)
- newOffset = getNewOffset(allIndexes, allSizes, 0, u);
- insert = -(newOffset & 3);
- } else if (!resize[u]) {
- // over estimation of the number of bytes to be
- // added to this instruction = 3 - current number
- // of padding bytes = 3 - (3 - u%4) = u%4 = u & 3
- insert = u & 3;
- resize[u] = true;
- }
- // skips instruction
- u = u + 4 - (u & 3);
- u += 4 * (readInt(b, u + 8) - readInt(b, u + 4) + 1) + 12;
- break;
- case ClassWriter.LOOK_INSN:
- if (state == 1) {
- // like TABL_INSN
- newOffset = getNewOffset(allIndexes, allSizes, 0, u);
- insert = -(newOffset & 3);
- } else if (!resize[u]) {
- // like TABL_INSN
- insert = u & 3;
- resize[u] = true;
- }
- // skips instruction
- u = u + 4 - (u & 3);
- u += 8 * readInt(b, u + 4) + 8;
- break;
- case ClassWriter.WIDE_INSN:
- opcode = b[u + 1] & 0xFF;
- if (opcode == Opcodes.IINC) {
- u += 6;
- } else {
- u += 4;
- }
- break;
- case ClassWriter.VAR_INSN:
- case ClassWriter.SBYTE_INSN:
- case ClassWriter.LDC_INSN:
- u += 2;
- break;
- case ClassWriter.SHORT_INSN:
- case ClassWriter.LDCW_INSN:
- case ClassWriter.FIELDORMETH_INSN:
- case ClassWriter.TYPE_INSN:
- case ClassWriter.IINC_INSN:
- u += 3;
- break;
- case ClassWriter.ITFMETH_INSN:
- case ClassWriter.INDYMETH_INSN:
- u += 5;
- break;
- // case ClassWriter.MANA_INSN:
- default:
- u += 4;
- break;
- }
- if (insert != 0) {
- // adds a new (u, insert) entry in the allIndexes and
- // allSizes arrays
- int[] newIndexes = new int[allIndexes.length + 1];
- int[] newSizes = new int[allSizes.length + 1];
- System.arraycopy(allIndexes,
- 0,
- newIndexes,
- 0,
- allIndexes.length);
- System.arraycopy(allSizes, 0, newSizes, 0, allSizes.length);
- newIndexes[allIndexes.length] = u;
- newSizes[allSizes.length] = insert;
- allIndexes = newIndexes;
- allSizes = newSizes;
- if (insert > 0) {
- state = 3;
- }
- }
- }
- if (state < 3) {
- --state;
- }
- } while (state != 0);
-
- // 2nd step:
- // copies the bytecode of the method into a new bytevector, updates the
- // offsets, and inserts (or removes) bytes as requested.
-
- ByteVector newCode = new ByteVector(code.length);
-
- u = 0;
- while (u < code.length) {
- int opcode = b[u] & 0xFF;
- switch (ClassWriter.TYPE[opcode]) {
case ClassWriter.NOARG_INSN:
case ClassWriter.IMPLVAR_INSN:
- newCode.putByte(opcode);
u += 1;
break;
case ClassWriter.LABEL_INSN:
if (opcode > 201) {
- // changes temporary opcodes 202 to 217 (inclusive), 218
- // and 219 to IFEQ ... JSR (inclusive), IFNULL and
+ // converts temporary opcodes 202 to 217, 218 and
+ // 219 to IFEQ ... JSR (inclusive), IFNULL and
// IFNONNULL
opcode = opcode < 218 ? opcode - 49 : opcode - 20;
label = u + readUnsignedShort(b, u + 1);
@@ -2335,100 +2205,78 @@ class MethodWriter extends MethodVisitor {
label = u + readShort(b, u + 1);
}
newOffset = getNewOffset(allIndexes, allSizes, u, label);
- if (resize[u]) {
- // replaces GOTO with GOTO_W, JSR with JSR_W and IFxxx
- // <l> with IFNOTxxx <l'> GOTO_W <l>, where IFNOTxxx is
- // the "opposite" opcode of IFxxx (i.e., IFNE for IFEQ)
- // and where <l'> designates the instruction just after
- // the GOTO_W.
- if (opcode == Opcodes.GOTO) {
- newCode.putByte(200); // GOTO_W
- } else if (opcode == Opcodes.JSR) {
- newCode.putByte(201); // JSR_W
- } else {
- newCode.putByte(opcode <= 166
- ? ((opcode + 1) ^ 1) - 1
- : opcode ^ 1);
- newCode.putShort(8); // jump offset
- newCode.putByte(200); // GOTO_W
- // newOffset now computed from start of GOTO_W
- newOffset -= 3;
+ if (newOffset < Short.MIN_VALUE
+ || newOffset > Short.MAX_VALUE) {
+ if (!resize[u]) {
+ if (opcode == Opcodes.GOTO || opcode == Opcodes.JSR) {
+ // two additional bytes will be required to
+ // replace this GOTO or JSR instruction with
+ // a GOTO_W or a JSR_W
+ insert = 2;
+ } else {
+ // five additional bytes will be required to
+ // replace this IFxxx <l> instruction with
+ // IFNOTxxx <l'> GOTO_W <l>, where IFNOTxxx
+ // is the "opposite" opcode of IFxxx (i.e.,
+ // IFNE for IFEQ) and where <l'> designates
+ // the instruction just after the GOTO_W.
+ insert = 5;
+ }
+ resize[u] = true;
}
- newCode.putInt(newOffset);
- } else {
- newCode.putByte(opcode);
- newCode.putShort(newOffset);
}
u += 3;
break;
case ClassWriter.LABELW_INSN:
- label = u + readInt(b, u + 1);
- newOffset = getNewOffset(allIndexes, allSizes, u, label);
- newCode.putByte(opcode);
- newCode.putInt(newOffset);
u += 5;
break;
case ClassWriter.TABL_INSN:
- // skips 0 to 3 padding bytes
- v = u;
- u = u + 4 - (v & 3);
- // reads and copies instruction
- newCode.putByte(Opcodes.TABLESWITCH);
- newCode.putByteArray(null, 0, (4 - newCode.length % 4) % 4);
- label = v + readInt(b, u);
- u += 4;
- newOffset = getNewOffset(allIndexes, allSizes, v, label);
- newCode.putInt(newOffset);
- j = readInt(b, u);
- u += 4;
- newCode.putInt(j);
- j = readInt(b, u) - j + 1;
- u += 4;
- newCode.putInt(readInt(b, u - 4));
- for (; j > 0; --j) {
- label = v + readInt(b, u);
- u += 4;
- newOffset = getNewOffset(allIndexes, allSizes, v, label);
- newCode.putInt(newOffset);
+ if (state == 1) {
+ // true number of bytes to be added (or removed)
+ // from this instruction = (future number of padding
+ // bytes - current number of padding byte) -
+ // previously over estimated variation =
+ // = ((3 - newOffset%4) - (3 - u%4)) - u%4
+ // = (-newOffset%4 + u%4) - u%4
+ // = -(newOffset & 3)
+ newOffset = getNewOffset(allIndexes, allSizes, 0, u);
+ insert = -(newOffset & 3);
+ } else if (!resize[u]) {
+ // over estimation of the number of bytes to be
+ // added to this instruction = 3 - current number
+ // of padding bytes = 3 - (3 - u%4) = u%4 = u & 3
+ insert = u & 3;
+ resize[u] = true;
}
+ // skips instruction
+ u = u + 4 - (u & 3);
+ u += 4 * (readInt(b, u + 8) - readInt(b, u + 4) + 1) + 12;
break;
case ClassWriter.LOOK_INSN:
- // skips 0 to 3 padding bytes
- v = u;
- u = u + 4 - (v & 3);
- // reads and copies instruction
- newCode.putByte(Opcodes.LOOKUPSWITCH);
- newCode.putByteArray(null, 0, (4 - newCode.length % 4) % 4);
- label = v + readInt(b, u);
- u += 4;
- newOffset = getNewOffset(allIndexes, allSizes, v, label);
- newCode.putInt(newOffset);
- j = readInt(b, u);
- u += 4;
- newCode.putInt(j);
- for (; j > 0; --j) {
- newCode.putInt(readInt(b, u));
- u += 4;
- label = v + readInt(b, u);
- u += 4;
- newOffset = getNewOffset(allIndexes, allSizes, v, label);
- newCode.putInt(newOffset);
+ if (state == 1) {
+ // like TABL_INSN
+ newOffset = getNewOffset(allIndexes, allSizes, 0, u);
+ insert = -(newOffset & 3);
+ } else if (!resize[u]) {
+ // like TABL_INSN
+ insert = u & 3;
+ resize[u] = true;
}
+ // skips instruction
+ u = u + 4 - (u & 3);
+ u += 8 * readInt(b, u + 4) + 8;
break;
case ClassWriter.WIDE_INSN:
opcode = b[u + 1] & 0xFF;
if (opcode == Opcodes.IINC) {
- newCode.putByteArray(b, u, 6);
u += 6;
} else {
- newCode.putByteArray(b, u, 4);
u += 4;
}
break;
case ClassWriter.VAR_INSN:
case ClassWriter.SBYTE_INSN:
case ClassWriter.LDC_INSN:
- newCode.putByteArray(b, u, 2);
u += 2;
break;
case ClassWriter.SHORT_INSN:
@@ -2436,19 +2284,178 @@ class MethodWriter extends MethodVisitor {
case ClassWriter.FIELDORMETH_INSN:
case ClassWriter.TYPE_INSN:
case ClassWriter.IINC_INSN:
- newCode.putByteArray(b, u, 3);
u += 3;
break;
case ClassWriter.ITFMETH_INSN:
case ClassWriter.INDYMETH_INSN:
- newCode.putByteArray(b, u, 5);
u += 5;
break;
- // case MANA_INSN:
+ // case ClassWriter.MANA_INSN:
default:
- newCode.putByteArray(b, u, 4);
u += 4;
break;
+ }
+ if (insert != 0) {
+ // adds a new (u, insert) entry in the allIndexes and
+ // allSizes arrays
+ int[] newIndexes = new int[allIndexes.length + 1];
+ int[] newSizes = new int[allSizes.length + 1];
+ System.arraycopy(allIndexes, 0, newIndexes, 0,
+ allIndexes.length);
+ System.arraycopy(allSizes, 0, newSizes, 0, allSizes.length);
+ newIndexes[allIndexes.length] = u;
+ newSizes[allSizes.length] = insert;
+ allIndexes = newIndexes;
+ allSizes = newSizes;
+ if (insert > 0) {
+ state = 3;
+ }
+ }
+ }
+ if (state < 3) {
+ --state;
+ }
+ } while (state != 0);
+
+ // 2nd step:
+ // copies the bytecode of the method into a new bytevector, updates the
+ // offsets, and inserts (or removes) bytes as requested.
+
+ ByteVector newCode = new ByteVector(code.length);
+
+ u = 0;
+ while (u < code.length) {
+ int opcode = b[u] & 0xFF;
+ switch (ClassWriter.TYPE[opcode]) {
+ case ClassWriter.NOARG_INSN:
+ case ClassWriter.IMPLVAR_INSN:
+ newCode.putByte(opcode);
+ u += 1;
+ break;
+ case ClassWriter.LABEL_INSN:
+ if (opcode > 201) {
+ // changes temporary opcodes 202 to 217 (inclusive), 218
+ // and 219 to IFEQ ... JSR (inclusive), IFNULL and
+ // IFNONNULL
+ opcode = opcode < 218 ? opcode - 49 : opcode - 20;
+ label = u + readUnsignedShort(b, u + 1);
+ } else {
+ label = u + readShort(b, u + 1);
+ }
+ newOffset = getNewOffset(allIndexes, allSizes, u, label);
+ if (resize[u]) {
+ // replaces GOTO with GOTO_W, JSR with JSR_W and IFxxx
+ // <l> with IFNOTxxx <l'> GOTO_W <l>, where IFNOTxxx is
+ // the "opposite" opcode of IFxxx (i.e., IFNE for IFEQ)
+ // and where <l'> designates the instruction just after
+ // the GOTO_W.
+ if (opcode == Opcodes.GOTO) {
+ newCode.putByte(200); // GOTO_W
+ } else if (opcode == Opcodes.JSR) {
+ newCode.putByte(201); // JSR_W
+ } else {
+ newCode.putByte(opcode <= 166 ? ((opcode + 1) ^ 1) - 1
+ : opcode ^ 1);
+ newCode.putShort(8); // jump offset
+ newCode.putByte(200); // GOTO_W
+ // newOffset now computed from start of GOTO_W
+ newOffset -= 3;
+ }
+ newCode.putInt(newOffset);
+ } else {
+ newCode.putByte(opcode);
+ newCode.putShort(newOffset);
+ }
+ u += 3;
+ break;
+ case ClassWriter.LABELW_INSN:
+ label = u + readInt(b, u + 1);
+ newOffset = getNewOffset(allIndexes, allSizes, u, label);
+ newCode.putByte(opcode);
+ newCode.putInt(newOffset);
+ u += 5;
+ break;
+ case ClassWriter.TABL_INSN:
+ // skips 0 to 3 padding bytes
+ v = u;
+ u = u + 4 - (v & 3);
+ // reads and copies instruction
+ newCode.putByte(Opcodes.TABLESWITCH);
+ newCode.putByteArray(null, 0, (4 - newCode.length % 4) % 4);
+ label = v + readInt(b, u);
+ u += 4;
+ newOffset = getNewOffset(allIndexes, allSizes, v, label);
+ newCode.putInt(newOffset);
+ j = readInt(b, u);
+ u += 4;
+ newCode.putInt(j);
+ j = readInt(b, u) - j + 1;
+ u += 4;
+ newCode.putInt(readInt(b, u - 4));
+ for (; j > 0; --j) {
+ label = v + readInt(b, u);
+ u += 4;
+ newOffset = getNewOffset(allIndexes, allSizes, v, label);
+ newCode.putInt(newOffset);
+ }
+ break;
+ case ClassWriter.LOOK_INSN:
+ // skips 0 to 3 padding bytes
+ v = u;
+ u = u + 4 - (v & 3);
+ // reads and copies instruction
+ newCode.putByte(Opcodes.LOOKUPSWITCH);
+ newCode.putByteArray(null, 0, (4 - newCode.length % 4) % 4);
+ label = v + readInt(b, u);
+ u += 4;
+ newOffset = getNewOffset(allIndexes, allSizes, v, label);
+ newCode.putInt(newOffset);
+ j = readInt(b, u);
+ u += 4;
+ newCode.putInt(j);
+ for (; j > 0; --j) {
+ newCode.putInt(readInt(b, u));
+ u += 4;
+ label = v + readInt(b, u);
+ u += 4;
+ newOffset = getNewOffset(allIndexes, allSizes, v, label);
+ newCode.putInt(newOffset);
+ }
+ break;
+ case ClassWriter.WIDE_INSN:
+ opcode = b[u + 1] & 0xFF;
+ if (opcode == Opcodes.IINC) {
+ newCode.putByteArray(b, u, 6);
+ u += 6;
+ } else {
+ newCode.putByteArray(b, u, 4);
+ u += 4;
+ }
+ break;
+ case ClassWriter.VAR_INSN:
+ case ClassWriter.SBYTE_INSN:
+ case ClassWriter.LDC_INSN:
+ newCode.putByteArray(b, u, 2);
+ u += 2;
+ break;
+ case ClassWriter.SHORT_INSN:
+ case ClassWriter.LDCW_INSN:
+ case ClassWriter.FIELDORMETH_INSN:
+ case ClassWriter.TYPE_INSN:
+ case ClassWriter.IINC_INSN:
+ newCode.putByteArray(b, u, 3);
+ u += 3;
+ break;
+ case ClassWriter.ITFMETH_INSN:
+ case ClassWriter.INDYMETH_INSN:
+ newCode.putByteArray(b, u, 5);
+ u += 5;
+ break;
+ // case MANA_INSN:
+ default:
+ newCode.putByteArray(b, u, 4);
+ u += 4;
+ break;
}
}
@@ -2471,8 +2478,7 @@ class MethodWriter extends MethodVisitor {
* must therefore never have been called for this label.
*/
u = l.position - 3;
- if ((l.status & Label.STORE) != 0 || (u >= 0 && resize[u]))
- {
+ if ((l.status & Label.STORE) != 0 || (u >= 0 && resize[u])) {
getNewOffset(allIndexes, allSizes, l);
// TODO update offsets in UNINITIALIZED values
visitFrame(l.frame);
@@ -2528,10 +2534,11 @@ class MethodWriter extends MethodVisitor {
b = lineNumber.data;
u = 0;
while (u < lineNumber.length) {
- writeShort(b, u, getNewOffset(allIndexes,
- allSizes,
- 0,
- readUnsignedShort(b, u)));
+ writeShort(
+ b,
+ u,
+ getNewOffset(allIndexes, allSizes, 0,
+ readUnsignedShort(b, u)));
u += 4;
}
}
@@ -2554,8 +2561,10 @@ class MethodWriter extends MethodVisitor {
/**
* Reads an unsigned short value in the given byte array.
*
- * @param b a byte array.
- * @param index the start index of the value to be read.
+ * @param b
+ * a byte array.
+ * @param index
+ * the start index of the value to be read.
* @return the read value.
*/
static int readUnsignedShort(final byte[] b, final int index) {
@@ -2565,8 +2574,10 @@ class MethodWriter extends MethodVisitor {
/**
* Reads a signed short value in the given byte array.
*
- * @param b a byte array.
- * @param index the start index of the value to be read.
+ * @param b
+ * a byte array.
+ * @param index
+ * the start index of the value to be read.
* @return the read value.
*/
static short readShort(final byte[] b, final int index) {
@@ -2576,8 +2587,10 @@ class MethodWriter extends MethodVisitor {
/**
* Reads a signed int value in the given byte array.
*
- * @param b a byte array.
- * @param index the start index of the value to be read.
+ * @param b
+ * a byte array.
+ * @param index
+ * the start index of the value to be read.
* @return the read value.
*/
static int readInt(final byte[] b, final int index) {
@@ -2588,9 +2601,12 @@ class MethodWriter extends MethodVisitor {
/**
* Writes a short value in the given byte array.
*
- * @param b a byte array.
- * @param index where the first byte of the short value must be written.
- * @param s the value to be written in the given byte array.
+ * @param b
+ * a byte array.
+ * @param index
+ * where the first byte of the short value must be written.
+ * @param s
+ * the value to be written in the given byte array.
*/
static void writeShort(final byte[] b, final int index, final int s) {
b[index] = (byte) (s >>> 8);
@@ -2598,32 +2614,34 @@ class MethodWriter extends MethodVisitor {
}
/**
- * Computes the future value of a bytecode offset. <p> Note: it is possible
- * to have several entries for the same instruction in the <tt>indexes</tt>
- * and <tt>sizes</tt>: two entries (index=a,size=b) and (index=a,size=b')
- * are equivalent to a single entry (index=a,size=b+b').
+ * Computes the future value of a bytecode offset.
+ * <p>
+ * Note: it is possible to have several entries for the same instruction in
+ * the <tt>indexes</tt> and <tt>sizes</tt>: two entries (index=a,size=b) and
+ * (index=a,size=b') are equivalent to a single entry (index=a,size=b+b').
*
- * @param indexes current positions of the instructions to be resized. Each
- * instruction must be designated by the index of its <i>last</i>
- * byte, plus one (or, in other words, by the index of the <i>first</i>
- * byte of the <i>next</i> instruction).
- * @param sizes the number of bytes to be <i>added</i> to the above
- * instructions. More precisely, for each i < <tt>len</tt>,
- * <tt>sizes</tt>[i] bytes will be added at the end of the
- * instruction designated by <tt>indexes</tt>[i] or, if
- * <tt>sizes</tt>[i] is negative, the <i>last</i> |<tt>sizes[i]</tt>|
- * bytes of the instruction will be removed (the instruction size
- * <i>must not</i> become negative or null).
- * @param begin index of the first byte of the source instruction.
- * @param end index of the first byte of the target instruction.
+ * @param indexes
+ * current positions of the instructions to be resized. Each
+ * instruction must be designated by the index of its <i>last</i>
+ * byte, plus one (or, in other words, by the index of the
+ * <i>first</i> byte of the <i>next</i> instruction).
+ * @param sizes
+ * the number of bytes to be <i>added</i> to the above
+ * instructions. More precisely, for each i < <tt>len</tt>,
+ * <tt>sizes</tt>[i] bytes will be added at the end of the
+ * instruction designated by <tt>indexes</tt>[i] or, if
+ * <tt>sizes</tt>[i] is negative, the <i>last</i> |
+ * <tt>sizes[i]</tt>| bytes of the instruction will be removed
+ * (the instruction size <i>must not</i> become negative or
+ * null).
+ * @param begin
+ * index of the first byte of the source instruction.
+ * @param end
+ * index of the first byte of the target instruction.
* @return the future value of the given bytecode offset.
*/
- static int getNewOffset(
- final int[] indexes,
- final int[] sizes,
- final int begin,
- final int end)
- {
+ static int getNewOffset(final int[] indexes, final int[] sizes,
+ final int begin, final int end) {
int offset = end - begin;
for (int i = 0; i < indexes.length; ++i) {
if (begin < indexes[i] && indexes[i] <= end) {
@@ -2640,24 +2658,25 @@ class MethodWriter extends MethodVisitor {
/**
* Updates the offset of the given label.
*
- * @param indexes current positions of the instructions to be resized. Each
- * instruction must be designated by the index of its <i>last</i>
- * byte, plus one (or, in other words, by the index of the <i>first</i>
- * byte of the <i>next</i> instruction).
- * @param sizes the number of bytes to be <i>added</i> to the above
- * instructions. More precisely, for each i < <tt>len</tt>,
- * <tt>sizes</tt>[i] bytes will be added at the end of the
- * instruction designated by <tt>indexes</tt>[i] or, if
- * <tt>sizes</tt>[i] is negative, the <i>last</i> |<tt>sizes[i]</tt>|
- * bytes of the instruction will be removed (the instruction size
- * <i>must not</i> become negative or null).
- * @param label the label whose offset must be updated.
- */
- static void getNewOffset(
- final int[] indexes,
- final int[] sizes,
- final Label label)
- {
+ * @param indexes
+ * current positions of the instructions to be resized. Each
+ * instruction must be designated by the index of its <i>last</i>
+ * byte, plus one (or, in other words, by the index of the
+ * <i>first</i> byte of the <i>next</i> instruction).
+ * @param sizes
+ * the number of bytes to be <i>added</i> to the above
+ * instructions. More precisely, for each i < <tt>len</tt>,
+ * <tt>sizes</tt>[i] bytes will be added at the end of the
+ * instruction designated by <tt>indexes</tt>[i] or, if
+ * <tt>sizes</tt>[i] is negative, the <i>last</i> |
+ * <tt>sizes[i]</tt>| bytes of the instruction will be removed
+ * (the instruction size <i>must not</i> become negative or
+ * null).
+ * @param label
+ * the label whose offset must be updated.
+ */
+ static void getNewOffset(final int[] indexes, final int[] sizes,
+ final Label label) {
if ((label.status & Label.RESIZED) == 0) {
label.position = getNewOffset(indexes, sizes, 0, label.position);
label.status |= Label.RESIZED;
diff --git a/src/asm/scala/tools/asm/Type.java b/src/asm/scala/tools/asm/Type.java
index bf1107182a..7821a492e6 100644
--- a/src/asm/scala/tools/asm/Type.java
+++ b/src/asm/scala/tools/asm/Type.java
@@ -190,13 +190,16 @@ public class Type {
/**
* Constructs a reference type.
*
- * @param sort the sort of the reference type to be constructed.
- * @param buf a buffer containing the descriptor of the previous type.
- * @param off the offset of this descriptor in the previous buffer.
- * @param len the length of this descriptor.
- */
- private Type(final int sort, final char[] buf, final int off, final int len)
- {
+ * @param sort
+ * the sort of the reference type to be constructed.
+ * @param buf
+ * a buffer containing the descriptor of the previous type.
+ * @param off
+ * the offset of this descriptor in the previous buffer.
+ * @param len
+ * the length of this descriptor.
+ */
+ private Type(final int sort, final char[] buf, final int off, final int len) {
this.sort = sort;
this.buf = buf;
this.off = off;
@@ -206,7 +209,8 @@ public class Type {
/**
* Returns the Java type corresponding to the given type descriptor.
*
- * @param typeDescriptor a field or method type descriptor.
+ * @param typeDescriptor
+ * a field or method type descriptor.
* @return the Java type corresponding to the given type descriptor.
*/
public static Type getType(final String typeDescriptor) {
@@ -216,7 +220,8 @@ public class Type {
/**
* Returns the Java type corresponding to the given internal name.
*
- * @param internalName an internal name.
+ * @param internalName
+ * an internal name.
* @return the Java type corresponding to the given internal name.
*/
public static Type getObjectType(final String internalName) {
@@ -228,7 +233,8 @@ public class Type {
* Returns the Java type corresponding to the given method descriptor.
* Equivalent to <code>Type.getType(methodDescriptor)</code>.
*
- * @param methodDescriptor a method descriptor.
+ * @param methodDescriptor
+ * a method descriptor.
* @return the Java type corresponding to the given method descriptor.
*/
public static Type getMethodType(final String methodDescriptor) {
@@ -239,18 +245,23 @@ public class Type {
* Returns the Java method type corresponding to the given argument and
* return types.
*
- * @param returnType the return type of the method.
- * @param argumentTypes the argument types of the method.
- * @return the Java type corresponding to the given argument and return types.
+ * @param returnType
+ * the return type of the method.
+ * @param argumentTypes
+ * the argument types of the method.
+ * @return the Java type corresponding to the given argument and return
+ * types.
*/
- public static Type getMethodType(final Type returnType, final Type... argumentTypes) {
+ public static Type getMethodType(final Type returnType,
+ final Type... argumentTypes) {
return getType(getMethodDescriptor(returnType, argumentTypes));
}
/**
* Returns the Java type corresponding to the given class.
*
- * @param c a class.
+ * @param c
+ * a class.
* @return the Java type corresponding to the given class.
*/
public static Type getType(final Class<?> c) {
@@ -282,7 +293,8 @@ public class Type {
/**
* Returns the Java method type corresponding to the given constructor.
*
- * @param c a {@link Constructor Constructor} object.
+ * @param c
+ * a {@link Constructor Constructor} object.
* @return the Java method type corresponding to the given constructor.
*/
public static Type getType(final Constructor<?> c) {
@@ -292,7 +304,8 @@ public class Type {
/**
* Returns the Java method type corresponding to the given method.
*
- * @param m a {@link Method Method} object.
+ * @param m
+ * a {@link Method Method} object.
* @return the Java method type corresponding to the given method.
*/
public static Type getType(final Method m) {
@@ -303,7 +316,8 @@ public class Type {
* Returns the Java types corresponding to the argument types of the given
* method descriptor.
*
- * @param methodDescriptor a method descriptor.
+ * @param methodDescriptor
+ * a method descriptor.
* @return the Java types corresponding to the argument types of the given
* method descriptor.
*/
@@ -338,7 +352,8 @@ public class Type {
* Returns the Java types corresponding to the argument types of the given
* method.
*
- * @param method a method.
+ * @param method
+ * a method.
* @return the Java types corresponding to the argument types of the given
* method.
*/
@@ -355,7 +370,8 @@ public class Type {
* Returns the Java type corresponding to the return type of the given
* method descriptor.
*
- * @param methodDescriptor a method descriptor.
+ * @param methodDescriptor
+ * a method descriptor.
* @return the Java type corresponding to the return type of the given
* method descriptor.
*/
@@ -368,7 +384,8 @@ public class Type {
* Returns the Java type corresponding to the return type of the given
* method.
*
- * @param method a method.
+ * @param method
+ * a method.
* @return the Java type corresponding to the return type of the given
* method.
*/
@@ -379,12 +396,13 @@ public class Type {
/**
* Computes the size of the arguments and of the return value of a method.
*
- * @param desc the descriptor of a method.
+ * @param desc
+ * the descriptor of a method.
* @return the size of the arguments of the method (plus one for the
* implicit this argument), argSize, and the size of its return
* value, retSize, packed into a single int i =
- * <tt>(argSize << 2) | retSize</tt> (argSize is therefore equal
- * to <tt>i >> 2</tt>, and retSize to <tt>i & 0x03</tt>).
+ * <tt>(argSize << 2) | retSize</tt> (argSize is therefore equal to
+ * <tt>i >> 2</tt>, and retSize to <tt>i & 0x03</tt>).
*/
public static int getArgumentsAndReturnSizes(final String desc) {
int n = 1;
@@ -419,52 +437,54 @@ public class Type {
* method descriptors, buf is supposed to contain nothing more than the
* descriptor itself.
*
- * @param buf a buffer containing a type descriptor.
- * @param off the offset of this descriptor in the previous buffer.
+ * @param buf
+ * a buffer containing a type descriptor.
+ * @param off
+ * the offset of this descriptor in the previous buffer.
* @return the Java type corresponding to the given type descriptor.
*/
private static Type getType(final char[] buf, final int off) {
int len;
switch (buf[off]) {
- case 'V':
- return VOID_TYPE;
- case 'Z':
- return BOOLEAN_TYPE;
- case 'C':
- return CHAR_TYPE;
- case 'B':
- return BYTE_TYPE;
- case 'S':
- return SHORT_TYPE;
- case 'I':
- return INT_TYPE;
- case 'F':
- return FLOAT_TYPE;
- case 'J':
- return LONG_TYPE;
- case 'D':
- return DOUBLE_TYPE;
- case '[':
- len = 1;
- while (buf[off + len] == '[') {
- ++len;
- }
- if (buf[off + len] == 'L') {
- ++len;
- while (buf[off + len] != ';') {
- ++len;
- }
- }
- return new Type(ARRAY, buf, off, len + 1);
- case 'L':
- len = 1;
+ case 'V':
+ return VOID_TYPE;
+ case 'Z':
+ return BOOLEAN_TYPE;
+ case 'C':
+ return CHAR_TYPE;
+ case 'B':
+ return BYTE_TYPE;
+ case 'S':
+ return SHORT_TYPE;
+ case 'I':
+ return INT_TYPE;
+ case 'F':
+ return FLOAT_TYPE;
+ case 'J':
+ return LONG_TYPE;
+ case 'D':
+ return DOUBLE_TYPE;
+ case '[':
+ len = 1;
+ while (buf[off + len] == '[') {
+ ++len;
+ }
+ if (buf[off + len] == 'L') {
+ ++len;
while (buf[off + len] != ';') {
++len;
}
- return new Type(OBJECT, buf, off + 1, len - 1);
+ }
+ return new Type(ARRAY, buf, off, len + 1);
+ case 'L':
+ len = 1;
+ while (buf[off + len] != ';') {
+ ++len;
+ }
+ return new Type(OBJECT, buf, off + 1, len - 1);
// case '(':
- default:
- return new Type(METHOD, buf, 0, buf.length);
+ default:
+ return new Type(METHOD, buf, off, buf.length - off);
}
}
@@ -475,11 +495,11 @@ public class Type {
/**
* Returns the sort of this Java type.
*
- * @return {@link #VOID VOID}, {@link #BOOLEAN BOOLEAN},
- * {@link #CHAR CHAR}, {@link #BYTE BYTE}, {@link #SHORT SHORT},
- * {@link #INT INT}, {@link #FLOAT FLOAT}, {@link #LONG LONG},
- * {@link #DOUBLE DOUBLE}, {@link #ARRAY ARRAY},
- * {@link #OBJECT OBJECT} or {@link #METHOD METHOD}.
+ * @return {@link #VOID VOID}, {@link #BOOLEAN BOOLEAN}, {@link #CHAR CHAR},
+ * {@link #BYTE BYTE}, {@link #SHORT SHORT}, {@link #INT INT},
+ * {@link #FLOAT FLOAT}, {@link #LONG LONG}, {@link #DOUBLE DOUBLE},
+ * {@link #ARRAY ARRAY}, {@link #OBJECT OBJECT} or {@link #METHOD
+ * METHOD}.
*/
public int getSort() {
return sort;
@@ -517,34 +537,34 @@ public class Type {
*/
public String getClassName() {
switch (sort) {
- case VOID:
- return "void";
- case BOOLEAN:
- return "boolean";
- case CHAR:
- return "char";
- case BYTE:
- return "byte";
- case SHORT:
- return "short";
- case INT:
- return "int";
- case FLOAT:
- return "float";
- case LONG:
- return "long";
- case DOUBLE:
- return "double";
- case ARRAY:
- StringBuffer b = new StringBuffer(getElementType().getClassName());
- for (int i = getDimensions(); i > 0; --i) {
- b.append("[]");
- }
- return b.toString();
- case OBJECT:
- return new String(buf, off, len).replace('/', '.');
- default:
- return null;
+ case VOID:
+ return "void";
+ case BOOLEAN:
+ return "boolean";
+ case CHAR:
+ return "char";
+ case BYTE:
+ return "byte";
+ case SHORT:
+ return "short";
+ case INT:
+ return "int";
+ case FLOAT:
+ return "float";
+ case LONG:
+ return "long";
+ case DOUBLE:
+ return "double";
+ case ARRAY:
+ StringBuffer b = new StringBuffer(getElementType().getClassName());
+ for (int i = getDimensions(); i > 0; --i) {
+ b.append("[]");
+ }
+ return b.toString();
+ case OBJECT:
+ return new String(buf, off, len).replace('/', '.');
+ default:
+ return null;
}
}
@@ -613,15 +633,15 @@ public class Type {
* Returns the descriptor corresponding to the given argument and return
* types.
*
- * @param returnType the return type of the method.
- * @param argumentTypes the argument types of the method.
+ * @param returnType
+ * the return type of the method.
+ * @param argumentTypes
+ * the argument types of the method.
* @return the descriptor corresponding to the given argument and return
* types.
*/
- public static String getMethodDescriptor(
- final Type returnType,
- final Type... argumentTypes)
- {
+ public static String getMethodDescriptor(final Type returnType,
+ final Type... argumentTypes) {
StringBuffer buf = new StringBuffer();
buf.append('(');
for (int i = 0; i < argumentTypes.length; ++i) {
@@ -636,11 +656,13 @@ public class Type {
* Appends the descriptor corresponding to this Java type to the given
* string buffer.
*
- * @param buf the string buffer to which the descriptor must be appended.
+ * @param buf
+ * the string buffer to which the descriptor must be appended.
*/
private void getDescriptor(final StringBuffer buf) {
if (this.buf == null) {
- // descriptor is in byte 3 of 'off' for primitive types (buf == null)
+ // descriptor is in byte 3 of 'off' for primitive types (buf ==
+ // null)
buf.append((char) ((off & 0xFF000000) >>> 24));
} else if (sort == OBJECT) {
buf.append('L');
@@ -661,7 +683,8 @@ public class Type {
* class is its fully qualified name, as returned by Class.getName(), where
* '.' are replaced by '/'.
*
- * @param c an object or array class.
+ * @param c
+ * an object or array class.
* @return the internal name of the given class.
*/
public static String getInternalName(final Class<?> c) {
@@ -671,7 +694,8 @@ public class Type {
/**
* Returns the descriptor corresponding to the given Java type.
*
- * @param c an object class, a primitive class or an array class.
+ * @param c
+ * an object class, a primitive class or an array class.
* @return the descriptor corresponding to the given class.
*/
public static String getDescriptor(final Class<?> c) {
@@ -683,7 +707,8 @@ public class Type {
/**
* Returns the descriptor corresponding to the given constructor.
*
- * @param c a {@link Constructor Constructor} object.
+ * @param c
+ * a {@link Constructor Constructor} object.
* @return the descriptor of the given constructor.
*/
public static String getConstructorDescriptor(final Constructor<?> c) {
@@ -699,7 +724,8 @@ public class Type {
/**
* Returns the descriptor corresponding to the given method.
*
- * @param m a {@link Method Method} object.
+ * @param m
+ * a {@link Method Method} object.
* @return the descriptor of the given method.
*/
public static String getMethodDescriptor(final Method m) {
@@ -717,8 +743,10 @@ public class Type {
/**
* Appends the descriptor of the given class to the given string buffer.
*
- * @param buf the string buffer to which the descriptor must be appended.
- * @param c the class whose descriptor must be computed.
+ * @param buf
+ * the string buffer to which the descriptor must be appended.
+ * @param c
+ * the class whose descriptor must be computed.
*/
private static void getDescriptor(final StringBuffer buf, final Class<?> c) {
Class<?> d = c;
@@ -783,9 +811,10 @@ public class Type {
* Returns a JVM instruction opcode adapted to this Java type. This method
* must not be used for method types.
*
- * @param opcode a JVM instruction opcode. This opcode must be one of ILOAD,
- * ISTORE, IALOAD, IASTORE, IADD, ISUB, IMUL, IDIV, IREM, INEG, ISHL,
- * ISHR, IUSHR, IAND, IOR, IXOR and IRETURN.
+ * @param opcode
+ * a JVM instruction opcode. This opcode must be one of ILOAD,
+ * ISTORE, IALOAD, IASTORE, IADD, ISUB, IMUL, IDIV, IREM, INEG,
+ * ISHL, ISHR, IUSHR, IAND, IOR, IXOR and IRETURN.
* @return an opcode that is similar to the given opcode, but adapted to
* this Java type. For example, if this type is <tt>float</tt> and
* <tt>opcode</tt> is IRETURN, this method returns FRETURN.
@@ -809,7 +838,8 @@ public class Type {
/**
* Tests if the given object is equal to this type.
*
- * @param o the object to be compared to this type.
+ * @param o
+ * the object to be compared to this type.
* @return <tt>true</tt> if the given object is equal to this type.
*/
@Override
diff --git a/src/asm/scala/tools/asm/signature/SignatureReader.java b/src/asm/scala/tools/asm/signature/SignatureReader.java
index 22e6427e63..9c7c3880d9 100644
--- a/src/asm/scala/tools/asm/signature/SignatureReader.java
+++ b/src/asm/scala/tools/asm/signature/SignatureReader.java
@@ -46,8 +46,9 @@ public class SignatureReader {
/**
* Constructs a {@link SignatureReader} for the given signature.
*
- * @param signature A <i>ClassSignature</i>, <i>MethodTypeSignature</i>,
- * or <i>FieldTypeSignature</i>.
+ * @param signature
+ * A <i>ClassSignature</i>, <i>MethodTypeSignature</i>, or
+ * <i>FieldTypeSignature</i>.
*/
public SignatureReader(final String signature) {
this.signature = signature;
@@ -58,15 +59,15 @@ public class SignatureReader {
* {@link SignatureReader}. This signature is the one specified in the
* constructor (see {@link #SignatureReader(String) SignatureReader}). This
* method is intended to be called on a {@link SignatureReader} that was
- * created using a <i>ClassSignature</i> (such as the
+ * created using a <i>ClassSignature</i> (such as the <code>signature</code>
+ * parameter of the {@link scala.tools.asm.ClassVisitor#visit
+ * ClassVisitor.visit} method) or a <i>MethodTypeSignature</i> (such as the
* <code>signature</code> parameter of the
- * {@link org.objectweb.asm.ClassVisitor#visit ClassVisitor.visit} method)
- * or a <i>MethodTypeSignature</i> (such as the <code>signature</code>
- * parameter of the
- * {@link org.objectweb.asm.ClassVisitor#visitMethod ClassVisitor.visitMethod}
- * method).
+ * {@link scala.tools.asm.ClassVisitor#visitMethod
+ * ClassVisitor.visitMethod} method).
*
- * @param v the visitor that must visit this signature.
+ * @param v
+ * the visitor that must visit this signature.
*/
public void accept(final SignatureVisitor v) {
String signature = this.signature;
@@ -118,12 +119,12 @@ public class SignatureReader {
* method is intended to be called on a {@link SignatureReader} that was
* created using a <i>FieldTypeSignature</i>, such as the
* <code>signature</code> parameter of the
- * {@link org.objectweb.asm.ClassVisitor#visitField
- * ClassVisitor.visitField} or {@link
- * org.objectweb.asm.MethodVisitor#visitLocalVariable
+ * {@link scala.tools.asm.ClassVisitor#visitField ClassVisitor.visitField}
+ * or {@link scala.tools.asm.MethodVisitor#visitLocalVariable
* MethodVisitor.visitLocalVariable} methods.
*
- * @param v the visitor that must visit this signature.
+ * @param v
+ * the visitor that must visit this signature.
*/
public void acceptType(final SignatureVisitor v) {
parseType(this.signature, 0, v);
@@ -132,98 +133,96 @@ public class SignatureReader {
/**
* Parses a field type signature and makes the given visitor visit it.
*
- * @param signature a string containing the signature that must be parsed.
- * @param pos index of the first character of the signature to parsed.
- * @param v the visitor that must visit this signature.
+ * @param signature
+ * a string containing the signature that must be parsed.
+ * @param pos
+ * index of the first character of the signature to parsed.
+ * @param v
+ * the visitor that must visit this signature.
* @return the index of the first character after the parsed signature.
*/
- private static int parseType(
- final String signature,
- int pos,
- final SignatureVisitor v)
- {
+ private static int parseType(final String signature, int pos,
+ final SignatureVisitor v) {
char c;
int start, end;
boolean visited, inner;
String name;
switch (c = signature.charAt(pos++)) {
- case 'Z':
- case 'C':
- case 'B':
- case 'S':
- case 'I':
- case 'F':
- case 'J':
- case 'D':
- case 'V':
- v.visitBaseType(c);
- return pos;
+ case 'Z':
+ case 'C':
+ case 'B':
+ case 'S':
+ case 'I':
+ case 'F':
+ case 'J':
+ case 'D':
+ case 'V':
+ v.visitBaseType(c);
+ return pos;
- case '[':
- return parseType(signature, pos, v.visitArrayType());
+ case '[':
+ return parseType(signature, pos, v.visitArrayType());
- case 'T':
- end = signature.indexOf(';', pos);
- v.visitTypeVariable(signature.substring(pos, end));
- return end + 1;
+ case 'T':
+ end = signature.indexOf(';', pos);
+ v.visitTypeVariable(signature.substring(pos, end));
+ return end + 1;
- default: // case 'L':
- start = pos;
- visited = false;
- inner = false;
- for (;;) {
- switch (c = signature.charAt(pos++)) {
- case '.':
- case ';':
- if (!visited) {
- name = signature.substring(start, pos - 1);
- if (inner) {
- v.visitInnerClassType(name);
- } else {
- v.visitClassType(name);
- }
- }
- if (c == ';') {
- v.visitEnd();
- return pos;
- }
- start = pos;
- visited = false;
- inner = true;
- break;
+ default: // case 'L':
+ start = pos;
+ visited = false;
+ inner = false;
+ for (;;) {
+ switch (c = signature.charAt(pos++)) {
+ case '.':
+ case ';':
+ if (!visited) {
+ name = signature.substring(start, pos - 1);
+ if (inner) {
+ v.visitInnerClassType(name);
+ } else {
+ v.visitClassType(name);
+ }
+ }
+ if (c == ';') {
+ v.visitEnd();
+ return pos;
+ }
+ start = pos;
+ visited = false;
+ inner = true;
+ break;
- case '<':
- name = signature.substring(start, pos - 1);
- if (inner) {
- v.visitInnerClassType(name);
- } else {
- v.visitClassType(name);
- }
- visited = true;
- top: for (;;) {
- switch (c = signature.charAt(pos)) {
- case '>':
- break top;
- case '*':
- ++pos;
- v.visitTypeArgument();
- break;
- case '+':
- case '-':
- pos = parseType(signature,
- pos + 1,
- v.visitTypeArgument(c));
- break;
- default:
- pos = parseType(signature,
- pos,
- v.visitTypeArgument('='));
- break;
- }
- }
+ case '<':
+ name = signature.substring(start, pos - 1);
+ if (inner) {
+ v.visitInnerClassType(name);
+ } else {
+ v.visitClassType(name);
+ }
+ visited = true;
+ top: for (;;) {
+ switch (c = signature.charAt(pos)) {
+ case '>':
+ break top;
+ case '*':
+ ++pos;
+ v.visitTypeArgument();
+ break;
+ case '+':
+ case '-':
+ pos = parseType(signature, pos + 1,
+ v.visitTypeArgument(c));
+ break;
+ default:
+ pos = parseType(signature, pos,
+ v.visitTypeArgument('='));
+ break;
+ }
}
}
+ }
}
}
}
diff --git a/src/asm/scala/tools/asm/signature/SignatureVisitor.java b/src/asm/scala/tools/asm/signature/SignatureVisitor.java
index 2fc364e374..f38f81f53b 100644
--- a/src/asm/scala/tools/asm/signature/SignatureVisitor.java
+++ b/src/asm/scala/tools/asm/signature/SignatureVisitor.java
@@ -35,21 +35,21 @@ import scala.tools.asm.Opcodes;
* A visitor to visit a generic signature. The methods of this interface must be
* called in one of the three following orders (the last one is the only valid
* order for a {@link SignatureVisitor} that is returned by a method of this
- * interface): <ul> <li><i>ClassSignature</i> = (
- * <tt>visitFormalTypeParameter</tt>
- * <tt>visitClassBound</tt>?
- * <tt>visitInterfaceBound</tt>* )* ( <tt>visitSuperClass</tt>
- * <tt>visitInterface</tt>* )</li>
+ * interface):
+ * <ul>
+ * <li><i>ClassSignature</i> = ( <tt>visitFormalTypeParameter</tt>
+ * <tt>visitClassBound</tt>? <tt>visitInterfaceBound</tt>* )* (
+ * <tt>visitSuperClass</tt> <tt>visitInterface</tt>* )</li>
* <li><i>MethodSignature</i> = ( <tt>visitFormalTypeParameter</tt>
- * <tt>visitClassBound</tt>?
- * <tt>visitInterfaceBound</tt>* )* ( <tt>visitParameterType</tt>*
- * <tt>visitReturnType</tt>
- * <tt>visitExceptionType</tt>* )</li> <li><i>TypeSignature</i> =
- * <tt>visitBaseType</tt> | <tt>visitTypeVariable</tt> |
- * <tt>visitArrayType</tt> | (
+ * <tt>visitClassBound</tt>? <tt>visitInterfaceBound</tt>* )* (
+ * <tt>visitParameterType</tt>* <tt>visitReturnType</tt>
+ * <tt>visitExceptionType</tt>* )</li>
+ * <li><i>TypeSignature</i> = <tt>visitBaseType</tt> |
+ * <tt>visitTypeVariable</tt> | <tt>visitArrayType</tt> | (
* <tt>visitClassType</tt> <tt>visitTypeArgument</tt>* (
- * <tt>visitInnerClassType</tt> <tt>visitTypeArgument</tt>* )*
- * <tt>visitEnd</tt> ) )</li> </ul>
+ * <tt>visitInnerClassType</tt> <tt>visitTypeArgument</tt>* )* <tt>visitEnd</tt>
+ * ) )</li>
+ * </ul>
*
* @author Thomas Hallgren
* @author Eric Bruneton
@@ -80,8 +80,9 @@ public abstract class SignatureVisitor {
/**
* Constructs a new {@link SignatureVisitor}.
*
- * @param api the ASM API version implemented by this visitor. Must be one
- * of {@link Opcodes#ASM4}.
+ * @param api
+ * the ASM API version implemented by this visitor. Must be one
+ * of {@link Opcodes#ASM4}.
*/
public SignatureVisitor(final int api) {
this.api = api;
@@ -90,7 +91,8 @@ public abstract class SignatureVisitor {
/**
* Visits a formal type parameter.
*
- * @param name the name of the formal parameter.
+ * @param name
+ * the name of the formal parameter.
*/
public void visitFormalTypeParameter(String name) {
}
@@ -162,8 +164,9 @@ public abstract class SignatureVisitor {
/**
* Visits a signature corresponding to a primitive type.
*
- * @param descriptor the descriptor of the primitive type, or 'V' for
- * <tt>void</tt>.
+ * @param descriptor
+ * the descriptor of the primitive type, or 'V' for <tt>void</tt>
+ * .
*/
public void visitBaseType(char descriptor) {
}
@@ -171,7 +174,8 @@ public abstract class SignatureVisitor {
/**
* Visits a signature corresponding to a type variable.
*
- * @param name the name of the type variable.
+ * @param name
+ * the name of the type variable.
*/
public void visitTypeVariable(String name) {
}
@@ -190,7 +194,8 @@ public abstract class SignatureVisitor {
* Starts the visit of a signature corresponding to a class or interface
* type.
*
- * @param name the internal name of the class or interface.
+ * @param name
+ * the internal name of the class or interface.
*/
public void visitClassType(String name) {
}
@@ -198,7 +203,8 @@ public abstract class SignatureVisitor {
/**
* Visits an inner class.
*
- * @param name the local name of the inner class in its enclosing class.
+ * @param name
+ * the local name of the inner class in its enclosing class.
*/
public void visitInnerClassType(String name) {
}
@@ -213,7 +219,8 @@ public abstract class SignatureVisitor {
/**
* Visits a type argument of the last visited class or inner class type.
*
- * @param wildcard '+', '-' or '='.
+ * @param wildcard
+ * '+', '-' or '='.
* @return a non null visitor to visit the signature of the type argument.
*/
public SignatureVisitor visitTypeArgument(char wildcard) {
diff --git a/src/asm/scala/tools/asm/signature/SignatureWriter.java b/src/asm/scala/tools/asm/signature/SignatureWriter.java
index a59fdfde2b..ebf4fe07b4 100644
--- a/src/asm/scala/tools/asm/signature/SignatureWriter.java
+++ b/src/asm/scala/tools/asm/signature/SignatureWriter.java
@@ -224,4 +224,4 @@ public class SignatureWriter extends SignatureVisitor {
}
argumentStack /= 2;
}
-} \ No newline at end of file
+}
diff --git a/src/asm/scala/tools/asm/tree/AbstractInsnNode.java b/src/asm/scala/tools/asm/tree/AbstractInsnNode.java
index 471f842ffc..411eead3c7 100644
--- a/src/asm/scala/tools/asm/tree/AbstractInsnNode.java
+++ b/src/asm/scala/tools/asm/tree/AbstractInsnNode.java
@@ -148,7 +148,8 @@ public abstract class AbstractInsnNode {
/**
* Constructs a new {@link AbstractInsnNode}.
*
- * @param opcode the opcode of the instruction to be constructed.
+ * @param opcode
+ * the opcode of the instruction to be constructed.
*/
protected AbstractInsnNode(final int opcode) {
this.opcode = opcode;
@@ -197,38 +198,47 @@ public abstract class AbstractInsnNode {
/**
* Makes the given code visitor visit this instruction.
*
- * @param cv a code visitor.
+ * @param cv
+ * a code visitor.
*/
public abstract void accept(final MethodVisitor cv);
/**
* Returns a copy of this instruction.
*
- * @param labels a map from LabelNodes to cloned LabelNodes.
+ * @param labels
+ * a map from LabelNodes to cloned LabelNodes.
* @return a copy of this instruction. The returned instruction does not
* belong to any {@link InsnList}.
*/
- public abstract AbstractInsnNode clone(final Map<LabelNode, LabelNode> labels);
+ public abstract AbstractInsnNode clone(
+ final Map<LabelNode, LabelNode> labels);
/**
* Returns the clone of the given label.
*
- * @param label a label.
- * @param map a map from LabelNodes to cloned LabelNodes.
+ * @param label
+ * a label.
+ * @param map
+ * a map from LabelNodes to cloned LabelNodes.
* @return the clone of the given label.
*/
- static LabelNode clone(final LabelNode label, final Map<LabelNode, LabelNode> map) {
+ static LabelNode clone(final LabelNode label,
+ final Map<LabelNode, LabelNode> map) {
return map.get(label);
}
/**
* Returns the clones of the given labels.
*
- * @param labels a list of labels.
- * @param map a map from LabelNodes to cloned LabelNodes.
+ * @param labels
+ * a list of labels.
+ * @param map
+ * a map from LabelNodes to cloned LabelNodes.
* @return the clones of the given labels.
*/
- static LabelNode[] clone(final List<LabelNode> labels, final Map<LabelNode, LabelNode> map) {
+ static LabelNode[] clone(final List<LabelNode> labels,
+ final Map<LabelNode, LabelNode> map) {
LabelNode[] clones = new LabelNode[labels.size()];
for (int i = 0; i < clones.length; ++i) {
clones[i] = map.get(labels.get(i));
diff --git a/src/asm/scala/tools/asm/tree/AnnotationNode.java b/src/asm/scala/tools/asm/tree/AnnotationNode.java
index 9f132550e6..1f4beef9f7 100644
--- a/src/asm/scala/tools/asm/tree/AnnotationNode.java
+++ b/src/asm/scala/tools/asm/tree/AnnotationNode.java
@@ -52,11 +52,11 @@ public class AnnotationNode extends AnnotationVisitor {
* as two consecutive elements in the list. The name is a {@link String},
* and the value may be a {@link Byte}, {@link Boolean}, {@link Character},
* {@link Short}, {@link Integer}, {@link Long}, {@link Float},
- * {@link Double}, {@link String} or {@link org.objectweb.asm.Type}, or an
+ * {@link Double}, {@link String} or {@link scala.tools.asm.Type}, or an
* two elements String array (for enumeration values), a
* {@link AnnotationNode}, or a {@link List} of values of one of the
- * preceding types. The list may be <tt>null</tt> if there is no name
- * value pair.
+ * preceding types. The list may be <tt>null</tt> if there is no name value
+ * pair.
*/
public List<Object> values;
@@ -65,7 +65,8 @@ public class AnnotationNode extends AnnotationVisitor {
* constructor</i>. Instead, they must use the
* {@link #AnnotationNode(int, String)} version.
*
- * @param desc the class descriptor of the annotation class.
+ * @param desc
+ * the class descriptor of the annotation class.
*/
public AnnotationNode(final String desc) {
this(Opcodes.ASM4, desc);
@@ -74,9 +75,11 @@ public class AnnotationNode extends AnnotationVisitor {
/**
* Constructs a new {@link AnnotationNode}.
*
- * @param api the ASM API version implemented by this visitor. Must be one
- * of {@link Opcodes#ASM4}.
- * @param desc the class descriptor of the annotation class.
+ * @param api
+ * the ASM API version implemented by this visitor. Must be one
+ * of {@link Opcodes#ASM4}.
+ * @param desc
+ * the class descriptor of the annotation class.
*/
public AnnotationNode(final int api, final String desc) {
super(api);
@@ -86,7 +89,8 @@ public class AnnotationNode extends AnnotationVisitor {
/**
* Constructs a new {@link AnnotationNode} to visit an array value.
*
- * @param values where the visited values must be stored.
+ * @param values
+ * where the visited values must be stored.
*/
AnnotationNode(final List<Object> values) {
super(Opcodes.ASM4);
@@ -109,11 +113,8 @@ public class AnnotationNode extends AnnotationVisitor {
}
@Override
- public void visitEnum(
- final String name,
- final String desc,
- final String value)
- {
+ public void visitEnum(final String name, final String desc,
+ final String value) {
if (values == null) {
values = new ArrayList<Object>(this.desc != null ? 2 : 1);
}
@@ -124,10 +125,8 @@ public class AnnotationNode extends AnnotationVisitor {
}
@Override
- public AnnotationVisitor visitAnnotation(
- final String name,
- final String desc)
- {
+ public AnnotationVisitor visitAnnotation(final String name,
+ final String desc) {
if (values == null) {
values = new ArrayList<Object>(this.desc != null ? 2 : 1);
}
@@ -166,7 +165,8 @@ public class AnnotationNode extends AnnotationVisitor {
* recursively, do not contain elements that were introduced in more recent
* versions of the ASM API than the given version.
*
- * @param api an ASM API version. Must be one of {@link Opcodes#ASM4}.
+ * @param api
+ * an ASM API version. Must be one of {@link Opcodes#ASM4}.
*/
public void check(final int api) {
// nothing to do
@@ -175,7 +175,8 @@ public class AnnotationNode extends AnnotationVisitor {
/**
* Makes the given visitor visit this annotation.
*
- * @param av an annotation visitor. Maybe <tt>null</tt>.
+ * @param av
+ * an annotation visitor. Maybe <tt>null</tt>.
*/
public void accept(final AnnotationVisitor av) {
if (av != null) {
@@ -193,15 +194,15 @@ public class AnnotationNode extends AnnotationVisitor {
/**
* Makes the given visitor visit a given annotation value.
*
- * @param av an annotation visitor. Maybe <tt>null</tt>.
- * @param name the value name.
- * @param value the actual value.
+ * @param av
+ * an annotation visitor. Maybe <tt>null</tt>.
+ * @param name
+ * the value name.
+ * @param value
+ * the actual value.
*/
- static void accept(
- final AnnotationVisitor av,
- final String name,
- final Object value)
- {
+ static void accept(final AnnotationVisitor av, final String name,
+ final Object value) {
if (av != null) {
if (value instanceof String[]) {
String[] typeconst = (String[]) value;
diff --git a/src/asm/scala/tools/asm/tree/ClassNode.java b/src/asm/scala/tools/asm/tree/ClassNode.java
index 64effae698..c3d999985a 100644
--- a/src/asm/scala/tools/asm/tree/ClassNode.java
+++ b/src/asm/scala/tools/asm/tree/ClassNode.java
@@ -53,33 +53,33 @@ public class ClassNode extends ClassVisitor {
public int version;
/**
- * The class's access flags (see {@link org.objectweb.asm.Opcodes}). This
+ * The class's access flags (see {@link scala.tools.asm.Opcodes}). This
* field also indicates if the class is deprecated.
*/
public int access;
/**
* The internal name of the class (see
- * {@link org.objectweb.asm.Type#getInternalName() getInternalName}).
+ * {@link scala.tools.asm.Type#getInternalName() getInternalName}).
*/
public String name;
/**
- * The signature of the class. Mayt be <tt>null</tt>.
+ * The signature of the class. May be <tt>null</tt>.
*/
public String signature;
/**
* The internal of name of the super class (see
- * {@link org.objectweb.asm.Type#getInternalName() getInternalName}). For
- * interfaces, the super class is {@link Object}. May be <tt>null</tt>,
- * but only for the {@link Object} class.
+ * {@link scala.tools.asm.Type#getInternalName() getInternalName}). For
+ * interfaces, the super class is {@link Object}. May be <tt>null</tt>, but
+ * only for the {@link Object} class.
*/
public String superName;
/**
* The internal names of the class's interfaces (see
- * {@link org.objectweb.asm.Type#getInternalName() getInternalName}). This
+ * {@link scala.tools.asm.Type#getInternalName() getInternalName}). This
* list is a list of {@link String} objects.
*/
public List<String> interfaces;
@@ -91,7 +91,7 @@ public class ClassNode extends ClassVisitor {
public String sourceFile;
/**
- * Debug information to compute the correspondance between source and
+ * Debug information to compute the correspondence between source and
* compiled elements of the class. May be <tt>null</tt>.
*/
public String sourceDebug;
@@ -109,8 +109,8 @@ public class ClassNode extends ClassVisitor {
public String outerMethod;
/**
- * The descriptor of the method that contains the class, or <tt>null</tt>
- * if the class is not enclosed in a method.
+ * The descriptor of the method that contains the class, or <tt>null</tt> if
+ * the class is not enclosed in a method.
*/
public String outerMethodDesc;
@@ -118,7 +118,7 @@ public class ClassNode extends ClassVisitor {
* The runtime visible annotations of this class. This list is a list of
* {@link AnnotationNode} objects. May be <tt>null</tt>.
*
- * @associates org.objectweb.asm.tree.AnnotationNode
+ * @associates scala.tools.asm.tree.AnnotationNode
* @label visible
*/
public List<AnnotationNode> visibleAnnotations;
@@ -127,7 +127,7 @@ public class ClassNode extends ClassVisitor {
* The runtime invisible annotations of this class. This list is a list of
* {@link AnnotationNode} objects. May be <tt>null</tt>.
*
- * @associates org.objectweb.asm.tree.AnnotationNode
+ * @associates scala.tools.asm.tree.AnnotationNode
* @label invisible
*/
public List<AnnotationNode> invisibleAnnotations;
@@ -136,7 +136,7 @@ public class ClassNode extends ClassVisitor {
* The non standard attributes of this class. This list is a list of
* {@link Attribute} objects. May be <tt>null</tt>.
*
- * @associates org.objectweb.asm.Attribute
+ * @associates scala.tools.asm.Attribute
*/
public List<Attribute> attrs;
@@ -144,7 +144,7 @@ public class ClassNode extends ClassVisitor {
* Informations about the inner classes of this class. This list is a list
* of {@link InnerClassNode} objects.
*
- * @associates org.objectweb.asm.tree.InnerClassNode
+ * @associates scala.tools.asm.tree.InnerClassNode
*/
public List<InnerClassNode> innerClasses;
@@ -152,7 +152,7 @@ public class ClassNode extends ClassVisitor {
* The fields of this class. This list is a list of {@link FieldNode}
* objects.
*
- * @associates org.objectweb.asm.tree.FieldNode
+ * @associates scala.tools.asm.tree.FieldNode
*/
public List<FieldNode> fields;
@@ -160,7 +160,7 @@ public class ClassNode extends ClassVisitor {
* The methods of this class. This list is a list of {@link MethodNode}
* objects.
*
- * @associates org.objectweb.asm.tree.MethodNode
+ * @associates scala.tools.asm.tree.MethodNode
*/
public List<MethodNode> methods;
@@ -176,8 +176,9 @@ public class ClassNode extends ClassVisitor {
/**
* Constructs a new {@link ClassNode}.
*
- * @param api the ASM API version implemented by this visitor. Must be one
- * of {@link Opcodes#ASM4}.
+ * @param api
+ * the ASM API version implemented by this visitor. Must be one
+ * of {@link Opcodes#ASM4}.
*/
public ClassNode(final int api) {
super(api);
@@ -192,14 +193,9 @@ public class ClassNode extends ClassVisitor {
// ------------------------------------------------------------------------
@Override
- public void visit(
- final int version,
- final int access,
- final String name,
- final String signature,
- final String superName,
- final String[] interfaces)
- {
+ public void visit(final int version, final int access, final String name,
+ final String signature, final String superName,
+ final String[] interfaces) {
this.version = version;
this.access = access;
this.name = name;
@@ -217,21 +213,16 @@ public class ClassNode extends ClassVisitor {
}
@Override
- public void visitOuterClass(
- final String owner,
- final String name,
- final String desc)
- {
+ public void visitOuterClass(final String owner, final String name,
+ final String desc) {
outerClass = owner;
outerMethod = name;
outerMethodDesc = desc;
}
@Override
- public AnnotationVisitor visitAnnotation(
- final String desc,
- final boolean visible)
- {
+ public AnnotationVisitor visitAnnotation(final String desc,
+ final boolean visible) {
AnnotationNode an = new AnnotationNode(desc);
if (visible) {
if (visibleAnnotations == null) {
@@ -256,44 +247,25 @@ public class ClassNode extends ClassVisitor {
}
@Override
- public void visitInnerClass(
- final String name,
- final String outerName,
- final String innerName,
- final int access)
- {
- InnerClassNode icn = new InnerClassNode(name,
- outerName,
- innerName,
+ public void visitInnerClass(final String name, final String outerName,
+ final String innerName, final int access) {
+ InnerClassNode icn = new InnerClassNode(name, outerName, innerName,
access);
innerClasses.add(icn);
}
@Override
- public FieldVisitor visitField(
- final int access,
- final String name,
- final String desc,
- final String signature,
- final Object value)
- {
+ public FieldVisitor visitField(final int access, final String name,
+ final String desc, final String signature, final Object value) {
FieldNode fn = new FieldNode(access, name, desc, signature, value);
fields.add(fn);
return fn;
}
@Override
- public MethodVisitor visitMethod(
- final int access,
- final String name,
- final String desc,
- final String signature,
- final String[] exceptions)
- {
- MethodNode mn = new MethodNode(access,
- name,
- desc,
- signature,
+ public MethodVisitor visitMethod(final int access, final String name,
+ final String desc, final String signature, final String[] exceptions) {
+ MethodNode mn = new MethodNode(access, name, desc, signature,
exceptions);
methods.add(mn);
return mn;
@@ -313,7 +285,8 @@ public class ClassNode extends ClassVisitor {
* contain elements that were introduced in more recent versions of the ASM
* API than the given version.
*
- * @param api an ASM API version. Must be one of {@link Opcodes#ASM4}.
+ * @param api
+ * an ASM API version. Must be one of {@link Opcodes#ASM4}.
*/
public void check(final int api) {
// nothing to do
@@ -322,7 +295,8 @@ public class ClassNode extends ClassVisitor {
/**
* Makes the given class visitor visit this class.
*
- * @param cv a class visitor.
+ * @param cv
+ * a class visitor.
*/
public void accept(final ClassVisitor cv) {
// visits header
diff --git a/src/asm/scala/tools/asm/tree/FieldInsnNode.java b/src/asm/scala/tools/asm/tree/FieldInsnNode.java
index 6b7a6a142a..0c94f18adf 100644
--- a/src/asm/scala/tools/asm/tree/FieldInsnNode.java
+++ b/src/asm/scala/tools/asm/tree/FieldInsnNode.java
@@ -43,7 +43,7 @@ public class FieldInsnNode extends AbstractInsnNode {
/**
* The internal name of the field's owner class (see
- * {@link org.objectweb.asm.Type#getInternalName() getInternalName}).
+ * {@link scala.tools.asm.Type#getInternalName() getInternalName}).
*/
public String owner;
@@ -53,26 +53,27 @@ public class FieldInsnNode extends AbstractInsnNode {
public String name;
/**
- * The field's descriptor (see {@link org.objectweb.asm.Type}).
+ * The field's descriptor (see {@link scala.tools.asm.Type}).
*/
public String desc;
/**
* Constructs a new {@link FieldInsnNode}.
*
- * @param opcode the opcode of the type instruction to be constructed. This
- * opcode must be GETSTATIC, PUTSTATIC, GETFIELD or PUTFIELD.
- * @param owner the internal name of the field's owner class (see
- * {@link org.objectweb.asm.Type#getInternalName() getInternalName}).
- * @param name the field's name.
- * @param desc the field's descriptor (see {@link org.objectweb.asm.Type}).
+ * @param opcode
+ * the opcode of the type instruction to be constructed. This
+ * opcode must be GETSTATIC, PUTSTATIC, GETFIELD or PUTFIELD.
+ * @param owner
+ * the internal name of the field's owner class (see
+ * {@link scala.tools.asm.Type#getInternalName()
+ * getInternalName}).
+ * @param name
+ * the field's name.
+ * @param desc
+ * the field's descriptor (see {@link scala.tools.asm.Type}).
*/
- public FieldInsnNode(
- final int opcode,
- final String owner,
- final String name,
- final String desc)
- {
+ public FieldInsnNode(final int opcode, final String owner,
+ final String name, final String desc) {
super(opcode);
this.owner = owner;
this.name = name;
@@ -82,8 +83,9 @@ public class FieldInsnNode extends AbstractInsnNode {
/**
* Sets the opcode of this instruction.
*
- * @param opcode the new instruction opcode. This opcode must be GETSTATIC,
- * PUTSTATIC, GETFIELD or PUTFIELD.
+ * @param opcode
+ * the new instruction opcode. This opcode must be GETSTATIC,
+ * PUTSTATIC, GETFIELD or PUTFIELD.
*/
public void setOpcode(final int opcode) {
this.opcode = opcode;
diff --git a/src/asm/scala/tools/asm/tree/FieldNode.java b/src/asm/scala/tools/asm/tree/FieldNode.java
index 9a1e17033c..61b614ec59 100644
--- a/src/asm/scala/tools/asm/tree/FieldNode.java
+++ b/src/asm/scala/tools/asm/tree/FieldNode.java
@@ -46,7 +46,7 @@ import scala.tools.asm.Opcodes;
public class FieldNode extends FieldVisitor {
/**
- * The field's access flags (see {@link org.objectweb.asm.Opcodes}). This
+ * The field's access flags (see {@link scala.tools.asm.Opcodes}). This
* field also indicates if the field is synthetic and/or deprecated.
*/
public int access;
@@ -57,7 +57,7 @@ public class FieldNode extends FieldVisitor {
public String name;
/**
- * The field's descriptor (see {@link org.objectweb.asm.Type}).
+ * The field's descriptor (see {@link scala.tools.asm.Type}).
*/
public String desc;
@@ -67,8 +67,8 @@ public class FieldNode extends FieldVisitor {
public String signature;
/**
- * The field's initial value. This field, which may be <tt>null</tt> if
- * the field does not have an initial value, must be an {@link Integer}, a
+ * The field's initial value. This field, which may be <tt>null</tt> if the
+ * field does not have an initial value, must be an {@link Integer}, a
* {@link Float}, a {@link Long}, a {@link Double} or a {@link String}.
*/
public Object value;
@@ -77,7 +77,7 @@ public class FieldNode extends FieldVisitor {
* The runtime visible annotations of this field. This list is a list of
* {@link AnnotationNode} objects. May be <tt>null</tt>.
*
- * @associates org.objectweb.asm.tree.AnnotationNode
+ * @associates scala.tools.asm.tree.AnnotationNode
* @label visible
*/
public List<AnnotationNode> visibleAnnotations;
@@ -86,7 +86,7 @@ public class FieldNode extends FieldVisitor {
* The runtime invisible annotations of this field. This list is a list of
* {@link AnnotationNode} objects. May be <tt>null</tt>.
*
- * @associates org.objectweb.asm.tree.AnnotationNode
+ * @associates scala.tools.asm.tree.AnnotationNode
* @label invisible
*/
public List<AnnotationNode> invisibleAnnotations;
@@ -95,7 +95,7 @@ public class FieldNode extends FieldVisitor {
* The non standard attributes of this field. This list is a list of
* {@link Attribute} objects. May be <tt>null</tt>.
*
- * @associates org.objectweb.asm.Attribute
+ * @associates scala.tools.asm.Attribute
*/
public List<Attribute> attrs;
@@ -104,25 +104,25 @@ public class FieldNode extends FieldVisitor {
* constructor</i>. Instead, they must use the
* {@link #FieldNode(int, int, String, String, String, Object)} version.
*
- * @param access the field's access flags (see
- * {@link org.objectweb.asm.Opcodes}). This parameter also indicates
- * if the field is synthetic and/or deprecated.
- * @param name the field's name.
- * @param desc the field's descriptor (see {@link org.objectweb.asm.Type
- * Type}).
- * @param signature the field's signature.
- * @param value the field's initial value. This parameter, which may be
- * <tt>null</tt> if the field does not have an initial value, must be
- * an {@link Integer}, a {@link Float}, a {@link Long}, a
- * {@link Double} or a {@link String}.
+ * @param access
+ * the field's access flags (see
+ * {@link scala.tools.asm.Opcodes}). This parameter also
+ * indicates if the field is synthetic and/or deprecated.
+ * @param name
+ * the field's name.
+ * @param desc
+ * the field's descriptor (see {@link scala.tools.asm.Type
+ * Type}).
+ * @param signature
+ * the field's signature.
+ * @param value
+ * the field's initial value. This parameter, which may be
+ * <tt>null</tt> if the field does not have an initial value,
+ * must be an {@link Integer}, a {@link Float}, a {@link Long}, a
+ * {@link Double} or a {@link String}.
*/
- public FieldNode(
- final int access,
- final String name,
- final String desc,
- final String signature,
- final Object value)
- {
+ public FieldNode(final int access, final String name, final String desc,
+ final String signature, final Object value) {
this(Opcodes.ASM4, access, name, desc, signature, value);
}
@@ -131,28 +131,28 @@ public class FieldNode extends FieldVisitor {
* constructor</i>. Instead, they must use the
* {@link #FieldNode(int, int, String, String, String, Object)} version.
*
- * @param api the ASM API version implemented by this visitor. Must be one
- * of {@link Opcodes#ASM4}.
- * @param access the field's access flags (see
- * {@link org.objectweb.asm.Opcodes}). This parameter also indicates
- * if the field is synthetic and/or deprecated.
- * @param name the field's name.
- * @param desc the field's descriptor (see {@link org.objectweb.asm.Type
- * Type}).
- * @param signature the field's signature.
- * @param value the field's initial value. This parameter, which may be
- * <tt>null</tt> if the field does not have an initial value, must be
- * an {@link Integer}, a {@link Float}, a {@link Long}, a
- * {@link Double} or a {@link String}.
+ * @param api
+ * the ASM API version implemented by this visitor. Must be one
+ * of {@link Opcodes#ASM4}.
+ * @param access
+ * the field's access flags (see
+ * {@link scala.tools.asm.Opcodes}). This parameter also
+ * indicates if the field is synthetic and/or deprecated.
+ * @param name
+ * the field's name.
+ * @param desc
+ * the field's descriptor (see {@link scala.tools.asm.Type
+ * Type}).
+ * @param signature
+ * the field's signature.
+ * @param value
+ * the field's initial value. This parameter, which may be
+ * <tt>null</tt> if the field does not have an initial value,
+ * must be an {@link Integer}, a {@link Float}, a {@link Long}, a
+ * {@link Double} or a {@link String}.
*/
- public FieldNode(
- final int api,
- final int access,
- final String name,
- final String desc,
- final String signature,
- final Object value)
- {
+ public FieldNode(final int api, final int access, final String name,
+ final String desc, final String signature, final Object value) {
super(api);
this.access = access;
this.name = name;
@@ -166,10 +166,8 @@ public class FieldNode extends FieldVisitor {
// ------------------------------------------------------------------------
@Override
- public AnnotationVisitor visitAnnotation(
- final String desc,
- final boolean visible)
- {
+ public AnnotationVisitor visitAnnotation(final String desc,
+ final boolean visible) {
AnnotationNode an = new AnnotationNode(desc);
if (visible) {
if (visibleAnnotations == null) {
@@ -207,7 +205,8 @@ public class FieldNode extends FieldVisitor {
* contain elements that were introduced in more recent versions of the ASM
* API than the given version.
*
- * @param api an ASM API version. Must be one of {@link Opcodes#ASM4}.
+ * @param api
+ * an ASM API version. Must be one of {@link Opcodes#ASM4}.
*/
public void check(final int api) {
// nothing to do
@@ -216,7 +215,8 @@ public class FieldNode extends FieldVisitor {
/**
* Makes the given class visitor visit this field.
*
- * @param cv a class visitor.
+ * @param cv
+ * a class visitor.
*/
public void accept(final ClassVisitor cv) {
FieldVisitor fv = cv.visitField(access, name, desc, signature, value);
diff --git a/src/asm/scala/tools/asm/tree/FrameNode.java b/src/asm/scala/tools/asm/tree/FrameNode.java
index 66825de0ac..f13fc66749 100644
--- a/src/asm/scala/tools/asm/tree/FrameNode.java
+++ b/src/asm/scala/tools/asm/tree/FrameNode.java
@@ -45,8 +45,9 @@ import scala.tools.asm.Opcodes;
* the target of a jump instruction, or that starts an exception handler block.
* The stack map frame types must describe the values of the local variables and
* of the operand stack elements <i>just before</i> <b>i</b> is executed. <br>
- * <br> (*) this is mandatory only for classes whose version is greater than or
- * equal to {@link Opcodes#V1_6 V1_6}.
+ * <br>
+ * (*) this is mandatory only for classes whose version is greater than or equal
+ * to {@link Opcodes#V1_6 V1_6}.
*
* @author Eric Bruneton
*/
@@ -83,48 +84,48 @@ public class FrameNode extends AbstractInsnNode {
/**
* Constructs a new {@link FrameNode}.
*
- * @param type the type of this frame. Must be {@link Opcodes#F_NEW} for
- * expanded frames, or {@link Opcodes#F_FULL},
- * {@link Opcodes#F_APPEND}, {@link Opcodes#F_CHOP},
- * {@link Opcodes#F_SAME} or {@link Opcodes#F_APPEND},
- * {@link Opcodes#F_SAME1} for compressed frames.
- * @param nLocal number of local variables of this stack map frame.
- * @param local the types of the local variables of this stack map frame.
- * Elements of this list can be Integer, String or LabelNode objects
- * (for primitive, reference and uninitialized types respectively -
- * see {@link MethodVisitor}).
- * @param nStack number of operand stack elements of this stack map frame.
- * @param stack the types of the operand stack elements of this stack map
- * frame. Elements of this list can be Integer, String or LabelNode
- * objects (for primitive, reference and uninitialized types
- * respectively - see {@link MethodVisitor}).
+ * @param type
+ * the type of this frame. Must be {@link Opcodes#F_NEW} for
+ * expanded frames, or {@link Opcodes#F_FULL},
+ * {@link Opcodes#F_APPEND}, {@link Opcodes#F_CHOP},
+ * {@link Opcodes#F_SAME} or {@link Opcodes#F_APPEND},
+ * {@link Opcodes#F_SAME1} for compressed frames.
+ * @param nLocal
+ * number of local variables of this stack map frame.
+ * @param local
+ * the types of the local variables of this stack map frame.
+ * Elements of this list can be Integer, String or LabelNode
+ * objects (for primitive, reference and uninitialized types
+ * respectively - see {@link MethodVisitor}).
+ * @param nStack
+ * number of operand stack elements of this stack map frame.
+ * @param stack
+ * the types of the operand stack elements of this stack map
+ * frame. Elements of this list can be Integer, String or
+ * LabelNode objects (for primitive, reference and uninitialized
+ * types respectively - see {@link MethodVisitor}).
*/
- public FrameNode(
- final int type,
- final int nLocal,
- final Object[] local,
- final int nStack,
- final Object[] stack)
- {
+ public FrameNode(final int type, final int nLocal, final Object[] local,
+ final int nStack, final Object[] stack) {
super(-1);
this.type = type;
switch (type) {
- case Opcodes.F_NEW:
- case Opcodes.F_FULL:
- this.local = asList(nLocal, local);
- this.stack = asList(nStack, stack);
- break;
- case Opcodes.F_APPEND:
- this.local = asList(nLocal, local);
- break;
- case Opcodes.F_CHOP:
- this.local = Arrays.asList(new Object[nLocal]);
- break;
- case Opcodes.F_SAME:
- break;
- case Opcodes.F_SAME1:
- this.stack = asList(1, stack);
- break;
+ case Opcodes.F_NEW:
+ case Opcodes.F_FULL:
+ this.local = asList(nLocal, local);
+ this.stack = asList(nStack, stack);
+ break;
+ case Opcodes.F_APPEND:
+ this.local = asList(nLocal, local);
+ break;
+ case Opcodes.F_CHOP:
+ this.local = Arrays.asList(new Object[nLocal]);
+ break;
+ case Opcodes.F_SAME:
+ break;
+ case Opcodes.F_SAME1:
+ this.stack = asList(1, stack);
+ break;
}
}
@@ -136,31 +137,29 @@ public class FrameNode extends AbstractInsnNode {
/**
* Makes the given visitor visit this stack map frame.
*
- * @param mv a method visitor.
+ * @param mv
+ * a method visitor.
*/
@Override
public void accept(final MethodVisitor mv) {
switch (type) {
- case Opcodes.F_NEW:
- case Opcodes.F_FULL:
- mv.visitFrame(type,
- local.size(),
- asArray(local),
- stack.size(),
- asArray(stack));
- break;
- case Opcodes.F_APPEND:
- mv.visitFrame(type, local.size(), asArray(local), 0, null);
- break;
- case Opcodes.F_CHOP:
- mv.visitFrame(type, local.size(), null, 0, null);
- break;
- case Opcodes.F_SAME:
- mv.visitFrame(type, 0, null, 0, null);
- break;
- case Opcodes.F_SAME1:
- mv.visitFrame(type, 0, null, 1, asArray(stack));
- break;
+ case Opcodes.F_NEW:
+ case Opcodes.F_FULL:
+ mv.visitFrame(type, local.size(), asArray(local), stack.size(),
+ asArray(stack));
+ break;
+ case Opcodes.F_APPEND:
+ mv.visitFrame(type, local.size(), asArray(local), 0, null);
+ break;
+ case Opcodes.F_CHOP:
+ mv.visitFrame(type, local.size(), null, 0, null);
+ break;
+ case Opcodes.F_SAME:
+ mv.visitFrame(type, 0, null, 0, null);
+ break;
+ case Opcodes.F_SAME1:
+ mv.visitFrame(type, 0, null, 1, asArray(stack));
+ break;
}
}
diff --git a/src/asm/scala/tools/asm/tree/IincInsnNode.java b/src/asm/scala/tools/asm/tree/IincInsnNode.java
index 75ac40884d..f9adf2e38c 100644
--- a/src/asm/scala/tools/asm/tree/IincInsnNode.java
+++ b/src/asm/scala/tools/asm/tree/IincInsnNode.java
@@ -54,8 +54,10 @@ public class IincInsnNode extends AbstractInsnNode {
/**
* Constructs a new {@link IincInsnNode}.
*
- * @param var index of the local variable to be incremented.
- * @param incr increment amount to increment the local variable by.
+ * @param var
+ * index of the local variable to be incremented.
+ * @param incr
+ * increment amount to increment the local variable by.
*/
public IincInsnNode(final int var, final int incr) {
super(Opcodes.IINC);
@@ -77,4 +79,4 @@ public class IincInsnNode extends AbstractInsnNode {
public AbstractInsnNode clone(final Map<LabelNode, LabelNode> labels) {
return new IincInsnNode(var, incr);
}
-} \ No newline at end of file
+}
diff --git a/src/asm/scala/tools/asm/tree/InnerClassNode.java b/src/asm/scala/tools/asm/tree/InnerClassNode.java
index 4579488921..aa3810c759 100644
--- a/src/asm/scala/tools/asm/tree/InnerClassNode.java
+++ b/src/asm/scala/tools/asm/tree/InnerClassNode.java
@@ -40,14 +40,14 @@ public class InnerClassNode {
/**
* The internal name of an inner class (see
- * {@link org.objectweb.asm.Type#getInternalName() getInternalName}).
+ * {@link scala.tools.asm.Type#getInternalName() getInternalName}).
*/
public String name;
/**
* The internal name of the class to which the inner class belongs (see
- * {@link org.objectweb.asm.Type#getInternalName() getInternalName}). May
- * be <tt>null</tt>.
+ * {@link scala.tools.asm.Type#getInternalName() getInternalName}). May be
+ * <tt>null</tt>.
*/
public String outerName;
@@ -66,24 +66,23 @@ public class InnerClassNode {
/**
* Constructs a new {@link InnerClassNode}.
*
- * @param name the internal name of an inner class (see
- * {@link org.objectweb.asm.Type#getInternalName() getInternalName}).
- * @param outerName the internal name of the class to which the inner class
- * belongs (see
- * {@link org.objectweb.asm.Type#getInternalName() getInternalName}).
- * May be <tt>null</tt>.
- * @param innerName the (simple) name of the inner class inside its
- * enclosing class. May be <tt>null</tt> for anonymous inner
- * classes.
- * @param access the access flags of the inner class as originally declared
- * in the enclosing class.
+ * @param name
+ * the internal name of an inner class (see
+ * {@link scala.tools.asm.Type#getInternalName()
+ * getInternalName}).
+ * @param outerName
+ * the internal name of the class to which the inner class
+ * belongs (see {@link scala.tools.asm.Type#getInternalName()
+ * getInternalName}). May be <tt>null</tt>.
+ * @param innerName
+ * the (simple) name of the inner class inside its enclosing
+ * class. May be <tt>null</tt> for anonymous inner classes.
+ * @param access
+ * the access flags of the inner class as originally declared in
+ * the enclosing class.
*/
- public InnerClassNode(
- final String name,
- final String outerName,
- final String innerName,
- final int access)
- {
+ public InnerClassNode(final String name, final String outerName,
+ final String innerName, final int access) {
this.name = name;
this.outerName = outerName;
this.innerName = innerName;
@@ -93,7 +92,8 @@ public class InnerClassNode {
/**
* Makes the given class visitor visit this inner class.
*
- * @param cv a class visitor.
+ * @param cv
+ * a class visitor.
*/
public void accept(final ClassVisitor cv) {
cv.visitInnerClass(name, outerName, innerName, access);
diff --git a/src/asm/scala/tools/asm/tree/InsnList.java b/src/asm/scala/tools/asm/tree/InsnList.java
index dedd3bba73..55d83c2e8b 100644
--- a/src/asm/scala/tools/asm/tree/InsnList.java
+++ b/src/asm/scala/tools/asm/tree/InsnList.java
@@ -73,8 +73,8 @@ public class InsnList {
/**
* Returns the first instruction in this list.
*
- * @return the first instruction in this list, or <tt>null</tt> if the
- * list is empty.
+ * @return the first instruction in this list, or <tt>null</tt> if the list
+ * is empty.
*/
public AbstractInsnNode getFirst() {
return first;
@@ -96,9 +96,11 @@ public class InsnList {
* time it is called. Once the cache is built, this method run in constant
* time. This cache is invalidated by all the methods that modify the list.
*
- * @param index the index of the instruction that must be returned.
+ * @param index
+ * the index of the instruction that must be returned.
* @return the instruction whose index is given.
- * @throws IndexOutOfBoundsException if (index < 0 || index >= size()).
+ * @throws IndexOutOfBoundsException
+ * if (index < 0 || index >= size()).
*/
public AbstractInsnNode get(final int index) {
if (index < 0 || index >= size) {
@@ -111,11 +113,12 @@ public class InsnList {
}
/**
- * Returns <tt>true</tt> if the given instruction belongs to this list.
- * This method always scans the instructions of this list until it finds the
+ * Returns <tt>true</tt> if the given instruction belongs to this list. This
+ * method always scans the instructions of this list until it finds the
* given instruction or reaches the end of the list.
*
- * @param insn an instruction.
+ * @param insn
+ * an instruction.
* @return <tt>true</tt> if the given instruction belongs to this list.
*/
public boolean contains(final AbstractInsnNode insn) {
@@ -133,7 +136,8 @@ public class InsnList {
* constant time. The cache is invalidated by all the methods that modify
* the list.
*
- * @param insn an instruction <i>of this list</i>.
+ * @param insn
+ * an instruction <i>of this list</i>.
* @return the index of the given instruction in this list. <i>The result of
* this method is undefined if the given instruction does not belong
* to this list</i>. Use {@link #contains contains} to test if an
@@ -149,7 +153,8 @@ public class InsnList {
/**
* Makes the given visitor visit all of the instructions in this list.
*
- * @param mv the method visitor that must visit the instructions.
+ * @param mv
+ * the method visitor that must visit the instructions.
*/
public void accept(final MethodVisitor mv) {
AbstractInsnNode insn = first;
@@ -198,9 +203,11 @@ public class InsnList {
/**
* Replaces an instruction of this list with another instruction.
*
- * @param location an instruction <i>of this list</i>.
- * @param insn another instruction, <i>which must not belong to any
- * {@link InsnList}</i>.
+ * @param location
+ * an instruction <i>of this list</i>.
+ * @param insn
+ * another instruction, <i>which must not belong to any
+ * {@link InsnList}</i>.
*/
public void set(final AbstractInsnNode location, final AbstractInsnNode insn) {
AbstractInsnNode next = location.next;
@@ -232,8 +239,9 @@ public class InsnList {
/**
* Adds the given instruction to the end of this list.
*
- * @param insn an instruction, <i>which must not belong to any
- * {@link InsnList}</i>.
+ * @param insn
+ * an instruction, <i>which must not belong to any
+ * {@link InsnList}</i>.
*/
public void add(final AbstractInsnNode insn) {
++size;
@@ -252,8 +260,9 @@ public class InsnList {
/**
* Adds the given instructions to the end of this list.
*
- * @param insns an instruction list, which is cleared during the process.
- * This list must be different from 'this'.
+ * @param insns
+ * an instruction list, which is cleared during the process. This
+ * list must be different from 'this'.
*/
public void add(final InsnList insns) {
if (insns.size == 0) {
@@ -276,8 +285,9 @@ public class InsnList {
/**
* Inserts the given instruction at the begining of this list.
*
- * @param insn an instruction, <i>which must not belong to any
- * {@link InsnList}</i>.
+ * @param insn
+ * an instruction, <i>which must not belong to any
+ * {@link InsnList}</i>.
*/
public void insert(final AbstractInsnNode insn) {
++size;
@@ -296,8 +306,9 @@ public class InsnList {
/**
* Inserts the given instructions at the begining of this list.
*
- * @param insns an instruction list, which is cleared during the process.
- * This list must be different from 'this'.
+ * @param insns
+ * an instruction list, which is cleared during the process. This
+ * list must be different from 'this'.
*/
public void insert(final InsnList insns) {
if (insns.size == 0) {
@@ -320,12 +331,15 @@ public class InsnList {
/**
* Inserts the given instruction after the specified instruction.
*
- * @param location an instruction <i>of this list</i> after which insn must be
- * inserted.
- * @param insn the instruction to be inserted, <i>which must not belong to
- * any {@link InsnList}</i>.
+ * @param location
+ * an instruction <i>of this list</i> after which insn must be
+ * inserted.
+ * @param insn
+ * the instruction to be inserted, <i>which must not belong to
+ * any {@link InsnList}</i>.
*/
- public void insert(final AbstractInsnNode location, final AbstractInsnNode insn) {
+ public void insert(final AbstractInsnNode location,
+ final AbstractInsnNode insn) {
++size;
AbstractInsnNode next = location.next;
if (next == null) {
@@ -343,10 +357,12 @@ public class InsnList {
/**
* Inserts the given instructions after the specified instruction.
*
- * @param location an instruction <i>of this list</i> after which the
- * instructions must be inserted.
- * @param insns the instruction list to be inserted, which is cleared during
- * the process. This list must be different from 'this'.
+ * @param location
+ * an instruction <i>of this list</i> after which the
+ * instructions must be inserted.
+ * @param insns
+ * the instruction list to be inserted, which is cleared during
+ * the process. This list must be different from 'this'.
*/
public void insert(final AbstractInsnNode location, final InsnList insns) {
if (insns.size == 0) {
@@ -371,12 +387,15 @@ public class InsnList {
/**
* Inserts the given instruction before the specified instruction.
*
- * @param location an instruction <i>of this list</i> before which insn must be
- * inserted.
- * @param insn the instruction to be inserted, <i>which must not belong to
- * any {@link InsnList}</i>.
+ * @param location
+ * an instruction <i>of this list</i> before which insn must be
+ * inserted.
+ * @param insn
+ * the instruction to be inserted, <i>which must not belong to
+ * any {@link InsnList}</i>.
*/
- public void insertBefore(final AbstractInsnNode location, final AbstractInsnNode insn) {
+ public void insertBefore(final AbstractInsnNode location,
+ final AbstractInsnNode insn) {
++size;
AbstractInsnNode prev = location.prev;
if (prev == null) {
@@ -394,37 +413,39 @@ public class InsnList {
/**
* Inserts the given instructions before the specified instruction.
*
- * @param location an instruction <i>of this list</i> before which the instructions
- * must be inserted.
- * @param insns the instruction list to be inserted, which is cleared during
- * the process. This list must be different from 'this'.
+ * @param location
+ * an instruction <i>of this list</i> before which the
+ * instructions must be inserted.
+ * @param insns
+ * the instruction list to be inserted, which is cleared during
+ * the process. This list must be different from 'this'.
*/
- public void insertBefore(final AbstractInsnNode location, final InsnList insns) {
+ public void insertBefore(final AbstractInsnNode location,
+ final InsnList insns) {
if (insns.size == 0) {
return;
}
size += insns.size;
AbstractInsnNode ifirst = insns.first;
AbstractInsnNode ilast = insns.last;
- AbstractInsnNode prev = location .prev;
+ AbstractInsnNode prev = location.prev;
if (prev == null) {
first = ifirst;
} else {
prev.next = ifirst;
}
- location .prev = ilast;
- ilast.next = location ;
+ location.prev = ilast;
+ ilast.next = location;
ifirst.prev = prev;
cache = null;
insns.removeAll(false);
}
-
-
/**
* Removes the given instruction from this list.
*
- * @param insn the instruction <i>of this list</i> that must be removed.
+ * @param insn
+ * the instruction <i>of this list</i> that must be removed.
*/
public void remove(final AbstractInsnNode insn) {
--size;
@@ -456,8 +477,9 @@ public class InsnList {
/**
* Removes all of the instructions of this list.
*
- * @param mark if the instructions must be marked as no longer belonging to
- * any {@link InsnList}.
+ * @param mark
+ * if the instructions must be marked as no longer belonging to
+ * any {@link InsnList}.
*/
void removeAll(final boolean mark) {
if (mark) {
@@ -499,14 +521,14 @@ public class InsnList {
}
// this class is not generified because it will create bridges
- private final class InsnListIterator implements ListIterator/*<AbstractInsnNode>*/ {
+ private final class InsnListIterator implements ListIterator {
AbstractInsnNode next;
AbstractInsnNode prev;
InsnListIterator(int index) {
- if(index==size()) {
+ if (index == size()) {
next = null;
prev = getLast();
} else {
diff --git a/src/asm/scala/tools/asm/tree/InsnNode.java b/src/asm/scala/tools/asm/tree/InsnNode.java
index d4664d23c2..4d5288cafa 100644
--- a/src/asm/scala/tools/asm/tree/InsnNode.java
+++ b/src/asm/scala/tools/asm/tree/InsnNode.java
@@ -43,20 +43,22 @@ public class InsnNode extends AbstractInsnNode {
/**
* Constructs a new {@link InsnNode}.
*
- * @param opcode the opcode of the instruction to be constructed. This
- * opcode must be NOP, ACONST_NULL, ICONST_M1, ICONST_0, ICONST_1,
- * ICONST_2, ICONST_3, ICONST_4, ICONST_5, LCONST_0, LCONST_1,
- * FCONST_0, FCONST_1, FCONST_2, DCONST_0, DCONST_1, IALOAD, LALOAD,
- * FALOAD, DALOAD, AALOAD, BALOAD, CALOAD, SALOAD, IASTORE, LASTORE,
- * FASTORE, DASTORE, AASTORE, BASTORE, CASTORE, SASTORE, POP, POP2,
- * DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, SWAP, IADD, LADD,
- * FADD, DADD, ISUB, LSUB, FSUB, DSUB, IMUL, LMUL, FMUL, DMUL, IDIV,
- * LDIV, FDIV, DDIV, IREM, LREM, FREM, DREM, INEG, LNEG, FNEG, DNEG,
- * ISHL, LSHL, ISHR, LSHR, IUSHR, LUSHR, IAND, LAND, IOR, LOR, IXOR,
- * LXOR, I2L, I2F, I2D, L2I, L2F, L2D, F2I, F2L, F2D, D2I, D2L, D2F,
- * I2B, I2C, I2S, LCMP, FCMPL, FCMPG, DCMPL, DCMPG, IRETURN, LRETURN,
- * FRETURN, DRETURN, ARETURN, RETURN, ARRAYLENGTH, ATHROW,
- * MONITORENTER, or MONITOREXIT.
+ * @param opcode
+ * the opcode of the instruction to be constructed. This opcode
+ * must be NOP, ACONST_NULL, ICONST_M1, ICONST_0, ICONST_1,
+ * ICONST_2, ICONST_3, ICONST_4, ICONST_5, LCONST_0, LCONST_1,
+ * FCONST_0, FCONST_1, FCONST_2, DCONST_0, DCONST_1, IALOAD,
+ * LALOAD, FALOAD, DALOAD, AALOAD, BALOAD, CALOAD, SALOAD,
+ * IASTORE, LASTORE, FASTORE, DASTORE, AASTORE, BASTORE, CASTORE,
+ * SASTORE, POP, POP2, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1,
+ * DUP2_X2, SWAP, IADD, LADD, FADD, DADD, ISUB, LSUB, FSUB, DSUB,
+ * IMUL, LMUL, FMUL, DMUL, IDIV, LDIV, FDIV, DDIV, IREM, LREM,
+ * FREM, DREM, INEG, LNEG, FNEG, DNEG, ISHL, LSHL, ISHR, LSHR,
+ * IUSHR, LUSHR, IAND, LAND, IOR, LOR, IXOR, LXOR, I2L, I2F, I2D,
+ * L2I, L2F, L2D, F2I, F2L, F2D, D2I, D2L, D2F, I2B, I2C, I2S,
+ * LCMP, FCMPL, FCMPG, DCMPL, DCMPG, IRETURN, LRETURN, FRETURN,
+ * DRETURN, ARETURN, RETURN, ARRAYLENGTH, ATHROW, MONITORENTER,
+ * or MONITOREXIT.
*/
public InsnNode(final int opcode) {
super(opcode);
@@ -70,7 +72,8 @@ public class InsnNode extends AbstractInsnNode {
/**
* Makes the given visitor visit this instruction.
*
- * @param mv a method visitor.
+ * @param mv
+ * a method visitor.
*/
@Override
public void accept(final MethodVisitor mv) {
diff --git a/src/asm/scala/tools/asm/tree/IntInsnNode.java b/src/asm/scala/tools/asm/tree/IntInsnNode.java
index b61270c786..e0aeed4bc8 100644
--- a/src/asm/scala/tools/asm/tree/IntInsnNode.java
+++ b/src/asm/scala/tools/asm/tree/IntInsnNode.java
@@ -48,9 +48,11 @@ public class IntInsnNode extends AbstractInsnNode {
/**
* Constructs a new {@link IntInsnNode}.
*
- * @param opcode the opcode of the instruction to be constructed. This
- * opcode must be BIPUSH, SIPUSH or NEWARRAY.
- * @param operand the operand of the instruction to be constructed.
+ * @param opcode
+ * the opcode of the instruction to be constructed. This opcode
+ * must be BIPUSH, SIPUSH or NEWARRAY.
+ * @param operand
+ * the operand of the instruction to be constructed.
*/
public IntInsnNode(final int opcode, final int operand) {
super(opcode);
@@ -60,8 +62,9 @@ public class IntInsnNode extends AbstractInsnNode {
/**
* Sets the opcode of this instruction.
*
- * @param opcode the new instruction opcode. This opcode must be BIPUSH,
- * SIPUSH or NEWARRAY.
+ * @param opcode
+ * the new instruction opcode. This opcode must be BIPUSH, SIPUSH
+ * or NEWARRAY.
*/
public void setOpcode(final int opcode) {
this.opcode = opcode;
diff --git a/src/asm/scala/tools/asm/tree/InvokeDynamicInsnNode.java b/src/asm/scala/tools/asm/tree/InvokeDynamicInsnNode.java
index d993b5a054..7ee84b875b 100644
--- a/src/asm/scala/tools/asm/tree/InvokeDynamicInsnNode.java
+++ b/src/asm/scala/tools/asm/tree/InvokeDynamicInsnNode.java
@@ -65,17 +65,17 @@ public class InvokeDynamicInsnNode extends AbstractInsnNode {
/**
* Constructs a new {@link InvokeDynamicInsnNode}.
*
- * @param name invokedynamic name.
- * @param desc invokedynamic descriptor (see {@link org.objectweb.asm.Type}).
- * @param bsm the bootstrap method.
- * @param bsmArgs the boostrap constant arguments.
+ * @param name
+ * invokedynamic name.
+ * @param desc
+ * invokedynamic descriptor (see {@link scala.tools.asm.Type}).
+ * @param bsm
+ * the bootstrap method.
+ * @param bsmArgs
+ * the boostrap constant arguments.
*/
- public InvokeDynamicInsnNode(
- final String name,
- final String desc,
- final Handle bsm,
- final Object... bsmArgs)
- {
+ public InvokeDynamicInsnNode(final String name, final String desc,
+ final Handle bsm, final Object... bsmArgs) {
super(Opcodes.INVOKEDYNAMIC);
this.name = name;
this.desc = desc;
@@ -97,4 +97,4 @@ public class InvokeDynamicInsnNode extends AbstractInsnNode {
public AbstractInsnNode clone(final Map<LabelNode, LabelNode> labels) {
return new InvokeDynamicInsnNode(name, desc, bsm, bsmArgs);
}
-} \ No newline at end of file
+}
diff --git a/src/asm/scala/tools/asm/tree/JumpInsnNode.java b/src/asm/scala/tools/asm/tree/JumpInsnNode.java
index 339ebbd2d0..81e1e09deb 100644
--- a/src/asm/scala/tools/asm/tree/JumpInsnNode.java
+++ b/src/asm/scala/tools/asm/tree/JumpInsnNode.java
@@ -50,13 +50,15 @@ public class JumpInsnNode extends AbstractInsnNode {
/**
* Constructs a new {@link JumpInsnNode}.
*
- * @param opcode the opcode of the type instruction to be constructed. This
- * opcode must be IFEQ, IFNE, IFLT, IFGE, IFGT, IFLE, IF_ICMPEQ,
- * IF_ICMPNE, IF_ICMPLT, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ACMPEQ,
- * IF_ACMPNE, GOTO, JSR, IFNULL or IFNONNULL.
- * @param label the operand of the instruction to be constructed. This
- * operand is a label that designates the instruction to which the
- * jump instruction may jump.
+ * @param opcode
+ * the opcode of the type instruction to be constructed. This
+ * opcode must be IFEQ, IFNE, IFLT, IFGE, IFGT, IFLE, IF_ICMPEQ,
+ * IF_ICMPNE, IF_ICMPLT, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE,
+ * IF_ACMPEQ, IF_ACMPNE, GOTO, JSR, IFNULL or IFNONNULL.
+ * @param label
+ * the operand of the instruction to be constructed. This operand
+ * is a label that designates the instruction to which the jump
+ * instruction may jump.
*/
public JumpInsnNode(final int opcode, final LabelNode label) {
super(opcode);
@@ -66,10 +68,11 @@ public class JumpInsnNode extends AbstractInsnNode {
/**
* Sets the opcode of this instruction.
*
- * @param opcode the new instruction opcode. This opcode must be IFEQ, IFNE,
- * IFLT, IFGE, IFGT, IFLE, IF_ICMPEQ, IF_ICMPNE, IF_ICMPLT,
- * IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ACMPEQ, IF_ACMPNE, GOTO, JSR,
- * IFNULL or IFNONNULL.
+ * @param opcode
+ * the new instruction opcode. This opcode must be IFEQ, IFNE,
+ * IFLT, IFGE, IFGT, IFLE, IF_ICMPEQ, IF_ICMPNE, IF_ICMPLT,
+ * IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ACMPEQ, IF_ACMPNE, GOTO,
+ * JSR, IFNULL or IFNONNULL.
*/
public void setOpcode(final int opcode) {
this.opcode = opcode;
diff --git a/src/asm/scala/tools/asm/tree/LabelNode.java b/src/asm/scala/tools/asm/tree/LabelNode.java
index 523a8d6442..44c48c1160 100644
--- a/src/asm/scala/tools/asm/tree/LabelNode.java
+++ b/src/asm/scala/tools/asm/tree/LabelNode.java
@@ -75,4 +75,4 @@ public class LabelNode extends AbstractInsnNode {
public void resetLabel() {
label = null;
}
-} \ No newline at end of file
+}
diff --git a/src/asm/scala/tools/asm/tree/LdcInsnNode.java b/src/asm/scala/tools/asm/tree/LdcInsnNode.java
index f8d115acd5..4e328f9b39 100644
--- a/src/asm/scala/tools/asm/tree/LdcInsnNode.java
+++ b/src/asm/scala/tools/asm/tree/LdcInsnNode.java
@@ -44,16 +44,17 @@ public class LdcInsnNode extends AbstractInsnNode {
/**
* The constant to be loaded on the stack. This parameter must be a non null
* {@link Integer}, a {@link Float}, a {@link Long}, a {@link Double}, a
- * {@link String} or a {@link org.objectweb.asm.Type}.
+ * {@link String} or a {@link scala.tools.asm.Type}.
*/
public Object cst;
/**
* Constructs a new {@link LdcInsnNode}.
*
- * @param cst the constant to be loaded on the stack. This parameter must be
- * a non null {@link Integer}, a {@link Float}, a {@link Long}, a
- * {@link Double} or a {@link String}.
+ * @param cst
+ * the constant to be loaded on the stack. This parameter must be
+ * a non null {@link Integer}, a {@link Float}, a {@link Long}, a
+ * {@link Double} or a {@link String}.
*/
public LdcInsnNode(final Object cst) {
super(Opcodes.LDC);
@@ -74,4 +75,4 @@ public class LdcInsnNode extends AbstractInsnNode {
public AbstractInsnNode clone(final Map<LabelNode, LabelNode> labels) {
return new LdcInsnNode(cst);
}
-} \ No newline at end of file
+}
diff --git a/src/asm/scala/tools/asm/tree/LineNumberNode.java b/src/asm/scala/tools/asm/tree/LineNumberNode.java
index acc83c8d30..9947aa70a9 100644
--- a/src/asm/scala/tools/asm/tree/LineNumberNode.java
+++ b/src/asm/scala/tools/asm/tree/LineNumberNode.java
@@ -55,9 +55,11 @@ public class LineNumberNode extends AbstractInsnNode {
/**
* Constructs a new {@link LineNumberNode}.
*
- * @param line a line number. This number refers to the source file from
- * which the class was compiled.
- * @param start the first instruction corresponding to this line number.
+ * @param line
+ * a line number. This number refers to the source file from
+ * which the class was compiled.
+ * @param start
+ * the first instruction corresponding to this line number.
*/
public LineNumberNode(final int line, final LabelNode start) {
super(-1);
diff --git a/src/asm/scala/tools/asm/tree/LocalVariableNode.java b/src/asm/scala/tools/asm/tree/LocalVariableNode.java
index 51cbd3ca00..0d8e27356f 100644
--- a/src/asm/scala/tools/asm/tree/LocalVariableNode.java
+++ b/src/asm/scala/tools/asm/tree/LocalVariableNode.java
@@ -73,24 +73,24 @@ public class LocalVariableNode {
/**
* Constructs a new {@link LocalVariableNode}.
*
- * @param name the name of a local variable.
- * @param desc the type descriptor of this local variable.
- * @param signature the signature of this local variable. May be
- * <tt>null</tt>.
- * @param start the first instruction corresponding to the scope of this
- * local variable (inclusive).
- * @param end the last instruction corresponding to the scope of this local
- * variable (exclusive).
- * @param index the local variable's index.
+ * @param name
+ * the name of a local variable.
+ * @param desc
+ * the type descriptor of this local variable.
+ * @param signature
+ * the signature of this local variable. May be <tt>null</tt>.
+ * @param start
+ * the first instruction corresponding to the scope of this local
+ * variable (inclusive).
+ * @param end
+ * the last instruction corresponding to the scope of this local
+ * variable (exclusive).
+ * @param index
+ * the local variable's index.
*/
- public LocalVariableNode(
- final String name,
- final String desc,
- final String signature,
- final LabelNode start,
- final LabelNode end,
- final int index)
- {
+ public LocalVariableNode(final String name, final String desc,
+ final String signature, final LabelNode start, final LabelNode end,
+ final int index) {
this.name = name;
this.desc = desc;
this.signature = signature;
@@ -102,14 +102,11 @@ public class LocalVariableNode {
/**
* Makes the given visitor visit this local variable declaration.
*
- * @param mv a method visitor.
+ * @param mv
+ * a method visitor.
*/
public void accept(final MethodVisitor mv) {
- mv.visitLocalVariable(name,
- desc,
- signature,
- start.getLabel(),
- end.getLabel(),
- index);
+ mv.visitLocalVariable(name, desc, signature, start.getLabel(),
+ end.getLabel(), index);
}
}
diff --git a/src/asm/scala/tools/asm/tree/LookupSwitchInsnNode.java b/src/asm/scala/tools/asm/tree/LookupSwitchInsnNode.java
index 6d0f971c29..d2479b4814 100644
--- a/src/asm/scala/tools/asm/tree/LookupSwitchInsnNode.java
+++ b/src/asm/scala/tools/asm/tree/LookupSwitchInsnNode.java
@@ -64,20 +64,21 @@ public class LookupSwitchInsnNode extends AbstractInsnNode {
/**
* Constructs a new {@link LookupSwitchInsnNode}.
*
- * @param dflt beginning of the default handler block.
- * @param keys the values of the keys.
- * @param labels beginnings of the handler blocks. <tt>labels[i]</tt> is
- * the beginning of the handler block for the <tt>keys[i]</tt> key.
+ * @param dflt
+ * beginning of the default handler block.
+ * @param keys
+ * the values of the keys.
+ * @param labels
+ * beginnings of the handler blocks. <tt>labels[i]</tt> is the
+ * beginning of the handler block for the <tt>keys[i]</tt> key.
*/
- public LookupSwitchInsnNode(
- final LabelNode dflt,
- final int[] keys,
- final LabelNode[] labels)
- {
+ public LookupSwitchInsnNode(final LabelNode dflt, final int[] keys,
+ final LabelNode[] labels) {
super(Opcodes.LOOKUPSWITCH);
this.dflt = dflt;
this.keys = new ArrayList<Integer>(keys == null ? 0 : keys.length);
- this.labels = new ArrayList<LabelNode>(labels == null ? 0 : labels.length);
+ this.labels = new ArrayList<LabelNode>(labels == null ? 0
+ : labels.length);
if (keys != null) {
for (int i = 0; i < keys.length; ++i) {
this.keys.add(new Integer(keys[i]));
diff --git a/src/asm/scala/tools/asm/tree/MethodInsnNode.java b/src/asm/scala/tools/asm/tree/MethodInsnNode.java
index c3036bc6b4..bf09f556d8 100644
--- a/src/asm/scala/tools/asm/tree/MethodInsnNode.java
+++ b/src/asm/scala/tools/asm/tree/MethodInsnNode.java
@@ -43,7 +43,7 @@ public class MethodInsnNode extends AbstractInsnNode {
/**
* The internal name of the method's owner class (see
- * {@link org.objectweb.asm.Type#getInternalName() getInternalName}).
+ * {@link scala.tools.asm.Type#getInternalName() getInternalName}).
*/
public String owner;
@@ -53,27 +53,28 @@ public class MethodInsnNode extends AbstractInsnNode {
public String name;
/**
- * The method's descriptor (see {@link org.objectweb.asm.Type}).
+ * The method's descriptor (see {@link scala.tools.asm.Type}).
*/
public String desc;
/**
* Constructs a new {@link MethodInsnNode}.
*
- * @param opcode the opcode of the type instruction to be constructed. This
- * opcode must be INVOKEVIRTUAL, INVOKESPECIAL, INVOKESTATIC or
- * INVOKEINTERFACE.
- * @param owner the internal name of the method's owner class (see
- * {@link org.objectweb.asm.Type#getInternalName() getInternalName}).
- * @param name the method's name.
- * @param desc the method's descriptor (see {@link org.objectweb.asm.Type}).
+ * @param opcode
+ * the opcode of the type instruction to be constructed. This
+ * opcode must be INVOKEVIRTUAL, INVOKESPECIAL, INVOKESTATIC or
+ * INVOKEINTERFACE.
+ * @param owner
+ * the internal name of the method's owner class (see
+ * {@link scala.tools.asm.Type#getInternalName()
+ * getInternalName}).
+ * @param name
+ * the method's name.
+ * @param desc
+ * the method's descriptor (see {@link scala.tools.asm.Type}).
*/
- public MethodInsnNode(
- final int opcode,
- final String owner,
- final String name,
- final String desc)
- {
+ public MethodInsnNode(final int opcode, final String owner,
+ final String name, final String desc) {
super(opcode);
this.owner = owner;
this.name = name;
@@ -83,8 +84,9 @@ public class MethodInsnNode extends AbstractInsnNode {
/**
* Sets the opcode of this instruction.
*
- * @param opcode the new instruction opcode. This opcode must be
- * INVOKEVIRTUAL, INVOKESPECIAL, INVOKESTATIC or INVOKEINTERFACE.
+ * @param opcode
+ * the new instruction opcode. This opcode must be INVOKEVIRTUAL,
+ * INVOKESPECIAL, INVOKESTATIC or INVOKEINTERFACE.
*/
public void setOpcode(final int opcode) {
this.opcode = opcode;
@@ -104,4 +106,4 @@ public class MethodInsnNode extends AbstractInsnNode {
public AbstractInsnNode clone(final Map<LabelNode, LabelNode> labels) {
return new MethodInsnNode(opcode, owner, name, desc);
}
-} \ No newline at end of file
+}
diff --git a/src/asm/scala/tools/asm/tree/MethodNode.java b/src/asm/scala/tools/asm/tree/MethodNode.java
index 70ec39e058..5f9c778e0c 100644
--- a/src/asm/scala/tools/asm/tree/MethodNode.java
+++ b/src/asm/scala/tools/asm/tree/MethodNode.java
@@ -81,7 +81,7 @@ public class MethodNode extends MethodVisitor {
* The runtime visible annotations of this method. This list is a list of
* {@link AnnotationNode} objects. May be <tt>null</tt>.
*
- * @associates org.objectweb.asm.tree.AnnotationNode
+ * @associates scala.tools.asm.tree.AnnotationNode
* @label visible
*/
public List<AnnotationNode> visibleAnnotations;
@@ -90,7 +90,7 @@ public class MethodNode extends MethodVisitor {
* The runtime invisible annotations of this method. This list is a list of
* {@link AnnotationNode} objects. May be <tt>null</tt>.
*
- * @associates org.objectweb.asm.tree.AnnotationNode
+ * @associates scala.tools.asm.tree.AnnotationNode
* @label invisible
*/
public List<AnnotationNode> invisibleAnnotations;
@@ -99,7 +99,7 @@ public class MethodNode extends MethodVisitor {
* The non standard attributes of this method. This list is a list of
* {@link Attribute} objects. May be <tt>null</tt>.
*
- * @associates org.objectweb.asm.Attribute
+ * @associates scala.tools.asm.Attribute
*/
public List<Attribute> attrs;
@@ -117,7 +117,7 @@ public class MethodNode extends MethodVisitor {
* The runtime visible parameter annotations of this method. These lists are
* lists of {@link AnnotationNode} objects. May be <tt>null</tt>.
*
- * @associates org.objectweb.asm.tree.AnnotationNode
+ * @associates scala.tools.asm.tree.AnnotationNode
* @label invisible parameters
*/
public List<AnnotationNode>[] visibleParameterAnnotations;
@@ -126,7 +126,7 @@ public class MethodNode extends MethodVisitor {
* The runtime invisible parameter annotations of this method. These lists
* are lists of {@link AnnotationNode} objects. May be <tt>null</tt>.
*
- * @associates org.objectweb.asm.tree.AnnotationNode
+ * @associates scala.tools.asm.tree.AnnotationNode
* @label visible parameters
*/
public List<AnnotationNode>[] invisibleParameterAnnotations;
@@ -135,7 +135,7 @@ public class MethodNode extends MethodVisitor {
* The instructions of this method. This list is a list of
* {@link AbstractInsnNode} objects.
*
- * @associates org.objectweb.asm.tree.AbstractInsnNode
+ * @associates scala.tools.asm.tree.AbstractInsnNode
* @label instructions
*/
public InsnList instructions;
@@ -144,7 +144,7 @@ public class MethodNode extends MethodVisitor {
* The try catch blocks of this method. This list is a list of
* {@link TryCatchBlockNode} objects.
*
- * @associates org.objectweb.asm.tree.TryCatchBlockNode
+ * @associates scala.tools.asm.tree.TryCatchBlockNode
*/
public List<TryCatchBlockNode> tryCatchBlocks;
@@ -162,7 +162,7 @@ public class MethodNode extends MethodVisitor {
* The local variables of this method. This list is a list of
* {@link LocalVariableNode} objects. May be <tt>null</tt>
*
- * @associates org.objectweb.asm.tree.LocalVariableNode
+ * @associates scala.tools.asm.tree.LocalVariableNode
*/
public List<LocalVariableNode> localVariables;
@@ -170,7 +170,7 @@ public class MethodNode extends MethodVisitor {
* If the accept method has been called on this object.
*/
private boolean visited;
-
+
/**
* Constructs an uninitialized {@link MethodNode}. <i>Subclasses must not
* use this constructor</i>. Instead, they must use the
@@ -183,8 +183,9 @@ public class MethodNode extends MethodVisitor {
/**
* Constructs an uninitialized {@link MethodNode}.
*
- * @param api the ASM API version implemented by this visitor. Must be one
- * of {@link Opcodes#ASM4}.
+ * @param api
+ * the ASM API version implemented by this visitor. Must be one
+ * of {@link Opcodes#ASM4}.
*/
public MethodNode(final int api) {
super(api);
@@ -196,56 +197,55 @@ public class MethodNode extends MethodVisitor {
* constructor</i>. Instead, they must use the
* {@link #MethodNode(int, int, String, String, String, String[])} version.
*
- * @param access the method's access flags (see {@link Opcodes}). This
- * parameter also indicates if the method is synthetic and/or
- * deprecated.
- * @param name the method's name.
- * @param desc the method's descriptor (see {@link Type}).
- * @param signature the method's signature. May be <tt>null</tt>.
- * @param exceptions the internal names of the method's exception classes
- * (see {@link Type#getInternalName() getInternalName}). May be
- * <tt>null</tt>.
+ * @param access
+ * the method's access flags (see {@link Opcodes}). This
+ * parameter also indicates if the method is synthetic and/or
+ * deprecated.
+ * @param name
+ * the method's name.
+ * @param desc
+ * the method's descriptor (see {@link Type}).
+ * @param signature
+ * the method's signature. May be <tt>null</tt>.
+ * @param exceptions
+ * the internal names of the method's exception classes (see
+ * {@link Type#getInternalName() getInternalName}). May be
+ * <tt>null</tt>.
*/
- public MethodNode(
- final int access,
- final String name,
- final String desc,
- final String signature,
- final String[] exceptions)
- {
+ public MethodNode(final int access, final String name, final String desc,
+ final String signature, final String[] exceptions) {
this(Opcodes.ASM4, access, name, desc, signature, exceptions);
}
/**
* Constructs a new {@link MethodNode}.
*
- * @param api the ASM API version implemented by this visitor. Must be one
- * of {@link Opcodes#ASM4}.
- * @param access the method's access flags (see {@link Opcodes}). This
- * parameter also indicates if the method is synthetic and/or
- * deprecated.
- * @param name the method's name.
- * @param desc the method's descriptor (see {@link Type}).
- * @param signature the method's signature. May be <tt>null</tt>.
- * @param exceptions the internal names of the method's exception classes
- * (see {@link Type#getInternalName() getInternalName}). May be
- * <tt>null</tt>.
+ * @param api
+ * the ASM API version implemented by this visitor. Must be one
+ * of {@link Opcodes#ASM4}.
+ * @param access
+ * the method's access flags (see {@link Opcodes}). This
+ * parameter also indicates if the method is synthetic and/or
+ * deprecated.
+ * @param name
+ * the method's name.
+ * @param desc
+ * the method's descriptor (see {@link Type}).
+ * @param signature
+ * the method's signature. May be <tt>null</tt>.
+ * @param exceptions
+ * the internal names of the method's exception classes (see
+ * {@link Type#getInternalName() getInternalName}). May be
+ * <tt>null</tt>.
*/
- public MethodNode(
- final int api,
- final int access,
- final String name,
- final String desc,
- final String signature,
- final String[] exceptions)
- {
+ public MethodNode(final int api, final int access, final String name,
+ final String desc, final String signature, final String[] exceptions) {
super(api);
this.access = access;
this.name = name;
this.desc = desc;
this.signature = signature;
- this.exceptions = new ArrayList<String>(exceptions == null
- ? 0
+ this.exceptions = new ArrayList<String>(exceptions == null ? 0
: exceptions.length);
boolean isAbstract = (access & Opcodes.ACC_ABSTRACT) != 0;
if (!isAbstract) {
@@ -274,10 +274,8 @@ public class MethodNode extends MethodVisitor {
}
@Override
- public AnnotationVisitor visitAnnotation(
- final String desc,
- final boolean visible)
- {
+ public AnnotationVisitor visitAnnotation(final String desc,
+ final boolean visible) {
AnnotationNode an = new AnnotationNode(desc);
if (visible) {
if (visibleAnnotations == null) {
@@ -294,28 +292,27 @@ public class MethodNode extends MethodVisitor {
}
@Override
- public AnnotationVisitor visitParameterAnnotation(
- final int parameter,
- final String desc,
- final boolean visible)
- {
+ public AnnotationVisitor visitParameterAnnotation(final int parameter,
+ final String desc, final boolean visible) {
AnnotationNode an = new AnnotationNode(desc);
if (visible) {
if (visibleParameterAnnotations == null) {
int params = Type.getArgumentTypes(this.desc).length;
- visibleParameterAnnotations = (List<AnnotationNode>[])new List<?>[params];
+ visibleParameterAnnotations = (List<AnnotationNode>[]) new List<?>[params];
}
if (visibleParameterAnnotations[parameter] == null) {
- visibleParameterAnnotations[parameter] = new ArrayList<AnnotationNode>(1);
+ visibleParameterAnnotations[parameter] = new ArrayList<AnnotationNode>(
+ 1);
}
visibleParameterAnnotations[parameter].add(an);
} else {
if (invisibleParameterAnnotations == null) {
int params = Type.getArgumentTypes(this.desc).length;
- invisibleParameterAnnotations = (List<AnnotationNode>[])new List<?>[params];
+ invisibleParameterAnnotations = (List<AnnotationNode>[]) new List<?>[params];
}
if (invisibleParameterAnnotations[parameter] == null) {
- invisibleParameterAnnotations[parameter] = new ArrayList<AnnotationNode>(1);
+ invisibleParameterAnnotations[parameter] = new ArrayList<AnnotationNode>(
+ 1);
}
invisibleParameterAnnotations[parameter].add(an);
}
@@ -335,17 +332,10 @@ public class MethodNode extends MethodVisitor {
}
@Override
- public void visitFrame(
- final int type,
- final int nLocal,
- final Object[] local,
- final int nStack,
- final Object[] stack)
- {
- instructions.add(new FrameNode(type, nLocal, local == null
- ? null
- : getLabelNodes(local), nStack, stack == null
- ? null
+ public void visitFrame(final int type, final int nLocal,
+ final Object[] local, final int nStack, final Object[] stack) {
+ instructions.add(new FrameNode(type, nLocal, local == null ? null
+ : getLabelNodes(local), nStack, stack == null ? null
: getLabelNodes(stack)));
}
@@ -370,32 +360,20 @@ public class MethodNode extends MethodVisitor {
}
@Override
- public void visitFieldInsn(
- final int opcode,
- final String owner,
- final String name,
- final String desc)
- {
+ public void visitFieldInsn(final int opcode, final String owner,
+ final String name, final String desc) {
instructions.add(new FieldInsnNode(opcode, owner, name, desc));
}
@Override
- public void visitMethodInsn(
- final int opcode,
- final String owner,
- final String name,
- final String desc)
- {
+ public void visitMethodInsn(final int opcode, final String owner,
+ final String name, final String desc) {
instructions.add(new MethodInsnNode(opcode, owner, name, desc));
}
@Override
- public void visitInvokeDynamicInsn(
- String name,
- String desc,
- Handle bsm,
- Object... bsmArgs)
- {
+ public void visitInvokeDynamicInsn(String name, String desc, Handle bsm,
+ Object... bsmArgs) {
instructions.add(new InvokeDynamicInsnNode(name, desc, bsm, bsmArgs));
}
@@ -420,26 +398,16 @@ public class MethodNode extends MethodVisitor {
}
@Override
- public void visitTableSwitchInsn(
- final int min,
- final int max,
- final Label dflt,
- final Label... labels)
- {
- instructions.add(new TableSwitchInsnNode(min,
- max,
- getLabelNode(dflt),
+ public void visitTableSwitchInsn(final int min, final int max,
+ final Label dflt, final Label... labels) {
+ instructions.add(new TableSwitchInsnNode(min, max, getLabelNode(dflt),
getLabelNodes(labels)));
}
@Override
- public void visitLookupSwitchInsn(
- final Label dflt,
- final int[] keys,
- final Label[] labels)
- {
- instructions.add(new LookupSwitchInsnNode(getLabelNode(dflt),
- keys,
+ public void visitLookupSwitchInsn(final Label dflt, final int[] keys,
+ final Label[] labels) {
+ instructions.add(new LookupSwitchInsnNode(getLabelNode(dflt), keys,
getLabelNodes(labels)));
}
@@ -449,33 +417,18 @@ public class MethodNode extends MethodVisitor {
}
@Override
- public void visitTryCatchBlock(
- final Label start,
- final Label end,
- final Label handler,
- final String type)
- {
+ public void visitTryCatchBlock(final Label start, final Label end,
+ final Label handler, final String type) {
tryCatchBlocks.add(new TryCatchBlockNode(getLabelNode(start),
- getLabelNode(end),
- getLabelNode(handler),
- type));
+ getLabelNode(end), getLabelNode(handler), type));
}
@Override
- public void visitLocalVariable(
- final String name,
- final String desc,
- final String signature,
- final Label start,
- final Label end,
- final int index)
- {
- localVariables.add(new LocalVariableNode(name,
- desc,
- signature,
- getLabelNode(start),
- getLabelNode(end),
- index));
+ public void visitLocalVariable(final String name, final String desc,
+ final String signature, final Label start, final Label end,
+ final int index) {
+ localVariables.add(new LocalVariableNode(name, desc, signature,
+ getLabelNode(start), getLabelNode(end), index));
}
@Override
@@ -499,12 +452,13 @@ public class MethodNode extends MethodVisitor {
* the {@link Label#info} field to store associations between labels and
* label nodes.
*
- * @param l a Label.
+ * @param l
+ * a Label.
* @return the LabelNode corresponding to l.
*/
protected LabelNode getLabelNode(final Label l) {
if (!(l.info instanceof LabelNode)) {
- l.info = new LabelNode(l);
+ l.info = new LabelNode();
}
return (LabelNode) l.info;
}
@@ -539,7 +493,8 @@ public class MethodNode extends MethodVisitor {
* recursively, do not contain elements that were introduced in more recent
* versions of the ASM API than the given version.
*
- * @param api an ASM API version. Must be one of {@link Opcodes#ASM4}.
+ * @param api
+ * an ASM API version. Must be one of {@link Opcodes#ASM4}.
*/
public void check(final int api) {
// nothing to do
@@ -548,15 +503,13 @@ public class MethodNode extends MethodVisitor {
/**
* Makes the given class visitor visit this method.
*
- * @param cv a class visitor.
+ * @param cv
+ * a class visitor.
*/
public void accept(final ClassVisitor cv) {
String[] exceptions = new String[this.exceptions.size()];
this.exceptions.toArray(exceptions);
- MethodVisitor mv = cv.visitMethod(access,
- name,
- desc,
- signature,
+ MethodVisitor mv = cv.visitMethod(access, name, desc, signature,
exceptions);
if (mv != null) {
accept(mv);
@@ -566,7 +519,8 @@ public class MethodNode extends MethodVisitor {
/**
* Makes the given method visitor visit this method.
*
- * @param mv a method visitor.
+ * @param mv
+ * a method visitor.
*/
public void accept(final MethodVisitor mv) {
// visits the method attributes
@@ -588,8 +542,7 @@ public class MethodNode extends MethodVisitor {
AnnotationNode an = invisibleAnnotations.get(i);
an.accept(mv.visitAnnotation(an.desc, false));
}
- n = visibleParameterAnnotations == null
- ? 0
+ n = visibleParameterAnnotations == null ? 0
: visibleParameterAnnotations.length;
for (i = 0; i < n; ++i) {
List<?> l = visibleParameterAnnotations[i];
@@ -601,8 +554,7 @@ public class MethodNode extends MethodVisitor {
an.accept(mv.visitParameterAnnotation(i, an.desc, true));
}
}
- n = invisibleParameterAnnotations == null
- ? 0
+ n = invisibleParameterAnnotations == null ? 0
: invisibleParameterAnnotations.length;
for (i = 0; i < n; ++i) {
List<?> l = invisibleParameterAnnotations[i];
diff --git a/src/asm/scala/tools/asm/tree/MultiANewArrayInsnNode.java b/src/asm/scala/tools/asm/tree/MultiANewArrayInsnNode.java
index 9dfba77335..fe5e8832b3 100644
--- a/src/asm/scala/tools/asm/tree/MultiANewArrayInsnNode.java
+++ b/src/asm/scala/tools/asm/tree/MultiANewArrayInsnNode.java
@@ -42,7 +42,7 @@ import scala.tools.asm.Opcodes;
public class MultiANewArrayInsnNode extends AbstractInsnNode {
/**
- * An array type descriptor (see {@link org.objectweb.asm.Type}).
+ * An array type descriptor (see {@link scala.tools.asm.Type}).
*/
public String desc;
@@ -54,8 +54,10 @@ public class MultiANewArrayInsnNode extends AbstractInsnNode {
/**
* Constructs a new {@link MultiANewArrayInsnNode}.
*
- * @param desc an array type descriptor (see {@link org.objectweb.asm.Type}).
- * @param dims number of dimensions of the array to allocate.
+ * @param desc
+ * an array type descriptor (see {@link scala.tools.asm.Type}).
+ * @param dims
+ * number of dimensions of the array to allocate.
*/
public MultiANewArrayInsnNode(final String desc, final int dims) {
super(Opcodes.MULTIANEWARRAY);
@@ -78,4 +80,4 @@ public class MultiANewArrayInsnNode extends AbstractInsnNode {
return new MultiANewArrayInsnNode(desc, dims);
}
-} \ No newline at end of file
+}
diff --git a/src/asm/scala/tools/asm/tree/TableSwitchInsnNode.java b/src/asm/scala/tools/asm/tree/TableSwitchInsnNode.java
index 929ad9b32b..9b3c2a3437 100644
--- a/src/asm/scala/tools/asm/tree/TableSwitchInsnNode.java
+++ b/src/asm/scala/tools/asm/tree/TableSwitchInsnNode.java
@@ -69,18 +69,18 @@ public class TableSwitchInsnNode extends AbstractInsnNode {
/**
* Constructs a new {@link TableSwitchInsnNode}.
*
- * @param min the minimum key value.
- * @param max the maximum key value.
- * @param dflt beginning of the default handler block.
- * @param labels beginnings of the handler blocks. <tt>labels[i]</tt> is
- * the beginning of the handler block for the <tt>min + i</tt> key.
+ * @param min
+ * the minimum key value.
+ * @param max
+ * the maximum key value.
+ * @param dflt
+ * beginning of the default handler block.
+ * @param labels
+ * beginnings of the handler blocks. <tt>labels[i]</tt> is the
+ * beginning of the handler block for the <tt>min + i</tt> key.
*/
- public TableSwitchInsnNode(
- final int min,
- final int max,
- final LabelNode dflt,
- final LabelNode... labels)
- {
+ public TableSwitchInsnNode(final int min, final int max,
+ final LabelNode dflt, final LabelNode... labels) {
super(Opcodes.TABLESWITCH);
this.min = min;
this.max = max;
@@ -107,9 +107,7 @@ public class TableSwitchInsnNode extends AbstractInsnNode {
@Override
public AbstractInsnNode clone(final Map<LabelNode, LabelNode> labels) {
- return new TableSwitchInsnNode(min,
- max,
- clone(dflt, labels),
- clone(this.labels, labels));
+ return new TableSwitchInsnNode(min, max, clone(dflt, labels), clone(
+ this.labels, labels));
}
-} \ No newline at end of file
+}
diff --git a/src/asm/scala/tools/asm/tree/TryCatchBlockNode.java b/src/asm/scala/tools/asm/tree/TryCatchBlockNode.java
index 375b4cfcb9..ab4fa97c34 100644
--- a/src/asm/scala/tools/asm/tree/TryCatchBlockNode.java
+++ b/src/asm/scala/tools/asm/tree/TryCatchBlockNode.java
@@ -62,19 +62,19 @@ public class TryCatchBlockNode {
/**
* Constructs a new {@link TryCatchBlockNode}.
*
- * @param start beginning of the exception handler's scope (inclusive).
- * @param end end of the exception handler's scope (exclusive).
- * @param handler beginning of the exception handler's code.
- * @param type internal name of the type of exceptions handled by the
- * handler, or <tt>null</tt> to catch any exceptions (for "finally"
- * blocks).
+ * @param start
+ * beginning of the exception handler's scope (inclusive).
+ * @param end
+ * end of the exception handler's scope (exclusive).
+ * @param handler
+ * beginning of the exception handler's code.
+ * @param type
+ * internal name of the type of exceptions handled by the
+ * handler, or <tt>null</tt> to catch any exceptions (for
+ * "finally" blocks).
*/
- public TryCatchBlockNode(
- final LabelNode start,
- final LabelNode end,
- final LabelNode handler,
- final String type)
- {
+ public TryCatchBlockNode(final LabelNode start, final LabelNode end,
+ final LabelNode handler, final String type) {
this.start = start;
this.end = end;
this.handler = handler;
@@ -84,11 +84,11 @@ public class TryCatchBlockNode {
/**
* Makes the given visitor visit this try catch block.
*
- * @param mv a method visitor.
+ * @param mv
+ * a method visitor.
*/
public void accept(final MethodVisitor mv) {
- mv.visitTryCatchBlock(start.getLabel(), end.getLabel(), handler == null
- ? null
- : handler.getLabel(), type);
+ mv.visitTryCatchBlock(start.getLabel(), end.getLabel(),
+ handler == null ? null : handler.getLabel(), type);
}
}
diff --git a/src/asm/scala/tools/asm/tree/TypeInsnNode.java b/src/asm/scala/tools/asm/tree/TypeInsnNode.java
index 0b2666c498..3210dd60e6 100644
--- a/src/asm/scala/tools/asm/tree/TypeInsnNode.java
+++ b/src/asm/scala/tools/asm/tree/TypeInsnNode.java
@@ -43,17 +43,19 @@ public class TypeInsnNode extends AbstractInsnNode {
/**
* The operand of this instruction. This operand is an internal name (see
- * {@link org.objectweb.asm.Type}).
+ * {@link scala.tools.asm.Type}).
*/
public String desc;
/**
* Constructs a new {@link TypeInsnNode}.
*
- * @param opcode the opcode of the type instruction to be constructed. This
- * opcode must be NEW, ANEWARRAY, CHECKCAST or INSTANCEOF.
- * @param desc the operand of the instruction to be constructed. This
- * operand is an internal name (see {@link org.objectweb.asm.Type}).
+ * @param opcode
+ * the opcode of the type instruction to be constructed. This
+ * opcode must be NEW, ANEWARRAY, CHECKCAST or INSTANCEOF.
+ * @param desc
+ * the operand of the instruction to be constructed. This operand
+ * is an internal name (see {@link scala.tools.asm.Type}).
*/
public TypeInsnNode(final int opcode, final String desc) {
super(opcode);
@@ -63,8 +65,9 @@ public class TypeInsnNode extends AbstractInsnNode {
/**
* Sets the opcode of this instruction.
*
- * @param opcode the new instruction opcode. This opcode must be NEW,
- * ANEWARRAY, CHECKCAST or INSTANCEOF.
+ * @param opcode
+ * the new instruction opcode. This opcode must be NEW,
+ * ANEWARRAY, CHECKCAST or INSTANCEOF.
*/
public void setOpcode(final int opcode) {
this.opcode = opcode;
@@ -84,4 +87,4 @@ public class TypeInsnNode extends AbstractInsnNode {
public AbstractInsnNode clone(final Map<LabelNode, LabelNode> labels) {
return new TypeInsnNode(opcode, desc);
}
-} \ No newline at end of file
+}
diff --git a/src/asm/scala/tools/asm/tree/VarInsnNode.java b/src/asm/scala/tools/asm/tree/VarInsnNode.java
index 89f572db59..5dd9ef6726 100644
--- a/src/asm/scala/tools/asm/tree/VarInsnNode.java
+++ b/src/asm/scala/tools/asm/tree/VarInsnNode.java
@@ -51,11 +51,13 @@ public class VarInsnNode extends AbstractInsnNode {
/**
* Constructs a new {@link VarInsnNode}.
*
- * @param opcode the opcode of the local variable instruction to be
- * constructed. This opcode must be ILOAD, LLOAD, FLOAD, DLOAD,
- * ALOAD, ISTORE, LSTORE, FSTORE, DSTORE, ASTORE or RET.
- * @param var the operand of the instruction to be constructed. This operand
- * is the index of a local variable.
+ * @param opcode
+ * the opcode of the local variable instruction to be
+ * constructed. This opcode must be ILOAD, LLOAD, FLOAD, DLOAD,
+ * ALOAD, ISTORE, LSTORE, FSTORE, DSTORE, ASTORE or RET.
+ * @param var
+ * the operand of the instruction to be constructed. This operand
+ * is the index of a local variable.
*/
public VarInsnNode(final int opcode, final int var) {
super(opcode);
@@ -65,9 +67,10 @@ public class VarInsnNode extends AbstractInsnNode {
/**
* Sets the opcode of this instruction.
*
- * @param opcode the new instruction opcode. This opcode must be ILOAD,
- * LLOAD, FLOAD, DLOAD, ALOAD, ISTORE, LSTORE, FSTORE, DSTORE, ASTORE
- * or RET.
+ * @param opcode
+ * the new instruction opcode. This opcode must be ILOAD, LLOAD,
+ * FLOAD, DLOAD, ALOAD, ISTORE, LSTORE, FSTORE, DSTORE, ASTORE or
+ * RET.
*/
public void setOpcode(final int opcode) {
this.opcode = opcode;
@@ -87,4 +90,4 @@ public class VarInsnNode extends AbstractInsnNode {
public AbstractInsnNode clone(final Map<LabelNode, LabelNode> labels) {
return new VarInsnNode(opcode, var);
}
-} \ No newline at end of file
+}
diff --git a/src/asm/scala/tools/asm/tree/analysis/Analyzer.java b/src/asm/scala/tools/asm/tree/analysis/Analyzer.java
index df387b0b8e..0134555f10 100644
--- a/src/asm/scala/tools/asm/tree/analysis/Analyzer.java
+++ b/src/asm/scala/tools/asm/tree/analysis/Analyzer.java
@@ -51,9 +51,10 @@ import scala.tools.asm.tree.VarInsnNode;
* A semantic bytecode analyzer. <i>This class does not fully check that JSR and
* RET instructions are valid.</i>
*
- * @param <V> type of the Value used for the analysis.
+ * @param <V>
+ * type of the Value used for the analysis.
*
- * @author Eric Bruneton
+ * @author Eric Bruneton
*/
public class Analyzer<V extends Value> implements Opcodes {
@@ -78,8 +79,9 @@ public class Analyzer<V extends Value> implements Opcodes {
/**
* Constructs a new {@link Analyzer}.
*
- * @param interpreter the interpreter to be used to symbolically interpret
- * the bytecode instructions.
+ * @param interpreter
+ * the interpreter to be used to symbolically interpret the
+ * bytecode instructions.
*/
public Analyzer(final Interpreter<V> interpreter) {
this.interpreter = interpreter;
@@ -88,26 +90,28 @@ public class Analyzer<V extends Value> implements Opcodes {
/**
* Analyzes the given method.
*
- * @param owner the internal name of the class to which the method belongs.
- * @param m the method to be analyzed.
+ * @param owner
+ * the internal name of the class to which the method belongs.
+ * @param m
+ * the method to be analyzed.
* @return the symbolic state of the execution stack frame at each bytecode
* instruction of the method. The size of the returned array is
* equal to the number of instructions (and labels) of the method. A
* given frame is <tt>null</tt> if and only if the corresponding
* instruction cannot be reached (dead code).
- * @throws AnalyzerException if a problem occurs during the analysis.
+ * @throws AnalyzerException
+ * if a problem occurs during the analysis.
*/
public Frame<V>[] analyze(final String owner, final MethodNode m)
- throws AnalyzerException
- {
+ throws AnalyzerException {
if ((m.access & (ACC_ABSTRACT | ACC_NATIVE)) != 0) {
- frames = (Frame<V>[])new Frame<?>[0];
+ frames = (Frame<V>[]) new Frame<?>[0];
return frames;
}
n = m.instructions.size();
insns = m.instructions;
- handlers = (List<TryCatchBlockNode>[])new List<?>[n];
- frames = (Frame<V>[])new Frame<?>[n];
+ handlers = (List<TryCatchBlockNode>[]) new List<?>[n];
+ frames = (Frame<V>[]) new Frame<?>[n];
subroutines = new Subroutine[n];
queued = new boolean[n];
queue = new int[n];
@@ -188,8 +192,7 @@ public class Analyzer<V extends Value> implements Opcodes {
if (insnType == AbstractInsnNode.LABEL
|| insnType == AbstractInsnNode.LINE
- || insnType == AbstractInsnNode.FRAME)
- {
+ || insnType == AbstractInsnNode.FRAME) {
merge(insn + 1, f, subroutine);
newControlFlowEdge(insn, insn + 1);
} else {
@@ -205,8 +208,7 @@ public class Analyzer<V extends Value> implements Opcodes {
int jump = insns.indexOf(j.label);
if (insnOpcode == JSR) {
merge(jump, current, new Subroutine(j.label,
- m.maxLocals,
- j));
+ m.maxLocals, j));
} else {
merge(jump, current, subroutine);
}
@@ -235,31 +237,27 @@ public class Analyzer<V extends Value> implements Opcodes {
}
} else if (insnOpcode == RET) {
if (subroutine == null) {
- throw new AnalyzerException(insnNode, "RET instruction outside of a sub routine");
+ throw new AnalyzerException(insnNode,
+ "RET instruction outside of a sub routine");
}
for (int i = 0; i < subroutine.callers.size(); ++i) {
JumpInsnNode caller = subroutine.callers.get(i);
int call = insns.indexOf(caller);
if (frames[call] != null) {
- merge(call + 1,
- frames[call],
- current,
- subroutines[call],
- subroutine.access);
+ merge(call + 1, frames[call], current,
+ subroutines[call], subroutine.access);
newControlFlowEdge(insn, call + 1);
}
}
} else if (insnOpcode != ATHROW
- && (insnOpcode < IRETURN || insnOpcode > RETURN))
- {
+ && (insnOpcode < IRETURN || insnOpcode > RETURN)) {
if (subroutine != null) {
if (insnNode instanceof VarInsnNode) {
int var = ((VarInsnNode) insnNode).var;
subroutine.access[var] = true;
if (insnOpcode == LLOAD || insnOpcode == DLOAD
|| insnOpcode == LSTORE
- || insnOpcode == DSTORE)
- {
+ || insnOpcode == DSTORE) {
subroutine.access[var + 1] = true;
}
} else if (insnNode instanceof IincInsnNode) {
@@ -292,23 +290,23 @@ public class Analyzer<V extends Value> implements Opcodes {
}
}
} catch (AnalyzerException e) {
- throw new AnalyzerException(e.node, "Error at instruction " + insn
- + ": " + e.getMessage(), e);
+ throw new AnalyzerException(e.node, "Error at instruction "
+ + insn + ": " + e.getMessage(), e);
} catch (Exception e) {
- throw new AnalyzerException(insnNode, "Error at instruction " + insn
- + ": " + e.getMessage(), e);
+ throw new AnalyzerException(insnNode, "Error at instruction "
+ + insn + ": " + e.getMessage(), e);
}
}
return frames;
}
- private void findSubroutine(int insn, final Subroutine sub, final List<AbstractInsnNode> calls)
- throws AnalyzerException
- {
+ private void findSubroutine(int insn, final Subroutine sub,
+ final List<AbstractInsnNode> calls) throws AnalyzerException {
while (true) {
if (insn < 0 || insn >= n) {
- throw new AnalyzerException(null, "Execution can fall off end of the code");
+ throw new AnalyzerException(null,
+ "Execution can fall off end of the code");
}
if (subroutines[insn] != null) {
return;
@@ -352,18 +350,18 @@ public class Analyzer<V extends Value> implements Opcodes {
// if insn does not falls through to the next instruction, return.
switch (node.getOpcode()) {
- case GOTO:
- case RET:
- case TABLESWITCH:
- case LOOKUPSWITCH:
- case IRETURN:
- case LRETURN:
- case FRETURN:
- case DRETURN:
- case ARETURN:
- case RETURN:
- case ATHROW:
- return;
+ case GOTO:
+ case RET:
+ case TABLESWITCH:
+ case LOOKUPSWITCH:
+ case IRETURN:
+ case LRETURN:
+ case FRETURN:
+ case DRETURN:
+ case ARETURN:
+ case RETURN:
+ case ATHROW:
+ return;
}
insn++;
}
@@ -387,8 +385,9 @@ public class Analyzer<V extends Value> implements Opcodes {
/**
* Returns the exception handlers for the given instruction.
*
- * @param insn the index of an instruction of the last recently analyzed
- * method.
+ * @param insn
+ * the index of an instruction of the last recently analyzed
+ * method.
* @return a list of {@link TryCatchBlockNode} objects.
*/
public List<TryCatchBlockNode> getHandlers(final int insn) {
@@ -400,9 +399,12 @@ public class Analyzer<V extends Value> implements Opcodes {
* execution of control flow analysis loop in #analyze. The default
* implementation of this method does nothing.
*
- * @param owner the internal name of the class to which the method belongs.
- * @param m the method to be analyzed.
- * @throws AnalyzerException if a problem occurs.
+ * @param owner
+ * the internal name of the class to which the method belongs.
+ * @param m
+ * the method to be analyzed.
+ * @throws AnalyzerException
+ * if a problem occurs.
*/
protected void init(String owner, MethodNode m) throws AnalyzerException {
}
@@ -410,8 +412,10 @@ public class Analyzer<V extends Value> implements Opcodes {
/**
* Constructs a new frame with the given size.
*
- * @param nLocals the maximum number of local variables of the frame.
- * @param nStack the maximum stack size of the frame.
+ * @param nLocals
+ * the maximum number of local variables of the frame.
+ * @param nStack
+ * the maximum stack size of the frame.
* @return the created frame.
*/
protected Frame<V> newFrame(final int nLocals, final int nStack) {
@@ -421,7 +425,8 @@ public class Analyzer<V extends Value> implements Opcodes {
/**
* Constructs a new frame that is identical to the given frame.
*
- * @param src a frame.
+ * @param src
+ * a frame.
* @return the created frame.
*/
protected Frame<V> newFrame(final Frame<? extends V> src) {
@@ -434,8 +439,10 @@ public class Analyzer<V extends Value> implements Opcodes {
* control flow graph of a method (this method is called by the
* {@link #analyze analyze} method during its visit of the method's code).
*
- * @param insn an instruction index.
- * @param successor index of a successor instruction.
+ * @param insn
+ * an instruction index.
+ * @param successor
+ * index of a successor instruction.
*/
protected void newControlFlowEdge(final int insn, final int successor) {
}
@@ -447,16 +454,16 @@ public class Analyzer<V extends Value> implements Opcodes {
* method is called by the {@link #analyze analyze} method during its visit
* of the method's code).
*
- * @param insn an instruction index.
- * @param successor index of a successor instruction.
+ * @param insn
+ * an instruction index.
+ * @param successor
+ * index of a successor instruction.
* @return true if this edge must be considered in the data flow analysis
* performed by this analyzer, or false otherwise. The default
* implementation of this method always returns true.
*/
- protected boolean newControlFlowExceptionEdge(
- final int insn,
- final int successor)
- {
+ protected boolean newControlFlowExceptionEdge(final int insn,
+ final int successor) {
return true;
}
@@ -469,28 +476,25 @@ public class Analyzer<V extends Value> implements Opcodes {
* the {@link #analyze analyze} method during its visit of the method's
* code).
*
- * @param insn an instruction index.
- * @param tcb TryCatchBlockNode corresponding to this edge.
+ * @param insn
+ * an instruction index.
+ * @param tcb
+ * TryCatchBlockNode corresponding to this edge.
* @return true if this edge must be considered in the data flow analysis
* performed by this analyzer, or false otherwise. The default
* implementation of this method delegates to
* {@link #newControlFlowExceptionEdge(int, int)
* newControlFlowExceptionEdge(int, int)}.
*/
- protected boolean newControlFlowExceptionEdge(
- final int insn,
- final TryCatchBlockNode tcb)
- {
+ protected boolean newControlFlowExceptionEdge(final int insn,
+ final TryCatchBlockNode tcb) {
return newControlFlowExceptionEdge(insn, insns.indexOf(tcb.handler));
}
// -------------------------------------------------------------------------
- private void merge(
- final int insn,
- final Frame<V> frame,
- final Subroutine subroutine) throws AnalyzerException
- {
+ private void merge(final int insn, final Frame<V> frame,
+ final Subroutine subroutine) throws AnalyzerException {
Frame<V> oldFrame = frames[insn];
Subroutine oldSubroutine = subroutines[insn];
boolean changes;
@@ -518,13 +522,9 @@ public class Analyzer<V extends Value> implements Opcodes {
}
}
- private void merge(
- final int insn,
- final Frame<V> beforeJSR,
- final Frame<V> afterRET,
- final Subroutine subroutineBeforeJSR,
- final boolean[] access) throws AnalyzerException
- {
+ private void merge(final int insn, final Frame<V> beforeJSR,
+ final Frame<V> afterRET, final Subroutine subroutineBeforeJSR,
+ final boolean[] access) throws AnalyzerException {
Frame<V> oldFrame = frames[insn];
Subroutine oldSubroutine = subroutines[insn];
boolean changes;
diff --git a/src/asm/scala/tools/asm/tree/analysis/AnalyzerException.java b/src/asm/scala/tools/asm/tree/analysis/AnalyzerException.java
index a89bb3513f..5e3f51f21a 100644
--- a/src/asm/scala/tools/asm/tree/analysis/AnalyzerException.java
+++ b/src/asm/scala/tools/asm/tree/analysis/AnalyzerException.java
@@ -46,17 +46,14 @@ public class AnalyzerException extends Exception {
this.node = node;
}
- public AnalyzerException(final AbstractInsnNode node, final String msg, final Throwable exception) {
+ public AnalyzerException(final AbstractInsnNode node, final String msg,
+ final Throwable exception) {
super(msg, exception);
this.node = node;
}
- public AnalyzerException(
- final AbstractInsnNode node,
- final String msg,
- final Object expected,
- final Value encountered)
- {
+ public AnalyzerException(final AbstractInsnNode node, final String msg,
+ final Object expected, final Value encountered) {
super((msg == null ? "Expected " : msg + ": expected ") + expected
+ ", but found " + encountered);
this.node = node;
diff --git a/src/asm/scala/tools/asm/tree/analysis/BasicInterpreter.java b/src/asm/scala/tools/asm/tree/analysis/BasicInterpreter.java
index 64ddcc11e6..8d6653c1c5 100644
--- a/src/asm/scala/tools/asm/tree/analysis/BasicInterpreter.java
+++ b/src/asm/scala/tools/asm/tree/analysis/BasicInterpreter.java
@@ -50,8 +50,7 @@ import scala.tools.asm.tree.TypeInsnNode;
* @author Bing Ran
*/
public class BasicInterpreter extends Interpreter<BasicValue> implements
- Opcodes
-{
+ Opcodes {
public BasicInterpreter() {
super(ASM4);
@@ -67,292 +66,286 @@ public class BasicInterpreter extends Interpreter<BasicValue> implements
return BasicValue.UNINITIALIZED_VALUE;
}
switch (type.getSort()) {
- case Type.VOID:
- return null;
- case Type.BOOLEAN:
- case Type.CHAR:
- case Type.BYTE:
- case Type.SHORT:
- case Type.INT:
- return BasicValue.INT_VALUE;
- case Type.FLOAT:
- return BasicValue.FLOAT_VALUE;
- case Type.LONG:
- return BasicValue.LONG_VALUE;
- case Type.DOUBLE:
- return BasicValue.DOUBLE_VALUE;
- case Type.ARRAY:
- case Type.OBJECT:
- return BasicValue.REFERENCE_VALUE;
- default:
- throw new Error("Internal error");
+ case Type.VOID:
+ return null;
+ case Type.BOOLEAN:
+ case Type.CHAR:
+ case Type.BYTE:
+ case Type.SHORT:
+ case Type.INT:
+ return BasicValue.INT_VALUE;
+ case Type.FLOAT:
+ return BasicValue.FLOAT_VALUE;
+ case Type.LONG:
+ return BasicValue.LONG_VALUE;
+ case Type.DOUBLE:
+ return BasicValue.DOUBLE_VALUE;
+ case Type.ARRAY:
+ case Type.OBJECT:
+ return BasicValue.REFERENCE_VALUE;
+ default:
+ throw new Error("Internal error");
}
}
@Override
public BasicValue newOperation(final AbstractInsnNode insn)
- throws AnalyzerException
- {
+ throws AnalyzerException {
switch (insn.getOpcode()) {
- case ACONST_NULL:
- return newValue(Type.getObjectType("null"));
- case ICONST_M1:
- case ICONST_0:
- case ICONST_1:
- case ICONST_2:
- case ICONST_3:
- case ICONST_4:
- case ICONST_5:
+ case ACONST_NULL:
+ return newValue(Type.getObjectType("null"));
+ case ICONST_M1:
+ case ICONST_0:
+ case ICONST_1:
+ case ICONST_2:
+ case ICONST_3:
+ case ICONST_4:
+ case ICONST_5:
+ return BasicValue.INT_VALUE;
+ case LCONST_0:
+ case LCONST_1:
+ return BasicValue.LONG_VALUE;
+ case FCONST_0:
+ case FCONST_1:
+ case FCONST_2:
+ return BasicValue.FLOAT_VALUE;
+ case DCONST_0:
+ case DCONST_1:
+ return BasicValue.DOUBLE_VALUE;
+ case BIPUSH:
+ case SIPUSH:
+ return BasicValue.INT_VALUE;
+ case LDC:
+ Object cst = ((LdcInsnNode) insn).cst;
+ if (cst instanceof Integer) {
return BasicValue.INT_VALUE;
- case LCONST_0:
- case LCONST_1:
- return BasicValue.LONG_VALUE;
- case FCONST_0:
- case FCONST_1:
- case FCONST_2:
+ } else if (cst instanceof Float) {
return BasicValue.FLOAT_VALUE;
- case DCONST_0:
- case DCONST_1:
+ } else if (cst instanceof Long) {
+ return BasicValue.LONG_VALUE;
+ } else if (cst instanceof Double) {
return BasicValue.DOUBLE_VALUE;
- case BIPUSH:
- case SIPUSH:
- return BasicValue.INT_VALUE;
- case LDC:
- Object cst = ((LdcInsnNode) insn).cst;
- if (cst instanceof Integer) {
- return BasicValue.INT_VALUE;
- } else if (cst instanceof Float) {
- return BasicValue.FLOAT_VALUE;
- } else if (cst instanceof Long) {
- return BasicValue.LONG_VALUE;
- } else if (cst instanceof Double) {
- return BasicValue.DOUBLE_VALUE;
- } else if (cst instanceof String) {
- return newValue(Type.getObjectType("java/lang/String"));
- } else if (cst instanceof Type) {
- int sort = ((Type) cst).getSort();
- if (sort == Type.OBJECT || sort == Type.ARRAY) {
- return newValue(Type.getObjectType("java/lang/Class"));
- } else if (sort == Type.METHOD) {
- return newValue(Type.getObjectType("java/lang/invoke/MethodType"));
- } else {
- throw new IllegalArgumentException("Illegal LDC constant " + cst);
- }
- } else if (cst instanceof Handle) {
- return newValue(Type.getObjectType("java/lang/invoke/MethodHandle"));
+ } else if (cst instanceof String) {
+ return newValue(Type.getObjectType("java/lang/String"));
+ } else if (cst instanceof Type) {
+ int sort = ((Type) cst).getSort();
+ if (sort == Type.OBJECT || sort == Type.ARRAY) {
+ return newValue(Type.getObjectType("java/lang/Class"));
+ } else if (sort == Type.METHOD) {
+ return newValue(Type
+ .getObjectType("java/lang/invoke/MethodType"));
} else {
- throw new IllegalArgumentException("Illegal LDC constant " + cst);
+ throw new IllegalArgumentException("Illegal LDC constant "
+ + cst);
}
- case JSR:
- return BasicValue.RETURNADDRESS_VALUE;
- case GETSTATIC:
- return newValue(Type.getType(((FieldInsnNode) insn).desc));
- case NEW:
- return newValue(Type.getObjectType(((TypeInsnNode) insn).desc));
- default:
- throw new Error("Internal error.");
+ } else if (cst instanceof Handle) {
+ return newValue(Type
+ .getObjectType("java/lang/invoke/MethodHandle"));
+ } else {
+ throw new IllegalArgumentException("Illegal LDC constant "
+ + cst);
+ }
+ case JSR:
+ return BasicValue.RETURNADDRESS_VALUE;
+ case GETSTATIC:
+ return newValue(Type.getType(((FieldInsnNode) insn).desc));
+ case NEW:
+ return newValue(Type.getObjectType(((TypeInsnNode) insn).desc));
+ default:
+ throw new Error("Internal error.");
}
}
@Override
- public BasicValue copyOperation(final AbstractInsnNode insn, final BasicValue value)
- throws AnalyzerException
- {
+ public BasicValue copyOperation(final AbstractInsnNode insn,
+ final BasicValue value) throws AnalyzerException {
return value;
}
@Override
- public BasicValue unaryOperation(final AbstractInsnNode insn, final BasicValue value)
- throws AnalyzerException
- {
+ public BasicValue unaryOperation(final AbstractInsnNode insn,
+ final BasicValue value) throws AnalyzerException {
switch (insn.getOpcode()) {
- case INEG:
- case IINC:
- case L2I:
- case F2I:
- case D2I:
- case I2B:
- case I2C:
- case I2S:
- return BasicValue.INT_VALUE;
- case FNEG:
- case I2F:
- case L2F:
- case D2F:
- return BasicValue.FLOAT_VALUE;
- case LNEG:
- case I2L:
- case F2L:
- case D2L:
- return BasicValue.LONG_VALUE;
- case DNEG:
- case I2D:
- case L2D:
- case F2D:
- return BasicValue.DOUBLE_VALUE;
- case IFEQ:
- case IFNE:
- case IFLT:
- case IFGE:
- case IFGT:
- case IFLE:
- case TABLESWITCH:
- case LOOKUPSWITCH:
- case IRETURN:
- case LRETURN:
- case FRETURN:
- case DRETURN:
- case ARETURN:
- case PUTSTATIC:
- return null;
- case GETFIELD:
- return newValue(Type.getType(((FieldInsnNode) insn).desc));
- case NEWARRAY:
- switch (((IntInsnNode) insn).operand) {
- case T_BOOLEAN:
- return newValue(Type.getType("[Z"));
- case T_CHAR:
- return newValue(Type.getType("[C"));
- case T_BYTE:
- return newValue(Type.getType("[B"));
- case T_SHORT:
- return newValue(Type.getType("[S"));
- case T_INT:
- return newValue(Type.getType("[I"));
- case T_FLOAT:
- return newValue(Type.getType("[F"));
- case T_DOUBLE:
- return newValue(Type.getType("[D"));
- case T_LONG:
- return newValue(Type.getType("[J"));
- default:
- throw new AnalyzerException(insn, "Invalid array type");
- }
- case ANEWARRAY:
- String desc = ((TypeInsnNode) insn).desc;
- return newValue(Type.getType("[" + Type.getObjectType(desc)));
- case ARRAYLENGTH:
- return BasicValue.INT_VALUE;
- case ATHROW:
- return null;
- case CHECKCAST:
- desc = ((TypeInsnNode) insn).desc;
- return newValue(Type.getObjectType(desc));
- case INSTANCEOF:
- return BasicValue.INT_VALUE;
- case MONITORENTER:
- case MONITOREXIT:
- case IFNULL:
- case IFNONNULL:
- return null;
+ case INEG:
+ case IINC:
+ case L2I:
+ case F2I:
+ case D2I:
+ case I2B:
+ case I2C:
+ case I2S:
+ return BasicValue.INT_VALUE;
+ case FNEG:
+ case I2F:
+ case L2F:
+ case D2F:
+ return BasicValue.FLOAT_VALUE;
+ case LNEG:
+ case I2L:
+ case F2L:
+ case D2L:
+ return BasicValue.LONG_VALUE;
+ case DNEG:
+ case I2D:
+ case L2D:
+ case F2D:
+ return BasicValue.DOUBLE_VALUE;
+ case IFEQ:
+ case IFNE:
+ case IFLT:
+ case IFGE:
+ case IFGT:
+ case IFLE:
+ case TABLESWITCH:
+ case LOOKUPSWITCH:
+ case IRETURN:
+ case LRETURN:
+ case FRETURN:
+ case DRETURN:
+ case ARETURN:
+ case PUTSTATIC:
+ return null;
+ case GETFIELD:
+ return newValue(Type.getType(((FieldInsnNode) insn).desc));
+ case NEWARRAY:
+ switch (((IntInsnNode) insn).operand) {
+ case T_BOOLEAN:
+ return newValue(Type.getType("[Z"));
+ case T_CHAR:
+ return newValue(Type.getType("[C"));
+ case T_BYTE:
+ return newValue(Type.getType("[B"));
+ case T_SHORT:
+ return newValue(Type.getType("[S"));
+ case T_INT:
+ return newValue(Type.getType("[I"));
+ case T_FLOAT:
+ return newValue(Type.getType("[F"));
+ case T_DOUBLE:
+ return newValue(Type.getType("[D"));
+ case T_LONG:
+ return newValue(Type.getType("[J"));
default:
- throw new Error("Internal error.");
+ throw new AnalyzerException(insn, "Invalid array type");
+ }
+ case ANEWARRAY:
+ String desc = ((TypeInsnNode) insn).desc;
+ return newValue(Type.getType("[" + Type.getObjectType(desc)));
+ case ARRAYLENGTH:
+ return BasicValue.INT_VALUE;
+ case ATHROW:
+ return null;
+ case CHECKCAST:
+ desc = ((TypeInsnNode) insn).desc;
+ return newValue(Type.getObjectType(desc));
+ case INSTANCEOF:
+ return BasicValue.INT_VALUE;
+ case MONITORENTER:
+ case MONITOREXIT:
+ case IFNULL:
+ case IFNONNULL:
+ return null;
+ default:
+ throw new Error("Internal error.");
}
}
@Override
- public BasicValue binaryOperation(
- final AbstractInsnNode insn,
- final BasicValue value1,
- final BasicValue value2) throws AnalyzerException
- {
+ public BasicValue binaryOperation(final AbstractInsnNode insn,
+ final BasicValue value1, final BasicValue value2)
+ throws AnalyzerException {
switch (insn.getOpcode()) {
- case IALOAD:
- case BALOAD:
- case CALOAD:
- case SALOAD:
- case IADD:
- case ISUB:
- case IMUL:
- case IDIV:
- case IREM:
- case ISHL:
- case ISHR:
- case IUSHR:
- case IAND:
- case IOR:
- case IXOR:
- return BasicValue.INT_VALUE;
- case FALOAD:
- case FADD:
- case FSUB:
- case FMUL:
- case FDIV:
- case FREM:
- return BasicValue.FLOAT_VALUE;
- case LALOAD:
- case LADD:
- case LSUB:
- case LMUL:
- case LDIV:
- case LREM:
- case LSHL:
- case LSHR:
- case LUSHR:
- case LAND:
- case LOR:
- case LXOR:
- return BasicValue.LONG_VALUE;
- case DALOAD:
- case DADD:
- case DSUB:
- case DMUL:
- case DDIV:
- case DREM:
- return BasicValue.DOUBLE_VALUE;
- case AALOAD:
- return BasicValue.REFERENCE_VALUE;
- case LCMP:
- case FCMPL:
- case FCMPG:
- case DCMPL:
- case DCMPG:
- return BasicValue.INT_VALUE;
- case IF_ICMPEQ:
- case IF_ICMPNE:
- case IF_ICMPLT:
- case IF_ICMPGE:
- case IF_ICMPGT:
- case IF_ICMPLE:
- case IF_ACMPEQ:
- case IF_ACMPNE:
- case PUTFIELD:
- return null;
- default:
- throw new Error("Internal error.");
+ case IALOAD:
+ case BALOAD:
+ case CALOAD:
+ case SALOAD:
+ case IADD:
+ case ISUB:
+ case IMUL:
+ case IDIV:
+ case IREM:
+ case ISHL:
+ case ISHR:
+ case IUSHR:
+ case IAND:
+ case IOR:
+ case IXOR:
+ return BasicValue.INT_VALUE;
+ case FALOAD:
+ case FADD:
+ case FSUB:
+ case FMUL:
+ case FDIV:
+ case FREM:
+ return BasicValue.FLOAT_VALUE;
+ case LALOAD:
+ case LADD:
+ case LSUB:
+ case LMUL:
+ case LDIV:
+ case LREM:
+ case LSHL:
+ case LSHR:
+ case LUSHR:
+ case LAND:
+ case LOR:
+ case LXOR:
+ return BasicValue.LONG_VALUE;
+ case DALOAD:
+ case DADD:
+ case DSUB:
+ case DMUL:
+ case DDIV:
+ case DREM:
+ return BasicValue.DOUBLE_VALUE;
+ case AALOAD:
+ return BasicValue.REFERENCE_VALUE;
+ case LCMP:
+ case FCMPL:
+ case FCMPG:
+ case DCMPL:
+ case DCMPG:
+ return BasicValue.INT_VALUE;
+ case IF_ICMPEQ:
+ case IF_ICMPNE:
+ case IF_ICMPLT:
+ case IF_ICMPGE:
+ case IF_ICMPGT:
+ case IF_ICMPLE:
+ case IF_ACMPEQ:
+ case IF_ACMPNE:
+ case PUTFIELD:
+ return null;
+ default:
+ throw new Error("Internal error.");
}
}
@Override
- public BasicValue ternaryOperation(
- final AbstractInsnNode insn,
- final BasicValue value1,
- final BasicValue value2,
- final BasicValue value3) throws AnalyzerException
- {
+ public BasicValue ternaryOperation(final AbstractInsnNode insn,
+ final BasicValue value1, final BasicValue value2,
+ final BasicValue value3) throws AnalyzerException {
return null;
}
@Override
- public BasicValue naryOperation(final AbstractInsnNode insn, final List<? extends BasicValue> values)
- throws AnalyzerException
- {
+ public BasicValue naryOperation(final AbstractInsnNode insn,
+ final List<? extends BasicValue> values) throws AnalyzerException {
int opcode = insn.getOpcode();
if (opcode == MULTIANEWARRAY) {
return newValue(Type.getType(((MultiANewArrayInsnNode) insn).desc));
- } else if (opcode == INVOKEDYNAMIC){
- return newValue(Type.getReturnType(((InvokeDynamicInsnNode) insn).desc));
+ } else if (opcode == INVOKEDYNAMIC) {
+ return newValue(Type
+ .getReturnType(((InvokeDynamicInsnNode) insn).desc));
} else {
return newValue(Type.getReturnType(((MethodInsnNode) insn).desc));
}
}
@Override
- public void returnOperation(
- final AbstractInsnNode insn,
- final BasicValue value,
- final BasicValue expected) throws AnalyzerException
- {
+ public void returnOperation(final AbstractInsnNode insn,
+ final BasicValue value, final BasicValue expected)
+ throws AnalyzerException {
}
@Override
diff --git a/src/asm/scala/tools/asm/tree/analysis/BasicValue.java b/src/asm/scala/tools/asm/tree/analysis/BasicValue.java
index 6c449db9b0..439941fb9f 100644
--- a/src/asm/scala/tools/asm/tree/analysis/BasicValue.java
+++ b/src/asm/scala/tools/asm/tree/analysis/BasicValue.java
@@ -48,11 +48,14 @@ public class BasicValue implements Value {
public static final BasicValue LONG_VALUE = new BasicValue(Type.LONG_TYPE);
- public static final BasicValue DOUBLE_VALUE = new BasicValue(Type.DOUBLE_TYPE);
+ public static final BasicValue DOUBLE_VALUE = new BasicValue(
+ Type.DOUBLE_TYPE);
- public static final BasicValue REFERENCE_VALUE = new BasicValue(Type.getObjectType("java/lang/Object"));
+ public static final BasicValue REFERENCE_VALUE = new BasicValue(
+ Type.getObjectType("java/lang/Object"));
- public static final BasicValue RETURNADDRESS_VALUE = new BasicValue(Type.VOID_TYPE);
+ public static final BasicValue RETURNADDRESS_VALUE = new BasicValue(
+ Type.VOID_TYPE);
private final Type type;
diff --git a/src/asm/scala/tools/asm/tree/analysis/BasicVerifier.java b/src/asm/scala/tools/asm/tree/analysis/BasicVerifier.java
index 9297dd9294..71666edb74 100644
--- a/src/asm/scala/tools/asm/tree/analysis/BasicVerifier.java
+++ b/src/asm/scala/tools/asm/tree/analysis/BasicVerifier.java
@@ -55,47 +55,41 @@ public class BasicVerifier extends BasicInterpreter {
}
@Override
- public BasicValue copyOperation(final AbstractInsnNode insn, final BasicValue value)
- throws AnalyzerException
- {
+ public BasicValue copyOperation(final AbstractInsnNode insn,
+ final BasicValue value) throws AnalyzerException {
Value expected;
switch (insn.getOpcode()) {
- case ILOAD:
- case ISTORE:
- expected = BasicValue.INT_VALUE;
- break;
- case FLOAD:
- case FSTORE:
- expected = BasicValue.FLOAT_VALUE;
- break;
- case LLOAD:
- case LSTORE:
- expected = BasicValue.LONG_VALUE;
- break;
- case DLOAD:
- case DSTORE:
- expected = BasicValue.DOUBLE_VALUE;
- break;
- case ALOAD:
- if (!value.isReference()) {
- throw new AnalyzerException(insn,
- null,
- "an object reference",
- value);
- }
- return value;
- case ASTORE:
- if (!value.isReference()
- && !BasicValue.RETURNADDRESS_VALUE.equals(value))
- {
- throw new AnalyzerException(insn,
- null,
- "an object reference or a return address",
- value);
- }
- return value;
- default:
- return value;
+ case ILOAD:
+ case ISTORE:
+ expected = BasicValue.INT_VALUE;
+ break;
+ case FLOAD:
+ case FSTORE:
+ expected = BasicValue.FLOAT_VALUE;
+ break;
+ case LLOAD:
+ case LSTORE:
+ expected = BasicValue.LONG_VALUE;
+ break;
+ case DLOAD:
+ case DSTORE:
+ expected = BasicValue.DOUBLE_VALUE;
+ break;
+ case ALOAD:
+ if (!value.isReference()) {
+ throw new AnalyzerException(insn, null, "an object reference",
+ value);
+ }
+ return value;
+ case ASTORE:
+ if (!value.isReference()
+ && !BasicValue.RETURNADDRESS_VALUE.equals(value)) {
+ throw new AnalyzerException(insn, null,
+ "an object reference or a return address", value);
+ }
+ return value;
+ default:
+ return value;
}
if (!expected.equals(value)) {
throw new AnalyzerException(insn, null, expected, value);
@@ -104,91 +98,85 @@ public class BasicVerifier extends BasicInterpreter {
}
@Override
- public BasicValue unaryOperation(final AbstractInsnNode insn, final BasicValue value)
- throws AnalyzerException
- {
+ public BasicValue unaryOperation(final AbstractInsnNode insn,
+ final BasicValue value) throws AnalyzerException {
BasicValue expected;
switch (insn.getOpcode()) {
- case INEG:
- case IINC:
- case I2F:
- case I2L:
- case I2D:
- case I2B:
- case I2C:
- case I2S:
- case IFEQ:
- case IFNE:
- case IFLT:
- case IFGE:
- case IFGT:
- case IFLE:
- case TABLESWITCH:
- case LOOKUPSWITCH:
- case IRETURN:
- case NEWARRAY:
- case ANEWARRAY:
- expected = BasicValue.INT_VALUE;
- break;
- case FNEG:
- case F2I:
- case F2L:
- case F2D:
- case FRETURN:
- expected = BasicValue.FLOAT_VALUE;
- break;
- case LNEG:
- case L2I:
- case L2F:
- case L2D:
- case LRETURN:
- expected = BasicValue.LONG_VALUE;
- break;
- case DNEG:
- case D2I:
- case D2F:
- case D2L:
- case DRETURN:
- expected = BasicValue.DOUBLE_VALUE;
- break;
- case GETFIELD:
- expected = newValue(Type.getObjectType(((FieldInsnNode) insn).owner));
- break;
- case CHECKCAST:
- if (!value.isReference()) {
- throw new AnalyzerException(insn,
- null,
- "an object reference",
- value);
- }
- return super.unaryOperation(insn, value);
- case ARRAYLENGTH:
- if (!isArrayValue(value)) {
- throw new AnalyzerException(insn,
- null,
- "an array reference",
- value);
- }
- return super.unaryOperation(insn, value);
- case ARETURN:
- case ATHROW:
- case INSTANCEOF:
- case MONITORENTER:
- case MONITOREXIT:
- case IFNULL:
- case IFNONNULL:
- if (!value.isReference()) {
- throw new AnalyzerException(insn,
- null,
- "an object reference",
- value);
- }
- return super.unaryOperation(insn, value);
- case PUTSTATIC:
- expected = newValue(Type.getType(((FieldInsnNode) insn).desc));
- break;
- default:
- throw new Error("Internal error.");
+ case INEG:
+ case IINC:
+ case I2F:
+ case I2L:
+ case I2D:
+ case I2B:
+ case I2C:
+ case I2S:
+ case IFEQ:
+ case IFNE:
+ case IFLT:
+ case IFGE:
+ case IFGT:
+ case IFLE:
+ case TABLESWITCH:
+ case LOOKUPSWITCH:
+ case IRETURN:
+ case NEWARRAY:
+ case ANEWARRAY:
+ expected = BasicValue.INT_VALUE;
+ break;
+ case FNEG:
+ case F2I:
+ case F2L:
+ case F2D:
+ case FRETURN:
+ expected = BasicValue.FLOAT_VALUE;
+ break;
+ case LNEG:
+ case L2I:
+ case L2F:
+ case L2D:
+ case LRETURN:
+ expected = BasicValue.LONG_VALUE;
+ break;
+ case DNEG:
+ case D2I:
+ case D2F:
+ case D2L:
+ case DRETURN:
+ expected = BasicValue.DOUBLE_VALUE;
+ break;
+ case GETFIELD:
+ expected = newValue(Type
+ .getObjectType(((FieldInsnNode) insn).owner));
+ break;
+ case CHECKCAST:
+ if (!value.isReference()) {
+ throw new AnalyzerException(insn, null, "an object reference",
+ value);
+ }
+ return super.unaryOperation(insn, value);
+ case ARRAYLENGTH:
+ if (!isArrayValue(value)) {
+ throw new AnalyzerException(insn, null, "an array reference",
+ value);
+ }
+ return super.unaryOperation(insn, value);
+ case ARETURN:
+ case ATHROW:
+ case INSTANCEOF:
+ case MONITORENTER:
+ case MONITOREXIT:
+ case IFNULL:
+ case IFNONNULL:
+ if (!value.isReference()) {
+ throw new AnalyzerException(insn, null, "an object reference",
+ value);
+ }
+ return super.unaryOperation(insn, value);
+ case PUTSTATIC:
+ expected = newValue(Type.getType(((FieldInsnNode) insn).desc));
+ break;
+ default:
+ throw new Error("Internal error.");
}
if (!isSubTypeOf(value, expected)) {
throw new AnalyzerException(insn, null, expected, value);
@@ -197,125 +185,125 @@ public class BasicVerifier extends BasicInterpreter {
}
@Override
- public BasicValue binaryOperation(
- final AbstractInsnNode insn,
- final BasicValue value1,
- final BasicValue value2) throws AnalyzerException
- {
+ public BasicValue binaryOperation(final AbstractInsnNode insn,
+ final BasicValue value1, final BasicValue value2)
+ throws AnalyzerException {
BasicValue expected1;
BasicValue expected2;
switch (insn.getOpcode()) {
- case IALOAD:
- expected1 = newValue(Type.getType("[I"));
- expected2 = BasicValue.INT_VALUE;
- break;
- case BALOAD:
- if (isSubTypeOf(value1, newValue(Type.getType("[Z")))) {
- expected1 = newValue(Type.getType("[Z"));
- } else {
- expected1 = newValue(Type.getType("[B"));
- }
- expected2 = BasicValue.INT_VALUE;
- break;
- case CALOAD:
- expected1 = newValue(Type.getType("[C"));
- expected2 = BasicValue.INT_VALUE;
- break;
- case SALOAD:
- expected1 = newValue(Type.getType("[S"));
- expected2 = BasicValue.INT_VALUE;
- break;
- case LALOAD:
- expected1 = newValue(Type.getType("[J"));
- expected2 = BasicValue.INT_VALUE;
- break;
- case FALOAD:
- expected1 = newValue(Type.getType("[F"));
- expected2 = BasicValue.INT_VALUE;
- break;
- case DALOAD:
- expected1 = newValue(Type.getType("[D"));
- expected2 = BasicValue.INT_VALUE;
- break;
- case AALOAD:
- expected1 = newValue(Type.getType("[Ljava/lang/Object;"));
- expected2 = BasicValue.INT_VALUE;
- break;
- case IADD:
- case ISUB:
- case IMUL:
- case IDIV:
- case IREM:
- case ISHL:
- case ISHR:
- case IUSHR:
- case IAND:
- case IOR:
- case IXOR:
- case IF_ICMPEQ:
- case IF_ICMPNE:
- case IF_ICMPLT:
- case IF_ICMPGE:
- case IF_ICMPGT:
- case IF_ICMPLE:
- expected1 = BasicValue.INT_VALUE;
- expected2 = BasicValue.INT_VALUE;
- break;
- case FADD:
- case FSUB:
- case FMUL:
- case FDIV:
- case FREM:
- case FCMPL:
- case FCMPG:
- expected1 = BasicValue.FLOAT_VALUE;
- expected2 = BasicValue.FLOAT_VALUE;
- break;
- case LADD:
- case LSUB:
- case LMUL:
- case LDIV:
- case LREM:
- case LAND:
- case LOR:
- case LXOR:
- case LCMP:
- expected1 = BasicValue.LONG_VALUE;
- expected2 = BasicValue.LONG_VALUE;
- break;
- case LSHL:
- case LSHR:
- case LUSHR:
- expected1 = BasicValue.LONG_VALUE;
- expected2 = BasicValue.INT_VALUE;
- break;
- case DADD:
- case DSUB:
- case DMUL:
- case DDIV:
- case DREM:
- case DCMPL:
- case DCMPG:
- expected1 = BasicValue.DOUBLE_VALUE;
- expected2 = BasicValue.DOUBLE_VALUE;
- break;
- case IF_ACMPEQ:
- case IF_ACMPNE:
- expected1 = BasicValue.REFERENCE_VALUE;
- expected2 = BasicValue.REFERENCE_VALUE;
- break;
- case PUTFIELD:
- FieldInsnNode fin = (FieldInsnNode) insn;
- expected1 = newValue(Type.getObjectType(fin.owner));
- expected2 = newValue(Type.getType(fin.desc));
- break;
- default:
- throw new Error("Internal error.");
+ case IALOAD:
+ expected1 = newValue(Type.getType("[I"));
+ expected2 = BasicValue.INT_VALUE;
+ break;
+ case BALOAD:
+ if (isSubTypeOf(value1, newValue(Type.getType("[Z")))) {
+ expected1 = newValue(Type.getType("[Z"));
+ } else {
+ expected1 = newValue(Type.getType("[B"));
+ }
+ expected2 = BasicValue.INT_VALUE;
+ break;
+ case CALOAD:
+ expected1 = newValue(Type.getType("[C"));
+ expected2 = BasicValue.INT_VALUE;
+ break;
+ case SALOAD:
+ expected1 = newValue(Type.getType("[S"));
+ expected2 = BasicValue.INT_VALUE;
+ break;
+ case LALOAD:
+ expected1 = newValue(Type.getType("[J"));
+ expected2 = BasicValue.INT_VALUE;
+ break;
+ case FALOAD:
+ expected1 = newValue(Type.getType("[F"));
+ expected2 = BasicValue.INT_VALUE;
+ break;
+ case DALOAD:
+ expected1 = newValue(Type.getType("[D"));
+ expected2 = BasicValue.INT_VALUE;
+ break;
+ case AALOAD:
+ expected1 = newValue(Type.getType("[Ljava/lang/Object;"));
+ expected2 = BasicValue.INT_VALUE;
+ break;
+ case IADD:
+ case ISUB:
+ case IMUL:
+ case IDIV:
+ case IREM:
+ case ISHL:
+ case ISHR:
+ case IUSHR:
+ case IAND:
+ case IOR:
+ case IXOR:
+ case IF_ICMPEQ:
+ case IF_ICMPNE:
+ case IF_ICMPLT:
+ case IF_ICMPGE:
+ case IF_ICMPGT:
+ case IF_ICMPLE:
+ expected1 = BasicValue.INT_VALUE;
+ expected2 = BasicValue.INT_VALUE;
+ break;
+ case FADD:
+ case FSUB:
+ case FMUL:
+ case FDIV:
+ case FREM:
+ case FCMPL:
+ case FCMPG:
+ expected1 = BasicValue.FLOAT_VALUE;
+ expected2 = BasicValue.FLOAT_VALUE;
+ break;
+ case LADD:
+ case LSUB:
+ case LMUL:
+ case LDIV:
+ case LREM:
+ case LAND:
+ case LOR:
+ case LXOR:
+ case LCMP:
+ expected1 = BasicValue.LONG_VALUE;
+ expected2 = BasicValue.LONG_VALUE;
+ break;
+ case LSHL:
+ case LSHR:
+ case LUSHR:
+ expected1 = BasicValue.LONG_VALUE;
+ expected2 = BasicValue.INT_VALUE;
+ break;
+ case DADD:
+ case DSUB:
+ case DMUL:
+ case DDIV:
+ case DREM:
+ case DCMPL:
+ case DCMPG:
+ expected1 = BasicValue.DOUBLE_VALUE;
+ expected2 = BasicValue.DOUBLE_VALUE;
+ break;
+ case IF_ACMPEQ:
+ case IF_ACMPNE:
+ expected1 = BasicValue.REFERENCE_VALUE;
+ expected2 = BasicValue.REFERENCE_VALUE;
+ break;
+ case PUTFIELD:
+ FieldInsnNode fin = (FieldInsnNode) insn;
+ expected1 = newValue(Type.getObjectType(fin.owner));
+ expected2 = newValue(Type.getType(fin.desc));
+ break;
+ default:
+ throw new Error("Internal error.");
}
if (!isSubTypeOf(value1, expected1)) {
- throw new AnalyzerException(insn, "First argument", expected1, value1);
+ throw new AnalyzerException(insn, "First argument", expected1,
+ value1);
} else if (!isSubTypeOf(value2, expected2)) {
- throw new AnalyzerException(insn, "Second argument", expected2, value2);
+ throw new AnalyzerException(insn, "Second argument", expected2,
+ value2);
}
if (insn.getOpcode() == AALOAD) {
return getElementValue(value1);
@@ -325,79 +313,73 @@ public class BasicVerifier extends BasicInterpreter {
}
@Override
- public BasicValue ternaryOperation(
- final AbstractInsnNode insn,
- final BasicValue value1,
- final BasicValue value2,
- final BasicValue value3) throws AnalyzerException
- {
+ public BasicValue ternaryOperation(final AbstractInsnNode insn,
+ final BasicValue value1, final BasicValue value2,
+ final BasicValue value3) throws AnalyzerException {
BasicValue expected1;
BasicValue expected3;
switch (insn.getOpcode()) {
- case IASTORE:
- expected1 = newValue(Type.getType("[I"));
- expected3 = BasicValue.INT_VALUE;
- break;
- case BASTORE:
- if (isSubTypeOf(value1, newValue(Type.getType("[Z")))) {
- expected1 = newValue(Type.getType("[Z"));
- } else {
- expected1 = newValue(Type.getType("[B"));
- }
- expected3 = BasicValue.INT_VALUE;
- break;
- case CASTORE:
- expected1 = newValue(Type.getType("[C"));
- expected3 = BasicValue.INT_VALUE;
- break;
- case SASTORE:
- expected1 = newValue(Type.getType("[S"));
- expected3 = BasicValue.INT_VALUE;
- break;
- case LASTORE:
- expected1 = newValue(Type.getType("[J"));
- expected3 = BasicValue.LONG_VALUE;
- break;
- case FASTORE:
- expected1 = newValue(Type.getType("[F"));
- expected3 = BasicValue.FLOAT_VALUE;
- break;
- case DASTORE:
- expected1 = newValue(Type.getType("[D"));
- expected3 = BasicValue.DOUBLE_VALUE;
- break;
- case AASTORE:
- expected1 = value1;
- expected3 = BasicValue.REFERENCE_VALUE;
- break;
- default:
- throw new Error("Internal error.");
+ case IASTORE:
+ expected1 = newValue(Type.getType("[I"));
+ expected3 = BasicValue.INT_VALUE;
+ break;
+ case BASTORE:
+ if (isSubTypeOf(value1, newValue(Type.getType("[Z")))) {
+ expected1 = newValue(Type.getType("[Z"));
+ } else {
+ expected1 = newValue(Type.getType("[B"));
+ }
+ expected3 = BasicValue.INT_VALUE;
+ break;
+ case CASTORE:
+ expected1 = newValue(Type.getType("[C"));
+ expected3 = BasicValue.INT_VALUE;
+ break;
+ case SASTORE:
+ expected1 = newValue(Type.getType("[S"));
+ expected3 = BasicValue.INT_VALUE;
+ break;
+ case LASTORE:
+ expected1 = newValue(Type.getType("[J"));
+ expected3 = BasicValue.LONG_VALUE;
+ break;
+ case FASTORE:
+ expected1 = newValue(Type.getType("[F"));
+ expected3 = BasicValue.FLOAT_VALUE;
+ break;
+ case DASTORE:
+ expected1 = newValue(Type.getType("[D"));
+ expected3 = BasicValue.DOUBLE_VALUE;
+ break;
+ case AASTORE:
+ expected1 = value1;
+ expected3 = BasicValue.REFERENCE_VALUE;
+ break;
+ default:
+ throw new Error("Internal error.");
}
if (!isSubTypeOf(value1, expected1)) {
- throw new AnalyzerException(insn, "First argument", "a " + expected1
- + " array reference", value1);
+ throw new AnalyzerException(insn, "First argument", "a "
+ + expected1 + " array reference", value1);
} else if (!BasicValue.INT_VALUE.equals(value2)) {
throw new AnalyzerException(insn, "Second argument",
- BasicValue.INT_VALUE,
- value2);
+ BasicValue.INT_VALUE, value2);
} else if (!isSubTypeOf(value3, expected3)) {
- throw new AnalyzerException(insn, "Third argument", expected3, value3);
+ throw new AnalyzerException(insn, "Third argument", expected3,
+ value3);
}
return null;
}
@Override
- public BasicValue naryOperation(final AbstractInsnNode insn, final List<? extends BasicValue> values)
- throws AnalyzerException
- {
+ public BasicValue naryOperation(final AbstractInsnNode insn,
+ final List<? extends BasicValue> values) throws AnalyzerException {
int opcode = insn.getOpcode();
if (opcode == MULTIANEWARRAY) {
for (int i = 0; i < values.size(); ++i) {
if (!BasicValue.INT_VALUE.equals(values.get(i))) {
- throw new AnalyzerException(insn,
- null,
- BasicValue.INT_VALUE,
- values.get(i));
+ throw new AnalyzerException(insn, null,
+ BasicValue.INT_VALUE, values.get(i));
}
}
} else {
@@ -407,22 +389,18 @@ public class BasicVerifier extends BasicInterpreter {
Type owner = Type.getObjectType(((MethodInsnNode) insn).owner);
if (!isSubTypeOf(values.get(i++), newValue(owner))) {
throw new AnalyzerException(insn, "Method owner",
- newValue(owner),
- values.get(0));
+ newValue(owner), values.get(0));
}
}
- String desc = (opcode == INVOKEDYNAMIC)?
- ((InvokeDynamicInsnNode) insn).desc:
- ((MethodInsnNode) insn).desc;
+ String desc = (opcode == INVOKEDYNAMIC) ? ((InvokeDynamicInsnNode) insn).desc
+ : ((MethodInsnNode) insn).desc;
Type[] args = Type.getArgumentTypes(desc);
while (i < values.size()) {
BasicValue expected = newValue(args[j++]);
BasicValue encountered = values.get(i++);
if (!isSubTypeOf(encountered, expected)) {
- throw new AnalyzerException(insn,
- "Argument " + j,
- expected,
- encountered);
+ throw new AnalyzerException(insn, "Argument " + j,
+ expected, encountered);
}
}
}
@@ -430,16 +408,12 @@ public class BasicVerifier extends BasicInterpreter {
}
@Override
- public void returnOperation(
- final AbstractInsnNode insn,
- final BasicValue value,
- final BasicValue expected) throws AnalyzerException
- {
+ public void returnOperation(final AbstractInsnNode insn,
+ final BasicValue value, final BasicValue expected)
+ throws AnalyzerException {
if (!isSubTypeOf(value, expected)) {
- throw new AnalyzerException(insn,
- "Incompatible return type",
- expected,
- value);
+ throw new AnalyzerException(insn, "Incompatible return type",
+ expected, value);
}
}
@@ -448,12 +422,12 @@ public class BasicVerifier extends BasicInterpreter {
}
protected BasicValue getElementValue(final BasicValue objectArrayValue)
- throws AnalyzerException
- {
+ throws AnalyzerException {
return BasicValue.REFERENCE_VALUE;
}
- protected boolean isSubTypeOf(final BasicValue value, final BasicValue expected) {
+ protected boolean isSubTypeOf(final BasicValue value,
+ final BasicValue expected) {
return value.equals(expected);
}
}
diff --git a/src/asm/scala/tools/asm/tree/analysis/Frame.java b/src/asm/scala/tools/asm/tree/analysis/Frame.java
index fe19c2c9ae..0d92edc4d6 100644
--- a/src/asm/scala/tools/asm/tree/analysis/Frame.java
+++ b/src/asm/scala/tools/asm/tree/analysis/Frame.java
@@ -44,10 +44,11 @@ import scala.tools.asm.tree.VarInsnNode;
/**
* A symbolic execution stack frame. A stack frame contains a set of local
* variable slots, and an operand stack. Warning: long and double values are
- * represented by <i>two</i> slots in local variables, and by <i>one</i> slot
- * in the operand stack.
+ * represented by <i>two</i> slots in local variables, and by <i>one</i> slot in
+ * the operand stack.
*
- * @param <V> type of the Value used for the analysis.
+ * @param <V>
+ * type of the Value used for the analysis.
*
* @author Eric Bruneton
*/
@@ -77,8 +78,10 @@ public class Frame<V extends Value> {
/**
* Constructs a new frame with the given size.
*
- * @param nLocals the maximum number of local variables of the frame.
- * @param nStack the maximum stack size of the frame.
+ * @param nLocals
+ * the maximum number of local variables of the frame.
+ * @param nStack
+ * the maximum stack size of the frame.
*/
public Frame(final int nLocals, final int nStack) {
this.values = (V[]) new Value[nLocals + nStack];
@@ -88,7 +91,8 @@ public class Frame<V extends Value> {
/**
* Constructs a new frame that is identical to the given frame.
*
- * @param src a frame.
+ * @param src
+ * a frame.
*/
public Frame(final Frame<? extends V> src) {
this(src.locals, src.values.length - src.locals);
@@ -98,7 +102,8 @@ public class Frame<V extends Value> {
/**
* Copies the state of the given frame into this frame.
*
- * @param src a frame.
+ * @param src
+ * a frame.
* @return this frame.
*/
public Frame<V> init(final Frame<? extends V> src) {
@@ -111,8 +116,9 @@ public class Frame<V extends Value> {
/**
* Sets the expected return type of the analyzed method.
*
- * @param v the expected return type of the analyzed method, or
- * <tt>null</tt> if the method returns void.
+ * @param v
+ * the expected return type of the analyzed method, or
+ * <tt>null</tt> if the method returns void.
*/
public void setReturn(final V v) {
returnValue = v;
@@ -130,13 +136,16 @@ public class Frame<V extends Value> {
/**
* Returns the value of the given local variable.
*
- * @param i a local variable index.
+ * @param i
+ * a local variable index.
* @return the value of the given local variable.
- * @throws IndexOutOfBoundsException if the variable does not exist.
+ * @throws IndexOutOfBoundsException
+ * if the variable does not exist.
*/
public V getLocal(final int i) throws IndexOutOfBoundsException {
if (i >= locals) {
- throw new IndexOutOfBoundsException("Trying to access an inexistant local variable");
+ throw new IndexOutOfBoundsException(
+ "Trying to access an inexistant local variable");
}
return values[i];
}
@@ -144,15 +153,18 @@ public class Frame<V extends Value> {
/**
* Sets the value of the given local variable.
*
- * @param i a local variable index.
- * @param value the new value of this local variable.
- * @throws IndexOutOfBoundsException if the variable does not exist.
+ * @param i
+ * a local variable index.
+ * @param value
+ * the new value of this local variable.
+ * @throws IndexOutOfBoundsException
+ * if the variable does not exist.
*/
public void setLocal(final int i, final V value)
- throws IndexOutOfBoundsException
- {
+ throws IndexOutOfBoundsException {
if (i >= locals) {
- throw new IndexOutOfBoundsException("Trying to access an inexistant local variable "+i);
+ throw new IndexOutOfBoundsException(
+ "Trying to access an inexistant local variable " + i);
}
values[i] = value;
}
@@ -170,10 +182,11 @@ public class Frame<V extends Value> {
/**
* Returns the value of the given operand stack slot.
*
- * @param i the index of an operand stack slot.
+ * @param i
+ * the index of an operand stack slot.
* @return the value of the given operand stack slot.
- * @throws IndexOutOfBoundsException if the operand stack slot does not
- * exist.
+ * @throws IndexOutOfBoundsException
+ * if the operand stack slot does not exist.
*/
public V getStack(final int i) throws IndexOutOfBoundsException {
return values[i + locals];
@@ -190,11 +203,13 @@ public class Frame<V extends Value> {
* Pops a value from the operand stack of this frame.
*
* @return the value that has been popped from the stack.
- * @throws IndexOutOfBoundsException if the operand stack is empty.
+ * @throws IndexOutOfBoundsException
+ * if the operand stack is empty.
*/
public V pop() throws IndexOutOfBoundsException {
if (top == 0) {
- throw new IndexOutOfBoundsException("Cannot pop operand off an empty stack.");
+ throw new IndexOutOfBoundsException(
+ "Cannot pop operand off an empty stack.");
}
return values[--top + locals];
}
@@ -202,466 +217,469 @@ public class Frame<V extends Value> {
/**
* Pushes a value into the operand stack of this frame.
*
- * @param value the value that must be pushed into the stack.
- * @throws IndexOutOfBoundsException if the operand stack is full.
+ * @param value
+ * the value that must be pushed into the stack.
+ * @throws IndexOutOfBoundsException
+ * if the operand stack is full.
*/
public void push(final V value) throws IndexOutOfBoundsException {
if (top + locals >= values.length) {
- throw new IndexOutOfBoundsException("Insufficient maximum stack size.");
+ throw new IndexOutOfBoundsException(
+ "Insufficient maximum stack size.");
}
values[top++ + locals] = value;
}
- public void execute(
- final AbstractInsnNode insn,
- final Interpreter<V> interpreter) throws AnalyzerException
- {
+ public void execute(final AbstractInsnNode insn,
+ final Interpreter<V> interpreter) throws AnalyzerException {
V value1, value2, value3, value4;
List<V> values;
int var;
switch (insn.getOpcode()) {
- case Opcodes.NOP:
- break;
- case Opcodes.ACONST_NULL:
- case Opcodes.ICONST_M1:
- case Opcodes.ICONST_0:
- case Opcodes.ICONST_1:
- case Opcodes.ICONST_2:
- case Opcodes.ICONST_3:
- case Opcodes.ICONST_4:
- case Opcodes.ICONST_5:
- case Opcodes.LCONST_0:
- case Opcodes.LCONST_1:
- case Opcodes.FCONST_0:
- case Opcodes.FCONST_1:
- case Opcodes.FCONST_2:
- case Opcodes.DCONST_0:
- case Opcodes.DCONST_1:
- case Opcodes.BIPUSH:
- case Opcodes.SIPUSH:
- case Opcodes.LDC:
- push(interpreter.newOperation(insn));
- break;
- case Opcodes.ILOAD:
- case Opcodes.LLOAD:
- case Opcodes.FLOAD:
- case Opcodes.DLOAD:
- case Opcodes.ALOAD:
- push(interpreter.copyOperation(insn,
- getLocal(((VarInsnNode) insn).var)));
- break;
- case Opcodes.IALOAD:
- case Opcodes.LALOAD:
- case Opcodes.FALOAD:
- case Opcodes.DALOAD:
- case Opcodes.AALOAD:
- case Opcodes.BALOAD:
- case Opcodes.CALOAD:
- case Opcodes.SALOAD:
- value2 = pop();
- value1 = pop();
- push(interpreter.binaryOperation(insn, value1, value2));
- break;
- case Opcodes.ISTORE:
- case Opcodes.LSTORE:
- case Opcodes.FSTORE:
- case Opcodes.DSTORE:
- case Opcodes.ASTORE:
- value1 = interpreter.copyOperation(insn, pop());
- var = ((VarInsnNode) insn).var;
- setLocal(var, value1);
- if (value1.getSize() == 2) {
- setLocal(var + 1, interpreter.newValue(null));
+ case Opcodes.NOP:
+ break;
+ case Opcodes.ACONST_NULL:
+ case Opcodes.ICONST_M1:
+ case Opcodes.ICONST_0:
+ case Opcodes.ICONST_1:
+ case Opcodes.ICONST_2:
+ case Opcodes.ICONST_3:
+ case Opcodes.ICONST_4:
+ case Opcodes.ICONST_5:
+ case Opcodes.LCONST_0:
+ case Opcodes.LCONST_1:
+ case Opcodes.FCONST_0:
+ case Opcodes.FCONST_1:
+ case Opcodes.FCONST_2:
+ case Opcodes.DCONST_0:
+ case Opcodes.DCONST_1:
+ case Opcodes.BIPUSH:
+ case Opcodes.SIPUSH:
+ case Opcodes.LDC:
+ push(interpreter.newOperation(insn));
+ break;
+ case Opcodes.ILOAD:
+ case Opcodes.LLOAD:
+ case Opcodes.FLOAD:
+ case Opcodes.DLOAD:
+ case Opcodes.ALOAD:
+ push(interpreter.copyOperation(insn,
+ getLocal(((VarInsnNode) insn).var)));
+ break;
+ case Opcodes.IALOAD:
+ case Opcodes.LALOAD:
+ case Opcodes.FALOAD:
+ case Opcodes.DALOAD:
+ case Opcodes.AALOAD:
+ case Opcodes.BALOAD:
+ case Opcodes.CALOAD:
+ case Opcodes.SALOAD:
+ value2 = pop();
+ value1 = pop();
+ push(interpreter.binaryOperation(insn, value1, value2));
+ break;
+ case Opcodes.ISTORE:
+ case Opcodes.LSTORE:
+ case Opcodes.FSTORE:
+ case Opcodes.DSTORE:
+ case Opcodes.ASTORE:
+ value1 = interpreter.copyOperation(insn, pop());
+ var = ((VarInsnNode) insn).var;
+ setLocal(var, value1);
+ if (value1.getSize() == 2) {
+ setLocal(var + 1, interpreter.newValue(null));
+ }
+ if (var > 0) {
+ Value local = getLocal(var - 1);
+ if (local != null && local.getSize() == 2) {
+ setLocal(var - 1, interpreter.newValue(null));
}
- if (var > 0) {
- Value local = getLocal(var - 1);
- if (local != null && local.getSize() == 2) {
- setLocal(var - 1, interpreter.newValue(null));
- }
+ }
+ break;
+ case Opcodes.IASTORE:
+ case Opcodes.LASTORE:
+ case Opcodes.FASTORE:
+ case Opcodes.DASTORE:
+ case Opcodes.AASTORE:
+ case Opcodes.BASTORE:
+ case Opcodes.CASTORE:
+ case Opcodes.SASTORE:
+ value3 = pop();
+ value2 = pop();
+ value1 = pop();
+ interpreter.ternaryOperation(insn, value1, value2, value3);
+ break;
+ case Opcodes.POP:
+ if (pop().getSize() == 2) {
+ throw new AnalyzerException(insn, "Illegal use of POP");
+ }
+ break;
+ case Opcodes.POP2:
+ if (pop().getSize() == 1) {
+ if (pop().getSize() != 1) {
+ throw new AnalyzerException(insn, "Illegal use of POP2");
}
- break;
- case Opcodes.IASTORE:
- case Opcodes.LASTORE:
- case Opcodes.FASTORE:
- case Opcodes.DASTORE:
- case Opcodes.AASTORE:
- case Opcodes.BASTORE:
- case Opcodes.CASTORE:
- case Opcodes.SASTORE:
- value3 = pop();
+ }
+ break;
+ case Opcodes.DUP:
+ value1 = pop();
+ if (value1.getSize() != 1) {
+ throw new AnalyzerException(insn, "Illegal use of DUP");
+ }
+ push(value1);
+ push(interpreter.copyOperation(insn, value1));
+ break;
+ case Opcodes.DUP_X1:
+ value1 = pop();
+ value2 = pop();
+ if (value1.getSize() != 1 || value2.getSize() != 1) {
+ throw new AnalyzerException(insn, "Illegal use of DUP_X1");
+ }
+ push(interpreter.copyOperation(insn, value1));
+ push(value2);
+ push(value1);
+ break;
+ case Opcodes.DUP_X2:
+ value1 = pop();
+ if (value1.getSize() == 1) {
value2 = pop();
- value1 = pop();
- interpreter.ternaryOperation(insn, value1, value2, value3);
- break;
- case Opcodes.POP:
- if (pop().getSize() == 2) {
- throw new AnalyzerException(insn, "Illegal use of POP");
- }
- break;
- case Opcodes.POP2:
- if (pop().getSize() == 1) {
- if (pop().getSize() != 1) {
- throw new AnalyzerException(insn, "Illegal use of POP2");
+ if (value2.getSize() == 1) {
+ value3 = pop();
+ if (value3.getSize() == 1) {
+ push(interpreter.copyOperation(insn, value1));
+ push(value3);
+ push(value2);
+ push(value1);
+ break;
}
+ } else {
+ push(interpreter.copyOperation(insn, value1));
+ push(value2);
+ push(value1);
+ break;
}
- break;
- case Opcodes.DUP:
- value1 = pop();
- if (value1.getSize() != 1) {
- throw new AnalyzerException(insn, "Illegal use of DUP");
+ }
+ throw new AnalyzerException(insn, "Illegal use of DUP_X2");
+ case Opcodes.DUP2:
+ value1 = pop();
+ if (value1.getSize() == 1) {
+ value2 = pop();
+ if (value2.getSize() == 1) {
+ push(value2);
+ push(value1);
+ push(interpreter.copyOperation(insn, value2));
+ push(interpreter.copyOperation(insn, value1));
+ break;
}
+ } else {
push(value1);
push(interpreter.copyOperation(insn, value1));
break;
- case Opcodes.DUP_X1:
- value1 = pop();
+ }
+ throw new AnalyzerException(insn, "Illegal use of DUP2");
+ case Opcodes.DUP2_X1:
+ value1 = pop();
+ if (value1.getSize() == 1) {
value2 = pop();
- if (value1.getSize() != 1 || value2.getSize() != 1) {
- throw new AnalyzerException(insn, "Illegal use of DUP_X1");
- }
- push(interpreter.copyOperation(insn, value1));
- push(value2);
- push(value1);
- break;
- case Opcodes.DUP_X2:
- value1 = pop();
- if (value1.getSize() == 1) {
- value2 = pop();
- if (value2.getSize() == 1) {
- value3 = pop();
- if (value3.getSize() == 1) {
- push(interpreter.copyOperation(insn, value1));
- push(value3);
- push(value2);
- push(value1);
- break;
- }
- } else {
+ if (value2.getSize() == 1) {
+ value3 = pop();
+ if (value3.getSize() == 1) {
+ push(interpreter.copyOperation(insn, value2));
push(interpreter.copyOperation(insn, value1));
+ push(value3);
push(value2);
push(value1);
break;
}
}
- throw new AnalyzerException(insn, "Illegal use of DUP_X2");
- case Opcodes.DUP2:
- value1 = pop();
- if (value1.getSize() == 1) {
- value2 = pop();
- if (value2.getSize() == 1) {
- push(value2);
- push(value1);
- push(interpreter.copyOperation(insn, value2));
- push(interpreter.copyOperation(insn, value1));
- break;
- }
- } else {
- push(value1);
+ } else {
+ value2 = pop();
+ if (value2.getSize() == 1) {
push(interpreter.copyOperation(insn, value1));
+ push(value2);
+ push(value1);
break;
}
- throw new AnalyzerException(insn, "Illegal use of DUP2");
- case Opcodes.DUP2_X1:
- value1 = pop();
- if (value1.getSize() == 1) {
- value2 = pop();
- if (value2.getSize() == 1) {
- value3 = pop();
- if (value3.getSize() == 1) {
+ }
+ throw new AnalyzerException(insn, "Illegal use of DUP2_X1");
+ case Opcodes.DUP2_X2:
+ value1 = pop();
+ if (value1.getSize() == 1) {
+ value2 = pop();
+ if (value2.getSize() == 1) {
+ value3 = pop();
+ if (value3.getSize() == 1) {
+ value4 = pop();
+ if (value4.getSize() == 1) {
push(interpreter.copyOperation(insn, value2));
push(interpreter.copyOperation(insn, value1));
+ push(value4);
push(value3);
push(value2);
push(value1);
break;
}
- }
- } else {
- value2 = pop();
- if (value2.getSize() == 1) {
+ } else {
+ push(interpreter.copyOperation(insn, value2));
push(interpreter.copyOperation(insn, value1));
+ push(value3);
push(value2);
push(value1);
break;
}
}
- throw new AnalyzerException(insn, "Illegal use of DUP2_X1");
- case Opcodes.DUP2_X2:
- value1 = pop();
- if (value1.getSize() == 1) {
- value2 = pop();
- if (value2.getSize() == 1) {
- value3 = pop();
- if (value3.getSize() == 1) {
- value4 = pop();
- if (value4.getSize() == 1) {
- push(interpreter.copyOperation(insn, value2));
- push(interpreter.copyOperation(insn, value1));
- push(value4);
- push(value3);
- push(value2);
- push(value1);
- break;
- }
- } else {
- push(interpreter.copyOperation(insn, value2));
- push(interpreter.copyOperation(insn, value1));
- push(value3);
- push(value2);
- push(value1);
- break;
- }
- }
- } else {
- value2 = pop();
- if (value2.getSize() == 1) {
- value3 = pop();
- if (value3.getSize() == 1) {
- push(interpreter.copyOperation(insn, value1));
- push(value3);
- push(value2);
- push(value1);
- break;
- }
- } else {
+ } else {
+ value2 = pop();
+ if (value2.getSize() == 1) {
+ value3 = pop();
+ if (value3.getSize() == 1) {
push(interpreter.copyOperation(insn, value1));
+ push(value3);
push(value2);
push(value1);
break;
}
- }
- throw new AnalyzerException(insn, "Illegal use of DUP2_X2");
- case Opcodes.SWAP:
- value2 = pop();
- value1 = pop();
- if (value1.getSize() != 1 || value2.getSize() != 1) {
- throw new AnalyzerException(insn, "Illegal use of SWAP");
- }
- push(interpreter.copyOperation(insn, value2));
- push(interpreter.copyOperation(insn, value1));
- break;
- case Opcodes.IADD:
- case Opcodes.LADD:
- case Opcodes.FADD:
- case Opcodes.DADD:
- case Opcodes.ISUB:
- case Opcodes.LSUB:
- case Opcodes.FSUB:
- case Opcodes.DSUB:
- case Opcodes.IMUL:
- case Opcodes.LMUL:
- case Opcodes.FMUL:
- case Opcodes.DMUL:
- case Opcodes.IDIV:
- case Opcodes.LDIV:
- case Opcodes.FDIV:
- case Opcodes.DDIV:
- case Opcodes.IREM:
- case Opcodes.LREM:
- case Opcodes.FREM:
- case Opcodes.DREM:
- value2 = pop();
- value1 = pop();
- push(interpreter.binaryOperation(insn, value1, value2));
- break;
- case Opcodes.INEG:
- case Opcodes.LNEG:
- case Opcodes.FNEG:
- case Opcodes.DNEG:
- push(interpreter.unaryOperation(insn, pop()));
- break;
- case Opcodes.ISHL:
- case Opcodes.LSHL:
- case Opcodes.ISHR:
- case Opcodes.LSHR:
- case Opcodes.IUSHR:
- case Opcodes.LUSHR:
- case Opcodes.IAND:
- case Opcodes.LAND:
- case Opcodes.IOR:
- case Opcodes.LOR:
- case Opcodes.IXOR:
- case Opcodes.LXOR:
- value2 = pop();
- value1 = pop();
- push(interpreter.binaryOperation(insn, value1, value2));
- break;
- case Opcodes.IINC:
- var = ((IincInsnNode) insn).var;
- setLocal(var, interpreter.unaryOperation(insn, getLocal(var)));
- break;
- case Opcodes.I2L:
- case Opcodes.I2F:
- case Opcodes.I2D:
- case Opcodes.L2I:
- case Opcodes.L2F:
- case Opcodes.L2D:
- case Opcodes.F2I:
- case Opcodes.F2L:
- case Opcodes.F2D:
- case Opcodes.D2I:
- case Opcodes.D2L:
- case Opcodes.D2F:
- case Opcodes.I2B:
- case Opcodes.I2C:
- case Opcodes.I2S:
- push(interpreter.unaryOperation(insn, pop()));
- break;
- case Opcodes.LCMP:
- case Opcodes.FCMPL:
- case Opcodes.FCMPG:
- case Opcodes.DCMPL:
- case Opcodes.DCMPG:
- value2 = pop();
- value1 = pop();
- push(interpreter.binaryOperation(insn, value1, value2));
- break;
- case Opcodes.IFEQ:
- case Opcodes.IFNE:
- case Opcodes.IFLT:
- case Opcodes.IFGE:
- case Opcodes.IFGT:
- case Opcodes.IFLE:
- interpreter.unaryOperation(insn, pop());
- break;
- case Opcodes.IF_ICMPEQ:
- case Opcodes.IF_ICMPNE:
- case Opcodes.IF_ICMPLT:
- case Opcodes.IF_ICMPGE:
- case Opcodes.IF_ICMPGT:
- case Opcodes.IF_ICMPLE:
- case Opcodes.IF_ACMPEQ:
- case Opcodes.IF_ACMPNE:
- value2 = pop();
- value1 = pop();
- interpreter.binaryOperation(insn, value1, value2);
- break;
- case Opcodes.GOTO:
- break;
- case Opcodes.JSR:
- push(interpreter.newOperation(insn));
- break;
- case Opcodes.RET:
- break;
- case Opcodes.TABLESWITCH:
- case Opcodes.LOOKUPSWITCH:
- interpreter.unaryOperation(insn, pop());
- break;
- case Opcodes.IRETURN:
- case Opcodes.LRETURN:
- case Opcodes.FRETURN:
- case Opcodes.DRETURN:
- case Opcodes.ARETURN:
- value1 = pop();
- interpreter.unaryOperation(insn, value1);
- interpreter.returnOperation(insn, value1, returnValue);
- break;
- case Opcodes.RETURN:
- if (returnValue != null) {
- throw new AnalyzerException(insn, "Incompatible return type");
- }
- break;
- case Opcodes.GETSTATIC:
- push(interpreter.newOperation(insn));
- break;
- case Opcodes.PUTSTATIC:
- interpreter.unaryOperation(insn, pop());
- break;
- case Opcodes.GETFIELD:
- push(interpreter.unaryOperation(insn, pop()));
- break;
- case Opcodes.PUTFIELD:
- value2 = pop();
- value1 = pop();
- interpreter.binaryOperation(insn, value1, value2);
- break;
- case Opcodes.INVOKEVIRTUAL:
- case Opcodes.INVOKESPECIAL:
- case Opcodes.INVOKESTATIC:
- case Opcodes.INVOKEINTERFACE: {
- values = new ArrayList<V>();
- String desc = ((MethodInsnNode) insn).desc;
- for (int i = Type.getArgumentTypes(desc).length; i > 0; --i) {
- values.add(0, pop());
- }
- if (insn.getOpcode() != Opcodes.INVOKESTATIC) {
- values.add(0, pop());
- }
- if (Type.getReturnType(desc) == Type.VOID_TYPE) {
- interpreter.naryOperation(insn, values);
} else {
- push(interpreter.naryOperation(insn, values));
+ push(interpreter.copyOperation(insn, value1));
+ push(value2);
+ push(value1);
+ break;
}
- break;
}
- case Opcodes.INVOKEDYNAMIC: {
- values = new ArrayList<V>();
- String desc = ((InvokeDynamicInsnNode) insn).desc;
- for (int i = Type.getArgumentTypes(desc).length; i > 0; --i) {
- values.add(0, pop());
- }
- if (Type.getReturnType(desc) == Type.VOID_TYPE) {
- interpreter.naryOperation(insn, values);
- } else {
- push(interpreter.naryOperation(insn, values));
- }
- break;
+ throw new AnalyzerException(insn, "Illegal use of DUP2_X2");
+ case Opcodes.SWAP:
+ value2 = pop();
+ value1 = pop();
+ if (value1.getSize() != 1 || value2.getSize() != 1) {
+ throw new AnalyzerException(insn, "Illegal use of SWAP");
}
- case Opcodes.NEW:
- push(interpreter.newOperation(insn));
- break;
- case Opcodes.NEWARRAY:
- case Opcodes.ANEWARRAY:
- case Opcodes.ARRAYLENGTH:
- push(interpreter.unaryOperation(insn, pop()));
- break;
- case Opcodes.ATHROW:
- interpreter.unaryOperation(insn, pop());
- break;
- case Opcodes.CHECKCAST:
- case Opcodes.INSTANCEOF:
- push(interpreter.unaryOperation(insn, pop()));
- break;
- case Opcodes.MONITORENTER:
- case Opcodes.MONITOREXIT:
- interpreter.unaryOperation(insn, pop());
- break;
- case Opcodes.MULTIANEWARRAY:
- values = new ArrayList<V>();
- for (int i = ((MultiANewArrayInsnNode) insn).dims; i > 0; --i) {
- values.add(0, pop());
- }
+ push(interpreter.copyOperation(insn, value2));
+ push(interpreter.copyOperation(insn, value1));
+ break;
+ case Opcodes.IADD:
+ case Opcodes.LADD:
+ case Opcodes.FADD:
+ case Opcodes.DADD:
+ case Opcodes.ISUB:
+ case Opcodes.LSUB:
+ case Opcodes.FSUB:
+ case Opcodes.DSUB:
+ case Opcodes.IMUL:
+ case Opcodes.LMUL:
+ case Opcodes.FMUL:
+ case Opcodes.DMUL:
+ case Opcodes.IDIV:
+ case Opcodes.LDIV:
+ case Opcodes.FDIV:
+ case Opcodes.DDIV:
+ case Opcodes.IREM:
+ case Opcodes.LREM:
+ case Opcodes.FREM:
+ case Opcodes.DREM:
+ value2 = pop();
+ value1 = pop();
+ push(interpreter.binaryOperation(insn, value1, value2));
+ break;
+ case Opcodes.INEG:
+ case Opcodes.LNEG:
+ case Opcodes.FNEG:
+ case Opcodes.DNEG:
+ push(interpreter.unaryOperation(insn, pop()));
+ break;
+ case Opcodes.ISHL:
+ case Opcodes.LSHL:
+ case Opcodes.ISHR:
+ case Opcodes.LSHR:
+ case Opcodes.IUSHR:
+ case Opcodes.LUSHR:
+ case Opcodes.IAND:
+ case Opcodes.LAND:
+ case Opcodes.IOR:
+ case Opcodes.LOR:
+ case Opcodes.IXOR:
+ case Opcodes.LXOR:
+ value2 = pop();
+ value1 = pop();
+ push(interpreter.binaryOperation(insn, value1, value2));
+ break;
+ case Opcodes.IINC:
+ var = ((IincInsnNode) insn).var;
+ setLocal(var, interpreter.unaryOperation(insn, getLocal(var)));
+ break;
+ case Opcodes.I2L:
+ case Opcodes.I2F:
+ case Opcodes.I2D:
+ case Opcodes.L2I:
+ case Opcodes.L2F:
+ case Opcodes.L2D:
+ case Opcodes.F2I:
+ case Opcodes.F2L:
+ case Opcodes.F2D:
+ case Opcodes.D2I:
+ case Opcodes.D2L:
+ case Opcodes.D2F:
+ case Opcodes.I2B:
+ case Opcodes.I2C:
+ case Opcodes.I2S:
+ push(interpreter.unaryOperation(insn, pop()));
+ break;
+ case Opcodes.LCMP:
+ case Opcodes.FCMPL:
+ case Opcodes.FCMPG:
+ case Opcodes.DCMPL:
+ case Opcodes.DCMPG:
+ value2 = pop();
+ value1 = pop();
+ push(interpreter.binaryOperation(insn, value1, value2));
+ break;
+ case Opcodes.IFEQ:
+ case Opcodes.IFNE:
+ case Opcodes.IFLT:
+ case Opcodes.IFGE:
+ case Opcodes.IFGT:
+ case Opcodes.IFLE:
+ interpreter.unaryOperation(insn, pop());
+ break;
+ case Opcodes.IF_ICMPEQ:
+ case Opcodes.IF_ICMPNE:
+ case Opcodes.IF_ICMPLT:
+ case Opcodes.IF_ICMPGE:
+ case Opcodes.IF_ICMPGT:
+ case Opcodes.IF_ICMPLE:
+ case Opcodes.IF_ACMPEQ:
+ case Opcodes.IF_ACMPNE:
+ value2 = pop();
+ value1 = pop();
+ interpreter.binaryOperation(insn, value1, value2);
+ break;
+ case Opcodes.GOTO:
+ break;
+ case Opcodes.JSR:
+ push(interpreter.newOperation(insn));
+ break;
+ case Opcodes.RET:
+ break;
+ case Opcodes.TABLESWITCH:
+ case Opcodes.LOOKUPSWITCH:
+ interpreter.unaryOperation(insn, pop());
+ break;
+ case Opcodes.IRETURN:
+ case Opcodes.LRETURN:
+ case Opcodes.FRETURN:
+ case Opcodes.DRETURN:
+ case Opcodes.ARETURN:
+ value1 = pop();
+ interpreter.unaryOperation(insn, value1);
+ interpreter.returnOperation(insn, value1, returnValue);
+ break;
+ case Opcodes.RETURN:
+ if (returnValue != null) {
+ throw new AnalyzerException(insn, "Incompatible return type");
+ }
+ break;
+ case Opcodes.GETSTATIC:
+ push(interpreter.newOperation(insn));
+ break;
+ case Opcodes.PUTSTATIC:
+ interpreter.unaryOperation(insn, pop());
+ break;
+ case Opcodes.GETFIELD:
+ push(interpreter.unaryOperation(insn, pop()));
+ break;
+ case Opcodes.PUTFIELD:
+ value2 = pop();
+ value1 = pop();
+ interpreter.binaryOperation(insn, value1, value2);
+ break;
+ case Opcodes.INVOKEVIRTUAL:
+ case Opcodes.INVOKESPECIAL:
+ case Opcodes.INVOKESTATIC:
+ case Opcodes.INVOKEINTERFACE: {
+ values = new ArrayList<V>();
+ String desc = ((MethodInsnNode) insn).desc;
+ for (int i = Type.getArgumentTypes(desc).length; i > 0; --i) {
+ values.add(0, pop());
+ }
+ if (insn.getOpcode() != Opcodes.INVOKESTATIC) {
+ values.add(0, pop());
+ }
+ if (Type.getReturnType(desc) == Type.VOID_TYPE) {
+ interpreter.naryOperation(insn, values);
+ } else {
push(interpreter.naryOperation(insn, values));
- break;
- case Opcodes.IFNULL:
- case Opcodes.IFNONNULL:
- interpreter.unaryOperation(insn, pop());
- break;
- default:
- throw new RuntimeException("Illegal opcode "+insn.getOpcode());
+ }
+ break;
+ }
+ case Opcodes.INVOKEDYNAMIC: {
+ values = new ArrayList<V>();
+ String desc = ((InvokeDynamicInsnNode) insn).desc;
+ for (int i = Type.getArgumentTypes(desc).length; i > 0; --i) {
+ values.add(0, pop());
+ }
+ if (Type.getReturnType(desc) == Type.VOID_TYPE) {
+ interpreter.naryOperation(insn, values);
+ } else {
+ push(interpreter.naryOperation(insn, values));
+ }
+ break;
+ }
+ case Opcodes.NEW:
+ push(interpreter.newOperation(insn));
+ break;
+ case Opcodes.NEWARRAY:
+ case Opcodes.ANEWARRAY:
+ case Opcodes.ARRAYLENGTH:
+ push(interpreter.unaryOperation(insn, pop()));
+ break;
+ case Opcodes.ATHROW:
+ interpreter.unaryOperation(insn, pop());
+ break;
+ case Opcodes.CHECKCAST:
+ case Opcodes.INSTANCEOF:
+ push(interpreter.unaryOperation(insn, pop()));
+ break;
+ case Opcodes.MONITORENTER:
+ case Opcodes.MONITOREXIT:
+ interpreter.unaryOperation(insn, pop());
+ break;
+ case Opcodes.MULTIANEWARRAY:
+ values = new ArrayList<V>();
+ for (int i = ((MultiANewArrayInsnNode) insn).dims; i > 0; --i) {
+ values.add(0, pop());
+ }
+ push(interpreter.naryOperation(insn, values));
+ break;
+ case Opcodes.IFNULL:
+ case Opcodes.IFNONNULL:
+ interpreter.unaryOperation(insn, pop());
+ break;
+ default:
+ throw new RuntimeException("Illegal opcode " + insn.getOpcode());
}
}
/**
* Merges this frame with the given frame.
*
- * @param frame a frame.
- * @param interpreter the interpreter used to merge values.
+ * @param frame
+ * a frame.
+ * @param interpreter
+ * the interpreter used to merge values.
* @return <tt>true</tt> if this frame has been changed as a result of the
* merge operation, or <tt>false</tt> otherwise.
- * @throws AnalyzerException if the frames have incompatible sizes.
+ * @throws AnalyzerException
+ * if the frames have incompatible sizes.
*/
- public boolean merge(final Frame<? extends V> frame, final Interpreter<V> interpreter)
- throws AnalyzerException
- {
+ public boolean merge(final Frame<? extends V> frame,
+ final Interpreter<V> interpreter) throws AnalyzerException {
if (top != frame.top) {
throw new AnalyzerException(null, "Incompatible stack heights");
}
boolean changes = false;
for (int i = 0; i < locals + top; ++i) {
V v = interpreter.merge(values[i], frame.values[i]);
- if (v != values[i]) {
+ if (!v.equals(values[i])) {
values[i] = v;
changes = true;
}
@@ -672,9 +690,11 @@ public class Frame<V extends Value> {
/**
* Merges this frame with the given frame (case of a RET instruction).
*
- * @param frame a frame
- * @param access the local variables that have been accessed by the
- * subroutine to which the RET instruction corresponds.
+ * @param frame
+ * a frame
+ * @param access
+ * the local variables that have been accessed by the subroutine
+ * to which the RET instruction corresponds.
* @return <tt>true</tt> if this frame has been changed as a result of the
* merge operation, or <tt>false</tt> otherwise.
*/
diff --git a/src/asm/scala/tools/asm/tree/analysis/Interpreter.java b/src/asm/scala/tools/asm/tree/analysis/Interpreter.java
index 930c8f4af8..56f4bedc00 100644
--- a/src/asm/scala/tools/asm/tree/analysis/Interpreter.java
+++ b/src/asm/scala/tools/asm/tree/analysis/Interpreter.java
@@ -42,7 +42,8 @@ import scala.tools.asm.tree.AbstractInsnNode;
* various semantic interpreters, without needing to duplicate the code to
* simulate the transfer of values.
*
- * @param <V> type of the Value used for the analysis.
+ * @param <V>
+ * type of the Value used for the analysis.
*
* @author Eric Bruneton
*/
@@ -57,12 +58,13 @@ public abstract class Interpreter<V extends Value> {
/**
* Creates a new value that represents the given type.
*
- * Called for method parameters (including <code>this</code>),
- * exception handler variable and with <code>null</code> type
- * for variables reserved by long and double types.
+ * Called for method parameters (including <code>this</code>), exception
+ * handler variable and with <code>null</code> type for variables reserved
+ * by long and double types.
*
- * @param type a primitive or reference type, or <tt>null</tt> to
- * represent an uninitialized value.
+ * @param type
+ * a primitive or reference type, or <tt>null</tt> to represent
+ * an uninitialized value.
* @return a value that represents the given type. The size of the returned
* value must be equal to the size of the given type.
*/
@@ -76,9 +78,11 @@ public abstract class Interpreter<V extends Value> {
* ICONST_5, LCONST_0, LCONST_1, FCONST_0, FCONST_1, FCONST_2, DCONST_0,
* DCONST_1, BIPUSH, SIPUSH, LDC, JSR, GETSTATIC, NEW
*
- * @param insn the bytecode instruction to be interpreted.
+ * @param insn
+ * the bytecode instruction to be interpreted.
* @return the result of the interpretation of the given instruction.
- * @throws AnalyzerException if an error occured during the interpretation.
+ * @throws AnalyzerException
+ * if an error occured during the interpretation.
*/
public abstract V newOperation(AbstractInsnNode insn)
throws AnalyzerException;
@@ -90,11 +94,14 @@ public abstract class Interpreter<V extends Value> {
* ILOAD, LLOAD, FLOAD, DLOAD, ALOAD, ISTORE, LSTORE, FSTORE, DSTORE,
* ASTORE, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, SWAP
*
- * @param insn the bytecode instruction to be interpreted.
- * @param value the value that must be moved by the instruction.
+ * @param insn
+ * the bytecode instruction to be interpreted.
+ * @param value
+ * the value that must be moved by the instruction.
* @return the result of the interpretation of the given instruction. The
* returned value must be <tt>equal</tt> to the given value.
- * @throws AnalyzerException if an error occured during the interpretation.
+ * @throws AnalyzerException
+ * if an error occured during the interpretation.
*/
public abstract V copyOperation(AbstractInsnNode insn, V value)
throws AnalyzerException;
@@ -109,10 +116,13 @@ public abstract class Interpreter<V extends Value> {
* PUTSTATIC, GETFIELD, NEWARRAY, ANEWARRAY, ARRAYLENGTH, ATHROW, CHECKCAST,
* INSTANCEOF, MONITORENTER, MONITOREXIT, IFNULL, IFNONNULL
*
- * @param insn the bytecode instruction to be interpreted.
- * @param value the argument of the instruction to be interpreted.
+ * @param insn
+ * the bytecode instruction to be interpreted.
+ * @param value
+ * the argument of the instruction to be interpreted.
* @return the result of the interpretation of the given instruction.
- * @throws AnalyzerException if an error occured during the interpretation.
+ * @throws AnalyzerException
+ * if an error occured during the interpretation.
*/
public abstract V unaryOperation(AbstractInsnNode insn, V value)
throws AnalyzerException;
@@ -128,11 +138,15 @@ public abstract class Interpreter<V extends Value> {
* DCMPG, IF_ICMPEQ, IF_ICMPNE, IF_ICMPLT, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE,
* IF_ACMPEQ, IF_ACMPNE, PUTFIELD
*
- * @param insn the bytecode instruction to be interpreted.
- * @param value1 the first argument of the instruction to be interpreted.
- * @param value2 the second argument of the instruction to be interpreted.
+ * @param insn
+ * the bytecode instruction to be interpreted.
+ * @param value1
+ * the first argument of the instruction to be interpreted.
+ * @param value2
+ * the second argument of the instruction to be interpreted.
* @return the result of the interpretation of the given instruction.
- * @throws AnalyzerException if an error occured during the interpretation.
+ * @throws AnalyzerException
+ * if an error occured during the interpretation.
*/
public abstract V binaryOperation(AbstractInsnNode insn, V value1, V value2)
throws AnalyzerException;
@@ -143,18 +157,20 @@ public abstract class Interpreter<V extends Value> {
*
* IASTORE, LASTORE, FASTORE, DASTORE, AASTORE, BASTORE, CASTORE, SASTORE
*
- * @param insn the bytecode instruction to be interpreted.
- * @param value1 the first argument of the instruction to be interpreted.
- * @param value2 the second argument of the instruction to be interpreted.
- * @param value3 the third argument of the instruction to be interpreted.
+ * @param insn
+ * the bytecode instruction to be interpreted.
+ * @param value1
+ * the first argument of the instruction to be interpreted.
+ * @param value2
+ * the second argument of the instruction to be interpreted.
+ * @param value3
+ * the third argument of the instruction to be interpreted.
* @return the result of the interpretation of the given instruction.
- * @throws AnalyzerException if an error occured during the interpretation.
+ * @throws AnalyzerException
+ * if an error occured during the interpretation.
*/
- public abstract V ternaryOperation(
- AbstractInsnNode insn,
- V value1,
- V value2,
- V value3) throws AnalyzerException;
+ public abstract V ternaryOperation(AbstractInsnNode insn, V value1,
+ V value2, V value3) throws AnalyzerException;
/**
* Interprets a bytecode instruction with a variable number of arguments.
@@ -163,14 +179,16 @@ public abstract class Interpreter<V extends Value> {
* INVOKEVIRTUAL, INVOKESPECIAL, INVOKESTATIC, INVOKEINTERFACE,
* MULTIANEWARRAY and INVOKEDYNAMIC
*
- * @param insn the bytecode instruction to be interpreted.
- * @param values the arguments of the instruction to be interpreted.
+ * @param insn
+ * the bytecode instruction to be interpreted.
+ * @param values
+ * the arguments of the instruction to be interpreted.
* @return the result of the interpretation of the given instruction.
- * @throws AnalyzerException if an error occured during the interpretation.
+ * @throws AnalyzerException
+ * if an error occured during the interpretation.
*/
- public abstract V naryOperation(
- AbstractInsnNode insn,
- List< ? extends V> values) throws AnalyzerException;
+ public abstract V naryOperation(AbstractInsnNode insn,
+ List<? extends V> values) throws AnalyzerException;
/**
* Interprets a bytecode return instruction. This method is called for the
@@ -178,15 +196,17 @@ public abstract class Interpreter<V extends Value> {
*
* IRETURN, LRETURN, FRETURN, DRETURN, ARETURN
*
- * @param insn the bytecode instruction to be interpreted.
- * @param value the argument of the instruction to be interpreted.
- * @param expected the expected return type of the analyzed method.
- * @throws AnalyzerException if an error occured during the interpretation.
+ * @param insn
+ * the bytecode instruction to be interpreted.
+ * @param value
+ * the argument of the instruction to be interpreted.
+ * @param expected
+ * the expected return type of the analyzed method.
+ * @throws AnalyzerException
+ * if an error occured during the interpretation.
*/
- public abstract void returnOperation(
- AbstractInsnNode insn,
- V value,
- V expected) throws AnalyzerException;
+ public abstract void returnOperation(AbstractInsnNode insn, V value,
+ V expected) throws AnalyzerException;
/**
* Merges two values. The merge operation must return a value that
@@ -195,8 +215,10 @@ public abstract class Interpreter<V extends Value> {
* values are integer intervals, the merged value must be an interval that
* contains the previous ones. Likewise for other types of values).
*
- * @param v a value.
- * @param w another value.
+ * @param v
+ * a value.
+ * @param w
+ * another value.
* @return the merged value. If the merged value is equal to <tt>v</tt>,
* this method <i>must</i> return <tt>v</tt>.
*/
diff --git a/src/asm/scala/tools/asm/tree/analysis/SimpleVerifier.java b/src/asm/scala/tools/asm/tree/analysis/SimpleVerifier.java
index c4f515d328..eaecd057ea 100644
--- a/src/asm/scala/tools/asm/tree/analysis/SimpleVerifier.java
+++ b/src/asm/scala/tools/asm/tree/analysis/SimpleVerifier.java
@@ -79,15 +79,15 @@ public class SimpleVerifier extends BasicVerifier {
* Constructs a new {@link SimpleVerifier} to verify a specific class. This
* class will not be loaded into the JVM since it may be incorrect.
*
- * @param currentClass the class that is verified.
- * @param currentSuperClass the super class of the class that is verified.
- * @param isInterface if the class that is verified is an interface.
+ * @param currentClass
+ * the class that is verified.
+ * @param currentSuperClass
+ * the super class of the class that is verified.
+ * @param isInterface
+ * if the class that is verified is an interface.
*/
- public SimpleVerifier(
- final Type currentClass,
- final Type currentSuperClass,
- final boolean isInterface)
- {
+ public SimpleVerifier(final Type currentClass,
+ final Type currentSuperClass, final boolean isInterface) {
this(currentClass, currentSuperClass, null, isInterface);
}
@@ -95,32 +95,25 @@ public class SimpleVerifier extends BasicVerifier {
* Constructs a new {@link SimpleVerifier} to verify a specific class. This
* class will not be loaded into the JVM since it may be incorrect.
*
- * @param currentClass the class that is verified.
- * @param currentSuperClass the super class of the class that is verified.
- * @param currentClassInterfaces the interfaces implemented by the class
- * that is verified.
- * @param isInterface if the class that is verified is an interface.
+ * @param currentClass
+ * the class that is verified.
+ * @param currentSuperClass
+ * the super class of the class that is verified.
+ * @param currentClassInterfaces
+ * the interfaces implemented by the class that is verified.
+ * @param isInterface
+ * if the class that is verified is an interface.
*/
- public SimpleVerifier(
- final Type currentClass,
- final Type currentSuperClass,
- final List<Type> currentClassInterfaces,
- final boolean isInterface)
- {
- this(ASM4,
- currentClass,
- currentSuperClass,
- currentClassInterfaces,
+ public SimpleVerifier(final Type currentClass,
+ final Type currentSuperClass,
+ final List<Type> currentClassInterfaces, final boolean isInterface) {
+ this(ASM4, currentClass, currentSuperClass, currentClassInterfaces,
isInterface);
}
- protected SimpleVerifier(
- final int api,
- final Type currentClass,
- final Type currentSuperClass,
- final List<Type> currentClassInterfaces,
- final boolean isInterface)
- {
+ protected SimpleVerifier(final int api, final Type currentClass,
+ final Type currentSuperClass,
+ final List<Type> currentClassInterfaces, final boolean isInterface) {
super(api);
this.currentClass = currentClass;
this.currentSuperClass = currentSuperClass;
@@ -133,7 +126,8 @@ public class SimpleVerifier extends BasicVerifier {
* classes. This is useful if you are verifying multiple interdependent
* classes.
*
- * @param loader a <code>ClassLoader</code> to use
+ * @param loader
+ * a <code>ClassLoader</code> to use
*/
public void setClassLoader(final ClassLoader loader) {
this.loader = loader;
@@ -148,11 +142,11 @@ public class SimpleVerifier extends BasicVerifier {
boolean isArray = type.getSort() == Type.ARRAY;
if (isArray) {
switch (type.getElementType().getSort()) {
- case Type.BOOLEAN:
- case Type.CHAR:
- case Type.BYTE:
- case Type.SHORT:
- return new BasicValue(type);
+ case Type.BOOLEAN:
+ case Type.CHAR:
+ case Type.BYTE:
+ case Type.SHORT:
+ return new BasicValue(type);
}
}
@@ -181,8 +175,7 @@ public class SimpleVerifier extends BasicVerifier {
@Override
protected BasicValue getElementValue(final BasicValue objectArrayValue)
- throws AnalyzerException
- {
+ throws AnalyzerException {
Type arrayType = objectArrayValue.getType();
if (arrayType != null) {
if (arrayType.getSort() == Type.ARRAY) {
@@ -196,28 +189,28 @@ public class SimpleVerifier extends BasicVerifier {
}
@Override
- protected boolean isSubTypeOf(final BasicValue value, final BasicValue expected) {
+ protected boolean isSubTypeOf(final BasicValue value,
+ final BasicValue expected) {
Type expectedType = expected.getType();
Type type = value.getType();
switch (expectedType.getSort()) {
- case Type.INT:
- case Type.FLOAT:
- case Type.LONG:
- case Type.DOUBLE:
- return type.equals(expectedType);
- case Type.ARRAY:
- case Type.OBJECT:
- if ("Lnull;".equals(type.getDescriptor())) {
- return true;
- } else if (type.getSort() == Type.OBJECT
- || type.getSort() == Type.ARRAY)
- {
- return isAssignableFrom(expectedType, type);
- } else {
- return false;
- }
- default:
- throw new Error("Internal error");
+ case Type.INT:
+ case Type.FLOAT:
+ case Type.LONG:
+ case Type.DOUBLE:
+ return type.equals(expectedType);
+ case Type.ARRAY:
+ case Type.OBJECT:
+ if ("Lnull;".equals(type.getDescriptor())) {
+ return true;
+ } else if (type.getSort() == Type.OBJECT
+ || type.getSort() == Type.ARRAY) {
+ return isAssignableFrom(expectedType, type);
+ } else {
+ return false;
+ }
+ default:
+ throw new Error("Internal error");
}
}
@@ -227,11 +220,9 @@ public class SimpleVerifier extends BasicVerifier {
Type t = v.getType();
Type u = w.getType();
if (t != null
- && (t.getSort() == Type.OBJECT || t.getSort() == Type.ARRAY))
- {
+ && (t.getSort() == Type.OBJECT || t.getSort() == Type.ARRAY)) {
if (u != null
- && (u.getSort() == Type.OBJECT || u.getSort() == Type.ARRAY))
- {
+ && (u.getSort() == Type.OBJECT || u.getSort() == Type.ARRAY)) {
if ("Lnull;".equals(t.getDescriptor())) {
return w;
}
@@ -288,7 +279,8 @@ public class SimpleVerifier extends BasicVerifier {
return false;
} else {
if (isInterface) {
- return u.getSort() == Type.OBJECT || u.getSort() == Type.ARRAY;
+ return u.getSort() == Type.OBJECT
+ || u.getSort() == Type.ARRAY;
}
return isAssignableFrom(t, getSuperClass(u));
}
@@ -318,8 +310,7 @@ public class SimpleVerifier extends BasicVerifier {
try {
if (t.getSort() == Type.ARRAY) {
return Class.forName(t.getDescriptor().replace('/', '.'),
- false,
- loader);
+ false, loader);
}
return Class.forName(t.getClassName(), false, loader);
} catch (ClassNotFoundException e) {
diff --git a/src/asm/scala/tools/asm/tree/analysis/SourceInterpreter.java b/src/asm/scala/tools/asm/tree/analysis/SourceInterpreter.java
index 067200b51e..a68086c073 100644
--- a/src/asm/scala/tools/asm/tree/analysis/SourceInterpreter.java
+++ b/src/asm/scala/tools/asm/tree/analysis/SourceInterpreter.java
@@ -47,8 +47,7 @@ import scala.tools.asm.tree.MethodInsnNode;
* @author Eric Bruneton
*/
public class SourceInterpreter extends Interpreter<SourceValue> implements
- Opcodes
-{
+ Opcodes {
public SourceInterpreter() {
super(ASM4);
@@ -70,125 +69,118 @@ public class SourceInterpreter extends Interpreter<SourceValue> implements
public SourceValue newOperation(final AbstractInsnNode insn) {
int size;
switch (insn.getOpcode()) {
- case LCONST_0:
- case LCONST_1:
- case DCONST_0:
- case DCONST_1:
- size = 2;
- break;
- case LDC:
- Object cst = ((LdcInsnNode) insn).cst;
- size = cst instanceof Long || cst instanceof Double ? 2 : 1;
- break;
- case GETSTATIC:
- size = Type.getType(((FieldInsnNode) insn).desc).getSize();
- break;
- default:
- size = 1;
+ case LCONST_0:
+ case LCONST_1:
+ case DCONST_0:
+ case DCONST_1:
+ size = 2;
+ break;
+ case LDC:
+ Object cst = ((LdcInsnNode) insn).cst;
+ size = cst instanceof Long || cst instanceof Double ? 2 : 1;
+ break;
+ case GETSTATIC:
+ size = Type.getType(((FieldInsnNode) insn).desc).getSize();
+ break;
+ default:
+ size = 1;
}
return new SourceValue(size, insn);
}
@Override
- public SourceValue copyOperation(final AbstractInsnNode insn, final SourceValue value) {
+ public SourceValue copyOperation(final AbstractInsnNode insn,
+ final SourceValue value) {
return new SourceValue(value.getSize(), insn);
}
@Override
- public SourceValue unaryOperation(final AbstractInsnNode insn, final SourceValue value)
- {
+ public SourceValue unaryOperation(final AbstractInsnNode insn,
+ final SourceValue value) {
int size;
switch (insn.getOpcode()) {
- case LNEG:
- case DNEG:
- case I2L:
- case I2D:
- case L2D:
- case F2L:
- case F2D:
- case D2L:
- size = 2;
- break;
- case GETFIELD:
- size = Type.getType(((FieldInsnNode) insn).desc).getSize();
- break;
- default:
- size = 1;
+ case LNEG:
+ case DNEG:
+ case I2L:
+ case I2D:
+ case L2D:
+ case F2L:
+ case F2D:
+ case D2L:
+ size = 2;
+ break;
+ case GETFIELD:
+ size = Type.getType(((FieldInsnNode) insn).desc).getSize();
+ break;
+ default:
+ size = 1;
}
return new SourceValue(size, insn);
}
@Override
- public SourceValue binaryOperation(
- final AbstractInsnNode insn,
- final SourceValue value1,
- final SourceValue value2)
- {
+ public SourceValue binaryOperation(final AbstractInsnNode insn,
+ final SourceValue value1, final SourceValue value2) {
int size;
switch (insn.getOpcode()) {
- case LALOAD:
- case DALOAD:
- case LADD:
- case DADD:
- case LSUB:
- case DSUB:
- case LMUL:
- case DMUL:
- case LDIV:
- case DDIV:
- case LREM:
- case DREM:
- case LSHL:
- case LSHR:
- case LUSHR:
- case LAND:
- case LOR:
- case LXOR:
- size = 2;
- break;
- default:
- size = 1;
+ case LALOAD:
+ case DALOAD:
+ case LADD:
+ case DADD:
+ case LSUB:
+ case DSUB:
+ case LMUL:
+ case DMUL:
+ case LDIV:
+ case DDIV:
+ case LREM:
+ case DREM:
+ case LSHL:
+ case LSHR:
+ case LUSHR:
+ case LAND:
+ case LOR:
+ case LXOR:
+ size = 2;
+ break;
+ default:
+ size = 1;
}
return new SourceValue(size, insn);
}
@Override
- public SourceValue ternaryOperation(
- final AbstractInsnNode insn,
- final SourceValue value1,
- final SourceValue value2,
- final SourceValue value3)
- {
+ public SourceValue ternaryOperation(final AbstractInsnNode insn,
+ final SourceValue value1, final SourceValue value2,
+ final SourceValue value3) {
return new SourceValue(1, insn);
}
@Override
- public SourceValue naryOperation(final AbstractInsnNode insn, final List<? extends SourceValue> values) {
+ public SourceValue naryOperation(final AbstractInsnNode insn,
+ final List<? extends SourceValue> values) {
int size;
int opcode = insn.getOpcode();
if (opcode == MULTIANEWARRAY) {
size = 1;
} else {
- String desc = (opcode == INVOKEDYNAMIC)?
- ((InvokeDynamicInsnNode) insn).desc:
- ((MethodInsnNode) insn).desc;
+ String desc = (opcode == INVOKEDYNAMIC) ? ((InvokeDynamicInsnNode) insn).desc
+ : ((MethodInsnNode) insn).desc;
size = Type.getReturnType(desc).getSize();
}
return new SourceValue(size, insn);
}
@Override
- public void returnOperation(
- final AbstractInsnNode insn,
- final SourceValue value,
- final SourceValue expected)
- {
+ public void returnOperation(final AbstractInsnNode insn,
+ final SourceValue value, final SourceValue expected) {
}
@Override
public SourceValue merge(final SourceValue d, final SourceValue w) {
if (d.insns instanceof SmallSet && w.insns instanceof SmallSet) {
- Set<AbstractInsnNode> s = ((SmallSet<AbstractInsnNode>) d.insns).union((SmallSet<AbstractInsnNode>) w.insns);
+ Set<AbstractInsnNode> s = ((SmallSet<AbstractInsnNode>) d.insns)
+ .union((SmallSet<AbstractInsnNode>) w.insns);
if (s == d.insns && d.size == w.size) {
return d;
} else {
diff --git a/src/asm/scala/tools/asm/tree/analysis/SourceValue.java b/src/asm/scala/tools/asm/tree/analysis/SourceValue.java
index 57ff212fb2..40d6b68180 100644
--- a/src/asm/scala/tools/asm/tree/analysis/SourceValue.java
+++ b/src/asm/scala/tools/asm/tree/analysis/SourceValue.java
@@ -48,8 +48,8 @@ public class SourceValue implements Value {
/**
* The instructions that can produce this value. For example, for the Java
- * code below, the instructions that can produce the value of <tt>i</tt>
- * at line 5 are the txo ISTORE instructions at line 1 and 3:
+ * code below, the instructions that can produce the value of <tt>i</tt> at
+ * line 5 are the txo ISTORE instructions at line 1 and 3:
*
* <pre>
* 1: i = 0;
@@ -64,7 +64,7 @@ public class SourceValue implements Value {
public final Set<AbstractInsnNode> insns;
public SourceValue(final int size) {
- this(size, SmallSet.<AbstractInsnNode>emptySet());
+ this(size, SmallSet.<AbstractInsnNode> emptySet());
}
public SourceValue(final int size, final AbstractInsnNode insn) {
@@ -84,7 +84,7 @@ public class SourceValue implements Value {
@Override
public boolean equals(final Object value) {
if (!(value instanceof SourceValue)) {
- return false;
+ return false;
}
SourceValue v = (SourceValue) value;
return size == v.size && insns.equals(v.insns);
diff --git a/src/asm/scala/tools/asm/tree/analysis/Subroutine.java b/src/asm/scala/tools/asm/tree/analysis/Subroutine.java
index 038880ddcd..d734bbd499 100644
--- a/src/asm/scala/tools/asm/tree/analysis/Subroutine.java
+++ b/src/asm/scala/tools/asm/tree/analysis/Subroutine.java
@@ -51,11 +51,8 @@ class Subroutine {
private Subroutine() {
}
- Subroutine(
- final LabelNode start,
- final int maxLocals,
- final JumpInsnNode caller)
- {
+ Subroutine(final LabelNode start, final int maxLocals,
+ final JumpInsnNode caller) {
this.start = start;
this.access = new boolean[maxLocals];
this.callers = new ArrayList<JumpInsnNode>();
@@ -90,4 +87,4 @@ class Subroutine {
}
return changes;
}
-} \ No newline at end of file
+}
diff --git a/src/asm/scala/tools/asm/util/ASMifiable.java b/src/asm/scala/tools/asm/util/ASMifiable.java
index 6a31dd508f..95cc6e3a74 100644
--- a/src/asm/scala/tools/asm/util/ASMifiable.java
+++ b/src/asm/scala/tools/asm/util/ASMifiable.java
@@ -34,7 +34,7 @@ import java.util.Map;
import scala.tools.asm.Label;
/**
- * An {@link org.objectweb.asm.Attribute Attribute} that can print the ASM code
+ * An {@link scala.tools.asm.Attribute Attribute} that can print the ASM code
* to create an equivalent attribute.
*
* @author Eugene Kuleshov
@@ -44,10 +44,13 @@ public interface ASMifiable {
/**
* Prints the ASM code to create an attribute equal to this attribute.
*
- * @param buf a buffer used for printing Java code.
- * @param varName name of the variable in a printed code used to store
- * attribute instance.
- * @param labelNames map of label instances to their names.
+ * @param buf
+ * a buffer used for printing Java code.
+ * @param varName
+ * name of the variable in a printed code used to store attribute
+ * instance.
+ * @param labelNames
+ * map of label instances to their names.
*/
void asmify(StringBuffer buf, String varName, Map<Label, String> labelNames);
}
diff --git a/src/asm/scala/tools/asm/util/ASMifier.java b/src/asm/scala/tools/asm/util/ASMifier.java
index 5967c877d1..7e6b223853 100644
--- a/src/asm/scala/tools/asm/util/ASMifier.java
+++ b/src/asm/scala/tools/asm/util/ASMifier.java
@@ -91,11 +91,14 @@ public class ASMifier extends Printer {
/**
* Constructs a new {@link ASMifier}.
*
- * @param api the ASM API version implemented by this class. Must be one of
- * {@link Opcodes#ASM4}.
- * @param name the name of the visitor variable in the produced code.
- * @param id identifier of the annotation visitor variable in the produced
- * code.
+ * @param api
+ * the ASM API version implemented by this class. Must be one of
+ * {@link Opcodes#ASM4}.
+ * @param name
+ * the name of the visitor variable in the produced code.
+ * @param id
+ * identifier of the annotation visitor variable in the produced
+ * code.
*/
protected ASMifier(final int api, final String name, final int id) {
super(api);
@@ -105,13 +108,15 @@ public class ASMifier extends Printer {
/**
* Prints the ASM source code to generate the given class to the standard
- * output. <p> Usage: ASMifier [-debug] &lt;binary
- * class name or class file name&gt;
+ * output.
+ * <p>
+ * Usage: ASMifier [-debug] &lt;binary class name or class file name&gt;
*
- * @param args the command line arguments.
+ * @param args
+ * the command line arguments.
*
- * @throws Exception if the class cannot be found, or if an IO exception
- * occurs.
+ * @throws Exception
+ * if the class cannot be found, or if an IO exception occurs.
*/
public static void main(final String[] args) throws Exception {
int i = 0;
@@ -129,22 +134,21 @@ public class ASMifier extends Printer {
}
}
if (!ok) {
- System.err.println("Prints the ASM code to generate the given class.");
+ System.err
+ .println("Prints the ASM code to generate the given class.");
System.err.println("Usage: ASMifier [-debug] "
+ "<fully qualified class name or class file name>");
return;
}
ClassReader cr;
if (args[i].endsWith(".class") || args[i].indexOf('\\') > -1
- || args[i].indexOf('/') > -1)
- {
+ || args[i].indexOf('/') > -1) {
cr = new ClassReader(new FileInputStream(args[i]));
} else {
cr = new ClassReader(args[i]);
}
- cr.accept(new TraceClassVisitor(null,
- new ASMifier(),
- new PrintWriter(System.out)), flags);
+ cr.accept(new TraceClassVisitor(null, new ASMifier(), new PrintWriter(
+ System.out)), flags);
}
// ------------------------------------------------------------------------
@@ -152,14 +156,9 @@ public class ASMifier extends Printer {
// ------------------------------------------------------------------------
@Override
- public void visit(
- final int version,
- final int access,
- final String name,
- final String signature,
- final String superName,
- final String[] interfaces)
- {
+ public void visit(final int version, final int access, final String name,
+ final String signature, final String superName,
+ final String[] interfaces) {
String simpleName;
int n = name.lastIndexOf('/');
if (n == -1) {
@@ -170,8 +169,8 @@ public class ASMifier extends Printer {
simpleName = name.substring(n + 1);
}
text.add("import java.util.*;\n");
- text.add("import org.objectweb.asm.*;\n");
- text.add("import org.objectweb.asm.attrs.*;\n");
+ text.add("import scala.tools.asm.*;\n");
+ text.add("import scala.tools.asm.attrs.*;\n");
text.add("public class " + simpleName + "Dump implements Opcodes {\n\n");
text.add("public static byte[] dump () throws Exception {\n\n");
text.add("ClassWriter cw = new ClassWriter(0);\n");
@@ -182,30 +181,30 @@ public class ASMifier extends Printer {
buf.setLength(0);
buf.append("cw.visit(");
switch (version) {
- case Opcodes.V1_1:
- buf.append("V1_1");
- break;
- case Opcodes.V1_2:
- buf.append("V1_2");
- break;
- case Opcodes.V1_3:
- buf.append("V1_3");
- break;
- case Opcodes.V1_4:
- buf.append("V1_4");
- break;
- case Opcodes.V1_5:
- buf.append("V1_5");
- break;
- case Opcodes.V1_6:
- buf.append("V1_6");
- break;
- case Opcodes.V1_7:
- buf.append("V1_7");
- break;
- default:
- buf.append(version);
- break;
+ case Opcodes.V1_1:
+ buf.append("V1_1");
+ break;
+ case Opcodes.V1_2:
+ buf.append("V1_2");
+ break;
+ case Opcodes.V1_3:
+ buf.append("V1_3");
+ break;
+ case Opcodes.V1_4:
+ buf.append("V1_4");
+ break;
+ case Opcodes.V1_5:
+ buf.append("V1_5");
+ break;
+ case Opcodes.V1_6:
+ buf.append("V1_6");
+ break;
+ case Opcodes.V1_7:
+ buf.append("V1_7");
+ break;
+ default:
+ buf.append(version);
+ break;
}
buf.append(", ");
appendAccess(access | ACCESS_CLASS);
@@ -242,11 +241,8 @@ public class ASMifier extends Printer {
}
@Override
- public void visitOuterClass(
- final String owner,
- final String name,
- final String desc)
- {
+ public void visitOuterClass(final String owner, final String name,
+ final String desc) {
buf.setLength(0);
buf.append("cw.visitOuterClass(");
appendConstant(owner);
@@ -259,10 +255,8 @@ public class ASMifier extends Printer {
}
@Override
- public ASMifier visitClassAnnotation(
- final String desc,
- final boolean visible)
- {
+ public ASMifier visitClassAnnotation(final String desc,
+ final boolean visible) {
return visitAnnotation(desc, visible);
}
@@ -272,12 +266,8 @@ public class ASMifier extends Printer {
}
@Override
- public void visitInnerClass(
- final String name,
- final String outerName,
- final String innerName,
- final int access)
- {
+ public void visitInnerClass(final String name, final String outerName,
+ final String innerName, final int access) {
buf.setLength(0);
buf.append("cw.visitInnerClass(");
appendConstant(name);
@@ -292,13 +282,8 @@ public class ASMifier extends Printer {
}
@Override
- public ASMifier visitField(
- final int access,
- final String name,
- final String desc,
- final String signature,
- final Object value)
- {
+ public ASMifier visitField(final int access, final String name,
+ final String desc, final String signature, final Object value) {
buf.setLength(0);
buf.append("{\n");
buf.append("fv = cw.visitField(");
@@ -320,13 +305,8 @@ public class ASMifier extends Printer {
}
@Override
- public ASMifier visitMethod(
- final int access,
- final String name,
- final String desc,
- final String signature,
- final String[] exceptions)
- {
+ public ASMifier visitMethod(final int access, final String name,
+ final String desc, final String signature, final String[] exceptions) {
buf.setLength(0);
buf.append("{\n");
buf.append("mv = cw.visitMethod(");
@@ -380,11 +360,8 @@ public class ASMifier extends Printer {
}
@Override
- public void visitEnum(
- final String name,
- final String desc,
- final String value)
- {
+ public void visitEnum(final String name, final String desc,
+ final String value) {
buf.setLength(0);
buf.append("av").append(id).append(".visitEnum(");
appendConstant(buf, name);
@@ -397,10 +374,7 @@ public class ASMifier extends Printer {
}
@Override
- public ASMifier visitAnnotation(
- final String name,
- final String desc)
- {
+ public ASMifier visitAnnotation(final String name, final String desc) {
buf.setLength(0);
buf.append("{\n");
buf.append("AnnotationVisitor av").append(id + 1).append(" = av");
@@ -443,10 +417,8 @@ public class ASMifier extends Printer {
// ------------------------------------------------------------------------
@Override
- public ASMifier visitFieldAnnotation(
- final String desc,
- final boolean visible)
- {
+ public ASMifier visitFieldAnnotation(final String desc,
+ final boolean visible) {
return visitAnnotation(desc, visible);
}
@@ -469,9 +441,7 @@ public class ASMifier extends Printer {
@Override
public ASMifier visitAnnotationDefault() {
buf.setLength(0);
- buf.append("{\n")
- .append("av0 = ")
- .append(name)
+ buf.append("{\n").append("av0 = ").append(name)
.append(".visitAnnotationDefault();\n");
text.add(buf.toString());
ASMifier a = createASMifier("av", 0);
@@ -481,23 +451,17 @@ public class ASMifier extends Printer {
}
@Override
- public ASMifier visitMethodAnnotation(
- final String desc,
- final boolean visible)
- {
+ public ASMifier visitMethodAnnotation(final String desc,
+ final boolean visible) {
return visitAnnotation(desc, visible);
}
@Override
- public ASMifier visitParameterAnnotation(
- final int parameter,
- final String desc,
- final boolean visible)
- {
+ public ASMifier visitParameterAnnotation(final int parameter,
+ final String desc, final boolean visible) {
buf.setLength(0);
- buf.append("{\n")
- .append("av0 = ").append(name).append(".visitParameterAnnotation(")
- .append(parameter)
+ buf.append("{\n").append("av0 = ").append(name)
+ .append(".visitParameterAnnotation(").append(parameter)
.append(", ");
appendConstant(desc);
buf.append(", ").append(visible).append(");\n");
@@ -519,52 +483,47 @@ public class ASMifier extends Printer {
}
@Override
- public void visitFrame(
- final int type,
- final int nLocal,
- final Object[] local,
- final int nStack,
- final Object[] stack)
- {
+ public void visitFrame(final int type, final int nLocal,
+ final Object[] local, final int nStack, final Object[] stack) {
buf.setLength(0);
switch (type) {
- case Opcodes.F_NEW:
- case Opcodes.F_FULL:
- declareFrameTypes(nLocal, local);
- declareFrameTypes(nStack, stack);
- if (type == Opcodes.F_NEW) {
- buf.append(name).append(".visitFrame(Opcodes.F_NEW, ");
- } else {
- buf.append(name).append(".visitFrame(Opcodes.F_FULL, ");
- }
- buf.append(nLocal).append(", new Object[] {");
- appendFrameTypes(nLocal, local);
- buf.append("}, ").append(nStack).append(", new Object[] {");
- appendFrameTypes(nStack, stack);
- buf.append('}');
- break;
- case Opcodes.F_APPEND:
- declareFrameTypes(nLocal, local);
- buf.append(name).append(".visitFrame(Opcodes.F_APPEND,")
- .append(nLocal)
- .append(", new Object[] {");
- appendFrameTypes(nLocal, local);
- buf.append("}, 0, null");
- break;
- case Opcodes.F_CHOP:
- buf.append(name).append(".visitFrame(Opcodes.F_CHOP,")
- .append(nLocal)
- .append(", null, 0, null");
- break;
- case Opcodes.F_SAME:
- buf.append(name).append(".visitFrame(Opcodes.F_SAME, 0, null, 0, null");
- break;
- case Opcodes.F_SAME1:
- declareFrameTypes(1, stack);
- buf.append(name).append(".visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] {");
- appendFrameTypes(1, stack);
- buf.append('}');
- break;
+ case Opcodes.F_NEW:
+ case Opcodes.F_FULL:
+ declareFrameTypes(nLocal, local);
+ declareFrameTypes(nStack, stack);
+ if (type == Opcodes.F_NEW) {
+ buf.append(name).append(".visitFrame(Opcodes.F_NEW, ");
+ } else {
+ buf.append(name).append(".visitFrame(Opcodes.F_FULL, ");
+ }
+ buf.append(nLocal).append(", new Object[] {");
+ appendFrameTypes(nLocal, local);
+ buf.append("}, ").append(nStack).append(", new Object[] {");
+ appendFrameTypes(nStack, stack);
+ buf.append('}');
+ break;
+ case Opcodes.F_APPEND:
+ declareFrameTypes(nLocal, local);
+ buf.append(name).append(".visitFrame(Opcodes.F_APPEND,")
+ .append(nLocal).append(", new Object[] {");
+ appendFrameTypes(nLocal, local);
+ buf.append("}, 0, null");
+ break;
+ case Opcodes.F_CHOP:
+ buf.append(name).append(".visitFrame(Opcodes.F_CHOP,")
+ .append(nLocal).append(", null, 0, null");
+ break;
+ case Opcodes.F_SAME:
+ buf.append(name).append(
+ ".visitFrame(Opcodes.F_SAME, 0, null, 0, null");
+ break;
+ case Opcodes.F_SAME1:
+ declareFrameTypes(1, stack);
+ buf.append(name).append(
+ ".visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] {");
+ appendFrameTypes(1, stack);
+ buf.append('}');
+ break;
}
buf.append(");\n");
text.add(buf.toString());
@@ -573,7 +532,8 @@ public class ASMifier extends Printer {
@Override
public void visitInsn(final int opcode) {
buf.setLength(0);
- buf.append(name).append(".visitInsn(").append(OPCODES[opcode]).append(");\n");
+ buf.append(name).append(".visitInsn(").append(OPCODES[opcode])
+ .append(");\n");
text.add(buf.toString());
}
@@ -584,43 +544,35 @@ public class ASMifier extends Printer {
.append(".visitIntInsn(")
.append(OPCODES[opcode])
.append(", ")
- .append(opcode == Opcodes.NEWARRAY
- ? TYPES[operand]
- : Integer.toString(operand))
- .append(");\n");
+ .append(opcode == Opcodes.NEWARRAY ? TYPES[operand] : Integer
+ .toString(operand)).append(");\n");
text.add(buf.toString());
}
@Override
public void visitVarInsn(final int opcode, final int var) {
buf.setLength(0);
- buf.append(name)
- .append(".visitVarInsn(")
- .append(OPCODES[opcode])
- .append(", ")
- .append(var)
- .append(");\n");
+ buf.append(name).append(".visitVarInsn(").append(OPCODES[opcode])
+ .append(", ").append(var).append(");\n");
text.add(buf.toString());
}
@Override
public void visitTypeInsn(final int opcode, final String type) {
buf.setLength(0);
- buf.append(name).append(".visitTypeInsn(").append(OPCODES[opcode]).append(", ");
+ buf.append(name).append(".visitTypeInsn(").append(OPCODES[opcode])
+ .append(", ");
appendConstant(type);
buf.append(");\n");
text.add(buf.toString());
}
@Override
- public void visitFieldInsn(
- final int opcode,
- final String owner,
- final String name,
- final String desc)
- {
+ public void visitFieldInsn(final int opcode, final String owner,
+ final String name, final String desc) {
buf.setLength(0);
- buf.append(this.name).append(".visitFieldInsn(").append(OPCODES[opcode]).append(", ");
+ buf.append(this.name).append(".visitFieldInsn(")
+ .append(OPCODES[opcode]).append(", ");
appendConstant(owner);
buf.append(", ");
appendConstant(name);
@@ -631,14 +583,11 @@ public class ASMifier extends Printer {
}
@Override
- public void visitMethodInsn(
- final int opcode,
- final String owner,
- final String name,
- final String desc)
- {
+ public void visitMethodInsn(final int opcode, final String owner,
+ final String name, final String desc) {
buf.setLength(0);
- buf.append(this.name).append(".visitMethodInsn(").append(OPCODES[opcode]).append(", ");
+ buf.append(this.name).append(".visitMethodInsn(")
+ .append(OPCODES[opcode]).append(", ");
appendConstant(owner);
buf.append(", ");
appendConstant(name);
@@ -649,12 +598,8 @@ public class ASMifier extends Printer {
}
@Override
- public void visitInvokeDynamicInsn(
- String name,
- String desc,
- Handle bsm,
- Object... bsmArgs)
- {
+ public void visitInvokeDynamicInsn(String name, String desc, Handle bsm,
+ Object... bsmArgs) {
buf.setLength(0);
buf.append(this.name).append(".visitInvokeDynamicInsn(");
appendConstant(name);
@@ -677,7 +622,8 @@ public class ASMifier extends Printer {
public void visitJumpInsn(final int opcode, final Label label) {
buf.setLength(0);
declareLabel(label);
- buf.append(name).append(".visitJumpInsn(").append(OPCODES[opcode]).append(", ");
+ buf.append(name).append(".visitJumpInsn(").append(OPCODES[opcode])
+ .append(", ");
appendLabel(label);
buf.append(");\n");
text.add(buf.toString());
@@ -705,34 +651,22 @@ public class ASMifier extends Printer {
@Override
public void visitIincInsn(final int var, final int increment) {
buf.setLength(0);
- buf.append(name)
- .append(".visitIincInsn(")
- .append(var)
- .append(", ")
- .append(increment)
- .append(");\n");
+ buf.append(name).append(".visitIincInsn(").append(var).append(", ")
+ .append(increment).append(");\n");
text.add(buf.toString());
}
@Override
- public void visitTableSwitchInsn(
- final int min,
- final int max,
- final Label dflt,
- final Label... labels)
- {
+ public void visitTableSwitchInsn(final int min, final int max,
+ final Label dflt, final Label... labels) {
buf.setLength(0);
for (int i = 0; i < labels.length; ++i) {
declareLabel(labels[i]);
}
declareLabel(dflt);
- buf.append(name)
- .append(".visitTableSwitchInsn(")
- .append(min)
- .append(", ")
- .append(max)
- .append(", ");
+ buf.append(name).append(".visitTableSwitchInsn(").append(min)
+ .append(", ").append(max).append(", ");
appendLabel(dflt);
buf.append(", new Label[] {");
for (int i = 0; i < labels.length; ++i) {
@@ -744,11 +678,8 @@ public class ASMifier extends Printer {
}
@Override
- public void visitLookupSwitchInsn(
- final Label dflt,
- final int[] keys,
- final Label[] labels)
- {
+ public void visitLookupSwitchInsn(final Label dflt, final int[] keys,
+ final Label[] labels) {
buf.setLength(0);
for (int i = 0; i < labels.length; ++i) {
declareLabel(labels[i]);
@@ -780,12 +711,8 @@ public class ASMifier extends Printer {
}
@Override
- public void visitTryCatchBlock(
- final Label start,
- final Label end,
- final Label handler,
- final String type)
- {
+ public void visitTryCatchBlock(final Label start, final Label end,
+ final Label handler, final String type) {
buf.setLength(0);
declareLabel(start);
declareLabel(end);
@@ -803,14 +730,9 @@ public class ASMifier extends Printer {
}
@Override
- public void visitLocalVariable(
- final String name,
- final String desc,
- final String signature,
- final Label start,
- final Label end,
- final int index)
- {
+ public void visitLocalVariable(final String name, final String desc,
+ final String signature, final Label start, final Label end,
+ final int index) {
buf.setLength(0);
buf.append(this.name).append(".visitLocalVariable(");
appendConstant(name);
@@ -838,12 +760,8 @@ public class ASMifier extends Printer {
@Override
public void visitMaxs(final int maxStack, final int maxLocals) {
buf.setLength(0);
- buf.append(name)
- .append(".visitMaxs(")
- .append(maxStack)
- .append(", ")
- .append(maxLocals)
- .append(");\n");
+ buf.append(name).append(".visitMaxs(").append(maxStack).append(", ")
+ .append(maxLocals).append(");\n");
text.add(buf.toString());
}
@@ -858,14 +776,9 @@ public class ASMifier extends Printer {
// Common methods
// ------------------------------------------------------------------------
- public ASMifier visitAnnotation(
- final String desc,
- final boolean visible)
- {
+ public ASMifier visitAnnotation(final String desc, final boolean visible) {
buf.setLength(0);
- buf.append("{\n")
- .append("av0 = ")
- .append(name)
+ buf.append("{\n").append("av0 = ").append(name)
.append(".visitAnnotation(");
appendConstant(desc);
buf.append(", ").append(visible).append(");\n");
@@ -895,15 +808,16 @@ public class ASMifier extends Printer {
// Utility methods
// ------------------------------------------------------------------------
- protected ASMifier createASMifier(final String name, final int id) {
+ protected ASMifier createASMifier(final String name, final int id) {
return new ASMifier(Opcodes.ASM4, name, id);
}
/**
- * Appends a string representation of the given access modifiers to {@link
- * #buf buf}.
+ * Appends a string representation of the given access modifiers to
+ * {@link #buf buf}.
*
- * @param access some access modifiers.
+ * @param access
+ * some access modifiers.
*/
void appendAccess(final int access) {
boolean first = true;
@@ -945,8 +859,7 @@ public class ASMifier extends Printer {
first = false;
}
if ((access & Opcodes.ACC_VOLATILE) != 0
- && (access & ACCESS_FIELD) != 0)
- {
+ && (access & ACCESS_FIELD) != 0) {
if (!first) {
buf.append(" + ");
}
@@ -954,8 +867,7 @@ public class ASMifier extends Printer {
first = false;
}
if ((access & Opcodes.ACC_BRIDGE) != 0 && (access & ACCESS_CLASS) == 0
- && (access & ACCESS_FIELD) == 0)
- {
+ && (access & ACCESS_FIELD) == 0) {
if (!first) {
buf.append(" + ");
}
@@ -963,8 +875,7 @@ public class ASMifier extends Printer {
first = false;
}
if ((access & Opcodes.ACC_VARARGS) != 0 && (access & ACCESS_CLASS) == 0
- && (access & ACCESS_FIELD) == 0)
- {
+ && (access & ACCESS_FIELD) == 0) {
if (!first) {
buf.append(" + ");
}
@@ -972,8 +883,7 @@ public class ASMifier extends Printer {
first = false;
}
if ((access & Opcodes.ACC_TRANSIENT) != 0
- && (access & ACCESS_FIELD) != 0)
- {
+ && (access & ACCESS_FIELD) != 0) {
if (!first) {
buf.append(" + ");
}
@@ -981,8 +891,7 @@ public class ASMifier extends Printer {
first = false;
}
if ((access & Opcodes.ACC_NATIVE) != 0 && (access & ACCESS_CLASS) == 0
- && (access & ACCESS_FIELD) == 0)
- {
+ && (access & ACCESS_FIELD) == 0) {
if (!first) {
buf.append(" + ");
}
@@ -991,8 +900,7 @@ public class ASMifier extends Printer {
}
if ((access & Opcodes.ACC_ENUM) != 0
&& ((access & ACCESS_CLASS) != 0
- || (access & ACCESS_FIELD) != 0 || (access & ACCESS_INNER) != 0))
- {
+ || (access & ACCESS_FIELD) != 0 || (access & ACCESS_INNER) != 0)) {
if (!first) {
buf.append(" + ");
}
@@ -1000,8 +908,7 @@ public class ASMifier extends Printer {
first = false;
}
if ((access & Opcodes.ACC_ANNOTATION) != 0
- && ((access & ACCESS_CLASS) != 0 || (access & ACCESS_INNER) != 0))
- {
+ && ((access & ACCESS_CLASS) != 0 || (access & ACCESS_INNER) != 0)) {
if (!first) {
buf.append(" + ");
}
@@ -1052,8 +959,9 @@ public class ASMifier extends Printer {
* Appends a string representation of the given constant to the given
* buffer.
*
- * @param cst an {@link Integer}, {@link Float}, {@link Long},
- * {@link Double} or {@link String} object. May be <tt>null</tt>.
+ * @param cst
+ * an {@link Integer}, {@link Float}, {@link Long},
+ * {@link Double} or {@link String} object. May be <tt>null</tt>.
*/
protected void appendConstant(final Object cst) {
appendConstant(buf, cst);
@@ -1063,9 +971,11 @@ public class ASMifier extends Printer {
* Appends a string representation of the given constant to the given
* buffer.
*
- * @param buf a string buffer.
- * @param cst an {@link Integer}, {@link Float}, {@link Long},
- * {@link Double} or {@link String} object. May be <tt>null</tt>.
+ * @param buf
+ * a string buffer.
+ * @param cst
+ * an {@link Integer}, {@link Float}, {@link Long},
+ * {@link Double} or {@link String} object. May be <tt>null</tt>.
*/
static void appendConstant(final StringBuffer buf, final Object cst) {
if (cst == null) {
@@ -1079,14 +989,16 @@ public class ASMifier extends Printer {
} else if (cst instanceof Handle) {
buf.append("new Handle(");
Handle h = (Handle) cst;
- buf.append("Opcodes.").append(HANDLE_TAG[h.getTag()]).append(", \"");
+ buf.append("Opcodes.").append(HANDLE_TAG[h.getTag()])
+ .append(", \"");
buf.append(h.getOwner()).append("\", \"");
buf.append(h.getName()).append("\", \"");
buf.append(h.getDesc()).append("\")");
} else if (cst instanceof Byte) {
buf.append("new Byte((byte)").append(cst).append(')');
} else if (cst instanceof Boolean) {
- buf.append(((Boolean) cst).booleanValue() ? "Boolean.TRUE" : "Boolean.FALSE");
+ buf.append(((Boolean) cst).booleanValue() ? "Boolean.TRUE"
+ : "Boolean.FALSE");
} else if (cst instanceof Short) {
buf.append("new Short((short)").append(cst).append(')');
} else if (cst instanceof Character) {
@@ -1125,8 +1037,7 @@ public class ASMifier extends Printer {
char[] v = (char[]) cst;
buf.append("new char[] {");
for (int i = 0; i < v.length; i++) {
- buf.append(i == 0 ? "" : ",")
- .append("(char)")
+ buf.append(i == 0 ? "" : ",").append("(char)")
.append((int) v[i]);
}
buf.append('}');
@@ -1178,27 +1089,27 @@ public class ASMifier extends Printer {
appendConstant(o[i]);
} else if (o[i] instanceof Integer) {
switch (((Integer) o[i]).intValue()) {
- case 0:
- buf.append("Opcodes.TOP");
- break;
- case 1:
- buf.append("Opcodes.INTEGER");
- break;
- case 2:
- buf.append("Opcodes.FLOAT");
- break;
- case 3:
- buf.append("Opcodes.DOUBLE");
- break;
- case 4:
- buf.append("Opcodes.LONG");
- break;
- case 5:
- buf.append("Opcodes.NULL");
- break;
- case 6:
- buf.append("Opcodes.UNINITIALIZED_THIS");
- break;
+ case 0:
+ buf.append("Opcodes.TOP");
+ break;
+ case 1:
+ buf.append("Opcodes.INTEGER");
+ break;
+ case 2:
+ buf.append("Opcodes.FLOAT");
+ break;
+ case 3:
+ buf.append("Opcodes.DOUBLE");
+ break;
+ case 4:
+ buf.append("Opcodes.LONG");
+ break;
+ case 5:
+ buf.append("Opcodes.NULL");
+ break;
+ case 6:
+ buf.append("Opcodes.UNINITIALIZED_THIS");
+ break;
}
} else {
appendLabel((Label) o[i]);
@@ -1211,7 +1122,8 @@ public class ASMifier extends Printer {
* declaration is of the form "Label lXXX = new Label();". Does nothing if
* the given label has already been declared.
*
- * @param l a label.
+ * @param l
+ * a label.
*/
protected void declareLabel(final Label l) {
if (labelNames == null) {
@@ -1227,10 +1139,11 @@ public class ASMifier extends Printer {
/**
* Appends the name of the given label to {@link #buf buf}. The given label
- * <i>must</i> already have a name. One way to ensure this is to always
- * call {@link #declareLabel declared} before calling this method.
+ * <i>must</i> already have a name. One way to ensure this is to always call
+ * {@link #declareLabel declared} before calling this method.
*
- * @param l a label.
+ * @param l
+ * a label.
*/
protected void appendLabel(final Label l) {
buf.append(labelNames.get(l));
diff --git a/src/asm/scala/tools/asm/util/CheckAnnotationAdapter.java b/src/asm/scala/tools/asm/util/CheckAnnotationAdapter.java
index 8030c14f2e..f00a8f04a2 100644
--- a/src/asm/scala/tools/asm/util/CheckAnnotationAdapter.java
+++ b/src/asm/scala/tools/asm/util/CheckAnnotationAdapter.java
@@ -65,8 +65,7 @@ public class CheckAnnotationAdapter extends AnnotationVisitor {
|| value instanceof byte[] || value instanceof boolean[]
|| value instanceof char[] || value instanceof short[]
|| value instanceof int[] || value instanceof long[]
- || value instanceof float[] || value instanceof double[]))
- {
+ || value instanceof float[] || value instanceof double[])) {
throw new IllegalArgumentException("Invalid annotation value");
}
if (value instanceof Type) {
@@ -81,11 +80,8 @@ public class CheckAnnotationAdapter extends AnnotationVisitor {
}
@Override
- public void visitEnum(
- final String name,
- final String desc,
- final String value)
- {
+ public void visitEnum(final String name, final String desc,
+ final String value) {
checkEnd();
checkName(name);
CheckMethodAdapter.checkDesc(desc, false);
@@ -98,15 +94,12 @@ public class CheckAnnotationAdapter extends AnnotationVisitor {
}
@Override
- public AnnotationVisitor visitAnnotation(
- final String name,
- final String desc)
- {
+ public AnnotationVisitor visitAnnotation(final String name,
+ final String desc) {
checkEnd();
checkName(name);
CheckMethodAdapter.checkDesc(desc, false);
- return new CheckAnnotationAdapter(av == null
- ? null
+ return new CheckAnnotationAdapter(av == null ? null
: av.visitAnnotation(name, desc));
}
@@ -114,8 +107,7 @@ public class CheckAnnotationAdapter extends AnnotationVisitor {
public AnnotationVisitor visitArray(final String name) {
checkEnd();
checkName(name);
- return new CheckAnnotationAdapter(av == null
- ? null
+ return new CheckAnnotationAdapter(av == null ? null
: av.visitArray(name), false);
}
@@ -130,13 +122,15 @@ public class CheckAnnotationAdapter extends AnnotationVisitor {
private void checkEnd() {
if (end) {
- throw new IllegalStateException("Cannot call a visit method after visitEnd has been called");
+ throw new IllegalStateException(
+ "Cannot call a visit method after visitEnd has been called");
}
}
private void checkName(final String name) {
if (named && name == null) {
- throw new IllegalArgumentException("Annotation value name must not be null");
+ throw new IllegalArgumentException(
+ "Annotation value name must not be null");
}
}
}
diff --git a/src/asm/scala/tools/asm/util/CheckClassAdapter.java b/src/asm/scala/tools/asm/util/CheckClassAdapter.java
index a455322531..0bfa143a95 100644
--- a/src/asm/scala/tools/asm/util/CheckClassAdapter.java
+++ b/src/asm/scala/tools/asm/util/CheckClassAdapter.java
@@ -59,10 +59,10 @@ import scala.tools.asm.tree.analysis.SimpleVerifier;
* <i>only</i> on its arguments, but does <i>not</i> check the <i>sequence</i>
* of method calls. For example, the invalid sequence
* <tt>visitField(ACC_PUBLIC, "i", "I", null)</tt> <tt>visitField(ACC_PUBLIC,
- * "i", "D", null)</tt>
- * will <i>not</i> be detected by this class adapter.
+ * "i", "D", null)</tt> will <i>not</i> be detected by this class adapter.
*
- * <p><code>CheckClassAdapter</code> can be also used to verify bytecode
+ * <p>
+ * <code>CheckClassAdapter</code> can be also used to verify bytecode
* transformations in order to make sure transformed bytecode is sane. For
* example:
*
@@ -80,19 +80,20 @@ import scala.tools.asm.tree.analysis.SimpleVerifier;
* </pre>
*
* Above code runs transformed bytecode trough the
- * <code>CheckClassAdapter</code>. It won't be exactly the same verification
- * as JVM does, but it run data flow analysis for the code of each method and
+ * <code>CheckClassAdapter</code>. It won't be exactly the same verification as
+ * JVM does, but it run data flow analysis for the code of each method and
* checks that expectations are met for each method instruction.
*
- * <p>If method bytecode has errors, assertion text will show the erroneous
+ * <p>
+ * If method bytecode has errors, assertion text will show the erroneous
* instruction number and dump of the failed method with information about
* locals and stack slot for each instruction. For example (format is -
* insnNumber locals : stack):
*
* <pre>
- * org.objectweb.asm.tree.analysis.AnalyzerException: Error at instruction 71: Expected I, but found .
- * at org.objectweb.asm.tree.analysis.Analyzer.analyze(Analyzer.java:289)
- * at org.objectweb.asm.util.CheckClassAdapter.verify(CheckClassAdapter.java:135)
+ * scala.tools.asm.tree.analysis.AnalyzerException: Error at instruction 71: Expected I, but found .
+ * at scala.tools.asm.tree.analysis.Analyzer.analyze(Analyzer.java:289)
+ * at scala.tools.asm.util.CheckClassAdapter.verify(CheckClassAdapter.java:135)
* ...
* remove()V
* 00000 LinkedBlockingQueue$Itr . . . . . . . . :
@@ -114,8 +115,9 @@ import scala.tools.asm.tree.analysis.SimpleVerifier;
* initialized. You can also see that at the beginning of the method (code
* inserted by the transformation) variable 2 is initialized.
*
- * <p>Note that when used like that, <code>CheckClassAdapter.verify()</code>
- * can trigger additional class loading, because it is using
+ * <p>
+ * Note that when used like that, <code>CheckClassAdapter.verify()</code> can
+ * trigger additional class loading, because it is using
* <code>SimpleVerifier</code>.
*
* @author Eric Bruneton
@@ -159,13 +161,15 @@ public class CheckClassAdapter extends ClassVisitor {
private boolean checkDataFlow;
/**
- * Checks a given class. <p> Usage: CheckClassAdapter &lt;binary
- * class name or class file name&gt;
+ * Checks a given class.
+ * <p>
+ * Usage: CheckClassAdapter &lt;binary class name or class file name&gt;
*
- * @param args the command line arguments.
+ * @param args
+ * the command line arguments.
*
- * @throws Exception if the class cannot be found, or if an IO exception
- * occurs.
+ * @throws Exception
+ * if the class cannot be found, or if an IO exception occurs.
*/
public static void main(final String[] args) throws Exception {
if (args.length != 1) {
@@ -187,27 +191,26 @@ public class CheckClassAdapter extends ClassVisitor {
/**
* Checks a given class.
*
- * @param cr a <code>ClassReader</code> that contains bytecode for the
- * analysis.
- * @param loader a <code>ClassLoader</code> which will be used to load
- * referenced classes. This is useful if you are verifiying multiple
- * interdependent classes.
- * @param dump true if bytecode should be printed out not only when errors
- * are found.
- * @param pw write where results going to be printed
+ * @param cr
+ * a <code>ClassReader</code> that contains bytecode for the
+ * analysis.
+ * @param loader
+ * a <code>ClassLoader</code> which will be used to load
+ * referenced classes. This is useful if you are verifiying
+ * multiple interdependent classes.
+ * @param dump
+ * true if bytecode should be printed out not only when errors
+ * are found.
+ * @param pw
+ * write where results going to be printed
*/
- public static void verify(
- final ClassReader cr,
- final ClassLoader loader,
- final boolean dump,
- final PrintWriter pw)
- {
+ public static void verify(final ClassReader cr, final ClassLoader loader,
+ final boolean dump, final PrintWriter pw) {
ClassNode cn = new ClassNode();
cr.accept(new CheckClassAdapter(cn, false), ClassReader.SKIP_DEBUG);
- Type syperType = cn.superName == null
- ? null
- : Type.getObjectType(cn.superName);
+ Type syperType = cn.superName == null ? null : Type
+ .getObjectType(cn.superName);
List<MethodNode> methods = cn.methods;
List<Type> interfaces = new ArrayList<Type>();
@@ -217,9 +220,8 @@ public class CheckClassAdapter extends ClassVisitor {
for (int i = 0; i < methods.size(); ++i) {
MethodNode method = methods.get(i);
- SimpleVerifier verifier = new SimpleVerifier(Type.getObjectType(cn.name),
- syperType,
- interfaces,
+ SimpleVerifier verifier = new SimpleVerifier(
+ Type.getObjectType(cn.name), syperType, interfaces,
(cn.access & Opcodes.ACC_INTERFACE) != 0);
Analyzer<BasicValue> a = new Analyzer<BasicValue>(verifier);
if (loader != null) {
@@ -241,25 +243,22 @@ public class CheckClassAdapter extends ClassVisitor {
/**
* Checks a given class
*
- * @param cr a <code>ClassReader</code> that contains bytecode for the
- * analysis.
- * @param dump true if bytecode should be printed out not only when errors
- * are found.
- * @param pw write where results going to be printed
+ * @param cr
+ * a <code>ClassReader</code> that contains bytecode for the
+ * analysis.
+ * @param dump
+ * true if bytecode should be printed out not only when errors
+ * are found.
+ * @param pw
+ * write where results going to be printed
*/
- public static void verify(
- final ClassReader cr,
- final boolean dump,
- final PrintWriter pw)
- {
+ public static void verify(final ClassReader cr, final boolean dump,
+ final PrintWriter pw) {
verify(cr, null, dump, pw);
}
- static void printAnalyzerResult(
- MethodNode method,
- Analyzer<BasicValue> a,
- final PrintWriter pw)
- {
+ static void printAnalyzerResult(MethodNode method, Analyzer<BasicValue> a,
+ final PrintWriter pw) {
Frame<BasicValue>[] frames = a.getFrames();
Textifier t = new Textifier();
TraceMethodVisitor mv = new TraceMethodVisitor(t);
@@ -310,7 +309,8 @@ public class CheckClassAdapter extends ClassVisitor {
* this constructor</i>. Instead, they must use the
* {@link #CheckClassAdapter(int, ClassVisitor, boolean)} version.
*
- * @param cv the class visitor to which this adapter must delegate calls.
+ * @param cv
+ * the class visitor to which this adapter must delegate calls.
*/
public CheckClassAdapter(final ClassVisitor cv) {
this(cv, true);
@@ -321,33 +321,34 @@ public class CheckClassAdapter extends ClassVisitor {
* this constructor</i>. Instead, they must use the
* {@link #CheckClassAdapter(int, ClassVisitor, boolean)} version.
*
- * @param cv the class visitor to which this adapter must delegate calls.
- * @param checkDataFlow <tt>true</tt> to perform basic data flow checks, or
- * <tt>false</tt> to not perform any data flow check (see
- * {@link CheckMethodAdapter}). This option requires valid maxLocals
- * and maxStack values.
+ * @param cv
+ * the class visitor to which this adapter must delegate calls.
+ * @param checkDataFlow
+ * <tt>true</tt> to perform basic data flow checks, or
+ * <tt>false</tt> to not perform any data flow check (see
+ * {@link CheckMethodAdapter}). This option requires valid
+ * maxLocals and maxStack values.
*/
- public CheckClassAdapter(final ClassVisitor cv, final boolean checkDataFlow)
- {
+ public CheckClassAdapter(final ClassVisitor cv, final boolean checkDataFlow) {
this(Opcodes.ASM4, cv, checkDataFlow);
}
/**
* Constructs a new {@link CheckClassAdapter}.
*
- * @param api the ASM API version implemented by this visitor. Must be one
- * of {@link Opcodes#ASM4}.
- * @param cv the class visitor to which this adapter must delegate calls.
- * @param checkDataFlow <tt>true</tt> to perform basic data flow checks, or
- * <tt>false</tt> to not perform any data flow check (see
- * {@link CheckMethodAdapter}). This option requires valid maxLocals
- * and maxStack values.
+ * @param api
+ * the ASM API version implemented by this visitor. Must be one
+ * of {@link Opcodes#ASM4}.
+ * @param cv
+ * the class visitor to which this adapter must delegate calls.
+ * @param checkDataFlow
+ * <tt>true</tt> to perform basic data flow checks, or
+ * <tt>false</tt> to not perform any data flow check (see
+ * {@link CheckMethodAdapter}). This option requires valid
+ * maxLocals and maxStack values.
*/
- protected CheckClassAdapter(
- final int api,
- final ClassVisitor cv,
- final boolean checkDataFlow)
- {
+ protected CheckClassAdapter(final int api, final ClassVisitor cv,
+ final boolean checkDataFlow) {
super(api, cv);
this.labels = new HashMap<Label, Integer>();
this.checkDataFlow = checkDataFlow;
@@ -358,14 +359,9 @@ public class CheckClassAdapter extends ClassVisitor {
// ------------------------------------------------------------------------
@Override
- public void visit(
- final int version,
- final int access,
- final String name,
- final String signature,
- final String superName,
- final String[] interfaces)
- {
+ public void visit(final int version, final int access, final String name,
+ final String signature, final String superName,
+ final String[] interfaces) {
if (start) {
throw new IllegalStateException("visit must be called only once");
}
@@ -375,24 +371,25 @@ public class CheckClassAdapter extends ClassVisitor {
+ Opcodes.ACC_SUPER + Opcodes.ACC_INTERFACE
+ Opcodes.ACC_ABSTRACT + Opcodes.ACC_SYNTHETIC
+ Opcodes.ACC_ANNOTATION + Opcodes.ACC_ENUM
- + Opcodes.ACC_DEPRECATED
- + 0x40000); // ClassWriter.ACC_SYNTHETIC_ATTRIBUTE
+ + Opcodes.ACC_DEPRECATED + 0x40000); // ClassWriter.ACC_SYNTHETIC_ATTRIBUTE
if (name == null || !name.endsWith("package-info")) {
CheckMethodAdapter.checkInternalName(name, "class name");
}
if ("java/lang/Object".equals(name)) {
if (superName != null) {
- throw new IllegalArgumentException("The super class name of the Object class must be 'null'");
+ throw new IllegalArgumentException(
+ "The super class name of the Object class must be 'null'");
}
} else {
CheckMethodAdapter.checkInternalName(superName, "super class name");
}
if (signature != null) {
- CheckMethodAdapter.checkClassSignature(signature);
+ checkClassSignature(signature);
}
if ((access & Opcodes.ACC_INTERFACE) != 0) {
if (!"java/lang/Object".equals(superName)) {
- throw new IllegalArgumentException("The super class name of interfaces must be 'java/lang/Object'");
+ throw new IllegalArgumentException(
+ "The super class name of interfaces must be 'java/lang/Object'");
}
}
if (interfaces != null) {
@@ -409,21 +406,20 @@ public class CheckClassAdapter extends ClassVisitor {
public void visitSource(final String file, final String debug) {
checkState();
if (source) {
- throw new IllegalStateException("visitSource can be called only once.");
+ throw new IllegalStateException(
+ "visitSource can be called only once.");
}
source = true;
super.visitSource(file, debug);
}
@Override
- public void visitOuterClass(
- final String owner,
- final String name,
- final String desc)
- {
+ public void visitOuterClass(final String owner, final String name,
+ final String desc) {
checkState();
if (outer) {
- throw new IllegalStateException("visitOuterClass can be called only once.");
+ throw new IllegalStateException(
+ "visitOuterClass can be called only once.");
}
outer = true;
if (owner == null) {
@@ -436,12 +432,8 @@ public class CheckClassAdapter extends ClassVisitor {
}
@Override
- public void visitInnerClass(
- final String name,
- final String outerName,
- final String innerName,
- final int access)
- {
+ public void visitInnerClass(final String name, final String outerName,
+ final String innerName, final int access) {
checkState();
CheckMethodAdapter.checkInternalName(name, "class name");
if (outerName != null) {
@@ -459,52 +451,44 @@ public class CheckClassAdapter extends ClassVisitor {
}
@Override
- public FieldVisitor visitField(
- final int access,
- final String name,
- final String desc,
- final String signature,
- final Object value)
- {
+ public FieldVisitor visitField(final int access, final String name,
+ final String desc, final String signature, final Object value) {
checkState();
checkAccess(access, Opcodes.ACC_PUBLIC + Opcodes.ACC_PRIVATE
+ Opcodes.ACC_PROTECTED + Opcodes.ACC_STATIC
+ Opcodes.ACC_FINAL + Opcodes.ACC_VOLATILE
+ Opcodes.ACC_TRANSIENT + Opcodes.ACC_SYNTHETIC
- + Opcodes.ACC_ENUM + Opcodes.ACC_DEPRECATED
- + 0x40000); // ClassWriter.ACC_SYNTHETIC_ATTRIBUTE
+ + Opcodes.ACC_ENUM + Opcodes.ACC_DEPRECATED + 0x40000); // ClassWriter.ACC_SYNTHETIC_ATTRIBUTE
CheckMethodAdapter.checkUnqualifiedName(version, name, "field name");
CheckMethodAdapter.checkDesc(desc, false);
if (signature != null) {
- CheckMethodAdapter.checkFieldSignature(signature);
+ checkFieldSignature(signature);
}
if (value != null) {
CheckMethodAdapter.checkConstant(value);
}
- FieldVisitor av = super.visitField(access, name, desc, signature, value);
+ FieldVisitor av = super
+ .visitField(access, name, desc, signature, value);
return new CheckFieldAdapter(av);
}
@Override
- public MethodVisitor visitMethod(
- final int access,
- final String name,
- final String desc,
- final String signature,
- final String[] exceptions)
- {
+ public MethodVisitor visitMethod(final int access, final String name,
+ final String desc, final String signature, final String[] exceptions) {
checkState();
checkAccess(access, Opcodes.ACC_PUBLIC + Opcodes.ACC_PRIVATE
+ Opcodes.ACC_PROTECTED + Opcodes.ACC_STATIC
+ Opcodes.ACC_FINAL + Opcodes.ACC_SYNCHRONIZED
+ Opcodes.ACC_BRIDGE + Opcodes.ACC_VARARGS + Opcodes.ACC_NATIVE
+ Opcodes.ACC_ABSTRACT + Opcodes.ACC_STRICT
- + Opcodes.ACC_SYNTHETIC + Opcodes.ACC_DEPRECATED
- + 0x40000); // ClassWriter.ACC_SYNTHETIC_ATTRIBUTE
- CheckMethodAdapter.checkMethodIdentifier(version, name, "method name");
+ + Opcodes.ACC_SYNTHETIC + Opcodes.ACC_DEPRECATED + 0x40000); // ClassWriter.ACC_SYNTHETIC_ATTRIBUTE
+ if (!"<init>".equals(name) && !"<clinit>".equals(name)) {
+ CheckMethodAdapter.checkMethodIdentifier(version, name,
+ "method name");
+ }
CheckMethodAdapter.checkMethodDesc(desc);
if (signature != null) {
- CheckMethodAdapter.checkMethodSignature(signature);
+ checkMethodSignature(signature);
}
if (exceptions != null) {
for (int i = 0; i < exceptions.length; ++i) {
@@ -514,27 +498,19 @@ public class CheckClassAdapter extends ClassVisitor {
}
CheckMethodAdapter cma;
if (checkDataFlow) {
- cma = new CheckMethodAdapter(access,
- name,
- desc,
- super.visitMethod(access, name, desc, signature, exceptions),
- labels);
+ cma = new CheckMethodAdapter(access, name, desc, super.visitMethod(
+ access, name, desc, signature, exceptions), labels);
} else {
- cma = new CheckMethodAdapter(super.visitMethod(access,
- name,
- desc,
- signature,
- exceptions), labels);
+ cma = new CheckMethodAdapter(super.visitMethod(access, name, desc,
+ signature, exceptions), labels);
}
cma.version = version;
return cma;
}
@Override
- public AnnotationVisitor visitAnnotation(
- final String desc,
- final boolean visible)
- {
+ public AnnotationVisitor visitAnnotation(final String desc,
+ final boolean visible) {
checkState();
CheckMethodAdapter.checkDesc(desc, false);
return new CheckAnnotationAdapter(super.visitAnnotation(desc, visible));
@@ -544,7 +520,8 @@ public class CheckClassAdapter extends ClassVisitor {
public void visitAttribute(final Attribute attr) {
checkState();
if (attr == null) {
- throw new IllegalArgumentException("Invalid attribute (must not be null)");
+ throw new IllegalArgumentException(
+ "Invalid attribute (must not be null)");
}
super.visitAttribute(attr);
}
@@ -566,10 +543,12 @@ public class CheckClassAdapter extends ClassVisitor {
*/
private void checkState() {
if (!start) {
- throw new IllegalStateException("Cannot visit member before visit has been called.");
+ throw new IllegalStateException(
+ "Cannot visit member before visit has been called.");
}
if (end) {
- throw new IllegalStateException("Cannot visit member after visitEnd has been called.");
+ throw new IllegalStateException(
+ "Cannot visit member after visitEnd has been called.");
}
}
@@ -578,8 +557,10 @@ public class CheckClassAdapter extends ClassVisitor {
* method also checks that mutually incompatible flags are not set
* simultaneously.
*
- * @param access the access flags to be checked
- * @param possibleAccess the valid access flags.
+ * @param access
+ * the access flags to be checked
+ * @param possibleAccess
+ * the valid access flags.
*/
static void checkAccess(final int access, final int possibleAccess) {
if ((access & ~possibleAccess) != 0) {
@@ -590,14 +571,336 @@ public class CheckClassAdapter extends ClassVisitor {
int pri = (access & Opcodes.ACC_PRIVATE) == 0 ? 0 : 1;
int pro = (access & Opcodes.ACC_PROTECTED) == 0 ? 0 : 1;
if (pub + pri + pro > 1) {
- throw new IllegalArgumentException("public private and protected are mutually exclusive: "
- + access);
+ throw new IllegalArgumentException(
+ "public private and protected are mutually exclusive: "
+ + access);
}
int fin = (access & Opcodes.ACC_FINAL) == 0 ? 0 : 1;
int abs = (access & Opcodes.ACC_ABSTRACT) == 0 ? 0 : 1;
if (fin + abs > 1) {
- throw new IllegalArgumentException("final and abstract are mutually exclusive: "
- + access);
+ throw new IllegalArgumentException(
+ "final and abstract are mutually exclusive: " + access);
+ }
+ }
+
+ /**
+ * Checks a class signature.
+ *
+ * @param signature
+ * a string containing the signature that must be checked.
+ */
+ public static void checkClassSignature(final String signature) {
+ // ClassSignature:
+ // FormalTypeParameters? ClassTypeSignature ClassTypeSignature*
+
+ int pos = 0;
+ if (getChar(signature, 0) == '<') {
+ pos = checkFormalTypeParameters(signature, pos);
+ }
+ pos = checkClassTypeSignature(signature, pos);
+ while (getChar(signature, pos) == 'L') {
+ pos = checkClassTypeSignature(signature, pos);
+ }
+ if (pos != signature.length()) {
+ throw new IllegalArgumentException(signature + ": error at index "
+ + pos);
+ }
+ }
+
+ /**
+ * Checks a method signature.
+ *
+ * @param signature
+ * a string containing the signature that must be checked.
+ */
+ public static void checkMethodSignature(final String signature) {
+ // MethodTypeSignature:
+ // FormalTypeParameters? ( TypeSignature* ) ( TypeSignature | V ) (
+ // ^ClassTypeSignature | ^TypeVariableSignature )*
+
+ int pos = 0;
+ if (getChar(signature, 0) == '<') {
+ pos = checkFormalTypeParameters(signature, pos);
+ }
+ pos = checkChar('(', signature, pos);
+ while ("ZCBSIFJDL[T".indexOf(getChar(signature, pos)) != -1) {
+ pos = checkTypeSignature(signature, pos);
+ }
+ pos = checkChar(')', signature, pos);
+ if (getChar(signature, pos) == 'V') {
+ ++pos;
+ } else {
+ pos = checkTypeSignature(signature, pos);
+ }
+ while (getChar(signature, pos) == '^') {
+ ++pos;
+ if (getChar(signature, pos) == 'L') {
+ pos = checkClassTypeSignature(signature, pos);
+ } else {
+ pos = checkTypeVariableSignature(signature, pos);
+ }
+ }
+ if (pos != signature.length()) {
+ throw new IllegalArgumentException(signature + ": error at index "
+ + pos);
+ }
+ }
+
+ /**
+ * Checks a field signature.
+ *
+ * @param signature
+ * a string containing the signature that must be checked.
+ */
+ public static void checkFieldSignature(final String signature) {
+ int pos = checkFieldTypeSignature(signature, 0);
+ if (pos != signature.length()) {
+ throw new IllegalArgumentException(signature + ": error at index "
+ + pos);
+ }
+ }
+
+ /**
+ * Checks the formal type parameters of a class or method signature.
+ *
+ * @param signature
+ * a string containing the signature that must be checked.
+ * @param pos
+ * index of first character to be checked.
+ * @return the index of the first character after the checked part.
+ */
+ private static int checkFormalTypeParameters(final String signature, int pos) {
+ // FormalTypeParameters:
+ // < FormalTypeParameter+ >
+
+ pos = checkChar('<', signature, pos);
+ pos = checkFormalTypeParameter(signature, pos);
+ while (getChar(signature, pos) != '>') {
+ pos = checkFormalTypeParameter(signature, pos);
+ }
+ return pos + 1;
+ }
+
+ /**
+ * Checks a formal type parameter of a class or method signature.
+ *
+ * @param signature
+ * a string containing the signature that must be checked.
+ * @param pos
+ * index of first character to be checked.
+ * @return the index of the first character after the checked part.
+ */
+ private static int checkFormalTypeParameter(final String signature, int pos) {
+ // FormalTypeParameter:
+ // Identifier : FieldTypeSignature? (: FieldTypeSignature)*
+
+ pos = checkIdentifier(signature, pos);
+ pos = checkChar(':', signature, pos);
+ if ("L[T".indexOf(getChar(signature, pos)) != -1) {
+ pos = checkFieldTypeSignature(signature, pos);
+ }
+ while (getChar(signature, pos) == ':') {
+ pos = checkFieldTypeSignature(signature, pos + 1);
+ }
+ return pos;
+ }
+
+ /**
+ * Checks a field type signature.
+ *
+ * @param signature
+ * a string containing the signature that must be checked.
+ * @param pos
+ * index of first character to be checked.
+ * @return the index of the first character after the checked part.
+ */
+ private static int checkFieldTypeSignature(final String signature, int pos) {
+ // FieldTypeSignature:
+ // ClassTypeSignature | ArrayTypeSignature | TypeVariableSignature
+ //
+ // ArrayTypeSignature:
+ // [ TypeSignature
+
+ switch (getChar(signature, pos)) {
+ case 'L':
+ return checkClassTypeSignature(signature, pos);
+ case '[':
+ return checkTypeSignature(signature, pos + 1);
+ default:
+ return checkTypeVariableSignature(signature, pos);
}
}
+
+ /**
+ * Checks a class type signature.
+ *
+ * @param signature
+ * a string containing the signature that must be checked.
+ * @param pos
+ * index of first character to be checked.
+ * @return the index of the first character after the checked part.
+ */
+ private static int checkClassTypeSignature(final String signature, int pos) {
+ // ClassTypeSignature:
+ // L Identifier ( / Identifier )* TypeArguments? ( . Identifier
+ // TypeArguments? )* ;
+
+ pos = checkChar('L', signature, pos);
+ pos = checkIdentifier(signature, pos);
+ while (getChar(signature, pos) == '/') {
+ pos = checkIdentifier(signature, pos + 1);
+ }
+ if (getChar(signature, pos) == '<') {
+ pos = checkTypeArguments(signature, pos);
+ }
+ while (getChar(signature, pos) == '.') {
+ pos = checkIdentifier(signature, pos + 1);
+ if (getChar(signature, pos) == '<') {
+ pos = checkTypeArguments(signature, pos);
+ }
+ }
+ return checkChar(';', signature, pos);
+ }
+
+ /**
+ * Checks the type arguments in a class type signature.
+ *
+ * @param signature
+ * a string containing the signature that must be checked.
+ * @param pos
+ * index of first character to be checked.
+ * @return the index of the first character after the checked part.
+ */
+ private static int checkTypeArguments(final String signature, int pos) {
+ // TypeArguments:
+ // < TypeArgument+ >
+
+ pos = checkChar('<', signature, pos);
+ pos = checkTypeArgument(signature, pos);
+ while (getChar(signature, pos) != '>') {
+ pos = checkTypeArgument(signature, pos);
+ }
+ return pos + 1;
+ }
+
+ /**
+ * Checks a type argument in a class type signature.
+ *
+ * @param signature
+ * a string containing the signature that must be checked.
+ * @param pos
+ * index of first character to be checked.
+ * @return the index of the first character after the checked part.
+ */
+ private static int checkTypeArgument(final String signature, int pos) {
+ // TypeArgument:
+ // * | ( ( + | - )? FieldTypeSignature )
+
+ char c = getChar(signature, pos);
+ if (c == '*') {
+ return pos + 1;
+ } else if (c == '+' || c == '-') {
+ pos++;
+ }
+ return checkFieldTypeSignature(signature, pos);
+ }
+
+ /**
+ * Checks a type variable signature.
+ *
+ * @param signature
+ * a string containing the signature that must be checked.
+ * @param pos
+ * index of first character to be checked.
+ * @return the index of the first character after the checked part.
+ */
+ private static int checkTypeVariableSignature(final String signature,
+ int pos) {
+ // TypeVariableSignature:
+ // T Identifier ;
+
+ pos = checkChar('T', signature, pos);
+ pos = checkIdentifier(signature, pos);
+ return checkChar(';', signature, pos);
+ }
+
+ /**
+ * Checks a type signature.
+ *
+ * @param signature
+ * a string containing the signature that must be checked.
+ * @param pos
+ * index of first character to be checked.
+ * @return the index of the first character after the checked part.
+ */
+ private static int checkTypeSignature(final String signature, int pos) {
+ // TypeSignature:
+ // Z | C | B | S | I | F | J | D | FieldTypeSignature
+
+ switch (getChar(signature, pos)) {
+ case 'Z':
+ case 'C':
+ case 'B':
+ case 'S':
+ case 'I':
+ case 'F':
+ case 'J':
+ case 'D':
+ return pos + 1;
+ default:
+ return checkFieldTypeSignature(signature, pos);
+ }
+ }
+
+ /**
+ * Checks an identifier.
+ *
+ * @param signature
+ * a string containing the signature that must be checked.
+ * @param pos
+ * index of first character to be checked.
+ * @return the index of the first character after the checked part.
+ */
+ private static int checkIdentifier(final String signature, int pos) {
+ if (!Character.isJavaIdentifierStart(getChar(signature, pos))) {
+ throw new IllegalArgumentException(signature
+ + ": identifier expected at index " + pos);
+ }
+ ++pos;
+ while (Character.isJavaIdentifierPart(getChar(signature, pos))) {
+ ++pos;
+ }
+ return pos;
+ }
+
+ /**
+ * Checks a single character.
+ *
+ * @param signature
+ * a string containing the signature that must be checked.
+ * @param pos
+ * index of first character to be checked.
+ * @return the index of the first character after the checked part.
+ */
+ private static int checkChar(final char c, final String signature, int pos) {
+ if (getChar(signature, pos) == c) {
+ return pos + 1;
+ }
+ throw new IllegalArgumentException(signature + ": '" + c
+ + "' expected at index " + pos);
+ }
+
+ /**
+ * Returns the signature car at the given index.
+ *
+ * @param signature
+ * a signature.
+ * @param pos
+ * an index in signature.
+ * @return the character at the given index, or 0 if there is no such
+ * character.
+ */
+ private static char getChar(final String signature, int pos) {
+ return pos < signature.length() ? signature.charAt(pos) : (char) 0;
+ }
}
diff --git a/src/asm/scala/tools/asm/util/CheckFieldAdapter.java b/src/asm/scala/tools/asm/util/CheckFieldAdapter.java
index bdcbe14b16..4657605936 100644
--- a/src/asm/scala/tools/asm/util/CheckFieldAdapter.java
+++ b/src/asm/scala/tools/asm/util/CheckFieldAdapter.java
@@ -46,7 +46,8 @@ public class CheckFieldAdapter extends FieldVisitor {
* this constructor</i>. Instead, they must use the
* {@link #CheckFieldAdapter(int, FieldVisitor)} version.
*
- * @param fv the field visitor to which this adapter must delegate calls.
+ * @param fv
+ * the field visitor to which this adapter must delegate calls.
*/
public CheckFieldAdapter(final FieldVisitor fv) {
this(Opcodes.ASM4, fv);
@@ -55,19 +56,19 @@ public class CheckFieldAdapter extends FieldVisitor {
/**
* Constructs a new {@link CheckFieldAdapter}.
*
- * @param api the ASM API version implemented by this visitor. Must be one
- * of {@link Opcodes#ASM4}.
- * @param fv the field visitor to which this adapter must delegate calls.
+ * @param api
+ * the ASM API version implemented by this visitor. Must be one
+ * of {@link Opcodes#ASM4}.
+ * @param fv
+ * the field visitor to which this adapter must delegate calls.
*/
protected CheckFieldAdapter(final int api, final FieldVisitor fv) {
super(api, fv);
}
@Override
- public AnnotationVisitor visitAnnotation(
- final String desc,
- final boolean visible)
- {
+ public AnnotationVisitor visitAnnotation(final String desc,
+ final boolean visible) {
checkEnd();
CheckMethodAdapter.checkDesc(desc, false);
return new CheckAnnotationAdapter(super.visitAnnotation(desc, visible));
@@ -77,7 +78,8 @@ public class CheckFieldAdapter extends FieldVisitor {
public void visitAttribute(final Attribute attr) {
checkEnd();
if (attr == null) {
- throw new IllegalArgumentException("Invalid attribute (must not be null)");
+ throw new IllegalArgumentException(
+ "Invalid attribute (must not be null)");
}
super.visitAttribute(attr);
}
@@ -91,7 +93,8 @@ public class CheckFieldAdapter extends FieldVisitor {
private void checkEnd() {
if (end) {
- throw new IllegalStateException("Cannot call a visit method after visitEnd has been called");
+ throw new IllegalStateException(
+ "Cannot call a visit method after visitEnd has been called");
}
}
}
diff --git a/src/asm/scala/tools/asm/util/CheckMethodAdapter.java b/src/asm/scala/tools/asm/util/CheckMethodAdapter.java
index 7549765421..9da01c9d6e 100644
--- a/src/asm/scala/tools/asm/util/CheckMethodAdapter.java
+++ b/src/asm/scala/tools/asm/util/CheckMethodAdapter.java
@@ -58,7 +58,7 @@ import scala.tools.asm.tree.analysis.BasicVerifier;
* arguments - such as the fact that the given opcode is correct for a given
* visit method. This adapter can also perform some basic data flow checks (more
* precisely those that can be performed without the full class hierarchy - see
- * {@link org.objectweb.asm.tree.analysis.BasicVerifier}). For instance in a
+ * {@link scala.tools.asm.tree.analysis.BasicVerifier}). For instance in a
* method whose signature is <tt>void m ()</tt>, the invalid instruction
* IRETURN, or the invalid sequence IADD L2I will be detected if the data flow
* checks are enabled. These checks are enabled by using the
@@ -75,6 +75,11 @@ public class CheckMethodAdapter extends MethodVisitor {
public int version;
/**
+ * The access flags of the method.
+ */
+ private int access;
+
+ /**
* <tt>true</tt> if the visitCode method has been called.
*/
private boolean startCode;
@@ -107,6 +112,21 @@ public class CheckMethodAdapter extends MethodVisitor {
private Set<Label> usedLabels;
/**
+ * Number of visited frames in expanded form.
+ */
+ private int expandedFrames;
+
+ /**
+ * Number of visited frames in compressed form.
+ */
+ private int compressedFrames;
+
+ /**
+ * Number of instructions before the last visited frame.
+ */
+ private int lastFrame = -1;
+
+ /**
* The exception handler ranges. Each pair of list element contains the
* start and end labels of an exception handler block.
*/
@@ -352,7 +372,8 @@ public class CheckMethodAdapter extends MethodVisitor {
* <i>Subclasses must not use this constructor</i>. Instead, they must use
* the {@link #CheckMethodAdapter(int, MethodVisitor, Map)} version.
*
- * @param mv the method visitor to which this adapter must delegate calls.
+ * @param mv
+ * the method visitor to which this adapter must delegate calls.
*/
public CheckMethodAdapter(final MethodVisitor mv) {
this(mv, new HashMap<Label, Integer>());
@@ -365,13 +386,13 @@ public class CheckMethodAdapter extends MethodVisitor {
* <i>Subclasses must not use this constructor</i>. Instead, they must use
* the {@link #CheckMethodAdapter(int, MethodVisitor, Map)} version.
*
- * @param mv the method visitor to which this adapter must delegate calls.
- * @param labels a map of already visited labels (in other methods).
+ * @param mv
+ * the method visitor to which this adapter must delegate calls.
+ * @param labels
+ * a map of already visited labels (in other methods).
*/
- public CheckMethodAdapter(
- final MethodVisitor mv,
- final Map<Label, Integer> labels)
- {
+ public CheckMethodAdapter(final MethodVisitor mv,
+ final Map<Label, Integer> labels) {
this(Opcodes.ASM4, mv, labels);
}
@@ -380,14 +401,13 @@ public class CheckMethodAdapter extends MethodVisitor {
* will not perform any data flow check (see
* {@link #CheckMethodAdapter(int,String,String,MethodVisitor,Map)}).
*
- * @param mv the method visitor to which this adapter must delegate calls.
- * @param labels a map of already visited labels (in other methods).
+ * @param mv
+ * the method visitor to which this adapter must delegate calls.
+ * @param labels
+ * a map of already visited labels (in other methods).
*/
- protected CheckMethodAdapter(
- final int api,
- final MethodVisitor mv,
- final Map<Label, Integer> labels)
- {
+ protected CheckMethodAdapter(final int api, final MethodVisitor mv,
+ final Map<Label, Integer> labels) {
super(api, mv);
this.labels = labels;
this.usedLabels = new HashSet<Label>();
@@ -400,30 +420,32 @@ public class CheckMethodAdapter extends MethodVisitor {
* signature is <tt>void m ()</tt>, the invalid instruction IRETURN, or the
* invalid sequence IADD L2I will be detected.
*
- * @param access the method's access flags.
- * @param name the method's name.
- * @param desc the method's descriptor (see {@link Type Type}).
- * @param cmv the method visitor to which this adapter must delegate calls.
- * @param labels a map of already visited labels (in other methods).
+ * @param access
+ * the method's access flags.
+ * @param name
+ * the method's name.
+ * @param desc
+ * the method's descriptor (see {@link Type Type}).
+ * @param cmv
+ * the method visitor to which this adapter must delegate calls.
+ * @param labels
+ * a map of already visited labels (in other methods).
*/
- public CheckMethodAdapter(
- final int access,
- final String name,
- final String desc,
- final MethodVisitor cmv,
- final Map<Label, Integer> labels)
- {
+ public CheckMethodAdapter(final int access, final String name,
+ final String desc, final MethodVisitor cmv,
+ final Map<Label, Integer> labels) {
this(new MethodNode(access, name, desc, null, null) {
@Override
public void visitEnd() {
- Analyzer<BasicValue> a = new Analyzer<BasicValue>(new BasicVerifier());
+ Analyzer<BasicValue> a = new Analyzer<BasicValue>(
+ new BasicVerifier());
try {
a.analyze("dummy", this);
} catch (Exception e) {
if (e instanceof IndexOutOfBoundsException
- && maxLocals == 0 && maxStack == 0)
- {
- throw new RuntimeException("Data flow checking option requires valid, non zero maxLocals and maxStack values.");
+ && maxLocals == 0 && maxStack == 0) {
+ throw new RuntimeException(
+ "Data flow checking option requires valid, non zero maxLocals and maxStack values.");
}
e.printStackTrace();
StringWriter sw = new StringWriter();
@@ -435,15 +457,13 @@ public class CheckMethodAdapter extends MethodVisitor {
}
accept(cmv);
}
- },
- labels);
+ }, labels);
+ this.access = access;
}
@Override
- public AnnotationVisitor visitAnnotation(
- final String desc,
- final boolean visible)
- {
+ public AnnotationVisitor visitAnnotation(final String desc,
+ final boolean visible) {
checkEndMethod();
checkDesc(desc, false);
return new CheckAnnotationAdapter(super.visitAnnotation(desc, visible));
@@ -456,68 +476,68 @@ public class CheckMethodAdapter extends MethodVisitor {
}
@Override
- public AnnotationVisitor visitParameterAnnotation(
- final int parameter,
- final String desc,
- final boolean visible)
- {
+ public AnnotationVisitor visitParameterAnnotation(final int parameter,
+ final String desc, final boolean visible) {
checkEndMethod();
checkDesc(desc, false);
- return new CheckAnnotationAdapter(super.visitParameterAnnotation(parameter,
- desc,
- visible));
+ return new CheckAnnotationAdapter(super.visitParameterAnnotation(
+ parameter, desc, visible));
}
@Override
public void visitAttribute(final Attribute attr) {
checkEndMethod();
if (attr == null) {
- throw new IllegalArgumentException("Invalid attribute (must not be null)");
+ throw new IllegalArgumentException(
+ "Invalid attribute (must not be null)");
}
super.visitAttribute(attr);
}
@Override
public void visitCode() {
+ if ((access & Opcodes.ACC_ABSTRACT) != 0) {
+ throw new RuntimeException("Abstract methods cannot have code");
+ }
startCode = true;
super.visitCode();
}
@Override
- public void visitFrame(
- final int type,
- final int nLocal,
- final Object[] local,
- final int nStack,
- final Object[] stack)
- {
+ public void visitFrame(final int type, final int nLocal,
+ final Object[] local, final int nStack, final Object[] stack) {
+ if (insnCount == lastFrame) {
+ throw new IllegalStateException(
+ "At most one frame can be visited at a given code location.");
+ }
+ lastFrame = insnCount;
int mLocal;
int mStack;
switch (type) {
- case Opcodes.F_NEW:
- case Opcodes.F_FULL:
- mLocal = Integer.MAX_VALUE;
- mStack = Integer.MAX_VALUE;
- break;
+ case Opcodes.F_NEW:
+ case Opcodes.F_FULL:
+ mLocal = Integer.MAX_VALUE;
+ mStack = Integer.MAX_VALUE;
+ break;
- case Opcodes.F_SAME:
- mLocal = 0;
- mStack = 0;
- break;
+ case Opcodes.F_SAME:
+ mLocal = 0;
+ mStack = 0;
+ break;
- case Opcodes.F_SAME1:
- mLocal = 0;
- mStack = 1;
- break;
+ case Opcodes.F_SAME1:
+ mLocal = 0;
+ mStack = 1;
+ break;
- case Opcodes.F_APPEND:
- case Opcodes.F_CHOP:
- mLocal = 3;
- mStack = 0;
- break;
+ case Opcodes.F_APPEND:
+ case Opcodes.F_CHOP:
+ mLocal = 3;
+ mStack = 0;
+ break;
- default:
- throw new IllegalArgumentException("Invalid frame type " + type);
+ default:
+ throw new IllegalArgumentException("Invalid frame type " + type);
}
if (nLocal > mLocal) {
@@ -531,19 +551,29 @@ public class CheckMethodAdapter extends MethodVisitor {
if (type != Opcodes.F_CHOP) {
if (nLocal > 0 && (local == null || local.length < nLocal)) {
- throw new IllegalArgumentException("Array local[] is shorter than nLocal");
+ throw new IllegalArgumentException(
+ "Array local[] is shorter than nLocal");
}
for (int i = 0; i < nLocal; ++i) {
checkFrameValue(local[i]);
}
}
if (nStack > 0 && (stack == null || stack.length < nStack)) {
- throw new IllegalArgumentException("Array stack[] is shorter than nStack");
+ throw new IllegalArgumentException(
+ "Array stack[] is shorter than nStack");
}
for (int i = 0; i < nStack; ++i) {
checkFrameValue(stack[i]);
}
-
+ if (type == Opcodes.F_NEW) {
+ ++expandedFrames;
+ } else {
+ ++compressedFrames;
+ }
+ if (expandedFrames > 0 && compressedFrames > 0) {
+ throw new RuntimeException(
+ "Expanded and compressed frames must not be mixed.");
+ }
super.visitFrame(type, nLocal, local, nStack, stack);
}
@@ -562,18 +592,19 @@ public class CheckMethodAdapter extends MethodVisitor {
checkEndCode();
checkOpcode(opcode, 1);
switch (opcode) {
- case Opcodes.BIPUSH:
- checkSignedByte(operand, "Invalid operand");
- break;
- case Opcodes.SIPUSH:
- checkSignedShort(operand, "Invalid operand");
- break;
- // case Constants.NEWARRAY:
- default:
- if (operand < Opcodes.T_BOOLEAN || operand > Opcodes.T_LONG) {
- throw new IllegalArgumentException("Invalid operand (must be an array type code T_...): "
- + operand);
- }
+ case Opcodes.BIPUSH:
+ checkSignedByte(operand, "Invalid operand");
+ break;
+ case Opcodes.SIPUSH:
+ checkSignedShort(operand, "Invalid operand");
+ break;
+ // case Constants.NEWARRAY:
+ default:
+ if (operand < Opcodes.T_BOOLEAN || operand > Opcodes.T_LONG) {
+ throw new IllegalArgumentException(
+ "Invalid operand (must be an array type code T_...): "
+ + operand);
+ }
}
super.visitIntInsn(opcode, operand);
++insnCount;
@@ -596,20 +627,16 @@ public class CheckMethodAdapter extends MethodVisitor {
checkOpcode(opcode, 3);
checkInternalName(type, "type");
if (opcode == Opcodes.NEW && type.charAt(0) == '[') {
- throw new IllegalArgumentException("NEW cannot be used to create arrays: "
- + type);
+ throw new IllegalArgumentException(
+ "NEW cannot be used to create arrays: " + type);
}
super.visitTypeInsn(opcode, type);
++insnCount;
}
@Override
- public void visitFieldInsn(
- final int opcode,
- final String owner,
- final String name,
- final String desc)
- {
+ public void visitFieldInsn(final int opcode, final String owner,
+ final String name, final String desc) {
checkStartCode();
checkEndCode();
checkOpcode(opcode, 4);
@@ -621,16 +648,14 @@ public class CheckMethodAdapter extends MethodVisitor {
}
@Override
- public void visitMethodInsn(
- final int opcode,
- final String owner,
- final String name,
- final String desc)
- {
+ public void visitMethodInsn(final int opcode, final String owner,
+ final String name, final String desc) {
checkStartCode();
checkEndCode();
checkOpcode(opcode, 5);
- checkMethodIdentifier(version, name, "name");
+ if (opcode != Opcodes.INVOKESPECIAL || !"<init>".equals(name)) {
+ checkMethodIdentifier(version, name, "name");
+ }
checkInternalName(owner, "owner");
checkMethodDesc(desc);
super.visitMethodInsn(opcode, owner, name, desc);
@@ -638,19 +663,14 @@ public class CheckMethodAdapter extends MethodVisitor {
}
@Override
- public void visitInvokeDynamicInsn(
- String name,
- String desc,
- Handle bsm,
- Object... bsmArgs)
- {
+ public void visitInvokeDynamicInsn(String name, String desc, Handle bsm,
+ Object... bsmArgs) {
checkStartCode();
checkEndCode();
checkMethodIdentifier(version, name, "name");
checkMethodDesc(desc);
if (bsm.getTag() != Opcodes.H_INVOKESTATIC
- && bsm.getTag() != Opcodes.H_NEWINVOKESPECIAL)
- {
+ && bsm.getTag() != Opcodes.H_NEWINVOKESPECIAL) {
throw new IllegalArgumentException("invalid handle tag "
+ bsm.getTag());
}
@@ -705,12 +725,8 @@ public class CheckMethodAdapter extends MethodVisitor {
}
@Override
- public void visitTableSwitchInsn(
- final int min,
- final int max,
- final Label dflt,
- final Label... labels)
- {
+ public void visitTableSwitchInsn(final int min, final int max,
+ final Label dflt, final Label... labels) {
checkStartCode();
checkEndCode();
if (max < min) {
@@ -720,7 +736,8 @@ public class CheckMethodAdapter extends MethodVisitor {
checkLabel(dflt, false, "default label");
checkNonDebugLabel(dflt);
if (labels == null || labels.length != max - min + 1) {
- throw new IllegalArgumentException("There must be max - min + 1 labels");
+ throw new IllegalArgumentException(
+ "There must be max - min + 1 labels");
}
for (int i = 0; i < labels.length; ++i) {
checkLabel(labels[i], false, "label at index " + i);
@@ -734,17 +751,15 @@ public class CheckMethodAdapter extends MethodVisitor {
}
@Override
- public void visitLookupSwitchInsn(
- final Label dflt,
- final int[] keys,
- final Label[] labels)
- {
+ public void visitLookupSwitchInsn(final Label dflt, final int[] keys,
+ final Label[] labels) {
checkEndCode();
checkStartCode();
checkLabel(dflt, false, "default label");
checkNonDebugLabel(dflt);
if (keys == null || labels == null || keys.length != labels.length) {
- throw new IllegalArgumentException("There must be the same number of keys and labels");
+ throw new IllegalArgumentException(
+ "There must be the same number of keys and labels");
}
for (int i = 0; i < labels.length; ++i) {
checkLabel(labels[i], false, "label at index " + i);
@@ -764,28 +779,26 @@ public class CheckMethodAdapter extends MethodVisitor {
checkEndCode();
checkDesc(desc, false);
if (desc.charAt(0) != '[') {
- throw new IllegalArgumentException("Invalid descriptor (must be an array type descriptor): "
- + desc);
+ throw new IllegalArgumentException(
+ "Invalid descriptor (must be an array type descriptor): "
+ + desc);
}
if (dims < 1) {
- throw new IllegalArgumentException("Invalid dimensions (must be greater than 0): "
- + dims);
+ throw new IllegalArgumentException(
+ "Invalid dimensions (must be greater than 0): " + dims);
}
if (dims > desc.lastIndexOf('[') + 1) {
- throw new IllegalArgumentException("Invalid dimensions (must not be greater than dims(desc)): "
- + dims);
+ throw new IllegalArgumentException(
+ "Invalid dimensions (must not be greater than dims(desc)): "
+ + dims);
}
super.visitMultiANewArrayInsn(desc, dims);
++insnCount;
}
@Override
- public void visitTryCatchBlock(
- final Label start,
- final Label end,
- final Label handler,
- final String type)
- {
+ public void visitTryCatchBlock(final Label start, final Label end,
+ final Label handler, final String type) {
checkStartCode();
checkEndCode();
checkLabel(start, false, "start label");
@@ -795,9 +808,9 @@ public class CheckMethodAdapter extends MethodVisitor {
checkNonDebugLabel(end);
checkNonDebugLabel(handler);
if (labels.get(start) != null || labels.get(end) != null
- || labels.get(handler) != null)
- {
- throw new IllegalStateException("Try catch blocks must be visited before their labels");
+ || labels.get(handler) != null) {
+ throw new IllegalStateException(
+ "Try catch blocks must be visited before their labels");
}
if (type != null) {
checkInternalName(type, "type");
@@ -808,14 +821,9 @@ public class CheckMethodAdapter extends MethodVisitor {
}
@Override
- public void visitLocalVariable(
- final String name,
- final String desc,
- final String signature,
- final Label start,
- final Label end,
- final int index)
- {
+ public void visitLocalVariable(final String name, final String desc,
+ final String signature, final Label start, final Label end,
+ final int index) {
checkStartCode();
checkEndCode();
checkUnqualifiedName(version, name, "name");
@@ -826,7 +834,8 @@ public class CheckMethodAdapter extends MethodVisitor {
int s = labels.get(start).intValue();
int e = labels.get(end).intValue();
if (e < s) {
- throw new IllegalArgumentException("Invalid start and end labels (end must be greater than start)");
+ throw new IllegalArgumentException(
+ "Invalid start and end labels (end must be greater than start)");
}
super.visitLocalVariable(name, desc, signature, start, end, index);
}
@@ -850,14 +859,16 @@ public class CheckMethodAdapter extends MethodVisitor {
throw new IllegalStateException("Undefined label used");
}
}
- for (int i = 0; i < handlers.size(); ) {
+ for (int i = 0; i < handlers.size();) {
Integer start = labels.get(handlers.get(i++));
Integer end = labels.get(handlers.get(i++));
if (start == null || end == null) {
- throw new IllegalStateException("Undefined try catch block labels");
+ throw new IllegalStateException(
+ "Undefined try catch block labels");
}
if (end.intValue() <= start.intValue()) {
- throw new IllegalStateException("Emty try catch block handler range");
+ throw new IllegalStateException(
+ "Emty try catch block handler range");
}
}
checkUnsignedShort(maxStack, "Invalid max stack");
@@ -879,7 +890,8 @@ public class CheckMethodAdapter extends MethodVisitor {
*/
void checkStartCode() {
if (!startCode) {
- throw new IllegalStateException("Cannot visit instructions before visitCode has been called.");
+ throw new IllegalStateException(
+ "Cannot visit instructions before visitCode has been called.");
}
}
@@ -888,7 +900,8 @@ public class CheckMethodAdapter extends MethodVisitor {
*/
void checkEndCode() {
if (endCode) {
- throw new IllegalStateException("Cannot visit instructions after visitMaxs has been called.");
+ throw new IllegalStateException(
+ "Cannot visit instructions after visitMaxs has been called.");
}
}
@@ -897,21 +910,22 @@ public class CheckMethodAdapter extends MethodVisitor {
*/
void checkEndMethod() {
if (endMethod) {
- throw new IllegalStateException("Cannot visit elements after visitEnd has been called.");
+ throw new IllegalStateException(
+ "Cannot visit elements after visitEnd has been called.");
}
}
/**
* Checks a stack frame value.
*
- * @param value the value to be checked.
+ * @param value
+ * the value to be checked.
*/
void checkFrameValue(final Object value) {
if (value == Opcodes.TOP || value == Opcodes.INTEGER
|| value == Opcodes.FLOAT || value == Opcodes.LONG
|| value == Opcodes.DOUBLE || value == Opcodes.NULL
- || value == Opcodes.UNINITIALIZED_THIS)
- {
+ || value == Opcodes.UNINITIALIZED_THIS) {
return;
}
if (value instanceof String) {
@@ -929,8 +943,10 @@ public class CheckMethodAdapter extends MethodVisitor {
/**
* Checks that the type of the given opcode is equal to the given type.
*
- * @param opcode the opcode to be checked.
- * @param type the expected opcode type.
+ * @param opcode
+ * the opcode to be checked.
+ * @param type
+ * the expected opcode type.
*/
static void checkOpcode(final int opcode, final int type) {
if (opcode < 0 || opcode > 199 || TYPE[opcode] != type) {
@@ -941,8 +957,10 @@ public class CheckMethodAdapter extends MethodVisitor {
/**
* Checks that the given value is a signed byte.
*
- * @param value the value to be checked.
- * @param msg an message to be used in case of error.
+ * @param value
+ * the value to be checked.
+ * @param msg
+ * an message to be used in case of error.
*/
static void checkSignedByte(final int value, final String msg) {
if (value < Byte.MIN_VALUE || value > Byte.MAX_VALUE) {
@@ -954,8 +972,10 @@ public class CheckMethodAdapter extends MethodVisitor {
/**
* Checks that the given value is a signed short.
*
- * @param value the value to be checked.
- * @param msg an message to be used in case of error.
+ * @param value
+ * the value to be checked.
+ * @param msg
+ * an message to be used in case of error.
*/
static void checkSignedShort(final int value, final String msg) {
if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) {
@@ -967,8 +987,10 @@ public class CheckMethodAdapter extends MethodVisitor {
/**
* Checks that the given value is an unsigned short.
*
- * @param value the value to be checked.
- * @param msg an message to be used in case of error.
+ * @param value
+ * the value to be checked.
+ * @param msg
+ * an message to be used in case of error.
*/
static void checkUnsignedShort(final int value, final String msg) {
if (value < 0 || value > 65535) {
@@ -981,13 +1003,13 @@ public class CheckMethodAdapter extends MethodVisitor {
* Checks that the given value is an {@link Integer}, a{@link Float}, a
* {@link Long}, a {@link Double} or a {@link String}.
*
- * @param cst the value to be checked.
+ * @param cst
+ * the value to be checked.
*/
static void checkConstant(final Object cst) {
if (!(cst instanceof Integer) && !(cst instanceof Float)
&& !(cst instanceof Long) && !(cst instanceof Double)
- && !(cst instanceof String))
- {
+ && !(cst instanceof String)) {
throw new IllegalArgumentException("Invalid constant: " + cst);
}
}
@@ -999,19 +1021,21 @@ public class CheckMethodAdapter extends MethodVisitor {
throw new IllegalArgumentException("Illegal LDC constant value");
}
if (s != Type.METHOD && (version & 0xFFFF) < Opcodes.V1_5) {
- throw new IllegalArgumentException("ldc of a constant class requires at least version 1.5");
+ throw new IllegalArgumentException(
+ "ldc of a constant class requires at least version 1.5");
}
if (s == Type.METHOD && (version & 0xFFFF) < Opcodes.V1_7) {
- throw new IllegalArgumentException("ldc of a method type requires at least version 1.7");
+ throw new IllegalArgumentException(
+ "ldc of a method type requires at least version 1.7");
}
} else if (cst instanceof Handle) {
if ((version & 0xFFFF) < Opcodes.V1_7) {
- throw new IllegalArgumentException("ldc of a handle requires at least version 1.7");
+ throw new IllegalArgumentException(
+ "ldc of a handle requires at least version 1.7");
}
int tag = ((Handle) cst).getTag();
if (tag < Opcodes.H_GETFIELD || tag > Opcodes.H_INVOKEINTERFACE) {
- throw new IllegalArgumentException("invalid handle tag "
- + tag);
+ throw new IllegalArgumentException("invalid handle tag " + tag);
}
} else {
checkConstant(cst);
@@ -1021,15 +1045,15 @@ public class CheckMethodAdapter extends MethodVisitor {
/**
* Checks that the given string is a valid unqualified name.
*
- * @param version the class version.
- * @param name the string to be checked.
- * @param msg a message to be used in case of error.
+ * @param version
+ * the class version.
+ * @param name
+ * the string to be checked.
+ * @param msg
+ * a message to be used in case of error.
*/
- static void checkUnqualifiedName(
- int version,
- final String name,
- final String msg)
- {
+ static void checkUnqualifiedName(int version, final String name,
+ final String msg) {
if ((version & 0xFFFF) < Opcodes.V1_5) {
checkIdentifier(name, msg);
} else {
@@ -1045,8 +1069,10 @@ public class CheckMethodAdapter extends MethodVisitor {
/**
* Checks that the given string is a valid Java identifier.
*
- * @param name the string to be checked.
- * @param msg a message to be used in case of error.
+ * @param name
+ * the string to be checked.
+ * @param msg
+ * a message to be used in case of error.
*/
static void checkIdentifier(final String name, final String msg) {
checkIdentifier(name, 0, -1, msg);
@@ -1055,21 +1081,20 @@ public class CheckMethodAdapter extends MethodVisitor {
/**
* Checks that the given substring is a valid Java identifier.
*
- * @param name the string to be checked.
- * @param start index of the first character of the identifier (inclusive).
- * @param end index of the last character of the identifier (exclusive). -1
- * is equivalent to <tt>name.length()</tt> if name is not
- * <tt>null</tt>.
- * @param msg a message to be used in case of error.
+ * @param name
+ * the string to be checked.
+ * @param start
+ * index of the first character of the identifier (inclusive).
+ * @param end
+ * index of the last character of the identifier (exclusive). -1
+ * is equivalent to <tt>name.length()</tt> if name is not
+ * <tt>null</tt>.
+ * @param msg
+ * a message to be used in case of error.
*/
- static void checkIdentifier(
- final String name,
- final int start,
- final int end,
- final String msg)
- {
- if (name == null || (end == -1 ? name.length() <= start : end <= start))
- {
+ static void checkIdentifier(final String name, final int start,
+ final int end, final String msg) {
+ if (name == null || (end == -1 ? name.length() <= start : end <= start)) {
throw new IllegalArgumentException("Invalid " + msg
+ " (must not be null or empty)");
}
@@ -1087,25 +1112,21 @@ public class CheckMethodAdapter extends MethodVisitor {
}
/**
- * Checks that the given string is a valid Java identifier or is equal to
- * '&lt;init&gt;' or '&lt;clinit&gt;'.
+ * Checks that the given string is a valid Java identifier.
*
- * @param version the class version.
- * @param name the string to be checked.
- * @param msg a message to be used in case of error.
+ * @param version
+ * the class version.
+ * @param name
+ * the string to be checked.
+ * @param msg
+ * a message to be used in case of error.
*/
- static void checkMethodIdentifier(
- int version,
- final String name,
- final String msg)
- {
+ static void checkMethodIdentifier(int version, final String name,
+ final String msg) {
if (name == null || name.length() == 0) {
throw new IllegalArgumentException("Invalid " + msg
+ " (must not be null or empty)");
}
- if ("<init>".equals(name) || "<clinit>".equals(name)) {
- return;
- }
if ((version & 0xFFFF) >= Opcodes.V1_5) {
for (int i = 0; i < name.length(); ++i) {
if (".;[/<>".indexOf(name.charAt(i)) != -1) {
@@ -1116,17 +1137,19 @@ public class CheckMethodAdapter extends MethodVisitor {
return;
}
if (!Character.isJavaIdentifierStart(name.charAt(0))) {
- throw new IllegalArgumentException("Invalid "
- + msg
- + " (must be a '<init>', '<clinit>' or a valid Java identifier): "
- + name);
+ throw new IllegalArgumentException(
+ "Invalid "
+ + msg
+ + " (must be a '<init>', '<clinit>' or a valid Java identifier): "
+ + name);
}
for (int i = 1; i < name.length(); ++i) {
if (!Character.isJavaIdentifierPart(name.charAt(i))) {
- throw new IllegalArgumentException("Invalid "
- + msg
- + " (must be '<init>' or '<clinit>' or a valid Java identifier): "
- + name);
+ throw new IllegalArgumentException(
+ "Invalid "
+ + msg
+ + " (must be '<init>' or '<clinit>' or a valid Java identifier): "
+ + name);
}
}
}
@@ -1134,8 +1157,10 @@ public class CheckMethodAdapter extends MethodVisitor {
/**
* Checks that the given string is a valid internal class name.
*
- * @param name the string to be checked.
- * @param msg a message to be used in case of error.
+ * @param name
+ * the string to be checked.
+ * @param msg
+ * a message to be used in case of error.
*/
static void checkInternalName(final String name, final String msg) {
if (name == null || name.length() == 0) {
@@ -1152,19 +1177,19 @@ public class CheckMethodAdapter extends MethodVisitor {
/**
* Checks that the given substring is a valid internal class name.
*
- * @param name the string to be checked.
- * @param start index of the first character of the identifier (inclusive).
- * @param end index of the last character of the identifier (exclusive). -1
- * is equivalent to <tt>name.length()</tt> if name is not
- * <tt>null</tt>.
- * @param msg a message to be used in case of error.
+ * @param name
+ * the string to be checked.
+ * @param start
+ * index of the first character of the identifier (inclusive).
+ * @param end
+ * index of the last character of the identifier (exclusive). -1
+ * is equivalent to <tt>name.length()</tt> if name is not
+ * <tt>null</tt>.
+ * @param msg
+ * a message to be used in case of error.
*/
- static void checkInternalName(
- final String name,
- final int start,
- final int end,
- final String msg)
- {
+ static void checkInternalName(final String name, final int start,
+ final int end, final String msg) {
int max = end == -1 ? name.length() : end;
try {
int begin = start;
@@ -1178,18 +1203,21 @@ public class CheckMethodAdapter extends MethodVisitor {
begin = slash + 1;
} while (slash != max);
} catch (IllegalArgumentException _) {
- throw new IllegalArgumentException("Invalid "
- + msg
- + " (must be a fully qualified class name in internal form): "
- + name);
+ throw new IllegalArgumentException(
+ "Invalid "
+ + msg
+ + " (must be a fully qualified class name in internal form): "
+ + name);
}
}
/**
* Checks that the given string is a valid type descriptor.
*
- * @param desc the string to be checked.
- * @param canBeVoid <tt>true</tt> if <tt>V</tt> can be considered valid.
+ * @param desc
+ * the string to be checked.
+ * @param canBeVoid
+ * <tt>true</tt> if <tt>V</tt> can be considered valid.
*/
static void checkDesc(final String desc, final boolean canBeVoid) {
int end = checkDesc(desc, 0, canBeVoid);
@@ -1201,75 +1229,77 @@ public class CheckMethodAdapter extends MethodVisitor {
/**
* Checks that a the given substring is a valid type descriptor.
*
- * @param desc the string to be checked.
- * @param start index of the first character of the identifier (inclusive).
- * @param canBeVoid <tt>true</tt> if <tt>V</tt> can be considered valid.
+ * @param desc
+ * the string to be checked.
+ * @param start
+ * index of the first character of the identifier (inclusive).
+ * @param canBeVoid
+ * <tt>true</tt> if <tt>V</tt> can be considered valid.
* @return the index of the last character of the type decriptor, plus one.
*/
- static int checkDesc(
- final String desc,
- final int start,
- final boolean canBeVoid)
- {
+ static int checkDesc(final String desc, final int start,
+ final boolean canBeVoid) {
if (desc == null || start >= desc.length()) {
- throw new IllegalArgumentException("Invalid type descriptor (must not be null or empty)");
+ throw new IllegalArgumentException(
+ "Invalid type descriptor (must not be null or empty)");
}
int index;
switch (desc.charAt(start)) {
- case 'V':
- if (canBeVoid) {
- return start + 1;
- } else {
- throw new IllegalArgumentException("Invalid descriptor: "
- + desc);
- }
- case 'Z':
- case 'C':
- case 'B':
- case 'S':
- case 'I':
- case 'F':
- case 'J':
- case 'D':
+ case 'V':
+ if (canBeVoid) {
return start + 1;
- case '[':
- index = start + 1;
- while (index < desc.length() && desc.charAt(index) == '[') {
- ++index;
- }
- if (index < desc.length()) {
- return checkDesc(desc, index, false);
- } else {
- throw new IllegalArgumentException("Invalid descriptor: "
- + desc);
- }
- case 'L':
- index = desc.indexOf(';', start);
- if (index == -1 || index - start < 2) {
- throw new IllegalArgumentException("Invalid descriptor: "
- + desc);
- }
- try {
- checkInternalName(desc, start + 1, index, null);
- } catch (IllegalArgumentException _) {
- throw new IllegalArgumentException("Invalid descriptor: "
- + desc);
- }
- return index + 1;
- default:
+ } else {
+ throw new IllegalArgumentException("Invalid descriptor: "
+ + desc);
+ }
+ case 'Z':
+ case 'C':
+ case 'B':
+ case 'S':
+ case 'I':
+ case 'F':
+ case 'J':
+ case 'D':
+ return start + 1;
+ case '[':
+ index = start + 1;
+ while (index < desc.length() && desc.charAt(index) == '[') {
+ ++index;
+ }
+ if (index < desc.length()) {
+ return checkDesc(desc, index, false);
+ } else {
throw new IllegalArgumentException("Invalid descriptor: "
+ desc);
+ }
+ case 'L':
+ index = desc.indexOf(';', start);
+ if (index == -1 || index - start < 2) {
+ throw new IllegalArgumentException("Invalid descriptor: "
+ + desc);
+ }
+ try {
+ checkInternalName(desc, start + 1, index, null);
+ } catch (IllegalArgumentException _) {
+ throw new IllegalArgumentException("Invalid descriptor: "
+ + desc);
+ }
+ return index + 1;
+ default:
+ throw new IllegalArgumentException("Invalid descriptor: " + desc);
}
}
/**
* Checks that the given string is a valid method descriptor.
*
- * @param desc the string to be checked.
+ * @param desc
+ * the string to be checked.
*/
static void checkMethodDesc(final String desc) {
if (desc == null || desc.length() == 0) {
- throw new IllegalArgumentException("Invalid method descriptor (must not be null or empty)");
+ throw new IllegalArgumentException(
+ "Invalid method descriptor (must not be null or empty)");
}
if (desc.charAt(0) != '(' || desc.length() < 3) {
throw new IllegalArgumentException("Invalid descriptor: " + desc);
@@ -1291,322 +1321,18 @@ public class CheckMethodAdapter extends MethodVisitor {
}
/**
- * Checks a class signature.
- *
- * @param signature a string containing the signature that must be checked.
- */
- static void checkClassSignature(final String signature) {
- // ClassSignature:
- // FormalTypeParameters? ClassTypeSignature ClassTypeSignature*
-
- int pos = 0;
- if (getChar(signature, 0) == '<') {
- pos = checkFormalTypeParameters(signature, pos);
- }
- pos = checkClassTypeSignature(signature, pos);
- while (getChar(signature, pos) == 'L') {
- pos = checkClassTypeSignature(signature, pos);
- }
- if (pos != signature.length()) {
- throw new IllegalArgumentException(signature + ": error at index "
- + pos);
- }
- }
-
- /**
- * Checks a method signature.
- *
- * @param signature a string containing the signature that must be checked.
- */
- static void checkMethodSignature(final String signature) {
- // MethodTypeSignature:
- // FormalTypeParameters? ( TypeSignature* ) ( TypeSignature | V ) (
- // ^ClassTypeSignature | ^TypeVariableSignature )*
-
- int pos = 0;
- if (getChar(signature, 0) == '<') {
- pos = checkFormalTypeParameters(signature, pos);
- }
- pos = checkChar('(', signature, pos);
- while ("ZCBSIFJDL[T".indexOf(getChar(signature, pos)) != -1) {
- pos = checkTypeSignature(signature, pos);
- }
- pos = checkChar(')', signature, pos);
- if (getChar(signature, pos) == 'V') {
- ++pos;
- } else {
- pos = checkTypeSignature(signature, pos);
- }
- while (getChar(signature, pos) == '^') {
- ++pos;
- if (getChar(signature, pos) == 'L') {
- pos = checkClassTypeSignature(signature, pos);
- } else {
- pos = checkTypeVariableSignature(signature, pos);
- }
- }
- if (pos != signature.length()) {
- throw new IllegalArgumentException(signature + ": error at index "
- + pos);
- }
- }
-
- /**
- * Checks a field signature.
- *
- * @param signature a string containing the signature that must be checked.
- */
- static void checkFieldSignature(final String signature) {
- int pos = checkFieldTypeSignature(signature, 0);
- if (pos != signature.length()) {
- throw new IllegalArgumentException(signature + ": error at index "
- + pos);
- }
- }
-
- /**
- * Checks the formal type parameters of a class or method signature.
- *
- * @param signature a string containing the signature that must be checked.
- * @param pos index of first character to be checked.
- * @return the index of the first character after the checked part.
- */
- private static int checkFormalTypeParameters(final String signature, int pos)
- {
- // FormalTypeParameters:
- // < FormalTypeParameter+ >
-
- pos = checkChar('<', signature, pos);
- pos = checkFormalTypeParameter(signature, pos);
- while (getChar(signature, pos) != '>') {
- pos = checkFormalTypeParameter(signature, pos);
- }
- return pos + 1;
- }
-
- /**
- * Checks a formal type parameter of a class or method signature.
- *
- * @param signature a string containing the signature that must be checked.
- * @param pos index of first character to be checked.
- * @return the index of the first character after the checked part.
- */
- private static int checkFormalTypeParameter(final String signature, int pos)
- {
- // FormalTypeParameter:
- // Identifier : FieldTypeSignature? (: FieldTypeSignature)*
-
- pos = checkIdentifier(signature, pos);
- pos = checkChar(':', signature, pos);
- if ("L[T".indexOf(getChar(signature, pos)) != -1) {
- pos = checkFieldTypeSignature(signature, pos);
- }
- while (getChar(signature, pos) == ':') {
- pos = checkFieldTypeSignature(signature, pos + 1);
- }
- return pos;
- }
-
- /**
- * Checks a field type signature.
- *
- * @param signature a string containing the signature that must be checked.
- * @param pos index of first character to be checked.
- * @return the index of the first character after the checked part.
- */
- private static int checkFieldTypeSignature(final String signature, int pos)
- {
- // FieldTypeSignature:
- // ClassTypeSignature | ArrayTypeSignature | TypeVariableSignature
- //
- // ArrayTypeSignature:
- // [ TypeSignature
-
- switch (getChar(signature, pos)) {
- case 'L':
- return checkClassTypeSignature(signature, pos);
- case '[':
- return checkTypeSignature(signature, pos + 1);
- default:
- return checkTypeVariableSignature(signature, pos);
- }
- }
-
- /**
- * Checks a class type signature.
- *
- * @param signature a string containing the signature that must be checked.
- * @param pos index of first character to be checked.
- * @return the index of the first character after the checked part.
- */
- private static int checkClassTypeSignature(final String signature, int pos)
- {
- // ClassTypeSignature:
- // L Identifier ( / Identifier )* TypeArguments? ( . Identifier
- // TypeArguments? )* ;
-
- pos = checkChar('L', signature, pos);
- pos = checkIdentifier(signature, pos);
- while (getChar(signature, pos) == '/') {
- pos = checkIdentifier(signature, pos + 1);
- }
- if (getChar(signature, pos) == '<') {
- pos = checkTypeArguments(signature, pos);
- }
- while (getChar(signature, pos) == '.') {
- pos = checkIdentifier(signature, pos + 1);
- if (getChar(signature, pos) == '<') {
- pos = checkTypeArguments(signature, pos);
- }
- }
- return checkChar(';', signature, pos);
- }
-
- /**
- * Checks the type arguments in a class type signature.
- *
- * @param signature a string containing the signature that must be checked.
- * @param pos index of first character to be checked.
- * @return the index of the first character after the checked part.
- */
- private static int checkTypeArguments(final String signature, int pos) {
- // TypeArguments:
- // < TypeArgument+ >
-
- pos = checkChar('<', signature, pos);
- pos = checkTypeArgument(signature, pos);
- while (getChar(signature, pos) != '>') {
- pos = checkTypeArgument(signature, pos);
- }
- return pos + 1;
- }
-
- /**
- * Checks a type argument in a class type signature.
- *
- * @param signature a string containing the signature that must be checked.
- * @param pos index of first character to be checked.
- * @return the index of the first character after the checked part.
- */
- private static int checkTypeArgument(final String signature, int pos) {
- // TypeArgument:
- // * | ( ( + | - )? FieldTypeSignature )
-
- char c = getChar(signature, pos);
- if (c == '*') {
- return pos + 1;
- } else if (c == '+' || c == '-') {
- pos++;
- }
- return checkFieldTypeSignature(signature, pos);
- }
-
- /**
- * Checks a type variable signature.
- *
- * @param signature a string containing the signature that must be checked.
- * @param pos index of first character to be checked.
- * @return the index of the first character after the checked part.
- */
- private static int checkTypeVariableSignature(
- final String signature,
- int pos)
- {
- // TypeVariableSignature:
- // T Identifier ;
-
- pos = checkChar('T', signature, pos);
- pos = checkIdentifier(signature, pos);
- return checkChar(';', signature, pos);
- }
-
- /**
- * Checks a type signature.
- *
- * @param signature a string containing the signature that must be checked.
- * @param pos index of first character to be checked.
- * @return the index of the first character after the checked part.
- */
- private static int checkTypeSignature(final String signature, int pos) {
- // TypeSignature:
- // Z | C | B | S | I | F | J | D | FieldTypeSignature
-
- switch (getChar(signature, pos)) {
- case 'Z':
- case 'C':
- case 'B':
- case 'S':
- case 'I':
- case 'F':
- case 'J':
- case 'D':
- return pos + 1;
- default:
- return checkFieldTypeSignature(signature, pos);
- }
- }
-
- /**
- * Checks an identifier.
- *
- * @param signature a string containing the signature that must be checked.
- * @param pos index of first character to be checked.
- * @return the index of the first character after the checked part.
- */
- private static int checkIdentifier(final String signature, int pos) {
- if (!Character.isJavaIdentifierStart(getChar(signature, pos))) {
- throw new IllegalArgumentException(signature
- + ": identifier expected at index " + pos);
- }
- ++pos;
- while (Character.isJavaIdentifierPart(getChar(signature, pos))) {
- ++pos;
- }
- return pos;
- }
-
- /**
- * Checks a single character.
- *
- * @param signature a string containing the signature that must be checked.
- * @param pos index of first character to be checked.
- * @return the index of the first character after the checked part.
- */
- private static int checkChar(final char c, final String signature, int pos)
- {
- if (getChar(signature, pos) == c) {
- return pos + 1;
- }
- throw new IllegalArgumentException(signature + ": '" + c
- + "' expected at index " + pos);
- }
-
- /**
- * Returns the signature car at the given index.
- *
- * @param signature a signature.
- * @param pos an index in signature.
- * @return the character at the given index, or 0 if there is no such
- * character.
- */
- private static char getChar(final String signature, int pos) {
- return pos < signature.length() ? signature.charAt(pos) : (char) 0;
- }
-
- /**
* Checks that the given label is not null. This method can also check that
* the label has been visited.
*
- * @param label the label to be checked.
- * @param checkVisited <tt>true</tt> to check that the label has been
- * visited.
- * @param msg a message to be used in case of error.
+ * @param label
+ * the label to be checked.
+ * @param checkVisited
+ * <tt>true</tt> to check that the label has been visited.
+ * @param msg
+ * a message to be used in case of error.
*/
- void checkLabel(
- final Label label,
- final boolean checkVisited,
- final String msg)
- {
+ void checkLabel(final Label label, final boolean checkVisited,
+ final String msg) {
if (label == null) {
throw new IllegalArgumentException("Invalid " + msg
+ " (must not be null)");
@@ -1620,7 +1346,8 @@ public class CheckMethodAdapter extends MethodVisitor {
/**
* Checks that the given label is not a label used only for debug purposes.
*
- * @param label the label to be checked.
+ * @param label
+ * the label to be checked.
*/
private static void checkNonDebugLabel(final Label label) {
Field f = getLabelStatusField();
@@ -1631,7 +1358,8 @@ public class CheckMethodAdapter extends MethodVisitor {
throw new Error("Internal error");
}
if ((status & 0x01) != 0) {
- throw new IllegalArgumentException("Labels used for debug info cannot be reused for control flow");
+ throw new IllegalArgumentException(
+ "Labels used for debug info cannot be reused for control flow");
}
}
@@ -1653,7 +1381,8 @@ public class CheckMethodAdapter extends MethodVisitor {
/**
* Returns the field of the Label class whose name is given.
*
- * @param name a field name.
+ * @param name
+ * a field name.
* @return the field of the Label class whose name is given, or null.
*/
private static Field getLabelField(final String name) {
diff --git a/src/asm/scala/tools/asm/util/CheckSignatureAdapter.java b/src/asm/scala/tools/asm/util/CheckSignatureAdapter.java
index 3a6c3e780f..e69302b8a6 100644
--- a/src/asm/scala/tools/asm/util/CheckSignatureAdapter.java
+++ b/src/asm/scala/tools/asm/util/CheckSignatureAdapter.java
@@ -41,19 +41,22 @@ public class CheckSignatureAdapter extends SignatureVisitor {
/**
* Type to be used to check class signatures. See
- * {@link #CheckSignatureAdapter(int, SignatureVisitor) CheckSignatureAdapter}.
+ * {@link #CheckSignatureAdapter(int, SignatureVisitor)
+ * CheckSignatureAdapter}.
*/
public static final int CLASS_SIGNATURE = 0;
/**
* Type to be used to check method signatures. See
- * {@link #CheckSignatureAdapter(int, SignatureVisitor) CheckSignatureAdapter}.
+ * {@link #CheckSignatureAdapter(int, SignatureVisitor)
+ * CheckSignatureAdapter}.
*/
public static final int METHOD_SIGNATURE = 1;
/**
* Type to be used to check type signatures.See
- * {@link #CheckSignatureAdapter(int, SignatureVisitor) CheckSignatureAdapter}.
+ * {@link #CheckSignatureAdapter(int, SignatureVisitor)
+ * CheckSignatureAdapter}.
*/
public static final int TYPE_SIGNATURE = 2;
@@ -101,11 +104,13 @@ public class CheckSignatureAdapter extends SignatureVisitor {
* not use this constructor</i>. Instead, they must use the
* {@link #CheckSignatureAdapter(int, int, SignatureVisitor)} version.
*
- * @param type the type of signature to be checked. See
- * {@link #CLASS_SIGNATURE}, {@link #METHOD_SIGNATURE} and
- * {@link #TYPE_SIGNATURE}.
- * @param sv the visitor to which this adapter must delegate calls. May be
- * <tt>null</tt>.
+ * @param type
+ * the type of signature to be checked. See
+ * {@link #CLASS_SIGNATURE}, {@link #METHOD_SIGNATURE} and
+ * {@link #TYPE_SIGNATURE}.
+ * @param sv
+ * the visitor to which this adapter must delegate calls. May be
+ * <tt>null</tt>.
*/
public CheckSignatureAdapter(final int type, final SignatureVisitor sv) {
this(Opcodes.ASM4, type, sv);
@@ -114,19 +119,19 @@ public class CheckSignatureAdapter extends SignatureVisitor {
/**
* Creates a new {@link CheckSignatureAdapter} object.
*
- * @param api the ASM API version implemented by this visitor. Must be one
- * of {@link Opcodes#ASM4}.
- * @param type the type of signature to be checked. See
- * {@link #CLASS_SIGNATURE}, {@link #METHOD_SIGNATURE} and
- * {@link #TYPE_SIGNATURE}.
- * @param sv the visitor to which this adapter must delegate calls. May be
- * <tt>null</tt>.
+ * @param api
+ * the ASM API version implemented by this visitor. Must be one
+ * of {@link Opcodes#ASM4}.
+ * @param type
+ * the type of signature to be checked. See
+ * {@link #CLASS_SIGNATURE}, {@link #METHOD_SIGNATURE} and
+ * {@link #TYPE_SIGNATURE}.
+ * @param sv
+ * the visitor to which this adapter must delegate calls. May be
+ * <tt>null</tt>.
*/
- protected CheckSignatureAdapter(
- final int api,
- final int type,
- final SignatureVisitor sv)
- {
+ protected CheckSignatureAdapter(final int api, final int type,
+ final SignatureVisitor sv) {
super(api);
this.type = type;
this.state = EMPTY;
@@ -138,8 +143,7 @@ public class CheckSignatureAdapter extends SignatureVisitor {
@Override
public void visitFormalTypeParameter(final String name) {
if (type == TYPE_SIGNATURE
- || (state != EMPTY && state != FORMAL && state != BOUND))
- {
+ || (state != EMPTY && state != FORMAL && state != BOUND)) {
throw new IllegalStateException();
}
CheckMethodAdapter.checkIdentifier(name, "formal type parameter");
@@ -172,8 +176,7 @@ public class CheckSignatureAdapter extends SignatureVisitor {
@Override
public SignatureVisitor visitSuperclass() {
- if (type != CLASS_SIGNATURE || (state & (EMPTY | FORMAL | BOUND)) == 0)
- {
+ if (type != CLASS_SIGNATURE || (state & (EMPTY | FORMAL | BOUND)) == 0) {
throw new IllegalArgumentException();
}
state = SUPER;
@@ -195,8 +198,7 @@ public class CheckSignatureAdapter extends SignatureVisitor {
@Override
public SignatureVisitor visitParameterType() {
if (type != METHOD_SIGNATURE
- || (state & (EMPTY | FORMAL | BOUND | PARAM)) == 0)
- {
+ || (state & (EMPTY | FORMAL | BOUND | PARAM)) == 0) {
throw new IllegalArgumentException();
}
state = PARAM;
@@ -207,8 +209,7 @@ public class CheckSignatureAdapter extends SignatureVisitor {
@Override
public SignatureVisitor visitReturnType() {
if (type != METHOD_SIGNATURE
- || (state & (EMPTY | FORMAL | BOUND | PARAM)) == 0)
- {
+ || (state & (EMPTY | FORMAL | BOUND | PARAM)) == 0) {
throw new IllegalArgumentException();
}
state = RETURN;
diff --git a/src/asm/scala/tools/asm/util/Printer.java b/src/asm/scala/tools/asm/util/Printer.java
index c39fd548ce..86e0f9e122 100644
--- a/src/asm/scala/tools/asm/util/Printer.java
+++ b/src/asm/scala/tools/asm/util/Printer.java
@@ -52,14 +52,14 @@ public abstract class Printer {
/**
* The names of the for <code>operand</code> parameter values of the
- * {@link org.objectweb.asm.MethodVisitor#visitIntInsn} method when
+ * {@link scala.tools.asm.MethodVisitor#visitIntInsn} method when
* <code>opcode</code> is <code>NEWARRAY</code>.
*/
public static final String[] TYPES;
/**
* The names of the <code>tag</code> field values for
- * {@link org.objectweb.asm.Handle}.
+ * {@link scala.tools.asm.Handle}.
*/
public static final String[] HANDLE_TAG;
@@ -103,8 +103,8 @@ public abstract class Printer {
}
s = "H_GETFIELD,H_GETSTATIC,H_PUTFIELD,H_PUTSTATIC,"
- + "H_INVOKEVIRTUAL,H_INVOKESTATIC,H_INVOKESPECIAL,"
- + "H_NEWINVOKESPECIAL,H_INVOKEINTERFACE,";
+ + "H_INVOKEVIRTUAL,H_INVOKESTATIC,H_INVOKESPECIAL,"
+ + "H_NEWINVOKESPECIAL,H_INVOKEINTERFACE,";
HANDLE_TAG = new String[10];
j = 0;
i = 1;
@@ -149,81 +149,58 @@ public abstract class Printer {
}
/**
- * Class header.
- * See {@link org.objectweb.asm.ClassVisitor#visit}.
+ * Class header. See {@link scala.tools.asm.ClassVisitor#visit}.
*/
- public abstract void visit(
- final int version,
- final int access,
- final String name,
- final String signature,
- final String superName,
- final String[] interfaces);
+ public abstract void visit(final int version, final int access,
+ final String name, final String signature, final String superName,
+ final String[] interfaces);
/**
- * Class source.
- * See {@link org.objectweb.asm.ClassVisitor#visitSource}.
+ * Class source. See {@link scala.tools.asm.ClassVisitor#visitSource}.
*/
public abstract void visitSource(final String file, final String debug);
/**
- * Class outer class.
- * See {@link org.objectweb.asm.ClassVisitor#visitOuterClass}.
+ * Class outer class. See
+ * {@link scala.tools.asm.ClassVisitor#visitOuterClass}.
*/
- public abstract void visitOuterClass(
- final String owner,
- final String name,
- final String desc);
+ public abstract void visitOuterClass(final String owner, final String name,
+ final String desc);
/**
- * Class annotation.
- * See {@link org.objectweb.asm.ClassVisitor#visitAnnotation}.
+ * Class annotation. See
+ * {@link scala.tools.asm.ClassVisitor#visitAnnotation}.
*/
- public abstract Printer visitClassAnnotation(
- final String desc,
- final boolean visible);
+ public abstract Printer visitClassAnnotation(final String desc,
+ final boolean visible);
/**
- * Class attribute.
- * See {@link org.objectweb.asm.ClassVisitor#visitAttribute}.
+ * Class attribute. See
+ * {@link scala.tools.asm.ClassVisitor#visitAttribute}.
*/
public abstract void visitClassAttribute(final Attribute attr);
/**
- * Class inner name.
- * See {@link org.objectweb.asm.ClassVisitor#visitInnerClass}.
+ * Class inner name. See
+ * {@link scala.tools.asm.ClassVisitor#visitInnerClass}.
*/
- public abstract void visitInnerClass(
- final String name,
- final String outerName,
- final String innerName,
- final int access);
+ public abstract void visitInnerClass(final String name,
+ final String outerName, final String innerName, final int access);
/**
- * Class field.
- * See {@link org.objectweb.asm.ClassVisitor#visitField}.
+ * Class field. See {@link scala.tools.asm.ClassVisitor#visitField}.
*/
- public abstract Printer visitField(
- final int access,
- final String name,
- final String desc,
- final String signature,
- final Object value);
+ public abstract Printer visitField(final int access, final String name,
+ final String desc, final String signature, final Object value);
/**
- * Class method.
- * See {@link org.objectweb.asm.ClassVisitor#visitMethod}.
+ * Class method. See {@link scala.tools.asm.ClassVisitor#visitMethod}.
*/
- public abstract Printer visitMethod(
- final int access,
- final String name,
- final String desc,
- final String signature,
- final String[] exceptions);
+ public abstract Printer visitMethod(final int access, final String name,
+ final String desc, final String signature, final String[] exceptions);
/**
- * Class end.
- * See {@link org.objectweb.asm.ClassVisitor#visitEnd}.
+ * Class end. See {@link scala.tools.asm.ClassVisitor#visitEnd}.
*/
public abstract void visitClassEnd();
@@ -232,37 +209,31 @@ public abstract class Printer {
// ------------------------------------------------------------------------
/**
- * Annotation value.
- * See {@link org.objectweb.asm.AnnotationVisitor#visit}.
+ * Annotation value. See {@link scala.tools.asm.AnnotationVisitor#visit}.
*/
public abstract void visit(final String name, final Object value);
/**
- * Annotation enum value.
- * See {@link org.objectweb.asm.AnnotationVisitor#visitEnum}.
+ * Annotation enum value. See
+ * {@link scala.tools.asm.AnnotationVisitor#visitEnum}.
*/
- public abstract void visitEnum(
- final String name,
- final String desc,
- final String value);
+ public abstract void visitEnum(final String name, final String desc,
+ final String value);
/**
- * Nested annotation value.
- * See {@link org.objectweb.asm.AnnotationVisitor#visitAnnotation}.
+ * Nested annotation value. See
+ * {@link scala.tools.asm.AnnotationVisitor#visitAnnotation}.
*/
- public abstract Printer visitAnnotation(
- final String name,
- final String desc);
+ public abstract Printer visitAnnotation(final String name, final String desc);
/**
- * Annotation array value.
- * See {@link org.objectweb.asm.AnnotationVisitor#visitArray}.
+ * Annotation array value. See
+ * {@link scala.tools.asm.AnnotationVisitor#visitArray}.
*/
public abstract Printer visitArray(final String name);
/**
- * Annotation end.
- * See {@link org.objectweb.asm.AnnotationVisitor#visitEnd}.
+ * Annotation end. See {@link scala.tools.asm.AnnotationVisitor#visitEnd}.
*/
public abstract void visitAnnotationEnd();
@@ -271,22 +242,20 @@ public abstract class Printer {
// ------------------------------------------------------------------------
/**
- * Field annotation.
- * See {@link org.objectweb.asm.FieldVisitor#visitAnnotation}.
+ * Field annotation. See
+ * {@link scala.tools.asm.FieldVisitor#visitAnnotation}.
*/
- public abstract Printer visitFieldAnnotation(
- final String desc,
- final boolean visible);
+ public abstract Printer visitFieldAnnotation(final String desc,
+ final boolean visible);
/**
- * Field attribute.
- * See {@link org.objectweb.asm.FieldVisitor#visitAttribute}.
+ * Field attribute. See
+ * {@link scala.tools.asm.FieldVisitor#visitAttribute}.
*/
public abstract void visitFieldAttribute(final Attribute attr);
/**
- * Field end.
- * See {@link org.objectweb.asm.FieldVisitor#visitEnd}.
+ * Field end. See {@link scala.tools.asm.FieldVisitor#visitEnd}.
*/
public abstract void visitFieldEnd();
@@ -295,193 +264,161 @@ public abstract class Printer {
// ------------------------------------------------------------------------
/**
- * Method default annotation.
- * See {@link org.objectweb.asm.MethodVisitor#visitAnnotationDefault}.
+ * Method default annotation. See
+ * {@link scala.tools.asm.MethodVisitor#visitAnnotationDefault}.
*/
public abstract Printer visitAnnotationDefault();
/**
- * Method annotation.
- * See {@link org.objectweb.asm.MethodVisitor#visitAnnotation}.
+ * Method annotation. See
+ * {@link scala.tools.asm.MethodVisitor#visitAnnotation}.
*/
- public abstract Printer visitMethodAnnotation(
- final String desc,
- final boolean visible);
+ public abstract Printer visitMethodAnnotation(final String desc,
+ final boolean visible);
/**
- * Method parameter annotation.
- * See {@link org.objectweb.asm.MethodVisitor#visitParameterAnnotation}.
+ * Method parameter annotation. See
+ * {@link scala.tools.asm.MethodVisitor#visitParameterAnnotation}.
*/
- public abstract Printer visitParameterAnnotation(
- final int parameter,
- final String desc,
- final boolean visible);
+ public abstract Printer visitParameterAnnotation(final int parameter,
+ final String desc, final boolean visible);
/**
- * Method attribute.
- * See {@link org.objectweb.asm.MethodVisitor#visitAttribute}.
+ * Method attribute. See
+ * {@link scala.tools.asm.MethodVisitor#visitAttribute}.
*/
public abstract void visitMethodAttribute(final Attribute attr);
/**
- * Method start.
- * See {@link org.objectweb.asm.MethodVisitor#visitCode}.
+ * Method start. See {@link scala.tools.asm.MethodVisitor#visitCode}.
*/
public abstract void visitCode();
/**
- * Method stack frame.
- * See {@link org.objectweb.asm.MethodVisitor#visitFrame}.
+ * Method stack frame. See
+ * {@link scala.tools.asm.MethodVisitor#visitFrame}.
*/
- public abstract void visitFrame(
- final int type,
- final int nLocal,
- final Object[] local,
- final int nStack,
- final Object[] stack);
+ public abstract void visitFrame(final int type, final int nLocal,
+ final Object[] local, final int nStack, final Object[] stack);
/**
- * Method instruction.
- * See {@link org.objectweb.asm.MethodVisitor#visitInsn}.
+ * Method instruction. See {@link scala.tools.asm.MethodVisitor#visitInsn}
+ * .
*/
public abstract void visitInsn(final int opcode);
/**
- * Method instruction.
- * See {@link org.objectweb.asm.MethodVisitor#visitIntInsn}.
+ * Method instruction. See
+ * {@link scala.tools.asm.MethodVisitor#visitIntInsn}.
*/
public abstract void visitIntInsn(final int opcode, final int operand);
/**
- * Method instruction.
- * See {@link org.objectweb.asm.MethodVisitor#visitVarInsn}.
+ * Method instruction. See
+ * {@link scala.tools.asm.MethodVisitor#visitVarInsn}.
*/
public abstract void visitVarInsn(final int opcode, final int var);
/**
- * Method instruction.
- * See {@link org.objectweb.asm.MethodVisitor#visitTypeInsn}.
+ * Method instruction. See
+ * {@link scala.tools.asm.MethodVisitor#visitTypeInsn}.
*/
public abstract void visitTypeInsn(final int opcode, final String type);
/**
- * Method instruction.
- * See {@link org.objectweb.asm.MethodVisitor#visitFieldInsn}.
+ * Method instruction. See
+ * {@link scala.tools.asm.MethodVisitor#visitFieldInsn}.
*/
- public abstract void visitFieldInsn(
- final int opcode,
- final String owner,
- final String name,
- final String desc);
+ public abstract void visitFieldInsn(final int opcode, final String owner,
+ final String name, final String desc);
/**
- * Method instruction.
- * See {@link org.objectweb.asm.MethodVisitor#visitMethodInsn}.
+ * Method instruction. See
+ * {@link scala.tools.asm.MethodVisitor#visitMethodInsn}.
*/
- public abstract void visitMethodInsn(
- final int opcode,
- final String owner,
- final String name,
- final String desc);
+ public abstract void visitMethodInsn(final int opcode, final String owner,
+ final String name, final String desc);
/**
- * Method instruction.
- * See {@link org.objectweb.asm.MethodVisitor#visitInvokeDynamicInsn}.
+ * Method instruction. See
+ * {@link scala.tools.asm.MethodVisitor#visitInvokeDynamicInsn}.
*/
- public abstract void visitInvokeDynamicInsn(
- String name,
- String desc,
- Handle bsm,
- Object... bsmArgs);
+ public abstract void visitInvokeDynamicInsn(String name, String desc,
+ Handle bsm, Object... bsmArgs);
/**
- * Method instruction.
- * See {@link org.objectweb.asm.MethodVisitor#visitJumpInsn}.
+ * Method instruction. See
+ * {@link scala.tools.asm.MethodVisitor#visitJumpInsn}.
*/
public abstract void visitJumpInsn(final int opcode, final Label label);
/**
- * Method label.
- * See {@link org.objectweb.asm.MethodVisitor#visitLabel}.
+ * Method label. See {@link scala.tools.asm.MethodVisitor#visitLabel}.
*/
public abstract void visitLabel(final Label label);
/**
- * Method instruction.
- * See {@link org.objectweb.asm.MethodVisitor#visitLdcInsn}.
+ * Method instruction. See
+ * {@link scala.tools.asm.MethodVisitor#visitLdcInsn}.
*/
public abstract void visitLdcInsn(final Object cst);
/**
- * Method instruction.
- * See {@link org.objectweb.asm.MethodVisitor#visitIincInsn}.
+ * Method instruction. See
+ * {@link scala.tools.asm.MethodVisitor#visitIincInsn}.
*/
public abstract void visitIincInsn(final int var, final int increment);
/**
- * Method instruction.
- * See {@link org.objectweb.asm.MethodVisitor#visitTableSwitchInsn}.
+ * Method instruction. See
+ * {@link scala.tools.asm.MethodVisitor#visitTableSwitchInsn}.
*/
- public abstract void visitTableSwitchInsn(
- final int min,
- final int max,
- final Label dflt,
- final Label... labels);
+ public abstract void visitTableSwitchInsn(final int min, final int max,
+ final Label dflt, final Label... labels);
/**
- * Method instruction.
- * See {@link org.objectweb.asm.MethodVisitor#visitLookupSwitchInsn}.
+ * Method instruction. See
+ * {@link scala.tools.asm.MethodVisitor#visitLookupSwitchInsn}.
*/
- public abstract void visitLookupSwitchInsn(
- final Label dflt,
- final int[] keys,
- final Label[] labels);
+ public abstract void visitLookupSwitchInsn(final Label dflt,
+ final int[] keys, final Label[] labels);
/**
- * Method instruction.
- * See {@link org.objectweb.asm.MethodVisitor#visitMultiANewArrayInsn}.
+ * Method instruction. See
+ * {@link scala.tools.asm.MethodVisitor#visitMultiANewArrayInsn}.
*/
- public abstract void visitMultiANewArrayInsn(
- final String desc,
- final int dims);
+ public abstract void visitMultiANewArrayInsn(final String desc,
+ final int dims);
/**
- * Method exception handler.
- * See {@link org.objectweb.asm.MethodVisitor#visitTryCatchBlock}.
+ * Method exception handler. See
+ * {@link scala.tools.asm.MethodVisitor#visitTryCatchBlock}.
*/
- public abstract void visitTryCatchBlock(
- final Label start,
- final Label end,
- final Label handler,
- final String type);
+ public abstract void visitTryCatchBlock(final Label start, final Label end,
+ final Label handler, final String type);
/**
- * Method debug info.
- * See {@link org.objectweb.asm.MethodVisitor#visitLocalVariable}.
+ * Method debug info. See
+ * {@link scala.tools.asm.MethodVisitor#visitLocalVariable}.
*/
- public abstract void visitLocalVariable(
- final String name,
- final String desc,
- final String signature,
- final Label start,
- final Label end,
- final int index);
+ public abstract void visitLocalVariable(final String name,
+ final String desc, final String signature, final Label start,
+ final Label end, final int index);
/**
- * Method debug info.
- * See {@link org.objectweb.asm.MethodVisitor#visitLineNumber}.
+ * Method debug info. See
+ * {@link scala.tools.asm.MethodVisitor#visitLineNumber}.
*/
public abstract void visitLineNumber(final int line, final Label start);
/**
- * Method max stack and max locals.
- * See {@link org.objectweb.asm.MethodVisitor#visitMaxs}.
+ * Method max stack and max locals. See
+ * {@link scala.tools.asm.MethodVisitor#visitMaxs}.
*/
public abstract void visitMaxs(final int maxStack, final int maxLocals);
/**
- * Method end.
- * See {@link org.objectweb.asm.MethodVisitor#visitEnd}.
+ * Method end. See {@link scala.tools.asm.MethodVisitor#visitEnd}.
*/
public abstract void visitMethodEnd();
@@ -497,7 +434,8 @@ public abstract class Printer {
/**
* Prints the text constructed by this visitor.
*
- * @param pw the print writer to be used.
+ * @param pw
+ * the print writer to be used.
*/
public void print(final PrintWriter pw) {
printList(pw, text);
@@ -506,8 +444,10 @@ public abstract class Printer {
/**
* Appends a quoted string to a given buffer.
*
- * @param buf the buffer where the string must be added.
- * @param s the string to be added.
+ * @param buf
+ * the buffer where the string must be added.
+ * @param s
+ * the string to be added.
*/
public static void appendString(final StringBuffer buf, final String s) {
buf.append('\"');
@@ -541,9 +481,11 @@ public abstract class Printer {
/**
* Prints the given string tree.
*
- * @param pw the writer to be used to print the tree.
- * @param l a string tree, i.e., a string list that can contain other string
- * lists, and so on recursively.
+ * @param pw
+ * the writer to be used to print the tree.
+ * @param l
+ * a string tree, i.e., a string list that can contain other
+ * string lists, and so on recursively.
*/
static void printList(final PrintWriter pw, final List<?> l) {
for (int i = 0; i < l.size(); ++i) {
diff --git a/src/asm/scala/tools/asm/util/SignatureChecker.java b/src/asm/scala/tools/asm/util/SignatureChecker.java
deleted file mode 100644
index 71f0d80027..0000000000
--- a/src/asm/scala/tools/asm/util/SignatureChecker.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/* NSC -- new Scala compiler
- * Copyright 2005-2013 LAMP/EPFL
- */
-
-package scala.tools.asm.util;
-
-import scala.tools.asm.util.CheckMethodAdapter;
-import scala.tools.asm.MethodVisitor;
-
-/**
- * A subclass of ASM's CheckMethodAdapter for the sole purpose of accessing some protected methods there.
- *
- */
-public class SignatureChecker extends CheckMethodAdapter {
-
- public SignatureChecker(final MethodVisitor mv) {
- super(mv);
- }
-
- /**
- * Checks a class signature.
- *
- * @param signature a string containing the signature that must be checked.
- */
- public static void checkClassSignature(final String signature) {
- CheckMethodAdapter.checkClassSignature(signature);
- }
-
- /**
- * Checks a method signature.
- *
- * @param signature a string containing the signature that must be checked.
- */
- public static void checkMethodSignature(final String signature) {
- CheckMethodAdapter.checkMethodSignature(signature);
- }
-
- /**
- * Checks a field signature.
- *
- * @param signature a string containing the signature that must be checked.
- */
- public static void checkFieldSignature(final String signature) {
- CheckMethodAdapter.checkFieldSignature(signature);
- }
-
-}
diff --git a/src/asm/scala/tools/asm/util/Textifiable.java b/src/asm/scala/tools/asm/util/Textifiable.java
index b80d0139db..85e051e2f8 100644
--- a/src/asm/scala/tools/asm/util/Textifiable.java
+++ b/src/asm/scala/tools/asm/util/Textifiable.java
@@ -34,7 +34,7 @@ import java.util.Map;
import scala.tools.asm.Label;
/**
- * An {@link org.objectweb.asm.Attribute Attribute} that can print a readable
+ * An {@link scala.tools.asm.Attribute Attribute} that can print a readable
* representation of itself.
*
* Implementations should construct readable output from an attribute data
@@ -47,8 +47,10 @@ public interface Textifiable {
/**
* Build a human readable representation of this attribute.
*
- * @param buf a buffer used for printing Java code.
- * @param labelNames map of label instances to their names.
+ * @param buf
+ * a buffer used for printing Java code.
+ * @param labelNames
+ * map of label instances to their names.
*/
void textify(StringBuffer buf, Map<Label, String> labelNames);
}
diff --git a/src/asm/scala/tools/asm/util/Textifier.java b/src/asm/scala/tools/asm/util/Textifier.java
index 8d40ebd026..a5c4f6779e 100644
--- a/src/asm/scala/tools/asm/util/Textifier.java
+++ b/src/asm/scala/tools/asm/util/Textifier.java
@@ -149,22 +149,24 @@ public class Textifier extends Printer {
/**
* Constructs a new {@link Textifier}.
*
- * @param api the ASM API version implemented by this visitor. Must be one
- * of {@link Opcodes#ASM4}.
+ * @param api
+ * the ASM API version implemented by this visitor. Must be one
+ * of {@link Opcodes#ASM4}.
*/
protected Textifier(final int api) {
super(api);
}
/**
- * Prints a disassembled view of the given class to the standard output. <p>
- * Usage: Textifier [-debug] &lt;binary class name or class
- * file name &gt;
+ * Prints a disassembled view of the given class to the standard output.
+ * <p>
+ * Usage: Textifier [-debug] &lt;binary class name or class file name &gt;
*
- * @param args the command line arguments.
+ * @param args
+ * the command line arguments.
*
- * @throws Exception if the class cannot be found, or if an IO exception
- * occurs.
+ * @throws Exception
+ * if the class cannot be found, or if an IO exception occurs.
*/
public static void main(final String[] args) throws Exception {
int i = 0;
@@ -182,21 +184,20 @@ public class Textifier extends Printer {
}
}
if (!ok) {
- System.err.println("Prints a disassembled view of the given class.");
+ System.err
+ .println("Prints a disassembled view of the given class.");
System.err.println("Usage: Textifier [-debug] "
+ "<fully qualified class name or class file name>");
return;
}
ClassReader cr;
if (args[i].endsWith(".class") || args[i].indexOf('\\') > -1
- || args[i].indexOf('/') > -1)
- {
+ || args[i].indexOf('/') > -1) {
cr = new ClassReader(new FileInputStream(args[i]));
} else {
cr = new ClassReader(args[i]);
}
- cr.accept(new TraceClassVisitor(new PrintWriter(System.out)),
- flags);
+ cr.accept(new TraceClassVisitor(new PrintWriter(System.out)), flags);
}
// ------------------------------------------------------------------------
@@ -204,38 +205,27 @@ public class Textifier extends Printer {
// ------------------------------------------------------------------------
@Override
- public void visit(
- final int version,
- final int access,
- final String name,
- final String signature,
- final String superName,
- final String[] interfaces)
- {
+ public void visit(final int version, final int access, final String name,
+ final String signature, final String superName,
+ final String[] interfaces) {
int major = version & 0xFFFF;
int minor = version >>> 16;
buf.setLength(0);
- buf.append("// class version ")
- .append(major)
- .append('.')
- .append(minor)
- .append(" (")
- .append(version)
- .append(")\n");
+ buf.append("// class version ").append(major).append('.').append(minor)
+ .append(" (").append(version).append(")\n");
if ((access & Opcodes.ACC_DEPRECATED) != 0) {
buf.append("// DEPRECATED\n");
}
- buf.append("// access flags 0x").append(Integer.toHexString(access).toUpperCase()).append('\n');
+ buf.append("// access flags 0x")
+ .append(Integer.toHexString(access).toUpperCase()).append('\n');
appendDescriptor(CLASS_SIGNATURE, signature);
if (signature != null) {
TraceSignatureVisitor sv = new TraceSignatureVisitor(access);
SignatureReader r = new SignatureReader(signature);
r.accept(sv);
- buf.append("// declaration: ")
- .append(name)
- .append(sv.getDeclaration())
- .append('\n');
+ buf.append("// declaration: ").append(name)
+ .append(sv.getDeclaration()).append('\n');
}
appendAccess(access & ~Opcodes.ACC_SUPER);
@@ -269,15 +259,11 @@ public class Textifier extends Printer {
public void visitSource(final String file, final String debug) {
buf.setLength(0);
if (file != null) {
- buf.append(tab)
- .append("// compiled from: ")
- .append(file)
+ buf.append(tab).append("// compiled from: ").append(file)
.append('\n');
}
if (debug != null) {
- buf.append(tab)
- .append("// debug info: ")
- .append(debug)
+ buf.append(tab).append("// debug info: ").append(debug)
.append('\n');
}
if (buf.length() > 0) {
@@ -286,11 +272,8 @@ public class Textifier extends Printer {
}
@Override
- public void visitOuterClass(
- final String owner,
- final String name,
- final String desc)
- {
+ public void visitOuterClass(final String owner, final String name,
+ final String desc) {
buf.setLength(0);
buf.append(tab).append("OUTERCLASS ");
appendDescriptor(INTERNAL_NAME, owner);
@@ -304,10 +287,8 @@ public class Textifier extends Printer {
}
@Override
- public Textifier visitClassAnnotation(
- final String desc,
- final boolean visible)
- {
+ public Textifier visitClassAnnotation(final String desc,
+ final boolean visible) {
text.add("\n");
return visitAnnotation(desc, visible);
}
@@ -319,15 +300,13 @@ public class Textifier extends Printer {
}
@Override
- public void visitInnerClass(
- final String name,
- final String outerName,
- final String innerName,
- final int access)
- {
+ public void visitInnerClass(final String name, final String outerName,
+ final String innerName, final int access) {
buf.setLength(0);
buf.append(tab).append("// access flags 0x");
- buf.append(Integer.toHexString(access & ~Opcodes.ACC_SUPER).toUpperCase()).append('\n');
+ buf.append(
+ Integer.toHexString(access & ~Opcodes.ACC_SUPER).toUpperCase())
+ .append('\n');
buf.append(tab);
appendAccess(access);
buf.append("INNERCLASS ");
@@ -341,19 +320,15 @@ public class Textifier extends Printer {
}
@Override
- public Textifier visitField(
- final int access,
- final String name,
- final String desc,
- final String signature,
- final Object value)
- {
+ public Textifier visitField(final int access, final String name,
+ final String desc, final String signature, final Object value) {
buf.setLength(0);
buf.append('\n');
if ((access & Opcodes.ACC_DEPRECATED) != 0) {
buf.append(tab).append("// DEPRECATED\n");
}
- buf.append(tab).append("// access flags 0x").append(Integer.toHexString(access).toUpperCase()).append('\n');
+ buf.append(tab).append("// access flags 0x")
+ .append(Integer.toHexString(access).toUpperCase()).append('\n');
if (signature != null) {
buf.append(tab);
appendDescriptor(FIELD_SIGNATURE, signature);
@@ -361,10 +336,8 @@ public class Textifier extends Printer {
TraceSignatureVisitor sv = new TraceSignatureVisitor(0);
SignatureReader r = new SignatureReader(signature);
r.acceptType(sv);
- buf.append(tab)
- .append("// declaration: ")
- .append(sv.getDeclaration())
- .append('\n');
+ buf.append(tab).append("// declaration: ")
+ .append(sv.getDeclaration()).append('\n');
}
buf.append(tab);
@@ -390,19 +363,15 @@ public class Textifier extends Printer {
}
@Override
- public Textifier visitMethod(
- final int access,
- final String name,
- final String desc,
- final String signature,
- final String[] exceptions)
- {
+ public Textifier visitMethod(final int access, final String name,
+ final String desc, final String signature, final String[] exceptions) {
buf.setLength(0);
buf.append('\n');
if ((access & Opcodes.ACC_DEPRECATED) != 0) {
buf.append(tab).append("// DEPRECATED\n");
}
- buf.append(tab).append("// access flags 0x").append(Integer.toHexString(access).toUpperCase()).append('\n');
+ buf.append(tab).append("// access flags 0x")
+ .append(Integer.toHexString(access).toUpperCase()).append('\n');
if (signature != null) {
buf.append(tab);
@@ -415,12 +384,8 @@ public class Textifier extends Printer {
String genericReturn = v.getReturnType();
String genericExceptions = v.getExceptions();
- buf.append(tab)
- .append("// declaration: ")
- .append(genericReturn)
- .append(' ')
- .append(name)
- .append(genericDecl);
+ buf.append(tab).append("// declaration: ").append(genericReturn)
+ .append(' ').append(name).append(genericDecl);
if (genericExceptions != null) {
buf.append(" throws ").append(genericExceptions);
}
@@ -593,11 +558,8 @@ public class Textifier extends Printer {
}
@Override
- public void visitEnum(
- final String name,
- final String desc,
- final String value)
- {
+ public void visitEnum(final String name, final String desc,
+ final String value) {
buf.setLength(0);
appendComa(valueNumber++);
if (name != null) {
@@ -609,10 +571,7 @@ public class Textifier extends Printer {
}
@Override
- public Textifier visitAnnotation(
- final String name,
- final String desc)
- {
+ public Textifier visitAnnotation(final String name, final String desc) {
buf.setLength(0);
appendComa(valueNumber++);
if (name != null) {
@@ -629,9 +588,7 @@ public class Textifier extends Printer {
}
@Override
- public Textifier visitArray(
- final String name)
- {
+ public Textifier visitArray(final String name) {
buf.setLength(0);
appendComa(valueNumber++);
if (name != null) {
@@ -654,10 +611,8 @@ public class Textifier extends Printer {
// ------------------------------------------------------------------------
@Override
- public Textifier visitFieldAnnotation(
- final String desc,
- final boolean visible)
- {
+ public Textifier visitFieldAnnotation(final String desc,
+ final boolean visible) {
return visitAnnotation(desc, visible);
}
@@ -684,19 +639,14 @@ public class Textifier extends Printer {
}
@Override
- public Textifier visitMethodAnnotation(
- final String desc,
- final boolean visible)
- {
+ public Textifier visitMethodAnnotation(final String desc,
+ final boolean visible) {
return visitAnnotation(desc, visible);
}
@Override
- public Textifier visitParameterAnnotation(
- final int parameter,
- final String desc,
- final boolean visible)
- {
+ public Textifier visitParameterAnnotation(final int parameter,
+ final String desc, final boolean visible) {
buf.setLength(0);
buf.append(tab2).append('@');
appendDescriptor(FIELD_DESCRIPTOR, desc);
@@ -730,40 +680,35 @@ public class Textifier extends Printer {
}
@Override
- public void visitFrame(
- final int type,
- final int nLocal,
- final Object[] local,
- final int nStack,
- final Object[] stack)
- {
+ public void visitFrame(final int type, final int nLocal,
+ final Object[] local, final int nStack, final Object[] stack) {
buf.setLength(0);
buf.append(ltab);
buf.append("FRAME ");
switch (type) {
- case Opcodes.F_NEW:
- case Opcodes.F_FULL:
- buf.append("FULL [");
- appendFrameTypes(nLocal, local);
- buf.append("] [");
- appendFrameTypes(nStack, stack);
- buf.append(']');
- break;
- case Opcodes.F_APPEND:
- buf.append("APPEND [");
- appendFrameTypes(nLocal, local);
- buf.append(']');
- break;
- case Opcodes.F_CHOP:
- buf.append("CHOP ").append(nLocal);
- break;
- case Opcodes.F_SAME:
- buf.append("SAME");
- break;
- case Opcodes.F_SAME1:
- buf.append("SAME1 ");
- appendFrameTypes(1, stack);
- break;
+ case Opcodes.F_NEW:
+ case Opcodes.F_FULL:
+ buf.append("FULL [");
+ appendFrameTypes(nLocal, local);
+ buf.append("] [");
+ appendFrameTypes(nStack, stack);
+ buf.append(']');
+ break;
+ case Opcodes.F_APPEND:
+ buf.append("APPEND [");
+ appendFrameTypes(nLocal, local);
+ buf.append(']');
+ break;
+ case Opcodes.F_CHOP:
+ buf.append("CHOP ").append(nLocal);
+ break;
+ case Opcodes.F_SAME:
+ buf.append("SAME");
+ break;
+ case Opcodes.F_SAME1:
+ buf.append("SAME1 ");
+ appendFrameTypes(1, stack);
+ break;
}
buf.append('\n');
text.add(buf.toString());
@@ -782,20 +727,15 @@ public class Textifier extends Printer {
buf.append(tab2)
.append(OPCODES[opcode])
.append(' ')
- .append(opcode == Opcodes.NEWARRAY
- ? TYPES[operand]
- : Integer.toString(operand))
- .append('\n');
+ .append(opcode == Opcodes.NEWARRAY ? TYPES[operand] : Integer
+ .toString(operand)).append('\n');
text.add(buf.toString());
}
@Override
public void visitVarInsn(final int opcode, final int var) {
buf.setLength(0);
- buf.append(tab2)
- .append(OPCODES[opcode])
- .append(' ')
- .append(var)
+ buf.append(tab2).append(OPCODES[opcode]).append(' ').append(var)
.append('\n');
text.add(buf.toString());
}
@@ -810,12 +750,8 @@ public class Textifier extends Printer {
}
@Override
- public void visitFieldInsn(
- final int opcode,
- final String owner,
- final String name,
- final String desc)
- {
+ public void visitFieldInsn(final int opcode, final String owner,
+ final String name, final String desc) {
buf.setLength(0);
buf.append(tab2).append(OPCODES[opcode]).append(' ');
appendDescriptor(INTERNAL_NAME, owner);
@@ -826,12 +762,8 @@ public class Textifier extends Printer {
}
@Override
- public void visitMethodInsn(
- final int opcode,
- final String owner,
- final String name,
- final String desc)
- {
+ public void visitMethodInsn(final int opcode, final String owner,
+ final String name, final String desc) {
buf.setLength(0);
buf.append(tab2).append(OPCODES[opcode]).append(' ');
appendDescriptor(INTERNAL_NAME, owner);
@@ -842,12 +774,8 @@ public class Textifier extends Printer {
}
@Override
- public void visitInvokeDynamicInsn(
- String name,
- String desc,
- Handle bsm,
- Object... bsmArgs)
- {
+ public void visitInvokeDynamicInsn(String name, String desc, Handle bsm,
+ Object... bsmArgs) {
buf.setLength(0);
buf.append(tab2).append("INVOKEDYNAMIC").append(' ');
buf.append(name);
@@ -855,11 +783,11 @@ public class Textifier extends Printer {
buf.append(" [");
appendHandle(bsm);
buf.append(tab3).append("// arguments:");
- if(bsmArgs.length == 0) {
+ if (bsmArgs.length == 0) {
buf.append(" none");
} else {
buf.append('\n').append(tab3);
- for(int i = 0; i < bsmArgs.length; i++) {
+ for (int i = 0; i < bsmArgs.length; i++) {
Object cst = bsmArgs[i];
if (cst instanceof String) {
Printer.appendString(buf, (String) cst);
@@ -915,22 +843,14 @@ public class Textifier extends Printer {
@Override
public void visitIincInsn(final int var, final int increment) {
buf.setLength(0);
- buf.append(tab2)
- .append("IINC ")
- .append(var)
- .append(' ')
- .append(increment)
- .append('\n');
+ buf.append(tab2).append("IINC ").append(var).append(' ')
+ .append(increment).append('\n');
text.add(buf.toString());
}
@Override
- public void visitTableSwitchInsn(
- final int min,
- final int max,
- final Label dflt,
- final Label... labels)
- {
+ public void visitTableSwitchInsn(final int min, final int max,
+ final Label dflt, final Label... labels) {
buf.setLength(0);
buf.append(tab2).append("TABLESWITCH\n");
for (int i = 0; i < labels.length; ++i) {
@@ -945,11 +865,8 @@ public class Textifier extends Printer {
}
@Override
- public void visitLookupSwitchInsn(
- final Label dflt,
- final int[] keys,
- final Label[] labels)
- {
+ public void visitLookupSwitchInsn(final Label dflt, final int[] keys,
+ final Label[] labels) {
buf.setLength(0);
buf.append(tab2).append("LOOKUPSWITCH\n");
for (int i = 0; i < labels.length; ++i) {
@@ -973,12 +890,8 @@ public class Textifier extends Printer {
}
@Override
- public void visitTryCatchBlock(
- final Label start,
- final Label end,
- final Label handler,
- final String type)
- {
+ public void visitTryCatchBlock(final Label start, final Label end,
+ final Label handler, final String type) {
buf.setLength(0);
buf.append(tab2).append("TRYCATCHBLOCK ");
appendLabel(start);
@@ -993,14 +906,9 @@ public class Textifier extends Printer {
}
@Override
- public void visitLocalVariable(
- final String name,
- final String desc,
- final String signature,
- final Label start,
- final Label end,
- final int index)
- {
+ public void visitLocalVariable(final String name, final String desc,
+ final String signature, final Label start, final Label end,
+ final int index) {
buf.setLength(0);
buf.append(tab2).append("LOCALVARIABLE ").append(name).append(' ');
appendDescriptor(FIELD_DESCRIPTOR, desc);
@@ -1017,10 +925,8 @@ public class Textifier extends Printer {
TraceSignatureVisitor sv = new TraceSignatureVisitor(0);
SignatureReader r = new SignatureReader(signature);
r.acceptType(sv);
- buf.append(tab2)
- .append("// declaration: ")
- .append(sv.getDeclaration())
- .append('\n');
+ buf.append(tab2).append("// declaration: ")
+ .append(sv.getDeclaration()).append('\n');
}
text.add(buf.toString());
}
@@ -1056,14 +962,13 @@ public class Textifier extends Printer {
/**
* Prints a disassembled view of the given annotation.
*
- * @param desc the class descriptor of the annotation class.
- * @param visible <tt>true</tt> if the annotation is visible at runtime.
+ * @param desc
+ * the class descriptor of the annotation class.
+ * @param visible
+ * <tt>true</tt> if the annotation is visible at runtime.
* @return a visitor to visit the annotation values.
*/
- public Textifier visitAnnotation(
- final String desc,
- final boolean visible)
- {
+ public Textifier visitAnnotation(final String desc, final boolean visible) {
buf.setLength(0);
buf.append(tab).append('@');
appendDescriptor(FIELD_DESCRIPTOR, desc);
@@ -1078,7 +983,8 @@ public class Textifier extends Printer {
/**
* Prints a disassembled view of the given attribute.
*
- * @param attr an attribute.
+ * @param attr
+ * an attribute.
*/
public void visitAttribute(final Attribute attr) {
buf.setLength(0);
@@ -1111,15 +1017,16 @@ public class Textifier extends Printer {
* Appends an internal name, a type descriptor or a type signature to
* {@link #buf buf}.
*
- * @param type indicates if desc is an internal name, a field descriptor, a
- * method descriptor, a class signature, ...
- * @param desc an internal name, type descriptor, or type signature. May be
- * <tt>null</tt>.
+ * @param type
+ * indicates if desc is an internal name, a field descriptor, a
+ * method descriptor, a class signature, ...
+ * @param desc
+ * an internal name, type descriptor, or type signature. May be
+ * <tt>null</tt>.
*/
protected void appendDescriptor(final int type, final String desc) {
if (type == CLASS_SIGNATURE || type == FIELD_SIGNATURE
- || type == METHOD_SIGNATURE)
- {
+ || type == METHOD_SIGNATURE) {
if (desc != null) {
buf.append("// signature ").append(desc).append('\n');
}
@@ -1132,7 +1039,8 @@ public class Textifier extends Printer {
* Appends the name of the given label to {@link #buf buf}. Creates a new
* label name if the given label does not yet have one.
*
- * @param l a label.
+ * @param l
+ * a label.
*/
protected void appendLabel(final Label l) {
if (labelNames == null) {
@@ -1149,40 +1057,42 @@ public class Textifier extends Printer {
/**
* Appends the information about the given handle to {@link #buf buf}.
*
- * @param h a handle, non null.
+ * @param h
+ * a handle, non null.
*/
protected void appendHandle(final Handle h) {
buf.append('\n').append(tab3);
int tag = h.getTag();
- buf.append("// handle kind 0x").append(Integer.toHexString(tag)).append(" : ");
+ buf.append("// handle kind 0x").append(Integer.toHexString(tag))
+ .append(" : ");
switch (tag) {
- case Opcodes.H_GETFIELD:
- buf.append("GETFIELD");
- break;
- case Opcodes.H_GETSTATIC:
- buf.append("GETSTATIC");
- break;
- case Opcodes.H_PUTFIELD:
- buf.append("PUTFIELD");
- break;
- case Opcodes.H_PUTSTATIC:
- buf.append("PUTSTATIC");
- break;
- case Opcodes.H_INVOKEINTERFACE:
- buf.append("INVOKEINTERFACE");
- break;
- case Opcodes.H_INVOKESPECIAL:
- buf.append("INVOKESPECIAL");
- break;
- case Opcodes.H_INVOKESTATIC:
- buf.append("INVOKESTATIC");
- break;
- case Opcodes.H_INVOKEVIRTUAL:
- buf.append("INVOKEVIRTUAL");
- break;
- case Opcodes.H_NEWINVOKESPECIAL:
- buf.append("NEWINVOKESPECIAL");
- break;
+ case Opcodes.H_GETFIELD:
+ buf.append("GETFIELD");
+ break;
+ case Opcodes.H_GETSTATIC:
+ buf.append("GETSTATIC");
+ break;
+ case Opcodes.H_PUTFIELD:
+ buf.append("PUTFIELD");
+ break;
+ case Opcodes.H_PUTSTATIC:
+ buf.append("PUTSTATIC");
+ break;
+ case Opcodes.H_INVOKEINTERFACE:
+ buf.append("INVOKEINTERFACE");
+ break;
+ case Opcodes.H_INVOKESPECIAL:
+ buf.append("INVOKESPECIAL");
+ break;
+ case Opcodes.H_INVOKESTATIC:
+ buf.append("INVOKESTATIC");
+ break;
+ case Opcodes.H_INVOKEVIRTUAL:
+ buf.append("INVOKEVIRTUAL");
+ break;
+ case Opcodes.H_NEWINVOKESPECIAL:
+ buf.append("NEWINVOKESPECIAL");
+ break;
}
buf.append('\n');
buf.append(tab3);
@@ -1195,10 +1105,11 @@ public class Textifier extends Printer {
}
/**
- * Appends a string representation of the given access modifiers to {@link
- * #buf buf}.
+ * Appends a string representation of the given access modifiers to
+ * {@link #buf buf}.
*
- * @param access some access modifiers.
+ * @param access
+ * some access modifiers.
*/
private void appendAccess(final int access) {
if ((access & Opcodes.ACC_PUBLIC) != 0) {
@@ -1231,6 +1142,9 @@ public class Textifier extends Printer {
if ((access & Opcodes.ACC_STRICT) != 0) {
buf.append("strictfp ");
}
+ if ((access & Opcodes.ACC_SYNTHETIC) != 0) {
+ buf.append("synthetic ");
+ }
if ((access & Opcodes.ACC_ENUM) != 0) {
buf.append("enum ");
}
@@ -1256,27 +1170,27 @@ public class Textifier extends Printer {
}
} else if (o[i] instanceof Integer) {
switch (((Integer) o[i]).intValue()) {
- case 0:
- appendDescriptor(FIELD_DESCRIPTOR, "T");
- break;
- case 1:
- appendDescriptor(FIELD_DESCRIPTOR, "I");
- break;
- case 2:
- appendDescriptor(FIELD_DESCRIPTOR, "F");
- break;
- case 3:
- appendDescriptor(FIELD_DESCRIPTOR, "D");
- break;
- case 4:
- appendDescriptor(FIELD_DESCRIPTOR, "J");
- break;
- case 5:
- appendDescriptor(FIELD_DESCRIPTOR, "N");
- break;
- case 6:
- appendDescriptor(FIELD_DESCRIPTOR, "U");
- break;
+ case 0:
+ appendDescriptor(FIELD_DESCRIPTOR, "T");
+ break;
+ case 1:
+ appendDescriptor(FIELD_DESCRIPTOR, "I");
+ break;
+ case 2:
+ appendDescriptor(FIELD_DESCRIPTOR, "F");
+ break;
+ case 3:
+ appendDescriptor(FIELD_DESCRIPTOR, "D");
+ break;
+ case 4:
+ appendDescriptor(FIELD_DESCRIPTOR, "J");
+ break;
+ case 5:
+ appendDescriptor(FIELD_DESCRIPTOR, "N");
+ break;
+ case 6:
+ appendDescriptor(FIELD_DESCRIPTOR, "U");
+ break;
}
} else {
appendLabel((Label) o[i]);
diff --git a/src/asm/scala/tools/asm/util/TraceAnnotationVisitor.java b/src/asm/scala/tools/asm/util/TraceAnnotationVisitor.java
index f112609031..33e7cf0b26 100644
--- a/src/asm/scala/tools/asm/util/TraceAnnotationVisitor.java
+++ b/src/asm/scala/tools/asm/util/TraceAnnotationVisitor.java
@@ -58,33 +58,26 @@ public final class TraceAnnotationVisitor extends AnnotationVisitor {
}
@Override
- public void visitEnum(
- final String name,
- final String desc,
- final String value)
- {
+ public void visitEnum(final String name, final String desc,
+ final String value) {
p.visitEnum(name, desc, value);
super.visitEnum(name, desc, value);
}
@Override
- public AnnotationVisitor visitAnnotation(
- final String name,
- final String desc)
- {
+ public AnnotationVisitor visitAnnotation(final String name,
+ final String desc) {
Printer p = this.p.visitAnnotation(name, desc);
- AnnotationVisitor av = this.av == null
- ? null
- : this.av.visitAnnotation(name, desc);
+ AnnotationVisitor av = this.av == null ? null : this.av
+ .visitAnnotation(name, desc);
return new TraceAnnotationVisitor(av, p);
}
@Override
public AnnotationVisitor visitArray(final String name) {
Printer p = this.p.visitArray(name);
- AnnotationVisitor av = this.av == null
- ? null
- : this.av.visitArray(name);
+ AnnotationVisitor av = this.av == null ? null : this.av
+ .visitArray(name);
return new TraceAnnotationVisitor(av, p);
}
diff --git a/src/asm/scala/tools/asm/util/TraceClassVisitor.java b/src/asm/scala/tools/asm/util/TraceClassVisitor.java
index bb830b71ce..ff7a017482 100644
--- a/src/asm/scala/tools/asm/util/TraceClassVisitor.java
+++ b/src/asm/scala/tools/asm/util/TraceClassVisitor.java
@@ -42,30 +42,41 @@ import scala.tools.asm.Opcodes;
* A {@link ClassVisitor} that prints the classes it visits with a
* {@link Printer}. This class visitor can be used in the middle of a class
* visitor chain to trace the class that is visited at a given point in this
- * chain. This may be useful for debugging purposes. <p> The trace printed when
- * visiting the <tt>Hello</tt> class is the following: <p> <blockquote>
- *
- * <pre> // class version 49.0 (49) // access flags 0x21 public class Hello {
- *
+ * chain. This may be useful for debugging purposes.
+ * <p>
+ * The trace printed when visiting the <tt>Hello</tt> class is the following:
+ * <p>
+ * <blockquote>
+ *
+ * <pre>
+ * // class version 49.0 (49) // access flags 0x21 public class Hello {
+ *
* // compiled from: Hello.java
- *
+ *
* // access flags 0x1 public &lt;init&gt; ()V ALOAD 0 INVOKESPECIAL
* java/lang/Object &lt;init&gt; ()V RETURN MAXSTACK = 1 MAXLOCALS = 1
- *
+ *
* // access flags 0x9 public static main ([Ljava/lang/String;)V GETSTATIC
* java/lang/System out Ljava/io/PrintStream; LDC &quot;hello&quot;
* INVOKEVIRTUAL java/io/PrintStream println (Ljava/lang/String;)V RETURN
- * MAXSTACK = 2 MAXLOCALS = 1 } </pre>
- *
- * </blockquote> where <tt>Hello</tt> is defined by: <p> <blockquote>
- *
- * <pre> public class Hello {
- *
- * public static void main(String[] args) {
- * System.out.println(&quot;hello&quot;); } } </pre>
- *
+ * MAXSTACK = 2 MAXLOCALS = 1 }
+ * </pre>
+ *
+ * </blockquote> where <tt>Hello</tt> is defined by:
+ * <p>
+ * <blockquote>
+ *
+ * <pre>
+ * public class Hello {
+ *
+ * public static void main(String[] args) {
+ * System.out.println(&quot;hello&quot;);
+ * }
+ * }
+ * </pre>
+ *
* </blockquote>
- *
+ *
* @author Eric Bruneton
* @author Eugene Kuleshov
*/
@@ -83,8 +94,9 @@ public final class TraceClassVisitor extends ClassVisitor {
/**
* Constructs a new {@link TraceClassVisitor}.
- *
- * @param pw the print writer to be used to print the class.
+ *
+ * @param pw
+ * the print writer to be used to print the class.
*/
public TraceClassVisitor(final PrintWriter pw) {
this(null, pw);
@@ -92,10 +104,12 @@ public final class TraceClassVisitor extends ClassVisitor {
/**
* Constructs a new {@link TraceClassVisitor}.
- *
- * @param cv the {@link ClassVisitor} to which this visitor delegates calls.
- * May be <tt>null</tt>.
- * @param pw the print writer to be used to print the class.
+ *
+ * @param cv
+ * the {@link ClassVisitor} to which this visitor delegates
+ * calls. May be <tt>null</tt>.
+ * @param pw
+ * the print writer to be used to print the class.
*/
public TraceClassVisitor(final ClassVisitor cv, final PrintWriter pw) {
this(cv, new Textifier(), pw);
@@ -103,33 +117,28 @@ public final class TraceClassVisitor extends ClassVisitor {
/**
* Constructs a new {@link TraceClassVisitor}.
- *
- * @param cv the {@link ClassVisitor} to which this visitor delegates calls.
- * May be <tt>null</tt>.
- * @param p the object that actually converts visit events into text.
- * @param pw the print writer to be used to print the class. May be null if
- * you simply want to use the result via
- * {@link Printer#getText()}, instead of printing it.
+ *
+ * @param cv
+ * the {@link ClassVisitor} to which this visitor delegates
+ * calls. May be <tt>null</tt>.
+ * @param p
+ * the object that actually converts visit events into text.
+ * @param pw
+ * the print writer to be used to print the class. May be null if
+ * you simply want to use the result via
+ * {@link Printer#getText()}, instead of printing it.
*/
- public TraceClassVisitor(
- final ClassVisitor cv,
- final Printer p,
- final PrintWriter pw)
- {
+ public TraceClassVisitor(final ClassVisitor cv, final Printer p,
+ final PrintWriter pw) {
super(Opcodes.ASM4, cv);
this.pw = pw;
this.p = p;
}
@Override
- public void visit(
- final int version,
- final int access,
- final String name,
- final String signature,
- final String superName,
- final String[] interfaces)
- {
+ public void visit(final int version, final int access, final String name,
+ final String signature, final String superName,
+ final String[] interfaces) {
p.visit(version, access, name, signature, superName, interfaces);
super.visit(version, access, name, signature, superName, interfaces);
}
@@ -141,20 +150,15 @@ public final class TraceClassVisitor extends ClassVisitor {
}
@Override
- public void visitOuterClass(
- final String owner,
- final String name,
- final String desc)
- {
+ public void visitOuterClass(final String owner, final String name,
+ final String desc) {
p.visitOuterClass(owner, name, desc);
super.visitOuterClass(owner, name, desc);
}
@Override
- public AnnotationVisitor visitAnnotation(
- final String desc,
- final boolean visible)
- {
+ public AnnotationVisitor visitAnnotation(final String desc,
+ final boolean visible) {
Printer p = this.p.visitClassAnnotation(desc, visible);
AnnotationVisitor av = cv == null ? null : cv.visitAnnotation(desc,
visible);
@@ -168,55 +172,28 @@ public final class TraceClassVisitor extends ClassVisitor {
}
@Override
- public void visitInnerClass(
- final String name,
- final String outerName,
- final String innerName,
- final int access)
- {
+ public void visitInnerClass(final String name, final String outerName,
+ final String innerName, final int access) {
p.visitInnerClass(name, outerName, innerName, access);
super.visitInnerClass(name, outerName, innerName, access);
}
@Override
- public FieldVisitor visitField(
- final int access,
- final String name,
- final String desc,
- final String signature,
- final Object value)
- {
- Printer p = this.p.visitField(access,
- name,
- desc,
- signature,
- value);
- FieldVisitor fv = cv == null ? null : cv.visitField(access,
- name,
- desc,
- signature,
- value);
+ public FieldVisitor visitField(final int access, final String name,
+ final String desc, final String signature, final Object value) {
+ Printer p = this.p.visitField(access, name, desc, signature, value);
+ FieldVisitor fv = cv == null ? null : cv.visitField(access, name, desc,
+ signature, value);
return new TraceFieldVisitor(fv, p);
}
@Override
- public MethodVisitor visitMethod(
- final int access,
- final String name,
- final String desc,
- final String signature,
- final String[] exceptions)
- {
- Printer p = this.p.visitMethod(access,
- name,
- desc,
- signature,
- exceptions);
- MethodVisitor mv = cv == null ? null : cv.visitMethod(access,
- name,
- desc,
- signature,
+ public MethodVisitor visitMethod(final int access, final String name,
+ final String desc, final String signature, final String[] exceptions) {
+ Printer p = this.p.visitMethod(access, name, desc, signature,
exceptions);
+ MethodVisitor mv = cv == null ? null : cv.visitMethod(access, name,
+ desc, signature, exceptions);
return new TraceMethodVisitor(mv, p);
}
diff --git a/src/asm/scala/tools/asm/util/TraceFieldVisitor.java b/src/asm/scala/tools/asm/util/TraceFieldVisitor.java
index f537e83be1..9547a70008 100644
--- a/src/asm/scala/tools/asm/util/TraceFieldVisitor.java
+++ b/src/asm/scala/tools/asm/util/TraceFieldVisitor.java
@@ -37,7 +37,7 @@ import scala.tools.asm.Opcodes;
/**
* A {@link FieldVisitor} that prints the fields it visits with a
* {@link Printer}.
- *
+ *
* @author Eric Bruneton
*/
public final class TraceFieldVisitor extends FieldVisitor {
@@ -52,12 +52,10 @@ public final class TraceFieldVisitor extends FieldVisitor {
super(Opcodes.ASM4, fv);
this.p = p;
}
-
+
@Override
- public AnnotationVisitor visitAnnotation(
- final String desc,
- final boolean visible)
- {
+ public AnnotationVisitor visitAnnotation(final String desc,
+ final boolean visible) {
Printer p = this.p.visitFieldAnnotation(desc, visible);
AnnotationVisitor av = fv == null ? null : fv.visitAnnotation(desc,
visible);
diff --git a/src/asm/scala/tools/asm/util/TraceMethodVisitor.java b/src/asm/scala/tools/asm/util/TraceMethodVisitor.java
index 9aabf2079e..9034567c8f 100644
--- a/src/asm/scala/tools/asm/util/TraceMethodVisitor.java
+++ b/src/asm/scala/tools/asm/util/TraceMethodVisitor.java
@@ -56,10 +56,8 @@ public final class TraceMethodVisitor extends MethodVisitor {
}
@Override
- public AnnotationVisitor visitAnnotation(
- final String desc,
- final boolean visible)
- {
+ public AnnotationVisitor visitAnnotation(final String desc,
+ final boolean visible) {
Printer p = this.p.visitMethodAnnotation(desc, visible);
AnnotationVisitor av = mv == null ? null : mv.visitAnnotation(desc,
visible);
@@ -80,17 +78,11 @@ public final class TraceMethodVisitor extends MethodVisitor {
}
@Override
- public AnnotationVisitor visitParameterAnnotation(
- final int parameter,
- final String desc,
- final boolean visible)
- {
- Printer p = this.p.visitParameterAnnotation(parameter,
- desc,
- visible);
- AnnotationVisitor av = mv == null
- ? null
- : mv.visitParameterAnnotation(parameter, desc, visible);
+ public AnnotationVisitor visitParameterAnnotation(final int parameter,
+ final String desc, final boolean visible) {
+ Printer p = this.p.visitParameterAnnotation(parameter, desc, visible);
+ AnnotationVisitor av = mv == null ? null : mv.visitParameterAnnotation(
+ parameter, desc, visible);
return new TraceAnnotationVisitor(av, p);
}
@@ -101,13 +93,8 @@ public final class TraceMethodVisitor extends MethodVisitor {
}
@Override
- public void visitFrame(
- final int type,
- final int nLocal,
- final Object[] local,
- final int nStack,
- final Object[] stack)
- {
+ public void visitFrame(final int type, final int nLocal,
+ final Object[] local, final int nStack, final Object[] stack) {
p.visitFrame(type, nLocal, local, nStack, stack);
super.visitFrame(type, nLocal, local, nStack, stack);
}
@@ -137,34 +124,22 @@ public final class TraceMethodVisitor extends MethodVisitor {
}
@Override
- public void visitFieldInsn(
- final int opcode,
- final String owner,
- final String name,
- final String desc)
- {
+ public void visitFieldInsn(final int opcode, final String owner,
+ final String name, final String desc) {
p.visitFieldInsn(opcode, owner, name, desc);
super.visitFieldInsn(opcode, owner, name, desc);
}
@Override
- public void visitMethodInsn(
- final int opcode,
- final String owner,
- final String name,
- final String desc)
- {
+ public void visitMethodInsn(final int opcode, final String owner,
+ final String name, final String desc) {
p.visitMethodInsn(opcode, owner, name, desc);
super.visitMethodInsn(opcode, owner, name, desc);
}
@Override
- public void visitInvokeDynamicInsn(
- String name,
- String desc,
- Handle bsm,
- Object... bsmArgs)
- {
+ public void visitInvokeDynamicInsn(String name, String desc, Handle bsm,
+ Object... bsmArgs) {
p.visitInvokeDynamicInsn(name, desc, bsm, bsmArgs);
super.visitInvokeDynamicInsn(name, desc, bsm, bsmArgs);
}
@@ -194,22 +169,15 @@ public final class TraceMethodVisitor extends MethodVisitor {
}
@Override
- public void visitTableSwitchInsn(
- final int min,
- final int max,
- final Label dflt,
- final Label... labels)
- {
+ public void visitTableSwitchInsn(final int min, final int max,
+ final Label dflt, final Label... labels) {
p.visitTableSwitchInsn(min, max, dflt, labels);
super.visitTableSwitchInsn(min, max, dflt, labels);
}
@Override
- public void visitLookupSwitchInsn(
- final Label dflt,
- final int[] keys,
- final Label[] labels)
- {
+ public void visitLookupSwitchInsn(final Label dflt, final int[] keys,
+ final Label[] labels) {
p.visitLookupSwitchInsn(dflt, keys, labels);
super.visitLookupSwitchInsn(dflt, keys, labels);
}
@@ -221,25 +189,16 @@ public final class TraceMethodVisitor extends MethodVisitor {
}
@Override
- public void visitTryCatchBlock(
- final Label start,
- final Label end,
- final Label handler,
- final String type)
- {
+ public void visitTryCatchBlock(final Label start, final Label end,
+ final Label handler, final String type) {
p.visitTryCatchBlock(start, end, handler, type);
super.visitTryCatchBlock(start, end, handler, type);
}
@Override
- public void visitLocalVariable(
- final String name,
- final String desc,
- final String signature,
- final Label start,
- final Label end,
- final int index)
- {
+ public void visitLocalVariable(final String name, final String desc,
+ final String signature, final Label start, final Label end,
+ final int index) {
p.visitLocalVariable(name, desc, signature, start, end, index);
super.visitLocalVariable(name, desc, signature, start, end, index);
}
diff --git a/src/asm/scala/tools/asm/util/TraceSignatureVisitor.java b/src/asm/scala/tools/asm/util/TraceSignatureVisitor.java
index a37b759811..1e23c7ef1a 100644
--- a/src/asm/scala/tools/asm/util/TraceSignatureVisitor.java
+++ b/src/asm/scala/tools/asm/util/TraceSignatureVisitor.java
@@ -117,8 +117,7 @@ public final class TraceSignatureVisitor extends SignatureVisitor {
@Override
public SignatureVisitor visitInterface() {
- separator = seenInterface ? ", " : isInterface
- ? " extends "
+ separator = seenInterface ? ", " : isInterface ? " extends "
: " implements ";
seenInterface = true;
startType();
@@ -165,34 +164,34 @@ public final class TraceSignatureVisitor extends SignatureVisitor {
@Override
public void visitBaseType(final char descriptor) {
switch (descriptor) {
- case 'V':
- declaration.append("void");
- break;
- case 'B':
- declaration.append("byte");
- break;
- case 'J':
- declaration.append("long");
- break;
- case 'Z':
- declaration.append("boolean");
- break;
- case 'I':
- declaration.append("int");
- break;
- case 'S':
- declaration.append("short");
- break;
- case 'C':
- declaration.append("char");
- break;
- case 'F':
- declaration.append("float");
- break;
- // case 'D':
- default:
- declaration.append("double");
- break;
+ case 'V':
+ declaration.append("void");
+ break;
+ case 'B':
+ declaration.append("byte");
+ break;
+ case 'J':
+ declaration.append("long");
+ break;
+ case 'Z':
+ declaration.append("boolean");
+ break;
+ case 'I':
+ declaration.append("int");
+ break;
+ case 'S':
+ declaration.append("short");
+ break;
+ case 'C':
+ declaration.append("char");
+ break;
+ case 'F':
+ declaration.append("float");
+ break;
+ // case 'D':
+ default:
+ declaration.append("double");
+ break;
}
endType();
}
diff --git a/src/compiler/scala/reflect/macros/runtime/Enclosures.scala b/src/compiler/scala/reflect/macros/runtime/Enclosures.scala
index be5f2dbe83..d9f337b5ba 100644
--- a/src/compiler/scala/reflect/macros/runtime/Enclosures.scala
+++ b/src/compiler/scala/reflect/macros/runtime/Enclosures.scala
@@ -5,7 +5,6 @@ trait Enclosures {
self: Context =>
import universe._
- import mirror._
private def site = callsiteTyper.context
private def enclTrees = site.enclosingContextChain map (_.tree)
diff --git a/src/compiler/scala/reflect/macros/runtime/ExprUtils.scala b/src/compiler/scala/reflect/macros/runtime/ExprUtils.scala
index 672699f00e..a719beed97 100644
--- a/src/compiler/scala/reflect/macros/runtime/ExprUtils.scala
+++ b/src/compiler/scala/reflect/macros/runtime/ExprUtils.scala
@@ -5,7 +5,6 @@ trait ExprUtils {
self: Context =>
import universe._
- import mirror._
def literalNull = Expr[Null](Literal(Constant(null)))(TypeTag.Null)
diff --git a/src/compiler/scala/reflect/reify/Errors.scala b/src/compiler/scala/reflect/reify/Errors.scala
index 7c66d5b9eb..3a68794c97 100644
--- a/src/compiler/scala/reflect/reify/Errors.scala
+++ b/src/compiler/scala/reflect/reify/Errors.scala
@@ -7,7 +7,6 @@ trait Errors {
self: Reifier =>
import global._
- import definitions._
def defaultErrorPosition = {
val stack = currents collect { case t: Tree if t.pos != NoPosition => t.pos }
@@ -22,11 +21,6 @@ trait Errors {
throw new ReificationException(defaultErrorPosition, msg)
}
- def CannotReifySymbol(sym: Symbol) = {
- val msg = "implementation restriction: cannot reify symbol %s (%s)".format(sym, sym.accurateKindString)
- throw new ReificationException(defaultErrorPosition, msg)
- }
-
def CannotReifyWeakType(details: Any) = {
val msg = "cannot create a TypeTag" + details + ": use WeakTypeTag instead"
throw new ReificationException(defaultErrorPosition, msg)
diff --git a/src/compiler/scala/reflect/reify/Phases.scala b/src/compiler/scala/reflect/reify/Phases.scala
index 1710cae2a5..d43532090c 100644
--- a/src/compiler/scala/reflect/reify/Phases.scala
+++ b/src/compiler/scala/reflect/reify/Phases.scala
@@ -10,7 +10,6 @@ trait Phases extends Reshape
self: Reifier =>
import global._
- import definitions._
private var alreadyRun = false
@@ -26,7 +25,7 @@ trait Phases extends Reshape
if (reifyDebug) println("[reshape phase]")
tree = reshape.transform(tree)
if (reifyDebug) println("[interlude]")
- if (reifyDebug) println("reifee = " + (if (opt.showTrees) "\n" + nodePrinters.nodeToString(tree).trim else tree.toString))
+ if (reifyDebug) println("reifee = " + (if (settings.Xshowtrees.value || settings.XshowtreesCompact.value || settings.XshowtreesStringified.value) "\n" + nodePrinters.nodeToString(tree).trim else tree.toString))
if (reifyDebug) println("[calculate phase]")
calculate.traverse(tree)
@@ -41,4 +40,4 @@ trait Phases extends Reshape
result
}
-} \ No newline at end of file
+}
diff --git a/src/compiler/scala/reflect/reify/Reifier.scala b/src/compiler/scala/reflect/reify/Reifier.scala
index 47669f57b0..b3224b1aa6 100644
--- a/src/compiler/scala/reflect/reify/Reifier.scala
+++ b/src/compiler/scala/reflect/reify/Reifier.scala
@@ -57,7 +57,7 @@ abstract class Reifier extends States
val result = reifee match {
case tree: Tree =>
- reifyTrace("reifying = ")(if (opt.showTrees) "\n" + nodePrinters.nodeToString(tree).trim else tree.toString)
+ reifyTrace("reifying = ")(if (settings.Xshowtrees.value || settings.XshowtreesCompact.value || settings.XshowtreesStringified.value) "\n" + nodePrinters.nodeToString(tree).trim else tree.toString)
reifyTrace("reifee is located at: ")(tree.pos)
reifyTrace("universe = ")(universe)
reifyTrace("mirror = ")(mirror)
diff --git a/src/compiler/scala/reflect/reify/States.scala b/src/compiler/scala/reflect/reify/States.scala
index 58455c9f3c..29bfa19845 100644
--- a/src/compiler/scala/reflect/reify/States.scala
+++ b/src/compiler/scala/reflect/reify/States.scala
@@ -4,7 +4,6 @@ trait States {
self: Reifier =>
import global._
- import definitions._
/** Encapsulates reifier state
*
diff --git a/src/compiler/scala/reflect/reify/Taggers.scala b/src/compiler/scala/reflect/reify/Taggers.scala
index cbaee41890..af0341fd38 100644
--- a/src/compiler/scala/reflect/reify/Taggers.scala
+++ b/src/compiler/scala/reflect/reify/Taggers.scala
@@ -8,7 +8,6 @@ abstract class Taggers {
import c.universe._
import definitions._
- import treeBuild._
val coreTags = Map(
ByteTpe -> nme.Byte,
diff --git a/src/compiler/scala/reflect/reify/codegen/GenAnnotationInfos.scala b/src/compiler/scala/reflect/reify/codegen/GenAnnotationInfos.scala
index dec491aabe..5a454e1e07 100644
--- a/src/compiler/scala/reflect/reify/codegen/GenAnnotationInfos.scala
+++ b/src/compiler/scala/reflect/reify/codegen/GenAnnotationInfos.scala
@@ -5,7 +5,6 @@ trait GenAnnotationInfos {
self: Reifier =>
import global._
- import definitions._
// usually annotations are reified as their originals from Modifiers
// however, when reifying free and tough types, we're forced to reify annotation infos as is
@@ -52,4 +51,4 @@ trait GenAnnotationInfos {
val reifiedAssocs = ann.assocs map (assoc => scalaFactoryCall(nme.Tuple2, reify(assoc._1), reifyClassfileAnnotArg(assoc._2)))
mirrorFactoryCall(nme.Annotation, reify(ann.atp), mkList(reifiedArgs), mkListMap(reifiedAssocs))
}
-} \ No newline at end of file
+}
diff --git a/src/compiler/scala/reflect/reify/codegen/GenNames.scala b/src/compiler/scala/reflect/reify/codegen/GenNames.scala
index 4abf88f475..7c3c1d1149 100644
--- a/src/compiler/scala/reflect/reify/codegen/GenNames.scala
+++ b/src/compiler/scala/reflect/reify/codegen/GenNames.scala
@@ -5,10 +5,9 @@ trait GenNames {
self: Reifier =>
import global._
- import definitions._
def reifyName(name: Name) = {
val factory = if (name.isTypeName) nme.nmeNewTypeName else nme.nmeNewTermName
mirrorCall(factory, Literal(Constant(name.toString)))
}
-} \ No newline at end of file
+}
diff --git a/src/compiler/scala/reflect/reify/codegen/GenPositions.scala b/src/compiler/scala/reflect/reify/codegen/GenPositions.scala
index 8c5db04454..1d151c5135 100644
--- a/src/compiler/scala/reflect/reify/codegen/GenPositions.scala
+++ b/src/compiler/scala/reflect/reify/codegen/GenPositions.scala
@@ -5,7 +5,6 @@ trait GenPositions {
self: Reifier =>
import global._
- import definitions._
// we do not reify positions because this inflates resulting trees, but doesn't buy as anything
// where would one use positions? right, in error messages
@@ -14,4 +13,4 @@ trait GenPositions {
// however both macros and toolboxes have their own means to report errors in synthetic trees
def reifyPosition(pos: Position): Tree =
reifyMirrorObject(NoPosition)
-} \ No newline at end of file
+}
diff --git a/src/compiler/scala/reflect/reify/codegen/GenSymbols.scala b/src/compiler/scala/reflect/reify/codegen/GenSymbols.scala
index 22a834d2e4..731aab93b8 100644
--- a/src/compiler/scala/reflect/reify/codegen/GenSymbols.scala
+++ b/src/compiler/scala/reflect/reify/codegen/GenSymbols.scala
@@ -5,7 +5,6 @@ trait GenSymbols {
self: Reifier =>
import global._
- import definitions._
/** Symbol table of the reifee.
*
@@ -99,7 +98,7 @@ trait GenSymbols {
def reifyFreeTerm(binding: Tree): Tree =
reifyIntoSymtab(binding.symbol) { sym =>
if (reifyDebug) println("Free term" + (if (sym.isCapturedVariable) " (captured)" else "") + ": " + sym + "(" + sym.accurateKindString + ")")
- val name = newTermName(nme.REIFY_FREE_PREFIX + sym.name + (if (sym.isType) nme.REIFY_FREE_THIS_SUFFIX else ""))
+ val name = newTermName("" + nme.REIFY_FREE_PREFIX + sym.name + (if (sym.isType) nme.REIFY_FREE_THIS_SUFFIX else ""))
if (sym.isCapturedVariable) {
assert(binding.isInstanceOf[Ident], showRaw(binding))
val capturedBinding = referenceCapturedVariable(sym)
@@ -113,14 +112,14 @@ trait GenSymbols {
reifyIntoSymtab(binding.symbol) { sym =>
if (reifyDebug) println("Free type: %s (%s)".format(sym, sym.accurateKindString))
state.reificationIsConcrete = false
- val name = newTermName(nme.REIFY_FREE_PREFIX + sym.name)
+ val name: TermName = nme.REIFY_FREE_PREFIX append sym.name
Reification(name, binding, mirrorBuildCall(nme.newFreeType, reify(sym.name.toString), mirrorBuildCall(nme.flagsFromBits, reify(sym.flags)), reify(origin(sym))))
}
def reifySymDef(sym: Symbol): Tree =
reifyIntoSymtab(sym) { sym =>
if (reifyDebug) println("Sym def: %s (%s)".format(sym, sym.accurateKindString))
- val name = newTermName(nme.REIFY_SYMDEF_PREFIX + sym.name)
+ val name: TermName = nme.REIFY_SYMDEF_PREFIX append sym.name
def reifiedOwner = if (sym.owner.isLocatable) reify(sym.owner) else reifySymDef(sym.owner)
Reification(name, Ident(sym), mirrorBuildCall(nme.newNestedSymbol, reifiedOwner, reify(sym.name), reify(sym.pos), mirrorBuildCall(nme.flagsFromBits, reify(sym.flags)), reify(sym.isClass)))
}
@@ -144,7 +143,7 @@ trait GenSymbols {
val reification = reificode(sym)
import reification.{name, binding}
val tree = reification.tree updateAttachment ReifyBindingAttachment(binding)
- state.symtab += (sym, name, tree)
+ state.symtab += (sym, name.toTermName, tree)
}
fromSymtab
}
diff --git a/src/compiler/scala/reflect/reify/codegen/GenTrees.scala b/src/compiler/scala/reflect/reify/codegen/GenTrees.scala
index 31974b5b76..f60089c935 100644
--- a/src/compiler/scala/reflect/reify/codegen/GenTrees.scala
+++ b/src/compiler/scala/reflect/reify/codegen/GenTrees.scala
@@ -66,7 +66,7 @@ trait GenTrees {
// usually we don't reify symbols/types, because they can be re-inferred during subsequent reflective compilation
// however, reification of AnnotatedTypes is special. see ``reifyType'' to find out why.
- if (reifyTreeSymbols && tree.hasSymbol) {
+ if (reifyTreeSymbols && tree.hasSymbolField) {
if (reifyDebug) println("reifying symbol %s for tree %s".format(tree.symbol, tree))
rtree = mirrorBuildCall(nme.setSymbol, rtree, reify(tree.symbol))
}
@@ -88,8 +88,8 @@ trait GenTrees {
// see ``Metalevels'' for more info about metalevel breaches
// and about how we deal with splices that contain them
- val isMetalevelBreach = splicee exists (sub => sub.hasSymbol && sub.symbol != NoSymbol && sub.symbol.metalevel > 0)
- val isRuntimeEval = splicee exists (sub => sub.hasSymbol && sub.symbol == ExprSplice)
+ val isMetalevelBreach = splicee exists (sub => sub.hasSymbolField && sub.symbol != NoSymbol && sub.symbol.metalevel > 0)
+ val isRuntimeEval = splicee exists (sub => sub.hasSymbolField && sub.symbol == ExprSplice)
if (isMetalevelBreach || isRuntimeEval) {
// we used to convert dynamic splices into runtime evals transparently, but we no longer do that
// why? see comments in ``Metalevels''
diff --git a/src/compiler/scala/reflect/reify/codegen/GenTypes.scala b/src/compiler/scala/reflect/reify/codegen/GenTypes.scala
index 7aa87dc2f8..ca44938f50 100644
--- a/src/compiler/scala/reflect/reify/codegen/GenTypes.scala
+++ b/src/compiler/scala/reflect/reify/codegen/GenTypes.scala
@@ -74,7 +74,6 @@ trait GenTypes {
if (reifyDebug) println("splicing " + tpe)
val tagFlavor = if (concrete) tpnme.TypeTag.toString else tpnme.WeakTypeTag.toString
- val key = (tagFlavor, tpe.typeSymbol)
// if this fails, it might produce the dreaded "erroneous or inaccessible type" error
// to find out the whereabouts of the error run scalac with -Ydebug
if (reifyDebug) println("launching implicit search for %s.%s[%s]".format(universe, tagFlavor, tpe))
diff --git a/src/compiler/scala/reflect/reify/codegen/GenUtils.scala b/src/compiler/scala/reflect/reify/codegen/GenUtils.scala
index 21db93d8f5..e0570d61f2 100644
--- a/src/compiler/scala/reflect/reify/codegen/GenUtils.scala
+++ b/src/compiler/scala/reflect/reify/codegen/GenUtils.scala
@@ -5,7 +5,6 @@ trait GenUtils {
self: Reifier =>
import global._
- import definitions._
def reifyList(xs: List[Any]): Tree =
mkList(xs map reify)
@@ -31,38 +30,32 @@ trait GenUtils {
def call(fname: String, args: Tree*): Tree =
Apply(termPath(fname), args.toList)
- def mirrorSelect(name: String): Tree =
- termPath(nme.UNIVERSE_PREFIX + name)
+ def mirrorSelect(name: String): Tree = termPath(nme.UNIVERSE_PREFIX + name)
+ def mirrorSelect(name: TermName): Tree = mirrorSelect(name.toString)
- def mirrorMirrorSelect(name: String): Tree =
- termPath(nme.MIRROR_PREFIX + name)
+ def mirrorMirrorSelect(name: TermName): Tree =
+ termPath("" + nme.MIRROR_PREFIX + name)
def mirrorCall(name: TermName, args: Tree*): Tree =
- call("" + (nme.UNIVERSE_PREFIX append name), args: _*)
-
- def mirrorCall(name: String, args: Tree*): Tree =
- call(nme.UNIVERSE_PREFIX + name, args: _*)
+ call("" + nme.UNIVERSE_PREFIX + name, args: _*)
def mirrorBuildCall(name: TermName, args: Tree*): Tree =
- call("" + (nme.UNIVERSE_BUILD_PREFIX append name), args: _*)
-
- def mirrorBuildCall(name: String, args: Tree*): Tree =
- call(nme.UNIVERSE_BUILD_PREFIX + name, args: _*)
+ call("" + nme.UNIVERSE_BUILD_PREFIX + name, args: _*)
def mirrorMirrorCall(name: TermName, args: Tree*): Tree =
- call("" + (nme.MIRROR_PREFIX append name), args: _*)
-
- def mirrorMirrorCall(name: String, args: Tree*): Tree =
- call(nme.MIRROR_PREFIX + name, args: _*)
+ call("" + nme.MIRROR_PREFIX + name, args: _*)
def mirrorFactoryCall(value: Product, args: Tree*): Tree =
mirrorFactoryCall(value.productPrefix, args: _*)
- def mirrorFactoryCall(prefix: String, args: Tree*): Tree =
- mirrorCall(prefix, args: _*)
+ def mirrorFactoryCall(prefix: TermName, args: Tree*): Tree =
+ mirrorCall("" + prefix, args: _*)
+
+ def scalaFactoryCall(name: TermName, args: Tree*): Tree =
+ call(s"scala.$name.apply", args: _*)
def scalaFactoryCall(name: String, args: Tree*): Tree =
- call("scala." + name + ".apply", args: _*)
+ scalaFactoryCall(name: TermName, args: _*)
def mkList(args: List[Tree]): Tree =
scalaFactoryCall("collection.immutable.List", args: _*)
@@ -88,22 +81,6 @@ trait GenUtils {
/** An (unreified) path that refers to term definition with given fully qualified name */
def termPath(fullname: String): Tree = path(fullname, newTermName)
- /** An (unreified) path that refers to type definition with given fully qualified name */
- def typePath(fullname: String): Tree = path(fullname, newTypeName)
-
- def isTough(tpe: Type) = {
- def isTough(tpe: Type) = tpe match {
- case _: RefinedType => true
- case _: ExistentialType => true
- case _: ClassInfoType => true
- case _: MethodType => true
- case _: PolyType => true
- case _ => false
- }
-
- tpe != null && (tpe exists isTough)
- }
-
object TypedOrAnnotated {
def unapply(tree: Tree): Option[Tree] = tree match {
case ty @ Typed(_, _) =>
@@ -115,15 +92,6 @@ trait GenUtils {
}
}
- def isAnnotated(tpe: Type) = {
- def isAnnotated(tpe: Type) = tpe match {
- case _: AnnotatedType => true
- case _ => false
- }
-
- tpe != null && (tpe exists isAnnotated)
- }
-
def isSemiConcreteTypeMember(tpe: Type) = tpe match {
case TypeRef(SingleType(_, _), sym, _) if sym.isAbstractType && !sym.isExistential => true
case _ => false
@@ -142,4 +110,4 @@ trait GenUtils {
if (origin == "") origin = "of unknown origin"
origin
}
-} \ No newline at end of file
+}
diff --git a/src/compiler/scala/reflect/reify/package.scala b/src/compiler/scala/reflect/reify/package.scala
index 55f8684df2..7be57c0cb7 100644
--- a/src/compiler/scala/reflect/reify/package.scala
+++ b/src/compiler/scala/reflect/reify/package.scala
@@ -1,11 +1,10 @@
package scala.reflect
-import scala.language.implicitConversions
-import scala.reflect.macros.{Context, ReificationException, UnexpectedReificationException}
+import scala.reflect.macros.ReificationException
import scala.tools.nsc.Global
package object reify {
- private def mkReifier(global1: Global)(typer: global1.analyzer.Typer, universe: global1.Tree, mirror: global1.Tree, reifee: Any, concrete: Boolean = false): Reifier { val global: global1.type } = {
+ private def mkReifier(global1: Global)(typer: global1.analyzer.Typer, universe: global1.Tree, mirror: global1.Tree, reifee: Any, concrete: Boolean): Reifier { val global: global1.type } = {
val typer1: typer.type = typer
val universe1: universe.type = universe
val mirror1: mirror.type = mirror
@@ -24,7 +23,8 @@ package object reify {
private[reify] def mkDefaultMirrorRef(global: Global)(universe: global.Tree, typer0: global.analyzer.Typer): global.Tree = {
import global._
- import definitions._
+ import definitions.JavaUniverseClass
+
val enclosingErasure = {
val rClassTree = reifyEnclosingRuntimeClass(global)(typer0)
// HACK around SI-6259
@@ -71,7 +71,6 @@ package object reify {
// a class/object body, this will return an EmptyTree.
def reifyEnclosingRuntimeClass(global: Global)(typer0: global.analyzer.Typer): global.Tree = {
import global._
- import definitions._
def isThisInScope = typer0.context.enclosingContextChain exists (_.tree.isInstanceOf[ImplDef])
if (isThisInScope) {
val enclosingClasses = typer0.context.enclosingContextChain map (_.tree) collect { case classDef: ClassDef => classDef }
diff --git a/src/compiler/scala/reflect/reify/phases/Calculate.scala b/src/compiler/scala/reflect/reify/phases/Calculate.scala
index 4d1e22abe7..5566fd7a77 100644
--- a/src/compiler/scala/reflect/reify/phases/Calculate.scala
+++ b/src/compiler/scala/reflect/reify/phases/Calculate.scala
@@ -5,7 +5,6 @@ trait Calculate {
self: Reifier =>
import global._
- import definitions._
implicit class RichCalculateSymbol(sym: Symbol) {
def metalevel: Int = { assert(sym != null && sym != NoSymbol); localSymbols.getOrElse(sym, 0) }
diff --git a/src/compiler/scala/reflect/reify/phases/Metalevels.scala b/src/compiler/scala/reflect/reify/phases/Metalevels.scala
index fbbd12a42f..cccf080dbf 100644
--- a/src/compiler/scala/reflect/reify/phases/Metalevels.scala
+++ b/src/compiler/scala/reflect/reify/phases/Metalevels.scala
@@ -1,11 +1,12 @@
package scala.reflect.reify
package phases
+import scala.collection.{ mutable }
+
trait Metalevels {
self: Reifier =>
import global._
- import definitions._
/**
* Makes sense of cross-stage bindings.
@@ -102,7 +103,7 @@ trait Metalevels {
*/
val metalevels = new Transformer {
var insideSplice = false
- var inlineableBindings = scala.collection.mutable.Map[TermName, Tree]()
+ val inlineableBindings = mutable.Map[TermName, Tree]()
def withinSplice[T](op: => T) = {
val old = insideSplice
@@ -124,7 +125,7 @@ trait Metalevels {
withinSplice { super.transform(TreeSplice(ReifiedTree(universe, mirror, symtab1, rtree, tpe, rtpe, concrete))) }
case TreeSplice(splicee) =>
if (reifyDebug) println("entering splice: " + splicee)
- val breaches = splicee filter (sub => sub.hasSymbol && sub.symbol != NoSymbol && sub.symbol.metalevel > 0)
+ val breaches = splicee filter (sub => sub.hasSymbolField && sub.symbol != NoSymbol && sub.symbol.metalevel > 0)
if (!insideSplice && breaches.nonEmpty) {
// we used to convert dynamic splices into runtime evals transparently, but we no longer do that
// why? see comments above
diff --git a/src/compiler/scala/reflect/reify/phases/Reify.scala b/src/compiler/scala/reflect/reify/phases/Reify.scala
index dc0028be38..2741785752 100644
--- a/src/compiler/scala/reflect/reify/phases/Reify.scala
+++ b/src/compiler/scala/reflect/reify/phases/Reify.scala
@@ -2,7 +2,6 @@ package scala.reflect.reify
package phases
import scala.runtime.ScalaRunTime.isAnyVal
-import scala.runtime.ScalaRunTime.isTuple
import scala.reflect.reify.codegen._
trait Reify extends GenSymbols
@@ -16,7 +15,6 @@ trait Reify extends GenSymbols
self: Reifier =>
import global._
- import definitions._
private object reifyStack {
def currents: List[Any] = state.reifyStack
@@ -56,4 +54,4 @@ trait Reify extends GenSymbols
case _ =>
throw new Error("reifee %s of type %s is not supported".format(reifee, reifee.getClass))
})
-} \ No newline at end of file
+}
diff --git a/src/compiler/scala/reflect/reify/phases/Reshape.scala b/src/compiler/scala/reflect/reify/phases/Reshape.scala
index 1b7509fdbe..75384ddce1 100644
--- a/src/compiler/scala/reflect/reify/phases/Reshape.scala
+++ b/src/compiler/scala/reflect/reify/phases/Reshape.scala
@@ -48,13 +48,13 @@ trait Reshape {
val Template(parents, self, body) = impl
var body1 = trimAccessors(classDef, reshapeLazyVals(body))
body1 = trimSyntheticCaseClassMembers(classDef, body1)
- var impl1 = Template(parents, self, body1).copyAttrs(impl)
+ val impl1 = Template(parents, self, body1).copyAttrs(impl)
ClassDef(mods, name, params, impl1).copyAttrs(classDef)
case moduledef @ ModuleDef(mods, name, impl) =>
val Template(parents, self, body) = impl
var body1 = trimAccessors(moduledef, reshapeLazyVals(body))
body1 = trimSyntheticCaseClassMembers(moduledef, body1)
- var impl1 = Template(parents, self, body1).copyAttrs(impl)
+ val impl1 = Template(parents, self, body1).copyAttrs(impl)
ModuleDef(mods, name, impl1).copyAttrs(moduledef)
case template @ Template(parents, self, body) =>
val discardedParents = parents collect { case tt: TypeTree => tt } filter isDiscarded
@@ -116,7 +116,6 @@ trait Reshape {
private def toPreTyperModifiers(mods: Modifiers, sym: Symbol) = {
if (!sym.annotations.isEmpty) {
- val Modifiers(flags, privateWithin, annotations) = mods
val postTyper = sym.annotations filter (_.original != EmptyTree)
if (reifyDebug && !postTyper.isEmpty) println("reify symbol annotations for: " + sym)
if (reifyDebug && !postTyper.isEmpty) println("originals are: " + sym.annotations)
@@ -252,10 +251,10 @@ trait Reshape {
val DefDef(mods0, name0, _, _, tpt0, rhs0) = ddef
val name1 = nme.dropLocalSuffix(name0)
val Modifiers(flags0, privateWithin0, annotations0) = mods0
- var flags1 = (flags0 & GetterFlags) & ~(STABLE | ACCESSOR | METHOD)
+ val flags1 = (flags0 & GetterFlags) & ~(STABLE | ACCESSOR | METHOD)
val mods1 = Modifiers(flags1, privateWithin0, annotations0) setPositions mods0.positions
val mods2 = toPreTyperModifiers(mods1, ddef.symbol)
- ValDef(mods2, name1, tpt0, extractRhs(rhs0))
+ ValDef(mods2, name1.toTermName, tpt0, extractRhs(rhs0))
}
private def trimAccessors(deff: Tree, stats: List[Tree]): List[Tree] = {
@@ -267,7 +266,7 @@ trait Reshape {
def detectBeanAccessors(prefix: String): Unit = {
if (defdef.name.startsWith(prefix)) {
- var name = defdef.name.toString.substring(prefix.length)
+ val name = defdef.name.toString.substring(prefix.length)
def uncapitalize(s: String) = if (s.length == 0) "" else { val chars = s.toCharArray; chars(0) = chars(0).toLower; new String(chars) }
def findValDef(name: String) = (symdefs.values collect { case vdef: ValDef if nme.dropLocalSuffix(vdef.name).toString == name => vdef }).headOption
val valdef = findValDef(name).orElse(findValDef(uncapitalize(name))).orNull
@@ -279,11 +278,11 @@ trait Reshape {
detectBeanAccessors("is")
});
- var stats1 = stats flatMap {
+ val stats1 = stats flatMap {
case vdef @ ValDef(mods, name, tpt, rhs) if !mods.isLazy =>
val mods1 = if (accessors.contains(vdef)) {
val ddef = accessors(vdef)(0) // any accessor will do
- val Modifiers(flags, privateWithin, annotations) = mods
+ val Modifiers(flags, _, annotations) = mods
var flags1 = flags & ~LOCAL
if (!ddef.symbol.isPrivate) flags1 = flags1 & ~PRIVATE
val privateWithin1 = ddef.mods.privateWithin
@@ -294,7 +293,7 @@ trait Reshape {
}
val mods2 = toPreTyperModifiers(mods1, vdef.symbol)
val name1 = nme.dropLocalSuffix(name)
- val vdef1 = ValDef(mods2, name1, tpt, rhs)
+ val vdef1 = ValDef(mods2, name1.toTermName, tpt, rhs)
if (reifyDebug) println("resetting visibility of field: %s => %s".format(vdef, vdef1))
Some(vdef1) // no copyAttrs here, because new ValDef and old symbols are now out of sync
case ddef: DefDef if !ddef.mods.isLazy =>
@@ -326,7 +325,8 @@ trait Reshape {
case Some(ddef) =>
toPreTyperLazyVal(ddef)
case None =>
- CannotReifyInvalidLazyVal(vdef)
+ if (reifyDebug) println("couldn't find corresponding lazy val accessor")
+ vdef
}
if (reifyDebug) println(s"reconstructed lazy val is $vdef1")
vdef1::Nil
diff --git a/src/compiler/scala/reflect/reify/utils/Extractors.scala b/src/compiler/scala/reflect/reify/utils/Extractors.scala
index ebbcb95481..254cb02ee6 100644
--- a/src/compiler/scala/reflect/reify/utils/Extractors.scala
+++ b/src/compiler/scala/reflect/reify/utils/Extractors.scala
@@ -187,7 +187,7 @@ trait Extractors {
Literal(Constant(origin: String)))))
if uref1.name == nme.UNIVERSE_SHORT && build1 == nme.build && newFreeTerm == nme.newFreeTerm &&
uref2.name == nme.UNIVERSE_SHORT && build2 == nme.build && flagsFromBits == nme.flagsFromBits =>
- Some(uref1, name, reifyBinding(tree), flags, origin)
+ Some((uref1, name, reifyBinding(tree), flags, origin))
case _ =>
None
}
@@ -204,7 +204,7 @@ trait Extractors {
Literal(Constant(origin: String)))))
if uref1.name == nme.UNIVERSE_SHORT && build1 == nme.build && newFreeType == nme.newFreeType &&
uref2.name == nme.UNIVERSE_SHORT && build2 == nme.build && flagsFromBits == nme.flagsFromBits =>
- Some(uref1, name, reifyBinding(tree), flags, origin)
+ Some((uref1, name, reifyBinding(tree), flags, origin))
case _ =>
None
}
diff --git a/src/compiler/scala/reflect/reify/utils/NodePrinters.scala b/src/compiler/scala/reflect/reify/utils/NodePrinters.scala
index aca18c7df7..86e50e0a68 100644
--- a/src/compiler/scala/reflect/reify/utils/NodePrinters.scala
+++ b/src/compiler/scala/reflect/reify/utils/NodePrinters.scala
@@ -11,8 +11,6 @@ trait NodePrinters {
self: Utils =>
import global._
- import definitions._
- import Flag._
object reifiedNodeToString extends (Tree => String) {
def apply(tree: Tree): String = {
@@ -25,8 +23,8 @@ trait NodePrinters {
// Rolling a full-fledged, robust TreePrinter would be several times more code.
// Also as of late we have tests that ensure that UX won't be broken by random changes to the reifier.
val lines = (tree.toString.split(EOL) drop 1 dropRight 1).toList splitAt 2
- var (List(universe, mirror), reification) = lines
- reification = (for (line <- reification) yield {
+ val (List(universe, mirror), reification0) = lines
+ val reification = (for (line <- reification0) yield {
var s = line substring 2
s = s.replace(nme.UNIVERSE_PREFIX.toString, "")
s = s.replace(".apply", "")
@@ -77,10 +75,10 @@ trait NodePrinters {
printout += universe.trim
if (mirrorIsUsed) printout += mirror.replace("Mirror[", "scala.reflect.api.Mirror[").trim
val imports = scala.collection.mutable.ListBuffer[String]();
- imports += nme.UNIVERSE_SHORT
+ imports += nme.UNIVERSE_SHORT.toString
// if (buildIsUsed) imports += nme.build
- if (mirrorIsUsed) imports += nme.MIRROR_SHORT
- if (flagsAreUsed) imports += nme.Flag
+ if (mirrorIsUsed) imports += nme.MIRROR_SHORT.toString
+ if (flagsAreUsed) imports += nme.Flag.toString
printout += s"""import ${imports map (_ + "._") mkString ", "}"""
val name = if (isExpr) "tree" else "tpe"
diff --git a/src/compiler/scala/reflect/reify/utils/SymbolTables.scala b/src/compiler/scala/reflect/reify/utils/SymbolTables.scala
index dbb0836e0a..5f8de9894f 100644
--- a/src/compiler/scala/reflect/reify/utils/SymbolTables.scala
+++ b/src/compiler/scala/reflect/reify/utils/SymbolTables.scala
@@ -8,8 +8,6 @@ trait SymbolTables {
self: Utils =>
import global._
- import definitions._
- import Flag._
class SymbolTable private[SymbolTable] (
private[SymbolTable] val symtab: immutable.ListMap[Symbol, Tree] = immutable.ListMap[Symbol, Tree](),
@@ -17,9 +15,6 @@ trait SymbolTables {
private[SymbolTable] val original: Option[List[Tree]] = None) {
def syms: List[Symbol] = symtab.keys.toList
- def isConcrete: Boolean = symtab.values forall (sym => !FreeTypeDef.unapply(sym).isDefined)
-
-// def aliases: Map[Symbol, List[TermName]] = aliases.distinct groupBy (_._1) mapValues (_ map (_._2))
def symDef(sym: Symbol): Tree =
symtab.getOrElse(sym, EmptyTree)
@@ -89,11 +84,6 @@ trait SymbolTables {
add(ValDef(NoMods, freshName(name0), TypeTree(), reification) updateAttachment bindingAttachment)
}
- private def add(sym: Symbol, name: TermName): SymbolTable = {
- if (!(syms contains sym)) error("cannot add an alias to a symbol not in the symbol table")
- add(sym, name, EmptyTree)
- }
-
private def remove(sym: Symbol): SymbolTable = {
val newSymtab = symtab - sym
val newAliases = aliases filter (_._1 != sym)
@@ -107,7 +97,7 @@ trait SymbolTables {
newSymtab = newSymtab map { case ((sym, tree)) =>
val ValDef(mods, primaryName, tpt, rhs) = tree
val tree1 =
- if (!(newAliases contains (sym, primaryName))) {
+ if (!(newAliases contains ((sym, primaryName)))) {
val primaryName1 = newAliases.find(_._1 == sym).get._2
ValDef(mods, primaryName1, tpt, rhs).copyAttrs(tree)
} else tree
@@ -143,7 +133,7 @@ trait SymbolTables {
var result = new SymbolTable(original = Some(encoded))
encoded foreach (entry => (entry.attachments.get[ReifyBindingAttachment], entry.attachments.get[ReifyAliasAttachment]) match {
case (Some(ReifyBindingAttachment(_)), _) => result += entry
- case (_, Some(ReifyAliasAttachment(sym, alias))) => result = new SymbolTable(result.symtab, result.aliases :+ (sym, alias))
+ case (_, Some(ReifyAliasAttachment(sym, alias))) => result = new SymbolTable(result.symtab, result.aliases :+ ((sym, alias)))
case _ => // do nothing, this is boilerplate that can easily be recreated by subsequent `result.encode`
})
result
@@ -214,4 +204,4 @@ trait SymbolTables {
}
}
}
-} \ No newline at end of file
+}
diff --git a/src/compiler/scala/tools/ant/Pack200Task.scala b/src/compiler/scala/tools/ant/Pack200Task.scala
index 255efe55ec..3180911414 100644
--- a/src/compiler/scala/tools/ant/Pack200Task.scala
+++ b/src/compiler/scala/tools/ant/Pack200Task.scala
@@ -99,8 +99,8 @@ class Pack200Task extends ScalaMatchingTask {
private def getFileList: List[File] = {
var files: List[File] = Nil
val fs = getImplicitFileSet
- var ds = fs.getDirectoryScanner(getProject())
- var dir = fs.getDir(getProject())
+ val ds = fs.getDirectoryScanner(getProject())
+ val dir = fs.getDir(getProject())
for (filename <- ds.getIncludedFiles()
if filename.toLowerCase.endsWith(".jar")) {
val file = new File(dir, filename)
diff --git a/src/compiler/scala/tools/ant/Scalac.scala b/src/compiler/scala/tools/ant/Scalac.scala
index 73d09e82ba..3b8ae202f6 100644
--- a/src/compiler/scala/tools/ant/Scalac.scala
+++ b/src/compiler/scala/tools/ant/Scalac.scala
@@ -19,6 +19,7 @@ import org.apache.tools.ant.util.facade.{FacadeTaskHelper,
ImplementationSpecificArgument}
import scala.tools.nsc.{Global, Settings, CompilerCommand}
+import scala.tools.nsc.interactive.RangePositions
import scala.tools.nsc.io.{Path => SPath}
import scala.tools.nsc.reporters.{Reporter, ConsoleReporter}
@@ -55,8 +56,6 @@ import scala.tools.nsc.reporters.{Reporter, ConsoleReporter}
* - `usejavacp`,
* - `failonerror`,
* - `scalacdebugging`,
- * - `assemname`,
- * - `assemrefs`.
*
* It also takes the following parameters as nested elements:
* - `src` (for `srcdir`),
@@ -99,7 +98,7 @@ class Scalac extends ScalaMatchingTask with ScalacShared {
/** Defines valid values for the `target` property. */
object Target extends PermissibleValue {
- val values = List("jvm-1.5", "jvm-1.5-fjbg", "jvm-1.5-asm", "jvm-1.6", "jvm-1.7", "msil")
+ val values = List("jvm-1.5", "jvm-1.6", "jvm-1.7")
}
/** Defines valid values for the `deprecation` and `unchecked` properties. */
@@ -169,11 +168,6 @@ class Scalac extends ScalaMatchingTask with ScalacShared {
/** Indicates whether compilation errors will fail the build; defaults to true. */
protected var failonerror: Boolean = true
- // Name of the output assembly (only relevant with -target:msil)
- protected var assemname: Option[String] = None
- // List of assemblies referenced by the program (only relevant with -target:msil)
- protected var assemrefs: Option[String] = None
-
/** Prints out the files being compiled by the scalac ant task
* (not only the number of files). */
protected var scalacDebugging: Boolean = false
@@ -420,9 +414,6 @@ class Scalac extends ScalaMatchingTask with ScalacShared {
* @param input The specified flag */
def setScalacdebugging(input: Boolean) { scalacDebugging = input }
- def setAssemname(input: String) { assemname = Some(input) }
- def setAssemrefs(input: String) { assemrefs = Some(input) }
-
/** Sets the `compilerarg` as a nested compilerarg Ant parameter.
* @return A compiler argument to be configured. */
def createCompilerArg(): ImplementationSpecificArgument = {
@@ -518,7 +509,10 @@ class Scalac extends ScalaMatchingTask with ScalacShared {
new Settings(error)
protected def newGlobal(settings: Settings, reporter: Reporter) =
- new Global(settings, reporter)
+ if (settings.Yrangepos.value)
+ new Global(settings, reporter) with RangePositions
+ else
+ new Global(settings, reporter)
/*============================================================================*\
** The big execute method **
@@ -612,9 +606,6 @@ class Scalac extends ScalaMatchingTask with ScalacShared {
if (!unchecked.isEmpty) settings.unchecked.value = unchecked.get
if (!usejavacp.isEmpty) settings.usejavacp.value = usejavacp.get
- if (!assemname.isEmpty) settings.assemname.value = assemname.get
- if (!assemrefs.isEmpty) settings.assemrefs.value = assemrefs.get
-
val jvmargs = scalacCompilerArgs.getArgs filter (_ startsWith "-J")
if (!jvmargs.isEmpty) settings.jvmargs.value = jvmargs.toList
val defines = scalacCompilerArgs.getArgs filter (_ startsWith "-D")
diff --git a/src/compiler/scala/tools/ant/sabbus/ScalacFork.scala b/src/compiler/scala/tools/ant/sabbus/ScalacFork.scala
index 9cdf484080..d5545fe76a 100644
--- a/src/compiler/scala/tools/ant/sabbus/ScalacFork.scala
+++ b/src/compiler/scala/tools/ant/sabbus/ScalacFork.scala
@@ -80,7 +80,7 @@ class ScalacFork extends ScalaMatchingTask with ScalacShared with TaskArgs {
private def createMapper() = {
val mapper = new GlobPatternMapper()
- val extension = if (isMSIL) "*.msil" else "*.class"
+ val extension = "*.class"
mapper setTo extension
mapper setFrom "*.scala"
@@ -104,9 +104,6 @@ class ScalacFork extends ScalaMatchingTask with ScalacShared with TaskArgs {
sourcePath foreach (settings.sourcepath = _)
settings.extraParams = extraArgsFlat
- if (isMSIL)
- settings.sourcedir = sourceDir
-
val mapper = createMapper()
val includedFiles: Array[File] =
diff --git a/src/compiler/scala/tools/ant/sabbus/Settings.scala b/src/compiler/scala/tools/ant/sabbus/Settings.scala
index fde61e9564..d0fefdaa03 100644
--- a/src/compiler/scala/tools/ant/sabbus/Settings.scala
+++ b/src/compiler/scala/tools/ant/sabbus/Settings.scala
@@ -10,7 +10,7 @@ package scala.tools.ant.sabbus
import java.io.File
-import org.apache.tools.ant.types.{Path, Reference}
+import org.apache.tools.ant.types.Path
class Settings {
diff --git a/src/compiler/scala/tools/ant/sabbus/TaskArgs.scala b/src/compiler/scala/tools/ant/sabbus/TaskArgs.scala
index 6bb1aaa306..b061bcf7fb 100644
--- a/src/compiler/scala/tools/ant/sabbus/TaskArgs.scala
+++ b/src/compiler/scala/tools/ant/sabbus/TaskArgs.scala
@@ -98,6 +98,4 @@ trait TaskArgs extends CompilationPathProperty {
val parts = a.getParts
if(parts eq null) Seq[String]() else parts.toSeq
}
-
- def isMSIL = compTarget exists (_ == "msil")
}
diff --git a/src/compiler/scala/tools/ant/templates/tool-unix.tmpl b/src/compiler/scala/tools/ant/templates/tool-unix.tmpl
index f1c6c52785..84ccaba749 100644
--- a/src/compiler/scala/tools/ant/templates/tool-unix.tmpl
+++ b/src/compiler/scala/tools/ant/templates/tool-unix.tmpl
@@ -102,6 +102,9 @@ if [[ -n "$cygwin" ]]; then
format=windows
fi
SCALA_HOME="$(cygpath --$format "$SCALA_HOME")"
+ if [[ -n "$JAVA_HOME" ]]; then
+ JAVA_HOME="$(cygpath --$format "$JAVA_HOME")"
+ fi
TOOL_CLASSPATH="$(cygpath --path --$format "$TOOL_CLASSPATH")"
elif [[ -n "$mingw" ]]; then
SCALA_HOME="$(cmd //c echo "$SCALA_HOME")"
diff --git a/src/compiler/scala/tools/cmd/CommandLine.scala b/src/compiler/scala/tools/cmd/CommandLine.scala
index 75f96d3c4b..cf0463423c 100644
--- a/src/compiler/scala/tools/cmd/CommandLine.scala
+++ b/src/compiler/scala/tools/cmd/CommandLine.scala
@@ -19,7 +19,7 @@ class CommandLine(val spec: Reference, val originalArgs: List[String]) extends C
def this(spec: Reference, line: String) = this(spec, Parser tokenize line)
def this(spec: Reference, args: Array[String]) = this(spec, args.toList)
- import spec.{ isAnyOption, isUnaryOption, isBinaryOption, isExpandOption }
+ import spec.{ isUnaryOption, isBinaryOption, isExpandOption }
val Terminator = "--"
val ValueForUnaryOption = "true" // so if --opt is given, x(--opt) = true
diff --git a/src/compiler/scala/tools/cmd/FromString.scala b/src/compiler/scala/tools/cmd/FromString.scala
index cba2e99998..433bbb167e 100644
--- a/src/compiler/scala/tools/cmd/FromString.scala
+++ b/src/compiler/scala/tools/cmd/FromString.scala
@@ -6,7 +6,7 @@
package scala.tools
package cmd
-import nsc.io.{ Path, File, Directory }
+import scala.tools.nsc.io.{ File, Directory }
import scala.reflect.runtime.{universe => ru}
import scala.tools.reflect.StdRuntimeTags._
@@ -24,18 +24,11 @@ abstract class FromString[+T](implicit t: ru.TypeTag[T]) extends PartialFunction
}
object FromString {
- // We need these because we clash with the String => Path implicits.
- private def toFile(s: String) = new File(new java.io.File(s))
+ // We need this because we clash with the String => Path implicits.
private def toDir(s: String) = new Directory(new java.io.File(s))
/** Path related stringifiers.
*/
- val ExistingFile: FromString[File] = new FromString[File]()(tagOfFile) {
- override def isDefinedAt(s: String) = toFile(s).isFile
- def apply(s: String): File =
- if (isDefinedAt(s)) toFile(s)
- else cmd.runAndExit(println("'%s' is not an existing file." format s))
- }
val ExistingDir: FromString[Directory] = new FromString[Directory]()(tagOfDirectory) {
override def isDefinedAt(s: String) = toDir(s).isDirectory
def apply(s: String): Directory =
diff --git a/src/compiler/scala/tools/cmd/Reference.scala b/src/compiler/scala/tools/cmd/Reference.scala
index bcbb454771..ec2a414065 100644
--- a/src/compiler/scala/tools/cmd/Reference.scala
+++ b/src/compiler/scala/tools/cmd/Reference.scala
@@ -26,7 +26,6 @@ trait Reference extends Spec {
def isUnaryOption(s: String) = unary contains toOpt(s)
def isBinaryOption(s: String) = binary contains toOpt(s)
def isExpandOption(s: String) = expansionMap contains toOpt(s)
- def isAnyOption(s: String) = isUnaryOption(s) || isBinaryOption(s) || isExpandOption(s)
def expandArg(arg: String) = expansionMap.getOrElse(fromOpt(arg), List(arg))
@@ -46,7 +45,7 @@ object Reference {
val MaxLine = 80
class Accumulators() {
- private var _help = new ListBuffer[() => String]
+ private val _help = new ListBuffer[() => String]
private var _unary = List[String]()
private var _binary = List[String]()
private var _expand = Map[String, List[String]]()
diff --git a/src/compiler/scala/tools/cmd/gen/CodegenSpec.scala b/src/compiler/scala/tools/cmd/gen/CodegenSpec.scala
index 903517c5b4..ee7e605425 100644
--- a/src/compiler/scala/tools/cmd/gen/CodegenSpec.scala
+++ b/src/compiler/scala/tools/cmd/gen/CodegenSpec.scala
@@ -12,8 +12,6 @@ trait CodegenSpec extends Spec with Meta.StdOpts with Interpolation {
def referenceSpec = CodegenSpec
def programInfo = Spec.Info("codegen", "", "scala.tools.cmd.gen.Codegen")
- import FromString.ExistingDir
-
help("Usage: codegen [<options>]")
// val inDir = "in" / "directory containing templates" --^ ExistingDir
diff --git a/src/compiler/scala/tools/nsc/CompilationUnits.scala b/src/compiler/scala/tools/nsc/CompilationUnits.scala
index 355a1fd262..a2108b8ced 100644
--- a/src/compiler/scala/tools/nsc/CompilationUnits.scala
+++ b/src/compiler/scala/tools/nsc/CompilationUnits.scala
@@ -6,7 +6,7 @@
package scala.tools.nsc
import util.FreshNameCreator
-import scala.reflect.internal.util.{ Position, NoPosition, BatchSourceFile, SourceFile, NoSourceFile }
+import scala.reflect.internal.util.{ SourceFile, NoSourceFile }
import scala.collection.mutable
import scala.collection.mutable.{ LinkedHashSet, ListBuffer }
@@ -26,7 +26,7 @@ trait CompilationUnits { self: Global =>
class CompilationUnit(val source: SourceFile) extends CompilationUnitContextApi { self =>
/** the fresh name creator */
- var fresh: FreshNameCreator = new FreshNameCreator.Default
+ val fresh: FreshNameCreator = new FreshNameCreator.Default
def freshTermName(prefix: String): TermName = newTermName(fresh.newName(prefix))
def freshTypeName(prefix: String): TypeName = newTypeName(fresh.newName(prefix))
@@ -36,16 +36,6 @@ trait CompilationUnits { self: Global =>
def exists = source != NoSourceFile && source != null
-// def parseSettings() = {
-// val argsmarker = "SCALAC_ARGS"
-// if(comments nonEmpty) {
-// val pragmas = comments find (_.text.startsWith("//#")) // only parse first one
-// pragmas foreach { p =>
-// val i = p.text.indexOf(argsmarker)
-// if(i > 0)
-// }
-// }
-// }
/** Note: depends now contains toplevel classes.
* To get their sourcefiles, you need to dereference with .sourcefile
*/
@@ -123,18 +113,5 @@ trait CompilationUnits { self: Global =>
lazy val isJava = source.file.name.endsWith(".java")
override def toString() = source.toString()
-
- def clear() {
- fresh = new FreshNameCreator.Default
- body = EmptyTree
- depends.clear()
- defined.clear()
- synthetics.clear()
- toCheck.clear()
- checkedFeatures = Set()
- icode.clear()
- }
}
}
-
-
diff --git a/src/compiler/scala/tools/nsc/CompileClient.scala b/src/compiler/scala/tools/nsc/CompileClient.scala
index 731f6926f0..c756a1b0d9 100644
--- a/src/compiler/scala/tools/nsc/CompileClient.scala
+++ b/src/compiler/scala/tools/nsc/CompileClient.scala
@@ -5,7 +5,6 @@
package scala.tools.nsc
-import java.io.{ BufferedReader, File, InputStreamReader, PrintWriter }
import settings.FscSettings
import scala.tools.util.CompileOutputCommon
import sys.SystemProperties.preferIPv4Stack
diff --git a/src/compiler/scala/tools/nsc/CompileServer.scala b/src/compiler/scala/tools/nsc/CompileServer.scala
index c23c1e6154..e4c250a3d9 100644
--- a/src/compiler/scala/tools/nsc/CompileServer.scala
+++ b/src/compiler/scala/tools/nsc/CompileServer.scala
@@ -5,7 +5,7 @@
package scala.tools.nsc
-import java.io.{ BufferedOutputStream, FileOutputStream, PrintStream }
+import java.io.PrintStream
import scala.tools.nsc.reporters.{Reporter, ConsoleReporter}
import scala.reflect.internal.util.FakePos //Position
import scala.tools.util.SocketServer
@@ -29,8 +29,6 @@ class StandardCompileServer extends SocketServer {
var shutdown = false
var verbose = false
- val versionMsg = "Fast " + Properties.versionMsg
-
val MaxCharge = 0.8
private val runtime = Runtime.getRuntime()
@@ -58,9 +56,6 @@ class StandardCompileServer extends SocketServer {
(totalMemory - freeMemory).toDouble / maxMemory.toDouble > MaxCharge
}
- protected def newOfflineCompilerCommand(arguments: List[String], settings: FscSettings): OfflineCompilerCommand =
- new OfflineCompilerCommand(arguments, settings)
-
/** Problematically, Settings are only considered equal if every setting
* is exactly equal. In fsc this immediately breaks down because the randomly
* chosen temporary outdirs differ between client and server. Among other
@@ -93,7 +88,7 @@ class StandardCompileServer extends SocketServer {
val args = input.split("\0", -1).toList
val newSettings = new FscSettings(fscError)
this.verbose = newSettings.verbose.value
- val command = newOfflineCompilerCommand(args, newSettings)
+ val command = new OfflineCompilerCommand(args, newSettings)
info("Settings after normalizing paths: " + newSettings)
printMemoryStats()
diff --git a/src/compiler/scala/tools/nsc/CompileSocket.scala b/src/compiler/scala/tools/nsc/CompileSocket.scala
index 9a3e8d1530..6b55537195 100644
--- a/src/compiler/scala/tools/nsc/CompileSocket.scala
+++ b/src/compiler/scala/tools/nsc/CompileSocket.scala
@@ -5,13 +5,9 @@
package scala.tools.nsc
-import java.io.{ IOException, FileNotFoundException, PrintWriter, FileOutputStream }
-import java.io.{ BufferedReader, FileReader }
-import java.util.regex.Pattern
-import java.net._
+import java.io.{ FileNotFoundException, PrintWriter, FileOutputStream }
import java.security.SecureRandom
import io.{ File, Path, Directory, Socket }
-import scala.util.control.Exception.catching
import scala.tools.util.CompileOutputCommon
import scala.reflect.internal.util.StringOps.splitWhere
import scala.sys.process._
diff --git a/src/compiler/scala/tools/nsc/CompilerCommand.scala b/src/compiler/scala/tools/nsc/CompilerCommand.scala
index e994150f6f..0462e69f74 100644
--- a/src/compiler/scala/tools/nsc/CompilerCommand.scala
+++ b/src/compiler/scala/tools/nsc/CompilerCommand.scala
@@ -5,7 +5,6 @@
package scala.tools.nsc
-import scala.collection.mutable.ListBuffer
import io.File
/** A class representing command line info for scalac */
@@ -15,9 +14,6 @@ class CompilerCommand(arguments: List[String], val settings: Settings) {
type Setting = Settings#Setting
- /** file extensions of files that the compiler can process */
- lazy val fileEndings = Properties.fileEndings
-
private val processArgumentsResult =
if (shouldProcessArguments) processArguments
else (true, Nil)
@@ -41,8 +37,6 @@ class CompilerCommand(arguments: List[String], val settings: Settings) {
""".stripMargin.trim + "\n"
def shortUsage = "Usage: %s <options> <source files>" format cmdName
- def createUsagePreface(shouldExplain: Boolean) =
- if (shouldExplain) shortUsage + "\n" + explainAdvanced else ""
/** Creates a help message for a subset of options based on cond */
def createUsageMsg(cond: Setting => Boolean): String = {
diff --git a/src/compiler/scala/tools/nsc/CompilerRun.scala b/src/compiler/scala/tools/nsc/CompilerRun.scala
deleted file mode 100644
index 6746b08155..0000000000
--- a/src/compiler/scala/tools/nsc/CompilerRun.scala
+++ /dev/null
@@ -1,21 +0,0 @@
-/* NSC -- new Scala compiler
- * Copyright 2005-2013 LAMP/EPFL
- * @author Martin Odersky
- */
-
-package scala.tools.nsc
-
-class CompilerRun {
- def firstPhase: Phase = NoPhase
- def terminalPhase: Phase = NoPhase
- def namerPhase: Phase = NoPhase
- def typerPhase: Phase = NoPhase
- def refchecksPhase: Phase = NoPhase
- def explicitouterPhase: Phase = NoPhase
- def erasurePhase: Phase = NoPhase
- def flattenPhase: Phase = NoPhase
- def mixinPhase: Phase = NoPhase
- def icodePhase: Phase = NoPhase
- def phaseNamed(name: String): Phase = NoPhase
-}
-
diff --git a/src/compiler/scala/tools/nsc/Driver.scala b/src/compiler/scala/tools/nsc/Driver.scala
index 814bd58a66..fc247600f6 100644
--- a/src/compiler/scala/tools/nsc/Driver.scala
+++ b/src/compiler/scala/tools/nsc/Driver.scala
@@ -1,11 +1,11 @@
package scala.tools.nsc
-import scala.tools.nsc.reporters.{Reporter, ConsoleReporter}
+import scala.tools.nsc.reporters.ConsoleReporter
import Properties.{ versionString, copyrightString, residentPromptString }
-import scala.reflect.internal.util.{ BatchSourceFile, FakePos }
+import scala.reflect.internal.util.FakePos
abstract class Driver {
-
+
val prompt = residentPromptString
val versionMsg = "Scala compiler " +
@@ -68,4 +68,4 @@ abstract class Driver {
sys.exit(if (reporter.hasErrors) 1 else 0)
}
-} \ No newline at end of file
+}
diff --git a/src/compiler/scala/tools/nsc/GenericRunnerSettings.scala b/src/compiler/scala/tools/nsc/GenericRunnerSettings.scala
index 9c2db11a56..ad75d02bff 100644
--- a/src/compiler/scala/tools/nsc/GenericRunnerSettings.scala
+++ b/src/compiler/scala/tools/nsc/GenericRunnerSettings.scala
@@ -39,7 +39,4 @@ class GenericRunnerSettings(error: String => Unit) extends Settings(error) {
val nc = BooleanSetting(
"-nc",
"do not use the fsc compilation daemon") withAbbreviation "-nocompdaemon"
-
- @deprecated("Use `nc` instead", "2.9.0") def nocompdaemon = nc
- @deprecated("Use `save` instead", "2.9.0") def savecompiled = save
}
diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala
index 757ac94dbd..75f38c7d67 100644
--- a/src/compiler/scala/tools/nsc/Global.scala
+++ b/src/compiler/scala/tools/nsc/Global.scala
@@ -8,14 +8,12 @@ package scala.tools.nsc
import java.io.{ File, FileOutputStream, PrintWriter, IOException, FileNotFoundException }
import java.nio.charset.{ Charset, CharsetDecoder, IllegalCharsetNameException, UnsupportedCharsetException }
import scala.compat.Platform.currentTime
-import scala.tools.util.PathResolver
import scala.collection.{ mutable, immutable }
import io.{ SourceReader, AbstractFile, Path }
import reporters.{ Reporter, ConsoleReporter }
-import util.{ Exceptional, ClassPath, MergedClassPath, StatisticsInfo, ScalaClassLoader, returning }
-import scala.reflect.internal.util.{ NoPosition, OffsetPosition, SourceFile, NoSourceFile, BatchSourceFile, ScriptSourceFile }
+import util.{ ClassPath, MergedClassPath, StatisticsInfo, returning, stackTraceString, stackTraceHeadString }
+import scala.reflect.internal.util.{ OffsetPosition, SourceFile, NoSourceFile, BatchSourceFile, ScriptSourceFile }
import scala.reflect.internal.pickling.{ PickleBuffer, PickleFormat }
-import settings.{ AestheticSettings }
import symtab.{ Flags, SymbolTable, SymbolLoaders, SymbolTrackers }
import symtab.classfile.Pickler
import dependencies.DependencyAnalysis
@@ -25,13 +23,11 @@ import ast.parser._
import typechecker._
import transform._
import backend.icode.{ ICodes, GenICode, ICodeCheckers }
-import backend.{ ScalaPrimitives, Platform, MSILPlatform, JavaPlatform }
-import backend.jvm.{GenJVM, GenASM}
+import backend.{ ScalaPrimitives, Platform, JavaPlatform }
+import backend.jvm.GenASM
import backend.opt.{ Inliners, InlineExceptionHandlers, ClosureElimination, DeadCodeElimination }
import backend.icode.analysis._
import scala.language.postfixOps
-import scala.reflect.internal.StdAttachments
-import scala.reflect.ClassTag
class Global(var currentSettings: Settings, var reporter: Reporter)
extends SymbolTable
@@ -74,8 +70,6 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
def this(settings: Settings) =
this(settings, new ConsoleReporter(settings))
- def mkAttributedQualifier(tpe: Type, termSym: Symbol): Tree = gen.mkAttributedQualifier(tpe, termSym)
-
def picklerPhase: Phase = if (currentRun.isDefined) currentRun.picklerPhase else NoPhase
// platform specific elements
@@ -83,8 +77,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
type ThisPlatform = Platform { val global: Global.this.type }
lazy val platform: ThisPlatform =
- if (forMSIL) new { val global: Global.this.type = Global.this } with MSILPlatform
- else new { val global: Global.this.type = Global.this } with JavaPlatform
+ new { val global: Global.this.type = Global.this } with JavaPlatform
type PlatformClassPath = ClassPath[platform.BinaryRepr]
type OptClassPath = Option[PlatformClassPath]
@@ -172,7 +165,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
if (lastPrintedSource == source)
println(": tree is unchanged since " + lastPrintedPhase)
else {
- lastPrintedPhase = phase.prev // since we're running inside "afterPhase"
+ lastPrintedPhase = phase.prev // since we're running inside "exitingPhase"
lastPrintedSource = source
println("")
println(source)
@@ -257,27 +250,26 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
if (settings.debug.value)
body
}
- // Warnings issued only under -Ydebug. For messages which should reach
- // developer ears, but are not adequately actionable by users.
- @inline final override def debugwarn(msg: => String) {
- if (settings.debug.value)
- warning(msg)
+ /** This is for WARNINGS which should reach the ears of scala developers
+ * whenever they occur, but are not useful for normal users. They should
+ * be precise, explanatory, and infrequent. Please don't use this as a
+ * logging mechanism. !!! is prefixed to all messages issued via this route
+ * to make them visually distinct.
+ */
+ @inline final override def devWarning(msg: => String) {
+ if (settings.developer.value || settings.debug.value)
+ warning("!!! " + msg)
}
private def elapsedMessage(msg: String, start: Long) =
msg + " in " + (currentTime - start) + "ms"
def informComplete(msg: String): Unit = reporter.withoutTruncating(inform(msg))
- def informProgress(msg: String) = if (opt.verbose) inform("[" + msg + "]")
- def inform[T](msg: String, value: T): T = returning(value)(x => inform(msg + x))
+ def informProgress(msg: String) = if (settings.verbose.value) inform("[" + msg + "]")
def informTime(msg: String, start: Long) = informProgress(elapsedMessage(msg, start))
def logError(msg: String, t: Throwable): Unit = ()
- def logAfterEveryPhase[T](msg: String)(op: => T) {
- log("Running operation '%s' after every phase.\n".format(msg) + describeAfterEveryPhase(op))
- }
-
override def shouldLogAtThisPhase = settings.log.isSetByUser && (
(settings.log containsPhase globalPhase) || (settings.log containsPhase phase)
)
@@ -301,7 +293,6 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
private val reader: SourceReader = {
val defaultEncoding = Properties.sourceEncoding
- val defaultReader = Properties.sourceReader
def loadCharset(name: String) =
try Some(Charset.forName(name))
@@ -314,7 +305,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
None
}
- val charset = opt.encoding flatMap loadCharset getOrElse {
+ val charset = ( if (settings.encoding.isSetByUser) Some(settings.encoding.value) else None ) flatMap loadCharset getOrElse {
settings.encoding.value = defaultEncoding // A mandatory charset
Charset.forName(defaultEncoding)
}
@@ -329,7 +320,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
}
}
- opt.sourceReader flatMap loadReader getOrElse {
+ ( if (settings.sourceReader.isSetByUser) Some(settings.sourceReader.value) else None ) flatMap loadReader getOrElse {
new SourceReader(charset.newDecoder(), reporter)
}
}
@@ -337,54 +328,12 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
if (!dependencyAnalysis.off)
dependencyAnalysis.loadDependencyAnalysis()
- if (opt.verbose || opt.logClasspath) {
+ if (settings.verbose.value || settings.Ylogcp.value) {
// Uses the "do not truncate" inform
informComplete("[search path for source files: " + classPath.sourcepaths.mkString(",") + "]")
informComplete("[search path for class files: " + classPath.asClasspathString + "]")
}
- object opt extends AestheticSettings {
- def settings = Global.this.settings
-
- // protected implicit lazy val globalPhaseOrdering: Ordering[Phase] = Ordering[Int] on (_.id)
- def isActive(ph: Settings#PhasesSetting) = ph containsPhase globalPhase
- def wasActive(ph: Settings#PhasesSetting) = ph containsPhase globalPhase.prev
-
- // Allows for syntax like scalac -Xshow-class Random@erasure,typer
- private def splitClassAndPhase(str: String, term: Boolean): Name = {
- def mkName(s: String) = if (term) newTermName(s) else newTypeName(s)
- (str indexOf '@') match {
- case -1 => mkName(str)
- case idx =>
- val phasePart = str drop (idx + 1)
- settings.Yshow.tryToSetColon(phasePart split ',' toList)
- mkName(str take idx)
- }
- }
-
- // behavior
-
- // debugging
- def checkPhase = wasActive(settings.check)
- def logPhase = isActive(settings.log)
-
- // Write *.icode files right after GenICode when -Xprint-icode was given.
- def writeICodeAtICode = settings.writeICode.isSetByUser && isActive(settings.writeICode)
-
- // showing/printing things
- def browsePhase = isActive(settings.browse)
- def echoFilenames = opt.debug && (opt.verbose || currentRun.size < 5)
- def noShow = settings.Yshow.isDefault
- def printLate = settings.printLate.value
- def printPhase = isActive(settings.Xprint)
- def showNames = List(showClass, showObject).flatten
- def showPhase = isActive(settings.Yshow)
- def showSymbols = settings.Yshowsyms.value
- def showTrees = settings.Xshowtrees.value || settings.XshowtreesCompact.value || settings.XshowtreesStringified.value
- val showClass = optSetting[String](settings.Xshowcls) map (x => splitClassAndPhase(x, false))
- val showObject = optSetting[String](settings.Xshowobj) map (x => splitClassAndPhase(x, true))
- }
-
// The current division between scala.reflect.* and scala.tools.nsc.* is pretty
// clunky. It is often difficult to have a setting influence something without having
// to create it on that side. For this one my strategy is a constant def at the file
@@ -393,11 +342,8 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
// Here comes another one...
override protected val enableTypeVarExperimentals = settings.Xexperimental.value
- // True if -Xscript has been set, indicating a script run.
- def isScriptRun = opt.script.isDefined
-
def getSourceFile(f: AbstractFile): BatchSourceFile =
- if (isScriptRun) ScriptSourceFile(f, reader read f)
+ if (settings.script.isSetByUser) ScriptSourceFile(f, reader read f)
else new BatchSourceFile(f, reader read f)
def getSourceFile(name: String): SourceFile = {
@@ -452,7 +398,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
if ((unit ne null) && unit.exists)
lastSeenSourceFile = unit.source
- if (opt.echoFilenames)
+ if (settings.debug.value && (settings.verbose.value || currentRun.size < 5))
inform("[running phase " + name + " on " + unit + "]")
val unit0 = currentUnit
@@ -471,8 +417,8 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
}
/** Switch to turn on detailed type logs */
- var printTypings = settings.Ytyperdebug.value
- var printInfers = settings.Yinferdebug.value
+ val printTypings = settings.Ytyperdebug.value
+ val printInfers = settings.Yinferdebug.value
// phaseName = "parser"
object syntaxAnalyzer extends {
@@ -649,13 +595,6 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
val runsRightAfter = None
} with DeadCodeElimination
- // phaseName = "jvm", FJBG-based version
- object genJVM extends {
- val global: Global.this.type = Global.this
- val runsAfter = List("dce")
- val runsRightAfter = None
- } with GenJVM
-
// phaseName = "jvm", ASM-based version
object genASM extends {
val global: Global.this.type = Global.this
@@ -675,7 +614,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
object terminal extends {
val global: Global.this.type = Global.this
val phaseName = "terminal"
- val runsAfter = List("jvm", "msil")
+ val runsAfter = List("jvm")
val runsRightAfter = None
} with SubComponent {
private var cache: Option[GlobalPhase] = None
@@ -690,13 +629,6 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
}
}
- // phaseName = "SAMPLE PHASE"
- object sampleTransform extends {
- val global: Global.this.type = Global.this
- val runsAfter = List[String]()
- val runsRightAfter = None
- } with SampleTransform
-
/** The checkers are for validating the compiler data structures
* at phase boundaries.
*/
@@ -829,48 +761,16 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
/** Returns List of (phase, value) pairs, including only those
* where the value compares unequal to the previous phase's value.
*/
- def afterEachPhase[T](op: => T): List[(Phase, T)] = {
+ def afterEachPhase[T](op: => T): List[(Phase, T)] = { // used in tests
phaseDescriptors.map(_.ownPhase).filterNot(_ eq NoPhase).foldLeft(List[(Phase, T)]()) { (res, ph) =>
- val value = afterPhase(ph)(op)
+ val value = exitingPhase(ph)(op)
if (res.nonEmpty && res.head._2 == value) res
else ((ph, value)) :: res
} reverse
}
- /** Returns List of ChangeAfterPhase objects, encapsulating those
- * phase transitions where the result of the operation gave a different
- * list than it had when run during the previous phase.
- */
- def changesAfterEachPhase[T](op: => List[T]): List[ChangeAfterPhase[T]] = {
- val ops = ((NoPhase, Nil)) :: afterEachPhase(op)
-
- ops sliding 2 map {
- case (_, before) :: (ph, after) :: Nil =>
- val lost = before filterNot (after contains _)
- val gained = after filterNot (before contains _)
- ChangeAfterPhase(ph, lost, gained)
- case _ => ???
- } toList
- }
private def numberedPhase(ph: Phase) = "%2d/%s".format(ph.id, ph.name)
- case class ChangeAfterPhase[+T](ph: Phase, lost: List[T], gained: List[T]) {
- private def mkStr(what: String, xs: List[_]) = (
- if (xs.isEmpty) ""
- else xs.mkString(what + " after " + numberedPhase(ph) + " {\n ", "\n ", "\n}\n")
- )
- override def toString = mkStr("Lost", lost) + mkStr("Gained", gained)
- }
-
- def describeAfterEachPhase[T](op: => T): List[String] =
- afterEachPhase(op) map { case (ph, t) => "[after %-15s] %s".format(numberedPhase(ph), t) }
-
- def describeAfterEveryPhase[T](op: => T): String =
- describeAfterEachPhase(op) map (" " + _ + "\n") mkString
-
- def printAfterEachPhase[T](op: => T): Unit =
- describeAfterEachPhase(op) foreach (m => println(" " + m))
-
// ------------ Invalidations ---------------------------------
/** Is given package class a system package class that cannot be invalidated?
@@ -1093,40 +993,37 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
def currentUnit: CompilationUnit = if (currentRun eq null) NoCompilationUnit else currentRun.currentUnit
def currentSource: SourceFile = if (currentUnit.exists) currentUnit.source else lastSeenSourceFile
- // TODO - trim these to the absolute minimum.
- @inline final def afterErasure[T](op: => T): T = afterPhase(currentRun.erasurePhase)(op)
- @inline final def afterPostErasure[T](op: => T): T = afterPhase(currentRun.posterasurePhase)(op)
- @inline final def afterExplicitOuter[T](op: => T): T = afterPhase(currentRun.explicitouterPhase)(op)
- @inline final def afterFlatten[T](op: => T): T = afterPhase(currentRun.flattenPhase)(op)
- @inline final def afterIcode[T](op: => T): T = afterPhase(currentRun.icodePhase)(op)
- @inline final def afterMixin[T](op: => T): T = afterPhase(currentRun.mixinPhase)(op)
- @inline final def afterPickler[T](op: => T): T = afterPhase(currentRun.picklerPhase)(op)
- @inline final def afterRefchecks[T](op: => T): T = afterPhase(currentRun.refchecksPhase)(op)
- @inline final def afterSpecialize[T](op: => T): T = afterPhase(currentRun.specializePhase)(op)
- @inline final def afterTyper[T](op: => T): T = afterPhase(currentRun.typerPhase)(op)
- @inline final def afterUncurry[T](op: => T): T = afterPhase(currentRun.uncurryPhase)(op)
- @inline final def beforeErasure[T](op: => T): T = beforePhase(currentRun.erasurePhase)(op)
- @inline final def beforeExplicitOuter[T](op: => T): T = beforePhase(currentRun.explicitouterPhase)(op)
- @inline final def beforeFlatten[T](op: => T): T = beforePhase(currentRun.flattenPhase)(op)
- @inline final def beforeIcode[T](op: => T): T = beforePhase(currentRun.icodePhase)(op)
- @inline final def beforeMixin[T](op: => T): T = beforePhase(currentRun.mixinPhase)(op)
- @inline final def beforePickler[T](op: => T): T = beforePhase(currentRun.picklerPhase)(op)
- @inline final def beforeRefchecks[T](op: => T): T = beforePhase(currentRun.refchecksPhase)(op)
- @inline final def beforeSpecialize[T](op: => T): T = beforePhase(currentRun.specializePhase)(op)
- @inline final def beforeTyper[T](op: => T): T = beforePhase(currentRun.typerPhase)(op)
- @inline final def beforeUncurry[T](op: => T): T = beforePhase(currentRun.uncurryPhase)(op)
-
- def explainContext(c: analyzer.Context): String = (
- if (c == null) "" else (
- """| context owners: %s
- |
- |Enclosing block or template:
- |%s""".format(
- c.owner.ownerChain.takeWhile(!_.isPackageClass).mkString(" -> "),
- nodePrinters.nodeToString(c.enclClassOrMethod.tree)
- )
- )
+ def isGlobalInitialized = (
+ definitions.isDefinitionsInitialized
+ && rootMirror.isMirrorInitialized
+ )
+ override def isPastTyper = (
+ (curRun ne null)
+ && isGlobalInitialized // defense against init order issues
+ && (globalPhase.id > currentRun.typerPhase.id)
)
+
+ // TODO - trim these to the absolute minimum.
+ @inline final def exitingErasure[T](op: => T): T = exitingPhase(currentRun.erasurePhase)(op)
+ @inline final def exitingPostErasure[T](op: => T): T = exitingPhase(currentRun.posterasurePhase)(op)
+ @inline final def exitingExplicitOuter[T](op: => T): T = exitingPhase(currentRun.explicitouterPhase)(op)
+ @inline final def exitingFlatten[T](op: => T): T = exitingPhase(currentRun.flattenPhase)(op)
+ @inline final def exitingMixin[T](op: => T): T = exitingPhase(currentRun.mixinPhase)(op)
+ @inline final def exitingPickler[T](op: => T): T = exitingPhase(currentRun.picklerPhase)(op)
+ @inline final def exitingRefchecks[T](op: => T): T = exitingPhase(currentRun.refchecksPhase)(op)
+ @inline final def exitingSpecialize[T](op: => T): T = exitingPhase(currentRun.specializePhase)(op)
+ @inline final def exitingTyper[T](op: => T): T = exitingPhase(currentRun.typerPhase)(op)
+ @inline final def exitingUncurry[T](op: => T): T = exitingPhase(currentRun.uncurryPhase)(op)
+ @inline final def enteringErasure[T](op: => T): T = enteringPhase(currentRun.erasurePhase)(op)
+ @inline final def enteringExplicitOuter[T](op: => T): T = enteringPhase(currentRun.explicitouterPhase)(op)
+ @inline final def enteringFlatten[T](op: => T): T = enteringPhase(currentRun.flattenPhase)(op)
+ @inline final def enteringIcode[T](op: => T): T = enteringPhase(currentRun.icodePhase)(op)
+ @inline final def enteringMixin[T](op: => T): T = enteringPhase(currentRun.mixinPhase)(op)
+ @inline final def enteringPickler[T](op: => T): T = enteringPhase(currentRun.picklerPhase)(op)
+ @inline final def enteringRefchecks[T](op: => T): T = enteringPhase(currentRun.refchecksPhase)(op)
+ @inline final def enteringTyper[T](op: => T): T = enteringPhase(currentRun.typerPhase)(op)
+ @inline final def enteringUncurry[T](op: => T): T = enteringPhase(currentRun.uncurryPhase)(op)
+
// Owners up to and including the first package class.
private def ownerChainString(sym: Symbol): String = (
if (sym == null) ""
@@ -1139,9 +1036,6 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
pairs.toList collect { case (k, v) if v != null => "%20s: %s".format(k, v) } mkString "\n"
)
- def explainTree(t: Tree): String = formatExplain(
- )
-
/** Don't want to introduce new errors trying to report errors,
* so swallow exceptions.
*/
@@ -1155,7 +1049,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
val info1 = formatExplain(
"while compiling" -> currentSource.path,
- "during phase" -> ( if (globalPhase eq phase) phase else "global=%s, atPhase=%s".format(globalPhase, phase) ),
+ "during phase" -> ( if (globalPhase eq phase) phase else "global=%s, enteringPhase=%s".format(globalPhase, phase) ),
"library version" -> scala.util.Properties.versionString,
"compiler version" -> Properties.versionString,
"reconstructed args" -> settings.recreateArgs.mkString(" ")
@@ -1171,7 +1065,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
val info3: List[String] = (
( List("== Enclosing template or block ==", nodePrinters.nodeToString(enclosing).trim) )
++ ( if (tpe eq null) Nil else List("== Expanded type of tree ==", typeDeconstruct.show(tpe)) )
- ++ ( if (!opt.debug) Nil else List("== Current unit body ==", nodePrinters.nodeToString(currentUnit.body)) )
+ ++ ( if (!settings.debug.value) Nil else List("== Current unit body ==", nodePrinters.nodeToString(currentUnit.body)) )
++ ( List(errorMessage) )
)
@@ -1187,7 +1081,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
def echoPhaseSummary(ph: Phase) = {
/** Only output a summary message under debug if we aren't echoing each file. */
- if (opt.debug && !opt.echoFilenames)
+ if (settings.debug.value && !(settings.verbose.value || currentRun.size < 5))
inform("[running phase " + ph.name + " on " + currentRun.size + " compilation units]")
}
@@ -1203,7 +1097,6 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
}
def newUnitParser(code: String) = new syntaxAnalyzer.UnitParser(newCompilationUnit(code))
- def newUnitScanner(code: String) = new syntaxAnalyzer.UnitScanner(newCompilationUnit(code))
def newCompilationUnit(code: String) = new CompilationUnit(newSourceFile(code))
def newSourceFile(code: String) = new BatchSourceFile("<console>", code)
@@ -1226,9 +1119,8 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
val inlinerWarnings = new ConditionalWarning("inliner", settings.YinlinerWarnings)
val allConditionalWarnings = List(deprecationWarnings0, uncheckedWarnings0, featureWarnings, inlinerWarnings)
- // for sbt's benefit
- def uncheckedWarnings: List[(Position, String)] = uncheckedWarnings0.warnings.toList
- def deprecationWarnings: List[(Position, String)] = deprecationWarnings0.warnings.toList
+ def uncheckedWarnings: List[(Position, String)] = uncheckedWarnings0.warnings.toList // used in sbt
+ def deprecationWarnings: List[(Position, String)] = deprecationWarnings0.warnings.toList // used in sbt
var reportedFeature = Set[Symbol]()
@@ -1238,9 +1130,6 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
/** Have we already supplemented the error message of a compiler crash? */
private[nsc] final var supplementedError = false
- /** To be initialized from firstPhase. */
- private var terminalPhase: Phase = NoPhase
-
private val unitbuf = new mutable.ListBuffer[CompilationUnit]
val compiledFiles = new mutable.HashSet[String]
@@ -1401,7 +1290,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
val namerPhase = phaseNamed("namer")
// val packageobjectsPhase = phaseNamed("packageobjects")
val typerPhase = phaseNamed("typer")
- val inlineclassesPhase = phaseNamed("inlineclasses")
+ // val inlineclassesPhase = phaseNamed("inlineclasses")
// val superaccessorsPhase = phaseNamed("superaccessors")
val picklerPhase = phaseNamed("pickler")
val refchecksPhase = phaseNamed("refchecks")
@@ -1414,7 +1303,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
val erasurePhase = phaseNamed("erasure")
val posterasurePhase = phaseNamed("posterasure")
// val lazyvalsPhase = phaseNamed("lazyvals")
- val lambdaliftPhase = phaseNamed("lambdalift")
+ // val lambdaliftPhase = phaseNamed("lambdalift")
// val constructorsPhase = phaseNamed("constructors")
val flattenPhase = phaseNamed("flatten")
val mixinPhase = phaseNamed("mixin")
@@ -1424,12 +1313,9 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
val inlineExceptionHandlersPhase = phaseNamed("inlineExceptionHandlers")
val closelimPhase = phaseNamed("closelim")
val dcePhase = phaseNamed("dce")
- val jvmPhase = phaseNamed("jvm")
- // val msilPhase = phaseNamed("msil")
+ // val jvmPhase = phaseNamed("jvm")
def runIsAt(ph: Phase) = globalPhase.id == ph.id
- def runIsPast(ph: Phase) = globalPhase.id > ph.id
- // def runIsAtBytecodeGen = (runIsAt(jvmPhase) || runIsAt(msilPhase))
def runIsAtOptimiz = {
runIsAt(inlinerPhase) || // listing phases in full for robustness when -Ystop-after has been given.
runIsAt(inlineExceptionHandlersPhase) ||
@@ -1498,8 +1384,24 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
}
}
- private def showMembers() =
- opt.showNames foreach (x => showDef(x, opt.declsOnly, globalPhase))
+ private def showMembers() = {
+ // Allows for syntax like scalac -Xshow-class Random@erasure,typer
+ def splitClassAndPhase(str: String, term: Boolean): Name = {
+ def mkName(s: String) = if (term) newTermName(s) else newTypeName(s)
+ (str indexOf '@') match {
+ case -1 => mkName(str)
+ case idx =>
+ val phasePart = str drop (idx + 1)
+ settings.Yshow.tryToSetColon(phasePart split ',' toList)
+ mkName(str take idx)
+ }
+ }
+ if (settings.Xshowcls.isSetByUser)
+ showDef(splitClassAndPhase(settings.Xshowcls.value, false), false, globalPhase)
+
+ if (settings.Xshowobj.isSetByUser)
+ showDef(splitClassAndPhase(settings.Xshowobj.value, true), false, globalPhase)
+ }
// Similarly, this will only be created under -Yshow-syms.
object trackerFactory extends SymbolTrackers {
@@ -1507,7 +1409,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
lazy val trackers = currentRun.units.toList map (x => SymbolTracker(x))
def snapshot() = {
inform("\n[[symbol layout at end of " + phase + "]]")
- afterPhase(phase) {
+ exitingPhase(phase) {
trackers foreach { t =>
t.snapshot()
inform(t.show("Heading from " + phase.prev.name + " to " + phase.name))
@@ -1517,6 +1419,9 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
}
def reportCompileErrors() {
+ if (!reporter.hasErrors && reporter.hasWarnings && settings.fatalWarnings.value)
+ globalError("No warnings can be incurred under -Xfatal-warnings.")
+
if (reporter.hasErrors) {
for ((sym, file) <- symSource.iterator) {
sym.reset(new loaders.SourcefileLoader(file))
@@ -1536,8 +1441,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
/** Compile list of source files */
def compileSources(_sources: List[SourceFile]) {
- val depSources = dependencyAnalysis calculateFiles _sources.distinct
- val sources = coreClassesFirst(depSources)
+ val sources = dependencyAnalysis calculateFiles _sources.distinct
// there is a problem already, e.g. a plugin was passed a bad option
if (reporter.hasErrors)
return
@@ -1555,12 +1459,11 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
def compileUnits(units: List[CompilationUnit], fromPhase: Phase) {
try compileUnitsInternal(units, fromPhase)
catch { case ex: Throwable =>
- val shown = if (settings.verbose.value) {
- val pw = new java.io.PrintWriter(new java.io.StringWriter)
- ex.printStackTrace(pw)
- pw.toString
- } else ex.getClass.getName
- // ex.printStackTrace(Console.out) // DEBUG for fsc, note that error stacktraces do not print in fsc
+ val shown = if (settings.verbose.value)
+ stackTraceString(ex)
+ else
+ stackTraceHeadString(ex) // note that error stacktraces do not print in fsc
+
globalError(supplementErrorMessage("uncaught exception during compilation: " + shown))
throw ex
}
@@ -1583,37 +1486,40 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
// progress update
informTime(globalPhase.description, startTime)
-
- if (opt.writeICodeAtICode || (opt.printPhase && runIsAtOptimiz)) {
+ val shouldWriteIcode = (
+ (settings.writeICode.isSetByUser && (settings.writeICode containsPhase globalPhase))
+ || (!settings.Xprint.doAllPhases && (settings.Xprint containsPhase globalPhase) && runIsAtOptimiz)
+ )
+ if (shouldWriteIcode) {
// Write *.icode files when -Xprint-icode or -Xprint:<some-optimiz-phase> was given.
writeICode()
- } else if (opt.printPhase || opt.printLate && runIsAt(cleanupPhase)) {
+ } else if ((settings.Xprint containsPhase globalPhase) || settings.printLate.value && runIsAt(cleanupPhase)) {
// print trees
- if (opt.showTrees) nodePrinters.printAll()
+ if (settings.Xshowtrees.value || settings.XshowtreesCompact.value || settings.XshowtreesStringified.value) nodePrinters.printAll()
else printAllUnits()
}
// print the symbols presently attached to AST nodes
- if (opt.showSymbols)
+ if (settings.Yshowsyms.value)
trackerFactory.snapshot()
// print members
- if (opt.showPhase)
+ if (settings.Yshow containsPhase globalPhase)
showMembers()
// browse trees with swing tree viewer
- if (opt.browsePhase)
+ if (settings.browse containsPhase globalPhase)
treeBrowser browse (phase.name, units)
// move the pointer
globalPhase = globalPhase.next
// run tree/icode checkers
- if (opt.checkPhase)
+ if (settings.check containsPhase globalPhase.prev)
runCheckers()
// output collected statistics
- if (opt.printStats)
+ if (settings.Ystatistics.value)
statistics.print(phase)
advancePhase
@@ -1623,7 +1529,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
units map (_.body) foreach (traceSymbols recordSymbolsInTree _)
// In case no phase was specified for -Xshow-class/object, show it now for sure.
- if (opt.noShow)
+ if (settings.Yshow.isDefault)
showMembers()
reportCompileErrors()
@@ -1639,7 +1545,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
// Reset project
if (!stopPhase("namer")) {
- atPhase(namerPhase) {
+ enteringPhase(namerPhase) {
resetProjectClasses(RootClass)
}
}
@@ -1655,7 +1561,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
def compile(filenames: List[String]) {
try {
val sources: List[SourceFile] =
- if (isScriptRun && filenames.size > 1) returning(Nil)(_ => globalError("can only compile one script at a time"))
+ if (settings.script.isSetByUser && filenames.size > 1) returning(Nil)(_ => globalError("can only compile one script at a time"))
else filenames map getSourceFile
compileSources(sources)
@@ -1679,7 +1585,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
if (firstPhase ne null) { // we might get here during initialization, is a source is newer than the binary
val maxId = math.max(globalPhase.id, typerPhase.id)
firstPhase.iterator takeWhile (_.id < maxId) foreach (ph =>
- atPhase(ph)(ph.asInstanceOf[GlobalPhase] applyPhase unit))
+ enteringPhase(ph)(ph.asInstanceOf[GlobalPhase] applyPhase unit))
refreshProgress
}
}
@@ -1688,56 +1594,16 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
* is needed for?)
*/
private def resetPackageClass(pclazz: Symbol) {
- atPhase(firstPhase) {
- pclazz.setInfo(atPhase(typerPhase)(pclazz.info))
+ enteringPhase(firstPhase) {
+ pclazz.setInfo(enteringPhase(typerPhase)(pclazz.info))
}
if (!pclazz.isRoot) resetPackageClass(pclazz.owner)
}
-
- /**
- * Re-orders the source files to
- * 1. This Space Intentionally Left Blank
- * 2. LowPriorityImplicits / EmbeddedControls (i.e. parents of Predef)
- * 3. the rest
- *
- * 1 is to avoid cyclic reference errors.
- * 2 is due to the following. When completing "Predef" (*), typedIdent is called
- * for its parents (e.g. "LowPriorityImplicits"). typedIdent checks whether
- * the symbol reallyExists, which tests if the type of the symbol after running
- * its completer is != NoType.
- * If the "namer" phase has not yet run for "LowPriorityImplicits", the symbol
- * has a SourcefileLoader as type. Calling "doComplete" on it does nothing at
- * all, because the source file is part of the files to be compiled anyway.
- * So the "reallyExists" test will return "false".
- * Only after the namer, the symbol has a lazy type which actually computes
- * the info, and "reallyExists" behaves as expected.
- * So we need to make sure that the "namer" phase is run on predef's parents
- * before running it on predef.
- *
- * (*) Predef is completed early when calling "mkAttributedRef" during the
- * addition of "import Predef._" to sourcefiles. So this situation can't
- * happen for user classes.
- *
- */
- private def coreClassesFirst(files: List[SourceFile]) = {
- val goLast = 4
- def rank(f: SourceFile) = {
- if (f.file.container.name != "scala") goLast
- else f.file.name match {
- case "LowPriorityImplicits.scala" => 2
- case "StandardEmbeddings.scala" => 2
- case "EmbeddedControls.scala" => 2
- case "Predef.scala" => 3 /* Predef.scala before Any.scala, etc. */
- case _ => goLast
- }
- }
- files sortBy rank
- }
} // class Run
def printAllUnits() {
print("[[syntax trees at end of %25s]]".format(phase))
- afterPhase(phase)(currentRun.units foreach { unit =>
+ exitingPhase(phase)(currentRun.units foreach { unit =>
nodePrinters showUnit unit
})
}
@@ -1746,7 +1612,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
*/
def showDef(fullName: Name, declsOnly: Boolean, ph: Phase) = {
val boringOwners = Set[Symbol](definitions.AnyClass, definitions.AnyRefClass, definitions.ObjectClass)
- def phased[T](body: => T): T = afterPhase(ph)(body)
+ def phased[T](body: => T): T = exitingPhase(ph)(body)
def boringMember(sym: Symbol) = boringOwners(sym.owner)
def symString(sym: Symbol) = if (sym.isTerm) sym.defString else sym.toString
@@ -1792,7 +1658,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
val printer = new icodes.TextPrinter(null, icodes.linearizer)
icodes.classes.values.foreach((cls) => {
val suffix = if (cls.symbol.hasModuleFlag) "$.icode" else ".icode"
- var file = getFile(cls.symbol, suffix)
+ val file = getFile(cls.symbol, suffix)
// if (file.exists())
// file = new File(file.getParentFile(), file.getName() + "1")
try {
@@ -1802,25 +1668,14 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
informProgress("wrote " + file)
} catch {
case ex: IOException =>
- if (opt.debug) ex.printStackTrace()
+ if (settings.debug.value) ex.printStackTrace()
globalError("could not write file " + file)
}
})
}
- // In order to not outright break code which overrides onlyPresentation (like sbt 0.7.5.RC0)
- // I restored and deprecated it. That would be enough to avoid the compilation
- // failure, but the override wouldn't accomplish anything. So now forInteractive
- // and forScaladoc default to onlyPresentation, which is the same as defaulting
- // to false except in old code. The downside is that this leaves us calling a
- // deprecated method: but I see no simple way out, so I leave it for now.
- def forJVM = opt.jvm
- override def forMSIL = opt.msil
- def forInteractive = onlyPresentation
- def forScaladoc = onlyPresentation
+ def forInteractive = false
+ def forScaladoc = false
def createJavadoc = false
-
- @deprecated("Use forInteractive or forScaladoc, depending on what you're after", "2.9.0")
- def onlyPresentation = false
}
object Global {
diff --git a/src/compiler/scala/tools/nsc/Main.scala b/src/compiler/scala/tools/nsc/Main.scala
index 7d112dfb3e..a4b22b0e11 100644
--- a/src/compiler/scala/tools/nsc/Main.scala
+++ b/src/compiler/scala/tools/nsc/Main.scala
@@ -7,15 +7,11 @@ package scala.tools.nsc
import java.io.File
import File.pathSeparator
-
import scala.tools.nsc.interactive.{ RefinedBuildManager, SimpleBuildManager }
import scala.tools.nsc.io.AbstractFile
-import scala.tools.nsc.reporters.{Reporter, ConsoleReporter}
-import scala.reflect.internal.util.{ BatchSourceFile, FakePos } //{Position}
-import Properties.msilLibPath
/** The main class for NSC, a compiler for the programming
- * language Scala.
+ * language Scala.
*/
object Main extends Driver with EvalLoop {
@@ -63,11 +59,7 @@ object Main extends Driver with EvalLoop {
}
false
}
- else {
- if (settings.target.value == "msil")
- msilLibPath foreach (x => settings.assemrefs.value += (pathSeparator + x))
- true
- }
+ else true
override def newCompiler(): Global =
if (settings.Yrangepos.value) new Global(settings, reporter) with interactive.RangePositions
diff --git a/src/compiler/scala/tools/nsc/MainBench.scala b/src/compiler/scala/tools/nsc/MainBench.scala
index f18ff19d7d..03190a63f3 100644
--- a/src/compiler/scala/tools/nsc/MainBench.scala
+++ b/src/compiler/scala/tools/nsc/MainBench.scala
@@ -5,28 +5,20 @@
package scala.tools.nsc
-import java.io.File
-import File.pathSeparator
-
-import scala.tools.nsc.interactive.{ RefinedBuildManager, SimpleBuildManager }
-import scala.tools.nsc.io.AbstractFile
-import scala.tools.nsc.reporters.{Reporter, ConsoleReporter}
-import scala.reflect.internal.util.{ BatchSourceFile, FakePos } //{Position}
-import Properties.{ versionString, copyrightString, residentPromptString, msilLibPath }
import scala.reflect.internal.util.Statistics
/** The main class for NSC, a compiler for the programming
* language Scala.
*/
object MainBench extends Driver with EvalLoop {
-
+
lazy val theCompiler = Global(settings, reporter)
-
+
override def newCompiler() = theCompiler
-
+
val NIter = 50
val NBest = 10
-
+
override def main(args: Array[String]) = {
val times = new Array[Long](NIter)
var start = System.nanoTime()
diff --git a/src/compiler/scala/tools/nsc/MainGenericRunner.scala b/src/compiler/scala/tools/nsc/MainGenericRunner.scala
index e4a20b4a8c..adb03ca374 100644
--- a/src/compiler/scala/tools/nsc/MainGenericRunner.scala
+++ b/src/compiler/scala/tools/nsc/MainGenericRunner.scala
@@ -5,8 +5,6 @@
package scala.tools.nsc
-import java.net.URL
-import scala.tools.util.PathResolver
import io.{ File }
import util.{ ClassPath, ScalaClassLoader }
import Properties.{ versionString, copyrightString }
diff --git a/src/compiler/scala/tools/nsc/ObjectRunner.scala b/src/compiler/scala/tools/nsc/ObjectRunner.scala
index f5123513c4..95264aeda6 100644
--- a/src/compiler/scala/tools/nsc/ObjectRunner.scala
+++ b/src/compiler/scala/tools/nsc/ObjectRunner.scala
@@ -8,15 +8,9 @@ package scala.tools.nsc
import java.net.URL
import util.ScalaClassLoader
-import java.lang.reflect.InvocationTargetException
import util.Exceptional.unwrap
trait CommonRunner {
- /** Check whether a class with the specified name
- * exists on the specified class path. */
- def classExists(urls: List[URL], objectName: String): Boolean =
- ScalaClassLoader.classExists(urls, objectName)
-
/** Run a given object, specified by name, using a
* specified classpath and argument list.
*
diff --git a/src/compiler/scala/tools/nsc/OfflineCompilerCommand.scala b/src/compiler/scala/tools/nsc/OfflineCompilerCommand.scala
index 8a3c531ff0..2f4975e681 100644
--- a/src/compiler/scala/tools/nsc/OfflineCompilerCommand.scala
+++ b/src/compiler/scala/tools/nsc/OfflineCompilerCommand.scala
@@ -26,8 +26,8 @@ class OfflineCompilerCommand(arguments: List[String], settings: FscSettings) ext
// instead of whatever it's supposed to be doing.
val baseDirectory = {
val pwd = System.getenv("PWD")
- if (pwd != null && !isWin) Directory(pwd)
- else Directory.Current getOrElse Directory("/")
+ if (pwd == null || isWin) Directory.Current getOrElse Directory("/")
+ else Directory(pwd)
}
currentDir.value = baseDirectory.path
}
diff --git a/src/compiler/scala/tools/nsc/PhaseAssembly.scala b/src/compiler/scala/tools/nsc/PhaseAssembly.scala
index cff3590b3f..67dc1e3b66 100644
--- a/src/compiler/scala/tools/nsc/PhaseAssembly.scala
+++ b/src/compiler/scala/tools/nsc/PhaseAssembly.scala
@@ -55,7 +55,7 @@ trait PhaseAssembly {
* node object does not exist, then create it.
*/
def getNodeByPhase(phs: SubComponent): Node = {
- var node: Node = getNodeByPhase(phs.phaseName)
+ val node: Node = getNodeByPhase(phs.phaseName)
node.phaseobj match {
case None =>
node.phaseobj = Some(List[SubComponent](phs))
@@ -75,7 +75,7 @@ trait PhaseAssembly {
* list of the nodes
*/
def softConnectNodes(frm: Node, to: Node) {
- var e = new Edge(frm, to, false)
+ val e = new Edge(frm, to, false)
this.edges += e
frm.after += e
@@ -87,7 +87,7 @@ trait PhaseAssembly {
* list of the nodes
*/
def hardConnectNodes(frm: Node, to: Node) {
- var e = new Edge(frm, to, true)
+ val e = new Edge(frm, to, true)
this.edges += e
frm.after += e
@@ -164,7 +164,7 @@ trait PhaseAssembly {
} else {
- var promote = hl.to.before.filter(e => (!e.hard))
+ val promote = hl.to.before.filter(e => (!e.hard))
hl.to.before.clear
sanity foreach (edge => hl.to.before += edge)
for (edge <- promote) {
@@ -182,7 +182,7 @@ trait PhaseAssembly {
/** Remove all nodes in the given graph, that have no phase object
* Make sure to clean up all edges when removing the node object
- * <code>Inform</code> with warnings, if an external phase has a
+ * `Inform` with warnings, if an external phase has a
* dependency on something that is dropped.
*/
def removeDanglingNodes() {
@@ -245,7 +245,7 @@ trait PhaseAssembly {
for (phs <- phsSet) {
- var fromnode = graph.getNodeByPhase(phs)
+ val fromnode = graph.getNodeByPhase(phs)
phs.runsRightAfter match {
case None =>
@@ -306,7 +306,7 @@ trait PhaseAssembly {
sbuf.append("\"" + node.allPhaseNames + "(" + node.level + ")" + "\" [color=\"#0000ff\"]\n")
}
sbuf.append("}\n")
- var out = new BufferedWriter(new FileWriter(filename))
+ val out = new BufferedWriter(new FileWriter(filename))
out.write(sbuf.toString)
out.flush()
out.close()
diff --git a/src/compiler/scala/tools/nsc/Phases.scala b/src/compiler/scala/tools/nsc/Phases.scala
index 0901ade2d7..e379afce9b 100644
--- a/src/compiler/scala/tools/nsc/Phases.scala
+++ b/src/compiler/scala/tools/nsc/Phases.scala
@@ -5,7 +5,6 @@
package scala.tools.nsc
-import symtab.Flags
import scala.reflect.internal.util.TableDef
import scala.language.postfixOps
@@ -22,7 +21,6 @@ object Phases {
}
val values = new Array[Cell](MaxPhases + 1)
def results = values filterNot (_ == null)
- def apply(ph: Phase): T = values(ph.id).value
def update(ph: Phase, value: T): Unit = values(ph.id) = Cell(ph, value)
}
/** A class for recording the elapsed time of each phase in the
@@ -40,7 +38,6 @@ object Phases {
>> ("ms" -> (_.value)) >+ " "
<< ("share" -> (_.value.toDouble * 100 / total formatted "%.2f"))
}
- def formatted = "" + table()
}
}
diff --git a/src/compiler/scala/tools/nsc/Properties.scala b/src/compiler/scala/tools/nsc/Properties.scala
index 55fd196716..feb4ded2f2 100644
--- a/src/compiler/scala/tools/nsc/Properties.scala
+++ b/src/compiler/scala/tools/nsc/Properties.scala
@@ -16,10 +16,6 @@ object Properties extends scala.util.PropertiesTrait {
def residentPromptString = scalaPropOrElse("resident.prompt", "\nnsc> ")
def shellPromptString = scalaPropOrElse("shell.prompt", "\nscala> ")
- // settings based on system properties
- def msilLibPath = propOrNone("msil.libpath")
-
// derived values
def isEmacsShell = propOrEmpty("env.emacs") != ""
- def fileEndings = fileEndingString.split("""\|""").toList
}
diff --git a/src/compiler/scala/tools/nsc/ScalaDoc.scala b/src/compiler/scala/tools/nsc/ScalaDoc.scala
index ba434bc797..14b76b53b3 100644
--- a/src/compiler/scala/tools/nsc/ScalaDoc.scala
+++ b/src/compiler/scala/tools/nsc/ScalaDoc.scala
@@ -10,7 +10,6 @@ import java.io.File.pathSeparator
import scala.tools.nsc.doc.DocFactory
import scala.tools.nsc.reporters.ConsoleReporter
import scala.reflect.internal.util.FakePos
-import Properties.msilLibPath
/** The main class for scaladoc, a front-end for the Scala compiler
* that generates documentation from source files.
@@ -42,12 +41,8 @@ class ScalaDoc {
reporter.warning(null, "Phases are restricted when using Scaladoc")
else if (docSettings.help.value || !hasFiles)
reporter.echo(command.usageMsg)
- else try {
- if (docSettings.target.value == "msil")
- msilLibPath foreach (x => docSettings.assemrefs.value += (pathSeparator + x))
-
- new DocFactory(reporter, docSettings) document command.files
- }
+ else
+ try { new DocFactory(reporter, docSettings) document command.files }
catch {
case ex @ FatalError(msg) =>
if (docSettings.debug.value) ex.printStackTrace()
diff --git a/src/compiler/scala/tools/nsc/ScriptRunner.scala b/src/compiler/scala/tools/nsc/ScriptRunner.scala
index 107c4b3df3..92b2dc79ed 100644
--- a/src/compiler/scala/tools/nsc/ScriptRunner.scala
+++ b/src/compiler/scala/tools/nsc/ScriptRunner.scala
@@ -7,7 +7,6 @@ package scala.tools.nsc
import io.{ Directory, File, Path }
import java.io.IOException
-import java.net.URL
import scala.tools.nsc.reporters.{Reporter,ConsoleReporter}
import util.Exceptional.unwrap
@@ -49,25 +48,12 @@ class ScriptRunner extends HasCompileSocket {
case x => x
}
- def isScript(settings: Settings) = settings.script.value != ""
-
/** Choose a jar filename to hold the compiled version of a script. */
private def jarFileFor(scriptFile: String)= File(
if (scriptFile endsWith ".jar") scriptFile
else scriptFile.stripSuffix(".scala") + ".jar"
)
- /** Read the entire contents of a file as a String. */
- private def contentsOfFile(filename: String) = File(filename).slurp()
-
- /** Split a fully qualified object name into a
- * package and an unqualified object name */
- private def splitObjectName(fullname: String): (Option[String], String) =
- (fullname lastIndexOf '.') match {
- case -1 => (None, fullname)
- case idx => (Some(fullname take idx), fullname drop (idx + 1))
- }
-
/** Compile a script using the fsc compilation daemon.
*/
private def compileWithDaemon(settings: GenericRunnerSettings, scriptFileIn: String) = {
diff --git a/src/compiler/scala/tools/nsc/SubComponent.scala b/src/compiler/scala/tools/nsc/SubComponent.scala
index a0468a22b9..9b8582ae02 100644
--- a/src/compiler/scala/tools/nsc/SubComponent.scala
+++ b/src/compiler/scala/tools/nsc/SubComponent.scala
@@ -47,8 +47,8 @@ abstract class SubComponent {
private var ownPhaseCache: WeakReference[Phase] = new WeakReference(null)
private var ownPhaseRunId = global.NoRunId
- @inline final def beforeOwnPhase[T](op: => T) = global.beforePhase(ownPhase)(op)
- @inline final def afterOwnPhase[T](op: => T) = global.afterPhase(ownPhase)(op)
+ @inline final def beforeOwnPhase[T](op: => T) = global.enteringPhase(ownPhase)(op)
+ @inline final def afterOwnPhase[T](op: => T) = global.exitingPhase(ownPhase)(op)
/** The phase corresponding to this subcomponent in the current compiler run */
def ownPhase: Phase = {
diff --git a/src/compiler/scala/tools/nsc/ast/DocComments.scala b/src/compiler/scala/tools/nsc/ast/DocComments.scala
index e635c5e87d..c9bf131b79 100755
--- a/src/compiler/scala/tools/nsc/ast/DocComments.scala
+++ b/src/compiler/scala/tools/nsc/ast/DocComments.scala
@@ -7,10 +7,7 @@ package scala.tools.nsc
package ast
import symtab._
-import reporters._
-import scala.reflect.internal.util.{Position, NoPosition}
import util.DocStrings._
-import scala.reflect.internal.Chars._
import scala.collection.mutable
/*
@@ -124,8 +121,6 @@ trait DocComments { self: Global =>
getDocComment(sym) map getUseCases getOrElse List()
}
- def useCases(sym: Symbol): List[(Symbol, String, Position)] = useCases(sym, sym.enclClass)
-
/** Returns the javadoc format of doc comment string `s`, including wiki expansion
*/
def toJavaDoc(s: String): String = expandWiki(s)
@@ -465,7 +460,7 @@ trait DocComments { self: Global =>
//val (classes, pkgs) = site.ownerChain.span(!_.isPackageClass)
//val sites = (classes ::: List(pkgs.head, rootMirror.RootClass)))
//findIn(sites)
- findIn(site.ownerChain ::: List(definitions.EmptyPackage))
+ findIn(site.ownerChain ::: List(rootMirror.EmptyPackage))
}
def getType(str: String, variable: String): Type = {
diff --git a/src/compiler/scala/tools/nsc/ast/Positions.scala b/src/compiler/scala/tools/nsc/ast/Positions.scala
index 49569f5e05..e7bd5da9dd 100644
--- a/src/compiler/scala/tools/nsc/ast/Positions.scala
+++ b/src/compiler/scala/tools/nsc/ast/Positions.scala
@@ -1,7 +1,7 @@
package scala.tools.nsc
package ast
-import scala.reflect.internal.util.{ SourceFile, Position, OffsetPosition, NoPosition }
+import scala.reflect.internal.util.{ SourceFile, OffsetPosition }
trait Positions extends scala.reflect.internal.Positions {
self: Global =>
diff --git a/src/compiler/scala/tools/nsc/ast/Printers.scala b/src/compiler/scala/tools/nsc/ast/Printers.scala
index 83222a24b4..b9f348632a 100644
--- a/src/compiler/scala/tools/nsc/ast/Printers.scala
+++ b/src/compiler/scala/tools/nsc/ast/Printers.scala
@@ -7,8 +7,6 @@ package scala.tools.nsc
package ast
import java.io.{ OutputStream, PrintWriter, StringWriter, Writer }
-import symtab.Flags._
-import symtab.SymbolTable
trait Printers extends scala.reflect.internal.Printers { this: Global =>
@@ -202,91 +200,12 @@ trait Printers extends scala.reflect.internal.Printers { this: Global =>
override def printTree(tree: Tree) { print(safe(tree)) }
}
- class TreeMatchTemplate {
- // non-trees defined in Trees
- //
- // case class ImportSelector(name: Name, namePos: Int, rename: Name, renamePos: Int)
- // case class Modifiers(flags: Long, privateWithin: Name, annotations: List[Tree], positions: Map[Long, Position])
- //
- def apply(t: Tree): Unit = t match {
- // eliminated by typer
- case Annotated(annot, arg) =>
- case AssignOrNamedArg(lhs, rhs) =>
- case DocDef(comment, definition) =>
- case Import(expr, selectors) =>
-
- // eliminated by refchecks
- case ModuleDef(mods, name, impl) =>
- case TypeTreeWithDeferredRefCheck() =>
-
- // eliminated by erasure
- case TypeDef(mods, name, tparams, rhs) =>
- case Typed(expr, tpt) =>
-
- // eliminated by cleanup
- case ApplyDynamic(qual, args) =>
-
- // eliminated by explicitouter
- case Alternative(trees) =>
- case Bind(name, body) =>
- case CaseDef(pat, guard, body) =>
- case Star(elem) =>
- case UnApply(fun, args) =>
-
- // eliminated by lambdalift
- case Function(vparams, body) =>
-
- // eliminated by uncurry
- case AppliedTypeTree(tpt, args) =>
- case CompoundTypeTree(templ) =>
- case ExistentialTypeTree(tpt, whereClauses) =>
- case SelectFromTypeTree(qual, selector) =>
- case SingletonTypeTree(ref) =>
- case TypeBoundsTree(lo, hi) =>
-
- // survivors
- case Apply(fun, args) =>
- case ArrayValue(elemtpt, trees) =>
- case Assign(lhs, rhs) =>
- case Block(stats, expr) =>
- case ClassDef(mods, name, tparams, impl) =>
- case DefDef(mods, name, tparams, vparamss, tpt, rhs) =>
- case EmptyTree =>
- case Ident(name) =>
- case If(cond, thenp, elsep) =>
- case LabelDef(name, params, rhs) =>
- case Literal(value) =>
- case Match(selector, cases) =>
- case New(tpt) =>
- case PackageDef(pid, stats) =>
- case Return(expr) =>
- case Select(qualifier, selector) =>
- case Super(qual, mix) =>
- case Template(parents, self, body) =>
- case This(qual) =>
- case Throw(expr) =>
- case Try(block, catches, finalizer) =>
- case TypeApply(fun, args) =>
- case TypeTree() =>
- case ValDef(mods, name, tpt, rhs) =>
-
- // missing from the Trees comment
- case Parens(args) => // only used during parsing
- case SelectFromArray(qual, name, erasure) => // only used during erasure
- }
- }
-
def asString(t: Tree): String = render(t, newStandardTreePrinter, settings.printtypes.value, settings.uniqid.value, settings.Yshowsymkinds.value)
def asCompactString(t: Tree): String = render(t, newCompactTreePrinter, settings.printtypes.value, settings.uniqid.value, settings.Yshowsymkinds.value)
def asCompactDebugString(t: Tree): String = render(t, newCompactTreePrinter, true, true, true)
def newStandardTreePrinter(writer: PrintWriter): TreePrinter = new TreePrinter(writer)
- def newStandardTreePrinter(stream: OutputStream): TreePrinter = newStandardTreePrinter(new PrintWriter(stream))
- def newStandardTreePrinter(): TreePrinter = newStandardTreePrinter(new PrintWriter(ConsoleWriter))
-
def newCompactTreePrinter(writer: PrintWriter): CompactTreePrinter = new CompactTreePrinter(writer)
- def newCompactTreePrinter(stream: OutputStream): CompactTreePrinter = newCompactTreePrinter(new PrintWriter(stream))
- def newCompactTreePrinter(): CompactTreePrinter = newCompactTreePrinter(new PrintWriter(ConsoleWriter))
override def newTreePrinter(writer: PrintWriter): TreePrinter =
if (settings.Ycompacttrees.value) newCompactTreePrinter(writer)
diff --git a/src/compiler/scala/tools/nsc/ast/TreeBrowsers.scala b/src/compiler/scala/tools/nsc/ast/TreeBrowsers.scala
index 5c954096f4..30a9348fb0 100644
--- a/src/compiler/scala/tools/nsc/ast/TreeBrowsers.scala
+++ b/src/compiler/scala/tools/nsc/ast/TreeBrowsers.scala
@@ -16,8 +16,6 @@ import javax.swing.tree._
import scala.concurrent.Lock
import scala.text._
-import symtab.Flags._
-import symtab.SymbolTable
import scala.language.implicitConversions
/**
@@ -509,7 +507,7 @@ abstract class TreeBrowsers {
/** Return a textual representation of this t's symbol */
def symbolText(t: Tree): String = {
val prefix =
- if (t.hasSymbol) "[has] "
+ if (t.hasSymbolField) "[has] "
else if (t.isDef) "[defines] "
else ""
@@ -529,10 +527,9 @@ abstract class TreeBrowsers {
* attributes */
def symbolAttributes(t: Tree): String = {
val s = t.symbol
- var att = ""
if ((s ne null) && (s != NoSymbol)) {
- var str = flagsToString(s.flags)
+ var str = s.flagString
if (s.isStaticMember) str = str + " isStatic ";
(str + " annotations: " + s.annotations.mkString("", " ", "")
+ (if (s.isTypeSkolem) "\ndeSkolemized annotations: " + s.deSkolemize.annotations.mkString("", " ", "") else ""))
diff --git a/src/compiler/scala/tools/nsc/ast/TreeDSL.scala b/src/compiler/scala/tools/nsc/ast/TreeDSL.scala
index 9a5b92e795..1c6bba19b3 100644
--- a/src/compiler/scala/tools/nsc/ast/TreeDSL.scala
+++ b/src/compiler/scala/tools/nsc/ast/TreeDSL.scala
@@ -21,7 +21,6 @@ trait TreeDSL {
import global._
import definitions._
- import gen.{ scalaDot }
object CODE {
// Add a null check to a Tree => Tree function
@@ -31,24 +30,17 @@ trait TreeDSL {
def returning[T](x: T)(f: T => Unit): T = util.returning(x)(f)
object LIT extends (Any => Literal) {
+ def typed(x: Any) = apply(x) setType ConstantType(Constant(x))
def apply(x: Any) = Literal(Constant(x))
def unapply(x: Any) = condOpt(x) { case Literal(Constant(value)) => value }
}
- // You might think these could all be vals, but empirically I have found that
- // at least in the case of UNIT the compiler breaks if you re-use trees.
- // However we need stable identifiers to have attractive pattern matching.
- // So it's inconsistent until I devise a better way.
- val TRUE = LIT(true)
- val FALSE = LIT(false)
- val ZERO = LIT(0)
- def NULL = LIT(null)
- def UNIT = LIT(())
-
- // for those preferring boring, predictable lives, without the thrills of tree-sharing
- // (but with the perk of typed trees)
- def TRUE_typed = LIT(true) setType ConstantType(Constant(true))
- def FALSE_typed = LIT(false) setType ConstantType(Constant(false))
+ // Boring, predictable trees.
+ def TRUE = LIT typed true
+ def FALSE = LIT typed false
+ def ZERO = LIT(0)
+ def NULL = LIT(null)
+ def UNIT = LIT(())
object WILD {
def empty = Ident(nme.WILDCARD)
@@ -85,16 +77,12 @@ trait TreeDSL {
def ANY_EQ (other: Tree) = OBJ_EQ(other AS ObjectClass.tpe)
def ANY_== (other: Tree) = fn(target, Any_==, other)
def ANY_!= (other: Tree) = fn(target, Any_!=, other)
- def OBJ_== (other: Tree) = fn(target, Object_==, other)
def OBJ_!= (other: Tree) = fn(target, Object_!=, other)
def OBJ_EQ (other: Tree) = fn(target, Object_eq, other)
def OBJ_NE (other: Tree) = fn(target, Object_ne, other)
- def INT_| (other: Tree) = fn(target, getMember(IntClass, nme.OR), other)
- def INT_& (other: Tree) = fn(target, getMember(IntClass, nme.AND), other)
def INT_>= (other: Tree) = fn(target, getMember(IntClass, nme.GE), other)
def INT_== (other: Tree) = fn(target, getMember(IntClass, nme.EQ), other)
- def INT_!= (other: Tree) = fn(target, getMember(IntClass, nme.NE), other)
// generic operations on ByteClass, IntClass, LongClass
def GEN_| (other: Tree, kind: ClassSymbol) = fn(target, getMember(kind, nme.OR), other)
@@ -102,9 +90,6 @@ trait TreeDSL {
def GEN_== (other: Tree, kind: ClassSymbol) = fn(target, getMember(kind, nme.EQ), other)
def GEN_!= (other: Tree, kind: ClassSymbol) = fn(target, getMember(kind, nme.NE), other)
- def BOOL_&& (other: Tree) = fn(target, Boolean_and, other)
- def BOOL_|| (other: Tree) = fn(target, Boolean_or, other)
-
/** Apply, Select, Match **/
def APPLY(params: Tree*) = Apply(target, params.toList)
def APPLY(params: List[Tree]) = Apply(target, params)
@@ -114,6 +99,10 @@ trait TreeDSL {
def DOT(sym: Symbol) = SelectStart(Select(target, sym))
/** Assignment */
+ // !!! This method is responsible for some tree sharing, but a diligent
+ // reviewer pointed out that we shouldn't blindly duplicate these trees
+ // as there might be DefTrees nested beneath them. It's not entirely
+ // clear how to proceed, so for now it retains the non-duplicating behavior.
def ===(rhs: Tree) = Assign(target, rhs)
/** Methods for sequences **/
@@ -130,8 +119,6 @@ trait TreeDSL {
def IS(tpe: Type) = gen.mkIsInstanceOf(target, tpe, true)
def IS_OBJ(tpe: Type) = gen.mkIsInstanceOf(target, tpe, false)
- // XXX having some difficulty expressing nullSafe in a way that doesn't freak out value types
- // def TOSTRING() = nullSafe(fn(_: Tree, nme.toString_), LIT("null"))(target)
def TOSTRING() = fn(target, nme.toString_)
def GETCLASS() = fn(target, Object_getClass)
}
@@ -159,7 +146,6 @@ trait TreeDSL {
def mkTree(rhs: Tree): ResultTreeType
def ===(rhs: Tree): ResultTreeType
- private var _mods: Modifiers = null
private var _tpt: Tree = null
private var _pos: Position = null
@@ -167,19 +153,12 @@ trait TreeDSL {
_tpt = TypeTree(tp)
this
}
- def withFlags(flags: Long*): this.type = {
- if (_mods == null)
- _mods = defaultMods
-
- _mods = flags.foldLeft(_mods)(_ | _)
- this
- }
def withPos(pos: Position): this.type = {
_pos = pos
this
}
- final def mods = if (_mods == null) defaultMods else _mods
+ final def mods = defaultMods
final def tpt = if (_tpt == null) defaultTpt else _tpt
final def pos = if (_pos == null) defaultPos else _pos
}
@@ -199,7 +178,7 @@ trait TreeDSL {
self: VODDStart =>
type ResultTreeType = ValDef
- def mkTree(rhs: Tree): ValDef = ValDef(mods, name, tpt, rhs)
+ def mkTree(rhs: Tree): ValDef = ValDef(mods, name.toTermName, tpt, rhs)
}
trait DefCreator {
self: VODDStart =>
@@ -244,7 +223,6 @@ trait TreeDSL {
}
class TryStart(body: Tree, catches: List[CaseDef], fin: Tree) {
def CATCH(xs: CaseDef*) = new TryStart(body, xs.toList, fin)
- def FINALLY(x: Tree) = Try(body, catches, x)
def ENDTRY = Try(body, catches, fin)
}
@@ -252,16 +230,9 @@ trait TreeDSL {
def DEFAULT: CaseStart = new CaseStart(WILD.empty, EmptyTree)
class SymbolMethods(target: Symbol) {
- def BIND(body: Tree) = Bind(target, body)
- def IS_NULL() = REF(target) OBJ_EQ NULL
- def NOT_NULL() = REF(target) OBJ_NE NULL
-
- def GET() = fn(REF(target), nme.get)
-
- // name of nth indexed argument to a method (first parameter list), defaults to 1st
- def ARG(idx: Int = 0) = Ident(target.paramss.head(idx))
- def ARGS = target.paramss.head
- def ARGNAMES = ARGS map Ident
+ def IS_NULL() = REF(target) OBJ_EQ NULL
+ def GET() = fn(REF(target), nme.get)
+ def ARGS = target.paramss.head
}
/** Top level accessible. */
@@ -269,32 +240,13 @@ trait TreeDSL {
def THROW(sym: Symbol, msg: Tree): Throw = Throw(sym.tpe, msg.TOSTRING())
def NEW(tpt: Tree, args: Tree*): Tree = New(tpt, List(args.toList))
- def NEW(sym: Symbol, args: Tree*): Tree = New(sym.tpe, args: _*)
-
- def DEF(name: Name, tp: Type): DefTreeStart = DEF(name) withType tp
- def DEF(name: Name): DefTreeStart = new DefTreeStart(name)
def DEF(sym: Symbol): DefSymStart = new DefSymStart(sym)
-
- def VAL(name: Name, tp: Type): ValTreeStart = VAL(name) withType tp
- def VAL(name: Name): ValTreeStart = new ValTreeStart(name)
def VAL(sym: Symbol): ValSymStart = new ValSymStart(sym)
- def VAR(name: Name, tp: Type): ValTreeStart = VAL(name, tp) withFlags Flags.MUTABLE
- def VAR(name: Name): ValTreeStart = VAL(name) withFlags Flags.MUTABLE
- def VAR(sym: Symbol): ValSymStart = VAL(sym) withFlags Flags.MUTABLE
-
- def LAZYVAL(name: Name, tp: Type): ValTreeStart = VAL(name, tp) withFlags Flags.LAZY
- def LAZYVAL(name: Name): ValTreeStart = VAL(name) withFlags Flags.LAZY
- def LAZYVAL(sym: Symbol): ValSymStart = VAL(sym) withFlags Flags.LAZY
-
def AND(guards: Tree*) =
if (guards.isEmpty) EmptyTree
else guards reduceLeft gen.mkAnd
- def OR(guards: Tree*) =
- if (guards.isEmpty) EmptyTree
- else guards reduceLeft gen.mkOr
-
def IF(tree: Tree) = new IfStart(tree, EmptyTree)
def TRY(tree: Tree) = new TryStart(tree, Nil, EmptyTree)
def BLOCK(xs: Tree*) = Block(xs.init.toList, xs.last)
@@ -312,11 +264,6 @@ trait TreeDSL {
case List(tree) if flattenUnary => tree
case _ => Apply(TupleClass(trees.length).companionModule, trees: _*)
}
- def makeTupleType(trees: List[Tree], flattenUnary: Boolean): Tree = trees match {
- case Nil => gen.scalaUnitConstr
- case List(tree) if flattenUnary => tree
- case _ => AppliedTypeTree(REF(TupleClass(trees.length)), trees)
- }
/** Implicits - some of these should probably disappear **/
implicit def mkTreeMethods(target: Tree): TreeMethods = new TreeMethods(target)
diff --git a/src/compiler/scala/tools/nsc/ast/TreeGen.scala b/src/compiler/scala/tools/nsc/ast/TreeGen.scala
index 5cb43575b8..af874ed28c 100644
--- a/src/compiler/scala/tools/nsc/ast/TreeGen.scala
+++ b/src/compiler/scala/tools/nsc/ast/TreeGen.scala
@@ -8,7 +8,6 @@ package ast
import scala.collection.mutable.ListBuffer
import symtab.Flags._
-import symtab.SymbolTable
import scala.language.postfixOps
/** XXX to resolve: TreeGen only assumes global is a SymbolTable, but
@@ -22,7 +21,7 @@ abstract class TreeGen extends scala.reflect.internal.TreeGen with TreeDSL {
def mkCheckInit(tree: Tree): Tree = {
val tpe =
- if (tree.tpe != null || !tree.hasSymbol) tree.tpe
+ if (tree.tpe != null || !tree.hasSymbolField) tree.tpe
else tree.symbol.tpe
if (!global.phase.erasedTypes && settings.warnSelectNullable.value &&
@@ -52,7 +51,10 @@ abstract class TreeGen extends scala.reflect.internal.TreeGen with TreeDSL {
}
// wrap the given expression in a SoftReference so it can be gc-ed
- def mkSoftRef(expr: Tree): Tree = atPos(expr.pos)(New(SoftReferenceClass.tpe, expr))
+ def mkSoftRef(expr: Tree): Tree = atPos(expr.pos) {
+ val constructor = SoftReferenceClass.info.nonPrivateMember(nme.CONSTRUCTOR).suchThat(_.paramss.flatten.size == 1)
+ NewFromConstructor(constructor, expr)
+ }
// annotate the expression with @unchecked
def mkUnchecked(expr: Tree): Tree = atPos(expr.pos) {
@@ -60,112 +62,19 @@ abstract class TreeGen extends scala.reflect.internal.TreeGen with TreeDSL {
// are very picky about things and it crashes the compiler with "unexpected new".
Annotated(New(scalaDot(UncheckedClass.name), Nil), expr)
}
- // if it's a Match, mark the selector unchecked; otherwise nothing.
- def mkUncheckedMatch(tree: Tree) = tree match {
- case Match(selector, cases) => atPos(tree.pos)(Match(mkUnchecked(selector), cases))
- case _ => tree
- }
-
- def mkSynthSwitchSelector(expr: Tree): Tree = atPos(expr.pos) {
- // This can't be "Annotated(New(SwitchClass), expr)" because annotations
- // are very picky about things and it crashes the compiler with "unexpected new".
- Annotated(Ident(nme.synthSwitch), expr)
- }
-
- // TODO: would be so much nicer if we would know during match-translation (i.e., type checking)
- // whether we should emit missingCase-style apply (and isDefinedAt), instead of transforming trees post-factum
- class MatchMatcher {
- def caseMatch(orig: Tree, selector: Tree, cases: List[CaseDef], wrap: Tree => Tree): Tree = unknownTree(orig)
- def caseVirtualizedMatch(orig: Tree, _match: Tree, targs: List[Tree], scrut: Tree, matcher: Tree): Tree = unknownTree(orig)
- def caseVirtualizedMatchOpt(orig: Tree, prologue: List[Tree], cases: List[Tree], matchEndDef: Tree, wrap: Tree => Tree): Tree = unknownTree(orig)
-
- def genVirtualizedMatch(prologue: List[Tree], cases: List[Tree], matchEndDef: Tree): Tree = Block(prologue ++ cases, matchEndDef)
-
- def apply(matchExpr: Tree): Tree = matchExpr match {
- // old-style match or virtpatmat switch
- case Match(selector, cases) => // println("simple match: "+ (selector, cases) + "for:\n"+ matchExpr )
- caseMatch(matchExpr, selector, cases, identity)
- // old-style match or virtpatmat switch
- case Block((vd: ValDef) :: Nil, orig@Match(selector, cases)) => // println("block match: "+ (selector, cases, vd) + "for:\n"+ matchExpr )
- caseMatch(matchExpr, selector, cases, m => copyBlock(matchExpr, List(vd), m))
- // virtpatmat
- case Apply(Apply(TypeApply(Select(tgt, nme.runOrElse), targs), List(scrut)), List(matcher)) if opt.virtPatmat => // println("virt match: "+ (tgt, targs, scrut, matcher) + "for:\n"+ matchExpr )
- caseVirtualizedMatch(matchExpr, tgt, targs, scrut, matcher)
- // optimized version of virtpatmat
- case Block(stats, matchEndDef) if opt.virtPatmat && (stats forall treeInfo.hasSynthCaseSymbol) =>
- // the assumption is once we encounter a case, the remainder of the block will consist of cases
- // the prologue may be empty, usually it is the valdef that stores the scrut
- val (prologue, cases) = stats span (s => !s.isInstanceOf[LabelDef])
- caseVirtualizedMatchOpt(matchExpr, prologue, cases, matchEndDef, identity)
- // optimized version of virtpatmat
- case Block(outerStats, orig@Block(stats, matchEndDef)) if opt.virtPatmat && (stats forall treeInfo.hasSynthCaseSymbol) =>
- val (prologue, cases) = stats span (s => !s.isInstanceOf[LabelDef])
- caseVirtualizedMatchOpt(matchExpr, prologue, cases, matchEndDef, m => copyBlock(matchExpr, outerStats, m))
- case other =>
- unknownTree(other)
- }
-
- def unknownTree(t: Tree): Tree = throw new MatchError(t)
- def copyBlock(orig: Tree, stats: List[Tree], expr: Tree): Block = Block(stats, expr)
-
- def dropSyntheticCatchAll(cases: List[CaseDef]): List[CaseDef] =
- if (!opt.virtPatmat) cases
- else cases filter {
- case CaseDef(pat, EmptyTree, Throw(Apply(Select(New(exTpt), nme.CONSTRUCTOR), _))) if (treeInfo.isWildcardArg(pat) && (exTpt.tpe.typeSymbol eq MatchErrorClass)) => false
- case CaseDef(pat, guard, body) => true
- }
- }
-
- def mkCached(cvar: Symbol, expr: Tree): Tree = {
- val cvarRef = mkUnattributedRef(cvar)
- Block(
- List(
- If(Apply(Select(cvarRef, nme.eq), List(Literal(Constant(null)))),
- Assign(cvarRef, expr),
- EmptyTree)),
- cvarRef
- )
- }
// Builds a tree of the form "{ lhs = rhs ; lhs }"
def mkAssignAndReturn(lhs: Symbol, rhs: Tree): Tree = {
- val lhsRef = mkUnattributedRef(lhs)
+ def lhsRef = if (lhs.owner.isClass) Select(This(lhs.owner), lhs) else Ident(lhs)
Block(Assign(lhsRef, rhs) :: Nil, lhsRef)
}
- def mkModuleVarDef(accessor: Symbol) = {
- val inClass = accessor.owner.isClass
- val extraFlags = if (inClass) PrivateLocal | SYNTHETIC else 0
-
- val mval = (
- accessor.owner.newVariable(nme.moduleVarName(accessor.name), accessor.pos.focus, MODULEVAR | extraFlags)
- setInfo accessor.tpe.finalResultType
- addAnnotation VolatileAttr
- )
- if (inClass)
- mval.owner.info.decls enter mval
-
- ValDef(mval)
- }
-
- // def m: T = { if (m$ eq null) m$ = new m$class(...) m$ }
- // where (...) are eventual outer accessors
- def mkCachedModuleAccessDef(accessor: Symbol, mvar: Symbol) =
- DefDef(accessor, mkCached(mvar, newModule(accessor, mvar.tpe)))
-
- def mkModuleAccessDef(accessor: Symbol, msym: Symbol) =
- DefDef(accessor, Select(This(msym.owner), msym))
-
def newModule(accessor: Symbol, tpe: Type) = {
val ps = tpe.typeSymbol.primaryConstructor.info.paramTypes
if (ps.isEmpty) New(tpe)
else New(tpe, This(accessor.owner.enclClass))
}
- // def m: T;
- def mkModuleAccessDcl(accessor: Symbol) =
- DefDef(accessor setFlag lateDEFERRED, EmptyTree)
-
def mkRuntimeCall(meth: Name, args: List[Tree]): Tree =
mkRuntimeCall(meth, Nil, args)
@@ -206,7 +115,7 @@ abstract class TreeGen extends scala.reflect.internal.TreeGen with TreeDSL {
else AppliedTypeTree(Ident(clazz), targs map TypeTree)
))
}
- def mkSuperSelect = Select(Super(This(tpnme.EMPTY), tpnme.EMPTY), nme.CONSTRUCTOR)
+ def mkSuperInitCall: Select = Select(Super(This(tpnme.EMPTY), tpnme.EMPTY), nme.CONSTRUCTOR)
def wildcardStar(tree: Tree) =
atPos(tree.pos) { Typed(tree, Ident(tpnme.WILDCARD_STAR)) }
@@ -262,25 +171,6 @@ abstract class TreeGen extends scala.reflect.internal.TreeGen with TreeDSL {
else
mkCast(tree, pt)
- def mkZeroContravariantAfterTyper(tp: Type): Tree = {
- // contravariant -- for replacing an argument in a method call
- // must use subtyping, as otherwise we miss types like `Any with Int`
- val tree =
- if (NullClass.tpe <:< tp) Literal(Constant(null))
- else if (UnitClass.tpe <:< tp) Literal(Constant())
- else if (BooleanClass.tpe <:< tp) Literal(Constant(false))
- else if (FloatClass.tpe <:< tp) Literal(Constant(0.0f))
- else if (DoubleClass.tpe <:< tp) Literal(Constant(0.0d))
- else if (ByteClass.tpe <:< tp) Literal(Constant(0.toByte))
- else if (ShortClass.tpe <:< tp) Literal(Constant(0.toShort))
- else if (IntClass.tpe <:< tp) Literal(Constant(0))
- else if (LongClass.tpe <:< tp) Literal(Constant(0L))
- else if (CharClass.tpe <:< tp) Literal(Constant(0.toChar))
- else mkCast(Literal(Constant(null)), tp)
-
- tree
- }
-
/** Translate names in Select/Ident nodes to type names.
*/
def convertToTypeName(tree: Tree): Option[RefTree] = tree match {
@@ -302,7 +192,7 @@ abstract class TreeGen extends scala.reflect.internal.TreeGen with TreeDSL {
*/
private def mkPackedValDef(expr: Tree, owner: Symbol, name: Name): (ValDef, () => Ident) = {
val packedType = typer.packedType(expr, owner)
- val sym = owner.newValue(name, expr.pos.makeTransparent, SYNTHETIC) setInfo packedType
+ val sym = owner.newValue(name.toTermName, expr.pos.makeTransparent, SYNTHETIC) setInfo packedType
(ValDef(sym, expr), () => Ident(sym) setPos sym.pos.focus setType expr.tpe)
}
diff --git a/src/compiler/scala/tools/nsc/ast/TreeInfo.scala b/src/compiler/scala/tools/nsc/ast/TreeInfo.scala
index cbbb4c8ba8..f53f99a279 100644
--- a/src/compiler/scala/tools/nsc/ast/TreeInfo.scala
+++ b/src/compiler/scala/tools/nsc/ast/TreeInfo.scala
@@ -6,10 +6,6 @@
package scala.tools.nsc
package ast
-import scala.reflect.internal.HasFlags
-import scala.reflect.internal.Flags._
-import symtab._
-
/** This class ...
*
* @author Martin Odersky
@@ -19,8 +15,6 @@ abstract class TreeInfo extends scala.reflect.internal.TreeInfo {
val global: Global
import global._
- import definitions.ThrowableClass
-
/** Is tree legal as a member definition of an interface?
*/
override def isInterfaceMember(tree: Tree): Boolean = tree match {
@@ -42,7 +36,4 @@ abstract class TreeInfo extends scala.reflect.internal.TreeInfo {
case ClassDef(_, `name`, _, _) :: Nil => true
case _ => super.firstDefinesClassOrObject(trees, name)
}
-
- def isInterface(mods: HasFlags, body: List[Tree]) =
- mods.isTrait && (body forall isInterfaceMember)
}
diff --git a/src/compiler/scala/tools/nsc/ast/Trees.scala b/src/compiler/scala/tools/nsc/ast/Trees.scala
index 54402f0903..4b5e23e177 100644
--- a/src/compiler/scala/tools/nsc/ast/Trees.scala
+++ b/src/compiler/scala/tools/nsc/ast/Trees.scala
@@ -68,8 +68,8 @@ trait Trees extends scala.reflect.internal.Trees { self: Global =>
/** Factory method for a primary constructor super call `super.<init>(args_1)...(args_n)`
*/
def PrimarySuperCall(argss: List[List[Tree]]): Tree = argss match {
- case Nil => Apply(gen.mkSuperSelect, Nil)
- case xs :: rest => rest.foldLeft(Apply(gen.mkSuperSelect, xs): Tree)(Apply.apply)
+ case Nil => Apply(gen.mkSuperInitCall, Nil)
+ case xs :: rest => rest.foldLeft(Apply(gen.mkSuperInitCall, xs): Tree)(Apply.apply)
}
/** Generates a template with constructor corresponding to
@@ -111,7 +111,7 @@ trait Trees extends scala.reflect.internal.Trees { self: Global =>
rhs = EmptyTree
)
}
- val lvdefs = evdefs collect { case vdef: ValDef => copyValDef(vdef)(mods = Modifiers(PRESUPER)) }
+ val lvdefs = evdefs collect { case vdef: ValDef => copyValDef(vdef)(mods = vdef.mods | PRESUPER) }
val constrs = {
if (constrMods hasFlag TRAIT) {
@@ -123,7 +123,7 @@ trait Trees extends scala.reflect.internal.Trees { self: Global =>
// convert (implicit ... ) to ()(implicit ... ) if its the only parameter section
if (vparamss1.isEmpty || !vparamss1.head.isEmpty && vparamss1.head.head.mods.isImplicit)
vparamss1 = List() :: vparamss1;
- val superRef: Tree = atPos(superPos)(gen.mkSuperSelect)
+ val superRef: Tree = atPos(superPos)(gen.mkSuperInitCall)
val superCall = pendingSuperCall // we can't know in advance which of the parents will end up as a superclass
// this requires knowing which of the parents is a type macro and which is not
// and that's something that cannot be found out before typer
@@ -343,9 +343,7 @@ trait Trees extends scala.reflect.internal.Trees { self: Global =>
if (tpt.original != null)
transform(tpt.original)
else if (tpt.tpe != null && (tpt.wasEmpty || (tpt.tpe exists (tp => locals contains tp.typeSymbol)))) {
- val dupl = tpt.duplicate
- dupl.tpe = null
- dupl
+ tpt.duplicate.clearType()
}
else tree
case TypeApply(fn, args) if args map transform exists (_.isEmpty) =>
@@ -354,10 +352,9 @@ trait Trees extends scala.reflect.internal.Trees { self: Global =>
tree
case _ =>
val dupl = tree.duplicate
- if (tree.hasSymbol && (!localOnly || (locals contains tree.symbol)) && !(keepLabels && tree.symbol.isLabel))
+ if (tree.hasSymbolField && (!localOnly || (locals contains tree.symbol)) && !(keepLabels && tree.symbol.isLabel))
dupl.symbol = NoSymbol
- dupl.tpe = null
- dupl
+ dupl.clearType()
}
}
}
diff --git a/src/compiler/scala/tools/nsc/ast/parser/MarkupParsers.scala b/src/compiler/scala/tools/nsc/ast/parser/MarkupParsers.scala
index 553a2088a6..639780149e 100755
--- a/src/compiler/scala/tools/nsc/ast/parser/MarkupParsers.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/MarkupParsers.scala
@@ -10,10 +10,8 @@ import scala.collection.mutable
import mutable.{ Buffer, ArrayBuffer, ListBuffer }
import scala.util.control.ControlThrowable
import scala.tools.nsc.util.CharArrayReader
-import scala.reflect.internal.util.SourceFile
-import scala.xml.{ Text, TextBuffer }
+import scala.xml.TextBuffer
import scala.xml.parsing.MarkupParserCommon
-import scala.xml.Utility.{ isNameStart, isNameChar, isSpace }
import scala.reflect.internal.Chars.{ SU, LF }
// XXX/Note: many/most of the functions in here are almost direct cut and pastes
@@ -26,12 +24,6 @@ import scala.reflect.internal.Chars.{ SU, LF }
// I rewrote most of these, but not as yet the library versions: so if you are
// tempted to touch any of these, please be aware of that situation and try not
// to let it get any worse. -- paulp
-
-/** This trait ...
- *
- * @author Burak Emir
- * @version 1.0
- */
trait MarkupParsers {
self: Parsers =>
@@ -51,7 +43,7 @@ trait MarkupParsers {
class MarkupParser(parser: SourceFileParser, final val preserveWS: Boolean) extends MarkupParserCommon {
- import Tokens.{ EMPTY, LBRACE, RBRACE }
+ import Tokens.{ LBRACE, RBRACE }
type PositionType = Position
type InputType = CharArrayReader
@@ -89,7 +81,7 @@ trait MarkupParsers {
var xEmbeddedBlock = false
- private var debugLastStartElement = new mutable.Stack[(Int, String)]
+ private val debugLastStartElement = new mutable.Stack[(Int, String)]
private def debugLastPos = debugLastStartElement.top._1
private def debugLastElem = debugLastStartElement.top._2
@@ -124,7 +116,6 @@ trait MarkupParsers {
val start = curOffset
val key = xName
xEQ
- val delim = ch
val mid = curOffset
val value: Tree = ch match {
case '"' | '\'' =>
@@ -219,9 +210,6 @@ trait MarkupParsers {
/** Returns true if it encounters an end tag (without consuming it),
* appends trees to ts as side-effect.
- *
- * @param ts ...
- * @return ...
*/
private def content_LT(ts: ArrayBuffer[Tree]): Boolean = {
if (ch == '/')
@@ -410,7 +398,7 @@ trait MarkupParsers {
* | Name [S] '/' '>'
*/
def xPattern: Tree = {
- var start = curOffset
+ val start = curOffset
val qname = xName
debugLastStartElement.push((start, qname))
xSpaceOpt
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
index 33db4ee2d5..76d7af7cc6 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
@@ -9,7 +9,8 @@
package scala.tools.nsc
package ast.parser
-import scala.collection.mutable.{ListBuffer, StringBuilder}
+import scala.collection.{ mutable, immutable }
+import mutable.{ ListBuffer, StringBuilder }
import scala.reflect.internal.{ ModifierFlags => Flags }
import scala.reflect.internal.Chars.{ isScalaLetter }
import scala.reflect.internal.util.{ SourceFile, OffsetPosition }
@@ -94,7 +95,7 @@ trait ParsersCommon extends ScannersCommon {
* <ol>
* <li>
* Places all pattern variables in Bind nodes. In a pattern, for
- * identifiers <code>x</code>:<pre>
+ * identifiers `x`:<pre>
* x => x @ _
* x:T => x @ (_ : T)</pre>
* </li>
@@ -167,7 +168,6 @@ self =>
object symbXMLBuilder extends SymbolicXMLBuilder(this, preserveWS = true) { // DEBUG choices
val global: self.global.type = self.global
- def freshName(prefix: String): Name = SourceFileParser.this.freshName(prefix)
}
def xmlLiteral : Tree = xmlp.xLiteral
@@ -299,11 +299,7 @@ self =>
inScalaPackage = false
currentPackage = ""
}
- private lazy val primitiveNames: Set[Name] = tpnme.ScalaValueNames.toSet
-
- private def inScalaRootPackage = inScalaPackage && currentPackage == "scala"
- private def isScalaArray(name: Name) = inScalaRootPackage && name == tpnme.Array
- private def isPrimitiveType(name: Name) = inScalaRootPackage && primitiveNames(name)
+ private def inScalaRootPackage = inScalaPackage && currentPackage == "scala"
def parseStartRule: () => Tree
@@ -380,7 +376,6 @@ self =>
* }
* }}}
*/
- import definitions._
def emptyPkg = atPos(0, 0, 0) { Ident(nme.EMPTY_PACKAGE_NAME) }
def emptyInit = DefDef(
@@ -389,7 +384,7 @@ self =>
Nil,
ListOfNil,
TypeTree(),
- Block(List(Apply(gen.mkSuperSelect, Nil)), Literal(Constant(())))
+ Block(List(Apply(gen.mkSuperInitCall, Nil)), Literal(Constant(())))
)
// def main
@@ -468,7 +463,7 @@ self =>
/* ------------- ERROR HANDLING ------------------------------------------- */
- var assumedClosingParens = scala.collection.mutable.Map(RPAREN -> 0, RBRACKET -> 0, RBRACE -> 0)
+ val assumedClosingParens = mutable.Map(RPAREN -> 0, RBRACKET -> 0, RBRACE -> 0)
private var inFunReturnType = false
@inline private def fromWithinReturnType[T](body: => T): T = {
@@ -645,8 +640,6 @@ self =>
case _ => false
}
- def isTypeIntro: Boolean = isTypeIntroToken(in.token)
-
def isStatSeqEnd = in.token == RBRACE || in.token == EOF
def isStatSep(token: Int): Boolean =
@@ -708,10 +701,10 @@ self =>
tree match {
case Ident(name) =>
removeAsPlaceholder(name)
- makeParam(name, TypeTree() setPos o2p(tree.pos.endOrPoint))
+ makeParam(name.toTermName, TypeTree() setPos o2p(tree.pos.endOrPoint))
case Typed(Ident(name), tpe) if tpe.isType => // get the ident!
removeAsPlaceholder(name)
- makeParam(name, tpe)
+ makeParam(name.toTermName, tpe)
case _ =>
syntaxError(tree.pos, "not a legal formal parameter", false)
makeParam(nme.ERROR, errorTypeTree setPos o2p(tree.pos.endOrPoint))
@@ -770,10 +763,6 @@ self =>
}
}
- def checkSize(kind: String, size: Int, max: Int) {
- if (size > max) syntaxError("too many "+kind+", maximum = "+max, false)
- }
-
def checkAssoc(offset: Int, op: Name, leftAssoc: Boolean) =
if (treeInfo.isLeftAssoc(op) != leftAssoc)
syntaxError(
@@ -794,7 +783,7 @@ self =>
val rPos = top.pos
val end = if (rPos.isDefined) rPos.endOrPoint else opPos.endOrPoint
top = atPos(start, opinfo.offset, end) {
- makeBinop(isExpr, opinfo.operand, opinfo.operator, top, opPos)
+ makeBinop(isExpr, opinfo.operand, opinfo.operator.toTermName, top, opPos)
}
}
top
@@ -923,7 +912,7 @@ self =>
)
def compoundTypeRest(t: Tree): Tree = {
- var ts = new ListBuffer[Tree] += t
+ val ts = new ListBuffer[Tree] += t
while (in.token == WITH) {
in.nextToken()
ts += annotType()
@@ -980,11 +969,8 @@ self =>
/** Assumed (provisionally) to be TermNames. */
def ident(skipIt: Boolean): Name =
- if (isIdent) {
- val name = in.name.encode
- in.nextToken()
- name
- } else {
+ if (isIdent) rawIdent().encode
+ else {
syntaxErrorOrIncomplete(expectedMsg(IDENTIFIER), skipIt)
nme.ERROR
}
@@ -1138,16 +1124,7 @@ self =>
})
}
- private def stringOp(t: Tree, op: TermName) = {
- val str = in.strVal
- in.nextToken()
- if (str.length == 0) t
- else atPos(t.pos.startOrPoint) {
- Apply(Select(t, op), List(Literal(Constant(str))))
- }
- }
-
- private def interpolatedString(inPattern: Boolean = false): Tree = atPos(in.offset) {
+ private def interpolatedString(inPattern: Boolean): Tree = atPos(in.offset) {
val start = in.offset
val interpolator = in.name
@@ -1231,15 +1208,6 @@ self =>
/* ----------- EXPRESSIONS ------------------------------------------------ */
- /** {{{
- * EqualsExpr ::= `=' Expr
- * }}}
- */
- def equalsExpr(): Tree = {
- accept(EQUALS)
- expr()
- }
-
def condExpr(): Tree = {
if (in.token == LPAREN) {
in.nextToken()
@@ -1283,7 +1251,7 @@ self =>
def expr(): Tree = expr(Local)
def expr(location: Int): Tree = {
- var savedPlaceholderParams = placeholderParams
+ val savedPlaceholderParams = placeholderParams
placeholderParams = List()
var res = expr0(location)
if (!placeholderParams.isEmpty && !isWildcard(res)) {
@@ -1333,26 +1301,24 @@ self =>
parseTry
case WHILE =>
def parseWhile = {
- val start = in.offset
atPos(in.skipToken()) {
val lname: Name = freshTermName(nme.WHILE_PREFIX)
val cond = condExpr()
newLinesOpt()
val body = expr()
- makeWhile(lname, cond, body)
+ makeWhile(lname.toTermName, cond, body)
}
}
parseWhile
case DO =>
def parseDo = {
- val start = in.offset
atPos(in.skipToken()) {
val lname: Name = freshTermName(nme.DO_WHILE_PREFIX)
val body = expr()
if (isStatSep) in.nextToken()
accept(WHILE)
val cond = condExpr()
- makeDoWhile(lname, body, cond)
+ makeDoWhile(lname.toTermName, body, cond)
}
}
parseDo
@@ -1511,7 +1477,7 @@ self =>
def prefixExpr(): Tree = {
if (isUnaryOp) {
atPos(in.offset) {
- val name = nme.toUnaryName(rawIdent())
+ val name = nme.toUnaryName(rawIdent().toTermName)
if (name == nme.UNARY_- && isNumericLit)
simpleExprRest(atPos(in.offset)(literal(isNegated = true)), canApply = true)
else
@@ -1549,7 +1515,7 @@ self =>
val pname = freshName("x$")
in.nextToken()
val id = atPos(start) (Ident(pname))
- val param = atPos(id.pos.focus){ makeSyntheticParam(pname) }
+ val param = atPos(id.pos.focus){ makeSyntheticParam(pname.toTermName) }
placeholderParams = param :: placeholderParams
id
case LPAREN =>
@@ -1809,7 +1775,6 @@ self =>
* }}}
*/
def pattern2(): Tree = {
- val nameOffset = in.offset
val p = pattern3()
if (in.token != AT) p
@@ -1922,7 +1887,7 @@ self =>
val start = in.offset
in.token match {
case IDENTIFIER | BACKQUOTED_IDENT | THIS =>
- var t = stableId()
+ val t = stableId()
in.token match {
case INTLIT | LONGLIT | FLOATLIT | DOUBLELIT =>
t match {
@@ -1984,7 +1949,6 @@ self =>
/** Default entry points into some pattern contexts. */
def pattern(): Tree = noSeq.pattern()
- def patterns(): List[Tree] = noSeq.patterns()
def seqPatterns(): List[Tree] = seqOK.patterns()
def xmlSeqPatterns(): List[Tree] = xmlSeqOK.patterns() // Called from xml parser
def argumentPatterns(): List[Tree] = inParens {
@@ -2172,7 +2136,7 @@ self =>
expr()
} else EmptyTree
atPos(start, if (name == nme.ERROR) start else nameOffset) {
- ValDef((mods | implicitmod | bynamemod) withAnnotations annots, name, tpt, default)
+ ValDef((mods | implicitmod | bynamemod) withAnnotations annots, name.toTermName, tpt, default)
}
}
def paramClause(): List[ValDef] = {
@@ -2629,7 +2593,6 @@ self =>
in.nextToken()
newLinesOpt()
atPos(start, in.offset) {
- val nameOffset = in.offset
val name = identForType()
// @M! a type alias as well as an abstract type may declare type parameters
val tparams = typeParamClauseOpt(name, null)
@@ -2733,7 +2696,7 @@ self =>
atPos(start, if (name == nme.ERROR) start else nameOffset) {
val mods1 = if (in.token == SUBTYPE) mods | Flags.DEFERRED else mods
val template = templateOpt(mods1, name, NoMods, Nil, tstart)
- ModuleDef(mods1, name, template)
+ ModuleDef(mods1, name.toTermName, template)
}
}
@@ -2904,7 +2867,6 @@ self =>
* }}}
*/
def packaging(start: Int): Tree = {
- val nameOffset = in.offset
val pkg = pkgQualId()
val stats = inBracesOrNil(topStatSeq())
makePackaging(start, pkg, stats)
@@ -3114,7 +3076,6 @@ self =>
ts ++= topStatSeq()
}
} else {
- val nameOffset = in.offset
in.flushDoc
val pkg = pkgQualId()
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala
index 4f564c5d0b..af7f48988f 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala
@@ -10,7 +10,8 @@ import scala.reflect.internal.util._
import scala.reflect.internal.Chars._
import Tokens._
import scala.annotation.switch
-import scala.collection.mutable.{ ListBuffer, ArrayBuffer }
+import scala.collection.{ mutable, immutable }
+import mutable.{ ListBuffer, ArrayBuffer }
import scala.xml.Utility.{ isNameStart }
/** See Parsers.scala / ParsersCommon for some explanation of ScannersCommon.
@@ -26,7 +27,6 @@ trait ScannersCommon {
trait ScannerCommon extends CommonTokenData {
// things to fill in, in addition to buf, decodeUni which come from CharArrayReader
- def warning(off: Int, msg: String): Unit
def error (off: Int, msg: String): Unit
def incompleteInputError(off: Int, msg: String): Unit
def deprecationWarning(off: Int, msg: String): Unit
@@ -50,9 +50,6 @@ trait Scanners extends ScannersCommon {
/** Offset into source character array */
type Offset = Int
- /** An undefined offset */
- val NoOffset: Offset = -1
-
trait TokenData extends CommonTokenData {
/** the next token */
@@ -88,8 +85,6 @@ trait Scanners extends ScannersCommon {
def isAtEnd = charOffset >= buf.length
- def flush = { charOffset = offset; nextChar(); this }
-
def resume(lastCode: Int) = {
token = lastCode
if (next.token != EMPTY && !reporter.hasErrors)
@@ -98,10 +93,6 @@ trait Scanners extends ScannersCommon {
nextToken()
}
- /** the last error offset
- */
- var errOffset: Offset = NoOffset
-
/** A character buffer for literals
*/
val cbuf = new StringBuilder
@@ -283,10 +274,16 @@ trait Scanners extends ScannersCommon {
prev copyFrom this
val nextLastOffset = charOffset - 1
fetchToken()
+ def resetOffset() {
+ offset = prev.offset
+ lastOffset = prev.lastOffset
+ }
if (token == CLASS) {
token = CASECLASS
+ resetOffset()
} else if (token == OBJECT) {
token = CASEOBJECT
+ resetOffset()
} else {
lastOffset = nextLastOffset
next copyFrom this
@@ -402,7 +399,7 @@ trait Scanners extends ScannersCommon {
* there a realistic situation where one would need it?
*/
if (isDigit(ch)) {
- if (opt.future) syntaxError("Non-zero numbers may not have a leading zero.")
+ if (settings.future.value) syntaxError("Non-zero numbers may not have a leading zero.")
else deprecationWarning("Treating numbers with a leading zero as octal is deprecated.")
}
base = 8
@@ -607,7 +604,10 @@ trait Scanners extends ScannersCommon {
if (ch == '`') {
nextChar()
finishNamed(BACKQUOTED_IDENT)
- if (name.length == 0) syntaxError("empty quoted identifier")
+ if (name.length == 0)
+ syntaxError("empty quoted identifier")
+ else if (name == nme.WILDCARD)
+ syntaxError("wildcard invalid as backquoted identifier")
}
else syntaxError("unclosed quoted identifier")
}
@@ -998,9 +998,9 @@ trait Scanners extends ScannersCommon {
val c = lookahead.getc()
/** As of scala 2.11, it isn't a number unless c here is a digit, so
- * opt.future excludes the rest of the logic.
+ * settings.future.value excludes the rest of the logic.
*/
- if (opt.future && !isDigit(c))
+ if (settings.future.value && !isDigit(c))
return setStrVal()
val isDefinitelyNumber = (c: @switch) match {
@@ -1054,7 +1054,6 @@ trait Scanners extends ScannersCommon {
def syntaxError(off: Offset, msg: String) {
error(off, msg)
token = ERROR
- errOffset = off
}
/** generate an error at the current token offset
@@ -1067,7 +1066,6 @@ trait Scanners extends ScannersCommon {
def incompleteInputError(msg: String) {
incompleteInputError(offset, msg)
token = EOF
- errOffset = offset
}
override def toString() = token match {
@@ -1232,7 +1230,6 @@ trait Scanners extends ScannersCommon {
override val decodeUni: Boolean = !settings.nouescape.value
// suppress warnings, throw exception on errors
- def warning(off: Offset, msg: String): Unit = ()
def deprecationWarning(off: Offset, msg: String): Unit = ()
def error (off: Offset, msg: String): Unit = throw new MalformedInput(off, msg)
def incompleteInputError(off: Offset, msg: String): Unit = throw new MalformedInput(off, msg)
@@ -1243,7 +1240,6 @@ trait Scanners extends ScannersCommon {
class UnitScanner(unit: CompilationUnit, patches: List[BracePatch]) extends SourceFileScanner(unit.source) {
def this(unit: CompilationUnit) = this(unit, List())
- override def warning(off: Offset, msg: String) = unit.warning(unit.position(off), msg)
override def deprecationWarning(off: Offset, msg: String) = unit.deprecationWarning(unit.position(off), msg)
override def error (off: Offset, msg: String) = unit.error(unit.position(off), msg)
override def incompleteInputError(off: Offset, msg: String) = unit.incompleteInputError(unit.position(off), msg)
@@ -1302,7 +1298,7 @@ trait Scanners extends ScannersCommon {
}
class ParensAnalyzer(unit: CompilationUnit, patches: List[BracePatch]) extends UnitScanner(unit, patches) {
- var balance = scala.collection.mutable.Map(RPAREN -> 0, RBRACKET -> 0, RBRACE -> 0)
+ val balance = mutable.Map(RPAREN -> 0, RBRACKET -> 0, RBRACE -> 0)
init()
@@ -1424,18 +1420,6 @@ trait Scanners extends ScannersCommon {
else bp :: insertPatch(bps, patch)
}
- def leftColumn(offset: Int) =
- if (offset == -1) -1 else column(lineStart(line(offset)))
-
- def rightColumn(offset: Int, default: Int) =
- if (offset == -1) -1
- else {
- val rlin = line(offset)
- if (lineStart(rlin) == offset) column(offset)
- else if (rlin + 1 < lineStart.length) column(lineStart(rlin + 1))
- else default
- }
-
def insertRBrace(): List[BracePatch] = {
def insert(bps: List[BracePair]): List[BracePatch] = bps match {
case List() => patches
@@ -1477,17 +1461,6 @@ trait Scanners extends ScannersCommon {
delete(bracePairs)
}
- def imbalanceMeasure: Int = {
- def measureList(bps: List[BracePair]): Int =
- (bps map measure).sum
- def measure(bp: BracePair): Int =
- (if (bp.lindent != bp.rindent) 1 else 0) + measureList(bp.nested)
- measureList(bracePairs)
- }
-
- def improves(patches1: List[BracePatch]): Boolean =
- imbalanceMeasure > new ParensAnalyzer(unit, patches1).imbalanceMeasure
-
override def error(offset: Int, msg: String) {}
}
}
diff --git a/src/compiler/scala/tools/nsc/ast/parser/SymbolicXMLBuilder.scala b/src/compiler/scala/tools/nsc/ast/parser/SymbolicXMLBuilder.scala
index e8ef670222..4329ccefc7 100755
--- a/src/compiler/scala/tools/nsc/ast/parser/SymbolicXMLBuilder.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/SymbolicXMLBuilder.scala
@@ -11,7 +11,6 @@ import scala.xml.{ EntityRef, Text }
import scala.xml.XML.{ xmlns }
import symtab.Flags.MUTABLE
import scala.reflect.internal.util.StringOps.splitWhere
-import scala.language.implicitConversions
/** This class builds instance of `Tree` that represent XML.
*
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Tokens.scala b/src/compiler/scala/tools/nsc/ast/parser/Tokens.scala
index c3fd414426..5a7dc4950d 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/Tokens.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/Tokens.scala
@@ -6,15 +6,11 @@
package scala.tools.nsc
package ast.parser
-import scala.annotation.switch
-
/** Common code between JavaTokens and Tokens. Not as much (and not as concrete)
* as one might like because JavaTokens for no clear reason chose new numbers for
* identical token sets.
*/
abstract class Tokens {
- import scala.reflect.internal.Chars._
-
/** special tokens */
final val EMPTY = -3
final val UNDEF = -2
@@ -34,14 +30,6 @@ abstract class Tokens {
def isIdentifier(code: Int): Boolean
def isLiteral(code: Int): Boolean
- def isKeyword(code: Int): Boolean
- def isSymbol(code: Int): Boolean
-
- final def isSpace(at: Char) = at == ' ' || at == '\t'
- final def isNewLine(at: Char) = at == CR || at == LF || at == FF
- final def isBrace(code: Int) = code >= LPAREN && code <= RBRACE
- final def isOpenBrace(code: Int) = isBrace(code) && (code % 2 == 0)
- final def isCloseBrace(code: Int) = isBrace(code) && (code % 2 == 1)
}
object Tokens extends Tokens {
@@ -52,20 +40,10 @@ object Tokens extends Tokens {
def isLiteral(code: Int) =
code >= CHARLIT && code <= INTERPOLATIONID
-
/** identifiers */
final val IDENTIFIER = 10
final val BACKQUOTED_IDENT = 11
- def isIdentifier(code: Int) =
- code >= IDENTIFIER && code <= BACKQUOTED_IDENT
-
- @switch def canBeginExpression(code: Int) = code match {
- case IDENTIFIER|BACKQUOTED_IDENT|USCORE => true
- case LBRACE|LPAREN|LBRACKET|COMMENT => true
- case IF|DO|WHILE|FOR|NEW|TRY|THROW => true
- case NULL|THIS|TRUE|FALSE => true
- case code => isLiteral(code)
- }
+ def isIdentifier(code: Int) = code >= IDENTIFIER && code <= BACKQUOTED_IDENT // used by ide
/** keywords */
final val IF = 20
@@ -113,17 +91,6 @@ object Tokens extends Tokens {
final val MACRO = 62 // not yet used in 2.10
final val THEN = 63 // not yet used in 2.10
- def isKeyword(code: Int) =
- code >= IF && code <= LAZY
-
- @switch def isDefinition(code: Int) = code match {
- case CLASS|TRAIT|OBJECT => true
- case CASECLASS|CASEOBJECT => true
- case DEF|VAL|VAR => true
- case TYPE => true
- case _ => false
- }
-
/** special symbols */
final val COMMA = 70
final val SEMI = 71
@@ -141,9 +108,6 @@ object Tokens extends Tokens {
final val AT = 83
final val VIEWBOUND = 84
- def isSymbol(code: Int) =
- code >= COMMA && code <= VIEWBOUND
-
/** parenthesis */
final val LPAREN = 90
final val RPAREN = 91
diff --git a/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala b/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala
index f94055f666..39270719fb 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala
@@ -26,15 +26,11 @@ abstract class TreeBuilder {
def o2p(offset: Int): Position
def r2p(start: Int, point: Int, end: Int): Position
- def rootId(name: Name) = gen.rootId(name)
def rootScalaDot(name: Name) = gen.rootScalaDot(name)
def scalaDot(name: Name) = gen.scalaDot(name)
def scalaAnyRefConstr = scalaDot(tpnme.AnyRef)
- def scalaAnyValConstr = scalaDot(tpnme.AnyVal)
- def scalaAnyConstr = scalaDot(tpnme.Any)
def scalaUnitConstr = scalaDot(tpnme.Unit)
def productConstr = scalaDot(tpnme.Product)
- def productConstrN(n: Int) = scalaDot(newTypeName("Product" + n))
def serializableConstr = scalaDot(tpnme.Serializable)
def convertToTypeName(t: Tree) = gen.convertToTypeName(t)
@@ -191,7 +187,7 @@ abstract class TreeBuilder {
} else {
val x = freshTermName()
Block(
- List(ValDef(Modifiers(SYNTHETIC), x, TypeTree(), stripParens(left))),
+ List(ValDef(Modifiers(SYNTHETIC | ARTIFACT), x, TypeTree(), stripParens(left))),
Apply(atPos(opPos union right.pos) { Select(stripParens(right), op.encode) }, List(Ident(x))))
}
} else {
@@ -385,13 +381,6 @@ abstract class TreeBuilder {
def makeCombination(pos: Position, meth: TermName, qual: Tree, pat: Tree, body: Tree): Tree =
Apply(Select(qual, meth) setPos qual.pos, List(makeClosure(pos, pat, body))) setPos pos
- /** Optionally, if pattern is a `Bind`, the bound name, otherwise None.
- */
- def patternVar(pat: Tree): Option[Name] = pat match {
- case Bind(name, _) => Some(name)
- case _ => None
- }
-
/** If `pat` is not yet a `Bind` wrap it in one with a fresh name
*/
def makeBind(pat: Tree): Tree = pat match {
@@ -457,18 +446,6 @@ abstract class TreeBuilder {
def makeForYield(enums: List[Enumerator], body: Tree): Tree =
makeFor(nme.map, nme.flatMap, enums, body)
- /** Create tree for a lifted expression XX-LIFTING
- */
- def makeLifted(gs: List[ValFrom], body: Tree): Tree = {
- def combine(gs: List[ValFrom]): ValFrom = (gs: @unchecked) match {
- case g :: Nil => g
- case ValFrom(pos1, pat1, rhs1) :: gs2 =>
- val ValFrom(pos2, pat2, rhs2) = combine(gs2)
- ValFrom(pos1, makeTuple(List(pat1, pat2), false), Apply(Select(rhs1, nme.zip), List(rhs2)))
- }
- makeForYield(List(combine(gs)), body)
- }
-
/** Create tree for a pattern alternative */
def makeAlternative(ts: List[Tree]): Tree = {
def alternatives(t: Tree): List[Tree] = t match {
@@ -503,7 +480,7 @@ abstract class TreeBuilder {
def makeCatchFromExpr(catchExpr: Tree): CaseDef = {
val binder = freshTermName("x")
val pat = Bind(binder, Typed(Ident(nme.WILDCARD), Ident(tpnme.Throwable)))
- val catchDef = ValDef(NoMods, freshTermName("catchExpr"), TypeTree(), catchExpr)
+ val catchDef = ValDef(Modifiers(ARTIFACT), freshTermName("catchExpr"), TypeTree(), catchExpr)
val catchFn = Ident(catchDef.name)
val body = atPos(catchExpr.pos.makeTransparent)(Block(
List(catchDef),
@@ -574,7 +551,7 @@ abstract class TreeBuilder {
val tmp = freshTermName()
val firstDef =
atPos(matchExpr.pos) {
- ValDef(Modifiers(PrivateLocal | SYNTHETIC | (mods.flags & LAZY)),
+ ValDef(Modifiers(PrivateLocal | SYNTHETIC | ARTIFACT | (mods.flags & LAZY)),
tmp, TypeTree(), matchExpr)
}
var cnt = 0
diff --git a/src/compiler/scala/tools/nsc/backend/JavaPlatform.scala b/src/compiler/scala/tools/nsc/backend/JavaPlatform.scala
index fc5d4372c5..5cc4404ca1 100644
--- a/src/compiler/scala/tools/nsc/backend/JavaPlatform.scala
+++ b/src/compiler/scala/tools/nsc/backend/JavaPlatform.scala
@@ -8,7 +8,6 @@ package backend
import io.AbstractFile
import util.{ClassPath,JavaClassPath,MergedClassPath,DeltaClassPath}
-import util.ClassPath.{ JavaContext, DefaultJavaContext }
import scala.tools.util.PathResolver
trait JavaPlatform extends Platform {
@@ -43,13 +42,9 @@ trait JavaPlatform extends Platform {
if (settings.make.isDefault) Nil
else List(dependencyAnalysis)
- private def classEmitPhase =
- if (settings.target.value == "jvm-1.5-fjbg") genJVM
- else genASM
-
def platformPhases = List(
flatten, // get rid of inner classes
- classEmitPhase // generate .class files
+ genASM // generate .class files
) ++ depAnalysisPhase
lazy val externalEquals = getDecl(BoxesRunTimeClass, nme.equals_)
diff --git a/src/compiler/scala/tools/nsc/backend/MSILPlatform.scala b/src/compiler/scala/tools/nsc/backend/MSILPlatform.scala
deleted file mode 100644
index 4493685b52..0000000000
--- a/src/compiler/scala/tools/nsc/backend/MSILPlatform.scala
+++ /dev/null
@@ -1,69 +0,0 @@
-/* NSC -- new Scala compiler
- * Copyright 2005-2013 LAMP/EPFL
- * @author Paul Phillips
- */
-
-package scala.tools.nsc
-package backend
-
-import ch.epfl.lamp.compiler.{ msil => msillib }
-import util.{ ClassPath, MsilClassPath }
-import msil.GenMSIL
-import io.{ AbstractFile, MsilFile }
-
-trait MSILPlatform extends Platform {
- import global._
- import definitions.{ ComparatorClass, BoxedNumberClass, getMember }
-
- type BinaryRepr = MsilFile
-
- if (settings.verbose.value)
- inform("[AssemRefs = " + settings.assemrefs.value + "]")
-
- // phaseName = "msil"
- object genMSIL extends {
- val global: MSILPlatform.this.global.type = MSILPlatform.this.global
- val runsAfter = List[String]("dce")
- val runsRightAfter = None
- } with GenMSIL
-
- lazy val classPath = MsilClassPath.fromSettings(settings)
- def rootLoader = new loaders.PackageLoader(classPath.asInstanceOf[ClassPath[platform.BinaryRepr]])
- // See discussion in JavaPlatForm for why we need a cast here.
-
- /** Update classpath with a substituted subentry */
- def updateClassPath(subst: Map[ClassPath[BinaryRepr], ClassPath[BinaryRepr]]) =
- throw new UnsupportedOperationException("classpath invalidations not supported on MSIL")
-
- def platformPhases = List(
- genMSIL // generate .msil files
- )
-
- lazy val externalEquals = getMember(ComparatorClass.companionModule, nme.equals_)
- def isMaybeBoxed(sym: Symbol) = sym isNonBottomSubClass BoxedNumberClass
-
- def newClassLoader(bin: MsilFile): loaders.SymbolLoader = new loaders.MsilFileLoader(bin)
-
- /**
- * Tells whether a class should be loaded and entered into the package
- * scope. On .NET, this method returns `false` for all synthetic classes
- * (anonymous classes, implementation classes, module classes), their
- * symtab is encoded in the pickle of another class.
- */
- def doLoad(cls: ClassPath[BinaryRepr]#ClassRep): Boolean = {
- if (cls.binary.isDefined) {
- val typ = cls.binary.get.msilType
- if (typ.IsDefined(loaders.clrTypes.SCALA_SYMTAB_ATTR, false)) {
- val attrs = typ.GetCustomAttributes(loaders.clrTypes.SCALA_SYMTAB_ATTR, false)
- assert(attrs.length == 1, attrs.length)
- val a = attrs(0).asInstanceOf[msillib.Attribute]
- // symtab_constr takes a byte array argument (the pickle), i.e. typ has a pickle.
- // otherwise, symtab_default_constr was used, which marks typ as scala-synthetic.
- a.getConstructor() == loaders.clrTypes.SYMTAB_CONSTR
- } else true // always load non-scala types
- } else true // always load source
- }
-
- def needCompile(bin: MsilFile, src: AbstractFile) =
- false // always use compiled file on .net
-}
diff --git a/src/compiler/scala/tools/nsc/backend/ScalaPrimitives.scala b/src/compiler/scala/tools/nsc/backend/ScalaPrimitives.scala
index 8cbb5bc980..f6b0701f86 100644
--- a/src/compiler/scala/tools/nsc/backend/ScalaPrimitives.scala
+++ b/src/compiler/scala/tools/nsc/backend/ScalaPrimitives.scala
@@ -6,7 +6,6 @@
package scala.tools.nsc
package backend
-import scala.tools.nsc.backend.icode._
import scala.collection.{ mutable, immutable }
/** Scala primitive operations are represented as methods in `Any` and
@@ -565,7 +564,7 @@ abstract class ScalaPrimitives {
import definitions._
val code = getPrimitive(fun)
- def elementType = beforeTyper {
+ def elementType = enteringTyper {
val arrayParent = tpe :: tpe.parents collectFirst {
case TypeRef(_, ArrayClass, elem :: Nil) => elem
}
diff --git a/src/compiler/scala/tools/nsc/backend/WorklistAlgorithm.scala b/src/compiler/scala/tools/nsc/backend/WorklistAlgorithm.scala
index 798a80ea37..45ca39fee4 100644
--- a/src/compiler/scala/tools/nsc/backend/WorklistAlgorithm.scala
+++ b/src/compiler/scala/tools/nsc/backend/WorklistAlgorithm.scala
@@ -6,8 +6,7 @@
package scala.tools.nsc
package backend
-import scala.tools.nsc.ast._
-import scala.collection.{ mutable, immutable }
+import scala.collection.mutable
/**
* Simple implementation of a worklist algorithm. A processing
@@ -32,8 +31,6 @@ trait WorklistAlgorithm {
* Run the iterative algorithm until the worklist remains empty.
* The initializer is run once before the loop starts and should
* initialize the worklist.
- *
- * @param initWorklist ...
*/
def run(initWorklist: => Unit) = {
initWorklist
diff --git a/src/compiler/scala/tools/nsc/backend/icode/BasicBlocks.scala b/src/compiler/scala/tools/nsc/backend/icode/BasicBlocks.scala
index d50d4cd125..24c18e6530 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/BasicBlocks.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/BasicBlocks.scala
@@ -17,7 +17,7 @@ trait BasicBlocks {
self: ICodes =>
import opcodes._
- import global.{ ifDebug, settings, log, nme }
+ import global.{ settings, log, nme }
import nme.isExceptionResultName
/** Override Array creation for efficiency (to not go through reflection). */
@@ -122,7 +122,7 @@ trait BasicBlocks {
def closed: Boolean = hasFlag(CLOSED)
def closed_=(b: Boolean) = if (b) setFlag(CLOSED) else resetFlag(CLOSED)
- /** When set, the <code>emit</code> methods will be ignored. */
+ /** When set, the `emit` methods will be ignored. */
def ignore: Boolean = hasFlag(IGNORING)
def ignore_=(b: Boolean) = if (b) setFlag(IGNORING) else resetFlag(IGNORING)
@@ -260,7 +260,7 @@ trait BasicBlocks {
}
}
- /** Replaces <code>oldInstr</code> with <code>is</code>. It does not update
+ /** Replaces `oldInstr` with `is`. It does not update
* the position field in the newly inserted instructions, so it behaves
* differently than the one-instruction versions of this function.
*
@@ -280,17 +280,7 @@ trait BasicBlocks {
}
}
- /** Insert instructions in 'is' immediately after index 'idx'. */
- def insertAfter(idx: Int, is: List[Instruction]) {
- assert(closed, "Instructions can be replaced only after the basic block is closed")
-
- instrs = instrs.patch(idx + 1, is, 0)
- code.touched = true
- }
-
/** Removes instructions found at the given positions.
- *
- * @param positions ...
*/
def removeInstructionsAt(positions: Int*) {
assert(closed, this)
@@ -311,8 +301,6 @@ trait BasicBlocks {
}
/** Replaces all instructions found in the map.
- *
- * @param map ...
*/
def subst(map: Map[Instruction, Instruction]): Unit =
if (!closed)
@@ -344,10 +332,6 @@ trait BasicBlocks {
* is closed, which sets the DIRTYSUCCS flag.
*/
def emit(instr: Instruction, pos: Position) {
-/* if (closed) {
- print()
- Console.println("trying to emit: " + instr)
- } */
assert(!closed || ignore, this)
if (ignore) {
@@ -441,11 +425,6 @@ trait BasicBlocks {
ignore = true
}
- def exitIgnoreMode() {
- assert(ignore, "Exit ignore mode when not in ignore mode: " + this)
- ignore = false
- }
-
/** Return the last instruction of this basic block. */
def lastInstruction =
if (closed) instrs(instrs.length - 1)
@@ -502,17 +481,6 @@ trait BasicBlocks {
override def hashCode = label * 41 + code.hashCode
- // Instead of it, rather use a printer
- def print() { print(java.lang.System.out) }
-
- def print(out: java.io.PrintStream) {
- out.println("block #"+label+" :")
- foreach(i => out.println(" " + i))
- out.print("Successors: ")
- successors.foreach((x: BasicBlock) => out.print(" "+x.label.toString()))
- out.println()
- }
-
private def succString = if (successors.isEmpty) "[S: N/A]" else successors.distinct.mkString("[S: ", ", ", "]")
private def predString = if (predecessors.isEmpty) "[P: N/A]" else predecessors.distinct.mkString("[P: ", ", ", "]")
diff --git a/src/compiler/scala/tools/nsc/backend/icode/ExceptionHandlers.scala b/src/compiler/scala/tools/nsc/backend/icode/ExceptionHandlers.scala
index 2cebf7ad99..a872e9cd00 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/ExceptionHandlers.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/ExceptionHandlers.scala
@@ -7,7 +7,7 @@ package scala.tools.nsc
package backend
package icode
-import scala.collection.{ mutable, immutable }
+import scala.collection.immutable
/**
* Exception handlers are pieces of code that `handle` exceptions on
@@ -27,9 +27,6 @@ trait ExceptionHandlers {
private var _startBlock: BasicBlock = _;
var finalizer: Finalizer = _;
- /** Needed for the MSIL backend. */
- var resultKind: TypeKind = _;
-
def setStartBlock(b: BasicBlock) = {
_startBlock = b;
b.exceptionHandlerStart = true
@@ -71,10 +68,4 @@ trait ExceptionHandlers {
override def toString() = "finalizer_" + label
override def dup: Finalizer = new Finalizer(method, label, pos)
}
-
- object NoFinalizer extends Finalizer(null, newTermNameCached("<no finalizer>"), NoPosition) {
- override def startBlock: BasicBlock = sys.error("NoFinalizer cannot have a start block.");
- override def setStartBlock(b: BasicBlock): Unit = sys.error("NoFinalizer cannot have a start block.");
- override def dup = this
- }
}
diff --git a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
index fd2b11898c..2ea26ddaa9 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
@@ -13,10 +13,8 @@ import scala.collection.mutable.{ ListBuffer, Buffer }
import scala.tools.nsc.symtab._
import scala.annotation.switch
import PartialFunction._
-import scala.language.postfixOps
-/** This class ...
- *
+/**
* @author Iulian Dragos
* @version 1.0
*/
@@ -160,18 +158,13 @@ abstract class GenICode extends SubComponent {
* and not produce any value. Use genLoad for expressions which leave
* a value on top of the stack.
*
- * @param tree ...
- * @param ctx ...
* @return a new context. This is necessary for control flow instructions
* which may change the current basic block.
*/
private def genStat(tree: Tree, ctx: Context): Context = tree match {
case Assign(lhs @ Select(_, _), rhs) =>
val isStatic = lhs.symbol.isStaticMember
- var ctx1 = if (isStatic) ctx
- else if (forMSIL && msil_IsValuetypeInstField(lhs.symbol))
- msil_genLoadQualifierAddress(lhs, ctx)
- else genLoadQualifier(lhs, ctx)
+ var ctx1 = if (isStatic) ctx else genLoadQualifier(lhs, ctx)
ctx1 = genLoad(rhs, ctx1, toTypeKind(lhs.symbol.info))
ctx1.bb.emit(STORE_FIELD(lhs.symbol, isStatic), tree.pos)
@@ -264,11 +257,6 @@ abstract class GenICode extends SubComponent {
}
/** Generate primitive array operations.
- *
- * @param tree ...
- * @param ctx ...
- * @param code ...
- * @return ...
*/
private def genArrayOp(tree: Tree, ctx: Context, code: Int, expectedType: TypeKind): (Context, TypeKind) = {
import scalaPrimitives._
@@ -310,9 +298,6 @@ abstract class GenICode extends SubComponent {
val Apply(fun, args) = tree
val monitor = ctx.makeLocal(tree.pos, ObjectClass.tpe, "monitor")
var monitorResult: Local = null
-
- // if the synchronized block returns a result, store it in a local variable. just leaving
- // it on the stack is not valid in MSIL (stack is cleaned when leaving try-blocks)
val argTpe = args.head.tpe
val hasResult = expectedType != UNIT
if (hasResult)
@@ -432,7 +417,7 @@ abstract class GenICode extends SubComponent {
private def genPrimitiveOp(tree: Apply, ctx: Context, expectedType: TypeKind): (Context, TypeKind) = {
val sym = tree.symbol
- val Apply(fun @ Select(receiver, _), args) = tree
+ val Apply(fun @ Select(receiver, _), _) = tree
val code = scalaPrimitives.getPrimitive(sym, receiver.tpe)
if (scalaPrimitives.isArithmeticOp(code))
@@ -471,132 +456,6 @@ abstract class GenICode extends SubComponent {
}
/**
- * forMSIL
- */
- private def msil_IsValuetypeInstMethod(msym: Symbol) = (
- loaders.clrTypes.methods get msym exists (mMSIL =>
- mMSIL.IsInstance && mMSIL.DeclaringType.IsValueType
- )
- )
- private def msil_IsValuetypeInstField(fsym: Symbol) = (
- loaders.clrTypes.fields get fsym exists (fMSIL =>
- !fMSIL.IsStatic && fMSIL.DeclaringType.IsValueType
- )
- )
-
- /**
- * forMSIL: Adds a local var, the emitted code requires one more slot on the stack as on entry
- */
- private def msil_genLoadZeroOfNonEnumValuetype(ctx: Context, kind: TypeKind, pos: Position, leaveAddressOnStackInstead: Boolean) {
- val REFERENCE(clssym) = kind
- assert(loaders.clrTypes.isNonEnumValuetype(clssym), clssym)
- val local = ctx.makeLocal(pos, clssym.tpe, "tmp")
- ctx.method.addLocal(local)
- ctx.bb.emit(CIL_LOAD_LOCAL_ADDRESS(local), pos)
- ctx.bb.emit(CIL_INITOBJ(kind), pos)
- val instr = if (leaveAddressOnStackInstead)
- CIL_LOAD_LOCAL_ADDRESS(local)
- else
- LOAD_LOCAL(local)
- ctx.bb.emit(instr, pos)
- }
-
- /**
- * forMSIL
- */
- private def msil_genLoadAddressOf(tree: Tree, ctx: Context, expectedType: TypeKind, butRawValueIsAlsoGoodEnough: Boolean): Context = {
- var generatedType = expectedType
- var addressTaken = false
- debuglog("at line: " + (if (tree.pos.isDefined) tree.pos.line else tree.pos))
-
- var resCtx: Context = tree match {
-
- // emits CIL_LOAD_FIELD_ADDRESS
- case Select(qualifier, selector) if (!tree.symbol.isModule) =>
- addressTaken = true
- val sym = tree.symbol
- generatedType = toTypeKind(sym.info)
-
- if (sym.isStaticMember) {
- ctx.bb.emit(CIL_LOAD_FIELD_ADDRESS(sym, true), tree.pos)
- ctx
- } else {
- val ctx1 = genLoadQualifier(tree, ctx)
- ctx1.bb.emit(CIL_LOAD_FIELD_ADDRESS(sym, false), tree.pos)
- ctx1
- }
-
- // emits CIL_LOAD_LOCAL_ADDRESS
- case Ident(name) if (!tree.symbol.isPackage && !tree.symbol.isModule)=>
- addressTaken = true
- val sym = tree.symbol
- try {
- val Some(l) = ctx.method.lookupLocal(sym)
- ctx.bb.emit(CIL_LOAD_LOCAL_ADDRESS(l), tree.pos)
- generatedType = l.kind // actually, should be "V&" but the callsite is aware of this
- } catch {
- case ex: MatchError =>
- abort("symbol " + sym + " does not exist in " + ctx.method)
- }
- ctx
-
- // emits CIL_LOAD_ARRAY_ITEM_ADDRESS
- case Apply(fun, args) =>
- if (isPrimitive(fun.symbol)) {
-
- val sym = tree.symbol
- val Apply(fun @ Select(receiver, _), args) = tree
- val code = scalaPrimitives.getPrimitive(sym, receiver.tpe)
-
- if (isArrayOp(code)) {
- val arrayObj = receiver
- val k = toTypeKind(arrayObj.tpe)
- val ARRAY(elementType) = k
- if (scalaPrimitives.isArrayGet(code)) {
- var ctx1 = genLoad(arrayObj, ctx, k)
- // load argument on stack
- debugassert(args.length == 1, "Too many arguments for array get operation: " + tree)
- ctx1 = genLoad(args.head, ctx1, INT)
- generatedType = elementType // actually "managed pointer to element type" but the callsite is aware of this
- ctx1.bb.emit(CIL_LOAD_ARRAY_ITEM_ADDRESS(elementType), tree.pos)
- addressTaken = true
- ctx1
- } else null
- } else null
- } else null
-
- case This(qual) =>
- /* TODO: this case handler is a placeholder for the time when Level 2 support for valuetypes is in place,
- in particular when invoking other methods on this where this is a valuetype value (boxed or not).
- As receiver, a managed pointer is expected, and a plain ldarg.0 achieves just that. */
- addressTaken = true
- genLoad(tree, ctx, expectedType)
-
- case _ =>
- null /* A method returning ByRef won't pass peverify, so I guess this case handler is dead code.
- Even if it's not, the code below to handler !addressTaken below. */
- }
-
- if (!addressTaken) {
- resCtx = genLoad(tree, ctx, expectedType)
- if (!butRawValueIsAlsoGoodEnough) {
- // raw value on stack (must be an intermediate result, e.g. returned by method call), take address
- addressTaken = true
- val boxType = expectedType // toTypeKind(expectedType /* TODO FIXME */)
- resCtx.bb.emit(BOX(boxType), tree.pos)
- resCtx.bb.emit(CIL_UNBOX(boxType), tree.pos)
- }
- }
-
- // emit conversion
- if (generatedType != expectedType)
- abort("Unexpected tree in msil_genLoadAddressOf: " + tree + " at: " + tree.pos)
-
- resCtx
- }
-
-
- /**
* Generate code for trees that produce values on the stack
*
* @param tree The tree to be translated
@@ -819,31 +678,15 @@ abstract class GenICode extends SubComponent {
debugassert(ctor.owner == cls,
"Symbol " + ctor.owner.fullName + " is different than " + tpt)
- val ctx2 = if (forMSIL && loaders.clrTypes.isNonEnumValuetype(cls)) {
- /* parameterful constructors are the only possible custom constructors,
- a default constructor can't be defined for valuetypes, CLR dixit */
- val isDefaultConstructor = args.isEmpty
- if (isDefaultConstructor) {
- msil_genLoadZeroOfNonEnumValuetype(ctx, rt, tree.pos, leaveAddressOnStackInstead = false)
- ctx
- } else {
- val ctx1 = genLoadArguments(args, ctor.info.paramTypes, ctx)
- ctx1.bb.emit(CIL_NEWOBJ(ctor), tree.pos)
- ctx1
- }
- } else {
- val nw = NEW(rt)
- ctx.bb.emit(nw, tree.pos)
- ctx.bb.emit(DUP(generatedType))
- val ctx1 = genLoadArguments(args, ctor.info.paramTypes, ctx)
-
- val init = CALL_METHOD(ctor, Static(true))
- nw.init = init
- ctx1.bb.emit(init, tree.pos)
- ctx1
- }
- ctx2
+ val nw = NEW(rt)
+ ctx.bb.emit(nw, tree.pos)
+ ctx.bb.emit(DUP(generatedType))
+ val ctx1 = genLoadArguments(args, ctor.info.paramTypes, ctx)
+ val init = CALL_METHOD(ctor, Static(true))
+ nw.init = init
+ ctx1.bb.emit(init, tree.pos)
+ ctx1
case _ =>
abort("Cannot instantiate " + tpt + " of kind: " + generatedType)
}
@@ -859,7 +702,7 @@ abstract class GenICode extends SubComponent {
// we store this boxed value to a local, even if not really needed.
// boxing optimization might use it, and dead code elimination will
// take care of unnecessary stores
- var loc1 = ctx.makeLocal(tree.pos, expr.tpe, "boxed")
+ val loc1 = ctx.makeLocal(tree.pos, expr.tpe, "boxed")
ctx1.bb.emit(STORE_LOCAL(loc1))
ctx1.bb.emit(LOAD_LOCAL(loc1))
}
@@ -877,12 +720,6 @@ abstract class GenICode extends SubComponent {
ctx1.bb.emit(UNBOX(boxType), expr.pos)
ctx1
- case Apply(fun @ _, List(expr)) if (forMSIL && loaders.clrTypes.isAddressOf(fun.symbol)) =>
- debuglog("ADDRESSOF : " + fun.symbol.fullName);
- val ctx1 = msil_genLoadAddressOf(expr, ctx, toTypeKind(expr.tpe), butRawValueIsAlsoGoodEnough = false)
- generatedType = toTypeKind(fun.symbol.tpe.resultType)
- ctx1
-
case app @ Apply(fun, args) =>
def genLoadApply6 = {
val sym = fun.symbol
@@ -924,19 +761,12 @@ abstract class GenICode extends SubComponent {
else
Dynamic
- var ctx1 =
- if (invokeStyle.hasInstance) {
- if (forMSIL && !(invokeStyle.isInstanceOf[SuperCall]) && msil_IsValuetypeInstMethod(sym))
- msil_genLoadQualifierAddress(fun, ctx)
- else
- genLoadQualifier(fun, ctx)
- } else ctx
-
+ var ctx1 = if (invokeStyle.hasInstance) genLoadQualifier(fun, ctx) else ctx
ctx1 = genLoadArguments(args, sym.info.paramTypes, ctx1)
val cm = CALL_METHOD(sym, invokeStyle)
/** In a couple cases, squirrel away a little extra information in the
- * CALL_METHOD for use by GenJVM.
+ * CALL_METHOD for use by GenASM.
*/
fun match {
case Select(qual, _) =>
@@ -967,7 +797,6 @@ abstract class GenICode extends SubComponent {
genLoadApply6
case ApplyDynamic(qual, args) =>
- assert(!forMSIL, tree)
// TODO - this is where we'd catch dynamic applies for invokedynamic.
sys.error("No invokedynamic support yet.")
// val ctx1 = genLoad(qual, ctx, ObjectReference)
@@ -1105,7 +934,7 @@ abstract class GenICode extends SubComponent {
case Match(selector, cases) =>
def genLoadMatch = {
debuglog("Generating SWITCH statement.");
- var ctx1 = genLoad(selector, ctx, INT) // TODO: Java 7 allows strings in switches (so, don't assume INT and don't convert the literals using intValue)
+ val ctx1 = genLoad(selector, ctx, INT) // TODO: Java 7 allows strings in switches (so, don't assume INT and don't convert the literals using intValue)
val afterCtx = ctx1.newBlock
var caseCtx: Context = null
generatedType = toTypeKind(tree.tpe)
@@ -1164,34 +993,30 @@ abstract class GenICode extends SubComponent {
resCtx
}
- private def adapt(from: TypeKind, to: TypeKind, ctx: Context, pos: Position): Unit = {
- if (!(from <:< to) && !(from == NullReference && to == NothingReference)) {
- to match {
- case UNIT =>
- ctx.bb.emit(DROP(from), pos)
- debuglog("Dropped an " + from);
-
- case _ =>
- debugassert(from != UNIT, "Can't convert from UNIT to " + to + " at: " + pos)
- assert(!from.isReferenceType && !to.isReferenceType,
- "type error: can't convert from " + from + " to " + to +" in unit " + unit.source + " at " + pos)
-
- ctx.bb.emit(CALL_PRIMITIVE(Conversion(from, to)), pos)
- }
- } else if (from == NothingReference) {
- ctx.bb.emit(THROW(ThrowableClass))
- ctx.bb.enterIgnoreMode
- } else if (from == NullReference) {
- ctx.bb.emit(DROP(from))
- ctx.bb.emit(CONSTANT(Constant(null)))
+ private def adapt(from: TypeKind, to: TypeKind, ctx: Context, pos: Position) {
+ // An awful lot of bugs explode here - let's leave ourselves more clues.
+ // A typical example is an overloaded type assigned after typer.
+ log(s"GenICode#adapt($from, $to, $ctx, $pos)")
+
+ val conforms = (from <:< to) || (from == NullReference && to == NothingReference)
+ def coerce(from: TypeKind, to: TypeKind) = ctx.bb.emit(CALL_PRIMITIVE(Conversion(from, to)), pos)
+ def checkAssertions() {
+ def msg = s"Can't convert from $from to $to in unit ${unit.source} at $pos"
+ debugassert(from != UNIT, msg)
+ assert(!from.isReferenceType && !to.isReferenceType, msg)
}
- else if (from == ThrowableReference && !(ThrowableClass.tpe <:< to.toType)) {
- log("Inserted check-cast on throwable to " + to + " at " + pos)
- ctx.bb.emit(CHECK_CAST(to))
+ if (conforms) from match {
+ case NothingReference => ctx.bb.emit(THROW(ThrowableClass)) ; ctx.bb.enterIgnoreMode
+ case NullReference => ctx.bb.emit(Seq(DROP(from), CONSTANT(Constant(null))))
+ case ThrowableReference if !(ThrowableClass.tpe <:< to.toType) => ctx.bb.emit(CHECK_CAST(to)) // downcast throwables
+ case _ =>
+ // widen subrange types
+ if (from.isIntSizedType && to == LONG)
+ coerce(INT, LONG)
}
- else (from, to) match {
- case (BYTE, LONG) | (SHORT, LONG) | (CHAR, LONG) | (INT, LONG) => ctx.bb.emit(CALL_PRIMITIVE(Conversion(INT, LONG)))
- case _ => ()
+ else to match {
+ case UNIT => ctx.bb.emit(DROP(from), pos) // value discarding
+ case _ => checkAssertions() ; coerce(from, to) // other primitive coercions
}
}
@@ -1204,15 +1029,6 @@ abstract class GenICode extends SubComponent {
abort("Unknown qualifier " + tree)
}
- /** forMSIL */
- private def msil_genLoadQualifierAddress(tree: Tree, ctx: Context): Context =
- tree match {
- case Select(qualifier, _) =>
- msil_genLoadAddressOf(qualifier, ctx, toTypeKind(qualifier.tpe), butRawValueIsAlsoGoodEnough = false)
- case _ =>
- abort("Unknown qualifier " + tree)
- }
-
/**
* Generate code that loads args into label parameters.
*/
@@ -1259,7 +1075,9 @@ abstract class GenICode extends SubComponent {
if (!tree.symbol.isPackageClass) tree.symbol
else tree.symbol.info.member(nme.PACKAGE) match {
case NoSymbol => abort("Cannot use package as value: " + tree)
- case s => debugwarn("Bug: found package class where package object expected. Converting.") ; s.moduleClass
+ case s =>
+ devWarning(s"Found ${tree.symbol} where a package object is required. Converting to ${s.moduleClass}")
+ s.moduleClass
}
)
debuglog("LOAD_MODULE from %s: %s".format(tree.shortClass, sym))
@@ -1393,15 +1211,11 @@ abstract class GenICode extends SubComponent {
// }
/** Generate string concatenation.
- *
- * @param tree ...
- * @param ctx ...
- * @return ...
*/
def genStringConcat(tree: Tree, ctx: Context): Context = {
liftStringConcat(tree) match {
// Optimization for expressions of the form "" + x. We can avoid the StringBuilder.
- case List(Literal(Constant("")), arg) if !forMSIL =>
+ case List(Literal(Constant("")), arg) =>
debuglog("Rewriting \"\" + x as String.valueOf(x) for: " + arg)
val ctx1 = genLoad(arg, ctx, ObjectReference)
ctx1.bb.emit(CALL_METHOD(String_valueOf, Static(false)), arg.pos)
@@ -1581,7 +1395,7 @@ abstract class GenICode extends SubComponent {
*/
def genEqEqPrimitive(l: Tree, r: Tree, ctx: Context)(thenCtx: Context, elseCtx: Context): Unit = {
def getTempLocal = ctx.method.lookupLocal(nme.EQEQ_LOCAL_VAR) getOrElse {
- ctx.makeLocal(l.pos, AnyRefClass.tpe, nme.EQEQ_LOCAL_VAR)
+ ctx.makeLocal(l.pos, AnyRefClass.tpe, nme.EQEQ_LOCAL_VAR.toString)
}
/** True if the equality comparison is between values that require the use of the rich equality
@@ -1710,8 +1524,6 @@ abstract class GenICode extends SubComponent {
* If the block consists of a single unconditional jump, prune
* it by replacing the instructions in the predecessor to jump
* directly to the JUMP target of the block.
- *
- * @param method ...
*/
def prune(method: IMethod) = {
var changed = false
@@ -1831,9 +1643,7 @@ abstract class GenICode extends SubComponent {
t match {
case t @ Apply(_, args) if sym.isLabel && !boundLabels(sym) =>
val newSym = getLabel(sym.pos, sym.name)
- val tree = Apply(global.gen.mkAttributedRef(newSym), transformTrees(args)) setPos t.pos
- tree.tpe = t.tpe
- tree
+ Apply(global.gen.mkAttributedRef(newSym), transformTrees(args)) setPos t.pos setType t.tpe
case t @ LabelDef(name, params, rhs) =>
val newSym = getLabel(t.pos, name)
@@ -1907,18 +1717,8 @@ abstract class GenICode extends SubComponent {
var handlerCount = 0
- override def toString(): String = {
- val buf = new StringBuilder()
- buf.append("\tpackage: ").append(packg).append('\n')
- buf.append("\tclazz: ").append(clazz).append('\n')
- buf.append("\tmethod: ").append(method).append('\n')
- buf.append("\tbb: ").append(bb).append('\n')
- buf.append("\tlabels: ").append(labels).append('\n')
- buf.append("\texception handlers: ").append(handlers).append('\n')
- buf.append("\tcleanups: ").append(cleanups).append('\n')
- buf.append("\tscope: ").append(scope).append('\n')
- buf.toString()
- }
+ override def toString =
+ s"package $packg { class $clazz { def $method { bb=$bb } } }"
def loadException(ctx: Context, exh: ExceptionHandler, pos: Position) = {
debuglog("Emitting LOAD_EXCEPTION for class: " + exh.loadExceptionClass)
@@ -1977,18 +1777,7 @@ abstract class GenICode extends SubComponent {
this
}
- def removeFinalizer(f: Tree): this.type = {
- assert(cleanups.head contains f,
- "Illegal nesting of cleanup operations: " + cleanups + " while exiting finalizer " + f);
- cleanups = cleanups.tail
- this
- }
-
/** Prepare a new context upon entry into a method.
- *
- * @param m ...
- * @param d ...
- * @return ...
*/
def enterMethod(m: IMethod, d: DefDef): Context = {
val ctx1 = new Context(this) setMethod(m)
@@ -2027,10 +1816,9 @@ abstract class GenICode extends SubComponent {
* 'covered' by this exception handler (in addition to the
* previously active handlers).
*/
- private def newExceptionHandler(cls: Symbol, resultKind: TypeKind, pos: Position): ExceptionHandler = {
+ private def newExceptionHandler(cls: Symbol, pos: Position): ExceptionHandler = {
handlerCount += 1
val exh = new ExceptionHandler(method, newTermNameCached("" + handlerCount), cls, pos)
- exh.resultKind = resultKind
method.addHandler(exh)
handlers = exh :: handlers
debuglog("added handler: " + exh);
@@ -2060,16 +1848,6 @@ abstract class GenICode extends SubComponent {
currentExceptionHandlers = currentExceptionHandlers.tail
}
- /** Remove the given handler from the list of active exception handlers. */
- def removeActiveHandler(exh: ExceptionHandler): Unit = {
- assert(handlerCount > 0 && handlers.head == exh,
- "Wrong nesting of exception handlers." + this + " for " + exh)
- handlerCount -= 1
- handlers = handlers.tail
- debuglog("removed handler: " + exh);
-
- }
-
/** Clone the current context */
def dup: Context = new Context(this)
@@ -2088,19 +1866,19 @@ abstract class GenICode extends SubComponent {
* It returns the resulting context, with the same active handlers as
* before the call. Use it like:
*
- * <code> ctx.Try( ctx => {
+ * ` ctx.Try( ctx => {
* ctx.bb.emit(...) // protected block
* }, (ThrowableClass,
* ctx => {
* ctx.bb.emit(...); // exception handler
* }), (AnotherExceptionClass,
* ctx => {...
- * } ))</code>
+ * } ))`
*/
def Try(body: Context => Context,
handlers: List[(Symbol, TypeKind, Context => Context)],
finalizer: Tree,
- tree: Tree) = if (forMSIL) TryMsil(body, handlers, finalizer, tree) else {
+ tree: Tree) = {
val outerCtx = this.dup // context for generating exception handlers, covered by finalizer
val finalizerCtx = this.dup // context for generating finalizer handler
@@ -2131,8 +1909,8 @@ abstract class GenICode extends SubComponent {
} else ctx
- val finalizerExh = if (finalizer != EmptyTree) Some({
- val exh = outerCtx.newExceptionHandler(NoSymbol, toTypeKind(finalizer.tpe), finalizer.pos) // finalizer covers exception handlers
+ if (finalizer != EmptyTree) {
+ val exh = outerCtx.newExceptionHandler(NoSymbol, finalizer.pos) // finalizer covers exception handlers
this.addActiveHandler(exh) // .. and body aswell
val ctx = finalizerCtx.enterExceptionHandler(exh)
val exception = ctx.makeLocal(finalizer.pos, ThrowableClass.tpe, "exc")
@@ -2144,91 +1922,29 @@ abstract class GenICode extends SubComponent {
ctx1.bb.enterIgnoreMode;
ctx1.bb.close
finalizerCtx.endHandler()
- exh
- }) else None
-
- val exhs = handlers.map { case (sym, kind, handler) => // def genWildcardHandler(sym: Symbol): (Symbol, TypeKind, Context => Context) =
- val exh = this.newExceptionHandler(sym, kind, tree.pos)
- var ctx1 = outerCtx.enterExceptionHandler(exh)
- ctx1.addFinalizer(finalizer, finalizerCtx)
- loadException(ctx1, exh, tree.pos)
- ctx1 = handler(ctx1)
- // emit finalizer
- val ctx2 = emitFinalizer(ctx1)
- ctx2.bb.closeWith(JUMP(afterCtx.bb))
- outerCtx.endHandler()
- exh
- }
- val bodyCtx = this.newBlock
- if (finalizer != EmptyTree)
- bodyCtx.addFinalizer(finalizer, finalizerCtx)
-
- var finalCtx = body(bodyCtx)
- finalCtx = emitFinalizer(finalCtx)
-
- outerCtx.bb.closeWith(JUMP(bodyCtx.bb))
-
- finalCtx.bb.closeWith(JUMP(afterCtx.bb))
-
- afterCtx
- }
-
-
- /** try-catch-finally blocks are actually simpler to emit in MSIL, because there
- * is support for `finally` in bytecode.
- *
- * A
- * try { .. } catch { .. } finally { .. }
- * block is de-sugared into
- * try { try { ..} catch { .. } } finally { .. }
- *
- * In ICode `finally` block is represented exactly the same as an exception handler,
- * but with `NoSymbol` as the exception class. The covered blocks are all blocks of
- * the `try { .. } catch { .. }`.
- *
- * Also, TryMsil does not enter any Finalizers into the `cleanups`, because the
- * CLI takes care of running the finalizer when seeing a `leave` statement inside
- * a try / catch.
- */
- def TryMsil(body: Context => Context,
- handlers: List[(Symbol, TypeKind, (Context => Context))],
- finalizer: Tree,
- tree: Tree) = {
-
- val outerCtx = this.dup // context for generating exception handlers, covered by finalizer
- val finalizerCtx = this.dup // context for generating finalizer handler
- val afterCtx = outerCtx.newBlock
-
- if (finalizer != EmptyTree) {
- // finalizer is covers try and all catch blocks, i.e.
- // try { try { .. } catch { ..} } finally { .. }
- val exh = outerCtx.newExceptionHandler(NoSymbol, UNIT, tree.pos)
- this.addActiveHandler(exh)
- val ctx = finalizerCtx.enterExceptionHandler(exh)
- loadException(ctx, exh, tree.pos)
- val ctx1 = genLoad(finalizer, ctx, UNIT)
- // need jump for the ICode to be valid. MSIL backend will emit `Endfinally` instead.
- ctx1.bb.closeWith(JUMP(afterCtx.bb))
- finalizerCtx.endHandler()
}
- for (handler <- handlers) {
- val exh = this.newExceptionHandler(handler._1, handler._2, tree.pos)
+ for ((sym, kind, handler) <- handlers) {
+ val exh = this.newExceptionHandler(sym, tree.pos)
var ctx1 = outerCtx.enterExceptionHandler(exh)
+ ctx1.addFinalizer(finalizer, finalizerCtx)
loadException(ctx1, exh, tree.pos)
- ctx1 = handler._3(ctx1)
- // msil backend will emit `Leave` to jump out of a handler
- ctx1.bb.closeWith(JUMP(afterCtx.bb))
+ ctx1 = handler(ctx1)
+ // emit finalizer
+ val ctx2 = emitFinalizer(ctx1)
+ ctx2.bb.closeWith(JUMP(afterCtx.bb))
outerCtx.endHandler()
}
val bodyCtx = this.newBlock
+ if (finalizer != EmptyTree)
+ bodyCtx.addFinalizer(finalizer, finalizerCtx)
- val finalCtx = body(bodyCtx)
+ var finalCtx = body(bodyCtx)
+ finalCtx = emitFinalizer(finalCtx)
outerCtx.bb.closeWith(JUMP(bodyCtx.bb))
- // msil backend will emit `Leave` to jump out of a try-block
finalCtx.bb.closeWith(JUMP(afterCtx.bb))
afterCtx
@@ -2357,7 +2073,6 @@ abstract class GenICode extends SubComponent {
val locals: ListBuffer[Local] = new ListBuffer
def add(l: Local) = locals += l
- def remove(l: Local) = locals -= l
/** Return all locals that are in scope. */
def varsInScope: Buffer[Local] = outer.varsInScope.clone() ++= locals
diff --git a/src/compiler/scala/tools/nsc/backend/icode/ICodeCheckers.scala b/src/compiler/scala/tools/nsc/backend/icode/ICodeCheckers.scala
index f05def3123..95913c7768 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/ICodeCheckers.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/ICodeCheckers.scala
@@ -9,7 +9,6 @@ package icode
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
-import scala.tools.nsc.symtab._
abstract class ICodeCheckers {
val global: Global
@@ -49,7 +48,7 @@ abstract class ICodeCheckers {
* @author Iulian Dragos
* @version 1.0, 06/09/2005
*
- * @todo Better checks for <code>MONITOR_ENTER/EXIT</code>
+ * @todo Better checks for `MONITOR_ENTER/EXIT`
* Better checks for local var initializations
*
* @todo Iulian says: I think there's some outdated logic in the checker.
@@ -103,7 +102,6 @@ abstract class ICodeCheckers {
private def posStr(p: Position) =
if (p.isDefined) p.line.toString else "<??>"
- private def indent(s: String, spaces: Int): String = indent(s, " " * spaces)
private def indent(s: String, prefix: String): String = {
val lines = s split "\\n"
lines map (prefix + _) mkString "\n"
@@ -170,7 +168,6 @@ abstract class ICodeCheckers {
val preds = bl.predecessors
def hasNothingType(s: TypeStack) = s.nonEmpty && (s.head == NothingReference)
- def hasNullType(s: TypeStack) = s.nonEmpty && (s.head == NullReference)
/** XXX workaround #1: one stack empty, the other has BoxedUnit.
* One example where this arises is:
@@ -296,7 +293,7 @@ abstract class ICodeCheckers {
else prefix + " with initial stack " + initial.types.mkString("[", ", ", "]")
})
- var stack = new TypeStack(initial)
+ val stack = new TypeStack(initial)
def checkStack(len: Int) {
if (stack.length < len)
ICodeChecker.this.icodeError("Expected at least " + len + " elements on the stack", stack)
@@ -369,11 +366,6 @@ abstract class ICodeCheckers {
}
}
- /** Return true if k1 is a subtype of any of the following types,
- * according to the somewhat relaxed subtyping standards in effect here.
- */
- def isOneOf(k1: TypeKind, kinds: TypeKind*) = kinds exists (k => isSubtype(k1, k))
-
def subtypeTest(k1: TypeKind, k2: TypeKind): Unit =
if (isSubtype(k1, k2)) ()
else typeError(k2, k1)
@@ -381,10 +373,9 @@ abstract class ICodeCheckers {
for (instr <- b) {
this.instruction = instr
- def checkLocal(local: Local): Unit = {
- method lookupLocal local.sym.name getOrElse {
- icodeError(" " + local + " is not defined in method " + method)
- }
+ def checkLocal(local: Local) {
+ if ((method lookupLocal local.sym.name).isEmpty)
+ icodeError(s" $local is not defined in method $method")
}
def checkField(obj: TypeKind, field: Symbol): Unit = obj match {
case REFERENCE(sym) =>
@@ -422,10 +413,7 @@ abstract class ICodeCheckers {
}
/** Checks that the object passed as receiver has a method
- * <code>method</code> and that it is callable from the current method.
- *
- * @param receiver ...
- * @param method ...
+ * `method` and that it is callable from the current method.
*/
def checkMethod(receiver: TypeKind, method: Symbol) =
receiver match {
@@ -495,7 +483,7 @@ abstract class ICodeCheckers {
case LOAD_MODULE(module) =>
checkBool((module.isModule || module.isModuleClass),
- "Expected module: " + module + " flags: " + Flags.flagsToString(module.flags));
+ "Expected module: " + module + " flags: " + module.flagString);
pushStack(toTypeKind(module.tpe));
case STORE_THIS(kind) =>
diff --git a/src/compiler/scala/tools/nsc/backend/icode/ICodes.scala b/src/compiler/scala/tools/nsc/backend/icode/ICodes.scala
index 93201089e4..e2d387c65d 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/ICodes.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/ICodes.scala
@@ -8,8 +8,6 @@ package backend
package icode
import java.io.PrintWriter
-import scala.collection.mutable
-import scala.tools.nsc.symtab._
import analysis.{ Liveness, ReachingDefinitions }
import scala.tools.nsc.symtab.classfile.ICodeReader
@@ -30,14 +28,14 @@ abstract class ICodes extends AnyRef
with Repository
{
val global: Global
- import global.{ log, definitions, settings, perRunCaches }
+ import global.{ log, definitions, settings, perRunCaches, devWarning }
/** The ICode representation of classes */
val classes = perRunCaches.newMap[global.Symbol, IClass]()
/** Debugging flag */
def shouldCheckIcode = settings.check contains global.genicode.phaseName
- def checkerDebug(msg: String) = if (shouldCheckIcode && global.opt.debug) println(msg)
+ def checkerDebug(msg: String) = if (shouldCheckIcode && global.settings.debug.value) println(msg)
/** The ICode linearizer. */
val linearizer: Linearizer = settings.Xlinearizer.value match {
@@ -84,7 +82,7 @@ abstract class ICodes extends AnyRef
// Something is leaving open/empty blocks around (see SI-4840) so
// let's not kill the deal unless it's nonempty.
if (b.isEmpty) {
- log("!!! Found open but empty block while inlining " + m + ": removing from block list.")
+ devWarning(s"Found open but empty block while inlining $m: removing from block list.")
m.code removeBlock b
}
else dumpMethodAndAbort(m, b)
diff --git a/src/compiler/scala/tools/nsc/backend/icode/Linearizers.scala b/src/compiler/scala/tools/nsc/backend/icode/Linearizers.scala
index a38eab4515..80477f0c6e 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/Linearizers.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/Linearizers.scala
@@ -8,7 +8,6 @@ package scala.tools.nsc
package backend
package icode
-import scala.tools.nsc.ast._
import scala.collection.{ mutable, immutable }
import mutable.ListBuffer
@@ -198,142 +197,4 @@ trait Linearizers {
def linearize(m: IMethod): List[BasicBlock] = m.blocks
def linearizeAt(m: IMethod, start: BasicBlock): List[BasicBlock] = sys.error("not implemented")
}
-
- /** The MSIL linearizer is used only for methods with at least one exception handler.
- * It makes sure that all the blocks belonging to a `try`, `catch` or `finally` block
- * are emitted in an order that allows the lexical nesting of try-catch-finally, just
- * like in the source code.
- */
- class MSILLinearizer extends Linearizer {
- /** The MSIL linearizer first calls a NormalLInearizer. This is because the ILGenerator checks
- * the stack size before emitting instructions. For instance, to emit a `store`, there needs
- * to be some value on the stack. This can blow up in situations like this:
- * ...
- * jump 3
- * 4: store_local 0
- * jump 5
- * 3: load_value
- * jump 4
- * 5: ...
- * here, 3 must be scheduled first.
- *
- * The NormalLinearizer also removes dead blocks (blocks without predecessor). This is important
- * in the following example:
- * try { throw new Exception }
- * catch { case e => throw e }
- * which adds a dead block containing just a "throw" (which, again, would blow up code generation
- * because of the stack size; there's no value on the stack when emitting that `throw`)
- */
- val normalLinearizer = new NormalLinearizer()
-
- def linearize(m: IMethod): List[BasicBlock] = {
-
- val handlersByCovered = m.exh.groupBy(_.covered)
-
- // number of basic blocks covered by the entire try-catch expression
- def size(covered: scala.collection.immutable.Set[BasicBlock]) = {
- val hs = handlersByCovered(covered)
- covered.size + (hs :\ 0)((h, s) => h.blocks.length + s)
- }
-
- val tryBlocks = handlersByCovered.keys.toList sortBy size
- var result = normalLinearizer.linearize(m)
- val frozen = mutable.HashSet[BasicBlock](result.head)
-
- for (tryBlock <- tryBlocks) {
- result = groupBlocks(m, result, handlersByCovered(tryBlock), frozen)
- }
- result
- }
-
- /** @param handlers a list of handlers covering the same blocks (same try, multiple catches)
- * @param frozen blocks can't be moved (fist block of a method, blocks directly following a try-catch)
- */
- def groupBlocks(method: IMethod, blocks: List[BasicBlock], handlers: List[ExceptionHandler], frozen: mutable.HashSet[BasicBlock]) = {
- assert(blocks.head == method.startBlock, method)
-
- // blocks before the try, and blocks for the try
- val beforeAndTry = new ListBuffer[BasicBlock]()
- // blocks for the handlers
- val catches = handlers map (_ => new ListBuffer[BasicBlock]())
- // blocks to be put at the end
- val after = new ListBuffer[BasicBlock]()
-
- var beforeTry = true
- val head = handlers.head
-
- for (b <- blocks) {
- if (head covers b) {
- beforeTry = false
- beforeAndTry += b
- } else {
- val handlerIndex = handlers.indexWhere(_.blocks.contains(b))
- if (handlerIndex >= 0) {
- catches(handlerIndex) += b
- } else if (beforeTry) {
- beforeAndTry += b
- } else {
- after += b
- }
- }
- }
-
- // reorder the blocks in "catches" so that the "firstBlock" is actually first
- (catches, handlers).zipped foreach { (lb, handler) =>
- lb -= handler.startBlock
- handler.startBlock +=: lb
- }
-
- // The first block emitted after a try-catch must be the one that the try / catch
- // blocks jump to (because in msil, these jumps cannot be emitted manually)
- var firstAfter: Option[BasicBlock] = None
-
- // Find the (hopefully) unique successor, look at the try and all catch blocks
- var blks = head.covered.toList :: handlers.map(_.blocks)
- while (firstAfter.isEmpty && !blks.isEmpty) {
- val b = blks.head
- blks = blks.tail
-
- val leaving = leavingBlocks(b)
- // no leaving blocks when the try or catch ends with THROW or RET
- if (!leaving.isEmpty) {
- assert(leaving.size <= 1, leaving)
- firstAfter = Some(leaving.head)
- }
- }
- if (firstAfter.isDefined) {
- val b = firstAfter.get
- if (frozen(b)) {
- assert(after contains b, b +", "+ method)
- } else {
- frozen += b
- if (beforeAndTry contains b) {
- beforeAndTry -= b
- } else {
- assert(after contains b, after)
- after -= b
- }
- b +=: after
- }
- }
-
- for (lb <- catches) { beforeAndTry ++= lb }
- beforeAndTry ++= after
- beforeAndTry.toList
- }
-
- /** Returns all direct successors of `blocks` wich are not part
- * that list, i.e. successors outside the `blocks` list.
- */
- private def leavingBlocks(blocks: List[BasicBlock]) = {
- val res = new mutable.HashSet[BasicBlock]()
- for (b <- blocks; s <- b.directSuccessors; if (!blocks.contains(s)))
- res += s
- res
- }
-
- def linearizeAt(m: IMethod, start: BasicBlock): List[BasicBlock] = {
- sys.error("not implemented")
- }
- }
}
diff --git a/src/compiler/scala/tools/nsc/backend/icode/Members.scala b/src/compiler/scala/tools/nsc/backend/icode/Members.scala
index 7ba212f42e..12daa32186 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/Members.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/Members.scala
@@ -7,10 +7,8 @@ package scala.tools.nsc
package backend
package icode
-import java.io.PrintWriter
import scala.collection.{ mutable, immutable }
import scala.reflect.internal.util.{ SourceFile, NoSourceFile }
-import symtab.Flags.{ DEFERRED }
trait ReferenceEquality {
override def hashCode = System.identityHashCode(this)
@@ -128,9 +126,7 @@ trait Members {
override def toString() = symbol.fullName
- def lookupField(s: Symbol) = fields find (_.symbol == s)
def lookupMethod(s: Symbol) = methods find (_.symbol == s)
- def lookupMethod(s: Name) = methods find (_.symbol.name == s)
/* returns this methods static ctor if it has one. */
def lookupStaticCtor: Option[IMethod] = methods find (_.symbol.isStaticConstructor)
@@ -161,7 +157,6 @@ trait Members {
def linearizedBlocks(lin: Linearizer = self.linearizer): List[BasicBlock] = lin linearize this
def foreachBlock[U](f: BasicBlock => U): Unit = blocks foreach f
- def foreachInstr[U](f: Instruction => U): Unit = foreachBlock(_.toList foreach f)
var native = false
@@ -194,7 +189,6 @@ trait Members {
}
def addLocals(ls: List[Local]) = ls foreach addLocal
- def addParams(as: List[Local]) = as foreach addParam
def lookupLocal(n: Name): Option[Local] = locals find (_.sym.name == n)
def lookupLocal(sym: Symbol): Option[Local] = locals find (_.sym == sym)
@@ -209,28 +203,7 @@ trait Members {
override def toString() = symbol.fullName
- def matchesSignature(other: IMethod) = {
- (symbol.name == other.symbol.name) &&
- (params corresponds other.params)(_.kind == _.kind) &&
- (returnType == other.returnType)
- }
-
import opcodes._
- def checkLocals(): Unit = {
- def localsSet = (code.blocks flatMap { bb =>
- bb.iterator collect {
- case LOAD_LOCAL(l) => l
- case STORE_LOCAL(l) => l
- }
- }).toSet
-
- if (hasCode) {
- log("[checking locals of " + this + "]")
- locals filterNot localsSet foreach { l =>
- log("Local " + l + " is not declared in " + this)
- }
- }
- }
/** Merge together blocks that have a single successor which has a
* single predecessor. Exception handlers are taken into account (they
@@ -296,9 +269,6 @@ trait Members {
/** Starting PC for this local's visibility range. */
var start: Int = _
- /** Ending PC for this local's visibility range. */
- var end: Int = _
-
/** PC-based ranges for this local variable's visibility */
var ranges: List[(Int, Int)] = Nil
diff --git a/src/compiler/scala/tools/nsc/backend/icode/Opcodes.scala b/src/compiler/scala/tools/nsc/backend/icode/Opcodes.scala
index 8c9a72638d..137e2b556f 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/Opcodes.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/Opcodes.scala
@@ -3,13 +3,10 @@
* @author Martin Odersky
*/
-
-
package scala.tools.nsc
package backend
package icode
-import scala.tools.nsc.ast._
import scala.reflect.internal.util.{Position,NoPosition}
/*
@@ -67,7 +64,7 @@ import scala.reflect.internal.util.{Position,NoPosition}
* in the source files.
*/
trait Opcodes { self: ICodes =>
- import global.{Symbol, NoSymbol, Type, Name, Constant};
+ import global.{Symbol, NoSymbol, Name, Constant};
// categories of ICode instructions
final val localsCat = 1
@@ -111,17 +108,11 @@ trait Opcodes { self: ICodes =>
// Vlad: I wonder why we keep producedTypes around -- it looks like an useless thing to have
def producedTypes: List[TypeKind] = Nil
- /** This method returns the difference of size of the stack when the instruction is used */
- def difference = produced-consumed
-
/** The corresponding position in the source file */
private var _pos: Position = NoPosition
def pos: Position = _pos
- /** Used by dead code elimination. */
- var useful: Boolean = false
-
def setPos(p: Position): this.type = {
_pos = p
this
@@ -133,13 +124,6 @@ trait Opcodes { self: ICodes =>
}
object opcodes {
-
- def mayThrow(i: Instruction): Boolean = i match {
- case LOAD_LOCAL(_) | STORE_LOCAL(_) | CONSTANT(_) | THIS(_) | CZJUMP(_, _, _, _)
- | DROP(_) | DUP(_) | RETURN(_) | LOAD_EXCEPTION(_) | JUMP(_) | CJUMP(_, _, _, _) => false
- case _ => true
- }
-
/** Loads "this" on top of the stack.
* Stack: ...
* ->: ...:ref
@@ -715,8 +699,6 @@ trait Opcodes { self: ICodes =>
/** Is this a static method call? */
def isStatic: Boolean = false
- def isSuper: Boolean = false
-
/** Is this an instance method call? */
def hasInstance: Boolean = true
@@ -750,77 +732,7 @@ trait Opcodes { self: ICodes =>
* On JVM, translated to `invokespecial`.
*/
case class SuperCall(mix: Name) extends InvokeStyle {
- override def isSuper = true
override def toString(): String = { "super(" + mix + ")" }
}
-
-
- // CLR backend
-
- case class CIL_LOAD_LOCAL_ADDRESS(local: Local) extends Instruction {
- /** Returns a string representation of this instruction */
- override def toString(): String = "CIL_LOAD_LOCAL_ADDRESS "+local //+isArgument?" (argument)":"";
-
- override def consumed = 0
- override def produced = 1
-
- override def producedTypes = msil_mgdptr(local.kind) :: Nil
-
- override def category = localsCat
- }
-
- case class CIL_LOAD_FIELD_ADDRESS(field: Symbol, isStatic: Boolean) extends Instruction {
- /** Returns a string representation of this instruction */
- override def toString(): String =
- "CIL_LOAD_FIELD_ADDRESS " + (if (isStatic) field.fullName else field.toString)
-
- override def consumed = if (isStatic) 0 else 1
- override def produced = 1
-
- override def consumedTypes = if (isStatic) Nil else REFERENCE(field.owner) :: Nil;
- override def producedTypes = msil_mgdptr(REFERENCE(field.owner)) :: Nil;
-
- override def category = fldsCat
- }
-
- case class CIL_LOAD_ARRAY_ITEM_ADDRESS(kind: TypeKind) extends Instruction {
- /** Returns a string representation of this instruction */
- override def toString(): String = "CIL_LOAD_ARRAY_ITEM_ADDRESS (" + kind + ")"
-
- override def consumed = 2
- override def produced = 1
-
- override def consumedTypes = ARRAY(kind) :: INT :: Nil
- override def producedTypes = msil_mgdptr(kind) :: Nil
-
- override def category = arraysCat
- }
-
- case class CIL_UNBOX(valueType: TypeKind) extends Instruction {
- override def toString(): String = "CIL_UNBOX " + valueType
- override def consumed = 1
- override def consumedTypes = ObjectReferenceList // actually consumes a 'boxed valueType'
- override def produced = 1
- override def producedTypes = msil_mgdptr(valueType) :: Nil
- override def category = objsCat
- }
-
- case class CIL_INITOBJ(valueType: TypeKind) extends Instruction {
- override def toString(): String = "CIL_INITOBJ " + valueType
- override def consumed = 1
- override def consumedTypes = ObjectReferenceList // actually consumes a managed pointer
- override def produced = 0
- override def category = objsCat
- }
-
- case class CIL_NEWOBJ(method: Symbol) extends Instruction {
- override def toString(): String = "CIL_NEWOBJ " + hostClass.fullName + method.fullName
- var hostClass: Symbol = method.owner;
- override def consumed = method.tpe.paramTypes.length
- override def consumedTypes = method.tpe.paramTypes map toTypeKind
- override def produced = 1
- override def producedTypes = toTypeKind(method.tpe.resultType) :: Nil
- override def category = objsCat
- }
}
}
diff --git a/src/compiler/scala/tools/nsc/backend/icode/Primitives.scala b/src/compiler/scala/tools/nsc/backend/icode/Primitives.scala
index c8579041ba..351d99f51a 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/Primitives.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/Primitives.scala
@@ -76,25 +76,12 @@ trait Primitives { self: ICodes =>
/** Pretty printer for primitives */
class PrimitivePrinter(out: PrintWriter) {
-
def print(s: String): PrimitivePrinter = {
out.print(s)
this
}
def print(o: AnyRef): PrimitivePrinter = print(o.toString())
-
- def printPrimitive(prim: Primitive) = prim match {
- case Negation(kind) =>
- print("!")
-
- case Test(op, kind, zero) =>
- print(op).print(kind)
-
- case Comparison(op, kind) =>
- print(op).print("(").print(kind)
-
- }
}
/** This class represents a comparison operation. */
diff --git a/src/compiler/scala/tools/nsc/backend/icode/Printers.scala b/src/compiler/scala/tools/nsc/backend/icode/Printers.scala
index 6cac641e3e..61af6e5119 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/Printers.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/Printers.scala
@@ -8,13 +8,9 @@ package backend
package icode
import java.io.PrintWriter
-import scala.tools.nsc.symtab.Flags
-import scala.reflect.internal.util.Position
trait Printers { self: ICodes =>
import global._
- import global.icodes.opcodes._
- import global.icodes._
class TextPrinter(writer: PrintWriter, lin: Linearizer) {
private var margin = 0
diff --git a/src/compiler/scala/tools/nsc/backend/icode/Repository.scala b/src/compiler/scala/tools/nsc/backend/icode/Repository.scala
index e73015c4da..e92e61c957 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/Repository.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/Repository.scala
@@ -26,17 +26,6 @@ trait Repository {
/** The icode of the given class, if available */
def icode(sym: Symbol): Option[IClass] = (classes get sym) orElse (loaded get sym)
- /** The icode of the given class. If not available, it loads
- * its bytecode.
- */
- def icode(sym: Symbol, force: Boolean): IClass =
- icode(sym) getOrElse {
- log("loading " + sym)
- load(sym)
- assert(available(sym))
- loaded(sym)
- }
-
/** Load bytecode for given symbol. */
def load(sym: Symbol): Boolean = {
try {
diff --git a/src/compiler/scala/tools/nsc/backend/icode/TypeKinds.scala b/src/compiler/scala/tools/nsc/backend/icode/TypeKinds.scala
index 4f8fda8024..84f5fe2678 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/TypeKinds.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/TypeKinds.scala
@@ -55,7 +55,7 @@ trait TypeKinds { self: ICodes =>
def toType: Type = reversePrimitiveMap get this map (_.tpe) getOrElse {
this match {
- case REFERENCE(cls) => cls.tpe
+ case REFERENCE(cls) => cls.tpe_*
case ARRAY(elem) => arrayType(elem.toType)
case _ => abort("Unknown type kind.")
}
@@ -66,7 +66,6 @@ trait TypeKinds { self: ICodes =>
def isValueType = false
def isBoxedType = false
final def isRefOrArrayType = isReferenceType || isArrayType
- final def isRefArrayOrBoxType = isRefOrArrayType || isBoxedType
final def isNothingType = this == NothingReference
final def isNullType = this == NullReference
final def isInterfaceType = this match {
@@ -114,8 +113,6 @@ trait TypeKinds { self: ICodes =>
}
}
- var lubs0 = 0
-
/**
* The least upper bound of two typekinds. They have to be either
* REFERENCE or ARRAY kinds.
@@ -139,8 +136,7 @@ trait TypeKinds { self: ICodes =>
* Here we make the adjustment by rewinding to a pre-erasure state and
* sifting through the parents for a class type.
*/
- def lub0(tk1: TypeKind, tk2: TypeKind): Type = beforeUncurry {
- import definitions._
+ def lub0(tk1: TypeKind, tk2: TypeKind): Type = enteringUncurry {
val tp = global.lub(List(tk1.toType, tk2.toType))
val (front, rest) = tp.parents span (_.typeSymbol.isTrait)
@@ -431,11 +427,4 @@ trait TypeKinds { self: ICodes =>
primitiveTypeMap.getOrElse(sym, newReference(sym))
private def primitiveOrClassType(sym: Symbol, targs: List[Type]) =
primitiveTypeMap.getOrElse(sym, arrayOrClassType(sym, targs))
-
- def msil_mgdptr(tk: TypeKind): TypeKind = (tk: @unchecked) match {
- case REFERENCE(cls) => REFERENCE(loaders.clrTypes.mdgptrcls4clssym(cls))
- // TODO have ready class-symbols for the by-ref versions of built-in valuetypes
- case _ => abort("cannot obtain a managed pointer for " + tk)
- }
-
}
diff --git a/src/compiler/scala/tools/nsc/backend/icode/TypeStacks.scala b/src/compiler/scala/tools/nsc/backend/icode/TypeStacks.scala
index 23d3d05c64..57d51dad49 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/TypeStacks.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/TypeStacks.scala
@@ -15,15 +15,11 @@ package icode
trait TypeStacks {
self: ICodes =>
- import opcodes._
-
/* This class simulates the type of the operand
* stack of the ICode.
*/
type Rep = List[TypeKind]
- object NoTypeStack extends TypeStack(Nil) { }
-
class TypeStack(var types: Rep) {
if (types.nonEmpty)
checkerDebug("Created " + this)
@@ -71,14 +67,6 @@ trait TypeStacks {
def apply(n: Int): TypeKind = types(n)
- /**
- * A TypeStack agrees with another one if they have the same
- * length and each type kind agrees position-wise. Two
- * types agree if one is a subtype of the other.
- */
- def agreesWith(other: TypeStack): Boolean =
- (types corresponds other.types)((t1, t2) => t1 <:< t2 || t2 <:< t1)
-
/* This method returns a String representation of the stack */
override def toString() =
if (types.isEmpty) "[]"
diff --git a/src/compiler/scala/tools/nsc/backend/icode/analysis/CopyPropagation.scala b/src/compiler/scala/tools/nsc/backend/icode/analysis/CopyPropagation.scala
index 53111d0ade..7f32b2b764 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/analysis/CopyPropagation.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/analysis/CopyPropagation.scala
@@ -26,12 +26,8 @@ abstract class CopyPropagation {
case object This extends Location
/** Values that can be on the stack. */
- abstract class Value {
- def isRecord = false
- }
- case class Record(cls: Symbol, bindings: mutable.Map[Symbol, Value]) extends Value {
- override def isRecord = true
- }
+ abstract class Value { }
+ case class Record(cls: Symbol, bindings: mutable.Map[Symbol, Value]) extends Value { }
/** The value of some location in memory. */
case class Deref(l: Location) extends Value
@@ -91,16 +87,6 @@ abstract class CopyPropagation {
loop(l) getOrElse Deref(LocalVar(l))
}
- /* Return the binding for the given field of the given record */
- def getBinding(r: Record, f: Symbol): Value = {
- assert(r.bindings contains f, "Record " + r + " does not contain a field " + f)
-
- r.bindings(f) match {
- case Deref(LocalVar(l)) => getBinding(l)
- case target => target
- }
- }
-
/** Return a local which contains the same value as this field, if any.
* If the field holds a reference to a local, the returned value is the
* binding of that local.
@@ -463,14 +449,9 @@ abstract class CopyPropagation {
}
}
- /** Update the state <code>s</code> after the call to <code>method</code>.
+ /** Update the state `s` after the call to `method`.
* The stack elements are dropped and replaced by the result of the call.
* If the method is impure, all bindings to record fields are cleared.
- *
- * @param state ...
- * @param method ...
- * @param static ...
- * @return ...
*/
final def simulateCall(state: copyLattice.State, method: Symbol, static: Boolean): copyLattice.State = {
val out = new copyLattice.State(state.bindings, state.stack);
@@ -554,10 +535,7 @@ abstract class CopyPropagation {
bindings
}
- /** Is symbol <code>m</code> a pure method?
- *
- * @param m ...
- * @return ...
+ /** Is symbol `m` a pure method?
*/
final def isPureMethod(m: Symbol): Boolean =
m.isGetter // abstract getters are still pure, as we 'know'
diff --git a/src/compiler/scala/tools/nsc/backend/icode/analysis/DataFlowAnalysis.scala b/src/compiler/scala/tools/nsc/backend/icode/analysis/DataFlowAnalysis.scala
index 04c3eedbad..cc3a7eb876 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/analysis/DataFlowAnalysis.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/analysis/DataFlowAnalysis.scala
@@ -34,15 +34,6 @@ trait DataFlowAnalysis[L <: SemiLattice] {
f
}
- /** Reinitialize, but keep the old solutions. Should be used when reanalyzing the
- * same method, after some code transformation.
- */
- def reinit(f: => Unit): Unit = {
- iterations = 0
- worklist.clear; visited.clear;
- f
- }
-
def run(): Unit
/** Implements forward dataflow analysis: the transfer function is
@@ -82,10 +73,6 @@ trait DataFlowAnalysis[L <: SemiLattice] {
sys.error("Could not find element " + e.getMessage)
}
- /** ...
- *
- * @param f ...
- */
def backwardAnalysis(f: (P, lattice.Elem) => lattice.Elem): Unit =
while (worklist.nonEmpty) {
if (stat) iterations += 1
diff --git a/src/compiler/scala/tools/nsc/backend/icode/analysis/ReachingDefinitions.scala b/src/compiler/scala/tools/nsc/backend/icode/analysis/ReachingDefinitions.scala
index 2717c432e8..48755d4424 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/analysis/ReachingDefinitions.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/analysis/ReachingDefinitions.scala
@@ -52,7 +52,7 @@ abstract class ReachingDefinitions {
// it makes it harder to spot the real problems.
val result = (a.stack, b.stack).zipped map (_ ++ _)
if (settings.debug.value && (a.stack.length != b.stack.length))
- debugwarn("Mismatched stacks in ReachingDefinitions#lub2: " + a.stack + ", " + b.stack + ", returning " + result)
+ devWarning(s"Mismatched stacks in ReachingDefinitions#lub2: ${a.stack}, ${b.stack}, returning $result")
result
}
)
@@ -155,7 +155,7 @@ abstract class ReachingDefinitions {
import lattice.IState
def updateReachingDefinition(b: BasicBlock, idx: Int, rd: ListSet[Definition]): ListSet[Definition] = {
val STORE_LOCAL(local) = b(idx)
- var tmp = local
+ val tmp = local
(rd filter { case (l, _, _) => l != tmp }) + ((tmp, b, idx))
}
@@ -197,7 +197,7 @@ abstract class ReachingDefinitions {
def findDefs(bb: BasicBlock, idx: Int, m: Int, depth: Int): List[(BasicBlock, Int)] = if (idx > 0) {
assert(bb.closed, bb)
- var instrs = bb.getArray
+ val instrs = bb.getArray
var res: List[(BasicBlock, Int)] = Nil
var i = idx
var n = m
diff --git a/src/compiler/scala/tools/nsc/backend/icode/analysis/TypeFlowAnalysis.scala b/src/compiler/scala/tools/nsc/backend/icode/analysis/TypeFlowAnalysis.scala
index b2ecb431ee..c9d295a350 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/analysis/TypeFlowAnalysis.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/analysis/TypeFlowAnalysis.scala
@@ -68,7 +68,6 @@ abstract class TypeFlowAnalysis {
* names to types and a type stack.
*/
object typeFlowLattice extends SemiLattice {
- import icodes._
type Elem = IState[VarBinding, icodes.TypeStack]
val top = new Elem(new VarBinding, typeStackLattice.top)
@@ -136,7 +135,7 @@ abstract class TypeFlowAnalysis {
timer.start
// icodes.lubs0 = 0
forwardAnalysis(blockTransfer)
- val t = timer.stop
+ timer.stop
if (settings.debug.value) {
linearizer.linearize(method).foreach(b => if (b != method.startBlock)
assert(visited.contains(b),
@@ -269,36 +268,6 @@ abstract class TypeFlowAnalysis {
out
} // interpret
-
- class SimulatedStack {
- private var types: List[InferredType] = Nil
- private var depth = 0
-
- /** Remove and return the topmost element on the stack. If the
- * stack is empty, return a reference to a negative index on the
- * stack, meaning it refers to elements pushed by a predecessor block.
- */
- def pop: InferredType = types match {
- case head :: rest =>
- types = rest
- head
- case _ =>
- depth -= 1
- TypeOfStackPos(depth)
- }
-
- def pop2: (InferredType, InferredType) = {
- (pop, pop)
- }
-
- def push(t: InferredType) {
- depth += 1
- types = types ::: List(t)
- }
-
- def push(k: TypeKind) { push(Const(k)) }
- }
-
abstract class InferredType {
/** Return the type kind pointed by this inferred type. */
def getKind(in: lattice.Elem): icodes.TypeKind = this match {
@@ -326,7 +295,6 @@ abstract class TypeFlowAnalysis {
class TransferFunction(consumed: Int, gens: List[Gen]) extends (lattice.Elem => lattice.Elem) {
def apply(in: lattice.Elem): lattice.Elem = {
val out = lattice.IState(new VarBinding(in.vars), new TypeStack(in.stack))
- val bindings = out.vars
val stack = out.stack
out.stack.pop(consumed)
@@ -389,7 +357,7 @@ abstract class TypeFlowAnalysis {
timer.start
forwardAnalysis(blockTransfer)
- val t = timer.stop
+ timer.stop
/* Now that `forwardAnalysis(blockTransfer)` has finished, all inlining candidates can be found in `remainingCALLs`,
whose keys are callsites and whose values are pieces of information about the typestack just before the callsite in question.
@@ -546,9 +514,6 @@ abstract class TypeFlowAnalysis {
relevantBBs ++= blocks
}
- /* the argument is also included in the result */
- private def transitivePreds(b: BasicBlock): Set[BasicBlock] = { transitivePreds(List(b)) }
-
/* those BBs in the argument are also included in the result */
private def transitivePreds(starters: Traversable[BasicBlock]): Set[BasicBlock] = {
val result = mutable.Set.empty[BasicBlock]
@@ -562,19 +527,6 @@ abstract class TypeFlowAnalysis {
result.toSet
}
- /* those BBs in the argument are also included in the result */
- private def transitiveSuccs(starters: Traversable[BasicBlock]): Set[BasicBlock] = {
- val result = mutable.Set.empty[BasicBlock]
- var toVisit: List[BasicBlock] = starters.toList.distinct
- while(toVisit.nonEmpty) {
- val h = toVisit.head
- toVisit = toVisit.tail
- result += h
- for(p <- h.successors; if !result(p) && !toVisit.contains(p)) { toVisit = p :: toVisit }
- }
- result.toSet
- }
-
/* A basic block B is "on the perimeter" of the current control-flow subgraph if none of its successors belongs to that subgraph.
* In that case, for the purposes of inlining, we're interested in the typestack right before the last inline candidate in B, not in those afterwards.
* In particular we can do without computing the outflow at B. */
@@ -685,12 +637,6 @@ abstract class TypeFlowAnalysis {
if(!worklist.contains(b)) { worklist += b }
}
- /* this is not a general purpose method to add to the worklist,
- * because the assert is expected to hold only when called from MTFAGrowable.reinit() */
- private def enqueue(bs: Traversable[BasicBlock]) {
- bs foreach enqueue
- }
-
private def blankOut(blocks: scala.collection.Set[BasicBlock]) {
blocks foreach { b =>
in(b) = typeFlowLattice.bottom
@@ -761,10 +707,6 @@ abstract class TypeFlowAnalysis {
private var lastStart = 0L
- def reset() {
- millis = 0L
- }
-
def start() {
lastStart = System.currentTimeMillis
}
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/BytecodeWriters.scala b/src/compiler/scala/tools/nsc/backend/jvm/BytecodeWriters.scala
index fb1f45fa40..941ccd9a2d 100644
--- a/src/compiler/scala/tools/nsc/backend/jvm/BytecodeWriters.scala
+++ b/src/compiler/scala/tools/nsc/backend/jvm/BytecodeWriters.scala
@@ -9,9 +9,8 @@ package backend.jvm
import java.io.{ DataOutputStream, FileOutputStream, OutputStream, File => JFile }
import scala.tools.nsc.io._
import scala.tools.nsc.util.ScalaClassLoader
-import scala.tools.util.JavapClass
-import java.util.jar.{ JarEntry, JarOutputStream, Attributes }
-import Attributes.Name
+import scala.tools.util.{ Javap, JavapClass }
+import java.util.jar.Attributes.Name
import scala.language.postfixOps
/** For the last mile: turning generated bytecode in memory into
@@ -23,7 +22,7 @@ trait BytecodeWriters {
import global._
private def outputDirectory(sym: Symbol): AbstractFile = (
- settings.outputDirs.outputDirFor(beforeFlatten(sym.sourceFile))
+ settings.outputDirs.outputDirFor(enteringFlatten(sym.sourceFile))
)
private def getFile(base: AbstractFile, /*cls.getName()*/ clsName: String, suffix: String): AbstractFile = {
var dir = base
@@ -60,27 +59,32 @@ trait BytecodeWriters {
override def close() = writer.close()
}
+ /** To be mixed-in with the BytecodeWriter that generates
+ * the class file to be disassembled.
+ */
trait JavapBytecodeWriter extends BytecodeWriter {
val baseDir = Directory(settings.Ygenjavap.value).createDirectory()
-
- def emitJavap(bytes: Array[Byte], javapFile: io.File) {
- val pw = javapFile.printWriter()
- val javap = new JavapClass(ScalaClassLoader.appLoader, pw) {
- override def findBytes(path: String): Array[Byte] = bytes
- }
-
- try javap(Seq("-verbose", "dummy")) foreach (_.show())
- finally pw.close()
+ val cl = ScalaClassLoader.appLoader
+
+ def emitJavap(classFile: AbstractFile, javapFile: File) {
+ val pw = javapFile.printWriter()
+ try {
+ val javap = new JavapClass(cl, pw) {
+ override def findBytes(path: String): Array[Byte] = classFile.toByteArray
+ }
+ javap(Seq("-verbose", "-protected", classFile.name)) foreach (_.show())
+ } finally pw.close()
}
abstract override def writeClass(label: String, jclassName: String, jclassBytes: Array[Byte], sym: Symbol) {
super.writeClass(label, jclassName, jclassBytes, sym)
- val bytes = getFile(sym, jclassName, ".class").toByteArray
+ val classFile = getFile(sym, jclassName, ".class")
val segments = jclassName.split("[./]")
val javapFile = segments.foldLeft(baseDir: Path)(_ / _) changeExtension "javap" toFile;
-
javapFile.parent.createDirectory()
- emitJavap(bytes, javapFile)
+
+ if (Javap.isAvailable(cl)) emitJavap(classFile, javapFile)
+ else warning("No javap on classpath, skipping javap output.")
}
}
@@ -102,7 +106,7 @@ trait BytecodeWriters {
super.writeClass(label, jclassName, jclassBytes, sym)
val pathName = jclassName
- var dumpFile = pathName.split("[./]").foldLeft(baseDir: Path) (_ / _) changeExtension "class" toFile;
+ val dumpFile = pathName.split("[./]").foldLeft(baseDir: Path) (_ / _) changeExtension "class" toFile;
dumpFile.parent.createDirectory()
val outstream = new DataOutputStream(new FileOutputStream(dumpFile.path))
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala
index d185ed0c34..92d732ed04 100644
--- a/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala
+++ b/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala
@@ -6,12 +6,9 @@
package scala.tools.nsc
package backend.jvm
-import java.nio.ByteBuffer
import scala.collection.{ mutable, immutable }
import scala.reflect.internal.pickling.{ PickleFormat, PickleBuffer }
import scala.tools.nsc.symtab._
-import scala.tools.nsc.io.AbstractFile
-
import scala.tools.asm
import asm.Label
@@ -32,6 +29,16 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM {
/** Create a new phase */
override def newPhase(p: Phase): Phase = new AsmPhase(p)
+ /** From the reference documentation of the Android SDK:
+ * The `Parcelable` interface identifies classes whose instances can be written to and restored from a `Parcel`.
+ * Classes implementing the `Parcelable` interface must also have a static field called `CREATOR`,
+ * which is an object implementing the `Parcelable.Creator` interface.
+ */
+ private val androidFieldName = newTermName("CREATOR")
+
+ private lazy val AndroidParcelableInterface = rootMirror.getClassIfDefined("android.os.Parcelable")
+ private lazy val AndroidCreatorClass = rootMirror.getClassIfDefined("android.os.Parcelable$Creator")
+
/** JVM code generation phase
*/
class AsmPhase(prev: Phase) extends ICodePhase(prev) {
@@ -39,7 +46,9 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM {
override def erasedTypes = true
def apply(cls: IClass) = sys.error("no implementation")
- val BeanInfoAttr = rootMirror.getRequiredClass("scala.beans.BeanInfo")
+ // Lazy val; can't have eager vals in Phase constructors which may
+ // cause cycles before Global has finished initialization.
+ lazy val BeanInfoAttr = rootMirror.getRequiredClass("scala.beans.BeanInfo")
private def initBytecodeWriter(entryPoints: List[IClass]): BytecodeWriter = {
settings.outputDirs.getSingleOutput match {
@@ -62,13 +71,18 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM {
new DirectToJarfileWriter(f.file)
case _ =>
+ import scala.tools.util.Javap
if (settings.Ygenjavap.isDefault) {
if(settings.Ydumpclasses.isDefault)
new ClassBytecodeWriter { }
else
new ClassBytecodeWriter with DumpBytecodeWriter { }
}
- else new ClassBytecodeWriter with JavapBytecodeWriter { }
+ else if (Javap.isAvailable()) new ClassBytecodeWriter with JavapBytecodeWriter { }
+ else {
+ warning("No javap on classpath, skipping javap output.")
+ new ClassBytecodeWriter { }
+ }
// TODO A ScalapBytecodeWriter could take asm.util.Textifier as starting point.
// Three areas where javap ouput is less than ideal (e.g. when comparing versions of the same classfile) are:
@@ -133,7 +147,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM {
/* don't javaNameCache.clear() because that causes the following tests to fail:
* test/files/run/macro-repl-dontexpand.scala
* test/files/jvm/interpreter.scala
- * TODO but why? what use could javaNameCache possibly see once GenJVM is over?
+ * TODO but why? what use could javaNameCache possibly see once GenASM is over?
*/
/* TODO After emitting all class files (e.g., in a separate compiler phase) ASM can perform bytecode verification:
@@ -248,7 +262,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM {
}
def isTopLevelModule(sym: Symbol): Boolean =
- afterPickler { sym.isModuleClass && !sym.isImplClass && !sym.isNestedClass }
+ exitingPickler { sym.isModuleClass && !sym.isImplClass && !sym.isNestedClass }
def isStaticModule(sym: Symbol): Boolean = {
sym.isModuleClass && !sym.isImplClass && !sym.isLifted
@@ -398,7 +412,6 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM {
/** basic functionality for class file building */
abstract class JBuilder(bytecodeWriter: BytecodeWriter) {
- val EMPTY_JTYPE_ARRAY = Array.empty[asm.Type]
val EMPTY_STRING_ARRAY = Array.empty[String]
val mdesc_arglessvoid = "()V"
@@ -466,7 +479,6 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM {
/** Specialized array conversion to prevent calling
* java.lang.reflect.Array.newInstance via TraversableOnce.toArray
*/
- def mkArray(xs: Traversable[asm.Type]): Array[asm.Type] = { val a = new Array[asm.Type](xs.size); xs.copyToArray(a); a }
def mkArray(xs: Traversable[String]): Array[String] = { val a = new Array[String](xs.size); xs.copyToArray(a); a }
// -----------------------------------------------------------------------------------------
@@ -516,7 +528,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM {
* of inner class all until root class.
*/
def collectInnerClass(s: Symbol): Unit = {
- // TODO: some beforeFlatten { ... } which accounts for
+ // TODO: some enteringFlatten { ... } which accounts for
// being nested in parameterized classes (if we're going to selectively flatten.)
val x = innerClassSymbolFor(s)
if(x ne NoSymbol) {
@@ -531,7 +543,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM {
collectInnerClass(sym)
- var hasInternalName = (sym.isClass || (sym.isModule && !sym.isMethod))
+ val hasInternalName = (sym.isClass || (sym.isModule && !sym.isMethod))
val cachedJN = javaNameCache.getOrElseUpdate(sym, {
if (hasInternalName) { sym.javaBinaryName }
else { sym.javaSimpleName }
@@ -541,12 +553,18 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM {
val internalName = cachedJN.toString()
val trackedSym = jsymbol(sym)
reverseJavaName.get(internalName) match {
- case None =>
+ case Some(oldsym) if oldsym.exists && trackedSym.exists =>
+ assert(
+ // In contrast, neither NothingClass nor NullClass show up bytecode-level.
+ (oldsym == trackedSym) || (oldsym == RuntimeNothingClass) || (oldsym == RuntimeNullClass) || (oldsym.isModuleClass && (oldsym.sourceModule == trackedSym.sourceModule)),
+ s"""|Different class symbols have the same bytecode-level internal name:
+ | name: $internalName
+ | oldsym: ${oldsym.fullNameString}
+ | tracked: ${trackedSym.fullNameString}
+ """.stripMargin
+ )
+ case _ =>
reverseJavaName.put(internalName, trackedSym)
- case Some(oldsym) =>
- assert((oldsym == trackedSym) || (oldsym == RuntimeNothingClass) || (oldsym == RuntimeNullClass) ||
- (oldsym.isModuleClass && (oldsym.sourceModule == trackedSym.sourceModule)), // In contrast, neither NothingClass nor NullClass show up bytecode-level.
- "how can getCommonSuperclass() do its job if different class symbols get the same bytecode-level internal name: " + internalName)
}
}
@@ -619,7 +637,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM {
innerSym.rawname + innerSym.moduleSuffix
// add inner classes which might not have been referenced yet
- afterErasure {
+ exitingErasure {
for (sym <- List(csym, csym.linkedClassOfClass); m <- sym.info.decls.map(innerClassSymbolFor) if m.isClass)
innerClassBuffer += m
}
@@ -810,7 +828,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM {
if (!needsGenericSignature(sym)) { return null }
- val memberTpe = beforeErasure(owner.thisType.memberInfo(sym))
+ val memberTpe = enteringErasure(owner.thisType.memberInfo(sym))
val jsOpt: Option[String] = erasure.javaSig(sym, memberTpe)
if (jsOpt.isEmpty) { return null }
@@ -827,10 +845,10 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM {
// Run the signature parser to catch bogus signatures.
val isValidSignature = wrap {
// Alternative: scala.tools.reflect.SigParser (frontend to sun.reflect.generics.parser.SignatureParser)
- import scala.tools.asm.util.SignatureChecker
- if (sym.isMethod) { SignatureChecker checkMethodSignature sig } // requires asm-util.jar
- else if (sym.isTerm) { SignatureChecker checkFieldSignature sig }
- else { SignatureChecker checkClassSignature sig }
+ import scala.tools.asm.util.CheckClassAdapter
+ if (sym.isMethod) { CheckClassAdapter checkMethodSignature sig } // requires asm-util.jar
+ else if (sym.isTerm) { CheckClassAdapter checkFieldSignature sig }
+ else { CheckClassAdapter checkClassSignature sig }
}
if(!isValidSignature) {
@@ -844,7 +862,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM {
}
if ((settings.check containsName phaseName)) {
- val normalizedTpe = beforeErasure(erasure.prepareSigMap(memberTpe))
+ val normalizedTpe = enteringErasure(erasure.prepareSigMap(memberTpe))
val bytecodeTpe = owner.thisType.memberInfo(sym)
if (!sym.isType && !sym.isConstructor && !(erasure.erasure(sym)(normalizedTpe) =:= bytecodeTpe)) {
getCurrentCUnit().warning(sym.pos,
@@ -1099,7 +1117,6 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM {
debuglog("Dumping mirror class for object: " + moduleClass)
val linkedClass = moduleClass.companionClass
- val linkedModule = linkedClass.companionSymbol
lazy val conflictingNames: Set[Name] = {
(linkedClass.info.members collect { case sym if sym.name.isTermName => sym.name }).toSet
}
@@ -1125,16 +1142,6 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM {
trait JAndroidBuilder {
self: JPlainBuilder =>
- /** From the reference documentation of the Android SDK:
- * The `Parcelable` interface identifies classes whose instances can be written to and restored from a `Parcel`.
- * Classes implementing the `Parcelable` interface must also have a static field called `CREATOR`,
- * which is an object implementing the `Parcelable.Creator` interface.
- */
- private val androidFieldName = newTermName("CREATOR")
-
- private lazy val AndroidParcelableInterface = rootMirror.getClassIfDefined("android.os.Parcelable")
- private lazy val AndroidCreatorClass = rootMirror.getClassIfDefined("android.os.Parcelable$Creator")
-
def isAndroidParcelableClass(sym: Symbol) =
(AndroidParcelableInterface != NoSymbol) &&
(sym.parentSymbols contains AndroidParcelableInterface)
@@ -1142,7 +1149,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM {
/* Typestate: should be called before emitting fields (because it adds an IField to the current IClass). */
def addCreatorCode(block: BasicBlock) {
val fieldSymbol = (
- clasz.symbol.newValue(newTermName(androidFieldName), NoPosition, Flags.STATIC | Flags.FINAL)
+ clasz.symbol.newValue(androidFieldName, NoPosition, Flags.STATIC | Flags.FINAL)
setInfo AndroidCreatorClass.tpe
)
val methodSymbol = definitions.getMember(clasz.symbol.companionModule, androidFieldName)
@@ -1157,7 +1164,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM {
jclass.visitField(
PublicStaticFinal,
- androidFieldName,
+ androidFieldName.toString,
tdesc_creator,
null, // no java-generic-signature
null // no initial value
@@ -1177,7 +1184,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM {
clinit.visitMethodInsn(
asm.Opcodes.INVOKEVIRTUAL,
moduleName,
- androidFieldName,
+ androidFieldName.toString,
asm.Type.getMethodDescriptor(creatorType, Array.empty[asm.Type]: _*)
)
@@ -1185,7 +1192,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM {
clinit.visitFieldInsn(
asm.Opcodes.PUTSTATIC,
thisName,
- androidFieldName,
+ androidFieldName.toString,
tdesc_creator
)
}
@@ -1267,7 +1274,6 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM {
// Additional interface parents based on annotations and other cues
def newParentForAttr(attr: Symbol): Option[Symbol] = attr match {
- case SerializableAttr => Some(SerializableClass)
case CloneableAttr => Some(CloneableClass)
case RemoteAttr => Some(RemoteInterfaceClass)
case _ => None
@@ -1371,7 +1377,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM {
if (lmoc != NoSymbol) {
// it must be a top level class (name contains no $s)
val isCandidateForForwarders = {
- afterPickler { !(lmoc.name.toString contains '$') && lmoc.hasModuleFlag && !lmoc.isImplClass && !lmoc.isNestedClass }
+ exitingPickler { !(lmoc.name.toString contains '$') && lmoc.hasModuleFlag && !lmoc.isImplClass && !lmoc.isNestedClass }
}
if (isCandidateForForwarders) {
log("Adding static forwarders from '%s' to implementations in '%s'".format(c.symbol, lmoc))
@@ -1700,11 +1706,6 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM {
import asm.Opcodes;
- def aconst(cst: AnyRef) {
- if (cst == null) { jmethod.visitInsn(Opcodes.ACONST_NULL) }
- else { jmethod.visitLdcInsn(cst) }
- }
-
final def boolconst(b: Boolean) { iconst(if(b) 1 else 0) }
def iconst(cst: Int) {
@@ -2150,7 +2151,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM {
def getMerged(): scala.collection.Map[Local, List[Interval]] = {
// TODO should but isn't: unbalanced start(s) of scope(s)
- val shouldBeEmpty = pending filter { p => val Pair(k, st) = p; st.nonEmpty };
+ val shouldBeEmpty = pending filter { p => val Pair(_, st) = p; st.nonEmpty };
val merged = mutable.Map[Local, List[Interval]]()
def addToMerged(lv: Local, start: Label, end: Label) {
val intv = Interval(start, end)
@@ -2213,7 +2214,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM {
}
// quest for deterministic output that Map.toList doesn't provide (so that ant test.stability doesn't complain).
val srtd = fltnd.sortBy { kr =>
- val Triple(name: String, local: Local, intrvl: Interval) = kr
+ val Triple(name: String, _, intrvl: Interval) = kr
Triple(intrvl.start, intrvl.end - intrvl.start, name) // ie sort by (start, length, name)
}
@@ -2333,6 +2334,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM {
import asm.Opcodes
(instr.category: @scala.annotation.switch) match {
+
case icodes.localsCat =>
def genLocalInstr() = (instr: @unchecked) match {
case THIS(_) => jmethod.visitVarInsn(Opcodes.ALOAD, 0)
@@ -2371,7 +2373,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM {
case LOAD_MODULE(module) =>
// assert(module.isModule, "Expected module: " + module)
- debuglog("generating LOAD_MODULE for: " + module + " flags: " + Flags.flagsToString(module.flags));
+ debuglog("generating LOAD_MODULE for: " + module + " flags: " + module.flagString);
if (clasz.symbol == module.moduleClass && jMethodName != nme.readResolve.toString) {
jmethod.visitVarInsn(Opcodes.ALOAD, 0)
} else {
@@ -2426,7 +2428,6 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM {
case icodes.objsCat =>
def genObjsInstr() = (instr: @unchecked) match {
-
case BOX(kind) =>
val MethodNameAndType(mname, mdesc) = jBoxTo(kind)
jcode.invokestatic(BoxesRunTime, mname, mdesc)
@@ -2448,8 +2449,8 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM {
def genFldsInstr() = (instr: @unchecked) match {
case lf @ LOAD_FIELD(field, isStatic) =>
- var owner = javaName(lf.hostClass)
- debuglog("LOAD_FIELD with owner: " + owner + " flags: " + Flags.flagsToString(field.owner.flags))
+ val owner = javaName(lf.hostClass)
+ debuglog("LOAD_FIELD with owner: " + owner + " flags: " + field.owner.flagString)
val fieldJName = javaName(field)
val fieldDescr = descriptor(field)
val opc = if (isStatic) Opcodes.GETSTATIC else Opcodes.GETFIELD
@@ -2867,15 +2868,8 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM {
////////////////////// local vars ///////////////////////
- // def sizeOf(sym: Symbol): Int = sizeOf(toTypeKind(sym.tpe))
-
def sizeOf(k: TypeKind): Int = if(k.isWideType) 2 else 1
- // def indexOf(m: IMethod, sym: Symbol): Int = {
- // val Some(local) = m lookupLocal sym
- // indexOf(local)
- // }
-
final def indexOf(local: Local): Int = {
assert(local.index >= 0, "Invalid index for: " + local + "{" + local.## + "}: ")
local.index
@@ -3281,8 +3275,8 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM {
var wasReduced = false
val entryPoints: List[BasicBlock] = m.startBlock :: (m.exh map (_.startBlock));
- var elided = mutable.Set.empty[BasicBlock] // debug
- var newTargets = mutable.Set.empty[BasicBlock] // debug
+ val elided = mutable.Set.empty[BasicBlock] // debug
+ val newTargets = mutable.Set.empty[BasicBlock] // debug
for (ep <- entryPoints) {
var reachable = directSuccStar(ep) // this list may contain blocks belonging to jump-chains that we'll skip over
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenAndroid.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenAndroid.scala
deleted file mode 100644
index 72b7e35408..0000000000
--- a/src/compiler/scala/tools/nsc/backend/jvm/GenAndroid.scala
+++ /dev/null
@@ -1,62 +0,0 @@
-/* NSC -- new Scala compiler
- * Copyright 2005-2013 LAMP/EPFL
- * @author Stephane Micheloud
- */
-
-
-package scala.tools.nsc
-package backend.jvm
-
-import ch.epfl.lamp.fjbg._
-import symtab.Flags
-
-trait GenAndroid {
- self: GenJVM =>
-
- import global._
- import icodes._
- import opcodes._
-
- /** From the reference documentation of the Android SDK:
- * The `Parcelable` interface identifies classes whose instances can be
- * written to and restored from a `Parcel`. Classes implementing the
- * `Parcelable` interface must also have a static field called `CREATOR`,
- * which is an object implementing the `Parcelable.Creator` interface.
- */
- private val fieldName = newTermName("CREATOR")
-
- private lazy val AndroidParcelableInterface = rootMirror.getClassIfDefined("android.os.Parcelable")
- private lazy val AndroidCreatorClass = rootMirror.getClassIfDefined("android.os.Parcelable$Creator")
-
- def isAndroidParcelableClass(sym: Symbol) =
- (AndroidParcelableInterface != NoSymbol) &&
- (sym.parentSymbols contains AndroidParcelableInterface)
-
- def addCreatorCode(codegen: BytecodeGenerator, block: BasicBlock) {
- import codegen._
- val fieldSymbol = (
- clasz.symbol.newValue(newTermName(fieldName), NoPosition, Flags.STATIC | Flags.FINAL)
- setInfo AndroidCreatorClass.tpe
- )
- val methodSymbol = definitions.getMember(clasz.symbol.companionModule, fieldName)
- clasz addField new IField(fieldSymbol)
- block emit CALL_METHOD(methodSymbol, Static(false))
- block emit STORE_FIELD(fieldSymbol, true)
- }
-
- def legacyAddCreatorCode(codegen: BytecodeGenerator, clinit: JExtendedCode) {
- import codegen._
- val creatorType = javaType(AndroidCreatorClass)
- jclass.addNewField(PublicStaticFinal,
- fieldName,
- creatorType)
- val moduleName = javaName(clasz.symbol)+"$"
- clinit.emitGETSTATIC(moduleName,
- nme.MODULE_INSTANCE_FIELD.toString,
- new JObjectType(moduleName))
- clinit.emitINVOKEVIRTUAL(moduleName, fieldName,
- new JMethodType(creatorType, Array()))
- clinit.emitPUTSTATIC(jclass.getName(), fieldName, creatorType)
- }
-
-}
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala
deleted file mode 100644
index fe0020e074..0000000000
--- a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala
+++ /dev/null
@@ -1,1921 +0,0 @@
-/* NSC -- new Scala compiler
- * Copyright 2005-2013 LAMP/EPFL
- * @author Iulian Dragos
- */
-
-package scala.tools.nsc
-package backend.jvm
-
-import java.io.{ByteArrayOutputStream, DataOutputStream, OutputStream }
-import java.nio.ByteBuffer
-import scala.collection.{ mutable, immutable }
-import scala.reflect.internal.pickling.{ PickleFormat, PickleBuffer }
-import scala.tools.nsc.symtab._
-import scala.reflect.internal.util.{ SourceFile, NoSourceFile }
-import scala.reflect.internal.ClassfileConstants._
-import ch.epfl.lamp.fjbg._
-import JAccessFlags._
-import JObjectType.{ JAVA_LANG_STRING, JAVA_LANG_OBJECT }
-import java.util.jar.{ JarEntry, JarOutputStream }
-import scala.tools.nsc.io.AbstractFile
-import scala.language.postfixOps
-
-/** This class ...
- *
- * @author Iulian Dragos
- * @version 1.0
- *
- */
-abstract class GenJVM extends SubComponent with GenJVMUtil with GenAndroid with BytecodeWriters with GenJVMASM {
- import global._
- import icodes._
- import icodes.opcodes._
- import definitions._
-
- val phaseName = "jvm"
-
- /** Create a new phase */
- override def newPhase(p: Phase): Phase = new JvmPhase(p)
-
- /** JVM code generation phase
- */
- class JvmPhase(prev: Phase) extends ICodePhase(prev) {
- def name = phaseName
- override def erasedTypes = true
- def apply(cls: IClass) = sys.error("no implementation")
-
- override def run() {
- // we reinstantiate the bytecode generator at each run, to allow the GC
- // to collect everything
- if (settings.debug.value)
- inform("[running phase " + name + " on icode]")
-
- if (settings.Xdce.value)
- for ((sym, cls) <- icodes.classes if inliner.isClosureClass(sym) && !deadCode.liveClosures(sym)) {
- log(s"Optimizer eliminated ${sym.fullNameString}")
- icodes.classes -= sym
- }
-
- // For predictably ordered error messages.
- val sortedClasses = classes.values.toList sortBy ("" + _.symbol.fullName)
- val entryPoints = sortedClasses filter isJavaEntryPoint
-
- val bytecodeWriter = settings.outputDirs.getSingleOutput match {
- case Some(f) if f hasExtension "jar" =>
- // If no main class was specified, see if there's only one
- // entry point among the classes going into the jar.
- if (settings.mainClass.isDefault) {
- entryPoints map (_.symbol fullName '.') match {
- case Nil =>
- log("No Main-Class designated or discovered.")
- case name :: Nil =>
- log("Unique entry point: setting Main-Class to " + name)
- settings.mainClass.value = name
- case names =>
- log("No Main-Class due to multiple entry points:\n " + names.mkString("\n "))
- }
- }
- else log("Main-Class was specified: " + settings.mainClass.value)
-
- new DirectToJarfileWriter(f.file)
-
- case _ =>
- if (settings.Ygenjavap.isDefault) {
- if(settings.Ydumpclasses.isDefault)
- new ClassBytecodeWriter { }
- else
- new ClassBytecodeWriter with DumpBytecodeWriter { }
- }
- else new ClassBytecodeWriter with JavapBytecodeWriter { }
- }
-
- val codeGenerator = new BytecodeGenerator(bytecodeWriter)
- debuglog("Created new bytecode generator for " + classes.size + " classes.")
-
- sortedClasses foreach { c =>
- try codeGenerator.genClass(c)
- catch {
- case e: JCode.CodeSizeTooBigException =>
- log("Skipped class %s because it has methods that are too long.".format(c))
- }
- }
-
- bytecodeWriter.close()
- classes.clear()
- }
- }
-
- var pickledBytes = 0 // statistics
-
- /**
- * Java bytecode generator.
- *
- */
- class BytecodeGenerator(bytecodeWriter: BytecodeWriter) extends BytecodeUtil {
- def this() = this(new ClassBytecodeWriter { })
- def debugLevel = settings.debuginfo.indexOfChoice
- import bytecodeWriter.writeClass
-
- val MIN_SWITCH_DENSITY = 0.7
- val INNER_CLASSES_FLAGS =
- (ACC_PUBLIC | ACC_PRIVATE | ACC_PROTECTED | ACC_STATIC | ACC_INTERFACE | ACC_ABSTRACT)
-
- val PublicStatic = ACC_PUBLIC | ACC_STATIC
- val PublicStaticFinal = ACC_PUBLIC | ACC_STATIC | ACC_FINAL
-
- val StringBuilderClassName = javaName(definitions.StringBuilderClass)
- val BoxesRunTime = "scala.runtime.BoxesRunTime"
-
- val StringBuilderType = new JObjectType(StringBuilderClassName) // TODO use ASMType.getObjectType
- val toStringType = new JMethodType(JAVA_LANG_STRING, JType.EMPTY_ARRAY) // TODO use ASMType.getMethodType
- val arrayCloneType = new JMethodType(JAVA_LANG_OBJECT, JType.EMPTY_ARRAY)
- val MethodTypeType = new JObjectType("java.dyn.MethodType")
- val JavaLangClassType = new JObjectType("java.lang.Class")
- val MethodHandleType = new JObjectType("java.dyn.MethodHandle")
-
- // Scala attributes
- val BeanInfoAttr = rootMirror.getRequiredClass("scala.beans.BeanInfo")
- val BeanInfoSkipAttr = rootMirror.getRequiredClass("scala.beans.BeanInfoSkip")
- val BeanDisplayNameAttr = rootMirror.getRequiredClass("scala.beans.BeanDisplayName")
- val BeanDescriptionAttr = rootMirror.getRequiredClass("scala.beans.BeanDescription")
-
- // Additional interface parents based on annotations and other cues
- def newParentForAttr(attr: Symbol): Option[Symbol] = attr match {
- case SerializableAttr => Some(SerializableClass)
- case CloneableAttr => Some(JavaCloneableClass)
- case RemoteAttr => Some(RemoteInterfaceClass)
- case _ => None
- }
-
- val versionPickle = {
- val vp = new PickleBuffer(new Array[Byte](16), -1, 0)
- assert(vp.writeIndex == 0, vp)
- vp writeNat PickleFormat.MajorVersion
- vp writeNat PickleFormat.MinorVersion
- vp writeNat 0
- vp
- }
-
- private def helperBoxTo(kind: ValueTypeKind): Tuple2[String, JMethodType] = {
- val boxedType = definitions.boxedClass(kind.toType.typeSymbol)
- val mtype = new JMethodType(javaType(boxedType), Array(javaType(kind)))
-
- Pair("boxTo" + boxedType.decodedName, mtype)
- }
-
- private val jBoxTo: Map[TypeKind, Tuple2[String, JMethodType]] = Map(
- BOOL -> helperBoxTo(BOOL) ,
- BYTE -> helperBoxTo(BYTE) ,
- CHAR -> helperBoxTo(CHAR) ,
- SHORT -> helperBoxTo(SHORT) ,
- INT -> helperBoxTo(INT) ,
- LONG -> helperBoxTo(LONG) ,
- FLOAT -> helperBoxTo(FLOAT) ,
- DOUBLE -> helperBoxTo(DOUBLE)
- )
-
- private def helperUnboxTo(kind: ValueTypeKind): Tuple2[String, JMethodType] = {
- val mtype = new JMethodType(javaType(kind), Array(JAVA_LANG_OBJECT))
- val mname = "unboxTo" + kind.toType.typeSymbol.decodedName
-
- Pair(mname, mtype)
- }
-
- private val jUnboxTo: Map[TypeKind, Tuple2[String, JMethodType]] = Map(
- BOOL -> helperUnboxTo(BOOL) ,
- BYTE -> helperUnboxTo(BYTE) ,
- CHAR -> helperUnboxTo(CHAR) ,
- SHORT -> helperUnboxTo(SHORT) ,
- INT -> helperUnboxTo(INT) ,
- LONG -> helperUnboxTo(LONG) ,
- FLOAT -> helperUnboxTo(FLOAT) ,
- DOUBLE -> helperUnboxTo(DOUBLE)
- )
-
- var clasz: IClass = _
- var method: IMethod = _
- var jclass: JClass = _
- var jmethod: JMethod = _
- // var jcode: JExtendedCode = _
-
- def isParcelableClass = isAndroidParcelableClass(clasz.symbol)
- def isRemoteClass = clasz.symbol hasAnnotation RemoteAttr
- def serialVUID = clasz.symbol getAnnotation SerialVersionUIDAttr collect {
- case AnnotationInfo(_, Literal(const) :: _, _) => const.longValue
- }
-
- val fjbgContext = new FJBGContext(49, 0)
-
- val emitSource = debugLevel >= 1
- val emitLines = debugLevel >= 2
- val emitVars = debugLevel >= 3
-
- // bug had phase with wrong name; leaving enabled for brief pseudo deprecation
- private val checkSignatures = (
- (settings.check containsName phaseName)
- || (settings.check.value contains "genjvm") && {
- global.warning("This option will be removed: please use -Ycheck:%s, not -Ycheck:genjvm." format phaseName)
- true
- }
- )
-
- /** For given symbol return a symbol corresponding to a class that should be declared as inner class.
- *
- * For example:
- * class A {
- * class B
- * object C
- * }
- *
- * then method will return NoSymbol for A, the same symbol for A.B (corresponding to A$B class) and A$C$ symbol
- * for A.C.
- */
- private def innerClassSymbolFor(s: Symbol): Symbol =
- if (s.isClass) s else if (s.isModule) s.moduleClass else NoSymbol
-
- override def javaName(sym: Symbol): String = { // TODO Miguel says: check whether a single pass over `icodes.classes` can populate `innerClassBuffer` faster.
- /**
- * Checks if given symbol corresponds to inner class/object and add it to innerClassBuffer
- *
- * Note: This method is called recursively thus making sure that we add complete chain
- * of inner class all until root class.
- */
- def collectInnerClass(s: Symbol): Unit = {
- // TODO: some beforeFlatten { ... } which accounts for
- // being nested in parameterized classes (if we're going to selectively flatten.)
- val x = innerClassSymbolFor(s)
- if(x ne NoSymbol) {
- assert(x.isClass, "not an inner-class symbol")
- val isInner = !x.rawowner.isPackageClass
- if (isInner) {
- innerClassBuffer += x
- collectInnerClass(x.rawowner)
- }
- }
- }
- collectInnerClass(sym)
-
- super.javaName(sym)
- }
-
- /** Write a class to disk, adding the Scala signature (pickled type
- * information) and inner classes.
- *
- * @param jclass The FJBG class, where code was emitted
- * @param sym The corresponding symbol, used for looking up pickled information
- */
- def emitClass(jclass: JClass, sym: Symbol) {
- addInnerClasses(jclass)
- writeClass("" + sym.name, jclass.getName(), toByteArray(jclass), sym)
- }
-
- /** Returns the ScalaSignature annotation if it must be added to this class,
- * none otherwise; furthermore, it adds to `jclass` the ScalaSig marker
- * attribute (marking that a scala signature annotation is present) or the
- * Scala marker attribute (marking that the signature for this class is in
- * another file). The annotation that is returned by this method must be
- * added to the class' annotations list when generating them.
- *
- * @param jclass The class file that is being readied.
- * @param sym The symbol for which the signature has been entered in
- * the symData map. This is different than the symbol
- * that is being generated in the case of a mirror class.
- * @return An option that is:
- * - defined and contains an annotation info of the
- * ScalaSignature type, instantiated with the pickle
- * signature for sym (a ScalaSig marker attribute has
- * been written);
- * - undefined if the jclass/sym couple must not contain a
- * signature (a Scala marker attribute has been written).
- */
- def scalaSignatureAddingMarker(jclass: JClass, sym: Symbol): Option[AnnotationInfo] =
- currentRun.symData get sym match {
- case Some(pickle) if !nme.isModuleName(newTermName(jclass.getName)) =>
- val scalaAttr =
- fjbgContext.JOtherAttribute(jclass, jclass, tpnme.ScalaSignatureATTR.toString,
- versionPickle.bytes, versionPickle.writeIndex)
- jclass addAttribute scalaAttr
- val scalaAnnot = {
- val sigBytes = ScalaSigBytes(pickle.bytes.take(pickle.writeIndex))
- AnnotationInfo(sigBytes.sigAnnot, Nil, List((nme.bytes, sigBytes)))
- }
- pickledBytes += pickle.writeIndex
- currentRun.symData -= sym
- currentRun.symData -= sym.companionSymbol
- Some(scalaAnnot)
- case _ =>
- val markerAttr =
- fjbgContext.JOtherAttribute(jclass, jclass, tpnme.ScalaATTR.toString, new Array[Byte](0), 0)
- jclass addAttribute markerAttr
- None
- }
-
- private var innerClassBuffer = mutable.LinkedHashSet[Symbol]()
-
- /** Drop redundant interfaces (ones which are implemented by some other parent) from the immediate parents.
- * This is important on Android because there is otherwise an interface explosion.
- */
- private def minimizeInterfaces(interfaces: List[Symbol]): List[Symbol] = {
- var rest = interfaces
- var leaves = List.empty[Symbol]
- while(!rest.isEmpty) {
- val candidate = rest.head
- val nonLeaf = leaves exists { lsym => lsym isSubClass candidate }
- if(!nonLeaf) {
- leaves = candidate :: (leaves filterNot { lsym => candidate isSubClass lsym })
- }
- rest = rest.tail
- }
-
- leaves
- }
-
- def genClass(c: IClass) {
- clasz = c
- innerClassBuffer.clear()
-
- val name = javaName(c.symbol)
-
- val ps = c.symbol.info.parents
-
- val superClass: Symbol = if(ps.isEmpty) ObjectClass else ps.head.typeSymbol;
-
- val superInterfaces0: List[Symbol] = if(ps.isEmpty) Nil else c.symbol.mixinClasses;
- val superInterfaces = superInterfaces0 ++ c.symbol.annotations.flatMap(ann => newParentForAttr(ann.symbol)) distinct
-
- val ifaces =
- if(superInterfaces.isEmpty) JClass.NO_INTERFACES
- else mkArray(minimizeInterfaces(superInterfaces) map javaName)
-
- jclass = fjbgContext.JClass(javaFlags(c.symbol),
- name,
- javaName(superClass),
- ifaces,
- c.cunit.source.toString)
-
- if (isStaticModule(c.symbol) || serialVUID != None || isParcelableClass) {
- if (isStaticModule(c.symbol))
- addModuleInstanceField
- addStaticInit(jclass, c.lookupStaticCtor)
-
- if (isTopLevelModule(c.symbol)) {
- if (c.symbol.companionClass == NoSymbol)
- generateMirrorClass(c.symbol, c.cunit.source)
- else
- log("No mirror class for module with linked class: " +
- c.symbol.fullName)
- }
- }
- else {
- c.lookupStaticCtor foreach (constructor => addStaticInit(jclass, Some(constructor)))
-
- // it must be a top level class (name contains no $s)
- def isCandidateForForwarders(sym: Symbol): Boolean =
- afterPickler {
- !(sym.name.toString contains '$') && sym.hasModuleFlag && !sym.isImplClass && !sym.isNestedClass
- }
-
- // At some point this started throwing lots of exceptions as a compile was finishing.
- // error: java.lang.AssertionError:
- // assertion failed: List(object package$CompositeThrowable, object package$CompositeThrowable)
- // ...is the one I've seen repeatedly. Suppressing.
- val lmoc = (
- try c.symbol.companionModule
- catch { case x: AssertionError =>
- Console.println("Suppressing failed assert: " + x)
- NoSymbol
- }
- )
- // add static forwarders if there are no name conflicts; see bugs #363 and #1735
- if (lmoc != NoSymbol && !c.symbol.isInterface) {
- if (isCandidateForForwarders(lmoc) && !settings.noForwarders.value) {
- log("Adding static forwarders from '%s' to implementations in '%s'".format(c.symbol, lmoc))
- addForwarders(jclass, lmoc.moduleClass)
- }
- }
- }
-
- clasz.fields foreach genField
- clasz.methods foreach genMethod
-
- val ssa = scalaSignatureAddingMarker(jclass, c.symbol)
- addGenericSignature(jclass, c.symbol, c.symbol.owner)
- addAnnotations(jclass, c.symbol.annotations ++ ssa)
- addEnclosingMethodAttribute(jclass, c.symbol)
- emitClass(jclass, c.symbol)
-
- if (c.symbol hasAnnotation BeanInfoAttr)
- genBeanInfoClass(c)
- }
-
- private def addEnclosingMethodAttribute(jclass: JClass, clazz: Symbol) {
- val sym = clazz.originalEnclosingMethod
- if (sym.isMethod) {
- debuglog("enclosing method for %s is %s (in %s)".format(clazz, sym, sym.enclClass))
- jclass addAttribute fjbgContext.JEnclosingMethodAttribute(
- jclass,
- javaName(sym.enclClass),
- javaName(sym),
- javaType(sym)
- )
- } else if (clazz.isAnonymousClass) {
- val enclClass = clazz.rawowner
- assert(enclClass.isClass, enclClass)
- val sym = enclClass.primaryConstructor
- if (sym == NoSymbol)
- log("Ran out of room looking for an enclosing method for %s: no constructor here.".format(
- enclClass, clazz)
- )
- else {
- debuglog("enclosing method for %s is %s (in %s)".format(clazz, sym, enclClass))
- jclass addAttribute fjbgContext.JEnclosingMethodAttribute(
- jclass,
- javaName(enclClass),
- javaName(sym),
- javaType(sym).asInstanceOf[JMethodType]
- )
- }
- }
- }
-
- private def toByteArray(jc: JClass): Array[Byte] = {
- val bos = new java.io.ByteArrayOutputStream()
- val dos = new java.io.DataOutputStream(bos)
- jc.writeTo(dos)
- dos.close()
- bos.toByteArray
- }
-
- /**
- * Generate a bean info class that describes the given class.
- *
- * @author Ross Judson (ross.judson@soletta.com)
- */
- def genBeanInfoClass(c: IClass) {
- val description = c.symbol getAnnotation BeanDescriptionAttr
- // informProgress(description.toString)
-
- val beanInfoClass = fjbgContext.JClass(javaFlags(c.symbol),
- javaName(c.symbol) + "BeanInfo",
- "scala/beans/ScalaBeanInfo",
- JClass.NO_INTERFACES,
- c.cunit.source.toString)
-
- var fieldList = List[String]()
- for (f <- clasz.fields if f.symbol.hasGetter;
- g = f.symbol.getter(c.symbol);
- s = f.symbol.setter(c.symbol);
- if g.isPublic && !(f.symbol.name startsWith "$")) // inserting $outer breaks the bean
- fieldList = javaName(f.symbol) :: javaName(g) :: (if (s != NoSymbol) javaName(s) else null) :: fieldList
- val methodList =
- for (m <- clasz.methods
- if !m.symbol.isConstructor &&
- m.symbol.isPublic &&
- !(m.symbol.name startsWith "$") &&
- !m.symbol.isGetter &&
- !m.symbol.isSetter) yield javaName(m.symbol)
-
- val constructor = beanInfoClass.addNewMethod(ACC_PUBLIC, "<init>", JType.VOID, new Array[JType](0), new Array[String](0))
- val jcode = constructor.getCode().asInstanceOf[JExtendedCode]
- val strKind = new JObjectType(javaName(StringClass))
- val stringArrayKind = new JArrayType(strKind)
- val conType = new JMethodType(JType.VOID, Array(javaType(ClassClass), stringArrayKind, stringArrayKind))
-
- def push(lst:Seq[String]) {
- var fi = 0
- for (f <- lst) {
- jcode.emitDUP()
- jcode emitPUSH fi
- if (f != null)
- jcode emitPUSH f
- else
- jcode.emitACONST_NULL()
- jcode emitASTORE strKind
- fi += 1
- }
- }
-
- jcode.emitALOAD_0()
- // push the class
- jcode emitPUSH javaType(c.symbol).asInstanceOf[JReferenceType]
-
- // push the string array of field information
- jcode emitPUSH fieldList.length
- jcode emitANEWARRAY strKind
- push(fieldList)
-
- // push the string array of method information
- jcode emitPUSH methodList.length
- jcode emitANEWARRAY strKind
- push(methodList)
-
- // invoke the superclass constructor, which will do the
- // necessary java reflection and create Method objects.
- jcode.emitINVOKESPECIAL("scala/beans/ScalaBeanInfo", "<init>", conType)
- jcode.emitRETURN()
-
- // write the bean information class file.
- writeClass("BeanInfo ", beanInfoClass.getName(), toByteArray(beanInfoClass), c.symbol)
- }
-
- /** Add the given 'throws' attributes to jmethod */
- def addExceptionsAttribute(jmethod: JMethod, excs: List[AnnotationInfo]) {
- if (excs.isEmpty) return
-
- val cpool = jmethod.getConstantPool
- val buf: ByteBuffer = ByteBuffer.allocate(512)
- var nattr = 0
-
- // put some random value; the actual number is determined at the end
- buf putShort 0xbaba.toShort
-
- for (ThrownException(exc) <- excs.distinct) {
- buf.putShort(
- cpool.addClass(
- javaName(exc)).shortValue)
- nattr += 1
- }
-
- assert(nattr > 0, nattr)
- buf.putShort(0, nattr.toShort)
- addAttribute(jmethod, tpnme.ExceptionsATTR, buf)
- }
-
- /** Whether an annotation should be emitted as a Java annotation
- * .initialize: if 'annot' is read from pickle, atp might be un-initialized
- */
- private def shouldEmitAnnotation(annot: AnnotationInfo) =
- annot.symbol.initialize.isJavaDefined &&
- annot.matches(ClassfileAnnotationClass) &&
- annot.args.isEmpty
-
- private def emitJavaAnnotations(cpool: JConstantPool, buf: ByteBuffer, annotations: List[AnnotationInfo]): Int = {
- def emitArgument(arg: ClassfileAnnotArg): Unit = arg match {
- case LiteralAnnotArg(const) =>
- const.tag match {
- case BooleanTag =>
- buf put 'Z'.toByte
- buf putShort cpool.addInteger(if(const.booleanValue) 1 else 0).toShort
- case ByteTag =>
- buf put 'B'.toByte
- buf putShort cpool.addInteger(const.byteValue).toShort
- case ShortTag =>
- buf put 'S'.toByte
- buf putShort cpool.addInteger(const.shortValue).toShort
- case CharTag =>
- buf put 'C'.toByte
- buf putShort cpool.addInteger(const.charValue).toShort
- case IntTag =>
- buf put 'I'.toByte
- buf putShort cpool.addInteger(const.intValue).toShort
- case LongTag =>
- buf put 'J'.toByte
- buf putShort cpool.addLong(const.longValue).toShort
- case FloatTag =>
- buf put 'F'.toByte
- buf putShort cpool.addFloat(const.floatValue).toShort
- case DoubleTag =>
- buf put 'D'.toByte
- buf putShort cpool.addDouble(const.doubleValue).toShort
- case StringTag =>
- buf put 's'.toByte
- buf putShort cpool.addUtf8(const.stringValue).toShort
- case ClazzTag =>
- buf put 'c'.toByte
- buf putShort cpool.addUtf8(javaType(const.typeValue).getSignature()).toShort
- case EnumTag =>
- buf put 'e'.toByte
- buf putShort cpool.addUtf8(javaType(const.tpe).getSignature()).toShort
- buf putShort cpool.addUtf8(const.symbolValue.name.toString).toShort
- }
-
- case sb@ScalaSigBytes(bytes) if !sb.isLong =>
- buf put 's'.toByte
- buf putShort cpool.addUtf8(sb.encodedBytes).toShort
-
- case sb@ScalaSigBytes(bytes) if sb.isLong =>
- buf put '['.toByte
- val stringCount = (sb.encodedBytes.length / 65534) + 1
- buf putShort stringCount.toShort
- for (i <- 0 until stringCount) {
- buf put 's'.toByte
- val j = i * 65535
- val string = sb.encodedBytes.slice(j, j + 65535)
- buf putShort cpool.addUtf8(string).toShort
- }
-
- case ArrayAnnotArg(args) =>
- buf put '['.toByte
- buf putShort args.length.toShort
- args foreach emitArgument
-
- case NestedAnnotArg(annInfo) =>
- buf put '@'.toByte
- emitAnnotation(annInfo)
- }
-
- def emitAnnotation(annotInfo: AnnotationInfo) {
- val AnnotationInfo(typ, args, assocs) = annotInfo
- val jtype = javaType(typ)
- buf putShort cpool.addUtf8(jtype.getSignature()).toShort
- assert(args.isEmpty, args)
- buf putShort assocs.length.toShort
- for ((name, value) <- assocs) {
- buf putShort cpool.addUtf8(name.toString).toShort
- emitArgument(value)
- }
- }
-
- var nannots = 0
- val pos = buf.position()
-
- // put some random value; the actual number of annotations is determined at the end
- buf putShort 0xbaba.toShort
-
- for (annot <- annotations if shouldEmitAnnotation(annot)) {
- nannots += 1
- emitAnnotation(annot)
- }
-
- // save the number of annotations
- buf.putShort(pos, nannots.toShort)
- nannots
- }
-
- // @M don't generate java generics sigs for (members of) implementation
- // classes, as they are monomorphic (TODO: ok?)
- private def needsGenericSignature(sym: Symbol) = !(
- // PP: This condition used to include sym.hasExpandedName, but this leads
- // to the total loss of generic information if a private member is
- // accessed from a closure: both the field and the accessor were generated
- // without it. This is particularly bad because the availability of
- // generic information could disappear as a consequence of a seemingly
- // unrelated change.
- settings.Ynogenericsig.value
- || sym.isArtifact
- || sym.isLiftedMethod
- || sym.isBridge
- || (sym.ownerChain exists (_.isImplClass))
- )
- def addGenericSignature(jmember: JMember, sym: Symbol, owner: Symbol) {
- if (needsGenericSignature(sym)) {
- val memberTpe = beforeErasure(owner.thisType.memberInfo(sym))
-
- erasure.javaSig(sym, memberTpe) foreach { sig =>
- // This seems useful enough in the general case.
- log(sig)
- if (checkSignatures) {
- val normalizedTpe = beforeErasure(erasure.prepareSigMap(memberTpe))
- val bytecodeTpe = owner.thisType.memberInfo(sym)
- if (!sym.isType && !sym.isConstructor && !(erasure.erasure(sym)(normalizedTpe) =:= bytecodeTpe)) {
- clasz.cunit.warning(sym.pos,
- """|compiler bug: created generic signature for %s in %s that does not conform to its erasure
- |signature: %s
- |original type: %s
- |normalized type: %s
- |erasure type: %s
- |if this is reproducible, please report bug at https://issues.scala-lang.org/
- """.trim.stripMargin.format(sym, sym.owner.skipPackageObject.fullName, sig, memberTpe, normalizedTpe, bytecodeTpe))
- return
- }
- }
- val index = jmember.getConstantPool.addUtf8(sig).toShort
- if (opt.verboseDebug)
- beforeErasure(println("add generic sig "+sym+":"+sym.info+" ==> "+sig+" @ "+index))
-
- val buf = ByteBuffer.allocate(2)
- buf putShort index
- addAttribute(jmember, tpnme.SignatureATTR, buf)
- }
- }
- }
-
- def addAnnotations(jmember: JMember, annotations: List[AnnotationInfo]) {
- if (annotations exists (_ matches definitions.DeprecatedAttr)) {
- val attr = jmember.getContext().JOtherAttribute(
- jmember.getJClass(), jmember, tpnme.DeprecatedATTR.toString,
- new Array[Byte](0), 0)
- jmember addAttribute attr
- }
-
- val toEmit = annotations filter shouldEmitAnnotation
- if (toEmit.isEmpty) return
-
- val buf: ByteBuffer = ByteBuffer.allocate(2048)
- emitJavaAnnotations(jmember.getConstantPool, buf, toEmit)
- addAttribute(jmember, tpnme.RuntimeAnnotationATTR, buf)
- }
-
- def addParamAnnotations(jmethod: JMethod, pannotss: List[List[AnnotationInfo]]) {
- val annotations = pannotss map (_ filter shouldEmitAnnotation)
- if (annotations forall (_.isEmpty)) return
-
- val buf: ByteBuffer = ByteBuffer.allocate(2048)
-
- // number of parameters
- buf.put(annotations.length.toByte)
- for (annots <- annotations)
- emitJavaAnnotations(jmethod.getConstantPool, buf, annots)
-
- addAttribute(jmethod, tpnme.RuntimeParamAnnotationATTR, buf)
- }
-
- def addAttribute(jmember: JMember, name: Name, buf: ByteBuffer) {
- if (buf.position() < 2)
- return
-
- val length = buf.position()
- val arr = buf.array().slice(0, length)
-
- val attr = jmember.getContext().JOtherAttribute(jmember.getJClass(),
- jmember,
- name.toString,
- arr,
- length)
- jmember addAttribute attr
- }
-
- def addInnerClasses(jclass: JClass) {
- /** The outer name for this inner class. Note that it returns null
- * when the inner class should not get an index in the constant pool.
- * That means non-member classes (anonymous). See Section 4.7.5 in the JVMS.
- */
- def outerName(innerSym: Symbol): String = {
- if (innerSym.originalEnclosingMethod != NoSymbol)
- null
- else {
- val outerName = javaName(innerSym.rawowner)
- if (isTopLevelModule(innerSym.rawowner)) "" + nme.stripModuleSuffix(newTermName(outerName))
- else outerName
- }
- }
-
- def innerName(innerSym: Symbol): String =
- if (innerSym.isAnonymousClass || innerSym.isAnonymousFunction)
- null
- else
- innerSym.rawname + innerSym.moduleSuffix
-
- // add inner classes which might not have been referenced yet
- afterErasure {
- for (sym <- List(clasz.symbol, clasz.symbol.linkedClassOfClass); m <- sym.info.decls.map(innerClassSymbolFor) if m.isClass)
- innerClassBuffer += m
- }
-
- val allInners = innerClassBuffer.toList
- if (allInners.nonEmpty) {
- debuglog(clasz.symbol.fullName('.') + " contains " + allInners.size + " inner classes.")
- val innerClassesAttr = jclass.getInnerClasses()
- // sort them so inner classes succeed their enclosing class
- // to satisfy the Eclipse Java compiler
- for (innerSym <- allInners sortBy (_.name.length)) {
- val flags = {
- val staticFlag = if (innerSym.rawowner.hasModuleFlag) ACC_STATIC else 0
- (javaFlags(innerSym) | staticFlag) & INNER_CLASSES_FLAGS
- }
- val jname = javaName(innerSym)
- val oname = outerName(innerSym)
- val iname = innerName(innerSym)
-
- // Mimicking javap inner class output
- debuglog(
- if (oname == null || iname == null) "//class " + jname
- else "//%s=class %s of class %s".format(iname, jname, oname)
- )
-
- innerClassesAttr.addEntry(jname, oname, iname, flags)
- }
- }
- }
-
- def genField(f: IField) {
- debuglog("Adding field: " + f.symbol.fullName)
-
- val jfield = jclass.addNewField(
- javaFieldFlags(f.symbol),
- javaName(f.symbol),
- javaType(f.symbol.tpe)
- )
-
- addGenericSignature(jfield, f.symbol, clasz.symbol)
- addAnnotations(jfield, f.symbol.annotations)
- }
-
- def genMethod(m: IMethod) {
- if (m.symbol.isStaticConstructor || definitions.isGetClass(m.symbol)) return
-
- debuglog("Generating method " + m.symbol.fullName)
- method = m
- endPC.clear
- computeLocalVarsIndex(m)
-
- var resTpe = javaType(m.symbol.tpe.resultType)
- if (m.symbol.isClassConstructor)
- resTpe = JType.VOID
-
- var flags = javaFlags(m.symbol)
- if (jclass.isInterface)
- flags |= ACC_ABSTRACT
-
- if (m.symbol.isStrictFP)
- flags |= ACC_STRICT
-
- // native methods of objects are generated in mirror classes
- if (method.native)
- flags |= ACC_NATIVE
-
- jmethod = jclass.addNewMethod(flags,
- javaName(m.symbol),
- resTpe,
- mkArray(m.params map (p => javaType(p.kind))),
- mkArray(m.params map (p => javaName(p.sym))))
-
- addRemoteException(jmethod, m.symbol)
-
- if (!jmethod.isAbstract() && !method.native) {
- val jcode = jmethod.getCode().asInstanceOf[JExtendedCode]
-
- // add a fake local for debugging purposes
- if (emitVars && isClosureApply(method.symbol)) {
- val outerField = clasz.symbol.info.decl(nme.OUTER_LOCAL)
- if (outerField != NoSymbol) {
- log("Adding fake local to represent outer 'this' for closure " + clasz)
- val _this = new Local(
- method.symbol.newVariable(nme.FAKE_LOCAL_THIS), toTypeKind(outerField.tpe), false)
- m.locals = m.locals ::: List(_this)
- computeLocalVarsIndex(m) // since we added a new local, we need to recompute indexes
-
- jcode.emitALOAD_0()
- jcode.emitGETFIELD(javaName(clasz.symbol),
- javaName(outerField),
- javaType(outerField))
- jcode.emitSTORE(indexOf(_this), javaType(_this.kind))
- }
- }
-
- for (local <- m.locals if ! m.params.contains(local)) {
- debuglog("add local var: " + local)
- jmethod.addNewLocalVariable(javaType(local.kind), javaName(local.sym))
- }
-
- genCode(m)
- if (emitVars)
- genLocalVariableTable(m, jcode)
- }
-
- addGenericSignature(jmethod, m.symbol, clasz.symbol)
- val (excs, others) = m.symbol.annotations partition (_.symbol == ThrowsClass)
- addExceptionsAttribute(jmethod, excs)
- addAnnotations(jmethod, others)
- addParamAnnotations(jmethod, m.params.map(_.sym.annotations))
-
- // check for code size
- try jmethod.freeze()
- catch {
- case e: JCode.CodeSizeTooBigException =>
- clasz.cunit.error(m.symbol.pos, "Code size exceeds JVM limits: %d".format(e.codeSize))
- throw e
- }
- }
-
- /** Adds a @remote annotation, actual use unknown.
- */
- private def addRemoteException(jmethod: JMethod, meth: Symbol) {
- val needsAnnotation = (
- (isRemoteClass || (meth hasAnnotation RemoteAttr) && jmethod.isPublic)
- && !(meth.throwsAnnotations contains RemoteExceptionClass)
- )
- if (needsAnnotation) {
- val c = Constant(RemoteExceptionClass.tpe)
- val arg = Literal(c) setType c.tpe
- meth.addAnnotation(ThrowsClass, arg)
- }
- }
-
- private def isClosureApply(sym: Symbol): Boolean = {
- (sym.name == nme.apply) &&
- sym.owner.isSynthetic &&
- sym.owner.tpe.parents.exists { t =>
- val TypeRef(_, sym, _) = t
- FunctionClass contains sym
- }
- }
-
- def addModuleInstanceField() {
- jclass.addNewField(PublicStaticFinal,
- nme.MODULE_INSTANCE_FIELD.toString,
- jclass.getType())
- }
-
- def addStaticInit(cls: JClass, mopt: Option[IMethod]) {
- val clinitMethod = cls.addNewMethod(PublicStatic,
- "<clinit>",
- JType.VOID,
- JType.EMPTY_ARRAY,
- new Array[String](0))
- val clinit = clinitMethod.getCode().asInstanceOf[JExtendedCode]
-
- mopt match {
- case Some(m) =>
- val oldLastBlock = m.lastBlock
- val lastBlock = m.newBlock()
- oldLastBlock.replaceInstruction(oldLastBlock.length - 1, JUMP(lastBlock))
-
- if (isStaticModule(clasz.symbol)) {
- // call object's private ctor from static ctor
- lastBlock emit NEW(REFERENCE(m.symbol.enclClass))
- lastBlock emit CALL_METHOD(m.symbol.enclClass.primaryConstructor, Static(true))
- }
-
- // add serialVUID code
- serialVUID foreach { value =>
- import Flags._, definitions._
- val fieldName = "serialVersionUID"
- val fieldSymbol = clasz.symbol.newValue(newTermName(fieldName), NoPosition, STATIC | FINAL) setInfo LongClass.tpe
- clasz addField new IField(fieldSymbol)
- lastBlock emit CONSTANT(Constant(value))
- lastBlock emit STORE_FIELD(fieldSymbol, true)
- }
-
- if (isParcelableClass)
- addCreatorCode(BytecodeGenerator.this, lastBlock)
-
- lastBlock emit RETURN(UNIT)
- lastBlock.close
-
- method = m
- jmethod = clinitMethod
- genCode(m)
- case None =>
- legacyStaticInitializer(cls, clinit)
- }
- }
-
- private def legacyStaticInitializer(cls: JClass, clinit: JExtendedCode) {
- if (isStaticModule(clasz.symbol)) {
- clinit emitNEW cls.getName()
- clinit.emitINVOKESPECIAL(cls.getName(),
- JMethod.INSTANCE_CONSTRUCTOR_NAME,
- JMethodType.ARGLESS_VOID_FUNCTION)
- }
-
- serialVUID foreach { value =>
- val fieldName = "serialVersionUID"
- jclass.addNewField(PublicStaticFinal, fieldName, JType.LONG)
- clinit emitPUSH value
- clinit.emitPUSH(value)
- clinit.emitPUTSTATIC(jclass.getName(), fieldName, JType.LONG)
- }
-
- if (isParcelableClass)
- legacyAddCreatorCode(BytecodeGenerator.this, clinit)
-
- clinit.emitRETURN()
- }
-
- /** Add a forwarder for method m */
- def addForwarder(jclass: JClass, module: Symbol, m: Symbol) {
- val moduleName = javaName(module)
- val methodInfo = module.thisType.memberInfo(m)
- val paramJavaTypes = methodInfo.paramTypes map javaType
- val paramNames = 0 until paramJavaTypes.length map ("x_" + _)
- // TODO: evaluate the other flags we might be dropping on the floor here.
- val flags = PublicStatic | (
- if (m.isVarargsMethod) ACC_VARARGS else 0
- )
-
- /** Forwarders must not be marked final, as the JVM will not allow
- * redefinition of a final static method, and we don't know what classes
- * might be subclassing the companion class. See SI-4827.
- */
- val mirrorMethod = jclass.addNewMethod(
- flags,
- javaName(m),
- javaType(methodInfo.resultType),
- mkArray(paramJavaTypes),
- mkArray(paramNames))
- val mirrorCode = mirrorMethod.getCode().asInstanceOf[JExtendedCode]
- mirrorCode.emitGETSTATIC(moduleName,
- nme.MODULE_INSTANCE_FIELD.toString,
- new JObjectType(moduleName))
-
- var i = 0
- var index = 0
- var argTypes = mirrorMethod.getArgumentTypes()
- while (i < argTypes.length) {
- mirrorCode.emitLOAD(index, argTypes(i))
- index += argTypes(i).getSize()
- i += 1
- }
-
- mirrorCode.emitINVOKEVIRTUAL(moduleName, mirrorMethod.getName, javaType(m).asInstanceOf[JMethodType])
- mirrorCode emitRETURN mirrorMethod.getReturnType()
-
- addRemoteException(mirrorMethod, m)
- // only add generic signature if the method is concrete; bug #1745
- if (!m.isDeferred)
- addGenericSignature(mirrorMethod, m, module)
-
- val (throws, others) = m.annotations partition (_.symbol == ThrowsClass)
- addExceptionsAttribute(mirrorMethod, throws)
- addAnnotations(mirrorMethod, others)
- addParamAnnotations(mirrorMethod, m.info.params.map(_.annotations))
- }
-
- /** Add forwarders for all methods defined in `module` that don't conflict
- * with methods in the companion class of `module`. A conflict arises when
- * a method with the same name is defined both in a class and its companion
- * object: method signature is not taken into account.
- */
- def addForwarders(jclass: JClass, moduleClass: Symbol) {
- assert(moduleClass.isModuleClass, moduleClass)
- debuglog("Dumping mirror class for object: " + moduleClass)
-
- val className = jclass.getName
- val linkedClass = moduleClass.companionClass
- val linkedModule = linkedClass.companionSymbol
- lazy val conflictingNames: Set[Name] = {
- linkedClass.info.members collect { case sym if sym.name.isTermName => sym.name } toSet
- }
- debuglog("Potentially conflicting names for forwarders: " + conflictingNames)
-
- for (m <- moduleClass.info.membersBasedOnFlags(ExcludedForwarderFlags, Flags.METHOD)) {
- if (m.isType || m.isDeferred || (m.owner eq ObjectClass) || m.isConstructor)
- debuglog("No forwarder for '%s' from %s to '%s'".format(m, className, moduleClass))
- else if (conflictingNames(m.name))
- log("No forwarder for " + m + " due to conflict with " + linkedClass.info.member(m.name))
- else {
- log("Adding static forwarder for '%s' from %s to '%s'".format(m, className, moduleClass))
- addForwarder(jclass, moduleClass, m)
- }
- }
- }
-
- /** Generate a mirror class for a top-level module. A mirror class is a class
- * containing only static methods that forward to the corresponding method
- * on the MODULE instance of the given Scala object. It will only be
- * generated if there is no companion class: if there is, an attempt will
- * instead be made to add the forwarder methods to the companion class.
- */
- def generateMirrorClass(clasz: Symbol, sourceFile: SourceFile) {
- import JAccessFlags._
- /* We need to save inner classes buffer and create a new one to make sure
- * that we do confuse inner classes of the class we mirror with inner
- * classes of the class we are mirroring. These two sets can be different
- * as seen in this case:
- *
- * class A {
- * class B
- * def b: B = new B
- * }
- * object C extends A
- *
- * Here mirror class of C has a static forwarder for (inherited) method `b`
- * therefore it refers to class `B` and needs InnerClasses entry. However,
- * the real class for `C` (named `C$`) is empty and does not refer to `B`
- * thus does not need InnerClasses entry it.
- *
- * NOTE: This logic has been refactored in GenASM and everything is
- * implemented in a much cleaner way by having two separate buffers.
- */
- val savedInnerClasses = innerClassBuffer
- innerClassBuffer = mutable.LinkedHashSet[Symbol]()
- val moduleName = javaName(clasz) // + "$"
- val mirrorName = moduleName.substring(0, moduleName.length() - 1)
- val mirrorClass = fjbgContext.JClass(ACC_SUPER | ACC_PUBLIC | ACC_FINAL,
- mirrorName,
- JAVA_LANG_OBJECT.getName,
- JClass.NO_INTERFACES,
- "" + sourceFile)
-
- log("Dumping mirror class for '%s'".format(mirrorClass.getName))
- addForwarders(mirrorClass, clasz)
- val ssa = scalaSignatureAddingMarker(mirrorClass, clasz.companionSymbol)
- addAnnotations(mirrorClass, clasz.annotations ++ ssa)
- emitClass(mirrorClass, clasz)
- innerClassBuffer = savedInnerClasses
- }
-
- var linearization: List[BasicBlock] = Nil
- var isModuleInitialized = false
-
- /**
- * @param m ...
- */
- def genCode(m: IMethod) {
- val jcode = jmethod.getCode.asInstanceOf[JExtendedCode]
-
- def makeLabels(bs: List[BasicBlock]) = {
- debuglog("Making labels for: " + method)
-
- mutable.HashMap(bs map (_ -> jcode.newLabel) : _*)
- }
-
- isModuleInitialized = false
-
- linearization = linearizer.linearize(m)
- val labels = makeLabels(linearization)
-
- var nextBlock: BasicBlock = linearization.head
-
- def genBlocks(l: List[BasicBlock]): Unit = l match {
- case Nil => ()
- case x :: Nil => nextBlock = null; genBlock(x)
- case x :: y :: ys => nextBlock = y; genBlock(x); genBlocks(y :: ys)
- }
-
- /** Generate exception handlers for the current method. */
- def genExceptionHandlers() {
-
- /** Return a list of pairs of intervals where the handler is active.
- * The intervals in the list have to be inclusive in the beginning and
- * exclusive in the end: [start, end).
- */
- def ranges(e: ExceptionHandler): List[(Int, Int)] = {
- var covered = e.covered
- var ranges: List[(Int, Int)] = Nil
- var start = -1
- var end = -1
-
- linearization foreach { b =>
- if (! (covered contains b) ) {
- if (start >= 0) { // we're inside a handler range
- end = labels(b).getAnchor()
- ranges ::= ((start, end))
- start = -1
- }
- } else {
- if (start < 0) // we're not inside a handler range
- start = labels(b).getAnchor()
-
- end = endPC(b)
- covered -= b
- }
- }
-
- /* Add the last interval. Note that since the intervals are
- * open-ended to the right, we have to give a number past the actual
- * code!
- */
- if (start >= 0) {
- ranges ::= ((start, jcode.getPC()))
- }
-
- if (!covered.isEmpty)
- debuglog("Some covered blocks were not found in method: " + method +
- " covered: " + covered + " not in " + linearization)
- ranges
- }
-
- for (e <- this.method.exh ; p <- ranges(e).sortBy(_._1)) {
- if (p._1 < p._2) {
- debuglog("Adding exception handler " + e + "at block: " + e.startBlock + " for " + method +
- " from: " + p._1 + " to: " + p._2 + " catching: " + e.cls);
- val cls = if (e.cls == NoSymbol || e.cls == ThrowableClass) null
- else javaName(e.cls)
- jcode.addExceptionHandler(p._1, p._2,
- labels(e.startBlock).getAnchor(),
- cls)
- } else
- log("Empty exception range: " + p)
- }
- }
-
- def isAccessibleFrom(target: Symbol, site: Symbol): Boolean = {
- target.isPublic || target.isProtected && {
- (site.enclClass isSubClass target.enclClass) ||
- (site.enclosingPackage == target.privateWithin)
- }
- }
-
- def genCallMethod(call: CALL_METHOD) {
- val CALL_METHOD(method, style) = call
- val siteSymbol = clasz.symbol
- val hostSymbol = call.hostClass
- val methodOwner = method.owner
- // info calls so that types are up to date; erasure may add lateINTERFACE to traits
- hostSymbol.info ; methodOwner.info
-
- def isInterfaceCall(sym: Symbol) = (
- sym.isInterface && methodOwner != ObjectClass
- || sym.isJavaDefined && sym.isNonBottomSubClass(ClassfileAnnotationClass)
- )
- // whether to reference the type of the receiver or
- // the type of the method owner (if not an interface!)
- val useMethodOwner = (
- style != Dynamic
- || !isInterfaceCall(hostSymbol) && isAccessibleFrom(methodOwner, siteSymbol)
- || hostSymbol.isBottomClass
- )
- val receiver = if (useMethodOwner) methodOwner else hostSymbol
- val jowner = javaName(receiver)
- val jname = javaName(method)
- val jtype = javaType(method).asInstanceOf[JMethodType]
-
- def dbg(invoke: String) {
- debuglog("%s %s %s.%s:%s".format(invoke, receiver.accessString, jowner, jname, jtype))
- }
-
- def initModule() {
- // we initialize the MODULE$ field immediately after the super ctor
- if (isStaticModule(siteSymbol) && !isModuleInitialized &&
- jmethod.getName() == JMethod.INSTANCE_CONSTRUCTOR_NAME &&
- jname == JMethod.INSTANCE_CONSTRUCTOR_NAME) {
- isModuleInitialized = true
- jcode.emitALOAD_0()
- jcode.emitPUTSTATIC(jclass.getName(),
- nme.MODULE_INSTANCE_FIELD.toString,
- jclass.getType())
- }
- }
-
- style match {
- case Static(true) => dbg("invokespecial"); jcode.emitINVOKESPECIAL(jowner, jname, jtype)
- case Static(false) => dbg("invokestatic"); jcode.emitINVOKESTATIC(jowner, jname, jtype)
- case Dynamic if isInterfaceCall(receiver) => dbg("invokinterface"); jcode.emitINVOKEINTERFACE(jowner, jname, jtype)
- case Dynamic => dbg("invokevirtual"); jcode.emitINVOKEVIRTUAL(jowner, jname, jtype)
- case SuperCall(_) =>
- dbg("invokespecial")
- jcode.emitINVOKESPECIAL(jowner, jname, jtype)
- initModule()
- }
- }
-
- def genBlock(b: BasicBlock) {
- labels(b).anchorToNext()
-
- debuglog("Generating code for block: " + b + " at pc: " + labels(b).getAnchor())
- var lastMappedPC = 0
- var lastLineNr = 0
- var crtPC = 0
-
- /** local variables whose scope appears in this block. */
- val varsInBlock: mutable.Set[Local] = new mutable.HashSet
- val lastInstr = b.lastInstruction
-
- for (instr <- b) {
- instr match {
- case THIS(clasz) => jcode.emitALOAD_0()
-
- case CONSTANT(const) => genConstant(jcode, const)
-
- case LOAD_ARRAY_ITEM(kind) =>
- if(kind.isRefOrArrayType) { jcode.emitAALOAD() }
- else {
- (kind: @unchecked) match {
- case UNIT => throw new IllegalArgumentException("invalid type for aload " + kind)
- case BOOL | BYTE => jcode.emitBALOAD()
- case SHORT => jcode.emitSALOAD()
- case CHAR => jcode.emitCALOAD()
- case INT => jcode.emitIALOAD()
- case LONG => jcode.emitLALOAD()
- case FLOAT => jcode.emitFALOAD()
- case DOUBLE => jcode.emitDALOAD()
- }
- }
-
- case LOAD_LOCAL(local) => jcode.emitLOAD(indexOf(local), javaType(local.kind))
-
- case lf @ LOAD_FIELD(field, isStatic) =>
- var owner = javaName(lf.hostClass)
- debuglog("LOAD_FIELD with owner: " + owner +
- " flags: " + Flags.flagsToString(field.owner.flags))
- val fieldJName = javaName(field)
- val fieldJType = javaType(field)
- if (isStatic) jcode.emitGETSTATIC(owner, fieldJName, fieldJType)
- else jcode.emitGETFIELD( owner, fieldJName, fieldJType)
-
- case LOAD_MODULE(module) =>
- // assert(module.isModule, "Expected module: " + module)
- debuglog("generating LOAD_MODULE for: " + module + " flags: " + Flags.flagsToString(module.flags));
- if (clasz.symbol == module.moduleClass && jmethod.getName() != nme.readResolve.toString)
- jcode.emitALOAD_0()
- else
- jcode.emitGETSTATIC(javaName(module) /* + "$" */ ,
- nme.MODULE_INSTANCE_FIELD.toString,
- javaType(module))
-
- case STORE_ARRAY_ITEM(kind) =>
- if(kind.isRefOrArrayType) { jcode.emitAASTORE() }
- else {
- (kind: @unchecked) match {
- case UNIT => throw new IllegalArgumentException("invalid type for astore " + kind)
- case BOOL | BYTE => jcode.emitBASTORE()
- case SHORT => jcode.emitSASTORE()
- case CHAR => jcode.emitCASTORE()
- case INT => jcode.emitIASTORE()
- case LONG => jcode.emitLASTORE()
- case FLOAT => jcode.emitFASTORE()
- case DOUBLE => jcode.emitDASTORE()
- }
- }
-
- case STORE_LOCAL(local) =>
- jcode.emitSTORE(indexOf(local), javaType(local.kind))
-
- case STORE_THIS(_) =>
- // this only works for impl classes because the self parameter comes first
- // in the method signature. If that changes, this code has to be revisited.
- jcode.emitASTORE_0()
-
- case STORE_FIELD(field, isStatic) =>
- val owner = javaName(field.owner)
- val fieldJName = javaName(field)
- val fieldJType = javaType(field)
- if (isStatic) jcode.emitPUTSTATIC(owner, fieldJName, fieldJType)
- else jcode.emitPUTFIELD( owner, fieldJName, fieldJType)
-
- case CALL_PRIMITIVE(primitive) => genPrimitive(primitive, instr.pos)
-
- /** Special handling to access native Array.clone() */
- case call @ CALL_METHOD(definitions.Array_clone, Dynamic) =>
- val target: String = javaType(call.targetTypeKind).getSignature()
- jcode.emitINVOKEVIRTUAL(target, "clone", arrayCloneType)
-
- case call @ CALL_METHOD(method, style) => genCallMethod(call)
-
- case BOX(kind) =>
- val Pair(mname, mtype) = jBoxTo(kind)
- jcode.emitINVOKESTATIC(BoxesRunTime, mname, mtype)
-
- case UNBOX(kind) =>
- val Pair(mname, mtype) = jUnboxTo(kind)
- jcode.emitINVOKESTATIC(BoxesRunTime, mname, mtype)
-
- case NEW(REFERENCE(cls)) =>
- val className = javaName(cls)
- jcode emitNEW className
-
- case CREATE_ARRAY(elem, 1) =>
- if(elem.isRefOrArrayType) { jcode emitANEWARRAY javaType(elem).asInstanceOf[JReferenceType] }
- else { jcode emitNEWARRAY javaType(elem) }
-
- case CREATE_ARRAY(elem, dims) =>
- jcode.emitMULTIANEWARRAY(javaType(ArrayN(elem, dims)).asInstanceOf[JReferenceType], dims)
-
- case IS_INSTANCE(tpe) =>
- tpe match {
- case REFERENCE(cls) => jcode emitINSTANCEOF new JObjectType(javaName(cls))
- case ARRAY(elem) => jcode emitINSTANCEOF new JArrayType(javaType(elem))
- case _ => abort("Unknown reference type in IS_INSTANCE: " + tpe)
- }
-
- case CHECK_CAST(tpe) =>
- tpe match {
- case REFERENCE(cls) => if (cls != ObjectClass) { jcode emitCHECKCAST new JObjectType(javaName(cls)) } // No need to checkcast for Objects
- case ARRAY(elem) => jcode emitCHECKCAST new JArrayType(javaType(elem))
- case _ => abort("Unknown reference type in IS_INSTANCE: " + tpe)
- }
-
- case SWITCH(tags, branches) =>
- val tagArray = new Array[Array[Int]](tags.length)
- var caze = tags
- var i = 0
-
- while (i < tagArray.length) {
- tagArray(i) = new Array[Int](caze.head.length)
- caze.head.copyToArray(tagArray(i), 0)
- i += 1
- caze = caze.tail
- }
- val branchArray = jcode.newLabels(tagArray.length)
- i = 0
- while (i < branchArray.length) {
- branchArray(i) = labels(branches(i))
- i += 1
- }
- debuglog("Emitting SWITCH:\ntags: " + tags + "\nbranches: " + branches)
- jcode.emitSWITCH(tagArray,
- branchArray,
- labels(branches.last),
- MIN_SWITCH_DENSITY)
- ()
-
- case JUMP(whereto) =>
- if (nextBlock != whereto)
- jcode.emitGOTO_maybe_W(labels(whereto), false) // default to short jumps
-
- case CJUMP(success, failure, cond, kind) =>
- if(kind.isIntSizedType) { // BOOL, BYTE, CHAR, SHORT, or INT
- if (nextBlock == success) {
- jcode.emitIF_ICMP(conds(cond.negate()), labels(failure))
- // .. and fall through to success label
- } else {
- jcode.emitIF_ICMP(conds(cond), labels(success))
- if (nextBlock != failure)
- jcode.emitGOTO_maybe_W(labels(failure), false)
- }
- } else if(kind.isRefOrArrayType) { // REFERENCE(_) | ARRAY(_)
- if (nextBlock == success) {
- jcode.emitIF_ACMP(conds(cond.negate()), labels(failure))
- // .. and fall through to success label
- } else {
- jcode.emitIF_ACMP(conds(cond), labels(success))
- if (nextBlock != failure)
- jcode.emitGOTO_maybe_W(labels(failure), false)
- }
- } else {
- (kind: @unchecked) match {
- case LONG => jcode.emitLCMP()
- case FLOAT =>
- if (cond == LT || cond == LE) jcode.emitFCMPG()
- else jcode.emitFCMPL()
- case DOUBLE =>
- if (cond == LT || cond == LE) jcode.emitDCMPG()
- else jcode.emitDCMPL()
- }
- if (nextBlock == success) {
- jcode.emitIF(conds(cond.negate()), labels(failure))
- // .. and fall through to success label
- } else {
- jcode.emitIF(conds(cond), labels(success));
- if (nextBlock != failure)
- jcode.emitGOTO_maybe_W(labels(failure), false)
- }
- }
-
- case CZJUMP(success, failure, cond, kind) =>
- if(kind.isIntSizedType) { // BOOL, BYTE, CHAR, SHORT, or INT
- if (nextBlock == success) {
- jcode.emitIF(conds(cond.negate()), labels(failure))
- } else {
- jcode.emitIF(conds(cond), labels(success))
- if (nextBlock != failure)
- jcode.emitGOTO_maybe_W(labels(failure), false)
- }
- } else if(kind.isRefOrArrayType) { // REFERENCE(_) | ARRAY(_)
- val Success = success
- val Failure = failure
- (cond, nextBlock) match {
- case (EQ, Success) => jcode emitIFNONNULL labels(failure)
- case (NE, Failure) => jcode emitIFNONNULL labels(success)
- case (EQ, Failure) => jcode emitIFNULL labels(success)
- case (NE, Success) => jcode emitIFNULL labels(failure)
- case (EQ, _) =>
- jcode emitIFNULL labels(success)
- jcode.emitGOTO_maybe_W(labels(failure), false)
- case (NE, _) =>
- jcode emitIFNONNULL labels(success)
- jcode.emitGOTO_maybe_W(labels(failure), false)
- case _ =>
- }
- } else {
- (kind: @unchecked) match {
- case LONG =>
- jcode.emitLCONST_0()
- jcode.emitLCMP()
- case FLOAT =>
- jcode.emitFCONST_0()
- if (cond == LT || cond == LE) jcode.emitFCMPG()
- else jcode.emitFCMPL()
- case DOUBLE =>
- jcode.emitDCONST_0()
- if (cond == LT || cond == LE) jcode.emitDCMPG()
- else jcode.emitDCMPL()
- }
- if (nextBlock == success) {
- jcode.emitIF(conds(cond.negate()), labels(failure))
- } else {
- jcode.emitIF(conds(cond), labels(success))
- if (nextBlock != failure)
- jcode.emitGOTO_maybe_W(labels(failure), false)
- }
- }
-
- case RETURN(kind) => jcode emitRETURN javaType(kind)
-
- case THROW(_) => jcode.emitATHROW()
-
- case DROP(kind) =>
- if(kind.isWideType) jcode.emitPOP2()
- else jcode.emitPOP()
-
- case DUP(kind) =>
- if(kind.isWideType) jcode.emitDUP2()
- else jcode.emitDUP()
-
- case MONITOR_ENTER() => jcode.emitMONITORENTER()
-
- case MONITOR_EXIT() => jcode.emitMONITOREXIT()
-
- case SCOPE_ENTER(lv) =>
- varsInBlock += lv
- lv.start = jcode.getPC()
-
- case SCOPE_EXIT(lv) =>
- if (varsInBlock(lv)) {
- lv.ranges = (lv.start, jcode.getPC()) :: lv.ranges
- varsInBlock -= lv
- }
- else if (b.varsInScope(lv)) {
- lv.ranges = (labels(b).getAnchor(), jcode.getPC()) :: lv.ranges
- b.varsInScope -= lv
- }
- else dumpMethodAndAbort(method, "Illegal local var nesting")
-
- case LOAD_EXCEPTION(_) =>
- ()
- }
-
- crtPC = jcode.getPC()
-
- // assert(instr.pos.source.isEmpty || instr.pos.source.get == (clasz.cunit.source), "sources don't match")
- // val crtLine = instr.pos.line.get(lastLineNr);
-
- val crtLine = try {
- if (instr.pos == NoPosition) lastLineNr else (instr.pos).line // check NoPosition to avoid costly exception
- } catch {
- case _: UnsupportedOperationException =>
- log("Warning: wrong position in: " + method)
- lastLineNr
- }
-
- if (instr eq lastInstr) { endPC(b) = jcode.getPC() }
-
- //System.err.println("CRTLINE: " + instr.pos + " " +
- // /* (if (instr.pos < clasz.cunit.source.content.length) clasz.cunit.source.content(instr.pos) else '*') + */ " " + crtLine);
-
- if (crtPC > lastMappedPC) {
- jcode.completeLineNumber(lastMappedPC, crtPC, crtLine)
- lastMappedPC = crtPC
- lastLineNr = crtLine
- }
- }
-
- // local vars that survived this basic block
- for (lv <- varsInBlock) {
- lv.ranges = (lv.start, jcode.getPC()) :: lv.ranges
- }
- for (lv <- b.varsInScope) {
- lv.ranges = (labels(b).getAnchor(), jcode.getPC()) :: lv.ranges
- }
- }
-
-
- /**
- * @param primitive ...
- * @param pos ...
- */
- def genPrimitive(primitive: Primitive, pos: Position) {
- primitive match {
- case Negation(kind) =>
- if(kind.isIntSizedType) { jcode.emitINEG() }
- else {
- kind match {
- case LONG => jcode.emitLNEG()
- case FLOAT => jcode.emitFNEG()
- case DOUBLE => jcode.emitDNEG()
- case _ => abort("Impossible to negate a " + kind)
- }
- }
-
- case Arithmetic(op, kind) =>
- op match {
- case ADD =>
- if(kind.isIntSizedType) { jcode.emitIADD() }
- else {
- (kind: @unchecked) match {
- case LONG => jcode.emitLADD()
- case FLOAT => jcode.emitFADD()
- case DOUBLE => jcode.emitDADD()
- }
- }
-
- case SUB =>
- if(kind.isIntSizedType) { jcode.emitISUB() }
- else {
- (kind: @unchecked) match {
- case LONG => jcode.emitLSUB()
- case FLOAT => jcode.emitFSUB()
- case DOUBLE => jcode.emitDSUB()
- }
- }
-
- case MUL =>
- if(kind.isIntSizedType) { jcode.emitIMUL() }
- else {
- (kind: @unchecked) match {
- case LONG => jcode.emitLMUL()
- case FLOAT => jcode.emitFMUL()
- case DOUBLE => jcode.emitDMUL()
- }
- }
-
- case DIV =>
- if(kind.isIntSizedType) { jcode.emitIDIV() }
- else {
- (kind: @unchecked) match {
- case LONG => jcode.emitLDIV()
- case FLOAT => jcode.emitFDIV()
- case DOUBLE => jcode.emitDDIV()
- }
- }
-
- case REM =>
- if(kind.isIntSizedType) { jcode.emitIREM() }
- else {
- (kind: @unchecked) match {
- case LONG => jcode.emitLREM()
- case FLOAT => jcode.emitFREM()
- case DOUBLE => jcode.emitDREM()
- }
- }
-
- case NOT =>
- if(kind.isIntSizedType) {
- jcode.emitPUSH(-1)
- jcode.emitIXOR()
- } else if(kind == LONG) {
- jcode.emitPUSH(-1l)
- jcode.emitLXOR()
- } else {
- abort("Impossible to negate an " + kind)
- }
-
- case _ =>
- abort("Unknown arithmetic primitive " + primitive)
- }
-
- case Logical(op, kind) => ((op, kind): @unchecked) match {
- case (AND, LONG) => jcode.emitLAND()
- case (AND, INT) => jcode.emitIAND()
- case (AND, _) =>
- jcode.emitIAND()
- if (kind != BOOL)
- jcode.emitT2T(javaType(INT), javaType(kind));
-
- case (OR, LONG) => jcode.emitLOR()
- case (OR, INT) => jcode.emitIOR()
- case (OR, _) =>
- jcode.emitIOR()
- if (kind != BOOL)
- jcode.emitT2T(javaType(INT), javaType(kind));
-
- case (XOR, LONG) => jcode.emitLXOR()
- case (XOR, INT) => jcode.emitIXOR()
- case (XOR, _) =>
- jcode.emitIXOR()
- if (kind != BOOL)
- jcode.emitT2T(javaType(INT), javaType(kind));
- }
-
- case Shift(op, kind) => ((op, kind): @unchecked) match {
- case (LSL, LONG) => jcode.emitLSHL()
- case (LSL, INT) => jcode.emitISHL()
- case (LSL, _) =>
- jcode.emitISHL()
- jcode.emitT2T(javaType(INT), javaType(kind))
-
- case (ASR, LONG) => jcode.emitLSHR()
- case (ASR, INT) => jcode.emitISHR()
- case (ASR, _) =>
- jcode.emitISHR()
- jcode.emitT2T(javaType(INT), javaType(kind))
-
- case (LSR, LONG) => jcode.emitLUSHR()
- case (LSR, INT) => jcode.emitIUSHR()
- case (LSR, _) =>
- jcode.emitIUSHR()
- jcode.emitT2T(javaType(INT), javaType(kind))
- }
-
- case Comparison(op, kind) => ((op, kind): @unchecked) match {
- case (CMP, LONG) => jcode.emitLCMP()
- case (CMPL, FLOAT) => jcode.emitFCMPL()
- case (CMPG, FLOAT) => jcode.emitFCMPG()
- case (CMPL, DOUBLE) => jcode.emitDCMPL()
- case (CMPG, DOUBLE) => jcode.emitDCMPL()
- }
-
- case Conversion(src, dst) =>
- debuglog("Converting from: " + src + " to: " + dst)
- if (dst == BOOL) {
- println("Illegal conversion at: " + clasz + " at: " + pos.source + ":" + pos.line)
- } else
- jcode.emitT2T(javaType(src), javaType(dst))
-
- case ArrayLength(_) =>
- jcode.emitARRAYLENGTH()
-
- case StartConcat =>
- jcode emitNEW StringBuilderClassName
- jcode.emitDUP()
- jcode.emitINVOKESPECIAL(StringBuilderClassName,
- JMethod.INSTANCE_CONSTRUCTOR_NAME,
- JMethodType.ARGLESS_VOID_FUNCTION)
-
- case StringConcat(el) =>
- val jtype = el match {
- case REFERENCE(_) | ARRAY(_) => JAVA_LANG_OBJECT
- case _ => javaType(el)
- }
- jcode.emitINVOKEVIRTUAL(StringBuilderClassName,
- "append",
- new JMethodType(StringBuilderType,
- Array(jtype)))
- case EndConcat =>
- jcode.emitINVOKEVIRTUAL(StringBuilderClassName,
- "toString",
- toStringType)
-
- case _ =>
- abort("Unimplemented primitive " + primitive)
- }
- }
-
- // genCode starts here
- genBlocks(linearization)
-
- if (this.method.exh != Nil)
- genExceptionHandlers;
- }
-
-
- /** Emit a Local variable table for debugging purposes.
- * Synthetic locals are skipped. All variables are method-scoped.
- */
- private def genLocalVariableTable(m: IMethod, jcode: JCode) {
- val vars = m.locals filterNot (_.sym.isSynthetic)
- if (vars.isEmpty) return
-
- val pool = jclass.getConstantPool
- val pc = jcode.getPC()
- var anonCounter = 0
- var entries = 0
- vars.foreach { lv =>
- lv.ranges = mergeEntries(lv.ranges.reverse);
- entries += lv.ranges.length
- }
- if (!jmethod.isStatic()) entries += 1
-
- val lvTab = ByteBuffer.allocate(2 + 10 * entries)
- def emitEntry(name: String, signature: String, idx: Short, start: Short, end: Short) {
- lvTab putShort start
- lvTab putShort end
- lvTab putShort pool.addUtf8(name).toShort
- lvTab putShort pool.addUtf8(signature).toShort
- lvTab putShort idx
- }
-
- lvTab.putShort(entries.toShort)
-
- if (!jmethod.isStatic()) {
- emitEntry("this", jclass.getType().getSignature(), 0, 0.toShort, pc.toShort)
- }
-
- for (lv <- vars) {
- val name = if (javaName(lv.sym) eq null) {
- anonCounter += 1
- "<anon" + anonCounter + ">"
- } else javaName(lv.sym)
-
- val index = indexOf(lv).toShort
- val tpe = javaType(lv.kind).getSignature()
- for ((start, end) <- lv.ranges) {
- emitEntry(name, tpe, index, start.toShort, (end - start).toShort)
- }
- }
- val attr =
- fjbgContext.JOtherAttribute(jclass,
- jcode,
- tpnme.LocalVariableTableATTR.toString,
- lvTab.array())
- jcode addAttribute attr
- }
-
-
- /** For each basic block, the first PC address following it. */
- val endPC = new mutable.HashMap[BasicBlock, Int]
-
- ////////////////////// local vars ///////////////////////
-
- def sizeOf(sym: Symbol): Int = sizeOf(toTypeKind(sym.tpe))
-
- def sizeOf(k: TypeKind): Int = if(k.isWideType) 2 else 1
-
- def indexOf(m: IMethod, sym: Symbol): Int = {
- val Some(local) = m lookupLocal sym
- indexOf(local)
- }
-
- def indexOf(local: Local): Int = {
- assert(local.index >= 0, "Invalid index for: " + local + "{" + local.## + "}: ")
- local.index
- }
-
- /**
- * Compute the indexes of each local variable of the given
- * method. *Does not assume the parameters come first!*
- */
- def computeLocalVarsIndex(m: IMethod) {
- var idx = if (m.symbol.isStaticMember) 0 else 1;
-
- for (l <- m.params) {
- debuglog("Index value for " + l + "{" + l.## + "}: " + idx)
- l.index = idx
- idx += sizeOf(l.kind)
- }
-
- for (l <- m.locals if !(m.params contains l)) {
- debuglog("Index value for " + l + "{" + l.## + "}: " + idx)
- l.index = idx
- idx += sizeOf(l.kind)
- }
- }
-
- ////////////////////// Utilities ////////////////////////
-
- /** Merge adjacent ranges. */
- private def mergeEntries(ranges: List[(Int, Int)]): List[(Int, Int)] =
- (ranges.foldLeft(Nil: List[(Int, Int)]) { (collapsed: List[(Int, Int)], p: (Int, Int)) => (collapsed, p) match {
- case (Nil, _) => List(p)
- case ((s1, e1) :: rest, (s2, e2)) if (e1 == s2) => (s1, e2) :: rest
- case _ => p :: collapsed
- }}).reverse
- }
-
- private def mkFlags(args: Int*) = args.foldLeft(0)(_ | _)
-
- /**
- * Return the Java modifiers for the given symbol.
- * Java modifiers for classes:
- * - public, abstract, final, strictfp (not used)
- * for interfaces:
- * - the same as for classes, without 'final'
- * for fields:
- * - public, private (*)
- * - static, final
- * for methods:
- * - the same as for fields, plus:
- * - abstract, synchronized (not used), strictfp (not used), native (not used)
- *
- * (*) protected cannot be used, since inner classes 'see' protected members,
- * and they would fail verification after lifted.
- */
- def javaFlags(sym: Symbol): Int = {
- // constructors of module classes should be private
- // PP: why are they only being marked private at this stage and not earlier?
- val privateFlag =
- sym.isPrivate || (sym.isPrimaryConstructor && isTopLevelModule(sym.owner))
-
- // Final: the only fields which can receive ACC_FINAL are eager vals.
- // Neither vars nor lazy vals can, because:
- //
- // Source: http://docs.oracle.com/javase/specs/jls/se7/html/jls-17.html#jls-17.5.3
- // "Another problem is that the specification allows aggressive
- // optimization of final fields. Within a thread, it is permissible to
- // reorder reads of a final field with those modifications of a final
- // field that do not take place in the constructor."
- //
- // A var or lazy val which is marked final still has meaning to the
- // scala compiler. The word final is heavily overloaded unfortunately;
- // for us it means "not overridable". At present you can't override
- // vars regardless; this may change.
- //
- // The logic does not check .isFinal (which checks flags for the FINAL flag,
- // and includes symbols marked lateFINAL) instead inspecting rawflags so
- // we can exclude lateFINAL. Such symbols are eligible for inlining, but to
- // avoid breaking proxy software which depends on subclassing, we do not
- // emit ACC_FINAL.
- // Nested objects won't receive ACC_FINAL in order to allow for their overriding.
-
- val finalFlag = (
- (((sym.rawflags & Flags.FINAL) != 0) || isTopLevelModule(sym))
- && !sym.enclClass.isInterface
- && !sym.isClassConstructor
- && !sym.isMutable // lazy vals and vars both
- )
-
- // Primitives are "abstract final" to prohibit instantiation
- // without having to provide any implementations, but that is an
- // illegal combination of modifiers at the bytecode level so
- // suppress final if abstract if present.
- mkFlags(
- if (privateFlag) ACC_PRIVATE else ACC_PUBLIC,
- if (sym.isDeferred || sym.hasAbstractFlag) ACC_ABSTRACT else 0,
- if (sym.isInterface) ACC_INTERFACE else 0,
- if (finalFlag && !sym.hasAbstractFlag) ACC_FINAL else 0,
- if (sym.isStaticMember) ACC_STATIC else 0,
- if (sym.isBridge) ACC_BRIDGE | ACC_SYNTHETIC else 0,
- if (sym.isArtifact) ACC_SYNTHETIC else 0,
- if (sym.isClass && !sym.isInterface) ACC_SUPER else 0,
- if (sym.isVarargsMethod) ACC_VARARGS else 0,
- if (sym.hasFlag(Flags.SYNCHRONIZED)) JAVA_ACC_SYNCHRONIZED else 0
- )
- }
- def javaFieldFlags(sym: Symbol) = (
- javaFlags(sym) | mkFlags(
- if (sym hasAnnotation TransientAttr) ACC_TRANSIENT else 0,
- if (sym hasAnnotation VolatileAttr) ACC_VOLATILE else 0,
- if (sym.isMutable) 0 else ACC_FINAL
- )
- )
-
- def isTopLevelModule(sym: Symbol): Boolean =
- afterPickler { sym.isModuleClass && !sym.isImplClass && !sym.isNestedClass }
-
- def isStaticModule(sym: Symbol): Boolean = {
- sym.isModuleClass && !sym.isImplClass && !sym.isLifted
- }
-
-}
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenJVMASM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenJVMASM.scala
index 49c0fa2757..f0f91e7d1a 100644
--- a/src/compiler/scala/tools/nsc/backend/jvm/GenJVMASM.scala
+++ b/src/compiler/scala/tools/nsc/backend/jvm/GenJVMASM.scala
@@ -20,7 +20,7 @@ trait GenJVMASM {
import definitions._
protected def outputDirectory(sym: Symbol): AbstractFile =
- settings.outputDirs outputDirFor beforeFlatten(sym.sourceFile)
+ settings.outputDirs outputDirFor enteringFlatten(sym.sourceFile)
protected def getFile(base: AbstractFile, clsName: String, suffix: String): AbstractFile = {
var dir = base
@@ -65,7 +65,7 @@ trait GenJVMASM {
// At this point it's a module with a main-looking method, so either succeed or warn that it isn't.
hasApproximate && {
// Before erasure so we can identify generic mains.
- beforeErasure {
+ enteringErasure {
val companion = sym.linkedClassOfClass
val companionMain = companion.tpe.member(nme.main)
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenJVMUtil.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenJVMUtil.scala
deleted file mode 100644
index e002a614bd..0000000000
--- a/src/compiler/scala/tools/nsc/backend/jvm/GenJVMUtil.scala
+++ /dev/null
@@ -1,142 +0,0 @@
-/* NSC -- new Scala compiler
- * Copyright 2005-2013 LAMP/EPFL
- * @author Iulian Dragos
- */
-
-package scala.tools.nsc
-package backend.jvm
-
-import scala.collection.{ mutable, immutable }
-import ch.epfl.lamp.fjbg._
-
-trait GenJVMUtil {
- self: GenJVM =>
-
- import global._
- import icodes._
- import icodes.opcodes._
- import definitions._
-
- /** Map from type kinds to the Java reference types. It is used for
- * loading class constants. @see Predef.classOf.
- */
- val classLiteral = immutable.Map[TypeKind, JObjectType](
- UNIT -> new JObjectType("java.lang.Void"),
- BOOL -> new JObjectType("java.lang.Boolean"),
- BYTE -> new JObjectType("java.lang.Byte"),
- SHORT -> new JObjectType("java.lang.Short"),
- CHAR -> new JObjectType("java.lang.Character"),
- INT -> new JObjectType("java.lang.Integer"),
- LONG -> new JObjectType("java.lang.Long"),
- FLOAT -> new JObjectType("java.lang.Float"),
- DOUBLE -> new JObjectType("java.lang.Double")
- )
-
- // Don't put this in per run caches.
- private val javaNameCache = new mutable.WeakHashMap[Symbol, Name]() ++= List(
- NothingClass -> binarynme.RuntimeNothing,
- RuntimeNothingClass -> binarynme.RuntimeNothing,
- NullClass -> binarynme.RuntimeNull,
- RuntimeNullClass -> binarynme.RuntimeNull
- )
-
- /** This trait may be used by tools who need access to
- * utility methods like javaName and javaType. (for instance,
- * the Eclipse plugin uses it).
- */
- trait BytecodeUtil {
-
- val conds = immutable.Map[TestOp, Int](
- EQ -> JExtendedCode.COND_EQ,
- NE -> JExtendedCode.COND_NE,
- LT -> JExtendedCode.COND_LT,
- GT -> JExtendedCode.COND_GT,
- LE -> JExtendedCode.COND_LE,
- GE -> JExtendedCode.COND_GE
- )
-
- /** Specialized array conversion to prevent calling
- * java.lang.reflect.Array.newInstance via TraversableOnce.toArray
- */
-
- def mkArray(xs: Traversable[JType]): Array[JType] = { val a = new Array[JType](xs.size); xs.copyToArray(a); a }
- def mkArray(xs: Traversable[String]): Array[String] = { val a = new Array[String](xs.size); xs.copyToArray(a); a }
-
- /** Return the a name of this symbol that can be used on the Java
- * platform. It removes spaces from names.
- *
- * Special handling:
- * scala.Nothing erases to scala.runtime.Nothing$
- * scala.Null erases to scala.runtime.Null$
- *
- * This is needed because they are not real classes, and they mean
- * 'abrupt termination upon evaluation of that expression' or null respectively.
- * This handling is done already in GenICode, but here we need to remove
- * references from method signatures to these types, because such classes can
- * not exist in the classpath: the type checker will be very confused.
- */
- def javaName(sym: Symbol): String =
- javaNameCache.getOrElseUpdate(sym, {
- if (sym.isClass || (sym.isModule && !sym.isMethod))
- sym.javaBinaryName
- else
- sym.javaSimpleName
- }).toString
-
- def javaType(t: TypeKind): JType = (t: @unchecked) match {
- case UNIT => JType.VOID
- case BOOL => JType.BOOLEAN
- case BYTE => JType.BYTE
- case SHORT => JType.SHORT
- case CHAR => JType.CHAR
- case INT => JType.INT
- case LONG => JType.LONG
- case FLOAT => JType.FLOAT
- case DOUBLE => JType.DOUBLE
- case REFERENCE(cls) => new JObjectType(javaName(cls))
- case ARRAY(elem) => new JArrayType(javaType(elem))
- }
-
- def javaType(t: Type): JType = javaType(toTypeKind(t))
-
- def javaType(s: Symbol): JType =
- if (s.isMethod)
- new JMethodType(
- if (s.isClassConstructor) JType.VOID else javaType(s.tpe.resultType),
- mkArray(s.tpe.paramTypes map javaType)
- )
- else
- javaType(s.tpe)
-
- protected def genConstant(jcode: JExtendedCode, const: Constant) {
- const.tag match {
- case UnitTag => ()
- case BooleanTag => jcode emitPUSH const.booleanValue
- case ByteTag => jcode emitPUSH const.byteValue
- case ShortTag => jcode emitPUSH const.shortValue
- case CharTag => jcode emitPUSH const.charValue
- case IntTag => jcode emitPUSH const.intValue
- case LongTag => jcode emitPUSH const.longValue
- case FloatTag => jcode emitPUSH const.floatValue
- case DoubleTag => jcode emitPUSH const.doubleValue
- case StringTag => jcode emitPUSH const.stringValue
- case NullTag => jcode.emitACONST_NULL()
- case ClazzTag =>
- val kind = toTypeKind(const.typeValue)
- val toPush =
- if (kind.isValueType) classLiteral(kind)
- else javaType(kind).asInstanceOf[JReferenceType]
-
- jcode emitPUSH toPush
-
- case EnumTag =>
- val sym = const.symbolValue
- jcode.emitGETSTATIC(javaName(sym.owner),
- javaName(sym),
- javaType(sym.tpe.underlying))
- case _ =>
- abort("Unknown constant value: " + const)
- }
- }
- }
-}
diff --git a/src/compiler/scala/tools/nsc/backend/msil/GenMSIL.scala b/src/compiler/scala/tools/nsc/backend/msil/GenMSIL.scala
deleted file mode 100644
index aaffaa84d8..0000000000
--- a/src/compiler/scala/tools/nsc/backend/msil/GenMSIL.scala
+++ /dev/null
@@ -1,2358 +0,0 @@
-/* NSC -- new scala compiler
- * Copyright 2005-2013 LAMP/EPFL
- * @author Nikolay Mihaylov
- */
-
-
-package scala.tools.nsc
-package backend.msil
-
-import java.io.{File, IOException}
-import java.nio.{ByteBuffer, ByteOrder}
-import scala.collection.{ mutable, immutable }
-import scala.tools.nsc.symtab._
-
-import ch.epfl.lamp.compiler.msil.{Type => MsilType, _}
-import ch.epfl.lamp.compiler.msil.emit._
-import ch.epfl.lamp.compiler.msil.util.PECustomMod
-import scala.language.postfixOps
-
-abstract class GenMSIL extends SubComponent {
- import global._
- import loaders.clrTypes
- import clrTypes.{types, constructors, methods, fields}
- import icodes._
- import icodes.opcodes._
-
- val x = loaders
-
- /** Create a new phase */
- override def newPhase(p: Phase) = new MsilPhase(p)
-
- val phaseName = "msil"
- /** MSIL code generation phase
- */
- class MsilPhase(prev: Phase) extends GlobalPhase(prev) {
- def name = phaseName
- override def newFlags = phaseNewFlags
-
- override def erasedTypes = true
-
- override def run() {
- if (settings.debug.value) inform("[running phase " + name + " on icode]")
-
- val codeGenerator = new BytecodeGenerator
-
- //classes is ICodes.classes, a HashMap[Symbol, IClass]
- classes.values foreach codeGenerator.findEntryPoint
- if( opt.showClass.isDefined && (codeGenerator.entryPoint == null) ) { // TODO introduce dedicated setting instead
- val entryclass = opt.showClass.get.toString
- warning("Couldn't find entry class " + entryclass)
- }
-
- codeGenerator.initAssembly
-
- val classesSorted = classes.values.toList.sortBy(c => c.symbol.id) // simplifies comparing cross-compiler vs. .exe output
- classesSorted foreach codeGenerator.createTypeBuilder
- classesSorted foreach codeGenerator.createClassMembers
-
- try {
- classesSorted foreach codeGenerator.genClass
- } finally {
- codeGenerator.writeAssembly
- }
- }
-
- override def apply(unit: CompilationUnit) {
- abort("MSIL works on icode classes, not on compilation units!")
- }
- }
-
- /**
- * MSIL bytecode generator.
- *
- */
- class BytecodeGenerator {
-
- val MODULE_INSTANCE_NAME = "MODULE$"
-
- import clrTypes.{VOID => MVOID, BOOLEAN => MBOOL, BYTE => MBYTE, SHORT => MSHORT,
- CHAR => MCHAR, INT => MINT, LONG => MLONG, FLOAT => MFLOAT,
- DOUBLE => MDOUBLE, OBJECT => MOBJECT, STRING => MSTRING,
- STRING_ARRAY => MSTRING_ARRAY,
- SYMTAB_CONSTR => SYMTAB_ATTRIBUTE_CONSTRUCTOR,
- SYMTAB_DEFAULT_CONSTR => SYMTAB_ATTRIBUTE_EMPTY_CONSTRUCTOR}
-
- val EXCEPTION = clrTypes.getType("System.Exception")
- val MBYTE_ARRAY = clrTypes.mkArrayType(MBYTE)
-
- val ICLONEABLE = clrTypes.getType("System.ICloneable")
- val MEMBERWISE_CLONE = MOBJECT.GetMethod("MemberwiseClone", MsilType.EmptyTypes)
-
- val MMONITOR = clrTypes.getType("System.Threading.Monitor")
- val MMONITOR_ENTER = MMONITOR.GetMethod("Enter", Array(MOBJECT))
- val MMONITOR_EXIT = MMONITOR.GetMethod("Exit", Array(MOBJECT))
-
- val MSTRING_BUILDER = clrTypes.getType("System.Text.StringBuilder")
- val MSTRING_BUILDER_CONSTR = MSTRING_BUILDER.GetConstructor(MsilType.EmptyTypes)
- val MSTRING_BUILDER_TOSTRING = MSTRING_BUILDER.GetMethod("ToString",
- MsilType.EmptyTypes)
-
- val TYPE_FROM_HANDLE =
- clrTypes.getType("System.Type").GetMethod("GetTypeFromHandle", Array(clrTypes.getType("System.RuntimeTypeHandle")))
-
- val INT_PTR = clrTypes.getType("System.IntPtr")
-
- val JOBJECT = definitions.ObjectClass
- val JSTRING = definitions.StringClass
-
- val SystemConvert = clrTypes.getType("System.Convert")
-
- val objParam = Array(MOBJECT)
-
- val toBool: MethodInfo = SystemConvert.GetMethod("ToBoolean", objParam) // see comment in emitUnbox
- val toSByte: MethodInfo = SystemConvert.GetMethod("ToSByte", objParam)
- val toShort: MethodInfo = SystemConvert.GetMethod("ToInt16", objParam)
- val toChar: MethodInfo = SystemConvert.GetMethod("ToChar", objParam)
- val toInt: MethodInfo = SystemConvert.GetMethod("ToInt32", objParam)
- val toLong: MethodInfo = SystemConvert.GetMethod("ToInt64", objParam)
- val toFloat: MethodInfo = SystemConvert.GetMethod("ToSingle", objParam)
- val toDouble: MethodInfo = SystemConvert.GetMethod("ToDouble", objParam)
-
- //val boxedUnit: FieldInfo = msilType(definitions.BoxedUnitModule.info).GetField("UNIT")
- val boxedUnit: FieldInfo = fields(definitions.BoxedUnit_UNIT)
-
- // Scala attributes
- // symtab.Definitions -> object (singleton..)
- val SerializableAttr = definitions.SerializableAttr.tpe
- val CloneableAttr = definitions.CloneableAttr.tpe
- val TransientAtt = definitions.TransientAttr.tpe
- // remoting: the architectures are too different, no mapping (no portable code
- // possible)
-
- // java instance methods that are mapped to static methods in .net
- // these will need to be called with OpCodes.Call (not Callvirt)
- val dynToStatMapped = mutable.HashSet[Symbol]()
-
- initMappings()
-
- /** Create the mappings between java and .net classes and methods */
- private def initMappings() {
- mapType(definitions.AnyClass, MOBJECT)
- mapType(definitions.AnyRefClass, MOBJECT)
- //mapType(definitions.NullClass, clrTypes.getType("scala.AllRef$"))
- //mapType(definitions.NothingClass, clrTypes.getType("scala.All$"))
- // FIXME: for some reason the upper two lines map to null
- mapType(definitions.NullClass, EXCEPTION)
- mapType(definitions.NothingClass, EXCEPTION)
-
- mapType(definitions.BooleanClass, MBOOL)
- mapType(definitions.ByteClass, MBYTE)
- mapType(definitions.ShortClass, MSHORT)
- mapType(definitions.CharClass, MCHAR)
- mapType(definitions.IntClass, MINT)
- mapType(definitions.LongClass, MLONG)
- mapType(definitions.FloatClass, MFLOAT)
- mapType(definitions.DoubleClass, MDOUBLE)
- }
-
- var clasz: IClass = _
- var method: IMethod = _
-
- var massembly: AssemblyBuilder = _
- var mmodule: ModuleBuilder = _
- var mcode: ILGenerator = _
-
- var assemName: String = _
- var firstSourceName = ""
- var outDir: File = _
- var srcPath: File = _
- var moduleName: String = _
-
- def initAssembly() {
-
- assemName = settings.assemname.value
-
- if (assemName == "") {
- if (entryPoint != null) {
- assemName = msilName(entryPoint.enclClass)
- // remove the $ at the end (from module-name)
- assemName = assemName.substring(0, assemName.length() - 1)
- } else {
- // assuming filename of first source file
- assert(firstSourceName.endsWith(".scala"), firstSourceName)
- assemName = firstSourceName.substring(0, firstSourceName.length() - 6)
- }
- } else {
- if (assemName.endsWith(".msil"))
- assemName = assemName.substring(0, assemName.length()-5)
- if (assemName.endsWith(".il"))
- assemName = assemName.substring(0, assemName.length()-3)
- val f: File = new File(assemName)
- assemName = f.getName()
- }
-
- outDir = new File(settings.outdir.value)
-
- srcPath = new File(settings.sourcedir.value)
-
- val assemblyName = new AssemblyName()
- assemblyName.Name = assemName
- massembly = AssemblyBuilderFactory.DefineDynamicAssembly(assemblyName)
-
- moduleName = assemName // + (if (entryPoint == null) ".dll" else ".exe")
- // filename here: .dll or .exe (in both parameters), second: give absolute-path
- mmodule = massembly.DefineDynamicModule(moduleName,
- new File(outDir, moduleName).getAbsolutePath())
- assert (mmodule != null)
- }
-
-
- /**
- * Form of the custom Attribute parameter (Ecma-335.pdf)
- * - p. 163 for CustomAttrib Form,
- * - p. 164 for FixedArg Form (Array and Element) (if array or not is known!)
- * !! least significant byte first if values longer than one byte !!
- *
- * 1: Prolog (unsigned int16, value 0x0001) -> symtab[0] = 0x01, symtab[1] = 0x00
- * 2: FixedArgs (directly the data, get number and types from related constructor)
- * 2.1: length of the array (unsigned int32, 4 bytes, least significant first)
- * 2.2: the byte array data
- * 3: NumNamed (unsigned int16, number of named fields and properties, 0x0000)
- */
- def addSymtabAttribute(sym: Symbol, tBuilder: TypeBuilder) {
- def addMarker() {
- val markerSymtab = new Array[Byte](4)
- markerSymtab(0) = 1.toByte
- tBuilder.SetCustomAttribute(SYMTAB_ATTRIBUTE_EMPTY_CONSTRUCTOR, markerSymtab)
- }
-
- // both conditions are needed (why exactly..?)
- if (tBuilder.Name.endsWith("$") || sym.isModuleClass) {
- addMarker()
- } else {
- currentRun.symData.get(sym) match {
- case Some(pickle) =>
- var size = pickle.writeIndex
- val symtab = new Array[Byte](size + 8)
- symtab(0) = 1.toByte
- for (i <- 2 until 6) {
- symtab(i) = (size & 0xff).toByte
- size = size >> 8
- }
- java.lang.System.arraycopy(pickle.bytes, 0, symtab, 6, pickle.writeIndex)
-
- tBuilder.SetCustomAttribute(SYMTAB_ATTRIBUTE_CONSTRUCTOR, symtab)
-
- currentRun.symData -= sym
- currentRun.symData -= sym.companionSymbol
-
- case _ =>
- addMarker()
- }
- }
- }
-
- /**
- * Mutates `member` adding CLR attributes (if any) based on sym.annotations.
- * Please notice that CLR custom modifiers are a different beast (see customModifiers below)
- * and thus shouldn't be added by this method.
- */
- def addAttributes(member: ICustomAttributeSetter, annotations: List[AnnotationInfo]) {
- val attributes = annotations.map(_.atp.typeSymbol).collect {
- case definitions.TransientAttr => null // TODO this is just an example
- }
- return // TODO: implement at some point
- }
-
- /**
- * What's a CLR custom modifier? Intro available as source comments in compiler.msil.CustomModifier.
- * It's basically a marker associated with a location (think of FieldInfo, ParameterInfo, and PropertyInfo)
- * and thus that marker (be it optional or required) becomes part of the signature of that location.
- * Some annotations will become CLR attributes (see addAttributes above), others custom modifiers (this method).
- */
- def customModifiers(annotations: List[AnnotationInfo]): Array[CustomModifier] = {
- annotations.map(_.atp.typeSymbol).collect {
- case definitions.VolatileAttr => new CustomModifier(true, CustomModifier.VolatileMarker)
- } toArray
- }
-
-
-
- /*
- debuglog("creating annotations: " + annotations + " for member : " + member)
- for (annot@ AnnotationInfo(typ, annArgs, nvPairs) <- annotations ;
- if annot.isConstant)
- //!typ.typeSymbol.isJavaDefined
- {
-// assert(consts.length <= 1,
-// "too many constant arguments for annotations; "+consts.toString())
-
- // Problem / TODO having the symbol of the annotations type would be nicer
- // (i hope that type.typeSymbol is the same as the one in types2create)
- // AND: this will crash if the annotations Type is already compiled (-> not a typeBuilder)
- // when this is solved, types2create will be the same as icodes.classes, thus superfluous
- val annType: TypeBuilder = getType(typ.typeSymbol).asInstanceOf[TypeBuilder]
-// val annType: MsilType = getType(typ.typeSymbol)
-
- // Problem / TODO: i have no idea which constructor is used. This
- // information should be available in AnnotationInfo.
- annType.CreateType() // else, GetConstructors can't be used
- val constr: ConstructorInfo = annType.GetConstructors()(0)
- // prevent a second call of CreateType, only needed because there's no
- // other way than GetConstructors()(0) to get the constructor, if there's
- // no constructor symbol available.
-
- val args: Array[Byte] =
- getAttributeArgs(
- annArgs map (_.constant.get),
- (for((n,v) <- nvPairs) yield (n, v.constant.get)))
- member.SetCustomAttribute(constr, args)
- }
- } */
-
-/* def getAttributeArgs(consts: List[Constant], nvPairs: List[(Name, Constant)]): Array[Byte] = {
- val buf = ByteBuffer.allocate(2048) // FIXME: this may be not enough!
- buf.order(ByteOrder.LITTLE_ENDIAN)
- buf.putShort(1.toShort) // signature
-
- def emitSerString(str: String) = {
- // this is wrong, it has to be the length of the UTF-8 byte array, which
- // may be longer (see clr-book on page 302)
-// val length: Int = str.length
- val strBytes: Array[Byte] = try {
- str.getBytes("UTF-8")
- } catch {
- case _: Error => abort("could not get byte-array for string: " + str)
- }
- val length: Int = strBytes.length //this length is stored big-endian
- if (length < 128)
- buf.put(length.toByte)
- else if (length < (1<<14)) {
- buf.put(((length >> 8) | 0x80).toByte) // the bits 14 and 15 of length are '0'
- buf.put((length | 0xff).toByte)
- } else if (length < (1 << 29)) {
- buf.put(((length >> 24) | 0xc0).toByte)
- buf.put(((length >> 16) & 0xff).toByte)
- buf.put(((length >> 8) & 0xff).toByte)
- buf.put(((length ) & 0xff).toByte)
- } else
- abort("string too long for attribute parameter: " + length)
- buf.put(strBytes)
- }
-
- def emitConst(const: Constant): Unit = const.tag match {
- case BooleanTag => buf.put((if (const.booleanValue) 1 else 0).toByte)
- case ByteTag => buf.put(const.byteValue)
- case ShortTag => buf.putShort(const.shortValue)
- case CharTag => buf.putChar(const.charValue)
- case IntTag => buf.putInt(const.intValue)
- case LongTag => buf.putLong(const.longValue)
- case FloatTag => buf.putFloat(const.floatValue)
- case DoubleTag => buf.putDouble(const.doubleValue)
- case StringTag =>
- val str: String = const.stringValue
- if (str == null) {
- buf.put(0xff.toByte)
- } else {
- emitSerString(str)
- }
- case ArrayTag =>
- val arr: Array[Constant] = const.arrayValue
- if (arr == null) {
- buf.putInt(0xffffffff)
- } else {
- buf.putInt(arr.length)
- arr.foreach(emitConst)
- }
-
- // TODO: other Tags: NoTag, UnitTag, ClazzTag, EnumTag, ArrayTag ???
-
- case _ => abort("could not handle attribute argument: " + const)
- }
-
- consts foreach emitConst
- buf.putShort(nvPairs.length.toShort)
- def emitNamedArg(nvPair: (Name, Constant)) {
- // the named argument is a property of the attribute (it can't be a field, since
- // all fields in scala are private)
- buf.put(0x54.toByte)
-
- def emitType(c: Constant) = c.tag match { // type of the constant, Ecma-335.pdf, page 151
- case BooleanTag => buf.put(0x02.toByte)
- case ByteTag => buf.put(0x05.toByte)
- case ShortTag => buf.put(0x06.toByte)
- case CharTag => buf.put(0x07.toByte)
- case IntTag => buf.put(0x08.toByte)
- case LongTag => buf.put(0x0a.toByte)
- case FloatTag => buf.put(0x0c.toByte)
- case DoubleTag => buf.put(0x0d.toByte)
- case StringTag => buf.put(0x0e.toByte)
-
- // TODO: other Tags: NoTag, UnitTag, ClazzTag, EnumTag ???
-
- // ArrayTag falls in here
- case _ => abort("could not handle attribute argument: " + c)
- }
-
- val cnst: Constant = nvPair._2
- if (cnst.tag == ArrayTag) {
- buf.put(0x1d.toByte)
- emitType(cnst.arrayValue(0)) // FIXME: will crash if array length = 0
- } else if (cnst.tag == EnumTag) {
- buf.put(0x55.toByte)
- // TODO: put a SerString (don't know what exactly, names of the enums somehow..)
- } else {
- buf.put(0x51.toByte)
- emitType(cnst)
- }
-
- emitSerString(nvPair._1.toString)
- emitConst(nvPair._2)
- }
-
- val length = buf.position()
- buf.array().slice(0, length)
- } */
-
- def writeAssembly() {
- if (entryPoint != null) {
- assert(entryPoint.enclClass.isModuleClass, entryPoint.enclClass)
- val mainMethod = methods(entryPoint)
- val stringArrayTypes: Array[MsilType] = Array(MSTRING_ARRAY)
- val globalMain = mmodule.DefineGlobalMethod(
- "Main", MethodAttributes.Public | MethodAttributes.Static,
- MVOID, stringArrayTypes)
- globalMain.DefineParameter(0, ParameterAttributes.None, "args")
- massembly.SetEntryPoint(globalMain)
- val code = globalMain.GetILGenerator()
- val moduleField = getModuleInstanceField(entryPoint.enclClass)
- code.Emit(OpCodes.Ldsfld, moduleField)
- code.Emit(OpCodes.Ldarg_0)
- code.Emit(OpCodes.Callvirt, mainMethod)
- code.Emit(OpCodes.Ret)
- }
- createTypes()
- var outDirName: String = null
- try {
- if (settings.Ygenjavap.isDefault) { // we reuse the JVM-sounding setting because it's conceptually similar
- outDirName = outDir.getPath()
- massembly.Save(outDirName + "\\" + assemName + ".msil") /* use SingleFileILPrinterVisitor */
- } else {
- outDirName = srcPath.getPath()
- massembly.Save(settings.Ygenjavap.value, outDirName) /* use MultipleFilesILPrinterVisitor */
- }
- } catch {
- case e:IOException => abort("Could not write to " + outDirName + ": " + e.getMessage())
- }
- }
-
- private def createTypes() {
- for (sym <- classes.keys) {
- val iclass = classes(sym)
- val tBuilder = types(sym).asInstanceOf[TypeBuilder]
-
- debuglog("Calling CreatType for " + sym + ", " + tBuilder.toString)
-
- tBuilder.CreateType()
- tBuilder.setSourceFilepath(iclass.cunit.source.file.path)
- }
- }
-
- private[GenMSIL] def ilasmFileName(iclass: IClass) : String = {
- // method.sourceFile contains just the filename
- iclass.cunit.source.file.toString.replace("\\", "\\\\")
- }
-
- private[GenMSIL] def genClass(iclass: IClass) {
- val sym = iclass.symbol
- debuglog("Generating class " + sym + " flags: " + Flags.flagsToString(sym.flags))
- clasz = iclass
-
- val tBuilder = getType(sym).asInstanceOf[TypeBuilder]
- if (isCloneable(sym)) {
- // FIXME: why there's no nme.clone_ ?
- // "Clone": if the code is non-portable, "Clone" is defined, not "clone"
- // TODO: improve condition (should override AnyRef.clone)
- if (iclass.methods.forall(m => {
- !((m.symbol.name.toString != "clone" || m.symbol.name.toString != "Clone") &&
- m.symbol.tpe.paramTypes.length != 0)
- })) {
- debuglog("auto-generating cloneable method for " + sym)
- val attrs: Short = (MethodAttributes.Public | MethodAttributes.Virtual |
- MethodAttributes.HideBySig).toShort
- val cloneMethod = tBuilder.DefineMethod("Clone", attrs, MOBJECT,
- MsilType.EmptyTypes)
- val clCode = cloneMethod.GetILGenerator()
- clCode.Emit(OpCodes.Ldarg_0)
- clCode.Emit(OpCodes.Call, MEMBERWISE_CLONE)
- clCode.Emit(OpCodes.Ret)
- }
- }
-
- val line = sym.pos.line
- tBuilder.setPosition(line, ilasmFileName(iclass))
-
- if (isTopLevelModule(sym)) {
- if (sym.companionClass == NoSymbol)
- generateMirrorClass(sym)
- else
- log("No mirror class for module with linked class: " +
- sym.fullName)
- }
-
- addSymtabAttribute(sym, tBuilder)
- addAttributes(tBuilder, sym.annotations)
-
- if (iclass.symbol != definitions.ArrayClass)
- iclass.methods foreach genMethod
-
- } //genClass
-
-
- private def genMethod(m: IMethod) {
- debuglog("Generating method " + m.symbol + " flags: " + Flags.flagsToString(m.symbol.flags) +
- " owner: " + m.symbol.owner)
- method = m
- localBuilders.clear
- computeLocalVarsIndex(m)
-
- if (m.symbol.isClassConstructor) {
- mcode = constructors(m.symbol).asInstanceOf[ConstructorBuilder].GetILGenerator()
- } else {
- val mBuilder = methods(m.symbol).asInstanceOf[MethodBuilder]
- if (!mBuilder.IsAbstract())
- try {
- mcode = mBuilder.GetILGenerator()
- } catch {
- case e: Exception =>
- java.lang.System.out.println("m.symbol = " + Flags.flagsToString(m.symbol.flags) + " " + m.symbol)
- java.lang.System.out.println("m.symbol.owner = " + Flags.flagsToString(m.symbol.owner.flags) + " " + m.symbol.owner)
- java.lang.System.out.println("mBuilder = " + mBuilder)
- java.lang.System.out.println("mBuilder.DeclaringType = " +
- TypeAttributes.toString(mBuilder.DeclaringType.Attributes) +
- "::" + mBuilder.DeclaringType)
- throw e
- }
- else
- mcode = null
- }
-
- if (mcode != null) {
- for (local <- m.locals ; if !(m.params contains local)) {
- debuglog("add local var: " + local + ", of kind " + local.kind)
- val t: MsilType = msilType(local.kind)
- val localBuilder = mcode.DeclareLocal(t)
- localBuilder.SetLocalSymInfo(msilName(local.sym))
- localBuilders(local) = localBuilder
- }
- genCode(m)
- }
-
- }
-
- /** Special linearizer for methods with at least one exception handler. This
- * linearizer brings all basic blocks in the right order so that nested
- * try-catch and try-finally blocks can be emitted.
- */
- val msilLinearizer = new MSILLinearizer()
-
- val labels = mutable.HashMap[BasicBlock, Label]()
-
- /* when emitting .line, it's enough to include the full filename just once per method, thus reducing filesize.
- * this scheme relies on the fact that the entry block is emitted first. */
- var dbFilenameSeen = false
-
- def genCode(m: IMethod) {
-
- def makeLabels(blocks: List[BasicBlock]) = {
- debuglog("Making labels for: " + method)
- for (bb <- blocks) labels(bb) = mcode.DefineLabel()
- }
-
- labels.clear
-
- var linearization = if(!m.exh.isEmpty) msilLinearizer.linearize(m)
- else linearizer.linearize(m)
-
- if (!m.exh.isEmpty)
- linearization = computeExceptionMaps(linearization, m)
-
- makeLabels(linearization)
-
- // debug val blocksInM = m.code.blocks.toList.sortBy(bb => bb.label)
- // debug val blocksInL = linearization.sortBy(bb => bb.label)
- // debug val MButNotL = (blocksInM.toSet) diff (blocksInL.toSet) // if non-empty, a jump to B fails to find a label for B (case CJUMP, case CZJUMP)
- // debug if(!MButNotL.isEmpty) { }
-
- dbFilenameSeen = false
- genBlocks(linearization)
-
- // RETURN inside exception blocks are replaced by Leave. The target of the
- // leave is a `Ret` outside any exception block (generated here).
- if (handlerReturnMethod == m) {
- mcode.MarkLabel(handlerReturnLabel)
- if (handlerReturnKind != UNIT)
- mcode.Emit(OpCodes.Ldloc, handlerReturnLocal)
- mcode.Emit(OpCodes.Ret)
- }
-
- beginExBlock.clear()
- beginCatchBlock.clear()
- endExBlock.clear()
- endFinallyLabels.clear()
- }
-
- def genBlocks(blocks: List[BasicBlock], previous: BasicBlock = null) {
- blocks match {
- case Nil => ()
- case x :: Nil => genBlock(x, prev = previous, next = null)
- case x :: y :: ys => genBlock(x, prev = previous, next = y); genBlocks(y :: ys, previous = x)
- }
- }
-
- // the try blocks starting at a certain BasicBlock
- val beginExBlock = mutable.HashMap[BasicBlock, List[ExceptionHandler]]()
-
- // the catch blocks starting / endling at a certain BasicBlock
- val beginCatchBlock = mutable.HashMap[BasicBlock, ExceptionHandler]()
- val endExBlock = mutable.HashMap[BasicBlock, List[ExceptionHandler]]()
-
- /** When emitting the code (genBlock), the number of currently active try / catch
- * blocks. When seeing a `RETURN` inside a try / catch, we need to
- * - store the result in a local (if it's not UNIT)
- * - emit `Leave handlerReturnLabel` instead of the Return
- * - emit code at the end: load the local and return its value
- */
- var currentHandlers = new mutable.Stack[ExceptionHandler]
- // The IMethod the Local/Label/Kind below belong to
- var handlerReturnMethod: IMethod = _
- // Stores the result when returning inside an exception block
- var handlerReturnLocal: LocalBuilder = _
- // Label for a return instruction outside any exception block
- var handlerReturnLabel: Label = _
- // The result kind.
- var handlerReturnKind: TypeKind = _
- def returnFromHandler(kind: TypeKind): (LocalBuilder, Label) = {
- if (handlerReturnMethod != method) {
- handlerReturnMethod = method
- if (kind != UNIT) {
- handlerReturnLocal = mcode.DeclareLocal(msilType(kind))
- handlerReturnLocal.SetLocalSymInfo("$handlerReturn")
- }
- handlerReturnLabel = mcode.DefineLabel()
- handlerReturnKind = kind
- }
- (handlerReturnLocal, handlerReturnLabel)
- }
-
- /** For try/catch nested inside a finally, we can't use `Leave OutsideFinally`, the
- * Leave target has to be inside the finally (and it has to be the `endfinally` instruction).
- * So for every finalizer, we have a label which marks the place of the `endfinally`,
- * nested try/catch blocks will leave there.
- */
- val endFinallyLabels = mutable.HashMap[ExceptionHandler, Label]()
-
- /** Computes which blocks are the beginning / end of a try or catch block */
- private def computeExceptionMaps(blocks: List[BasicBlock], m: IMethod): List[BasicBlock] = {
- val visitedBlocks = new mutable.HashSet[BasicBlock]()
-
- // handlers which have not been introduced so far
- var openHandlers = m.exh
-
-
- /** Example
- * try {
- * try {
- * // *1*
- * } catch {
- * case h1 =>
- * }
- * } catch {
- * case h2 =>
- * case h3 =>
- * try {
- *
- * } catch {
- * case h4 => // *2*
- * case h5 =>
- * }
- * }
- */
-
- // Stack of nested try blocks. Each bloc has a List of ExceptionHandler (multiple
- // catch statements). Example *1*: Stack(List(h2, h3), List(h1))
- val currentTryHandlers = new mutable.Stack[List[ExceptionHandler]]()
-
- // Stack of nested catch blocks. The head of the list is the current catch block. The
- // tail is all following catch blocks. Example *2*: Stack(List(h3), List(h4, h5))
- val currentCatchHandlers = new mutable.Stack[List[ExceptionHandler]]()
-
- for (b <- blocks) {
-
- // are we past the current catch blocks?
- def endHandlers(): List[ExceptionHandler] = {
- var res: List[ExceptionHandler] = Nil
- if (!currentCatchHandlers.isEmpty) {
- val handler = currentCatchHandlers.top.head
- if (!handler.blocks.contains(b)) {
- // all blocks of the handler are either visited, or not part of the linearization (i.e. dead)
- assert(handler.blocks.forall(b => visitedBlocks.contains(b) || !blocks.contains(b)),
- "Bad linearization of basic blocks inside catch. Found block not part of the handler\n"+
- b.fullString +"\nwhile in catch-part of\n"+ handler)
-
- val rest = currentCatchHandlers.pop.tail
- if (rest.isEmpty) {
- // all catch blocks of that exception handler are covered
- res = handler :: endHandlers()
- } else {
- // there are more catch blocks for that try (handlers covering the same)
- currentCatchHandlers.push(rest)
- beginCatchBlock(b) = rest.head
- }
- }
- }
- res
- }
- val end = endHandlers()
- if (!end.isEmpty) endExBlock(b) = end
-
- // are we past the current try block?
- if (!currentTryHandlers.isEmpty) {
- val handler = currentTryHandlers.top.head
- if (!handler.covers(b)) {
- // all of the covered blocks are visited, or not part of the linearization
- assert(handler.covered.forall(b => visitedBlocks.contains(b) || !blocks.contains(b)),
- "Bad linearization of basic blocks inside try. Found non-covered block\n"+
- b.fullString +"\nwhile in try-part of\n"+ handler)
-
- assert(handler.startBlock == b,
- "Bad linearization of basic blocks. The entry block of a catch does not directly follow the try\n"+
- b.fullString +"\n"+ handler)
-
- val handlers = currentTryHandlers.pop
- currentCatchHandlers.push(handlers)
- beginCatchBlock(b) = handler
- }
- }
-
- // are there try blocks starting at b?
- val (newHandlers, stillOpen) = openHandlers.partition(_.covers(b))
- openHandlers = stillOpen
-
- val newHandlersBySize = newHandlers.groupBy(_.covered.size)
- // big handlers first, smaller ones are nested inside the try of the big one
- // (checked by the assertions below)
- val sizes = newHandlersBySize.keys.toList.sortWith(_ > _)
-
- val beginHandlers = new mutable.ListBuffer[ExceptionHandler]
- for (s <- sizes) {
- val sHandlers = newHandlersBySize(s)
- for (h <- sHandlers) {
- assert(h.covered == sHandlers.head.covered,
- "bad nesting of exception handlers. same size, but not covering same blocks\n"+
- h +"\n"+ sHandlers.head)
- assert(h.resultKind == sHandlers.head.resultKind,
- "bad nesting of exception handlers. same size, but the same resultKind\n"+
- h +"\n"+ sHandlers.head)
- }
- for (bigger <- beginHandlers; h <- sHandlers) {
- assert(h.covered.subsetOf(bigger.covered),
- "bad nesting of exception handlers. try blocks of smaller handler are not nested in bigger one.\n"+
- h +"\n"+ bigger)
- assert(h.blocks.toSet.subsetOf(bigger.covered),
- "bad nesting of exception handlers. catch blocks of smaller handler are not nested in bigger one.\n"+
- h +"\n"+ bigger)
- }
- beginHandlers += sHandlers.head
- currentTryHandlers.push(sHandlers)
- }
- beginExBlock(b) = beginHandlers.toList
- visitedBlocks += b
- }
-
- // if there handlers left (i.e. handlers covering nothing, or a
- // non-existent (dead) block), remove their catch-blocks.
- val liveBlocks = if (openHandlers.isEmpty) blocks else {
- blocks.filter(b => openHandlers.forall(h => !h.blocks.contains(b)))
- }
-
- /** There might be open handlers, but no more blocks. happens when try/catch end
- * with `throw` or `return`
- * def foo() { try { .. throw } catch { _ => .. throw } }
- *
- * In this case we need some code after the catch block for the auto-generated
- * `leave` instruction. So we're adding a (dead) `throw new Exception`.
- */
- val rest = currentCatchHandlers.map(handlers => {
- assert(handlers.length == 1, handlers)
- handlers.head
- }).toList
-
- if (rest.isEmpty) {
- liveBlocks
- } else {
- val b = m.code.newBlock
- b.emit(Seq(
- NEW(REFERENCE(definitions.ThrowableClass)),
- DUP(REFERENCE(definitions.ObjectClass)),
- CALL_METHOD(definitions.ThrowableClass.primaryConstructor, Static(true)),
- THROW(definitions.ThrowableClass)
- ))
- b.close
- endExBlock(b) = rest
- liveBlocks ::: List(b)
- }
- }
-
- /**
- * @param block the BasicBlock to emit code for
- * @param next the following BasicBlock, `null` if `block` is the last one
- */
- def genBlock(block: BasicBlock, prev: BasicBlock, next: BasicBlock) {
-
- def loadLocalOrAddress(local: Local, msg : String , loadAddr : Boolean) {
- debuglog(msg + " for " + local)
- val isArg = local.arg
- val i = local.index
- if (isArg)
- loadArg(mcode, loadAddr)(i)
- else
- loadLocal(i, local, mcode, loadAddr)
- }
-
- def loadFieldOrAddress(field: Symbol, isStatic: Boolean, msg: String, loadAddr : Boolean) {
- debuglog(msg + " with owner: " + field.owner +
- " flags: " + Flags.flagsToString(field.owner.flags))
- var fieldInfo = fields.get(field) match {
- case Some(fInfo) => fInfo
- case None =>
- val fInfo = getType(field.owner).GetField(msilName(field))
- fields(field) = fInfo
- fInfo
- }
- if (fieldInfo.IsVolatile) {
- mcode.Emit(OpCodes.Volatile)
- }
- if (!fieldInfo.IsLiteral) {
- if (loadAddr) {
- mcode.Emit(if (isStatic) OpCodes.Ldsflda else OpCodes.Ldflda, fieldInfo)
- } else {
- mcode.Emit(if (isStatic) OpCodes.Ldsfld else OpCodes.Ldfld, fieldInfo)
- }
- } else {
- assert(!loadAddr, "can't take AddressOf a literal field (not even with readonly. prefix) because no memory was allocated to such field ...")
- // TODO the above can be overcome by loading the value, boxing, and finally unboxing. An address to a copy of the raw value will be on the stack.
- /* We perform `field inlining' as required by CLR.
- * Emit as for a CONSTANT ICode stmt, with the twist that the constant value is available
- * as a java.lang.Object and its .NET type allows constant initialization in CLR, i.e. that type
- * is one of I1, I2, I4, I8, R4, R8, CHAR, BOOLEAN, STRING, or CLASS (in this last case,
- * only accepting nullref as value). See Table 9-1 in Lidin's book on ILAsm. */
- val value = fieldInfo.getValue()
- if (value == null) {
- mcode.Emit(OpCodes.Ldnull)
- } else {
- val typ = if (fieldInfo.FieldType.IsEnum) fieldInfo.FieldType.getUnderlyingType
- else fieldInfo.FieldType
- if (typ == clrTypes.STRING) {
- mcode.Emit(OpCodes.Ldstr, value.asInstanceOf[String])
- } else if (typ == clrTypes.BOOLEAN) {
- mcode.Emit(if (value.asInstanceOf[Boolean]) OpCodes.Ldc_I4_1
- else OpCodes.Ldc_I4_0)
- } else if (typ == clrTypes.BYTE || typ == clrTypes.UBYTE) {
- loadI4(value.asInstanceOf[Byte], mcode)
- } else if (typ == clrTypes.SHORT || typ == clrTypes.USHORT) {
- loadI4(value.asInstanceOf[Int], mcode)
- } else if (typ == clrTypes.CHAR) {
- loadI4(value.asInstanceOf[Char], mcode)
- } else if (typ == clrTypes.INT || typ == clrTypes.UINT) {
- loadI4(value.asInstanceOf[Int], mcode)
- } else if (typ == clrTypes.LONG || typ == clrTypes.ULONG) {
- mcode.Emit(OpCodes.Ldc_I8, value.asInstanceOf[Long])
- } else if (typ == clrTypes.FLOAT) {
- mcode.Emit(OpCodes.Ldc_R4, value.asInstanceOf[Float])
- } else if (typ == clrTypes.DOUBLE) {
- mcode.Emit(OpCodes.Ldc_R8, value.asInstanceOf[Double])
- } else {
- /* TODO one more case is described in Partition II, 16.2: bytearray(...) */
- abort("Unknown type for static literal field: " + fieldInfo)
- }
- }
- }
- }
-
- /** Creating objects works differently on .NET. On the JVM
- * - NEW(type) => reference on Stack
- * - DUP, load arguments, CALL_METHOD(constructor)
- *
- * On .NET, the NEW and DUP are ignored, but we emit a special method call
- * - load arguments
- * - NewObj(constructor) => reference on stack
- *
- * This variable tells whether the previous instruction was a NEW,
- * we expect a DUP which is not emitted. */
- var previousWasNEW = false
-
- var lastLineNr: Int = 0
- var lastPos: Position = NoPosition
-
-
- // EndExceptionBlock must happen before MarkLabel because it adds the
- // Leave instruction. Otherwise, labels(block) points to the Leave
- // (inside the catch) instead of the instruction afterwards.
- for (handlers <- endExBlock.get(block); exh <- handlers) {
- currentHandlers.pop()
- for (l <- endFinallyLabels.get(exh))
- mcode.MarkLabel(l)
- mcode.EndExceptionBlock()
- }
-
- mcode.MarkLabel(labels(block))
- debuglog("Generating code for block: " + block)
-
- for (handler <- beginCatchBlock.get(block)) {
- if (!currentHandlers.isEmpty && currentHandlers.top.covered == handler.covered) {
- currentHandlers.pop()
- currentHandlers.push(handler)
- }
- if (handler.cls == NoSymbol) {
- // `finally` blocks are represented the same as `catch`, but with no catch-type
- mcode.BeginFinallyBlock()
- } else {
- val t = getType(handler.cls)
- mcode.BeginCatchBlock(t)
- }
- }
- for (handlers <- beginExBlock.get(block); exh <- handlers) {
- currentHandlers.push(exh)
- mcode.BeginExceptionBlock()
- }
-
- for (instr <- block) {
- try {
- val currentLineNr = instr.pos.line
- val skip = if(instr.pos.isRange) instr.pos.sameRange(lastPos) else (currentLineNr == lastLineNr);
- if(!skip || !dbFilenameSeen) {
- val fileName = if(dbFilenameSeen) "" else {dbFilenameSeen = true; ilasmFileName(clasz)};
- if(instr.pos.isRange) {
- val startLine = instr.pos.focusStart.line
- val endLine = instr.pos.focusEnd.line
- val startCol = instr.pos.focusStart.column
- val endCol = instr.pos.focusEnd.column
- mcode.setPosition(startLine, endLine, startCol, endCol, fileName)
- } else {
- mcode.setPosition(instr.pos.line, fileName)
- }
- lastLineNr = currentLineNr
- lastPos = instr.pos
- }
- } catch { case _: UnsupportedOperationException => () }
-
- if (previousWasNEW)
- assert(instr.isInstanceOf[DUP], block)
-
- instr match {
- case THIS(clasz) =>
- mcode.Emit(OpCodes.Ldarg_0)
-
- case CONSTANT(const) =>
- const.tag match {
- case UnitTag => ()
- case BooleanTag => mcode.Emit(if (const.booleanValue) OpCodes.Ldc_I4_1
- else OpCodes.Ldc_I4_0)
- case ByteTag => loadI4(const.byteValue, mcode)
- case ShortTag => loadI4(const.shortValue, mcode)
- case CharTag => loadI4(const.charValue, mcode)
- case IntTag => loadI4(const.intValue, mcode)
- case LongTag => mcode.Emit(OpCodes.Ldc_I8, const.longValue)
- case FloatTag => mcode.Emit(OpCodes.Ldc_R4, const.floatValue)
- case DoubleTag => mcode.Emit(OpCodes.Ldc_R8, const.doubleValue)
- case StringTag => mcode.Emit(OpCodes.Ldstr, const.stringValue)
- case NullTag => mcode.Emit(OpCodes.Ldnull)
- case ClazzTag =>
- mcode.Emit(OpCodes.Ldtoken, msilType(const.typeValue))
- mcode.Emit(OpCodes.Call, TYPE_FROM_HANDLE)
- case _ => abort("Unknown constant value: " + const)
- }
-
- case LOAD_ARRAY_ITEM(kind) =>
- (kind: @unchecked) match {
- case BOOL => mcode.Emit(OpCodes.Ldelem_I1)
- case BYTE => mcode.Emit(OpCodes.Ldelem_I1) // I1 for System.SByte, i.e. a scala.Byte
- case SHORT => mcode.Emit(OpCodes.Ldelem_I2)
- case CHAR => mcode.Emit(OpCodes.Ldelem_U2)
- case INT => mcode.Emit(OpCodes.Ldelem_I4)
- case LONG => mcode.Emit(OpCodes.Ldelem_I8)
- case FLOAT => mcode.Emit(OpCodes.Ldelem_R4)
- case DOUBLE => mcode.Emit(OpCodes.Ldelem_R8)
- case REFERENCE(cls) => mcode.Emit(OpCodes.Ldelem_Ref)
- case ARRAY(elem) => mcode.Emit(OpCodes.Ldelem_Ref)
-
- // case UNIT is not possible: an Array[Unit] will be an
- // Array[scala.runtime.BoxedUnit] (-> case REFERENCE)
- }
-
- case LOAD_LOCAL(local) => loadLocalOrAddress(local, "load_local", false)
-
- case CIL_LOAD_LOCAL_ADDRESS(local) => loadLocalOrAddress(local, "cil_load_local_address", true)
-
- case LOAD_FIELD(field, isStatic) => loadFieldOrAddress(field, isStatic, "load_field", false)
-
- case CIL_LOAD_FIELD_ADDRESS(field, isStatic) => loadFieldOrAddress(field, isStatic, "cil_load_field_address", true)
-
- case CIL_LOAD_ARRAY_ITEM_ADDRESS(kind) => mcode.Emit(OpCodes.Ldelema, msilType(kind))
-
- case CIL_NEWOBJ(msym) =>
- assert(msym.isClassConstructor)
- val constructorInfo: ConstructorInfo = getConstructor(msym)
- mcode.Emit(OpCodes.Newobj, constructorInfo)
-
- case LOAD_MODULE(module) =>
- debuglog("Generating LOAD_MODULE for: " + showsym(module))
- mcode.Emit(OpCodes.Ldsfld, getModuleInstanceField(module))
-
- case STORE_ARRAY_ITEM(kind) =>
- (kind: @unchecked) match {
- case BOOL => mcode.Emit(OpCodes.Stelem_I1)
- case BYTE => mcode.Emit(OpCodes.Stelem_I1)
- case SHORT => mcode.Emit(OpCodes.Stelem_I2)
- case CHAR => mcode.Emit(OpCodes.Stelem_I2)
- case INT => mcode.Emit(OpCodes.Stelem_I4)
- case LONG => mcode.Emit(OpCodes.Stelem_I8)
- case FLOAT => mcode.Emit(OpCodes.Stelem_R4)
- case DOUBLE => mcode.Emit(OpCodes.Stelem_R8)
- case REFERENCE(cls) => mcode.Emit(OpCodes.Stelem_Ref)
- case ARRAY(elem) => mcode.Emit(OpCodes.Stelem_Ref) // @TODO: test this! (occurs when calling a Array[Object]* vararg param method)
-
- // case UNIT not possible (see comment at LOAD_ARRAY_ITEM)
- }
-
- case STORE_LOCAL(local) =>
- val isArg = local.arg
- val i = local.index
- debuglog("store_local for " + local + ", index " + i)
-
- // there are some locals defined by the compiler that
- // are isArg and are need to be stored.
- if (isArg) {
- if (i >= -128 && i <= 127)
- mcode.Emit(OpCodes.Starg_S, i)
- else
- mcode.Emit(OpCodes.Starg, i)
- } else {
- i match {
- case 0 => mcode.Emit(OpCodes.Stloc_0)
- case 1 => mcode.Emit(OpCodes.Stloc_1)
- case 2 => mcode.Emit(OpCodes.Stloc_2)
- case 3 => mcode.Emit(OpCodes.Stloc_3)
- case _ =>
- if (i >= -128 && i <= 127)
- mcode.Emit(OpCodes.Stloc_S, localBuilders(local))
- else
- mcode.Emit(OpCodes.Stloc, localBuilders(local))
- }
- }
-
- case STORE_THIS(_) =>
- // this only works for impl classes because the self parameter comes first
- // in the method signature. If that changes, this code has to be revisited.
- mcode.Emit(OpCodes.Starg_S, 0)
-
- case STORE_FIELD(field, isStatic) =>
- val fieldInfo = fields.get(field) match {
- case Some(fInfo) => fInfo
- case None =>
- val fInfo = getType(field.owner).GetField(msilName(field))
- fields(field) = fInfo
- fInfo
- }
- mcode.Emit(if (isStatic) OpCodes.Stsfld else OpCodes.Stfld, fieldInfo)
-
- case CALL_PRIMITIVE(primitive) =>
- genPrimitive(primitive, instr.pos)
-
- case CALL_METHOD(msym, style) =>
- if (msym.isClassConstructor) {
- val constructorInfo: ConstructorInfo = getConstructor(msym)
- (style: @unchecked) match {
- // normal constructor calls are Static..
- case Static(_) =>
- if (method.symbol.isClassConstructor && method.symbol.owner == msym.owner)
- // we're generating a constructor (method: IMethod is a constructor), and we're
- // calling another constructor of the same class.
-
- // @LUC TODO: this can probably break, namely when having: class A { def this() { new A() } }
- // instead, we should instruct the CALL_METHOD with additional information, know whether it's
- // an instance creation constructor call or not.
- mcode.Emit(OpCodes.Call, constructorInfo)
- else
- mcode.Emit(OpCodes.Newobj, constructorInfo)
- case SuperCall(_) =>
- mcode.Emit(OpCodes.Call, constructorInfo)
- if (isStaticModule(clasz.symbol) &&
- notInitializedModules.contains(clasz.symbol) &&
- method.symbol.isClassConstructor)
- {
- notInitializedModules -= clasz.symbol
- mcode.Emit(OpCodes.Ldarg_0)
- mcode.Emit(OpCodes.Stsfld, getModuleInstanceField(clasz.symbol))
- }
- }
-
- } else {
-
- var doEmit = true
- getTypeOpt(msym.owner) match {
- case Some(typ) if (typ.IsEnum) => {
- def negBool() = {
- mcode.Emit(OpCodes.Ldc_I4_0)
- mcode.Emit(OpCodes.Ceq)
- }
- doEmit = false
- val name = msym.name
- if (name eq nme.EQ) { mcode.Emit(OpCodes.Ceq) }
- else if (name eq nme.NE) { mcode.Emit(OpCodes.Ceq); negBool }
- else if (name eq nme.LT) { mcode.Emit(OpCodes.Clt) }
- else if (name eq nme.LE) { mcode.Emit(OpCodes.Cgt); negBool }
- else if (name eq nme.GT) { mcode.Emit(OpCodes.Cgt) }
- else if (name eq nme.GE) { mcode.Emit(OpCodes.Clt); negBool }
- else if (name eq nme.OR) { mcode.Emit(OpCodes.Or) }
- else if (name eq nme.AND) { mcode.Emit(OpCodes.And) }
- else if (name eq nme.XOR) { mcode.Emit(OpCodes.Xor) }
- else
- doEmit = true
- }
- case _ => ()
- }
-
- // method: implicit view(FunctionX[PType0, PType1, ...,PTypeN, ResType]):DelegateType
- val (isDelegateView, paramType, resType) = beforeTyper {
- msym.tpe match {
- case MethodType(params, resultType)
- if (params.length == 1 && msym.name == nme.view_) =>
- val paramType = params(0).tpe
- val isDel = definitions.isCorrespondingDelegate(resultType, paramType)
- (isDel, paramType, resultType)
- case _ => (false, null, null)
- }
- }
- if (doEmit && isDelegateView) {
- doEmit = false
- createDelegateCaller(paramType, resType)
- }
-
- if (doEmit &&
- (msym.name == nme.PLUS || msym.name == nme.MINUS)
- && clrTypes.isDelegateType(msilType(msym.owner.tpe)))
- {
- doEmit = false
- val methodInfo: MethodInfo = getMethod(msym)
- // call it as a static method, even if the compiler (symbol) thinks it's virtual
- mcode.Emit(OpCodes.Call, methodInfo)
- mcode.Emit(OpCodes.Castclass, msilType(msym.owner.tpe))
- }
-
- if (doEmit && definitions.Delegate_scalaCallers.contains(msym)) {
- doEmit = false
- val methodSym: Symbol = definitions.Delegate_scalaCallerTargets(msym)
- val delegateType: Type = msym.tpe match {
- case MethodType(_, retType) => retType
- case _ => abort("not a method type: " + msym.tpe)
- }
- val methodInfo: MethodInfo = getMethod(methodSym)
- val delegCtor = msilType(delegateType).GetConstructor(Array(MOBJECT, INT_PTR))
- if (methodSym.isStatic) {
- mcode.Emit(OpCodes.Ldftn, methodInfo)
- } else {
- mcode.Emit(OpCodes.Dup)
- mcode.Emit(OpCodes.Ldvirtftn, methodInfo)
- }
- mcode.Emit(OpCodes.Newobj, delegCtor)
- }
-
- if (doEmit) {
- val methodInfo: MethodInfo = getMethod(msym)
- (style: @unchecked) match {
- case SuperCall(_) =>
- mcode.Emit(OpCodes.Call, methodInfo)
- case Dynamic =>
- // methodInfo.DeclaringType is null for global methods
- val isValuetypeMethod = (methodInfo.DeclaringType ne null) && (methodInfo.DeclaringType.IsValueType)
- val isValuetypeVirtualMethod = isValuetypeMethod && (methodInfo.IsVirtual)
- if (dynToStatMapped(msym)) {
- mcode.Emit(OpCodes.Call, methodInfo)
- } else if (isValuetypeVirtualMethod) {
- mcode.Emit(OpCodes.Constrained, methodInfo.DeclaringType)
- mcode.Emit(OpCodes.Callvirt, methodInfo)
- } else if (isValuetypeMethod) {
- // otherwise error "Callvirt on a value type method" ensues
- mcode.Emit(OpCodes.Call, methodInfo)
- } else {
- mcode.Emit(OpCodes.Callvirt, methodInfo)
- }
- case Static(_) =>
- if(methodInfo.IsVirtual && !mcode.Ldarg0WasJustEmitted) {
- mcode.Emit(OpCodes.Callvirt, methodInfo)
- } else mcode.Emit(OpCodes.Call, methodInfo)
- }
- }
- }
-
- case BOX(boxType) =>
- emitBox(mcode, boxType)
-
- case UNBOX(boxType) =>
- emitUnbox(mcode, boxType)
-
- case CIL_UNBOX(boxType) =>
- mcode.Emit(OpCodes.Unbox, msilType(boxType))
-
- case CIL_INITOBJ(valueType) =>
- mcode.Emit(OpCodes.Initobj, msilType(valueType))
-
- case NEW(REFERENCE(cls)) =>
- // the next instruction must be a DUP, see comment on `var previousWasNEW`
- previousWasNEW = true
-
- // works also for arrays and reference-types
- case CREATE_ARRAY(elem, dims) =>
- // TODO: handle multi dimensional arrays
- assert(dims == 1, "Can't handle multi dimensional arrays")
- mcode.Emit(OpCodes.Newarr, msilType(elem))
-
- // works for arrays and reference-types
- case IS_INSTANCE(tpe) =>
- mcode.Emit(OpCodes.Isinst, msilType(tpe))
- mcode.Emit(OpCodes.Ldnull)
- mcode.Emit(OpCodes.Ceq)
- mcode.Emit(OpCodes.Ldc_I4_0)
- mcode.Emit(OpCodes.Ceq)
-
- // works for arrays and reference-types
- // part from the scala reference: "S <: T does not imply
- // Array[S] <: Array[T] in Scala. However, it is possible
- // to cast an array of S to an array of T if such a cast
- // is permitted in the host environment."
- case CHECK_CAST(tpknd) =>
- val tMSIL = msilType(tpknd)
- mcode.Emit(OpCodes.Castclass, tMSIL)
-
- // no SWITCH is generated when there's
- // - a default case ("case _ => ...") in the matching expr
- // - OR is used ("case 1 | 2 => ...")
- case SWITCH(tags, branches) =>
- // tags is List[List[Int]]; a list of integers for every label.
- // if the int on stack is 4, and 4 is in the second list => jump
- // to second label
- // branches is List[BasicBlock]
- // the labels to jump to (the last one is the default one)
-
- val switchLocal = mcode.DeclareLocal(MINT)
- // several switch variables will appear with the same name in the
- // assembly code, but this makes no truble
- switchLocal.SetLocalSymInfo("$switch_var")
-
- mcode.Emit(OpCodes.Stloc, switchLocal)
- var i = 0
- for (l <- tags) {
- var targetLabel = labels(branches(i))
- for (i <- l) {
- mcode.Emit(OpCodes.Ldloc, switchLocal)
- loadI4(i, mcode)
- mcode.Emit(OpCodes.Beq, targetLabel)
- }
- i += 1
- }
- val defaultTarget = labels(branches(i))
- if (next != branches(i))
- mcode.Emit(OpCodes.Br, defaultTarget)
-
- case JUMP(whereto) =>
- val (leaveHandler, leaveFinally, lfTarget) = leavesHandler(block, whereto)
- if (leaveHandler) {
- if (leaveFinally) {
- if (lfTarget.isDefined) mcode.Emit(OpCodes.Leave, lfTarget.get)
- else mcode.Emit(OpCodes.Endfinally)
- } else
- mcode.Emit(OpCodes.Leave, labels(whereto))
- } else if (next != whereto)
- mcode.Emit(OpCodes.Br, labels(whereto))
-
- case CJUMP(success, failure, cond, kind) =>
- // cond is TestOp (see Primitives.scala), and can take
- // values EQ, NE, LT, GE LE, GT
- // kind is TypeKind
- val isFloat = kind == FLOAT || kind == DOUBLE
- val emit = (c: TestOp, l: Label) => emitBr(c, l, isFloat)
- emitCondBr(block, cond, success, failure, next, emit)
-
- case CZJUMP(success, failure, cond, kind) =>
- emitCondBr(block, cond, success, failure, next, emitBrBool(_, _))
-
- case RETURN(kind) =>
- if (currentHandlers.isEmpty)
- mcode.Emit(OpCodes.Ret)
- else {
- val (local, label) = returnFromHandler(kind)
- if (kind != UNIT)
- mcode.Emit(OpCodes.Stloc, local)
- mcode.Emit(OpCodes.Leave, label)
- }
-
- case THROW(_) =>
- mcode.Emit(OpCodes.Throw)
-
- case DROP(kind) =>
- mcode.Emit(OpCodes.Pop)
-
- case DUP(kind) =>
- // see comment on `var previousWasNEW`
- if (!previousWasNEW)
- mcode.Emit(OpCodes.Dup)
- else
- previousWasNEW = false
-
- case MONITOR_ENTER() =>
- mcode.Emit(OpCodes.Call, MMONITOR_ENTER)
-
- case MONITOR_EXIT() =>
- mcode.Emit(OpCodes.Call, MMONITOR_EXIT)
-
- case SCOPE_ENTER(_) | SCOPE_EXIT(_) | LOAD_EXCEPTION(_) =>
- ()
- }
-
- } // end for (instr <- b) { .. }
- } // end genBlock
-
- def genPrimitive(primitive: Primitive, pos: Position) {
- primitive match {
- case Negation(kind) =>
- kind match {
- // CHECK: is ist possible to get this for BOOL? in this case, verify.
- case BOOL | BYTE | CHAR | SHORT | INT | LONG | FLOAT | DOUBLE =>
- mcode.Emit(OpCodes.Neg)
-
- case _ => abort("Impossible to negate a " + kind)
- }
-
- case Arithmetic(op, kind) =>
- op match {
- case ADD => mcode.Emit(OpCodes.Add)
- case SUB => mcode.Emit(OpCodes.Sub)
- case MUL => mcode.Emit(OpCodes.Mul)
- case DIV => mcode.Emit(OpCodes.Div)
- case REM => mcode.Emit(OpCodes.Rem)
- case NOT => mcode.Emit(OpCodes.Not) //bitwise complement (one's complement)
- case _ => abort("Unknown arithmetic primitive " + primitive )
- }
-
- case Logical(op, kind) => op match {
- case AND => mcode.Emit(OpCodes.And)
- case OR => mcode.Emit(OpCodes.Or)
- case XOR => mcode.Emit(OpCodes.Xor)
- }
-
- case Shift(op, kind) => op match {
- case LSL => mcode.Emit(OpCodes.Shl)
- case ASR => mcode.Emit(OpCodes.Shr)
- case LSR => mcode.Emit(OpCodes.Shr_Un)
- }
-
- case Conversion(src, dst) =>
- debuglog("Converting from: " + src + " to: " + dst)
-
- dst match {
- case BYTE => mcode.Emit(OpCodes.Conv_I1) // I1 for System.SByte, i.e. a scala.Byte
- case SHORT => mcode.Emit(OpCodes.Conv_I2)
- case CHAR => mcode.Emit(OpCodes.Conv_U2)
- case INT => mcode.Emit(OpCodes.Conv_I4)
- case LONG => mcode.Emit(OpCodes.Conv_I8)
- case FLOAT => mcode.Emit(OpCodes.Conv_R4)
- case DOUBLE => mcode.Emit(OpCodes.Conv_R8)
- case _ =>
- Console.println("Illegal conversion at: " + clasz +
- " at: " + pos.source + ":" + pos.line)
- }
-
- case ArrayLength(_) =>
- mcode.Emit(OpCodes.Ldlen)
-
- case StartConcat =>
- mcode.Emit(OpCodes.Newobj, MSTRING_BUILDER_CONSTR)
-
-
- case StringConcat(el) =>
- val elemType : MsilType = el match {
- case REFERENCE(_) | ARRAY(_) => MOBJECT
- case _ => msilType(el)
- }
-
- val argTypes:Array[MsilType] = Array(elemType)
- val stringBuilderAppend = MSTRING_BUILDER.GetMethod("Append", argTypes )
- mcode.Emit(OpCodes.Callvirt, stringBuilderAppend)
-
- case EndConcat =>
- mcode.Emit(OpCodes.Callvirt, MSTRING_BUILDER_TOSTRING)
-
- case _ =>
- abort("Unimplemented primitive " + primitive)
- }
- } // end genPrimitive
-
-
- ////////////////////// loading ///////////////////////
-
- def loadI4(value: Int, code: ILGenerator): Unit = value match {
- case -1 => code.Emit(OpCodes.Ldc_I4_M1)
- case 0 => code.Emit(OpCodes.Ldc_I4_0)
- case 1 => code.Emit(OpCodes.Ldc_I4_1)
- case 2 => code.Emit(OpCodes.Ldc_I4_2)
- case 3 => code.Emit(OpCodes.Ldc_I4_3)
- case 4 => code.Emit(OpCodes.Ldc_I4_4)
- case 5 => code.Emit(OpCodes.Ldc_I4_5)
- case 6 => code.Emit(OpCodes.Ldc_I4_6)
- case 7 => code.Emit(OpCodes.Ldc_I4_7)
- case 8 => code.Emit(OpCodes.Ldc_I4_8)
- case _ =>
- if (value >= -128 && value <= 127)
- code.Emit(OpCodes.Ldc_I4_S, value)
- else
- code.Emit(OpCodes.Ldc_I4, value)
- }
-
- def loadArg(code: ILGenerator, loadAddr: Boolean)(i: Int) =
- if (loadAddr) {
- if (i >= -128 && i <= 127)
- code.Emit(OpCodes.Ldarga_S, i)
- else
- code.Emit(OpCodes.Ldarga, i)
- } else {
- i match {
- case 0 => code.Emit(OpCodes.Ldarg_0)
- case 1 => code.Emit(OpCodes.Ldarg_1)
- case 2 => code.Emit(OpCodes.Ldarg_2)
- case 3 => code.Emit(OpCodes.Ldarg_3)
- case _ =>
- if (i >= -128 && i <= 127)
- code.Emit(OpCodes.Ldarg_S, i)
- else
- code.Emit(OpCodes.Ldarg, i)
- }
- }
-
- def loadLocal(i: Int, local: Local, code: ILGenerator, loadAddr: Boolean) =
- if (loadAddr) {
- if (i >= -128 && i <= 127)
- code.Emit(OpCodes.Ldloca_S, localBuilders(local))
- else
- code.Emit(OpCodes.Ldloca, localBuilders(local))
- } else {
- i match {
- case 0 => code.Emit(OpCodes.Ldloc_0)
- case 1 => code.Emit(OpCodes.Ldloc_1)
- case 2 => code.Emit(OpCodes.Ldloc_2)
- case 3 => code.Emit(OpCodes.Ldloc_3)
- case _ =>
- if (i >= -128 && i <= 127)
- code.Emit(OpCodes.Ldloc_S, localBuilders(local))
- else
- code.Emit(OpCodes.Ldloc, localBuilders(local))
- }
- }
-
- ////////////////////// branches ///////////////////////
-
- /** Returns a Triple (Boolean, Boolean, Option[Label])
- * - whether the jump leaves some exception block (try / catch / finally)
- * - whether it leaves a finally handler (finally block, but not it's try / catch)
- * - a label where to jump for leaving the finally handler
- * . None to leave directly using `endfinally`
- * . Some(label) to emit `leave label` (for try / catch inside a finally handler)
- */
- def leavesHandler(from: BasicBlock, to: BasicBlock): (Boolean, Boolean, Option[Label]) =
- if (currentHandlers.isEmpty) (false, false, None)
- else {
- val h = currentHandlers.head
- val leaveHead = { h.covers(from) != h.covers(to) ||
- h.blocks.contains(from) != h.blocks.contains(to) }
- if (leaveHead) {
- // we leave the innermost exception block.
- // find out if we also leave som e `finally` handler
- currentHandlers.find(e => {
- e.cls == NoSymbol && e.blocks.contains(from) != e.blocks.contains(to)
- }) match {
- case Some(finallyHandler) =>
- if (h == finallyHandler) {
- // the finally handler is the innermost, so we can emit `endfinally` directly
- (true, true, None)
- } else {
- // we need to `Leave` to the `endfinally` of the next outer finally handler
- val l = endFinallyLabels.getOrElseUpdate(finallyHandler, mcode.DefineLabel())
- (true, true, Some(l))
- }
- case None =>
- (true, false, None)
- }
- } else (false, false, None)
- }
-
- def emitCondBr(block: BasicBlock, cond: TestOp, success: BasicBlock, failure: BasicBlock,
- next: BasicBlock, emitBrFun: (TestOp, Label) => Unit) {
- val (sLeaveHandler, sLeaveFinally, slfTarget) = leavesHandler(block, success)
- val (fLeaveHandler, fLeaveFinally, flfTarget) = leavesHandler(block, failure)
-
- if (sLeaveHandler || fLeaveHandler) {
- val sLabelOpt = if (sLeaveHandler) {
- val leaveSLabel = mcode.DefineLabel()
- emitBrFun(cond, leaveSLabel)
- Some(leaveSLabel)
- } else {
- emitBrFun(cond, labels(success))
- None
- }
-
- if (fLeaveHandler) {
- if (fLeaveFinally) {
- if (flfTarget.isDefined) mcode.Emit(OpCodes.Leave, flfTarget.get)
- else mcode.Emit(OpCodes.Endfinally)
- } else
- mcode.Emit(OpCodes.Leave, labels(failure))
- } else
- mcode.Emit(OpCodes.Br, labels(failure))
-
- sLabelOpt.map(l => {
- mcode.MarkLabel(l)
- if (sLeaveFinally) {
- if (slfTarget.isDefined) mcode.Emit(OpCodes.Leave, slfTarget.get)
- else mcode.Emit(OpCodes.Endfinally)
- } else
- mcode.Emit(OpCodes.Leave, labels(success))
- })
- } else {
- if (next == success) {
- emitBrFun(cond.negate, labels(failure))
- } else {
- emitBrFun(cond, labels(success))
- if (next != failure) {
- mcode.Emit(OpCodes.Br, labels(failure))
- }
- }
- }
- }
-
- def emitBr(condition: TestOp, dest: Label, isFloat: Boolean) {
- condition match {
- case EQ => mcode.Emit(OpCodes.Beq, dest)
- case NE => mcode.Emit(OpCodes.Bne_Un, dest)
- case LT => mcode.Emit(if (isFloat) OpCodes.Blt_Un else OpCodes.Blt, dest)
- case GE => mcode.Emit(if (isFloat) OpCodes.Bge_Un else OpCodes.Bge, dest)
- case LE => mcode.Emit(if (isFloat) OpCodes.Ble_Un else OpCodes.Ble, dest)
- case GT => mcode.Emit(if (isFloat) OpCodes.Bgt_Un else OpCodes.Bgt, dest)
- }
- }
-
- def emitBrBool(cond: TestOp, dest: Label) {
- (cond: @unchecked) match {
- // EQ -> Brfalse, NE -> Brtrue; this is because we come from
- // a CZJUMP. If the value on the stack is 0 (e.g. a boolean
- // method returned false), and we are in the case EQ, then
- // we need to emit Brfalse (EQ Zero means false). vice versa
- case EQ => mcode.Emit(OpCodes.Brfalse, dest)
- case NE => mcode.Emit(OpCodes.Brtrue, dest)
- }
- }
-
- ////////////////////// local vars ///////////////////////
-
- /**
- * Compute the indexes of each local variable of the given
- * method.
- */
- def computeLocalVarsIndex(m: IMethod) {
- var idx = if (m.symbol.isStaticMember) 0 else 1
-
- val params = m.params
- for (l <- params) {
- debuglog("Index value for parameter " + l + ": " + idx)
- l.index = idx
- idx += 1 // sizeOf(l.kind)
- }
-
- val locvars = m.locals filterNot (params contains)
- idx = 0
-
- for (l <- locvars) {
- debuglog("Index value for local variable " + l + ": " + idx)
- l.index = idx
- idx += 1 // sizeOf(l.kind)
- }
-
- }
-
- ////////////////////// Utilities ////////////////////////
-
- /** Return the a name of this symbol that can be used on the .NET
- * platform. It removes spaces from names.
- *
- * Special handling: scala.All and scala.AllRef are 'erased' to
- * scala.All$ and scala.AllRef$. This is needed because they are
- * not real classes, and they mean 'abrupt termination upon evaluation
- * of that expression' or 'null' respectively. This handling is
- * done already in GenICode, but here we need to remove references
- * from method signatures to these types, because such classes can
- * not exist in the classpath: the type checker will be very confused.
- */
- def msilName(sym: Symbol): String = {
- val suffix = sym.moduleSuffix
- // Flags.JAVA: "symbol was not defined by a scala-class" (java, or .net-class)
-
- if (sym == definitions.NothingClass)
- return "scala.runtime.Nothing$"
- else if (sym == definitions.NullClass)
- return "scala.runtime.Null$"
-
- (if (sym.isClass || (sym.isModule && !sym.isMethod)) {
- if (sym.isNestedClass) sym.simpleName
- else sym.fullName
- } else
- sym.simpleName.toString.trim()) + suffix
- }
-
-
- ////////////////////// flags ///////////////////////
-
- def msilTypeFlags(sym: Symbol): Int = {
- var mf: Int = TypeAttributes.AutoLayout | TypeAttributes.AnsiClass
-
- if(sym.isNestedClass) {
- mf = mf | (if (sym hasFlag Flags.PRIVATE) TypeAttributes.NestedPrivate else TypeAttributes.NestedPublic)
- } else {
- mf = mf | (if (sym hasFlag Flags.PRIVATE) TypeAttributes.NotPublic else TypeAttributes.Public)
- }
- mf = mf | (if (sym hasFlag Flags.ABSTRACT) TypeAttributes.Abstract else 0)
- mf = mf | (if (sym.isTrait && !sym.isImplClass) TypeAttributes.Interface else TypeAttributes.Class)
- mf = mf | (if (sym isFinal) TypeAttributes.Sealed else 0)
-
- sym.annotations foreach { a => a match {
- case AnnotationInfo(SerializableAttr, _, _) =>
- // TODO: add the Serializable TypeAttribute also if the annotation
- // System.SerializableAttribute is present (.net annotation, not scala)
- // Best way to do it: compare with
- // definitions.getClass("System.SerializableAttribute").tpe
- // when frontend available
- mf = mf | TypeAttributes.Serializable
- case _ => ()
- }}
-
- mf
- // static: not possible (or?)
- }
-
- def msilMethodFlags(sym: Symbol): Short = {
- var mf: Int = MethodAttributes.HideBySig |
- (if (sym hasFlag Flags.PRIVATE) MethodAttributes.Private
- else MethodAttributes.Public)
-
- if (!sym.isClassConstructor) {
- if (sym.isStaticMember)
- mf = mf | FieldAttributes.Static // coincidentally, same value as for MethodAttributes.Static ...
- else {
- mf = mf | MethodAttributes.Virtual
- if (sym.isFinal && !getType(sym.owner).IsInterface)
- mf = mf | MethodAttributes.Final
- if (sym.isDeferred || getType(sym.owner).IsInterface)
- mf = mf | MethodAttributes.Abstract
- }
- }
-
- if (sym.isStaticMember) {
- mf = mf | MethodAttributes.Static
- }
-
- // constructors of module classes should be private
- if (sym.isPrimaryConstructor && isTopLevelModule(sym.owner)) {
- mf |= MethodAttributes.Private
- mf &= ~(MethodAttributes.Public)
- }
-
- mf.toShort
- }
-
- def msilFieldFlags(sym: Symbol): Short = {
- var mf: Int =
- if (sym hasFlag Flags.PRIVATE) FieldAttributes.Private
- else if (sym hasFlag Flags.PROTECTED) FieldAttributes.FamORAssem
- else FieldAttributes.Public
-
- if (sym hasFlag Flags.FINAL)
- mf = mf | FieldAttributes.InitOnly
-
- if (sym.isStaticMember)
- mf = mf | FieldAttributes.Static
-
- // TRANSIENT: "not serialized", VOLATILE: doesn't exist on .net
- // TODO: add this annotation also if the class has the custom attribute
- // System.NotSerializedAttribute
- sym.annotations.foreach( a => a match {
- case AnnotationInfo(TransientAtt, _, _) =>
- mf = mf | FieldAttributes.NotSerialized
- case _ => ()
- })
-
- mf.toShort
- }
-
- ////////////////////// builders, types ///////////////////////
-
- var entryPoint: Symbol = _
-
- val notInitializedModules = mutable.HashSet[Symbol]()
-
- // TODO: create fields also in def createType, and not in genClass,
- // add a getField method (it only works as it is because fields never
- // accessed from outside a class)
-
- val localBuilders = mutable.HashMap[Local, LocalBuilder]()
-
- private[GenMSIL] def findEntryPoint(cls: IClass) {
-
- def isEntryPoint(sym: Symbol):Boolean = {
- if (isStaticModule(sym.owner) && msilName(sym) == "main")
- if (sym.tpe.paramTypes.length == 1) {
- toTypeKind(sym.tpe.paramTypes(0)) match {
- case ARRAY(elem) =>
- if (elem.toType.typeSymbol == definitions.StringClass) {
- return true
- }
- case _ => ()
- }
- }
- false
- }
-
- if((entryPoint == null) && opt.showClass.isDefined) { // TODO introduce dedicated setting instead
- val entryclass = opt.showClass.get.toString
- val cfn = cls.symbol.fullName
- if(cfn == entryclass) {
- for (m <- cls.methods; if isEntryPoint(m.symbol)) { entryPoint = m.symbol }
- if(entryPoint == null) { warning("Couldn't find main method in class " + cfn) }
- }
- }
-
- if (firstSourceName == "")
- if (cls.symbol.sourceFile != null) // is null for nested classes
- firstSourceName = cls.symbol.sourceFile.name
- }
-
- // #####################################################################
- // get and create types
-
- private def msilType(t: TypeKind): MsilType = (t: @unchecked) match {
- case UNIT => MVOID
- case BOOL => MBOOL
- case BYTE => MBYTE
- case SHORT => MSHORT
- case CHAR => MCHAR
- case INT => MINT
- case LONG => MLONG
- case FLOAT => MFLOAT
- case DOUBLE => MDOUBLE
- case REFERENCE(cls) => getType(cls)
- case ARRAY(elem) =>
- msilType(elem) match {
- // For type builders, cannot call "clrTypes.mkArrayType" because this looks up
- // the type "tp" in the assembly (not in the HashMap "types" of the backend).
- // This can fail for nested types because the builders are not complete yet.
- case tb: TypeBuilder => tb.MakeArrayType()
- case tp: MsilType => clrTypes.mkArrayType(tp)
- }
- }
-
- private def msilType(tpe: Type): MsilType = msilType(toTypeKind(tpe))
-
- private def msilParamTypes(sym: Symbol): Array[MsilType] = {
- sym.tpe.paramTypes.map(msilType).toArray
- }
-
- def getType(sym: Symbol) = getTypeOpt(sym).getOrElse(abort(showsym(sym)))
-
- /**
- * Get an MSIL type from a symbol. First look in the clrTypes.types map, then
- * lookup the name using clrTypes.getType
- */
- def getTypeOpt(sym: Symbol): Option[MsilType] = {
- val tmp = types.get(sym)
- tmp match {
- case typ @ Some(_) => typ
- case None =>
- def typeString(sym: Symbol): String = {
- val s = if (sym.isNestedClass) typeString(sym.owner) +"+"+ sym.simpleName
- else sym.fullName
- if (sym.isModuleClass && !sym.isTrait) s + "$" else s
- }
- val name = typeString(sym)
- val typ = clrTypes.getType(name)
- if (typ == null)
- None
- else {
- types(sym) = typ
- Some(typ)
- }
- }
- }
-
- def mapType(sym: Symbol, mType: MsilType) {
- assert(mType != null, showsym(sym))
- types(sym) = mType
- }
-
- def createTypeBuilder(iclass: IClass) {
- /**
- * First look in the clrTypes.types map, if that fails check if it's a class being compiled, otherwise
- * lookup by name (clrTypes.getType calls the static method msil.Type.GetType(fullname)).
- */
- def msilTypeFromSym(sym: Symbol): MsilType = {
- types.get(sym).getOrElse {
- classes.get(sym) match {
- case Some(iclass) =>
- msilTypeBuilderFromSym(sym)
- case None =>
- getType(sym)
- }
- }
- }
-
- def msilTypeBuilderFromSym(sym: Symbol): TypeBuilder = {
- if(!(types.contains(sym) && types(sym).isInstanceOf[TypeBuilder])){
- val iclass = classes(sym)
- assert(iclass != null)
- createTypeBuilder(iclass)
- }
- types(sym).asInstanceOf[TypeBuilder]
- }
-
- val sym = iclass.symbol
- if (types.contains(sym) && types(sym).isInstanceOf[TypeBuilder])
- return
-
- def isInterface(s: Symbol) = s.isTrait && !s.isImplClass
- val parents: List[Type] =
- if (sym.info.parents.isEmpty) List(definitions.ObjectClass.tpe)
- else sym.info.parents.distinct
-
- val superType : MsilType = if (isInterface(sym)) null else msilTypeFromSym(parents.head.typeSymbol)
- debuglog("super type: " + parents(0).typeSymbol + ", msil type: " + superType)
-
- val interfaces: Array[MsilType] =
- parents.tail.map(p => msilTypeFromSym(p.typeSymbol)).toArray
- if (parents.length > 1) {
- if (settings.debug.value) {
- log("interfaces:")
- for (i <- 0.until(interfaces.length)) {
- log(" type: " + parents(i + 1).typeSymbol + ", msil type: " + interfaces(i))
- }
- }
- }
-
- val tBuilder = if (sym.isNestedClass) {
- val ownerT = msilTypeBuilderFromSym(sym.owner).asInstanceOf[TypeBuilder]
- ownerT.DefineNestedType(msilName(sym), msilTypeFlags(sym), superType, interfaces)
- } else {
- mmodule.DefineType(msilName(sym), msilTypeFlags(sym), superType, interfaces)
- }
- mapType(sym, tBuilder)
- } // createTypeBuilder
-
- def createClassMembers(iclass: IClass) {
- try {
- createClassMembers0(iclass)
- }
- catch {
- case e: Throwable =>
- java.lang.System.err.println(showsym(iclass.symbol))
- java.lang.System.err.println("with methods = " + iclass.methods)
- throw e
- }
- }
-
- def createClassMembers0(iclass: IClass) {
-
- val mtype = getType(iclass.symbol).asInstanceOf[TypeBuilder]
-
- for (ifield <- iclass.fields) {
- val sym = ifield.symbol
- debuglog("Adding field: " + sym.fullName)
-
- var attributes = msilFieldFlags(sym)
- val fieldTypeWithCustomMods =
- new PECustomMod(msilType(sym.tpe),
- customModifiers(sym.annotations))
- val fBuilder = mtype.DefineField(msilName(sym),
- fieldTypeWithCustomMods,
- attributes)
- fields(sym) = fBuilder
- addAttributes(fBuilder, sym.annotations)
- } // all iclass.fields iterated over
-
- if (isStaticModule(iclass.symbol)) {
- val sc = iclass.lookupStaticCtor
- if (sc.isDefined) {
- val m = sc.get
- val oldLastBlock = m.lastBlock
- val lastBlock = m.newBlock()
- oldLastBlock.replaceInstruction(oldLastBlock.length - 1, JUMP(lastBlock))
- // call object's private ctor from static ctor
- lastBlock.emit(CIL_NEWOBJ(iclass.symbol.primaryConstructor))
- lastBlock.emit(DROP(toTypeKind(iclass.symbol.tpe)))
- lastBlock emit RETURN(UNIT)
- lastBlock.close
- }
- }
-
- if (iclass.symbol != definitions.ArrayClass) {
- for (m: IMethod <- iclass.methods) {
- val sym = m.symbol
- debuglog("Creating MethodBuilder for " + Flags.flagsToString(sym.flags) + " " +
- sym.owner.fullName + "::" + sym.name)
-
- val ownerType = getType(sym.enclClass).asInstanceOf[TypeBuilder]
- assert(mtype == ownerType, "mtype = " + mtype + "; ownerType = " + ownerType)
- var paramTypes = msilParamTypes(sym)
- val attr = msilMethodFlags(sym)
-
- if (m.symbol.isClassConstructor) {
- val constr =
- ownerType.DefineConstructor(attr, CallingConventions.Standard, paramTypes)
- for (i <- 0.until(paramTypes.length)) {
- constr.DefineParameter(i, ParameterAttributes.None, msilName(m.params(i).sym))
- }
- mapConstructor(sym, constr)
- addAttributes(constr, sym.annotations)
- } else {
- var resType = msilType(m.returnType)
- val method =
- ownerType.DefineMethod(msilName(sym), attr, resType, paramTypes)
- for (i <- 0.until(paramTypes.length)) {
- method.DefineParameter(i, ParameterAttributes.None, msilName(m.params(i).sym))
- }
- if (!methods.contains(sym))
- mapMethod(sym, method)
- addAttributes(method, sym.annotations)
- debuglog("\t created MethodBuilder " + method)
- }
- }
- } // method builders created for non-array iclass
-
- if (isStaticModule(iclass.symbol)) {
- addModuleInstanceField(iclass.symbol)
- notInitializedModules += iclass.symbol
- if (iclass.lookupStaticCtor.isEmpty) {
- addStaticInit(iclass.symbol)
- }
- }
-
- } // createClassMembers0
-
- private def isTopLevelModule(sym: Symbol): Boolean =
- beforeRefchecks {
- sym.isModuleClass && !sym.isImplClass && !sym.isNestedClass
- }
-
- // if the module is lifted it does not need to be initialized in
- // its static constructor, and the MODULE$ field is not required.
- // the outer class will care about it.
- private def isStaticModule(sym: Symbol): Boolean = {
- // .net inner classes: removed '!sym.hasFlag(Flags.LIFTED)', added
- // 'sym.isStatic'. -> no longer compatible without skipping flatten!
- sym.isModuleClass && sym.isStatic && !sym.isImplClass
- }
-
- private def isCloneable(sym: Symbol): Boolean = {
- !sym.annotations.forall( a => a match {
- case AnnotationInfo(CloneableAttr, _, _) => false
- case _ => true
- })
- }
-
- private def addModuleInstanceField(sym: Symbol) {
- debuglog("Adding Module-Instance Field for " + showsym(sym))
- val tBuilder = getType(sym).asInstanceOf[TypeBuilder]
- val fb = tBuilder.DefineField(MODULE_INSTANCE_NAME,
- tBuilder,
- (FieldAttributes.Public |
- //FieldAttributes.InitOnly |
- FieldAttributes.Static).toShort)
- fields(sym) = fb
- }
-
-
- // the symbol may be a object-symbol (module-symbol), or a module-class-symbol
- private def getModuleInstanceField(sym: Symbol): FieldInfo = {
- assert(sym.isModule || sym.isModuleClass, "Expected module: " + showsym(sym))
-
- // when called by LOAD_MODULE, the corresponding type maybe doesn't
- // exist yet -> make a getType
- val moduleClassSym = if (sym.isModule) sym.moduleClass else sym
-
- // TODO: get module field for modules not defined in the
- // source currently compiling (e.g. Console)
-
- fields get moduleClassSym match {
- case Some(sym) => sym
- case None =>
- //val mclass = types(moduleClassSym)
- val nameInMetadata = nestingAwareFullClassname(moduleClassSym)
- val mClass = clrTypes.getType(nameInMetadata)
- val mfield = mClass.GetField("MODULE$")
- assert(mfield ne null, "module not found " + showsym(moduleClassSym))
- fields(moduleClassSym) = mfield
- mfield
- }
-
- //fields(moduleClassSym)
- }
-
- def nestingAwareFullClassname(csym: Symbol) : String = {
- val suffix = csym.moduleSuffix
- val res = if (csym.isNestedClass)
- nestingAwareFullClassname(csym.owner) + "+" + csym.encodedName
- else
- csym.fullName
- res + suffix
- }
-
- /** Adds a static initializer which creates an instance of the module
- * class (calls the primary constructor). A special primary constructor
- * will be generated (notInitializedModules) which stores the new instance
- * in the MODULE$ field right after the super call.
- */
- private def addStaticInit(sym: Symbol) {
- val tBuilder = getType(sym).asInstanceOf[TypeBuilder]
-
- val staticInit = tBuilder.DefineConstructor(
- (MethodAttributes.Static | MethodAttributes.Public).toShort,
- CallingConventions.Standard,
- MsilType.EmptyTypes)
-
- val sicode = staticInit.GetILGenerator()
-
- val instanceConstructor = constructors(sym.primaryConstructor)
-
- // there are no constructor parameters. assuming the constructor takes no parameter
- // is fine: we call (in the static constructor) the constructor of the module class,
- // which takes no arguments - an object definition cannot take constructor arguments.
- sicode.Emit(OpCodes.Newobj, instanceConstructor)
- // the stsfld is done in the instance constructor, just after the super call.
- sicode.Emit(OpCodes.Pop)
-
- sicode.Emit(OpCodes.Ret)
- }
-
- private def generateMirrorClass(sym: Symbol) {
- val tBuilder = getType(sym)
- assert(sym.isModuleClass, "Can't generate Mirror-Class for the Non-Module class " + sym)
- debuglog("Dumping mirror class for object: " + sym)
- val moduleName = msilName(sym)
- val mirrorName = moduleName.substring(0, moduleName.length() - 1)
- val mirrorTypeBuilder = mmodule.DefineType(mirrorName,
- TypeAttributes.Class |
- TypeAttributes.Public |
- TypeAttributes.Sealed,
- MOBJECT,
- MsilType.EmptyTypes)
-
- val iclass = classes(sym)
-
- for (m <- sym.tpe.nonPrivateMembers
- if m.owner != definitions.ObjectClass && !m.isProtected &&
- m.isMethod && !m.isClassConstructor && !m.isStaticMember && !m.isCase &&
- !m.isDeferred)
- {
- debuglog(" Mirroring method: " + m)
- val paramTypes = msilParamTypes(m)
- val paramNames: Array[String] = new Array[String](paramTypes.length)
- for (i <- 0 until paramTypes.length)
- paramNames(i) = "x_" + i
-
- // CHECK: verify if getMethodName is better than msilName
- val mirrorMethod = mirrorTypeBuilder.DefineMethod(msilName(m),
- (MethodAttributes.Public |
- MethodAttributes.Static).toShort,
- msilType(m.tpe.resultType),
- paramTypes)
-
- var i = 0
- while (i < paramTypes.length) {
- mirrorMethod.DefineParameter(i, ParameterAttributes.None, paramNames(i))
- i += 1
- }
-
- val mirrorCode = mirrorMethod.GetILGenerator()
- mirrorCode.Emit(OpCodes.Ldsfld, getModuleInstanceField(sym))
- val mInfo = getMethod(m)
- for (paramidx <- 0.until(paramTypes.length)) {
- val mInfoParams = mInfo.GetParameters
- val loadAddr = mInfoParams(paramidx).ParameterType.IsByRef
- loadArg(mirrorCode, loadAddr)(paramidx)
- }
-
- mirrorCode.Emit(OpCodes.Callvirt, getMethod(m))
- mirrorCode.Emit(OpCodes.Ret)
- }
-
- addSymtabAttribute(sym.sourceModule, mirrorTypeBuilder)
-
- mirrorTypeBuilder.CreateType()
- mirrorTypeBuilder.setSourceFilepath(iclass.cunit.source.file.path)
- }
-
-
- // #####################################################################
- // delegate callers
-
- var delegateCallers: TypeBuilder = _
- var nbDelegateCallers: Int = 0
-
- private def initDelegateCallers() = {
- delegateCallers = mmodule.DefineType("$DelegateCallers", TypeAttributes.Public |
- TypeAttributes.Sealed)
- }
-
- private def createDelegateCaller(functionType: Type, delegateType: Type) = {
- if (delegateCallers == null)
- initDelegateCallers()
- // create a field an store the function-object
- val mFunctionType: MsilType = msilType(functionType)
- val anonfunField: FieldBuilder = delegateCallers.DefineField(
- "$anonfunField$$" + nbDelegateCallers, mFunctionType,
- (FieldAttributes.InitOnly | FieldAttributes.Public | FieldAttributes.Static).toShort)
- mcode.Emit(OpCodes.Stsfld, anonfunField)
-
-
- // create the static caller method and the delegate object
- val (params, returnType) = delegateType.member(nme.apply).tpe match {
- case MethodType(delParams, delReturn) => (delParams, delReturn)
- case _ => abort("not a delegate type: " + delegateType)
- }
- val caller: MethodBuilder = delegateCallers.DefineMethod(
- "$delegateCaller$$" + nbDelegateCallers,
- (MethodAttributes.Final | MethodAttributes.Public | MethodAttributes.Static).toShort,
- msilType(returnType), (params map (_.tpe)).map(msilType).toArray)
- for (i <- 0 until params.length)
- caller.DefineParameter(i, ParameterAttributes.None, "arg" + i) // FIXME: use name of parameter symbol
- val delegCtor = msilType(delegateType).GetConstructor(Array(MOBJECT, INT_PTR))
- mcode.Emit(OpCodes.Ldnull)
- mcode.Emit(OpCodes.Ldftn, caller)
- mcode.Emit(OpCodes.Newobj, delegCtor)
-
-
- // create the static caller method body
- val functionApply: MethodInfo = getMethod(functionType.member(nme.apply))
- val dcode: ILGenerator = caller.GetILGenerator()
- dcode.Emit(OpCodes.Ldsfld, anonfunField)
- for (i <- 0 until params.length) {
- loadArg(dcode, false /* TODO confirm whether passing actual as-is to formal is correct wrt the ByRef attribute of the param */)(i)
- emitBox(dcode, toTypeKind(params(i).tpe))
- }
- dcode.Emit(OpCodes.Callvirt, functionApply)
- emitUnbox(dcode, toTypeKind(returnType))
- dcode.Emit(OpCodes.Ret)
-
- nbDelegateCallers = nbDelegateCallers + 1
-
- } //def createDelegateCaller
-
- def emitBox(code: ILGenerator, boxType: TypeKind) = (boxType: @unchecked) match {
- // doesn't make sense, unit as parameter..
- case UNIT => code.Emit(OpCodes.Ldsfld, boxedUnit)
- case BOOL | BYTE | SHORT | CHAR | INT | LONG | FLOAT | DOUBLE =>
- code.Emit(OpCodes.Box, msilType(boxType))
- case REFERENCE(cls) if clrTypes.isValueType(cls) =>
- code.Emit(OpCodes.Box, (msilType(boxType)))
- case REFERENCE(_) | ARRAY(_) =>
- warning("Tried to BOX a non-valuetype.")
- ()
- }
-
- def emitUnbox(code: ILGenerator, boxType: TypeKind) = (boxType: @unchecked) match {
- case UNIT => code.Emit(OpCodes.Pop)
- /* (1) it's essential to keep the code emitted here (as of now plain calls to System.Convert.ToBlaBla methods)
- behaviorally.equiv.wrt. BoxesRunTime.unboxToBlaBla methods
- (case null: that's easy, case boxed: track changes to unboxBlaBla)
- (2) See also: asInstanceOf to cast from Any to number,
- tracked in http://lampsvn.epfl.ch/trac/scala/ticket/4437 */
- case BOOL => code.Emit(OpCodes.Call, toBool)
- case BYTE => code.Emit(OpCodes.Call, toSByte)
- case SHORT => code.Emit(OpCodes.Call, toShort)
- case CHAR => code.Emit(OpCodes.Call, toChar)
- case INT => code.Emit(OpCodes.Call, toInt)
- case LONG => code.Emit(OpCodes.Call, toLong)
- case FLOAT => code.Emit(OpCodes.Call, toFloat)
- case DOUBLE => code.Emit(OpCodes.Call, toDouble)
- case REFERENCE(cls) if clrTypes.isValueType(cls) =>
- code.Emit(OpCodes.Unbox, msilType(boxType))
- code.Emit(OpCodes.Ldobj, msilType(boxType))
- case REFERENCE(_) | ARRAY(_) =>
- warning("Tried to UNBOX a non-valuetype.")
- ()
- }
-
- // #####################################################################
- // get and create methods / constructors
-
- def getConstructor(sym: Symbol): ConstructorInfo = constructors.get(sym) match {
- case Some(constr) => constr
- case None =>
- val mClass = getType(sym.owner)
- val constr = mClass.GetConstructor(msilParamTypes(sym))
- if (constr eq null) {
- java.lang.System.out.println("Cannot find constructor " + sym.owner + "::" + sym.name)
- java.lang.System.out.println("scope = " + sym.owner.tpe.decls)
- abort(sym.fullName)
- }
- else {
- mapConstructor(sym, constr)
- constr
- }
- }
-
- def mapConstructor(sym: Symbol, cInfo: ConstructorInfo) = {
- constructors(sym) = cInfo
- }
-
- private def getMethod(sym: Symbol): MethodInfo = {
-
- methods.get(sym) match {
- case Some(method) => method
- case None =>
- val mClass = getType(sym.owner)
- try {
- val method = mClass.GetMethod(msilName(sym), msilParamTypes(sym),
- msilType(sym.tpe.resultType))
- if (method eq null) {
- java.lang.System.out.println("Cannot find method " + sym.owner + "::" + msilName(sym))
- java.lang.System.out.println("scope = " + sym.owner.tpe.decls)
- abort(sym.fullName)
- }
- else {
- mapMethod(sym, method)
- method
- }
- }
- catch {
- case e: Exception =>
- Console.println("While looking up " + mClass + "::" + sym.nameString)
- Console.println("\t" + showsym(sym))
- throw e
- }
- }
- }
-
- /*
- * add a mapping between sym and mInfo
- */
- private def mapMethod(sym: Symbol, mInfo: MethodInfo) {
- assert (mInfo != null, mInfo)
- methods(sym) = mInfo
- }
-
- /*
- * add mapping between sym and method with newName, paramTypes of newClass
- */
- private def mapMethod(sym: Symbol, newClass: MsilType, newName: String, paramTypes: Array[MsilType]) {
- val methodInfo = newClass.GetMethod(newName, paramTypes)
- assert(methodInfo != null, "Can't find mapping for " + sym + " -> " +
- newName + "(" + paramTypes + ")")
- mapMethod(sym, methodInfo)
- if (methodInfo.IsStatic)
- dynToStatMapped += sym
- }
-
- /*
- * add mapping between method with name and paramTypes of clazz to
- * method with newName and newParamTypes of newClass (used for instance
- * for "wait")
- */
- private def mapMethod(
- clazz: Symbol, name: Name, paramTypes: Array[Type],
- newClass: MsilType, newName: String, newParamTypes: Array[MsilType]) {
- val methodSym = lookupMethod(clazz, name, paramTypes)
- assert(methodSym != null, "cannot find method " + name + "(" +
- paramTypes + ")" + " in class " + clazz)
- mapMethod(methodSym, newClass, newName, newParamTypes)
- }
-
- /*
- * add mapping for member with name and paramTypes to member
- * newName of newClass (same parameters)
- */
- private def mapMethod(
- clazz: Symbol, name: Name, paramTypes: Array[Type],
- newClass: MsilType, newName: String) {
- mapMethod(clazz, name, paramTypes, newClass, newName, paramTypes map msilType)
- }
-
- /*
- * add mapping for all methods with name of clazz to the corresponding
- * method (same parameters) with newName of newClass
- */
- private def mapMethod(
- clazz: Symbol, name: Name,
- newClass: MsilType, newName: String) {
- val memberSym: Symbol = clazz.tpe.member(name)
- memberSym.tpe match {
- // alternatives: List[Symbol]
- case OverloadedType(_, alternatives) =>
- alternatives.foreach(s => mapMethod(s, newClass, newName, msilParamTypes(s)))
-
- // paramTypes: List[Type], resType: Type
- case MethodType(params, resType) =>
- mapMethod(memberSym, newClass, newName, msilParamTypes(memberSym))
-
- case _ =>
- abort("member not found: " + clazz + ", " + name)
- }
- }
-
-
- /*
- * find the method in clazz with name and paramTypes
- */
- private def lookupMethod(clazz: Symbol, name: Name, paramTypes: Array[Type]): Symbol = {
- val memberSym = clazz.tpe.member(name)
- memberSym.tpe match {
- case OverloadedType(_, alternatives) =>
- alternatives.find(s => {
- var i: Int = 0
- var typesOK: Boolean = true
- if (paramTypes.length == s.tpe.paramTypes.length) {
- while(i < paramTypes.length) {
- if (paramTypes(i) != s.tpe.paramTypes(i))
- typesOK = false
- i += 1
- }
- } else {
- typesOK = false
- }
- typesOK
- }) match {
- case Some(sym) => sym
- case None => abort("member of " + clazz + ", " + name + "(" +
- paramTypes + ") not found")
- }
-
- case MethodType(_, _) => memberSym
-
- case _ => abort("member not found: " + name + " of " + clazz)
- }
- }
-
- private def showsym(sym: Symbol): String = (sym.toString +
- "\n symbol = " + Flags.flagsToString(sym.flags) + " " + sym +
- "\n owner = " + Flags.flagsToString(sym.owner.flags) + " " + sym.owner
- )
-
- } // class BytecodeGenerator
-
-} // class GenMSIL
diff --git a/src/compiler/scala/tools/nsc/backend/opt/ClosureElimination.scala b/src/compiler/scala/tools/nsc/backend/opt/ClosureElimination.scala
index 23f932b5b4..5dd20a6919 100644
--- a/src/compiler/scala/tools/nsc/backend/opt/ClosureElimination.scala
+++ b/src/compiler/scala/tools/nsc/backend/opt/ClosureElimination.scala
@@ -7,7 +7,6 @@ package scala.tools.nsc
package backend.opt
import scala.tools.nsc.backend.icode.analysis.LubException
-import scala.tools.nsc.symtab._
/**
* @author Iulian Dragos
@@ -120,7 +119,7 @@ abstract class ClosureElimination extends SubComponent {
case LOAD_FIELD(f, false) /* if accessible(f, m.symbol) */ =>
def replaceFieldAccess(r: Record) {
- val Record(cls, bindings) = r
+ val Record(cls, _) = r
info.getFieldNonRecordValue(r, f) foreach { v =>
bb.replaceInstruction(i, DROP(REFERENCE(cls)) :: valueToInstruction(v) :: Nil)
debuglog(s"replaced $i with $v")
@@ -188,25 +187,17 @@ abstract class ClosureElimination extends SubComponent {
case Boxed(LocalVar(v)) =>
LOAD_LOCAL(v)
}
-
- /** is field 'f' accessible from method 'm'? */
- def accessible(f: Symbol, m: Symbol): Boolean =
- f.isPublic || (f.isProtected && (f.enclosingPackageClass == m.enclosingPackageClass))
} /* class ClosureElim */
/** Peephole optimization. */
abstract class PeepholeOpt {
-
- private var method: IMethod = NoIMethod
-
/** Concrete implementations will perform their optimizations here */
def peep(bb: BasicBlock, i1: Instruction, i2: Instruction): Option[List[Instruction]]
var liveness: global.icodes.liveness.LivenessAnalysis = null
def apply(m: IMethod): Unit = if (m.hasCode) {
- method = m
liveness = new global.icodes.liveness.LivenessAnalysis
liveness.init(m)
liveness.run
diff --git a/src/compiler/scala/tools/nsc/backend/opt/DeadCodeElimination.scala b/src/compiler/scala/tools/nsc/backend/opt/DeadCodeElimination.scala
index fee683ce3a..f7e743a6f1 100644
--- a/src/compiler/scala/tools/nsc/backend/opt/DeadCodeElimination.scala
+++ b/src/compiler/scala/tools/nsc/backend/opt/DeadCodeElimination.scala
@@ -8,7 +8,6 @@ package scala.tools.nsc
package backend.opt
import scala.collection.{ mutable, immutable }
-import symtab._
/**
*/
@@ -280,13 +279,6 @@ abstract class DeadCodeElimination extends SubComponent {
compensations
}
- private def withClosed[a](bb: BasicBlock)(f: => a): a = {
- if (bb.nonEmpty) bb.close
- val res = f
- if (bb.nonEmpty) bb.open
- res
- }
-
private def findInstruction(bb: BasicBlock, i: Instruction): (BasicBlock, Int) = {
for (b <- linearizer.linearizeAt(method, bb)) {
val idx = b.toList indexWhere (_ eq i)
diff --git a/src/compiler/scala/tools/nsc/backend/opt/InlineExceptionHandlers.scala b/src/compiler/scala/tools/nsc/backend/opt/InlineExceptionHandlers.scala
index ab238af239..c534c2230c 100644
--- a/src/compiler/scala/tools/nsc/backend/opt/InlineExceptionHandlers.scala
+++ b/src/compiler/scala/tools/nsc/backend/opt/InlineExceptionHandlers.scala
@@ -4,7 +4,6 @@
package scala.tools.nsc
package backend.opt
-import scala.util.control.Breaks._
/**
* This optimization phase inlines the exception handlers so that further phases can optimize the code better
diff --git a/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala b/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala
index 521b6cc132..ca1cfc8929 100644
--- a/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala
+++ b/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala
@@ -50,6 +50,7 @@ abstract class Inliners extends SubComponent {
val phaseName = "inliner"
/** Debug - for timing the inliner. */
+ /****
private def timed[T](s: String, body: => T): T = {
val t1 = System.currentTimeMillis()
val res = body
@@ -60,6 +61,7 @@ abstract class Inliners extends SubComponent {
res
}
+ ****/
/** Look up implementation of method 'sym in 'clazz'.
*/
@@ -193,7 +195,7 @@ abstract class Inliners extends SubComponent {
private var currentIClazz: IClass = _
private def warn(pos: Position, msg: String) = currentIClazz.cunit.inlinerWarning(pos, msg)
- private def ownedName(sym: Symbol): String = afterUncurry {
+ private def ownedName(sym: Symbol): String = exitingUncurry {
val count = (
if (!sym.isMethod) 1
else if (sym.owner.isAnonymousFunction) 3
@@ -279,7 +281,7 @@ abstract class Inliners extends SubComponent {
}
val tfa = new analysis.MTFAGrowable()
- tfa.stat = global.opt.printStats
+ tfa.stat = global.settings.Ystatistics.value
val staleOut = new mutable.ListBuffer[BasicBlock]
val splicedBlocks = mutable.Set.empty[BasicBlock]
val staleIn = mutable.Set.empty[BasicBlock]
@@ -320,8 +322,8 @@ abstract class Inliners extends SubComponent {
if (settings.debug.value)
inlineLog("caller", ownedName(m.symbol), "in " + m.symbol.owner.fullName)
- var sizeBeforeInlining = m.code.blockCount
- var instrBeforeInlining = m.code.instructionCount
+ val sizeBeforeInlining = m.code.blockCount
+ val instrBeforeInlining = m.code.instructionCount
var retry = false
var count = 0
@@ -477,7 +479,7 @@ abstract class Inliners extends SubComponent {
* As a whole, both `preInline()` invocations amount to priming the inlining process,
* so that the first TFA that is run afterwards is able to gain more information as compared to a cold-start.
*/
- val totalPreInlines = {
+ /*val totalPreInlines = */ { // Val name commented out to emphasize it is never used
val firstRound = preInline(true)
if(firstRound == 0) 0 else (firstRound + preInline(false))
}
@@ -569,7 +571,6 @@ abstract class Inliners extends SubComponent {
m.normalize
if (sizeBeforeInlining > 0) {
val instrAfterInlining = m.code.instructionCount
- val prefix = if ((instrAfterInlining > 2 * instrBeforeInlining) && (instrAfterInlining > 200)) "!!" else ""
val inlinings = caller.inlinedCalls
if (inlinings > 0) {
val s1 = s"instructions $instrBeforeInlining -> $instrAfterInlining"
@@ -584,7 +585,7 @@ abstract class Inliners extends SubComponent {
private def isHigherOrderMethod(sym: Symbol) = (
sym.isMethod
- && beforeExplicitOuter(sym.info.paramTypes exists isFunctionType) // was "at erasurePhase.prev"
+ && enteringExplicitOuter(sym.info.paramTypes exists isFunctionType) // was "at erasurePhase.prev"
)
/** Should method 'sym' being called in 'receiver' be loaded from disk? */
@@ -601,7 +602,6 @@ abstract class Inliners extends SubComponent {
override def toString = m.toString
val sym = m.symbol
- val name = sym.name
def owner = sym.owner
def paramTypes = sym.info.paramTypes
def minimumStack = paramTypes.length + 1
@@ -617,13 +617,11 @@ abstract class Inliners extends SubComponent {
def length = blocks.length
def openBlocks = blocks filterNot (_.closed)
def instructions = m.code.instructions
- // def linearized = linearizer linearize m
def isSmall = (length <= SMALL_METHOD_SIZE) && blocks(0).length < 10
def isLarge = length > MAX_INLINE_SIZE
def isRecursive = m.recursive
def hasHandlers = handlers.nonEmpty || m.bytecodeHasEHs
- def hasClosureParam = paramTypes exists (tp => isByNameParamType(tp) || isFunctionType(tp))
def isSynchronized = sym.hasFlag(Flags.SYNCHRONIZED)
def hasNonFinalizerHandler = handlers exists {
@@ -731,7 +729,6 @@ abstract class Inliners extends SubComponent {
*/
sealed abstract class InlineSafetyInfo {
def isSafe = false
- def isUnsafe = !isSafe
}
case object NeverSafeToInline extends InlineSafetyInfo
case object InlineableAtThisCaller extends InlineSafetyInfo { override def isSafe = true }
@@ -1031,7 +1028,6 @@ abstract class Inliners extends SubComponent {
case Public => true
}
private def sameSymbols = caller.sym == inc.sym
- private def sameOwner = caller.owner == inc.owner
/** Gives green light for inlining (which may still be vetoed later). Heuristics:
* - it's bad to make the caller larger (> SMALL_METHOD_SIZE) if it was small
@@ -1058,8 +1054,8 @@ abstract class Inliners extends SubComponent {
if (inc.isMonadic) score += 3
else if (inc.isHigherOrder) score += 1
- if (inc.isInClosure) score += 2
- if (inlinedMethodCount(inc.sym) > 2) score -= 2
+ if (inc.isInClosure) score += 2;
+ if (inlinedMethodCount(inc.sym) > 2) score -= 2;
score
}
}
diff --git a/src/compiler/scala/tools/nsc/dependencies/Changes.scala b/src/compiler/scala/tools/nsc/dependencies/Changes.scala
index 7f5f412a20..b3cacee20a 100644
--- a/src/compiler/scala/tools/nsc/dependencies/Changes.scala
+++ b/src/compiler/scala/tools/nsc/dependencies/Changes.scala
@@ -61,12 +61,7 @@ abstract class Changes {
annotationsChecked.forall(a =>
(sym1.hasAnnotation(a) == sym2.hasAnnotation(a)))
- private def sameType(tp1: Type, tp2: Type)(implicit strict: Boolean) = {
- def typeOf(tp: Type): String = tp.toString + "[" + tp.getClass + "]"
- val res = sameType0(tp1, tp2)
- //if (!res) println("\t different types: " + typeOf(tp1) + " : " + typeOf(tp2))
- res
- }
+ private def sameType(tp1: Type, tp2: Type)(implicit strict: Boolean) = sameType0(tp1, tp2)
private def sameType0(tp1: Type, tp2: Type)(implicit strict: Boolean): Boolean = ((tp1, tp2) match {
/*case (ErrorType, _) => false
@@ -170,7 +165,6 @@ abstract class Changes {
/** Return the list of changes between 'from' and 'toSym.info'.
*/
def changeSet(from: Type, toSym: Symbol): List[Change] = {
- implicit val defaultReason = "types"
implicit val defaultStrictTypeRefTest = true
val to = toSym.info
diff --git a/src/compiler/scala/tools/nsc/dependencies/DependencyAnalysis.scala b/src/compiler/scala/tools/nsc/dependencies/DependencyAnalysis.scala
index cdde768274..4d4b6589a0 100644
--- a/src/compiler/scala/tools/nsc/dependencies/DependencyAnalysis.scala
+++ b/src/compiler/scala/tools/nsc/dependencies/DependencyAnalysis.scala
@@ -3,7 +3,6 @@ package dependencies
import io.Path
import scala.collection._
-import symtab.Flags
import scala.tools.nsc.io.AbstractFile
import scala.reflect.internal.util.SourceFile
@@ -145,7 +144,7 @@ trait DependencyAnalysis extends SubComponent with Files {
val name = d.toString
d.symbol match {
case s : ModuleClassSymbol =>
- val isTopLevelModule = afterPickler { !s.isImplClass && !s.isNestedClass }
+ val isTopLevelModule = exitingPickler { !s.isImplClass && !s.isNestedClass }
if (isTopLevelModule && (s.companionModule != NoSymbol)) {
dependencies.emits(source, nameToFile(unit.source.file, name))
@@ -183,7 +182,7 @@ trait DependencyAnalysis extends SubComponent with Files {
// was "at uncurryPhase.prev", which is actually non-deterministic
// because the continuations plugin may or may not supply uncurry's
// immediately preceding phase.
- beforeRefchecks(checkType(tree.symbol.tpe))
+ enteringRefchecks(checkType(tree.symbol.tpe))
}
tree match {
@@ -191,7 +190,7 @@ trait DependencyAnalysis extends SubComponent with Files {
!cdef.symbol.isAnonymousFunction =>
if (cdef.symbol != NoSymbol) buf += cdef.symbol
// was "at erasurePhase.prev"
- beforeExplicitOuter {
+ enteringExplicitOuter {
for (s <- cdef.symbol.info.decls)
s match {
case ts: TypeSymbol if !ts.isClass =>
@@ -203,7 +202,7 @@ trait DependencyAnalysis extends SubComponent with Files {
case ddef: DefDef =>
// was "at typer.prev"
- beforeTyper { checkType(ddef.symbol.tpe) }
+ enteringTyper { checkType(ddef.symbol.tpe) }
super.traverse(tree)
case a @ Select(q, n) if ((a.symbol != NoSymbol) && (q.symbol != null)) => // #2556
if (!a.symbol.isConstructor &&
diff --git a/src/compiler/scala/tools/nsc/doc/DocFactory.scala b/src/compiler/scala/tools/nsc/doc/DocFactory.scala
index a091b04993..77e53bd90b 100644
--- a/src/compiler/scala/tools/nsc/doc/DocFactory.scala
+++ b/src/compiler/scala/tools/nsc/doc/DocFactory.scala
@@ -8,9 +8,7 @@ package doc
import scala.util.control.ControlThrowable
import reporters.Reporter
-import scala.reflect.internal.util.{ NoPosition, BatchSourceFile}
-import io.{ File, Directory }
-import DocParser.Parsed
+import scala.reflect.internal.util.BatchSourceFile
/** A documentation processor controls the process of generating Scala
* documentation, which is as follows.
diff --git a/src/compiler/scala/tools/nsc/doc/Settings.scala b/src/compiler/scala/tools/nsc/doc/Settings.scala
index 10a0d8d879..16f3c3776b 100644
--- a/src/compiler/scala/tools/nsc/doc/Settings.scala
+++ b/src/compiler/scala/tools/nsc/doc/Settings.scala
@@ -6,9 +6,7 @@
package scala.tools.nsc
package doc
-import java.io.File
import java.net.URI
-import java.lang.System
import scala.language.postfixOps
/** An extended version of compiler settings, with additional Scaladoc-specific options.
diff --git a/src/compiler/scala/tools/nsc/doc/Uncompilable.scala b/src/compiler/scala/tools/nsc/doc/Uncompilable.scala
index d3e5c869e0..9447e36610 100644
--- a/src/compiler/scala/tools/nsc/doc/Uncompilable.scala
+++ b/src/compiler/scala/tools/nsc/doc/Uncompilable.scala
@@ -15,7 +15,7 @@ trait Uncompilable {
val global: Global
val settings: Settings
- import global.{ reporter, inform, warning, newTypeName, newTermName, Symbol, Name, DocComment, NoSymbol }
+ import global.{ reporter, inform, warning, newTypeName, newTermName, Symbol, DocComment, NoSymbol }
import global.definitions.AnyRefClass
import global.rootMirror.RootClass
diff --git a/src/compiler/scala/tools/nsc/doc/base/CommentFactoryBase.scala b/src/compiler/scala/tools/nsc/doc/base/CommentFactoryBase.scala
index f60d56d9bb..30f33e48c9 100755
--- a/src/compiler/scala/tools/nsc/doc/base/CommentFactoryBase.scala
+++ b/src/compiler/scala/tools/nsc/doc/base/CommentFactoryBase.scala
@@ -8,11 +8,9 @@ package doc
package base
import base.comment._
-import reporters.Reporter
import scala.collection._
import scala.util.matching.Regex
-import scala.annotation.switch
-import scala.reflect.internal.util.{NoPosition, Position}
+import scala.reflect.internal.util.Position
import scala.language.postfixOps
/** The comment parser transforms raw comment strings into `Comment` objects.
@@ -26,7 +24,7 @@ import scala.language.postfixOps
trait CommentFactoryBase { this: MemberLookupBase =>
val global: Global
- import global.{ reporter, definitions, Symbol }
+ import global.{ reporter, Symbol }
/* Creates comments with necessary arguments */
def createComment (
@@ -66,7 +64,6 @@ trait CommentFactoryBase { this: MemberLookupBase =>
val note = note0
val example = example0
val constructor = constructor0
- val source = source0
val inheritDiagram = inheritDiagram0
val contentDiagram = contentDiagram0
val groupDesc = groupDesc0
@@ -683,7 +680,7 @@ trait CommentFactoryBase { this: MemberLookupBase =>
def link(): Inline = {
val SchemeUri = """([a-z]+:.*)""".r
jump("[[")
- var parens = 2 + repeatJump('[')
+ val parens = 2 + repeatJump('[')
val start = "[" * parens
val stop = "]" * parens
//println("link with " + parens + " matching parens")
@@ -729,7 +726,7 @@ trait CommentFactoryBase { this: MemberLookupBase =>
*/
def normalizeIndentation(_code: String): String = {
- var code = _code.trim
+ val code = _code.trim
var maxSkip = Integer.MAX_VALUE
var crtSkip = 0
var wsArea = true
@@ -884,20 +881,6 @@ trait CommentFactoryBase { this: MemberLookupBase =>
count
}
- final def jumpUntil(chars: String): Int = {
- assert(chars.length > 0)
- var count = 0
- val c = chars.charAt(0)
- while (!check(chars) && char != endOfText) {
- nextChar()
- while (char != c && char != endOfText) {
- nextChar()
- count += 1
- }
- }
- count
- }
-
final def jumpUntil(pred: => Boolean): Int = {
var count = 0
while (!pred && char != endOfText) {
diff --git a/src/compiler/scala/tools/nsc/doc/base/comment/Body.scala b/src/compiler/scala/tools/nsc/doc/base/comment/Body.scala
index 02e662da85..2a07547de2 100755
--- a/src/compiler/scala/tools/nsc/doc/base/comment/Body.scala
+++ b/src/compiler/scala/tools/nsc/doc/base/comment/Body.scala
@@ -10,8 +10,6 @@ package comment
import scala.collection._
-import java.net.URL
-
/** A body of text. A comment has a single body, which is composed of
* at least one block. Inside every body is exactly one summary (see
* [[scala.tools.nsc.doc.model.comment.Summary]]). */
diff --git a/src/compiler/scala/tools/nsc/doc/base/comment/Comment.scala b/src/compiler/scala/tools/nsc/doc/base/comment/Comment.scala
index 2b28164ca4..a3d05ae50b 100644
--- a/src/compiler/scala/tools/nsc/doc/base/comment/Comment.scala
+++ b/src/compiler/scala/tools/nsc/doc/base/comment/Comment.scala
@@ -102,9 +102,6 @@ abstract class Comment {
/** A usage example related to the entity. */
def example: List[Body]
- /** The comment as it appears in the source text. */
- def source: Option[String]
-
/** A description for the primary constructor */
def constructor: Option[Body]
diff --git a/src/compiler/scala/tools/nsc/doc/html/HtmlPage.scala b/src/compiler/scala/tools/nsc/doc/html/HtmlPage.scala
index 69da322418..829df97fc2 100644
--- a/src/compiler/scala/tools/nsc/doc/html/HtmlPage.scala
+++ b/src/compiler/scala/tools/nsc/doc/html/HtmlPage.scala
@@ -11,7 +11,7 @@ import base._
import base.comment._
import model._
-import scala.xml.{XML, NodeSeq}
+import scala.xml.NodeSeq
import scala.xml.dtd.{DocType, PublicID}
import scala.collection._
import java.io.Writer
diff --git a/src/compiler/scala/tools/nsc/doc/html/Page.scala b/src/compiler/scala/tools/nsc/doc/html/Page.scala
index 62166f7def..ef9beb1dce 100644
--- a/src/compiler/scala/tools/nsc/doc/html/Page.scala
+++ b/src/compiler/scala/tools/nsc/doc/html/Page.scala
@@ -88,12 +88,6 @@ abstract class Page {
def relativeLinkTo(destClass: TemplateEntity): String =
relativeLinkTo(templateToPath(destClass))
- /** A relative link from this page to some destination page in the Scaladoc site.
- * @param destPage The page that the link will point to. */
- def relativeLinkTo(destPage: HtmlPage): String = {
- relativeLinkTo(destPage.path)
- }
-
/** A relative link from this page to some destination path.
* @param destPath The path that the link will point to. */
def relativeLinkTo(destPath: List[String]): String = {
diff --git a/src/compiler/scala/tools/nsc/doc/html/SyntaxHigh.scala b/src/compiler/scala/tools/nsc/doc/html/SyntaxHigh.scala
index ee78f4ea7a..2783a27811 100644
--- a/src/compiler/scala/tools/nsc/doc/html/SyntaxHigh.scala
+++ b/src/compiler/scala/tools/nsc/doc/html/SyntaxHigh.scala
@@ -40,7 +40,7 @@ private[html] object SyntaxHigh {
/** Standard library classes/objects, sorted alphabetically */
val standards = Array (
- "WeakTypeTag", "Any", "AnyRef", "AnyVal", "App", "Application", "Array",
+ "WeakTypeTag", "Any", "AnyRef", "AnyVal", "App", "Array",
"Boolean", "Byte", "Char", "Class", "ClassTag", "ClassManifest",
"Console", "Double", "Enumeration", "Float", "Function", "Int",
"List", "Long", "Manifest", "Map",
diff --git a/src/compiler/scala/tools/nsc/doc/html/page/Index.scala b/src/compiler/scala/tools/nsc/doc/html/page/Index.scala
index 86407fb9a3..daa9df690c 100644
--- a/src/compiler/scala/tools/nsc/doc/html/page/Index.scala
+++ b/src/compiler/scala/tools/nsc/doc/html/page/Index.scala
@@ -9,10 +9,8 @@ package html
package page
import model._
-
import scala.collection._
import scala.xml._
-import scala.util.parsing.json.{JSONObject, JSONArray}
class Index(universe: doc.Universe, val index: doc.Index) extends HtmlPage {
diff --git a/src/compiler/scala/tools/nsc/doc/html/page/IndexScript.scala b/src/compiler/scala/tools/nsc/doc/html/page/IndexScript.scala
index a205e02533..e3c94505ab 100644
--- a/src/compiler/scala/tools/nsc/doc/html/page/IndexScript.scala
+++ b/src/compiler/scala/tools/nsc/doc/html/page/IndexScript.scala
@@ -8,7 +8,6 @@ package scala.tools.nsc.doc.html.page
import scala.tools.nsc.doc
import scala.tools.nsc.doc.model.{Package, DocTemplateEntity}
import scala.tools.nsc.doc.html.{Page, HtmlFactory}
-import java.nio.channels.Channels
import scala.util.parsing.json.{JSONObject, JSONArray}
class IndexScript(universe: doc.Universe, index: doc.Index) extends Page {
diff --git a/src/compiler/scala/tools/nsc/doc/html/page/Source.scala b/src/compiler/scala/tools/nsc/doc/html/page/Source.scala
index 68289b7474..37145756d9 100644
--- a/src/compiler/scala/tools/nsc/doc/html/page/Source.scala
+++ b/src/compiler/scala/tools/nsc/doc/html/page/Source.scala
@@ -8,8 +8,7 @@ package doc
package html
package page
-import model._
-import scala.xml.{NodeSeq, Unparsed}
+import scala.xml.NodeSeq
import java.io.File
class Source(sourceFile: File) extends HtmlPage {
diff --git a/src/compiler/scala/tools/nsc/doc/html/page/Template.scala b/src/compiler/scala/tools/nsc/doc/html/page/Template.scala
index ea07ff29c4..ff64fb4c0f 100644
--- a/src/compiler/scala/tools/nsc/doc/html/page/Template.scala
+++ b/src/compiler/scala/tools/nsc/doc/html/page/Template.scala
@@ -13,8 +13,6 @@ import base.comment._
import model._
import model.diagram._
-import diagram._
-
import scala.xml.{ NodeSeq, Text, UnprefixedAttribute }
import scala.language.postfixOps
@@ -525,7 +523,7 @@ class Template(universe: doc.Universe, generator: DiagramGenerator, tpl: DocTemp
val sourceLink: NodeSeq = mbr match {
case dtpl: DocTemplateEntity if (isSelf && dtpl.sourceUrl.isDefined && dtpl.inSource.isDefined && !isReduced) =>
- val (absFile, line) = dtpl.inSource.get
+ val (absFile, _) = dtpl.inSource.get
<dt>Source</dt>
<dd>{ <a href={ dtpl.sourceUrl.get.toString } target="_blank">{ Text(absFile.file.getName) }</a> }</dd>
case _ => NodeSeq.Empty
@@ -653,7 +651,6 @@ class Template(universe: doc.Universe, generator: DiagramGenerator, tpl: DocTemp
case dtpl: DocTemplateEntity if isSelf && !isReduced =>
val diagram = f(dtpl)
if (diagram.isDefined) {
- val s = universe.settings
val diagramSvg = generator.generate(diagram.get, tpl, this)
if (diagramSvg != NodeSeq.Empty) {
<div class="toggleContainer block diagram-container" id={ id + "-container"}>
diff --git a/src/compiler/scala/tools/nsc/doc/html/page/diagram/DotDiagramGenerator.scala b/src/compiler/scala/tools/nsc/doc/html/page/diagram/DotDiagramGenerator.scala
index 847367838c..512becd04d 100644
--- a/src/compiler/scala/tools/nsc/doc/html/page/diagram/DotDiagramGenerator.scala
+++ b/src/compiler/scala/tools/nsc/doc/html/page/diagram/DotDiagramGenerator.scala
@@ -10,7 +10,6 @@ package diagram
import scala.xml.{NodeSeq, XML, PrefixedAttribute, Elem, MetaData, Null, UnprefixedAttribute}
import scala.collection.immutable._
-import javax.xml.parsers.SAXParser
import model._
import model.diagram._
@@ -22,8 +21,6 @@ class DotDiagramGenerator(settings: doc.Settings) extends DiagramGenerator {
private var pathToLib: String = null
// maps nodes to unique indices
private var node2Index: Map[Node, Int] = null
- // maps an index to its corresponding node
- private var index2Node: Map[Int, Node] = null
// true if the current diagram is a class diagram
private var isInheritanceDiagram = false
// incoming implicit nodes (needed for determining the CSS class of a node)
@@ -42,7 +39,6 @@ class DotDiagramGenerator(settings: doc.Settings) extends DiagramGenerator {
// clean things up a bit, so we don't leave garbage on the heap
this.page = null
node2Index = null
- index2Node = null
incomingImplicitNodes = List()
result
}
@@ -116,7 +112,6 @@ class DotDiagramGenerator(settings: doc.Settings) extends DiagramGenerator {
node2Index = d.nodes.zipWithIndex.toMap
incomingImplicitNodes = List()
}
- index2Node = node2Index map {_.swap}
val implicitsDot = {
if (!isInheritanceDiagram) ""
@@ -215,7 +210,7 @@ class DotDiagramGenerator(settings: doc.Settings) extends DiagramGenerator {
def escape(name: String) = name.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;");
// assemble node attribues in a map
- var attr = scala.collection.mutable.Map[String, String]()
+ val attr = scala.collection.mutable.Map[String, String]()
// link
node.doctpl match {
diff --git a/src/compiler/scala/tools/nsc/doc/html/page/diagram/DotRunner.scala b/src/compiler/scala/tools/nsc/doc/html/page/diagram/DotRunner.scala
index 5cdd5c74a4..2fa1bf62f3 100644
--- a/src/compiler/scala/tools/nsc/doc/html/page/diagram/DotRunner.scala
+++ b/src/compiler/scala/tools/nsc/doc/html/page/diagram/DotRunner.scala
@@ -10,12 +10,10 @@ import java.io.InputStreamReader
import java.io.OutputStreamWriter
import java.io.BufferedWriter
import java.io.BufferedReader
-import java.io.IOException
import scala.sys.process._
import scala.concurrent.SyncVar
import model._
-import model.diagram._
/** This class takes care of running the graphviz dot utility */
class DotRunner(settings: doc.Settings) {
@@ -183,7 +181,7 @@ class DotProcess(settings: doc.Settings) {
private[this] def outputFn(stdOut: InputStream): Unit = {
val reader = new BufferedReader(new InputStreamReader(stdOut))
- var buffer: StringBuilder = new StringBuilder()
+ val buffer: StringBuilder = new StringBuilder()
try {
var line = reader.readLine
while (!error && line != null) {
@@ -209,7 +207,6 @@ class DotProcess(settings: doc.Settings) {
private[this] def errorFn(stdErr: InputStream): Unit = {
val reader = new BufferedReader(new InputStreamReader(stdErr))
- var buffer: StringBuilder = new StringBuilder()
try {
var line = reader.readLine
while (line != null) {
@@ -225,4 +222,4 @@ class DotProcess(settings: doc.Settings) {
errorBuffer.append(" Error thread in " + templateName + ": Exception: " + exc + "\n")
}
}
-} \ No newline at end of file
+}
diff --git a/src/compiler/scala/tools/nsc/doc/model/Entity.scala b/src/compiler/scala/tools/nsc/doc/model/Entity.scala
index cbc1a23d44..924f203a59 100644
--- a/src/compiler/scala/tools/nsc/doc/model/Entity.scala
+++ b/src/compiler/scala/tools/nsc/doc/model/Entity.scala
@@ -23,10 +23,6 @@ import diagram._
* - type and value parameters;
* - annotations. */
trait Entity {
-
- /** Similar to symbols, so we can track entities */
- def id: Int
-
/** The name of the entity. Note that the name does not qualify this entity uniquely; use its `qualifiedName`
* instead. */
def name : String
@@ -59,9 +55,6 @@ trait Entity {
/** Indicates whether this entity lives in the types namespace (classes, traits, abstract/alias types) */
def isType: Boolean
-
- /** Indicates whether this entity lives in the terms namespace (objects, packages, methods, values) */
- def isTerm: Boolean
}
object Entity {
@@ -97,9 +90,6 @@ trait TemplateEntity extends Entity {
/** Whether documentation is available for this template. */
def isDocTemplate: Boolean
- /** Whether documentation is available for this template. */
- def isNoDocMemberTemplate: Boolean
-
/** Whether this template is a case class. */
def isCaseClass: Boolean
@@ -149,9 +139,6 @@ trait MemberEntity extends Entity {
/** Some migration warning if this member has a migration annotation, or none otherwise. */
def migration: Option[Body]
- @deprecated("Use `inDefinitionTemplates` instead", "2.9.0")
- def inheritedFrom: List[TemplateEntity]
-
/** For members representing values: the type of the value returned by this member; for members
* representing types: the type itself. */
def resultType: TypeEntity
@@ -177,12 +164,6 @@ trait MemberEntity extends Entity {
/** Whether this member is an abstract type. */
def isAbstractType: Boolean
- /** Whether this member is a template. */
- def isTemplate: Boolean
-
- /** Whether this member is implicit. */
- def isImplicit: Boolean
-
/** Whether this member is abstract. */
def isAbstract: Boolean
@@ -384,14 +365,9 @@ trait RootPackage extends Package
/** A non-template member (method, value, lazy value, variable, constructor, alias type, and abstract type). */
trait NonTemplateMemberEntity extends MemberEntity {
-
/** Whether this member is a use case. A use case is a member which does not exist in the documented code.
* It corresponds to a real member, and provides a simplified, yet compatible signature for that member. */
def isUseCase: Boolean
-
- /** Whether this member is a bridge member. A bridge member does only exist for binary compatibility reasons
- * and should not appear in ScalaDoc. */
- def isBridge: Boolean
}
@@ -506,12 +482,6 @@ trait ImplicitConversion {
/** The result type after the conversion */
def targetType: TypeEntity
- /** The result type after the conversion
- * Note: not all targetTypes have a corresponding template. Examples include conversions resulting in refinement
- * types. Need to check it's not option!
- */
- def targetTemplate: Option[TemplateEntity]
-
/** The components of the implicit conversion type parents */
def targetTypeComponents: List[(TemplateEntity, TypeEntity)]
diff --git a/src/compiler/scala/tools/nsc/doc/model/IndexModelFactory.scala b/src/compiler/scala/tools/nsc/doc/model/IndexModelFactory.scala
index 10e2f23142..1d6063255d 100755
--- a/src/compiler/scala/tools/nsc/doc/model/IndexModelFactory.scala
+++ b/src/compiler/scala/tools/nsc/doc/model/IndexModelFactory.scala
@@ -17,8 +17,6 @@ object IndexModelFactory {
object result extends mutable.HashMap[Char,SymbolMap] {
- /* Owner template ordering */
- implicit def orderingSet = math.Ordering.String.on { x: MemberEntity => x.name.toLowerCase }
/* symbol name ordering */
implicit def orderingMap = math.Ordering.String.on { x: String => x.toLowerCase }
diff --git a/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala b/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala
index c6cfc317ea..dc75b15f87 100644
--- a/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala
+++ b/src/compiler/scala/tools/nsc/doc/model/ModelFactory.scala
@@ -43,20 +43,6 @@ class ModelFactory(val global: Global, val settings: doc.Settings) {
def modelFinished: Boolean = _modelFinished
private var universe: Universe = null
- private def dbg(msg: String) = if (sys.props contains "scala.scaladoc.debug") println(msg)
- protected def closestPackage(sym: Symbol) = {
- if (sym.isPackage || sym.isPackageClass) sym
- else sym.enclosingPackage
- }
-
- private def printWithoutPrefix(memberSym: Symbol, templateSym: Symbol) = {
- dbg(
- "memberSym " + memberSym + " templateSym " + templateSym + " encls = " +
- closestPackage(memberSym) + ", " + closestPackage(templateSym)
- )
- memberSym.isOmittablePrefix || (closestPackage(memberSym) == closestPackage(templateSym))
- }
-
def makeModel: Option[Universe] = {
val universe = new Universe { thisUniverse =>
thisFactory.universe = thisUniverse
@@ -86,7 +72,6 @@ class ModelFactory(val global: Global, val settings: doc.Settings) {
/* ============== IMPLEMENTATION PROVIDING ENTITY TYPES ============== */
abstract class EntityImpl(val sym: Symbol, val inTpl: TemplateImpl) extends Entity {
- val id = { ids += 1; ids }
val name = optimize(sym.nameString)
val universe = thisFactory.universe
@@ -100,7 +85,6 @@ class ModelFactory(val global: Global, val settings: doc.Settings) {
def annotations = sym.annotations.map(makeAnnotation)
def inPackageObject: Boolean = sym.owner.isModuleClass && sym.owner.sourceModule.isPackageObject
def isType = sym.name.isTypeName
- def isTerm = sym.name.isTermName
}
trait TemplateImpl extends EntityImpl with TemplateEntity {
@@ -112,7 +96,6 @@ class ModelFactory(val global: Global, val settings: doc.Settings) {
def isObject = sym.isModule && !sym.isPackage
def isCaseClass = sym.isCaseClass
def isRootPackage = false
- def isNoDocMemberTemplate = false
def selfType = if (sym.thisSym eq sym) None else Some(makeType(sym.thisSym.typeOfThis, this))
}
@@ -127,18 +110,14 @@ class ModelFactory(val global: Global, val settings: doc.Settings) {
}
if (inTpl != null) thisFactory.comment(sym, thisTpl, inTpl) else None
}
- def group = if (comment.isDefined) comment.get.group.getOrElse(defaultGroup) else defaultGroup
+ def group = comment flatMap (_.group) getOrElse defaultGroup
override def inTemplate = inTpl
override def toRoot: List[MemberImpl] = this :: inTpl.toRoot
- def inDefinitionTemplates = this match {
- case mb: NonTemplateMemberEntity if (mb.useCaseOf.isDefined) =>
- mb.useCaseOf.get.inDefinitionTemplates
- case _ =>
- if (inTpl == null)
- List(makeRootPackage)
- else
- makeTemplate(sym.owner)::(sym.allOverriddenSymbols map { inhSym => makeTemplate(inhSym.owner) })
- }
+ def inDefinitionTemplates =
+ if (inTpl == null)
+ List(makeRootPackage)
+ else
+ makeTemplate(sym.owner)::(sym.allOverriddenSymbols map { inhSym => makeTemplate(inhSym.owner) })
def visibility = {
if (sym.isPrivateLocal) PrivateInInstance()
else if (sym.isProtectedLocal) ProtectedInInstance()
@@ -149,8 +128,10 @@ class ModelFactory(val global: Global, val settings: doc.Settings) {
else None
if (sym.isPrivate) PrivateInTemplate(inTpl)
else if (sym.isProtected) ProtectedInTemplate(qual getOrElse inTpl)
- else if (qual.isDefined) PrivateInTemplate(qual.get)
- else Public()
+ else qual match {
+ case Some(q) => PrivateInTemplate(q)
+ case None => Public()
+ }
}
}
def flags = {
@@ -189,9 +170,7 @@ class ModelFactory(val global: Global, val settings: doc.Settings) {
})
else
None
- def inheritedFrom =
- if (inTemplate.sym == this.sym.owner || inTemplate.sym.isPackage) Nil else
- makeTemplate(this.sym.owner) :: (sym.allOverriddenSymbols map { os => makeTemplate(os.owner) })
+
def resultType = {
def resultTpe(tpe: Type): Type = tpe match { // similar to finalResultType, except that it leaves singleton types alone
case PolyType(_, res) => resultTpe(res)
@@ -199,14 +178,13 @@ class ModelFactory(val global: Global, val settings: doc.Settings) {
case NullaryMethodType(res) => resultTpe(res)
case _ => tpe
}
- val tpe = if (!isImplicitlyInherited) sym.tpe else byConversion.get.toType memberInfo sym
+ val tpe = byConversion.fold(sym.tpe) (_.toType memberInfo sym)
makeTypeInTemplateContext(resultTpe(tpe), inTemplate, sym)
}
def isDef = false
def isVal = false
def isLazyVal = false
def isVar = false
- def isImplicit = sym.isImplicit
def isConstructor = false
def isAliasType = false
def isAbstractType = false
@@ -214,7 +192,7 @@ class ModelFactory(val global: Global, val settings: doc.Settings) {
// for the explanation of conversion == null see comment on flags
((!sym.isTrait && ((sym hasFlag Flags.ABSTRACT) || (sym hasFlag Flags.DEFERRED)) && (!isImplicitlyInherited)) ||
sym.isAbstractClass || sym.isAbstractType) && !sym.isSynthetic
- def isTemplate = false
+
def signature = externalSignature(sym)
lazy val signatureCompat = {
@@ -255,8 +233,8 @@ class ModelFactory(val global: Global, val settings: doc.Settings) {
* exists, but should not be documented (either it's not included in the source or it's not visible)
*/
class NoDocTemplateImpl(sym: Symbol, inTpl: TemplateImpl) extends EntityImpl(sym, inTpl) with TemplateImpl with HigherKindedImpl with NoDocTemplate {
- assert(modelFinished)
- assert(!(noDocTemplatesCache isDefinedAt sym))
+ assert(modelFinished, this)
+ assert(!(noDocTemplatesCache isDefinedAt sym), (sym, noDocTemplatesCache(sym)))
noDocTemplatesCache += (sym -> this)
def isDocTemplate = false
}
@@ -268,25 +246,10 @@ class ModelFactory(val global: Global, val settings: doc.Settings) {
*/
abstract class MemberTemplateImpl(sym: Symbol, inTpl: DocTemplateImpl) extends MemberImpl(sym, inTpl) with TemplateImpl with HigherKindedImpl with MemberTemplateEntity {
// no templates cache for this class, each owner gets its own instance
- override def isTemplate = true
def isDocTemplate = false
- override def isNoDocMemberTemplate = true
lazy val definitionName = optimize(inDefinitionTemplates.head.qualifiedName + "." + name)
def valueParams: List[List[ValueParam]] = Nil /** TODO, these are now only computed for DocTemplates */
- // Seems unused
- // def parentTemplates =
- // if (sym.isPackage || sym == AnyClass)
- // List()
- // else
- // sym.tpe.parents.flatMap { tpe: Type =>
- // val tSym = tpe.typeSymbol
- // if (tSym != NoSymbol)
- // List(makeTemplate(tSym))
- // else
- // List()
- // } filter (_.isInstanceOf[DocTemplateEntity])
-
def parentTypes =
if (sym.isPackage || sym == AnyClass) List() else {
val tps = (this match {
@@ -306,7 +269,7 @@ class ModelFactory(val global: Global, val settings: doc.Settings) {
* All ancestors of the template and all non-package members.
*/
abstract class DocTemplateImpl(sym: Symbol, inTpl: DocTemplateImpl) extends MemberTemplateImpl(sym, inTpl) with DocTemplateEntity {
- assert(!modelFinished)
+ assert(!modelFinished, (sym, inTpl))
assert(!(docTemplatesCache isDefinedAt sym), sym)
docTemplatesCache += (sym -> this)
@@ -391,9 +354,9 @@ class ModelFactory(val global: Global, val settings: doc.Settings) {
lazy val memberSyms = sym.info.members.filter(s => membersShouldDocument(s, this)).toList
// the inherited templates (classes, traits or objects)
- var memberSymsLazy = memberSyms.filter(t => templateShouldDocument(t, this) && !inOriginalOwner(t, this))
+ val memberSymsLazy = memberSyms.filter(t => templateShouldDocument(t, this) && !inOriginalOwner(t, this))
// the direct members (methods, values, vars, types and directly contained templates)
- var memberSymsEager = memberSyms.filter(!memberSymsLazy.contains(_))
+ val memberSymsEager = memberSyms.filter(!memberSymsLazy.contains(_))
// the members generated by the symbols in memberSymsEager
val ownMembers = (memberSymsEager.flatMap(makeMember(_, None, this)))
@@ -439,17 +402,16 @@ class ModelFactory(val global: Global, val settings: doc.Settings) {
conversions flatMap (conv =>
if (!implicitExcluded(conv.conversionQualifiedName))
conv.targetTypeComponents map {
- case pair@(template, tpe) =>
+ case (template, tpe) =>
template match {
case d: DocTemplateImpl if (d != this) => d.registerImplicitlyConvertibleClass(this, conv)
case _ => // nothing
}
- (pair._1, pair._2, conv)
+ (template, tpe, conv)
}
else List()
)
- override def isTemplate = true
override def isDocTemplate = true
private[this] lazy val companionSymbol =
if (sym.isAliasType || sym.isAbstractType) {
@@ -524,31 +486,26 @@ class ModelFactory(val global: Global, val settings: doc.Settings) {
extends MemberImpl(sym, inTpl) with NonTemplateMemberEntity {
override lazy val comment = {
val inRealTpl =
- /* Variable precendence order for implicitly added members: Take the variable defifinitions from ...
- * 1. the target of the implicit conversion
- * 2. the definition template (owner)
- * 3. the current template
- */
- if (conversion.isDefined) findTemplateMaybe(conversion.get.toType.typeSymbol) match {
- case Some(d) if d != makeRootPackage => d //in case of NoSymbol, it will give us the root package
- case _ => findTemplateMaybe(sym.owner) match {
- case Some(d) if d != makeRootPackage => d //in case of NoSymbol, it will give us the root package
- case _ => inTpl
- }
- } else inTpl
- if (inRealTpl != null) thisFactory.comment(sym, None, inRealTpl) else None
+ conversion.fold(Option(inTpl)) { conv =>
+ /* Variable precendence order for implicitly added members: Take the variable defifinitions from ...
+ * 1. the target of the implicit conversion
+ * 2. the definition template (owner)
+ * 3. the current template
+ */
+ findTemplateMaybe(conv.toType.typeSymbol) filterNot (_ == makeRootPackage) orElse (
+ findTemplateMaybe(sym.owner) filterNot (_ == makeRootPackage) orElse Option(inTpl)
+ )
+ }
+ inRealTpl flatMap (thisFactory.comment(sym, None, _))
}
+ override def inDefinitionTemplates = useCaseOf.fold(super.inDefinitionTemplates)(_.inDefinitionTemplates)
+
override def qualifiedName = optimize(inTemplate.qualifiedName + "#" + name)
lazy val definitionName = {
- // this contrived name is here just to satisfy some older tests -- if you decide to remove it, be my guest, and
- // also remove property("package object") from test/scaladoc/scalacheck/HtmlFactoryTest.scala so you don't break
- // the test suite...
- val packageObject = if (inPackageObject) ".package" else ""
- if (!conversion.isDefined) optimize(inDefinitionTemplates.head.qualifiedName + packageObject + "#" + name)
- else optimize(conversion.get.conversionQualifiedName + packageObject + "#" + name)
+ val qualifiedName = conversion.fold(inDefinitionTemplates.head.qualifiedName)(_.conversionQualifiedName)
+ optimize(qualifiedName + "#" + name)
}
- def isBridge = sym.isBridge
def isUseCase = useCaseOf.isDefined
override def byConversion: Option[ImplicitConversionImpl] = conversion
override def isImplicitlyInherited = { assert(modelFinished); conversion.isDefined }
@@ -561,7 +518,7 @@ class ModelFactory(val global: Global, val settings: doc.Settings) {
useCaseOf: Option[MemberEntity], inTpl: DocTemplateImpl)
extends NonTemplateMemberImpl(sym, conversion, useCaseOf, inTpl) {
def valueParams = {
- val info = if (!isImplicitlyInherited) sym.info else conversion.get.toType memberInfo sym
+ val info = conversion.fold(sym.info)(_.toType memberInfo sym)
info.paramss map { ps => (ps.zipWithIndex) map { case (p, i) =>
if (p.nameString contains "$") makeValueParam(p, inTpl, optimize("arg" + i)) else makeValueParam(p, inTpl)
}}
@@ -663,7 +620,7 @@ class ModelFactory(val global: Global, val settings: doc.Settings) {
*/
def createTemplate(aSym: Symbol, inTpl: DocTemplateImpl): Option[MemberImpl] = {
// don't call this after the model finished!
- assert(!modelFinished)
+ assert(!modelFinished, (aSym, inTpl))
def createRootPackageComment: Option[Comment] =
if(settings.docRootContent.isDefault) None
@@ -679,7 +636,7 @@ class ModelFactory(val global: Global, val settings: doc.Settings) {
}
def createDocTemplate(bSym: Symbol, inTpl: DocTemplateImpl): DocTemplateImpl = {
- assert(!modelFinished) // only created BEFORE the model is finished
+ assert(!modelFinished, (bSym, inTpl)) // only created BEFORE the model is finished
if (bSym.isAliasType && bSym != AnyRefClass)
new DocTemplateImpl(bSym, inTpl) with AliasImpl with AliasType { override def isAliasType = true }
else if (bSym.isAbstractType)
@@ -710,7 +667,6 @@ class ModelFactory(val global: Global, val settings: doc.Settings) {
override def inTemplate = this
override def toRoot = this :: Nil
override def qualifiedName = "_root_"
- override def inheritedFrom = Nil
override def isRootPackage = true
override lazy val memberSyms =
(bSym.info.members ++ EmptyPackage.info.members).toList filter { s =>
@@ -780,7 +736,6 @@ class ModelFactory(val global: Global, val settings: doc.Settings) {
}
}
- /** Get the root package */
def makeRootPackage: PackageImpl = docTemplatesCache(RootPackage).asInstanceOf[PackageImpl]
// TODO: Should be able to override the type
@@ -857,16 +812,10 @@ class ModelFactory(val global: Global, val settings: doc.Settings) {
}
def findMember(aSym: Symbol, inTpl: DocTemplateImpl): Option[MemberImpl] = {
- val tplSym = normalizeTemplate(aSym.owner)
+ normalizeTemplate(aSym.owner)
inTpl.members.find(_.sym == aSym)
}
- @deprecated("Use `findLinkTarget` instead.", "2.10.0")
- def findTemplate(query: String): Option[DocTemplateImpl] = {
- assert(modelFinished)
- docTemplatesCache.values find { (tpl: DocTemplateImpl) => tpl.qualifiedName == query && !packageDropped(tpl) && !tpl.isObject }
- }
-
def findTemplateMaybe(aSym: Symbol): Option[DocTemplateImpl] = {
assert(modelFinished)
docTemplatesCache.get(normalizeTemplate(aSym)).filterNot(packageDropped(_))
@@ -877,20 +826,12 @@ class ModelFactory(val global: Global, val settings: doc.Settings) {
def makeTemplate(aSym: Symbol, inTpl: Option[TemplateImpl]): TemplateImpl = {
assert(modelFinished)
- def makeNoDocTemplate(aSym: Symbol, inTpl: TemplateImpl): NoDocTemplateImpl = {
- val bSym = normalizeTemplate(aSym)
- noDocTemplatesCache.get(bSym) match {
- case Some(noDocTpl) => noDocTpl
- case None => new NoDocTemplateImpl(bSym, inTpl)
- }
- }
+ def makeNoDocTemplate(aSym: Symbol, inTpl: TemplateImpl): NoDocTemplateImpl =
+ noDocTemplatesCache getOrElse (aSym, new NoDocTemplateImpl(aSym, inTpl))
- findTemplateMaybe(aSym) match {
- case Some(dtpl) =>
- dtpl
- case None =>
- val bSym = normalizeTemplate(aSym)
- makeNoDocTemplate(bSym, if (inTpl.isDefined) inTpl.get else makeTemplate(bSym.owner))
+ findTemplateMaybe(aSym) getOrElse {
+ val bSym = normalizeTemplate(aSym)
+ makeNoDocTemplate(bSym, inTpl getOrElse makeTemplate(bSym.owner))
}
}
@@ -901,24 +842,28 @@ class ModelFactory(val global: Global, val settings: doc.Settings) {
lazy val annotationClass =
makeTemplate(annot.symbol)
val arguments = { // lazy
- def noParams = annot.args map { _ => None }
+ def annotArgs = annot.args match {
+ case Nil => annot.assocs collect { case (_, LiteralAnnotArg(const)) => Literal(const) }
+ case xs => xs
+ }
+ def noParams = annotArgs map (_ => None)
+
val params: List[Option[ValueParam]] = annotationClass match {
case aClass: DocTemplateEntity with Class =>
(aClass.primaryConstructor map { _.valueParams.head }) match {
case Some(vps) => vps map { Some(_) }
- case None => noParams
+ case _ => noParams
}
case _ => noParams
}
- assert(params.length == annot.args.length)
- (params zip annot.args) flatMap { case (param, arg) =>
- makeTree(arg) match {
- case Some(tree) =>
- Some(new ValueArgument {
- def parameter = param
- def value = tree
- })
- case None => None
+ assert(params.length == annotArgs.length, (params, annotArgs))
+
+ params zip annotArgs flatMap { case (param, arg) =>
+ makeTree(arg) map { tree =>
+ new ValueArgument {
+ def parameter = param
+ def value = tree
+ }
}
}
}
@@ -992,10 +937,10 @@ class ModelFactory(val global: Global, val settings: doc.Settings) {
val ignoreParents = Set[Symbol](AnyClass, AnyRefClass, ObjectClass)
val filtParents =
// we don't want to expose too many links to AnyRef, that will just be redundant information
- if (tpl.isDefined && { val sym = tpl.get.sym; (!sym.isModule && parents.length < 2) || (sym == AnyValClass) || (sym == AnyRefClass) || (sym == AnyClass) })
- parents
- else
- parents.filterNot((p: Type) => ignoreParents(p.typeSymbol))
+ tpl match {
+ case Some(tpl) if (!tpl.sym.isModule && parents.length < 2) || (tpl.sym == AnyValClass) || (tpl.sym == AnyRefClass) || (tpl.sym == AnyClass) => parents
+ case _ => parents.filterNot((p: Type) => ignoreParents(p.typeSymbol))
+ }
/** Returns:
* - a DocTemplate if the type's symbol is documented
@@ -1026,9 +971,9 @@ class ModelFactory(val global: Global, val settings: doc.Settings) {
}
def makeQualifiedName(sym: Symbol, relativeTo: Option[Symbol] = None): String = {
- val stop = if (relativeTo.isDefined) relativeTo.get.ownerChain.toSet else Set[Symbol]()
+ val stop = relativeTo map (_.ownerChain.toSet) getOrElse Set[Symbol]()
var sym1 = sym
- var path = new StringBuilder()
+ val path = new StringBuilder()
// var path = List[Symbol]()
while ((sym1 != NoSymbol) && (path.isEmpty || !stop(sym1))) {
diff --git a/src/compiler/scala/tools/nsc/doc/model/ModelFactoryImplicitSupport.scala b/src/compiler/scala/tools/nsc/doc/model/ModelFactoryImplicitSupport.scala
index f88251b22e..5d2cc51c97 100644
--- a/src/compiler/scala/tools/nsc/doc/model/ModelFactoryImplicitSupport.scala
+++ b/src/compiler/scala/tools/nsc/doc/model/ModelFactoryImplicitSupport.scala
@@ -11,12 +11,7 @@ package doc
package model
import scala.collection._
-import scala.util.matching.Regex
-
import symtab.Flags
-import io._
-
-import model.{ RootPackage => RootPackageEntity }
/**
* This trait finds implicit conversions for a class in the default scope and creates scaladoc entries for each of them.
@@ -56,7 +51,6 @@ trait ModelFactoryImplicitSupport {
import global._
import global.analyzer._
import global.definitions._
- import rootMirror.{RootPackage, RootClass, EmptyPackage, EmptyPackageClass}
import settings.hardcoded
// debugging:
@@ -94,9 +88,9 @@ trait ModelFactoryImplicitSupport {
// But we don't want that, so we'll simply refuse to find implicit conversions on for Nothing and Null
if (!(sym.isClass || sym.isTrait || sym == AnyRefClass) || sym == NothingClass || sym == NullClass) Nil
else {
- var context: global.analyzer.Context = global.analyzer.rootContext(NoCompilationUnit)
+ val context: global.analyzer.Context = global.analyzer.rootContext(NoCompilationUnit)
- val results = global.analyzer.allViewsFrom(sym.tpe, context, sym.typeParams)
+ val results = global.analyzer.allViewsFrom(sym.tpe_*, context, sym.typeParams)
var conversions = results.flatMap(result => makeImplicitConversion(sym, result._1, result._2, context, inTpl))
// also keep empty conversions, so they appear in diagrams
// conversions = conversions.filter(!_.members.isEmpty)
@@ -107,7 +101,7 @@ trait ModelFactoryImplicitSupport {
hardcoded.arraySkipConversions.contains(conv.conversionQualifiedName))
// Filter out non-sensical conversions from value types
- if (isPrimitiveValueType(sym.tpe))
+ if (isPrimitiveValueType(sym.tpe_*))
conversions = conversions.filter((ic: ImplicitConversionImpl) =>
hardcoded.valueClassFilter(sym.nameString, ic.conversionQualifiedName))
@@ -349,15 +343,6 @@ trait ModelFactoryImplicitSupport {
makeRootPackage
}
- def targetTemplate: Option[TemplateEntity] = toType match {
- // @Vlad: I'm being extra conservative in template creation -- I don't want to create templates for complex types
- // such as refinement types because the template can't represent the type corectly (a template corresponds to a
- // package, class, trait or object)
- case t: TypeRef => Some(makeTemplate(t.sym))
- case RefinedType(parents, decls) => None
- case _ => error("Scaladoc implicits: Could not create template for: " + toType + " of type " + toType.getClass); None
- }
-
def targetTypeComponents: List[(TemplateEntity, TypeEntity)] = makeParentTypes(toType, None, inTpl)
def convertorMethod: Either[MemberEntity, String] = {
@@ -385,7 +370,6 @@ trait ModelFactoryImplicitSupport {
lazy val memberImpls: List[MemberImpl] = {
// Obtain the members inherited by the implicit conversion
val memberSyms = toType.members.filter(implicitShouldDocument(_)).toList
- val existingSyms = sym.info.members
// Debugging part :)
debug(sym.nameString + "\n" + "=" * sym.nameString.length())
@@ -422,66 +406,52 @@ trait ModelFactoryImplicitSupport {
/* ========================= HELPER METHODS ========================== */
/**
* Computes the shadowing table for all the members in the implicit conversions
- * @param mbrs All template's members, including usecases and full signature members
+ * @param members All template's members, including usecases and full signature members
* @param convs All the conversions the template takes part in
- * @param inTpl the ususal :)
+ * @param inTpl the usual :)
*/
- def makeShadowingTable(mbrs: List[MemberImpl],
+ def makeShadowingTable(members: List[MemberImpl],
convs: List[ImplicitConversionImpl],
inTpl: DocTemplateImpl): Map[MemberEntity, ImplicitMemberShadowing] = {
assert(modelFinished)
- var shadowingTable = Map[MemberEntity, ImplicitMemberShadowing]()
+ val shadowingTable = mutable.Map[MemberEntity, ImplicitMemberShadowing]()
+ val membersByName: Map[Name, List[MemberImpl]] = members.groupBy(_.sym.name)
+ val convsByMember = (Map.empty[MemberImpl, ImplicitConversionImpl] /: convs) {
+ case (map, conv) => map ++ conv.memberImpls.map (_ -> conv)
+ }
for (conv <- convs) {
- val otherConvs = convs.filterNot(_ == conv)
+ val otherConvMembers: Map[Name, List[MemberImpl]] = convs filterNot (_ == conv) flatMap (_.memberImpls) groupBy (_.sym.name)
for (member <- conv.memberImpls) {
- // for each member in our list
val sym1 = member.sym
val tpe1 = conv.toType.memberInfo(sym1)
- // check if it's shadowed by a member in the original class
- var shadowedBySyms: List[Symbol] = List()
- for (mbr <- mbrs) {
- val sym2 = mbr.sym
- if (sym1.name == sym2.name) {
- val shadowed = !settings.docImplicitsSoundShadowing.value || {
- val tpe2 = inTpl.sym.info.memberInfo(sym2)
- !isDistinguishableFrom(tpe1, tpe2)
- }
- if (shadowed)
- shadowedBySyms ::= sym2
- }
+ // check if it's shadowed by a member in the original class.
+ val shadowed = membersByName.get(sym1.name).toList.flatten filter { other =>
+ !settings.docImplicitsSoundShadowing.value || !isDistinguishableFrom(tpe1, inTpl.sym.info.memberInfo(other.sym))
}
- val shadowedByMembers = mbrs.filter((mb: MemberImpl) => shadowedBySyms.contains(mb.sym))
-
- // check if it's shadowed by another member
- var ambiguousByMembers: List[MemberEntity] = List()
- for (conv <- otherConvs)
- for (member2 <- conv.memberImpls) {
- val sym2 = member2.sym
- if (sym1.name == sym2.name) {
- val tpe2 = conv.toType.memberInfo(sym2)
- // Ambiguity should be an equivalence relation
- val ambiguated = !isDistinguishableFrom(tpe1, tpe2) || !isDistinguishableFrom(tpe2, tpe1)
- if (ambiguated)
- ambiguousByMembers ::= member2
- }
- }
+ // check if it's shadowed by another conversion.
+ val ambiguous = otherConvMembers.get(sym1.name).toList.flatten filter { other =>
+ val tpe2 = convsByMember(other).toType.memberInfo(other.sym)
+ !isDistinguishableFrom(tpe1, tpe2) || !isDistinguishableFrom(tpe2, tpe1)
+ }
// we finally have the shadowing info
- val shadowing = new ImplicitMemberShadowing {
- def shadowingMembers: List[MemberEntity] = shadowedByMembers
- def ambiguatingMembers: List[MemberEntity] = ambiguousByMembers
- }
+ if (!shadowed.isEmpty || !ambiguous.isEmpty) {
+ val shadowing = new ImplicitMemberShadowing {
+ def shadowingMembers: List[MemberEntity] = shadowed
+ def ambiguatingMembers: List[MemberEntity] = ambiguous
+ }
- shadowingTable += (member -> shadowing)
+ shadowingTable += (member -> shadowing)
+ }
}
}
- shadowingTable
+ shadowingTable.toMap
}
@@ -511,14 +481,14 @@ trait ModelFactoryImplicitSupport {
/**
* Make implicits explicit - Not used curently
*/
- object implicitToExplicit extends TypeMap {
- def apply(tp: Type): Type = mapOver(tp) match {
- case MethodType(params, resultType) =>
- MethodType(params.map(param => if (param.isImplicit) param.cloneSymbol.resetFlag(Flags.IMPLICIT) else param), resultType)
- case other =>
- other
- }
- }
+ // object implicitToExplicit extends TypeMap {
+ // def apply(tp: Type): Type = mapOver(tp) match {
+ // case MethodType(params, resultType) =>
+ // MethodType(params.map(param => if (param.isImplicit) param.cloneSymbol.resetFlag(Flags.IMPLICIT) else param), resultType)
+ // case other =>
+ // other
+ // }
+ // }
/**
* removeImplicitParameters transforms implicit parameters from the view result type into constraints and
diff --git a/src/compiler/scala/tools/nsc/doc/model/ModelFactoryTypeSupport.scala b/src/compiler/scala/tools/nsc/doc/model/ModelFactoryTypeSupport.scala
index 844a509b7e..99e9059d79 100644
--- a/src/compiler/scala/tools/nsc/doc/model/ModelFactoryTypeSupport.scala
+++ b/src/compiler/scala/tools/nsc/doc/model/ModelFactoryTypeSupport.scala
@@ -8,13 +8,6 @@ import base._
import diagram._
import scala.collection._
-import scala.util.matching.Regex
-
-import symtab.Flags
-
-import io._
-
-import model.{ RootPackage => RootPackageEntity }
/** This trait extracts all required information for documentation from compilation units */
trait ModelFactoryTypeSupport {
@@ -28,14 +21,11 @@ trait ModelFactoryTypeSupport {
import global._
import definitions.{ ObjectClass, NothingClass, AnyClass, AnyValClass, AnyRefClass }
- import rootMirror.{ RootPackage, RootClass, EmptyPackage }
protected val typeCache = new mutable.LinkedHashMap[Type, TypeEntity]
/** */
def makeType(aType: Type, inTpl: TemplateImpl): TypeEntity = {
- def templatePackage = closestPackage(inTpl.sym)
-
def createTypeEntity = new TypeEntity {
private var nameBuffer = new StringBuilder
private var refBuffer = new immutable.TreeMap[Int, (LinkTo, Int)]
@@ -234,7 +224,6 @@ trait ModelFactoryTypeSupport {
def appendClauses = {
nameBuffer append " forSome {"
var first = true
- val qset = quantified.toSet
for (sym <- quantified) {
if (!first) { nameBuffer append ", " } else first = false
if (sym.isSingletonExistential) {
diff --git a/src/compiler/scala/tools/nsc/doc/model/TreeFactory.scala b/src/compiler/scala/tools/nsc/doc/model/TreeFactory.scala
index bd7534ded4..b972649194 100755
--- a/src/compiler/scala/tools/nsc/doc/model/TreeFactory.scala
+++ b/src/compiler/scala/tools/nsc/doc/model/TreeFactory.scala
@@ -21,7 +21,7 @@ trait TreeFactory { thisTreeFactory: ModelFactory with TreeFactory =>
def makeTree(rhs: Tree): Option[TreeEntity] = {
- var expr = new StringBuilder
+ val expr = new StringBuilder
var refs = new immutable.TreeMap[Int, (Entity, Int)] // start, (Entity to be linked to , end)
rhs.pos match {
@@ -39,7 +39,7 @@ trait TreeFactory { thisTreeFactory: ModelFactory with TreeFactory =>
* stores it in tree.refs with its position
*/
def makeLink(rhs: Tree){
- var start = pos.startOrPoint - firstIndex
+ val start = pos.startOrPoint - firstIndex
val end = pos.endOrPoint - firstIndex
if(start != end) {
var asym = rhs.symbol
diff --git a/src/compiler/scala/tools/nsc/doc/model/diagram/Diagram.scala b/src/compiler/scala/tools/nsc/doc/model/diagram/Diagram.scala
index c2aa1f17f3..150b293b81 100644
--- a/src/compiler/scala/tools/nsc/doc/model/diagram/Diagram.scala
+++ b/src/compiler/scala/tools/nsc/doc/model/diagram/Diagram.scala
@@ -36,20 +36,12 @@ case class InheritanceDiagram(thisNode: ThisNode,
override def isInheritanceDiagram = true
lazy val depthInfo = new DepthInfo {
def maxDepth = 3
- def nodeDepth(node: Node) =
- if (node == thisNode) 1
- else if (superClasses.contains(node)) 0
- else if (subClasses.contains(node)) 2
- else if (incomingImplicits.contains(node) || outgoingImplicits.contains(node)) 1
- else -1
}
}
trait DepthInfo {
/** Gives the maximum depth */
def maxDepth: Int
- /** Gives the depth of any node in the diagram or -1 if the node is not in the diagram */
- def nodeDepth(node: Node): Int
}
abstract class Node {
@@ -142,5 +134,4 @@ class ContentDiagramDepth(pack: ContentDiagram) extends DepthInfo {
}
val maxDepth = _maxDepth
- def nodeDepth(node: Node) = _nodeDepth.getOrElse(node, -1)
-} \ No newline at end of file
+}
diff --git a/src/compiler/scala/tools/nsc/doc/model/diagram/DiagramDirectiveParser.scala b/src/compiler/scala/tools/nsc/doc/model/diagram/DiagramDirectiveParser.scala
index cd60865ce7..96bba0498c 100644
--- a/src/compiler/scala/tools/nsc/doc/model/diagram/DiagramDirectiveParser.scala
+++ b/src/compiler/scala/tools/nsc/doc/model/diagram/DiagramDirectiveParser.scala
@@ -6,9 +6,6 @@ import model._
import java.util.regex.{Pattern, Matcher}
import scala.util.matching.Regex
-// statistics
-import html.page.diagram.DiagramStats
-
/**
* This trait takes care of parsing @{inheritance, content}Diagram annotations
*
@@ -153,7 +150,6 @@ trait DiagramDirectiveParser {
private val NodeSpecRegex = "\\\"[A-Za-z\\*][A-Za-z\\.\\*]*\\\""
private val NodeSpecPattern = Pattern.compile(NodeSpecRegex)
private val EdgeSpecRegex = "\\(" + NodeSpecRegex + "\\s*\\->\\s*" + NodeSpecRegex + "\\)"
- private val EdgeSpecPattern = Pattern.compile(NodeSpecRegex)
// And the composed regexes:
private val HideNodesRegex = new Regex("^hideNodes(\\s*" + NodeSpecRegex + ")+$")
private val HideEdgesRegex = new Regex("^hideEdges(\\s*" + EdgeSpecRegex + ")+$")
@@ -182,7 +178,7 @@ trait DiagramDirectiveParser {
def warning(message: String) = {
// we need the position from the package object (well, ideally its comment, but yeah ...)
val sym = if (template.sym.isPackage) template.sym.info.member(global.nme.PACKAGE) else template.sym
- assert((sym != global.NoSymbol) || (sym == global.definitions.RootPackage))
+ assert((sym != global.NoSymbol) || (sym == global.rootMirror.RootPackage))
global.reporter.warning(sym.pos, message)
}
diff --git a/src/compiler/scala/tools/nsc/doc/model/diagram/DiagramFactory.scala b/src/compiler/scala/tools/nsc/doc/model/diagram/DiagramFactory.scala
index 175b4a6472..ebac25bbe4 100644
--- a/src/compiler/scala/tools/nsc/doc/model/diagram/DiagramFactory.scala
+++ b/src/compiler/scala/tools/nsc/doc/model/diagram/DiagramFactory.scala
@@ -3,7 +3,6 @@ package model
package diagram
import model._
-import scala.collection.mutable
// statistics
import html.page.diagram.DiagramStats
@@ -47,7 +46,7 @@ trait DiagramFactory extends DiagramDirectiveParser {
val thisNode = ThisNode(tpl.resultType, Some(tpl))(Some(tpl.qualifiedName + " (this " + tpl.kind + ")"))
// superclasses
- var superclasses: List[Node] =
+ val superclasses: List[Node] =
tpl.parentTypes.collect {
case p: (TemplateEntity, TypeEntity) if !classExcluded(p._1) => NormalNode(p._2, Some(p._1))()
}.reverse
diff --git a/src/compiler/scala/tools/nsc/interactive/BuildManager.scala b/src/compiler/scala/tools/nsc/interactive/BuildManager.scala
index 3e7ac573e9..6b72eb12f8 100644
--- a/src/compiler/scala/tools/nsc/interactive/BuildManager.scala
+++ b/src/compiler/scala/tools/nsc/interactive/BuildManager.scala
@@ -7,11 +7,6 @@ package scala.tools.nsc
package interactive
import scala.collection._
-
-import scala.tools.nsc.reporters.{Reporter, ConsoleReporter}
-import scala.reflect.internal.util.FakePos
-
-import dependencies._
import io.AbstractFile
import scala.language.implicitConversions
@@ -20,9 +15,6 @@ trait BuildManager {
/** Add the given source files to the managed build process. */
def addSourceFiles(files: Set[AbstractFile])
- /** Remove the given files from the managed build process. */
- def removeFiles(files: Set[AbstractFile])
-
/** The given files have been modified by the user. Recompile
* them and their dependent files.
*/
@@ -76,8 +68,6 @@ object BuildManagerTest extends EvalLoop {
val settings = new Settings(buildError)
settings.Ybuildmanagerdebug.value = true
val command = new CompilerCommand(args.toList, settings)
-// settings.make.value = "off"
-// val buildManager: BuildManager = new SimpleBuildManager(settings)
val buildManager: BuildManager = new RefinedBuildManager(settings)
buildManager.addSourceFiles(command.files)
diff --git a/src/compiler/scala/tools/nsc/interactive/CompilerControl.scala b/src/compiler/scala/tools/nsc/interactive/CompilerControl.scala
index b4af8f00d6..f3cd41f32f 100644
--- a/src/compiler/scala/tools/nsc/interactive/CompilerControl.scala
+++ b/src/compiler/scala/tools/nsc/interactive/CompilerControl.scala
@@ -7,8 +7,6 @@ package interactive
import scala.util.control.ControlThrowable
import scala.tools.nsc.io.AbstractFile
-import scala.tools.nsc.symtab._
-import scala.tools.nsc.ast._
import scala.tools.nsc.util.FailedInterrupt
import scala.tools.nsc.util.EmptyAction
import scala.tools.nsc.util.WorkScheduler
diff --git a/src/compiler/scala/tools/nsc/interactive/ContextTrees.scala b/src/compiler/scala/tools/nsc/interactive/ContextTrees.scala
index b2568e34bd..93ef4c4d6c 100644
--- a/src/compiler/scala/tools/nsc/interactive/ContextTrees.scala
+++ b/src/compiler/scala/tools/nsc/interactive/ContextTrees.scala
@@ -6,7 +6,6 @@ package scala.tools.nsc
package interactive
import scala.collection.mutable.ArrayBuffer
-import scala.reflect.internal.util.Position
trait ContextTrees { self: Global =>
diff --git a/src/compiler/scala/tools/nsc/interactive/Global.scala b/src/compiler/scala/tools/nsc/interactive/Global.scala
index 0fc4fcaaf7..a34ebb2b8c 100644
--- a/src/compiler/scala/tools/nsc/interactive/Global.scala
+++ b/src/compiler/scala/tools/nsc/interactive/Global.scala
@@ -8,17 +8,13 @@ package interactive
import java.io.{ PrintWriter, StringWriter, FileReader, FileWriter }
import scala.collection.mutable
import mutable.{LinkedHashMap, SynchronizedMap, HashSet, SynchronizedSet}
-import scala.concurrent.SyncVar
import scala.util.control.ControlThrowable
import scala.tools.nsc.io.{ AbstractFile, LogReplay, Logger, NullLogger, Replayer }
-import scala.tools.nsc.util.{ WorkScheduler, MultiHashMap }
+import scala.tools.nsc.util.MultiHashMap
import scala.reflect.internal.util.{ SourceFile, BatchSourceFile, Position, RangePosition, NoPosition }
import scala.tools.nsc.reporters._
import scala.tools.nsc.symtab._
-import scala.tools.nsc.ast._
-import scala.tools.nsc.io.Pickler._
import scala.tools.nsc.typechecker.DivergentImplicit
-import scala.annotation.tailrec
import symtab.Flags.{ACCESSOR, PARAMACCESSOR}
import scala.annotation.elidable
import scala.language.implicitConversions
@@ -362,7 +358,7 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "")
}
// don't forget to service interrupt requests
- val iqs = scheduler.dequeueAllInterrupts(_.execute())
+ scheduler.dequeueAllInterrupts(_.execute())
debugLog("ShutdownReq: cleaning work queue (%d items)".format(units.size))
debugLog("Cleanup up responses (%d loadedType pending, %d parsedEntered pending)"
@@ -400,41 +396,6 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "")
if (typerRun != currentTyperRun) demandNewCompilerRun()
}
- def debugInfo(source : SourceFile, start : Int, length : Int): String = {
- println("DEBUG INFO "+source+"/"+start+"/"+length)
- val end = start+length
- val pos = rangePos(source, start, start, end)
-
- val tree = locateTree(pos)
- val sw = new StringWriter
- val pw = new PrintWriter(sw)
- newTreePrinter(pw).print(tree)
- pw.flush
-
- val typed = new Response[Tree]
- askTypeAt(pos, typed)
- val typ = typed.get.left.toOption match {
- case Some(tree) =>
- val sw = new StringWriter
- val pw = new PrintWriter(sw)
- newTreePrinter(pw).print(tree)
- pw.flush
- sw.toString
- case None => "<None>"
- }
-
- val completionResponse = new Response[List[Member]]
- askTypeCompletion(pos, completionResponse)
- val completion = completionResponse.get.left.toOption match {
- case Some(members) =>
- members mkString "\n"
- case None => "<None>"
- }
-
- source.content.view.drop(start).take(length).mkString+" : "+source.path+" ("+start+", "+end+
- ")\n\nlocateTree:\n"+sw.toString+"\n\naskTypeAt:\n"+typ+"\n\ncompletion:\n"+completion
- }
-
// ----------------- The Background Runner Thread -----------------------
private var threadId = 0
@@ -850,8 +811,6 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "")
respond(response) { scopeMembers(pos) }
}
- private val Dollar = newTermName("$")
-
private class Members[M <: Member] extends LinkedHashMap[Name, Set[M]] {
override def default(key: Name) = Set()
@@ -867,7 +826,7 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "")
def add(sym: Symbol, pre: Type, implicitlyAdded: Boolean)(toMember: (Symbol, Type) => M) {
if ((sym.isGetter || sym.isSetter) && sym.accessed != NoSymbol) {
add(sym.accessed, pre, implicitlyAdded)(toMember)
- } else if (!sym.name.decodedName.containsName(Dollar) && !sym.isSynthetic && sym.hasRawInfo) {
+ } else if (!sym.name.decodedName.containsName("$") && !sym.isSynthetic && sym.hasRawInfo) {
val symtpe = pre.memberType(sym) onTypeError ErrorType
matching(sym, symtpe, this(sym.name)) match {
case Some(m) =>
@@ -1060,7 +1019,7 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "")
}
@deprecated("SI-6458: Instrumentation logic will be moved out of the compiler.","2.10.0")
- def getInstrumented(source: SourceFile, line: Int, response: Response[(String, Array[Char])]) =
+ def getInstrumented(source: SourceFile, line: Int, response: Response[(String, Array[Char])]) {
try {
interruptsEnabled = false
respond(response) {
@@ -1069,6 +1028,7 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "")
} finally {
interruptsEnabled = true
}
+ }
// ---------------- Helper classes ---------------------------
@@ -1100,7 +1060,7 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "")
* @return true iff typechecked correctly
*/
private def applyPhase(phase: Phase, unit: CompilationUnit) {
- atPhase(phase) { phase.asInstanceOf[GlobalPhase] applyPhase unit }
+ enteringPhase(phase) { phase.asInstanceOf[GlobalPhase] applyPhase unit }
}
}
diff --git a/src/compiler/scala/tools/nsc/interactive/Picklers.scala b/src/compiler/scala/tools/nsc/interactive/Picklers.scala
index ffad19fbaa..1dc891b984 100644
--- a/src/compiler/scala/tools/nsc/interactive/Picklers.scala
+++ b/src/compiler/scala/tools/nsc/interactive/Picklers.scala
@@ -6,12 +6,10 @@ package scala.tools.nsc
package interactive
import util.InterruptReq
-import scala.reflect.internal.util.{SourceFile, BatchSourceFile}
-import io.{AbstractFile, PlainFile}
-
+import scala.reflect.internal.util.{ SourceFile, BatchSourceFile }
+import io.{ AbstractFile, PlainFile, Pickler, CondPickler }
import util.EmptyAction
-import scala.reflect.internal.util.{Position, RangePosition, NoPosition, OffsetPosition, TransparentPosition}
-import io.{Pickler, CondPickler}
+import scala.reflect.internal.util.{ RangePosition, OffsetPosition, TransparentPosition }
import io.Pickler._
import scala.collection.mutable
import mutable.ListBuffer
diff --git a/src/compiler/scala/tools/nsc/interactive/REPL.scala b/src/compiler/scala/tools/nsc/interactive/REPL.scala
index dacfa679dd..d1a29aeb07 100644
--- a/src/compiler/scala/tools/nsc/interactive/REPL.scala
+++ b/src/compiler/scala/tools/nsc/interactive/REPL.scala
@@ -5,15 +5,11 @@
package scala.tools.nsc
package interactive
-import scala.concurrent.SyncVar
import scala.reflect.internal.util._
-import scala.tools.nsc.symtab._
-import scala.tools.nsc.ast._
import scala.tools.nsc.reporters._
import scala.tools.nsc.io._
import scala.tools.nsc.scratchpad.SourceInserter
-import scala.tools.nsc.interpreter.AbstractFileClassLoader
-import java.io.{File, FileWriter}
+import java.io.FileWriter
/** Interface of interactive compiler to a client such as an IDE
*/
diff --git a/src/compiler/scala/tools/nsc/interactive/RangePositions.scala b/src/compiler/scala/tools/nsc/interactive/RangePositions.scala
index 64117bd8ee..5a1a4cbdeb 100644
--- a/src/compiler/scala/tools/nsc/interactive/RangePositions.scala
+++ b/src/compiler/scala/tools/nsc/interactive/RangePositions.scala
@@ -8,7 +8,6 @@ package interactive
import ast.Trees
import ast.Positions
import scala.reflect.internal.util.{SourceFile, Position, RangePosition, NoPosition}
-import scala.tools.nsc.util.WorkScheduler
import scala.collection.mutable.ListBuffer
/** Handling range positions
@@ -60,7 +59,7 @@ self: scala.tools.nsc.Global =>
}
// -------------- ensuring no overlaps -------------------------------
-
+
/** Ensure that given tree has no positions that overlap with
* any of the positions of `others`. This is done by
* shortening the range, assigning TransparentPositions
diff --git a/src/compiler/scala/tools/nsc/interactive/RefinedBuildManager.scala b/src/compiler/scala/tools/nsc/interactive/RefinedBuildManager.scala
index b2ef45a7d8..9873276f05 100644
--- a/src/compiler/scala/tools/nsc/interactive/RefinedBuildManager.scala
+++ b/src/compiler/scala/tools/nsc/interactive/RefinedBuildManager.scala
@@ -12,7 +12,6 @@ import scala.util.control.Breaks._
import scala.tools.nsc.symtab.Flags
import dependencies._
-import scala.reflect.internal.util.FakePos
import util.ClassPath
import io.AbstractFile
import scala.tools.util.PathResolver
@@ -49,7 +48,7 @@ class RefinedBuildManager(val settings: Settings) extends Changes with BuildMana
protected def newCompiler(settings: Settings) = new BuilderGlobal(settings)
val compiler = newCompiler(settings)
- import compiler.{ Symbol, Type, beforeErasure }
+ import compiler.{ Symbol, Type, enteringErasure }
import compiler.dependencyAnalysis.Inherited
private case class SymWithHistory(sym: Symbol, befErasure: Type)
@@ -69,7 +68,7 @@ class RefinedBuildManager(val settings: Settings) extends Changes with BuildMana
private var inherited: mutable.Map[AbstractFile, immutable.Set[Inherited]] = _
/** Reverse of definitions, used for caching */
- private var classes: mutable.Map[String, AbstractFile] =
+ private val classes: mutable.Map[String, AbstractFile] =
new mutable.HashMap[String, AbstractFile] {
override def default(key: String) = null
}
@@ -161,7 +160,7 @@ class RefinedBuildManager(val settings: Settings) extends Changes with BuildMana
isCorrespondingSym(s.sym, sym)) match {
case Some(SymWithHistory(oldSym, info)) =>
val changes = changeSet(oldSym.info, sym)
- val changesErasure = beforeErasure(changeSet(info, sym))
+ val changesErasure = enteringErasure(changeSet(info, sym))
changesOf(oldSym) = (changes ++ changesErasure).distinct
case _ =>
@@ -332,7 +331,7 @@ class RefinedBuildManager(val settings: Settings) extends Changes with BuildMana
for (src <- files; localDefs = compiler.dependencyAnalysis.definitions(src)) {
definitions(src) = (localDefs map (s => {
this.classes += s.fullName -> src
- SymWithHistory(s.cloneSymbol, beforeErasure(s.info.cloneInfo(s)))
+ SymWithHistory(s.cloneSymbol, enteringErasure(s.info.cloneInfo(s)))
}))
}
this.references = compiler.dependencyAnalysis.references
diff --git a/src/compiler/scala/tools/nsc/interactive/SimpleBuildManager.scala b/src/compiler/scala/tools/nsc/interactive/SimpleBuildManager.scala
index 465dcaaf1c..ff25dac7ac 100644
--- a/src/compiler/scala/tools/nsc/interactive/SimpleBuildManager.scala
+++ b/src/compiler/scala/tools/nsc/interactive/SimpleBuildManager.scala
@@ -8,9 +8,6 @@ package interactive
import scala.collection._
import scala.tools.nsc.reporters.{Reporter, ConsoleReporter}
-import dependencies._
-
-import scala.reflect.internal.util.FakePos
import io.AbstractFile
/** A simple build manager, using the default scalac dependency tracker.
diff --git a/src/compiler/scala/tools/nsc/interactive/tests/InteractiveTest.scala b/src/compiler/scala/tools/nsc/interactive/tests/InteractiveTest.scala
index 62d274bc70..f2614bcc42 100644
--- a/src/compiler/scala/tools/nsc/interactive/tests/InteractiveTest.scala
+++ b/src/compiler/scala/tools/nsc/interactive/tests/InteractiveTest.scala
@@ -7,14 +7,6 @@ package interactive
package tests
import core._
-
-import java.io.File.pathSeparatorChar
-import java.io.File.separatorChar
-
-import scala.annotation.migration
-import scala.reflect.internal.util.Position
-import scala.reflect.internal.util.SourceFile
-
import scala.collection.mutable.ListBuffer
/** A base class for writing interactive compiler tests.
@@ -110,6 +102,7 @@ abstract class InteractiveTest
}
/** Perform n random tests with random changes. */
+ /****
private def randomTests(n: Int, files: Array[SourceFile]) {
val tester = new Tester(n, files, settings) {
override val compiler = self.compiler
@@ -117,6 +110,7 @@ abstract class InteractiveTest
}
tester.run()
}
+ ****/
/** shutdown the presentation compiler. */
protected def shutdown() {
diff --git a/src/compiler/scala/tools/nsc/interactive/tests/InteractiveTestSettings.scala b/src/compiler/scala/tools/nsc/interactive/tests/InteractiveTestSettings.scala
index 4d85ab9d88..ad5c61b2b0 100644
--- a/src/compiler/scala/tools/nsc/interactive/tests/InteractiveTestSettings.scala
+++ b/src/compiler/scala/tools/nsc/interactive/tests/InteractiveTestSettings.scala
@@ -25,7 +25,6 @@ trait InteractiveTestSettings extends TestSettings with PresentationCompilerInst
* test.
*/
override protected def prepareSettings(settings: Settings) {
- import java.io.File._
def adjustPaths(paths: settings.PathSetting*) {
for (p <- paths if argsString.contains(p.name)) p.value = p.value.map {
case '/' => separatorChar
@@ -45,10 +44,10 @@ trait InteractiveTestSettings extends TestSettings with PresentationCompilerInst
case _ => ()
}
- // Make the --sourcepath path provided in the .flags file (if any) relative to the test's base directory
+ // Make the --sourcepath path provided in the .flags file (if any) relative to the test's base directory
if(settings.sourcepath.isSetByUser)
settings.sourcepath.value = (baseDir / Path(settings.sourcepath.value)).path
-
+
adjustPaths(settings.bootclasspath, settings.classpath, settings.javabootclasspath, settings.sourcepath)
}
@@ -67,4 +66,4 @@ trait InteractiveTestSettings extends TestSettings with PresentationCompilerInst
reporter.println("\targsString: %s".format(argsString))
super.printClassPath(reporter)
}
-} \ No newline at end of file
+}
diff --git a/src/compiler/scala/tools/nsc/interactive/tests/core/CoreTestDefs.scala b/src/compiler/scala/tools/nsc/interactive/tests/core/CoreTestDefs.scala
index c8e6b6ccce..9085eb56e6 100644
--- a/src/compiler/scala/tools/nsc/interactive/tests/core/CoreTestDefs.scala
+++ b/src/compiler/scala/tools/nsc/interactive/tests/core/CoreTestDefs.scala
@@ -3,7 +3,6 @@ package interactive
package tests.core
import scala.reflect.internal.util.Position
-import scala.tools.nsc.interactive.tests.core._
/** Set of core test definitions that are executed for each test run. */
private[tests] trait CoreTestDefs
@@ -77,7 +76,8 @@ private[tests] trait CoreTestDefs
// askHyperlinkPos for `Int` at (73,19) pi.scala --> class Int in package scala has null sourceFile!
val treePath = if (tree.symbol.sourceFile ne null) tree.symbol.sourceFile.path else null
val treeName = if (tree.symbol.sourceFile ne null) tree.symbol.sourceFile.name else null
- val sourceFile = sourceFiles.find(_.path == treePath) match {
+
+ sourceFiles.find(_.path == treePath) match {
case Some(source) =>
compiler.askLinkPos(tree.symbol, source, r)
r.get match {
@@ -97,4 +97,4 @@ private[tests] trait CoreTestDefs
}
}
}
-} \ No newline at end of file
+}
diff --git a/src/compiler/scala/tools/nsc/interactive/tests/core/PresentationCompilerInstance.scala b/src/compiler/scala/tools/nsc/interactive/tests/core/PresentationCompilerInstance.scala
index ea2333a65b..11ae7c974b 100644
--- a/src/compiler/scala/tools/nsc/interactive/tests/core/PresentationCompilerInstance.scala
+++ b/src/compiler/scala/tools/nsc/interactive/tests/core/PresentationCompilerInstance.scala
@@ -3,7 +3,6 @@ package interactive
package tests.core
import reporters.{Reporter => CompilerReporter}
-import scala.reflect.internal.util.Position
/** Trait encapsulating the creation of a presentation compiler's instance.*/
private[tests] trait PresentationCompilerInstance extends TestSettings {
diff --git a/src/compiler/scala/tools/nsc/interactive/tests/core/PresentationCompilerTestDef.scala b/src/compiler/scala/tools/nsc/interactive/tests/core/PresentationCompilerTestDef.scala
index 9cf2aa4fe4..4d5b4e1129 100644
--- a/src/compiler/scala/tools/nsc/interactive/tests/core/PresentationCompilerTestDef.scala
+++ b/src/compiler/scala/tools/nsc/interactive/tests/core/PresentationCompilerTestDef.scala
@@ -1,6 +1,5 @@
package scala.tools.nsc.interactive.tests.core
-import scala.tools.nsc.interactive.Global
import scala.reflect.internal.util.Position
trait PresentationCompilerTestDef {
@@ -16,4 +15,4 @@ trait PresentationCompilerTestDef {
protected def format(pos: Position): String =
(if(pos.isDefined) "(%d,%d)".format(pos.line, pos.column) else "<no position>")
-} \ No newline at end of file
+}
diff --git a/src/compiler/scala/tools/nsc/interactive/tests/core/SourcesCollector.scala b/src/compiler/scala/tools/nsc/interactive/tests/core/SourcesCollector.scala
index e80b741a8d..676feeba8a 100644
--- a/src/compiler/scala/tools/nsc/interactive/tests/core/SourcesCollector.scala
+++ b/src/compiler/scala/tools/nsc/interactive/tests/core/SourcesCollector.scala
@@ -4,7 +4,6 @@ import scala.reflect.internal.util.{SourceFile,BatchSourceFile}
import scala.tools.nsc.io.{AbstractFile,Path}
private[tests] object SourcesCollector {
- import Path._
type SourceFilter = Path => Boolean
/**
@@ -17,6 +16,5 @@ private[tests] object SourcesCollector {
}
private def source(file: Path): SourceFile = source(AbstractFile.getFile(file.toFile))
- private def source(filename: String): SourceFile = source(AbstractFile.getFile(filename))
private def source(file: AbstractFile): SourceFile = new BatchSourceFile(file)
-} \ No newline at end of file
+}
diff --git a/src/compiler/scala/tools/nsc/interpreter/AbstractFileClassLoader.scala b/src/compiler/scala/tools/nsc/interpreter/AbstractFileClassLoader.scala
index 638bca8a72..9fbd337b9d 100644
--- a/src/compiler/scala/tools/nsc/interpreter/AbstractFileClassLoader.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/AbstractFileClassLoader.scala
@@ -5,9 +5,9 @@
package scala.tools.nsc
package interpreter
-import scala.tools.nsc.io.{ File, AbstractFile }
+import scala.tools.nsc.io.AbstractFile
import util.ScalaClassLoader
-import java.net.URL
+import java.net.{ URL, URLConnection, URLStreamHandler }
import scala.collection.{ mutable, immutable }
/**
@@ -25,7 +25,7 @@ class AbstractFileClassLoader(val root: AbstractFile, parent: ClassLoader)
protected def findAbstractFile(name: String): AbstractFile = {
var file: AbstractFile = root
- val pathParts = classNameToPath(name) split '/'
+ val pathParts = name split '/'
for (dirPart <- pathParts.init) {
file = file.lookupName(dirPart, true)
@@ -55,11 +55,26 @@ class AbstractFileClassLoader(val root: AbstractFile, parent: ClassLoader)
return file
}
+ // parent delegation in JCL uses getResource; so either add parent.getResAsStream
+ // or implement findResource, which we do here as a study in scarlet (my complexion
+ // after looking at CLs and URLs)
+ override def findResource(name: String): URL = findAbstractFile(name) match {
+ case null => null
+ case file => new URL(null, "repldir:" + file.path, new URLStreamHandler {
+ override def openConnection(url: URL): URLConnection = new URLConnection(url) {
+ override def connect() { }
+ override def getInputStream = file.input
+ }
+ })
+ }
+
+ // this inverts delegation order: super.getResAsStr calls parent.getRes if we fail
override def getResourceAsStream(name: String) = findAbstractFile(name) match {
case null => super.getResourceAsStream(name)
case file => file.input
}
- override def classBytes(name: String): Array[Byte] = findAbstractFile(name) match {
+ // ScalaClassLoader.classBytes uses getResAsStream, so we'll try again before delegating
+ override def classBytes(name: String): Array[Byte] = findAbstractFile(classNameToPath(name)) match {
case null => super.classBytes(name)
case file => file.toByteArray
}
diff --git a/src/compiler/scala/tools/nsc/interpreter/ByteCode.scala b/src/compiler/scala/tools/nsc/interpreter/ByteCode.scala
index 40e9d3d600..48890a21c6 100644
--- a/src/compiler/scala/tools/nsc/interpreter/ByteCode.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/ByteCode.scala
@@ -7,7 +7,6 @@ package scala.tools.nsc
package interpreter
import java.lang.reflect
-import java.util.concurrent.ConcurrentHashMap
import util.ScalaClassLoader
import ScalaClassLoader.appLoader
import scala.reflect.NameTransformer._
@@ -39,25 +38,5 @@ object ByteCode {
}
yield names
- /** Attempts to retrieve case parameter names for given class name.
- */
- def caseParamNamesForPath(path: String) =
- for {
- module <- DECODER
- method <- decoderMethod("caseParamNames", classOf[String])
- names <- method.invoke(module, path).asInstanceOf[Option[List[String]]]
- }
- yield names
-
def aliasesForPackage(pkg: String) = aliasMap flatMap (_(pkg))
-
- /** Attempts to find type aliases in package objects.
- */
- def aliasForType(path: String): Option[String] = {
- val (pkg, name) = (path lastIndexOf '.') match {
- case -1 => return None
- case idx => (path take idx, path drop (idx + 1))
- }
- aliasesForPackage(pkg) flatMap (_ get name)
- }
}
diff --git a/src/compiler/scala/tools/nsc/interpreter/CodeHandlers.scala b/src/compiler/scala/tools/nsc/interpreter/CodeHandlers.scala
deleted file mode 100644
index 1741a82775..0000000000
--- a/src/compiler/scala/tools/nsc/interpreter/CodeHandlers.scala
+++ /dev/null
@@ -1,50 +0,0 @@
-/* NSC -- new Scala compiler
- * Copyright 2005-2013 LAMP/EPFL
- * @author Paul Phillips
- */
-
-package scala.tools.nsc
-package interpreter
-
-import CodeHandlers.NoSuccess
-import scala.util.control.ControlThrowable
-
-/**
- * The start of a simpler interface for utilizing the compiler with piecemeal
- * code strings. The "T" here could potentially be a Tree, a Type, a Symbol,
- * a Boolean, or something even more exotic.
- */
-trait CodeHandlers[T] {
- self =>
-
- // Expressions are composed of operators and operands.
- def expr(code: String): T
-
- // Statements occur as parts of blocks and templates.
- // A statement can be an import, a definition or an expression, or it can be empty.
- // Statements used in the template of a class definition can also be declarations.
- def stmt(code: String): T
- def stmts(code: String): Seq[T]
-
- object opt extends CodeHandlers[Option[T]] {
- val handler: PartialFunction[Throwable, Option[T]] = {
- case _: NoSuccess => None
- }
- val handlerSeq: PartialFunction[Throwable, Seq[Option[T]]] = {
- case _: NoSuccess => Nil
- }
-
- def expr(code: String) = try Some(self.expr(code)) catch handler
- def stmt(code: String) = try Some(self.stmt(code)) catch handler
- def stmts(code: String) = try (self.stmts(code) map (x => Some(x))) catch handlerSeq
- }
-}
-
-object CodeHandlers {
- def incomplete() = throw CodeIncomplete
- def fail(msg: String) = throw new CodeException(msg)
-
- trait NoSuccess extends ControlThrowable
- class CodeException(msg: String) extends RuntimeException(msg) with NoSuccess { }
- object CodeIncomplete extends CodeException("CodeIncomplete")
-}
diff --git a/src/compiler/scala/tools/nsc/interpreter/CommandLine.scala b/src/compiler/scala/tools/nsc/interpreter/CommandLine.scala
index 8042f0aee2..0ab92ab769 100644
--- a/src/compiler/scala/tools/nsc/interpreter/CommandLine.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/CommandLine.scala
@@ -10,5 +10,4 @@ package interpreter
*/
class CommandLine(arguments: List[String], error: String => Unit) extends CompilerCommand(arguments, error) {
override def cmdName = "scala"
- override lazy val fileEndings = List(".scalaint")
}
diff --git a/src/compiler/scala/tools/nsc/interpreter/Completion.scala b/src/compiler/scala/tools/nsc/interpreter/Completion.scala
index 1dfccbfbf7..84a5cb49ae 100644
--- a/src/compiler/scala/tools/nsc/interpreter/Completion.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/Completion.scala
@@ -23,8 +23,6 @@ object NoCompletion extends Completion {
}
object Completion {
- def empty: Completion = NoCompletion
-
case class Candidates(cursor: Int, candidates: List[String]) { }
val NoCandidates = Candidates(-1, Nil)
diff --git a/src/compiler/scala/tools/nsc/interpreter/CompletionAware.scala b/src/compiler/scala/tools/nsc/interpreter/CompletionAware.scala
index ab96f415db..3dd5d93390 100644
--- a/src/compiler/scala/tools/nsc/interpreter/CompletionAware.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/CompletionAware.scala
@@ -6,8 +6,6 @@
package scala.tools.nsc
package interpreter
-import scala.reflect.NameTransformer
-
/** An interface for objects which are aware of tab completion and
* will supply their own candidates and resolve their own paths.
*/
@@ -53,31 +51,3 @@ trait CompletionAware {
results.sorted
}
}
-
-object CompletionAware {
- val Empty = new CompletionAware { def completions(verbosity: Int) = Nil }
-
- def unapply(that: Any): Option[CompletionAware] = that match {
- case x: CompletionAware => Some((x))
- case _ => None
- }
-
- /** Create a CompletionAware object from the given functions.
- * The first should generate the list of completions whenever queried,
- * and the second should return Some(CompletionAware) object if
- * subcompletions are possible.
- */
- def apply(terms: () => List[String], followFunction: String => Option[CompletionAware]): CompletionAware =
- new CompletionAware {
- def completions = terms()
- def completions(verbosity: Int) = completions
- override def follow(id: String) = followFunction(id)
- }
-
- /** Convenience factories.
- */
- def apply(terms: () => List[String]): CompletionAware = apply(terms, _ => None)
- def apply(map: scala.collection.Map[String, CompletionAware]): CompletionAware =
- apply(() => map.keys.toList, map.get _)
-}
-
diff --git a/src/compiler/scala/tools/nsc/interpreter/CompletionOutput.scala b/src/compiler/scala/tools/nsc/interpreter/CompletionOutput.scala
index 13880bb8af..c647ef6f51 100644
--- a/src/compiler/scala/tools/nsc/interpreter/CompletionOutput.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/CompletionOutput.scala
@@ -38,7 +38,6 @@ trait CompletionOutput {
def relativize(str: String): String = quietString(str stripPrefix (pkg + "."))
def relativize(tp: Type): String = relativize(tp.normalize.toString)
- def relativize(sym: Symbol): String = relativize(sym.info)
def braceList(tparams: List[String]) = if (tparams.isEmpty) "" else (tparams map relativize).mkString("[", ", ", "]")
def parenList(params: List[Any]) = params.mkString("(", ", ", ")")
diff --git a/src/compiler/scala/tools/nsc/interpreter/ConsoleReaderHelper.scala b/src/compiler/scala/tools/nsc/interpreter/ConsoleReaderHelper.scala
index 07e36f4f27..48af261937 100644
--- a/src/compiler/scala/tools/nsc/interpreter/ConsoleReaderHelper.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/ConsoleReaderHelper.scala
@@ -7,19 +7,12 @@ package scala.tools.nsc
package interpreter
import scala.tools.jline.console.{ ConsoleReader, CursorBuffer }
-import scala.tools.jline.console.completer.CompletionHandler
-import Completion._
trait ConsoleReaderHelper extends ConsoleReader {
- def currentLine = "" + getCursorBuffer.buffer
- def currentPos = getCursorBuffer.cursor
def terminal = getTerminal()
def width = terminal.getWidth()
def height = terminal.getHeight()
- def paginate = isPaginationEnabled()
- def paginate_=(value: Boolean) = setPaginationEnabled(value)
- def goBack(num: Int): Unit
def readOneKey(prompt: String): Int
def eraseLine(): Unit
diff --git a/src/compiler/scala/tools/nsc/interpreter/Delimited.scala b/src/compiler/scala/tools/nsc/interpreter/Delimited.scala
index 80debfacb9..e88a044931 100644
--- a/src/compiler/scala/tools/nsc/interpreter/Delimited.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/Delimited.scala
@@ -26,7 +26,6 @@ trait Delimited {
def delimited: Char => Boolean
def escapeChars: List[Char] = List('\\')
- def quoteChars: List[(Char, Char)] = List(('\'', '\''), ('"', '"'))
/** Break String into args based on delimiting function.
*/
@@ -39,6 +38,4 @@ trait Delimited {
def isDelimiterChar(ch: Char) = delimited(ch)
def isEscapeChar(ch: Char): Boolean = escapeChars contains ch
- def isQuoteStart(ch: Char): Boolean = quoteChars map (_._1) contains ch
- def isQuoteEnd(ch: Char): Boolean = quoteChars map (_._2) contains ch
}
diff --git a/src/compiler/scala/tools/nsc/interpreter/ExprTyper.scala b/src/compiler/scala/tools/nsc/interpreter/ExprTyper.scala
index c4a672ac37..b087547cf8 100644
--- a/src/compiler/scala/tools/nsc/interpreter/ExprTyper.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/ExprTyper.scala
@@ -6,7 +6,6 @@
package scala.tools.nsc
package interpreter
-import scala.reflect.internal.util.BatchSourceFile
import scala.tools.nsc.ast.parser.Tokens.EOF
trait ExprTyper {
@@ -15,10 +14,11 @@ trait ExprTyper {
import repl._
import global.{ reporter => _, Import => _, _ }
import definitions._
- import syntaxAnalyzer.{ UnitParser, UnitScanner, token2name }
+ import syntaxAnalyzer.UnitParser
import naming.freshInternalVarName
- object codeParser extends { val global: repl.global.type = repl.global } with CodeHandlers[Tree] {
+ object codeParser {
+ val global: repl.global.type = repl.global
def applyRule[T](code: String, rule: UnitParser => T): T = {
reporter.reset()
val scanner = newUnitParser(code)
@@ -29,11 +29,7 @@ trait ExprTyper {
result
}
-
- def defns(code: String) = stmts(code) collect { case x: DefTree => x }
- def expr(code: String) = applyRule(code, _.expr())
def stmts(code: String) = applyRule(code, _.templateStats())
- def stmt(code: String) = stmts(code).last // guaranteed nonempty
}
/** Parse a line into a sequence of trees. Returns None if the input is incomplete. */
@@ -46,10 +42,6 @@ trait ExprTyper {
else Some(trees)
}
}
- // def parsesAsExpr(line: String) = {
- // import codeParser._
- // (opt expr line).isDefined
- // }
def symbolOfLine(code: String): Symbol = {
def asExpr(): Symbol = {
@@ -63,7 +55,7 @@ trait ExprTyper {
case IR.Success =>
val sym0 = symbolOfTerm(name)
// drop NullaryMethodType
- val sym = sym0.cloneSymbol setInfo afterTyper(sym0.info.finalResultType)
+ val sym = sym0.cloneSymbol setInfo exitingTyper(sym0.info.finalResultType)
if (sym.info.typeSymbol eq UnitClass) NoSymbol
else sym
case _ => NoSymbol
diff --git a/src/compiler/scala/tools/nsc/interpreter/ILoop.scala b/src/compiler/scala/tools/nsc/interpreter/ILoop.scala
index b7e07ecdd6..b2af53574f 100644
--- a/src/compiler/scala/tools/nsc/interpreter/ILoop.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/ILoop.scala
@@ -8,24 +8,20 @@ package interpreter
import Predef.{ println => _, _ }
import java.io.{ BufferedReader, FileReader }
-import java.util.concurrent.locks.ReentrantLock
-import scala.sys.process.Process
import session._
-import scala.util.Properties.{ jdkHome, javaVersion }
-import scala.tools.util.{ Javap }
import scala.annotation.tailrec
-import scala.collection.mutable.ListBuffer
-import scala.concurrent.ops
+import scala.util.Properties.{ jdkHome, javaVersion, versionString, javaVmName }
+import scala.tools.util.{ Javap }
import util.{ ClassPath, Exceptional, stringFromWriter, stringFromStream }
-import interpreter._
import io.{ File, Directory }
-import scala.reflect.NameTransformer._
import util.ScalaClassLoader
import ScalaClassLoader._
import scala.tools.util._
import scala.language.{implicitConversions, existentials}
-import scala.reflect.{ClassTag, classTag}
+import scala.reflect.classTag
import scala.tools.reflect.StdRuntimeTags._
+import scala.concurrent.{ ExecutionContext, Await, Future, future }
+import ExecutionContext.Implicits._
/** The Scala interactive shell. It provides a read-eval-print loop
* around the Interpreter class.
@@ -42,77 +38,41 @@ import scala.tools.reflect.StdRuntimeTags._
class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
extends AnyRef
with LoopCommands
- with ILoopInit
{
def this(in0: BufferedReader, out: JPrintWriter) = this(Some(in0), out)
def this() = this(None, new JPrintWriter(Console.out, true))
- var in: InteractiveReader = _ // the input stream from which commands come
- var settings: Settings = _
- var intp: IMain = _
-
@deprecated("Use `intp` instead.", "2.9.0") def interpreter = intp
@deprecated("Use `intp` instead.", "2.9.0") def interpreter_= (i: Interpreter): Unit = intp = i
- /** Having inherited the difficult "var-ness" of the repl instance,
- * I'm trying to work around it by moving operations into a class from
- * which it will appear a stable prefix.
- */
- private def onIntp[T](f: IMain => T): T = f(intp)
-
- class IMainOps[T <: IMain](val intp: T) {
- import intp._
- import global._
-
- def printAfterTyper(msg: => String) =
- intp.reporter printUntruncatedMessage afterTyper(msg)
-
- /** Strip NullaryMethodType artifacts. */
- private def replInfo(sym: Symbol) = {
- sym.info match {
- case NullaryMethodType(restpe) if sym.isAccessor => restpe
- case info => info
- }
- }
- def echoTypeStructure(sym: Symbol) =
- printAfterTyper("" + deconstruct.show(replInfo(sym)))
+ var in: InteractiveReader = _ // the input stream from which commands come
+ var settings: Settings = _
+ var intp: IMain = _
- def echoTypeSignature(sym: Symbol, verbose: Boolean) = {
- if (verbose) ILoop.this.echo("// Type signature")
- printAfterTyper("" + replInfo(sym))
+ private var globalFuture: Future[Boolean] = _
- if (verbose) {
- ILoop.this.echo("\n// Internal Type structure")
- echoTypeStructure(sym)
- }
- }
+ /** Print a welcome message */
+ def printWelcome() {
+ echo(s"""
+ |Welcome to Scala $versionString ($javaVmName, Java $javaVersion).
+ |Type in expressions to have them evaluated.
+ |Type :help for more information.""".trim.stripMargin
+ )
+ replinfo("[info] started at " + new java.util.Date)
}
- implicit def stabilizeIMain(intp: IMain) = new IMainOps[intp.type](intp)
- /** TODO -
- * -n normalize
- * -l label with case class parameter names
- * -c complete - leave nothing out
- */
- private def typeCommandInternal(expr: String, verbose: Boolean): Result = {
- onIntp { intp =>
- val sym = intp.symbolOfLine(expr)
- if (sym.exists) intp.echoTypeSignature(sym, verbose)
- else ""
- }
+ protected def asyncMessage(msg: String) {
+ if (isReplInfo || isReplPower)
+ echoAndRefresh(msg)
}
override def echoCommandMessage(msg: String) {
intp.reporter printUntruncatedMessage msg
}
- def isAsync = !settings.Yreplsync.value
lazy val power = new Power(intp, new StdReplVals(this))(tagOfStdReplVals, classTag[StdReplVals])
def history = in.history
- /** The context class loader at the time this object was created */
- protected val originalClassLoader = Thread.currentThread.getContextClassLoader
-
// classpath entries added via :cp
var addedClasspath: String = ""
@@ -166,20 +126,18 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
def helpCommand(line: String): Result = {
if (line == "") helpSummary()
else uniqueCommand(line) match {
- case Some(lc) => echo("\n" + lc.longHelp)
+ case Some(lc) => echo("\n" + lc.help)
case _ => ambiguousError(line)
}
}
private def helpSummary() = {
val usageWidth = commands map (_.usageMsg.length) max
- val formatStr = "%-" + usageWidth + "s %s %s"
+ val formatStr = "%-" + usageWidth + "s %s"
echo("All commands can be abbreviated, e.g. :he instead of :help.")
- echo("Those marked with a * have more detailed help, e.g. :help imports.\n")
commands foreach { cmd =>
- val star = if (cmd.hasLongHelp) "*" else " "
- echo(formatStr.format(cmd.usageMsg, star, cmd.help))
+ echo(formatStr.format(cmd.usageMsg, cmd.help))
}
}
private def ambiguousError(cmd: String): Result = {
@@ -229,10 +187,6 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
out println msg
out.flush()
}
- protected def echoNoNL(msg: String) = {
- out print msg
- out.flush()
- }
/** Search the history */
def searchHistory(_cmdline: String) {
@@ -243,8 +197,8 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
echo("%d %s".format(index + offset, line))
}
- private var currentPrompt = Properties.shellPromptString
- def setPrompt(prompt: String) = currentPrompt = prompt
+ private val currentPrompt = Properties.shellPromptString
+
/** Prompt to print when awaiting input */
def prompt = currentPrompt
@@ -257,7 +211,7 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
historyCommand,
cmd("h?", "<string>", "search the history", searchHistory),
cmd("imports", "[name name ...]", "show import history, identifying sources of names", importsCommand),
- cmd("implicits", "[-v]", "show the implicits in scope", implicitsCommand),
+ cmd("implicits", "[-v]", "show the implicits in scope", intp.implicitsCommand),
cmd("javap", "<path|class>", "disassemble a file or class name", javapCommand),
cmd("load", "<path>", "load and interpret a Scala file", loadCommand),
nullary("paste", "enter paste mode: all input up to ctrl-D compiled together", pasteCommand),
@@ -276,25 +230,9 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
cmd("phase", "<phase>", "set the implicit phase for power commands", phaseCommand)
)
- private def dumpCommand(): Result = {
- echo("" + power)
- history.asStrings takeRight 30 foreach echo
- in.redrawLine()
- }
- private def valsCommand(): Result = power.valsDescription
-
- private val typeTransforms = List(
- "scala.collection.immutable." -> "immutable.",
- "scala.collection.mutable." -> "mutable.",
- "scala.collection.generic." -> "generic.",
- "java.lang." -> "jl.",
- "scala.runtime." -> "runtime."
- )
-
private def importsCommand(line: String): Result = {
val tokens = words(line)
val handlers = intp.languageWildcardHandlers ++ intp.importHandlers
- val isVerbose = tokens contains "-v"
handlers.filterNot(_.importedSymbols.isEmpty).zipWithIndex foreach {
case (handler, idx) =>
@@ -316,63 +254,6 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
}
}
- private def implicitsCommand(line: String): Result = onIntp { intp =>
- import intp._
- import global._
-
- def p(x: Any) = intp.reporter.printMessage("" + x)
-
- // If an argument is given, only show a source with that
- // in its name somewhere.
- val args = line split "\\s+"
- val filtered = intp.implicitSymbolsBySource filter {
- case (source, syms) =>
- (args contains "-v") || {
- if (line == "") (source.fullName.toString != "scala.Predef")
- else (args exists (source.name.toString contains _))
- }
- }
-
- if (filtered.isEmpty)
- return "No implicits have been imported other than those in Predef."
-
- filtered foreach {
- case (source, syms) =>
- p("/* " + syms.size + " implicit members imported from " + source.fullName + " */")
-
- // This groups the members by where the symbol is defined
- val byOwner = syms groupBy (_.owner)
- val sortedOwners = byOwner.toList sortBy { case (owner, _) => afterTyper(source.info.baseClasses indexOf owner) }
-
- sortedOwners foreach {
- case (owner, members) =>
- // Within each owner, we cluster results based on the final result type
- // if there are more than a couple, and sort each cluster based on name.
- // This is really just trying to make the 100 or so implicits imported
- // by default into something readable.
- val memberGroups: List[List[Symbol]] = {
- val groups = members groupBy (_.tpe.finalResultType) toList
- val (big, small) = groups partition (_._2.size > 3)
- val xss = (
- (big sortBy (_._1.toString) map (_._2)) :+
- (small flatMap (_._2))
- )
-
- xss map (xs => xs sortBy (_.name.toString))
- }
-
- val ownerMessage = if (owner == source) " defined in " else " inherited from "
- p(" /* " + members.size + ownerMessage + owner.fullName + " */")
-
- memberGroups foreach { group =>
- group foreach (s => p(" " + intp.symbolDefString(s)))
- p("")
- }
- }
- p("")
- }
- }
-
private def findToolsJar() = {
val jdkPath = Directory(jdkHome)
val jar = jdkPath / "lib" / "tools.jar" toFile;
@@ -398,42 +279,17 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
}
}
- protected def newJavap() = new JavapClass(addToolsJarToLoader(), new IMain.ReplStrippingWriter(intp)) {
- override def tryClass(path: String): Array[Byte] = {
- val hd :: rest = path split '.' toList;
- // If there are dots in the name, the first segment is the
- // key to finding it.
- if (rest.nonEmpty) {
- intp optFlatName hd match {
- case Some(flat) =>
- val clazz = flat :: rest mkString NAME_JOIN_STRING
- val bytes = super.tryClass(clazz)
- if (bytes.nonEmpty) bytes
- else super.tryClass(clazz + MODULE_SUFFIX_STRING)
- case _ => super.tryClass(path)
- }
- }
- else {
- // Look for Foo first, then Foo$, but if Foo$ is given explicitly,
- // we have to drop the $ to find object Foo, then tack it back onto
- // the end of the flattened name.
- def className = intp flatName path
- def moduleName = (intp flatName path.stripSuffix(MODULE_SUFFIX_STRING)) + MODULE_SUFFIX_STRING
-
- val bytes = super.tryClass(className)
- if (bytes.nonEmpty) bytes
- else super.tryClass(moduleName)
- }
- }
- }
+ protected def newJavap() =
+ JavapClass(addToolsJarToLoader(), new IMain.ReplStrippingWriter(intp), Some(intp))
+
private lazy val javap = substituteAndLog[Javap]("javap", NoJavap)(newJavap())
// Still todo: modules.
private def typeCommand(line0: String): Result = {
line0.trim match {
case "" => ":type [-v] <expression>"
- case s if s startsWith "-v " => typeCommandInternal(s stripPrefix "-v " trim, true)
- case s => typeCommandInternal(s, false)
+ case s if s startsWith "-v " => intp.typeCommandInternal(s stripPrefix "-v " trim, true)
+ case s => intp.typeCommandInternal(s, false)
}
}
@@ -447,8 +303,6 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
private def javapCommand(line: String): Result = {
if (javap == null)
":javap unavailable, no tools.jar at %s. Set JDK_HOME.".format(jdkHome)
- else if (javaVersion startsWith "1.7")
- ":javap not yet working with java 1.7"
else if (line == "")
":javap [-lcsvp] [path1 path2 ...]"
else
@@ -458,37 +312,8 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
}
}
- private def wrapCommand(line: String): Result = {
- def failMsg = "Argument to :wrap must be the name of a method with signature [T](=> T): T"
- onIntp { intp =>
- import intp._
- import global._
+ private def pathToPhaseWrapper = intp.originalPath("$r") + ".phased.atCurrent"
- words(line) match {
- case Nil =>
- intp.executionWrapper match {
- case "" => "No execution wrapper is set."
- case s => "Current execution wrapper: " + s
- }
- case "clear" :: Nil =>
- intp.executionWrapper match {
- case "" => "No execution wrapper is set."
- case s => intp.clearExecutionWrapper() ; "Cleared execution wrapper."
- }
- case wrapper :: Nil =>
- intp.typeOfExpression(wrapper) match {
- case PolyType(List(targ), MethodType(List(arg), restpe)) =>
- intp setExecutionWrapper intp.pathToTerm(wrapper)
- "Set wrapper to '" + wrapper + "'"
- case tp =>
- failMsg + "\nFound: <unknown>"
- }
- case _ => failMsg
- }
- }
- }
-
- private def pathToPhaseWrapper = intp.pathToTerm("$r") + ".phased.atCurrent"
private def phaseCommand(name: String): Result = {
val phased: Phased = power.phased
import phased.NoPhaseName
@@ -547,33 +372,30 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
true
}
+ // return false if repl should exit
+ def processLine(line: String): Boolean = {
+ import scala.concurrent.duration._
+ Await.ready(globalFuture, 60.seconds)
+
+ (line ne null) && (command(line) match {
+ case Result(false, _) => false
+ case Result(_, Some(line)) => addReplay(line) ; true
+ case _ => true
+ })
+ }
+
+ private def readOneLine() = {
+ out.flush()
+ in readLine prompt
+ }
+
/** The main read-eval-print loop for the repl. It calls
* command() for each line of input, and stops when
* command() returns false.
*/
- def loop() {
- def readOneLine() = {
- out.flush()
- in readLine prompt
- }
- // return false if repl should exit
- def processLine(line: String): Boolean = {
- if (isAsync) {
- if (!awaitInitialized()) return false
- runThunks()
- }
- if (line eq null) false // assume null means EOF
- else command(line) match {
- case Result(false, _) => false
- case Result(_, Some(finalLine)) => addReplay(finalLine) ; true
- case _ => true
- }
- }
- def innerLoop() {
- if ( try processLine(readOneLine()) catch crashRecovery )
- innerLoop()
- }
- innerLoop()
+ @tailrec final def loop() {
+ if ( try processLine(readOneLine()) catch crashRecovery )
+ loop()
}
/** interpret all lines from a specified file */
@@ -819,48 +641,39 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
SimpleReader()
}
}
- def process(settings: Settings): Boolean = savingContextLoader {
- this.settings = settings
- createInterpreter()
- // sets in to some kind of reader depending on environmental cues
- in = in0 match {
- case Some(reader) => SimpleReader(reader, out, true)
- case None =>
- // some post-initialization
- chooseReader(settings) match {
- case x: JLineReader => addThunk(x.consoleReader.postInit) ; x
- case x => x
- }
+ private def loopPostInit() {
+ in match {
+ case x: JLineReader => x.consoleReader.postInit
+ case _ =>
}
// Bind intp somewhere out of the regular namespace where
// we can get at it in generated code.
- addThunk(intp.quietBind(NamedParam[IMain]("$intp", intp)(tagOfIMain, classTag[IMain])))
- addThunk({
- import scala.tools.nsc.io._
- import Properties.userHome
- import scala.compat.Platform.EOL
- val autorun = replProps.replAutorunCode.option flatMap (f => io.File(f).safeSlurp())
- if (autorun.isDefined) intp.quietRun(autorun.get)
- })
-
- loadFiles(settings)
- // it is broken on startup; go ahead and exit
- if (intp.reporter.hasErrors)
- return false
-
- // This is about the illusion of snappiness. We call initialize()
- // which spins off a separate thread, then print the prompt and try
- // our best to look ready. The interlocking lazy vals tend to
- // inter-deadlock, so we break the cycle with a single asynchronous
- // message to an actor.
- if (isAsync) {
- intp initialize initializedCallback()
- createAsyncListener() // listens for signal to run postInitialization
+ intp.quietBind(NamedParam[IMain]("$intp", intp)(tagOfIMain, classTag[IMain]))
+ // Auto-run code via some setting.
+ ( replProps.replAutorunCode.option
+ flatMap (f => io.File(f).safeSlurp())
+ foreach (intp quietRun _)
+ )
+ // classloader and power mode setup
+ intp.setContextClassLoader
+ if (isReplPower) {
+ replProps.power setValue true
+ unleashAndSetPhase()
+ asyncMessage(power.banner)
}
- else {
+ }
+ def process(settings: Settings): Boolean = savingContextLoader {
+ this.settings = settings
+ createInterpreter()
+
+ // sets in to some kind of reader depending on environmental cues
+ in = in0.fold(chooseReader(settings))(r => SimpleReader(r, out, true))
+ globalFuture = future {
intp.initializeSynchronous()
- postInitialization()
+ loopPostInit()
+ loadFiles(settings)
+ !intp.reporter.hasErrors
}
printWelcome()
@@ -871,27 +684,12 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
true
}
- /** process command-line arguments and do as they request */
- def process(args: Array[String]): Boolean = {
- val command = new CommandLine(args.toList, echo)
- def neededHelp(): String =
- (if (command.settings.help.value) command.usageMsg + "\n" else "") +
- (if (command.settings.Xhelp.value) command.xusageMsg + "\n" else "")
-
- // if they asked for no help and command is valid, we call the real main
- neededHelp() match {
- case "" => command.ok && process(command.settings)
- case help => echoNoNL(help) ; true
- }
- }
-
@deprecated("Use `process` instead", "2.9.0")
- def main(settings: Settings): Unit = process(settings)
+ def main(settings: Settings): Unit = process(settings) //used by sbt
}
object ILoop {
implicit def loopToInterpreter(repl: ILoop): IMain = repl.intp
- private def echo(msg: String) = Console println msg
// Designed primarily for use by test code: take a String with a
// bunch of code, and prints out a transcript of what it would look
diff --git a/src/compiler/scala/tools/nsc/interpreter/ILoopInit.scala b/src/compiler/scala/tools/nsc/interpreter/ILoopInit.scala
deleted file mode 100644
index e3c0494fa3..0000000000
--- a/src/compiler/scala/tools/nsc/interpreter/ILoopInit.scala
+++ /dev/null
@@ -1,125 +0,0 @@
-/* NSC -- new Scala compiler
- * Copyright 2005-2013 LAMP/EPFL
- * @author Paul Phillips
- */
-
-package scala.tools.nsc
-package interpreter
-
-import scala.reflect.internal.util.Position
-import scala.util.control.Exception.ignoring
-import scala.tools.nsc.util.stackTraceString
-
-/**
- * Machinery for the asynchronous initialization of the repl.
- */
-trait ILoopInit {
- self: ILoop =>
-
- /** Print a welcome message */
- def printWelcome() {
- import Properties._
- val welcomeMsg =
- """|Welcome to Scala %s (%s, Java %s).
- |Type in expressions to have them evaluated.
- |Type :help for more information.""" .
- stripMargin.format(versionString, javaVmName, javaVersion)
- echo(welcomeMsg)
- replinfo("[info] started at " + new java.util.Date)
- }
-
- protected def asyncMessage(msg: String) {
- if (isReplInfo || isReplPower)
- echoAndRefresh(msg)
- }
-
- private val initLock = new java.util.concurrent.locks.ReentrantLock()
- private val initCompilerCondition = initLock.newCondition() // signal the compiler is initialized
- private val initLoopCondition = initLock.newCondition() // signal the whole repl is initialized
- private val initStart = System.nanoTime
-
- private def withLock[T](body: => T): T = {
- initLock.lock()
- try body
- finally initLock.unlock()
- }
- // a condition used to ensure serial access to the compiler.
- @volatile private var initIsComplete = false
- @volatile private var initError: String = null
- private def elapsed() = "%.3f".format((System.nanoTime - initStart).toDouble / 1000000000L)
-
- // the method to be called when the interpreter is initialized.
- // Very important this method does nothing synchronous (i.e. do
- // not try to use the interpreter) because until it returns, the
- // repl's lazy val `global` is still locked.
- protected def initializedCallback() = withLock(initCompilerCondition.signal())
-
- // Spins off a thread which awaits a single message once the interpreter
- // has been initialized.
- protected def createAsyncListener() = {
- io.spawn {
- withLock(initCompilerCondition.await())
- asyncMessage("[info] compiler init time: " + elapsed() + " s.")
- postInitialization()
- }
- }
-
- // called from main repl loop
- protected def awaitInitialized(): Boolean = {
- if (!initIsComplete)
- withLock { while (!initIsComplete) initLoopCondition.await() }
- if (initError != null) {
- println("""
- |Failed to initialize the REPL due to an unexpected error.
- |This is a bug, please, report it along with the error diagnostics printed below.
- |%s.""".stripMargin.format(initError)
- )
- false
- } else true
- }
- // private def warningsThunks = List(
- // () => intp.bind("lastWarnings", "" + typeTag[List[(Position, String)]], intp.lastWarnings _),
- // )
-
- protected def postInitThunks = List[Option[() => Unit]](
- Some(intp.setContextClassLoader _),
- if (isReplPower) Some(() => enablePowerMode(true)) else None
- ).flatten
- // ++ (
- // warningsThunks
- // )
- // called once after init condition is signalled
- protected def postInitialization() {
- try {
- postInitThunks foreach (f => addThunk(f()))
- runThunks()
- } catch {
- case ex: Throwable =>
- initError = stackTraceString(ex)
- throw ex
- } finally {
- initIsComplete = true
-
- if (isAsync) {
- asyncMessage("[info] total init time: " + elapsed() + " s.")
- withLock(initLoopCondition.signal())
- }
- }
- }
- // code to be executed only after the interpreter is initialized
- // and the lazy val `global` can be accessed without risk of deadlock.
- private var pendingThunks: List[() => Unit] = Nil
- protected def addThunk(body: => Unit) = synchronized {
- pendingThunks :+= (() => body)
- }
- protected def runThunks(): Unit = synchronized {
- if (pendingThunks.nonEmpty)
- repldbg("Clearing " + pendingThunks.size + " thunks.")
-
- while (pendingThunks.nonEmpty) {
- val thunk = pendingThunks.head
- pendingThunks = pendingThunks.tail
- thunk()
- }
- }
-}
diff --git a/src/compiler/scala/tools/nsc/interpreter/IMain.scala b/src/compiler/scala/tools/nsc/interpreter/IMain.scala
index 2b97f81024..91e909b1f1 100644
--- a/src/compiler/scala/tools/nsc/interpreter/IMain.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/IMain.scala
@@ -11,37 +11,19 @@ import util.stringFromWriter
import scala.reflect.internal.util._
import java.net.URL
import scala.sys.BooleanProp
-import io.VirtualDirectory
import scala.tools.nsc.io.AbstractFile
import reporters._
-import symtab.Flags
-import scala.reflect.internal.Names
import scala.tools.util.PathResolver
import scala.tools.nsc.util.ScalaClassLoader
import ScalaClassLoader.URLClassLoader
import scala.tools.nsc.util.Exceptional.unwrap
import scala.collection.{ mutable, immutable }
-import scala.util.control.Exception.{ ultimately }
import IMain._
import java.util.concurrent.Future
-import typechecker.Analyzer
-import scala.language.implicitConversions
import scala.reflect.runtime.{ universe => ru }
import scala.reflect.{ ClassTag, classTag }
import scala.tools.reflect.StdRuntimeTags._
-/** directory to save .class files to */
-private class ReplVirtualDirectory(out: JPrintWriter) extends VirtualDirectory("(memory)", None) {
- private def pp(root: AbstractFile, indentLevel: Int) {
- val spaces = " " * indentLevel
- out.println(spaces + root.name)
- if (root.isDirectory)
- root.toList sortBy (_.name) foreach (x => pp(x, indentLevel + 1))
- }
- // print the contents hierarchically
- def show() = pp(this, 0)
-}
-
/** An interpreter for Scala code.
*
* The main public entry points are compile(), interpret(), and bind().
@@ -77,16 +59,19 @@ private class ReplVirtualDirectory(out: JPrintWriter) extends VirtualDirectory("
class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends Imports {
imain =>
- /** Leading with the eagerly evaluated.
- */
- val virtualDirectory: VirtualDirectory = new ReplVirtualDirectory(out) // "directory" for classfiles
- private var currentSettings: Settings = initialSettings
- private[nsc] var printResults = true // whether to print result lines
- private[nsc] var totalSilence = false // whether to print anything
- private var _initializeComplete = false // compiler is initialized
- private var _isInitialized: Future[Boolean] = null // set up initialization future
- private var bindExceptions = true // whether to bind the lastException variable
- private var _executionWrapper = "" // code to be wrapped around all lines
+ object replOutput extends ReplOutput(settings.Yreploutdir) { }
+
+ @deprecated("Use replOutput.dir instead", "2.11.0")
+ def virtualDirectory = replOutput.dir
+ // Used in a test case.
+ def showDirectory() = replOutput.show(out)
+
+ private[nsc] var printResults = true // whether to print result lines
+ private[nsc] var totalSilence = false // whether to print anything
+ private var _initializeComplete = false // compiler is initialized
+ private var _isInitialized: Future[Boolean] = null // set up initialization future
+ private var bindExceptions = true // whether to bind the lastException variable
+ private var _executionWrapper = "" // code to be wrapped around all lines
/** We're going to go to some trouble to initialize the compiler asynchronously.
* It's critical that nothing call into it until it's been initialized or we will
@@ -98,20 +83,11 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
private var _classLoader: AbstractFileClassLoader = null // active classloader
private val _compiler: Global = newCompiler(settings, reporter) // our private compiler
- private val nextReqId = {
- var counter = 0
- () => { counter += 1 ; counter }
- }
-
def compilerClasspath: Seq[URL] = (
if (isInitializeComplete) global.classPath.asURLs
else new PathResolver(settings).result.asURLs // the compiler's classpath
)
- def settings = currentSettings
- def mostRecentLine = prevRequestList match {
- case Nil => ""
- case req :: _ => req.originalLine
- }
+ def settings = initialSettings
// Run the code body with the given boolean settings flipped to true.
def withoutWarnings[T](body: => T): T = beQuietDuring {
val saved = settings.nowarn.value
@@ -126,12 +102,6 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
def this(settings: Settings) = this(settings, new NewLinePrintWriter(new ConsoleWriter, true))
def this() = this(new Settings())
- lazy val repllog: Logger = new Logger {
- val out: JPrintWriter = imain.out
- val isInfo: Boolean = BooleanProp keyExists "scala.repl.info"
- val isDebug: Boolean = BooleanProp keyExists "scala.repl.debug"
- val isTrace: Boolean = BooleanProp keyExists "scala.repl.trace"
- }
lazy val formatting: Formatting = new Formatting {
val prompt = Properties.shellPromptString
}
@@ -153,6 +123,8 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
catch AbstractOrMissingHandler()
}
private def tquoted(s: String) = "\"\"\"" + s + "\"\"\""
+ private val logScope = scala.sys.props contains "scala.repl.scope"
+ private def scopelog(msg: String) = if (logScope) Console.err.println(msg)
// argument is a thunk to execute after init is done
def initialize(postInitSignal: => Unit) {
@@ -187,15 +159,24 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
else null
}
}
- @deprecated("Use `global` for access to the compiler instance.", "2.9.0")
- lazy val compiler: global.type = global
import global._
- import definitions.{ScalaPackage, JavaLangPackage, termMember, typeMember}
- import rootMirror.{RootClass, getClassIfDefined, getModuleIfDefined, getRequiredModule, getRequiredClass}
+ import definitions.{ ObjectClass, termMember, dropNullaryMethod}
+
+ lazy val runtimeMirror = ru.runtimeMirror(classLoader)
+
+ private def noFatal(body: => Symbol): Symbol = try body catch { case _: FatalError => NoSymbol }
+
+ def getClassIfDefined(path: String) = (
+ noFatal(runtimeMirror staticClass path)
+ orElse noFatal(rootMirror staticClass path)
+ )
+ def getModuleIfDefined(path: String) = (
+ noFatal(runtimeMirror staticModule path)
+ orElse noFatal(rootMirror staticModule path)
+ )
implicit class ReplTypeOps(tp: Type) {
- def orElse(other: => Type): Type = if (tp ne NoType) tp else other
def andAlso(fn: Type => Type): Type = if (tp eq NoType) tp else fn(tp)
}
@@ -208,10 +189,9 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
// make sure we don't overwrite their unwisely named res3 etc.
def freshUserTermName(): TermName = {
val name = newTermName(freshUserVarName())
- if (definedNameMap contains name) freshUserTermName()
+ if (replScope containsName name) freshUserTermName()
else name
}
- def isUserTermName(name: Name) = isUserVarName("" + name)
def isInternalTermName(name: Name) = isInternalVarName("" + name)
}
import naming._
@@ -260,9 +240,12 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
/** Instantiate a compiler. Overridable. */
protected def newCompiler(settings: Settings, reporter: Reporter): ReplGlobal = {
- settings.outputDirs setSingleOutput virtualDirectory
+ settings.outputDirs setSingleOutput replOutput.dir
settings.exposeEmptyPackage.value = true
- new Global(settings, reporter) with ReplGlobal
+ if (settings.Yrangepos.value)
+ new Global(settings, reporter) with ReplGlobal with interactive.RangePositions
+ else
+ new Global(settings, reporter) with ReplGlobal
}
/** Parent classloader. Overridable. */
@@ -295,20 +278,59 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
ensureClassLoader()
_classLoader
}
- private class TranslatingClassLoader(parent: ClassLoader) extends AbstractFileClassLoader(virtualDirectory, parent) {
+
+ def backticked(s: String): String = (
+ (s split '.').toList map {
+ case "_" => "_"
+ case s if nme.keywords(newTermName(s)) => s"`$s`"
+ case s => s
+ } mkString "."
+ )
+
+ abstract class PhaseDependentOps {
+ def shift[T](op: => T): T
+
+ def path(name: => Name): String = shift(path(symbolOfName(name)))
+ def path(sym: Symbol): String = backticked(shift(sym.fullName))
+ def sig(sym: Symbol): String = shift(sym.defString)
+ }
+ object typerOp extends PhaseDependentOps {
+ def shift[T](op: => T): T = exitingTyper(op)
+ }
+ object flatOp extends PhaseDependentOps {
+ def shift[T](op: => T): T = exitingFlatten(op)
+ }
+
+ def originalPath(name: String): String = originalPath(name: TermName)
+ def originalPath(name: Name): String = typerOp path name
+ def originalPath(sym: Symbol): String = typerOp path sym
+ def flatPath(sym: Symbol): String = flatOp shift sym.javaClassName
+ def translatePath(path: String) = {
+ val sym = if (path endsWith "$") symbolOfTerm(path.init) else symbolOfIdent(path)
+ sym match {
+ case NoSymbol => None
+ case _ => Some(flatPath(sym))
+ }
+ }
+ def translateEnclosingClass(n: String) = {
+ def enclosingClass(s: Symbol): Symbol =
+ if (s == NoSymbol || s.isClass) s else enclosingClass(s.owner)
+ enclosingClass(symbolOfTerm(n)) match {
+ case NoSymbol => None
+ case c => Some(flatPath(c))
+ }
+ }
+
+ private class TranslatingClassLoader(parent: ClassLoader) extends AbstractFileClassLoader(replOutput.dir, parent) {
/** Overridden here to try translating a simple name to the generated
* class name if the original attempt fails. This method is used by
* getResourceAsStream as well as findClass.
*/
- override protected def findAbstractFile(name: String): AbstractFile = {
+ override protected def findAbstractFile(name: String): AbstractFile =
super.findAbstractFile(name) match {
- // deadlocks on startup if we try to translate names too early
- case null if isInitializeComplete =>
- generatedName(name) map (x => super.findAbstractFile(x)) orNull
- case file =>
- file
+ case null => translatePath(name) map (super.findAbstractFile(_)) orNull
+ case file => file
}
- }
}
private def makeClassLoader(): AbstractFileClassLoader =
new TranslatingClassLoader(parentClassLoader match {
@@ -316,32 +338,11 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
case p => new URLClassLoader(compilerClasspath, p)
})
- def getInterpreterClassLoader() = classLoader
-
// Set the current Java "context" class loader to this interpreter's class loader
def setContextClassLoader() = classLoader.setAsContext()
- /** Given a simple repl-defined name, returns the real name of
- * the class representing it, e.g. for "Bippy" it may return
- * {{{
- * $line19.$read$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$Bippy
- * }}}
- */
- def generatedName(simpleName: String): Option[String] = {
- if (simpleName endsWith nme.MODULE_SUFFIX_STRING) optFlatName(simpleName.init) map (_ + nme.MODULE_SUFFIX_STRING)
- else optFlatName(simpleName)
- }
- def flatName(id: String) = optFlatName(id) getOrElse id
- def optFlatName(id: String) = requestForIdent(id) map (_ fullFlatName id)
-
- def allDefinedNames = definedNameMap.keys.toList.sorted
- def pathToType(id: String): String = pathToName(newTypeName(id))
- def pathToTerm(id: String): String = pathToName(newTermName(id))
- def pathToName(name: Name): String = {
- if (definedNameMap contains name)
- definedNameMap(name) fullPath name
- else name.toString
- }
+ def allDefinedNames: List[Name] = exitingTyper(replScope.toList.map(_.name).sorted)
+ def unqualifiedIds: List[String] = allDefinedNames map (_.decode) sorted
/** Most recent tree handled which wasn't wholly synthetic. */
private def mostRecentlyHandledTree: Option[Tree] = {
@@ -354,50 +355,47 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
None
}
- /** Stubs for work in progress. */
- def handleTypeRedefinition(name: TypeName, old: Request, req: Request) = {
- for (t1 <- old.simpleNameOfType(name) ; t2 <- req.simpleNameOfType(name)) {
- repldbg("Redefining type '%s'\n %s -> %s".format(name, t1, t2))
- }
- }
+ private def updateReplScope(sym: Symbol, isDefined: Boolean) {
+ def log(what: String) {
+ val mark = if (sym.isType) "t " else "v "
+ val name = exitingTyper(sym.nameString)
+ val info = cleanTypeAfterTyper(sym)
+ val defn = sym defStringSeenAs info
- def handleTermRedefinition(name: TermName, old: Request, req: Request) = {
- for (t1 <- old.compilerTypeOf get name ; t2 <- req.compilerTypeOf get name) {
- // Printing the types here has a tendency to cause assertion errors, like
- // assertion failed: fatal: <refinement> has owner value x, but a class owner is required
- // so DBG is by-name now to keep it in the family. (It also traps the assertion error,
- // but we don't want to unnecessarily risk hosing the compiler's internal state.)
- repldbg("Redefining term '%s'\n %s -> %s".format(name, t1, t2))
+ scopelog(f"[$mark$what%6s] $name%-25s $defn%s")
+ }
+ if (ObjectClass isSubClass sym.owner) return
+ // unlink previous
+ replScope lookupAll sym.name foreach { sym =>
+ log("unlink")
+ replScope unlink sym
}
+ val what = if (isDefined) "define" else "import"
+ log(what)
+ replScope enter sym
}
def recordRequest(req: Request) {
- if (req == null || referencedNameMap == null)
+ if (req == null)
return
prevRequests += req
- req.referencedNames foreach (x => referencedNameMap(x) = req)
// warning about serially defining companions. It'd be easy
// enough to just redefine them together but that may not always
// be what people want so I'm waiting until I can do it better.
- for {
- name <- req.definedNames filterNot (x => req.definedNames contains x.companionName)
- oldReq <- definedNameMap get name.companionName
- newSym <- req.definedSymbols get name
- oldSym <- oldReq.definedSymbols get name.companionName
- } {
- afterTyper(replwarn(s"warning: previously defined $oldSym is not a companion to $newSym."))
- replwarn("Companions must be defined together; you may wish to use :paste mode for this.")
- }
-
- // Updating the defined name map
- req.definedNames foreach { name =>
- if (definedNameMap contains name) {
- if (name.isTypeName) handleTypeRedefinition(name.toTypeName, definedNameMap(name), req)
- else handleTermRedefinition(name.toTermName, definedNameMap(name), req)
+ exitingTyper {
+ req.defines filterNot (s => req.defines contains s.companionSymbol) foreach { newSym =>
+ val companion = newSym.name.companionName
+ replScope lookup companion andAlso { oldSym =>
+ replwarn(s"warning: previously defined $oldSym is not a companion to $newSym.")
+ replwarn("Companions must be defined together; you may wish to use :paste mode for this.")
+ }
}
- definedNameMap(name) = req
+ }
+ exitingTyper {
+ req.imports foreach (sym => updateReplScope(sym, isDefined = false))
+ req.defines foreach (sym => updateReplScope(sym, isDefined = true))
}
}
@@ -406,19 +404,6 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
printMessage(msg)
}
- def isParseable(line: String): Boolean = {
- beSilentDuring {
- try parse(line) match {
- case Some(xs) => xs.nonEmpty // parses as-is
- case None => true // incomplete
- }
- catch { case x: Exception => // crashed the compiler
- replwarn("Exception in isParseable(\"" + line + "\"): " + x)
- false
- }
- }
- }
-
def compileSourcesKeepingRun(sources: SourceFile*) = {
val run = new Run()
reporter.reset()
@@ -445,18 +430,6 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
executingRequest
}
- // rewriting "5 // foo" to "val x = { 5 // foo }" creates broken code because
- // the close brace is commented out. Strip single-line comments.
- // ... but for error message output reasons this is not used, and rather than
- // enclosing in braces it is constructed like "val x =\n5 // foo".
- private def removeComments(line: String): String = {
- showCodeIfDebugging(line) // as we're about to lose our // show
- line.lines map (s => s indexOf "//" match {
- case -1 => s
- case idx => s take idx
- }) mkString "\n"
- }
-
private def safePos(t: Tree, alt: Int): Int =
try t.pos.startOrPoint
catch { case _: UnsupportedOperationException => alt }
@@ -612,7 +585,7 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
*/
def bind(name: String, boundType: String, value: Any, modifiers: List[String] = Nil): IR.Result = {
val bindRep = new ReadEvalPrint()
- val run = bindRep.compile("""
+ bindRep.compile("""
|object %s {
| var value: %s = _
| def set(x: Any) = value = x.asInstanceOf[%s]
@@ -642,24 +615,15 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
def rebind(p: NamedParam): IR.Result = {
val name = p.name
- val oldType = typeOfTerm(name) orElse { return IR.Error }
val newType = p.tpe
val tempName = freshInternalVarName()
quietRun("val %s = %s".format(tempName, name))
quietRun("val %s = %s.asInstanceOf[%s]".format(name, tempName, newType))
}
- def quietImport(ids: String*): IR.Result = beQuietDuring(addImports(ids: _*))
- def addImports(ids: String*): IR.Result =
- if (ids.isEmpty) IR.Success
- else interpret("import " + ids.mkString(", "))
-
def quietBind(p: NamedParam): IR.Result = beQuietDuring(bind(p))
def bind(p: NamedParam): IR.Result = bind(p.name, p.tpe, p.value)
def bind[T: ru.TypeTag : ClassTag](name: String, value: T): IR.Result = bind((name, value))
- def bindSyntheticValue(x: Any): IR.Result = bindValue(freshInternalVarName(), x)
- def bindValue(x: Any): IR.Result = bindValue(freshUserVarName(), x)
- def bindValue(name: String, x: Any): IR.Result = bind(name, TypeStrings.fromValue(x), x)
/** Reset this interpreter, forgetting all user-specified requests. */
def reset() {
@@ -667,9 +631,8 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
resetClassLoader()
resetAllCreators()
prevRequests.clear()
- referencedNameMap.clear()
- definedNameMap.clear()
- virtualDirectory.clear()
+ resetReplScope()
+ replOutput.dir.clear()
}
/** This instance is no longer needed, so release any resources
@@ -690,10 +653,6 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
class ReadEvalPrint(lineId: Int) {
def this() = this(freshLineId())
- private var lastRun: Run = _
- private var evalCaught: Option[Throwable] = None
- private var conditionalWarnings: List[ConditionalWarning] = Nil
-
val packageName = sessionNames.line + lineId
val readName = sessionNames.read
val evalName = sessionNames.eval
@@ -720,7 +679,6 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
def readPath = pathTo(readName)
def evalPath = pathTo(evalName)
- def printPath = pathTo(printName)
def call(name: String, args: Any*): AnyRef = {
val m = evalMethod(name)
@@ -735,10 +693,6 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
try Right(call(name, args: _*))
catch { case ex: Throwable => Left(ex) }
- def callOpt(name: String, args: Any*): Option[AnyRef] =
- try Some(call(name, args: _*))
- catch { case ex: Throwable => bindError(ex) ; None }
-
class EvalException(msg: String, cause: Throwable) extends RuntimeException(msg, cause) { }
private def evalError(path: String, ex: Throwable) =
@@ -750,10 +704,6 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
}
lazy val evalClass = load(evalPath)
- lazy val evalValue = callEither(resultName) match {
- case Left(ex) => evalCaught = Some(ex) ; None
- case Right(result) => Some(result)
- }
def compile(source: String): Boolean = compileAndSaveRun("<console>", source)
@@ -761,10 +711,10 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
* following accessPath into the outer one.
*/
def resolvePathToSymbol(accessPath: String): Symbol = {
- val readRoot = getRequiredModule(readPath) // the outermost wrapper
+ val readRoot = getModuleIfDefined(readPath) // the outermost wrapper
(accessPath split '.').foldLeft(readRoot: Symbol) {
case (sym, "") => sym
- case (sym, name) => afterTyper(termMember(sym, name))
+ case (sym, name) => exitingTyper(termMember(sym, name))
}
}
/** We get a bunch of repeated warnings for reasons I haven't
@@ -797,15 +747,16 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
showCodeIfDebugging(code)
val (success, run) = compileSourcesKeepingRun(new BatchSourceFile(label, packaged(code)))
updateRecentWarnings(run)
- lastRun = run
success
}
}
/** One line of code submitted by the user for interpretation */
- // private
class Request(val line: String, val trees: List[Tree]) {
- val reqId = nextReqId()
+ def defines = defHandlers flatMap (_.definedSymbols)
+ def imports = importedSymbols
+ def value = Some(handlers.last) filter (h => h.definesValue) map (h => definedSymbols(h.definesTerm.get)) getOrElse NoSymbol
+
val lineRep = new ReadEvalPrint()
private var _originalLine: String = null
@@ -816,50 +767,31 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
val handlers: List[MemberHandler] = trees map (memberHandlers chooseHandler _)
def defHandlers = handlers collect { case x: MemberDefHandler => x }
- /** all (public) names defined by these statements */
- val definedNames = handlers flatMap (_.definedNames)
-
/** list of names used by this expression */
val referencedNames: List[Name] = handlers flatMap (_.referencedNames)
/** def and val names */
def termNames = handlers flatMap (_.definesTerm)
def typeNames = handlers flatMap (_.definesType)
- def definedOrImported = handlers flatMap (_.definedOrImported)
- def definedSymbolList = defHandlers flatMap (_.definedSymbols)
-
- def definedTypeSymbol(name: String) = definedSymbols(newTypeName(name))
- def definedTermSymbol(name: String) = definedSymbols(newTermName(name))
+ def importedSymbols = handlers flatMap {
+ case x: ImportHandler => x.importedSymbols
+ case _ => Nil
+ }
/** Code to import bound names from previous lines - accessPath is code to
* append to objectName to access anything bound by request.
*/
val ComputedImports(importsPreamble, importsTrailer, accessPath) =
- importsCode(referencedNames.toSet)
-
- /** Code to access a variable with the specified name */
- def fullPath(vname: String) = (
- lineRep.readPath + accessPath + ".`%s`".format(vname)
- )
- /** Same as fullpath, but after it has been flattened, so:
- * $line5.$iw.$iw.$iw.Bippy // fullPath
- * $line5.$iw$$iw$$iw$Bippy // fullFlatName
- */
- def fullFlatName(name: String) =
- lineRep.readPath + accessPath.replace('.', '$') + nme.NAME_JOIN_STRING + name
-
- /** The unmangled symbol name, but supplemented with line info. */
- def disambiguated(name: Name): String = name + " (in " + lineRep + ")"
-
- /** Code to access a variable with the specified name */
- def fullPath(vname: Name): String = fullPath(vname.toString)
+ exitingTyper(importsCode(referencedNames.toSet))
/** the line of code to compute */
def toCompute = line
+ def fullPath(vname: String) = s"${lineRep.readPath}$accessPath.`$vname`"
+
/** generate the source code for the object that computes this request */
private object ObjectSourceCode extends CodeAssembler[MemberHandler] {
- def path = pathToTerm("$intp")
+ def path = originalPath("$intp")
def envLines = {
if (!isReplPower) Nil // power mode only for now
// $intp is not bound; punt, but include the line.
@@ -869,8 +801,7 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
)
else List(
"def $line = " + tquoted(originalLine),
- "def $req = %s.requestForReqId(%s).orNull".format(path, reqId),
- "def $trees = if ($req eq null) Nil else $req.trees".format(lineRep.readName, path, reqId)
+ "def $trees = Nil"
)
}
@@ -886,13 +817,10 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
/** We only want to generate this code when the result
* is a value which can be referred to as-is.
*/
- val evalResult =
- if (!handlers.last.definesValue) ""
- else handlers.last.definesTerm match {
- case Some(vname) if typeOf contains vname =>
- "lazy val %s = %s".format(lineRep.resultName, fullPath(vname))
- case _ => ""
- }
+ val evalResult = Request.this.value match {
+ case NoSymbol => ""
+ case sym => "lazy val %s = %s".format(lineRep.resultName, originalPath(sym))
+ }
// first line evaluates object to make sure constructor is run
// initial "" so later code can uniformly be: + etc
val preamble = """
@@ -914,15 +842,6 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
val generate = (m: MemberHandler) => m resultExtractionCode Request.this
}
- // get it
- def getEvalTyped[T] : Option[T] = getEval map (_.asInstanceOf[T])
- def getEval: Option[AnyRef] = {
- // ensure it has been compiled
- compile
- // try to load it and call the value method
- lineRep.evalValue filterNot (_ == null)
- }
-
/** Compile the object file. Returns whether the compilation succeeded.
* If all goes well, the "types" map is computed. */
lazy val compile: Boolean = {
@@ -941,7 +860,7 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
val name = dh.member.name
definedSymbols get name foreach { sym =>
dh.member setSymbol sym
- repldbg("Set symbol of " + name + " to " + sym.defString)
+ repldbg("Set symbol of " + name + " to " + symbolDefString(sym))
}
}
@@ -951,11 +870,10 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
}
lazy val resultSymbol = lineRep.resolvePathToSymbol(accessPath)
- def applyToResultMember[T](name: Name, f: Symbol => T) = afterTyper(f(resultSymbol.info.nonPrivateDecl(name)))
+ def applyToResultMember[T](name: Name, f: Symbol => T) = exitingTyper(f(resultSymbol.info.nonPrivateDecl(name)))
/* typeOf lookup with encoding */
def lookupTypeOf(name: Name) = typeOf.getOrElse(name, typeOf(global.encode(name.toString)))
- def simpleNameOfType(name: TypeName) = (compilerTypeOf get name) map (_.typeSymbol.simpleName)
private def typeMap[T](f: Type => T) =
mapFrom[Name, Name, T](termNames ++ typeNames)(x => f(cleanMemberDecl(resultSymbol, x)))
@@ -963,14 +881,11 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
/** Types of variables defined by this request. */
lazy val compilerTypeOf = typeMap[Type](x => x) withDefaultValue NoType
/** String representations of same. */
- lazy val typeOf = typeMap[String](tp => afterTyper(tp.toString))
+ lazy val typeOf = typeMap[String](tp => exitingTyper(tp.toString))
- // lazy val definedTypes: Map[Name, Type] = {
- // typeNames map (x => x -> afterTyper(resultSymbol.info.nonPrivateDecl(x).tpe)) toMap
- // }
lazy val definedSymbols = (
termNames.map(x => x -> applyToResultMember(x, x => x)) ++
- typeNames.map(x => x -> compilerTypeOf(x).typeSymbol)
+ typeNames.map(x => x -> compilerTypeOf(x).typeSymbolDirect)
).toMap[Name, Symbol] withDefaultValue NoSymbol
lazy val typesOfDefinedTerms = mapFrom[Name, Name, Type](termNames)(x => applyToResultMember(x, _.tpe))
@@ -1000,45 +915,48 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
private var mostRecentWarnings: List[(global.Position, String)] = Nil
def lastWarnings = mostRecentWarnings
- def treesForRequestId(id: Int): List[Tree] =
- requestForReqId(id).toList flatMap (_.trees)
-
- def requestForReqId(id: Int): Option[Request] =
- if (executingRequest != null && executingRequest.reqId == id) Some(executingRequest)
- else prevRequests find (_.reqId == id)
+ private lazy val importToGlobal = global mkImporter ru
+ private lazy val importToRuntime = ru mkImporter global
+ private lazy val javaMirror = ru.rootMirror match {
+ case x: ru.JavaMirror => x
+ case _ => null
+ }
+ private implicit def importFromRu(sym: ru.Symbol): Symbol = importToGlobal importSymbol sym
+ private implicit def importToRu(sym: Symbol): ru.Symbol = importToRuntime importSymbol sym
- def requestForName(name: Name): Option[Request] = {
- assert(definedNameMap != null, "definedNameMap is null")
- definedNameMap get name
+ def classOfTerm(id: String): Option[JClass] = symbolOfTerm(id) match {
+ case NoSymbol => None
+ case sym => Some(javaMirror runtimeClass importToRu(sym).asClass)
}
- def requestForIdent(line: String): Option[Request] =
- requestForName(newTermName(line)) orElse requestForName(newTypeName(line))
+ def typeOfTerm(id: String): Type = symbolOfTerm(id).tpe
- def requestHistoryForName(name: Name): List[Request] =
- prevRequests.toList.reverse filter (_.definedNames contains name)
+ def valueOfTerm(id: String): Option[Any] = exitingTyper {
+ def value() = {
+ val sym0 = symbolOfTerm(id)
+ val sym = (importToRuntime importSymbol sym0).asTerm
+ val module = runtimeMirror.reflectModule(sym.owner.companionSymbol.asModule).instance
+ val module1 = runtimeMirror.reflect(module)
+ val invoker = module1.reflectField(sym)
- def definitionForName(name: Name): Option[MemberHandler] =
- requestForName(name) flatMap { req =>
- req.handlers find (_.definedNames contains name)
+ invoker.get
}
- def valueOfTerm(id: String): Option[AnyRef] =
- requestForName(newTermName(id)) flatMap (_.getEval)
-
- def classOfTerm(id: String): Option[JClass] =
- valueOfTerm(id) map (_.getClass)
-
- def typeOfTerm(id: String): Type = newTermName(id) match {
- case nme.ROOTPKG => RootClass.tpe
- case name => requestForName(name).fold(NoType: Type)(_ compilerTypeOf name)
+ try Some(value()) catch { case _: Exception => None }
}
- def symbolOfType(id: String): Symbol =
- requestForName(newTypeName(id)).fold(NoSymbol: Symbol)(_ definedTypeSymbol id)
+ /** It's a bit of a shotgun approach, but for now we will gain in
+ * robustness. Try a symbol-producing operation at phase typer, and
+ * if that is NoSymbol, try again at phase flatten. I'll be able to
+ * lose this and run only from exitingTyper as soon as I figure out
+ * exactly where a flat name is sneaking in when calculating imports.
+ */
+ def tryTwice(op: => Symbol): Symbol = exitingTyper(op) orElse exitingFlatten(op)
- def symbolOfTerm(id: String): Symbol =
- requestForIdent(newTermName(id)).fold(NoSymbol: Symbol)(_ definedTermSymbol id)
+ def symbolOfIdent(id: String): Symbol = symbolOfTerm(id) orElse symbolOfType(id)
+ def symbolOfType(id: String): Symbol = tryTwice(replScope lookup (id: TypeName))
+ def symbolOfTerm(id: String): Symbol = tryTwice(replScope lookup (id: TermName))
+ def symbolOfName(id: Name): Symbol = replScope lookup id
def runtimeClassAndTypeOfTerm(id: String): Option[(JClass, Type)] = {
classOfTerm(id) flatMap { clazz =>
@@ -1059,14 +977,18 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
else NoType
}
}
- def cleanMemberDecl(owner: Symbol, member: Name): Type = afterTyper {
- normalizeNonPublic {
- owner.info.nonPrivateDecl(member).tpe match {
- case NullaryMethodType(tp) => tp
- case tp => tp
- }
- }
+
+ def cleanTypeAfterTyper(sym: => Symbol): Type = {
+ exitingTyper(
+ normalizeNonPublic(
+ dropNullaryMethod(
+ sym.tpe_*
+ )
+ )
+ )
}
+ def cleanMemberDecl(owner: Symbol, member: Name): Type =
+ cleanTypeAfterTyper(owner.info nonPrivateDecl member)
object exprTyper extends {
val repl: IMain.this.type = imain
@@ -1080,64 +1002,35 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
def typeOfExpression(expr: String, silent: Boolean = true): Type =
exprTyper.typeOfExpression(expr, silent)
- protected def onlyTerms(xs: List[Name]) = xs collect { case x: TermName => x }
- protected def onlyTypes(xs: List[Name]) = xs collect { case x: TypeName => x }
+ protected def onlyTerms(xs: List[Name]): List[TermName] = xs collect { case x: TermName => x }
+ protected def onlyTypes(xs: List[Name]): List[TypeName] = xs collect { case x: TypeName => x }
def definedTerms = onlyTerms(allDefinedNames) filterNot isInternalTermName
def definedTypes = onlyTypes(allDefinedNames)
- def definedSymbols = prevRequestList.flatMap(_.definedSymbols.values).toSet[Symbol]
- def definedSymbolList = prevRequestList flatMap (_.definedSymbolList) filterNot (s => isInternalTermName(s.name))
+ def definedSymbolList = prevRequestList flatMap (_.defines) filterNot (s => isInternalTermName(s.name))
// Terms with user-given names (i.e. not res0 and not synthetic)
def namedDefinedTerms = definedTerms filterNot (x => isUserVarName("" + x) || directlyBoundNames(x))
- private def findName(name: Name) = definedSymbols find (_.name == name) getOrElse NoSymbol
-
- /** Translate a repl-defined identifier into a Symbol.
- */
- def apply(name: String): Symbol =
- types(name) orElse terms(name)
-
- def types(name: String): Symbol = {
- val tpname = newTypeName(name)
- findName(tpname) orElse getClassIfDefined(tpname)
+ private var _replScope: Scope = _
+ private def resetReplScope() {
+ _replScope = newScope
}
- def terms(name: String): Symbol = {
- val termname = newTypeName(name)
- findName(termname) orElse getModuleIfDefined(termname)
- }
- // [Eugene to Paul] possibly you could make use of TypeTags here
- def types[T: ClassTag] : Symbol = types(classTag[T].runtimeClass.getName)
- def terms[T: ClassTag] : Symbol = terms(classTag[T].runtimeClass.getName)
- def apply[T: ClassTag] : Symbol = apply(classTag[T].runtimeClass.getName)
+ def replScope = {
+ if (_replScope eq null)
+ _replScope = newScope
- def classSymbols = allDefSymbols collect { case x: ClassSymbol => x }
- def methodSymbols = allDefSymbols collect { case x: MethodSymbol => x }
+ _replScope
+ }
- /** the previous requests this interpreter has processed */
private var executingRequest: Request = _
private val prevRequests = mutable.ListBuffer[Request]()
- private val referencedNameMap = mutable.Map[Name, Request]()
- private val definedNameMap = mutable.Map[Name, Request]()
private val directlyBoundNames = mutable.Set[Name]()
- def allHandlers = prevRequestList flatMap (_.handlers)
- def allDefHandlers = allHandlers collect { case x: MemberDefHandler => x }
- def allDefSymbols = allDefHandlers map (_.symbol) filter (_ ne NoSymbol)
-
- def lastRequest = if (prevRequests.isEmpty) null else prevRequests.last
- def prevRequestList = prevRequests.toList
- def allSeenTypes = prevRequestList flatMap (_.typeOf.values.toList) distinct
- def allImplicits = allHandlers filter (_.definesImplicit) flatMap (_.definedNames)
- def importHandlers = allHandlers collect { case x: ImportHandler => x }
-
- def visibleTermNames: List[Name] = definedTerms ++ importedTerms distinct
-
- /** Another entry point for tab-completion, ids in scope */
- def unqualifiedIds = visibleTermNames map (_.toString) filterNot (_ contains "$") sorted
-
- /** Parse the ScalaSig to find type aliases */
- def aliasForType(path: String) = ByteCode.aliasForType(path)
+ def allHandlers = prevRequestList flatMap (_.handlers)
+ def lastRequest = if (prevRequests.isEmpty) null else prevRequests.last
+ def prevRequestList = prevRequests.toList
+ def importHandlers = allHandlers collect { case x: ImportHandler => x }
def withoutUnwrapping(op: => Unit): Unit = {
val saved = isettings.unwrapStrings
@@ -1148,7 +1041,7 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
def symbolDefString(sym: Symbol) = {
TypeStrings.quieter(
- afterTyper(sym.defString),
+ exitingTyper(sym.defString),
sym.owner.name + ".this.",
sym.owner.fullName + "."
)
@@ -1158,13 +1051,12 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
/** Secret bookcase entrance for repl debuggers: end the line
* with "// show" and see what's going on.
*/
- def isShow = code.lines exists (_.trim endsWith "// show")
- def isShowRaw = code.lines exists (_.trim endsWith "// raw")
-
- // old style
- beSilentDuring(parse(code)) foreach { ts =>
- ts foreach { t =>
- withoutUnwrapping(repldbg(asCompactString(t)))
+ def isShow = code.lines exists (_.trim endsWith "// show")
+ if (isReplDebug || isShow) {
+ beSilentDuring(parse(code)) foreach { ts =>
+ ts foreach { t =>
+ withoutUnwrapping(echo(asCompactString(t)))
+ }
}
}
}
diff --git a/src/compiler/scala/tools/nsc/interpreter/ISettings.scala b/src/compiler/scala/tools/nsc/interpreter/ISettings.scala
index a8f77afcdf..9541d08db1 100644
--- a/src/compiler/scala/tools/nsc/interpreter/ISettings.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/ISettings.scala
@@ -12,13 +12,6 @@ package interpreter
* @author Lex Spoon, 2007/3/24
**/
class ISettings(intp: IMain) {
- /** A list of paths where :load should look */
- var loadPath = List(".")
-
- /** Set this to true to see repl machinery under -Yrich-exceptions.
- */
- var showInternalStackTraces = false
-
/** The maximum length of toString to use when printing the result
* of an evaluation. 0 means no maximum. If a printout requires
* more than this number of characters, then the printout is
@@ -32,7 +25,7 @@ class ISettings(intp: IMain) {
var maxAutoprintCompletion = 250
/** String unwrapping can be disabled if it is causing issues.
- * Settings this to false means you will see Strings like "$iw.$iw.".
+ * Setting this to false means you will see Strings like "$iw.$iw.".
*/
var unwrapStrings = true
@@ -44,7 +37,7 @@ class ISettings(intp: IMain) {
}
def deprecation: Boolean = intp.settings.deprecation.value
- def allSettings = Map(
+ def allSettings = Map[String, Any](
"maxPrintString" -> maxPrintString,
"maxAutoprintCompletion" -> maxAutoprintCompletion,
"unwrapStrings" -> unwrapStrings,
diff --git a/src/compiler/scala/tools/nsc/interpreter/Imports.scala b/src/compiler/scala/tools/nsc/interpreter/Imports.scala
index 73d962b5b0..ff7bfd432c 100644
--- a/src/compiler/scala/tools/nsc/interpreter/Imports.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/Imports.scala
@@ -12,12 +12,9 @@ trait Imports {
self: IMain =>
import global._
- import definitions.{ ScalaPackage, JavaLangPackage, PredefModule }
+ import definitions.{ ObjectClass, ScalaPackage, JavaLangPackage, PredefModule }
import memberHandlers._
- def isNoImports = settings.noimports.value
- def isNoPredef = settings.nopredef.value
-
/** Synthetic import handlers for the language defined imports. */
private def makeWildcardImportHandler(sym: Symbol): ImportHandler = {
val hd :: tl = sym.fullName.split('.').toList map newTermName
@@ -31,12 +28,9 @@ trait Imports {
/** Symbols whose contents are language-defined to be imported. */
def languageWildcardSyms: List[Symbol] = List(JavaLangPackage, ScalaPackage, PredefModule)
- def languageWildcards: List[Type] = languageWildcardSyms map (_.tpe)
def languageWildcardHandlers = languageWildcardSyms map makeWildcardImportHandler
def allImportedNames = importHandlers flatMap (_.importedNames)
- def importedTerms = onlyTerms(allImportedNames)
- def importedTypes = onlyTypes(allImportedNames)
/** Types which have been wildcard imported, such as:
* val x = "abc" ; import x._ // type java.lang.String
@@ -52,17 +46,11 @@ trait Imports {
def sessionWildcards: List[Type] = {
importHandlers filter (_.importsWildcard) map (_.targetType) distinct
}
- def wildcardTypes = languageWildcards ++ sessionWildcards
def languageSymbols = languageWildcardSyms flatMap membersAtPickler
def sessionImportedSymbols = importHandlers flatMap (_.importedSymbols)
def importedSymbols = languageSymbols ++ sessionImportedSymbols
def importedTermSymbols = importedSymbols collect { case x: TermSymbol => x }
- def importedTypeSymbols = importedSymbols collect { case x: TypeSymbol => x }
- def implicitSymbols = importedSymbols filter (_.isImplicit)
-
- def importedTermNamed(name: String): Symbol =
- importedTermSymbols find (_.name.toString == name) getOrElse NoSymbol
/** Tuples of (source, imported symbols) in the order they were imported.
*/
@@ -146,44 +134,42 @@ trait Imports {
code append "object %s {\n".format(impname)
trailingBraces append "}\n"
accessPath append ("." + impname)
-
- currentImps.clear
+ currentImps.clear()
+ }
+ def maybeWrap(names: Name*) = if (names exists currentImps) addWrapper()
+ def wrapBeforeAndAfter[T](op: => T): T = {
+ addWrapper()
+ try op finally addWrapper()
}
-
- addWrapper()
// loop through previous requests, adding imports for each one
- for (ReqAndHandler(req, handler) <- reqsToUse) {
- handler match {
- // If the user entered an import, then just use it; add an import wrapping
- // level if the import might conflict with some other import
- case x: ImportHandler =>
- if (x.importsWildcard || currentImps.exists(x.importedNames contains _))
- addWrapper()
-
- code append (x.member + "\n")
-
- // give wildcard imports a import wrapper all to their own
- if (x.importsWildcard) addWrapper()
- else currentImps ++= x.importedNames
-
- // For other requests, import each defined name.
- // import them explicitly instead of with _, so that
- // ambiguity errors will not be generated. Also, quote
- // the name of the variable, so that we don't need to
- // handle quoting keywords separately.
- case x =>
- for (imv <- x.definedNames) {
- if (currentImps contains imv) addWrapper()
-
- code append ("import " + (req fullPath imv) + "\n")
- currentImps += imv
- }
+ wrapBeforeAndAfter {
+ for (ReqAndHandler(req, handler) <- reqsToUse) {
+ handler match {
+ // If the user entered an import, then just use it; add an import wrapping
+ // level if the import might conflict with some other import
+ case x: ImportHandler if x.importsWildcard =>
+ wrapBeforeAndAfter(code append (x.member + "\n"))
+ case x: ImportHandler =>
+ maybeWrap(x.importedNames: _*)
+ code append (x.member + "\n")
+ currentImps ++= x.importedNames
+
+ // For other requests, import each defined name.
+ // import them explicitly instead of with _, so that
+ // ambiguity errors will not be generated. Also, quote
+ // the name of the variable, so that we don't need to
+ // handle quoting keywords separately.
+ case x =>
+ for (sym <- x.definedSymbols) {
+ maybeWrap(sym.name)
+ code append s"import ${x.path}\n"
+ currentImps += sym.name
+ }
+ }
}
}
- // add one extra wrapper, to prevent warnings in the common case of
- // redefining the value bound in the last interpreter request.
- addWrapper()
+
ComputedImports(code.toString, trailingBraces.toString, accessPath.toString)
}
@@ -191,5 +177,5 @@ trait Imports {
prevRequestList flatMap (req => req.handlers map (req -> _))
private def membersAtPickler(sym: Symbol): List[Symbol] =
- beforePickler(sym.info.nonPrivateMembers.toList)
+ enteringPickler(sym.info.nonPrivateMembers.toList)
}
diff --git a/src/compiler/scala/tools/nsc/interpreter/InteractiveReader.scala b/src/compiler/scala/tools/nsc/interpreter/InteractiveReader.scala
index 8331fddca6..28ddf2939c 100644
--- a/src/compiler/scala/tools/nsc/interpreter/InteractiveReader.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/InteractiveReader.scala
@@ -7,8 +7,6 @@ package scala.tools.nsc
package interpreter
import java.io.IOException
-import java.nio.channels.ClosedByInterruptException
-import scala.util.control.Exception._
import session.History
import InteractiveReader._
import Properties.isMac
@@ -17,22 +15,16 @@ import Properties.isMac
trait InteractiveReader {
val interactive: Boolean
- def init(): Unit
def reset(): Unit
-
def history: History
def completion: Completion
- def eraseLine(): Unit
def redrawLine(): Unit
- def currentLine: String
def readYesOrNo(prompt: String, alt: => Boolean): Boolean = readOneKey(prompt) match {
case 'y' => true
case 'n' => false
case _ => alt
}
- def readAssumingNo(prompt: String) = readYesOrNo(prompt, false)
- def readAssumingYes(prompt: String) = readYesOrNo(prompt, true)
protected def readOneLine(prompt: String): String
protected def readOneKey(prompt: String): Int
@@ -52,6 +44,6 @@ object InteractiveReader {
def apply(): InteractiveReader = SimpleReader()
@deprecated("Use `apply` instead.", "2.9.0")
- def createDefault(): InteractiveReader = apply()
+ def createDefault(): InteractiveReader = apply() // used by sbt
}
diff --git a/src/compiler/scala/tools/nsc/interpreter/JLineCompletion.scala b/src/compiler/scala/tools/nsc/interpreter/JLineCompletion.scala
index 219cb35242..19fa562234 100644
--- a/src/compiler/scala/tools/nsc/interpreter/JLineCompletion.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/JLineCompletion.scala
@@ -6,10 +6,9 @@
package scala.tools.nsc
package interpreter
-import scala.tools.jline._
-import scala.tools.jline.console.completer._
import Completion._
import scala.collection.mutable.ListBuffer
+import scala.reflect.internal.util.StringOps.longestCommonPrefix
// REPL completor - queries supplied interpreter for valid
// completions based on current contents of buffer.
@@ -29,9 +28,6 @@ class JLineCompletion(val intp: IMain) extends Completion with CompletionOutput
if (isModule) getModuleIfDefined(name)
else getModuleIfDefined(name)
)
- def getType(name: String, isModule: Boolean) = getSymbol(name, isModule).tpe
- def typeOf(name: String) = getType(name, false)
- def moduleOf(name: String) = getType(name, true)
trait CompilerCompletion {
def tp: Type
@@ -47,12 +43,11 @@ class JLineCompletion(val intp: IMain) extends Completion with CompletionOutput
def anyRefMethodsToShow = Set("isInstanceOf", "asInstanceOf", "toString")
def tos(sym: Symbol): String = sym.decodedName
- def memberNamed(s: String) = afterTyper(effectiveTp member newTermName(s))
- def hasMethod(s: String) = memberNamed(s).isMethod
+ def memberNamed(s: String) = exitingTyper(effectiveTp member newTermName(s))
// XXX we'd like to say "filterNot (_.isDeprecated)" but this causes the
// compiler to crash for reasons not yet known.
- def members = afterTyper((effectiveTp.nonPrivateMembers.toList ++ anyMembers) filter (_.isPublic))
+ def members = exitingTyper((effectiveTp.nonPrivateMembers.toList ++ anyMembers) filter (_.isPublic))
def methods = members.toList filter (_.isMethod)
def packages = members.toList filter (_.isPackage)
def aliases = members.toList filter (_.isAliasType)
@@ -111,7 +106,7 @@ class JLineCompletion(val intp: IMain) extends Completion with CompletionOutput
def excludeNames: List[String] = (anyref.methodNames filterNot anyRefMethodsToShow) :+ "_root_"
def methodSignatureString(sym: Symbol) = {
- IMain stripString afterTyper(new MethodSymbolOutput(sym).methodString())
+ IMain stripString exitingTyper(new MethodSymbolOutput(sym).methodString())
}
def exclude(name: String): Boolean = (
@@ -280,10 +275,6 @@ class JLineCompletion(val intp: IMain) extends Completion with CompletionOutput
if (parsed.isEmpty) xs map ("." + _) else xs
}
- // generic interface for querying (e.g. interpreter loop, testing)
- def completions(buf: String): List[String] =
- topLevelFor(Parsed.dotted(buf + ".", buf.length + 1))
-
def completer(): ScalaCompleter = new JLineTabCompletion
/** This gets a little bit hairy. It's no small feat delegating everything
@@ -301,16 +292,6 @@ class JLineCompletion(val intp: IMain) extends Completion with CompletionOutput
def isConsecutiveTabs(buf: String, cursor: Int) =
cursor == lastCursor && buf == lastBuf
- // Longest common prefix
- def commonPrefix(xs: List[String]): String = {
- if (xs.isEmpty || xs.contains("")) ""
- else xs.head.head match {
- case ch =>
- if (xs.tail forall (_.head == ch)) "" + ch + commonPrefix(xs map (_.tail))
- else ""
- }
- }
-
// This is jline's entry point for completion.
override def complete(buf: String, cursor: Int): Candidates = {
verbosity = if (isConsecutiveTabs(buf, cursor)) verbosity + 1 else 0
@@ -324,7 +305,7 @@ class JLineCompletion(val intp: IMain) extends Completion with CompletionOutput
val newCursor =
if (winners contains "") p.cursor
else {
- val advance = commonPrefix(winners)
+ val advance = longestCommonPrefix(winners)
lastCursor = p.position + advance.length
lastBuf = (buf take p.position) + advance
repldbg("tryCompletion(%s, _) lastBuf = %s, lastCursor = %s, p.position = %s".format(
@@ -335,8 +316,7 @@ class JLineCompletion(val intp: IMain) extends Completion with CompletionOutput
Some(Candidates(newCursor, winners))
}
- def mkDotted = Parsed.dotted(buf, cursor) withVerbosity verbosity
- def mkUndelimited = Parsed.undelimited(buf, cursor) withVerbosity verbosity
+ def mkDotted = Parsed.dotted(buf, cursor) withVerbosity verbosity
// a single dot is special cased to completion on the previous result
def lastResultCompletion =
diff --git a/src/compiler/scala/tools/nsc/interpreter/JLineReader.scala b/src/compiler/scala/tools/nsc/interpreter/JLineReader.scala
index 10f972452f..a620c7c75a 100644
--- a/src/compiler/scala/tools/nsc/interpreter/JLineReader.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/JLineReader.scala
@@ -9,9 +9,7 @@ package interpreter
import scala.tools.jline.console.ConsoleReader
import scala.tools.jline.console.completer._
import session._
-import scala.collection.JavaConverters._
import Completion._
-import io.Streamable.slurp
/**
* Reads from the console using JLine.
@@ -25,7 +23,6 @@ class JLineReader(_completion: => Completion) extends InteractiveReader {
private def term = consoleReader.getTerminal()
def reset() = term.reset()
- def init() = term.init()
def scalaToJline(tc: ScalaCompleter): Completer = new Completer {
def complete(_buf: String, cursor: Int, candidates: JList[CharSequence]): Int = {
@@ -37,8 +34,6 @@ class JLineReader(_completion: => Completion) extends InteractiveReader {
}
class JLineConsoleReader extends ConsoleReader with ConsoleReaderHelper {
- // working around protected/trait/java insufficiencies.
- def goBack(num: Int): Unit = back(num)
def readOneKey(prompt: String) = {
this.print(prompt)
this.flush()
@@ -46,7 +41,6 @@ class JLineReader(_completion: => Completion) extends InteractiveReader {
}
def eraseLine() = consoleReader.resetPromptLine("", "", 0)
def redrawLineAndFlush(): Unit = { flush() ; drawLine() ; flush() }
- // override def readLine(prompt: String): String
// A hook for running code after the repl is done initializing.
lazy val postInit: Unit = {
@@ -65,11 +59,7 @@ class JLineReader(_completion: => Completion) extends InteractiveReader {
}
}
- def currentLine = consoleReader.getCursorBuffer.buffer.toString
def redrawLine() = consoleReader.redrawLineAndFlush()
- def eraseLine() = consoleReader.eraseLine()
- // Alternate implementation, not sure if/when I need this.
- // def eraseLine() = while (consoleReader.delete()) { }
def readOneLine(prompt: String) = consoleReader readLine prompt
def readOneKey(prompt: String) = consoleReader readOneKey prompt
}
diff --git a/src/compiler/scala/tools/nsc/interpreter/Logger.scala b/src/compiler/scala/tools/nsc/interpreter/Logger.scala
index aeb25fc688..7407daf8d0 100644
--- a/src/compiler/scala/tools/nsc/interpreter/Logger.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/Logger.scala
@@ -11,8 +11,4 @@ trait Logger {
def isDebug: Boolean
def isTrace: Boolean
def out: JPrintWriter
-
- def info(msg: => Any): Unit = if (isInfo) out println msg
- def debug(msg: => Any): Unit = if (isDebug) out println msg
- def trace(msg: => Any): Unit = if (isTrace) out println msg
}
diff --git a/src/compiler/scala/tools/nsc/interpreter/LoopCommands.scala b/src/compiler/scala/tools/nsc/interpreter/LoopCommands.scala
index 60325ece30..39979c8fbe 100644
--- a/src/compiler/scala/tools/nsc/interpreter/LoopCommands.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/LoopCommands.scala
@@ -19,13 +19,8 @@ class ProcessResult(val line: String) {
val exitCode = builder ! logger
def lines = buffer.toList
- def show() = lines foreach println
override def toString = "`%s` (%d lines, exit %d)".format(line, buffer.size, exitCode)
}
-object ProcessResult {
- implicit def processResultToOutputLines(pr: ProcessResult): List[String] = pr.lines
- def apply(line: String): ProcessResult = new ProcessResult(line)
-}
trait LoopCommands {
protected def out: JPrintWriter
@@ -35,14 +30,6 @@ trait LoopCommands {
// a single interpreter command
abstract class LoopCommand(val name: String, val help: String) extends (String => Result) {
- private var _longHelp: String = null
- final def defaultHelp = usageMsg + " (no extended help available.)"
- def hasLongHelp = _longHelp != null || longHelp != defaultHelp
- def withLongHelp(text: String): this.type = { _longHelp = text ; this }
- def longHelp = _longHelp match {
- case null => defaultHelp
- case text => text
- }
def usage: String = ""
def usageMsg: String = ":" + name + (
if (usage == "") "" else " " + usage
@@ -54,11 +41,6 @@ trait LoopCommands {
"usage is " + usageMsg
Result(true, None)
}
-
- def onError(msg: String) = {
- out.println("error: " + msg)
- showUsage()
- }
}
object LoopCommand {
def nullary(name: String, help: String, f: () => Result): LoopCommand =
@@ -67,9 +49,6 @@ trait LoopCommands {
def cmd(name: String, usage: String, help: String, f: String => Result): LoopCommand =
if (usage == "") new NullaryCmd(name, help, f)
else new LineCmd(name, usage, help, f)
-
- def varargs(name: String, usage: String, help: String, f: List[String] => Result): LoopCommand =
- new VarArgsCmd(name, usage, help, f)
}
class NullaryCmd(name: String, help: String, f: String => Result) extends LoopCommand(name, help) {
diff --git a/src/compiler/scala/tools/nsc/interpreter/MemberHandlers.scala b/src/compiler/scala/tools/nsc/interpreter/MemberHandlers.scala
index 67519cf90c..cb091ac9a7 100644
--- a/src/compiler/scala/tools/nsc/interpreter/MemberHandlers.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/MemberHandlers.scala
@@ -7,8 +7,6 @@ package scala.tools.nsc
package interpreter
import scala.collection.{ mutable, immutable }
-import scala.PartialFunction.cond
-import scala.reflect.internal.Chars
import scala.reflect.internal.Flags._
import scala.language.implicitConversions
@@ -21,8 +19,6 @@ trait MemberHandlers {
private def codegenln(leadingPlus: Boolean, xs: String*): String = codegen(leadingPlus, (xs ++ Array("\n")): _*)
private def codegenln(xs: String*): String = codegenln(true, xs: _*)
-
- private def codegen(xs: String*): String = codegen(true, xs: _*)
private def codegen(leadingPlus: Boolean, xs: String*): String = {
val front = if (leadingPlus) "+ " else ""
front + (xs map string2codeQuoted mkString " + ")
@@ -55,21 +51,20 @@ trait MemberHandlers {
def chooseHandler(member: Tree): MemberHandler = member match {
case member: DefDef => new DefHandler(member)
case member: ValDef => new ValHandler(member)
- case member: Assign => new AssignHandler(member)
case member: ModuleDef => new ModuleHandler(member)
case member: ClassDef => new ClassHandler(member)
case member: TypeDef => new TypeAliasHandler(member)
+ case member: Assign => new AssignHandler(member)
case member: Import => new ImportHandler(member)
case DocDef(_, documented) => chooseHandler(documented)
case member => new GenericHandler(member)
}
sealed abstract class MemberDefHandler(override val member: MemberDef) extends MemberHandler(member) {
- def symbol = if (member.symbol eq null) NoSymbol else member.symbol
- def name: Name = member.name
- def mods: Modifiers = member.mods
- def keyword = member.keyword
- def prettyName = name.decode
+ override def name: Name = member.name
+ def mods: Modifiers = member.mods
+ def keyword = member.keyword
+ def prettyName = name.decode
override def definesImplicit = member.mods.isImplicit
override def definesTerm: Option[TermName] = Some(name.toTermName) filter (_ => name.isTermName)
@@ -81,9 +76,11 @@ trait MemberHandlers {
* in a single interpreter request.
*/
sealed abstract class MemberHandler(val member: Tree) {
+ def name: Name = nme.NO_NAME
+ def path = intp.originalPath(symbol)
+ def symbol = if (member.symbol eq null) NoSymbol else member.symbol
def definesImplicit = false
def definesValue = false
- def isLegalTopLevel = false
def definesTerm = Option.empty[TermName]
def definesType = Option.empty[TypeName]
@@ -91,7 +88,6 @@ trait MemberHandlers {
lazy val referencedNames = ImportVarsTraverser(member)
def importedNames = List[Name]()
def definedNames = definesTerm.toList ++ definesType.toList
- def definedOrImported = definedNames ++ importedNames
def definedSymbols = List[Symbol]()
def extraCodeToEvaluate(req: Request): String = ""
@@ -114,10 +110,10 @@ trait MemberHandlers {
// if this is a lazy val we avoid evaluating it here
val resultString =
if (mods.isLazy) codegenln(false, "<lazy>")
- else any2stringOf(req fullPath name, maxStringElements)
+ else any2stringOf(path, maxStringElements)
val vidString =
- if (replProps.vids) """" + " @ " + "%%8x".format(System.identityHashCode(%s)) + " """.trim.format(req fullPath name)
+ if (replProps.vids) s"""" + " @ " + "%%8x".format(System.identityHashCode($path)) + " """.trim
else ""
""" + "%s%s: %s = " + %s""".format(string2code(prettyName), vidString, string2code(req typeOf name), resultString)
@@ -136,7 +132,7 @@ trait MemberHandlers {
class AssignHandler(member: Assign) extends MemberHandler(member) {
val Assign(lhs, rhs) = member
- val name = newTermName(freshInternalVarName())
+ override lazy val name = newTermName(freshInternalVarName())
override def definesTerm = Some(name)
override def definesValue = true
@@ -152,17 +148,16 @@ trait MemberHandlers {
}
class ModuleHandler(module: ModuleDef) extends MemberDefHandler(module) {
- override def definesTerm = Some(name)
+ override def definesTerm = Some(name.toTermName)
override def definesValue = true
- override def isLegalTopLevel = true
override def resultExtractionCode(req: Request) = codegenln("defined module ", name)
}
class ClassHandler(member: ClassDef) extends MemberDefHandler(member) {
+ override def definedSymbols = List(symbol, symbol.companionSymbol) filterNot (_ == NoSymbol)
override def definesType = Some(name.toTypeName)
override def definesTerm = Some(name.toTermName) filter (_ => mods.isCase)
- override def isLegalTopLevel = true
override def resultExtractionCode(req: Request) =
codegenln("defined %s %s".format(keyword, name))
@@ -178,21 +173,11 @@ trait MemberHandlers {
class ImportHandler(imp: Import) extends MemberHandler(imp) {
val Import(expr, selectors) = imp
- def targetType: Type = intp.typeOfExpression("" + expr)
- override def isLegalTopLevel = true
-
- def createImportForName(name: Name): String = {
- selectors foreach {
- case sel @ ImportSelector(old, _, `name`, _) => return "import %s.{ %s }".format(expr, sel)
- case _ => ()
- }
- "import %s.%s".format(expr, name)
+ def targetType = intp.global.rootMirror.getModuleIfDefined("" + expr) match {
+ case NoSymbol => intp.typeOfExpression("" + expr)
+ case sym => sym.thisType
}
- // TODO: Need to track these specially to honor Predef masking attempts,
- // because they must be the leading imports in the code generated for each
- // line. We can use the same machinery as Contexts now, anyway.
- def isPredefImport = isReferenceToPredef(expr)
-
+ private def importableTargetMembers = importableMembers(targetType).toList
// wildcard imports, e.g. import foo._
private def selectorWild = selectors filter (_.name == nme.USCOREkw)
// renamed imports, e.g. import foo.{ bar => baz }
@@ -201,22 +186,16 @@ trait MemberHandlers {
/** Whether this import includes a wildcard import */
val importsWildcard = selectorWild.nonEmpty
- /** Whether anything imported is implicit .*/
- def importsImplicit = implicitSymbols.nonEmpty
-
def implicitSymbols = importedSymbols filter (_.isImplicit)
def importedSymbols = individualSymbols ++ wildcardSymbols
- lazy val individualSymbols: List[Symbol] =
- beforePickler(individualNames map (targetType nonPrivateMember _))
-
- lazy val wildcardSymbols: List[Symbol] =
- if (importsWildcard) beforePickler(targetType.nonPrivateMembers.toList)
- else Nil
+ private val selectorNames = selectorRenames filterNot (_ == nme.USCOREkw) flatMap (_.bothNames) toSet
+ lazy val individualSymbols: List[Symbol] = exitingTyper(importableTargetMembers filter (m => selectorNames(m.name)))
+ lazy val wildcardSymbols: List[Symbol] = exitingTyper(if (importsWildcard) importableTargetMembers else Nil)
/** Complete list of names imported by a wildcard */
lazy val wildcardNames: List[Name] = wildcardSymbols map (_.name)
- lazy val individualNames: List[Name] = selectorRenames filterNot (_ == nme.USCOREkw) flatMap (_.bothNames)
+ lazy val individualNames: List[Name] = individualSymbols map (_.name)
/** The names imported by this statement */
override lazy val importedNames: List[Name] = wildcardNames ++ individualNames
diff --git a/src/compiler/scala/tools/nsc/interpreter/NamedParam.scala b/src/compiler/scala/tools/nsc/interpreter/NamedParam.scala
index eff0ef59c5..627a881cae 100644
--- a/src/compiler/scala/tools/nsc/interpreter/NamedParam.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/NamedParam.scala
@@ -14,14 +14,10 @@ import scala.reflect.{ClassTag, classTag}
trait NamedParamCreator {
protected def freshName: () => String
- def apply(name: String, tpe: String, value: Any): NamedParam = NamedParamClass(name, tpe, value)
def apply[T: ru.TypeTag : ClassTag](name: String, x: T): NamedParam = new Typed[T](name, x)
def apply[T: ru.TypeTag : ClassTag](x: T): NamedParam = apply(freshName(), x)
-
def clazz(name: String, x: Any): NamedParam = new Untyped(name, x)
- def clazz(x: Any): NamedParam = clazz(freshName(), x)
- implicit def namedValue[T: ru.TypeTag : ClassTag](name: String, x: T): NamedParam = apply(name, x)
implicit def tuple[T: ru.TypeTag : ClassTag](pair: (String, T)): NamedParam = apply(pair._1, pair._2)
}
diff --git a/src/compiler/scala/tools/nsc/interpreter/Naming.scala b/src/compiler/scala/tools/nsc/interpreter/Naming.scala
index 0d03a8669a..57f3675ada 100644
--- a/src/compiler/scala/tools/nsc/interpreter/Naming.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/Naming.scala
@@ -6,6 +6,8 @@
package scala.tools.nsc
package interpreter
+import scala.util.Properties.lineSeparator
+
/** This is for name logic which is independent of the compiler (notice there's no Global.)
* That includes at least generating, metaquoting, mangling, and unmangling.
*/
@@ -18,8 +20,14 @@ trait Naming {
// <ESC> for ansi codes.
val binaryChars = cleaned count (ch => ch < 32 && !ch.isWhitespace && ch != ESC)
// Lots of binary chars - translate all supposed whitespace into spaces
- if (binaryChars > 5)
- cleaned map (ch => if (ch.isWhitespace) ' ' else if (ch < 32) '?' else ch)
+ // except supposed line endings, otherwise scrubbed lines run together
+ if (binaryChars > 5) // more than one can count while holding a hamburger
+ cleaned map {
+ case c if lineSeparator contains c => c
+ case c if c.isWhitespace => ' '
+ case c if c < 32 => '?'
+ case c => c
+ }
// Not lots - preserve whitespace and ESC
else
cleaned map (ch => if (ch.isWhitespace || ch == ESC) ch else if (ch < 32) '?' else ch)
@@ -78,7 +86,6 @@ trait Naming {
private lazy val userVar = new NameCreator(sessionNames.res) // var name, like res0
private lazy val internalVar = new NameCreator(sessionNames.ires) // internal var name, like $ires0
- def isLineName(name: String) = (name startsWith sessionNames.line) && (name stripPrefix sessionNames.line forall (_.isDigit))
def isUserVarName(name: String) = userVar didGenerate name
def isInternalVarName(name: String) = internalVar didGenerate name
diff --git a/src/compiler/scala/tools/nsc/interpreter/Parsed.scala b/src/compiler/scala/tools/nsc/interpreter/Parsed.scala
index b0be956df8..672a6fd28f 100644
--- a/src/compiler/scala/tools/nsc/interpreter/Parsed.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/Parsed.scala
@@ -6,7 +6,6 @@
package scala.tools.nsc
package interpreter
-import scala.tools.jline.console.completer.ArgumentCompleter.{ ArgumentDelimiter, ArgumentList }
import util.returning
/** One instance of a command buffer.
@@ -18,7 +17,6 @@ class Parsed private (
) extends Delimited {
def isEmpty = args.isEmpty
def isUnqualified = args.size == 1
- def isQualified = args.size > 1
def isAtStart = cursor <= 0
private var _verbosity = 0
@@ -32,7 +30,6 @@ class Parsed private (
def bufferTail = new Parsed(buffer drop headLength, cursor - headLength, delimited) withVerbosity verbosity
def prev = new Parsed(buffer, cursor - 1, delimited) withVerbosity verbosity
- def next = new Parsed(buffer, cursor + 1, delimited) withVerbosity verbosity
def currentChar = buffer(cursor)
def currentArg = args.last
def position =
@@ -42,8 +39,6 @@ class Parsed private (
def isFirstDelimiter = !isEmpty && isDelimiterChar(buffer.head)
def isLastDelimiter = !isEmpty && isDelimiterChar(buffer.last)
- def firstIfDelimiter = if (isFirstDelimiter) buffer.head.toString else ""
- def lastIfDelimiter = if (isLastDelimiter) buffer.last.toString else ""
def isQuoted = false // TODO
def isEscaped = !isAtStart && isEscapeChar(currentChar) && !isEscapeChar(prev.currentChar)
@@ -57,13 +52,9 @@ object Parsed {
private def onull(s: String) = if (s == null) "" else s
- def apply(s: String): Parsed = apply(onull(s), onull(s).length)
def apply(s: String, cursor: Int): Parsed = apply(onull(s), cursor, DefaultDelimiters)
def apply(s: String, cursor: Int, delimited: Char => Boolean): Parsed =
new Parsed(onull(s), cursor, delimited)
- def dotted(s: String): Parsed = dotted(onull(s), onull(s).length)
def dotted(s: String, cursor: Int): Parsed = new Parsed(onull(s), cursor, _ == '.')
-
- def undelimited(s: String, cursor: Int): Parsed = new Parsed(onull(s), cursor, _ => false)
}
diff --git a/src/compiler/scala/tools/nsc/interpreter/Phased.scala b/src/compiler/scala/tools/nsc/interpreter/Phased.scala
index 638944713a..f625124e70 100644
--- a/src/compiler/scala/tools/nsc/interpreter/Phased.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/Phased.scala
@@ -6,7 +6,7 @@
package scala.tools.nsc
package interpreter
-import scala.collection.{ mutable, immutable }
+import scala.collection.immutable
import scala.language.implicitConversions
/** Mix this into an object and use it as a phasing
@@ -24,7 +24,6 @@ trait Phased {
case NoPhaseName => false
case name => active = name ; true
}
- def getMulti = multi
def setMulti(phases: Seq[PhaseName]): Boolean = {
if (phases contains NoPhaseName) false
else {
@@ -66,16 +65,8 @@ trait Phased {
try parseInternal(str)
catch { case _: Exception => NoPhaseName }
- def apply[T](body: => T) = immutable.SortedMap[PhaseName, T](atMap(PhaseName.all)(body): _*)
-
- def atCurrent[T](body: => T): T = atPhase(get)(body)
+ def atCurrent[T](body: => T): T = enteringPhase(get)(body)
def multi[T](body: => T): Seq[T] = multi map (ph => at(ph)(body))
- def all[T](body: => T): Seq[T] = atMulti(PhaseName.all)(body)
- def show[T](body: => T): Seq[T] = {
- val pairs = atMap(PhaseName.all)(body)
- pairs foreach { case (ph, op) => Console.println("%15s -> %s".format(ph, op.toString take 240)) }
- pairs map (_._2)
- }
def at[T](ph: PhaseName)(body: => T): T = {
val saved = get
@@ -90,11 +81,6 @@ trait Phased {
finally setMulti(saved)
}
- def showAt[T](phs: Seq[PhaseName])(body: => T): Unit =
- atMap[T](phs)(body) foreach {
- case (ph, op) => Console.println("%15s -> %s".format(ph, op.toString take 240))
- }
-
def atMap[T](phs: Seq[PhaseName])(body: => T): Seq[(PhaseName, T)] =
phs zip atMulti(phs)(body)
@@ -112,16 +98,12 @@ trait Phased {
def apply(id: Int): PhaseName = all find (_.id == id) getOrElse NoPhaseName
implicit def apply(s: String): PhaseName = nameMap(s)
- implicit def defaultPhaseName: PhaseName = active
}
sealed abstract class PhaseName {
lazy val id = phase.id
lazy val name = toString.toLowerCase
def phase = currentRun.phaseNamed(name)
def isEmpty = this eq NoPhaseName
-
- // Execute some code during this phase.
- def apply[T](body: => T): T = atPhase(phase)(body)
}
case object Parser extends PhaseName
@@ -158,5 +140,4 @@ trait Phased {
}
implicit def phaseEnumToPhase(name: PhaseName): Phase = name.phase
- implicit def phaseNameToPhase(name: String): Phase = currentRun.phaseNamed(name)
}
diff --git a/src/compiler/scala/tools/nsc/interpreter/Power.scala b/src/compiler/scala/tools/nsc/interpreter/Power.scala
index 5e6bf8824d..e517a16b32 100644
--- a/src/compiler/scala/tools/nsc/interpreter/Power.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/Power.scala
@@ -8,8 +8,6 @@ package interpreter
import scala.collection.{ mutable, immutable }
import scala.util.matching.Regex
-import scala.reflect.internal.util.{ BatchSourceFile }
-import session.{ History }
import scala.io.Codec
import java.net.{ URL, MalformedURLException }
import io.{ Path }
@@ -48,7 +46,6 @@ class Power[ReplValsImpl <: ReplVals : ru.TypeTag: ClassTag](val intp: IMain, re
import intp.{ beQuietDuring, typeOfExpression, interpret, parse }
import intp.global._
import definitions.{ compilerTypeFromTag, compilerSymbolFromTag}
- import rootMirror.{ getClassIfDefined, getModuleIfDefined }
abstract class SymSlurper {
def isKeep(sym: Symbol): Boolean
@@ -73,7 +70,7 @@ class Power[ReplValsImpl <: ReplVals : ru.TypeTag: ClassTag](val intp: IMain, re
pass += 1
val (repeats, unseen) = todo partition seen
unseenHistory += unseen.size
- if (opt.verbose) {
+ if (settings.verbose.value) {
println("%3d %s accumulated, %s discarded. This pass: %s unseen, %s repeats".format(
pass, keep.size, discarded, unseen.size, repeats.size))
}
@@ -148,21 +145,10 @@ class Power[ReplValsImpl <: ReplVals : ru.TypeTag: ClassTag](val intp: IMain, re
// First we create the ReplVals instance and bind it to $r
intp.bind("$r", replVals)
// Then we import everything from $r.
- intp interpret ("import " + intp.pathToTerm("$r") + "._")
+ intp interpret ("import " + intp.originalPath("$r") + "._")
// And whatever else there is to do.
init.lines foreach (intp interpret _)
}
- def valsDescription: String = {
- def to_str(m: Symbol) = "%12s %s".format(
- m.decodedName, "" + elimRefinement(m.accessedOrSelf.tpe) stripPrefix "scala.tools.nsc.")
-
- ( rutil.info[ReplValsImpl].membersDeclared
- filter (m => m.isPublic && !m.hasModuleFlag && !m.isConstructor)
- sortBy (_.decodedName)
- map to_str
- mkString ("Name and type of values imported into the repl in power mode.\n\n", "\n", "")
- )
- }
trait LowPriorityInternalInfo {
implicit def apply[T: ru.TypeTag : ClassTag] : InternalInfo[T] = new InternalInfo[T](None)
@@ -175,12 +161,7 @@ class Power[ReplValsImpl <: ReplVals : ru.TypeTag: ClassTag](val intp: IMain, re
* symbol, by only implicitly installing one method, "?", and the rest
* of the conveniences exist on that wrapper.
*/
- trait LowPriorityInternalInfoWrapper {
- implicit def apply[T: ru.TypeTag : ClassTag] : InternalInfoWrapper[T] = new InternalInfoWrapper[T](None)
- }
- object InternalInfoWrapper extends LowPriorityInternalInfoWrapper {
-
- }
+ trait LowPriorityInternalInfoWrapper { }
class InternalInfoWrapper[T: ru.TypeTag : ClassTag](value: Option[T] = None) {
def ? : InternalInfo[T] = new InternalInfo[T](value)
}
@@ -190,7 +171,6 @@ class Power[ReplValsImpl <: ReplVals : ru.TypeTag: ClassTag](val intp: IMain, re
* customizable symbol filter (had to hardcode no-spec to reduce noise)
*/
class InternalInfo[T](value: Option[T] = None)(implicit typeEvidence: ru.TypeTag[T], runtimeClassEvidence: ClassTag[T]) {
- private def newInfo[U: ru.TypeTag : ClassTag](value: U): InternalInfo[U] = new InternalInfo[U](Some(value))
private def isSpecialized(s: Symbol) = s.name.toString contains "$mc"
private def isImplClass(s: Symbol) = s.name.toString endsWith "$class"
@@ -201,47 +181,15 @@ class Power[ReplValsImpl <: ReplVals : ru.TypeTag: ClassTag](val intp: IMain, re
|| s.isAnonOrRefinementClass
|| s.isAnonymousFunction
)
- def symbol = compilerSymbolFromTag(tag)
- def tpe = compilerTypeFromTag(tag)
- def name = symbol.name
- def companion = symbol.companionSymbol
- def info = symbol.info
- def moduleClass = symbol.moduleClass
- def owner = symbol.owner
- def owners = symbol.ownerChain drop 1
- def signature = symbol.defString
-
- def decls = info.decls
- def declsOverride = membersDeclared filter (_.isOverride)
- def declsOriginal = membersDeclared filterNot (_.isOverride)
-
+ def symbol = compilerSymbolFromTag(tag)
+ def tpe = compilerTypeFromTag(tag)
def members = membersUnabridged filterNot excludeMember
def membersUnabridged = tpe.members.toList
- def membersDeclared = members filterNot excludeMember
- def membersInherited = members filterNot (membersDeclared contains _)
- def memberTypes = members filter (_.name.isTypeName)
- def memberMethods = members filter (_.isMethod)
-
- def pkg = symbol.enclosingPackage
- def pkgName = pkg.fullName
- def pkgClass = symbol.enclosingPackageClass
- def pkgMembers = pkg.info.members filterNot excludeMember
- def pkgClasses = pkgMembers filter (s => s.isClass && s.isDefinedInPackage)
- def pkgSymbols = new PackageSlurper(pkgClass).slurp() filterNot excludeMember
-
- def tag = typeEvidence
- def runtimeClass = runtimeClassEvidence.runtimeClass
- def shortClass = runtimeClass.getName split "[$.]" last
-
- def baseClasses = tpe.baseClasses
- def baseClassDecls = mapFrom(baseClasses)(_.info.decls.toList.sortBy(_.name))
- def ancestors = baseClasses drop 1
- def ancestorDeclares(name: String) = ancestors filter (_.info member newTermName(name) ne NoSymbol)
- def baseTypes = tpe.baseTypeSeq.toList
-
- def <:<[U: ru.TypeTag : ClassTag](other: U) = tpe <:< newInfo(other).tpe
- def lub[U: ru.TypeTag : ClassTag](other: U) = intp.global.lub(List(tpe, newInfo(other).tpe))
- def glb[U: ru.TypeTag : ClassTag](other: U) = intp.global.glb(List(tpe, newInfo(other).tpe))
+ def pkg = symbol.enclosingPackage
+ def tag = typeEvidence
+ def runtimeClass = runtimeClassEvidence.runtimeClass
+ def shortClass = runtimeClass.getName split "[$.]" last
+ def baseClasses = tpe.baseClasses
override def toString = value match {
case Some(x) => "%s (%s)".format(x, shortClass)
@@ -267,7 +215,6 @@ class Power[ReplValsImpl <: ReplVals : ru.TypeTag: ClassTag](val intp: IMain, re
}
object Prettifier extends LowPriorityPrettifier {
def stringOf(x: Any): String = scala.runtime.ScalaRunTime.stringOf(x)
- def prettify[T](value: T): TraversableOnce[String] = default[T] prettify value
def default[T] = new Prettifier[T] {
def prettify(x: T): TraversableOnce[String] = AnyPrettifier prettify x
def show(x: T): Unit = AnyPrettifier show x
@@ -277,45 +224,21 @@ class Power[ReplValsImpl <: ReplVals : ru.TypeTag: ClassTag](val intp: IMain, re
def show(x: T): Unit
def prettify(x: T): TraversableOnce[String]
- def show(xs: TraversableOnce[T]): Unit = prettify(xs) foreach println
def prettify(xs: TraversableOnce[T]): TraversableOnce[String] = xs flatMap (x => prettify(x))
}
abstract class PrettifierClass[T: Prettifier]() {
val pretty = implicitly[Prettifier[T]]
- import pretty._
-
def value: Seq[T]
def pp(f: Seq[T] => Seq[T]): Unit =
pretty prettify f(value) foreach (StringPrettifier show _)
def freq[U](p: T => U) = (value.toSeq groupBy p mapValues (_.size)).toList sortBy (-_._2) map (_.swap)
- def ppfreq[U](p: T => U): Unit = freq(p) foreach { case (count, key) => println("%5d %s".format(count, key)) }
-
- def |[U](f: Seq[T] => Seq[U]): Seq[U] = f(value)
- def ^^[U](f: T => U): Seq[U] = value map f
- def ^?[U](pf: PartialFunction[T, U]): Seq[U] = value collect pf
- def >>!(implicit ord: Ordering[T]): Unit = pp(_.sorted.distinct)
def >>(implicit ord: Ordering[T]): Unit = pp(_.sorted)
def >!(): Unit = pp(_.distinct)
def >(): Unit = pp(identity)
-
- def >#(): Unit = this ># (identity[T] _)
- def >#[U](p: T => U): Unit = this ppfreq p
-
- def >?(p: T => Boolean): Unit = pp(_ filter p)
- def >?(s: String): Unit = pp(_ filter (_.toString contains s))
- def >?(r: Regex): Unit = pp(_ filter (_.toString matches fixRegex(r)))
-
- private def fixRegex(r: scala.util.matching.Regex): String = {
- val s = r.pattern.toString
- val prefix = if (s startsWith "^") "" else """^.*?"""
- val suffix = if (s endsWith "$") "" else """.*$"""
-
- prefix + s + suffix
- }
}
class MultiPrettifierClass[T: Prettifier](val value: Seq[T]) extends PrettifierClass[T]() { }
@@ -339,17 +262,11 @@ class Power[ReplValsImpl <: ReplVals : ru.TypeTag: ClassTag](val intp: IMain, re
class RichReplURL(url: URL)(implicit codec: Codec) {
def slurp(): String = io.Streamable.slurp(url)
}
- class RichSymbolList(syms: List[Symbol]) {
- def sigs = syms map (_.defString)
- def infos = syms map (_.info)
- }
trait Implicits1 {
// fallback
implicit def replPrinting[T](x: T)(implicit pretty: Prettifier[T] = Prettifier.default[T]) =
new SinglePrettifierClass[T](x)
-
- implicit def liftToTypeName(s: String): TypeName = newTypeName(s)
}
trait Implicits2 extends Implicits1 {
class RichSymbol(sym: Symbol) {
@@ -374,26 +291,13 @@ class Power[ReplValsImpl <: ReplVals : ru.TypeTag: ClassTag](val intp: IMain, re
implicit def replInputStream(in: InputStream)(implicit codec: Codec) = new RichInputStream(in)
implicit def replEnhancedURLs(url: URL)(implicit codec: Codec): RichReplURL = new RichReplURL(url)(codec)
-
- implicit def liftToTermName(s: String): TermName = newTermName(s)
- implicit def replListOfSymbols(xs: List[Symbol]) = new RichSymbolList(xs)
}
trait ReplUtilities {
- // [Eugene to Paul] needs review!
- // def module[T: Manifest] = getModuleIfDefined(manifest[T].erasure.getName stripSuffix nme.MODULE_SUFFIX_STRING)
- // def clazz[T: Manifest] = getClassIfDefined(manifest[T].erasure.getName)
def module[T: ru.TypeTag] = ru.typeOf[T].typeSymbol.suchThat(_.isPackage)
def clazz[T: ru.TypeTag] = ru.typeOf[T].typeSymbol.suchThat(_.isClass)
def info[T: ru.TypeTag : ClassTag] = InternalInfo[T]
def ?[T: ru.TypeTag : ClassTag] = InternalInfo[T]
- def url(s: String) = {
- try new URL(s)
- catch { case _: MalformedURLException =>
- if (Path(s).exists) Path(s).toURL
- else new URL("http://" + s)
- }
- }
def sanitize(s: String): String = sanitize(s.getBytes())
def sanitize(s: Array[Byte]): String = (s map {
case x if x.toChar.isControl => '?'
@@ -411,20 +315,12 @@ class Power[ReplValsImpl <: ReplVals : ru.TypeTag: ClassTag](val intp: IMain, re
lazy val rutil: ReplUtilities = new ReplUtilities { }
lazy val phased: Phased = new { val global: intp.global.type = intp.global } with Phased { }
- def context(code: String) = analyzer.rootContext(unit(code))
- def source(code: String) = newSourceFile(code)
- def unit(code: String) = newCompilationUnit(code)
- def trees(code: String) = parse(code) getOrElse Nil
- def typeOf(id: String) = intp.typeOfExpression(id)
+ def unit(code: String) = newCompilationUnit(code)
+ def trees(code: String) = parse(code) getOrElse Nil
- override def toString = """
+ override def toString = s"""
|** Power mode status **
- |Default phase: %s
- |Names: %s
- |Identifiers: %s
- """.stripMargin.format(
- phased.get,
- intp.allDefinedNames mkString " ",
- intp.unqualifiedIds mkString " "
- )
+ |Default phase: ${phased.get}
+ |Names: ${intp.unqualifiedIds mkString " "}
+ """.stripMargin
}
diff --git a/src/compiler/scala/tools/nsc/interpreter/ReplConfig.scala b/src/compiler/scala/tools/nsc/interpreter/ReplConfig.scala
index 7cd0f436c4..3392ea0b5e 100644
--- a/src/compiler/scala/tools/nsc/interpreter/ReplConfig.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/ReplConfig.scala
@@ -14,9 +14,7 @@ trait ReplConfig {
lazy val replProps = new ReplProps
class TapMaker[T](x: T) {
- def tapInfo(msg: => String): T = tap(x => replinfo(parens(x)))
def tapDebug(msg: => String): T = tap(x => repldbg(parens(x)))
- def tapTrace(msg: => String): T = tap(x => repltrace(parens(x)))
def tap[U](f: T => U): T = {
f(x)
x
@@ -28,12 +26,6 @@ trait ReplConfig {
try Console println msg
catch { case x: AssertionError => Console.println("Assertion error printing debugging output: " + x) }
- private[nsc] def repldbgex(ex: Throwable): Unit = {
- if (isReplDebug) {
- echo("Caught/suppressing: " + ex)
- ex.printStackTrace
- }
- }
private[nsc] def repldbg(msg: => String) = if (isReplDebug) echo(msg)
private[nsc] def repltrace(msg: => String) = if (isReplTrace) echo(msg)
private[nsc] def replinfo(msg: => String) = if (isReplInfo) echo(msg)
@@ -45,14 +37,10 @@ trait ReplConfig {
repltrace(stackTraceString(unwrap(t)))
alt
}
- private[nsc] def substituteAndLog[T](alt: => T)(body: => T): T =
- substituteAndLog("" + alt, alt)(body)
private[nsc] def substituteAndLog[T](label: String, alt: => T)(body: => T): T = {
try body
catch logAndDiscard(label, alt)
}
- private[nsc] def squashAndLog(label: String)(body: => Unit): Unit =
- substituteAndLog(label, ())(body)
def isReplTrace: Boolean = replProps.trace
def isReplDebug: Boolean = replProps.debug || isReplTrace
diff --git a/src/compiler/scala/tools/nsc/interpreter/ReplDir.scala b/src/compiler/scala/tools/nsc/interpreter/ReplDir.scala
new file mode 100644
index 0000000000..9fbf64acb5
--- /dev/null
+++ b/src/compiler/scala/tools/nsc/interpreter/ReplDir.scala
@@ -0,0 +1,48 @@
+/* NSC -- new Scala compiler
+ * Copyright 2005-2012 LAMP/EPFL
+ * @author Paul Phillips
+ */
+
+package scala.tools.nsc
+package interpreter
+
+import io.VirtualDirectory
+import settings.MutableSettings
+import scala.reflect.io.{ AbstractFile, PlainDirectory, Directory }
+import scala.collection.generic.Clearable
+
+/** Directory to save .class files to. */
+trait ReplDir extends AbstractFile with Clearable { }
+
+private class ReplVirtualDir() extends VirtualDirectory("(memory)", None) with ReplDir { }
+private class ReplRealDir(dir: Directory) extends PlainDirectory(dir) with ReplDir {
+ def clear() = {
+ dir.deleteRecursively()
+ dir.createDirectory()
+ }
+}
+
+class ReplOutput(val dirSetting: MutableSettings#StringSetting) {
+ // outdir for generated classfiles - may be in-memory (the default),
+ // a generated temporary directory, or a specified outdir.
+ val dir: ReplDir = (
+ if (dirSetting.isDefault)
+ new ReplVirtualDir()
+ else if (dirSetting.value == "")
+ new ReplRealDir(Directory.makeTemp("repl"))
+ else
+ new ReplRealDir(Directory(dirSetting.value))
+ )
+
+ // print the contents hierarchically
+ def show(out: JPrintWriter) = {
+ def pp(root: AbstractFile, indentLevel: Int) {
+ val label = root.name
+ val spaces = " " * indentLevel
+ out.println(spaces + label)
+ if (root.isDirectory)
+ root.toList sortBy (_.name) foreach (x => pp(x, indentLevel + 1))
+ }
+ pp(dir, 0)
+ }
+}
diff --git a/src/compiler/scala/tools/nsc/interpreter/ReplGlobal.scala b/src/compiler/scala/tools/nsc/interpreter/ReplGlobal.scala
index 7c698a2f3e..16b22869e7 100644
--- a/src/compiler/scala/tools/nsc/interpreter/ReplGlobal.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/ReplGlobal.scala
@@ -6,7 +6,6 @@
package scala.tools.nsc
package interpreter
-import reporters._
import typechecker.Analyzer
/** A layer on top of Global so I can guarantee some extra
diff --git a/src/compiler/scala/tools/nsc/interpreter/ReplProps.scala b/src/compiler/scala/tools/nsc/interpreter/ReplProps.scala
index bc3e7a10d7..2364918494 100644
--- a/src/compiler/scala/tools/nsc/interpreter/ReplProps.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/ReplProps.scala
@@ -13,15 +13,11 @@ class ReplProps {
private def bool(name: String) = BooleanProp.keyExists(name)
private def int(name: String) = IntProp(name)
- val jlineDebug = bool("scala.tools.jline.internal.Log.debug")
- val jlineTrace = bool("scala.tools.jline.internal.Log.trace")
-
val info = bool("scala.repl.info")
val debug = bool("scala.repl.debug")
val trace = bool("scala.repl.trace")
val power = bool("scala.repl.power")
- val replInitCode = Prop[JFile]("scala.repl.initcode")
val replAutorunCode = Prop[JFile]("scala.repl.autoruncode")
val powerInitCode = Prop[JFile]("scala.repl.power.initcode")
val powerBanner = Prop[JFile]("scala.repl.power.banner")
diff --git a/src/compiler/scala/tools/nsc/interpreter/ReplStrings.scala b/src/compiler/scala/tools/nsc/interpreter/ReplStrings.scala
index f8ecc6c6fe..08472bbc64 100644
--- a/src/compiler/scala/tools/nsc/interpreter/ReplStrings.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/ReplStrings.scala
@@ -6,8 +6,6 @@
package scala.tools.nsc
package interpreter
-import scala.collection.{ mutable, immutable }
-import scala.PartialFunction.cond
import scala.reflect.internal.Chars
trait ReplStrings {
@@ -31,5 +29,4 @@ trait ReplStrings {
"scala.runtime.ScalaRunTime.replStringOf(%s, %s)".format(x, maxlen)
def words(s: String) = s.trim split "\\s+" filterNot (_ == "") toList
- def isQuoted(s: String) = (s.length >= 2) && (s.head == s.last) && ("\"'" contains s.head)
}
diff --git a/src/compiler/scala/tools/nsc/interpreter/ReplVals.scala b/src/compiler/scala/tools/nsc/interpreter/ReplVals.scala
index 53478bdc5d..ea100b25f2 100644
--- a/src/compiler/scala/tools/nsc/interpreter/ReplVals.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/ReplVals.scala
@@ -57,7 +57,6 @@ object ReplVals {
*/
def mkCompilerTypeFromTag[T <: Global](global: T) = {
import global._
- import definitions._
/** We can't use definitions.compilerTypeFromTag directly because we're passing
* it to map and the compiler refuses to perform eta expansion on a method
diff --git a/src/compiler/scala/tools/nsc/interpreter/RichClass.scala b/src/compiler/scala/tools/nsc/interpreter/RichClass.scala
index 4371f7fe05..36cdf65510 100644
--- a/src/compiler/scala/tools/nsc/interpreter/RichClass.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/RichClass.scala
@@ -10,7 +10,6 @@ import scala.reflect.{ ClassTag, classTag }
class RichClass[T](val clazz: Class[T]) {
def toTag: ClassTag[T] = ClassTag[T](clazz)
- def toTypeString: String = TypeStrings.fromClazz(clazz)
// Sadly isAnonymousClass does not return true for scala anonymous
// classes because our naming scheme is not doing well against the
@@ -20,14 +19,12 @@ class RichClass[T](val clazz: Class[T]) {
catch { case _: java.lang.InternalError => false } // good ol' "Malformed class name"
)
- /** It's not easy... to be... me... */
- def supermans: List[ClassTag[_]] = supers map (_.toTag)
+ def supertags: List[ClassTag[_]] = supers map (_.toTag)
def superNames: List[String] = supers map (_.getName)
def interfaces: List[JClass] = supers filter (_.isInterface)
def hasAncestorName(f: String => Boolean) = superNames exists f
def hasAncestor(f: JClass => Boolean) = supers exists f
- def hasAncestorInPackage(pkg: String) = hasAncestorName(_ startsWith (pkg + "."))
def supers: List[JClass] = {
def loop(x: JClass): List[JClass] = x.getSuperclass match {
diff --git a/src/compiler/scala/tools/nsc/interpreter/SimpleReader.scala b/src/compiler/scala/tools/nsc/interpreter/SimpleReader.scala
index bccd8158ec..2d0917d91f 100644
--- a/src/compiler/scala/tools/nsc/interpreter/SimpleReader.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/SimpleReader.scala
@@ -19,11 +19,8 @@ extends InteractiveReader
val history = NoHistory
val completion = NoCompletion
- def init() = ()
def reset() = ()
- def eraseLine() = ()
def redrawLine() = ()
- def currentLine = ""
def readOneLine(prompt: String): String = {
if (interactive) {
out.print(prompt)
@@ -40,4 +37,4 @@ object SimpleReader {
def apply(in: BufferedReader = defaultIn, out: JPrintWriter = defaultOut, interactive: Boolean = true): SimpleReader =
new SimpleReader(in, out, interactive)
-} \ No newline at end of file
+}
diff --git a/src/compiler/scala/tools/nsc/interpreter/TypeStrings.scala b/src/compiler/scala/tools/nsc/interpreter/TypeStrings.scala
index 6abb52a649..239dbb8149 100644
--- a/src/compiler/scala/tools/nsc/interpreter/TypeStrings.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/TypeStrings.scala
@@ -13,15 +13,12 @@ import NameTransformer._
import scala.reflect.runtime.{universe => ru}
import scala.reflect.{ClassTag, classTag}
import typechecker.DestructureTypes
-import scala.reflect.internal.util.StringOps.ojoin
-import scala.language.implicitConversions
/** A more principled system for turning types into strings.
*/
trait StructuredTypeStrings extends DestructureTypes {
val global: Global
import global._
- import definitions._
case class LabelAndType(label: String, typeName: String) { }
object LabelAndType {
@@ -36,10 +33,8 @@ trait StructuredTypeStrings extends DestructureTypes {
val NoGrouping = Grouping("", "", "", false)
val ListGrouping = Grouping("(", ", ", ")", false)
val ProductGrouping = Grouping("(", ", ", ")", true)
- val ParamGrouping = Grouping("(", ", ", ")", true)
val BlockGrouping = Grouping(" { ", "; ", "}", false)
- private implicit def lowerName(n: Name): String = "" + n
private def str(level: Int)(body: => String): String = " " * level + body
private def block(level: Int, grouping: Grouping)(name: String, nodes: List[TypeNode]): String = {
val l1 = str(level)(name + grouping.ldelim)
@@ -49,7 +44,6 @@ trait StructuredTypeStrings extends DestructureTypes {
l1 +: l2 :+ l3 mkString "\n"
}
private def maybeBlock(level: Int, grouping: Grouping)(name: String, nodes: List[TypeNode]): String = {
- import grouping._
val threshold = 70
val try1 = str(level)(name + grouping.join(nodes map (_.show(0, grouping.labels)): _*))
@@ -57,7 +51,7 @@ trait StructuredTypeStrings extends DestructureTypes {
else block(level, grouping)(name, nodes)
}
private def shortClass(x: Any) = {
- if (opt.debug) {
+ if (settings.debug.value) {
val name = (x.getClass.getName split '.').last
val isAnon = name.reverse takeWhile (_ != '$') forall (_.isDigit)
val str = if (isAnon) name else (name split '$').last
@@ -194,7 +188,6 @@ trait TypeStrings {
else enclClass.getName + "." + (name stripPrefix enclPre)
)
}
- def scalaName(ct: ClassTag[_]): String = scalaName(ct.runtimeClass)
def anyClass(x: Any): JClass = if (x == null) null else x.getClass
private def brackets(tps: String*): String =
@@ -212,10 +205,8 @@ trait TypeStrings {
}
private def tparamString[T: ru.TypeTag] : String = {
+ import ru._
def typeArguments: List[ru.Type] = ru.typeOf[T] match { case ru.TypeRef(_, _, args) => args; case _ => Nil }
- // [Eugene to Paul] need to use not the `rootMirror`, but a mirror with the REPL's classloader
- // how do I get to it? acquiring context classloader seems unreliable because of multithreading
- def typeVariables: List[java.lang.Class[_]] = typeArguments map (targ => ru.rootMirror.runtimeClass(targ))
brackets(typeArguments map (jc => tvarString(List(jc))): _*)
}
@@ -227,7 +218,6 @@ trait TypeStrings {
* practice to rely on toString for correctness) generated the VALID string
* representation of the type.
*/
- def fromTypedValue[T: ru.TypeTag : ClassTag](x: T): String = fromTag[T]
def fromValue(value: Any): String = if (value == null) "Null" else fromClazz(anyClass(value))
def fromClazz(clazz: JClass): String = scalaName(clazz) + tparamString(clazz)
def fromTag[T: ru.TypeTag : ClassTag] : String = scalaName(classTag[T].runtimeClass) + tparamString[T]
@@ -247,13 +237,6 @@ trait TypeStrings {
case (res, (k, v)) => res.replaceAll(k, v)
}
}
-
- val typeTransforms = List(
- "java.lang." -> "",
- "scala.collection.immutable." -> "immutable.",
- "scala.collection.mutable." -> "mutable.",
- "scala.collection.generic." -> "generic."
- )
}
object TypeStrings extends TypeStrings { }
diff --git a/src/compiler/scala/tools/nsc/interpreter/package.scala b/src/compiler/scala/tools/nsc/interpreter/package.scala
index e3440c9f8b..52a085080b 100644
--- a/src/compiler/scala/tools/nsc/interpreter/package.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/package.scala
@@ -6,6 +6,10 @@
package scala.tools.nsc
import scala.language.implicitConversions
+import scala.reflect.{ classTag, ClassTag }
+import scala.reflect.runtime.{ universe => ru }
+import scala.reflect.{ClassTag, classTag}
+import scala.reflect.api.{Mirror, TypeCreator, Universe => ApiUniverse}
/** The main REPL related classes and values are as follows.
* In addition to standard compiler classes Global and Settings, there are:
@@ -44,6 +48,110 @@ package object interpreter extends ReplConfig with ReplStrings {
private[nsc] implicit def enrichClass[T](clazz: Class[T]) = new RichClass[T](clazz)
private[nsc] implicit def enrichAnyRefWithTap[T](x: T) = new TapMaker(x)
- private[nsc] def tracing[T](msg: String)(x: T): T = x.tapTrace(msg)
private[nsc] def debugging[T](msg: String)(x: T) = x.tapDebug(msg)
+
+ private val ourClassloader = getClass.getClassLoader
+
+ def staticTypeTag[T: ClassTag]: ru.TypeTag[T] = ru.TypeTag[T](
+ ru.runtimeMirror(ourClassloader),
+ new TypeCreator {
+ def apply[U <: ApiUniverse with Singleton](m: Mirror[U]): U # Type =
+ m.staticClass(classTag[T].runtimeClass.getName).toTypeConstructor.asInstanceOf[U # Type]
+ })
+
+ /** This class serves to trick the compiler into treating a var
+ * (intp, in ILoop) as a stable identifier.
+ */
+ implicit class IMainOps(val intp: IMain) {
+ import intp._
+ import global.{ reporter => _, _ }
+ import definitions._
+
+ protected def echo(msg: String) = {
+ Console.out println msg
+ Console.out.flush()
+ }
+
+ def implicitsCommand(line: String): String = {
+ def p(x: Any) = intp.reporter.printMessage("" + x)
+
+ // If an argument is given, only show a source with that
+ // in its name somewhere.
+ val args = line split "\\s+"
+ val filtered = intp.implicitSymbolsBySource filter {
+ case (source, syms) =>
+ (args contains "-v") || {
+ if (line == "") (source.fullName.toString != "scala.Predef")
+ else (args exists (source.name.toString contains _))
+ }
+ }
+
+ if (filtered.isEmpty)
+ return "No implicits have been imported other than those in Predef."
+
+ filtered foreach {
+ case (source, syms) =>
+ p("/* " + syms.size + " implicit members imported from " + source.fullName + " */")
+
+ // This groups the members by where the symbol is defined
+ val byOwner = syms groupBy (_.owner)
+ val sortedOwners = byOwner.toList sortBy { case (owner, _) => exitingTyper(source.info.baseClasses indexOf owner) }
+
+ sortedOwners foreach {
+ case (owner, members) =>
+ // Within each owner, we cluster results based on the final result type
+ // if there are more than a couple, and sort each cluster based on name.
+ // This is really just trying to make the 100 or so implicits imported
+ // by default into something readable.
+ val memberGroups: List[List[Symbol]] = {
+ val groups = members groupBy (_.tpe.finalResultType) toList
+ val (big, small) = groups partition (_._2.size > 3)
+ val xss = (
+ (big sortBy (_._1.toString) map (_._2)) :+
+ (small flatMap (_._2))
+ )
+
+ xss map (xs => xs sortBy (_.name.toString))
+ }
+
+ val ownerMessage = if (owner == source) " defined in " else " inherited from "
+ p(" /* " + members.size + ownerMessage + owner.fullName + " */")
+
+ memberGroups foreach { group =>
+ group foreach (s => p(" " + intp.symbolDefString(s)))
+ p("")
+ }
+ }
+ p("")
+ }
+ ""
+ }
+
+ /** TODO -
+ * -n normalize
+ * -l label with case class parameter names
+ * -c complete - leave nothing out
+ */
+ def typeCommandInternal(expr: String, verbose: Boolean): Unit =
+ symbolOfLine(expr) andAlso (echoTypeSignature(_, verbose))
+
+ def printAfterTyper(msg: => String) =
+ reporter printUntruncatedMessage exitingTyper(msg)
+
+ private def replInfo(sym: Symbol) =
+ if (sym.isAccessor) dropNullaryMethod(sym.info) else sym.info
+
+ def echoTypeStructure(sym: Symbol) =
+ printAfterTyper("" + deconstruct.show(replInfo(sym)))
+
+ def echoTypeSignature(sym: Symbol, verbose: Boolean) = {
+ if (verbose) echo("// Type signature")
+ printAfterTyper("" + replInfo(sym))
+
+ if (verbose) {
+ echo("\n// Internal Type structure")
+ echoTypeStructure(sym)
+ }
+ }
+ }
}
diff --git a/src/compiler/scala/tools/nsc/interpreter/session/History.scala b/src/compiler/scala/tools/nsc/interpreter/session/History.scala
index daa05b86db..794d41adc7 100644
--- a/src/compiler/scala/tools/nsc/interpreter/session/History.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/session/History.scala
@@ -14,15 +14,9 @@ trait History {
def asStrings: List[String]
def index: Int
def size: Int
- def grep(s: String): List[String]
}
object NoHistory extends History {
def asStrings = Nil
- def grep(s: String) = Nil
def index = 0
def size = 0
}
-
-object History {
- def empty: History = NoHistory
-}
diff --git a/src/compiler/scala/tools/nsc/interpreter/session/SimpleHistory.scala b/src/compiler/scala/tools/nsc/interpreter/session/SimpleHistory.scala
index 9f4e2b9df3..89998e438a 100644
--- a/src/compiler/scala/tools/nsc/interpreter/session/SimpleHistory.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/session/SimpleHistory.scala
@@ -54,9 +54,5 @@ class SimpleHistory extends JLineHistory {
def moveTo(idx: Int) = (idx > 0) && (idx <= lastIndex) && setTo(idx)
def moveToEnd(): Unit = setTo(size)
- // scala legacy interface
- def asList: List[JEntry] = toEntries().toList
- def asJavaList = entries()
- def asStrings = buf.toList
- def grep(s: String) = buf.toList filter (_ contains s)
+ def asStrings = buf.toList
}
diff --git a/src/compiler/scala/tools/nsc/io/Fileish.scala b/src/compiler/scala/tools/nsc/io/Fileish.scala
deleted file mode 100644
index 7b4e385dd8..0000000000
--- a/src/compiler/scala/tools/nsc/io/Fileish.scala
+++ /dev/null
@@ -1,33 +0,0 @@
-/* NSC -- new Scala compiler
- * Copyright 2005-2013 LAMP/EPFL
- * @author Paul Phillips
- */
-
-package scala.tools.nsc
-package io
-
-import java.io.{ InputStream }
-import java.util.jar.JarEntry
-
-/** A common interface for File-based things and Stream-based things.
- * (In particular, io.File and JarEntry.)
- */
-class Fileish(val path: Path, val input: () => InputStream) extends Streamable.Chars {
- def inputStream() = input()
-
- def parent = path.parent
- def name = path.name
- def isSourceFile = path.hasExtension("java", "scala")
-
- private lazy val pkgLines = lines() collect { case x if x startsWith "package " => x stripPrefix "package" trim }
- lazy val pkgFromPath = parent.path.replaceAll("""[/\\]""", ".")
- lazy val pkgFromSource = pkgLines map (_ stripSuffix ";") mkString "."
-
- override def toString = path.path
-}
-
-object Fileish {
- def apply(f: File): Fileish = new Fileish(f, () => f.inputStream())
- def apply(f: JarEntry, in: () => InputStream): Fileish = new Fileish(Path(f.getName), in)
- def apply(path: String, in: () => InputStream): Fileish = new Fileish(Path(path), in)
-}
diff --git a/src/compiler/scala/tools/nsc/io/Jar.scala b/src/compiler/scala/tools/nsc/io/Jar.scala
index e919621338..49a1ff114f 100644
--- a/src/compiler/scala/tools/nsc/io/Jar.scala
+++ b/src/compiler/scala/tools/nsc/io/Jar.scala
@@ -10,7 +10,6 @@ import java.io.{ InputStream, OutputStream, IOException, FileNotFoundException,
import java.util.jar._
import scala.collection.JavaConverters._
import Attributes.Name
-import util.ClassPath
import scala.language.implicitConversions
// Attributes.Name instances:
@@ -37,9 +36,6 @@ class Jar(file: File) extends Iterable[JarEntry] {
def this(jfile: JFile) = this(File(jfile))
def this(path: String) = this(File(path))
- protected def errorFn(msg: String): Unit = Console println msg
-
- lazy val jarFile = new JarFile(file.jfile)
lazy val manifest = withJarInput(s => Option(s.getManifest))
def mainClass = manifest map (f => f(Name.MAIN_CLASS))
@@ -64,12 +60,6 @@ class Jar(file: File) extends Iterable[JarEntry] {
Iterator continually in.getNextJarEntry() takeWhile (_ != null) foreach f
}
override def iterator: Iterator[JarEntry] = this.toList.iterator
- def fileishIterator: Iterator[Fileish] = jarFile.entries.asScala map (x => Fileish(x, () => getEntryStream(x)))
-
- private def getEntryStream(entry: JarEntry) = jarFile getInputStream entry match {
- case null => errorFn("No such entry: " + entry) ; null
- case x => x
- }
override def toString = "" + file
}
@@ -131,7 +121,6 @@ object Jar {
m
}
def apply(manifest: JManifest): WManifest = new WManifest(manifest)
- implicit def unenrichManifest(x: WManifest): JManifest = x.underlying
}
class WManifest(manifest: JManifest) {
for ((k, v) <- initialMainAttrs)
@@ -148,12 +137,7 @@ object Jar {
}
def apply(name: Attributes.Name): String = attrs(name)
- def apply(name: String): String = apply(new Attributes.Name(name))
def update(key: Attributes.Name, value: String) = attrs.put(key, value)
- def update(key: String, value: String) = attrs.put(new Attributes.Name(key), value)
-
- def mainClass: String = apply(Name.MAIN_CLASS)
- def mainClass_=(value: String) = update(Name.MAIN_CLASS, value)
}
// See http://download.java.net/jdk7/docs/api/java/nio/file/Path.html
diff --git a/src/compiler/scala/tools/nsc/io/Lexer.scala b/src/compiler/scala/tools/nsc/io/Lexer.scala
index 5ffb5b4d4f..e843f8d5ce 100644
--- a/src/compiler/scala/tools/nsc/io/Lexer.scala
+++ b/src/compiler/scala/tools/nsc/io/Lexer.scala
@@ -1,8 +1,6 @@
package scala.tools.nsc.io
-import java.io.{Reader, Writer, StringReader, StringWriter}
-import scala.collection.mutable.{Buffer, ArrayBuffer}
-import scala.math.BigInt
+import java.io.Reader
/** Companion object of class `Lexer` which defines tokens and some utility concepts
* used for tokens and lexers
diff --git a/src/compiler/scala/tools/nsc/io/MsilFile.scala b/src/compiler/scala/tools/nsc/io/MsilFile.scala
deleted file mode 100644
index 2f0a71fc60..0000000000
--- a/src/compiler/scala/tools/nsc/io/MsilFile.scala
+++ /dev/null
@@ -1,18 +0,0 @@
-/* NSC -- new Scala compiler
- * Copyright 2005-2013 LAMP/EPFL
- * @author Paul Phillips
- */
-
-package scala.tools.nsc
-package io
-
-import ch.epfl.lamp.compiler.msil.{ Type => MsilType, _ }
-
-/** This class wraps an MsilType. It exists only so
- * ClassPath can treat all of JVM/MSIL/bin/src files
- * uniformly, as AbstractFiles.
- */
-class MsilFile(val msilType: MsilType) extends VirtualFile(msilType.FullName, msilType.Namespace) {
-}
-
-object NoMsilFile extends MsilFile(null) { }
diff --git a/src/compiler/scala/tools/nsc/io/Pickler.scala b/src/compiler/scala/tools/nsc/io/Pickler.scala
index b03a921e87..5d32c10143 100644
--- a/src/compiler/scala/tools/nsc/io/Pickler.scala
+++ b/src/compiler/scala/tools/nsc/io/Pickler.scala
@@ -1,6 +1,5 @@
package scala.tools.nsc.io
-import scala.annotation.unchecked
import Lexer._
import java.io.Writer
import scala.language.implicitConversions
@@ -71,14 +70,6 @@ abstract class Pickler[T] {
*/
def wrapped [U] (in: T => U)(out: U => T): Pickler[U] = wrappedPickler(this)(in)(out)
- /** A pickler obtained from the current pickler by also admitting `null` as
- * a handled value, represented as the token `null`.
- *
- * @param fromNull an implicit evidence parameter ensuring that the type of values
- * handled by this pickler contains `null`.
- */
- def orNull(implicit fromNull: Null <:< T): Pickler[T] = nullablePickler(this)
-
/** A conditional pickler obtained from the current pickler.
* @param cond the condition to test to find out whether pickler can handle
* some Scala value.
@@ -93,9 +84,6 @@ abstract class Pickler[T] {
}
object Pickler {
-
- var picklerDebugMode = false
-
/** A base class representing unpickler result. It has two subclasses:
* `UnpickleSucess` for successful unpicklings and `UnpickleFailure` for failures,
* where a value of the given type `T` could not be unpickled from input.
@@ -175,17 +163,6 @@ object Pickler {
def ~ [T](y: T): S ~ T = new ~ (x, y)
}
- /** A converter from binary functions to functions over `~`-pairs
- */
- implicit def fromTilde[T1, T2, R](f: (T1, T2) => R): T1 ~ T2 => R = { case x1 ~ x2 => f(x1, x2) }
-
- /** An converter from unctions returning Options over pair to functions returning `~`-pairs
- * The converted function will raise a `MatchError` where the original function returned
- * a `None`. This converter is useful for turning `unapply` methods of case classes
- * into wrapper methods that can be passed as second argument to `wrap`.
- */
- implicit def toTilde[T1, T2, S](f: S => Option[(T1, T2)]): S => T1 ~ T2 = { x => (f(x): @unchecked) match { case Some((x1, x2)) => x1 ~ x2 } }
-
/** Same as `p.labelled(label)`.
*/
def labelledPickler[T](label: String, p: Pickler[T]): Pickler[T] = new Pickler[T] {
@@ -249,16 +226,6 @@ object Pickler {
def unpickle(rd: Lexer) = p.unpickle(rd) orElse qq.unpickle(rd)
}
- /** Same as `p.orNull`
- */
- def nullablePickler[T](p: Pickler[T])(implicit fromNull: Null <:< T): Pickler[T] = new Pickler[T] {
- def pickle(wr: Writer, x: T) =
- if (x == null) wr.write("null") else p.pickle(wr, x)
- def unpickle(rd: Lexer): Unpickled[T] =
- if (rd.token == NullLit) nextSuccess(rd, fromNull(null))
- else p.unpickle(rd)
- }
-
/** A conditional pickler for singleton objects. It represents these
* with the object's underlying class as a label.
* Example: Object scala.None would be represented as `scala.None$()`.
@@ -330,22 +297,9 @@ object Pickler {
implicit val longPickler: Pickler[Long] =
tokenPickler("integer literal") { case IntLit(s) => s.toLong }
- /** A pickler for values of type `Double`, represented as floating point literals */
- implicit val doublePickler: Pickler[Double] =
- tokenPickler("floating point literal") { case FloatLit(s) => s.toDouble }
-
- /** A pickler for values of type `Byte`, represented as integer literals */
- implicit val bytePickler: Pickler[Byte] = longPickler.wrapped { _.toByte } { _.toLong }
-
- /** A pickler for values of type `Short`, represented as integer literals */
- implicit val shortPickler: Pickler[Short] = longPickler.wrapped { _.toShort } { _.toLong }
-
/** A pickler for values of type `Int`, represented as integer literals */
implicit val intPickler: Pickler[Int] = longPickler.wrapped { _.toInt } { _.toLong }
- /** A pickler for values of type `Float`, represented as floating point literals */
- implicit val floatPickler: Pickler[Float] = doublePickler.wrapped { _.toFloat } { _.toLong }
-
/** A conditional pickler for the boolean value `true` */
private val truePickler =
tokenPickler("boolean literal") { case TrueLit => true } cond { _ == true }
@@ -373,52 +327,15 @@ object Pickler {
}
}
- /** A pickler for values of type `Char`, represented as string literals of length 1 */
- implicit val charPickler: Pickler[Char] =
- stringPickler
- .wrapped { s => require(s.length == 1, "single character string literal expected, but "+quoted(s)+" found"); s(0) } { _.toString }
-
- /** A pickler for pairs, represented as `~`-pairs */
- implicit def tuple2Pickler[T1: Pickler, T2: Pickler]: Pickler[(T1, T2)] =
- (pkl[T1] ~ pkl[T2])
- .wrapped { case x1 ~ x2 => (x1, x2) } { case (x1, x2) => x1 ~ x2 }
- .labelled ("tuple2")
-
/** A pickler for 3-tuples, represented as `~`-tuples */
implicit def tuple3Pickler[T1, T2, T3](implicit p1: Pickler[T1], p2: Pickler[T2], p3: Pickler[T3]): Pickler[(T1, T2, T3)] =
(p1 ~ p2 ~ p3)
.wrapped { case x1 ~ x2 ~ x3 => (x1, x2, x3) } { case (x1, x2, x3) => x1 ~ x2 ~ x3 }
.labelled ("tuple3")
- /** A pickler for 4-tuples, represented as `~`-tuples */
- implicit def tuple4Pickler[T1, T2, T3, T4](implicit p1: Pickler[T1], p2: Pickler[T2], p3: Pickler[T3], p4: Pickler[T4]): Pickler[(T1, T2, T3, T4)] =
- (p1 ~ p2 ~ p3 ~ p4)
- .wrapped { case x1 ~ x2 ~ x3 ~ x4 => (x1, x2, x3, x4) } { case (x1, x2, x3, x4) => x1 ~ x2 ~ x3 ~ x4 }
- .labelled ("tuple4")
-
- /** A conditional pickler for the `scala.None` object */
- implicit val nonePickler = singletonPickler(None)
-
- /** A conditional pickler for instances of class `scala.Some` */
- implicit def somePickler[T: Pickler]: CondPickler[Some[T]] =
- pkl[T]
- .wrapped { Some(_) } { _.get }
- .asClass (classOf[Some[T]])
-
- /** A pickler for optional values */
- implicit def optionPickler[T: Pickler]: Pickler[Option[T]] = nonePickler | somePickler[T]
-
/** A pickler for list values */
implicit def listPickler[T: Pickler]: Pickler[List[T]] =
iterPickler[T] .wrapped { _.toList } { _.iterator } .labelled ("scala.List")
-
- /** A pickler for vector values */
- implicit def vectorPickler[T: Pickler]: Pickler[Vector[T]] =
- iterPickler[T] .wrapped { Vector() ++ _ } { _.iterator } .labelled ("scala.Vector")
-
- /** A pickler for array values */
- implicit def array[T : ClassTag : Pickler]: Pickler[Array[T]] =
- iterPickler[T] .wrapped { _.toArray} { _.iterator } .labelled ("scala.Array")
}
/** A subclass of Pickler can indicate whether a particular value can be pickled by instances
diff --git a/src/compiler/scala/tools/nsc/io/Replayer.scala b/src/compiler/scala/tools/nsc/io/Replayer.scala
index 5cb61b6cb1..e3dc8939a3 100644
--- a/src/compiler/scala/tools/nsc/io/Replayer.scala
+++ b/src/compiler/scala/tools/nsc/io/Replayer.scala
@@ -3,7 +3,7 @@ package scala.tools.nsc.io
import java.io.{Reader, Writer}
import Pickler._
-import Lexer.{Token, EOF}
+import Lexer.EOF
abstract class LogReplay {
def logreplay(event: String, x: => Boolean): Boolean
diff --git a/src/compiler/scala/tools/nsc/io/Socket.scala b/src/compiler/scala/tools/nsc/io/Socket.scala
index e766c1b2fd..4925c50d85 100644
--- a/src/compiler/scala/tools/nsc/io/Socket.scala
+++ b/src/compiler/scala/tools/nsc/io/Socket.scala
@@ -28,13 +28,10 @@ object Socket {
private val optHandler = handlerFn[Option[T]](_ => None)
private val eitherHandler = handlerFn[Either[Throwable, T]](x => Left(x))
- def getOrElse[T1 >: T](alt: T1): T1 = opt getOrElse alt
def either: Either[Throwable, T] = try Right(f()) catch eitherHandler
def opt: Option[T] = try Some(f()) catch optHandler
}
- def newIPv4Server(port: Int = 0) = new Box(() => preferringIPv4(new ServerSocket(0)))
- def newServer(port: Int = 0) = new Box(() => new ServerSocket(0))
def localhost(port: Int) = apply(InetAddress.getLocalHost(), port)
def apply(host: InetAddress, port: Int) = new Box(() => new Socket(new JSocket(host, port)))
def apply(host: String, port: Int) = new Box(() => new Socket(new JSocket(host, port)))
@@ -62,4 +59,4 @@ class Socket(jsocket: JSocket) extends Streamable.Bytes with Closeable {
out.close()
}
}
-} \ No newline at end of file
+}
diff --git a/src/compiler/scala/tools/nsc/io/SourceReader.scala b/src/compiler/scala/tools/nsc/io/SourceReader.scala
index 569270f530..ece78db2cf 100644
--- a/src/compiler/scala/tools/nsc/io/SourceReader.scala
+++ b/src/compiler/scala/tools/nsc/io/SourceReader.scala
@@ -9,7 +9,7 @@ package io
import java.io.{ FileInputStream, InputStream, IOException }
import java.nio.{ByteBuffer, CharBuffer}
-import java.nio.channels.{FileChannel, ReadableByteChannel, Channels}
+import java.nio.channels.{ ReadableByteChannel, Channels }
import java.nio.charset.{CharsetDecoder, CoderResult}
import scala.tools.nsc.reporters._
@@ -33,9 +33,6 @@ class SourceReader(decoder: CharsetDecoder, reporter: Reporter) {
"Please try specifying another one using the -encoding option")
}
- /** Reads the file with the specified name. */
- def read(filename: String): Array[Char]= read(new JFile(filename))
-
/** Reads the specified file. */
def read(file: JFile): Array[Char] = {
val c = new FileInputStream(file).getChannel
diff --git a/src/compiler/scala/tools/nsc/io/package.scala b/src/compiler/scala/tools/nsc/io/package.scala
index 711696bb6e..0b2db115fb 100644
--- a/src/compiler/scala/tools/nsc/io/package.scala
+++ b/src/compiler/scala/tools/nsc/io/package.scala
@@ -7,7 +7,6 @@ package scala.tools.nsc
import java.util.concurrent.{ Future, Callable }
import java.util.{ Timer, TimerTask }
-import java.util.jar.{ Attributes }
import scala.language.implicitConversions
package object io {
@@ -21,14 +20,10 @@ package object io {
type Path = scala.reflect.io.Path
val Path = scala.reflect.io.Path
type PlainFile = scala.reflect.io.PlainFile
- val PlainFile = scala.reflect.io.PlainFile
val Streamable = scala.reflect.io.Streamable
type VirtualDirectory = scala.reflect.io.VirtualDirectory
type VirtualFile = scala.reflect.io.VirtualFile
- val ZipArchive = scala.reflect.io.ZipArchive
type ZipArchive = scala.reflect.io.ZipArchive
-
- implicit def postfixOps = scala.language.postfixOps // make all postfix ops in this package compile without warning
type JManifest = java.util.jar.Manifest
type JFile = java.io.File
@@ -39,23 +34,11 @@ package object io {
def runnable(body: => Unit): Runnable = new Runnable { override def run() = body }
def callable[T](body: => T): Callable[T] = new Callable[T] { override def call() = body }
def spawn[T](body: => T): Future[T] = daemonThreadPool submit callable(body)
- def submit(runnable: Runnable) = daemonThreadPool submit runnable
- // Create, start, and return a daemon thread
- def daemonize(body: => Unit): Thread = newThread(_ setDaemon true)(body)
def newThread(f: Thread => Unit)(body: => Unit): Thread = {
val thread = new Thread(runnable(body))
f(thread)
thread.start
thread
}
-
- // Set a timer to execute the given code.
- def timer(seconds: Int)(body: => Unit): Timer = {
- val alarm = new Timer(true) // daemon
- val tt = new TimerTask { def run() = body }
-
- alarm.schedule(tt, seconds * 1000)
- alarm
- }
}
diff --git a/src/compiler/scala/tools/nsc/javac/JavaParsers.scala b/src/compiler/scala/tools/nsc/javac/JavaParsers.scala
index 050f7a8f95..bb82cfb827 100644
--- a/src/compiler/scala/tools/nsc/javac/JavaParsers.scala
+++ b/src/compiler/scala/tools/nsc/javac/JavaParsers.scala
@@ -35,7 +35,6 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners {
abstract class JavaParser extends ParserCommon {
val in: JavaScanner
- protected def posToReport: Int = in.currentPos
def freshName(prefix : String): Name
protected implicit def i2p(offset : Int) : Position
private implicit def p2i(pos : Position): Int = if (pos.isDefined) pos.point else -1
@@ -94,11 +93,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners {
if (skipIt)
skip()
}
- def warning(msg: String) : Unit = warning(in.currentPos, msg)
-
def errorTypeTree = TypeTree().setType(ErrorType) setPos in.currentPos
- def errorTermTree = Literal(Constant(null)) setPos in.currentPos
- def errorPatternTree = blankExpr setPos in.currentPos
// --------- tree building -----------------------------
@@ -130,7 +125,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners {
def makeSyntheticParam(count: Int, tpt: Tree): ValDef =
makeParam(nme.syntheticParamName(count), tpt)
def makeParam(name: String, tpt: Tree): ValDef =
- makeParam(newTypeName(name), tpt)
+ makeParam(name: TermName, tpt)
def makeParam(name: TermName, tpt: Tree): ValDef =
ValDef(Modifiers(Flags.JAVA | Flags.PARAM), name, tpt, EmptyTree)
@@ -178,11 +173,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners {
def accept(token: Int): Int = {
val pos = in.currentPos
if (in.token != token) {
- val posToReport =
- //if (in.currentPos.line(unit.source).get(0) > in.lastPos.line(unit.source).get(0))
- // in.lastPos
- //else
- in.currentPos
+ val posToReport = in.currentPos
val msg =
JavaScannerConfiguration.token2string(token) + " expected but " +
JavaScannerConfiguration.token2string(in.token) + " found."
@@ -348,46 +339,10 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners {
/** Annotation ::= TypeName [`(` AnnotationArgument {`,` AnnotationArgument} `)`]
*/
def annotation() {
- val pos = in.currentPos
- var t = qualId()
+ qualId()
if (in.token == LPAREN) { skipAhead(); accept(RPAREN) }
else if (in.token == LBRACE) { skipAhead(); accept(RBRACE) }
}
-/*
- def annotationArg() = {
- val pos = in.token
- if (in.token == IDENTIFIER && in.lookaheadToken == ASSIGN) {
- val name = ident()
- accept(ASSIGN)
- atPos(pos) {
- ValDef(Modifiers(Flags.JAVA), name, TypeTree(), elementValue())
- }
- } else {
- elementValue()
- }
- }
-
- def elementValue(): Tree =
- if (in.token == AT) annotation()
- else if (in.token == LBRACE) elementValueArrayInitializer()
- else expression1()
-
- def elementValueArrayInitializer() = {
- accept(LBRACE)
- val buf = new ListBuffer[Tree]
- def loop() =
- if (in.token != RBRACE) {
- buf += elementValue()
- if (in.token == COMMA) {
- in.nextToken
- loop()
- }
- }
- loop()
- accept(RBRACE)
- buf.toList
- }
- */
def modifiers(inInterface: Boolean): Modifiers = {
var flags: Long = Flags.JAVA
@@ -493,7 +448,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners {
AppliedTypeTree(scalaDot(tpnme.JAVA_REPEATED_PARAM_CLASS_NAME), List(t))
}
}
- varDecl(in.currentPos, Modifiers(Flags.JAVA | Flags.PARAM), t, ident())
+ varDecl(in.currentPos, Modifiers(Flags.JAVA | Flags.PARAM), t, ident().toTermName)
}
def optThrows() {
@@ -587,7 +542,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners {
* these potential definitions are real or not.
*/
def fieldDecls(pos: Position, mods: Modifiers, tpt: Tree, name: Name): List[Tree] = {
- val buf = ListBuffer[Tree](varDecl(pos, mods, tpt, name))
+ val buf = ListBuffer[Tree](varDecl(pos, mods, tpt, name.toTermName))
val maybe = new ListBuffer[Tree] // potential variable definitions.
while (in.token == COMMA) {
in.nextToken
@@ -595,10 +550,10 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners {
val name = ident()
if (in.token == ASSIGN || in.token == SEMI) { // ... followed by a `=` or `;`, we know it's a real variable definition
buf ++= maybe
- buf += varDecl(in.currentPos, mods, tpt.duplicate, name)
+ buf += varDecl(in.currentPos, mods, tpt.duplicate, name.toTermName)
maybe.clear()
} else if (in.token == COMMA) { // ... if there's a comma after the ident, it could be a real vardef or not.
- maybe += varDecl(in.currentPos, mods, tpt.duplicate, name)
+ maybe += varDecl(in.currentPos, mods, tpt.duplicate, name.toTermName)
} else { // ... if there's something else we were still in the initializer of the
// previous var def; skip to next comma or semicolon.
skipTo(COMMA, SEMI)
@@ -875,7 +830,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners {
// The STABLE flag is to signal to namer that this was read from a
// java enum, and so should be given a Constant type (thereby making
// it usable in annotations.)
- ValDef(Modifiers(Flags.STABLE | Flags.JAVA | Flags.STATIC), name, enumType, blankExpr)
+ ValDef(Modifiers(Flags.STABLE | Flags.JAVA | Flags.STATIC), name.toTermName, enumType, blankExpr)
}
}
diff --git a/src/compiler/scala/tools/nsc/javac/JavaScanners.scala b/src/compiler/scala/tools/nsc/javac/JavaScanners.scala
index e230585a8b..84eee36f18 100644
--- a/src/compiler/scala/tools/nsc/javac/JavaScanners.scala
+++ b/src/compiler/scala/tools/nsc/javac/JavaScanners.scala
@@ -57,23 +57,14 @@ trait JavaScanners extends ast.parser.ScannersCommon {
/** ...
*/
abstract class AbstractJavaScanner extends AbstractJavaTokenData {
- implicit def p2g(pos: Position): ScanPosition
implicit def g2p(pos: ScanPosition): Position
- /** the last error position
- */
- var errpos: ScanPosition
- var lastPos: ScanPosition
- def skipToken: ScanPosition
def nextToken(): Unit
def next: AbstractJavaTokenData
def intVal(negated: Boolean): Long
def floatVal(negated: Boolean): Double
def intVal: Long = intVal(false)
def floatVal: Double = floatVal(false)
- //def token2string(token : Int) : String = configuration.token2string(token)
- /** return recent scala doc, if any */
- def flushDoc: DocComment
def currentPos: Position
}
@@ -227,17 +218,9 @@ trait JavaScanners extends ast.parser.ScannersCommon {
abstract class JavaScanner extends AbstractJavaScanner with JavaTokenData with Cloneable with ScannerCommon {
override def intVal = super.intVal// todo: needed?
override def floatVal = super.floatVal
- override var errpos: Int = NoPos
def currentPos: Position = g2p(pos - 1)
-
var in: JavaCharArrayReader = _
- def dup: JavaScanner = {
- val dup = clone().asInstanceOf[JavaScanner]
- dup.in = in.dup
- dup
- }
-
/** character buffer for literals
*/
val cbuf = new StringBuilder()
@@ -256,12 +239,6 @@ trait JavaScanners extends ast.parser.ScannersCommon {
*/
var docBuffer: StringBuilder = null
- def flushDoc: DocComment = {
- val ret = if (docBuffer != null) DocComment(docBuffer.toString, NoPosition) else null
- docBuffer = null
- ret
- }
-
/** add the given character to the documentation buffer
*/
protected def putDocChar(c: Char) {
@@ -277,13 +254,6 @@ trait JavaScanners extends ast.parser.ScannersCommon {
// Get next token ------------------------------------------------------------
- /** read next token and return last position
- */
- def skipToken: Int = {
- val p = pos; nextToken
- p - 1
- }
-
def nextToken() {
if (next.token == EMPTY) {
fetchToken()
@@ -308,7 +278,6 @@ trait JavaScanners extends ast.parser.ScannersCommon {
private def fetchToken() {
if (token == EOF) return
lastPos = in.cpos - 1
- //var index = bp
while (true) {
in.ch match {
case ' ' | '\t' | CR | LF | FF =>
@@ -868,7 +837,6 @@ trait JavaScanners extends ast.parser.ScannersCommon {
def syntaxError(pos: Int, msg: String) {
error(pos, msg)
token = ERROR
- errpos = pos
}
/** generate an error at the current token position
@@ -879,7 +847,6 @@ trait JavaScanners extends ast.parser.ScannersCommon {
def incompleteInputError(msg: String) {
incompleteInputError(pos, msg)
token = EOF
- errpos = pos
}
override def toString() = token match {
@@ -913,16 +880,12 @@ trait JavaScanners extends ast.parser.ScannersCommon {
}
}
- /** ...
- */
class JavaUnitScanner(unit: CompilationUnit) extends JavaScanner {
in = new JavaCharArrayReader(unit.source.content, !settings.nouescape.value, syntaxError)
init
- def warning(pos: Int, msg: String) = unit.warning(pos, msg)
def error (pos: Int, msg: String) = unit. error(pos, msg)
def incompleteInputError(pos: Int, msg: String) = unit.incompleteInputError(pos, msg)
def deprecationWarning(pos: Int, msg: String) = unit.deprecationWarning(pos, msg)
- implicit def p2g(pos: Position): Int = if (pos.isDefined) pos.point else -1
implicit def g2p(pos: Int): Position = new OffsetPosition(unit.source, pos)
}
}
diff --git a/src/compiler/scala/tools/nsc/javac/JavaTokens.scala b/src/compiler/scala/tools/nsc/javac/JavaTokens.scala
index a562de291d..953a3c6d82 100644
--- a/src/compiler/scala/tools/nsc/javac/JavaTokens.scala
+++ b/src/compiler/scala/tools/nsc/javac/JavaTokens.scala
@@ -68,9 +68,6 @@ object JavaTokens extends ast.parser.Tokens {
final val VOLATILE = 68
final val WHILE = 69
- def isKeyword(code : Int) =
- code >= ABSTRACT && code <= WHILE
-
/** special symbols */
final val COMMA = 70
final val SEMI = 71
@@ -115,9 +112,6 @@ object JavaTokens extends ast.parser.Tokens {
final val GTGTEQ = 113
final val GTGTGTEQ = 114
- def isSymbol(code : Int) =
- code >= COMMA && code <= GTGTGTEQ
-
/** parenthesis */
final val LPAREN = 115
final val RPAREN = 116
diff --git a/src/compiler/scala/tools/nsc/matching/MatchSupport.scala b/src/compiler/scala/tools/nsc/matching/MatchSupport.scala
index 5ca9fd5062..3c26997cfe 100644
--- a/src/compiler/scala/tools/nsc/matching/MatchSupport.scala
+++ b/src/compiler/scala/tools/nsc/matching/MatchSupport.scala
@@ -6,9 +6,6 @@
package scala.tools.nsc
package matching
-import transform.ExplicitOuter
-import ast.{ Printers, Trees }
-import java.io.{ StringWriter, PrintWriter }
import scala.annotation.elidable
import scala.language.postfixOps
@@ -25,9 +22,6 @@ trait MatchSupport extends ast.TreeDSL { self: ParallelMatching =>
def impossible: Nothing = abort("this never happens")
- def treeCollect[T](tree: Tree, pf: PartialFunction[Tree, T]): List[T] =
- tree filter (pf isDefinedAt _) map (x => pf(x))
-
object Types {
import definitions._
@@ -39,24 +33,12 @@ trait MatchSupport extends ast.TreeDSL { self: ParallelMatching =>
// These tests for final classes can inspect the typeSymbol
private def is(s: Symbol) = tpe.typeSymbol eq s
- def isByte = is(ByteClass)
- def isShort = is(ShortClass)
def isInt = is(IntClass)
- def isChar = is(CharClass)
- def isBoolean = is(BooleanClass)
def isNothing = is(NothingClass)
- def isArray = is(ArrayClass)
}
}
object Debug {
- def typeToString(t: Type): String = t match {
- case NoType => "x"
- case x => x.toString
- }
- def symbolToString(s: Symbol): String = s match {
- case x => x.toString
- }
def treeToString(t: Tree): String = treeInfo.unbind(t) match {
case EmptyTree => "?"
case WILD() => "_"
@@ -69,10 +51,6 @@ trait MatchSupport extends ast.TreeDSL { self: ParallelMatching =>
// Formatting for some error messages
private val NPAD = 15
def pad(s: String): String = "%%%ds" format (NPAD-1) format s
- def pad(s: Any): String = pad(s match {
- case x: Tree => treeToString(x)
- case x => x.toString
- })
// pretty print for debugging
def pp(x: Any): String = pp(x, false)
@@ -120,7 +98,6 @@ trait MatchSupport extends ast.TreeDSL { self: ParallelMatching =>
else x
}
- def indent(s: Any) = s.toString() split "\n" map (" " + _) mkString "\n"
def indentAll(s: Seq[Any]) = s map (" " + _.toString() + "\n") mkString
}
diff --git a/src/compiler/scala/tools/nsc/matching/Matrix.scala b/src/compiler/scala/tools/nsc/matching/Matrix.scala
index daefe4c545..ba966acf34 100644
--- a/src/compiler/scala/tools/nsc/matching/Matrix.scala
+++ b/src/compiler/scala/tools/nsc/matching/Matrix.scala
@@ -140,7 +140,6 @@ trait Matrix extends MatrixAdditions {
cases: List[CaseDef],
default: Tree
) {
- def tvars = roots map (_.lhs)
def valDefs = roots map (_.valDef)
override def toString() = "MatrixInit(roots = %s, %d cases)".format(pp(roots), cases.size)
}
@@ -151,27 +150,12 @@ trait Matrix extends MatrixAdditions {
object PatternVarGroup {
def apply(xs: PatternVar*) = new PatternVarGroup(xs.toList)
def apply(xs: List[PatternVar]) = new PatternVarGroup(xs)
-
- // XXX - transitional
- def fromBindings(vlist: List[Binding], freeVars: List[Symbol] = Nil) = {
- def vmap(v: Symbol): Option[Binding] = vlist find (_.pvar eq v)
- val info =
- if (freeVars.isEmpty) vlist
- else (freeVars map vmap).flatten
-
- val xs =
- for (Binding(lhs, rhs) <- info) yield
- new PatternVar(lhs, Ident(rhs) setType lhs.tpe, !(rhs hasFlag NO_EXHAUSTIVE))
-
- new PatternVarGroup(xs)
- }
}
val emptyPatternVarGroup = PatternVarGroup()
class PatternVarGroup(val pvs: List[PatternVar]) {
def syms = pvs map (_.sym)
def valDefs = pvs map (_.valDef)
- def idents = pvs map (_.ident)
def extractIndex(index: Int): (PatternVar, PatternVarGroup) = {
val (t, ts) = self.extractIndex(pvs, index)
@@ -180,16 +164,11 @@ trait Matrix extends MatrixAdditions {
def isEmpty = pvs.isEmpty
def size = pvs.size
- def head = pvs.head
- def ::(t: PatternVar) = PatternVarGroup(t :: pvs)
def :::(ts: List[PatternVar]) = PatternVarGroup(ts ::: pvs)
- def ++(other: PatternVarGroup) = PatternVarGroup(pvs ::: other.pvs)
def apply(i: Int) = pvs(i)
def zipWithIndex = pvs.zipWithIndex
def indices = pvs.indices
- def map[T](f: PatternVar => T) = pvs map f
- def filter(p: PatternVar => Boolean) = PatternVarGroup(pvs filter p)
override def toString() = pp(pvs)
}
@@ -237,17 +216,11 @@ trait Matrix extends MatrixAdditions {
tracing("create")(new PatternVar(lhs, rhs, checked))
}
- def createLazy(tpe: Type, f: Symbol => Tree, checked: Boolean) = {
- val lhs = newVar(owner.pos, tpe, Flags.LAZY :: flags(checked))
- val rhs = f(lhs)
-
- tracing("createLazy")(new PatternVar(lhs, rhs, checked))
- }
private def newVar(
pos: Position,
tpe: Type,
- flags: List[Long] = Nil,
+ flags: List[Long],
name: TermName = null): Symbol =
{
val n = if (name == null) cunit.freshTermName("temp") else name
diff --git a/src/compiler/scala/tools/nsc/matching/MatrixAdditions.scala b/src/compiler/scala/tools/nsc/matching/MatrixAdditions.scala
index 7220253003..b1ca6e7b5a 100644
--- a/src/compiler/scala/tools/nsc/matching/MatrixAdditions.scala
+++ b/src/compiler/scala/tools/nsc/matching/MatrixAdditions.scala
@@ -7,7 +7,6 @@ package scala.tools.nsc
package matching
import transform.ExplicitOuter
-import PartialFunction._
/** Traits which are mixed into MatchMatrix, but separated out as
* (somewhat) independent components to keep them on the sidelines.
@@ -17,7 +16,6 @@ trait MatrixAdditions extends ast.TreeDSL {
import global.{ typer => _, _ }
import symtab.Flags
- import CODE._
import Debug._
import treeInfo._
import definitions.{ isPrimitiveValueClass }
@@ -190,4 +188,4 @@ trait MatrixAdditions extends ast.TreeDSL {
}
}
}
-} \ No newline at end of file
+}
diff --git a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala
index 9d01e73063..b5e25f3809 100644
--- a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala
+++ b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala
@@ -9,11 +9,8 @@ package matching
import PartialFunction._
import scala.collection.{ mutable }
-import scala.reflect.internal.util.Position
import transform.ExplicitOuter
-import symtab.Flags
import mutable.ListBuffer
-import scala.annotation.elidable
import scala.language.postfixOps
trait ParallelMatching extends ast.TreeDSL
@@ -26,7 +23,7 @@ trait ParallelMatching extends ast.TreeDSL
import global.{ typer => _, _ }
import definitions.{
- AnyRefClass, IntClass, BooleanClass, SomeClass, OptionClass,
+ IntClass, BooleanClass, SomeClass, OptionClass,
getProductArgs, productProj, Object_eq, Any_asInstanceOf
}
import CODE._
@@ -129,7 +126,7 @@ trait ParallelMatching extends ast.TreeDSL
// for propagating "unchecked" to synthetic vars
def isChecked = !(sym hasFlag NO_EXHAUSTIVE)
- def flags: List[Long] = List(NO_EXHAUSTIVE) filter (sym hasFlag _)
+ // def flags: List[Long] = List(NO_EXHAUSTIVE) filter (sym hasFlag _)
// this is probably where this actually belongs
def createVar(tpe: Type, f: Symbol => Tree) = context.createVar(tpe, f, isChecked)
@@ -173,7 +170,7 @@ trait ParallelMatching extends ast.TreeDSL
case class PatternMatch(scrut: Scrutinee, ps: List[Pattern]) {
def head = ps.head
def tail = ps.tail
- def size = ps.length
+ // def size = ps.length
def headType = head.necessaryType
private val dummyCount = if (head.isCaseClass) headType.typeSymbol.caseFieldAccessors.length else 0
@@ -579,7 +576,7 @@ trait ParallelMatching extends ast.TreeDSL
(_ys.toList, _ns.toList)
}
- val moreSpecific = yeses map (_.moreSpecific)
+ // val moreSpecific = yeses map (_.moreSpecific)
val subsumed = yeses map (x => (x.bx, x.subsumed))
val remaining = noes map (x => (x.bx, x.remaining))
diff --git a/src/compiler/scala/tools/nsc/matching/PatternBindings.scala b/src/compiler/scala/tools/nsc/matching/PatternBindings.scala
index 7b2fcf0e9b..c6fa6f6ba0 100644
--- a/src/compiler/scala/tools/nsc/matching/PatternBindings.scala
+++ b/src/compiler/scala/tools/nsc/matching/PatternBindings.scala
@@ -7,7 +7,6 @@ package scala.tools.nsc
package matching
import transform.ExplicitOuter
-import PartialFunction._
import scala.language.postfixOps
trait PatternBindings extends ast.TreeDSL
@@ -17,7 +16,6 @@ trait PatternBindings extends ast.TreeDSL
import global.{ typer => _, _ }
import definitions.{ EqualsPatternClass }
import CODE._
- import Debug._
/** EqualsPattern **/
def isEquals(tpe: Type) = tpe.typeSymbol == EqualsPatternClass
@@ -61,10 +59,6 @@ trait PatternBindings extends ast.TreeDSL
trait PatternBindingLogic {
self: Pattern =>
- // This is for traversing the pattern tree - pattern types which might have
- // bound variables beneath them return a list of said patterns for flatMapping.
- def subpatternsForVars: List[Pattern] = Nil
-
// The outermost Bind(x1, Bind(x2, ...)) surrounding the tree.
private var _boundTree: Tree = tree
def boundTree = _boundTree
@@ -108,8 +102,6 @@ trait PatternBindings extends ast.TreeDSL
case b @ Bind(_, pat) => b.symbol :: strip(pat)
case _ => Nil
}
- private def deepstrip(t: Tree): List[Symbol] =
- treeCollect(t, { case x: Bind => x.symbol })
}
case class Binding(pvar: Symbol, tvar: Symbol) {
@@ -117,9 +109,6 @@ trait PatternBindings extends ast.TreeDSL
}
class Bindings(private val vlist: List[Binding]) {
- // if (!vlist.isEmpty)
- // traceCategory("Bindings", this.toString)
-
def get() = vlist
def toMap = vlist map (x => (x.pvar, x.tvar)) toMap
diff --git a/src/compiler/scala/tools/nsc/matching/Patterns.scala b/src/compiler/scala/tools/nsc/matching/Patterns.scala
index 99b72fa26e..df536da108 100644
--- a/src/compiler/scala/tools/nsc/matching/Patterns.scala
+++ b/src/compiler/scala/tools/nsc/matching/Patterns.scala
@@ -6,7 +6,6 @@
package scala.tools.nsc
package matching
-import symtab.Flags
import PartialFunction._
/** Patterns are wrappers for Trees with enhanced semantics.
@@ -33,9 +32,6 @@ trait Patterns extends ast.TreeDSL {
// An empty pattern
def NoPattern = WildcardPattern()
- // The constant null pattern
- def NullPattern = LiteralPattern(NULL)
-
// The Nil pattern
def NilPattern = Pattern(gen.mkNil)
@@ -61,7 +57,6 @@ trait Patterns extends ast.TreeDSL {
override def covers(sym: Symbol) = newMatchesPattern(sym, tpt.tpe)
override def sufficientType = tpt.tpe
- override def subpatternsForVars: List[Pattern] = List(Pattern(expr))
override def simplify(pv: PatternVar) = Pattern(expr) match {
case ExtractorPattern(ua) if pv.sym.tpe <:< tpt.tpe => this rebindTo expr
case _ => this
@@ -141,10 +136,6 @@ trait Patterns extends ast.TreeDSL {
require(fn.isType && this.isCaseClass, "tree: " + tree + " fn: " + fn)
def name = tpe.typeSymbol.name
def cleanName = tpe.typeSymbol.decodedName
- def hasPrefix = tpe.prefix.prefixString != ""
- def prefixedName =
- if (hasPrefix) "%s.%s".format(tpe.prefix.prefixString, cleanName)
- else cleanName
private def isColonColon = cleanName == "::"
@@ -189,13 +180,6 @@ trait Patterns extends ast.TreeDSL {
private lazy val packedType = global.typer.computeType(tpt, tpt.tpe)
private lazy val consRef = appliedType(ConsClass, packedType)
private lazy val listRef = appliedType(ListClass, packedType)
- private lazy val seqRef = appliedType(SeqClass, packedType)
-
- private def thisSeqRef = {
- val tc = (tree.tpe baseType SeqClass).typeConstructor
- if (tc.typeParams.size == 1) appliedType(tc, List(packedType))
- else seqRef
- }
// Fold a list into a well-typed x :: y :: etc :: tree.
private def listFolder(hd: Tree, tl: Tree): Tree = unbind(hd) match {
@@ -230,15 +214,13 @@ trait Patterns extends ast.TreeDSL {
// 8.1.8 (b) (literal ArrayValues)
case class SequencePattern(tree: ArrayValue) extends Pattern with SequenceLikePattern {
- lazy val ArrayValue(elemtpt, elems) = tree
+ lazy val ArrayValue(_, elems) = tree
- override def subpatternsForVars: List[Pattern] = elemPatterns
override def description = "Seq(%s)".format(elemPatterns mkString ", ")
}
// 8.1.8 (c)
case class StarPattern(tree: Star) extends Pattern {
- lazy val Star(elem) = tree
override def description = "_*"
}
// XXX temporary?
@@ -392,15 +374,7 @@ trait Patterns extends ast.TreeDSL {
// Covers if the symbol matches the unapply method's argument type,
// and the return type of the unapply is Some.
override def covers(sym: Symbol) = newMatchesPattern(sym, arg.tpe)
-
- // TODO: for alwaysCovers:
- // fn.tpe.finalResultType.typeSymbol == SomeClass
-
override def necessaryType = arg.tpe
- override def subpatternsForVars = args match {
- case List(ArrayValue(elemtpe, elems)) => toPats(elems)
- case _ => toPats(args)
- }
def resTypes = analyzer.unapplyTypeList(unfn.symbol, unfn.tpe, args.length)
def resTypesString = resTypes match {
@@ -411,13 +385,7 @@ trait Patterns extends ast.TreeDSL {
sealed trait ApplyPattern extends Pattern {
lazy val Apply(fn, args) = tree
- override def subpatternsForVars: List[Pattern] = toPats(args)
- override def dummies =
- if (!this.isCaseClass) Nil
- else emptyPatterns(sufficientType.typeSymbol.caseFieldAccessors.size)
-
- def isConstructorPattern = fn.isType
override def covers(sym: Symbol) = newMatchesPattern(sym, fn.tpe)
}
@@ -427,9 +395,6 @@ trait Patterns extends ast.TreeDSL {
// returns either a simplification of this pattern or identity.
def simplify(pv: PatternVar): Pattern = this
- // the right number of dummies for this pattern
- def dummies: List[Pattern] = Nil
-
// Is this a default pattern (untyped "_" or an EmptyTree inserted by the matcher)
def isDefault = false
@@ -459,14 +424,8 @@ trait Patterns extends ast.TreeDSL {
def isModule = sym.isModule || tpe.termSymbol.isModule
def isCaseClass = tpe.typeSymbol.isCase
def isObject = (sym != null) && (sym != NoSymbol) && tpe.prefix.isStable // XXX not entire logic
-
def hasStar = false
- def setType(tpe: Type): this.type = {
- tree setType tpe
- this
- }
-
def equalsCheck =
tracing("equalsCheck")(
if (sym.isValue) singleType(NoPrefix, sym)
@@ -483,7 +442,6 @@ trait Patterns extends ast.TreeDSL {
final override def toString = description
- def toTypeString() = "%s <: x <: %s".format(necessaryType, sufficientType)
def kindString = ""
}
diff --git a/src/compiler/scala/tools/nsc/plugins/Plugin.scala b/src/compiler/scala/tools/nsc/plugins/Plugin.scala
index 2050ce7ffd..093f8285e1 100644
--- a/src/compiler/scala/tools/nsc/plugins/Plugin.scala
+++ b/src/compiler/scala/tools/nsc/plugins/Plugin.scala
@@ -6,13 +6,10 @@
package scala.tools.nsc
package plugins
-import io.{ File, Path, Jar }
+import io.{ Path, Jar }
import java.net.URLClassLoader
import java.util.jar.JarFile
import java.util.zip.ZipException
-
-import scala.collection.mutable
-import mutable.ListBuffer
import scala.xml.XML
/** Information about a plugin loaded from a jar file.
@@ -74,7 +71,7 @@ object Plugin {
}
/** Try to load a plugin description from the specified
- * file, returning <code>None</code> if it does not work.
+ * file, returning `None` if it does not work.
*/
private def loadDescription(jarfile: Path): Option[PluginDescription] =
// XXX Return to this once we have some ARM support
diff --git a/src/compiler/scala/tools/nsc/plugins/PluginDescription.scala b/src/compiler/scala/tools/nsc/plugins/PluginDescription.scala
index bd567400fb..f77123ba11 100644
--- a/src/compiler/scala/tools/nsc/plugins/PluginDescription.scala
+++ b/src/compiler/scala/tools/nsc/plugins/PluginDescription.scala
@@ -6,7 +6,7 @@
package scala.tools.nsc
package plugins
-import scala.xml.{Node,NodeSeq}
+import scala.xml.Node
/** A description of a compiler plugin, suitable for serialization
* to XML for inclusion in the plugin's .jar file.
@@ -26,7 +26,7 @@ abstract class PluginDescription {
val classname: String
/** An XML representation of this description. It can be
- * read back using <code>PluginDescription.fromXML</code>.
+ * read back using `PluginDescription.fromXML`.
* It should be stored inside the jar archive file.
*/
def toXML: Node = {
diff --git a/src/compiler/scala/tools/nsc/reporters/AbstractReporter.scala b/src/compiler/scala/tools/nsc/reporters/AbstractReporter.scala
index c7ee11dec0..025fc8e068 100644
--- a/src/compiler/scala/tools/nsc/reporters/AbstractReporter.scala
+++ b/src/compiler/scala/tools/nsc/reporters/AbstractReporter.scala
@@ -29,11 +29,7 @@ abstract class AbstractReporter extends Reporter {
private def noWarnings = settings.nowarnings.value
private def isPromptSet = settings.prompt.value
- protected def info0(pos: Position, msg: String, _severity: Severity, force: Boolean) {
- val severity =
- if (settings.fatalWarnings.value && _severity == WARNING) ERROR
- else _severity
-
+ protected def info0(pos: Position, msg: String, severity: Severity, force: Boolean) {
if (severity == INFO) {
if (isVerbose || force) {
severity.count += 1
diff --git a/src/compiler/scala/tools/nsc/reporters/ConsoleReporter.scala b/src/compiler/scala/tools/nsc/reporters/ConsoleReporter.scala
index e847fb5b86..bda195f9d3 100644
--- a/src/compiler/scala/tools/nsc/reporters/ConsoleReporter.scala
+++ b/src/compiler/scala/tools/nsc/reporters/ConsoleReporter.scala
@@ -34,9 +34,6 @@ class ConsoleReporter(val settings: Settings, reader: BufferedReader, writer: Pr
}
/** Returns the number of errors issued totally as a string.
- *
- * @param severity ...
- * @return ...
*/
private def getCountString(severity: Severity): String =
StringOps.countElementsAsString((severity).count, label(severity))
@@ -52,17 +49,12 @@ class ConsoleReporter(val settings: Settings, reader: BufferedReader, writer: Pr
printMessage(pos, clabel(severity) + msg)
}
- /**
- * @param pos ...
- */
def printSourceLine(pos: Position) {
printMessage(pos.lineContent.stripLineEnd)
printColumnMarker(pos)
}
/** Prints the column marker of the given position.
- *
- * @param pos ...
*/
def printColumnMarker(pos: Position) =
if (pos.isDefined) { printMessage(" " * (pos.column - 1) + "^") }
@@ -94,6 +86,5 @@ class ConsoleReporter(val settings: Settings, reader: BufferedReader, writer: Pr
}
}
- private def abort(msg: String) = throw new Error(msg)
override def flush() { writer.flush() }
}
diff --git a/src/compiler/scala/tools/nsc/reporters/Reporter.scala b/src/compiler/scala/tools/nsc/reporters/Reporter.scala
index 8871ae6555..817ec47ab3 100644
--- a/src/compiler/scala/tools/nsc/reporters/Reporter.scala
+++ b/src/compiler/scala/tools/nsc/reporters/Reporter.scala
@@ -7,7 +7,6 @@ package scala.tools.nsc
package reporters
import scala.reflect.internal.util._
-import scala.reflect.internal.util.StringOps._
/**
* This interface provides methods to issue information, warning and
diff --git a/src/compiler/scala/tools/nsc/scratchpad/Mixer.scala b/src/compiler/scala/tools/nsc/scratchpad/Mixer.scala
index 10e9982594..3aecc06b1e 100644
--- a/src/compiler/scala/tools/nsc/scratchpad/Mixer.scala
+++ b/src/compiler/scala/tools/nsc/scratchpad/Mixer.scala
@@ -2,9 +2,6 @@ package scala.tools.nsc.scratchpad
import java.io.{FileInputStream, InputStreamReader, IOException}
-import scala.runtime.ScalaRunTime.stringOf
-import java.lang.reflect.InvocationTargetException
-import scala.reflect.runtime.ReflectionUtils._
import scala.collection.mutable.ArrayBuffer
@deprecated("SI-6458: Instrumentation logic will be moved out of the compiler.","2.10.0")
diff --git a/src/compiler/scala/tools/nsc/scratchpad/SourceInserter.scala b/src/compiler/scala/tools/nsc/scratchpad/SourceInserter.scala
index 01dccd7521..61c1717fea 100644
--- a/src/compiler/scala/tools/nsc/scratchpad/SourceInserter.scala
+++ b/src/compiler/scala/tools/nsc/scratchpad/SourceInserter.scala
@@ -1,8 +1,6 @@
package scala.tools.nsc
package scratchpad
-import java.io.Writer
-import scala.reflect.internal.util.SourceFile
import scala.reflect.internal.Chars._
@deprecated("SI-6458: Instrumentation logic will be moved out of the compiler.","2.10.0")
diff --git a/src/compiler/scala/tools/nsc/settings/AbsSettings.scala b/src/compiler/scala/tools/nsc/settings/AbsSettings.scala
index adabeb02a3..4727e6d867 100644
--- a/src/compiler/scala/tools/nsc/settings/AbsSettings.scala
+++ b/src/compiler/scala/tools/nsc/settings/AbsSettings.scala
@@ -47,8 +47,6 @@ trait AbsSettings extends scala.reflect.internal.settings.AbsSettings {
}
})
- implicit lazy val SettingOrdering: Ordering[Setting] = Ordering.ordered
-
trait AbsSetting extends Ordered[Setting] with AbsSettingValue {
def name: String
def helpDescription: String
@@ -83,14 +81,6 @@ trait AbsSettings extends scala.reflect.internal.settings.AbsSettings {
this
}
- /** If the appearance of the setting should halt argument processing. */
- private var isTerminatorSetting = false
- def shouldStopProcessing = isTerminatorSetting
- def stopProcessing(): this.type = {
- isTerminatorSetting = true
- this
- }
-
/** Issue error and return */
def errorAndValue[T](msg: String, x: T): T = { errorFn(msg) ; x }
@@ -110,6 +100,7 @@ trait AbsSettings extends scala.reflect.internal.settings.AbsSettings {
/** Attempt to set from a properties file style property value.
* Currently used by Eclipse SDT only.
+ * !!! Needs test.
*/
def tryToSetFromPropertyValue(s: String): Unit = tryToSet(s :: Nil)
@@ -133,7 +124,7 @@ trait AbsSettings extends scala.reflect.internal.settings.AbsSettings {
case _ => false
}
override def hashCode() = name.hashCode + value.hashCode
- override def toString() = name + " = " + value
+ override def toString() = name + " = " + (if (value == "") "\"\"" else value)
}
trait InternalSetting extends AbsSetting {
diff --git a/src/compiler/scala/tools/nsc/settings/AdvancedScalaSettings.scala b/src/compiler/scala/tools/nsc/settings/AdvancedScalaSettings.scala
deleted file mode 100644
index 0bec113743..0000000000
--- a/src/compiler/scala/tools/nsc/settings/AdvancedScalaSettings.scala
+++ /dev/null
@@ -1,77 +0,0 @@
-/* NSC -- new Scala compiler
- * Copyright 2005-2013 LAMP/EPFL
- * @author Paul Phillips
- */
-
-package scala.tools.nsc
-package settings
-
-trait AdvancedScalaSettings {
- self: AbsScalaSettings =>
-
- abstract class X extends SettingGroup("-X") {
- val assemextdirs: StringSetting
- val assemname: StringSetting
- val assempath: StringSetting
- val checkinit: BooleanSetting
- val disableassertions: BooleanSetting
- val elidebelow: IntSetting
- val experimental: BooleanSetting
- val future: BooleanSetting
- val generatephasegraph: StringSetting
- val logimplicits: BooleanSetting
- val mainClass: StringSetting
- val migration: BooleanSetting
- val noforwarders: BooleanSetting
- val nojline: BooleanSetting
- val nouescape: BooleanSetting
- val plugin: MultiStringSetting
- val plugindisable: MultiStringSetting
- val pluginlist: BooleanSetting
- val pluginrequire: MultiStringSetting
- val pluginsdir: StringSetting
- val print: PhasesSetting
- val printicode: BooleanSetting
- val printpos: BooleanSetting
- val printtypes: BooleanSetting
- val prompt: BooleanSetting
- val resident: BooleanSetting
- val script: StringSetting
- val showclass: StringSetting
- val showobject: StringSetting
- val showphases: BooleanSetting
- val sourcedir: StringSetting
- val sourcereader: StringSetting
- }
- // def Xexperimental = X.experimental
- // def Xmigration28 = X.migration
- // def Xnojline = X.nojline
- // def Xprint = X.print
- // def Xprintpos = X.printpos
- // def Xshowcls = X.showclass
- // def Xshowobj = X.showobject
- // def assemextdirs = X.assemextdirs
- // def assemname = X.assemname
- // def assemrefs = X.assempath
- // def checkInit = X.checkinit
- // def disable = X.plugindisable
- // def elideLevel = X.elidelevel
- // def future = X.future
- // def genPhaseGraph = X.generatephasegraph
- // def logimplicits = X.logimplicits
- // def noForwarders = X.noforwarders
- // def noassertions = X.disableassertions
- // def nouescape = X.nouescape
- // def plugin = X.plugin
- // def pluginsDir = X.pluginsdir
- // def printtypes = X.printtypes
- // def prompt = X.prompt
- // def require = X.require
- // def resident = X.resident
- // def script = X.script
- // def showPhases = X.showphases
- // def showPlugins = X.pluginlist
- // def sourceReader = X.sourcereader
- // def sourcedir = X.sourcedir
- // def writeICode = X.printicode
-} \ No newline at end of file
diff --git a/src/compiler/scala/tools/nsc/settings/AestheticSettings.scala b/src/compiler/scala/tools/nsc/settings/AestheticSettings.scala
deleted file mode 100644
index da2c89d707..0000000000
--- a/src/compiler/scala/tools/nsc/settings/AestheticSettings.scala
+++ /dev/null
@@ -1,39 +0,0 @@
-/* NSC -- new Scala compiler
- * Copyright 2005-2013 LAMP/EPFL
- * @author Paul Phillips
- */
-
-package scala.tools.nsc
-package settings
-
-/** Taking flag checking to a somewhat higher level. */
-trait AestheticSettings {
- def settings: Settings
-
- // Some(value) if setting has been set by user, None otherwise.
- def optSetting[T](s: Settings#Setting): Option[T] =
- if (s.isDefault) None else Some(s.value.asInstanceOf[T])
-
- def script = optSetting[String](settings.script)
- def encoding = optSetting[String](settings.encoding)
- def sourceReader = optSetting[String](settings.sourceReader)
-
- def debug = settings.debug.value
- def declsOnly = false
- def deprecation = settings.deprecation.value
- def experimental = settings.Xexperimental.value
- def fatalWarnings = settings.fatalWarnings.value
- def feature = settings.feature.value
- def future = settings.future.value
- def logClasspath = settings.Ylogcp.value
- def printStats = settings.Ystatistics.value
- def target = settings.target.value
- def unchecked = settings.unchecked.value
- def verbose = settings.verbose.value
- def virtPatmat = !settings.XoldPatmat.value
-
- /** Derived values */
- def jvm = target startsWith "jvm"
- def msil = target == "msil"
- def verboseDebug = debug && verbose
-}
diff --git a/src/compiler/scala/tools/nsc/settings/FscSettings.scala b/src/compiler/scala/tools/nsc/settings/FscSettings.scala
index 06ebc20d3e..14b398e50a 100644
--- a/src/compiler/scala/tools/nsc/settings/FscSettings.scala
+++ b/src/compiler/scala/tools/nsc/settings/FscSettings.scala
@@ -8,7 +8,7 @@ package nsc
package settings
import util.ClassPath
-import io.{ Directory, Path, AbstractFile }
+import io.{ Path, AbstractFile }
class FscSettings(error: String => Unit) extends Settings(error) {
outer =>
diff --git a/src/compiler/scala/tools/nsc/settings/MutableSettings.scala b/src/compiler/scala/tools/nsc/settings/MutableSettings.scala
index f1f289ed4d..748c6069f0 100644
--- a/src/compiler/scala/tools/nsc/settings/MutableSettings.scala
+++ b/src/compiler/scala/tools/nsc/settings/MutableSettings.scala
@@ -10,7 +10,6 @@ package settings
import io.{ AbstractFile, Jar, Path, PlainFile, VirtualDirectory }
import scala.reflect.internal.util.StringOps
-import scala.collection.mutable.ListBuffer
import scala.io.Source
import scala.reflect.{ ClassTag, classTag }
@@ -63,30 +62,23 @@ class MutableSettings(val errorFn: String => Unit)
(checkDependencies, residualArgs)
case "--" :: xs =>
(checkDependencies, xs)
+ // discard empties, sometimes they appear because of ant or etc.
+ // but discard carefully, because an empty string is valid as an argument
+ // to an option, e.g. -cp "" . So we discard them only when they appear
+ // where an option should be, not where an argument to an option should be.
+ case "" :: xs =>
+ loop(xs, residualArgs)
case x :: xs =>
- val isOpt = x startsWith "-"
- if (isOpt) {
- val newArgs = parseParams(args)
- if (args eq newArgs) {
- errorFn(s"bad option: '$x'")
- (false, args)
+ if (x startsWith "-") {
+ parseParams(args) match {
+ case newArgs if newArgs eq args => errorFn(s"bad option: '$x'") ; (false, args)
+ case newArgs => loop(newArgs, residualArgs)
}
- // discard empties, sometimes they appear because of ant or etc.
- // but discard carefully, because an empty string is valid as an argument
- // to an option, e.g. -cp "" . So we discard them only when they appear
- // in option position.
- else if (x == "") {
- loop(xs, residualArgs)
- }
- else lookupSetting(x) match {
- case Some(s) if s.shouldStopProcessing => (checkDependencies, newArgs)
- case _ => loop(newArgs, residualArgs)
- }
- }
- else {
- if (processAll) loop(xs, residualArgs :+ x)
- else (checkDependencies, args)
}
+ else if (processAll)
+ loop(xs, residualArgs :+ x)
+ else
+ (checkDependencies, args)
}
loop(arguments, Nil)
}
@@ -184,7 +176,7 @@ class MutableSettings(val errorFn: String => Unit)
* The class loader defining `T` should provide resources `app.class.path`
* and `boot.class.path`. These resources should contain the application
* and boot classpaths in the same form as would be passed on the command line.*/
- def embeddedDefaults[T: ClassTag]: Unit =
+ def embeddedDefaults[T: ClassTag]: Unit = // called from sbt and repl
embeddedDefaults(classTag[T].runtimeClass.getClassLoader)
/** Initializes these settings for embedded use by a class from the given class loader.
@@ -247,7 +239,7 @@ class MutableSettings(val errorFn: String => Unit)
/** Add a destination directory for sources found under srcdir.
* Both directories should exits.
*/
- def add(srcDir: String, outDir: String): Unit =
+ def add(srcDir: String, outDir: String): Unit = // used in ide?
add(checkDir(AbstractFile.getDirectory(srcDir), srcDir),
checkDir(AbstractFile.getDirectory(outDir), outDir))
@@ -442,7 +434,7 @@ class MutableSettings(val errorFn: String => Unit)
def tryToSet(args: List[String]) = { value = true ; Some(args) }
def unparse: List[String] = if (value) List(name) else Nil
- override def tryToSetFromPropertyValue(s : String) {
+ override def tryToSetFromPropertyValue(s : String) { // used from ide
value = s.equalsIgnoreCase("true")
}
}
@@ -535,7 +527,7 @@ class MutableSettings(val errorFn: String => Unit)
Some(rest)
}
override def tryToSetColon(args: List[String]) = tryToSet(args)
- override def tryToSetFromPropertyValue(s: String) = tryToSet(s.trim.split(',').toList)
+ override def tryToSetFromPropertyValue(s: String) = tryToSet(s.trim.split(',').toList) // used from ide
def unparse: List[String] = value map (name + ":" + _)
withHelpSyntax(name + ":<" + arg + ">")
@@ -569,7 +561,7 @@ class MutableSettings(val errorFn: String => Unit)
}
def unparse: List[String] =
if (value == default) Nil else List(name + ":" + value)
- override def tryToSetFromPropertyValue(s: String) = tryToSetColon(s::Nil)
+ override def tryToSetFromPropertyValue(s: String) = tryToSetColon(s::Nil) // used from ide
withHelpSyntax(name + ":<" + helpArg + ">")
}
diff --git a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
index cfc7f14210..8f964cf9e1 100644
--- a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
+++ b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
@@ -52,14 +52,14 @@ trait ScalaSettings extends AbsScalaSettings
val jvmargs = PrefixSetting("-J<flag>", "-J", "Pass <flag> directly to the runtime system.")
val defines = PrefixSetting("-Dproperty=value", "-D", "Pass -Dproperty=value directly to the runtime system.")
- val toolcp = PathSetting("-toolcp", "Add to the runner classpath.", "")
+ /*val toolcp =*/ PathSetting("-toolcp", "Add to the runner classpath.", "")
val nobootcp = BooleanSetting("-nobootcp", "Do not use the boot classpath for the scala jars.")
/**
* Standard settings
*/
// argfiles is only for the help message
- val argfiles = BooleanSetting ("@<file>", "A text file containing compiler arguments (options and source files)")
+ /*val argfiles = */ BooleanSetting ("@<file>", "A text file containing compiler arguments (options and source files)")
val classpath = PathSetting ("-classpath", "Specify where to find user class files.", defaultClasspath) withAbbreviation "-cp"
val d = OutputSetting (outputDirs, ".")
val nospecialization = BooleanSetting ("-no-specialization", "Ignore @specialize annotations.")
@@ -69,11 +69,8 @@ trait ScalaSettings extends AbsScalaSettings
* -X "Advanced" settings
*/
val Xhelp = BooleanSetting ("-X", "Print a synopsis of advanced options.")
- val assemname = StringSetting ("-Xassem-name", "file", "(Requires -target:msil) Name of the output assembly.", "").dependsOn(target, "msil")
- val assemrefs = StringSetting ("-Xassem-path", "path", "(Requires -target:msil) List of assemblies referenced by the program.", ".").dependsOn(target, "msil")
- val assemextdirs = StringSetting ("-Xassem-extdirs", "dirs", "(Requires -target:msil) List of directories containing assemblies. default:lib", Defaults.scalaLibDir.path).dependsOn(target, "msil")
- val sourcedir = StringSetting ("-Xsourcedir", "directory", "(Requires -target:msil) Mirror source folder structure in output directory.", ".").dependsOn(target, "msil")
val checkInit = BooleanSetting ("-Xcheckinit", "Wrap field accessors to throw an exception on uninitialized access.")
+ val developer = BooleanSetting ("-Xdev", "Indicates user is a developer - issue warnings about anything which seems amiss")
val noassertions = BooleanSetting ("-Xdisable-assertions", "Generate no assertions or assumptions.")
val elidebelow = IntSetting ("-Xelide-below", "Calls to @elidable methods are omitted if method priority is lower than argument",
elidable.MINIMUM, None, elidable.byName get _)
@@ -114,7 +111,6 @@ trait ScalaSettings extends AbsScalaSettings
/** Compatibility stubs for options whose value name did
* not previously match the option name.
*/
- def XO = optimise
def debuginfo = g
def dependenciesFile = dependencyfile
def nowarnings = nowarn
@@ -127,6 +123,7 @@ trait ScalaSettings extends AbsScalaSettings
val overrideObjects = BooleanSetting ("-Yoverride-objects", "Allow member objects to be overridden.")
val overrideVars = BooleanSetting ("-Yoverride-vars", "Allow vars to be overridden.")
val Yhelp = BooleanSetting ("-Y", "Print a synopsis of private options.")
+ val breakCycles = BooleanSetting ("-Ybreak-cycles", "Attempt to break cycles encountered during typing")
val browse = PhasesSetting ("-Ybrowse", "Browse the abstract syntax tree after")
val check = PhasesSetting ("-Ycheck", "Check the tree at the end of")
val Yshow = PhasesSetting ("-Yshow", "(Requires -Xshow-class or -Xshow-object) Show after")
@@ -169,6 +166,7 @@ trait ScalaSettings extends AbsScalaSettings
val Ybuilderdebug = ChoiceSetting ("-Ybuilder-debug", "manager", "Compile using the specified build manager.", List("none", "refined", "simple"), "none")
val Yreifycopypaste = BooleanSetting ("-Yreify-copypaste", "Dump the reified trees in copypasteable representation.")
val Yreplsync = BooleanSetting ("-Yrepl-sync", "Do not use asynchronous code for repl startup")
+ val Yreploutdir = StringSetting ("-Yrepl-outdir", "path", "Write repl-generated classfiles to given output directory (use \"\" to generate a temporary dir)" , "")
val Ynotnull = BooleanSetting ("-Ynotnull", "Enable (experimental and incomplete) scala.NotNull.")
val YmethodInfer = BooleanSetting ("-Yinfer-argument-types", "Infer types for arguments of overriden methods.")
val etaExpandKeepsStar = BooleanSetting ("-Yeta-expand-keeps-star", "Eta-expand varargs methods to T* rather than Seq[T]. This is a temporary option to ease transition.")
@@ -178,12 +176,9 @@ trait ScalaSettings extends AbsScalaSettings
val exposeEmptyPackage = BooleanSetting("-Yexpose-empty-package", "Internal only: expose the empty package.").internalOnly()
- def stop = stopAfter
-
/** Area-specific debug output.
*/
val Ybuildmanagerdebug = BooleanSetting("-Ybuild-manager-debug", "Generate debug information for the Refined Build Manager compiler.")
- val Ycompletion = BooleanSetting("-Ycompletion-debug", "Trace all tab completion activity.")
val Ydocdebug = BooleanSetting("-Ydoc-debug", "Trace all scaladoc activity.")
val Yidedebug = BooleanSetting("-Yide-debug", "Generate, validate and output trees using the interactive compiler.")
val Yinferdebug = BooleanSetting("-Yinfer-debug", "Trace type inference and implicit search.")
diff --git a/src/compiler/scala/tools/nsc/settings/StandardScalaSettings.scala b/src/compiler/scala/tools/nsc/settings/StandardScalaSettings.scala
index e866ad6ae0..9338d9e5b5 100644
--- a/src/compiler/scala/tools/nsc/settings/StandardScalaSettings.scala
+++ b/src/compiler/scala/tools/nsc/settings/StandardScalaSettings.scala
@@ -41,16 +41,10 @@ trait StandardScalaSettings {
val optimise: BooleanSetting // depends on post hook which mutates other settings
val print = BooleanSetting ("-print", "Print program with Scala-specific features removed.")
val target = ChoiceSetting ("-target", "target", "Target platform for object files. All JVM 1.5 targets are deprecated.",
- List("jvm-1.5", "jvm-1.5-fjbg", "jvm-1.5-asm", "jvm-1.6", "jvm-1.7", "msil"),
- "jvm-1.6")
+ List("jvm-1.5", "jvm-1.6", "jvm-1.7"), "jvm-1.6")
val unchecked = BooleanSetting ("-unchecked", "Enable additional warnings where generated code depends on assumptions.")
val uniqid = BooleanSetting ("-uniqid", "Uniquely tag all identifiers in debugging output.")
val usejavacp = BooleanSetting ("-usejavacp", "Utilize the java.class.path in classpath resolution.")
val verbose = BooleanSetting ("-verbose", "Output messages about what the compiler is doing.")
val version = BooleanSetting ("-version", "Print product version and exit.")
-
- /** These are @<file> and -Dkey=val style settings, which don't
- * nicely map to identifiers.
- */
- val argfiles: BooleanSetting // exists only to echo help message, should be done differently
}
diff --git a/src/compiler/scala/tools/nsc/settings/Warnings.scala b/src/compiler/scala/tools/nsc/settings/Warnings.scala
index 9f9879210c..2649a150ad 100644
--- a/src/compiler/scala/tools/nsc/settings/Warnings.scala
+++ b/src/compiler/scala/tools/nsc/settings/Warnings.scala
@@ -26,11 +26,11 @@ trait Warnings {
// These warnings should be pretty quiet unless you're doing
// something inadvisable.
protected def lintWarnings = List(
- // warnDeadCode,
warnInaccessible,
warnNullaryOverride,
warnNullaryUnit,
- warnAdaptedArgs
+ warnAdaptedArgs,
+ warnInferAny
)
// Warning groups.
@@ -38,9 +38,13 @@ trait Warnings {
BooleanSetting("-Xlint", "Enable recommended additional warnings.")
withPostSetHook (_ => lintWarnings foreach (_.value = true))
)
- val warnEverything = (
+
+ /*val warnEverything = */ (
BooleanSetting("-Ywarn-all", "Enable all -Y warnings.")
- withPostSetHook (_ => lintWarnings foreach (_.value = true))
+ withPostSetHook { _ =>
+ lint.value = true
+ allWarnings foreach (_.value = true)
+ }
)
// Individual warnings.
@@ -53,9 +57,10 @@ trait Warnings {
val warnInaccessible = BooleanSetting ("-Ywarn-inaccessible", "Warn about inaccessible types in method signatures.")
val warnNullaryOverride = BooleanSetting ("-Ywarn-nullary-override",
"Warn when non-nullary overrides nullary, e.g. `def foo()` over `def foo`.")
+ val warnInferAny = BooleanSetting ("-Ywarn-infer-any", "Warn when a type argument is inferred to be `Any`.")
// Backward compatibility.
- def Xwarnfatal = fatalWarnings
- def Xchecknull = warnSelectNullable
- def Ywarndeadcode = warnDeadCode
+ @deprecated("Use fatalWarnings", "2.11.0") def Xwarnfatal = fatalWarnings // used by sbt
+ @deprecated("Use warnSelectNullable", "2.11.0") def Xchecknull = warnSelectNullable // used by ide
+ @deprecated("Use warnDeadCode", "2.11.0") def Ywarndeadcode = warnDeadCode // used by ide
}
diff --git a/src/compiler/scala/tools/nsc/symtab/BrowsingLoaders.scala b/src/compiler/scala/tools/nsc/symtab/BrowsingLoaders.scala
index f2aab36b51..4e4efef607 100644
--- a/src/compiler/scala/tools/nsc/symtab/BrowsingLoaders.scala
+++ b/src/compiler/scala/tools/nsc/symtab/BrowsingLoaders.scala
@@ -6,7 +6,6 @@
package scala.tools.nsc
package symtab
-import scala.reflect.internal.util.BatchSourceFile
import scala.tools.nsc.io.AbstractFile
/** A subclass of SymbolLoaders that implements browsing behavior.
@@ -28,7 +27,7 @@ abstract class BrowsingLoaders extends SymbolLoaders {
override protected def enterIfNew(owner: Symbol, member: Symbol, completer: SymbolLoader): Symbol = {
completer.sourcefile match {
case Some(src) =>
- (if (member.isModule) member.moduleClass else member).sourceFile = src
+ (if (member.isModule) member.moduleClass else member).associatedFile = src
case _ =>
}
val decls = owner.info.decls
diff --git a/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala b/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala
index 348c7f688f..bbff03f67f 100644
--- a/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala
+++ b/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala
@@ -10,10 +10,9 @@ import java.io.IOException
import scala.compat.Platform.currentTime
import scala.tools.nsc.util.{ ClassPath }
import classfile.ClassfileParser
-import scala.reflect.internal.Flags._
import scala.reflect.internal.MissingRequirementError
import scala.reflect.internal.util.Statistics
-import scala.tools.nsc.io.{ AbstractFile, MsilFile }
+import scala.tools.nsc.io.{ AbstractFile }
/** This class ...
*
@@ -153,7 +152,7 @@ abstract class SymbolLoaders {
def sourcefile: Option[AbstractFile] = None
/**
- * Description of the resource (ClassPath, AbstractFile, MsilFile)
+ * Description of the resource (ClassPath, AbstractFile)
* being processed by this loader
*/
protected def description: String
@@ -162,8 +161,8 @@ abstract class SymbolLoaders {
private def setSource(sym: Symbol) {
sourcefile foreach (sf => sym match {
- case cls: ClassSymbol => cls.sourceFile = sf
- case mod: ModuleSymbol => mod.moduleClass.sourceFile = sf
+ case cls: ClassSymbol => cls.associatedFile = sf
+ case mod: ModuleSymbol => mod.moduleClass.associatedFile = sf
case _ => ()
})
}
@@ -226,7 +225,6 @@ abstract class SymbolLoaders {
assert(root.isPackageClass, root)
root.setInfo(new PackageClassInfoType(newScope, root))
- val sourcepaths = classpath.sourcepaths
if (!root.isRoot) {
for (classRep <- classpath.classes if platform.doLoad(classRep)) {
initializeFromClassPath(root, classRep)
@@ -267,16 +265,6 @@ abstract class SymbolLoaders {
override def sourcefile: Option[AbstractFile] = classfileParser.srcfile
}
- class MsilFileLoader(msilFile: MsilFile) extends SymbolLoader with FlagAssigningCompleter {
- private def typ = msilFile.msilType
- private object typeParser extends clr.TypeParser {
- val global: SymbolLoaders.this.global.type = SymbolLoaders.this.global
- }
-
- protected def description = "MsilFile "+ typ.FullName + ", assembly "+ typ.Assembly.FullName
- protected def doComplete(root: Symbol) { typeParser.parse(typ, root) }
- }
-
class SourcefileLoader(val srcfile: AbstractFile) extends SymbolLoader with FlagAssigningCompleter {
protected def description = "source file "+ srcfile.toString
override def fromSource = true
@@ -289,11 +277,6 @@ abstract class SymbolLoaders {
protected def doComplete(root: Symbol) { root.sourceModule.initialize }
}
- object clrTypes extends clr.CLRTypes {
- val global: SymbolLoaders.this.global.type = SymbolLoaders.this.global
- if (global.forMSIL) init()
- }
-
/** used from classfile parser to avoid cyclies */
var parentsLevel = 0
var pendingLoadActions: List[() => Unit] = Nil
diff --git a/src/compiler/scala/tools/nsc/symtab/SymbolTrackers.scala b/src/compiler/scala/tools/nsc/symtab/SymbolTrackers.scala
index 7a84441e09..035244e421 100644
--- a/src/compiler/scala/tools/nsc/symtab/SymbolTrackers.scala
+++ b/src/compiler/scala/tools/nsc/symtab/SymbolTrackers.scala
@@ -6,7 +6,6 @@
package scala.tools.nsc
package symtab
-import scala.collection.{ mutable, immutable }
import scala.language.implicitConversions
import scala.language.postfixOps
@@ -17,9 +16,6 @@ trait SymbolTrackers {
val global: Global
import global._
- private implicit lazy val TreeOrdering: Ordering[Tree] =
- Ordering by (x => (x.shortClass, x.symbol))
-
private implicit lazy val SymbolOrdering: Ordering[Symbol] =
Ordering by (x => (x.kindString, x.name.toString))
@@ -76,7 +72,6 @@ trait SymbolTrackers {
private def isFlagsChange(sym: Symbol) = changed.flags contains sym
private implicit def NodeOrdering: Ordering[Node] = Ordering by (_.root)
- private def ownersString(sym: Symbol, num: Int) = sym.ownerChain drop 1 take num mkString " -> "
object Node {
def nodes(syms: Set[Symbol]): List[Node] = {
@@ -114,7 +109,6 @@ trait SymbolTrackers {
case Some(oldFlags) =>
val added = masked & ~oldFlags
val removed = oldFlags & ~masked
- val steady = masked & ~(added | removed)
val all = masked | oldFlags
val strs = 0 to 63 map { bit =>
val flag = 1L << bit
@@ -181,7 +175,7 @@ trait SymbolTrackers {
}
def show(label: String): String = {
val hierarchy = Node(current)
- val Change(added, removed, symMap, owners, flags) = history.head
+ val Change(_, removed, symMap, _, _) = history.head
def detailString(sym: Symbol) = {
val ownerString = sym.ownerChain splitAt 3 match {
case (front, back) =>
diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/AbstractFileReader.scala b/src/compiler/scala/tools/nsc/symtab/classfile/AbstractFileReader.scala
index 427b5bf887..17e3b08ec2 100644
--- a/src/compiler/scala/tools/nsc/symtab/classfile/AbstractFileReader.scala
+++ b/src/compiler/scala/tools/nsc/symtab/classfile/AbstractFileReader.scala
@@ -29,11 +29,6 @@ class AbstractFileReader(val file: AbstractFile) {
*/
var bp: Int = 0
- /** return byte at offset 'pos'
- */
- @throws(classOf[IndexOutOfBoundsException])
- def byteAt(pos: Int): Byte = buf(pos)
-
/** read a byte
*/
@throws(classOf[IndexOutOfBoundsException])
@@ -45,7 +40,7 @@ class AbstractFileReader(val file: AbstractFile) {
/** read some bytes
*/
- def nextBytes(len: Int): Array[Byte] = {
+ def nextBytes(len: Int): Array[Byte] = { // used in ide
bp += len
buf.slice(bp - len, bp)
}
diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala
index a708a262e7..cb58111b51 100644
--- a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala
+++ b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala
@@ -23,7 +23,6 @@ import scala.tools.nsc.io.AbstractFile
abstract class ClassfileParser {
val global: Global
import global._
- import definitions.{ AnnotationClass, ClassfileAnnotationClass }
import scala.reflect.internal.ClassfileConstants._
import Flags._
@@ -186,7 +185,7 @@ abstract class ClassfileParser {
if (in.buf(start).toInt != CONSTANT_CLASS) errorBadTag(start)
val name = getExternalName(in.getChar(start + 1))
if (nme.isModuleName(name))
- c = rootMirror.getModule(nme.stripModuleSuffix(name))
+ c = rootMirror.getModuleByName(nme.stripModuleSuffix(name))
else
c = classNameToSymbol(name)
@@ -237,7 +236,7 @@ abstract class ClassfileParser {
//assert(name.endsWith("$"), "Not a module class: " + name)
f = forceMangledName(name dropRight 1, true)
if (f == NoSymbol)
- f = rootMirror.getModule(name dropRight 1)
+ f = rootMirror.getModuleByName(name dropRight 1)
} else {
val origName = nme.originalName(name)
val owner = if (static) ownerTpe.typeSymbol.linkedClassOfClass else ownerTpe.typeSymbol
@@ -253,8 +252,8 @@ abstract class ClassfileParser {
} else {
log("Couldn't find " + name + ": " + tpe + " inside: \n" + ownerTpe)
f = tpe match {
- case MethodType(_, _) => owner.newMethod(name, owner.pos)
- case _ => owner.newVariable(name, owner.pos)
+ case MethodType(_, _) => owner.newMethod(name.toTermName, owner.pos)
+ case _ => owner.newVariable(name.toTermName, owner.pos)
}
f setInfo tpe
log("created fake member " + f.fullName)
@@ -283,7 +282,7 @@ abstract class ClassfileParser {
if (in.buf(start).toInt != CONSTANT_NAMEANDTYPE) errorBadTag(start)
val name = getName(in.getChar(start + 1).toInt)
// create a dummy symbol for method types
- val dummySym = ownerTpe.typeSymbol.newMethod(name, ownerTpe.typeSymbol.pos)
+ val dummySym = ownerTpe.typeSymbol.newMethod(name.toTermName, ownerTpe.typeSymbol.pos)
var tpe = getType(dummySym, in.getChar(start + 3).toInt)
// fix the return type, which is blindly set to the class currently parsed
@@ -361,7 +360,7 @@ abstract class ClassfileParser {
}
value match {
case ct: Constant => ct
- case cls: Symbol => Constant(cls.tpe)
+ case cls: Symbol => Constant(cls.tpe_*)
case arr: Type => Constant(arr)
}
}
@@ -423,9 +422,9 @@ abstract class ClassfileParser {
var sym: Symbol = rootMirror.RootClass
// was "at flatten.prev"
- beforeFlatten {
+ enteringFlatten {
for (part0 <- parts; if !(part0 == ""); part = newTermName(part0)) {
- val sym1 = beforeIcode {
+ val sym1 = enteringIcode {
sym.linkedClassOfClass.info
sym.info.decl(part.encode)
}//.suchThat(module == _.isModule)
@@ -458,7 +457,7 @@ abstract class ClassfileParser {
ss = name.subName(start, end)
sym = owner.info.decls lookup ss
if (sym == NoSymbol) {
- sym = owner.newPackage(ss) setInfo completer
+ sym = owner.newPackage(ss.toTermName) setInfo completer
sym.moduleClass setInfo completer
owner.info.decls enter sym
}
@@ -478,7 +477,7 @@ abstract class ClassfileParser {
if (name.pos('.') == name.length)
definitions.getMember(rootMirror.EmptyPackageClass, name.toTypeName)
else
- rootMirror.getClass(name) // see tickets #2464, #3756
+ rootMirror.getClassByName(name) // see tickets #2464, #3756
} catch {
case _: FatalError => loadClassSymbol(name)
}
@@ -500,8 +499,8 @@ abstract class ClassfileParser {
def parseClass() {
val jflags = in.nextChar
val isAnnotation = hasAnnotation(jflags)
- var sflags = toScalaClassFlags(jflags)
- var nameIdx = in.nextChar
+ val sflags = toScalaClassFlags(jflags)
+ val nameIdx = in.nextChar
currentClass = pool.getClassName(nameIdx)
/** Parse parents for Java classes. For Scala, return AnyRef, since the real type will be unpickled.
@@ -515,9 +514,9 @@ abstract class ClassfileParser {
}
else raiseLoaderLevel {
val superType = if (isAnnotation) { in.nextChar; definitions.AnnotationClass.tpe }
- else pool.getSuperClass(in.nextChar).tpe
+ else pool.getSuperClass(in.nextChar).tpe_*
val ifaceCount = in.nextChar
- var ifaces = for (i <- List.range(0, ifaceCount)) yield pool.getSuperClass(in.nextChar).tpe
+ var ifaces = for (i <- List.range(0, ifaceCount)) yield pool.getSuperClass(in.nextChar).tpe_*
if (isAnnotation) ifaces = definitions.ClassfileAnnotationClass.tpe :: ifaces
superType :: ifaces
}
@@ -565,7 +564,7 @@ abstract class ClassfileParser {
0 until in.nextChar foreach (_ => parseMethod())
val needsConstructor = (
!sawPrivateConstructor
- && instanceScope.lookup(nme.CONSTRUCTOR) == NoSymbol
+ && !(instanceScope containsName nme.CONSTRUCTOR)
&& (sflags & INTERFACE) == 0
)
if (needsConstructor)
@@ -599,13 +598,13 @@ abstract class ClassfileParser {
def parseField() {
val jflags = in.nextChar
- var sflags = toScalaFieldFlags(jflags)
+ val sflags = toScalaFieldFlags(jflags)
if ((sflags & PRIVATE) != 0L && !global.settings.optimise.value) {
in.skip(4); skipAttributes()
} else {
val name = pool.getName(in.nextChar)
val info = pool.getType(in.nextChar)
- val sym = getOwner(jflags).newValue(name, NoPosition, sflags)
+ val sym = getOwner(jflags).newValue(name.toTermName, NoPosition, sflags)
val isEnum = (jflags & JAVA_ACC_ENUM) != 0
sym setInfo {
@@ -629,7 +628,7 @@ abstract class ClassfileParser {
def parseMethod() {
val jflags = in.nextChar.toInt
- var sflags = toScalaMethodFlags(jflags)
+ val sflags = toScalaMethodFlags(jflags)
if (isPrivate(jflags) && !global.settings.optimise.value) {
val name = pool.getName(in.nextChar)
if (name == nme.CONSTRUCTOR)
@@ -640,7 +639,7 @@ abstract class ClassfileParser {
in.skip(4); skipAttributes()
} else {
val name = pool.getName(in.nextChar)
- val sym = getOwner(jflags).newMethod(name, NoPosition, sflags)
+ val sym = getOwner(jflags).newMethod(name.toTermName, NoPosition, sflags)
var info = pool.getType(sym, (in.nextChar))
if (name == nme.CONSTRUCTOR)
info match {
@@ -735,17 +734,19 @@ abstract class ClassfileParser {
}
accept('>')
assert(xs.length > 0, tp)
- newExistentialType(existentials.toList, typeRef(pre, classSym, xs.toList))
- } else if (classSym.isMonomorphicType) {
+ logResult("new existential")(newExistentialType(existentials.toList, typeRef(pre, classSym, xs.toList)))
+ }
+ // isMonomorphicType is false if the info is incomplete, as it usually is here
+ // so have to check unsafeTypeParams.isEmpty before worrying about raw type case below,
+ // or we'll create a boatload of needless existentials.
+ else if (classSym.isMonomorphicType || classSym.unsafeTypeParams.isEmpty) {
tp
- } else {
+ }
+ else {
// raw type - existentially quantify all type parameters
val eparams = typeParamsToExistentials(classSym, classSym.unsafeTypeParams)
- val t = typeRef(pre, classSym, eparams.map(_.tpeHK))
- val res = newExistentialType(eparams, t)
- if (settings.debug.value && settings.verbose.value)
- println("raw type " + classSym + " -> " + res)
- res
+ val t = typeRef(pre, classSym, eparams.map(_.tpeHK))
+ logResult(s"raw type from $classSym")(newExistentialType(eparams, t))
}
case tp =>
assert(sig.charAt(index) != '<', tp)
@@ -754,7 +755,7 @@ abstract class ClassfileParser {
val classSym = classNameToSymbol(subName(c => c == ';' || c == '<'))
assert(!classSym.isOverloaded, classSym.alternatives)
- var tpe = processClassType(processInner(classSym.tpe))
+ var tpe = processClassType(processInner(classSym.tpe_*))
while (sig.charAt(index) == '.') {
accept('.')
val name = subName(c => c == ';' || c == '<' || c == '.').toTypeName
@@ -787,7 +788,7 @@ abstract class ClassfileParser {
index += 1
val restype = if (sym != null && sym.isClassConstructor) {
accept('V')
- clazz.tpe
+ clazz.tpe_*
} else
sig2type(tparams, skiptvs)
JavaMethodType(sym.newSyntheticValueParams(paramtypes.toList), restype)
@@ -875,7 +876,7 @@ abstract class ClassfileParser {
sym.setFlag(SYNTHETIC | ARTIFACT)
in.skip(attrLen)
case tpnme.BridgeATTR =>
- sym.setFlag(BRIDGE)
+ sym.setFlag(BRIDGE | ARTIFACT)
in.skip(attrLen)
case tpnme.DeprecatedATTR =>
val arg = Literal(Constant("see corresponding Javadoc for more information."))
@@ -1079,7 +1080,7 @@ abstract class ClassfileParser {
def enterClassAndModule(entry: InnerClassEntry, file: AbstractFile, jflags: Int) {
val completer = new global.loaders.ClassfileLoader(file)
val name = entry.originalName
- var sflags = toScalaClassFlags(jflags)
+ val sflags = toScalaClassFlags(jflags)
val owner = getOwner(jflags)
val scope = getScope(jflags)
val innerClass = owner.newClass(name.toTypeName, NoPosition, sflags) setInfo completer
@@ -1167,21 +1168,7 @@ abstract class ClassfileParser {
originalName + " in " + outerName + "(" + externalName +")"
}
- object innerClasses extends scala.collection.mutable.HashMap[Name, InnerClassEntry] {
- /** Return the Symbol of the top level class enclosing `name`,
- * or 'name's symbol if no entry found for `name`.
- */
- def topLevelClass(name: Name): Symbol = {
- val tlName = if (isDefinedAt(name)) {
- var entry = this(name)
- while (isDefinedAt(entry.outerName))
- entry = this(entry.outerName)
- entry.outerName
- } else
- name
- classNameToSymbol(tlName)
- }
-
+ object innerClasses extends mutable.HashMap[Name, InnerClassEntry] {
/** Return the class symbol for `externalName`. It looks it up in its outer class.
* Forces all outer class symbols to be completed.
*
@@ -1206,7 +1193,7 @@ abstract class ClassfileParser {
// if loading during initialization of `definitions` typerPhase is not yet set.
// in that case we simply load the member at the current phase
if (currentRun.typerPhase != null)
- beforeTyper(getMember(sym, innerName.toTypeName))
+ enteringTyper(getMember(sym, innerName.toTypeName))
else
getMember(sym, innerName.toTypeName)
diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ICodeReader.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ICodeReader.scala
index 13c0d8993a..79b08bcabf 100644
--- a/src/compiler/scala/tools/nsc/symtab/classfile/ICodeReader.scala
+++ b/src/compiler/scala/tools/nsc/symtab/classfile/ICodeReader.scala
@@ -9,9 +9,7 @@ package classfile
import scala.collection.{ mutable, immutable }
import mutable.ListBuffer
-import backend.icode._
import ClassfileConstants._
-import scala.reflect.internal.Flags._
/** ICode reader from Java bytecode.
*
@@ -33,7 +31,6 @@ abstract class ICodeReader extends ClassfileParser {
* for non-static members.
*/
def readClass(cls: Symbol): (IClass, IClass) = {
- var classFile: io.AbstractFile = null;
cls.info // ensure accurate type information
isScalaModule = cls.isModule && !cls.isJavaDefined
@@ -58,11 +55,9 @@ abstract class ICodeReader extends ClassfileParser {
override def parseClass() {
this.instanceCode = new IClass(clazz)
this.staticCode = new IClass(staticModule)
- val jflags = in.nextChar
- val isAttribute = (jflags & JAVA_ACC_ANNOTATION) != 0
- val sflags = toScalaClassFlags(jflags) // what, this is never used??
- val c = pool getClassSymbol in.nextChar
+ in.nextChar
+ pool getClassSymbol in.nextChar
parseInnerClasses()
in.skip(2) // super class
@@ -85,7 +80,7 @@ abstract class ICodeReader extends ClassfileParser {
val jflags = in.nextChar
val name = pool getName in.nextChar
val owner = getOwner(jflags)
- val dummySym = owner.newMethod(name, owner.pos, toScalaMethodFlags(jflags))
+ val dummySym = owner.newMethod(name.toTermName, owner.pos, toScalaMethodFlags(jflags))
try {
val ch = in.nextChar
@@ -99,7 +94,7 @@ abstract class ICodeReader extends ClassfileParser {
if (sym == NoSymbol)
sym = owner.info.findMember(newTermName(name + nme.LOCAL_SUFFIX_STRING), 0, 0, false).suchThat(_.tpe =:= tpe)
if (sym == NoSymbol) {
- sym = if (field) owner.newValue(name, owner.pos, toScalaFieldFlags(jflags)) else dummySym
+ sym = if (field) owner.newValue(name.toTermName, owner.pos, toScalaFieldFlags(jflags)) else dummySym
sym setInfoAndEnter tpe
log(s"ICodeReader could not locate ${name.decode} in $owner. Created ${sym.defString}.")
}
@@ -125,7 +120,7 @@ abstract class ICodeReader extends ClassfileParser {
override def parseMethod() {
val (jflags, sym) = parseMember(false)
- var beginning = in.bp
+ val beginning = in.bp
try {
if (sym != NoSymbol) {
this.method = new IMethod(sym)
@@ -170,11 +165,11 @@ abstract class ICodeReader extends ClassfileParser {
}
else if (nme.isModuleName(name)) {
val strippedName = nme.stripModuleSuffix(name)
- forceMangledName(newTermName(strippedName.decode), true) orElse rootMirror.getModule(strippedName)
+ forceMangledName(newTermName(strippedName.decode), true) orElse rootMirror.getModuleByName(strippedName)
}
else {
forceMangledName(name, false)
- afterFlatten(rootMirror.getClassByName(name.toTypeName))
+ exitingFlatten(rootMirror.getClassByName(name.toTypeName))
}
if (sym.isModule)
sym.moduleClass
@@ -637,9 +632,9 @@ abstract class ICodeReader extends ClassfileParser {
else instanceCode
class LinearCode {
- var instrs: ListBuffer[(Int, Instruction)] = new ListBuffer
- var jmpTargets: mutable.Set[Int] = perRunCaches.newSet[Int]()
- var locals: mutable.Map[Int, List[(Local, TypeKind)]] = perRunCaches.newMap()
+ val instrs: ListBuffer[(Int, Instruction)] = new ListBuffer
+ val jmpTargets: mutable.Set[Int] = perRunCaches.newSet[Int]()
+ val locals: mutable.Map[Int, List[(Local, TypeKind)]] = perRunCaches.newMap()
var containsDUPX = false
var containsNEW = false
@@ -669,7 +664,6 @@ abstract class ICodeReader extends ClassfileParser {
val blocks = makeBasicBlocks
var otherBlock: BasicBlock = NoBasicBlock
- var disableJmpTarget = false
for ((pc, instr) <- instrs.iterator) {
// Console.println("> " + pc + ": " + instr);
@@ -720,11 +714,9 @@ abstract class ICodeReader extends ClassfileParser {
val tfa = new analysis.MethodTFA() {
import analysis._
- import analysis.typeFlowLattice.IState
/** Abstract interpretation for one instruction. */
override def mutatingInterpret(out: typeFlowLattice.Elem, i: Instruction): typeFlowLattice.Elem = {
- val bindings = out.vars
val stack = out.stack
import stack.push
i match {
@@ -901,7 +893,7 @@ abstract class ICodeReader extends ClassfileParser {
for (bb <- method.code.blocks ; (i, idx) <- bb.toList.zipWithIndex) i match {
case cm @ CALL_METHOD(m, Static(true)) if m.isClassConstructor =>
- def loop(bb0: BasicBlock, idx0: Int, depth: Int = 0): Unit = {
+ def loop(bb0: BasicBlock, idx0: Int, depth: Int): Unit = {
rdef.findDefs(bb0, idx0, 1, depth) match {
case ((bb1, idx1)) :: _ =>
bb1(idx1) match {
diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala b/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala
index 25b7813646..efe7519d5e 100644
--- a/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala
+++ b/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala
@@ -26,15 +26,23 @@ import Flags._
abstract class Pickler extends SubComponent {
import global._
- private final val showSig = false
-
val phaseName = "pickler"
- currentRun
-
def newPhase(prev: Phase): StdPhase = new PicklePhase(prev)
class PicklePhase(prev: Phase) extends StdPhase(prev) {
+ override def run() {
+ super.run()
+ // This is run here rather than after typer because I found
+ // some symbols - usually annotations, possibly others - had not
+ // yet performed the necessary symbol lookup, leading to
+ // spurious claims of unusedness.
+ if (settings.lint.value) {
+ log("Clearing recorded import selectors.")
+ analyzer.clearUnusedImports()
+ }
+ }
+
def apply(unit: CompilationUnit) {
def pickle(tree: Tree) {
def add(sym: Symbol, pickle: Pickle) = {
@@ -68,17 +76,19 @@ abstract class Pickler extends SubComponent {
return
}
- if (!t.isDef && t.hasSymbol && t.symbol.isTermMacro) {
+ if (!t.isDef && t.hasSymbolField && t.symbol.isTermMacro) {
unit.error(t.pos, t.symbol.typeParams.length match {
case 0 => "macro has not been expanded"
- case 1 => "type parameter not specified"
- case _ => "type parameters not specified"
+ case 1 => "this type parameter must be specified"
+ case _ => "these type parameters must be specified"
})
return
}
}
pickle(unit.body)
+ if (settings.lint.value)
+ analyzer.warnUnusedImports(unit)
}
}
@@ -138,11 +148,34 @@ abstract class Pickler extends SubComponent {
true
}
+ /** If the symbol is a type skolem, deskolemize and log it.
+ * If we fail to deskolemize, in a method like
+ * trait Trait[+A] { def f[CC[X]] : CC[A] }
+ * the applied type CC[A] will hold a different CC symbol
+ * than the type-constructor type-parameter CC.
+ */
+ private def deskolemize(sym: Symbol) = {
+ if (sym.isTypeSkolem) {
+ val sym1 = sym.deSkolemize
+ log({
+ val what0 = sym.defString
+ val what = sym1.defString match {
+ case `what0` => what0
+ case other => what0 + "->" + other
+ }
+ val where = sym.enclMethod.fullLocationString
+ s"deskolemizing $what in $where"
+ })
+ sym1
+ }
+ else sym
+ }
+
/** Store symbol in index. If symbol is local, also store everything it references.
- *
- * @param sym ...
*/
- def putSymbol(sym: Symbol) {
+ def putSymbol(sym0: Symbol) {
+ val sym = deskolemize(sym0)
+
if (putEntry(sym)) {
if (isLocal(sym)) {
putEntry(sym.name)
@@ -177,7 +210,7 @@ abstract class Pickler extends SubComponent {
*/
private def putType(tp: Type): Unit = if (putEntry(tp)) {
tp match {
- case NoType | NoPrefix /*| DeBruijnIndex(_, _) */ =>
+ case NoType | NoPrefix =>
;
case ThisType(sym) =>
putSymbol(sym)
@@ -235,7 +268,7 @@ abstract class Pickler extends SubComponent {
private def putTree(tree: Tree): Unit = if (putEntry(tree)) {
if (tree != EmptyTree)
putType(tree.tpe)
- if (tree.hasSymbol)
+ if (tree.hasSymbolField)
putSymbol(tree.symbol)
tree match {
@@ -427,7 +460,7 @@ abstract class Pickler extends SubComponent {
* argument of some Annotation */
private def putMods(mods: Modifiers) = if (putEntry(mods)) {
// annotations in Modifiers are removed by the typechecker
- val Modifiers(flags, privateWithin, Nil) = mods
+ val Modifiers(_, privateWithin, Nil) = mods
putEntry(privateWithin)
}
@@ -495,7 +528,13 @@ abstract class Pickler extends SubComponent {
/** Write a reference to object, i.e., the object's number in the map index.
*/
- private def writeRef(ref: AnyRef) { writeNat(index(ref)) }
+ private def writeRef(ref0: AnyRef) {
+ val ref = ref0 match {
+ case sym: Symbol => deskolemize(sym)
+ case _ => ref0
+ }
+ writeNat(index(ref))
+ }
private def writeRefs(refs: List[AnyRef]) { refs foreach writeRef }
private def writeRefsWithLength(refs: List[AnyRef]) {
writeNat(refs.length)
@@ -568,7 +607,7 @@ abstract class Pickler extends SubComponent {
tag
case sym: ClassSymbol =>
writeSymInfo(sym)
- if (sym.thisSym.tpe != sym.tpe) writeRef(sym.typeOfThis)
+ if (sym.thisSym.tpe_* != sym.tpe_*) writeRef(sym.typeOfThis)
CLASSsym
case sym: TypeSymbol =>
writeSymInfo(sym)
@@ -609,8 +648,6 @@ abstract class Pickler extends SubComponent {
writeRef(restpe); writeRefs(tparams); POLYtpe
case ExistentialType(tparams, restpe) =>
writeRef(restpe); writeRefs(tparams); EXISTENTIALtpe
- // case DeBruijnIndex(l, i) =>
- // writeNat(l); writeNat(i); DEBRUIJNINDEXtpe
case c @ Constant(_) =>
if (c.tag == BooleanTag) writeLong(if (c.booleanValue) 1 else 0)
else if (ByteTag <= c.tag && c.tag <= LongTag) writeLong(c.longValue)
@@ -993,115 +1030,6 @@ abstract class Pickler extends SubComponent {
patchNat(startpos + 1, writeIndex - (startpos + 2))
}
- /** Print entry for diagnostics */
- def printEntryAtIndex(idx: Int) = printEntry(entries(idx))
- def printEntry(entry: AnyRef) {
- def printRef(ref: AnyRef) {
- print(index(ref)+
- (if (ref.isInstanceOf[Name]) "("+ref+") " else " "))
- }
- def printRefs(refs: List[AnyRef]) { refs foreach printRef }
- def printSymInfo(sym: Symbol) {
- var posOffset = 0
- printRef(sym.name)
- printRef(localizedOwner(sym))
- print(flagsToString(sym.flags & PickledFlags)+" ")
- if (sym.hasAccessBoundary) printRef(sym.privateWithin)
- printRef(sym.info)
- }
- def printBody(entry: AnyRef) = entry match {
- case name: Name =>
- print((if (name.isTermName) "TERMname " else "TYPEname ")+name)
- case NoSymbol =>
- print("NONEsym")
- case sym: Symbol if !isLocal(sym) =>
- if (sym.isModuleClass) {
- print("EXTMODCLASSref "); printRef(sym.name.toTermName)
- } else {
- print("EXTref "); printRef(sym.name)
- }
- if (!sym.owner.isRoot) printRef(sym.owner)
- case sym: ClassSymbol =>
- print("CLASSsym ")
- printSymInfo(sym)
- if (sym.thisSym.tpe != sym.tpe) printRef(sym.typeOfThis)
- case sym: TypeSymbol =>
- print(if (sym.isAbstractType) "TYPEsym " else "ALIASsym ")
- printSymInfo(sym)
- case sym: TermSymbol =>
- print(if (sym.isModule) "MODULEsym " else "VALsym ")
- printSymInfo(sym)
- if (sym.alias != NoSymbol) printRef(sym.alias)
- case NoType =>
- print("NOtpe")
- case NoPrefix =>
- print("NOPREFIXtpe")
- case ThisType(sym) =>
- print("THIStpe "); printRef(sym)
- case SingleType(pre, sym) =>
- print("SINGLEtpe "); printRef(pre); printRef(sym);
- case ConstantType(value) =>
- print("CONSTANTtpe "); printRef(value);
- case TypeRef(pre, sym, args) =>
- print("TYPEREFtpe "); printRef(pre); printRef(sym); printRefs(args);
- case TypeBounds(lo, hi) =>
- print("TYPEBOUNDStpe "); printRef(lo); printRef(hi);
- case tp @ RefinedType(parents, decls) =>
- print("REFINEDtpe "); printRef(tp.typeSymbol); printRefs(parents);
- case ClassInfoType(parents, decls, clazz) =>
- print("CLASSINFOtpe "); printRef(clazz); printRefs(parents);
- case mt @ MethodType(formals, restpe) =>
- print("METHODtpe"); printRef(restpe); printRefs(formals)
- case PolyType(tparams, restpe) =>
- print("POLYtpe "); printRef(restpe); printRefs(tparams);
- case ExistentialType(tparams, restpe) =>
- print("EXISTENTIALtpe "); printRef(restpe); printRefs(tparams);
- print("||| "+entry)
- // case DeBruijnIndex(l, i) =>
- // print("DEBRUIJNINDEXtpe "); print(l+" "+i)
- case c @ Constant(_) =>
- print("LITERAL ")
- if (c.tag == BooleanTag) print("Boolean "+(if (c.booleanValue) 1 else 0))
- else if (c.tag == ByteTag) print("Byte "+c.longValue)
- else if (c.tag == ShortTag) print("Short "+c.longValue)
- else if (c.tag == CharTag) print("Char "+c.longValue)
- else if (c.tag == IntTag) print("Int "+c.longValue)
- else if (c.tag == LongTag) print("Long "+c.longValue)
- else if (c.tag == FloatTag) print("Float "+c.floatValue)
- else if (c.tag == DoubleTag) print("Double "+c.doubleValue)
- else if (c.tag == StringTag) { print("String "); printRef(newTermName(c.stringValue)) }
- else if (c.tag == ClazzTag) { print("Class "); printRef(c.typeValue) }
- else if (c.tag == EnumTag) { print("Enum "); printRef(c.symbolValue) }
- case AnnotatedType(annots, tp, selfsym) =>
- if (settings.selfInAnnots.value) {
- print("ANNOTATEDWSELFtpe ")
- printRef(tp)
- printRef(selfsym)
- printRefs(annots)
- } else {
- print("ANNOTATEDtpe ")
- printRef(tp)
- printRefs(annots)
- }
- case (target: Symbol, AnnotationInfo(atp, args, Nil)) =>
- print("SYMANNOT ")
- printRef(target)
- printRef(atp)
- for (c <- args) printRef(c)
- case (target: Symbol, children: List[_]) =>
- print("CHILDREN ")
- printRef(target)
- for (c <- children) printRef(c.asInstanceOf[Symbol])
- case AnnotationInfo(atp, args, Nil) =>
- print("ANNOTINFO")
- printRef(atp)
- for (c <- args) printRef(c)
- case _ =>
- throw new FatalError("bad entry: " + entry + " " + entry.getClass)
- }
- printBody(entry); println()
- }
-
/** Write byte array */
def writeArray() {
assert(writeIndex == 0)
diff --git a/src/compiler/scala/tools/nsc/symtab/clr/CLRTypes.scala b/src/compiler/scala/tools/nsc/symtab/clr/CLRTypes.scala
deleted file mode 100644
index 40189b9444..0000000000
--- a/src/compiler/scala/tools/nsc/symtab/clr/CLRTypes.scala
+++ /dev/null
@@ -1,137 +0,0 @@
-/* NSC -- new scala compiler
- * Copyright 2004-2013 LAMP/EPFL
- */
-
-
-package scala.tools.nsc
-package symtab
-package clr
-
-import java.io.File
-import java.util.{Comparator, StringTokenizer}
-import scala.util.Sorting
-import ch.epfl.lamp.compiler.msil._
-import scala.collection.{ mutable, immutable }
-import scala.reflect.internal.util.{Position, NoPosition}
-
-/**
- * Collects all types from all reference assemblies.
- */
-abstract class CLRTypes {
-
- val global: Global
- import global.Symbol
- import global.definitions
-
- //##########################################################################
-
- var BYTE: Type = _
- var UBYTE: Type = _
- var SHORT: Type = _
- var USHORT: Type = _
- var CHAR: Type = _
- var INT: Type = _
- var UINT: Type = _
- var LONG: Type = _
- var ULONG: Type = _
- var FLOAT: Type = _
- var DOUBLE: Type = _
- var BOOLEAN: Type = _
- var VOID: Type = _
- var ENUM: Type = _
- var DELEGATE: Type = _
-
- var OBJECT: Type = _
- var STRING: Type = _
- var STRING_ARRAY: Type = _
-
- var VALUE_TYPE: Type = _
-
- var SCALA_SYMTAB_ATTR: Type = _
- var SYMTAB_CONSTR: ConstructorInfo = _
- var SYMTAB_DEFAULT_CONSTR: ConstructorInfo = _
-
- var DELEGATE_COMBINE: MethodInfo = _
- var DELEGATE_REMOVE: MethodInfo = _
-
- val types: mutable.Map[Symbol,Type] = new mutable.HashMap
- val constructors: mutable.Map[Symbol,ConstructorInfo] = new mutable.HashMap
- val methods: mutable.Map[Symbol,MethodInfo] = new mutable.HashMap
- val fields: mutable.Map[Symbol, FieldInfo] = new mutable.HashMap
- val sym2type: mutable.Map[Type,Symbol] = new mutable.HashMap
- val addressOfViews = new mutable.HashSet[Symbol]
- val mdgptrcls4clssym: mutable.Map[ /*cls*/ Symbol, /*cls*/ Symbol] = new mutable.HashMap
-
- def isAddressOf(msym : Symbol) = addressOfViews.contains(msym)
-
- def isNonEnumValuetype(cls: Symbol) = {
- val msilTOpt = types.get(cls)
- val res = msilTOpt.isDefined && {
- val msilT = msilTOpt.get
- msilT.IsValueType && !msilT.IsEnum
- }
- res
- }
-
- def isValueType(cls: Symbol): Boolean = {
- val opt = types.get(cls)
- opt.isDefined && opt.get.IsValueType
- }
-
- def init() = try { // initialize
- // the MsilClasspath (nsc/util/Classpath.scala) initializes the msil-library by calling
- // Assembly.LoadFrom("mscorlib.dll"), so this type should be found
- Type.initMSCORLIB(getTypeSafe("System.String").Assembly)
-
- BYTE = getTypeSafe("System.SByte")
- UBYTE = getTypeSafe("System.Byte")
- CHAR = getTypeSafe("System.Char")
- SHORT = getTypeSafe("System.Int16")
- USHORT = getTypeSafe("System.UInt16")
- INT = getTypeSafe("System.Int32")
- UINT = getTypeSafe("System.UInt32")
- LONG = getTypeSafe("System.Int64")
- ULONG = getTypeSafe("System.UInt64")
- FLOAT = getTypeSafe("System.Single")
- DOUBLE = getTypeSafe("System.Double")
- BOOLEAN = getTypeSafe("System.Boolean")
- VOID = getTypeSafe("System.Void")
- ENUM = getTypeSafe("System.Enum")
- DELEGATE = getTypeSafe("System.MulticastDelegate")
-
- OBJECT = getTypeSafe("System.Object")
- STRING = getTypeSafe("System.String")
- STRING_ARRAY = getTypeSafe("System.String[]")
- VALUE_TYPE = getTypeSafe("System.ValueType")
-
- SCALA_SYMTAB_ATTR = getTypeSafe("scala.runtime.SymtabAttribute")
- val bytearray: Array[Type] = Array(Type.GetType("System.Byte[]"))
- SYMTAB_CONSTR = SCALA_SYMTAB_ATTR.GetConstructor(bytearray)
- SYMTAB_DEFAULT_CONSTR = SCALA_SYMTAB_ATTR.GetConstructor(Type.EmptyTypes)
-
- val delegate: Type = getTypeSafe("System.Delegate")
- val dargs: Array[Type] = Array(delegate, delegate)
- DELEGATE_COMBINE = delegate.GetMethod("Combine", dargs)
- DELEGATE_REMOVE = delegate.GetMethod("Remove", dargs)
- }
- catch {
- case e: RuntimeException =>
- Console.println(e.getMessage)
- throw e
- }
-
- //##########################################################################
- // type mapping and lookup
-
- def getType(name: String): Type = Type.GetType(name)
-
- def getTypeSafe(name: String): Type = {
- val t = Type.GetType(name)
- assert(t != null, name)
- t
- }
-
- def mkArrayType(elemType: Type): Type = getType(elemType.FullName + "[]")
-
- def isDelegateType(t: Type): Boolean = { t.BaseType() == DELEGATE }
-} // CLRTypes
diff --git a/src/compiler/scala/tools/nsc/symtab/clr/TypeParser.scala b/src/compiler/scala/tools/nsc/symtab/clr/TypeParser.scala
deleted file mode 100644
index 5a0253c18b..0000000000
--- a/src/compiler/scala/tools/nsc/symtab/clr/TypeParser.scala
+++ /dev/null
@@ -1,850 +0,0 @@
-/* NSC -- new scala compiler
- * Copyright 2004-2013 LAMP/EPFL
- */
-
-package scala.tools.nsc
-package symtab
-package clr
-
-import java.io.IOException
-import io.MsilFile
-import ch.epfl.lamp.compiler.msil.{Type => MSILType, Attribute => MSILAttribute, _}
-import scala.collection.{ mutable, immutable }
-import scala.reflect.internal.pickling.UnPickler
-import ch.epfl.lamp.compiler.msil.Type.TMVarUsage
-import scala.language.implicitConversions
-
-/**
- * @author Nikolay Mihaylov
- */
-abstract class TypeParser {
-
- val global: Global
-
- import global._
- import loaders.clrTypes
-
- //##########################################################################
-
- private var clazz: Symbol = _
- private var instanceDefs: Scope = _ // was members
- private var staticModule: Symbol = _ // was staticsClass
- private var staticDefs: Scope = _ // was statics
-
- protected def statics: Symbol = staticModule.moduleClass
-
- protected var busy: Boolean = false // lock to detect recursive reads
-
- private object unpickler extends UnPickler {
- val global: TypeParser.this.global.type = TypeParser.this.global
- }
-
- def parse(typ: MSILType, root: Symbol) {
-
- def handleError(e: Throwable) = {
- if (settings.debug.value) e.printStackTrace() //debug
- throw new IOException("type '" + typ.FullName + "' is broken\n(" + e.getMessage() + ")")
- }
- assert(!busy)
- busy = true
-
- if (root.isModule) {
- this.clazz = root.companionClass
- this.staticModule = root
- } else {
- this.clazz = root
- this.staticModule = root.companionModule
- }
- try {
- parseClass(typ)
- } catch {
- case e: FatalError => handleError(e)
- case e: RuntimeException => handleError(e)
- }
- busy = false
- }
-
- class TypeParamsType(override val typeParams: List[Symbol]) extends LazyType with FlagAgnosticCompleter {
- override def complete(sym: Symbol) { throw new AssertionError("cyclic type dereferencing") }
- }
-
- /* the names `classTParams` and `newTParams` stem from the forJVM version (ClassfileParser.sigToType())
- * but there are differences that should be kept in mind.
- * forMSIL, a nested class knows nothing about any type-params in the nesting class,
- * therefore newTParams is redundant (other than for recording lexical order),
- * it always contains the same elements as classTParams.value */
- val classTParams = scala.collection.mutable.Map[Int,Symbol]() // TODO should this be a stack? (i.e., is it possible for >1 invocation to getCLRType on the same TypeParser instance be active )
- val newTParams = new scala.collection.mutable.ListBuffer[Symbol]()
- val methodTParams = scala.collection.mutable.Map[Int,Symbol]()
-
- private def sig2typeBounds(tvarCILDef: GenericParamAndConstraints): Type = {
- val ts = new scala.collection.mutable.ListBuffer[Type]
- for (cnstrnt <- tvarCILDef.Constraints) {
- ts += getCLRType(cnstrnt) // TODO we're definitely not at or after erasure, no need to call objToAny, right?
- }
- TypeBounds.upper(intersectionType(ts.toList, clazz))
- // TODO variance???
- }
-
- private def createViewFromTo(viewSuffix : String, fromTpe : Type, toTpe : Type,
- addToboxMethodMap : Boolean, isAddressOf : Boolean) : Symbol = {
- val flags = Flags.JAVA | Flags.STATIC | Flags.IMPLICIT; // todo: static? shouldn't be final instead?
- val viewMethodType = (msym: Symbol) => JavaMethodType(msym.newSyntheticValueParams(List(fromTpe)), toTpe)
- val vmsym = createMethod(nme.view_ + viewSuffix, flags, viewMethodType, null, true);
- // !!! this used to mutate a mutable map in definitions, but that map became
- // immutable and this kept "working" with a no-op. So now it's commented out
- // since I retired the deprecated code which allowed for that bug.
- //
- // if (addToboxMethodMap) definitions.boxMethod(clazz) = vmsym
-
- if (isAddressOf) clrTypes.addressOfViews += vmsym
- vmsym
- }
-
- private def createDefaultConstructor(typ: MSILType) {
- val attrs = MethodAttributes.Public | MethodAttributes.RTSpecialName | MethodAttributes.SpecialName // TODO instance
- val declType= typ
- val method = new ConstructorInfo(declType, attrs, Array[MSILType]())
- val flags = Flags.JAVA
- val owner = clazz
- val methodSym = owner.newMethod(nme.CONSTRUCTOR, NoPosition, flags)
- val rettype = clazz.tpe
- val mtype = methodType(Array[MSILType](), rettype);
- val mInfo = mtype(methodSym)
- methodSym.setInfo(mInfo)
- instanceDefs.enter(methodSym);
- clrTypes.constructors(methodSym) = method
- }
-
- private def parseClass(typ: MSILType) {
-
- {
- val t4c = clrTypes.types.get(clazz)
- assert(t4c == None || t4c == Some(typ))
- }
- clrTypes.types(clazz) = typ
-
- {
- val c4t = clrTypes.sym2type.get(typ)
- assert(c4t == None || c4t == Some(clazz))
- }
- clrTypes.sym2type(typ) = clazz
-
- if (typ.IsDefined(clrTypes.SCALA_SYMTAB_ATTR, false)) {
- val attrs = typ.GetCustomAttributes(clrTypes.SCALA_SYMTAB_ATTR, false);
- assert (attrs.length == 1, attrs.length);
- val a = attrs(0).asInstanceOf[MSILAttribute];
- assert (a.getConstructor() == clrTypes.SYMTAB_CONSTR);
- val symtab = a.getConstructorArguments()(0).asInstanceOf[Array[Byte]]
- unpickler.unpickle(symtab, 0, clazz, staticModule, typ.FullName);
- val mClass = clrTypes.getType(typ.FullName + "$");
- if (mClass != null) {
- clrTypes.types(statics) = mClass;
- val moduleInstance = mClass.GetField("MODULE$");
- assert (moduleInstance != null, mClass);
- clrTypes.fields(statics) = moduleInstance;
- }
- return
- }
- val flags = translateAttributes(typ)
-
- var clazzBoxed : Symbol = NoSymbol
- var clazzMgdPtr : Symbol = NoSymbol
-
- val canBeTakenAddressOf = (typ.IsValueType || typ.IsEnum) && (typ.FullName != "System.Enum")
-
- if(canBeTakenAddressOf) {
- clazzBoxed = clazz.owner.newClass(clazz.name.toTypeName append newTypeName("Boxed"))
- clazzMgdPtr = clazz.owner.newClass(clazz.name.toTypeName append newTypeName("MgdPtr"))
- clrTypes.mdgptrcls4clssym(clazz) = clazzMgdPtr
- /* adding typMgdPtr to clrTypes.sym2type should happen early (before metadata for supertypes is parsed,
- before metadata for members are parsed) so that clazzMgdPtr can be found by getClRType. */
- val typMgdPtr = MSILType.mkByRef(typ)
- clrTypes.types(clazzMgdPtr) = typMgdPtr
- clrTypes.sym2type(typMgdPtr) = clazzMgdPtr
- /* clazzMgdPtr but not clazzBoxed is mapped by clrTypes.types into an msil.Type instance,
- because there's no metadata-level representation for a "boxed valuetype" */
- val instanceDefsMgdPtr = newScope
- val classInfoMgdPtr = ClassInfoType(definitions.anyvalparam, instanceDefsMgdPtr, clazzMgdPtr)
- clazzMgdPtr.setFlag(flags)
- clazzMgdPtr.setInfo(classInfoMgdPtr)
- }
-
-/* START CLR generics (snippet 1) */
- // first pass
- for (tvarCILDef <- typ.getSortedTVars() ) {
- val tpname = newTypeName(tvarCILDef.Name.replaceAll("!", "")) // TODO are really all type-params named in all assemblies out there? (NO)
- val tpsym = clazz.newTypeParameter(tpname)
- classTParams.put(tvarCILDef.Number, tpsym)
- newTParams += tpsym
- // TODO wouldn't the following also be needed later, i.e. during getCLRType
- tpsym.setInfo(definitions.AnyClass.tpe)
- }
- // second pass
- for (tvarCILDef <- typ.getSortedTVars() ) {
- val tpsym = classTParams(tvarCILDef.Number)
- tpsym.setInfo(sig2typeBounds(tvarCILDef)) // we never skip bounds unlike in forJVM
- }
-/* END CLR generics (snippet 1) */
- val ownTypeParams = newTParams.toList
-/* START CLR generics (snippet 2) */
- if (!ownTypeParams.isEmpty) {
- clazz.setInfo(new TypeParamsType(ownTypeParams))
- if(typ.IsValueType && !typ.IsEnum) {
- clazzBoxed.setInfo(new TypeParamsType(ownTypeParams))
- }
- }
-/* END CLR generics (snippet 2) */
- instanceDefs = newScope
- staticDefs = newScope
-
- val classInfoAsInMetadata = {
- val ifaces: Array[MSILType] = typ.getInterfaces()
- val superType = if (typ.BaseType() != null) getCLRType(typ.BaseType())
- else if (typ.IsInterface()) definitions.ObjectClass.tpe
- else definitions.AnyClass.tpe; // this branch activates for System.Object only.
- // parents (i.e., base type and interfaces)
- val parents = new scala.collection.mutable.ListBuffer[Type]()
- parents += superType
- for (iface <- ifaces) {
- parents += getCLRType(iface) // here the variance doesn't matter
- }
- // methods, properties, events, fields are entered in a moment
- if (canBeTakenAddressOf) {
- val instanceDefsBoxed = newScope
- ClassInfoType(parents.toList, instanceDefsBoxed, clazzBoxed)
- } else
- ClassInfoType(parents.toList, instanceDefs, clazz)
- }
-
- val staticInfo = ClassInfoType(List(), staticDefs, statics)
-
- clazz.setFlag(flags)
-
- if (canBeTakenAddressOf) {
- clazzBoxed.setInfo( if (ownTypeParams.isEmpty) classInfoAsInMetadata
- else genPolyType(ownTypeParams, classInfoAsInMetadata) )
- clazzBoxed.setFlag(flags)
- val rawValueInfoType = ClassInfoType(definitions.anyvalparam, instanceDefs, clazz)
- clazz.setInfo( if (ownTypeParams.isEmpty) rawValueInfoType
- else genPolyType(ownTypeParams, rawValueInfoType) )
- } else {
- clazz.setInfo( if (ownTypeParams.isEmpty) classInfoAsInMetadata
- else genPolyType(ownTypeParams, classInfoAsInMetadata) )
- }
-
- // TODO I don't remember if statics.setInfo and staticModule.setInfo should also know about type params
- statics.setFlag(Flags.JAVA)
- statics.setInfo(staticInfo)
- staticModule.setFlag(Flags.JAVA)
- staticModule.setInfo(statics.tpe)
-
-
- if (canBeTakenAddressOf) {
- // implicit conversions are owned by staticModule.moduleClass
- createViewFromTo("2Boxed", clazz.tpe, clazzBoxed.tpe, addToboxMethodMap = true, isAddressOf = false)
- // createViewFromTo("2Object", clazz.tpe, definitions.ObjectClass.tpe, addToboxMethodMap = true, isAddressOf = false)
- createViewFromTo("2MgdPtr", clazz.tpe, clazzMgdPtr.tpe, addToboxMethodMap = false, isAddressOf = true)
- // a return can't have type managed-pointer, thus a dereference-conversion is not needed
- // similarly, a method can't declare as return type "boxed valuetype"
- if (!typ.IsEnum) {
- // a synthetic default constructor for raw-type allows `new X' syntax
- createDefaultConstructor(typ)
- }
- }
-
- // import nested types
- for (ntype <- typ.getNestedTypes() if !(ntype.IsNestedPrivate || ntype.IsNestedAssembly || ntype.IsNestedFamANDAssem)
- || ntype.IsInterface /* TODO why shouldn't nested ifaces be type-parsed too? */ )
- {
- val loader = new loaders.MsilFileLoader(new MsilFile(ntype))
- val nclazz = statics.newClass(ntype.Name)
- val nmodule = statics.newModule(ntype.Name)
- nclazz.setInfo(loader)
- nmodule.setInfo(loader)
- staticDefs.enter(nclazz)
- staticDefs.enter(nmodule)
-
- assert(nclazz.companionModule == nmodule, nmodule)
- assert(nmodule.companionClass == nclazz, nclazz)
- }
-
- val fields = typ.getFields()
- for (field <- fields
- if !(field.IsPrivate() || field.IsAssembly() || field.IsFamilyAndAssembly)
- if (getCLRType(field.FieldType) != null)
- ) {
- assert (!field.FieldType.IsPointer && !field.FieldType.IsByRef, "CLR requirement")
- val flags = translateAttributes(field);
- val name = newTermName(field.Name);
- val fieldType =
- if (field.IsLiteral && !field.FieldType.IsEnum && isDefinedAtgetConstant(getCLRType(field.FieldType)))
- ConstantType(getConstant(getCLRType(field.FieldType), field.getValue))
- else
- getCLRType(field.FieldType)
- val owner = if (field.IsStatic()) statics else clazz;
- val sym = owner.newValue(name, NoPosition, flags).setInfo(fieldType);
- // TODO: set private within!!! -> look at typechecker/Namers.scala
- (if (field.IsStatic()) staticDefs else instanceDefs).enter(sym);
- clrTypes.fields(sym) = field;
- }
-
- for (constr <- typ.getConstructors() if !constr.IsStatic() && !constr.IsPrivate() &&
- !constr.IsAssembly() && !constr.IsFamilyAndAssembly() && !constr.HasPtrParamOrRetType())
- createMethod(constr);
-
- // initially also contains getters and setters of properties.
- val methodsSet = new mutable.HashSet[MethodInfo]();
- methodsSet ++= typ.getMethods();
-
- for (prop <- typ.getProperties) {
- val propType: Type = getCLSType(prop.PropertyType);
- if (propType != null) {
- val getter: MethodInfo = prop.GetGetMethod(true);
- val setter: MethodInfo = prop.GetSetMethod(true);
- var gparamsLength: Int = -1;
- if (!(getter == null || getter.IsPrivate || getter.IsAssembly
- || getter.IsFamilyAndAssembly || getter.HasPtrParamOrRetType))
- {
- assert(prop.PropertyType == getter.ReturnType);
- val gparams: Array[ParameterInfo] = getter.GetParameters();
- gparamsLength = gparams.length;
- val name: TermName = if (gparamsLength == 0) prop.Name else nme.apply;
- val flags = translateAttributes(getter);
- val owner: Symbol = if (getter.IsStatic) statics else clazz;
- val methodSym = owner.newMethod(name, NoPosition, flags)
- val mtype: Type = if (gparamsLength == 0) NullaryMethodType(propType) // .NET properties can't be polymorphic
- else methodType(getter, getter.ReturnType)(methodSym)
- methodSym.setInfo(mtype);
- methodSym.setFlag(Flags.ACCESSOR);
- (if (getter.IsStatic) staticDefs else instanceDefs).enter(methodSym)
- clrTypes.methods(methodSym) = getter;
- methodsSet -= getter;
- }
- if (!(setter == null || setter.IsPrivate || setter.IsAssembly
- || setter.IsFamilyAndAssembly || setter.HasPtrParamOrRetType))
- {
- val sparams: Array[ParameterInfo] = setter.GetParameters()
- if(getter != null)
- assert(getter.IsStatic == setter.IsStatic);
- assert(setter.ReturnType == clrTypes.VOID);
- if(getter != null)
- assert(sparams.length == gparamsLength + 1, "" + getter + "; " + setter);
-
- val name: TermName = if (gparamsLength == 0) nme.getterToSetter(prop.Name)
- else nme.update;
- val flags = translateAttributes(setter);
- val mtype = methodType(setter, definitions.UnitClass.tpe);
- val owner: Symbol = if (setter.IsStatic) statics else clazz;
- val methodSym = owner.newMethod(name, NoPosition, flags)
- methodSym.setInfo(mtype(methodSym))
- methodSym.setFlag(Flags.ACCESSOR);
- (if (setter.IsStatic) staticDefs else instanceDefs).enter(methodSym);
- clrTypes.methods(methodSym) = setter;
- methodsSet -= setter;
- }
- }
- }
-
-/* for (event <- typ.GetEvents) {
- // adding += and -= methods to add delegates to an event.
- // raising the event ist not possible from outside the class (this is so
- // generally in .net world)
- val adder: MethodInfo = event.GetAddMethod();
- val remover: MethodInfo = event.GetRemoveMethod();
- if (!(adder == null || adder.IsPrivate || adder.IsAssembly
- || adder.IsFamilyAndAssembly))
- {
- assert(adder.ReturnType == clrTypes.VOID);
- assert(adder.GetParameters().map(_.ParameterType).toList == List(event.EventHandlerType));
- val name = encode("+=");
- val flags = translateAttributes(adder);
- val mtype: Type = methodType(adder, adder.ReturnType);
- createMethod(name, flags, mtype, adder, adder.IsStatic)
- methodsSet -= adder;
- }
- if (!(remover == null || remover.IsPrivate || remover.IsAssembly
- || remover.IsFamilyAndAssembly))
- {
- assert(remover.ReturnType == clrTypes.VOID);
- assert(remover.GetParameters().map(_.ParameterType).toList == List(event.EventHandlerType));
- val name = encode("-=");
- val flags = translateAttributes(remover);
- val mtype: Type = methodType(remover, remover.ReturnType);
- createMethod(name, flags, mtype, remover, remover.IsStatic)
- methodsSet -= remover;
- }
- } */
-
-/* Adds view amounting to syntax sugar for a CLR implicit overload.
- The long-form syntax can also be supported if "methodsSet -= method" (last statement) is removed.
-
- /* remember, there's typ.getMethods and type.GetMethods */
- for (method <- typ.getMethods)
- if(!method.HasPtrParamOrRetType &&
- method.IsPublic && method.IsStatic && method.IsSpecialName &&
- method.Name == "op_Implicit") {
- // create a view: typ => method's return type
- val viewRetType: Type = getCLRType(method.ReturnType)
- val viewParamTypes: List[Type] = method.GetParameters().map(_.ParameterType).map(getCLSType).toList;
- /* The spec says "The operator method shall be defined as a static method on either the operand or return type."
- * We don't consider the declaring type for the purposes of definitions.functionType,
- * instead we regard op_Implicit's argument type and return type as defining the view's signature.
- */
- if (viewRetType != null && !viewParamTypes.contains(null)) {
- /* The check above applies e.g. to System.Decimal that has a conversion from UInt16, a non-CLS type, whose CLS-mapping returns null */
- val funType: Type = definitions.functionType(viewParamTypes, viewRetType);
- val flags = Flags.JAVA | Flags.STATIC | Flags.IMPLICIT; // todo: static? shouldn't be final instead?
- val viewMethodType = (msym: Symbol) => JavaMethodType(msym.newSyntheticValueParams(viewParamTypes), funType)
- val vmsym = createMethod(nme.view_, flags, viewMethodType, method, true);
- methodsSet -= method;
- }
- }
-*/
-
- for (method <- methodsSet.iterator)
- if (!method.IsPrivate() && !method.IsAssembly() && !method.IsFamilyAndAssembly()
- && !method.HasPtrParamOrRetType)
- createMethod(method);
-
- // Create methods and views for delegate support
- if (clrTypes.isDelegateType(typ)) {
- createDelegateView(typ)
- createDelegateChainers(typ)
- }
-
- // for enumerations introduce comparison and bitwise logical operations;
- // the backend will recognize them and replace them with comparison or
- // bitwise logical operations on the primitive underlying type
-
- if (typ.IsEnum) {
- val ENUM_CMP_NAMES = List(nme.EQ, nme.NE, nme.LT, nme.LE, nme.GT, nme.GE);
- val ENUM_BIT_LOG_NAMES = List(nme.OR, nme.AND, nme.XOR);
-
- val flags = Flags.JAVA | Flags.FINAL
- for (cmpName <- ENUM_CMP_NAMES) {
- val enumCmp = clazz.newMethod(cmpName)
- val enumCmpType = JavaMethodType(enumCmp.newSyntheticValueParams(List(clazz.tpe)), definitions.BooleanClass.tpe)
- enumCmp.setFlag(flags).setInfo(enumCmpType)
- instanceDefs.enter(enumCmp)
- }
-
- for (bitLogName <- ENUM_BIT_LOG_NAMES) {
- val enumBitLog = clazz.newMethod(bitLogName)
- val enumBitLogType = JavaMethodType(enumBitLog.newSyntheticValueParams(List(clazz.tpe)), clazz.tpe /* was classInfo, infinite typer */)
- enumBitLog.setFlag(flags).setInfo(enumBitLogType)
- instanceDefs.enter(enumBitLog)
- }
- }
-
- } // parseClass
-
- private def populateMethodTParams(method: MethodBase, methodSym: MethodSymbol) : List[Symbol] = {
- if(!method.IsGeneric) Nil
- else {
- methodTParams.clear
- val newMethodTParams = new scala.collection.mutable.ListBuffer[Symbol]()
-
- // first pass
- for (mvarCILDef <- method.getSortedMVars() ) {
- val mtpname = newTypeName(mvarCILDef.Name.replaceAll("!", "")) // TODO are really all method-level-type-params named in all assemblies out there? (NO)
- val mtpsym = methodSym.newTypeParameter(mtpname)
- methodTParams.put(mvarCILDef.Number, mtpsym)
- newMethodTParams += mtpsym
- // TODO wouldn't the following also be needed later, i.e. during getCLRType
- mtpsym.setInfo(definitions.AnyClass.tpe)
- }
- // second pass
- for (mvarCILDef <- method.getSortedMVars() ) {
- val mtpsym = methodTParams(mvarCILDef.Number)
- mtpsym.setInfo(sig2typeBounds(mvarCILDef)) // we never skip bounds unlike in forJVM
- }
-
- newMethodTParams.toList
- }
- }
-
- private def createMethod(method: MethodBase) {
-
- val flags = translateAttributes(method);
- val owner = if (method.IsStatic()) statics else clazz;
- val methodSym = owner.newMethod(getName(method), NoPosition, flags)
- /* START CLR generics (snippet 3) */
- val newMethodTParams = populateMethodTParams(method, methodSym)
- /* END CLR generics (snippet 3) */
-
- val rettype = if (method.IsConstructor()) clazz.tpe
- else getCLSType(method.asInstanceOf[MethodInfo].ReturnType);
- if (rettype == null) return;
- val mtype = methodType(method, rettype);
- if (mtype == null) return;
-/* START CLR generics (snippet 4) */
- val mInfo = if (method.IsGeneric) genPolyType(newMethodTParams, mtype(methodSym))
- else mtype(methodSym)
-/* END CLR generics (snippet 4) */
-/* START CLR non-generics (snippet 4)
- val mInfo = mtype(methodSym)
- END CLR non-generics (snippet 4) */
- methodSym.setInfo(mInfo)
- (if (method.IsStatic()) staticDefs else instanceDefs).enter(methodSym);
- if (method.IsConstructor())
- clrTypes.constructors(methodSym) = method.asInstanceOf[ConstructorInfo]
- else clrTypes.methods(methodSym) = method.asInstanceOf[MethodInfo];
- }
-
- private def createMethod(name: TermName, flags: Long, args: Array[MSILType], retType: MSILType, method: MethodInfo, statik: Boolean): Symbol = {
- val mtype = methodType(args, getCLSType(retType))
- assert(mtype != null)
- createMethod(name, flags, mtype, method, statik)
- }
-
- private def createMethod(name: TermName, flags: Long, mtype: Symbol => Type, method: MethodInfo, statik: Boolean): Symbol = {
- val methodSym: Symbol = (if (statik) statics else clazz).newMethod(name)
- methodSym.setFlag(flags).setInfo(mtype(methodSym))
- (if (statik) staticDefs else instanceDefs).enter(methodSym)
- if (method != null)
- clrTypes.methods(methodSym) = method
- methodSym
- }
-
- private def createDelegateView(typ: MSILType) = {
- val invoke: MethodInfo = typ.GetMember("Invoke")(0).asInstanceOf[MethodInfo];
- val invokeRetType: Type = getCLRType(invoke.ReturnType);
- val invokeParamTypes: List[Type] =invoke.GetParameters().map(_.ParameterType).map(getCLSType).toList;
- val funType: Type = definitions.functionType(invokeParamTypes, invokeRetType);
-
- val typClrType: Type = getCLRType(typ);
- val flags = Flags.JAVA | Flags.STATIC | Flags.IMPLICIT; // todo: static? think not needed
-
- // create the forward view: delegate => function
- val delegateParamTypes: List[Type] = List(typClrType);
- // not ImplicitMethodType, this is for methods with implicit parameters (not implicit methods)
- val forwardViewMethodType = (msym: Symbol) => JavaMethodType(msym.newSyntheticValueParams(delegateParamTypes), funType)
- val fmsym = createMethod(nme.view_, flags, forwardViewMethodType, null, true);
-
- // create the backward view: function => delegate
- val functionParamTypes: List[Type] = List(funType);
- val backwardViewMethodType = (msym: Symbol) => JavaMethodType(msym.newSyntheticValueParams(functionParamTypes), typClrType)
- val bmsym = createMethod(nme.view_, flags, backwardViewMethodType, null, true);
- }
-
- private def createDelegateChainers(typ: MSILType) = {
- val flags: Long = Flags.JAVA | Flags.FINAL
- val args: Array[MSILType] = Array(typ)
-
- var s = createMethod(encode("+="), flags, args, clrTypes.VOID, clrTypes.DELEGATE_COMBINE, false);
- s = createMethod(encode("-="), flags, args, clrTypes.VOID, clrTypes.DELEGATE_REMOVE, false);
-
- s = createMethod(nme.PLUS, flags, args, typ, clrTypes.DELEGATE_COMBINE, false);
- s = createMethod(nme.MINUS, flags, args, typ, clrTypes.DELEGATE_REMOVE, false);
- }
-
- private def getName(method: MethodBase): TermName = {
-
- def operatorOverload(name : String, paramsArity : Int) : Option[Name] = paramsArity match {
- case 1 => name match {
- // PartitionI.10.3.1
- case "op_Decrement" => Some(encode("--"))
- case "op_Increment" => Some(encode("++"))
- case "op_UnaryNegation" => Some(nme.UNARY_-)
- case "op_UnaryPlus" => Some(nme.UNARY_+)
- case "op_LogicalNot" => Some(nme.UNARY_!)
- case "op_OnesComplement" => Some(nme.UNARY_~)
- /* op_True and op_False have no operator symbol assigned,
- Other methods that will have to be written in full are:
- op_AddressOf & (unary)
- op_PointerDereference * (unary) */
- case _ => None
- }
- case 2 => name match {
- // PartitionI.10.3.2
- case "op_Addition" => Some(nme.ADD)
- case "op_Subtraction" => Some(nme.SUB)
- case "op_Multiply" => Some(nme.MUL)
- case "op_Division" => Some(nme.DIV)
- case "op_Modulus" => Some(nme.MOD)
- case "op_ExclusiveOr" => Some(nme.XOR)
- case "op_BitwiseAnd" => Some(nme.AND)
- case "op_BitwiseOr" => Some(nme.OR)
- case "op_LogicalAnd" => Some(nme.ZAND)
- case "op_LogicalOr" => Some(nme.ZOR)
- case "op_LeftShift" => Some(nme.LSL)
- case "op_RightShift" => Some(nme.ASR)
- case "op_Equality" => Some(nme.EQ)
- case "op_GreaterThan" => Some(nme.GT)
- case "op_LessThan" => Some(nme.LT)
- case "op_Inequality" => Some(nme.NE)
- case "op_GreaterThanOrEqual" => Some(nme.GE)
- case "op_LessThanOrEqual" => Some(nme.LE)
-
- /* op_MemberSelection is reserved in Scala */
-
- /* The standard does not assign operator symbols to op_Assign , op_SignedRightShift , op_UnsignedRightShift ,
- * and op_UnsignedRightShiftAssignment so those names will be used instead to invoke those methods. */
-
- /*
- The remaining binary operators are not overloaded in C# and are therefore not in widespread use. They have to be written in full.
-
- op_RightShiftAssignment >>=
- op_MultiplicationAssignment *=
- op_PointerToMemberSelection ->*
- op_SubtractionAssignment -=
- op_ExclusiveOrAssignment ^=
- op_LeftShiftAssignment <<=
- op_ModulusAssignment %=
- op_AdditionAssignment +=
- op_BitwiseAndAssignment &=
- op_BitwiseOrAssignment |=
- op_Comma ,
- op_DivisionAssignment /=
- */
- case _ => None
- }
- case _ => None
- }
-
- if (method.IsConstructor()) return nme.CONSTRUCTOR;
- val name = method.Name;
- if (method.IsStatic()) {
- if(method.IsSpecialName) {
- val paramsArity = method.GetParameters().size
- // handle operator overload, otherwise handle as any static method
- val operName = operatorOverload(name, paramsArity)
- if (operName.isDefined) { return operName.get; }
- }
- return newTermName(name);
- }
- val params = method.GetParameters();
- name match {
- case "GetHashCode" if (params.length == 0) => nme.hashCode_;
- case "ToString" if (params.length == 0) => nme.toString_;
- case "Finalize" if (params.length == 0) => nme.finalize_;
- case "Equals" if (params.length == 1 && params(0).ParameterType == clrTypes.OBJECT) =>
- nme.equals_;
- case "Invoke" if (clrTypes.isDelegateType(method.DeclaringType)) => nme.apply;
- case _ => newTermName(name);
- }
- }
-
- //##########################################################################
-
- private def methodType(method: MethodBase, rettype: MSILType): Symbol => Type = {
- val rtype = getCLSType(rettype);
- if (rtype == null) null else methodType(method, rtype);
- }
-
- /** Return a method type for the given method. */
- private def methodType(method: MethodBase, rettype: Type): Symbol => Type =
- methodType(method.GetParameters().map(_.ParameterType), rettype);
-
- /** Return a method type for the provided argument types and return type. */
- private def methodType(argtypes: Array[MSILType], rettype: Type): Symbol => Type = {
- def paramType(typ: MSILType): Type =
- if (typ eq clrTypes.OBJECT) definitions.AnyClass.tpe // TODO a hack to compile scalalib, should be definitions.AnyRefClass.tpe
- else getCLSType(typ);
- val ptypes = argtypes.map(paramType).toList;
- if (ptypes.contains(null)) null
- else method => JavaMethodType(method.newSyntheticValueParams(ptypes), rettype);
- }
-
- //##########################################################################
-
- private def getClassType(typ: MSILType): Type = {
- assert(typ != null);
- val res = rootMirror.getClassByName(typ.FullName.replace('+', '.') : TypeName).tpe;
- //if (res.isError())
- // global.reporter.error("unknown class reference " + type.FullName);
- res
- }
-
- private def getCLSType(typ: MSILType): Type = { // getCLS returns non-null for types GenMSIL can handle, be they CLS-compliant or not
- if (typ.IsTMVarUsage())
- /* START CLR generics (snippet 5) */
- getCLRType(typ)
- /* END CLR generics (snippet 5) */
- /* START CLR non-generics (snippet 5)
- null
- END CLR non-generics (snippet 5) */
- else if ( /* TODO hack if UBYE, uncommented, "ambiguous reference to overloaded definition" ensues, for example for System.Math.Max(x, y) */
- typ == clrTypes.USHORT || typ == clrTypes.UINT || typ == clrTypes.ULONG
- /* || typ == clrTypes.UBYTE */
- || typ.IsNotPublic() || typ.IsNestedPrivate()
- || typ.IsNestedAssembly() || typ.IsNestedFamANDAssem()
- || typ.IsPointer()
- || (typ.IsArray() && getCLRType(typ.GetElementType()) == null) /* TODO hack: getCLR instead of getCLS */
- || (typ.IsByRef() && !typ.GetElementType().CanBeTakenAddressOf()))
- null
- else
- getCLRType(typ)
- }
-
- private def getCLRTypeIfPrimitiveNullOtherwise(typ: MSILType): Type =
- if (typ == clrTypes.OBJECT)
- definitions.ObjectClass.tpe;
- else if (typ == clrTypes.VALUE_TYPE)
- definitions.AnyValClass.tpe
- else if (typ == clrTypes.STRING)
- definitions.StringClass.tpe;
- else if (typ == clrTypes.VOID)
- definitions.UnitClass.tpe
- else if (typ == clrTypes.BOOLEAN)
- definitions.BooleanClass.tpe
- else if (typ == clrTypes.CHAR)
- definitions.CharClass.tpe
- else if ((typ == clrTypes.BYTE) || (typ == clrTypes.UBYTE)) // TODO U... is a hack to compile scalalib
- definitions.ByteClass.tpe
- else if ((typ == clrTypes.SHORT) || (typ == clrTypes.SHORT)) // TODO U... is a hack to compile scalalib
- definitions.ShortClass.tpe
- else if ((typ == clrTypes.INT) || (typ == clrTypes.UINT)) // TODO U... is a hack to compile scalalib
- definitions.IntClass.tpe
- else if ((typ == clrTypes.LONG) || (typ == clrTypes.LONG)) // TODO U... is a hack to compile scalalib
- definitions.LongClass.tpe
- else if (typ == clrTypes.FLOAT)
- definitions.FloatClass.tpe
- else if (typ == clrTypes.DOUBLE)
- definitions.DoubleClass.tpe
- else null
-
-
- private def getCLRType(tMSIL: MSILType): Type = {
- var res = getCLRTypeIfPrimitiveNullOtherwise(tMSIL)
- if (res != null) res
- else if (tMSIL.isInstanceOf[ConstructedType]) {
- val ct = tMSIL.asInstanceOf[ConstructedType]
- /* START CLR generics (snippet 6) */
- val cttpArgs = ct.typeArgs.map(tmsil => getCLRType(tmsil)).toList
- appliedType(getCLRType(ct.instantiatedType), cttpArgs)
- /* END CLR generics (snippet 6) */
- /* START CLR non-generics (snippet 6)
- getCLRType(ct.instantiatedType)
- END CLR non-generics (snippet 6) */
- } else if (tMSIL.isInstanceOf[TMVarUsage]) {
- /* START CLR generics (snippet 7) */
- val tVarUsage = tMSIL.asInstanceOf[TMVarUsage]
- val tVarNumber = tVarUsage.Number
- if (tVarUsage.isTVar) classTParams(tVarNumber).typeConstructor // shouldn't fail, just return definitions.AnyClass.tpe at worst
- else methodTParams(tVarNumber).typeConstructor // shouldn't fail, just return definitions.AnyClass.tpe at worst
- /* END CLR generics (snippet 7) */
- /* START CLR non-generics (snippet 7)
- null // definitions.ObjectClass.tpe
- END CLR non-generics (snippet 7) */
- } else if (tMSIL.IsArray()) {
- var elemtp = getCLRType(tMSIL.GetElementType())
- // cut&pasted from ClassfileParser
- // make unbounded Array[T] where T is a type variable into Array[T with Object]
- // (this is necessary because such arrays have a representation which is incompatible
- // with arrays of primitive types).
- // TODO does that incompatibility also apply to .NET?
- if (elemtp.typeSymbol.isAbstractType && !(elemtp <:< definitions.ObjectClass.tpe))
- elemtp = intersectionType(List(elemtp, definitions.ObjectClass.tpe))
- appliedType(definitions.ArrayClass.tpe, List(elemtp))
- } else {
- res = clrTypes.sym2type.get(tMSIL) match {
- case Some(sym) => sym.tpe
- case None => if (tMSIL.IsByRef && tMSIL.GetElementType.IsValueType) {
- val addressed = getCLRType(tMSIL.GetElementType)
- val clasym = addressed.typeSymbolDirect // TODO should be .typeSymbol?
- clasym.info.load(clasym)
- val secondAttempt = clrTypes.sym2type.get(tMSIL)
- secondAttempt match { case Some(sym) => sym.tpe
- case None => null
- }
- } else getClassType(tMSIL)
- }
- if (res == null)
- null // TODO new RuntimeException()
- else res
- }
- }
-
- // the values are Java-Box-Classes (e.g. Integer, Boolean, Character)
- // java.lang.Number to get the value (if a number, not for boolean, character)
- // see ch.epfl.lamp.compiler.msil.util.PEStream.java
- def getConstant(constType: Type, value: Object): Constant = {
- val typeClass = constType.typeSymbol
- if (typeClass == definitions.BooleanClass)
- Constant(value.asInstanceOf[java.lang.Boolean].booleanValue)
- else if (typeClass == definitions.ByteClass)
- Constant(value.asInstanceOf[java.lang.Number].byteValue)
- else if (typeClass == definitions.ShortClass)
- Constant(value.asInstanceOf[java.lang.Number].shortValue)
- else if (typeClass == definitions.CharClass)
- Constant(value.asInstanceOf[java.lang.Character].charValue)
- else if (typeClass == definitions.IntClass)
- Constant(value.asInstanceOf[java.lang.Number].intValue)
- else if (typeClass == definitions.LongClass)
- Constant(value.asInstanceOf[java.lang.Number].longValue)
- else if (typeClass == definitions.FloatClass)
- Constant(value.asInstanceOf[java.lang.Number].floatValue)
- else if (typeClass == definitions.DoubleClass)
- Constant(value.asInstanceOf[java.lang.Number].doubleValue)
- else if (typeClass == definitions.StringClass)
- Constant(value.asInstanceOf[java.lang.String])
- else
- abort("illegal value: " + value + ", class-symbol: " + typeClass)
- }
-
- def isDefinedAtgetConstant(constType: Type): Boolean = {
- val typeClass = constType.typeSymbol
- if ( (typeClass == definitions.BooleanClass)
- || (typeClass == definitions.ByteClass)
- || (typeClass == definitions.ShortClass)
- || (typeClass == definitions.CharClass)
- || (typeClass == definitions.IntClass)
- || (typeClass == definitions.LongClass)
- || (typeClass == definitions.FloatClass)
- || (typeClass == definitions.DoubleClass)
- || (typeClass == definitions.StringClass)
- )
- true
- else
- false
- }
-
- private def translateAttributes(typ: MSILType): Long = {
- var flags: Long = Flags.JAVA;
- if (typ.IsNotPublic() || typ.IsNestedPrivate()
- || typ.IsNestedAssembly() || typ.IsNestedFamANDAssem())
- flags = flags | Flags.PRIVATE;
- else if (typ.IsNestedFamily() || typ.IsNestedFamORAssem())
- flags = flags | Flags.PROTECTED;
- if (typ.IsAbstract())
- flags = flags | Flags.ABSTRACT;
- if (typ.IsSealed())
- flags = flags | Flags.FINAL;
- if (typ.IsInterface())
- flags = flags | Flags.INTERFACE | Flags.TRAIT | Flags.ABSTRACT;
-
- flags
- }
-
- private def translateAttributes(field: FieldInfo): Long = {
- var flags: Long = Flags.JAVA;
- if (field.IsPrivate() || field.IsAssembly() || field.IsFamilyAndAssembly())
- flags = flags | Flags.PRIVATE;
- else if (field.IsFamily() || field.IsFamilyOrAssembly())
- flags = flags | Flags.PROTECTED;
- if (field.IsInitOnly() || field.IsLiteral())
- flags = flags | Flags.FINAL;
- else
- flags = flags | Flags.MUTABLE;
- if (field.IsStatic)
- flags = flags | Flags.STATIC
-
- flags
- }
-
- private def translateAttributes(method: MethodBase): Long = {
- var flags: Long = Flags.JAVA;
- if (method.IsPrivate() || method.IsAssembly() || method.IsFamilyAndAssembly())
- flags = flags | Flags.PRIVATE;
- else if (method.IsFamily() || method.IsFamilyOrAssembly())
- flags = flags | Flags.PROTECTED;
- if (method.IsAbstract())
- flags = flags | Flags.DEFERRED;
- if (method.IsStatic)
- flags = flags | Flags.STATIC
-
- flags
- }
-}
diff --git a/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala b/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala
index bacd8c39e1..5fbc15f858 100644
--- a/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala
+++ b/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala
@@ -8,8 +8,6 @@ package transform
import symtab._
import Flags._
-import scala.collection.{ mutable, immutable }
-import scala.collection.mutable.ListBuffer
abstract class AddInterfaces extends InfoTransform { self: Erasure =>
import global._ // the global environment
@@ -94,7 +92,7 @@ abstract class AddInterfaces extends InfoTransform { self: Erasure =>
impl.typeOfThis = iface.typeOfThis
impl.thisSym setName iface.thisSym.name
}
- impl.sourceFile = iface.sourceFile
+ impl.associatedFile = iface.sourceFile
if (inClass)
iface.owner.info.decls enter impl
@@ -111,7 +109,7 @@ abstract class AddInterfaces extends InfoTransform { self: Erasure =>
def implClass(iface: Symbol): Symbol = {
iface.info
- implClassMap.getOrElse(iface, atPhase(implClassPhase) {
+ implClassMap.getOrElse(iface, enteringPhase(implClassPhase) {
if (iface.implClass eq NoSymbol)
debuglog(s"${iface.fullLocationString} has no implClass yet, creating it now.")
else
@@ -196,7 +194,7 @@ abstract class AddInterfaces extends InfoTransform { self: Erasure =>
case PolyType(_, restpe) =>
implType(restpe)
}
- implSym setInfo implType(beforeErasure(iface.info))
+ implSym setInfo implType(enteringErasure(iface.info))
}
override def load(clazz: Symbol) { complete(clazz) }
@@ -317,10 +315,10 @@ abstract class AddInterfaces extends InfoTransform { self: Erasure =>
// body until now, because the typer knows that Any has no
// constructor and won't accept a call to super.init.
assert((clazz isSubClass AnyValClass) || clazz.info.parents.isEmpty, clazz)
- Block(List(Apply(gen.mkSuperSelect, Nil)), expr)
+ Block(List(Apply(gen.mkSuperInitCall, Nil)), expr)
case Block(stats, expr) =>
- // needs `hasSymbol` check because `supercall` could be a block (named / default args)
+ // needs `hasSymbolField` check because `supercall` could be a block (named / default args)
val (presuper, supercall :: rest) = stats span (t => t.hasSymbolWhich(_ hasFlag PRESUPER))
treeCopy.Block(tree, presuper ::: (supercall :: mixinConstructorCalls ::: rest), expr)
}
@@ -352,7 +350,7 @@ abstract class AddInterfaces extends InfoTransform { self: Erasure =>
val mix1 = mix
if (mix == tpnme.EMPTY) mix
else {
- val ps = beforeErasure {
+ val ps = enteringErasure {
sym.info.parents dropWhile (p => p.symbol.name != mix)
}
assert(!ps.isEmpty, tree);
diff --git a/src/compiler/scala/tools/nsc/transform/CleanUp.scala b/src/compiler/scala/tools/nsc/transform/CleanUp.scala
index 0c9cb31d58..39460ef004 100644
--- a/src/compiler/scala/tools/nsc/transform/CleanUp.scala
+++ b/src/compiler/scala/tools/nsc/transform/CleanUp.scala
@@ -15,6 +15,7 @@ abstract class CleanUp extends Transform with ast.TreeDSL {
import global._
import definitions._
import CODE._
+ import treeInfo.StripCast
/** the following two members override abstract members in Transform */
val phaseName: String = "cleanup"
@@ -45,7 +46,7 @@ abstract class CleanUp extends Transform with ast.TreeDSL {
result
}
private def transformTemplate(tree: Tree) = {
- val Template(parents, self, body) = tree
+ val Template(_, _, body) = tree
clearStatics()
val newBody = transformTrees(body)
val templ = deriveTemplate(tree)(_ => transformTrees(newStaticMembers.toList) ::: newBody)
@@ -68,12 +69,6 @@ abstract class CleanUp extends Transform with ast.TreeDSL {
case "mono-cache" => MONO_CACHE
case "poly-cache" => POLY_CACHE
}
-
- def shouldRewriteTry(tree: Try) = {
- val sym = tree.tpe.typeSymbol
- forMSIL && (sym != UnitClass) && (sym != NothingClass)
- }
-
private def typedWithPos(pos: Position)(tree: Tree) =
localTyper.typedPos(pos)(tree)
@@ -119,7 +114,7 @@ abstract class CleanUp extends Transform with ast.TreeDSL {
}
def addStaticMethodToClass(forBody: (Symbol, Symbol) => Tree): Symbol = {
- val methSym = currentClass.newMethod(mkTerm(nme.reflMethodName), ad.pos, STATIC | SYNTHETIC)
+ val methSym = currentClass.newMethod(mkTerm(nme.reflMethodName.toString), ad.pos, STATIC | SYNTHETIC)
val params = methSym.newSyntheticValueParams(List(ClassClass.tpe))
methSym setInfoAndEnter MethodType(params, MethodClass.tpe)
@@ -437,19 +432,31 @@ abstract class CleanUp extends Transform with ast.TreeDSL {
* is a value type (int et al.) in which case it must cast to the boxed version
* because invoke only returns object and erasure made sure the result is
* expected to be an AnyRef. */
- val t: Tree = ad.symbol.tpe match {
- case MethodType(mparams, resType) =>
- assert(params.length == mparams.length, mparams)
-
- typedPos {
- val sym = currentOwner.newValue(mkTerm("qual"), ad.pos) setInfo qual0.tpe
- qual = REF(sym)
+ val t: Tree = {
+ val (mparams, resType) = ad.symbol.tpe match {
+ case MethodType(mparams, resType) =>
+ assert(params.length == mparams.length, ((params, mparams)))
+ (mparams, resType)
+ case tpe @ OverloadedType(pre, alts) =>
+ unit.warning(ad.pos, s"Overloaded type reached the backend! This is a bug in scalac.\n Symbol: ${ad.symbol}\n Overloads: $tpe\n Arguments: " + ad.args.map(_.tpe))
+ alts filter (_.paramss.flatten.size == params.length) map (_.tpe) match {
+ case mt @ MethodType(mparams, resType) :: Nil =>
+ unit.warning(NoPosition, "Only one overload has the right arity, proceeding with overload " + mt)
+ (mparams, resType)
+ case _ =>
+ unit.error(ad.pos, "Cannot resolve overload.")
+ (Nil, NoType)
+ }
+ }
+ typedPos {
+ val sym = currentOwner.newValue(mkTerm("qual"), ad.pos) setInfo qual0.tpe
+ qual = REF(sym)
- BLOCK(
- VAL(sym) === qual0,
- callAsReflective(mparams map (_.tpe), resType)
- )
- }
+ BLOCK(
+ VAL(sym) === qual0,
+ callAsReflective(mparams map (_.tpe), resType)
+ )
+ }
}
/* For testing purposes, the dynamic application's condition
@@ -530,10 +537,9 @@ abstract class CleanUp extends Transform with ast.TreeDSL {
* constructor. */
case Template(parents, self, body) =>
localTyper = typer.atOwner(tree, currentClass)
- if (forMSIL) savingStatics( transformTemplate(tree) )
- else transformTemplate(tree)
+ transformTemplate(tree)
- case Literal(c) if (c.tag == ClazzTag) && !forMSIL=>
+ case Literal(c) if c.tag == ClazzTag =>
val tpe = c.typeValue
typedWithPos(tree.pos) {
if (isPrimitiveValueClass(tpe.typeSymbol)) {
@@ -546,24 +552,6 @@ abstract class CleanUp extends Transform with ast.TreeDSL {
else tree
}
- /* MSIL requires that the stack is empty at the end of a try-block.
- * Hence, we here rewrite all try blocks with a result != {Unit, All} such that they
- * store their result in a local variable. The catch blocks are adjusted as well.
- * The try tree is subsituted by a block whose result expression is read of that variable. */
- case theTry @ Try(block, catches, finalizer) if shouldRewriteTry(theTry) =>
- def transformTry = {
- val tpe = theTry.tpe.widen
- val tempVar = currentOwner.newVariable(mkTerm(nme.EXCEPTION_RESULT_PREFIX), theTry.pos).setInfo(tpe)
- def assignBlock(rhs: Tree) = super.transform(BLOCK(Ident(tempVar) === transform(rhs)))
-
- val newBlock = assignBlock(block)
- val newCatches = for (CaseDef(pattern, guard, body) <- catches) yield
- (CASE(super.transform(pattern)) IF (super.transform(guard))) ==> assignBlock(body)
- val newTry = Try(newBlock, newCatches, super.transform(finalizer))
-
- typedWithPos(theTry.pos)(BLOCK(VAL(tempVar) === EmptyTree, newTry, Ident(tempVar)))
- }
- transformTry
/*
* This transformation should identify Scala symbol invocations in the tree and replace them
* with references to a static member. Also, whenever a class has at least a single symbol invocation
@@ -606,14 +594,16 @@ abstract class CleanUp extends Transform with ast.TreeDSL {
}
transformApply
- // This transform replaces Array(Predef.wrapArray(Array(...)), <tag>)
- // with just Array(...)
- case Apply(appMeth, List(Apply(wrapRefArrayMeth, List(array)), _))
- if (wrapRefArrayMeth.symbol == Predef_wrapRefArray &&
- appMeth.symbol == ArrayModule_overloadedApply.suchThat {
- _.tpe.resultType.dealias.typeSymbol == ObjectClass
- }) =>
- super.transform(array)
+ // Replaces `Array(Predef.wrapArray(ArrayValue(...).$asInstanceOf[...]), <tag>)`
+ // with just `ArrayValue(...).$asInstanceOf[...]`
+ //
+ // See SI-6611; we must *only* do this for literal vararg arrays.
+ case Apply(appMeth, List(Apply(wrapRefArrayMeth, List(arg @ StripCast(ArrayValue(_, _)))), _))
+ if wrapRefArrayMeth.symbol == Predef_wrapRefArray && appMeth.symbol == ArrayModule_genericApply =>
+ super.transform(arg)
+ case Apply(appMeth, List(elem0, Apply(wrapArrayMeth, List(rest @ ArrayValue(elemtpt, _)))))
+ if wrapArrayMeth.symbol == Predef_wrapArray(elemtpt.tpe) && appMeth.symbol == ArrayModule_apply(elemtpt.tpe) =>
+ super.transform(treeCopy.ArrayValue(rest, rest.elemtpt, elem0 :: rest.elems))
case _ =>
super.transform(tree)
@@ -630,9 +620,8 @@ abstract class CleanUp extends Transform with ast.TreeDSL {
// create a symbol for the static field
val stfieldSym = (
currentClass.newVariable(mkTerm("symbol$"), pos, PRIVATE | STATIC | SYNTHETIC | FINAL)
- setInfo SymbolClass.tpe
+ setInfoAndEnter SymbolClass.tpe
)
- currentClass.info.decls enter stfieldSym
// create field definition and initialization
val stfieldDef = theTyper.typedPos(pos)(VAL(stfieldSym) === rhs)
diff --git a/src/compiler/scala/tools/nsc/transform/Constructors.scala b/src/compiler/scala/tools/nsc/transform/Constructors.scala
index ec0797acb5..e99b42a402 100644
--- a/src/compiler/scala/tools/nsc/transform/Constructors.scala
+++ b/src/compiler/scala/tools/nsc/transform/Constructors.scala
@@ -60,7 +60,7 @@ abstract class Constructors extends Transform with ast.TreeDSL {
// The constructor parameter corresponding to an accessor
def parameter(acc: Symbol): Symbol =
- parameterNamed(nme.getterName(acc.originalName))
+ parameterNamed(nme.getterName(acc.originalName.toTermName))
// The constructor parameter with given name. This means the parameter
// has given name, or starts with given name, and continues with a `$` afterwards.
@@ -130,7 +130,7 @@ abstract class Constructors extends Transform with ast.TreeDSL {
if (from.name != nme.OUTER ||
from.tpe.typeSymbol.isPrimitiveValueClass) result
else localTyper.typedPos(to.pos) {
- IF (from OBJ_EQ NULL) THEN Throw(NullPointerExceptionClass.tpe) ELSE result
+ IF (from OBJ_EQ NULL) THEN Throw(NewFromConstructor(NPEConstructor)) ELSE result
}
}
@@ -281,7 +281,7 @@ abstract class Constructors extends Transform with ast.TreeDSL {
specializedStats find {
case Assign(sel @ Select(This(_), _), rhs) =>
( (sel.symbol hasFlag SPECIALIZED)
- && (nme.unspecializedName(nme.localToGetter(sel.symbol.name)) == nme.localToGetter(sym.name))
+ && (nme.unspecializedName(nme.localToGetter(sel.symbol.name.toTermName)) == nme.localToGetter(sym.name.toTermName))
)
case _ => false
}
@@ -399,7 +399,7 @@ abstract class Constructors extends Transform with ast.TreeDSL {
def addGetter(sym: Symbol): Symbol = {
val getr = addAccessor(
- sym, nme.getterName(sym.name), getterFlags(sym.flags))
+ sym, nme.getterName(sym.name.toTermName), getterFlags(sym.flags))
getr setInfo MethodType(List(), sym.tpe)
defBuf += localTyper.typedPos(sym.pos)(DefDef(getr, Select(This(clazz), sym)))
getr
@@ -408,7 +408,7 @@ abstract class Constructors extends Transform with ast.TreeDSL {
def addSetter(sym: Symbol): Symbol = {
sym setFlag MUTABLE
val setr = addAccessor(
- sym, nme.getterToSetter(nme.getterName(sym.name)), setterFlags(sym.flags))
+ sym, nme.getterToSetter(nme.getterName(sym.name.toTermName)), setterFlags(sym.flags))
setr setInfo MethodType(setr.newSyntheticValueParams(List(sym.tpe)), UnitClass.tpe)
defBuf += localTyper.typed {
//util.trace("adding setter def for "+setr) {
@@ -422,7 +422,7 @@ abstract class Constructors extends Transform with ast.TreeDSL {
def ensureAccessor(sym: Symbol)(acc: => Symbol) =
if (sym.owner == clazz && !sym.isMethod && sym.isPrivate) { // there's an access to a naked field of the enclosing class
- var getr = acc
+ val getr = acc
getr makeNotPrivate clazz
getr
} else {
@@ -528,7 +528,8 @@ abstract class Constructors extends Transform with ast.TreeDSL {
(pre ::: supercalls, rest)
}
- var (uptoSuperStats, remainingConstrStats) = splitAtSuper(constrStatBuf.toList)
+ val (uptoSuperStats, remainingConstrStats0) = splitAtSuper(constrStatBuf.toList)
+ var remainingConstrStats = remainingConstrStats0
/** XXX This is not corect: remainingConstrStats.nonEmpty excludes too much,
* but excluding it includes too much. The constructor sequence being mimicked
diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala
index 7b9b13ae1c..13d3bb23cb 100644
--- a/src/compiler/scala/tools/nsc/transform/Erasure.scala
+++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala
@@ -172,7 +172,7 @@ abstract class Erasure extends AddInterfaces
/** The Java signature of type 'info', for symbol sym. The symbol is used to give the right return
* type for constructors.
*/
- def javaSig(sym0: Symbol, info: Type): Option[String] = beforeErasure {
+ def javaSig(sym0: Symbol, info: Type): Option[String] = enteringErasure {
val isTraitSignature = sym0.enclClass.isTrait
def superSig(parents: List[Type]) = {
@@ -206,7 +206,7 @@ abstract class Erasure extends AddInterfaces
// Anything which could conceivably be a module (i.e. isn't known to be
// a type parameter or similar) must go through here or the signature is
// likely to end up with Foo<T>.Empty where it needs Foo<T>.Empty$.
- def fullNameInSig(sym: Symbol) = "L" + beforeIcode(sym.javaBinaryName)
+ def fullNameInSig(sym: Symbol) = "L" + enteringIcode(sym.javaBinaryName)
def jsig(tp0: Type, existentiallyBound: List[Symbol] = Nil, toplevel: Boolean = false, primitiveOK: Boolean = true): String = {
val tp = tp0.dealias
@@ -398,7 +398,7 @@ abstract class Erasure extends AddInterfaces
val bridgeTarget = mutable.HashMap[Symbol, Symbol]()
var bridges = List[Tree]()
- val opc = beforeExplicitOuter {
+ val opc = enteringExplicitOuter {
new overridingPairs.Cursor(root) {
override def parents = List(root.info.firstParent)
override def exclude(sym: Symbol) = !sym.isMethod || sym.isPrivate || super.exclude(sym)
@@ -410,7 +410,7 @@ abstract class Erasure extends AddInterfaces
val member = opc.overriding
val other = opc.overridden
//println("bridge? " + member + ":" + member.tpe + member.locationString + " to " + other + ":" + other.tpe + other.locationString)//DEBUG
- if (beforeExplicitOuter(!member.isDeferred))
+ if (enteringExplicitOuter(!member.isDeferred))
checkPair(member, other)
opc.next
@@ -440,11 +440,11 @@ abstract class Erasure extends AddInterfaces
sm"""bridge generated for member ${fulldef(member)}
|which overrides ${fulldef(other)}
|clashes with definition of $what;
- |both have erased type ${afterPostErasure(bridge.tpe)}""")
+ |both have erased type ${exitingPostErasure(bridge.tpe)}""")
}
for (bc <- root.baseClasses) {
if (settings.debug.value)
- afterPostErasure(println(
+ exitingPostErasure(println(
sm"""check bridge overrides in $bc
|${bc.info.nonPrivateDecl(bridge.name)}
|${site.memberType(bridge)}
@@ -453,13 +453,13 @@ abstract class Erasure extends AddInterfaces
def overriddenBy(sym: Symbol) =
sym.matchingSymbol(bc, site).alternatives filter (sym => !sym.isBridge)
- for (overBridge <- afterPostErasure(overriddenBy(bridge))) {
+ for (overBridge <- exitingPostErasure(overriddenBy(bridge))) {
if (overBridge == member) {
clashError("the member itself")
} else {
val overMembers = overriddenBy(member)
if (!overMembers.exists(overMember =>
- afterPostErasure(overMember.tpe =:= overBridge.tpe))) {
+ exitingPostErasure(overMember.tpe =:= overBridge.tpe))) {
clashError(fulldef(overBridge))
}
}
@@ -470,7 +470,7 @@ abstract class Erasure extends AddInterfaces
def checkPair(member: Symbol, other: Symbol) {
val otpe = specialErasure(root)(other.tpe)
- val bridgeNeeded = afterErasure (
+ val bridgeNeeded = exitingErasure (
!(other.tpe =:= member.tpe) &&
!(deconstMap(other.tpe) =:= deconstMap(member.tpe)) &&
{ var e = bridgesScope.lookupEntry(member.name)
@@ -482,7 +482,7 @@ abstract class Erasure extends AddInterfaces
if (!bridgeNeeded)
return
- val newFlags = (member.flags | BRIDGE) & ~(ACCESSOR | DEFERRED | LAZY | lateDEFERRED)
+ val newFlags = (member.flags | BRIDGE | ARTIFACT) & ~(ACCESSOR | DEFERRED | LAZY | lateDEFERRED)
val bridge = other.cloneSymbolImpl(root, newFlags) setPos root.pos
debuglog("generating bridge from %s (%s): %s to %s: %s".format(
@@ -497,9 +497,9 @@ abstract class Erasure extends AddInterfaces
if (!(member.tpe exists (_.typeSymbol.isDerivedValueClass)) ||
checkBridgeOverrides(member, other, bridge)) {
- afterErasure(root.info.decls enter bridge)
+ exitingErasure(root.info.decls enter bridge)
if (other.owner == root) {
- afterErasure(root.info.decls.unlink(other))
+ exitingErasure(root.info.decls.unlink(other))
toBeRemoved += other
}
@@ -508,7 +508,7 @@ abstract class Erasure extends AddInterfaces
}
}
- def makeBridgeDefDef(bridge: Symbol, member: Symbol, other: Symbol) = afterErasure {
+ def makeBridgeDefDef(bridge: Symbol, member: Symbol, other: Symbol) = exitingErasure {
// type checking ensures we can safely call `other`, but unless `member.tpe <:< other.tpe`,
// calling `member` is not guaranteed to succeed in general, there's
// nothing we can do about this, except for an unapply: when this subtype test fails,
@@ -519,10 +519,10 @@ abstract class Erasure extends AddInterfaces
def maybeWrap(bridgingCall: Tree): Tree = {
val guardExtractor = ( // can't statically know which member is going to be selected, so don't let this depend on member.isSynthetic
(member.name == nme.unapply || member.name == nme.unapplySeq)
- && !afterErasure((member.tpe <:< other.tpe))) // no static guarantees (TODO: is the subtype test ever true?)
+ && !exitingErasure((member.tpe <:< other.tpe))) // no static guarantees (TODO: is the subtype test ever true?)
import CODE._
- val _false = FALSE_typed
+ val _false = FALSE
val pt = member.tpe.resultType
lazy val zero =
if (_false.tpe <:< pt) _false
@@ -724,19 +724,11 @@ abstract class Erasure extends AddInterfaces
case Apply(TypeApply(sel @ Select(qual, name), List(targ)), List())
if tree.symbol == Any_asInstanceOf =>
val qual1 = typedQualifier(qual, NOmode, ObjectClass.tpe) // need to have an expected type, see #3037
- val qualClass = qual1.tpe.typeSymbol
-/*
- val targClass = targ.tpe.typeSymbol
- if (isNumericValueClass(qualClass) && isNumericValueClass(targClass))
- // convert numeric type casts
- atPos(tree.pos)(Apply(Select(qual1, "to" + targClass.name), List()))
- else
-*/
if (isPrimitiveValueType(targ.tpe) || isErasedValueType(targ.tpe)) {
val noNullCheckNeeded = targ.tpe match {
case ErasedValueType(tref) =>
- atPhase(currentRun.erasurePhase) {
+ enteringPhase(currentRun.erasurePhase) {
isPrimitiveValueClass(erasedValueClassArg(tref).typeSymbol)
}
case _ =>
@@ -744,7 +736,6 @@ abstract class Erasure extends AddInterfaces
}
if (noNullCheckNeeded) unbox(qual1, targ.tpe)
else {
- def nullConst = Literal(Constant(null)) setType NullClass.tpe
val untyped =
// util.trace("new asinstanceof test") {
gen.evalOnce(qual1, context.owner, context.unit) { qual =>
@@ -822,7 +813,7 @@ abstract class Erasure extends AddInterfaces
(tree.attachments.get[TypeRefAttachment]: @unchecked) match {
case Some(itype) =>
val tref = itype.tpe
- val argPt = atPhase(currentRun.erasurePhase)(erasedValueClassArg(tref))
+ val argPt = enteringPhase(currentRun.erasurePhase)(erasedValueClassArg(tref))
log(s"transforming inject $arg -> $tref/$argPt")
val result = typed(arg, mode, argPt)
log(s"transformed inject $arg -> $tref/$argPt = $result:${result.tpe}")
@@ -866,8 +857,7 @@ abstract class Erasure extends AddInterfaces
alt => alt == first || !(first.tpe looselyMatches alt.tpe)
}
if (tree.symbol ne sym1) {
- tree1.symbol = sym1
- tree1.tpe = sym1.tpe
+ tree1 setSymbol sym1 setType sym1.tpe
}
}
tree1
@@ -895,20 +885,20 @@ abstract class Erasure extends AddInterfaces
private def checkNoDoubleDefs(root: Symbol) {
def doubleDefError(sym1: Symbol, sym2: Symbol) {
// the .toString must also be computed at the earlier phase
- val tpe1 = afterRefchecks(root.thisType.memberType(sym1))
- val tpe2 = afterRefchecks(root.thisType.memberType(sym2))
+ val tpe1 = exitingRefchecks(root.thisType.memberType(sym1))
+ val tpe2 = exitingRefchecks(root.thisType.memberType(sym2))
if (!tpe1.isErroneous && !tpe2.isErroneous)
unit.error(
if (sym1.owner == root) sym1.pos else root.pos,
(if (sym1.owner == sym2.owner) "double definition:\n"
else if (sym1.owner == root) "name clash between defined and inherited member:\n"
else "name clash between inherited members:\n") +
- sym1 + ":" + afterRefchecks(tpe1.toString) +
+ sym1 + ":" + exitingRefchecks(tpe1.toString) +
(if (sym1.owner == root) "" else sym1.locationString) + " and\n" +
- sym2 + ":" + afterRefchecks(tpe2.toString) +
+ sym2 + ":" + exitingRefchecks(tpe2.toString) +
(if (sym2.owner == root) " at line " + (sym2.pos).line else sym2.locationString) +
"\nhave same type" +
- (if (afterRefchecks(tpe1 =:= tpe2)) "" else " after erasure: " + afterPostErasure(sym1.tpe)))
+ (if (exitingRefchecks(tpe1 =:= tpe2)) "" else " after erasure: " + exitingPostErasure(sym1.tpe)))
sym1.setInfo(ErrorType)
}
@@ -918,7 +908,7 @@ abstract class Erasure extends AddInterfaces
if (e.sym.isTerm) {
var e1 = decls.lookupNextEntry(e)
while (e1 ne null) {
- if (afterPostErasure(e1.sym.info =:= e.sym.info)) doubleDefError(e.sym, e1.sym)
+ if (exitingPostErasure(e1.sym.info =:= e.sym.info)) doubleDefError(e.sym, e1.sym)
e1 = decls.lookupNextEntry(e1)
}
}
@@ -926,16 +916,17 @@ abstract class Erasure extends AddInterfaces
}
val opc = new overridingPairs.Cursor(root) {
- override def exclude(sym: Symbol): Boolean =
- (!sym.isTerm || sym.isPrivate || super.exclude(sym)
- // specialized members have no type history before 'specialize', causing double def errors for curried defs
- || !sym.hasTypeAt(currentRun.refchecksPhase.id))
+ override def exclude(sym: Symbol): Boolean = (
+ !sym.isTerm || sym.isPrivate || super.exclude(sym)
+ // specialized members have no type history before 'specialize', causing double def errors for curried defs
+ || !sym.hasTypeAt(currentRun.refchecksPhase.id)
+ )
override def matches(sym1: Symbol, sym2: Symbol): Boolean =
- afterPostErasure(sym1.tpe =:= sym2.tpe)
+ exitingPostErasure(sym1.tpe =:= sym2.tpe)
}
while (opc.hasNext) {
- if (!afterRefchecks(
+ if (!exitingRefchecks(
root.thisType.memberType(opc.overriding) matches
root.thisType.memberType(opc.overridden))) {
debuglog("" + opc.overriding.locationString + " " +
@@ -954,8 +945,8 @@ abstract class Erasure extends AddInterfaces
for (member <- root.info.nonPrivateMember(other.name).alternatives) {
if (member != other &&
!(member hasFlag BRIDGE) &&
- afterErasure(member.tpe =:= other.tpe) &&
- !afterRefchecks(
+ exitingErasure(member.tpe =:= other.tpe) &&
+ !exitingRefchecks(
root.thisType.memberType(member) matches root.thisType.memberType(other))) {
debuglog("" + member.locationString + " " + member.infosString + other.locationString + " " + other.infosString);
doubleDefError(member, other)
@@ -1051,17 +1042,17 @@ abstract class Erasure extends AddInterfaces
Apply(Select(qual, cmpOp), List(gen.mkAttributedQualifier(targ.tpe)))
}
case RefinedType(parents, decls) if (parents.length >= 2) =>
- // Optimization: don't generate isInstanceOf tests if the static type
- // conforms, because it always succeeds. (Or at least it had better.)
- // At this writing the pattern matcher generates some instance tests
- // involving intersections where at least one parent is statically known true.
- // That needs fixing, but filtering the parents here adds an additional
- // level of robustness (in addition to the short term fix.)
- val parentTests = parents filterNot (qual.tpe <:< _)
-
- if (parentTests.isEmpty) Literal(Constant(true))
- else gen.evalOnce(qual, currentOwner, unit) { q =>
- atPos(tree.pos) {
+ gen.evalOnce(qual, currentOwner, unit) { q =>
+ // Optimization: don't generate isInstanceOf tests if the static type
+ // conforms, because it always succeeds. (Or at least it had better.)
+ // At this writing the pattern matcher generates some instance tests
+ // involving intersections where at least one parent is statically known true.
+ // That needs fixing, but filtering the parents here adds an additional
+ // level of robustness (in addition to the short term fix.)
+ val parentTests = parents filterNot (qual.tpe <:< _)
+
+ if (parentTests.isEmpty) Literal(Constant(true))
+ else atPos(tree.pos) {
parentTests map mkIsInstanceOf(q) reduceRight gen.mkAnd
}
}
@@ -1077,6 +1068,7 @@ abstract class Erasure extends AddInterfaces
} else if (fn.symbol == Any_isInstanceOf) {
preEraseIsInstanceOf
} else if (fn.symbol.owner.isRefinementClass && !fn.symbol.isOverridingSymbol) {
+ // !!! Another spot where we produce overloaded types (see test run/t6301)
ApplyDynamic(qualifier, args) setSymbol fn.symbol setPos tree.pos
} else if (fn.symbol.isMethodWithExtension && !fn.symbol.tpe.isErroneous) {
Apply(gen.mkAttributedRef(extensionMethods.extensionMethod(fn.symbol)), qualifier :: args)
@@ -1135,7 +1127,8 @@ abstract class Erasure extends AddInterfaces
SelectFromArray(qual, name, erasure(tree.symbol)(qual.tpe)).copyAttrs(fn),
args)
}
- } else if (args.isEmpty && interceptedMethods(fn.symbol)) {
+ }
+ else if (args.isEmpty && interceptedMethods(fn.symbol)) {
if (fn.symbol == Any_## || fn.symbol == Object_##) {
// This is unattractive, but without it we crash here on ().## because after
// erasure the ScalaRunTime.hash overload goes from Unit => Int to BoxedUnit => Int.
@@ -1147,7 +1140,18 @@ abstract class Erasure extends AddInterfaces
case s @ (ShortClass | ByteClass | CharClass) => numericConversion(qual, s)
case BooleanClass => If(qual, LIT(true.##), LIT(false.##))
case _ =>
- global.typer.typed(gen.mkRuntimeCall(nme.hash_, List(qual)))
+ // Since we are past typer, we need to avoid creating trees carrying
+ // overloaded types. This logic is custom (and technically incomplete,
+ // although serviceable) for def hash. What is really needed is for
+ // the overloading logic presently hidden away in a few different
+ // places to be properly exposed so we can just call "resolveOverload"
+ // after typer. Until then:
+ val alts = ScalaRunTimeModule.info.member(nme.hash_).alternatives
+ def alt1 = alts find (_.info.paramTypes.head =:= qual.tpe)
+ def alt2 = ScalaRunTimeModule.info.member(nme.hash_) suchThat (_.info.paramTypes.head.typeSymbol == AnyClass)
+ val newTree = gen.mkRuntimeCall(nme.hash_, qual :: Nil) setSymbol (alt1 getOrElse alt2)
+
+ global.typer.typed(newTree)
}
} else if (isPrimitiveValueClass(qual.tpe.typeSymbol)) {
// Rewrite 5.getClass to ScalaRunTime.anyValClass(5)
@@ -1255,13 +1259,12 @@ abstract class Erasure extends AddInterfaces
tree1 setType specialScalaErasure(tree1.tpe)
case ArrayValue(elemtpt, trees) =>
treeCopy.ArrayValue(
- tree1, elemtpt setType specialScalaErasure.applyInArray(elemtpt.tpe), trees map transform) setType null
+ tree1, elemtpt setType specialScalaErasure.applyInArray(elemtpt.tpe), trees map transform).clearType()
case DefDef(_, _, _, _, tpt, _) =>
- val result = super.transform(tree1) setType null
- tpt.tpe = specialErasure(tree1.symbol)(tree1.symbol.tpe).resultType
- result
+ try super.transform(tree1).clearType()
+ finally tpt setType specialErasure(tree1.symbol)(tree1.symbol.tpe).resultType
case _ =>
- super.transform(tree1) setType null
+ super.transform(tree1).clearType()
}
}
}
@@ -1273,7 +1276,7 @@ abstract class Erasure extends AddInterfaces
override def transform(tree: Tree): Tree = {
val tree1 = preTransformer.transform(tree)
// log("tree after pretransform: "+tree1)
- afterErasure {
+ exitingErasure {
val tree2 = mixinTransformer.transform(tree1)
// debuglog("tree after addinterfaces: \n" + tree2)
diff --git a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala
index 1003d417f6..01c22245cb 100644
--- a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala
+++ b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala
@@ -83,12 +83,6 @@ abstract class ExplicitOuter extends InfoTransform
}
}
- /** Issue a migration warning for instance checks which might be on an Array and
- * for which the type parameter conforms to Seq, because these answers changed in 2.8.
- */
- def isArraySeqTest(lhs: Type, rhs: Type) =
- (ArrayClass.tpe <:< lhs.widen) && (rhs.widen matchesPattern SeqClass.tpe)
-
def outerAccessor(clazz: Symbol): Symbol = {
val firstTry = clazz.info.decl(nme.expandedName(nme.OUTER, clazz))
if (firstTry != NoSymbol && firstTry.outerSource == clazz) firstTry
@@ -97,7 +91,7 @@ abstract class ExplicitOuter extends InfoTransform
def newOuterAccessor(clazz: Symbol) = {
val accFlags = SYNTHETIC | ARTIFACT | METHOD | STABLE | ( if (clazz.isTrait) DEFERRED else 0 )
val sym = clazz.newMethod(nme.OUTER, clazz.pos, accFlags)
- val restpe = if (clazz.isTrait) clazz.outerClass.tpe else clazz.outerClass.thisType
+ val restpe = if (clazz.isTrait) clazz.outerClass.tpe_* else clazz.outerClass.thisType
sym expandName clazz
sym.referenced = clazz
@@ -164,16 +158,13 @@ abstract class ExplicitOuter extends InfoTransform
var decls1 = decls
if (isInner(clazz) && !clazz.isInterface) {
decls1 = decls.cloneScope
- val outerAcc = clazz.newMethod(nme.OUTER, clazz.pos) // 3
- outerAcc expandName clazz
-
- decls1 enter newOuterAccessor(clazz)
+ decls1 enter newOuterAccessor(clazz) // 3
if (hasOuterField(clazz)) //2
decls1 enter newOuterField(clazz)
}
if (!clazz.isTrait && !parents.isEmpty) {
for (mc <- clazz.mixinClasses) {
- val mixinOuterAcc: Symbol = afterExplicitOuter(outerAccessor(mc))
+ val mixinOuterAcc: Symbol = exitingExplicitOuter(outerAccessor(mc))
if (mixinOuterAcc != NoSymbol) {
if (decls1 eq decls) decls1 = decls.cloneScope
val newAcc = mixinOuterAcc.cloneSymbol(clazz, mixinOuterAcc.flags & ~DEFERRED)
@@ -243,11 +234,6 @@ abstract class ExplicitOuter extends InfoTransform
* <blockquote><pre>`base'.$outer$$C1 ... .$outer$$Cn</pre></blockquote>
* which refers to the outer instance of class to of
* value base. The result is typed but not positioned.
- *
- * @param base ...
- * @param from ...
- * @param to ...
- * @return ...
*/
protected def outerPath(base: Tree, from: Symbol, to: Symbol): Tree = {
//Console.println("outerPath from "+from+" to "+to+" at "+base+":"+base.tpe)
@@ -341,7 +327,7 @@ abstract class ExplicitOuter extends InfoTransform
*/
def outerAccessorDef: Tree = {
val outerAcc = outerAccessor(currentClass)
- var rhs: Tree =
+ val rhs: Tree =
if (outerAcc.isDeferred) EmptyTree
else This(currentClass) DOT outerField(currentClass)
@@ -553,13 +539,6 @@ abstract class ExplicitOuter extends InfoTransform
}
case _ =>
- if (settings.Xmigration28.value) tree match {
- case TypeApply(fn @ Select(qual, _), args) if fn.symbol == Object_isInstanceOf || fn.symbol == Any_isInstanceOf =>
- if (isArraySeqTest(qual.tpe, args.head.tpe))
- unit.warning(tree.pos, "An Array will no longer match as Seq[_].")
- case _ => ()
- }
-
val x = super.transform(tree)
if (x.tpe eq null) x
else x setType transformInfo(currentOwner, x.tpe)
@@ -568,7 +547,7 @@ abstract class ExplicitOuter extends InfoTransform
/** The transformation method for whole compilation units */
override def transformUnit(unit: CompilationUnit) {
- afterExplicitOuter(super.transformUnit(unit))
+ exitingExplicitOuter(super.transformUnit(unit))
}
}
diff --git a/src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala b/src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala
index 6f3d7932a5..77e7e013ab 100644
--- a/src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala
+++ b/src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala
@@ -8,9 +8,6 @@ package transform
import symtab._
import Flags._
import scala.collection.{ mutable, immutable }
-import scala.collection.mutable
-import scala.tools.nsc.util.FreshNameCreator
-import scala.runtime.ScalaRunTime.{ isAnyVal, isTuple }
/**
* Perform Step 1 in the inline classes SIP: Creates extension methods for all
@@ -23,7 +20,6 @@ abstract class ExtensionMethods extends Transform with TypingTransformers {
import global._ // the global environment
import definitions._ // standard classes and methods
- import typer.{ typed, atOwner } // methods to type trees
/** the following two members override abstract members in Transform */
val phaseName: String = "extmethods"
@@ -66,7 +62,7 @@ abstract class ExtensionMethods extends Transform with TypingTransformers {
/** Return the extension method that corresponds to given instance method `meth`.
*/
- def extensionMethod(imeth: Symbol): Symbol = atPhase(currentRun.refchecksPhase) {
+ def extensionMethod(imeth: Symbol): Symbol = enteringPhase(currentRun.refchecksPhase) {
val companionInfo = imeth.owner.companionModule.info
val candidates = extensionNames(imeth) map (companionInfo.decl(_)) filter (_.exists)
val matching = candidates filter (alt => normalize(alt.tpe, imeth.owner) matches imeth.tpe)
@@ -75,32 +71,41 @@ abstract class ExtensionMethods extends Transform with TypingTransformers {
matching.head
}
+ /** Recognize a MethodType which represents an extension method.
+ *
+ * It may have a curried parameter list with the `$this` alone in the first
+ * parameter list, in which case that parameter list is dropped. Or, since
+ * the curried lists disappear during uncurry, it may have a single parameter
+ * list with `$this` as the first parameter, in which case that parameter is
+ * removed from the list.
+ */
+ object ExtensionMethodType {
+ def unapply(tp: Type) = tp match {
+ case MethodType(thiz :: rest, restpe) if thiz.name == nme.SELF =>
+ Some( if (rest.isEmpty) restpe else MethodType(rest, restpe) )
+ case _ =>
+ None
+ }
+ }
+
/** This method removes the `$this` argument from the parameter list a method.
*
* A method may be a `PolyType`, in which case we tear out the `$this` and the class
- * type params from its nested `MethodType`.
- * It may be a `MethodType`, either with a curried parameter list in which the first argument
- * is a `$this` - we just return the rest of the list.
- * This means that the corresponding symbol was generated during `extmethods`.
- *
- * It may also be a `MethodType` in which the `$this` does not appear in a curried parameter list.
- * The curried lists disappear during `uncurry`, and the methods may be duplicated afterwards,
- * for instance, during `specialize`.
- * In this case, the first argument is `$this` and we just get rid of it.
+ * type params from its nested `MethodType`. Or it may be a MethodType, as
+ * described at the ExtensionMethodType extractor.
*/
private def normalize(stpe: Type, clazz: Symbol): Type = stpe match {
case PolyType(tparams, restpe) =>
- GenPolyType(tparams dropRight clazz.typeParams.length, normalize(restpe.substSym(tparams takeRight clazz.typeParams.length, clazz.typeParams), clazz))
- case MethodType(List(thiz), restpe) if thiz.name == nme.SELF =>
- restpe
- case MethodType(tparams, restpe) =>
- MethodType(tparams.drop(1), restpe)
+ // method type parameters, class type parameters
+ val (mtparams, ctparams) = tparams splitAt (tparams.length - clazz.typeParams.length)
+ GenPolyType(mtparams, normalize(restpe.substSym(ctparams, clazz.typeParams), clazz))
+ case ExtensionMethodType(etpe) =>
+ etpe
case _ =>
stpe
}
class Extender(unit: CompilationUnit) extends TypingTransformer(unit) {
-
private val extensionDefs = mutable.Map[Symbol, mutable.ListBuffer[Tree]]()
def checkNonCyclic(pos: Position, seen: Set[Symbol], clazz: Symbol): Unit =
@@ -111,27 +116,51 @@ abstract class ExtensionMethods extends Transform with TypingTransformers {
if (unboxed.isDerivedValueClass) checkNonCyclic(pos, seen + clazz, unboxed)
}
+ /** We will need to clone the info of the original method (which obtains clones
+ * of the method type parameters), clone the type parameters of the value class,
+ * and create a new polymethod with the union of all those type parameters, with
+ * their infos adjusted to be consistent with their new home. Example:
+ *
+ * class Foo[+A <: AnyRef](val xs: List[A]) extends AnyVal {
+ * def baz[B >: A](x: B): List[B] = x :: xs
+ * // baz has to be transformed into this extension method, where
+ * // A is cloned from class Foo and B is cloned from method baz:
+ * // def extension$baz[B >: A <: Any, A >: Nothing <: AnyRef]($this: Foo[A])(x: B): List[B]
+ * }
+ *
+ * TODO: factor out the logic for consolidating type parameters from a class
+ * and a method for re-use elsewhere, because nobody will get this right without
+ * some higher level facilities.
+ */
def extensionMethInfo(extensionMeth: Symbol, origInfo: Type, clazz: Symbol): Type = {
- // No variance for method type parameters
- var newTypeParams = cloneSymbolsAtOwner(clazz.typeParams, extensionMeth) map (_ resetFlag COVARIANT | CONTRAVARIANT)
- val thisParamType = appliedType(clazz.typeConstructor, newTypeParams map (_.tpeHK))
- val thisParam = extensionMeth.newValueParameter(nme.SELF, extensionMeth.pos) setInfo thisParamType
- def transform(clonedType: Type): Type = clonedType match {
- case MethodType(params, restpe) =>
- // I assume it was a bug that this was dropping params... [Martin]: No, it wasn't; it's curried.
- MethodType(List(thisParam), clonedType)
- case NullaryMethodType(restpe) =>
- MethodType(List(thisParam), restpe)
- }
- val GenPolyType(tparams, restpe) = origInfo cloneInfo extensionMeth
- GenPolyType(tparams ::: newTypeParams, transform(restpe) substSym (clazz.typeParams, newTypeParams))
- }
+ val GenPolyType(tparamsFromMethod, methodResult) = origInfo cloneInfo extensionMeth
+ // Start with the class type parameters - clones will be method type parameters
+ // so must drop their variance.
+ val tparamsFromClass = cloneSymbolsAtOwner(clazz.typeParams, extensionMeth) map (_ resetFlag COVARIANT | CONTRAVARIANT)
+ def fix(tp: Type) = tp.substSym(clazz.typeParams, tparamsFromClass)
- private def allParams(tpe: Type): List[Symbol] = tpe match {
- case MethodType(params, res) => params ::: allParams(res)
- case _ => List()
+ val thisParamType = appliedType(clazz, tparamsFromClass map (_.tpeHK): _*)
+ val thisParam = extensionMeth.newValueParameter(nme.SELF, extensionMeth.pos) setInfo thisParamType
+ val resultType = MethodType(List(thisParam), dropNullaryMethod(methodResult))
+
+ // We can't substitute symbols on the entire polytype because we
+ // need to modify the bounds of the cloned type parameters, but we
+ // don't want to substitute for the cloned type parameters themselves.
+ val tparams = tparamsFromMethod ::: tparamsFromClass
+ GenPolyType(tparams map (_ modifyInfo fix), fix(resultType))
+
+ // For reference, calling fix on the GenPolyType plays out like this:
+ // error: scala.reflect.internal.Types$TypeError: type arguments [B#7344,A#6966]
+ // do not conform to method extension$baz#16148's type parameter bounds
+ //
+ // And the difference is visible here. See how B is bounded from below by A#16149
+ // in both cases, but in the failing case, the other type parameter has turned into
+ // a different A. (What is that A? It is a clone of the original A created in
+ // SubstMap during the call to substSym, but I am not clear on all the particulars.)
+ //
+ // bad: [B#16154 >: A#16149, A#16155 <: AnyRef#2189]($this#16156: Foo#6965[A#16155])(x#16157: B#16154)List#2457[B#16154]
+ // good: [B#16151 >: A#16149, A#16149 <: AnyRef#2189]($this#16150: Foo#6965[A#16149])(x#16153: B#16151)List#2457[B#16151]
}
-
override def transform(tree: Tree): Tree = {
tree match {
case Template(_, _, _) =>
@@ -146,37 +175,56 @@ abstract class ExtensionMethods extends Transform with TypingTransformers {
super.transform(tree)
} else tree
case DefDef(_, _, tparams, vparamss, _, rhs) if tree.symbol.isMethodWithExtension =>
- val companion = currentOwner.companionModule
- val origMeth = tree.symbol
- val extensionName = extensionNames(origMeth).head
- val extensionMeth = companion.moduleClass.newMethod(extensionName, origMeth.pos, origMeth.flags & ~OVERRIDE & ~PROTECTED | FINAL)
- .setAnnotations(origMeth.annotations)
- companion.info.decls.enter(extensionMeth)
- val newInfo = extensionMethInfo(extensionMeth, origMeth.info, currentOwner)
+ val origMeth = tree.symbol
+ val origThis = currentOwner
+ val origTpeParams = tparams.map(_.symbol) ::: origThis.typeParams // method type params ++ class type params
+ val origParams = vparamss.flatten map (_.symbol)
+ val companion = origThis.companionModule
+
+ def makeExtensionMethodSymbol = {
+ val extensionName = extensionNames(origMeth).head
+ val extensionMeth = (
+ companion.moduleClass.newMethod(extensionName.toTermName, origMeth.pos, origMeth.flags & ~OVERRIDE & ~PROTECTED | FINAL)
+ setAnnotations origMeth.annotations
+ )
+ companion.info.decls.enter(extensionMeth)
+ }
+
+ val extensionMeth = makeExtensionMethodSymbol
+ val newInfo = extensionMethInfo(extensionMeth, origMeth.info, origThis)
extensionMeth setInfo newInfo
- log("Value class %s spawns extension method.\n Old: %s\n New: %s".format(
- currentOwner,
- origMeth.defString,
- extensionMeth.defString)) // extensionMeth.defStringSeenAs(origInfo
-
- def thisParamRef = gen.mkAttributedIdent(extensionMeth.info.params.head setPos extensionMeth.pos)
- val GenPolyType(extensionTpeParams, extensionMono) = extensionMeth.info
- val origTpeParams = (tparams map (_.symbol)) ::: currentOwner.typeParams
- val extensionBody = rhs
+
+ log(s"Value class $origThis spawns extension method.\n Old: ${origMeth.defString}\n New: ${extensionMeth.defString}")
+
+ val GenPolyType(extensionTpeParams, MethodType(thiz :: Nil, extensionMono)) = newInfo
+ val extensionParams = allParameters(extensionMono)
+ val extensionThis = gen.mkAttributedIdent(thiz setPos extensionMeth.pos)
+
+ val extensionBody = (
+ rhs
.substituteSymbols(origTpeParams, extensionTpeParams)
- .substituteSymbols(vparamss.flatten map (_.symbol), allParams(extensionMono).tail)
- .substituteThis(currentOwner, thisParamRef)
- .changeOwner((origMeth, extensionMeth))
- extensionDefs(companion) += atPos(tree.pos) { DefDef(extensionMeth, extensionBody) }
- val extensionCallPrefix = Apply(
- gen.mkTypeApply(gen.mkAttributedRef(companion), extensionMeth, origTpeParams map (_.tpeHK)),
- List(This(currentOwner)))
- val extensionCall = atOwner(origMeth) {
- localTyper.typedPos(rhs.pos) {
- gen.mkForwarder(extensionCallPrefix, mmap(vparamss)(_.symbol))
- }
- }
- deriveDefDef(tree)(_ => extensionCall)
+ .substituteSymbols(origParams, extensionParams)
+ .substituteThis(origThis, extensionThis)
+ .changeOwner(origMeth -> extensionMeth)
+ )
+
+ // Record the extension method ( FIXME: because... ? )
+ extensionDefs(companion) += atPos(tree.pos)(DefDef(extensionMeth, extensionBody))
+
+ // These three lines are assembling Foo.bar$extension[T1, T2, ...]($this)
+ // which leaves the actual argument application for extensionCall.
+ val sel = Select(gen.mkAttributedRef(companion), extensionMeth)
+ val targs = origTpeParams map (_.tpeHK)
+ val callPrefix = gen.mkMethodCall(sel, targs, This(origThis) :: Nil)
+
+ // Apply all the argument lists.
+ deriveDefDef(tree)(_ =>
+ atOwner(origMeth)(
+ localTyper.typedPos(rhs.pos)(
+ gen.mkForwarder(callPrefix, mmap(vparamss)(_.symbol))
+ )
+ )
+ )
case _ =>
super.transform(tree)
}
@@ -184,12 +232,13 @@ abstract class ExtensionMethods extends Transform with TypingTransformers {
override def transformStats(stats: List[Tree], exprOwner: Symbol): List[Tree] =
super.transformStats(stats, exprOwner) map {
- case md @ ModuleDef(_, _, _) if extensionDefs contains md.symbol =>
- val defns = extensionDefs(md.symbol).toList map (member =>
- atOwner(md.symbol)(localTyper.typedPos(md.pos.focus)(member))
- )
- extensionDefs -= md.symbol
- deriveModuleDef(md)(tmpl => deriveTemplate(tmpl)(_ ++ defns))
+ case md @ ModuleDef(_, _, _) =>
+ val extraStats = extensionDefs remove md.symbol match {
+ case Some(defns) => defns.toList map (defn => atOwner(md.symbol)(localTyper.typedPos(md.pos.focus)(defn.duplicate)))
+ case _ => Nil
+ }
+ if (extraStats.isEmpty) md
+ else deriveModuleDef(md)(tmpl => deriveTemplate(tmpl)(_ ++ extraStats))
case stat =>
stat
}
diff --git a/src/compiler/scala/tools/nsc/transform/Flatten.scala b/src/compiler/scala/tools/nsc/transform/Flatten.scala
index cd26f95958..b2602f47de 100644
--- a/src/compiler/scala/tools/nsc/transform/Flatten.scala
+++ b/src/compiler/scala/tools/nsc/transform/Flatten.scala
@@ -8,28 +8,22 @@ package transform
import symtab._
import Flags._
-import scala.collection.{ mutable, immutable }
import scala.collection.mutable.ListBuffer
abstract class Flatten extends InfoTransform {
import global._
- import definitions._
/** the following two members override abstract members in Transform */
val phaseName: String = "flatten"
- /** Updates the owning scope with the given symbol; returns the old symbol.
+ /** Updates the owning scope with the given symbol, unlinking any others.
*/
- private def replaceSymbolInCurrentScope(sym: Symbol): Symbol = afterFlatten {
+ private def replaceSymbolInCurrentScope(sym: Symbol): Unit = exitingFlatten {
val scope = sym.owner.info.decls
- val old = scope lookup sym.name andAlso scope.unlink
+ val old = (scope lookupUnshadowedEntries sym.name).toList
+ old foreach (scope unlink _)
scope enter sym
-
- if (old eq NoSymbol)
- log(s"lifted ${sym.fullLocationString}")
- else
- log(s"lifted ${sym.fullLocationString} after unlinking existing $old from scope.")
-
+ log(s"lifted ${sym.fullLocationString}" + ( if (old.isEmpty) "" else s" after unlinking $old from scope." ))
old
}
@@ -53,7 +47,7 @@ abstract class Flatten extends InfoTransform {
clazz.isClass && !clazz.isPackageClass && {
// Cannot flatten here: class A[T] { object B }
// was "at erasurePhase.prev"
- beforeErasure(clazz.typeParams.isEmpty)
+ enteringErasure(clazz.typeParams.isEmpty)
}
}
@@ -67,11 +61,11 @@ abstract class Flatten extends InfoTransform {
val decls1 = scopeTransform(clazz) {
val decls1 = newScope
if (clazz.isPackageClass) {
- afterFlatten { decls foreach (decls1 enter _) }
+ exitingFlatten { decls foreach (decls1 enter _) }
}
else {
val oldowner = clazz.owner
- afterFlatten { oldowner.info }
+ exitingFlatten { oldowner.info }
parents1 = parents mapConserve (this)
for (sym <- decls) {
@@ -123,7 +117,7 @@ abstract class Flatten extends InfoTransform {
liftedDefs(sym.enclosingTopLevelClass.owner) += tree
EmptyTree
case Select(qual, name) if (sym.isStaticModule && !sym.owner.isPackageClass) =>
- afterFlatten(atPos(tree.pos)(gen.mkAttributedRef(sym)))
+ exitingFlatten(atPos(tree.pos)(gen.mkAttributedRef(sym)))
case _ =>
tree
}
diff --git a/src/compiler/scala/tools/nsc/transform/InfoTransform.scala b/src/compiler/scala/tools/nsc/transform/InfoTransform.scala
index b6dbacaa29..dc321e26ca 100644
--- a/src/compiler/scala/tools/nsc/transform/InfoTransform.scala
+++ b/src/compiler/scala/tools/nsc/transform/InfoTransform.scala
@@ -10,11 +10,11 @@ package transform
* An InfoTransform contains a compiler phase that transforms trees and symbol infos -- making sure they stay consistent.
* The symbol info is transformed assuming it is consistent right before this phase.
* The info transformation is triggered by Symbol::rawInfo, which caches the results in the symbol's type history.
- * This way sym.info (during an atPhase(p)) can look up what the symbol's info should look like at the beginning of phase p.
+ * This way sym.info (during an enteringPhase(p)) can look up what the symbol's info should look like at the beginning of phase p.
* (If the transformed info had not been stored yet, rawInfo will compute the info by composing the info-transformers
* of the most recent phase before p, up to the transformer of the phase right before p.)
*
- * Concretely, atPhase(p) { sym.info } yields the info *before* phase p has transformed it. Imagine you're a phase and it all makes sense.
+ * Concretely, enteringPhase(p) { sym.info } yields the info *before* phase p has transformed it. Imagine you're a phase and it all makes sense.
*/
trait InfoTransform extends Transform {
import global.{Symbol, Type, InfoTransformer, infoTransformers}
diff --git a/src/compiler/scala/tools/nsc/transform/InlineErasure.scala b/src/compiler/scala/tools/nsc/transform/InlineErasure.scala
index 0af3cf732f..83dbc23014 100644
--- a/src/compiler/scala/tools/nsc/transform/InlineErasure.scala
+++ b/src/compiler/scala/tools/nsc/transform/InlineErasure.scala
@@ -1,9 +1,11 @@
package scala.tools.nsc
package transform
-trait InlineErasure { self: Erasure =>
-
+trait InlineErasure {
+ self: Erasure =>
+
+/**
import global._
import definitions._
-
-} \ No newline at end of file
+ **/
+}
diff --git a/src/compiler/scala/tools/nsc/transform/LambdaLift.scala b/src/compiler/scala/tools/nsc/transform/LambdaLift.scala
index 4a23e65ad2..0198f959e3 100644
--- a/src/compiler/scala/tools/nsc/transform/LambdaLift.scala
+++ b/src/compiler/scala/tools/nsc/transform/LambdaLift.scala
@@ -247,8 +247,8 @@ abstract class LambdaLift extends InfoTransform {
// SI-5652 If the lifted symbol is accessed from an inner class, it will be made public. (where?)
// Generating a a unique name, mangled with the enclosing class name, avoids a VerifyError
// in the case that a sub-class happens to lifts out a method with the *same* name.
- val name = freshen(sym.name + nme.NAME_JOIN_STRING)
- if (originalName.isTermName && !sym.enclClass.isImplClass && calledFromInner(sym)) nme.expandedName(name, sym.enclClass)
+ val name = freshen("" + sym.name + nme.NAME_JOIN_STRING)
+ if (originalName.isTermName && !sym.enclClass.isImplClass && calledFromInner(sym)) nme.expandedName(name.toTermName, sym.enclClass)
else name
}
}
@@ -290,7 +290,7 @@ abstract class LambdaLift extends InfoTransform {
proxies(owner) =
for (fv <- freeValues.toList) yield {
val proxyName = proxyNames.getOrElse(fv, fv.name)
- val proxy = owner.newValue(proxyName, owner.pos, newFlags) setInfo fv.info
+ val proxy = owner.newValue(proxyName.toTermName, owner.pos, newFlags) setInfo fv.info
if (owner.isClass) owner.info.decls enter proxy
proxy
}
diff --git a/src/compiler/scala/tools/nsc/transform/LazyVals.scala b/src/compiler/scala/tools/nsc/transform/LazyVals.scala
index 21213cf9d9..e6c9afb042 100644
--- a/src/compiler/scala/tools/nsc/transform/LazyVals.scala
+++ b/src/compiler/scala/tools/nsc/transform/LazyVals.scala
@@ -68,7 +68,7 @@ abstract class LazyVals extends Transform with TypingTransformers with ast.TreeD
curTree = tree
tree match {
-
+
case Block(_, _) =>
val block1 = super.transform(tree)
val Block(stats, expr) = block1
@@ -79,7 +79,7 @@ abstract class LazyVals extends Transform with TypingTransformers with ast.TreeD
List(stat)
})
treeCopy.Block(block1, stats1, expr)
-
+
case DefDef(_, _, _, _, _, rhs) => atOwner(tree.symbol) {
val (res, slowPathDef) = if (!sym.owner.isClass && sym.isLazy) {
val enclosingClassOrDummyOrMethod = {
@@ -100,9 +100,9 @@ abstract class LazyVals extends Transform with TypingTransformers with ast.TreeD
val (rhs1, sDef) = mkLazyDef(enclosingClassOrDummyOrMethod, transform(rhs), idx, sym)
sym.resetFlag((if (lazyUnit(sym)) 0 else LAZY) | ACCESSOR)
(rhs1, sDef)
- } else
+ } else
(transform(rhs), EmptyTree)
-
+
val ddef1 = deriveDefDef(tree)(_ => if (LocalLazyValFinder.find(res)) typed(addBitmapDefs(sym, res)) else res)
if (slowPathDef != EmptyTree) Block(slowPathDef, ddef1) else ddef1
}
@@ -189,10 +189,10 @@ abstract class LazyVals extends Transform with TypingTransformers with ast.TreeD
case _ => prependStats(bmps, rhs)
}
}
-
+
def mkSlowPathDef(clazz: Symbol, lzyVal: Symbol, cond: Tree, syncBody: List[Tree],
stats: List[Tree], retVal: Tree): Tree = {
- val defSym = clazz.newMethod(nme.newLazyValSlowComputeName(lzyVal.name), lzyVal.pos, STABLE | PRIVATE)
+ val defSym = clazz.newMethod(nme.newLazyValSlowComputeName(lzyVal.name.toTermName), lzyVal.pos, STABLE | PRIVATE)
defSym setInfo MethodType(List(), lzyVal.tpe.resultType)
defSym.owner = lzyVal.owner
debuglog(s"crete slow compute path $defSym with owner ${defSym.owner} for lazy val $lzyVal")
@@ -201,8 +201,8 @@ abstract class LazyVals extends Transform with TypingTransformers with ast.TreeD
val rhs: Tree = (gen.mkSynchronizedCheck(clazz, cond, syncBody, stats)).changeOwner(currentOwner -> defSym)
DEF(defSym).mkTree(addBitmapDefs(lzyVal, BLOCK(rhs, retVal))) setSymbol defSym
}
-
-
+
+
def mkFastPathBody(clazz: Symbol, lzyVal: Symbol, cond: Tree, syncBody: List[Tree],
stats: List[Tree], retVal: Tree): (Tree, Tree) = {
val slowPathDef: Tree = mkSlowPathDef(clazz, lzyVal, cond, syncBody, stats, retVal)
@@ -221,7 +221,7 @@ abstract class LazyVals extends Transform with TypingTransformers with ast.TreeD
* Similarly as for normal lazy val members (see Mixin), the result will be a tree of the form
* { if ((bitmap&n & MASK) == 0) this.l$compute()
* else l$
- *
+ *
* def l$compute() = { synchronized(enclosing_class_or_dummy) {
* if ((bitmap$n & MASK) == 0) {
* l$ = <rhs>
@@ -278,7 +278,7 @@ abstract class LazyVals extends Transform with TypingTransformers with ast.TreeD
bmps(n)
else {
val sym = meth.newVariable(nme.newBitmapName(nme.BITMAP_NORMAL, n), meth.pos).setInfo(ByteClass.tpe)
- beforeTyper {
+ enteringTyper {
sym addAnnotation VolatileAttr
}
diff --git a/src/compiler/scala/tools/nsc/transform/Mixin.scala b/src/compiler/scala/tools/nsc/transform/Mixin.scala
index 57bdaea17a..0769b67282 100644
--- a/src/compiler/scala/tools/nsc/transform/Mixin.scala
+++ b/src/compiler/scala/tools/nsc/transform/Mixin.scala
@@ -68,7 +68,7 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
* maps all other types to themselves.
*/
private def toInterface(tp: Type): Type =
- beforeMixin(tp.typeSymbol.toInterface).tpe
+ enteringMixin(tp.typeSymbol.toInterface).tpe
private def isFieldWithBitmap(field: Symbol) = {
field.info // ensure that nested objects are transformed
@@ -102,7 +102,7 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
private val toInterfaceMap = new TypeMap {
def apply(tp: Type): Type = mapOver( tp match {
case TypeRef(pre, sym, args) if sym.isImplClass =>
- typeRef(pre, beforeMixin(sym.toInterface), args)
+ typeRef(pre, enteringMixin(sym.toInterface), args)
case _ => tp
})
}
@@ -119,7 +119,7 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
* @param mixinClass The mixin class that produced the superaccessor
*/
private def rebindSuper(base: Symbol, member: Symbol, mixinClass: Symbol): Symbol =
- afterPickler {
+ exitingPickler {
var bcs = base.info.baseClasses.dropWhile(mixinClass != _).tail
var sym: Symbol = NoSymbol
debuglog("starting rebindsuper " + base + " " + member + ":" + member.tpe +
@@ -165,7 +165,7 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
addMember(clazz, cloneBeforeErasure(mixinClass, mixinMember, clazz))
def cloneBeforeErasure(mixinClass: Symbol, mixinMember: Symbol, clazz: Symbol): Symbol = {
- val newSym = beforeErasure {
+ val newSym = enteringErasure {
// since we used `mixinMember` from the interface that represents the trait that's
// being mixed in, have to instantiate the interface type params (that may occur in mixinMember's
// info) as they are seen from the class. We can't use the member that we get from the
@@ -197,9 +197,6 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
* - lazy fields don't get a setter.
*/
def addLateInterfaceMembers(clazz: Symbol) {
- def makeConcrete(member: Symbol) =
- member setPos clazz.pos resetFlag (DEFERRED | lateDEFERRED)
-
if (treatedClassInfos(clazz) != clazz.info) {
treatedClassInfos(clazz) = clazz.info
assert(phase == currentRun.mixinPhase, phase)
@@ -210,14 +207,14 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
// println("creating new getter for "+ field +" : "+ field.info +" at "+ field.locationString+(field hasFlag MUTABLE))
val newFlags = field.flags & ~PrivateLocal | ACCESSOR | lateDEFERRED | ( if (field.isMutable) 0 else STABLE )
// TODO preserve pre-erasure info?
- clazz.newMethod(nme.getterName(field.name), field.pos, newFlags) setInfo MethodType(Nil, field.info)
+ clazz.newMethod(nme.getterName(field.name.toTermName), field.pos, newFlags) setInfo MethodType(Nil, field.info)
}
/** Create a new setter. Setters are never private or local. They are
* always accessors and deferred. */
def newSetter(field: Symbol): Symbol = {
//println("creating new setter for "+field+field.locationString+(field hasFlag MUTABLE))
- val setterName = nme.getterToSetter(nme.getterName(field.name))
+ val setterName = nme.getterToSetter(nme.getterName(field.name.toTermName))
val newFlags = field.flags & ~PrivateLocal | ACCESSOR | lateDEFERRED
val setter = clazz.newMethod(setterName, field.pos, newFlags)
// TODO preserve pre-erasure info?
@@ -292,7 +289,7 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
for (mixinMember <- mixinClass.info.decls) {
if (isConcreteAccessor(mixinMember)) {
if (isOverriddenAccessor(mixinMember, clazz.info.baseClasses))
- debugwarn("!!! is overridden val: "+mixinMember.fullLocationString)
+ devWarning(s"Overridden concrete accessor: ${mixinMember.fullLocationString}")
else {
// mixin field accessors
val mixedInAccessor = cloneAndAddMixinMember(mixinClass, mixinMember)
@@ -311,14 +308,14 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
// mixinMember is a value of type unit. No field needed
;
case _ => // otherwise mixin a field as well
- // atPhase: the private field is moved to the implementation class by erasure,
+ // enteringPhase: the private field is moved to the implementation class by erasure,
// so it can no longer be found in the mixinMember's owner (the trait)
- val accessed = beforePickler(mixinMember.accessed)
+ val accessed = enteringPickler(mixinMember.accessed)
// #3857, need to retain info before erasure when cloning (since cloning only
// carries over the current entry in the type history)
- val sym = beforeErasure {
+ val sym = enteringErasure {
// so we have a type history entry before erasure
- clazz.newValue(nme.getterToLocal(mixinMember.name), mixinMember.pos).setInfo(mixinMember.tpe.resultType)
+ clazz.newValue(nme.getterToLocal(mixinMember.name.toTermName), mixinMember.pos).setInfo(mixinMember.tpe.resultType)
}
sym updateInfo mixinMember.tpe.resultType // info at current phase
@@ -379,35 +376,34 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
var parents1 = parents
var decls1 = decls
if (!clazz.isPackageClass) {
- afterMixin(clazz.owner.info)
+ exitingMixin(clazz.owner.info)
if (clazz.isImplClass) {
clazz setFlag lateMODULE
var sourceModule = clazz.owner.info.decls.lookup(sym.name.toTermName)
- if (sourceModule != NoSymbol) {
- sourceModule setPos sym.pos
- if (sourceModule.flags != MODULE) {
- log("!!! Directly setting sourceModule flags from %s to MODULE".format(flagsToString(sourceModule.flags)))
- sourceModule.flags = MODULE
- }
- }
- else {
+ if (sourceModule == NoSymbol) {
sourceModule = (
clazz.owner.newModuleSymbol(sym.name.toTermName, sym.pos, MODULE)
setModuleClass sym.asInstanceOf[ClassSymbol]
)
clazz.owner.info.decls enter sourceModule
}
+ else {
+ sourceModule setPos sym.pos
+ if (sourceModule.flags != MODULE) {
+ log("!!! Directly setting sourceModule flags from %s to MODULE".format(sourceModule.flagString))
+ sourceModule.flags = MODULE
+ }
+ }
sourceModule setInfo sym.tpe
// Companion module isn't visible for anonymous class at this point anyway
- assert(clazz.sourceModule != NoSymbol || clazz.isAnonymousClass,
- clazz + " has no sourceModule: sym = " + sym + " sym.tpe = " + sym.tpe)
+ assert(clazz.sourceModule != NoSymbol || clazz.isAnonymousClass, s"$clazz has no sourceModule: $sym ${sym.tpe}")
parents1 = List()
decls1 = newScopeWith(decls.toList filter isImplementedStatically: _*)
} else if (!parents.isEmpty) {
parents1 = parents.head :: (parents.tail map toInterface)
}
}
- //decls1 = atPhase(phase.next)(newScopeWith(decls1.toList: _*))//debug
+ //decls1 = enteringPhase(phase.next)(newScopeWith(decls1.toList: _*))//debug
if ((parents1 eq parents) && (decls1 eq decls)) tp
else ClassInfoType(parents1, decls1, clazz)
@@ -437,7 +433,7 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
tree match {
case Assign(lhs, rhs) => traverse(rhs) // assignments don't count
case _ =>
- if (tree.hasSymbol && tree.symbol != NoSymbol) {
+ if (tree.hasSymbolField && tree.symbol != NoSymbol) {
val sym = tree.symbol
if ((sym.hasAccessorFlag || (sym.isTerm && !sym.isMethod))
&& sym.isPrivate
@@ -515,7 +511,7 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
* - create a new method definition that also has a `self` parameter
* (which comes first) Iuli: this position is assumed by tail call elimination
* on a different receiver. Storing a new 'this' assumes it is located at
- * index 0 in the local variable table. See 'STORE_THIS' and GenJVM/GenMSIL.
+ * index 0 in the local variable table. See 'STORE_THIS' and GenASM.
* - Map implementation class types in type-apply's to their interfaces
* - Remove all fields in implementation classes
*/
@@ -524,7 +520,7 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
tree match {
case Template(parents, self, body) =>
localTyper = erasure.newTyper(rootContext.make(tree, currentOwner))
- afterMixin(currentOwner.owner.info)//todo: needed?
+ exitingMixin(currentOwner.owner.info)//todo: needed?
if (!currentOwner.isTrait && !isPrimitiveValueClass(currentOwner))
addMixedinMembers(currentOwner, unit)
@@ -543,17 +539,23 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
else EmptyTree
}
else {
- if (currentOwner.isTrait && sym.isSetter && !beforePickler(sym.isDeferred)) {
+ if (currentOwner.isTrait && sym.isSetter && !enteringPickler(sym.isDeferred)) {
sym.addAnnotation(TraitSetterAnnotationClass)
}
tree
}
+ // !!! What is this doing, and why is it only looking for exactly
+ // one type parameter? It would seem to be
+ // "Map implementation class types in type-apply's to their interfaces"
+ // from the comment on preTransform, but is there some way we should know
+ // that impl class types in type applies can only appear in single
+ // type parameter type constructors?
case Apply(tapp @ TypeApply(fn, List(arg)), List()) =>
if (arg.tpe.typeSymbol.isImplClass) {
val ifacetpe = toInterface(arg.tpe)
- arg.tpe = ifacetpe
- tapp.tpe = MethodType(List(), ifacetpe)
- tree.tpe = ifacetpe
+ arg setType ifacetpe
+ tapp setType MethodType(Nil, ifacetpe)
+ tree setType ifacetpe
}
tree
case ValDef(_, _, _, _) if currentOwner.isImplClass =>
@@ -590,8 +592,8 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
tree
}
- /** Create a static reference to given symbol <code>sym</code> of the
- * form <code>M.sym</code> where M is the symbol's implementation module.
+ /** Create a static reference to given symbol `sym` of the
+ * form `M.sym` where M is the symbol's implementation module.
*/
private def staticRef(sym: Symbol): Tree = {
sym.owner.info //todo: needed?
@@ -673,8 +675,8 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
def addValDef(sym: Symbol, rhs: Tree = EmptyTree) = addDef(position(sym), ValDef(sym, rhs))
/** Add `newdefs` to `stats`, removing any abstract method definitions
- * in <code>stats</code> that are matched by some symbol defined in
- * <code>newDefs</code>.
+ * in `stats` that are matched by some symbol defined in
+ * `newDefs`.
*/
def add(stats: List[Tree], newDefs: List[Tree]) = {
val newSyms = newDefs map (_.symbol)
@@ -702,7 +704,7 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
val rhs0 = (Super(clazz, tpnme.EMPTY) DOT stat.symbol.alias)(vparams map (v => Ident(v.symbol)): _*)
val rhs1 = localTyped(stat.pos, rhs0, stat.symbol.tpe.resultType)
- deriveDefDef(stat)(_ => beforeMixin(transform(rhs1)))
+ deriveDefDef(stat)(_ => enteringMixin(transform(rhs1)))
case _ =>
stat
}
@@ -713,7 +715,7 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
*/
def bitmapFor(clazz0: Symbol, offset: Int, field: Symbol): Symbol = {
val category = bitmapCategory(field)
- val bitmapName = nme.newBitmapName(category, offset / flagsPerBitmap(field))
+ val bitmapName = nme.newBitmapName(category, offset / flagsPerBitmap(field)).toTermName
val sym = clazz0.info.decl(bitmapName)
assert(!sym.isOverloaded, sym)
@@ -721,7 +723,7 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
def createBitmap: Symbol = {
val bitmapKind = bitmapKindForCategory(category)
val sym = clazz0.newVariable(bitmapName, clazz0.pos) setInfo bitmapKind.tpe
- beforeTyper(sym addAnnotation VolatileAttr)
+ enteringTyper(sym addAnnotation VolatileAttr)
category match {
case nme.BITMAP_TRANSIENT | nme.BITMAP_CHECKINIT_TRANSIENT => sym addAnnotation TransientAttr
@@ -777,7 +779,7 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
def mkSlowPathDef(clazz: Symbol, lzyVal: Symbol, cond: Tree, syncBody: List[Tree],
stats: List[Tree], retVal: Tree, attrThis: Tree, args: List[Tree]): Symbol = {
- val defSym = clazz.newMethod(nme.newLazyValSlowComputeName(lzyVal.name), lzyVal.pos, PRIVATE)
+ val defSym = clazz.newMethod(nme.newLazyValSlowComputeName(lzyVal.name.toTermName), lzyVal.pos, PRIVATE)
val params = defSym newSyntheticValueParams args.map(_.symbol.tpe)
defSym setInfoAndEnter MethodType(params, lzyVal.tpe.resultType)
val rhs: Tree = (gen.mkSynchronizedCheck(attrThis, cond, syncBody, stats)).changeOwner(currentOwner -> defSym)
@@ -803,7 +805,7 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
*/
class TreeSymSubstituterWithCopying(from: List[Symbol], to: List[Symbol]) extends TreeSymSubstituter(from, to) {
override def transform(tree: Tree): Tree =
- if (tree.hasSymbol && from.contains(tree.symbol))
+ if (tree.hasSymbolField && from.contains(tree.symbol))
super.transform(tree.duplicate)
else super.transform(tree.duplicate)
@@ -867,10 +869,10 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
rhs match {
case Block(List(assign), returnTree) =>
val Assign(moduleVarRef, _) = assign
- val cond = Apply(Select(moduleVarRef, nme.eq), List(NULL))
+ val cond = Apply(Select(moduleVarRef, Object_eq), List(NULL))
mkFastPathBody(clazz, moduleSym, cond, List(assign), List(NULL), returnTree, attrThis, args)
case _ =>
- abort("Invalid getter " + rhs + " for module in class " + clazz)
+ abort(s"Invalid getter $rhs for module in $clazz")
}
def mkCheckedAccessor(clazz: Symbol, retVal: Tree, offset: Int, pos: Position, fieldSym: Symbol): Tree = {
@@ -878,11 +880,11 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
val bitmapSym = bitmapFor(clazz, offset, sym)
val kind = bitmapKind(sym)
val mask = maskForOffset(offset, sym, kind)
- val msg = "Uninitialized field: " + unit.source + ": " + pos.line
+ val msg = s"Uninitialized field: ${unit.source}: ${pos.line}"
val result =
IF (mkTest(clazz, mask, bitmapSym, false, kind)) .
THEN (retVal) .
- ELSE (THROW(UninitializedErrorClass, LIT(msg)))
+ ELSE (Throw(NewFromConstructor(UninitializedFieldConstructor, LIT(msg))))
typedPos(pos)(BLOCK(result, retVal))
}
@@ -978,12 +980,6 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
def addInitBits(clazz: Symbol, rhs: Tree): Tree =
new AddInitBitsTransformer(clazz) transform rhs
- def isCheckInitField(field: Symbol) =
- needsInitFlag(field) && !field.isDeferred
-
- def superClassesToCheck(clazz: Symbol) =
- clazz.ancestors filterNot (_ hasFlag TRAIT | JAVA)
-
// begin addNewDefs
/** Fill the map from fields to offset numbers.
@@ -1044,16 +1040,17 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
}
// if class is not a trait add accessor definitions
else if (!clazz.isTrait) {
+ // This needs to be a def to avoid sharing trees
+ def accessedRef = accessedReference(sym)
if (sym.hasAccessorFlag && (!sym.isDeferred || sym.hasFlag(lateDEFERRED))) {
// add accessor definitions
addDefDef(sym, {
- val accessedRef = accessedReference(sym)
if (sym.isSetter) {
if (isOverriddenSetter(sym)) UNIT
else accessedRef match {
- case Literal(_) => accessedRef
- case _ =>
- val init = Assign(accessedRef, Ident(sym.firstParam))
+ case ref @ Literal(_) => ref
+ case ref =>
+ val init = Assign(ref, Ident(sym.firstParam))
val getter = sym.getter(clazz)
if (!needsInitFlag(getter)) init
@@ -1068,11 +1065,13 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
}
else if (sym.isModule && !(sym hasFlag LIFTED | BRIDGE)) {
// add modules
- val vdef = gen.mkModuleVarDef(sym)
- addDef(position(sym), vdef)
+ val vsym = sym.owner.newModuleVarSymbol(sym)
+ addDef(position(sym), ValDef(vsym))
- val rhs = gen.newModule(sym, vdef.symbol.tpe)
- val assignAndRet = gen.mkAssignAndReturn(vdef.symbol, rhs)
+ // !!! TODO - unravel the enormous duplication between this code and
+ // eliminateModuleDefs in RefChecks.
+ val rhs = gen.newModule(sym, vsym.tpe)
+ val assignAndRet = gen.mkAssignAndReturn(vsym, rhs)
val attrThis = gen.mkAttributedThis(clazz)
val rhs1 = mkInnerClassAccessorDoubleChecked(attrThis, assignAndRet, sym, List())
@@ -1135,7 +1134,7 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
// change every node type that refers to an implementation class to its
// corresponding interface, unless the node's symbol is an implementation class.
if (tree.tpe.typeSymbol.isImplClass && ((sym eq null) || !sym.isImplClass))
- tree.tpe = toInterface(tree.tpe)
+ tree modifyType toInterface
tree match {
case templ @ Template(parents, self, body) =>
@@ -1151,9 +1150,9 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
qual
case Apply(Select(qual, _), args) =>
- /** Changes <code>qual.m(args)</code> where m refers to an implementation
+ /** Changes `qual.m(args)` where m refers to an implementation
* class method to Q.m(S, args) where Q is the implementation module of
- * <code>m</code> and S is the self parameter for the call, which
+ * `m` and S is the self parameter for the call, which
* is determined as follows:
* - if qual != super, qual itself
* - if qual == super, and we are in an implementation class,
@@ -1164,7 +1163,7 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
def implSym = implClass(sym.owner).info.member(sym.name)
assert(target ne NoSymbol,
List(sym + ":", sym.tpe, sym.owner, implClass(sym.owner), implSym,
- beforePrevPhase(implSym.tpe), phase) mkString " "
+ enteringPrevPhase(implSym.tpe), phase) mkString " "
)
typedPos(tree.pos)(Apply(staticRef(target), transformSuper(qual) :: args))
}
@@ -1193,7 +1192,7 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
typedPos(tree.pos)((transformSuper(qual) DOT sym1)())
}
else {
- staticCall(beforePrevPhase(sym.overridingSymbol(implClass(sym.owner))))
+ staticCall(enteringPrevPhase(sym.overridingSymbol(implClass(sym.owner))))
}
}
else {
@@ -1211,7 +1210,7 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
tree
case Select(qual, name) if sym.owner.isImplClass && !isStaticOnly(sym) =>
- assert(!sym.isMethod, "no method allowed here: %s%s %s".format(sym, sym.isImplOnly, flagsToString(sym.flags)))
+ assert(!sym.isMethod, "no method allowed here: %s%s %s".format(sym, sym.isImplOnly, sym.flagString))
// refer to fields in some implementation class via an abstract
// getter in the interface.
val iface = toInterface(sym.owner.tpe).typeSymbol
@@ -1243,7 +1242,7 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
val tree1 = super.transform(preTransform(tree))
// localTyper needed when not flattening inner classes. parts after an
// inner class will otherwise be typechecked with a wrong scope
- try afterMixin(postTransform(tree1))
+ try exitingMixin(postTransform(tree1))
finally localTyper = saved
}
}
diff --git a/src/compiler/scala/tools/nsc/transform/OverridingPairs.scala b/src/compiler/scala/tools/nsc/transform/OverridingPairs.scala
index 67be81bd3c..28e6e3be26 100644
--- a/src/compiler/scala/tools/nsc/transform/OverridingPairs.scala
+++ b/src/compiler/scala/tools/nsc/transform/OverridingPairs.scala
@@ -31,11 +31,11 @@ abstract class OverridingPairs {
private val self = base.thisType
/** Symbols to exclude: Here these are constructors, private locals,
- * and bridges. But it may be refined in subclasses.
+ * and hidden symbols, including bridges. But it may be refined in subclasses.
*
*/
protected def exclude(sym: Symbol): Boolean =
- sym.isConstructor || sym.isPrivateLocal || sym.hasFlag(BRIDGE)
+ sym.isConstructor || sym.isPrivateLocal || sym.isArtifact
/** The parents of base (may also be refined).
*/
diff --git a/src/compiler/scala/tools/nsc/transform/PostErasure.scala b/src/compiler/scala/tools/nsc/transform/PostErasure.scala
index 3ef32caa2c..a8dc47046b 100644
--- a/src/compiler/scala/tools/nsc/transform/PostErasure.scala
+++ b/src/compiler/scala/tools/nsc/transform/PostErasure.scala
@@ -24,7 +24,7 @@ trait PostErasure extends InfoTransform with TypingTransformers {
case ConstantType(Constant(tp: Type)) =>
ConstantType(Constant(apply(tp)))
case ErasedValueType(tref) =>
- atPhase(currentRun.erasurePhase)(erasure.erasedValueClassArg(tref))
+ enteringPhase(currentRun.erasurePhase)(erasure.erasedValueClassArg(tref))
case _ => mapOver(tp)
}
}
@@ -39,7 +39,7 @@ trait PostErasure extends InfoTransform with TypingTransformers {
Apply(sel @ Select(
Apply(Select(New(tpt), nme.CONSTRUCTOR), List(arg)),
acc), List())
- if atPhase(currentRun.erasurePhase) {
+ if enteringPhase(currentRun.erasurePhase) {
tpt.tpe.typeSymbol.isDerivedValueClass &&
sel.symbol == tpt.tpe.typeSymbol.derivedValueClassUnbox
} =>
@@ -50,7 +50,7 @@ trait PostErasure extends InfoTransform with TypingTransformers {
Apply(Select(New(tpt1), nme.CONSTRUCTOR), List(arg1)),
cmp),
List(Apply(Select(New(tpt2), nme.CONSTRUCTOR), List(arg2))))
- if atPhase(currentRun.erasurePhase) {
+ if enteringPhase(currentRun.erasurePhase) {
tpt1.tpe.typeSymbol.isDerivedValueClass &&
(sel.symbol == Object_== || sel.symbol == Object_!=) &&
tpt2.tpe.typeSymbol == tpt1.tpe.typeSymbol
diff --git a/src/compiler/scala/tools/nsc/transform/SampleTransform.scala b/src/compiler/scala/tools/nsc/transform/SampleTransform.scala
index 44d8860916..cffb483072 100644
--- a/src/compiler/scala/tools/nsc/transform/SampleTransform.scala
+++ b/src/compiler/scala/tools/nsc/transform/SampleTransform.scala
@@ -11,9 +11,8 @@ package transform
abstract class SampleTransform extends Transform {
// inherits abstract value `global` and class `Phase` from Transform
- import global._ // the global environment
- import definitions._ // standard classes and methods
- import typer.{typed, atOwner} // methods to type trees
+ import global._ // the global environment
+ import typer.typed // method to type trees
/** the following two members override abstract members in Transform */
val phaseName: String = "sample-phase"
diff --git a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala
index bbab545d9e..9715dd3d44 100644
--- a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala
+++ b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala
@@ -101,7 +101,6 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
/** Concrete methods that use a specialized type, or override such methods. */
private val concreteSpecMethods = perRunCaches.newWeakSet[Symbol]()
- private def specializedTypes(tps: List[Symbol]) = tps filter (_.isSpecialized)
private def specializedOn(sym: Symbol): List[Symbol] = {
sym getAnnotation SpecializedClass match {
case Some(AnnotationInfo(_, Nil, _)) => specializableTypes.map(_.typeSymbol)
@@ -119,6 +118,22 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
}
}
+ @annotation.tailrec private def findSymbol[T](candidates: List[T], f: T => Symbol): Symbol = {
+ if (candidates.isEmpty) NoSymbol
+ else f(candidates.head) match {
+ case NoSymbol => findSymbol(candidates.tail, f)
+ case sym => sym
+ }
+ }
+ private def hasNewParents(tree: Tree) = {
+ val parents = tree.symbol.info.parents
+ val prev = enteringPrevPhase(tree.symbol.info.parents)
+ (parents != prev) && {
+ debuglog(s"$tree parents changed from: $prev to: $parents")
+ true
+ }
+ }
+
// If we replace `isBoundedGeneric` with (tp <:< AnyRefClass.tpe),
// then pos/spec-List.scala fails - why? Does this kind of check fail
// for similar reasons? Does `sym.isAbstractType` make a difference?
@@ -169,15 +184,16 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
}
}
- /** Returns the generic class that was specialized to 'sClass', or
- * 'sClass' itself if sClass is not a specialized subclass.
- */
- def genericClass(sClass: Symbol): Symbol =
- if (sClass.isSpecialized) sClass.superClass
- else sClass
-
case class Overload(sym: Symbol, env: TypeEnv) {
override def toString = "specialized overload " + sym + " in " + env
+ def matchesSym(sym1: Symbol) = sym.info =:= sym1.info
+ def matchesEnv(env1: TypeEnv) = TypeEnv.includes(env, env1)
+ }
+ private def newOverload(method: Symbol, specializedMethod: Symbol, env: TypeEnv) = {
+ assert(!specializedMethod.isOverloaded, specializedMethod.defString)
+ val om = Overload(specializedMethod, env)
+ overloads(method) ::= om
+ om
}
/** Just to mark uncheckable */
@@ -199,8 +215,6 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
* type bounds of other @specialized type parameters (and not in its result type).
*/
def degenerate = false
-
- def isAccessor = false
}
/** Symbol is a special overloaded method of 'original', in the environment env. */
@@ -218,11 +232,14 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
def target = t
}
- /** Symbol is a specialized accessor for the `target` field. */
- case class SpecializedAccessor(target: Symbol) extends SpecializedInfo {
- override def isAccessor = true
+ /** Symbol is a special overload of the super accessor. */
+ case class SpecialSuperAccessor(t: Symbol) extends SpecializedInfo {
+ def target = t
}
+ /** Symbol is a specialized accessor for the `target` field. */
+ case class SpecializedAccessor(target: Symbol) extends SpecializedInfo { }
+
/** Symbol is a specialized method whose body should be the target's method body. */
case class Implementation(target: Symbol) extends SpecializedInfo
@@ -260,9 +277,6 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
def specializedParams(sym: Symbol): List[Symbol] =
sym.info.typeParams filter (_.isSpecialized)
- def splitParams(tps: List[Symbol]) =
- tps partition (_.isSpecialized)
-
/** Given an original class symbol and a list of types its type parameters are instantiated at
* returns a list of type parameters that should remain in the TypeRef when instantiating a
* specialized type.
@@ -289,10 +303,6 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
}
}
- /** Return the specialized overload of sym in the given env, if any. */
- def overload(sym: Symbol, env: TypeEnv) =
- overloads(sym).find(ov => TypeEnv.includes(ov.env, env))
-
/** Return the specialized name of 'sym' in the given environment. It
* guarantees the same result regardless of the map order by sorting
* type variables alphabetically.
@@ -313,11 +323,11 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
*/
private def specializedName(name: Name, types1: List[Type], types2: List[Type]): TermName = {
if (nme.INITIALIZER == name || (types1.isEmpty && types2.isEmpty))
- name
+ name.toTermName
else if (nme.isSetterName(name))
- nme.getterToSetter(specializedName(nme.setterToGetter(name), types1, types2))
+ nme.getterToSetter(specializedName(nme.setterToGetter(name.toTermName), types1, types2))
else if (nme.isLocalName(name))
- nme.getterToLocal(specializedName(nme.localToGetter(name), types1, types2))
+ nme.getterToLocal(specializedName(nme.localToGetter(name.toTermName), types1, types2))
else {
val (base, cs, ms) = nme.splitSpecializedName(name)
newTermName(base.toString + "$"
@@ -397,7 +407,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
tpes foreach (tp => buf ++= specializedTypeVars(tp))
buf.result
}
- def specializedTypeVars(sym: Symbol): immutable.Set[Symbol] = beforeTyper(specializedTypeVars(sym.info))
+ def specializedTypeVars(sym: Symbol): immutable.Set[Symbol] = enteringTyper(specializedTypeVars(sym.info))
/** Return the set of @specialized type variables mentioned by the given type.
* It only counts type variables that appear:
@@ -521,7 +531,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
def cloneInSpecializedClass(member: Symbol, flagFn: Long => Long, newName: Name = null) =
member.cloneSymbol(sClass, flagFn(member.flags | SPECIALIZED), newName)
- sClass.sourceFile = clazz.sourceFile
+ sClass.associatedFile = clazz.sourceFile
currentRun.symSource(sClass) = clazz.sourceFile // needed later on by mixin
val env = mapAnyRefsInSpecSym(env0, clazz, sClass)
@@ -533,7 +543,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
var newClassTParams: List[Symbol] = Nil // unspecialized type parameters of 'specializedClass' (cloned)
// has to be a val in order to be computed early. It is later called
- // within 'atPhase(next)', which would lead to an infinite cycle otherwise
+ // within 'enteringPhase(next)', which would lead to an infinite cycle otherwise
val specializedInfoType: Type = {
oldClassTParams = survivingParams(clazz.info.typeParams, env)
newClassTParams = produceTypeParameters(oldClassTParams, sClass, env) map subst(env)
@@ -553,7 +563,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
var res: List[Type] = Nil
// log(specializedClass + ": seeking specialized parents of class with parents: " + parents.map(_.typeSymbol))
for (p <- parents) {
- val stp = afterSpecialize(specializedType(p))
+ val stp = exitingSpecialize(specializedType(p))
if (stp != p)
if (p.typeSymbol.isTrait) res ::= stp
else if (currentRun.compiles(clazz))
@@ -563,7 +573,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
res
}
- var parents = List(applyContext(beforeTyper(clazz.tpe)))
+ var parents = List(applyContext(enteringTyper(clazz.tpe_*)))
// log("!!! Parents: " + parents + ", sym: " + parents.map(_.typeSymbol))
if (parents.head.typeSymbol.isTrait)
parents = parents.head.parents.head :: parents
@@ -585,7 +595,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
GenPolyType(newClassTParams, ClassInfoType(parents ::: extraSpecializedMixins, decls1, sClass))
}
- afterSpecialize(sClass setInfo specializedInfoType)
+ exitingSpecialize(sClass setInfo specializedInfoType)
val fullEnv = outerEnv ++ env
/** Enter 'sym' in the scope of the current specialized class. It's type is
@@ -628,7 +638,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
info(om) = if (original.isDeferred) Forward(original) else Implementation(original)
typeEnv(om) = env ++ typeEnv(m) // add the environment for any method tparams
- overloads(specMember) ::= Overload(om, typeEnv(om))
+ newOverload(specMember, om, typeEnv(om))
enterMember(om)
}
@@ -679,7 +689,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
def mkAccessor(field: Symbol, name: Name) = {
val newFlags = (SPECIALIZED | m.getter(clazz).flags) & ~(LOCAL | CASEACCESSOR | PARAMACCESSOR)
// we rely on the super class to initialize param accessors
- val sym = sClass.newMethod(name, field.pos, newFlags)
+ val sym = sClass.newMethod(name.toTermName, field.pos, newFlags)
info(sym) = SpecializedAccessor(field)
sym
}
@@ -698,7 +708,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
// debuglog("m: " + m + " isLocal: " + nme.isLocalName(m.name) + " specVal: " + specVal.name + " isLocal: " + nme.isLocalName(specVal.name))
if (nme.isLocalName(m.name)) {
- val specGetter = mkAccessor(specVal, nme.localToGetter(specVal.name)) setInfo MethodType(Nil, specVal.info)
+ val specGetter = mkAccessor(specVal, nme.localToGetter(specVal.name.toTermName)) setInfo MethodType(Nil, specVal.info)
val origGetter = overrideIn(sClass, m.getter(clazz))
info(origGetter) = Forward(specGetter)
enterMember(specGetter)
@@ -773,7 +783,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
if (existing != NoSymbol)
clazz.owner.info.decls.unlink(existing)
- afterSpecialize(clazz.owner.info.decls enter spc) //!!! assumes fully specialized classes
+ exitingSpecialize(clazz.owner.info.decls enter spc) //!!! assumes fully specialized classes
}
if (subclasses.nonEmpty) clazz.resetFlag(FINAL)
cleanAnyRefSpecCache(clazz, decls1)
@@ -791,7 +801,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
*/
private def normalizeMember(owner: Symbol, sym: Symbol, outerEnv: TypeEnv): List[Symbol] = {
sym :: (
- if (!sym.isMethod || beforeTyper(sym.typeParams.isEmpty)) Nil
+ if (!sym.isMethod || enteringTyper(sym.typeParams.isEmpty)) Nil
else {
// debuglog("normalizeMember: " + sym.fullNameAsName('.').decode)
var specializingOn = specializedParams(sym)
@@ -835,7 +845,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
debuglog("%s expands to %s in %s".format(sym, specMember.name.decode, pp(env)))
info(specMember) = NormalizedMember(sym)
- overloads(sym) ::= Overload(specMember, env)
+ newOverload(sym, specMember, env)
owner.info.decls.enter(specMember)
specMember
}
@@ -870,6 +880,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
}
val specMember = subst(outerEnv)(specializedOverload(owner, sym, spec))
+ owner.info.decls.enter(specMember)
typeEnv(specMember) = typeEnv(sym) ++ outerEnv ++ spec
wasSpecializedForTypeVars(specMember) ++= spec collect { case (s, tp) if s.tpe == tp => s }
@@ -877,9 +888,8 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
if (wasSpec.nonEmpty)
debuglog("specialized overload for %s in %s".format(specMember, pp(typeEnv(specMember))))
- overloads(sym) ::= Overload(specMember, spec)
+ newOverload(sym, specMember, spec)
info(specMember) = SpecialOverload(sym, typeEnv(specMember))
-
specMember
}
@@ -899,10 +909,11 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
}
/** Return the specialized overload of `m`, in the given environment. */
- private def specializedOverload(owner: Symbol, sym: Symbol, env: TypeEnv): Symbol = {
+ private def specializedOverload(owner: Symbol, sym: Symbol, env: TypeEnv, nameSymbol: Symbol = NoSymbol): Symbol = {
val newFlags = (sym.flags | SPECIALIZED) & ~(DEFERRED | CASEACCESSOR)
// this method properly duplicates the symbol's info
- ( sym.cloneSymbol(owner, newFlags, newName = specializedName(sym, env))
+ val specname = specializedName(nameSymbol orElse sym, env)
+ ( sym.cloneSymbol(owner, newFlags, newName = specname)
modifyInfo (info => subst(env, info.asSeenFrom(owner.thisType, sym.owner)))
)
}
@@ -949,7 +960,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
checkOverriddenTParams(overridden)
val env = unify(overridden.info, overriding.info, emptyEnv, false, true)
- def atNext = afterSpecialize(overridden.owner.info.decl(specializedName(overridden, env)))
+ def atNext = exitingSpecialize(overridden.owner.info.decl(specializedName(overridden, env)))
if (TypeEnv.restrict(env, stvars).nonEmpty && TypeEnv.isValid(env, overridden) && atNext != NoSymbol) {
debuglog(" " + pp(env) + " found " + atNext)
@@ -962,19 +973,37 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
}
(clazz.info.decls flatMap { overriding =>
needsSpecialOverride(overriding) match {
- case (NoSymbol, _) => None
+ case (NoSymbol, _) =>
+ if (overriding.isSuperAccessor) {
+ val alias = overriding.alias
+ debuglog("checking special overload for super accessor: %s, alias for %s".format(overriding.fullName, alias.fullName))
+ needsSpecialOverride(alias) match {
+ case nope @ (NoSymbol, _) => None
+ case (overridden, env) =>
+ val om = specializedOverload(clazz, overriding, env, overridden)
+ om.setName(nme.superName(om.name))
+ om.asInstanceOf[TermSymbol].setAlias(info(alias).target)
+ om.owner.info.decls.enter(om)
+ info(om) = SpecialSuperAccessor(om)
+ om.makeNotPrivate(om.owner)
+ newOverload(overriding, om, env)
+ Some(om)
+ }
+ } else None
case (overridden, env) =>
val om = specializedOverload(clazz, overridden, env)
+ clazz.info.decls.enter(om)
foreachWithIndex(om.paramss) { (params, i) =>
foreachWithIndex(params) { (param, j) =>
param.name = overriding.paramss(i)(j).name // SI-6555 Retain the parameter names from the subclass.
}
}
debuglog("specialized overload %s for %s in %s: %s".format(om, overriding.name.decode, pp(env), om.info))
+ if (overriding.isAbstractOverride) om.setFlag(ABSOVERRIDE)
typeEnv(om) = env
addConcreteSpecMethod(overriding)
info(om) = (
- if (overriding.isDeferred) { // abstract override
+ if (overriding.isDeferred) { // abstract override
debuglog("abstract override " + overriding.fullName + " with specialized " + om.fullName)
Forward(overriding)
}
@@ -994,8 +1023,8 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
SpecialOverride(impl)
}
)
- overloads(overriding) ::= Overload(om, env)
- ifDebug(afterSpecialize(assert(
+ newOverload(overriding, om, env)
+ ifDebug(exitingSpecialize(assert(
overridden.owner.info.decl(om.name) != NoSymbol,
"Could not find " + om.name + " in " + overridden.owner.info.decls))
)
@@ -1024,7 +1053,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
if (isPrimitiveValueClass(tp2.typeSymbol) || isSpecializedAnyRefSubtype(tp2, sym1))
env + ((sym1, tp2))
else if (isSpecializedAnyRefSubtype(tp2, sym1))
- env + ((sym1, tp2)) // env + ((sym1, AnyRefClass.tpe))
+ env + ((sym1, tp2))
else if (strict)
unifyError(tp1, tp2)
else
@@ -1081,10 +1110,6 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
}
}
- /** Apply type bindings in the given environment `env` to all declarations. */
- private def subst(env: TypeEnv, decls: List[Symbol]): List[Symbol] =
- decls map subst(env)
-
/** Apply the type environment 'env' to the given type. All type
* bindings are supposed to be to primitive types. A type variable
* that is annotated with 'uncheckedVariance' is mapped to the corresponding
@@ -1111,33 +1136,10 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
private def subst(env: TypeEnv)(decl: Symbol): Symbol =
decl modifyInfo (info =>
- if (decl.isConstructor) MethodType(subst(env, info).params, decl.owner.tpe)
+ if (decl.isConstructor) MethodType(subst(env, info).params, decl.owner.tpe_*)
else subst(env, info)
)
- /** Checks if the type parameter symbol is not specialized
- * and is used as type parameters when extending a class with a specialized
- * type parameter.
- * At some point we may remove this restriction.
- *
- * Example:
- *
- * class Base[@specialized T]
- * class Derived[T] extends Base[T] // a non-specialized T is
- * // used as a type param for Base
- * // -> returning true
- */
- private def notSpecializedIn(tsym: Symbol, supertpe: Type) = supertpe match {
- case TypeRef(_, supersym, supertargs) =>
- val tspec = specializedOn(tsym).toSet
- for (supt <- supersym.typeParams) {
- val supspec = specializedOn(supt).toSet
- if (tspec != supspec && tspec.subsetOf(supspec))
- reporter.error(tsym.pos, "Type parameter has to be specialized at least for the same types as in the superclass. Missing types: " + (supspec.diff(tspec)).mkString(", "))
- }
- case _ => //log("nope")
- }
-
private def unspecializableClass(tp: Type) = (
definitions.isRepeatedParamType(tp) // ???
|| tp.typeSymbol.isJavaDefined
@@ -1153,7 +1155,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
case cinfo @ ClassInfoType(parents, decls, clazz) if !unspecializableClass(cinfo) =>
val tparams = tpe.typeParams
if (tparams.isEmpty)
- afterSpecialize(parents map (_.typeSymbol.info))
+ exitingSpecialize(parents map (_.typeSymbol.info))
val parents1 = parents mapConserve specializedType
if (parents ne parents1) {
@@ -1174,7 +1176,6 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
*
* A conflicting type environment could still be satisfiable.
*/
- def conflicting(env: TypeEnv) = !nonConflicting(env)
def nonConflicting(env: TypeEnv) = env forall { case (tvar, tpe) =>
(subst(env, tvar.info.bounds.lo) <:< tpe) && (tpe <:< subst(env, tvar.info.bounds.hi))
}
@@ -1244,9 +1245,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
class BodyDuplicator(_context: Context) extends super.BodyDuplicator(_context) {
override def castType(tree: Tree, pt: Type): Tree = {
- // log(" expected type: " + pt)
- // log(" tree type: " + tree.tpe)
- tree.tpe = if (tree.tpe != null) fixType(tree.tpe) else null
+ tree modifyType fixType
// log(" tree type: " + tree.tpe)
val ntree = if (tree.tpe != null && !(tree.tpe <:< pt)) {
val casttpe = CastMap(tree.tpe)
@@ -1254,8 +1253,8 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
else if (casttpe <:< CastMap(pt)) gen.mkCast(tree, pt)
else tree
} else tree
- ntree.tpe = null
- ntree
+
+ ntree.clearType()
}
}
@@ -1297,7 +1296,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
if (sym.isPrivate) debuglog(
"seeing private member %s, currentClass: %s, owner: %s, isAccessible: %b, isLocalName: %b".format(
sym, currentClass, sym.owner.enclClass, isAccessible(sym), nme.isLocalName(sym.name))
- )
+ )
if (shouldMakePublic(sym) && !isAccessible(sym)) {
debuglog("changing private flag of " + sym)
sym.makeNotPrivate(sym.owner)
@@ -1382,59 +1381,72 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
def transform1(tree: Tree) = {
val symbol = tree.symbol
-
/** The specialized symbol of 'tree.symbol' for tree.tpe, if there is one */
- def specSym(qual: Tree): Option[Symbol] = {
+ def specSym(qual: Tree): Symbol = {
val env = unify(symbol.tpe, tree.tpe, emptyEnv, false)
- debuglog("[specSym] checking for rerouting: %s with \n\tsym.tpe: %s, \n\ttree.tpe: %s \n\tenv: %s \n\tname: %s"
- .format(tree, symbol.tpe, tree.tpe, env, specializedName(symbol, env)))
- if (!env.isEmpty) { // a method?
- val specCandidates = qual.tpe.member(specializedName(symbol, env))
- val specMember = specCandidates suchThat { s =>
- doesConform(symbol, tree.tpe, qual.tpe.memberType(s), env)
- }
+ def isMatch(member: Symbol) = (
+ doesConform(symbol, tree.tpe, qual.tpe memberType member, env)
+ && TypeEnv.includes(typeEnv(member), env)
+ )
+ if (env.isEmpty) NoSymbol
+ else qual.tpe member specializedName(symbol, env) suchThat isMatch
+ }
- debuglog("[specSym] found: " + specCandidates.tpe + ", instantiated as: " + tree.tpe)
- debuglog("[specSym] found specMember: " + specMember)
- if (specMember ne NoSymbol)
- if (TypeEnv.includes(typeEnv(specMember), env)) Some(specMember)
- else {
- debuglog("wrong environments for specialized member: \n\ttypeEnv(%s) = %s\n\tenv = %s".format(specMember, typeEnv(specMember), env))
- None
- }
- else None
- } else None
+ def matchingSymbolInPrefix(pre: Type, member: Symbol, env: TypeEnv): Symbol = {
+ pre member specializedName(member, env) suchThat (_.tpe matches subst(env, member.tpe))
+ }
+
+ def transformSelect(sel: Select) = {
+ val Select(qual, name) = sel
+ debuglog(s"specializing Select(sym=${symbol.defString}, tree.tpe=${tree.tpe})")
+
+ val qual1 = transform(qual)
+ def copySelect = treeCopy.Select(tree, qual1, name)
+ def newSelect(member: Symbol) = atPos(tree.pos)(Select(qual1, member))
+ def typedOp(member: Symbol) = localTyper typedOperator newSelect(member)
+ def typedTree(member: Symbol) = localTyper typed newSelect(member)
+
+ val ignoreEnv = specializedTypeVars(symbol.info).isEmpty || name == nme.CONSTRUCTOR
+ if (ignoreEnv) overloads(symbol) find (_ matchesSym symbol) match {
+ case Some(Overload(member, _)) => typedOp(member)
+ case _ => copySelect
+ }
+ else {
+ val env = unify(symbol.tpe, tree.tpe, emptyEnv, false)
+ overloads(symbol) find (_ matchesEnv env) match {
+ case Some(Overload(member, _)) => typedOp(member)
+ case _ =>
+ matchingSymbolInPrefix(qual1.tpe, symbol, env) match {
+ case NoSymbol => copySelect
+ case member if member.isMethod => typedOp(member)
+ case member => typedTree(member)
+ }
+ }
+ }
}
curTree = tree
tree match {
case Apply(Select(New(tpt), nme.CONSTRUCTOR), args) =>
def transformNew = {
- debuglog("Attempting to specialize new %s(%s)".format(tpt, args.mkString(", ")))
- val found = findSpec(tpt.tpe)
- if (found.typeSymbol ne tpt.tpe.typeSymbol) {
- // the ctor can be specialized
- debuglog("** instantiated specialized type: " + found)
- reportError {
- localTyper.typedPos(tree.pos)(New(found, transformTrees(args): _*))
- } {
- _ => super.transform(tree)
+ debuglog("Attempting to specialize new %s(%s)".format(tpt, args.mkString(", ")))
+ val found = specializedType(tpt.tpe)
+ if (found.typeSymbol ne tpt.tpe.typeSymbol) { // the ctor can be specialized
+ val inst = New(found, transformTrees(args): _*)
+ reportError(localTyper.typedPos(tree.pos)(inst))(_ => super.transform(tree))
}
- } else super.transform(tree)
+ else
+ super.transform(tree)
}
transformNew
- case Apply(sel @ Select(sup @ Super(qual, name), name1), args)
- if (sup.symbol.info.parents != beforePrevPhase(sup.symbol.info.parents)) =>
+ case Apply(sel @ Select(sup @ Super(qual, name), name1), args) if hasNewParents(sup) =>
def transformSuperApply = {
-
- def parents = sup.symbol.info.parents
- debuglog(tree + " parents changed from: " + beforePrevPhase(parents) + " to: " + parents)
-
- val res = localTyper.typed(
- Apply(Select(Super(qual, name) setPos sup.pos, name1) setPos sel.pos, transformTrees(args)) setPos tree.pos)
- debuglog("retyping call to super, from: " + symbol + " to " + res.symbol)
- res
+ val sup1 = Super(qual, name) setPos sup.pos
+ val tree1 = Apply(Select(sup1, name1) setPos sel.pos, transformTrees(args))
+ val res = localTyper.typedPos(tree.pos)(tree1)
+ debuglog(s"retyping call to super, from: $symbol to ${res.symbol}")
+ res
}
transformSuperApply
@@ -1445,7 +1457,10 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
val qual1 = transform(qual)
// log(">>> TypeApply: " + tree + ", qual1: " + qual1)
specSym(qual1) match {
- case Some(specMember) =>
+ case NoSymbol =>
+ // See pos/exponential-spec.scala - can't call transform on the whole tree again.
+ treeCopy.TypeApply(tree, treeCopy.Select(sel, qual1, name), transformTrees(targs))
+ case specMember =>
debuglog("found " + specMember.fullName)
ifDebug(assert(symbol.info.typeParams.length == targs.length, symbol.info.typeParams + " / " + targs))
@@ -1455,7 +1470,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
}
// See SI-5583. Don't know why it happens now if it didn't before.
if (specMember.info.typeParams.isEmpty && residualTargs.nonEmpty) {
- log("!!! Type args to be applied, but symbol says no parameters: " + ((specMember.defString, residualTargs)))
+ devWarning("Type args to be applied, but symbol says no parameters: " + ((specMember.defString, residualTargs)))
localTyper.typed(sel)
}
else {
@@ -1467,63 +1482,17 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
debuglog("rewrote " + tree + " to " + tree1)
localTyper.typedOperator(atPos(tree.pos)(tree1)) // being polymorphic, it must be a method
}
-
- case None =>
- treeCopy.TypeApply(tree, treeCopy.Select(sel, qual1, name), super.transformTrees(targs))
- // See pos/exponential-spec.scala - can't call transform on the whole tree again.
- // super.transform(tree)
}
}
transformTypeApply
- case Select(qual, name) =>
- def transformSelect = {
- qual match {
- case _: Super if illegalSpecializedInheritance(currentClass) =>
- val pos = tree.pos
- debuglog(pos.source.file.name+":"+pos.line+": not specializing call to super inside illegal specialized inheritance class.")
- debuglog(pos.lineContent)
- tree
- case _ =>
+ case Select(Super(_, _), _) if illegalSpecializedInheritance(currentClass) =>
+ val pos = tree.pos
+ debuglog(pos.source.file.name+":"+pos.line+": not specializing call to super inside illegal specialized inheritance class.\n" + pos.lineContent)
+ tree
- debuglog("specializing Select %s [tree.tpe: %s]".format(symbol.defString, tree.tpe))
-
- //log("!!! select " + tree + " -> " + symbol.info + " specTypeVars: " + specializedTypeVars(symbol.info))
- if (specializedTypeVars(symbol.info).nonEmpty && name != nme.CONSTRUCTOR) {
- // log("!!! unifying " + (symbol, symbol.tpe) + " and " + (tree, tree.tpe))
- val env = unify(symbol.tpe, tree.tpe, emptyEnv, false)
- // log("!!! found env: " + env + "; overloads: " + overloads(symbol))
- if (!env.isEmpty) {
- // debuglog("checking for rerouting: " + tree + " with sym.tpe: " + symbol.tpe + " tree.tpe: " + tree.tpe + " env: " + env)
- val specMember = overload(symbol, env)
- if (specMember.isDefined) {
- localTyper.typedOperator(atPos(tree.pos)(Select(transform(qual), specMember.get.sym.name)))
- }
- else {
- val qual1 = transform(qual)
- val specMember = qual1.tpe.member(specializedName(symbol, env)).suchThat(_.tpe matches subst(env, symbol.tpe))
- if (specMember ne NoSymbol) {
- val tree1 = atPos(tree.pos)(Select(qual1, specMember))
- if (specMember.isMethod)
- localTyper.typedOperator(tree1)
- else
- localTyper.typed(tree1)
- } else
- treeCopy.Select(tree, qual1, name)
- }
- } else
- super.transform(tree)
- } else overloads(symbol).find(_.sym.info =:= symbol.info) match {
- case Some(specMember) =>
- val qual1 = transform(qual)
- debuglog("** routing " + tree + " to " + specMember.sym.fullName + " tree: " + Select(qual1, specMember.sym))
- localTyper.typedOperator(atPos(tree.pos)(Select(qual1, specMember.sym)))
- case None =>
- super.transform(tree)
- }
- }
- }
- transformSelect
+ case sel @ Select(_, _) =>
+ transformSelect(sel)
case PackageDef(pid, stats) =>
tree.symbol.info // make sure specializations have been performed
@@ -1548,47 +1517,37 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
transformTemplate
case ddef @ DefDef(_, _, _, vparamss, _, _) if info.isDefinedAt(symbol) =>
- def transformDefDef = {
- // log("--> method: " + ddef + " in " + ddef.symbol.owner + ", " + info(symbol))
- def reportTypeError(body: =>Tree) = reportError(body)(_ => ddef)
-
+ def transformDefDef = {
if (symbol.isConstructor) {
-
- val t = atOwner(symbol)(forwardCtorCall(tree.pos, gen.mkSuperSelect, vparamss, symbol.owner))
-
+ val t = atOwner(symbol)(forwardCtorCall(tree.pos, gen.mkSuperInitCall, vparamss, symbol.owner))
if (symbol.isPrimaryConstructor)
localTyper.typedPos(symbol.pos)(deriveDefDef(tree)(_ => Block(List(t), Literal(Constant()))))
else // duplicate the original constructor
- reportTypeError(duplicateBody(ddef, info(symbol).target))
+ reportError(duplicateBody(ddef, info(symbol).target))(_ => ddef)
}
else info(symbol) match {
case Implementation(target) =>
assert(body.isDefinedAt(target), "sym: " + symbol.fullName + " target: " + target.fullName)
// we have an rhs, specialize it
- val tree1 = reportTypeError {
- duplicateBody(ddef, target)
- }
+ val tree1 = reportError(duplicateBody(ddef, target))(_ => ddef)
debuglog("implementation: " + tree1)
deriveDefDef(tree1)(transform)
case NormalizedMember(target) =>
- val constraints = satisfiabilityConstraints(typeEnv(symbol))
- log("constraints: " + constraints)
- if (target.isDeferred || constraints == None) {
- deriveDefDef(tree)(_ => localTyper typed gen.mkSysErrorCall("Fatal error in code generation: this should never be called."))
- } else {
- // we have an rhs, specialize it
- val tree1 = reportTypeError {
- duplicateBody(ddef, target, constraints.get)
- }
- debuglog("implementation: " + tree1)
- deriveDefDef(tree1)(transform)
+ logResult("constraints")(satisfiabilityConstraints(typeEnv(symbol))) match {
+ case Some(constraint) if !target.isDeferred =>
+ // we have an rhs, specialize it
+ val tree1 = reportError(duplicateBody(ddef, target, constraint))(_ => ddef)
+ debuglog("implementation: " + tree1)
+ deriveDefDef(tree1)(transform)
+ case _ =>
+ deriveDefDef(tree)(_ => localTyper typed gen.mkSysErrorCall("Fatal error in code generation: this should never be called."))
}
case SpecialOverride(target) =>
assert(body.isDefinedAt(target), "sym: " + symbol.fullName + " target: " + target.fullName)
//debuglog("moving implementation, body of target " + target + ": " + body(target))
- debuglog("%s is param accessor? %b".format(ddef.symbol, ddef.symbol.isParamAccessor))
+ log("%s is param accessor? %b".format(ddef.symbol, ddef.symbol.isParamAccessor))
// we have an rhs, specialize it
val tree1 = addBody(ddef, target)
(new ChangeOwnerTraverser(target, tree1.symbol))(tree1.rhs)
@@ -1636,6 +1595,10 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
case Abstract(targ) =>
debuglog("abstract: " + targ)
localTyper.typed(deriveDefDef(tree)(rhs => rhs))
+
+ case SpecialSuperAccessor(targ) =>
+ debuglog("special super accessor: " + targ + " for " + tree)
+ localTyper.typed(deriveDefDef(tree)(rhs => rhs))
}
}
transformDefDef
@@ -1657,7 +1620,6 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
deriveValDef(newValDef)(transform)
}
transformValDef
-
case _ =>
super.transform(tree)
}
@@ -1694,7 +1656,6 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
val symbol = tree.symbol
debuglog("specializing body of" + symbol.defString)
val DefDef(_, _, tparams, vparams :: Nil, tpt, _) = tree
-// val (_, origtparams) = splitParams(source.typeParams)
val env = typeEnv(symbol)
val boundTvars = env.keySet
val origtparams = source.typeParams.filter(tparam => !boundTvars(tparam) || !isPrimitiveValueType(env(tparam)))
@@ -1721,8 +1682,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
false) // don't make private fields public
val newBody = symSubstituter(body(source).duplicate)
- tpt.tpe = tpt.tpe.substSym(oldtparams, newtparams)
-
+ tpt modifyType (_.substSym(oldtparams, newtparams))
copyDefDef(tree)(vparamss = List(newSyms map ValDef), rhs = newBody)
}
@@ -1829,6 +1789,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
* }}
*/
private def forwardCtorCall(pos: scala.reflect.internal.util.Position, receiver: Tree, paramss: List[List[ValDef]], clazz: Symbol): Tree = {
+ log(s"forwardCtorCall($pos, $receiver, $paramss, $clazz)")
/** A constructor parameter `f` initializes a specialized field
* iff:
@@ -1865,16 +1826,12 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
//! TODO: make sure the param types are seen from the right prefix
map2(fun.info.paramTypes, vparams)((tp, arg) => gen.maybeMkAsInstanceOf(Ident(arg), tp, arg.tpe))
)
- private def findSpec(tp: Type): Type = tp match {
- case TypeRef(pre, sym, _ :: _) => specializedType(tp)
- case _ => tp
- }
class SpecializationTransformer(unit: CompilationUnit) extends Transformer {
informProgress("specializing " + unit)
override def transform(tree: Tree) = {
val resultTree = if (settings.nospecialization.value) tree
- else afterSpecialize(specializeCalls(unit).transform(tree))
+ else exitingSpecialize(specializeCalls(unit).transform(tree))
// Remove the final modifier and @inline annotation from anything in the
// original class (since it's being overridden in at least onesubclass).
@@ -1894,11 +1851,4 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
resultTree
}
}
-
- def printSpecStats() {
- println(" concreteSpecMembers: %7d".format(concreteSpecMethods.size))
- println(" overloads: %7d".format(overloads.size))
- println(" typeEnv: %7d".format(typeEnv.size))
- println(" info: %7d".format(info.size))
- }
}
diff --git a/src/compiler/scala/tools/nsc/transform/TailCalls.scala b/src/compiler/scala/tools/nsc/transform/TailCalls.scala
index a767850cba..c375bc4362 100644
--- a/src/compiler/scala/tools/nsc/transform/TailCalls.scala
+++ b/src/compiler/scala/tools/nsc/transform/TailCalls.scala
@@ -17,7 +17,7 @@ import Flags.SYNTHETIC
abstract class TailCalls extends Transform {
import global._ // the global environment
import definitions._ // standard classes and methods
- import typer.{ typed, typedPos } // methods to type trees
+ import typer.typedPos // methods to type trees
val phaseName: String = "tailcalls"
@@ -82,7 +82,7 @@ abstract class TailCalls extends Transform {
* that label.
* </p>
* <p>
- * Assumes: <code>Uncurry</code> has been run already, and no multiple
+ * Assumes: `Uncurry` has been run already, and no multiple
* parameter lists exit.
* </p>
*/
@@ -147,10 +147,9 @@ abstract class TailCalls extends Transform {
}
def enclosingType = method.enclClass.typeOfThis
- def methodTypeParams = method.tpe.typeParams
def isEligible = method.isEffectivelyFinal
// @tailrec annotation indicates mandatory transformation
- def isMandatory = method.hasAnnotation(TailrecClass) && !forMSIL
+ def isMandatory = method.hasAnnotation(TailrecClass)
def isTransformed = isEligible && accessed(label)
def tailrecFailure() = unit.error(failPos, "could not optimize @tailrec annotated " + method + ": " + failReason)
@@ -230,7 +229,6 @@ abstract class TailCalls extends Transform {
}
else if (!matchesTypeArgs) failHere("it is called recursively with different type arguments")
else if (receiver == EmptyTree) rewriteTailCall(This(currentClass))
- else if (forMSIL) fail("it cannot be optimized on MSIL")
else if (!receiverIsSame) failHere("it changes type of 'this' on a polymorphic recursive call")
else rewriteTailCall(receiver)
}
diff --git a/src/compiler/scala/tools/nsc/transform/TypingTransformers.scala b/src/compiler/scala/tools/nsc/transform/TypingTransformers.scala
index c7bc16f249..73f39225bd 100644
--- a/src/compiler/scala/tools/nsc/transform/TypingTransformers.scala
+++ b/src/compiler/scala/tools/nsc/transform/TypingTransformers.scala
@@ -6,8 +6,6 @@
package scala.tools.nsc
package transform
-import scala.collection.{ mutable, immutable }
-
/** A base class for transforms.
* A transform contains a compiler phase which applies a tree transformer.
*/
@@ -23,13 +21,11 @@ trait TypingTransformers {
else
analyzer.newTyper(analyzer.rootContext(unit, EmptyTree, true))
protected var curTree: Tree = _
- protected def typedPos(pos: Position)(tree: Tree) = localTyper typed { atPos(pos)(tree) }
override final def atOwner[A](owner: Symbol)(trans: => A): A = atOwner(curTree, owner)(trans)
def atOwner[A](tree: Tree, owner: Symbol)(trans: => A): A = {
val savedLocalTyper = localTyper
-// println("transformer atOwner: " + owner + " isPackage? " + owner.isPackage)
localTyper = localTyper.atOwner(tree, if (owner.isModule) owner.moduleClass else owner)
val result = super.atOwner(owner)(trans)
localTyper = savedLocalTyper
diff --git a/src/compiler/scala/tools/nsc/transform/UnCurry.scala b/src/compiler/scala/tools/nsc/transform/UnCurry.scala
index 838ea7d5a0..b94ae99263 100644
--- a/src/compiler/scala/tools/nsc/transform/UnCurry.scala
+++ b/src/compiler/scala/tools/nsc/transform/UnCurry.scala
@@ -61,24 +61,6 @@ abstract class UnCurry extends InfoTransform
// uncurry and uncurryType expand type aliases
- /** Traverse tree omitting local method definitions.
- * If a `return` is encountered, set `returnFound` to true.
- * Used for MSIL only.
- */
- private object lookForReturns extends Traverser {
- var returnFound = false
- override def traverse(tree: Tree): Unit = tree match {
- case Return(_) => returnFound = true
- case DefDef(_, _, _, _, _, _) => ;
- case _ => super.traverse(tree)
- }
- def found(tree: Tree) = {
- returnFound = false
- traverse(tree)
- returnFound
- }
- }
-
class UnCurryTransformer(unit: CompilationUnit) extends TypingTransformer(unit) {
private var needTryLift = false
private var inPattern = false
@@ -112,8 +94,6 @@ abstract class UnCurry extends InfoTransform
private lazy val serialVersionUIDAnnotation =
AnnotationInfo(SerialVersionUIDAttr.tpe, List(Literal(Constant(0))), List())
- private var nprinted = 0
-
// I don't have a clue why I'm catching TypeErrors here, but it's better
// than spewing stack traces at end users for internal errors. Examples
// which hit at this point should not be hard to come by, but the immediate
@@ -134,7 +114,7 @@ abstract class UnCurry extends InfoTransform
def isByNameRef(tree: Tree) = (
tree.isTerm
&& !byNameArgs(tree)
- && tree.hasSymbolWhich(s => isByNameParamType(s.tpe))
+ && tree.hasSymbolWhich(isByName)
)
/** Uncurry a type of a tree node.
@@ -205,6 +185,9 @@ abstract class UnCurry extends InfoTransform
val keyDef = ValDef(key, New(ObjectClass.tpe))
val tryCatch = Try(body, pat -> rhs)
+ for (Try(t, catches, _) <- body ; cdef <- catches ; if treeInfo catchesThrowable cdef)
+ unit.warning(body.pos, "catch block may intercept non-local return from " + meth)
+
Block(List(keyDef), tryCatch)
}
}
@@ -299,7 +282,8 @@ abstract class UnCurry extends InfoTransform
* If there's a default case, the original match is used for applyOrElse, and isDefinedAt returns `true`
*/
def synthPartialFunction(fun: Function) = {
- if (!settings.XoldPatmat.value) debugwarn("Under the new pattern matching scheme, PartialFunction should have been synthesized during typers.")
+ if (!settings.XoldPatmat.value)
+ devWarning("Under the new pattern matching scheme, PartialFunction should have been synthesized during typers.")
val targs = fun.tpe.typeArgs
val (formals, restpe) = (targs.init, targs.last)
@@ -338,7 +322,7 @@ abstract class UnCurry extends InfoTransform
// def applyOrElse[A1 <: A, B1 >: B](x: A1, default: A1 => B1): B1 =
val applyOrElseMethodDef = {
- val methSym = anonClass.newMethod(fun.pos, nme.applyOrElse) setFlag (FINAL | OVERRIDE)
+ val methSym = anonClass.newMethod(nme.applyOrElse, fun.pos, newFlags = FINAL | OVERRIDE | SYNTHETIC)
val List(argtpe) = formals
val A1 = methSym newTypeParameter(newTypeName("A1")) setInfo TypeBounds.upper(argtpe)
@@ -381,11 +365,11 @@ abstract class UnCurry extends InfoTransform
val body = bodyForIDA match {
case Match(selector, cases) =>
- if (cases exists treeInfo.isDefaultCase) TRUE_typed
+ if (cases exists treeInfo.isDefaultCase) TRUE
else
doSubst(Match(/*gen.mkUnchecked*/(selector),
- (cases map (c => deriveCaseDef(c)(x => TRUE_typed))) :+ (
- DEFAULT ==> FALSE_typed)))
+ (cases map (c => deriveCaseDef(c)(x => TRUE))) :+ (
+ DEFAULT ==> FALSE)))
}
body.changeOwner(fun.symbol -> methSym)
@@ -408,7 +392,7 @@ abstract class UnCurry extends InfoTransform
// when calling into scala varargs, make sure it's a sequence.
def arrayToSequence(tree: Tree, elemtp: Type) = {
- afterUncurry {
+ exitingUncurry {
localTyper.typedPos(pos) {
val pt = arrayType(elemtp)
val adaptedTree = // might need to cast to Array[elemtp], as arrays are not covariant
@@ -438,7 +422,7 @@ abstract class UnCurry extends InfoTransform
case _ => EmptyTree
}
}
- afterUncurry {
+ exitingUncurry {
localTyper.typedPos(pos) {
gen.mkMethodCall(tree, toArraySym, Nil, List(traversableClassTag(tree.tpe)))
}
@@ -462,7 +446,7 @@ abstract class UnCurry extends InfoTransform
else arrayToSequence(mkArray, varargsElemType)
}
- afterUncurry {
+ exitingUncurry {
if (isJava && !isReferenceArray(suffix.tpe) && isArrayOfSymbol(fun.tpe.params.last.tpe, ObjectClass)) {
// The array isn't statically known to be a reference array, so call ScalaRuntime.toObjectArray.
suffix = localTyper.typedPos(pos) {
@@ -538,13 +522,6 @@ abstract class UnCurry extends InfoTransform
finally needTryLift = saved
}
- /** A try or synchronized needs to be lifted anyway for MSIL if it contains
- * return statements. These are disallowed in the CLR. By lifting
- * such returns will be converted to throws.
- */
- def shouldBeLiftedAnyway(tree: Tree) = false && // buggy, see #1981
- forMSIL && lookForReturns.found(tree)
-
/** Transform tree `t` to { def f = t; f } where `f` is a fresh name
*/
def liftTree(tree: Tree) = {
@@ -619,15 +596,12 @@ abstract class UnCurry extends InfoTransform
treeCopy.UnApply(tree, fn1, args1)
case Apply(fn, args) =>
- if (fn.symbol == Object_synchronized && shouldBeLiftedAnyway(args.head))
- transform(treeCopy.Apply(tree, fn, List(liftTree(args.head))))
- else
- withNeedLift(true) {
- val formals = fn.tpe.paramTypes
- treeCopy.Apply(tree, transform(fn), transformTrees(transformArgs(tree.pos, fn.symbol, args, formals)))
- }
+ withNeedLift(true) {
+ val formals = fn.tpe.paramTypes
+ treeCopy.Apply(tree, transform(fn), transformTrees(transformArgs(tree.pos, fn.symbol, args, formals)))
+ }
- case Assign(Select(_, _), _) =>
+ case Assign(_: RefTree, _) =>
withNeedLift(true) { super.transform(tree) }
case Assign(lhs, _) if lhs.symbol.owner != currentMethod || lhs.symbol.hasFlag(LAZY | ACCESSOR) =>
@@ -644,7 +618,7 @@ abstract class UnCurry extends InfoTransform
super.transform(tree)
case Try(block, catches, finalizer) =>
- if (needTryLift || shouldBeLiftedAnyway(tree)) transform(liftTree(tree))
+ if (needTryLift) transform(liftTree(tree))
else super.transform(tree)
case CaseDef(pat, guard, body) =>
@@ -669,11 +643,11 @@ abstract class UnCurry extends InfoTransform
tree1
}
)
- assert(result.tpe != null, result + " tpe is null")
+ assert(result.tpe != null, result.shortClass + " tpe is null:\n" + result)
result setType uncurryTreeType(result.tpe)
}
- def postTransform(tree: Tree): Tree = afterUncurry {
+ def postTransform(tree: Tree): Tree = exitingUncurry {
def applyUnary(): Tree = {
// TODO_NMT: verify that the inner tree of a type-apply also gets parens if the
// whole tree is a polymorphic nullary method application
@@ -704,9 +678,9 @@ abstract class UnCurry extends InfoTransform
val body = tree.block
val catches = tree.catches
val finalizer = tree.finalizer
- if (opt.virtPatmat) {
+ if (!settings.XoldPatmat.value) {
if (catches exists (cd => !treeInfo.isCatchCase(cd)))
- debugwarn("VPM BUG! illegal try/catch " + catches)
+ devWarning("VPM BUG - illegal try/catch " + catches)
tree
} else if (catches forall treeInfo.isCatchCase) {
tree
@@ -802,10 +776,6 @@ abstract class UnCurry extends InfoTransform
if (!dd.symbol.hasAnnotation(VarargsClass) || !repeatedParams.contains(dd.symbol))
return flatdd
- def toSeqType(tp: Type): Type = {
- val arg = elementType(ArrayClass, tp)
- seqType(arg)
- }
def toArrayType(tp: Type): Type = {
val arg = elementType(SeqClass, tp)
// to prevent generation of an `Object` parameter from `Array[T]` parameter later
@@ -840,7 +810,7 @@ abstract class UnCurry extends InfoTransform
}
// create the symbol
- val forwsym = currentClass.newMethod(dd.name, dd.pos, VARARGS | SYNTHETIC | flatdd.symbol.flags) setInfo forwtype
+ val forwsym = currentClass.newMethod(dd.name.toTermName, dd.pos, VARARGS | SYNTHETIC | flatdd.symbol.flags) setInfo forwtype
// create the tree
val forwtree = theTyper.typedPos(dd.pos) {
diff --git a/src/compiler/scala/tools/nsc/typechecker/Analyzer.scala b/src/compiler/scala/tools/nsc/typechecker/Analyzer.scala
index 78175f393a..5e8bb3e424 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Analyzer.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Analyzer.scala
@@ -87,22 +87,25 @@ trait Analyzer extends AnyRef
override def run() {
val start = if (Statistics.canEnable) Statistics.startTimer(typerNanos) else null
global.echoPhaseSummary(this)
- currentRun.units foreach applyPhase
- undoLog.clear()
- // need to clear it after as well or 10K+ accumulated entries are
- // uncollectable the rest of the way.
+ for (unit <- currentRun.units) {
+ applyPhase(unit)
+ undoLog.clear()
+ }
if (Statistics.canEnable) Statistics.stopTimer(typerNanos, start)
}
def apply(unit: CompilationUnit) {
try {
- unit.body = newTyper(rootContext(unit)).typed(unit.body)
+ val typer = newTyper(rootContext(unit))
+ unit.body = typer.typed(unit.body)
if (global.settings.Yrangepos.value && !global.reporter.hasErrors) global.validatePositions(unit.body)
for (workItem <- unit.toCheck) workItem()
- } finally {
+ if (settings.lint.value)
+ typer checkUnused unit
+ }
+ finally {
unit.toCheck.clear()
}
}
}
}
}
-
diff --git a/src/compiler/scala/tools/nsc/typechecker/Checkable.scala b/src/compiler/scala/tools/nsc/typechecker/Checkable.scala
index d30b5c2601..9efa3f36b0 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Checkable.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Checkable.scala
@@ -6,12 +6,8 @@
package scala.tools.nsc
package typechecker
-import scala.collection.{ mutable, immutable }
-import scala.collection.mutable.ListBuffer
-import scala.util.control.ControlThrowable
-import symtab.Flags._
-import scala.annotation.tailrec
import Checkability._
+import scala.language.postfixOps
/** On pattern matcher checkability:
*
@@ -134,7 +130,7 @@ trait Checkable {
else if (P3) RuntimeCheckable
else if (uncheckableType == NoType) {
// Avoid warning (except ourselves) if we can't pinpoint the uncheckable type
- debugwarn("Checkability checker says 'Uncheckable', but uncheckable type cannot be found:\n" + summaryString)
+ debuglog("Checkability checker says 'Uncheckable', but uncheckable type cannot be found:\n" + summaryString)
CheckabilityError
}
else Uncheckable
@@ -154,6 +150,7 @@ trait Checkable {
def neverSubClass = isNeverSubClass(Xsym, Psym)
def neverMatches = result == StaticallyFalse
def isUncheckable = result == Uncheckable
+ def isCheckable = !isUncheckable
def uncheckableMessage = uncheckableType match {
case NoType => "something"
case tp @ RefinedType(_, _) => "refinement " + tp
@@ -232,6 +229,17 @@ trait Checkable {
trait InferCheckable {
self: Inferencer =>
+ def isUncheckable(P0: Type) = !isCheckable(P0)
+
+ def isCheckable(P0: Type): Boolean = (
+ uncheckedOk(P0) || (P0.widen match {
+ case TypeRef(_, NothingClass | NullClass | AnyValClass, _) => false
+ case RefinedType(_, decls) if !decls.isEmpty => false
+ case p =>
+ new CheckabilityChecker(AnyClass.tpe, p) isCheckable
+ })
+ )
+
/** TODO: much better error positions.
* Kind of stuck right now because they just pass us the one tree.
* TODO: Eliminate inPattern, canRemedy, which have no place here.
diff --git a/src/compiler/scala/tools/nsc/typechecker/ConstantFolder.scala b/src/compiler/scala/tools/nsc/typechecker/ConstantFolder.scala
index 89e2ee44be..65bfd8e34e 100644
--- a/src/compiler/scala/tools/nsc/typechecker/ConstantFolder.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/ConstantFolder.scala
@@ -6,7 +6,6 @@
package scala.tools.nsc
package typechecker
-
import java.lang.ArithmeticException
/** This class ...
@@ -18,7 +17,6 @@ abstract class ConstantFolder {
val global: Global
import global._
- import definitions._
/** If tree is a constant operation, replace with result. */
def apply(tree: Tree): Tree = fold(tree, tree match {
@@ -29,9 +27,6 @@ abstract class ConstantFolder {
/** If tree is a constant value that can be converted to type `pt`, perform
* the conversion.
- *
- * @param tree ...
- * @param pt ...
*/
def apply(tree: Tree, pt: Type): Tree = fold(apply(tree), tree.tpe match {
case ConstantType(x) => x convertTo pt
diff --git a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala
index 4268398081..27944b8767 100644
--- a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala
@@ -6,9 +6,8 @@
package scala.tools.nsc
package typechecker
-import scala.collection.{ mutable, immutable }
import scala.reflect.internal.util.StringOps.{ countElementsAsString, countAsString }
-import symtab.Flags.{ PRIVATE, PROTECTED, IS_ERROR }
+import symtab.Flags.IS_ERROR
import scala.compat.Platform.EOL
import scala.reflect.runtime.ReflectionUtils
import scala.reflect.macros.runtime.AbortMacroException
@@ -155,9 +154,8 @@ trait ContextErrors {
// the found/req types.
val foundType: Type = req.normalize match {
case RefinedType(parents, decls) if !decls.isEmpty && found.typeSymbol.isAnonOrRefinementClass =>
- val retyped = typed (tree.duplicate setType null)
+ val retyped = typed (tree.duplicate.clearType())
val foundDecls = retyped.tpe.decls filter (sym => !sym.isConstructor && !sym.isSynthetic)
-
if (foundDecls.isEmpty || (found.typeSymbol eq NoSymbol)) found
else {
// The members arrive marked private, presumably because there was no
@@ -171,11 +169,11 @@ trait ContextErrors {
case _ =>
found
}
- assert(!found.isErroneous && !req.isErroneous, (found, req))
+ assert(!foundType.isErroneous && !req.isErroneous, (foundType, req))
- issueNormalTypeError(tree, withAddendum(tree.pos)(typeErrorMsg(found, req, infer.isPossiblyMissingArgs(found, req))) )
+ issueNormalTypeError(tree, withAddendum(tree.pos)(typeErrorMsg(foundType, req, infer.isPossiblyMissingArgs(foundType, req))) )
if (settings.explaintypes.value)
- explainTypes(found, req)
+ explainTypes(foundType, req)
}
def WithFilterError(tree: Tree, ex: AbsTypeError) = {
@@ -184,7 +182,7 @@ trait ContextErrors {
}
def ParentTypesError(templ: Template, ex: TypeError) = {
- templ.tpe = null
+ templ.clearType()
issueNormalTypeError(templ, ex.getMessage())
setError(templ)
}
@@ -273,9 +271,6 @@ trait ContextErrors {
def VolatileValueError(vdef: Tree) =
issueNormalTypeError(vdef, "values cannot be volatile")
- def FinalVolatileVarError(vdef: Tree) =
- issueNormalTypeError(vdef, "final vars cannot be volatile")
-
def LocalVarUninitializedError(vdef: Tree) =
issueNormalTypeError(vdef, "local variables must be initialized")
@@ -520,7 +515,7 @@ trait ContextErrors {
NormalTypeError(tree, fun.tpe+" does not take parameters")
// Dynamic
- def DynamicVarArgUnsupported(tree: Tree, name: String) =
+ def DynamicVarArgUnsupported(tree: Tree, name: Name) =
issueNormalTypeError(tree, name+ " does not support passing a vararg parameter")
def DynamicRewriteError(tree: Tree, err: AbsTypeError) = {
@@ -664,8 +659,8 @@ trait ContextErrors {
def CyclicAliasingOrSubtypingError(errPos: Position, sym0: Symbol) =
issueTypeError(PosAndMsgTypeError(errPos, "cyclic aliasing or subtyping involving "+sym0))
- def CyclicReferenceError(errPos: Position, lockedSym: Symbol) =
- issueTypeError(PosAndMsgTypeError(errPos, "illegal cyclic reference involving " + lockedSym))
+ def CyclicReferenceError(errPos: Position, tp: Type, lockedSym: Symbol) =
+ issueTypeError(PosAndMsgTypeError(errPos, s"illegal cyclic reference involving $tp and $lockedSym"))
// macro-related errors (also see MacroErrors below)
@@ -677,10 +672,9 @@ trait ContextErrors {
// same reason as for MacroBodyTypecheckException
case object MacroExpansionException extends Exception with scala.util.control.ControlThrowable
- private def macroExpansionError(expandee: Tree, msg: String = null, pos: Position = NoPosition) = {
+ private def macroExpansionError(expandee: Tree, msg: String, pos: Position = NoPosition) = {
def msgForLog = if (msg != null && (msg contains "exception during macro expansion")) msg.split(EOL).drop(1).headOption.getOrElse("?") else msg
macroLogLite("macro expansion has failed: %s".format(msgForLog))
- val errorPos = if (pos != NoPosition) pos else (if (expandee.pos != NoPosition) expandee.pos else enclosingMacroPosition)
if (msg != null) context.error(pos, msg) // issueTypeError(PosAndMsgTypeError(..)) won't work => swallows positions
setError(expandee)
throw MacroExpansionException
@@ -809,7 +803,10 @@ trait ContextErrors {
)
}
- def AccessError(tree: Tree, sym: Symbol, pre: Type, owner0: Symbol, explanation: String) = {
+ def AccessError(tree: Tree, sym: Symbol, ctx: Context, explanation: String): AbsTypeError =
+ AccessError(tree, sym, ctx.enclClass.owner.thisType, ctx.enclClass.owner, explanation)
+
+ def AccessError(tree: Tree, sym: Symbol, pre: Type, owner0: Symbol, explanation: String): AbsTypeError = {
def errMsg = {
val location = if (sym.isClassConstructor) owner0 else pre.widen.directObjectString
diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
index 0907f1088a..e8c48184b0 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
@@ -6,8 +6,7 @@
package scala.tools.nsc
package typechecker
-import symtab.Flags._
-import scala.collection.mutable.{LinkedHashSet, Set}
+import scala.collection.mutable
import scala.annotation.tailrec
/**
@@ -16,6 +15,7 @@ import scala.annotation.tailrec
*/
trait Contexts { self: Analyzer =>
import global._
+ import definitions.{ JavaLangPackage, ScalaPackage, PredefModule }
object NoContext extends Context {
outer = this
@@ -28,13 +28,17 @@ trait Contexts { self: Analyzer =>
override def toString = "NoContext"
}
private object RootImports {
- import definitions._
// Possible lists of root imports
val javaList = JavaLangPackage :: Nil
val javaAndScalaList = JavaLangPackage :: ScalaPackage :: Nil
val completeList = JavaLangPackage :: ScalaPackage :: PredefModule :: Nil
}
+ def ambiguousImports(imp1: ImportInfo, imp2: ImportInfo) =
+ LookupAmbiguous(s"it is imported twice in the same scope by\n$imp1\nand $imp2")
+ def ambiguousDefnAndImport(owner: Symbol, imp: ImportInfo) =
+ LookupAmbiguous(s"it is both defined in $owner and imported subsequently by \n$imp")
+
private val startContext = {
NoContext.make(
Template(List(), emptyValDef, List()) setSymbol global.NoSymbol setType global.NoType,
@@ -42,6 +46,28 @@ trait Contexts { self: Analyzer =>
rootMirror.RootClass.info.decls)
}
+ private lazy val allUsedSelectors =
+ mutable.Map[ImportInfo, Set[ImportSelector]]() withDefaultValue Set()
+ private lazy val allImportInfos =
+ mutable.Map[CompilationUnit, List[ImportInfo]]() withDefaultValue Nil
+
+ def clearUnusedImports() {
+ allUsedSelectors.clear()
+ allImportInfos.clear()
+ }
+ def warnUnusedImports(unit: CompilationUnit) = {
+ val imps = allImportInfos(unit).reverse.distinct
+
+ for (imp <- imps) {
+ val used = allUsedSelectors(imp)
+ def isMask(s: ImportSelector) = s.name != nme.WILDCARD && s.rename == nme.WILDCARD
+
+ imp.tree.selectors filterNot (s => isMask(s) || used(s)) foreach { sel =>
+ unit.warning(imp posOf sel, "Unused import")
+ }
+ }
+ }
+
var lastAccessCheckDetails: String = ""
/** List of symbols to import from in a root context. Typically that
@@ -64,7 +90,6 @@ trait Contexts { self: Analyzer =>
def rootContext(unit: CompilationUnit): Context = rootContext(unit, EmptyTree, false)
def rootContext(unit: CompilationUnit, tree: Tree): Context = rootContext(unit, tree, false)
def rootContext(unit: CompilationUnit, tree: Tree, erasedTypes: Boolean): Context = {
- import definitions._
var sc = startContext
for (sym <- rootImports(unit)) {
sc = sc.makeNewImport(sym)
@@ -81,8 +106,8 @@ trait Contexts { self: Analyzer =>
var sc = startContext
while (sc != NoContext) {
sc.tree match {
- case Import(qual, _) => qual.tpe = singleType(qual.symbol.owner.thisType, qual.symbol)
- case _ =>
+ case Import(qual, _) => qual setType singleType(qual.symbol.owner.thisType, qual.symbol)
+ case _ =>
}
sc = sc.outer
}
@@ -143,7 +168,7 @@ trait Contexts { self: Analyzer =>
var typingIndentLevel: Int = 0
def typingIndent = " " * typingIndentLevel
- var buffer: Set[AbsTypeError] = _
+ var buffer: mutable.Set[AbsTypeError] = _
def enclClassOrMethod: Context =
if ((owner eq NoSymbol) || (owner.isClass) || (owner.isMethod)) this
@@ -182,20 +207,18 @@ trait Contexts { self: Analyzer =>
def setThrowErrors() = mode &= (~AllMask)
def setAmbiguousErrors(report: Boolean) = if (report) mode |= AmbiguousErrors else mode &= notThrowMask
- def updateBuffer(errors: Set[AbsTypeError]) = buffer ++= errors
+ def updateBuffer(errors: mutable.Set[AbsTypeError]) = buffer ++= errors
def condBufferFlush(removeP: AbsTypeError => Boolean) {
val elems = buffer.filter(removeP)
buffer --= elems
}
def flushBuffer() { buffer.clear() }
- def flushAndReturnBuffer(): Set[AbsTypeError] = {
+ def flushAndReturnBuffer(): mutable.Set[AbsTypeError] = {
val current = buffer.clone()
buffer.clear()
current
}
- def logError(err: AbsTypeError) = buffer += err
-
def withImplicitsEnabled[T](op: => T): T = {
val saved = implicitsEnabled
implicitsEnabled = true
@@ -281,26 +304,22 @@ trait Contexts { self: Analyzer =>
c.checking = this.checking
c.retyping = this.retyping
c.openImplicits = this.openImplicits
- c.buffer = if (this.buffer == null) LinkedHashSet[AbsTypeError]() else this.buffer // need to initialize
+ c.buffer = if (this.buffer == null) mutable.LinkedHashSet[AbsTypeError]() else this.buffer // need to initialize
registerContext(c.asInstanceOf[analyzer.Context])
debuglog("[context] ++ " + c.unit + " / " + tree.summaryString)
c
}
- // TODO: remove? Doesn't seem to be used
- def make(unit: CompilationUnit): Context = {
- val c = make(unit, EmptyTree, owner, scope, imports)
- c.setReportErrors()
- c.implicitsEnabled = true
- c.macrosEnabled = true
- c
- }
-
def makeNewImport(sym: Symbol): Context =
makeNewImport(gen.mkWildcardImport(sym))
- def makeNewImport(imp: Import): Context =
- make(unit, imp, owner, scope, new ImportInfo(imp, depth) :: imports)
+ def makeNewImport(imp: Import): Context = {
+ val impInfo = new ImportInfo(imp, depth)
+ if (settings.lint.value && imp.pos.isDefined) // pos.isDefined excludes java.lang/scala/Predef imports
+ allImportInfos(unit) ::= impInfo
+
+ make(unit, imp, owner, scope, impInfo :: imports)
+ }
def make(tree: Tree, owner: Symbol, scope: Scope): Context =
if (tree == this.tree && owner == this.owner && scope == this.scope) this
@@ -323,7 +342,7 @@ trait Contexts { self: Analyzer =>
val c = make(newtree)
c.setBufferErrors()
c.setAmbiguousErrors(reportAmbiguousErrors)
- c.buffer = new LinkedHashSet[AbsTypeError]()
+ c.buffer = mutable.LinkedHashSet[AbsTypeError]()
c
}
@@ -368,8 +387,10 @@ trait Contexts { self: Analyzer =>
unit.error(pos, if (checking) "\n**** ERROR DURING INTERNAL CHECKING ****\n" + msg else msg)
@inline private def issueCommon(err: AbsTypeError)(pf: PartialFunction[AbsTypeError, Unit]) {
- debugwarn("issue error: " + err.errMsg)
- if (settings.Yissuedebug.value) (new Exception).printStackTrace()
+ if (settings.Yissuedebug.value) {
+ log("issue error: " + err.errMsg)
+ (new Exception).printStackTrace()
+ }
if (pf isDefinedAt err) pf(err)
else if (bufferErrors) { buffer += err }
else throw new TypeError(err.errPos, err.errMsg)
@@ -415,16 +436,7 @@ trait Contexts { self: Analyzer =>
case _ => outer.isLocal()
}
- /** Fast path for some slow checks (ambiguous assignment in Refchecks, and
- * existence of __match for MatchTranslation in virtpatmat.) This logic probably
- * needs improvement.
- */
- def isNameInScope(name: Name) = (
- enclosingContextChain exists (ctx =>
- (ctx.scope.lookupEntry(name) != null)
- || (ctx.owner.rawInfo.member(name) != NoSymbol)
- )
- )
+ def isNameInScope(name: Name) = lookupSymbol(name, _ => true).isSuccess
// nextOuter determines which context is searched next for implicits
// (after `this`, which contributes `newImplicits` below.) In
@@ -459,17 +471,6 @@ trait Contexts { self: Analyzer =>
sub.isNonBottomSubClass(base) ||
sub.isModuleClass && sub.linkedClassOfClass.isNonBottomSubClass(base)
- /** Return closest enclosing context that defines a superclass of `clazz`, or a
- * companion module of a superclass of `clazz`, or NoContext if none exists */
- def enclosingSuperClassContext(clazz: Symbol): Context = {
- var c = this.enclClass
- while (c != NoContext &&
- !clazz.isNonBottomSubClass(c.owner) &&
- !(c.owner.isModuleClass && clazz.isNonBottomSubClass(c.owner.companionClass)))
- c = c.outer.enclClass
- c
- }
-
/** Return the closest enclosing context that defines a subclass of `clazz`
* or a companion object thereof, or `NoContext` if no such context exists.
*/
@@ -480,8 +481,7 @@ trait Contexts { self: Analyzer =>
c
}
- /** Is `sym` accessible as a member of tree `site` with type
- * `pre` in current context?
+ /** Is `sym` accessible as a member of `pre` in current context?
*/
def isAccessible(sym: Symbol, pre: Type, superAccess: Boolean = false): Boolean = {
lastAccessCheckDetails = ""
@@ -507,20 +507,6 @@ trait Contexts { self: Analyzer =>
} else (owner hasTransOwner ab)
}
-/*
- var c = this
- while (c != NoContext && c.owner != owner) {
- if (c.outer eq null) abort("accessWithin(" + owner + ") " + c);//debug
- if (c.outer.enclClass eq null) abort("accessWithin(" + owner + ") " + c);//debug
- c = c.outer.enclClass
- }
- c != NoContext
- }
-*/
- /** Is `clazz` a subclass of an enclosing class? */
- def isSubClassOfEnclosing(clazz: Symbol): Boolean =
- enclosingSuperClassContext(clazz) != NoContext
-
def isSubThisType(pre: Type, clazz: Symbol): Boolean = pre match {
case ThisType(pclazz) => pclazz isNonBottomSubClass clazz
case _ => false
@@ -632,7 +618,7 @@ trait Contexts { self: Analyzer =>
case ImportSelector(from, _, to, _) :: sels1 =>
var impls = collect(sels1) filter (info => info.name != from)
if (to != nme.WILDCARD) {
- for (sym <- imp.importedSymbol(to).alternatives)
+ for (sym <- importedAccessibleSymbol(imp, to).alternatives)
if (isQualifyingImplicit(to, sym, pre, imported = true))
impls = new ImplicitInfo(to, pre, sym) :: impls
}
@@ -678,6 +664,259 @@ trait Contexts { self: Analyzer =>
implicitsCache
}
+ /** It's possible that seemingly conflicting identifiers are
+ * identifiably the same after type normalization. In such cases,
+ * allow compilation to proceed. A typical example is:
+ * package object foo { type InputStream = java.io.InputStream }
+ * import foo._, java.io._
+ */
+ private def resolveAmbiguousImport(name: Name, imp1: ImportInfo, imp2: ImportInfo): Option[ImportInfo] = {
+ val imp1Explicit = imp1 isExplicitImport name
+ val imp2Explicit = imp2 isExplicitImport name
+ val ambiguous = if (imp1.depth == imp2.depth) imp1Explicit == imp2Explicit else !imp1Explicit && imp2Explicit
+ val imp1Symbol = (imp1 importedSymbol name).initialize filter (s => isAccessible(s, imp1.qual.tpe, superAccess = false))
+ val imp2Symbol = (imp2 importedSymbol name).initialize filter (s => isAccessible(s, imp2.qual.tpe, superAccess = false))
+
+ // The types of the qualifiers from which the ambiguous imports come.
+ // If the ambiguous name is a value, these must be the same.
+ def t1 = imp1.qual.tpe
+ def t2 = imp2.qual.tpe
+ // The types of the ambiguous symbols, seen as members of their qualifiers.
+ // If the ambiguous name is a monomorphic type, we can relax this far.
+ def mt1 = t1 memberType imp1Symbol
+ def mt2 = t2 memberType imp2Symbol
+
+ def characterize = List(
+ s"types: $t1 =:= $t2 ${t1 =:= t2} members: ${mt1 =:= mt2}",
+ s"member type 1: $mt1",
+ s"member type 2: $mt2"
+ ).mkString("\n ")
+
+ if (!ambiguous || !imp2Symbol.exists) Some(imp1)
+ else if (!imp1Symbol.exists) Some(imp2)
+ else (
+ // The symbol names are checked rather than the symbols themselves because
+ // each time an overloaded member is looked up it receives a new symbol.
+ // So foo.member("x") != foo.member("x") if x is overloaded. This seems
+ // likely to be the cause of other bugs too...
+ if (t1 =:= t2 && imp1Symbol.name == imp2Symbol.name) {
+ log(s"Suppressing ambiguous import: $t1 =:= $t2 && $imp1Symbol == $imp2Symbol")
+ Some(imp1)
+ }
+ // Monomorphism restriction on types is in part because type aliases could have the
+ // same target type but attach different variance to the parameters. Maybe it can be
+ // relaxed, but doesn't seem worth it at present.
+ else if (mt1 =:= mt2 && name.isTypeName && imp1Symbol.isMonomorphicType && imp2Symbol.isMonomorphicType) {
+ log(s"Suppressing ambiguous import: $mt1 =:= $mt2 && $imp1Symbol and $imp2Symbol are equivalent")
+ Some(imp1)
+ }
+ else {
+ log(s"Import is genuinely ambiguous:\n " + characterize)
+ None
+ }
+ )
+ }
+
+ /** The symbol with name `name` imported via the import in `imp`,
+ * if any such symbol is accessible from this context.
+ */
+ def importedAccessibleSymbol(imp: ImportInfo, name: Name): Symbol =
+ importedAccessibleSymbol(imp, name, requireExplicit = false)
+
+ private def importedAccessibleSymbol(imp: ImportInfo, name: Name, requireExplicit: Boolean): Symbol =
+ imp.importedSymbol(name, requireExplicit) filter (s => isAccessible(s, imp.qual.tpe, superAccess = false))
+
+ /** Is `sym` defined in package object of package `pkg`?
+ * Since sym may be defined in some parent of the package object,
+ * we cannot inspect its owner only; we have to go through the
+ * info of the package object. However to avoid cycles we'll check
+ * what other ways we can before pushing that way.
+ */
+ def isInPackageObject(sym: Symbol, pkg: Symbol): Boolean = {
+ def uninitialized(what: String) = {
+ log(s"Cannot look for $sym in package object of $pkg; $what is not initialized.")
+ false
+ }
+ def pkgClass = if (pkg.isTerm) pkg.moduleClass else pkg
+ def matchesInfo = (
+ // need to be careful here to not get a cyclic reference during bootstrap
+ if (pkg.isInitialized) {
+ val module = pkg.info member nme.PACKAGEkw
+ if (module.isInitialized)
+ module.info.member(sym.name).alternatives contains sym
+ else
+ uninitialized("" + module)
+ }
+ else uninitialized("" + pkg)
+ )
+ def inPackageObject(sym: Symbol) = (
+ // To be in the package object, one of these must be true:
+ // 1) sym.owner is a package object class, and sym.owner.owner is the package class for `pkg`
+ // 2) sym.owner is inherited by the correct package object class
+ // We try to establish 1) by inspecting the owners directly, and then we try
+ // to rule out 2), and only if both those fail do we resort to looking in the info.
+ !sym.isPackage && (sym.owner ne NoSymbol) && (
+ if (sym.owner.isPackageObjectClass)
+ sym.owner.owner == pkgClass
+ else
+ !sym.owner.isPackageClass && matchesInfo
+ )
+ )
+
+ // An overloaded symbol might not have the expected owner!
+ // The alternatives must be inspected directly.
+ pkgClass.isPackageClass && (
+ if (sym.isOverloaded)
+ sym.alternatives forall (isInPackageObject(_, pkg))
+ else
+ inPackageObject(sym)
+ )
+ }
+
+ /** Find the symbol of a simple name starting from this context.
+ * All names are filtered through the "qualifies" predicate,
+ * the search continuing as long as no qualifying name is found.
+ */
+ def lookupSymbol(name: Name, qualifies: Symbol => Boolean): NameLookup = {
+ var lookupError: NameLookup = null // set to non-null if a definite error is encountered
+ var inaccessible: NameLookup = null // records inaccessible symbol for error reporting in case none is found
+ var defSym: Symbol = NoSymbol // the directly found symbol
+ var pre: Type = NoPrefix // the prefix type of defSym, if a class member
+ var cx: Context = this // the context under consideration
+ var symbolDepth: Int = -1 // the depth of the directly found symbol
+
+ def finish(qual: Tree, sym: Symbol): NameLookup = (
+ if (lookupError ne null) lookupError
+ else sym match {
+ case NoSymbol if inaccessible ne null => inaccessible
+ case NoSymbol => LookupNotFound
+ case _ => LookupSucceeded(qual, sym)
+ }
+ )
+ def isPackageOwnedInDifferentUnit(s: Symbol) = (
+ s.isDefinedInPackage && (
+ !currentRun.compiles(s)
+ || unit.exists && s.sourceFile != unit.source.file
+ )
+ )
+ def requiresQualifier(s: Symbol) = (
+ s.owner.isClass
+ && !s.owner.isPackageClass
+ && !s.isTypeParameterOrSkolem
+ )
+ def lookupInPrefix(name: Name) = pre member name filter qualifies
+ def accessibleInPrefix(s: Symbol) = isAccessible(s, pre, superAccess = false)
+
+ def searchPrefix = {
+ cx = cx.enclClass
+ val found0 = lookupInPrefix(name)
+ val found1 = found0 filter accessibleInPrefix
+ if (found0.exists && !found1.exists && inaccessible == null)
+ inaccessible = LookupInaccessible(found0, analyzer.lastAccessCheckDetails)
+
+ found1
+ }
+ // cx.scope eq null arises during FixInvalidSyms in Duplicators
+ while (defSym == NoSymbol && (cx ne NoContext) && (cx.scope ne null)) {
+ pre = cx.enclClass.prefix
+ val entries = (cx.scope lookupUnshadowedEntries name filter (e => qualifies(e.sym))).toList
+ defSym = entries match {
+ case Nil => searchPrefix
+ case hd :: tl =>
+ // we have a winner: record the symbol depth
+ symbolDepth = (cx.depth - cx.scope.nestingLevel) + hd.depth
+ if (tl.isEmpty) hd.sym
+ else logResult(s"!!! lookup overloaded")(cx.owner.newOverloaded(pre, entries map (_.sym)))
+ }
+ if (!defSym.exists)
+ cx = cx.outer // push further outward
+ }
+ if (symbolDepth < 0)
+ symbolDepth = cx.depth
+
+ var impSym: Symbol = NoSymbol
+ var imports = Context.this.imports
+ def imp1 = imports.head
+ def imp2 = imports.tail.head
+ def sameDepth = imp1.depth == imp2.depth
+ def imp1Explicit = imp1 isExplicitImport name
+ def imp2Explicit = imp2 isExplicitImport name
+
+ def lookupImport(imp: ImportInfo, requireExplicit: Boolean) =
+ importedAccessibleSymbol(imp, name, requireExplicit) filter qualifies
+
+ while (!impSym.exists && imports.nonEmpty && imp1.depth > symbolDepth) {
+ impSym = lookupImport(imp1, requireExplicit = false)
+ if (!impSym.exists)
+ imports = imports.tail
+ }
+
+ if (defSym.exists && impSym.exists) {
+ // imported symbols take precedence over package-owned symbols in different compilation units.
+ if (isPackageOwnedInDifferentUnit(defSym))
+ defSym = NoSymbol
+ // Defined symbols take precedence over erroneous imports.
+ else if (impSym.isError || impSym.name == nme.CONSTRUCTOR)
+ impSym = NoSymbol
+ // Otherwise they are irreconcilably ambiguous
+ else
+ return ambiguousDefnAndImport(defSym.owner, imp1)
+ }
+
+ // At this point only one or the other of defSym and impSym might be set.
+ if (defSym.exists) {
+ if (requiresQualifier(defSym))
+ finish(gen.mkAttributedQualifier(pre), defSym)
+ else
+ finish(EmptyTree, defSym)
+ }
+ else if (impSym.exists) {
+ // We continue walking down the imports as long as the tail is non-empty, which gives us:
+ // imports == imp1 :: imp2 :: _
+ // And at least one of the following is true:
+ // - imp1 and imp2 are at the same depth
+ // - imp1 is a wildcard import, so all explicit imports from outer scopes must be checked
+ def keepLooking = (
+ lookupError == null
+ && imports.tail.nonEmpty
+ && (sameDepth || !imp1Explicit)
+ )
+ // If we find a competitor imp2 which imports the same name, possible outcomes are:
+ //
+ // - same depth, imp1 wild, imp2 explicit: imp2 wins, drop imp1
+ // - same depth, imp1 wild, imp2 wild: ambiguity check
+ // - same depth, imp1 explicit, imp2 explicit: ambiguity check
+ // - differing depth, imp1 wild, imp2 explicit: ambiguity check
+ // - all others: imp1 wins, drop imp2
+ //
+ // The ambiguity check is: if we can verify that both imports refer to the same
+ // symbol (e.g. import foo.X followed by import foo._) then we discard imp2
+ // and proceed. If we cannot, issue an ambiguity error.
+ while (keepLooking) {
+ // If not at the same depth, limit the lookup to explicit imports.
+ // This is desirable from a performance standpoint (compare to
+ // filtering after the fact) but also necessary to keep the unused
+ // import check from being misled by symbol lookups which are not
+ // actually used.
+ val other = lookupImport(imp2, requireExplicit = !sameDepth)
+ def imp1wins = { imports = imp1 :: imports.tail.tail }
+ def imp2wins = { impSym = other ; imports = imports.tail }
+
+ if (!other.exists) // imp1 wins; drop imp2 and continue.
+ imp1wins
+ else if (sameDepth && !imp1Explicit && imp2Explicit) // imp2 wins; drop imp1 and continue.
+ imp2wins
+ else resolveAmbiguousImport(name, imp1, imp2) match {
+ case Some(imp) => if (imp eq imp1) imp1wins else imp2wins
+ case _ => lookupError = ambiguousImports(imp1, imp2)
+ }
+ }
+ // optimization: don't write out package prefixes
+ finish(resetPos(imp1.qual.duplicate), impSym)
+ }
+ else finish(EmptyTree, NoSymbol)
+ }
+
/**
* Find a symbol in this context or one of its outers.
*
@@ -702,11 +941,14 @@ trait Contexts { self: Analyzer =>
} //class Context
class ImportInfo(val tree: Import, val depth: Int) {
+ def pos = tree.pos
+ def posOf(sel: ImportSelector) = tree.pos withPoint sel.namePos
+
/** The prefix expression */
def qual: Tree = tree.symbol.info match {
case ImportType(expr) => expr
- case ErrorType => tree setType NoType // fix for #2870
- case _ => throw new FatalError("symbol " + tree.symbol + " has bad type: " + tree.symbol.info) //debug
+ case ErrorType => tree setType NoType // fix for #2870
+ case _ => throw new FatalError("symbol " + tree.symbol + " has bad type: " + tree.symbol.info) //debug
}
/** Is name imported explicitly, not via wildcard? */
@@ -715,25 +957,53 @@ trait Contexts { self: Analyzer =>
/** The symbol with name `name` imported from import clause `tree`.
*/
- def importedSymbol(name: Name): Symbol = {
+ def importedSymbol(name: Name): Symbol = importedSymbol(name, requireExplicit = false)
+
+ private def recordUsage(sel: ImportSelector, result: Symbol) {
+ def posstr = pos.source.file.name + ":" + posOf(sel).safeLine
+ def resstr = if (tree.symbol.hasCompleteInfo) s"(qual=$qual, $result)" else s"(expr=${tree.expr}, ${result.fullLocationString})"
+ debuglog(s"In $this at $posstr, selector '${selectorString(sel)}' resolved to $resstr")
+ allUsedSelectors(this) += sel
+ }
+
+ /** If requireExplicit is true, wildcard imports are not considered. */
+ def importedSymbol(name: Name, requireExplicit: Boolean): Symbol = {
var result: Symbol = NoSymbol
var renamed = false
var selectors = tree.selectors
- while (selectors != Nil && result == NoSymbol) {
- if (selectors.head.rename == name.toTermName)
+ def current = selectors.head
+ while (selectors.nonEmpty && result == NoSymbol) {
+ if (current.rename == name.toTermName)
result = qual.tpe.nonLocalMember( // new to address #2733: consider only non-local members for imports
- if (name.isTypeName) selectors.head.name.toTypeName else selectors.head.name)
- else if (selectors.head.name == name.toTermName)
+ if (name.isTypeName) current.name.toTypeName else current.name)
+ else if (current.name == name.toTermName)
renamed = true
- else if (selectors.head.name == nme.WILDCARD && !renamed)
+ else if (current.name == nme.WILDCARD && !renamed && !requireExplicit)
result = qual.tpe.nonLocalMember(name)
- selectors = selectors.tail
+
+ if (result == NoSymbol)
+ selectors = selectors.tail
}
- result
+ if (settings.lint.value && selectors.nonEmpty && result != NoSymbol && pos != NoPosition)
+ recordUsage(current, result)
+
+ // Harden against the fallout from bugs like SI-6745
+ //
+ // [JZ] I considered issuing a devWarning and moving the
+ // check inside the above loop, as I believe that
+ // this always represents a mistake on the part of
+ // the caller.
+ if (definitions isImportable result) result
+ else NoSymbol
+ }
+ private def selectorString(s: ImportSelector): String = {
+ if (s.name == nme.WILDCARD && s.rename == null) "_"
+ else if (s.name == s.rename) "" + s.name
+ else s.name + " => " + s.rename
}
def allImportedSymbols: Iterable[Symbol] =
- qual.tpe.members flatMap (transformImport(tree.selectors, _))
+ importableMembers(qual.tpe) flatMap (transformImport(tree.selectors, _))
private def transformImport(selectors: List[ImportSelector], sym: Symbol): List[Symbol] = selectors match {
case List() => List()
@@ -744,7 +1014,12 @@ trait Contexts { self: Analyzer =>
case _ :: rest => transformImport(rest, sym)
}
- override def toString() = tree.toString()
+ override def hashCode = tree.##
+ override def equals(other: Any) = other match {
+ case that: ImportInfo => (tree == that.tree)
+ case _ => false
+ }
+ override def toString = tree.toString
}
case class ImportType(expr: Tree) extends Type {
diff --git a/src/compiler/scala/tools/nsc/typechecker/DestructureTypes.scala b/src/compiler/scala/tools/nsc/typechecker/DestructureTypes.scala
index 3e249e57bb..73572bcae9 100644
--- a/src/compiler/scala/tools/nsc/typechecker/DestructureTypes.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/DestructureTypes.scala
@@ -6,8 +6,6 @@
package scala.tools.nsc
package typechecker
-import scala.language.implicitConversions
-
/** A generic means of breaking down types into their subcomponents.
* Types are decomposed top down, and recognizable substructure is
* dispatched via self-apparently named methods. Those methods can
@@ -37,8 +35,6 @@ trait DestructureTypes {
def wrapSequence(nodes: List[Node]): Node
def wrapAtom[U](value: U): Node
- private implicit def liftToTerm(name: String): TermName = newTermName(name)
-
private val openSymbols = scala.collection.mutable.Set[Symbol]()
private def nodeList[T](elems: List[T], mkNode: T => Node): Node =
@@ -68,15 +64,6 @@ trait DestructureTypes {
},
tree.productPrefix
)
- def wrapSymbol(label: String, sym: Symbol): Node = {
- if (sym eq NoSymbol) wrapEmpty
- else atom(label, sym)
- }
- def wrapInfo(sym: Symbol) = sym.info match {
- case TypeBounds(lo, hi) => typeBounds(lo, hi)
- case PolyType(tparams, restpe) => polyFunction(tparams, restpe)
- case _ => wrapEmpty
- }
def wrapSymbolInfo(sym: Symbol): Node = {
if ((sym eq NoSymbol) || openSymbols(sym)) wrapEmpty
else {
@@ -99,7 +86,6 @@ trait DestructureTypes {
def constant(label: String, const: Constant): Node = atom(label, const)
def scope(decls: Scope): Node = node("decls", scopeMemberList(decls.toList))
- def const[T](named: (String, T)): Node = constant(named._1, Constant(named._2))
def resultType(restpe: Type): Node = this("resultType", restpe)
def typeParams(tps: List[Symbol]): Node = node("typeParams", symbolList(tps))
@@ -188,7 +174,6 @@ trait DestructureTypes {
case AntiPolyType(pre, targs) => product(tp, prefix(pre), typeArgs(targs))
case ClassInfoType(parents, decls, clazz) => product(tp, parentList(parents), scope(decls), wrapAtom(clazz))
case ConstantType(const) => product(tp, constant("value", const))
- case DeBruijnIndex(level, index, args) => product(tp, const("level" -> level), const("index" -> index), typeArgs(args))
case OverloadedType(pre, alts) => product(tp, prefix(pre), node("alts", typeList(alts map pre.memberType)))
case RefinedType(parents, decls) => product(tp, parentList(parents), scope(decls))
case SingleType(pre, sym) => product(tp, prefix(pre), wrapAtom(sym))
diff --git a/src/compiler/scala/tools/nsc/typechecker/Duplicators.scala b/src/compiler/scala/tools/nsc/typechecker/Duplicators.scala
index df753ba53c..1c48eeed70 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Duplicators.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Duplicators.scala
@@ -19,11 +19,6 @@ abstract class Duplicators extends Analyzer {
import global._
import definitions.{ AnyRefClass, AnyValClass }
- def retyped(context: Context, tree: Tree): Tree = {
- resetClassOwners
- (newBodyDuplicator(context)).typed(tree)
- }
-
/** Retype the given tree in the given context. Use this method when retyping
* a method in a different class. The typer will replace references to the this of
* the old class with the new class, and map symbols through the given 'env'. The
@@ -42,9 +37,6 @@ abstract class Duplicators extends Analyzer {
protected def newBodyDuplicator(context: Context) = new BodyDuplicator(context)
- def retypedMethod(context: Context, tree: Tree, oldThis: Symbol, newThis: Symbol): Tree =
- (newBodyDuplicator(context)).retypedMethod(tree.asInstanceOf[DefDef], oldThis, newThis)
-
/** Return the special typer for duplicate method bodies. */
override def newTyper(context: Context): Typer =
newBodyDuplicator(context)
@@ -186,31 +178,6 @@ abstract class Duplicators extends Analyzer {
stats.foreach(invalidate(_, owner))
}
- def retypedMethod(ddef: DefDef, oldThis: Symbol, newThis: Symbol): Tree = {
- oldClassOwner = oldThis
- newClassOwner = newThis
- invalidateAll(ddef.tparams)
- mforeach(ddef.vparamss) { vdef =>
- invalidate(vdef)
- vdef.tpe = null
- }
- ddef.symbol = NoSymbol
- enterSym(context, ddef)
- debuglog("remapping this of " + oldClassOwner + " to " + newClassOwner)
- typed(ddef)
- }
-
- private def inspectTpe(tpe: Type) = {
- tpe match {
- case MethodType(_, res) =>
- res + ", " + res.bounds.hi + ", " + (res.bounds.hi match {
- case TypeRef(_, _, args) if (args.length > 0) => args(0) + ", " + args(0).bounds.hi
- case _ => "non-tref: " + res.bounds.hi.getClass
- })
- case _ =>
- }
- }
-
/** Optionally cast this tree into some other type, if required.
* Unless overridden, just returns the tree.
*/
@@ -233,7 +200,7 @@ abstract class Duplicators extends Analyzer {
override def typed(tree: Tree, mode: Int, pt: Type): Tree = {
debuglog("typing " + tree + ": " + tree.tpe + ", " + tree.getClass)
val origtreesym = tree.symbol
- if (tree.hasSymbol && tree.symbol != NoSymbol
+ if (tree.hasSymbolField && tree.symbol != NoSymbol
&& !tree.symbol.isLabel // labels cannot be retyped by the type checker as LabelDef has no ValDef/return type trees
&& invalidSyms.isDefinedAt(tree.symbol)) {
debuglog("removed symbol " + tree.symbol)
@@ -243,40 +210,35 @@ abstract class Duplicators extends Analyzer {
tree match {
case ttree @ TypeTree() =>
// log("fixing tpe: " + tree.tpe + " with sym: " + tree.tpe.typeSymbol)
- ttree.tpe = fixType(ttree.tpe)
- ttree
+ ttree modifyType fixType
case Block(stats, res) =>
debuglog("invalidating block")
invalidateAll(stats)
invalidate(res)
- tree.tpe = null
- super.typed(tree, mode, pt)
+ super.typed(tree.clearType(), mode, pt)
case ClassDef(_, _, _, tmpl @ Template(parents, _, stats)) =>
// log("invalidating classdef " + tree)
tmpl.symbol = tree.symbol.newLocalDummy(tree.pos)
invalidateAll(stats, tree.symbol)
- tree.tpe = null
- super.typed(tree, mode, pt)
+ super.typed(tree.clearType(), mode, pt)
case ddef @ DefDef(_, _, _, _, tpt, rhs) =>
- ddef.tpt.tpe = fixType(ddef.tpt.tpe)
- ddef.tpe = null
- super.typed(ddef, mode, pt)
+ ddef.tpt modifyType fixType
+ super.typed(ddef.clearType(), mode, pt)
case vdef @ ValDef(mods, name, tpt, rhs) =>
// log("vdef fixing tpe: " + tree.tpe + " with sym: " + tree.tpe.typeSymbol + " and " + invalidSyms)
//if (mods.hasFlag(Flags.LAZY)) vdef.symbol.resetFlag(Flags.MUTABLE) // Martin to Iulian: lazy vars can now appear because they are no longer boxed; Please check that deleting this statement is OK.
- vdef.tpt.tpe = fixType(vdef.tpt.tpe)
- vdef.tpe = null
- super.typed(vdef, mode, pt)
+ vdef.tpt modifyType fixType
+ super.typed(vdef.clearType(), mode, pt)
case ldef @ LabelDef(name, params, rhs) =>
// log("label def: " + ldef)
// in case the rhs contains any definitions -- TODO: is this necessary?
invalidate(rhs)
- ldef.tpe = null
+ ldef.clearType()
// is this LabelDef generated by tailcalls?
val isTailLabel = (ldef.params.length >= 1) && (ldef.params.head.name == nme.THIS)
@@ -294,38 +256,58 @@ abstract class Duplicators extends Analyzer {
val params1 = params map newParam
val rhs1 = (new TreeSubstituter(params map (_.symbol), params1) transform rhs) // TODO: duplicate?
- rhs1.tpe = null
- super.typed(treeCopy.LabelDef(tree, name, params1, rhs1), mode, pt)
+ super.typed(treeCopy.LabelDef(tree, name, params1, rhs1.clearType()), mode, pt)
case Bind(name, _) =>
// log("bind: " + tree)
invalidate(tree)
- tree.tpe = null
- super.typed(tree, mode, pt)
+ super.typed(tree.clearType(), mode, pt)
case Ident(_) if tree.symbol.isLabel =>
debuglog("Ident to labeldef " + tree + " switched to ")
tree.symbol = updateSym(tree.symbol)
- tree.tpe = null
- super.typed(tree, mode, pt)
+ super.typed(tree.clearType(), mode, pt)
case Ident(_) if (origtreesym ne null) && origtreesym.isLazy =>
debuglog("Ident to a lazy val " + tree + ", " + tree.symbol + " updated to " + origtreesym)
tree.symbol = updateSym(origtreesym)
- tree.tpe = null
- super.typed(tree, mode, pt)
+ super.typed(tree.clearType(), mode, pt)
case Select(th @ This(_), sel) if (oldClassOwner ne null) && (th.symbol == oldClassOwner) =>
- // log("selection on this, no type ascription required")
- // we use the symbol name instead of the tree name because the symbol may have been
- // name mangled, rendering the tree name obsolete
- // log(tree)
- val t = super.typedPos(tree.pos, mode, pt) {
- Select(This(newClassOwner), tree.symbol.name)
- }
- // log("typed to: " + t + "; tpe = " + t.tpe + "; " + inspectTpe(t.tpe))
- t
+ // We use the symbol name instead of the tree name because the symbol
+ // may have been name mangled, rendering the tree name obsolete.
+ // ...but you can't just do a Select on a name because if the symbol is
+ // overloaded, you will crash in the backend.
+ val memberByName = newClassOwner.thisType.member(tree.symbol.name)
+ def nameSelection = Select(This(newClassOwner), tree.symbol.name)
+ val newTree = (
+ if (memberByName.isOverloaded) {
+ // Find the types of the overload alternatives as seen in the new class,
+ // and filter the list down to those which match the old type (after
+ // fixing the old type so it is seen as if from the new class.)
+ val typeInNewClass = fixType(oldClassOwner.info memberType tree.symbol)
+ val alts = memberByName.alternatives
+ val memberTypes = alts map (newClassOwner.info memberType _)
+ val memberString = memberByName.defString
+ alts zip memberTypes filter (_._2 =:= typeInNewClass) match {
+ case ((alt, tpe)) :: Nil =>
+ log(s"Arrested overloaded type in Duplicators, narrowing to ${alt.defStringSeenAs(tpe)}\n Overload was: $memberString")
+ Select(This(newClassOwner), alt)
+ case xs =>
+ alts filter (alt => (alt.paramss corresponds tree.symbol.paramss)(_.size == _.size)) match {
+ case alt :: Nil =>
+ log(s"Resorted to parameter list arity to disambiguate to $alt\n Overload was: $memberString")
+ Select(This(newClassOwner), alt)
+ case _ =>
+ log(s"Could not disambiguate $memberTypes. Attempting name-based selection, but we may crash later.")
+ nameSelection
+ }
+ }
+ }
+ else nameSelection
+ )
+ super.typed(atPos(tree.pos)(newTree), mode, pt)
case This(_) if (oldClassOwner ne null) && (tree.symbol == oldClassOwner) =>
// val tree1 = Typed(This(newClassOwner), TypeTree(fixType(tree.tpe.widen)))
@@ -379,7 +361,7 @@ abstract class Duplicators extends Analyzer {
case _ =>
debuglog("Duplicators default case: " + tree.summaryString)
debuglog(" ---> " + tree)
- if (tree.hasSymbol && tree.symbol != NoSymbol && (tree.symbol.owner == definitions.AnyClass)) {
+ if (tree.hasSymbolField && tree.symbol != NoSymbol && (tree.symbol.owner == definitions.AnyClass)) {
tree.symbol = NoSymbol // maybe we can find a more specific member in a subclass of Any (see AnyVal members, like ==)
}
val ntree = castType(tree, pt)
diff --git a/src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala b/src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala
index bbba7e0435..4fbb788c7b 100644
--- a/src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala
@@ -33,7 +33,7 @@ trait EtaExpansion { self: Analyzer =>
}
/** <p>
- * Expand partial function applications of type <code>type</code>.
+ * Expand partial function applications of type `type`.
* </p><pre>
* p.f(es_1)...(es_n)
* ==> {
@@ -56,11 +56,8 @@ trait EtaExpansion { self: Analyzer =>
}
val defs = new ListBuffer[Tree]
- /** Append to <code>defs</code> value definitions for all non-stable
- * subexpressions of the function application <code>tree</code>.
- *
- * @param tree ...
- * @return ...
+ /** Append to `defs` value definitions for all non-stable
+ * subexpressions of the function application `tree`.
*/
def liftoutPrefix(tree: Tree): Tree = {
def liftout(tree: Tree, byName: Boolean): Tree =
@@ -97,11 +94,11 @@ trait EtaExpansion { self: Analyzer =>
// with repeated params, there might be more or fewer args than params
liftout(arg, byName(i).getOrElse(false))
}
- treeCopy.Apply(tree, liftoutPrefix(fn), newArgs) setType null
+ treeCopy.Apply(tree, liftoutPrefix(fn), newArgs).clearType()
case TypeApply(fn, args) =>
- treeCopy.TypeApply(tree, liftoutPrefix(fn), args) setType null
+ treeCopy.TypeApply(tree, liftoutPrefix(fn), args).clearType()
case Select(qual, name) =>
- treeCopy.Select(tree, liftout(qual, false), name) setSymbol NoSymbol setType null
+ treeCopy.Select(tree, liftout(qual, false), name).clearType() setSymbol NoSymbol
case Ident(name) =>
tree
}
@@ -118,7 +115,7 @@ trait EtaExpansion { self: Analyzer =>
val origTpe = sym.tpe
val isRepeated = definitions.isRepeatedParamType(origTpe)
// SI-4176 Don't leak A* in eta-expanded function types. See t4176b.scala
- val droppedStarTpe = if (settings.etaExpandKeepsStar.value) origTpe else dropRepeatedParamType(origTpe)
+ val droppedStarTpe = if (settings.etaExpandKeepsStar.value) origTpe else dropIllegalStarTypes(origTpe)
val valDef = ValDef(Modifiers(SYNTHETIC | PARAM), sym.name.toTermName, TypeTree(droppedStarTpe), EmptyTree)
(valDef, isRepeated)
}
diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
index 70a736c91f..8d869b669c 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala
@@ -30,7 +30,7 @@ trait Implicits {
import global._
import definitions._
import ImplicitsStats._
- import typeDebug.{ ptTree, ptBlock, ptLine }
+ import typeDebug.{ ptBlock, ptLine }
import global.typer.{ printTyping, deindentTyping, indentTyping, printInference }
def inferImplicit(tree: Tree, pt: Type, reportAmbiguous: Boolean, isView: Boolean, context: Context): SearchResult =
@@ -82,7 +82,7 @@ trait Implicits {
val result = new ImplicitSearch(tree, pt, isView, implicitSearchContext, pos).bestImplicit
if (saveAmbiguousDivergent && implicitSearchContext.hasErrors) {
context.updateBuffer(implicitSearchContext.errBuffer.filter(err => err.kind == ErrorKinds.Ambiguous || err.kind == ErrorKinds.Divergent))
- debugwarn("update buffer: " + implicitSearchContext.errBuffer)
+ debuglog("update buffer: " + implicitSearchContext.errBuffer)
}
printInference("[infer implicit] inferred " + result)
context.undetparams = context.undetparams filterNot result.subst.from.contains
@@ -132,7 +132,7 @@ trait Implicits {
}
/* Map a polytype to one in which all type parameters and argument-dependent types are replaced by wildcards.
- * Consider `implicit def b(implicit x: A): x.T = error("")`. We need to approximate DebruijnIndex types
+ * Consider `implicit def b(implicit x: A): x.T = error("")`. We need to approximate debruijn index types
* when checking whether `b` is a valid implicit, as we haven't even searched a value for the implicit arg `x`,
* so we have to approximate (otherwise it is excluded a priori).
*/
@@ -149,7 +149,7 @@ trait Implicits {
class SearchResult(val tree: Tree, val subst: TreeTypeSubstituter) {
override def toString = "SearchResult(%s, %s)".format(tree,
if (subst.isEmpty) "" else subst)
-
+
def isFailure = false
def isAmbiguousFailure = false
final def isSuccess = !isFailure
@@ -158,7 +158,7 @@ trait Implicits {
lazy val SearchFailure = new SearchResult(EmptyTree, EmptyTreeTypeSubstituter) {
override def isFailure = true
}
-
+
lazy val AmbiguousSearchFailure = new SearchResult(EmptyTree, EmptyTreeTypeSubstituter) {
override def isFailure = true
override def isAmbiguousFailure = true
@@ -244,10 +244,6 @@ trait Implicits {
object HasMember {
private val hasMemberCache = perRunCaches.newMap[Name, Type]()
def apply(name: Name): Type = hasMemberCache.getOrElseUpdate(name, memberWildcardType(name, WildcardType))
- def unapply(pt: Type): Option[Name] = pt match {
- case RefinedType(List(WildcardType), Scope(sym)) if sym.tpe == WildcardType => Some(sym.name)
- case _ => None
- }
}
/** An extractor for types of the form ? { name: (? >: argtpe <: Any*)restp }
@@ -675,10 +671,6 @@ trait Implicits {
// duplicating the code here, but this is probably a
// hotspot (and you can't just call typed, need to force
// re-typecheck)
- // TODO: the return tree is ignored. This seems to make
- // no difference, but it's bad practice regardless.
-
-
val checked = itree2 match {
case TypeApply(fun, args) => typedTypeApply(itree2, EXPRmode, fun, args)
case Apply(TypeApply(fun, args), _) => typedTypeApply(itree2, EXPRmode, fun, args) // t2421c
@@ -688,7 +680,7 @@ trait Implicits {
if (context.hasErrors)
fail("typing TypeApply reported errors for the implicit tree: " + context.errBuffer.head.errMsg)
else {
- val result = new SearchResult(itree2, subst)
+ val result = new SearchResult(checked, subst)
if (Statistics.canEnable) Statistics.incCounter(foundImplicits)
printInference("[success] found %s for pt %s".format(result, ptInstantiated))
result
@@ -1008,7 +1000,7 @@ trait Implicits {
case Some(imap) => imap
case None =>
val result = new InfoMap
- getClassParts(sym.tpe)(result, new mutable.HashSet(), pending + sym)
+ getClassParts(sym.tpeHK)(result, new mutable.HashSet(), pending + sym)
infoMapCache(sym) = result
result
}
@@ -1216,7 +1208,7 @@ trait Implicits {
}
)
// todo. migrate hardcoded materialization in Implicits to corresponding implicit macros
- var materializer = atPos(pos.focus)(gen.mkMethodCall(TagMaterializers(tagClass), List(tp), if (prefix != EmptyTree) List(prefix) else List()))
+ val materializer = atPos(pos.focus)(gen.mkMethodCall(TagMaterializers(tagClass), List(tp), if (prefix != EmptyTree) List(prefix) else List()))
if (settings.XlogImplicits.value) println("materializing requested %s.%s[%s] using %s".format(pre, tagClass.name, tp, materializer))
if (context.macrosEnabled) success(materializer)
// don't call `failure` here. if macros are disabled, we just fail silently
@@ -1484,7 +1476,6 @@ trait Implicits {
interpolate(msg, Map((typeParamNames zip typeArgs): _*)) // TODO: give access to the name and type of the implicit argument, etc?
def validate: Option[String] = {
- import scala.util.matching.Regex; import scala.collection.breakOut
// is there a shorter way to avoid the intermediate toList?
val refs = """\$\{([^}]+)\}""".r.findAllIn(msg).matchData.map(_ group 1).toSet
val decls = typeParamNames.toSet
@@ -1510,9 +1501,7 @@ object ImplicitsStats {
val subtypeImpl = Statistics.newSubCounter(" of which in implicit", subtypeCount)
val findMemberImpl = Statistics.newSubCounter(" of which in implicit", findMemberCount)
val subtypeAppInfos = Statistics.newSubCounter(" of which in app impl", subtypeCount)
- val subtypeImprovCount = Statistics.newSubCounter(" of which in improves", subtypeCount)
val implicitSearchCount = Statistics.newCounter ("#implicit searches", "typer")
- val triedImplicits = Statistics.newSubCounter(" #tried", implicitSearchCount)
val plausiblyCompatibleImplicits
= Statistics.newSubCounter(" #plausibly compatible", implicitSearchCount)
val matchingImplicits = Statistics.newSubCounter(" #matching", implicitSearchCount)
diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala
index 7ae8923e43..a541906a99 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala
@@ -6,11 +6,10 @@
package scala.tools.nsc
package typechecker
-import scala.collection.{ mutable, immutable }
+import scala.collection.immutable
import scala.collection.mutable.ListBuffer
import scala.util.control.ControlThrowable
import symtab.Flags._
-import scala.annotation.tailrec
/** This trait ...
*
@@ -30,8 +29,8 @@ trait Infer extends Checkable {
private def assertNonCyclic(tvar: TypeVar) =
assert(tvar.constr.inst != tvar, tvar.origin)
- /** The formal parameter types corresponding to <code>formals</code>.
- * If <code>formals</code> has a repeated last parameter, a list of
+ /** The formal parameter types corresponding to `formals`.
+ * If `formals` has a repeated last parameter, a list of
* (nargs - params.length + 1) copies of its type is returned.
* By-name types are replaced with their underlying type.
*
@@ -49,6 +48,24 @@ trait Infer extends Checkable {
} else formals1
}
+ /** Sorts the alternatives according to the given comparison function.
+ * Returns a list containing the best alternative as well as any which
+ * the best fails to improve upon.
+ */
+ private def bestAlternatives(alternatives: List[Symbol])(isBetter: (Symbol, Symbol) => Boolean): List[Symbol] = {
+ def improves(sym1: Symbol, sym2: Symbol) = (
+ sym2 == NoSymbol
+ || sym2.isError
+ || sym2.hasAnnotation(BridgeClass)
+ || isBetter(sym1, sym2)
+ )
+
+ alternatives sortWith improves match {
+ case best :: rest if rest.nonEmpty => best :: rest.filterNot(alt => improves(best, alt))
+ case bests => bests
+ }
+ }
+
/** Returns `(formals, formalsExpanded)` where `formalsExpanded` are the expected types
* for the `nbSubPats` sub-patterns of an extractor pattern, of which the corresponding
* unapply[Seq] call is assumed to have result type `resTp`.
@@ -112,21 +129,7 @@ trait Infer extends Checkable {
else (formals, formalsExpanded)
}
- def actualTypes(actuals: List[Type], nformals: Int): List[Type] =
- if (nformals == 1 && !hasLength(actuals, 1))
- List(if (actuals.isEmpty) UnitClass.tpe else tupleType(actuals))
- else actuals
-
- def actualArgs(pos: Position, actuals: List[Tree], nformals: Int): List[Tree] = {
- val inRange = nformals == 1 && !hasLength(actuals, 1) && actuals.lengthCompare(MaxTupleArity) <= 0
- if (inRange && !phase.erasedTypes) List(atPos(pos)(gen.mkTuple(actuals)))
- else actuals
- }
-
/** A fresh type variable with given type parameter as origin.
- *
- * @param tparam ...
- * @return ...
*/
def freshVar(tparam: Symbol): TypeVar = TypeVar(tparam)
@@ -149,14 +152,13 @@ trait Infer extends Checkable {
case tv @ TypeVar(origin, constr) if !tv.untouchable =>
if (constr.inst == NoType) {
throw new DeferredNoInstance(() =>
- "no unique instantiation of type variable " + origin + " could be found")
+ s"no unique instantiation of type variable $origin could be found")
} else if (excludedVars(tv)) {
throw new NoInstance("cyclic instantiation")
} else {
excludedVars += tv
- val res = apply(constr.inst)
- excludedVars -= tv
- res
+ try apply(constr.inst)
+ finally excludedVars -= tv
}
case _ =>
mapOver(tp)
@@ -164,9 +166,6 @@ trait Infer extends Checkable {
}
/** Is type fully defined, i.e. no embedded anytypes or wildcards in it?
- *
- * @param tp ...
- * @return ...
*/
private[typechecker] def isFullyDefined(tp: Type): Boolean = tp match {
case WildcardType | BoundedWildcardType(_) | NoType =>
@@ -270,7 +269,7 @@ trait Infer extends Checkable {
def errorValue = if (context.reportErrors) context.owner.newErrorValue(name) else stdErrorValue
def errorSym = if (tree.isType) errorClass else errorValue
- if (tree.hasSymbol)
+ if (tree.hasSymbolField)
tree setSymbol errorSym
tree setType ErrorType
@@ -296,8 +295,8 @@ trait Infer extends Checkable {
/* -- Tests & Checks---------------------------------------------------- */
- /** Check that <code>sym</code> is defined and accessible as a member of
- * tree <code>site</code> with type <code>pre</code> in current context.
+ /** Check that `sym` is defined and accessible as a member of
+ * tree `site` with type `pre` in current context.
*
* Note: pre is not refchecked -- moreover, refchecking the resulting tree may not refcheck pre,
* since pre may not occur in its type (callers should wrap the result in a TypeTreeWithDeferredRefCheck)
@@ -306,7 +305,6 @@ trait Infer extends Checkable {
if (sym.isError) {
tree setSymbol sym setType ErrorType
} else {
- val topClass = context.owner.enclosingTopLevelClass
if (context.unit.exists)
context.unit.depends += sym.enclosingTopLevelClass
@@ -404,8 +402,19 @@ trait Infer extends Checkable {
/** Like weakly compatible but don't apply any implicit conversions yet.
* Used when comparing the result type of a method with its prototype.
+ *
* [Martin] I think Infer is also created by Erasure, with the default
* implementation of isCoercible
+ * [Paulp] (Assuming the above must refer to my comment on isCoercible)
+ * Nope, I examined every occurrence of Inferencer in trunk. It
+ * appears twice as a self-type, once at its definition, and once
+ * where it is instantiated in Typers. There are no others.
+ *
+ % ack -A0 -B0 --no-filename '\bInferencer\b' src
+ self: Inferencer =>
+ self: Inferencer =>
+ class Inferencer(context: Context) extends InferencerContextErrors with InferCheckable {
+ val infer = new Inferencer(context0) {
*/
def isConservativelyCompatible(tp: Type, pt: Type): Boolean =
context.withImplicitsDisabled(isWeaklyCompatible(tp, pt))
@@ -439,14 +448,9 @@ trait Infer extends Checkable {
}
/** Return inferred type arguments of polymorphic expression, given
- * its type parameters and result type and a prototype <code>pt</code>.
+ * its type parameters and result type and a prototype `pt`.
* If no minimal type variables exist that make the
- * instantiated type a subtype of <code>pt</code>, return null.
- *
- * @param tparams ...
- * @param restpe ...
- * @param pt ...
- * @return ...
+ * instantiated type a subtype of `pt`, return null.
*/
private def exprTypeArgs(tparams: List[Symbol], restpe: Type, pt: Type, useWeaklyCompatible: Boolean = false): (List[Type], List[TypeVar]) = {
val tvars = tparams map freshVar
@@ -473,18 +477,12 @@ trait Infer extends Checkable {
/** Return inferred proto-type arguments of function, given
* its type and value parameters and result type, and a
- * prototype <code>pt</code> for the function result.
+ * prototype `pt` for the function result.
* Type arguments need to be either determined precisely by
* the prototype, or they are maximized, if they occur only covariantly
* in the value parameter list.
* If instantiation of a type parameter fails,
* take WildcardType for the proto-type argument.
- *
- * @param tparams ...
- * @param formals ...
- * @param restype ...
- * @param pt ...
- * @return ...
*/
def protoTypeArgs(tparams: List[Symbol], formals: List[Type], restpe: Type,
pt: Type): List[Type] = {
@@ -566,7 +564,7 @@ trait Infer extends Checkable {
*
* Rewrite for repeated param types: Map T* entries to Seq[T].
* @return map from tparams to inferred arg, if inference was successful, tparams that map to None are considered left undetermined
- * type parameters that are inferred as `scala.Nothing` and that are not covariant in <code>restpe</code> are taken to be undetermined
+ * type parameters that are inferred as `scala.Nothing` and that are not covariant in `restpe` are taken to be undetermined
*/
def adjustTypeArgs(tparams: List[Symbol], tvars: List[TypeVar], targs: List[Type], restpe: Type = WildcardType): AdjustedTypeArgs.Result = {
val buf = AdjustedTypeArgs.Result.newBuilder[Symbol, Option[Type]]
@@ -577,14 +575,14 @@ trait Infer extends Checkable {
&& (restpe.isWildcard || (varianceInType(restpe)(tparam) & COVARIANT) == 0) // don't retract covariant occurrences
)
- // checks opt.virtPatmat directly so one need not run under -Xexperimental to use virtpatmat
+ // checks !settings.XoldPatmat.value directly so one need not run under -Xexperimental to use virtpatmat
buf += ((tparam,
if (retract) None
else Some(
if (targ.typeSymbol == RepeatedParamClass) targ.baseType(SeqClass)
else if (targ.typeSymbol == JavaRepeatedParamClass) targ.baseType(ArrayClass)
// this infers Foo.type instead of "object Foo" (see also widenIfNecessary)
- else if (targ.typeSymbol.isModuleClass || ((opt.experimental || opt.virtPatmat) && tvar.constr.avoidWiden)) targ
+ else if (targ.typeSymbol.isModuleClass || ((settings.Xexperimental.value || !settings.XoldPatmat.value) && tvar.constr.avoidWiden)) targ
else targ.widen
)
))
@@ -594,7 +592,7 @@ trait Infer extends Checkable {
/** Return inferred type arguments, given type parameters, formal parameters,
* argument types, result type and expected result type.
- * If this is not possible, throw a <code>NoInstance</code> exception.
+ * If this is not possible, throw a `NoInstance` exception.
* Undetermined type arguments are represented by `definitions.NothingClass.tpe`.
* No check that inferred parameters conform to their bounds is made here.
*
@@ -651,9 +649,57 @@ trait Infer extends Checkable {
tvars, tparams, tparams map varianceInTypes(formals),
false, lubDepth(formals) max lubDepth(argtpes)
)
+ // Can warn about inferring Any/AnyVal as long as they don't appear
+ // explicitly anywhere amongst the formal, argument, result, or expected type.
+ def canWarnAboutAny = !(pt :: restpe :: formals ::: argtpes exists (t => (t contains AnyClass) || (t contains AnyValClass)))
+ def argumentPosition(idx: Int): Position = context.tree match {
+ case x: ValOrDefDef => x.rhs match {
+ case Apply(fn, args) if idx < args.size => args(idx).pos
+ case _ => context.tree.pos
+ }
+ case _ => context.tree.pos
+ }
+ if (settings.warnInferAny.value && context.reportErrors && canWarnAboutAny) {
+ foreachWithIndex(targs) ((targ, idx) =>
+ targ.typeSymbol match {
+ case sym @ (AnyClass | AnyValClass) =>
+ context.unit.warning(argumentPosition(idx), s"a type was inferred to be `${sym.name}`; this may indicate a programming error.")
+ case _ =>
+ }
+ )
+ }
adjustTypeArgs(tparams, tvars, targs, restpe)
}
+ /** One must step carefully when assessing applicability due to
+ * complications from varargs, tuple-conversion, named arguments.
+ * This method is used to filter out inapplicable methods,
+ * its behavior slightly configurable based on what stage of
+ * overloading resolution we're at.
+ *
+ * This method has boolean parameters, which is usually suboptimal
+ * but I didn't work out a better way. They don't have defaults,
+ * and the method's scope is limited.
+ */
+ private[typechecker] def isApplicableBasedOnArity(tpe: Type, argsCount: Int, varargsStar: Boolean, tuplingAllowed: Boolean): Boolean = followApply(tpe) match {
+ case OverloadedType(pre, alts) =>
+ alts exists (alt => isApplicableBasedOnArity(pre memberType alt, argsCount, varargsStar, tuplingAllowed))
+ case _ =>
+ val paramsCount = tpe.params.length
+ val simpleMatch = paramsCount == argsCount
+ val varargsTarget = isVarArgsList(tpe.params)
+ def varargsMatch = varargsTarget && (paramsCount - 1) <= argsCount
+ def tuplingMatch = tuplingAllowed && eligibleForTupleConversion(paramsCount, argsCount, varargsTarget)
+
+ // A varargs star call, e.g. (x, y:_*) can only match a varargs method
+ // with the same number of parameters. See SI-5859 for an example of what
+ // would fail were this not enforced before we arrived at isApplicable.
+ if (varargsStar)
+ varargsTarget && simpleMatch
+ else
+ simpleMatch || varargsMatch || tuplingMatch
+ }
+
private[typechecker] def followApply(tp: Type): Type = tp match {
case NullaryMethodType(restp) =>
val restp1 = followApply(restp)
@@ -670,14 +716,6 @@ trait Infer extends Checkable {
else OverloadedType(tp, appmeth.alternatives)
}
- def hasExactlyNumParams(tp: Type, n: Int): Boolean = tp match {
- case OverloadedType(pre, alts) =>
- alts exists (alt => hasExactlyNumParams(pre.memberType(alt), n))
- case _ =>
- val len = tp.params.length
- len == n || isVarArgsList(tp.params) && len <= n + 1
- }
-
/**
* Verifies whether the named application is valid. The logic is very
* similar to the one in NamesDefaults.removeNames.
@@ -723,17 +761,54 @@ trait Infer extends Checkable {
(argtpes1, argPos, namesOK)
}
- /** don't do a () to (()) conversion for methods whose second parameter
- * is a varargs. This is a fairly kludgey way to address #3224.
- * We'll probably find a better way to do this by identifying
- * tupled and n-ary methods, but thiws is something for a future major revision.
+ /** True if the given parameter list can accept a tupled argument list,
+ * and the argument list can be tupled (based on its length.)
+ */
+ def eligibleForTupleConversion(paramsCount: Int, argsCount: Int, varargsTarget: Boolean): Boolean = {
+ def canSendTuple = argsCount match {
+ case 0 => !varargsTarget // avoid () to (()) conversion - SI-3224
+ case 1 => false // can't tuple a single argument
+ case n => n <= MaxTupleArity // <= 22 arguments
+ }
+ def canReceiveTuple = paramsCount match {
+ case 1 => true
+ case 2 => varargsTarget
+ case _ => false
+ }
+ canSendTuple && canReceiveTuple
+ }
+ def eligibleForTupleConversion(formals: List[Type], argsCount: Int): Boolean = formals match {
+ case p :: Nil => eligibleForTupleConversion(1, argsCount, varargsTarget = isScalaRepeatedParamType(p))
+ case _ :: p :: Nil if isScalaRepeatedParamType(p) => eligibleForTupleConversion(2, argsCount, varargsTarget = true)
+ case _ => false
+ }
+
+ /** The type of an argument list after being coerced to a tuple.
+ * @pre: the argument list is eligible for tuple conversion.
*/
- def isUnitForVarArgs(args: List[AnyRef], params: List[Symbol]): Boolean =
- args.isEmpty && hasLength(params, 2) && isVarArgsList(params)
+ private def typeAfterTupleConversion(argtpes: List[Type]): Type = (
+ if (argtpes.isEmpty) UnitClass.tpe // aka "Tuple0"
+ else tupleType(argtpes map {
+ case NamedType(name, tp) => UnitClass.tpe // not a named arg - only assignments here
+ case RepeatedType(tp) => tp // but probably shouldn't be tupling a call containing :_*
+ case tp => tp
+ })
+ )
- /** Is there an instantiation of free type variables <code>undetparams</code>
- * such that function type <code>ftpe</code> is applicable to
- * <code>argtpes</code> and its result conform to <code>pt</code>?
+ /** If the argument list needs to be tupled for the parameter list,
+ * a list containing the type of the tuple. Otherwise, the original
+ * argument list.
+ */
+ def tupleIfNecessary(formals: List[Type], argtpes: List[Type]): List[Type] = {
+ if (eligibleForTupleConversion(formals, argtpes.size))
+ typeAfterTupleConversion(argtpes) :: Nil
+ else
+ argtpes
+ }
+
+ /** Is there an instantiation of free type variables `undetparams`
+ * such that function type `ftpe` is applicable to
+ * `argtpes` and its result conform to `pt`?
*
* @param undetparams ...
* @param ftpe the type of the function (often a MethodType)
@@ -748,23 +823,16 @@ trait Infer extends Checkable {
argtpes0: List[Type], pt: Type): Boolean =
ftpe match {
case OverloadedType(pre, alts) =>
- alts exists (alt => isApplicable(undetparams, pre.memberType(alt), argtpes0, pt))
+ alts exists (alt => isApplicable(undetparams, pre memberType alt, argtpes0, pt))
case ExistentialType(tparams, qtpe) =>
isApplicable(undetparams, qtpe, argtpes0, pt)
case mt @ MethodType(params, _) =>
- val formals = formalTypes(mt.paramTypes, argtpes0.length, removeByName = false)
-
- def tryTupleApply: Boolean = {
- // if 1 formal, 1 argtpe (a tuple), otherwise unmodified argtpes0
- val tupleArgTpes = actualTypes(argtpes0 map {
- // no assignment is treated as named argument here
- case NamedType(name, tp) => UnitClass.tpe
- case tp => tp
- }, formals.length)
-
- !sameLength(argtpes0, tupleArgTpes) &&
- !isUnitForVarArgs(argtpes0, params) &&
- isApplicable(undetparams, ftpe, tupleArgTpes, pt)
+ val argslen = argtpes0.length
+ val formals = formalTypes(mt.paramTypes, argslen, removeByName = false)
+
+ def tryTupleApply = {
+ val tupled = tupleIfNecessary(mt.paramTypes, argtpes0)
+ (tupled ne argtpes0) && isApplicable(undetparams, ftpe, tupled, pt)
}
def typesCompatible(argtpes: List[Type]) = {
val restpe = ftpe.resultType(argtpes)
@@ -786,17 +854,16 @@ trait Infer extends Checkable {
val lencmp = compareLengths(argtpes0, formals)
if (lencmp > 0) tryTupleApply
else if (lencmp == 0) {
- if (!argtpes0.exists(_.isInstanceOf[NamedType])) {
- // fast track if no named arguments are used
+ // fast track if no named arguments are used
+ if (!containsNamedType(argtpes0))
typesCompatible(argtpes0)
- }
else {
// named arguments are used
val (argtpes1, argPos, namesOK) = checkNames(argtpes0, params)
// when using named application, the vararg param has to be specified exactly once
- ( namesOK && (isIdentity(argPos) || sameLength(formals, params)) &&
- // nb. arguments and names are OK, check if types are compatible
- typesCompatible(reorderArgs(argtpes1, argPos))
+ ( namesOK
+ && (isIdentity(argPos) || sameLength(formals, params))
+ && typesCompatible(reorderArgs(argtpes1, argPos)) // nb. arguments and names are OK, check if types are compatible
)
}
}
@@ -840,17 +907,13 @@ trait Infer extends Checkable {
} else res1
}
- /** Is type <code>ftpe1</code> strictly more specific than type <code>ftpe2</code>
+ /** Is type `ftpe1` strictly more specific than type `ftpe2`
* when both are alternatives in an overloaded function?
* @see SLS (sec:overloading-resolution)
- *
- * @param ftpe1 ...
- * @param ftpe2 ...
- * @return ...
*/
def isAsSpecific(ftpe1: Type, ftpe2: Type): Boolean = ftpe1 match {
case OverloadedType(pre, alts) =>
- alts exists (alt => isAsSpecific(pre.memberType(alt), ftpe2))
+ alts exists (alt => isAsSpecific(pre memberType alt, ftpe2))
case et: ExistentialType =>
isAsSpecific(ftpe1.skolemizeExistential, ftpe2)
//et.withTypeVars(isAsSpecific(_, ftpe2))
@@ -877,7 +940,7 @@ trait Infer extends Checkable {
case _ =>
ftpe2 match {
case OverloadedType(pre, alts) =>
- alts forall (alt => isAsSpecific(ftpe1, pre.memberType(alt)))
+ alts forall (alt => isAsSpecific(ftpe1, pre memberType alt))
case et: ExistentialType =>
et.withTypeVars(isAsSpecific(ftpe1, _))
case mt: MethodType =>
@@ -1089,25 +1152,20 @@ trait Infer extends Checkable {
/** Substitute free type variables `undetparams` of polymorphic argument
* expression `tree` to `targs`, Error if `targs` is null.
- *
- * @param tree ...
- * @param undetparams ...
- * @param targs ...
- * @param pt ...
*/
- private def substExpr(tree: Tree, undetparams: List[Symbol],
- targs: List[Type], pt: Type) {
+ private def substExpr(tree: Tree, undetparams: List[Symbol], targs: List[Type], pt: Type) {
if (targs eq null) {
if (!tree.tpe.isErroneous && !pt.isErroneous)
PolymorphicExpressionInstantiationError(tree, undetparams, pt)
- } else {
+ }
+ else {
new TreeTypeSubstituter(undetparams, targs).traverse(tree)
notifyUndetparamsInferred(undetparams, targs)
}
}
- /** Substitute free type variables <code>undetparams</code> of application
- * <code>fn(args)</code>, given prototype <code>pt</code>.
+ /** Substitute free type variables `undetparams` of application
+ * `fn(args)`, given prototype `pt`.
*
* @param fn fn: the function that needs to be instantiated.
* @param undetparams the parameters that need to be determined
@@ -1120,10 +1178,10 @@ trait Infer extends Checkable {
args: List[Tree], pt0: Type): List[Symbol] = fn.tpe match {
case mt @ MethodType(params0, _) =>
try {
- val pt = if (pt0.typeSymbol == UnitClass) WildcardType else pt0
- val formals = formalTypes(mt.paramTypes, args.length)
- val argtpes = actualTypes(args map (x => elimAnonymousClass(x.tpe.deconst)), formals.length)
- val restpe = fn.tpe.resultType(argtpes)
+ val pt = if (pt0.typeSymbol == UnitClass) WildcardType else pt0
+ val formals = formalTypes(mt.paramTypes, args.length)
+ val argtpes = tupleIfNecessary(formals, args map (x => elimAnonymousClass(x.tpe.deconst)))
+ val restpe = fn.tpe.resultType(argtpes)
val AdjustedTypeArgs.AllArgsAndUndets(okparams, okargs, allargs, leftUndet) =
methTypeArgs(undetparams, formals, restpe, argtpes, pt)
@@ -1160,8 +1218,8 @@ trait Infer extends Checkable {
def widen(tp: Type): Type = abstractTypesToBounds(tp)
- /** Substitute free type variables <code>undetparams</code> of type constructor
- * <code>tree</code> in pattern, given prototype <code>pt</code>.
+ /** Substitute free type variables `undetparams` of type constructor
+ * `tree` in pattern, given prototype `pt`.
*
* @param tree the constuctor that needs to be instantiated
* @param undetparams the undetermined type parameters
@@ -1228,17 +1286,20 @@ trait Infer extends Checkable {
}
} else None
- (inferFor(pt) orElse inferForApproxPt) map { targs =>
- new TreeTypeSubstituter(undetparams, targs).traverse(tree)
- notifyUndetparamsInferred(undetparams, targs)
- } getOrElse {
- debugwarn("failed inferConstructorInstance for "+ tree +" : "+ tree.tpe +" under "+ undetparams +" pt = "+ pt +(if(isFullyDefined(pt)) " (fully defined)" else " (not fully defined)"))
- // if (settings.explaintypes.value) explainTypes(resTp.instantiateTypeParams(undetparams, tvars), pt)
- ConstrInstantiationError(tree, resTp, pt)
+ val inferred = inferFor(pt) orElse inferForApproxPt
+
+ inferred match {
+ case Some(targs) =>
+ new TreeTypeSubstituter(undetparams, targs).traverse(tree)
+ notifyUndetparamsInferred(undetparams, targs)
+ case _ =>
+ def full = if (isFullyDefined(pt)) "(fully defined)" else "(not fully defined)"
+ devWarning(s"failed inferConstructorInstance for $tree: ${tree.tpe} undet=$undetparams, pt=$pt $full")
+ // if (settings.explaintypes.value) explainTypes(resTp.instantiateTypeParams(undetparams, tvars), pt)
+ ConstrInstantiationError(tree, resTp, pt)
}
}
-
def instBounds(tvar: TypeVar): (Type, Type) = {
val tparam = tvar.origin.typeSymbol
val instType = toOrigin(tvar.constr.inst)
@@ -1286,51 +1347,6 @@ trait Infer extends Checkable {
}
}
- /** Does `tp` contain any types that cannot be checked at run-time (i.e., after erasure, will isInstanceOf[erased(tp)] imply conceptualIsInstanceOf[tp]?)
- * we should find a way to ask erasure: hey, is `tp` going to make it through you with all of its isInstanceOf resolving powers intact?
- * TODO: at the very least, reduce duplication wrt checkCheckable
- */
- def containsUnchecked(tp: Type): Boolean = {
- def check(tp: Type, bound: List[Symbol]): Boolean = {
- def isSurroundingTypeParam(sym: Symbol) = {
- val e = context.scope.lookupEntry(sym.name)
- ( (e ne null)
- && (e.sym == sym )
- && !e.sym.isTypeParameterOrSkolem
- && (e.owner == context.scope)
- )
- }
- def isLocalBinding(sym: Symbol) = (
- sym.isAbstractType && (
- (bound contains sym)
- || (sym.name == tpnme.WILDCARD)
- || isSurroundingTypeParam(sym)
- )
- )
- tp.normalize match {
- case SingleType(pre, _) =>
- check(pre, bound)
- case TypeRef(_, ArrayClass, arg :: _) =>
- check(arg, bound)
- case tp @ TypeRef(pre, sym, args) =>
- ( (sym.isAbstractType && !isLocalBinding(sym))
- || (args exists (x => !isLocalBinding(x.typeSymbol)))
- || check(pre, bound)
- )
- // case RefinedType(_, decls) if decls.nonEmpty =>
- // patternWarning(tp, "refinement ")
- case RefinedType(parents, _) =>
- parents exists (p => check(p, bound))
- case ExistentialType(quantified, tp1) =>
- check(tp1, bound ::: quantified)
- case _ =>
- false
- }
- }
- check(tp, Nil)
- }
-
-
/** Type intersection of simple type tp1 with general type tp2.
* The result eliminates some redundancies.
*/
@@ -1469,52 +1485,30 @@ trait Infer extends Checkable {
}
*/
- /** Assign <code>tree</code> the symbol and type of the alternative which
- * matches prototype <code>pt</code>, if it exists.
+ /** Assign `tree` the symbol and type of the alternative which
+ * matches prototype `pt`, if it exists.
* If several alternatives match `pt`, take parameterless one.
* If no alternative matches `pt`, take the parameterless one anyway.
*/
def inferExprAlternative(tree: Tree, pt: Type) = tree.tpe match {
case OverloadedType(pre, alts) => tryTwice { isSecondTry =>
- val alts0 = alts filter (alt => isWeaklyCompatible(pre.memberType(alt), pt))
- val noAlternatives = alts0.isEmpty
- val alts1 = if (noAlternatives) alts else alts0
-
- //println("trying "+alts1+(alts1 map (_.tpe))+(alts1 map (_.locationString))+" for "+pt)
- def improves(sym1: Symbol, sym2: Symbol): Boolean =
- sym2 == NoSymbol || sym2.hasAnnotation(BridgeClass) ||
- { val tp1 = pre.memberType(sym1)
- val tp2 = pre.memberType(sym2)
- (tp2 == ErrorType ||
- !global.typer.infer.isWeaklyCompatible(tp2, pt) && global.typer.infer.isWeaklyCompatible(tp1, pt) ||
- isStrictlyMoreSpecific(tp1, tp2, sym1, sym2)) }
+ val alts0 = alts filter (alt => isWeaklyCompatible(pre.memberType(alt), pt))
+ val alts1 = if (alts0.isEmpty) alts else alts0
- val best = ((NoSymbol: Symbol) /: alts1) ((best, alt) =>
- if (improves(alt, best)) alt else best)
+ val bests = bestAlternatives(alts1) { (sym1, sym2) =>
+ val tp1 = pre.memberType(sym1)
+ val tp2 = pre.memberType(sym2)
- val competing = alts1 dropWhile (alt => best == alt || improves(best, alt))
-
- if (best == NoSymbol) {
- if (settings.debug.value) {
- tree match {
- case Select(qual, _) =>
- Console.println("qual: " + qual + ":" + qual.tpe +
- " with decls " + qual.tpe.decls +
- " with members " + qual.tpe.members +
- " with members " + qual.tpe.member(newTermName("$minus")))
- case _ =>
- }
- }
- // todo: missing test case
- NoBestExprAlternativeError(tree, pt, isSecondTry)
- } else if (!competing.isEmpty) {
- if (noAlternatives) NoBestExprAlternativeError(tree, pt, isSecondTry)
- else if (!pt.isErroneous) AmbiguousExprAlternativeError(tree, pre, best, competing.head, pt, isSecondTry)
- } else {
-// val applicable = alts1 filter (alt =>
-// global.typer.infer.isWeaklyCompatible(pre.memberType(alt), pt))
-// checkNotShadowed(tree.pos, pre, best, applicable)
- tree.setSymbol(best).setType(pre.memberType(best))
+ ( tp2 == ErrorType
+ || (!isWeaklyCompatible(tp2, pt) && isWeaklyCompatible(tp1, pt))
+ || isStrictlyMoreSpecific(tp1, tp2, sym1, sym2)
+ )
+ }
+ // todo: missing test case for bests.isEmpty
+ bests match {
+ case best :: Nil => tree setSymbol best setType (pre memberType best)
+ case best :: competing :: _ if alts0.nonEmpty => if (!pt.isErroneous) AmbiguousExprAlternativeError(tree, pre, best, competing, pt, isSecondTry)
+ case _ => if (bests.isEmpty || alts0.isEmpty) NoBestExprAlternativeError(tree, pt, isSecondTry)
}
}
}
@@ -1533,48 +1527,47 @@ trait Infer extends Checkable {
private def paramMatchesName(param: Symbol, name: Name) =
param.name == name || param.deprecatedParamName.exists(_ == name)
- // Check the first parameter list the same way.
- private def methodMatchesName(method: Symbol, name: Name) = method.paramss match {
- case ps :: _ => ps exists (p => paramMatchesName(p, name))
- case _ => false
+ private def containsNamedType(argtpes: List[Type]): Boolean = argtpes match {
+ case Nil => false
+ case NamedType(_, _) :: _ => true
+ case _ :: rest => containsNamedType(rest)
}
-
- private def resolveOverloadedMethod(argtpes: List[Type], eligible: List[Symbol]) = {
+ private def namesOfNamedArguments(argtpes: List[Type]) =
+ argtpes collect { case NamedType(name, _) => name }
+
+ /** Given a list of argument types and eligible method overloads, whittle the
+ * list down to the methods which should be considered for specificity
+ * testing, taking into account here:
+ * - named arguments at the call site (keep only methods with name-matching parameters)
+ * - if multiple methods are eligible, drop any methods which take default arguments
+ * - drop any where arity cannot match under any conditions (allowing for
+ * overloaded applies, varargs, and tupling conversions)
+ * This method is conservative; it can tolerate some varieties of false positive,
+ * but no false negatives.
+ *
+ * @param eligible the overloaded method symbols
+ * @param argtpes the argument types at the call site
+ * @param varargsStar true if the call site has a `: _*` attached to the last argument
+ */
+ private def overloadsToConsiderBySpecificity(eligible: List[Symbol], argtpes: List[Type], varargsStar: Boolean): List[Symbol] = {
// If there are any foo=bar style arguments, and any of the overloaded
// methods has a parameter named `foo`, then only those methods are considered.
- val namesOfArgs = argtpes collect { case NamedType(name, _) => name }
- val namesMatch = (
- if (namesOfArgs.isEmpty) Nil
- else eligible filter { m =>
- namesOfArgs forall { name =>
- methodMatchesName(m, name)
- }
- }
- )
-
- if (namesMatch.nonEmpty) namesMatch
- else if (eligible.isEmpty || eligible.tail.isEmpty) eligible
- else eligible filter { alt =>
- // for functional values, the `apply` method might be overloaded
- val mtypes = followApply(alt.tpe) match {
- case OverloadedType(_, alts) => alts map (_.tpe)
- case t => t :: Nil
- }
- // Drop those that use a default; keep those that use vararg/tupling conversion.
- mtypes exists (t =>
- !t.typeSymbol.hasDefaultFlag && {
- compareLengths(t.params, argtpes) < 0 || // tupling (*)
- hasExactlyNumParams(t, argtpes.length) // same nb or vararg
- }
- )
- // (*) more arguments than parameters, but still applicable: tupling conversion works.
- // todo: should not return "false" when paramTypes = (Unit) no argument is given
- // (tupling would work)
+ val namesMatch = namesOfNamedArguments(argtpes) match {
+ case Nil => Nil
+ case names => eligible filter (m => names forall (name => m.info.params exists (p => paramMatchesName(p, name))))
}
+ if (namesMatch.nonEmpty)
+ namesMatch
+ else if (eligible.isEmpty || eligible.tail.isEmpty)
+ eligible
+ else
+ eligible filter (alt =>
+ !alt.hasDefault && isApplicableBasedOnArity(alt.tpe, argtpes.length, varargsStar, tuplingAllowed = true)
+ )
}
- /** Assign <code>tree</code> the type of an alternative which is applicable
- * to <code>argtpes</code>, and whose result type is compatible with `pt`.
+ /** Assign `tree` the type of an alternative which is applicable
+ * to `argtpes`, and whose result type is compatible with `pt`.
* If several applicable alternatives exist, drop the alternatives which use
* default arguments, then select the most specialized one.
* If no applicable alternative exists, and pt != WildcardType, try again
@@ -1586,49 +1579,42 @@ trait Infer extends Checkable {
* of some NamedType does not exist in an alternative's parameter names,
* the type is replaces by `Unit`, i.e. the argument is treated as an
* assignment expression.
+ *
+ * @pre tree.tpe is an OverloadedType.
*/
- def inferMethodAlternative(tree: Tree, undetparams: List[Symbol],
- argtpes: List[Type], pt0: Type, varArgsOnly: Boolean = false, lastInferAttempt: Boolean = true): Unit = tree.tpe match {
- case OverloadedType(pre, alts) =>
- val pt = if (pt0.typeSymbol == UnitClass) WildcardType else pt0
- tryTwice { isSecondTry =>
- debuglog("infer method alt "+ tree.symbol +" with alternatives "+
- (alts map pre.memberType) +", argtpes = "+ argtpes +", pt = "+ pt)
-
- val applicable = resolveOverloadedMethod(argtpes, {
- alts filter { alt =>
- inSilentMode(context)(isApplicable(undetparams, followApply(pre.memberType(alt)), argtpes, pt)) &&
- (!varArgsOnly || isVarArgsList(alt.tpe.params))
- }
- })
-
- def improves(sym1: Symbol, sym2: Symbol) = {
- // util.trace("improve "+sym1+sym1.locationString+" on "+sym2+sym2.locationString)
- sym2 == NoSymbol || sym2.isError || sym2.hasAnnotation(BridgeClass) ||
- isStrictlyMoreSpecific(followApply(pre.memberType(sym1)),
- followApply(pre.memberType(sym2)), sym1, sym2)
- }
-
- val best = ((NoSymbol: Symbol) /: applicable) ((best, alt) =>
- if (improves(alt, best)) alt else best)
- val competing = applicable.dropWhile(alt => best == alt || improves(best, alt))
- if (best == NoSymbol) {
- if (pt == WildcardType) NoBestMethodAlternativeError(tree, argtpes, pt, isSecondTry && lastInferAttempt)
- else inferMethodAlternative(tree, undetparams, argtpes, WildcardType, lastInferAttempt = isSecondTry)
- } else if (!competing.isEmpty) {
- AmbiguousMethodAlternativeError(tree, pre, best, competing.head, argtpes, pt, isSecondTry && lastInferAttempt)
- } else {
-// checkNotShadowed(tree.pos, pre, best, applicable)
- tree.setSymbol(best).setType(pre.memberType(best))
- }
+ def inferMethodAlternative(tree: Tree, undetparams: List[Symbol], argtpes0: List[Type], pt0: Type): Unit = {
+ val OverloadedType(pre, alts) = tree.tpe
+ var varargsStar = false
+ val argtpes = argtpes0 mapConserve {
+ case RepeatedType(tp) => varargsStar = true ; tp
+ case tp => tp
+ }
+ def followType(sym: Symbol) = followApply(pre memberType sym)
+ def bestForExpectedType(pt: Type, isLastTry: Boolean): Unit = {
+ val applicable0 = alts filter (alt => inSilentMode(context)(isApplicable(undetparams, followType(alt), argtpes, pt)))
+ val applicable = overloadsToConsiderBySpecificity(applicable0, argtpes, varargsStar)
+ val ranked = bestAlternatives(applicable)((sym1, sym2) =>
+ isStrictlyMoreSpecific(followType(sym1), followType(sym2), sym1, sym2)
+ )
+ ranked match {
+ case best :: competing :: _ => AmbiguousMethodAlternativeError(tree, pre, best, competing, argtpes, pt, isLastTry) // ambiguous
+ case best :: Nil => tree setSymbol best setType (pre memberType best) // success
+ case Nil if pt eq WildcardType => NoBestMethodAlternativeError(tree, argtpes, pt, isLastTry) // failed
+ case Nil => bestForExpectedType(WildcardType, isLastTry) // failed, but retry with WildcardType
}
- case _ =>
+ }
+ // This potentially makes up to four attempts: tryTwice may execute
+ // with and without views enabled, and bestForExpectedType will try again
+ // with pt = WildcardType if it fails with pt != WildcardType.
+ tryTwice { isLastTry =>
+ val pt = if (pt0.typeSymbol == UnitClass) WildcardType else pt0
+ debuglog(s"infer method alt ${tree.symbol} with alternatives ${alts map pre.memberType} argtpes=$argtpes pt=$pt")
+ bestForExpectedType(pt, isLastTry)
+ }
}
/** Try inference twice, once without views and once with views,
* unless views are already disabled.
- *
- * @param infer ...
*/
def tryTwice(infer: Boolean => Unit): Unit = {
if (context.implicitsEnabled) {
@@ -1663,12 +1649,9 @@ trait Infer extends Checkable {
else infer(true)
}
- /** Assign <code>tree</code> the type of all polymorphic alternatives
- * with <code>nparams</code> as the number of type parameters, if it exists.
+ /** Assign `tree` the type of all polymorphic alternatives
+ * with `nparams` as the number of type parameters, if it exists.
* If no such polymorphic alternative exist, error.
- *
- * @param tree ...
- * @param nparams ...
*/
def inferPolyAlternatives(tree: Tree, argtypes: List[Type]): Unit = {
val OverloadedType(pre, alts) = tree.tpe
diff --git a/src/compiler/scala/tools/nsc/typechecker/Macros.scala b/src/compiler/scala/tools/nsc/typechecker/Macros.scala
index b20a9ea626..4d1ab98fa0 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Macros.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Macros.scala
@@ -3,15 +3,10 @@ package typechecker
import symtab.Flags._
import scala.tools.nsc.util._
-import scala.tools.nsc.util.ClassPath._
import scala.reflect.runtime.ReflectionUtils
import scala.collection.mutable.ListBuffer
-import scala.compat.Platform.EOL
import scala.reflect.internal.util.Statistics
import scala.reflect.macros.util._
-import java.lang.{Class => jClass}
-import java.lang.reflect.{Array => jArray, Method => jMethod}
-import scala.reflect.internal.util.Collections._
import scala.util.control.ControlThrowable
import scala.reflect.macros.runtime.AbortMacroException
@@ -293,53 +288,51 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces {
private def macroImplSig(macroDef: Symbol, tparams: List[TypeDef], vparamss: List[List[ValDef]], retTpe: Type): (List[List[Symbol]], Type) = {
// had to move method's body to an object because of the recursive dependencies between sigma and param
object SigGenerator {
- def sigma(tpe: Type): Type = {
- class SigmaTypeMap extends TypeMap {
- def apply(tp: Type): Type = tp match {
- case TypeRef(pre, sym, args) =>
- val pre1 = pre match {
- case ThisType(sym) if sym == macroDef.owner =>
- SingleType(SingleType(SingleType(NoPrefix, ctxParam), MacroContextPrefix), ExprValue)
- case SingleType(NoPrefix, sym) =>
- mfind(vparamss)(_.symbol == sym) match {
- case Some(macroDefParam) => SingleType(SingleType(NoPrefix, param(macroDefParam)), ExprValue)
- case _ => pre
- }
- case _ =>
- pre
- }
- TypeRef(pre1, sym, args map mapOver)
- case _ =>
- mapOver(tp)
- }
+ def WeakTagClass = getMember(MacroContextClass, tpnme.WeakTypeTag)
+ def ExprClass = getMember(MacroContextClass, tpnme.Expr)
+ val cache = scala.collection.mutable.Map[Symbol, Symbol]()
+ val ctxParam = makeParam(nme.macroContext, macroDef.pos, MacroContextClass.tpe, SYNTHETIC)
+ val paramss = List(ctxParam) :: mmap(vparamss)(param)
+ val implReturnType = typeRef(singleType(NoPrefix, ctxParam), ExprClass, List(sigma(retTpe)))
+
+ object SigmaTypeMap extends TypeMap {
+ def mapPrefix(pre: Type) = pre match {
+ case ThisType(sym) if sym == macroDef.owner =>
+ singleType(singleType(singleType(NoPrefix, ctxParam), MacroContextPrefix), ExprValue)
+ case SingleType(NoPrefix, sym) =>
+ mfind(vparamss)(_.symbol == sym).fold(pre)(p => singleType(singleType(NoPrefix, param(p)), ExprValue))
+ case _ =>
+ mapOver(pre)
+ }
+ def apply(tp: Type): Type = tp match {
+ case TypeRef(pre, sym, args) =>
+ val pre1 = mapPrefix(pre)
+ val args1 = mapOverArgs(args, sym.typeParams)
+ if ((pre eq pre1) && (args eq args1)) tp
+ else typeRef(pre1, sym, args1)
+ case _ =>
+ mapOver(tp)
}
-
- new SigmaTypeMap() apply tpe
}
+ def sigma(tpe: Type): Type = SigmaTypeMap(tpe)
+
+ def makeParam(name: Name, pos: Position, tpe: Type, flags: Long) =
+ macroDef.newValueParameter(name.toTermName, pos, flags) setInfo tpe
+ def implType(isType: Boolean, origTpe: Type): Type = {
+ def tsym = if (isType) WeakTagClass else ExprClass
+ def targ = origTpe.typeArgs.headOption getOrElse NoType
- def makeParam(name: Name, pos: Position, tpe: Type, flags: Long = 0L) =
- macroDef.newValueParameter(name, pos, flags) setInfo tpe
- val ctxParam = makeParam(nme.macroContext, macroDef.pos, MacroContextClass.tpe, SYNTHETIC)
- def implType(isType: Boolean, origTpe: Type): Type =
if (isRepeatedParamType(origTpe))
- appliedType(
- RepeatedParamClass.typeConstructor,
- List(implType(isType, sigma(origTpe.typeArgs.head))))
- else {
- val tsym = getMember(MacroContextClass, if (isType) tpnme.WeakTypeTag else tpnme.Expr)
+ scalaRepeatedType(implType(isType, sigma(targ)))
+ else
typeRef(singleType(NoPrefix, ctxParam), tsym, List(sigma(origTpe)))
- }
- val paramCache = scala.collection.mutable.Map[Symbol, Symbol]()
- def param(tree: Tree): Symbol =
- paramCache.getOrElseUpdate(tree.symbol, {
+ }
+ def param(tree: Tree): Symbol = (
+ cache.getOrElseUpdate(tree.symbol, {
val sym = tree.symbol
- val sigParam = makeParam(sym.name, sym.pos, implType(sym.isType, sym.tpe))
- if (sym.isSynthetic) sigParam.flags |= SYNTHETIC
- sigParam
+ makeParam(sym.name, sym.pos, implType(sym.isType, sym.tpe), sym getFlag SYNTHETIC)
})
-
- val paramss = List(ctxParam) :: mmap(vparamss)(param)
- val implRetTpe = typeRef(singleType(NoPrefix, ctxParam), getMember(MacroContextClass, tpnme.Expr), List(sigma(retTpe)))
+ )
}
import SigGenerator._
@@ -347,7 +340,7 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces {
macroTraceVerbose("tparams are: ")(tparams)
macroTraceVerbose("vparamss are: ")(vparamss)
macroTraceVerbose("retTpe is: ")(retTpe)
- macroTraceVerbose("macroImplSig is: ")((paramss, implRetTpe))
+ macroTraceVerbose("macroImplSig is: ")((paramss, implReturnType))
}
/** Verifies that the body of a macro def typechecks to a reference to a static public non-overloaded method,
@@ -477,9 +470,6 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces {
* Is also capable of detecting REPL and reusing its classloader.
*/
lazy val macroClassloader: ClassLoader = {
- if (global.forMSIL)
- throw new UnsupportedOperationException("Scala reflection not available on this platform")
-
val classpath = global.classPath.asURLs
macroLogVerbose("macro classloader: initializing from -cp: %s".format(classpath))
val loader = ScalaClassLoader.fromURLs(classpath, self.getClass.getClassLoader)
@@ -720,16 +710,15 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces {
/** Does the same as `macroExpand`, but without typechecking the expansion
* Meant for internal use within the macro infrastructure, don't use it elsewhere.
*/
- private def macroExpand1(typer: Typer, expandee: Tree): MacroExpansionResult =
+ private def macroExpand1(typer: Typer, expandee: Tree): MacroExpansionResult = {
// verbose printing might cause recursive macro expansions, so I'm shutting it down here
withInfoLevel(nodePrinters.InfoLevel.Quiet) {
if (expandee.symbol.isErroneous || (expandee exists (_.isErroneous))) {
val reason = if (expandee.symbol.isErroneous) "not found or incompatible macro implementation" else "erroneous arguments"
macroTraceVerbose("cancelled macro expansion because of %s: ".format(reason))(expandee)
- return Cancel(typer.infer.setError(expandee))
+ Cancel(typer.infer.setError(expandee))
}
-
- try {
+ else try {
val runtime = macroRuntime(expandee.symbol)
if (runtime != null) macroExpandWithRuntime(typer, expandee, runtime)
else macroExpandWithoutRuntime(typer, expandee)
@@ -737,6 +726,7 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces {
case typer.TyperErrorGen.MacroExpansionException => Failure(expandee)
}
}
+ }
/** Expands a macro when a runtime (i.e. the macro implementation) can be successfully loaded
* Meant for internal use within the macro infrastructure, don't use it elsewhere.
diff --git a/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala b/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala
index acc4f7ff67..d74d5ecfbe 100644
--- a/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/MethodSynthesis.scala
@@ -6,7 +6,6 @@ package scala.tools.nsc
package typechecker
import symtab.Flags._
-import scala.collection.{ mutable, immutable }
import scala.reflect.internal.util.StringOps.{ ojoin }
import scala.reflect.ClassTag
import scala.reflect.runtime.{ universe => ru }
@@ -30,66 +29,30 @@ trait MethodSynthesis {
if (sym.isLazy) ValDef(sym, body)
else DefDef(sym, body)
- def applyTypeInternal(tags: List[TT[_]]): Type = {
- val symbols = tags map compilerSymbolFromTag
- val container :: args = symbols
- val tparams = container.typeConstructor.typeParams
-
- // Conservative at present - if manifests were more usable this could do a lot more.
- // [Eugene to Paul] all right, they are now. what do you have in mind?
- require(symbols forall (_ ne NoSymbol), "Must find all tags: " + symbols)
- require(container.owner.isPackageClass, "Container must be a top-level class in a package: " + container)
- require(tparams.size == args.size, "Arguments must match type constructor arity: " + tparams + ", " + args)
-
- appliedType(container, args map (_.tpe): _*)
- }
-
- def companionType[T](implicit ct: CT[T]) =
- rootMirror.getRequiredModule(ct.runtimeClass.getName).tpe
-
- // Use these like `applyType[List, Int]` or `applyType[Map, Int, String]`
- def applyType[CC](implicit t1: TT[CC]): Type =
- applyTypeInternal(List(t1))
-
- def applyType[CC[X1], X1](implicit t1: TT[CC[_]], t2: TT[X1]): Type =
- applyTypeInternal(List(t1, t2))
-
- def applyType[CC[X1, X2], X1, X2](implicit t1: TT[CC[_,_]], t2: TT[X1], t3: TT[X2]): Type =
- applyTypeInternal(List(t1, t2, t3))
-
- def applyType[CC[X1, X2, X3], X1, X2, X3](implicit t1: TT[CC[_,_,_]], t2: TT[X1], t3: TT[X2], t4: TT[X3]): Type =
- applyTypeInternal(List(t1, t2, t3, t4))
-
- def newMethodType[F](owner: Symbol)(implicit t: TT[F]): Type = {
- val fnSymbol = compilerSymbolFromTag(t)
- val formals = compilerTypeFromTag(t).typeArguments
- assert(fnSymbol isSubClass FunctionClass(formals.size - 1), (owner, t))
- val params = owner newSyntheticValueParams formals
- MethodType(params, formals.last)
- }
-
- /** The annotations amongst those found on the original symbol which
- * should be propagated to this kind of accessor.
- */
- def deriveAnnotations(initial: List[AnnotationInfo], category: Symbol, keepClean: Boolean): List[AnnotationInfo] = {
- initial filter { ann =>
- // There are no meta-annotation arguments attached to `ann`
- if (ann.metaAnnotations.isEmpty) {
- // A meta-annotation matching `annotKind` exists on `ann`'s definition.
- (ann.defaultTargets contains category) ||
- // `ann`'s definition has no meta-annotations, and `keepClean` is true.
- (ann.defaultTargets.isEmpty && keepClean)
- }
- // There are meta-annotation arguments, and one of them matches `annotKind`
- else ann.metaAnnotations exists (_ matches category)
+ /** The annotations amongst those found on the original symbol which
+ * should be propagated to this kind of accessor.
+ */
+ def deriveAnnotations(initial: List[AnnotationInfo], category: Symbol, keepClean: Boolean): List[AnnotationInfo] = {
+ initial filter { ann =>
+ // There are no meta-annotation arguments attached to `ann`
+ if (ann.metaAnnotations.isEmpty) {
+ // A meta-annotation matching `annotKind` exists on `ann`'s definition.
+ (ann.defaultTargets contains category) ||
+ // `ann`'s definition has no meta-annotations, and `keepClean` is true.
+ (ann.defaultTargets.isEmpty && keepClean)
}
+ // There are meta-annotation arguments, and one of them matches `annotKind`
+ else ann.metaAnnotations exists (_ matches category)
}
- }
+ }
+ }
import synthesisUtil._
class ClassMethodSynthesis(val clazz: Symbol, localTyper: Typer) {
def mkThis = This(clazz) setPos clazz.pos.focus
- def mkThisSelect(sym: Symbol) = atPos(clazz.pos.focus)(Select(mkThis, sym))
+ def mkThisSelect(sym: Symbol) = atPos(clazz.pos.focus)(
+ if (clazz.isClass) Select(This(clazz), sym) else Ident(sym)
+ )
private def isOverride(name: TermName) =
clazzMember(name).alternatives exists (sym => !sym.isDeferred && (sym.owner != clazz))
@@ -99,7 +62,7 @@ trait MethodSynthesis {
overrideFlag | SYNTHETIC
}
def newMethodFlags(method: Symbol) = {
- val overrideFlag = if (isOverride(method.name)) OVERRIDE else 0L
+ val overrideFlag = if (isOverride(method.name.toTermName)) OVERRIDE else 0L
(method.flags | overrideFlag | SYNTHETIC) & ~DEFERRED
}
@@ -107,11 +70,13 @@ trait MethodSynthesis {
localTyper typed ValOrDefDef(method, f(method))
private def createInternal(name: Name, f: Symbol => Tree, info: Type): Tree = {
- val m = clazz.newMethod(name.toTermName, clazz.pos.focus, newMethodFlags(name))
+ val name1 = name.toTermName
+ val m = clazz.newMethod(name1, clazz.pos.focus, newMethodFlags(name1))
finishMethod(m setInfoAndEnter info, f)
}
private def createInternal(name: Name, f: Symbol => Tree, infoFn: Symbol => Type): Tree = {
- val m = clazz.newMethod(name.toTermName, clazz.pos.focus, newMethodFlags(name))
+ val name1 = name.toTermName
+ val m = clazz.newMethod(name1, clazz.pos.focus, newMethodFlags(name1))
finishMethod(m setInfoAndEnter infoFn(m), f)
}
private def cloneInternal(original: Symbol, f: Symbol => Tree, name: Name): Tree = {
@@ -119,22 +84,9 @@ trait MethodSynthesis {
finishMethod(clazz.info.decls enter m, f)
}
- private def cloneInternal(original: Symbol, f: Symbol => Tree): Tree =
- cloneInternal(original, f, original.name)
-
def clazzMember(name: Name) = clazz.info nonPrivateMember name
def typeInClazz(sym: Symbol) = clazz.thisType memberType sym
- /** Function argument takes the newly created method symbol of
- * the same type as `name` in clazz, and returns the tree to be
- * added to the template.
- */
- def overrideMethod(name: Name)(f: Symbol => Tree): Tree =
- overrideMethod(clazzMember(name))(f)
-
- def overrideMethod(original: Symbol)(f: Symbol => Tree): Tree =
- cloneInternal(original, sym => f(sym setFlag OVERRIDE))
-
def deriveMethod(original: Symbol, nameFn: Name => Name)(f: Symbol => Tree): Tree =
cloneInternal(original, f, nameFn(original.name))
@@ -253,8 +205,7 @@ trait MethodSynthesis {
)
def beanAccessors(vd: ValDef): List[DerivedFromValDef] = {
val setter = if (vd.mods.isMutable) List(BeanSetter(vd)) else Nil
- if (forMSIL) Nil
- else if (vd.symbol hasAnnotation BeanPropertyAttr)
+ if (vd.symbol hasAnnotation BeanPropertyAttr)
BeanGetter(vd) :: setter
else if (vd.symbol hasAnnotation BooleanBeanPropertyAttr)
BooleanBeanGetter(vd) :: setter
@@ -312,7 +263,6 @@ trait MethodSynthesis {
// Final methods to make the rest easier to reason about.
final def mods = tree.mods
final def basisSym = tree.symbol
- final def derivedFlags: Long = basisSym.flags & flagsMask | flagsExtra
}
trait DerivedFromClassDef extends DerivedFromMemberDef {
@@ -457,7 +407,7 @@ trait MethodSynthesis {
case class LazyValGetter(tree: ValDef) extends BaseGetter(tree) {
class ChangeOwnerAndModuleClassTraverser(oldowner: Symbol, newowner: Symbol)
extends ChangeOwnerTraverser(oldowner, newowner) {
-
+
override def traverse(tree: Tree) {
tree match {
case _: DefTree => change(tree.symbol.moduleClass)
@@ -557,7 +507,7 @@ trait MethodSynthesis {
// No Symbols available.
private def beanAccessorsFromNames(tree: ValDef) = {
- val ValDef(mods, name, tpt, _) = tree
+ val ValDef(mods, _, _, _) = tree
val hasBP = mods hasAnnotationNamed tpnme.BeanPropertyAnnot
val hasBoolBP = mods hasAnnotationNamed tpnme.BooleanBeanPropertyAnnot
@@ -574,9 +524,6 @@ trait MethodSynthesis {
}
protected def enterBeans(tree: ValDef) {
- if (forMSIL)
- return
-
val ValDef(mods, name, _, _) = tree
val beans = beanAccessorsFromNames(tree)
if (beans.nonEmpty) {
diff --git a/src/compiler/scala/tools/nsc/typechecker/Modes.scala b/src/compiler/scala/tools/nsc/typechecker/Modes.scala
index d650762ac1..e1ee3c482a 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Modes.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Modes.scala
@@ -109,6 +109,7 @@ trait Modes {
final def inFunMode(mode: Int) = (mode & FUNmode) != 0
final def inPolyMode(mode: Int) = (mode & POLYmode) != 0
final def inPatternMode(mode: Int) = (mode & PATTERNmode) != 0
+ final def inPatternNotFunMode(mode: Int) = inPatternMode(mode) && !inFunMode(mode)
final def inExprModeOr(mode: Int, others: Int) = (mode & (EXPRmode | others)) != 0
final def inExprModeButNot(mode: Int, prohibited: Int) =
(mode & (EXPRmode | prohibited)) == EXPRmode
diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala
index 98b6264051..b5160c0519 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala
@@ -8,9 +8,7 @@ package typechecker
import scala.collection.mutable
import scala.annotation.tailrec
-import scala.ref.WeakReference
import symtab.Flags._
-import scala.tools.nsc.io.AbstractFile
/** This trait declares methods to create symbols and to enter them into scopes.
*
@@ -159,6 +157,9 @@ trait Namers extends MethodSynthesis {
else innerNamer
}
+ // FIXME - this logic needs to be thoroughly explained
+ // and justified. I know it's wrong with repect to package
+ // objects, but I think it's also wrong in other ways.
protected def conflict(newS: Symbol, oldS: Symbol) = (
( !oldS.isSourceMethod
|| nme.isSetterName(newS.name)
@@ -186,6 +187,19 @@ trait Namers extends MethodSynthesis {
/** Enter symbol into given scope and return symbol itself */
def enterInScope(sym: Symbol, scope: Scope): Symbol = {
+ // FIXME - this is broken in a number of ways.
+ //
+ // 1) If "sym" allows overloading, that is not itself sufficient to skip
+ // the check, because "prev.sym" also must allow overloading.
+ //
+ // 2) There is nothing which reconciles a package's scope with
+ // the package object's scope. This is the source of many bugs
+ // with e.g. defining a case class in a package object. When
+ // compiling against classes, the class symbol is created in the
+ // package and in the package object, and the conflict is undetected.
+ // There is also a non-deterministic outcome for situations like
+ // an object with the same name as a method in the package object.
+
// allow for overloaded methods
if (!allowsOverload(sym)) {
val prev = scope.lookupEntry(sym.name)
@@ -286,11 +300,11 @@ trait Namers extends MethodSynthesis {
case DefDef(_, nme.CONSTRUCTOR, _, _, _, _) => owner.newConstructor(pos, flags)
case DefDef(_, _, _, _, _, _) => owner.newMethod(name.toTermName, pos, flags)
case ClassDef(_, _, _, _) => owner.newClassSymbol(name.toTypeName, pos, flags)
- case ModuleDef(_, _, _) => owner.newModule(name, pos, flags)
+ case ModuleDef(_, _, _) => owner.newModule(name.toTermName, pos, flags)
case PackageDef(pid, _) => createPackageSymbol(pos, pid)
case ValDef(_, _, _, _) =>
- if (isParameter) owner.newValueParameter(name, pos, flags)
- else owner.newValue(name, pos, flags)
+ if (isParameter) owner.newValueParameter(name.toTermName, pos, flags)
+ else owner.newValue(name.toTermName, pos, flags)
}
}
private def createFieldSymbol(tree: ValDef): TermSymbol =
@@ -321,11 +335,10 @@ trait Namers extends MethodSynthesis {
}
private def enterClassSymbol(tree: ClassDef, clazz: ClassSymbol): Symbol = {
- val file = contextFile
if (clazz.sourceFile != null && clazz.sourceFile != contextFile)
- debugwarn("!!! Source mismatch in " + clazz + ": " + clazz.sourceFile + " vs. " + contextFile)
+ devWarning(s"Source file mismatch in $clazz: ${clazz.sourceFile} vs. $contextFile")
- clazz.sourceFile = contextFile
+ clazz.associatedFile = contextFile
if (clazz.sourceFile != null) {
assert(currentRun.canRedefine(clazz) || clazz.sourceFile == currentRun.symSource(clazz), clazz.sourceFile)
currentRun.symSource(clazz) = clazz.sourceFile
@@ -365,8 +378,8 @@ trait Namers extends MethodSynthesis {
if (sym eq NoSymbol) return
val ctx = if (context.owner.isPackageObjectClass) context.outer else context
- val module = if (sym.isModule) sym else ctx.scope lookup tree.name.toTermName
- val clazz = if (sym.isClass) sym else ctx.scope lookup tree.name.toTypeName
+ val module = if (sym.isModule) sym else ctx.scope lookupModule tree.name
+ val clazz = if (sym.isClass) sym else ctx.scope lookupClass tree.name
val fails = (
module.isModule
&& clazz.isClass
@@ -413,7 +426,7 @@ trait Namers extends MethodSynthesis {
setPrivateWithin(tree, m.moduleClass)
}
if (m.owner.isPackageClass && !m.isPackage) {
- m.moduleClass.sourceFile = contextFile
+ m.moduleClass.associatedFile = contextFile
currentRun.symSource(m) = m.moduleClass.sourceFile
registerTopLevelSym(m)
}
@@ -596,7 +609,7 @@ trait Namers extends MethodSynthesis {
// via "x$lzy" as can be seen in test #3927.
val sym = (
if (owner.isClass) createFieldSymbol(tree)
- else owner.newValue(tree.name append nme.LAZY_LOCAL, tree.pos, tree.mods.flags & ~IMPLICIT)
+ else owner.newValue(tree.name append nme.LAZY_LOCAL, tree.pos, (tree.mods.flags | ARTIFACT) & ~IMPLICIT)
)
enterValSymbol(tree, sym setFlag MUTABLE setLazyAccessor lazyAccessor)
}
@@ -617,7 +630,7 @@ trait Namers extends MethodSynthesis {
case DefDef(_, nme.CONSTRUCTOR, _, _, _, _) =>
assignAndEnterFinishedSymbol(tree)
case DefDef(mods, name, tparams, _, _, _) =>
- val bridgeFlag = if (mods hasAnnotationNamed tpnme.bridgeAnnot) BRIDGE else 0
+ val bridgeFlag = if (mods hasAnnotationNamed tpnme.bridgeAnnot) BRIDGE | ARTIFACT else 0
val sym = assignAndEnterSymbol(tree) setFlag bridgeFlag
if (name == nme.copy && sym.isSynthetic)
@@ -627,7 +640,7 @@ trait Namers extends MethodSynthesis {
}
def enterClassDef(tree: ClassDef) {
- val ClassDef(mods, name, tparams, impl) = tree
+ val ClassDef(mods, _, _, impl) = tree
val primaryConstructorArity = treeInfo.firstConstructorArgs(impl.body).size
tree.symbol = enterClassSymbol(tree)
tree.symbol setInfo completerOf(tree)
@@ -691,41 +704,55 @@ trait Namers extends MethodSynthesis {
// --- Lazy Type Assignment --------------------------------------------------
- def initializeLowerBounds(tp: Type): Type = {
+ def findCyclicalLowerBound(tp: Type): Symbol = {
tp match {
case TypeBounds(lo, _) =>
// check that lower bound is not an F-bound
- for (TypeRef(_, sym, _) <- lo)
- sym.initialize
+ // but carefully: class Foo[T <: Bar[_ >: T]] should be allowed
+ for (tp1 @ TypeRef(_, sym, _) <- lo) {
+ if (settings.breakCycles.value) {
+ if (!sym.maybeInitialize) {
+ log(s"Cycle inspecting $lo for possible f-bounds: ${sym.fullLocationString}")
+ return sym
+ }
+ }
+ else sym.initialize
+ }
case _ =>
}
- tp
+ NoSymbol
}
def monoTypeCompleter(tree: Tree) = mkTypeCompleter(tree) { sym =>
+ // this early test is there to avoid infinite baseTypes when
+ // adding setters and getters --> bug798
+ // It is a def in an attempt to provide some insulation against
+ // uninitialized symbols misleading us. It is not a certainty
+ // this accomplishes anything, but performance is a non-consideration
+ // on these flag checks so it can't hurt.
+ def needsCycleCheck = sym.isNonClassType && !sym.isParameter && !sym.isExistential
logAndValidate(sym) {
- val tp = initializeLowerBounds(typeSig(tree))
+ val tp = typeSig(tree)
+
+ findCyclicalLowerBound(tp) andAlso { sym =>
+ if (needsCycleCheck) {
+ // neg/t1224: trait C[T] ; trait A { type T >: C[T] <: C[C[T]] }
+ // To avoid an infinite loop on the above, we cannot break all cycles
+ log(s"Reinitializing info of $sym to catch any genuine cycles")
+ sym reset sym.info
+ sym.initialize
+ }
+ }
sym setInfo {
if (sym.isJavaDefined) RestrictJavaArraysMap(tp)
else tp
}
- // this early test is there to avoid infinite baseTypes when
- // adding setters and getters --> bug798
- val needsCycleCheck = (sym.isAliasType || sym.isAbstractType) && !sym.isParameter
- if (needsCycleCheck && !typer.checkNonCyclic(tree.pos, tp))
- sym setInfo ErrorType
+ if (needsCycleCheck) {
+ log(s"Needs cycle check: ${sym.debugLocationString}")
+ if (!typer.checkNonCyclic(tree.pos, tp))
+ sym setInfo ErrorType
+ }
}
- // tree match {
- // case ClassDef(_, _, _, impl) =>
- // val parentsOK = (
- // treeInfo.isInterface(sym, impl.body)
- // || (sym eq ArrayClass)
- // || (sym isSubClass AnyValClass)
- // )
- // if (!parentsOK)
- // ensureParent(sym, AnyRefClass)
- // case _ => ()
- // }
}
def moduleClassTypeCompleter(tree: ModuleDef) = {
@@ -784,7 +811,7 @@ trait Namers extends MethodSynthesis {
false
}
- val tpe1 = dropRepeatedParamType(tpe.deconst)
+ val tpe1 = dropIllegalStarTypes(tpe.deconst)
val tpe2 = tpe1.widen
// This infers Foo.type instead of "object Foo"
@@ -832,7 +859,7 @@ trait Namers extends MethodSynthesis {
val sym = (
if (hasType || hasName) {
- owner.typeOfThis = if (hasType) selfTypeCompleter(tpt) else owner.tpe
+ owner.typeOfThis = if (hasType) selfTypeCompleter(tpt) else owner.tpe_*
val selfSym = owner.thisSym setPos self.pos
if (hasName) selfSym setName name else selfSym
}
@@ -877,11 +904,10 @@ trait Namers extends MethodSynthesis {
val modClass = companionSymbolOf(clazz, context).moduleClass
modClass.attachments.get[ClassForCaseCompanionAttachment] foreach { cma =>
val cdef = cma.caseClass
- def hasCopy(decls: Scope) = (decls lookup nme.copy) != NoSymbol
+ def hasCopy = (decls containsName nme.copy) || parents.exists(_ member nme.copy exists)
+
// SI-5956 needs (cdef.symbol == clazz): there can be multiple class symbols with the same name
- if (cdef.symbol == clazz && !hasCopy(decls) &&
- !parents.exists(p => hasCopy(p.typeSymbol.info.decls)) &&
- !parents.flatMap(_.baseClasses).distinct.exists(bc => hasCopy(bc.info.decls)))
+ if (cdef.symbol == clazz && !hasCopy)
addCopyMethod(cdef, templateNamer)
}
}
@@ -913,7 +939,7 @@ trait Namers extends MethodSynthesis {
// DEPMETTODO: do we need to skolemize value parameter symbols?
if (tpt.isEmpty && meth.name == nme.CONSTRUCTOR) {
- tpt defineType context.enclClass.owner.tpe
+ tpt defineType context.enclClass.owner.tpe_*
tpt setPos meth.pos.focus
}
var resultPt = if (tpt.isEmpty) WildcardType else typer.typedType(tpt).tpe
@@ -1165,9 +1191,9 @@ trait Namers extends MethodSynthesis {
// same local block several times (which can happen in interactive mode) we might
// otherwise not find the default symbol, because the second time it the method
// symbol will be re-entered in the scope but the default parameter will not.
- val att = meth.attachments.get[DefaultsOfLocalMethodAttachment] match {
+ meth.attachments.get[DefaultsOfLocalMethodAttachment] match {
case Some(att) => att.defaultGetters += default
- case None => meth.updateAttachment(new DefaultsOfLocalMethodAttachment(default))
+ case None => meth.updateAttachment(new DefaultsOfLocalMethodAttachment(default))
}
}
} else if (baseHasDefault) {
@@ -1258,7 +1284,7 @@ trait Namers extends MethodSynthesis {
AnnotationInfo lazily {
val context1 = typer.context.make(ann)
context1.setReportErrors()
- beforeTyper(newTyper(context1) typedAnnotation ann)
+ enteringTyper(newTyper(context1) typedAnnotation ann)
}
}
if (ainfos.nonEmpty) {
@@ -1335,8 +1361,7 @@ trait Namers extends MethodSynthesis {
transformed(tree) = newImport
// copy symbol and type attributes back into old expression
// so that the structure builder will find it.
- expr.symbol = expr1.symbol
- expr.tpe = expr1.tpe
+ expr setSymbol expr1.symbol setType expr1.tpe
ImportType(expr1)
}
}
@@ -1361,12 +1386,6 @@ trait Namers extends MethodSynthesis {
tpe
}
- def ensureParent(clazz: Symbol, parent: Symbol) = {
- val info0 = clazz.info
- val info1 = includeParent(info0, parent)
- if (info0 ne info1) clazz setInfo info1
- }
-
class LogTransitions[S](onEnter: S => String, onExit: S => String) {
val enabled = settings.debug.value
@inline final def apply[T](entity: S)(body: => T): T = {
diff --git a/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala b/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala
index be218fcb02..14c8d85836 100644
--- a/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala
@@ -8,7 +8,6 @@ package typechecker
import symtab.Flags._
import scala.collection.mutable
-import scala.ref.WeakReference
import scala.reflect.ClassTag
/**
@@ -42,8 +41,6 @@ trait NamesDefaults { self: Analyzer =>
blockTyper: Typer
) { }
- val noApplyInfo = NamedApplyInfo(None, Nil, Nil, null)
-
def nameOf(arg: Tree) = arg match {
case AssignOrNamedArg(Ident(name), rhs) => Some(name)
case _ => None
@@ -164,14 +161,14 @@ trait NamesDefaults { self: Analyzer =>
// never used for constructor calls, they always have a stable qualifier
def blockWithQualifier(qual: Tree, selected: Name) = {
- val sym = blockTyper.context.owner.newValue(unit.freshTermName("qual$"), qual.pos) setInfo qual.tpe
+ val sym = blockTyper.context.owner.newValue(unit.freshTermName("qual$"), qual.pos, newFlags = ARTIFACT) setInfo qual.tpe
blockTyper.context.scope enter sym
val vd = atPos(sym.pos)(ValDef(sym, qual) setType NoType)
// it stays in Vegas: SI-5720, SI-5727
qual changeOwner (blockTyper.context.owner -> sym)
val newQual = atPos(qual.pos.focus)(blockTyper.typedQualifier(Ident(sym.name)))
- var baseFunTransformed = atPos(baseFun.pos.makeTransparent) {
+ val baseFunTransformed = atPos(baseFun.pos.makeTransparent) {
// setSymbol below is important because the 'selected' function might be overloaded. by
// assigning the correct method symbol, typedSelect will just assign the type. the reason
// to still call 'typed' is to correctly infer singleton types, SI-5259.
@@ -281,7 +278,7 @@ trait NamesDefaults { self: Analyzer =>
}
else arg.tpe
).widen // have to widen or types inferred from literal defaults will be singletons
- val s = context.owner.newValue(unit.freshTermName("x$"), arg.pos) setInfo (
+ val s = context.owner.newValue(unit.freshTermName("x$"), arg.pos, newFlags = ARTIFACT) setInfo (
if (byName) functionType(Nil, argTpe) else argTpe
)
(context.scope.enter(s), byName, repeated)
@@ -319,7 +316,7 @@ trait NamesDefaults { self: Analyzer =>
assert(isNamedApplyBlock(transformedFun), transformedFun)
val NamedApplyInfo(qual, targs, vargss, blockTyper) =
context.namedApplyBlockInfo.get._2
- val existingBlock @ Block(stats, funOnly) = transformedFun
+ val Block(stats, funOnly) = transformedFun
// type the application without names; put the arguments in definition-site order
val typedApp = doTypedApply(tree, funOnly, reorderArgs(namelessArgs, argPos), mode, pt)
diff --git a/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala b/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala
index fa8aff5cdd..dba2f25e32 100644
--- a/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala
@@ -37,13 +37,11 @@ import scala.reflect.internal.Types
* - recover exhaustivity/unreachability of user-defined extractors by partitioning the types they match on using an HList or similar type-level structure
*/
trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL { // self: Analyzer =>
- import Statistics._
import PatternMatchingStats._
val global: Global // need to repeat here because otherwise last mixin defines global as
// SymbolTable. If we had DOT this would not be an issue
import global._ // the global environment
- import definitions._ // standard classes and methods
val phaseName: String = "patmat"
@@ -70,7 +68,7 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
}
def newTransformer(unit: CompilationUnit): Transformer =
- if (opt.virtPatmat) new MatchTransformer(unit)
+ if (!settings.XoldPatmat.value) new MatchTransformer(unit)
else noopTransformer
// duplicated from CPSUtils (avoid dependency from compiler -> cps plugin...)
@@ -192,7 +190,6 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
trait MatchTranslation extends MatchMonadInterface { self: TreeMakers with CodegenCore =>
import typer.{typed, context, silent, reallyExists}
- // import typer.infer.containsUnchecked
// Why is it so difficult to say "here's a name and a context, give me any
// matching symbol in scope" ? I am sure this code is wrong, but attempts to
@@ -274,7 +271,9 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
// we don't transform after uncurry
// (that would require more sophistication when generating trees,
// and the only place that emits Matches after typers is for exception handling anyway)
- if(phase.id >= currentRun.uncurryPhase.id) debugwarn("running translateMatch at "+ phase +" on "+ selector +" match "+ cases)
+ if (phase.id >= currentRun.uncurryPhase.id)
+ devWarning(s"running translateMatch past uncurry (at $phase) on $selector match $cases")
+
patmatDebug("translating "+ cases.mkString("{", "\n", "}"))
val start = if (Statistics.canEnable) Statistics.startTimer(patmatNanos) else null
@@ -294,8 +293,6 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
// pt is the skolemized version
val pt = repeatedToSeq(ptUnCPS)
- // val packedPt = repeatedToSeq(typer.packedType(match_, context.owner))
-
// the alternative to attaching the default case override would be to simply
// append the default to the list of cases and suppress the unreachable case error that may arise (once we detect that...)
val matchFailGenOverride = match_.attachments.get[DefaultOverrideMatchAttachment].map{case DefaultOverrideMatchAttachment(default) => ((scrut: Tree) => default)}
@@ -560,54 +557,55 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
def fromCaseClass(fun: Tree, args: List[Tree]): Option[ExtractorCall] = Some(new ExtractorCallProd(fun, args))
// THE PRINCIPLED SLOW PATH -- NOT USED
+ // !!! Use it, test it, or delete it, else it is unlikely to be an asset.
// generate a call to the (synthetically generated) extractor of a case class
// NOTE: it's an apply, not a select, since in general an extractor call may have multiple argument lists (including an implicit one)
// that we need to preserve, so we supply the scrutinee as Ident(nme.SELECTOR_DUMMY),
// and replace that dummy by a reference to the actual binder in translateExtractorPattern
- def fromCaseClassUnapply(fun: Tree, args: List[Tree]): Option[ExtractorCall] = {
- // TODO: can we rework the typer so we don't have to do all this twice?
- // undo rewrite performed in (5) of adapt
- val orig = fun match {case tpt: TypeTree => tpt.original case _ => fun}
- val origSym = orig.symbol
- val extractor = unapplyMember(origSym.filter(sym => reallyExists(unapplyMember(sym.tpe))).tpe)
-
- if((fun.tpe eq null) || fun.tpe.isError || (extractor eq NoSymbol)) {
- None
- } else {
- // this is a tricky balance: pos/t602.scala, pos/sudoku.scala, run/virtpatmat_alts.scala must all be happy
- // bypass typing at own risk: val extractorCall = Select(orig, extractor) setType caseClassApplyToUnapplyTp(fun.tpe)
- // can't always infer type arguments (pos/t602):
- /* case class Span[K <: Ordered[K]](low: Option[K]) {
- override def equals(x: Any): Boolean = x match {
- case Span((low0 @ _)) if low0 equals low => true
- }
- }*/
- // so... leave undetermined type params floating around if we have to
- // (if we don't infer types, uninstantiated type params show up later: pos/sudoku.scala)
- // (see also run/virtpatmat_alts.scala)
- val savedUndets = context.undetparams
- val extractorCall = try {
- context.undetparams = Nil
- silent(_.typed(Apply(Select(orig, extractor), List(Ident(nme.SELECTOR_DUMMY) setType fun.tpe.finalResultType)), EXPRmode, WildcardType), reportAmbiguousErrors = false) match {
- case SilentResultValue(extractorCall) => extractorCall // if !extractorCall.containsError()
- case _ =>
- // this fails to resolve overloading properly...
- // Apply(typedOperator(Select(orig, extractor)), List(Ident(nme.SELECTOR_DUMMY))) // no need to set the type of the dummy arg, it will be replaced anyway
-
- // patmatDebug("funtpe after = "+ fun.tpe.finalResultType)
- // patmatDebug("orig: "+(orig, orig.tpe))
- val tgt = typed(orig, EXPRmode | QUALmode | POLYmode, HasMember(extractor.name)) // can't specify fun.tpe.finalResultType as the type for the extractor's arg,
- // as it may have been inferred incorrectly (see t602, where it's com.mosol.sl.Span[Any], instead of com.mosol.sl.Span[?K])
- // patmatDebug("tgt = "+ (tgt, tgt.tpe))
- val oper = typed(Select(tgt, extractor.name), EXPRmode | FUNmode | POLYmode | TAPPmode, WildcardType)
- // patmatDebug("oper: "+ (oper, oper.tpe))
- Apply(oper, List(Ident(nme.SELECTOR_DUMMY))) // no need to set the type of the dummy arg, it will be replaced anyway
- }
- } finally context.undetparams = savedUndets
-
- Some(this(extractorCall, args)) // TODO: simplify spliceApply?
- }
- }
+ // def fromCaseClassUnapply(fun: Tree, args: List[Tree]): Option[ExtractorCall] = {
+ // // TODO: can we rework the typer so we don't have to do all this twice?
+ // // undo rewrite performed in (5) of adapt
+ // val orig = fun match {case tpt: TypeTree => tpt.original case _ => fun}
+ // val origSym = orig.symbol
+ // val extractor = unapplyMember(origSym.filter(sym => reallyExists(unapplyMember(sym.tpe))).tpe)
+
+ // if((fun.tpe eq null) || fun.tpe.isError || (extractor eq NoSymbol)) {
+ // None
+ // } else {
+ // // this is a tricky balance: pos/t602.scala, pos/sudoku.scala, run/virtpatmat_alts.scala must all be happy
+ // // bypass typing at own risk: val extractorCall = Select(orig, extractor) setType caseClassApplyToUnapplyTp(fun.tpe)
+ // // can't always infer type arguments (pos/t602):
+ // /* case class Span[K <: Ordered[K]](low: Option[K]) {
+ // override def equals(x: Any): Boolean = x match {
+ // case Span((low0 @ _)) if low0 equals low => true
+ // }
+ // }*/
+ // // so... leave undetermined type params floating around if we have to
+ // // (if we don't infer types, uninstantiated type params show up later: pos/sudoku.scala)
+ // // (see also run/virtpatmat_alts.scala)
+ // val savedUndets = context.undetparams
+ // val extractorCall = try {
+ // context.undetparams = Nil
+ // silent(_.typed(Apply(Select(orig, extractor), List(Ident(nme.SELECTOR_DUMMY) setType fun.tpe.finalResultType)), EXPRmode, WildcardType), reportAmbiguousErrors = false) match {
+ // case SilentResultValue(extractorCall) => extractorCall // if !extractorCall.containsError()
+ // case _ =>
+ // // this fails to resolve overloading properly...
+ // // Apply(typedOperator(Select(orig, extractor)), List(Ident(nme.SELECTOR_DUMMY))) // no need to set the type of the dummy arg, it will be replaced anyway
+
+ // // patmatDebug("funtpe after = "+ fun.tpe.finalResultType)
+ // // patmatDebug("orig: "+(orig, orig.tpe))
+ // val tgt = typed(orig, EXPRmode | QUALmode | POLYmode, HasMember(extractor.name)) // can't specify fun.tpe.finalResultType as the type for the extractor's arg,
+ // // as it may have been inferred incorrectly (see t602, where it's com.mosol.sl.Span[Any], instead of com.mosol.sl.Span[?K])
+ // // patmatDebug("tgt = "+ (tgt, tgt.tpe))
+ // val oper = typed(Select(tgt, extractor.name), EXPRmode | FUNmode | POLYmode | TAPPmode, WildcardType)
+ // // patmatDebug("oper: "+ (oper, oper.tpe))
+ // Apply(oper, List(Ident(nme.SELECTOR_DUMMY))) // no need to set the type of the dummy arg, it will be replaced anyway
+ // }
+ // } finally context.undetparams = savedUndets
+
+ // Some(this(extractorCall, args)) // TODO: simplify spliceApply?
+ // }
+ // }
}
abstract class ExtractorCall(val args: List[Tree]) {
@@ -1148,7 +1146,7 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
val expectedOuter = expectedTp.prefix match {
case ThisType(clazz) => THIS(clazz)
case pre if pre != NoType => REF(pre.prefix, pre.termSymbol)
- case _ => TRUE_typed // fallback for SI-6183
+ case _ => TRUE // fallback for SI-6183
}
// ExplicitOuter replaces `Select(q, outerSym) OBJ_EQ expectedPrefix` by `Select(q, outerAccessor(outerSym.owner)) OBJ_EQ expectedPrefix`
@@ -1280,10 +1278,10 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
// one alternative may still generate multiple trees (e.g., an extractor call + equality test)
// (for now,) alternatives may not bind variables (except wildcards), so we don't care about the final substitution built internally by makeTreeMakers
val combinedAlts = altss map (altTreeMakers =>
- ((casegen: Casegen) => combineExtractors(altTreeMakers :+ TrivialTreeMaker(casegen.one(TRUE_typed)))(casegen))
+ ((casegen: Casegen) => combineExtractors(altTreeMakers :+ TrivialTreeMaker(casegen.one(TRUE)))(casegen))
)
- val findAltMatcher = codegenAlt.matcher(EmptyTree, NoSymbol, BooleanClass.tpe)(combinedAlts, Some(x => FALSE_typed))
+ val findAltMatcher = codegenAlt.matcher(EmptyTree, NoSymbol, BooleanClass.tpe)(combinedAlts, Some(x => FALSE))
codegenAlt.ifThenElseZero(findAltMatcher, substitution(next))
}
}
@@ -1426,10 +1424,8 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
// local / context-free
def _asInstanceOf(b: Symbol, tp: Type): Tree
- def _asInstanceOf(t: Tree, tp: Type): Tree
def _equals(checker: Tree, binder: Symbol): Tree
def _isInstanceOf(b: Symbol, tp: Type): Tree
- def and(a: Tree, b: Tree): Tree
def drop(tgt: Tree)(n: Int): Tree
def index(tgt: Tree)(i: Int): Tree
def mkZero(tp: Type): Tree
@@ -1443,7 +1439,7 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
def flatMap(prev: Tree, b: Symbol, next: Tree): Tree
def flatMapCond(cond: Tree, res: Tree, nextBinder: Symbol, next: Tree): Tree
def flatMapGuard(cond: Tree, next: Tree): Tree
- def ifThenElseZero(c: Tree, then: Tree): Tree = IF (c) THEN then ELSE zero
+ def ifThenElseZero(c: Tree, thenp: Tree): Tree = IF (c) THEN thenp ELSE zero
protected def zero: Tree
}
@@ -1471,12 +1467,10 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
abstract class CommonCodegen extends AbsCodegen { import CODE._
def fun(arg: Symbol, body: Tree): Tree = Function(List(ValDef(arg)), body)
- def genTypeApply(tfun: Tree, args: Type*): Tree = if(args contains NoType) tfun else TypeApply(tfun, args.toList map TypeTree)
def tupleSel(binder: Symbol)(i: Int): Tree = (REF(binder) DOT nme.productAccessorName(i)) // make tree that accesses the i'th component of the tuple referenced by binder
def index(tgt: Tree)(i: Int): Tree = tgt APPLY (LIT(i))
def drop(tgt: Tree)(n: Int): Tree = (tgt DOT vpmName.drop) (LIT(n))
def _equals(checker: Tree, binder: Symbol): Tree = checker MEMBER_== REF(binder) // NOTE: checker must be the target of the ==, that's the patmat semantics for ya
- def and(a: Tree, b: Tree): Tree = a AND b
// drop annotations generated by CPS plugin etc, since its annotationchecker rejects T @cps[U] <: Any
// let's assume for now annotations don't affect casts, drop them there, and bring them back using the outer Typed tree
@@ -1484,10 +1478,8 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
Typed(gen.mkAsInstanceOf(t, tp.withoutAnnotations, true, false), TypeTree() setType tp)
// the force is needed mainly to deal with the GADT typing hack (we can't detect it otherwise as tp nor pt need contain an abstract type, we're just casting wildly)
- def _asInstanceOf(t: Tree, tp: Type): Tree = if (t.tpe != NoType && t.isTyped && typesConform(t.tpe, tp)) t else mkCast(t, tp)
def _asInstanceOf(b: Symbol, tp: Type): Tree = if (typesConform(b.info, tp)) REF(b) else mkCast(REF(b), tp)
def _isInstanceOf(b: Symbol, tp: Type): Tree = gen.mkIsInstanceOf(REF(b), tp.withoutAnnotations, true, false)
- // if (typesConform(b.info, tpX)) { patmatDebug("warning: emitted spurious isInstanceOf: "+(b, tp)); TRUE }
// duplicated out of frustration with cast generation
def mkZero(tp: Type): Tree = {
@@ -1536,7 +1528,7 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
// __match.zero
protected def zero: Tree = _match(vpmName.zero)
// __match.guard(`c`, `then`)
- def guard(c: Tree, then: Tree): Tree = _match(vpmName.guard) APPLY (c, then)
+ def guard(c: Tree, thenp: Tree): Tree = _match(vpmName.guard) APPLY (c, thenp)
//// methods in the monad instance -- used directly in translation
// `prev`.flatMap(`b` => `next`)
@@ -1829,9 +1821,9 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
def toString(x: AnyRef) = if (x eq null) "" else x.toString
if (cols.isEmpty || cols.tails.isEmpty) cols map toString
else {
- val (colStrs, colLens) = cols map {c => val s = toString(c); (s, s.length)} unzip
- val maxLen = max(colLens)
- val avgLen = colLens.sum/colLens.length
+ val colLens = cols map (c => toString(c).length)
+ val maxLen = max(colLens)
+ val avgLen = colLens.sum/colLens.length
val goalLen = maxLen min avgLen*2
def pad(s: String) = {
val toAdd = ((goalLen - s.length) max 0) + 2
@@ -2065,7 +2057,7 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
// throws an AnalysisBudget.Exception when the prop results in a CNF that's too big
// TODO: be smarter/more efficient about this (http://lara.epfl.ch/w/sav09:tseitin_s_encoding)
def eqFreePropToSolvable(p: Prop): Formula = {
- def negationNormalFormNot(p: Prop, budget: Int = AnalysisBudget.max): Prop =
+ def negationNormalFormNot(p: Prop, budget: Int): Prop =
if (budget <= 0) throw AnalysisBudget.exceeded
else p match {
case And(a, b) => Or(negationNormalFormNot(a, budget - 1), negationNormalFormNot(b, budget - 1))
@@ -2274,9 +2266,9 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
private[this] val id: Int = Var.nextId
// private[this] var canModify: Option[Array[StackTraceElement]] = None
- private[this] def ensureCanModify = {} //if (canModify.nonEmpty) patmatDebug("BUG!"+ this +" modified after having been observed: "+ canModify.get.mkString("\n"))
+ private[this] def ensureCanModify() = {} //if (canModify.nonEmpty) patmatDebug("BUG!"+ this +" modified after having been observed: "+ canModify.get.mkString("\n"))
- private[this] def observed = {} //canModify = Some(Thread.currentThread.getStackTrace)
+ private[this] def observed() = {} //canModify = Some(Thread.currentThread.getStackTrace)
// don't access until all potential equalities have been registered using registerEquality
private[this] val symForEqualsTo = new scala.collection.mutable.HashMap[Const, Sym]
@@ -2429,7 +2421,13 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
private lazy val equalitySyms = {observed; symForEqualsTo.values.toList}
// don't call until all equalities have been registered and registerNull has been called (if needed)
- def describe = toString + ": " + staticTp + domain.map(_.mkString(" ::= ", " | ", "// "+ symForEqualsTo.keys)).getOrElse(symForEqualsTo.keys.mkString(" ::= ", " | ", " | ...")) + " // = " + path
+ def describe = {
+ def domain_s = domain match {
+ case Some(d) => d mkString (" ::= ", " | ", "// "+ symForEqualsTo.keys)
+ case _ => symForEqualsTo.keys mkString (" ::= ", " | ", " | ...")
+ }
+ s"$this: ${staticTp}${domain_s} // = $path"
+ }
override def toString = "V"+ id
}
@@ -2515,7 +2513,7 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
// corresponds to a type test that does not imply any value-equality (well, except for outer checks, which we don't model yet)
sealed class TypeConst(val tp: Type) extends Const {
assert(!(tp =:= NullTp))
- private[this] val id: Int = Const.nextTypeId
+ /*private[this] val id: Int = */ Const.nextTypeId
val wideTp = widenToClass(tp)
def isValue = false
@@ -2553,7 +2551,7 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
}
val toString =
- if (p.hasSymbol && p.symbol.isStable) p.symbol.name.toString // tp.toString
+ if (p.hasSymbolField && p.symbol.isStable) p.symbol.name.toString // tp.toString
else p.toString //+"#"+ id
Const.unique(narrowTp, new ValueConst(narrowTp, checkableType(wideTp), toString)) // must make wide type checkable so that it is comparable to types from TypeConst
@@ -2563,7 +2561,7 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
sealed class ValueConst(val tp: Type, val wideTp: Type, override val toString: String) extends Const {
// patmatDebug("VC"+(tp, wideTp, toString))
assert(!(tp =:= NullTp)) // TODO: assert(!tp.isStable)
- private[this] val id: Int = Const.nextValueId
+ /*private[this] val id: Int = */Const.nextValueId
def isValue = true
}
@@ -2789,7 +2787,6 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
// when does the match fail?
val matchFails = Not(\/(symbolicCases))
- val vars = gatherVariables(matchFails)
// debug output:
patmatDebug("analysing:")
@@ -2887,8 +2884,6 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
v +"(="+ v.path +": "+ v.staticTpCheckable +") "+ assignment
}.mkString("\n")
- def modelString(model: Model) = varAssignmentString(modelToVarAssignment(model))
-
// return constructor call when the model is a true counter example
// (the variables don't take into account type information derived from other variables,
// so, naively, you might try to construct a counter example like _ :: Nil(_ :: _, _ :: _),
@@ -3246,7 +3241,7 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
}
}
- private val defaultLabel: Symbol = newSynthCaseLabel("default")
+ private val defaultLabel: Symbol = newSynthCaseLabel("default")
/** Collapse guarded cases that switch on the same constant (the last case may be unguarded).
*
@@ -3546,7 +3541,6 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
// for the catch-cases in a try/catch
private object typeSwitchMaker extends SwitchMaker {
val unchecked = false
- def switchableTpe(tp: Type) = true
val alternativesSupported = false // TODO: needs either back-end support of flattening of alternatives during typers
val canJump = false
@@ -3592,11 +3586,6 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
trait OptimizedCodegen extends CodegenCore with TypedSubstitution with OptimizedMatchMonadInterface {
override def codegen: AbsCodegen = optimizedCodegen
- // trait AbsOptimizedCodegen extends AbsCodegen {
- // def flatMapCondStored(cond: Tree, condSym: Symbol, res: Tree, nextBinder: Symbol, next: Tree): Tree
- // }
- // def optimizedCodegen: AbsOptimizedCodegen
-
// when we know we're targetting Option, do some inlining the optimizer won't do
// for example, `o.flatMap(f)` becomes `if(o == None) None else f(o.get)`, similarly for orElse and guard
// this is a special instance of the advanced inlining optimization that takes a method call on
@@ -3693,7 +3682,7 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
def flatMapCondStored(cond: Tree, condSym: Symbol, res: Tree, nextBinder: Symbol, next: Tree): Tree =
ifThenElseZero(cond, BLOCK(
- condSym === TRUE_typed,
+ condSym === TRUE,
nextBinder === res,
next
))
diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
index 9bd3aa8fe5..12562fecf8 100644
--- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
@@ -60,23 +60,8 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans
super.transformInfo(sym, tp)
}
- val toJavaRepeatedParam = new TypeMap {
- def apply(tp: Type) = tp match {
- case TypeRef(pre, RepeatedParamClass, args) =>
- typeRef(pre, JavaRepeatedParamClass, args)
- case _ =>
- mapOver(tp)
- }
- }
-
- val toScalaRepeatedParam = new TypeMap {
- def apply(tp: Type): Type = tp match {
- case TypeRef(pre, JavaRepeatedParamClass, args) =>
- typeRef(pre, RepeatedParamClass, args)
- case _ =>
- mapOver(tp)
- }
- }
+ val toJavaRepeatedParam = new SubstSymMap(RepeatedParamClass -> JavaRepeatedParamClass)
+ val toScalaRepeatedParam = new SubstSymMap(JavaRepeatedParamClass -> RepeatedParamClass)
def accessFlagsToString(sym: Symbol) = flagsToString(
sym getFlag (PRIVATE | PROTECTED),
@@ -145,7 +130,17 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans
}
}
}
- if (settings.lint.value) {
+
+ // Check for doomed attempt to overload applyDynamic
+ if (clazz isSubClass DynamicClass) {
+ clazz.info member nme.applyDynamic match {
+ case sym if sym.isOverloaded => unit.error(sym.pos, "implementation restriction: applyDynamic cannot be overloaded")
+ case _ =>
+ }
+ }
+
+ // This has become noisy with implicit classes.
+ if (settings.lint.value && settings.developer.value) {
clazz.info.decls filter (x => x.isImplicit && x.typeParams.nonEmpty) foreach { sym =>
val alts = clazz.info.decl(sym.name).alternatives
if (alts.size > 1)
@@ -156,27 +151,22 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans
// Override checking ------------------------------------------------------------
- def isJavaVarargsAncestor(clazz: Symbol) = (
- clazz.isClass
- && clazz.isJavaDefined
- && (clazz.info.nonPrivateDecls exists isJavaVarArgsMethod)
- )
-
/** Add bridges for vararg methods that extend Java vararg methods
*/
def addVarargBridges(clazz: Symbol): List[Tree] = {
// This is quite expensive, so attempt to skip it completely.
// Insist there at least be a java-defined ancestor which
// defines a varargs method. TODO: Find a cheaper way to exclude.
- if (clazz.thisType.baseClasses exists isJavaVarargsAncestor) {
+ if (inheritsJavaVarArgsMethod(clazz)) {
log("Found java varargs ancestor in " + clazz.fullLocationString + ".")
val self = clazz.thisType
val bridges = new ListBuffer[Tree]
def varargBridge(member: Symbol, bridgetpe: Type): Tree = {
- log("Generating varargs bridge for " + member.fullLocationString + " of type " + bridgetpe)
+ log(s"Generating varargs bridge for ${member.fullLocationString} of type $bridgetpe")
- val bridge = member.cloneSymbolImpl(clazz, member.flags | VBRIDGE) setPos clazz.pos
+ val newFlags = (member.flags | VBRIDGE | ARTIFACT) & ~PRIVATE
+ val bridge = member.cloneSymbolImpl(clazz, newFlags) setPos clazz.pos
bridge.setInfo(bridgetpe.cloneInfo(bridge))
clazz.info.decls enter bridge
@@ -189,26 +179,35 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans
localTyper typed DefDef(bridge, body)
}
- // For all concrete non-private members that have a (Scala) repeated parameter:
- // compute the corresponding method type `jtpe` with a Java repeated parameter
+ // For all concrete non-private members (but: see below) that have a (Scala) repeated
+ // parameter: compute the corresponding method type `jtpe` with a Java repeated parameter
// if a method with type `jtpe` exists and that method is not a varargs bridge
// then create a varargs bridge of type `jtpe` that forwards to the
// member method with the Scala vararg type.
- for (member <- clazz.info.nonPrivateMembers) {
+ //
+ // @PP: Can't call nonPrivateMembers because we will miss refinement members,
+ // which have been marked private. See SI-4729.
+ for (member <- nonTrivialMembers(clazz)) {
+ log(s"Considering $member for java varargs bridge in $clazz")
if (!member.isDeferred && member.isMethod && hasRepeatedParam(member.info)) {
val inherited = clazz.info.nonPrivateMemberAdmitting(member.name, VBRIDGE)
+
// Delaying calling memberType as long as possible
if (inherited ne NoSymbol) {
- val jtpe = toJavaRepeatedParam(self.memberType(member))
+ val jtpe = toJavaRepeatedParam(self memberType member)
// this is a bit tortuous: we look for non-private members or bridges
// if we find a bridge everything is OK. If we find another member,
// we need to create a bridge
- if (inherited filter (sym => (self.memberType(sym) matches jtpe) && !(sym hasFlag VBRIDGE)) exists)
+ val inherited1 = inherited filter (sym => !(sym hasFlag VBRIDGE) && (self memberType sym matches jtpe))
+ if (inherited1.exists)
bridges += varargBridge(member, jtpe)
}
}
}
+ if (bridges.size > 0)
+ log(s"Adding ${bridges.size} bridges for methods extending java varargs.")
+
bridges.toList
}
else Nil
@@ -248,7 +247,7 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans
case class MixinOverrideError(member: Symbol, msg: String)
- var mixinOverrideErrors = new ListBuffer[MixinOverrideError]()
+ val mixinOverrideErrors = new ListBuffer[MixinOverrideError]()
def printMixinOverrideErrors() {
mixinOverrideErrors.toList match {
@@ -556,13 +555,13 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans
def uncurryAndErase(tp: Type) = erasure.erasure(sym)(uncurry.transformInfo(sym, tp))
val tp1 = uncurryAndErase(clazz.thisType.memberType(sym))
val tp2 = uncurryAndErase(clazz.thisType.memberType(other))
- afterErasure(tp1 matches tp2)
+ exitingErasure(tp1 matches tp2)
})
def ignoreDeferred(member: Symbol) = (
(member.isAbstractType && !member.isFBounded) || (
member.isJavaDefined &&
- // the test requires afterErasure so shouldn't be
+ // the test requires exitingErasure so shouldn't be
// done if the compiler has no erasure phase available
(currentRun.erasurePhase == NoPhase || javaErasedOverridingSym(member) != NoSymbol)
)
@@ -845,7 +844,6 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans
// Variance Checking --------------------------------------------------------
- private val ContraVariance = -1
private val NoVariance = 0
private val CoVariance = 1
private val AnyVariance = 2
@@ -905,13 +903,14 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans
* the type occurs itself at variance position given by `variance`
*/
def validateVariance(tp: Type, variance: Int): Unit = tp match {
- case ErrorType => ;
- case WildcardType => ;
- case NoType => ;
- case NoPrefix => ;
- case ThisType(_) => ;
- case ConstantType(_) => ;
- // case DeBruijnIndex(_, _) => ;
+ case ErrorType =>
+ case WildcardType =>
+ case BoundedWildcardType(bounds) =>
+ validateVariance(bounds, variance)
+ case NoType =>
+ case NoPrefix =>
+ case ThisType(_) =>
+ case ConstantType(_) =>
case SingleType(pre, sym) =>
validateVariance(pre, variance)
case TypeRef(pre, sym, args) =>
@@ -1062,6 +1061,12 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans
def apply(tp: Type) = mapOver(tp).normalize
}
+ def checkImplicitViewOptionApply(pos: Position, fn: Tree, args: List[Tree]): Unit = if (settings.lint.value) (fn, args) match {
+ case (tap@TypeApply(fun, targs), List(view: ApplyImplicitView)) if fun.symbol == Option_apply =>
+ unit.warning(pos, s"Suspicious application of an implicit view (${view.fun}) in the argument to Option.apply.") // SI-6567
+ case _ =>
+ }
+
def checkSensible(pos: Position, fn: Tree, args: List[Tree]) = fn match {
case Select(qual, name @ (nme.EQ | nme.NE | nme.eq | nme.ne)) if args.length == 1 =>
def isReferenceOp = name == nme.eq || name == nme.ne
@@ -1111,15 +1116,12 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans
def isUnit(s: Symbol) = unboxedValueClass(s) == UnitClass
def isNumeric(s: Symbol) = isNumericValueClass(unboxedValueClass(s)) || isAnyNumber(s)
def isScalaNumber(s: Symbol) = s isSubClass ScalaNumberClass
- // test is behind a platform guard
- def isJavaNumber(s: Symbol) = !forMSIL && (s isSubClass JavaNumberClass)
+ def isJavaNumber(s: Symbol) = s isSubClass JavaNumberClass
// includes java.lang.Number if appropriate [SI-5779]
def isAnyNumber(s: Symbol) = isScalaNumber(s) || isJavaNumber(s)
def isMaybeAnyValue(s: Symbol) = isPrimitiveValueClass(unboxedValueClass(s)) || isMaybeValue(s)
// used to short-circuit unrelatedTypes check if both sides are special
def isSpecial(s: Symbol) = isMaybeAnyValue(s) || isAnyNumber(s)
- // unused
- def possibleNumericCount = onSyms(_ filter (x => isNumeric(x) || isMaybeValue(x)) size)
val nullCount = onSyms(_ filter (_ == NullClass) size)
def nonSensibleWarning(what: String, alwaysEqual: Boolean) = {
@@ -1157,7 +1159,7 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans
nonSensiblyNeq()
}
else if (isNumeric(receiver)) {
- if (!isNumeric(actual) && !forMSIL)
+ if (!isNumeric(actual))
if (isUnit(actual) || isBoolean(actual) || !isMaybeValue(actual)) // 5 == "abc"
nonSensiblyNeq()
}
@@ -1230,7 +1232,7 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans
/* Convert a reference to a case factory of type `tpe` to a new of the class it produces. */
def toConstructor(pos: Position, tpe: Type): Tree = {
- var rtpe = tpe.finalResultType
+ val rtpe = tpe.finalResultType
assert(rtpe.typeSymbol hasFlag CASE, tpe);
localTyper.typedOperator {
atPos(pos) {
@@ -1249,57 +1251,61 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans
finally popLevel()
}
- /** Eliminate ModuleDefs.
- * - A top level object is replaced with their module class.
- * - An inner object is transformed into a module var, created on first access.
+ /** Eliminate ModuleDefs. In all cases the ModuleDef (carrying a module symbol) is
+ * replaced with a ClassDef (carrying the corresponding module class symbol) with additional
+ * trees created as follows:
*
- * In both cases, this transformation returns the list of replacement trees:
- * - Top level: the module class accessor definition
- * - Inner: a class definition, declaration of module var, and module var accessor
+ * 1) A statically reachable object (either top-level or nested only in objects) receives
+ * no additional trees.
+ * 2) An inner object which matches an existing member (e.g. implements an interface)
+ * receives an accessor DefDef to implement the interface.
+ * 3) An inner object otherwise receives a private ValDef which declares a module var
+ * (the field which holds the module class - it has a name like Foo$module) and an
+ * accessor for that field. The instance is created lazily, on first access.
*/
- private def eliminateModuleDefs(tree: Tree): List[Tree] = {
- val ModuleDef(mods, name, impl) = tree
- val sym = tree.symbol
- val classSym = sym.moduleClass
- val cdef = ClassDef(mods | MODULE, name.toTypeName, Nil, impl) setSymbol classSym setType NoType
-
- def findOrCreateModuleVar() = localTyper.typedPos(tree.pos) {
- // See SI-5012, SI-6712.
+ private def eliminateModuleDefs(moduleDef: Tree): List[Tree] = exitingRefchecks {
+ val ModuleDef(mods, name, impl) = moduleDef
+ val module = moduleDef.symbol
+ val site = module.owner
+ val moduleName = module.name.toTermName
+ // The typer doesn't take kindly to seeing this ClassDef; we have to
+ // set NoType so it will be ignored.
+ val cdef = ClassDef(module.moduleClass, impl) setType NoType
+
+ // Create the module var unless the immediate owner is a class and
+ // the module var already exists there. See SI-5012, SI-6712.
+ def findOrCreateModuleVar() = {
val vsym = (
- if (sym.owner.isTerm) NoSymbol
- else sym.enclClass.info.decl(nme.moduleVarName(sym.name.toTermName))
+ if (site.isTerm) NoSymbol
+ else site.info decl nme.moduleVarName(moduleName)
)
- // In case we are dealing with local symbol then we already have
- // to correct error with forward reference
- if (vsym == NoSymbol) gen.mkModuleVarDef(sym)
- else ValDef(vsym)
+ vsym orElse (site newModuleVarSymbol module)
}
- def createStaticModuleAccessor() = afterRefchecks {
- val method = (
- sym.owner.newMethod(sym.name.toTermName, sym.pos, (sym.flags | STABLE) & ~MODULE)
- setInfoAndEnter NullaryMethodType(sym.moduleClass.tpe)
- )
- localTyper.typedPos(tree.pos)(gen.mkModuleAccessDef(method, sym))
+ def newInnerObject() = {
+ // Create the module var unless it is already in the module owner's scope.
+ // The lookup is on module.enclClass and not module.owner lest there be a
+ // nullary method between us and the class; see SI-5012.
+ val moduleVar = findOrCreateModuleVar()
+ val rhs = gen.newModule(module, moduleVar.tpe)
+ val body = if (site.isTrait) rhs else gen.mkAssignAndReturn(moduleVar, rhs)
+ val accessor = DefDef(module, body.changeOwner(moduleVar -> module))
+
+ ValDef(moduleVar) :: accessor :: Nil
}
- def createInnerModuleAccessor(vdef: Tree) = List(
- vdef,
- localTyper.typedPos(tree.pos) {
- val vsym = vdef.symbol
- afterRefchecks {
- val rhs = gen.newModule(sym, vsym.tpe)
- val body = if (sym.owner.isTrait) rhs else gen.mkAssignAndReturn(vsym, rhs)
- DefDef(sym, body.changeOwner(vsym -> sym))
- }
- }
- )
- transformTrees(cdef :: {
- if (!sym.isStatic)
- createInnerModuleAccessor(findOrCreateModuleVar)
- else if (sym.isOverridingSymbol)
- List(createStaticModuleAccessor())
+ def matchingInnerObject() = {
+ val newFlags = (module.flags | STABLE) & ~MODULE
+ val newInfo = NullaryMethodType(module.moduleClass.tpe)
+ val accessor = site.newMethod(moduleName, module.pos, newFlags) setInfoAndEnter newInfo
+
+ DefDef(accessor, Select(This(site), module)) :: Nil
+ }
+ val newTrees = cdef :: (
+ if (module.isStatic)
+ if (module.isOverridingSymbol) matchingInnerObject() else Nil
else
- Nil
- })
+ newInnerObject()
+ )
+ transformTrees(newTrees map localTyper.typedPos(moduleDef.pos))
}
def transformStat(tree: Tree, index: Int): List[Tree] = tree match {
@@ -1313,7 +1319,7 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans
}
case ModuleDef(_, _, _) => eliminateModuleDefs(tree)
case ValDef(_, _, _, _) =>
- val tree1 @ ValDef(_, _, _, rhs) = transform(tree) // important to do before forward reference check
+ val tree1 = transform(tree) // important to do before forward reference check
if (tree1.symbol.isLazy) tree1 :: Nil
else {
val lazySym = tree.symbol.lazyAccessorOrSelf
@@ -1467,8 +1473,11 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans
}
private def isRepeatedParamArg(tree: Tree) = currentApplication match {
case Apply(fn, args) =>
- !args.isEmpty && (args.last eq tree) &&
- fn.tpe.params.length == args.length && isRepeatedParamType(fn.tpe.params.last.tpe)
+ ( args.nonEmpty
+ && (args.last eq tree)
+ && (fn.tpe.params.length == args.length)
+ && isRepeatedParamType(fn.tpe.params.last.tpe)
+ )
case _ =>
false
}
@@ -1563,12 +1572,15 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans
case Apply(fn, args) =>
// sensicality should be subsumed by the unreachability/exhaustivity/irrefutability analyses in the pattern matcher
- if (!inPattern) checkSensible(tree.pos, fn, args)
+ if (!inPattern) {
+ checkImplicitViewOptionApply(tree.pos, fn, args)
+ checkSensible(tree.pos, fn, args)
+ }
currentApplication = tree
tree
}
private def transformSelect(tree: Select): Tree = {
- val Select(qual, name) = tree
+ val Select(qual, _) = tree
val sym = tree.symbol
/** Note: if a symbol has both @deprecated and @migration annotations and both
diff --git a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala
index fb8a111da1..0992cd7955 100644
--- a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala
@@ -60,8 +60,8 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT
val clazz = qual.symbol
val supername = nme.superName(name)
val superAcc = clazz.info.decl(supername).suchThat(_.alias == sym) orElse {
- debuglog("add super acc " + sym + sym.locationString + " to `" + clazz);//debug
- val acc = clazz.newMethod(supername, sel.pos, SUPERACCESSOR | PRIVATE) setAlias sym
+ debuglog(s"add super acc ${sym.fullLocationString} to $clazz")
+ val acc = clazz.newMethod(supername, sel.pos, SUPERACCESSOR | PRIVATE | ARTIFACT) setAlias sym
val tpe = clazz.thisType memberType sym match {
case t if sym.isModule && !sym.isMethod => NullaryMethodType(t)
case t => t
@@ -291,7 +291,8 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT
&& !sym.owner.isTrait
&& (sym.owner.enclosingPackageClass != currentClass.enclosingPackageClass)
&& (qual.symbol.info.member(sym.name) ne NoSymbol)
- && !needsProtectedAccessor(sym, tree.pos))
+ && !needsProtectedAccessor(sym, tree.pos)
+ )
if (shouldEnsureAccessor) {
log("Ensuring accessor for call to protected " + sym.fullLocationString + " from " + currentClass)
ensureAccessor(sel)
@@ -387,7 +388,7 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT
* typed.
*/
private def makeAccessor(tree: Select, targs: List[Tree]): Tree = {
- val Select(qual, name) = tree
+ val Select(qual, _) = tree
val sym = tree.symbol
val clazz = hostForAccessorOf(sym, currentClass)
@@ -412,7 +413,7 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT
}
val protAcc = clazz.info.decl(accName).suchThat(s => s == NoSymbol || s.tpe =:= accType(s)) orElse {
- val newAcc = clazz.newMethod(nme.protName(sym.originalName), tree.pos)
+ val newAcc = clazz.newMethod(nme.protName(sym.originalName), tree.pos, newFlags = ARTIFACT)
newAcc setInfoAndEnter accType(newAcc)
val code = DefDef(newAcc, {
@@ -423,7 +424,7 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT
args.foldLeft(base)(Apply(_, _))
})
- debuglog("" + code)
+ debuglog("created protected accessor: " + code)
storeAccessorDefinition(clazz, code)
newAcc
}
@@ -435,7 +436,7 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT
case _ => mkApply(TypeApply(selection, targs))
}
}
- debuglog("Replaced " + tree + " with " + res)
+ debuglog(s"Replaced $tree with $res")
if (hasArgs) localTyper.typedOperator(res) else localTyper.typed(res)
}
@@ -474,7 +475,7 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT
val accName = nme.protSetterName(field.originalName)
val protectedAccessor = clazz.info decl accName orElse {
- val protAcc = clazz.newMethod(accName, field.pos)
+ val protAcc = clazz.newMethod(accName, field.pos, newFlags = ARTIFACT)
val paramTypes = List(clazz.typeOfThis, field.tpe)
val params = protAcc newSyntheticValueParams paramTypes
val accessorType = MethodType(params, UnitClass.tpe)
@@ -506,9 +507,6 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT
def accessibleThroughSubclassing =
validCurrentOwner && clazz.thisSym.isSubClass(sym.owner) && !clazz.isTrait
- def packageAccessBoundry(sym: Symbol) =
- sym.accessBoundary(sym.enclosingPackageClass)
-
val isCandidate = (
sym.isProtected
&& sym.isJavaDefined
diff --git a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala
index 17e67e6429..07135c3af9 100644
--- a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala
@@ -6,9 +6,7 @@
package scala.tools.nsc
package typechecker
-import symtab.Flags
import symtab.Flags._
-import scala.collection.mutable
import scala.collection.mutable.ListBuffer
/** Synthetic method implementations for case classes and case objects.
@@ -97,7 +95,7 @@ trait SyntheticMethods extends ast.TreeDSL {
// like Tags and Arrays which are not robust and infer things
// which they shouldn't.
val accessorLub = (
- if (opt.experimental) {
+ if (settings.Xexperimental.value) {
global.weakLub(accessors map (_.tpe.finalResultType))._1 match {
case RefinedType(parents, decls) if !decls.isEmpty => intersectionType(parents)
case tp => tp
@@ -124,20 +122,11 @@ trait SyntheticMethods extends ast.TreeDSL {
(m0 ne meth) && !m0.isDeferred && !m0.isSynthetic && (m0.owner != AnyValClass) && (typeInClazz(m0) matches typeInClazz(meth))
}
}
- def readConstantValue[T](name: String, default: T = null.asInstanceOf[T]): T = {
- clazzMember(newTermName(name)).info match {
- case NullaryMethodType(ConstantType(Constant(value))) => value.asInstanceOf[T]
- case _ => default
- }
- }
def productIteratorMethod = {
createMethod(nme.productIterator, iteratorOfType(accessorLub))(_ =>
gen.mkMethodCall(ScalaRunTimeModule, nme.typedProductIterator, List(accessorLub), List(mkThis))
)
}
- def projectionMethod(accessor: Symbol, num: Int) = {
- createMethod(nme.productAccessorName(num), accessor.tpe.resultType)(_ => REF(accessor))
- }
/** Common code for productElement and (currently disabled) productElementName
*/
@@ -229,10 +218,15 @@ trait SyntheticMethods extends ast.TreeDSL {
/** The _1, _2, etc. methods to implement ProductN, disabled
* until we figure out how to introduce ProductN without cycles.
*/
- def productNMethods = {
+ /****
+ def productNMethods = {
val accs = accessors.toIndexedSeq
1 to arity map (num => productProj(arity, num) -> (() => projectionMethod(accs(num - 1), num)))
}
+ def projectionMethod(accessor: Symbol, num: Int) = {
+ createMethod(nme.productAccessorName(num), accessor.tpe.resultType)(_ => REF(accessor))
+ }
+ ****/
// methods for both classes and objects
def productMethods = {
@@ -370,7 +364,6 @@ trait SyntheticMethods extends ast.TreeDSL {
def isRewrite(sym: Symbol) = sym.isCaseAccessorMethod && !sym.isPublic
for (ddef @ DefDef(_, _, _, _, _, _) <- templ.body ; if isRewrite(ddef.symbol)) {
- val original = ddef.symbol
val newAcc = deriveMethod(ddef.symbol, name => context.unit.freshTermName(name + "$")) { newAcc =>
newAcc.makePublic
newAcc resetFlag (ACCESSOR | PARAMACCESSOR)
diff --git a/src/compiler/scala/tools/nsc/typechecker/Tags.scala b/src/compiler/scala/tools/nsc/typechecker/Tags.scala
index d82fbd7c77..45aa1bcbdb 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Tags.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Tags.scala
@@ -10,7 +10,7 @@ trait Tags {
trait Tag {
self: Typer =>
- private def resolveTag(pos: Position, taggedTp: Type, allowMaterialization: Boolean) = beforeTyper {
+ private def resolveTag(pos: Position, taggedTp: Type, allowMaterialization: Boolean) = enteringTyper {
def wrapper (tree: => Tree): Tree = if (allowMaterialization) (context.withMacrosEnabled[Tree](tree)) else (context.withMacrosDisabled[Tree](tree))
wrapper(inferImplicit(
EmptyTree,
diff --git a/src/compiler/scala/tools/nsc/typechecker/TreeCheckers.scala b/src/compiler/scala/tools/nsc/typechecker/TreeCheckers.scala
index 48a5a36b00..260bd87fdf 100644
--- a/src/compiler/scala/tools/nsc/typechecker/TreeCheckers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/TreeCheckers.scala
@@ -6,7 +6,6 @@
package scala.tools.nsc
package typechecker
-import scala.tools.nsc.symtab.Flags._
import scala.collection.mutable
import mutable.ListBuffer
import util.returning
@@ -143,13 +142,6 @@ abstract class TreeCheckers extends Analyzer {
currentRun.units foreach (x => wrap(x)(check(x)))
}
- def printingTypings[T](body: => T): T = {
- val saved = global.printTypings
- global.printTypings = true
- val result = body
- global.printTypings = saved
- result
- }
def runWithUnit[T](unit: CompilationUnit)(body: => Unit): Unit = {
val unit0 = currentUnit
currentRun.currentUnit = unit
@@ -186,10 +178,6 @@ abstract class TreeCheckers extends Analyzer {
errorFn(t1.pos, "trees differ\n old: " + treestr(t1) + "\n new: " + treestr(t2))
private def typesDiffer(tree: Tree, tp1: Type, tp2: Type) =
errorFn(tree.pos, "types differ\n old: " + tp1 + "\n new: " + tp2 + "\n tree: " + tree)
- private def ownersDiffer(tree: Tree, shouldBe: Symbol) = {
- val sym = tree.symbol
- errorFn(tree.pos, sym + " has wrong owner: " + ownerstr(sym.owner) + ", should be: " + ownerstr(shouldBe))
- }
/** XXX Disabled reporting of position errors until there is less noise. */
private def noPos(t: Tree) =
@@ -204,11 +192,8 @@ abstract class TreeCheckers extends Analyzer {
override def typed(tree: Tree, mode: Int, pt: Type): Tree = returning(tree) {
case EmptyTree | TypeTree() => ()
case _ if tree.tpe != null =>
- tpeOfTree.getOrElseUpdate(tree, {
- val saved = tree.tpe
- tree.tpe = null
- saved
- })
+ tpeOfTree.getOrElseUpdate(tree, try tree.tpe finally tree.clearType())
+
wrap(tree)(super.typed(tree, mode, pt) match {
case _: Literal => ()
case x if x ne tree => treesDiffer(tree, x)
@@ -278,7 +263,7 @@ abstract class TreeCheckers extends Analyzer {
def cond(s: Symbol) = !s.isTerm || s.isMethod || s == sym.owner
if (sym.owner != currentOwner) {
- val expected = currentOwner.ownerChain find (x => cond(x)) getOrElse fail("DefTree can't find owner: ")
+ val expected = currentOwner.ownerChain find (x => cond(x)) getOrElse { fail("DefTree can't find owner: ") ; NoSymbol }
if (sym.owner != expected)
fail(sm"""|
| currentOwner chain: ${currentOwner.ownerChain take 3 mkString " -> "}
@@ -300,7 +285,7 @@ abstract class TreeCheckers extends Analyzer {
if (oldtpe =:= tree.tpe) ()
else typesDiffer(tree, oldtpe, tree.tpe)
- tree.tpe = oldtpe
+ tree setType oldtpe
super.traverse(tree)
}
}
diff --git a/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala b/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala
index 4233bde770..3bb6ae53dc 100644
--- a/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala
@@ -8,7 +8,6 @@ package typechecker
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
-import scala.util.control.ControlThrowable
import scala.util.control.Exception.ultimately
import symtab.Flags._
import PartialFunction._
@@ -37,15 +36,6 @@ trait TypeDiagnostics {
import global._
import definitions._
- import global.typer.{ infer, context }
-
- /** The common situation of making sure nothing is erroneous could be
- * nicer if Symbols, Types, and Trees all implemented some common interface
- * in which isErroneous and similar would be placed.
- */
- def noErroneousTypes(tps: Type*) = tps forall (x => !x.isErroneous)
- def noErroneousSyms(syms: Symbol*) = syms forall (x => !x.isErroneous)
- def noErroneousTrees(trees: Tree*) = trees forall (x => !x.isErroneous)
/** For errors which are artifacts of the implementation: such messages
* indicate that the restriction may be lifted in the future.
@@ -58,7 +48,7 @@ trait TypeDiagnostics {
/** A map of Positions to addendums - if an error involves a position in
* the map, the addendum should also be printed.
*/
- private var addendums = perRunCaches.newMap[Position, () => String]()
+ private val addendums = perRunCaches.newMap[Position, () => String]()
private var isTyperInPattern = false
/** Devising new ways of communicating error info out of
@@ -296,7 +286,6 @@ trait TypeDiagnostics {
// distinguished from the other types in the same error message
private val savedName = sym.name
def restoreName() = sym.name = savedName
- def isAltered = sym.name != savedName
def modifyName(f: String => String) = sym setName newTypeName(f(sym.name.toString))
/** Prepend java.lang, scala., or Predef. if this type originated
@@ -426,6 +415,120 @@ trait TypeDiagnostics {
def permanentlyHiddenWarning(pos: Position, hidden: Name, defn: Symbol) =
contextWarning(pos, "imported `%s' is permanently hidden by definition of %s".format(hidden, defn.fullLocationString))
+ object checkUnused {
+ val ignoreNames = Set[TermName]("readResolve", "readObject", "writeObject", "writeReplace")
+
+ class UnusedPrivates extends Traverser {
+ val defnTrees = ListBuffer[MemberDef]()
+ val targets = mutable.Set[Symbol]()
+ val setVars = mutable.Set[Symbol]()
+ val treeTypes = mutable.Set[Type]()
+
+ def defnSymbols = defnTrees.toList map (_.symbol)
+ def localVars = defnSymbols filter (t => t.isLocal && t.isVar)
+
+ def qualifiesTerm(sym: Symbol) = (
+ (sym.isModule || sym.isMethod || sym.isPrivateLocal || sym.isLocal)
+ && !nme.isLocalName(sym.name)
+ && !sym.isParameter
+ && !sym.isParamAccessor // could improve this, but it's a pain
+ && !sym.isEarlyInitialized // lots of false positives in the way these are encoded
+ && !(sym.isGetter && sym.accessed.isEarlyInitialized)
+ )
+ def qualifiesType(sym: Symbol) = !sym.isDefinedInPackage
+ def qualifies(sym: Symbol) = (
+ (sym ne null)
+ && (sym.isTerm && qualifiesTerm(sym) || sym.isType && qualifiesType(sym))
+ )
+
+ override def traverse(t: Tree): Unit = {
+ t match {
+ case t: MemberDef if qualifies(t.symbol) => defnTrees += t
+ case t: RefTree if t.symbol ne null => targets += t.symbol
+ case Assign(lhs, _) if lhs.symbol != null => setVars += lhs.symbol
+ case _ =>
+ }
+ // Only record type references which don't originate within the
+ // definition of the class being referenced.
+ if (t.tpe ne null) {
+ for (tp <- t.tpe ; if !treeTypes(tp) && !currentOwner.ownerChain.contains(tp.typeSymbol)) {
+ tp match {
+ case NoType | NoPrefix =>
+ case NullaryMethodType(_) =>
+ case MethodType(_, _) =>
+ case _ =>
+ log(s"$tp referenced from $currentOwner")
+ treeTypes += tp
+ }
+ }
+ // e.g. val a = new Foo ; new a.Bar ; don't let a be reported as unused.
+ t.tpe.prefix foreach {
+ case SingleType(_, sym) => targets += sym
+ case _ =>
+ }
+ }
+ super.traverse(t)
+ }
+ def isUnusedType(m: Symbol): Boolean = (
+ m.isType
+ && !m.isTypeParameterOrSkolem // would be nice to improve this
+ && (m.isPrivate || m.isLocal)
+ && !(treeTypes.exists(tp => tp exists (t => t.typeSymbolDirect == m)))
+ )
+ def isUnusedTerm(m: Symbol): Boolean = (
+ (m.isTerm)
+ && (m.isPrivate || m.isLocal)
+ && !targets(m)
+ && !(m.name == nme.WILDCARD) // e.g. val _ = foo
+ && !ignoreNames(m.name.toTermName) // serialization methods
+ && !isConstantType(m.info.resultType) // subject to constant inlining
+ && !treeTypes.exists(_ contains m) // e.g. val a = new Foo ; new a.Bar
+ )
+ def unusedTypes = defnTrees.toList filter (t => isUnusedType(t.symbol))
+ def unusedTerms = defnTrees.toList filter (v => isUnusedTerm(v.symbol))
+ // local vars which are never set, except those already returned in unused
+ def unsetVars = localVars filter (v => !setVars(v) && !isUnusedTerm(v))
+ }
+
+ def apply(unit: CompilationUnit) = {
+ val p = new UnusedPrivates
+ p traverse unit.body
+ val unused = p.unusedTerms
+ unused foreach { defn: DefTree =>
+ val sym = defn.symbol
+ val isDefaultGetter = sym.name containsName nme.DEFAULT_GETTER_STRING
+ val pos = (
+ if (defn.pos.isDefined) defn.pos
+ else if (sym.pos.isDefined) sym.pos
+ else sym match {
+ case sym: TermSymbol => sym.referenced.pos
+ case _ => NoPosition
+ }
+ )
+ val why = if (sym.isPrivate) "private" else "local"
+ val what = (
+ if (isDefaultGetter) "default argument"
+ else if (sym.isConstructor) "constructor"
+ else if (sym.isVar || sym.isGetter && sym.accessed.isVar) "var"
+ else if (sym.isVal || sym.isGetter && sym.accessed.isVal) "val"
+ else if (sym.isSetter) "setter"
+ else if (sym.isMethod) "method"
+ else if (sym.isModule) "object"
+ else "term"
+ )
+ unit.warning(pos, s"$why $what in ${sym.owner} is never used")
+ }
+ p.unsetVars foreach { v =>
+ unit.warning(v.pos, s"local var ${v.name} in ${v.owner} is never set - it could be a val")
+ }
+ p.unusedTypes foreach { t =>
+ val sym = t.symbol
+ val why = if (sym.isPrivate) "private" else "local"
+ unit.warning(t.pos, s"$why ${sym.fullLocationString} is never used")
+ }
+ }
+ }
+
object checkDead {
private var expr: Symbol = NoSymbol
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index e45d64ade5..2b01e32497 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -54,24 +54,27 @@ trait Typers extends Modes with Adaptations with Tags {
object UnTyper extends Traverser {
override def traverse(tree: Tree) = {
if (tree.canHaveAttrs) {
- tree.tpe = null
- if (tree.hasSymbol) tree.symbol = NoSymbol
+ tree.clearType()
+ if (tree.hasSymbolField) tree.symbol = NoSymbol
}
super.traverse(tree)
}
}
-/* needed for experimental version where early types can be type arguments
- class EarlyMap(clazz: Symbol) extends TypeMap {
- def apply(tp: Type): Type = tp match {
- case TypeRef(NoPrefix, sym, List()) if (sym hasFlag PRESUPER) =>
- TypeRef(ThisType(clazz), sym, List())
- case _ =>
- mapOver(tp)
+
+ sealed abstract class SilentResult[+T] {
+ @inline final def map[U](f: T => U): SilentResult[U] = this match {
+ case SilentResultValue(value) => SilentResultValue(f(value))
+ case x: SilentTypeError => x
+ }
+ @inline final def filter(p: T => Boolean): SilentResult[T] = this match {
+ case SilentResultValue(value) if !p(value) => SilentTypeError(TypeErrorWrapper(new TypeError(NoPosition, "!p")))
+ case _ => this
+ }
+ @inline final def orElse[T1 >: T](f: AbsTypeError => T1): T1 = this match {
+ case SilentResultValue(value) => value
+ case SilentTypeError(err) => f(err)
}
}
-*/
-
- sealed abstract class SilentResult[+T]
case class SilentTypeError(err: AbsTypeError) extends SilentResult[Nothing] { }
case class SilentResultValue[+T](value: T) extends SilentResult[T] { }
@@ -94,7 +97,7 @@ trait Typers extends Modes with Adaptations with Tags {
// - we may virtualize matches (if -Xexperimental and there's a suitable __match in scope)
// - we synthesize PartialFunction implementations for `x => x match {...}` and `match {...}` when the expected type is PartialFunction
// this is disabled by: -Xoldpatmat or interactive compilation (we run it for scaladoc due to SI-5933)
- private def newPatternMatching = opt.virtPatmat && !forInteractive //&& !forScaladoc && (phase.id < currentRun.uncurryPhase.id)
+ private def newPatternMatching = !settings.XoldPatmat.value && !forInteractive //&& !forScaladoc && (phase.id < currentRun.uncurryPhase.id)
abstract class Typer(context0: Context) extends TyperDiagnostics with Adaptation with Tag with TyperContextErrors {
import context0.unit
@@ -197,7 +200,7 @@ trait Typers extends Modes with Adaptations with Tags {
case PolyType(_, _) => EmptyTree
case _ =>
def wrapImplicit(from: Type): Tree = {
- val result = inferImplicit(tree, functionType(from :: Nil, to), reportAmbiguous, true, context, saveErrors)
+ val result = inferImplicit(tree, functionType(from.withoutAnnotations :: Nil, to), reportAmbiguous, true, context, saveErrors)
if (result.subst != EmptyTreeTypeSubstituter) {
result.subst traverse tree
notifyUndetparamsInferred(result.subst.from, result.subst.to)
@@ -230,10 +233,7 @@ trait Typers extends Modes with Adaptations with Tags {
case _ => tp
}
- /** Check that <code>tree</code> is a stable expression.
- *
- * @param tree ...
- * @return ...
+ /** Check that `tree` is a stable expression.
*/
def checkStable(tree: Tree): Tree = (
if (treeInfo.isExprSafeToInline(tree)) tree
@@ -245,7 +245,7 @@ trait Typers extends Modes with Adaptations with Tags {
* of its symbol was not volatile?
*/
protected def isStableExceptVolatile(tree: Tree) = {
- tree.hasSymbol && tree.symbol != NoSymbol && tree.tpe.isVolatile &&
+ tree.hasSymbolField && tree.symbol != NoSymbol && tree.tpe.isVolatile &&
{ val savedTpe = tree.symbol.info
val savedSTABLE = tree.symbol getFlag STABLE
tree.symbol setInfo AnyRefClass.tpe
@@ -287,16 +287,11 @@ trait Typers extends Modes with Adaptations with Tags {
)
}
- /** Check that type <code>tp</code> is not a subtype of itself.
- *
- * @param pos ...
- * @param tp ...
- * @return <code>true</code> if <code>tp</code> is not a subtype of itself.
+ /** Check that type `tp` is not a subtype of itself.
*/
def checkNonCyclic(pos: Position, tp: Type): Boolean = {
def checkNotLocked(sym: Symbol) = {
- sym.initialize
- sym.lockOK || { CyclicAliasingOrSubtypingError(pos, sym); false }
+ sym.initialize.lockOK || { CyclicAliasingOrSubtypingError(pos, sym); false }
}
tp match {
case TypeRef(pre, sym, args) =>
@@ -307,12 +302,6 @@ trait Typers extends Modes with Adaptations with Tags {
case SingleType(pre, sym) =>
checkNotLocked(sym)
-/*
- case TypeBounds(lo, hi) =>
- var ok = true
- for (t <- lo) ok = ok & checkNonCyclic(pos, t)
- ok
-*/
case st: SubType =>
checkNonCyclic(pos, st.supertype)
case ct: CompoundType =>
@@ -323,19 +312,19 @@ trait Typers extends Modes with Adaptations with Tags {
}
def checkNonCyclic(pos: Position, tp: Type, lockedSym: Symbol): Boolean = try {
- if (!lockedSym.lock(CyclicReferenceError(pos, lockedSym))) false
+ if (!lockedSym.lock(CyclicReferenceError(pos, tp, lockedSym))) false
else checkNonCyclic(pos, tp)
} finally {
lockedSym.unlock()
}
def checkNonCyclic(sym: Symbol) {
- if (!checkNonCyclic(sym.pos, sym.tpe)) sym.setInfo(ErrorType)
+ if (!checkNonCyclic(sym.pos, sym.tpe_*)) sym.setInfo(ErrorType)
}
def checkNonCyclic(defn: Tree, tpt: Tree) {
if (!checkNonCyclic(defn.pos, tpt.tpe, defn.symbol)) {
- tpt.tpe = ErrorType
+ tpt setType ErrorType
defn.symbol.setInfo(ErrorType)
}
}
@@ -366,28 +355,13 @@ trait Typers extends Modes with Adaptations with Tags {
private var scope: Scope = _
private var hiddenSymbols: List[Symbol] = _
- /** Check that type <code>tree</code> does not refer to private
+ /** Check that type `tree` does not refer to private
* components unless itself is wrapped in something private
- * (<code>owner</code> tells where the type occurs).
- *
- * @param owner ...
- * @param tree ...
- * @return ...
+ * (`owner` tells where the type occurs).
*/
def privates[T <: Tree](owner: Symbol, tree: T): T =
check(owner, EmptyScope, WildcardType, tree)
- /** Check that type <code>tree</code> does not refer to entities
- * defined in scope <code>scope</code>.
- *
- * @param scope ...
- * @param pt ...
- * @param tree ...
- * @return ...
- */
- def locals[T <: Tree](scope: Scope, pt: Type, tree: T): T =
- check(NoSymbol, scope, pt, tree)
-
private def check[T <: Tree](owner: Symbol, scope: Scope, pt: Type, tree: T): T = {
this.owner = owner
this.scope = scope
@@ -463,7 +437,7 @@ trait Typers extends Modes with Adaptations with Tags {
}
/** The qualifying class
- * of a this or super with prefix <code>qual</code>.
+ * of a this or super with prefix `qual`.
* packageOk is equal false when qualifying class symbol
*/
def qualifyingClass(tree: Tree, qual: Name, packageOK: Boolean) =
@@ -549,7 +523,7 @@ trait Typers extends Modes with Adaptations with Tags {
}
}
- /** Does the context of tree <code>tree</code> require a stable type?
+ /** Does the context of tree `tree` require a stable type?
*/
private def isStableContext(tree: Tree, mode: Int, pt: Type) =
isNarrowable(tree.tpe) && ((mode & (EXPRmode | LHSmode)) == EXPRmode) &&
@@ -568,11 +542,13 @@ trait Typers extends Modes with Adaptations with Tags {
* @return modified tree and new prefix type
*/
private def makeAccessible(tree: Tree, sym: Symbol, pre: Type, site: Tree): (Tree, Type) =
- if (isInPackageObject(sym, pre.typeSymbol)) {
+ if (context.isInPackageObject(sym, pre.typeSymbol)) {
if (pre.typeSymbol == ScalaPackageClass && sym.isTerm) {
// short cut some aliases. It seems pattern matching needs this
// to notice exhaustiveness and to generate good code when
// List extractors are mixed with :: patterns. See Test5 in lists.scala.
+ //
+ // TODO SI-6609 Eliminate this special case once the old pattern matcher is removed.
def dealias(sym: Symbol) =
(atPos(tree.pos.makeTransparent) {gen.mkAttributedRef(sym)} setPos tree.pos, sym.owner.thisType)
sym.name match {
@@ -601,26 +577,6 @@ trait Typers extends Modes with Adaptations with Tags {
(checkAccessible(tree, sym, pre, site), pre)
}
- /** Is `sym` defined in package object of package `pkg`?
- */
- private def isInPackageObject(sym: Symbol, pkg: Symbol) = {
- def isInPkgObj(sym: Symbol) =
- !sym.owner.isPackage && {
- sym.owner.isPackageObjectClass &&
- sym.owner.owner == pkg ||
- pkg.isInitialized && {
- // need to be careful here to not get a cyclic reference during bootstrap
- val pkgobj = pkg.info.member(nme.PACKAGEkw)
- pkgobj.isInitialized &&
- (pkgobj.info.member(sym.name).alternatives contains sym)
- }
- }
- pkg.isPackageClass && {
- if (sym.isOverloaded) sym.alternatives forall isInPkgObj
- else isInPkgObj(sym)
- }
- }
-
/** Post-process an identifier or selection node, performing the following:
* 1. Check that non-function pattern expressions are stable
* 2. Check that packages and static modules are not used as values
@@ -635,7 +591,7 @@ trait Typers extends Modes with Adaptations with Tags {
def fail() = NotAValueError(tree, sym)
if (tree.isErrorTyped) tree
- else if ((mode & (PATTERNmode | FUNmode)) == PATTERNmode && tree.isTerm) { // (1)
+ else if (inPatternNotFunMode(mode) && tree.isTerm) { // (1)
if (sym.isValue) {
val tree1 = checkStable(tree)
// A module reference in a pattern has type Foo.type, not "object Foo"
@@ -669,12 +625,6 @@ trait Typers extends Modes with Adaptations with Tags {
case _ => !phase.erasedTypes
}
- /**
- * @param tree ...
- * @param mode ...
- * @param pt ...
- * @return ...
- */
def stabilizeFun(tree: Tree, mode: Int, pt: Type): Tree = {
val sym = tree.symbol
val pre = tree match {
@@ -850,26 +800,27 @@ trait Typers extends Modes with Adaptations with Tags {
// avoid throwing spurious DivergentImplicit errors
if (context.hasErrors)
- return setError(tree)
-
- withCondConstrTyper(treeInfo.isSelfOrSuperConstrCall(tree)){ typer1 =>
- if (original != EmptyTree && pt != WildcardType)
- typer1.silent(tpr => {
- val withImplicitArgs = tpr.applyImplicitArgs(tree)
- if (tpr.context.hasErrors) tree // silent will wrap it in SilentTypeError anyway
- else tpr.typed(withImplicitArgs, mode, pt)
- }) match {
- case SilentResultValue(result) =>
- result
- case _ =>
+ setError(tree)
+ else
+ withCondConstrTyper(treeInfo.isSelfOrSuperConstrCall(tree))(typer1 =>
+ if (original != EmptyTree && pt != WildcardType) (
+ typer1 silent { tpr =>
+ val withImplicitArgs = tpr.applyImplicitArgs(tree)
+ if (tpr.context.hasErrors) tree // silent will wrap it in SilentTypeError anyway
+ else tpr.typed(withImplicitArgs, mode, pt)
+ }
+ orElse { _ =>
debuglog("fallback on implicits: " + tree + "/" + resetAllAttrs(original))
val tree1 = typed(resetAllAttrs(original), mode, WildcardType)
- tree1.tpe = addAnnotations(tree1, tree1.tpe)
+ // Q: `typed` already calls `addAnnotations` and `adapt`. the only difference here is that
+ // we pass `EmptyTree` as the `original`. intended? added in 2009 (53d98e7d42) by martin.
+ tree1 setType addAnnotations(tree1, tree1.tpe)
if (tree1.isEmpty) tree1 else adapt(tree1, mode, pt, EmptyTree)
- }
- else
- typer1.typed(typer1.applyImplicitArgs(tree), mode, pt)
- }
+ }
+ )
+ else
+ typer1.typed(typer1.applyImplicitArgs(tree), mode, pt)
+ )
}
def instantiateToMethodType(mt: MethodType): Tree = {
@@ -882,7 +833,6 @@ trait Typers extends Modes with Adaptations with Tags {
debuglog("eta-expanding " + tree + ":" + tree.tpe + " to " + pt)
checkParamsConvertible(tree, tree.tpe)
val tree0 = etaExpand(context.unit, tree, this)
- // println("eta "+tree+" ---> "+tree0+":"+tree0.tpe+" undet: "+context.undetparams+ " mode: "+Integer.toHexString(mode))
if (context.undetparams.nonEmpty) {
// #2624: need to infer type arguments for eta expansion of a polymorphic method
@@ -910,7 +860,7 @@ trait Typers extends Modes with Adaptations with Tags {
// but this needs additional investigation, because it crashes t5228, gadts1 and maybe something else
// tree setType tree.tpe.normalize
tree
- } else if (tree.hasSymbol && !tree.symbol.typeParams.isEmpty && !inHKMode(mode) &&
+ } else if (tree.hasSymbolField && !tree.symbol.typeParams.isEmpty && !inHKMode(mode) &&
!(tree.symbol.isJavaDefined && context.unit.isJava)) { // (7)
// @M When not typing a higher-kinded type ((mode & HKmode) == 0)
// or raw type (tree.symbol.isJavaDefined && context.unit.isJava), types must be of kind *,
@@ -918,7 +868,7 @@ trait Typers extends Modes with Adaptations with Tags {
// @M TODO: why do kind-* tree's have symbols, while higher-kinded ones don't?
MissingTypeParametersError(tree)
} else if ( // (7.1) @M: check kind-arity
- // @M: removed check for tree.hasSymbol and replace tree.symbol by tree.tpe.symbol (TypeTree's must also be checked here, and they don't directly have a symbol)
+ // @M: removed check for tree.hasSymbolField and replace tree.symbol by tree.tpe.symbol (TypeTree's must also be checked here, and they don't directly have a symbol)
(inHKMode(mode)) &&
// @M: don't check tree.tpe.symbol.typeParams. check tree.tpe.typeParams!!!
// (e.g., m[Int] --> tree.tpe.symbol.typeParams.length == 1, tree.tpe.typeParams.length == 0!)
@@ -968,9 +918,11 @@ trait Typers extends Modes with Adaptations with Tags {
def adaptConstrPattern(): Tree = { // (5)
def hasUnapplyMember(tp: Type) = reallyExists(unapplyMember(tp))
val overloadedExtractorOfObject = tree.symbol filter (sym => hasUnapplyMember(sym.tpe))
- // if the tree's symbol's type does not define an extractor, maybe the tree's type does
- // this is the case when we encounter an arbitrary tree as the target of an unapply call (rather than something that looks like a constructor call)
- // (for now, this only happens due to wrapClassTagUnapply, but when we support parameterized extractors, it will become more common place)
+ // if the tree's symbol's type does not define an extractor, maybe the tree's type does.
+ // this is the case when we encounter an arbitrary tree as the target of an unapply call
+ // (rather than something that looks like a constructor call.) (for now, this only happens
+ // due to wrapClassTagUnapply, but when we support parameterized extractors, it will become
+ // more common place)
val extractor = overloadedExtractorOfObject orElse unapplyMember(tree.tpe)
if (extractor != NoSymbol) {
// if we did some ad-hoc overloading resolution, update the tree's symbol
@@ -980,7 +932,7 @@ trait Typers extends Modes with Adaptations with Tags {
tree setSymbol overloadedExtractorOfObject
tree.tpe match {
- case OverloadedType(pre, alts) => tree.tpe = overloadedType(pre, alts filter (alt => hasUnapplyMember(alt.tpe)))
+ case OverloadedType(pre, alts) => tree setType overloadedType(pre, alts filter (alt => hasUnapplyMember(alt.tpe)))
case _ =>
}
val unapply = unapplyMember(extractor.tpe)
@@ -1040,15 +992,21 @@ trait Typers extends Modes with Adaptations with Tags {
def insertApply(): Tree = {
assert(!inHKMode(mode), modeString(mode)) //@M
- val qual = adaptToName(tree, nme.apply) match {
- case id @ Ident(_) =>
- val pre = if (id.symbol.owner.isPackageClass) id.symbol.owner.thisType
- else if (id.symbol.owner.isClass)
- context.enclosingSubClassContext(id.symbol.owner).prefix
- else NoPrefix
- stabilize(id, pre, EXPRmode | QUALmode, WildcardType)
- case sel @ Select(qualqual, _) =>
- stabilize(sel, qualqual.tpe, EXPRmode | QUALmode, WildcardType)
+ val adapted = adaptToName(tree, nme.apply)
+ def stabilize0(pre: Type): Tree = stabilize(adapted, pre, EXPRmode | QUALmode, WildcardType)
+ // TODO reconcile the overlap between Typers#stablize and TreeGen.stabilize
+ val qual = adapted match {
+ case This(_) =>
+ gen.stabilize(adapted)
+ case Ident(_) =>
+ val owner = adapted.symbol.owner
+ val pre =
+ if (owner.isPackageClass) owner.thisType
+ else if (owner.isClass) context.enclosingSubClassContext(owner).prefix
+ else NoPrefix
+ stabilize0(pre)
+ case Select(qualqual, _) =>
+ stabilize0(qualqual.tpe)
case other =>
other
}
@@ -1123,7 +1081,7 @@ trait Typers extends Modes with Adaptations with Tags {
tree.symbol != null && tree.symbol.isTermMacro && // of a macro
!tree.attachments.get[SuppressMacroExpansionAttachment.type].isDefined)
macroExpand(this, tree, mode, pt)
- else if ((mode & (PATTERNmode | FUNmode)) == (PATTERNmode | FUNmode))
+ else if (inAllModes(mode, PATTERNmode | FUNmode))
adaptConstrPattern()
else if (shouldInsertApply(tree))
insertApply()
@@ -1175,13 +1133,6 @@ trait Typers extends Modes with Adaptations with Tags {
// (14); the condition prevents chains of views
debuglog("inferring view from " + tree.tpe + " to " + pt)
val coercion = inferView(tree, tree.tpe, pt, true)
- // convert forward views of delegate types into closures wrapped around
- // the delegate's apply method (the "Invoke" method, which was translated into apply)
- if (forMSIL && coercion != null && isCorrespondingDelegate(tree.tpe, pt)) {
- val meth: Symbol = tree.tpe.member(nme.apply)
- debuglog("replacing forward delegate view with: " + meth + ":" + meth.tpe)
- return typed(Select(tree, meth), mode, pt)
- }
if (coercion != EmptyTree) {
def msg = "inferred view from " + tree.tpe + " to " + pt + " = " + coercion + ":" + coercion.tpe
if (settings.logImplicitConv.value)
@@ -1203,9 +1154,9 @@ trait Typers extends Modes with Adaptations with Tags {
val found = tree.tpe
if (!found.isErroneous && !pt.isErroneous) {
if ((!context.reportErrors && isPastTyper) || tree.attachments.get[MacroExpansionAttachment].isDefined) {
- val (bound, req) = pt match {
- case ExistentialType(qs, tpe) => (qs, tpe)
- case _ => (Nil, pt)
+ val bound = pt match {
+ case ExistentialType(qs, _) => qs
+ case _ => Nil
}
val boundOrSkolems = bound ++ pt.skolemsExceptMethodTypeParams
if (boundOrSkolems.nonEmpty) {
@@ -1271,12 +1222,10 @@ trait Typers extends Modes with Adaptations with Tags {
*/
def instantiateExpectingUnit(tree: Tree, mode: Int): Tree = {
val savedUndetparams = context.undetparams
- silent(_.instantiate(tree, mode, UnitClass.tpe)) match {
- case SilentResultValue(t) => t
- case _ =>
- context.undetparams = savedUndetparams
- val valueDiscard = atPos(tree.pos)(Block(List(instantiate(tree, mode, WildcardType)), Literal(Constant())))
- typed(valueDiscard, mode, UnitClass.tpe)
+ silent(_.instantiate(tree, mode, UnitClass.tpe)) orElse { _ =>
+ context.undetparams = savedUndetparams
+ val valueDiscard = atPos(tree.pos)(Block(List(instantiate(tree, mode, WildcardType)), Literal(Constant())))
+ typed(valueDiscard, mode, UnitClass.tpe)
}
}
@@ -1333,16 +1282,12 @@ trait Typers extends Modes with Adaptations with Tags {
def doAdapt(restpe: Type) =
//util.trace("adaptToArgs "+qual+", name = "+name+", argtpes = "+(args map (_.tpe))+", pt = "+pt+" = ")
adaptToMember(qual, HasMethodMatching(name, args map (_.tpe), restpe), reportAmbiguous, saveErrors)
- if (pt != WildcardType) {
- silent(_ => doAdapt(pt)) match {
- case SilentResultValue(result) if result != qual =>
- result
- case _ =>
- debuglog("fallback on implicits in adaptToArguments: "+qual+" . "+name)
- doAdapt(WildcardType)
- }
- } else
+
+ if (pt == WildcardType)
doAdapt(pt)
+ else silent(_ => doAdapt(pt)) filter (_ != qual) orElse (_ =>
+ logResult(s"fallback on implicits in adaptToArguments: $qual.$name")(doAdapt(WildcardType))
+ )
}
/** Try to apply an implicit conversion to `qual` so that it contains
@@ -1350,27 +1295,24 @@ trait Typers extends Modes with Adaptations with Tags {
* account using `adaptToArguments`.
*/
def adaptToMemberWithArgs(tree: Tree, qual: Tree, name: Name, mode: Int, reportAmbiguous: Boolean, saveErrors: Boolean): Tree = {
- def onError(reportError: => Tree): Tree = {
- context.tree match {
- case Apply(tree1, args) if (tree1 eq tree) && args.nonEmpty =>
- silent(_.typedArgs(args, mode)) match {
- case SilentResultValue(xs) =>
- val args = xs.asInstanceOf[List[Tree]]
- if (args exists (_.isErrorTyped))
- reportError
- else
- adaptToArguments(qual, name, args, WildcardType, reportAmbiguous, saveErrors)
- case _ =>
- reportError
- }
- case _ =>
- reportError
- }
- }
- silent(_.adaptToMember(qual, HasMember(name), false)) match {
- case SilentResultValue(res) => res
- case SilentTypeError(err) => onError({if (reportAmbiguous) { context.issue(err) }; setError(tree)})
+ def onError(reportError: => Tree): Tree = context.tree match {
+ case Apply(tree1, args) if (tree1 eq tree) && args.nonEmpty =>
+ ( silent (_.typedArgs(args, mode))
+ map (_.asInstanceOf[List[Tree]])
+ filter (xs => !(xs exists (_.isErrorTyped)))
+ map (xs => adaptToArguments(qual, name, xs, WildcardType, reportAmbiguous, saveErrors))
+ orElse ( _ => reportError)
+ )
+ case _ =>
+ reportError
}
+
+ silent(_.adaptToMember(qual, HasMember(name), false)) orElse (err =>
+ onError {
+ if (reportAmbiguous) context issue err
+ setError(tree)
+ }
+ )
}
/** Try to apply an implicit conversion to `qual` to that it contains a
@@ -1562,7 +1504,7 @@ trait Typers extends Modes with Adaptations with Tags {
typedType(decodedtpt)
} else {
var supertpt = typedTypeConstructor(decodedtpt)
- val supertparams = if (supertpt.hasSymbol) supertpt.symbol.typeParams else Nil
+ val supertparams = if (supertpt.hasSymbolField) supertpt.symbol.typeParams else Nil
if (supertparams.nonEmpty) {
typedPrimaryConstrBody(templ) {
val supertpe = PolyType(supertparams, appliedType(supertpt.tpe, supertparams map (_.tpeHK)))
@@ -1628,7 +1570,6 @@ trait Typers extends Modes with Adaptations with Tags {
case EmptyTree => EmptyTree
}) orElse cunit
val cbody1 = treeCopy.Block(cbody, preSuperStats, superCall1)
-
val clazz = context.owner
assert(clazz != NoSymbol, templ)
val cscope = context.outer.makeNewScope(ctor, context.outer.owner)
@@ -1642,9 +1583,9 @@ trait Typers extends Modes with Adaptations with Tags {
val preSuperVals = treeInfo.preSuperFields(templ.body)
if (preSuperVals.isEmpty && preSuperStats.nonEmpty)
- debugwarn("Wanted to zip empty presuper val list with " + preSuperStats)
+ devWarning("Wanted to zip empty presuper val list with " + preSuperStats)
else
- map2(preSuperStats, preSuperVals)((ldef, gdef) => gdef.tpt.tpe = ldef.symbol.tpe)
+ map2(preSuperStats, preSuperVals)((ldef, gdef) => gdef.tpt setType ldef.symbol.tpe)
if (superCall1 == cunit) EmptyTree else cbody2
case _ =>
@@ -1664,7 +1605,7 @@ trait Typers extends Modes with Adaptations with Tags {
return explode(supersupertpt, supertpt1 :: acc)
}
}
- if (supertpt.tpe.typeSymbol == AnyClass) supertpt.tpe = AnyRefClass.tpe
+ if (supertpt.tpe.typeSymbol == AnyClass) supertpt setType AnyRefClass.tpe
supertpt :: acc
}
explode(first, Nil) ++ rest
@@ -1777,9 +1718,6 @@ trait Typers extends Modes with Adaptations with Tags {
!selfType.isErroneous &&
!parent.tpe.isErroneous)
{
- //Console.println(context.owner);//DEBUG
- //Console.println(context.owner.unsafeTypeParams);//DEBUG
- //Console.println(List.fromArray(context.owner.info.closure));//DEBUG
pending += ParentSelfTypeConformanceError(parent, selfType)
if (settings.explaintypes.value) explainTypes(selfType, parent.tpe.typeOfThis)
}
@@ -1795,13 +1733,6 @@ trait Typers extends Modes with Adaptations with Tags {
for (p <- parents) validateParentClass(p, superclazz)
}
-/*
- if (settings.Xshowcls.value != "" &&
- settings.Xshowcls.value == context.owner.fullName)
- println("INFO "+context.owner+
- ", baseclasses = "+(context.owner.info.baseClasses map (_.fullName))+
- ", lin = "+(context.owner.info.baseClasses map (context.owner.thisType.baseType)))
-*/
pending.foreach(ErrorUtils.issueTypeError)
}
@@ -1825,12 +1756,7 @@ trait Typers extends Modes with Adaptations with Tags {
}
}
- /**
- * @param cdef ...
- * @return ...
- */
def typedClassDef(cdef: ClassDef): Tree = {
-// attributes(cdef)
val clazz = cdef.symbol
val typedMods = typedModifiers(cdef.mods)
assert(clazz != NoSymbol, cdef)
@@ -1859,10 +1785,6 @@ trait Typers extends Modes with Adaptations with Tags {
.setType(NoType)
}
- /**
- * @param mdef ...
- * @return ...
- */
def typedModuleDef(mdef: ModuleDef): Tree = {
// initialize all constructors of the linked class: the type completer (Namer.methodSig)
// might add default getters to this object. example: "object T; class T(x: Int = 1)"
@@ -1920,13 +1842,7 @@ trait Typers extends Modes with Adaptations with Tags {
if (txt eq context) namer.enterSym(tree)
else newNamer(txt).enterSym(tree)
- /**
- * @param templ ...
- * @param parents1 ...
- * <li> <!-- 2 -->
- * Check that inner classes do not inherit from Annotation
- * </li>
- * @return ...
+ /** <!-- 2 --> Check that inner classes do not inherit from Annotation
*/
def typedTemplate(templ: Template, parents1: List[Tree]): Template = {
val clazz = context.owner
@@ -1997,7 +1913,7 @@ trait Typers extends Modes with Adaptations with Tags {
}
}
- treeCopy.Template(templ, parents1, self1, body1) setType clazz.tpe
+ treeCopy.Template(templ, parents1, self1, body1) setType clazz.tpe_*
}
/** Remove definition annotations from modifiers (they have been saved
@@ -2015,26 +1931,18 @@ trait Typers extends Modes with Adaptations with Tags {
def typedModifiers(mods: Modifiers): Modifiers =
mods.copy(annotations = Nil) setPositions mods.positions
- /**
- * @param vdef ...
- * @return ...
- */
def typedValDef(vdef: ValDef): ValDef = {
-// attributes(vdef)
val sym = vdef.symbol.initialize
val typer1 = constrTyperIf(sym.isParameter && sym.owner.isConstructor)
val typedMods = typedModifiers(vdef.mods)
sym.annotations.map(_.completeInfo)
- var tpt1 = checkNoEscaping.privates(sym, typer1.typedType(vdef.tpt))
+ val tpt1 = checkNoEscaping.privates(sym, typer1.typedType(vdef.tpt))
checkNonCyclic(vdef, tpt1)
- if (sym.hasAnnotation(definitions.VolatileAttr)) {
- if (!sym.isMutable)
+ if (sym.hasAnnotation(definitions.VolatileAttr) && !sym.isMutable)
VolatileValueError(vdef)
- else if (sym.isFinal)
- FinalVolatileVarError(vdef)
- }
+
val rhs1 =
if (vdef.rhs.isEmpty) {
if (sym.isVariable && sym.owner.isTerm && !sym.isLazy && !isPastTyper)
@@ -2063,10 +1971,6 @@ trait Typers extends Modes with Adaptations with Tags {
}
/** Enter all aliases of local parameter accessors.
- *
- * @param clazz ...
- * @param vparamss ...
- * @param rhs ...
*/
def computeParamAliases(clazz: Symbol, vparamss: List[List[ValDef]], rhs: Tree) {
debuglog(s"computing param aliases for $clazz:${clazz.primaryConstructor.tpe}:$rhs")
@@ -2161,7 +2065,7 @@ trait Typers extends Modes with Adaptations with Tags {
f(subTree)
}
- /** Check if a structurally defined method violates implementation restrictions.
+ /** Check if a structurally defined method violates implementation restrictions.
* A method cannot be called if it is a non-private member of a refinement type
* and if its parameter's types are any of:
* - the self-type of the refinement
@@ -2219,18 +2123,14 @@ trait Typers extends Modes with Adaptations with Tags {
val enclClass = context.enclClass.owner
def defineAlias(name: Name) =
if (context.scope.lookup(name) == NoSymbol) {
- lookupVariable(name.toString.substring(1), enclClass) match {
- case Some(repl) =>
- silent(_.typedTypeConstructor(stringParser(repl).typ())) match {
- case SilentResultValue(tpt) =>
- val alias = enclClass.newAliasType(name.toTypeName, useCase.pos)
- val tparams = cloneSymbolsAtOwner(tpt.tpe.typeSymbol.typeParams, alias)
- val newInfo = genPolyType(tparams, appliedType(tpt.tpe, tparams map (_.tpe)))
- alias setInfo newInfo
- context.scope.enter(alias)
- case _ =>
- }
- case _ =>
+ lookupVariable(name.toString.substring(1), enclClass) foreach { repl =>
+ silent(_.typedTypeConstructor(stringParser(repl).typ())) map { tpt =>
+ val alias = enclClass.newAliasType(name.toTypeName, useCase.pos)
+ val tparams = cloneSymbolsAtOwner(tpt.tpe.typeSymbol.typeParams, alias)
+ val newInfo = genPolyType(tparams, appliedType(tpt.tpe, tparams map (_.tpe)))
+ alias setInfo newInfo
+ context.scope.enter(alias)
+ }
}
}
for (tree <- trees; t <- tree)
@@ -2246,10 +2146,6 @@ trait Typers extends Modes with Adaptations with Tags {
useCase.defined foreach (sym => println("defined use cases: %s:%s".format(sym, sym.tpe)))
}
- /**
- * @param ddef ...
- * @return ...
- */
def typedDefDef(ddef: DefDef): DefDef = {
val meth = ddef.symbol.initialize
@@ -2274,7 +2170,7 @@ trait Typers extends Modes with Adaptations with Tags {
if (isRepeatedParamType(vparam1.symbol.tpe))
StarParamNotLastError(vparam1)
- var tpt1 = checkNoEscaping.privates(meth, typedType(ddef.tpt))
+ val tpt1 = checkNoEscaping.privates(meth, typedType(ddef.tpt))
checkNonCyclic(ddef, tpt1)
ddef.tpt.setType(tpt1.tpe)
val typedMods = typedModifiers(ddef.mods)
@@ -2379,7 +2275,7 @@ trait Typers extends Modes with Adaptations with Tags {
if (!nme.isLoopHeaderLabel(ldef.symbol.name) || isPastTyper) {
val restpe = ldef.symbol.tpe.resultType
val rhs1 = typed(ldef.rhs, restpe)
- ldef.params foreach (param => param.tpe = param.symbol.tpe)
+ ldef.params foreach (param => param setType param.symbol.tpe)
deriveLabelDef(ldef)(_ => rhs1) setType restpe
}
else {
@@ -2387,25 +2283,19 @@ trait Typers extends Modes with Adaptations with Tags {
val rhs1 = typed(ldef.rhs)
val restpe = rhs1.tpe
if (restpe == initpe) { // stable result, no need to check again
- ldef.params foreach (param => param.tpe = param.symbol.tpe)
+ ldef.params foreach (param => param setType param.symbol.tpe)
treeCopy.LabelDef(ldef, ldef.name, ldef.params, rhs1) setType restpe
} else {
context.scope.unlink(ldef.symbol)
val sym2 = namer.enterInScope(
context.owner.newLabel(ldef.name, ldef.pos) setInfo MethodType(List(), restpe))
val rhs2 = typed(resetAllAttrs(ldef.rhs), restpe)
- ldef.params foreach (param => param.tpe = param.symbol.tpe)
+ ldef.params foreach (param => param setType param.symbol.tpe)
deriveLabelDef(ldef)(_ => rhs2) setSymbol sym2 setType restpe
}
}
}
- /**
- * @param block ...
- * @param mode ...
- * @param pt ...
- * @return ...
- */
def typedBlock(block: Block, mode: Int, pt: Type): Block = {
val syntheticPrivates = new ListBuffer[Symbol]
try {
@@ -2478,12 +2368,6 @@ trait Typers extends Modes with Adaptations with Tags {
}
}
- /**
- * @param cdef ...
- * @param pattpe ...
- * @param pt ...
- * @return ...
- */
def typedCase(cdef: CaseDef, pattpe: Type, pt: Type): CaseDef = {
// verify no _* except in last position
for (Apply(_, xs) <- cdef.pat ; x <- xs dropRight 1 ; if treeInfo isStar x)
@@ -2512,7 +2396,7 @@ trait Typers extends Modes with Adaptations with Tags {
val contextWithTypeBounds = context.nextEnclosing(_.tree.isInstanceOf[CaseDef])
if (contextWithTypeBounds.savedTypeBounds.nonEmpty) {
- body1.tpe = contextWithTypeBounds restoreTypeBounds body1.tpe
+ body1 modifyType (contextWithTypeBounds restoreTypeBounds _)
// insert a cast if something typechecked under the GADT constraints,
// but not in real life (i.e., now that's we've reset the method's type skolems'
@@ -2557,7 +2441,7 @@ trait Typers extends Modes with Adaptations with Tags {
val casesTyped = typedCases(cases, selectorTp, pt)
val (resTp, needAdapt) =
- if (opt.virtPatmat) ptOrLubPacked(casesTyped, pt)
+ if (!settings.XoldPatmat.value) ptOrLubPacked(casesTyped, pt)
else ptOrLub(casesTyped map (_.tpe), pt)
val casesAdapted = if (!needAdapt) casesTyped else casesTyped map (adaptCase(_, mode, resTp))
@@ -2569,15 +2453,12 @@ trait Typers extends Modes with Adaptations with Tags {
// (virtualized matches are expanded during type checking so they have the full context available)
// otherwise, do nothing: matches are translated during phase `patmat` (unless -Xoldpatmat)
def virtualizedMatch(match_ : Match, mode: Int, pt: Type) = {
- import patmat.{vpmName, PureMatchTranslator, OptimizingMatchTranslator}
+ import patmat.{ vpmName, PureMatchTranslator }
// TODO: add fallback __match sentinel to predef
val matchStrategy: Tree =
- if (!(newPatternMatching && opt.experimental && context.isNameInScope(vpmName._match))) null // fast path, avoiding the next line if there's no __match to be seen
- else newTyper(context.makeImplicit(reportAmbiguousErrors = false)).silent(_.typed(Ident(vpmName._match), EXPRmode, WildcardType), reportAmbiguousErrors = false) match {
- case SilentResultValue(ms) => ms
- case _ => null
- }
+ if (!(newPatternMatching && settings.Xexperimental.value && context.isNameInScope(vpmName._match))) null // fast path, avoiding the next line if there's no __match to be seen
+ else newTyper(context.makeImplicit(reportAmbiguousErrors = false)).silent(_.typed(Ident(vpmName._match), EXPRmode, WildcardType), reportAmbiguousErrors = false) orElse (_ => null)
if (matchStrategy ne null) // virtualize
typed((new PureMatchTranslator(this.asInstanceOf[patmat.global.analyzer.Typer] /*TODO*/, matchStrategy)).translateMatch(match_), mode, pt)
@@ -2603,7 +2484,6 @@ trait Typers extends Modes with Adaptations with Tags {
assert(isPartial)
private val anonClass = context.owner.newAnonymousFunctionClass(tree.pos)
- private val funThis = This(anonClass)
anonClass addAnnotation AnnotationInfo(SerialVersionUIDAttr.tpe, List(Literal(Constant(0))), List())
@@ -2625,7 +2505,7 @@ trait Typers extends Modes with Adaptations with Tags {
import CODE._
// need to duplicate the cases before typing them to generate the apply method, or the symbols will be all messed up
- val casesTrue = if (isPartial) cases map (c => deriveCaseDef(c)(x => atPos(x.pos.focus)(TRUE_typed)).duplicate.asInstanceOf[CaseDef]) else Nil
+ val casesTrue = if (isPartial) cases map (c => deriveCaseDef(c)(x => atPos(x.pos.focus)(TRUE)).duplicate.asInstanceOf[CaseDef]) else Nil
// println("casesTrue "+ casesTrue)
def parentsPartial(targs: List[Type]) = addSerializable(appliedType(AbstractPartialFunctionClass.typeConstructor, targs))
@@ -2711,7 +2591,7 @@ trait Typers extends Modes with Adaptations with Tags {
methodSym setInfoAndEnter MethodType(paramSyms, BooleanClass.tpe)
val match_ = methodBodyTyper.typedMatch(gen.mkUnchecked(selector), casesTrue, mode, BooleanClass.tpe)
- val body = methodBodyTyper.virtualizedMatch(match_ updateAttachment DefaultOverrideMatchAttachment(FALSE_typed), mode, BooleanClass.tpe)
+ val body = methodBodyTyper.virtualizedMatch(match_ updateAttachment DefaultOverrideMatchAttachment(FALSE), mode, BooleanClass.tpe)
DefDef(methodSym, body)
}
@@ -2753,12 +2633,6 @@ trait Typers extends Modes with Adaptations with Tags {
override def mkSel(params: List[Symbol]) = sel.duplicate
}
- /**
- * @param fun ...
- * @param mode ...
- * @param pt ...
- * @return ...
- */
private def typedFunction(fun: Function, mode: Int, pt: Type): Tree = {
val numVparams = fun.vparams.length
if (numVparams > definitions.MaxFunctionArity)
@@ -2784,15 +2658,13 @@ trait Typers extends Modes with Adaptations with Tags {
else {
fun match {
case etaExpansion(vparams, fn, args) =>
- silent(_.typed(fn, forFunMode(mode), pt)) match {
- case SilentResultValue(fn1) if context.undetparams.isEmpty =>
- // if context,undetparams is not empty, the function was polymorphic,
- // so we need the missing arguments to infer its type. See #871
- //println("typing eta "+fun+":"+fn1.tpe+"/"+context.undetparams)
- val ftpe = normalize(fn1.tpe) baseType FunctionClass(numVparams)
- if (isFunctionType(ftpe) && isFullyDefined(ftpe))
- return typedFunction(fun, mode, ftpe)
- case _ =>
+ silent(_.typed(fn, forFunMode(mode), pt)) filter (_ => context.undetparams.isEmpty) map { fn1 =>
+ // if context,undetparams is not empty, the function was polymorphic,
+ // so we need the missing arguments to infer its type. See #871
+ //println("typing eta "+fun+":"+fn1.tpe+"/"+context.undetparams)
+ val ftpe = normalize(fn1.tpe) baseType FunctionClass(numVparams)
+ if (isFunctionType(ftpe) && isFullyDefined(ftpe))
+ return typedFunction(fun, mode, ftpe)
}
case _ =>
}
@@ -2818,16 +2690,13 @@ trait Typers extends Modes with Adaptations with Tags {
if (context.retyping) context.scope enter vparam.symbol
vparam.symbol
}
- val vparams = fun.vparams mapConserve (typedValDef)
- // for (vparam <- vparams) {
- // checkNoEscaping.locals(context.scope, WildcardType, vparam.tpt); ()
- // }
+ val vparams = fun.vparams mapConserve typedValDef
val formals = vparamSyms map (_.tpe)
- val body1 = typed(fun.body, respt)
- val restpe = packedType(body1, fun.symbol).deconst.resultType
- val funtpe = typeRef(clazz.tpe.prefix, clazz, formals :+ restpe)
- // body = checkNoEscaping.locals(context.scope, restpe, body)
- treeCopy.Function(fun, vparams, body1).setType(funtpe)
+ val body1 = typed(fun.body, respt)
+ val restpe = packedType(body1, fun.symbol).deconst.resultType
+ val funtpe = appliedType(clazz, formals :+ restpe: _*)
+
+ treeCopy.Function(fun, vparams, body1) setType funtpe
}
}
}
@@ -2859,17 +2728,6 @@ trait Typers extends Modes with Adaptations with Tags {
case Some(imp1: Import) => imp1
case _ => log("unhandled import: "+imp+" in "+unit); imp
}
- private def isWarnablePureExpression(tree: Tree) = tree match {
- case EmptyTree | Literal(Constant(())) => false
- case _ =>
- !tree.isErrorTyped && (treeInfo isExprSafeToInline tree) && {
- val sym = tree.symbol
- (sym == null) || !(sym.isModule || sym.isLazy) || {
- debuglog("'Pure' but side-effecting expression in statement position: " + tree)
- false
- }
- }
- }
def typedStats(stats: List[Tree], exprOwner: Symbol): List[Tree] = {
val inBlock = exprOwner == context.owner
@@ -2906,7 +2764,7 @@ trait Typers extends Modes with Adaptations with Tags {
ConstructorsOrderError(stat)
}
- if (isWarnablePureExpression(result)) context.warning(stat.pos,
+ if (treeInfo.isPureExprForWarningPurposes(result)) context.warning(stat.pos,
"a pure expression does nothing in statement position; " +
"you may be omitting necessary parentheses"
)
@@ -2957,7 +2815,7 @@ trait Typers extends Modes with Adaptations with Tags {
// SI-5877 The decls of a package include decls of the package object. But we don't want to add
// the corresponding synthetics to the package class, only to the package object class.
def shouldAdd(sym: Symbol) =
- inBlock || !isInPackageObject(sym, context.owner)
+ inBlock || !context.isInPackageObject(sym, context.owner)
for (sym <- scope if shouldAdd(sym))
for (tree <- context.unit.synthetics get sym) {
newStats += typedStat(tree) // might add even more synthetics to the scope
@@ -3094,21 +2952,20 @@ trait Typers extends Modes with Adaptations with Tags {
def duplErrorTree(err: AbsTypeError) = { issue(err); duplErrTree }
def preSelectOverloaded(fun: Tree): Tree = {
- if (fun.hasSymbol && fun.symbol.isOverloaded) {
+ if (fun.hasSymbolField && fun.symbol.isOverloaded) {
// remove alternatives with wrong number of parameters without looking at types.
- // less expensive than including them in inferMethodAlternatvie (see below).
+ // less expensive than including them in inferMethodAlternative (see below).
def shapeType(arg: Tree): Type = arg match {
case Function(vparams, body) =>
- functionType(vparams map (vparam => AnyClass.tpe), shapeType(body))
+ functionType(vparams map (_ => AnyClass.tpe), shapeType(body))
case AssignOrNamedArg(Ident(name), rhs) =>
NamedType(name, shapeType(rhs))
case _ =>
NothingClass.tpe
}
val argtypes = args map shapeType
- val pre = fun.symbol.tpe.prefix
-
- var sym = fun.symbol filter { alt =>
+ val pre = fun.symbol.tpe.prefix
+ var sym = fun.symbol filter { alt =>
// must use pt as expected type, not WildcardType (a tempting quick fix to #2665)
// now fixed by using isWeaklyCompatible in exprTypeArgs
// TODO: understand why exactly -- some types were not inferred anymore (`ant clean quick.bin` failed)
@@ -3119,16 +2976,15 @@ trait Typers extends Modes with Adaptations with Tags {
// Types: "refs = Array(Map(), Map())". I determined that inference fails if there are at
// least two invariant type parameters. See the test case I checked in to help backstop:
// pos/isApplicableSafe.scala.
- isApplicableSafe(context.undetparams, followApply(pre.memberType(alt)), argtypes, pt)
+ isApplicableSafe(context.undetparams, followApply(pre memberType alt), argtypes, pt)
}
if (sym.isOverloaded) {
- val sym1 = sym filter (alt => {
- // eliminate functions that would result from tupling transforms
- // keeps alternatives with repeated params
- hasExactlyNumParams(followApply(alt.tpe), argtypes.length) ||
- // also keep alts which define at least one default
- alt.tpe.paramss.exists(_.exists(_.hasDefault))
- })
+ // eliminate functions that would result from tupling transforms
+ // keeps alternatives with repeated params
+ val sym1 = sym filter (alt =>
+ isApplicableBasedOnArity(pre memberType alt, argtypes.length, varargsStar = false, tuplingAllowed = false)
+ || alt.tpe.params.exists(_.hasDefault)
+ )
if (sym1 != NoSymbol) sym = sym1
}
if (sym == NoSymbol) fun
@@ -3142,16 +2998,19 @@ trait Typers extends Modes with Adaptations with Tags {
case OverloadedType(pre, alts) =>
def handleOverloaded = {
val undetparams = context.extractUndetparams()
-
- val argtpes = new ListBuffer[Type]
- val amode = forArgMode(fun, mode)
+ val argtpes = new ListBuffer[Type]
+ val amode = forArgMode(fun, mode)
val args1 = args map {
case arg @ AssignOrNamedArg(Ident(name), rhs) =>
// named args: only type the righthand sides ("unknown identifier" errors otherwise)
val rhs1 = typedArg(rhs, amode, BYVALmode, WildcardType)
argtpes += NamedType(name, rhs1.tpe.deconst)
// the assign is untyped; that's ok because we call doTypedApply
- atPos(arg.pos) { new AssignOrNamedArg(arg.lhs, rhs1) }
+ treeCopy.AssignOrNamedArg(arg, arg.lhs, rhs1)
+ case arg @ Typed(repeated, Ident(tpnme.WILDCARD_STAR)) =>
+ val arg1 = typedArg(arg, amode, BYVALmode, WildcardType)
+ argtpes += RepeatedType(arg1.tpe.deconst)
+ arg1
case arg =>
val arg1 = typedArg(arg, amode, BYVALmode, WildcardType)
argtpes += arg1.tpe.deconst
@@ -3161,7 +3020,7 @@ trait Typers extends Modes with Adaptations with Tags {
if (context.hasErrors)
setError(tree)
else {
- inferMethodAlternative(fun, undetparams, argtpes.toList, pt, varArgsOnly = treeInfo.isWildcardStarArgList(args))
+ inferMethodAlternative(fun, undetparams, argtpes.toList, pt)
doTypedApply(tree, adapt(fun, forFunMode(mode), WildcardType), args1, mode, pt)
}
}
@@ -3170,22 +3029,20 @@ trait Typers extends Modes with Adaptations with Tags {
case mt @ MethodType(params, _) =>
val paramTypes = mt.paramTypes
// repeat vararg as often as needed, remove by-name
- val formals = formalTypes(paramTypes, args.length)
+ val argslen = args.length
+ val formals = formalTypes(paramTypes, argslen)
/** Try packing all arguments into a Tuple and apply `fun`
* to that. This is the last thing which is tried (after
* default arguments)
*/
- def tryTupleApply: Option[Tree] = {
- // if 1 formal, 1 arg (a tuple), otherwise unmodified args
- val tupleArgs = actualArgs(tree.pos.makeTransparent, args, formals.length)
-
- if (!sameLength(tupleArgs, args) && !isUnitForVarArgs(args, params)) {
+ def tryTupleApply: Option[Tree] = (
+ if (eligibleForTupleConversion(paramTypes, argslen) && !phase.erasedTypes) {
+ val tupleArgs = List(atPos(tree.pos.makeTransparent)(gen.mkTuple(args)))
// expected one argument, but got 0 or >1 ==> try applying to tuple
// the inner "doTypedApply" does "extractUndetparams" => restore when it fails
val savedUndetparams = context.undetparams
- silent(_.doTypedApply(tree, fun, tupleArgs, mode, pt)) match {
- case SilentResultValue(t) =>
+ silent(_.doTypedApply(tree, fun, tupleArgs, mode, pt)) map { t =>
// Depending on user options, may warn or error here if
// a Unit or tuple was inserted.
Some(t) filter (tupledTree =>
@@ -3193,12 +3050,10 @@ trait Typers extends Modes with Adaptations with Tags {
|| tupledTree.symbol == null
|| checkValidAdaptation(tupledTree, args)
)
- case _ =>
- context.undetparams = savedUndetparams
- None
- }
- } else None
- }
+ } orElse { _ => context.undetparams = savedUndetparams ; None }
+ }
+ else None
+ )
/** Treats an application which uses named or default arguments.
* Also works if names + a vararg used: when names are used, the vararg
@@ -3315,26 +3170,6 @@ trait Typers extends Modes with Adaptations with Tags {
case _ => tp
}
- // Replace the Delegate-Chainer methods += and -= with corresponding
- // + and - calls, which are translated in the code generator into
- // Combine and Remove
- if (forMSIL) {
- fun match {
- case Select(qual, name) =>
- if (isSubType(qual.tpe, DelegateClass.tpe)
- && (name == encode("+=") || name == encode("-="))) {
- val n = if (name == encode("+=")) nme.PLUS else nme.MINUS
- val f = Select(qual, n)
- // the compiler thinks, the PLUS method takes only one argument,
- // but he thinks it's an instance method -> still two ref's on the stack
- // -> translated by backend
- val rhs = treeCopy.Apply(tree, f, args)
- return typed(Assign(qual, rhs))
- }
- case _ => ()
- }
- }
-
/**
* This is translating uses of List() into Nil. This is less
* than ideal from a consistency standpoint, but it shouldn't be
@@ -3375,15 +3210,14 @@ trait Typers extends Modes with Adaptations with Tags {
} else arg1
}
val args1 = map2(args, formals)(typedArgToPoly)
- if (args1 exists { _.isErrorTyped }) duplErrTree
+ if (args1 exists {_.isErrorTyped}) duplErrTree
else {
- debuglog("infer method inst " + fun + ", tparams = " + tparams + ", args = " + args1.map(_.tpe) + ", pt = " + pt + ", lobounds = " + tparams.map(_.tpe.bounds.lo) + ", parambounds = " + tparams.map(_.info)) //debug
+ debuglog("infer method inst "+fun+", tparams = "+tparams+", args = "+args1.map(_.tpe)+", pt = "+pt+", lobounds = "+tparams.map(_.tpe.bounds.lo)+", parambounds = "+tparams.map(_.info)) //debug
// define the undetparams which have been fixed by this param list, replace the corresponding symbols in "fun"
// returns those undetparams which have not been instantiated.
val undetparams = inferMethodInstance(fun, tparams, args1, pt)
- val result = doTypedApply(tree, fun, args1, mode, pt)
- context.undetparams = undetparams
- result
+ try doTypedApply(tree, fun, args1, mode, pt)
+ finally context.undetparams = undetparams
}
}
handlePolymorphicCall
@@ -3440,7 +3274,7 @@ trait Typers extends Modes with Adaptations with Tags {
else None
if (!isApplicableSafe(Nil, unappType, List(pt), WildcardType)) {
- //Console.println("UNAPP: need to typetest, arg.tpe = "+arg.tpe+", unappType = "+unappType)
+ //Console.println(s"UNAPP: need to typetest, arg: ${arg.tpe} unappType: $unappType")
val (freeVars, unappFormal) = freshArgType(unappType.skolemizeExistential(context.owner, tree))
val unapplyContext = context.makeNewScope(context.tree, context.owner)
freeVars foreach unapplyContext.scope.enter
@@ -3450,12 +3284,12 @@ trait Typers extends Modes with Adaptations with Tags {
// turn any unresolved type variables in freevars into existential skolems
val skolems = freeVars map (fv => unapplyContext.owner.newExistentialSkolem(fv, fv))
- arg.tpe = pattp.substSym(freeVars, skolems)
+ arg setType pattp.substSym(freeVars, skolems)
argDummy setInfo arg.tpe
}
- // setType null is necessary so that ref will be stabilized; see bug 881
- val fun1 = typedPos(fun.pos)(Apply(Select(fun setType null, unapp), List(arg)))
+ // clearing the type is necessary so that ref will be stabilized; see bug 881
+ val fun1 = typedPos(fun.pos)(Apply(Select(fun.clearType(), unapp), List(arg)))
if (fun1.tpe.isErroneous) duplErrTree
else {
@@ -3466,13 +3300,10 @@ trait Typers extends Modes with Adaptations with Tags {
if (formals == null) duplErrorTree(WrongNumberOfArgsError(tree, fun))
else {
val args1 = typedArgs(args, mode, formals, formalsExpanded)
- // This used to be the following (failing) assert:
- // assert(isFullyDefined(pt), tree+" ==> "+UnApply(fun1, args1)+", pt = "+pt)
- // I modified as follows. See SI-1048.
- val pt1 = if (isFullyDefined(pt)) pt else makeFullyDefined(pt)
+ val pt1 = if (isFullyDefined(pt)) pt else makeFullyDefined(pt) // SI-1048
val itype = glb(List(pt1, arg.tpe))
- arg.tpe = pt1 // restore type (arg is a dummy tree, just needs to pass typechecking)
+ arg setType pt1 // restore type (arg is a dummy tree, just needs to pass typechecking)
val unapply = UnApply(fun1, args1) setPos tree.pos setType itype
// if the type that the unapply method expects for its argument is uncheckable, wrap in classtag extractor
@@ -3507,16 +3338,16 @@ trait Typers extends Modes with Adaptations with Tags {
// if there's a ClassTag that allows us to turn the unchecked type test for `pt` into a checked type test
// return the corresponding extractor (an instance of ClassTag[`pt`])
- def extractorForUncheckedType(pos: Position, pt: Type): Option[Tree] = if (!opt.virtPatmat || isPastTyper) None else {
+ def extractorForUncheckedType(pos: Position, pt: Type): Option[Tree] = if (settings.XoldPatmat.value || isPastTyper) None else {
// only look at top-level type, can't (reliably) do anything about unchecked type args (in general)
pt.normalize.typeConstructor match {
// if at least one of the types in an intersection is checkable, use the checkable ones
// this avoids problems as in run/matchonseq.scala, where the expected type is `Coll with scala.collection.SeqLike`
// Coll is an abstract type, but SeqLike of course is not
- case RefinedType(parents, _) if (parents.length >= 2) && (parents.exists(tp => !infer.containsUnchecked(tp))) =>
+ case RefinedType(ps, _) if ps.length > 1 && (ps exists infer.isCheckable) =>
None
- case ptCheckable if infer.containsUnchecked(ptCheckable) =>
+ case ptCheckable if infer isUncheckable ptCheckable =>
val classTagExtractor = resolveClassTag(pos, ptCheckable)
if (classTagExtractor != EmptyTree && unapplyMember(classTagExtractor.tpe) != NoSymbol)
@@ -3680,35 +3511,23 @@ trait Typers extends Modes with Adaptations with Tags {
// local dummy fixes SI-5544
val localTyper = newTyper(context.make(ann, context.owner.newLocalDummy(ann.pos)))
localTyper.typed(ann, mode, annClass.tpe)
- } else {
- // Since a selfsym is supplied, the annotation should have
- // an extra "self" identifier in scope for type checking.
- // This is implemented by wrapping the rhs
- // in a function like "self => rhs" during type checking,
- // and then stripping the "self =>" and substituting
- // in the supplied selfsym.
+ }
+ else {
+ // Since a selfsym is supplied, the annotation should have an extra
+ // "self" identifier in scope for type checking. This is implemented
+ // by wrapping the rhs in a function like "self => rhs" during type
+ // checking, and then stripping the "self =>" and substituting in
+ // the supplied selfsym.
val funcparm = ValDef(NoMods, nme.self, TypeTree(selfsym.info), EmptyTree)
- val func = Function(List(funcparm), ann.duplicate)
- // The .duplicate of annot.constr
- // deals with problems that
- // accur if this annotation is
- // later typed again, which
- // the compiler sometimes does.
- // The problem is that "self"
- // ident's within annot.constr
- // will retain the old symbol
- // from the previous typing.
- val fun1clazz = FunctionClass(1)
- val funcType = typeRef(fun1clazz.tpe.prefix,
- fun1clazz,
- List(selfsym.info, annClass.tpe))
-
- (typed(func, mode, funcType): @unchecked) match {
- case t @ Function(List(arg), rhs) =>
- val subs =
- new TreeSymSubstituter(List(arg.symbol),List(selfsym))
- subs(rhs)
- }
+ // The .duplicate of annot.constr deals with problems that accur
+ // if this annotation is later typed again, which the compiler
+ // sometimes does. The problem is that "self" ident's within
+ // annot.constr will retain the old symbol from the previous typing.
+ val func = Function(funcparm :: Nil, ann.duplicate)
+ val funcType = appliedType(FunctionClass(1), selfsym.info, annClass.tpe_*)
+ val Function(arg :: Nil, rhs) = typed(func, mode, funcType)
+
+ rhs.substituteSymbols(arg.symbol :: Nil, selfsym :: Nil)
}
def annInfo(t: Tree): AnnotationInfo = t match {
@@ -3929,11 +3748,11 @@ trait Typers extends Modes with Adaptations with Tags {
if (wc.symbol == NoSymbol) { namer.enterSym(wc); wc.symbol setFlag EXISTENTIAL }
else context.scope enter wc.symbol
val whereClauses1 = typedStats(tree.whereClauses, context.owner)
- for (vd @ ValDef(_, _, _, _) <- tree.whereClauses)
+ for (vd @ ValDef(_, _, _, _) <- whereClauses1)
if (vd.symbol.tpe.isVolatile)
AbstractionFromVolatileTypeError(vd)
val tpt1 = typedType(tree.tpt, mode)
- existentialTransform(tree.whereClauses map (_.symbol), tpt1.tpe)((tparams, tp) =>
+ existentialTransform(whereClauses1 map (_.symbol), tpt1.tpe)((tparams, tp) =>
TypeTree(newExistentialType(tparams, tp)) setOriginal tree
)
}
@@ -4098,12 +3917,8 @@ trait Typers extends Modes with Adaptations with Tags {
}
}
- def wrapErrors(tree: Tree, typeTree: Typer => Tree): Tree = {
- silent(typeTree) match {
- case SilentResultValue(r) => r
- case SilentTypeError(err) => DynamicRewriteError(tree, err)
- }
- }
+ def wrapErrors(tree: Tree, typeTree: Typer => Tree): Tree =
+ silent(typeTree) orElse (err => DynamicRewriteError(tree, err))
}
final def deindentTyping() = context.typingIndentLevel -= 2
@@ -4119,14 +3934,24 @@ trait Typers extends Modes with Adaptations with Tags {
def typed1(tree: Tree, mode: Int, pt: Type): Tree = {
def isPatternMode = inPatternMode(mode)
-
- //Console.println("typed1("+tree.getClass()+","+Integer.toHexString(mode)+","+pt+")")
- //@M! get the type of the qualifier in a Select tree, otherwise: NoType
- def prefixType(fun: Tree): Type = fun match {
- case Select(qualifier, _) => qualifier.tpe
-// case Ident(name) => ??
- case _ => NoType
- }
+ def inPatternConstructor = inAllModes(mode, PATTERNmode | FUNmode)
+ def isQualifierMode = (mode & QUALmode) != 0
+
+ // Lookup in the given class using the root mirror.
+ def lookupInOwner(owner: Symbol, name: Name): Symbol =
+ if (isQualifierMode) rootMirror.missingHook(owner, name) else NoSymbol
+
+ // Lookup in the given qualifier. Used in last-ditch efforts by typedIdent and typedSelect.
+ def lookupInRoot(name: Name): Symbol = lookupInOwner(rootMirror.RootClass, name)
+ def lookupInEmpty(name: Name): Symbol = lookupInOwner(rootMirror.EmptyPackageClass, name)
+ def lookupInQualifier(qual: Tree, name: Name): Symbol = (
+ if (name == nme.ERROR || qual.tpe.widen.isErroneous)
+ NoSymbol
+ else lookupInOwner(qual.tpe.typeSymbol, name) orElse {
+ NotAMemberError(tree, qual, name)
+ NoSymbol
+ }
+ )
def typedAnnotated(atd: Annotated): Tree = {
val ann = atd.annot
@@ -4191,7 +4016,7 @@ trait Typers extends Modes with Adaptations with Tags {
// Erroneous annotations were already reported in typedAnnotation
arg1 // simply drop erroneous annotations
else {
- ann.tpe = atype
+ ann setType atype
resultingTypeTree(atype)
}
} else {
@@ -4202,7 +4027,7 @@ trait Typers extends Modes with Adaptations with Tags {
else {
if (ann.tpe == null) {
val annotInfo = typedAnnotation(ann, annotMode)
- ann.tpe = arg1.tpe.withAnnotation(annotInfo)
+ ann setType arg1.tpe.withAnnotation(annotInfo)
}
val atype = ann.tpe
Typed(arg1, resultingTypeTree(atype)) setPos tree.pos setType atype
@@ -4226,7 +4051,7 @@ trait Typers extends Modes with Adaptations with Tags {
if (name != tpnme.WILDCARD) namer.enterInScope(sym)
else context.scope.enter(sym)
- tree setSymbol sym setType sym.tpe
+ tree setSymbol sym setType sym.tpeHK
case name: TermName =>
val sym =
@@ -4322,7 +4147,7 @@ trait Typers extends Modes with Adaptations with Tags {
// in the special (though common) case where the types are equal, it pays to pack before comparing
// especially virtpatmat needs more aggressive unification of skolemized types
// this breaks src/library/scala/collection/immutable/TrieIterator.scala
- if ( opt.virtPatmat && !isPastTyper
+ if ( !settings.XoldPatmat.value && !isPastTyper
&& thenp1.tpe.annotations.isEmpty && elsep1.tpe.annotations.isEmpty // annotated types need to be lubbed regardless (at least, continations break if you by pass them like this)
&& thenTp =:= elseTp
) (thenp1.tpe.deconst, false) // use unpacked type. Important to deconst, as is done in ptOrLub, otherwise `if (???) 0 else 0` evaluates to 0 (SI-6331)
@@ -4395,7 +4220,7 @@ trait Typers extends Modes with Adaptations with Tags {
val tpt1 = {
val tpt0 = typedTypeConstructor(tpt)
if (checkStablePrefixClassType(tpt0))
- if (tpt0.hasSymbol && !tpt0.symbol.typeParams.isEmpty) {
+ if (tpt0.hasSymbolField && !tpt0.symbol.typeParams.isEmpty) {
context.undetparams = cloneSymbols(tpt0.symbol.typeParams)
notifyUndetparamsAdded(context.undetparams)
TypeTree().setOriginal(tpt0)
@@ -4425,7 +4250,7 @@ trait Typers extends Modes with Adaptations with Tags {
NotAMemberError(tpt, TypeTree(tp), nme.CONSTRUCTOR)
setError(tpt)
}
- else if (!( tp == sym.thisSym.tpe // when there's no explicit self type -- with (#3612) or without self variable
+ else if (!( tp == sym.thisSym.tpe_* // when there's no explicit self type -- with (#3612) or without self variable
// sym.thisSym.tpe == tp.typeOfThis (except for objects)
|| narrowRhs(tp) <:< tp.typeOfThis
|| phase.erasedTypes
@@ -4449,34 +4274,13 @@ trait Typers extends Modes with Adaptations with Tags {
else adapt(expr1, mode, functionType(formals map (t => WildcardType), WildcardType))
case MethodType(formals, _) =>
if (isFunctionType(pt)) expr1
- else expr1 match {
- case Select(qual, name) if (forMSIL &&
- pt != WildcardType &&
- pt != ErrorType &&
- isSubType(pt, DelegateClass.tpe)) =>
- val scalaCaller = newScalaCaller(pt)
- addScalaCallerInfo(scalaCaller, expr1.symbol)
- val n: Name = scalaCaller.name
- val del = Ident(DelegateClass) setType DelegateClass.tpe
- val f = Select(del, n)
- //val f1 = TypeApply(f, List(Ident(pt.symbol) setType pt))
- val args: List[Tree] = if(expr1.symbol.isStatic) List(Literal(Constant(null)))
- else List(qual) // where the scala-method is located
- val rhs = Apply(f, args)
- typed(rhs)
- case _ =>
- adapt(expr1, mode, functionType(formals map (t => WildcardType), WildcardType))
- }
+ else adapt(expr1, mode, functionType(formals map (t => WildcardType), WildcardType))
case ErrorType =>
expr1
case _ =>
UnderscoreEtaError(expr1)
}
- /**
- * @param args ...
- * @return ...
- */
def tryTypedArgs(args: List[Tree], mode: Int): Option[List[Tree]] = {
val c = context.makeSilent(false)
c.retyping = true
@@ -4550,12 +4354,7 @@ trait Typers extends Modes with Adaptations with Tags {
setError(treeCopy.Apply(tree, fun, args))
}
- silent(_.doTypedApply(tree, fun, args, mode, pt)) match {
- case SilentResultValue(t) =>
- t
- case SilentTypeError(err) =>
- onError(err)
- }
+ silent(_.doTypedApply(tree, fun, args, mode, pt)) orElse onError
}
def normalTypedApply(tree: Tree, fun: Tree, args: List[Tree]) = {
@@ -4606,15 +4405,6 @@ trait Typers extends Modes with Adaptations with Tags {
if (useTry) tryTypedApply(fun2, args)
else doTypedApply(tree, fun2, args, mode, pt)
- /*
- if (fun2.hasSymbol && fun2.symbol.isConstructor && (mode & EXPRmode) != 0) {
- res.tpe = res.tpe.notNull
- }
- */
- // TODO: In theory we should be able to call:
- //if (fun2.hasSymbol && fun2.symbol.name == nme.apply && fun2.symbol.owner == ArrayClass) {
- // But this causes cyclic reference for Array class in Cleanup. It is easy to overcome this
- // by calling ArrayClass.info here (or some other place before specialize).
if (fun2.symbol == Array_apply && !res.isErrorTyped) {
val checked = gen.mkCheckInit(res)
// this check is needed to avoid infinite recursion in Duplicators
@@ -4629,37 +4419,36 @@ trait Typers extends Modes with Adaptations with Tags {
}
}
- def typedApply(tree: Apply) = {
- val fun = tree.fun
- val args = tree.args
- fun match {
- case Block(stats, expr) =>
- typed1(atPos(tree.pos)(Block(stats, Apply(expr, args) setPos tree.pos.makeTransparent)), mode, pt)
- case _ =>
- normalTypedApply(tree, fun, args) match {
- case Apply(Select(New(tpt), name), args)
- if (tpt.tpe != null &&
- tpt.tpe.typeSymbol == ArrayClass &&
- args.length == 1 &&
- erasure.GenericArray.unapply(tpt.tpe).isDefined) => // !!! todo simplify by using extractor
- // convert new Array[T](len) to evidence[ClassTag[T]].newArray(len)
- // convert new Array^N[T](len) for N > 1 to evidence[ClassTag[Array[...Array[T]...]]].newArray(len), where Array HK gets applied (N-1) times
- // [Eugene] no more MaxArrayDims. ClassTags are flexible enough to allow creation of arrays of arbitrary dimensionality (w.r.t JVM restrictions)
- val Some((level, componentType)) = erasure.GenericArray.unapply(tpt.tpe)
- val tagType = List.iterate(componentType, level)(tpe => appliedType(ArrayClass.toTypeConstructor, List(tpe))).last
- atPos(tree.pos) {
- val tag = resolveClassTag(tree.pos, tagType)
- if (tag.isEmpty) MissingClassTagError(tree, tagType)
- else typed(new ApplyToImplicitArgs(Select(tag, nme.newArray), args))
+ // convert new Array[T](len) to evidence[ClassTag[T]].newArray(len)
+ // convert new Array^N[T](len) for N > 1 to evidence[ClassTag[Array[...Array[T]...]]].newArray(len)
+ // where Array HK gets applied (N-1) times
+ object ArrayInstantiation {
+ def unapply(tree: Apply) = tree match {
+ case Apply(Select(New(tpt), name), arg :: Nil) if tpt.tpe != null && tpt.tpe.typeSymbol == ArrayClass =>
+ Some(tpt.tpe) collect {
+ case erasure.GenericArray(level, componentType) =>
+ val tagType = (1 until level).foldLeft(componentType)((res, _) => arrayType(res))
+
+ resolveClassTag(tree.pos, tagType) match {
+ case EmptyTree => MissingClassTagError(tree, tagType)
+ case tag => atPos(tree.pos)(new ApplyToImplicitArgs(Select(tag, nme.newArray), arg :: Nil))
}
- case Apply(Select(fun, nme.apply), _) if treeInfo.isSuperConstrCall(fun) => //SI-5696
- TooManyArgumentListsForConstructor(tree)
- case tree1 =>
- tree1
}
+ case _ => None
}
}
+ def typedApply(tree: Apply) = tree match {
+ case Apply(Block(stats, expr), args) =>
+ typed1(atPos(tree.pos)(Block(stats, Apply(expr, args) setPos tree.pos.makeTransparent)), mode, pt)
+ case Apply(fun, args) =>
+ normalTypedApply(tree, fun, args) match {
+ case ArrayInstantiation(tree1) => typed(tree1, mode, pt)
+ case Apply(Select(fun, nme.apply), _) if treeInfo.isSuperConstrCall(fun) => TooManyArgumentListsForConstructor(tree) //SI-5696
+ case tree1 => tree1
+ }
+ }
+
def convertToAssignment(fun: Tree, qual: Tree, name: Name, args: List[Tree]): Tree = {
val prefix = name.toTermName stripSuffix nme.EQL
def mkAssign(vble: Tree): Tree =
@@ -4713,8 +4502,6 @@ trait Typers extends Modes with Adaptations with Tags {
case This(_) => qual1.symbol
case _ => qual1.tpe.typeSymbol
}
- //println(clazz+"/"+qual1.tpe.typeSymbol+"/"+qual1)
-
def findMixinSuper(site: Type): Type = {
var ps = site.parents filter (_.typeSymbol.name == mix)
if (ps.isEmpty)
@@ -4722,11 +4509,6 @@ trait Typers extends Modes with Adaptations with Tags {
if (ps.isEmpty) {
debuglog("Fatal: couldn't find site " + site + " in " + site.parents.map(_.typeSymbol.name))
if (phase.erasedTypes && context.enclClass.owner.isImplClass) {
- // println(qual1)
- // println(clazz)
- // println(site)
- // println(site.parents)
- // println(mix)
// the reference to super class got lost during erasure
restrictionError(tree.pos, unit, "traits may not select fields or methods from super[C] where C is a class")
ErrorType
@@ -4758,14 +4540,28 @@ trait Typers extends Modes with Adaptations with Tags {
if (isStableContext(tree, mode, pt)) tree setType clazz.thisType else tree
}
- /** Attribute a selection where <code>tree</code> is <code>qual.name</code>.
- * <code>qual</code> is already attributed.
- *
- * @param qual ...
- * @param name ...
- * @return ...
+ /** Attribute a selection where `tree` is `qual.name`.
+ * `qual` is already attributed.
*/
def typedSelect(tree: Tree, qual: Tree, name: Name): Tree = {
+ val t = typedSelectInternal(tree, qual, name)
+ // Checking for OverloadedTypes being handed out after overloading
+ // resolution has already happened.
+ if (isPastTyper) t.tpe match {
+ case OverloadedType(pre, alts) =>
+ if (alts forall (s => (s.owner == ObjectClass) || (s.owner == AnyClass) || isPrimitiveValueClass(s.owner))) ()
+ else if (settings.debug.value) printCaller(
+ s"""|Select received overloaded type during $phase, but typer is over.
+ |If this type reaches the backend, we are likely doomed to crash.
+ |$t has these overloads:
+ |${alts map (s => " " + s.defStringSeenAs(pre memberType s)) mkString "\n"}
+ |""".stripMargin
+ )("")
+ case _ =>
+ }
+ t
+ }
+ def typedSelectInternal(tree: Tree, qual: Tree, name: Name): Tree = {
def asDynamicCall = dyna.mkInvoke(context.tree, tree, qual, name) map { t =>
dyna.wrapErrors(t, (_.typed1(t, mode, pt)))
}
@@ -4782,49 +4578,47 @@ trait Typers extends Modes with Adaptations with Tags {
NoSymbol
}
if (phase.erasedTypes && qual.isInstanceOf[Super] && tree.symbol != NoSymbol)
- qual.tpe = tree.symbol.owner.tpe
+ qual setType tree.symbol.owner.tpe
if (!reallyExists(sym)) {
def handleMissing: Tree = {
- if (context.owner.enclosingTopLevelClass.isJavaDefined && name.isTypeName) {
- val tree1 = atPos(tree.pos) { gen.convertToSelectFromType(qual, name) }
- if (tree1 != EmptyTree) return typed1(tree1, mode, pt)
+ def errorTree = tree match {
+ case _ if !forInteractive => tree
+ case Select(_, _) => treeCopy.Select(tree, qual, name)
+ case SelectFromTypeTree(_, _) => treeCopy.SelectFromTypeTree(tree, qual, name)
}
-
- // try to expand according to Dynamic rules.
- asDynamicCall foreach (x => return x)
-
- debuglog(
- "qual = " + qual + ":" + qual.tpe +
- "\nSymbol=" + qual.tpe.termSymbol + "\nsymbol-info = " + qual.tpe.termSymbol.info +
- "\nscope-id = " + qual.tpe.termSymbol.info.decls.hashCode() + "\nmembers = " + qual.tpe.members +
- "\nname = " + name + "\nfound = " + sym + "\nowner = " + context.enclClass.owner)
-
- def makeInteractiveErrorTree = {
- val tree1 = tree match {
- case Select(_, _) => treeCopy.Select(tree, qual, name)
- case SelectFromTypeTree(_, _) => treeCopy.SelectFromTypeTree(tree, qual, name)
- }
- setError(tree1)
- }
-
- if (name == nme.ERROR && forInteractive)
- return makeInteractiveErrorTree
-
- if (!qual.tpe.widen.isErroneous) {
- if ((mode & QUALmode) != 0) {
- val lastTry = rootMirror.missingHook(qual.tpe.typeSymbol, name)
- if (lastTry != NoSymbol) return typed1(tree setSymbol lastTry, mode, pt)
+ def asTypeSelection = (
+ if (context.owner.enclosingTopLevelClass.isJavaDefined && name.isTypeName) {
+ atPos(tree.pos)(gen.convertToSelectFromType(qual, name)) match {
+ case EmptyTree => None
+ case tree1 => Some(typed1(tree1, mode, pt))
+ }
}
- NotAMemberError(tree, qual, name)
- }
-
- if (forInteractive) makeInteractiveErrorTree else setError(tree)
+ else None
+ )
+ debuglog(s"""
+ |qual=$qual:${qual.tpe}
+ |symbol=${qual.tpe.termSymbol.defString}
+ |scope-id=${qual.tpe.termSymbol.info.decls.hashCode}
+ |members=${qual.tpe.members mkString ", "}
+ |name=$name
+ |found=$sym
+ |owner=${context.enclClass.owner}
+ """.stripMargin)
+
+ // 1) Try converting a term selection on a java class into a type selection.
+ // 2) Try expanding according to Dynamic rules.
+ // 3) Try looking up the name in the qualifier.
+ asTypeSelection orElse asDynamicCall getOrElse (lookupInQualifier(qual, name) match {
+ case NoSymbol => setError(errorTree)
+ case found => typed1(tree setSymbol found, mode, pt)
+ })
}
handleMissing
- } else {
+ }
+ else {
val tree1 = tree match {
- case Select(_, _) => treeCopy.Select(tree, qual, name)
+ case Select(_, _) => treeCopy.Select(tree, qual, name)
case SelectFromTypeTree(_, _) => treeCopy.SelectFromTypeTree(tree, qual, name)
}
val (result, accessibleError) = silent(_.makeAccessible(tree1, sym, qual.tpe, qual)) match {
@@ -4893,19 +4687,16 @@ trait Typers extends Modes with Adaptations with Tags {
val tree1 = // temporarily use `filter` and an alternative for `withFilter`
if (name == nme.withFilter)
- silent(_ => typedSelect(tree, qual1, name)) match {
- case SilentResultValue(result) =>
- result
- case _ =>
- silent(_ => typed1(Select(qual1, nme.filter) setPos tree.pos, mode, pt)) match {
- case SilentResultValue(result2) =>
- unit.deprecationWarning(
- tree.pos, "`withFilter' method does not yet exist on " + qual1.tpe.widen +
- ", using `filter' method instead")
- result2
- case SilentTypeError(err) =>
- WithFilterError(tree, err)
- }
+ silent(_ => typedSelect(tree, qual1, name)) orElse { _ =>
+ silent(_ => typed1(Select(qual1, nme.filter) setPos tree.pos, mode, pt)) match {
+ case SilentResultValue(result2) =>
+ unit.deprecationWarning(
+ tree.pos, "`withFilter' method does not yet exist on " + qual1.tpe.widen +
+ ", using `filter' method instead")
+ result2
+ case SilentTypeError(err) =>
+ WithFilterError(tree, err)
+ }
}
else
typedSelect(tree, qual1, name)
@@ -4920,6 +4711,18 @@ trait Typers extends Modes with Adaptations with Tags {
}
}
+ /** A symbol qualifies if:
+ * - it exists
+ * - it is not stale (stale symbols are made to disappear here)
+ * - if we are in a pattern constructor, method definitions do not qualify
+ * unless they are stable. Otherwise, 'case x :: xs' would find the :: method.
+ */
+ def qualifies(sym: Symbol) = (
+ sym.hasRawInfo
+ && reallyExists(sym)
+ && !(inPatternConstructor && sym.isMethod && !sym.isStable)
+ )
+
/** Attribute an identifier consisting of a simple name or an outer reference.
*
* @param tree The tree representing the identifier.
@@ -4928,243 +4731,48 @@ trait Typers extends Modes with Adaptations with Tags {
* (2) Change imported symbols to selections
*/
def typedIdent(tree: Tree, name: Name): Tree = {
- var errorContainer: AbsTypeError = null
- def ambiguousError(msg: String) = {
- assert(errorContainer == null, "Cannot set ambiguous error twice for identifier")
- errorContainer = AmbiguousIdentError(tree, name, msg)
- }
- def identError(tree: AbsTypeError) = {
- assert(errorContainer == null, "Cannot set ambiguous error twice for identifier")
- errorContainer = tree
- }
+ // setting to enable unqualified idents in empty package
+ def inEmptyPackage = if (settings.exposeEmptyPackage.value) lookupInEmpty(name) else NoSymbol
- var defSym: Symbol = tree.symbol // the directly found symbol
- var pre: Type = NoPrefix // the prefix type of defSym, if a class member
- var qual: Tree = EmptyTree // the qualifier tree if transformed tree is a select
- var inaccessibleSym: Symbol = NoSymbol // the first symbol that was found but that was discarded
- // for being inaccessible; used for error reporting
- var inaccessibleExplanation: String = ""
-
- // If a special setting is given, the empty package will be checked as a
- // last ditch effort before failing. This method sets defSym and returns
- // true if a member of the given name exists.
- def checkEmptyPackage(): Boolean = {
- defSym = rootMirror.EmptyPackageClass.tpe.nonPrivateMember(name)
- defSym != NoSymbol
- }
- def startingIdentContext = (
- // ignore current variable scope in patterns to enforce linearity
- if ((mode & (PATTERNmode | TYPEPATmode)) == 0) context
- else context.outer
- )
- // A symbol qualifies if it exists and is not stale. Stale symbols
- // are made to disappear here. In addition,
- // if we are in a constructor of a pattern, we ignore all definitions
- // which are methods (note: if we don't do that
- // case x :: xs in class List would return the :: method)
- // unless they are stable or are accessors (the latter exception is for better error messages).
- def qualifies(sym: Symbol): Boolean = {
- sym.hasRawInfo && // this condition avoids crashing on self-referential pattern variables
- reallyExists(sym) &&
- ((mode & PATTERNmode | FUNmode) != (PATTERNmode | FUNmode) || !sym.isSourceMethod || sym.hasFlag(ACCESSOR))
- }
+ def issue(err: AbsTypeError) = {
+ // Avoiding some spurious error messages: see SI-2388.
+ val suppress = reporter.hasErrors && (name startsWith tpnme.ANON_CLASS_NAME)
+ if (!suppress)
+ ErrorUtils.issueTypeError(err)
- if (defSym == NoSymbol) {
- var defEntry: ScopeEntry = null // the scope entry of defSym, if defined in a local scope
-
- var cx = startingIdentContext
- while (defSym == NoSymbol && cx != NoContext && (cx.scope ne null)) { // cx.scope eq null arises during FixInvalidSyms in Duplicators
- pre = cx.enclClass.prefix
- defEntry = cx.scope.lookupEntry(name)
- if ((defEntry ne null) && qualifies(defEntry.sym)) {
- // Right here is where SI-1987, overloading in package objects, can be
- // seen to go wrong. There is an overloaded symbol, but when referring
- // to the unqualified identifier from elsewhere in the package, only
- // the last definition is visible. So overloading mis-resolves and is
- // definition-order dependent, bad things. See run/t1987.scala.
- //
- // I assume the actual problem involves how/where these symbols are entered
- // into the scope. But since I didn't figure out how to fix it that way, I
- // catch it here by looking up package-object-defined symbols in the prefix.
- if (isInPackageObject(defEntry.sym, pre.typeSymbol)) {
- defSym = pre.member(defEntry.sym.name)
- if (defSym ne defEntry.sym) {
- qual = gen.mkAttributedQualifier(pre)
- log(sm"""
- | !!! Overloaded package object member resolved incorrectly.
- | prefix: $pre
- | Discarded: ${defEntry.sym.defString}
- | Using: ${defSym.defString}
- """)
- }
- }
- else
- defSym = defEntry.sym
- }
- else {
- cx = cx.enclClass
- val foundSym = pre.member(name) filter qualifies
- defSym = foundSym filter (context.isAccessible(_, pre, false))
- if (defSym == NoSymbol) {
- if ((foundSym ne NoSymbol) && (inaccessibleSym eq NoSymbol)) {
- inaccessibleSym = foundSym
- inaccessibleExplanation = analyzer.lastAccessCheckDetails
- }
- cx = cx.outer
- }
- }
- }
-
- val symDepth = if (defEntry eq null) cx.depth
- else cx.depth - (cx.scope.nestingLevel - defEntry.owner.nestingLevel)
- var impSym: Symbol = NoSymbol // the imported symbol
- var imports = context.imports // impSym != NoSymbol => it is imported from imports.head
- while (!reallyExists(impSym) && !imports.isEmpty && imports.head.depth > symDepth) {
- impSym = imports.head.importedSymbol(name)
- if (!impSym.exists) imports = imports.tail
- }
-
- // detect ambiguous definition/import,
- // update `defSym` to be the final resolved symbol,
- // update `pre` to be `sym`s prefix type in case it is an imported member,
- // and compute value of:
-
- if (defSym.exists && impSym.exists) {
- // imported symbols take precedence over package-owned symbols in different
- // compilation units. Defined symbols take precedence over erroneous imports.
- if (defSym.isDefinedInPackage &&
- (!currentRun.compiles(defSym) ||
- context.unit.exists && defSym.sourceFile != context.unit.source.file))
- defSym = NoSymbol
- else if (impSym.isError || impSym.name == nme.CONSTRUCTOR)
- impSym = NoSymbol
- }
- if (defSym.exists) {
- if (impSym.exists)
- ambiguousError(
- "it is both defined in "+defSym.owner +
- " and imported subsequently by \n"+imports.head)
- else if (!defSym.owner.isClass || defSym.owner.isPackageClass || defSym.isTypeParameterOrSkolem)
- pre = NoPrefix
- else
- qual = atPos(tree.pos.focusStart)(gen.mkAttributedQualifier(pre))
- } else {
- if (impSym.exists) {
- var impSym1: Symbol = NoSymbol
- var imports1 = imports.tail
-
- /** It's possible that seemingly conflicting identifiers are
- * identifiably the same after type normalization. In such cases,
- * allow compilation to proceed. A typical example is:
- * package object foo { type InputStream = java.io.InputStream }
- * import foo._, java.io._
- */
- def ambiguousImport() = {
- // The types of the qualifiers from which the ambiguous imports come.
- // If the ambiguous name is a value, these must be the same.
- def t1 = imports.head.qual.tpe
- def t2 = imports1.head.qual.tpe
- // The types of the ambiguous symbols, seen as members of their qualifiers.
- // If the ambiguous name is a monomorphic type, we can relax this far.
- def mt1 = t1 memberType impSym
- def mt2 = t2 memberType impSym1
- def characterize = List(
- s"types: $t1 =:= $t2 ${t1 =:= t2} members: ${mt1 =:= mt2}",
- s"member type 1: $mt1",
- s"member type 2: $mt2",
- s"$impSym == $impSym1 ${impSym == impSym1}",
- s"${impSym.debugLocationString} ${impSym.getClass}",
- s"${impSym1.debugLocationString} ${impSym1.getClass}"
- ).mkString("\n ")
-
- // The symbol names are checked rather than the symbols themselves because
- // each time an overloaded member is looked up it receives a new symbol.
- // So foo.member("x") != foo.member("x") if x is overloaded. This seems
- // likely to be the cause of other bugs too...
- if (t1 =:= t2 && impSym.name == impSym1.name)
- log(s"Suppressing ambiguous import: $t1 =:= $t2 && $impSym == $impSym1")
- // Monomorphism restriction on types is in part because type aliases could have the
- // same target type but attach different variance to the parameters. Maybe it can be
- // relaxed, but doesn't seem worth it at present.
- else if (mt1 =:= mt2 && name.isTypeName && impSym.isMonomorphicType && impSym1.isMonomorphicType)
- log(s"Suppressing ambiguous import: $mt1 =:= $mt2 && $impSym and $impSym1 are equivalent")
- else {
- log(s"Import is genuinely ambiguous:\n " + characterize)
- ambiguousError(s"it is imported twice in the same scope by\n${imports.head}\nand ${imports1.head}")
- }
- }
- while (errorContainer == null && !imports1.isEmpty &&
- (!imports.head.isExplicitImport(name) ||
- imports1.head.depth == imports.head.depth)) {
- impSym1 = imports1.head.importedSymbol(name)
- if (reallyExists(impSym1)) {
- if (imports1.head.isExplicitImport(name)) {
- if (imports.head.isExplicitImport(name) ||
- imports1.head.depth != imports.head.depth) ambiguousImport()
- impSym = impSym1
- imports = imports1
- } else if (!imports.head.isExplicitImport(name) &&
- imports1.head.depth == imports.head.depth) ambiguousImport()
- }
- imports1 = imports1.tail
- }
- defSym = impSym
- val qual0 = imports.head.qual
- if (!(shortenImports && qual0.symbol.isPackage)) // optimization: don't write out package prefixes
- qual = atPos(tree.pos.focusStart)(resetPos(qual0.duplicate))
- pre = qual.tpe
+ setError(tree)
+ }
+ // ignore current variable scope in patterns to enforce linearity
+ val startContext = if (inNoModes(mode, PATTERNmode | TYPEPATmode)) context else context.outer
+ val nameLookup = tree.symbol match {
+ case NoSymbol => startContext.lookupSymbol(name, qualifies)
+ case sym => LookupSucceeded(EmptyTree, sym)
+ }
+ import InferErrorGen._
+ nameLookup match {
+ case LookupAmbiguous(msg) => issue(AmbiguousIdentError(tree, name, msg))
+ case LookupInaccessible(sym, msg) => issue(AccessError(tree, sym, context, msg))
+ case LookupNotFound =>
+ inEmptyPackage orElse lookupInRoot(name) match {
+ case NoSymbol => issue(SymbolNotFoundError(tree, name, context.owner, startContext))
+ case sym => typed1(tree setSymbol sym, mode, pt)
}
- else if (settings.exposeEmptyPackage.value && checkEmptyPackage())
- log("Allowing empty package member " + name + " due to settings.")
+ case LookupSucceeded(qual, sym) =>
+ // this -> Foo.this
+ if (sym.isThisSym)
+ typed1(This(sym.owner) setPos tree.pos, mode, pt)
+ // Inferring classOf type parameter from expected type. Otherwise an
+ // actual call to the stubbed classOf method is generated, returning null.
+ else if (isPredefMemberNamed(sym, nme.classOf) && pt.typeSymbol == ClassClass && pt.typeArgs.nonEmpty)
+ typedClassOf(tree, TypeTree(pt.typeArgs.head))
else {
- if ((mode & QUALmode) != 0) {
- val lastTry = rootMirror.missingHook(rootMirror.RootClass, name)
- if (lastTry != NoSymbol) return typed1(tree setSymbol lastTry, mode, pt)
- }
- if (settings.debug.value) {
- log(context.imports)//debug
- }
- if (inaccessibleSym eq NoSymbol) {
- // Avoiding some spurious error messages: see SI-2388.
- if (reporter.hasErrors && (name startsWith tpnme.ANON_CLASS_NAME)) ()
- else identError(SymbolNotFoundError(tree, name, context.owner, startingIdentContext))
- } else
- identError(InferErrorGen.AccessError(
- tree, inaccessibleSym, context.enclClass.owner.thisType, context.enclClass.owner,
- inaccessibleExplanation
- ))
- defSym = context.owner.newErrorSymbol(name)
+ val pre1 = if (sym.owner.isPackageClass) sym.owner.thisType else if (qual == EmptyTree) NoPrefix else qual.tpe
+ val tree1 = if (qual == EmptyTree) tree else atPos(tree.pos)(Select(atPos(tree.pos.focusStart)(qual), name) setAttachments tree.attachments)
+ val (tree2, pre2) = makeAccessible(tree1, sym, pre1, qual)
+ // SI-5967 Important to replace param type A* with Seq[A] when seen from from a reference, to avoid
+ // inference errors in pattern matching.
+ stabilize(tree2, pre2, mode, pt) modifyType dropIllegalStarTypes
}
- }
- }
- if (errorContainer != null) {
- ErrorUtils.issueTypeError(errorContainer)
- setError(tree)
- } else {
- if (defSym.owner.isPackageClass)
- pre = defSym.owner.thisType
-
- // Inferring classOf type parameter from expected type.
- if (defSym.isThisSym) {
- typed1(This(defSym.owner) setPos tree.pos, mode, pt)
- }
- // Inferring classOf type parameter from expected type. Otherwise an
- // actual call to the stubbed classOf method is generated, returning null.
- else if (isPredefMemberNamed(defSym, nme.classOf) && pt.typeSymbol == ClassClass && pt.typeArgs.nonEmpty)
- typedClassOf(tree, TypeTree(pt.typeArgs.head))
- else {
- val tree1 = (
- if (qual == EmptyTree) tree
- // atPos necessary because qualifier might come from startContext
- else atPos(tree.pos)(Select(qual, name) setAttachments tree.attachments)
- )
- val (tree2, pre2) = makeAccessible(tree1, defSym, pre, qual)
- // assert(pre.typeArgs isEmpty) // no need to add #2416-style check here, right?
- val tree3 = stabilize(tree2, pre2, mode, pt)
- // SI-5967 Important to replace param type A* with Seq[A] when seen from from a reference, to avoid
- // inference errors in pattern matching.
- tree3 setType dropRepeatedParamType(tree3.tpe)
- }
}
}
@@ -5204,7 +4812,7 @@ trait Typers extends Modes with Adaptations with Tags {
val tpt1 = typed1(tpt, mode | FUNmode | TAPPmode, WildcardType)
if (tpt1.isErrorTyped) {
tpt1
- } else if (!tpt1.hasSymbol) {
+ } else if (!tpt1.hasSymbolField) {
AppliedTypeNoParametersError(tree, tpt1.tpe)
} else {
val tparams = tpt1.symbol.typeParams
@@ -5264,7 +4872,7 @@ trait Typers extends Modes with Adaptations with Tags {
def typedDocDef(docdef: DocDef) = {
if (forScaladoc && (sym ne null) && (sym ne NoSymbol)) {
- val comment = docdef.comment
+ val comment = docdef.comment
docComments(sym) = comment
comment.defineVariables(sym)
val typer1 = newTyper(context.makeNewScope(tree, context.owner))
@@ -5311,14 +4919,12 @@ trait Typers extends Modes with Adaptations with Tags {
var block1 = typed(tree.block, pt)
var catches1 = typedCases(tree.catches, ThrowableClass.tpe, pt)
- for (cdef <- catches1 if cdef.guard.isEmpty) {
- def warn(name: Name) = context.warning(cdef.pat.pos, s"This catches all Throwables. If this is really intended, use `case ${name.decoded} : Throwable` to clear this warning.")
- def unbound(t: Tree) = t.symbol == null || t.symbol == NoSymbol
- cdef.pat match {
- case Bind(name, i @ Ident(_)) if unbound(i) => warn(name)
- case i @ Ident(name) if unbound(i) => warn(name)
- case _ =>
- }
+ for (cdef <- catches1; if treeInfo catchesThrowable cdef) {
+ val name = (treeInfo assignedNameOfPattern cdef).decoded
+ context.warning(cdef.pat.pos,
+ s"""|This catches all Throwables, which often has undesirable consequences.
+ |If intentional, use `case $name : Throwable` to clear this warning.""".stripMargin
+ )
}
val finalizer1 =
@@ -5563,28 +5169,21 @@ trait Typers extends Modes with Adaptations with Tags {
}
}
- /**
- * @param tree ...
- * @param mode ...
- * @param pt ...
- * @return ...
- */
def typed(tree: Tree, mode: Int, pt: Type): Tree = {
lastTreeToTyper = tree
indentTyping()
- var alreadyTyped = false
val startByType = if (Statistics.canEnable) Statistics.pushTimer(byTypeStack, byTypeNanos(tree.getClass)) else null
if (Statistics.canEnable) Statistics.incCounter(visitsByType, tree.getClass)
try {
if (context.retyping &&
(tree.tpe ne null) && (tree.tpe.isErroneous || !(tree.tpe <:< pt))) {
- tree.tpe = null
- if (tree.hasSymbol) tree.symbol = NoSymbol
+ tree.clearType()
+ if (tree.hasSymbolField) tree.symbol = NoSymbol
}
- alreadyTyped = tree.tpe ne null
- var tree1: Tree = if (alreadyTyped) tree else {
+ val alreadyTyped = tree.tpe ne null
+ val tree1: Tree = if (alreadyTyped) tree else {
printTyping(
ptLine("typing %s: pt = %s".format(ptTree(tree), pt),
"undetparams" -> context.undetparams,
@@ -5603,7 +5202,7 @@ trait Typers extends Modes with Adaptations with Tags {
tree1
}
- tree1.tpe = addAnnotations(tree1, tree1.tpe)
+ tree1 modifyType (addAnnotations(tree1, _))
val result = if (tree1.isEmpty) tree1 else adapt(tree1, mode, pt, tree)
if (!alreadyTyped) {
@@ -5615,7 +5214,7 @@ trait Typers extends Modes with Adaptations with Tags {
result
} catch {
case ex: TypeError =>
- tree.tpe = null
+ tree.clearType()
// The only problematic case are (recoverable) cyclic reference errors which can pop up almost anywhere.
printTyping("caught %s: while typing %s".format(ex, tree)) //DEBUG
@@ -5640,10 +5239,7 @@ trait Typers extends Modes with Adaptations with Tags {
def atOwner(tree: Tree, owner: Symbol): Typer =
newTyper(context.make(tree, owner))
- /** Types expression or definition <code>tree</code>.
- *
- * @param tree ...
- * @return ...
+ /** Types expression or definition `tree`.
*/
def typed(tree: Tree): Tree = {
val ret = typed(tree, EXPRmode, WildcardType)
@@ -5656,23 +5252,19 @@ trait Typers extends Modes with Adaptations with Tags {
// it makes for a lot less casting.
// def typedPos[T <: Tree](pos: Position)(tree: T): T = typed(atPos(pos)(tree)).asInstanceOf[T]
- /** Types expression <code>tree</code> with given prototype <code>pt</code>.
- *
- * @param tree ...
- * @param pt ...
- * @return ...
+ /** Types expression `tree` with given prototype `pt`.
*/
def typed(tree: Tree, pt: Type): Tree =
typed(tree, EXPRmode, pt)
- /** Types qualifier <code>tree</code> of a select node.
- * E.g. is tree occurs in a context like <code>tree.m</code>.
+ /** Types qualifier `tree` of a select node.
+ * E.g. is tree occurs in a context like `tree.m`.
*/
def typedQualifier(tree: Tree, mode: Int, pt: Type): Tree =
typed(tree, EXPRmode | QUALmode | POLYmode | mode & TYPEPATmode, pt) // TR: don't set BYVALmode, since qualifier might end up as by-name param to an implicit
- /** Types qualifier <code>tree</code> of a select node.
- * E.g. is tree occurs in a context like <code>tree.m</code>.
+ /** Types qualifier `tree` of a select node.
+ * E.g. is tree occurs in a context like `tree.m`.
*/
def typedQualifier(tree: Tree, mode: Int): Tree =
typedQualifier(tree, mode, WildcardType)
@@ -5683,7 +5275,7 @@ trait Typers extends Modes with Adaptations with Tags {
def typedOperator(tree: Tree): Tree =
typed(tree, EXPRmode | FUNmode | POLYmode | TAPPmode, WildcardType)
- /** Types a pattern with prototype <code>pt</code> */
+ /** Types a pattern with prototype `pt` */
def typedPattern(tree: Tree, pt: Type): Tree = {
// We disable implicits because otherwise some constructs will
// type check which should not. The pattern matcher does not
@@ -5721,8 +5313,6 @@ trait Typers extends Modes with Adaptations with Tags {
def typedHigherKindedType(tree: Tree, mode: Int): Tree =
typed(tree, HKmode, WildcardType)
- def typedHigherKindedType(tree: Tree): Tree = typedHigherKindedType(tree, NOmode)
-
/** Types a type constructor tree used in a new or supertype */
def typedTypeConstructor(tree: Tree, mode: Int): Tree = {
val result = typed(tree, forTypeMode(mode) | FUNmode, WildcardType)
@@ -5797,28 +5387,17 @@ trait Typers extends Modes with Adaptations with Tags {
case Some(tree1) => transformed -= tree; tree1
case None => typed(tree, mode, pt)
}
-
-/*
- def convertToTypeTree(tree: Tree): Tree = tree match {
- case TypeTree() => tree
- case _ => TypeTree(tree.tpe)
- }
-*/
}
}
object TypersStats {
import scala.reflect.internal.TypesStats._
- import scala.reflect.internal.BaseTypeSeqsStats._
val typedIdentCount = Statistics.newCounter("#typechecked identifiers")
val typedSelectCount = Statistics.newCounter("#typechecked selections")
val typedApplyCount = Statistics.newCounter("#typechecked applications")
val rawTypeFailed = Statistics.newSubCounter (" of which in failed", rawTypeCount)
val subtypeFailed = Statistics.newSubCounter(" of which in failed", subtypeCount)
val findMemberFailed = Statistics.newSubCounter(" of which in failed", findMemberCount)
- val compoundBaseTypeSeqCount = Statistics.newSubCounter(" of which for compound types", baseTypeSeqCount)
- val typerefBaseTypeSeqCount = Statistics.newSubCounter(" of which for typerefs", baseTypeSeqCount)
- val singletonBaseTypeSeqCount = Statistics.newSubCounter(" of which for singletons", baseTypeSeqCount)
val failedSilentNanos = Statistics.newSubTimer("time spent in failed", typerNanos)
val failedApplyNanos = Statistics.newSubTimer(" failed apply", typerNanos)
val failedOpEqNanos = Statistics.newSubTimer(" failed op=", typerNanos)
diff --git a/src/compiler/scala/tools/nsc/typechecker/Unapplies.scala b/src/compiler/scala/tools/nsc/typechecker/Unapplies.scala
index a34d7389bf..3e76da4fdc 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Unapplies.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Unapplies.scala
@@ -23,7 +23,6 @@ trait Unapplies extends ast.TreeDSL
private val unapplyParamName = nme.x_0
-
// In the typeCompleter (templateSig) of a case class (resp it's module),
// synthetic `copy` (reps `apply`, `unapply`) methods are added. To compute
// their signatures, the corresponding ClassDef is needed. During naming (in
@@ -46,17 +45,6 @@ trait Unapplies extends ast.TreeDSL
}
}
- /** returns type of the unapply method returning T_0...T_n
- * for n == 0, boolean
- * for n == 1, Some[T0]
- * else Some[Product[Ti]]
- */
- def unapplyReturnTypeExpected(argsLength: Int) = argsLength match {
- case 0 => BooleanClass.tpe
- case 1 => optionType(WildcardType)
- case n => optionType(productType((List fill n)(WildcardType)))
- }
-
/** returns unapply or unapplySeq if available */
def unapplyMember(tp: Type): Symbol = (tp member nme.unapply) match {
case NoSymbol => tp member nme.unapplySeq
diff --git a/src/compiler/scala/tools/nsc/typechecker/Variances.scala b/src/compiler/scala/tools/nsc/typechecker/Variances.scala
index 7d97b0c782..aa66a8d00a 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Variances.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Variances.scala
@@ -40,7 +40,7 @@ trait Variances {
(VARIANCES /: tps) ((v, tp) => v & varianceInType(tp)(tparam))
/** Compute variance of type parameter `tparam` in all type arguments
- * <code>tps</code> which correspond to formal type parameters `tparams1`.
+ * `tps` which correspond to formal type parameters `tparams1`.
*/
def varianceInArgs(tps: List[Type], tparams1: List[Symbol])(tparam: Symbol): Int = {
var v: Int = VARIANCES;
@@ -63,10 +63,12 @@ trait Variances {
varianceInType(annot.atp)(tparam)
}
- /** Compute variance of type parameter <code>tparam</code> in type <code>tp</code>. */
+ /** Compute variance of type parameter `tparam` in type `tp`. */
def varianceInType(tp: Type)(tparam: Symbol): Int = tp match {
case ErrorType | WildcardType | NoType | NoPrefix | ThisType(_) | ConstantType(_) =>
VARIANCES
+ case BoundedWildcardType(bounds) =>
+ varianceInType(bounds)(tparam)
case SingleType(pre, sym) =>
varianceInType(pre)(tparam)
case TypeRef(pre, sym, args) =>
diff --git a/src/compiler/scala/tools/nsc/util/ClassPath.scala b/src/compiler/scala/tools/nsc/util/ClassPath.scala
index 8732e06502..cbf6ef69d7 100644
--- a/src/compiler/scala/tools/nsc/util/ClassPath.scala
+++ b/src/compiler/scala/tools/nsc/util/ClassPath.scala
@@ -11,7 +11,6 @@ import java.net.URL
import scala.collection.{ mutable, immutable }
import io.{ File, Directory, Path, Jar, AbstractFile }
import scala.reflect.internal.util.StringOps.splitWhere
-import scala.reflect.ClassTag
import Jar.isJarOrZip
import File.pathSeparator
import java.net.MalformedURLException
@@ -32,10 +31,6 @@ object ClassPath {
def lsDir(dir: Directory, filt: String => Boolean = _ => true) =
dir.list filter (x => filt(x.name) && (x.isDirectory || isJarOrZip(x))) map (_.path) toList
- def basedir(s: String) =
- if (s contains File.separator) s.substring(0, s.lastIndexOf(File.separator))
- else "."
-
if (pattern == "*") lsDir(Directory("."))
else if (pattern endsWith wildSuffix) lsDir(Directory(pattern dropRight 2))
else if (pattern contains '*') {
@@ -54,22 +49,6 @@ object ClassPath {
/** Split the classpath, apply a transformation function, and reassemble it. */
def map(cp: String, f: String => String): String = join(split(cp) map f: _*)
- /** Split the classpath, filter according to predicate, and reassemble. */
- def filter(cp: String, p: String => Boolean): String = join(split(cp) filter p: _*)
-
- /** Split the classpath and map them into Paths */
- def toPaths(cp: String): List[Path] = split(cp) map (x => Path(x).toAbsolute)
-
- /** Make all classpath components absolute. */
- def makeAbsolute(cp: String): String = fromPaths(toPaths(cp): _*)
-
- /** Join the paths as a classpath */
- def fromPaths(paths: Path*): String = join(paths map (_.path): _*)
- def fromURLs(urls: URL*): String = fromPaths(urls map (x => Path(x.getPath)) : _*)
-
- /** Split the classpath and map them into URLs */
- def toURLs(cp: String): List[URL] = toPaths(cp) map (_.toURL)
-
/** Expand path and possibly expanding stars */
def expandPath(path: String, expandStar: Boolean = true): List[String] =
if (expandStar) split(path) flatMap expandS
@@ -129,13 +108,6 @@ object ClassPath {
for (dir <- expandPath(path, false) ; name <- expandDir(dir) ; entry <- Option(AbstractFile getDirectory name)) yield
newClassPath(entry)
- def classesAtAllURLS(path: String): List[ClassPath[T]] =
- (path split " ").toList flatMap classesAtURL
-
- def classesAtURL(spec: String) =
- for (url <- specToURL(spec).toList ; location <- Option(AbstractFile getURL url)) yield
- newClassPath(location)
-
def classesInExpandedPath(path: String): IndexedSeq[ClassPath[T]] =
classesInPathImpl(path, true).toIndexedSeq
@@ -212,8 +184,7 @@ abstract class ClassPath[T] {
def sourcepaths: IndexedSeq[AbstractFile]
/**
- * Represents classes which can be loaded with a ClassfileLoader/MsilFileLoader
- * and / or a SourcefileLoader.
+ * Represents classes which can be loaded with a ClassfileLoader and/or SourcefileLoader.
*/
case class ClassRep(binary: Option[T], source: Option[AbstractFile]) {
def name: String = binary match {
@@ -404,15 +375,3 @@ class JavaClassPath(
containers: IndexedSeq[ClassPath[AbstractFile]],
context: JavaContext)
extends MergedClassPath[AbstractFile](containers, context) { }
-
-object JavaClassPath {
- def fromURLs(urls: Seq[URL], context: JavaContext): JavaClassPath = {
- val containers = {
- for (url <- urls ; f = AbstractFile getURL url ; if f != null) yield
- new DirectoryClassPath(f, context)
- }
- new JavaClassPath(containers.toIndexedSeq, context)
- }
- def fromURLs(urls: Seq[URL]): JavaClassPath =
- fromURLs(urls, ClassPath.DefaultJavaContext)
-}
diff --git a/src/compiler/scala/tools/nsc/util/CommandLineParser.scala b/src/compiler/scala/tools/nsc/util/CommandLineParser.scala
index 9cf2c535df..e8f962a9e2 100644
--- a/src/compiler/scala/tools/nsc/util/CommandLineParser.scala
+++ b/src/compiler/scala/tools/nsc/util/CommandLineParser.scala
@@ -7,7 +7,6 @@ package scala.tools.nsc
package util
import scala.util.parsing.combinator._
-import scala.util.parsing.input.{ Reader }
import scala.util.parsing.input.CharArrayReader.EofCh
import scala.collection.mutable.ListBuffer
@@ -22,7 +21,6 @@ import scala.collection.mutable.ListBuffer
trait ParserUtil extends Parsers {
protected implicit class ParserPlus[+T](underlying: Parser[T]) {
def !~>[U](p: => Parser[U]): Parser[U] = (underlying ~! p) ^^ { case a~b => b }
- def <~![U](p: => Parser[U]): Parser[T] = (underlying ~! p) ^^ { case a~b => a }
}
}
@@ -38,7 +36,6 @@ case class CommandLine(
def withUnaryArgs(xs: List[String]) = copy(unaryArguments = xs)
def withBinaryArgs(xs: List[String]) = copy(binaryArguments = xs)
- def originalArgs = args
def assumeBinary = true
def enforceArity = true
def onlyKnownOptions = false
@@ -106,7 +103,6 @@ case class CommandLine(
def isSet(arg: String) = args contains arg
def get(arg: String) = argMap get arg
- def getOrElse(arg: String, orElse: => String) = if (isSet(arg)) apply(arg) else orElse
def apply(arg: String) = argMap(arg)
override def toString() = "CommandLine(\n%s)\n" format (args map (" " + _ + "\n") mkString)
@@ -116,7 +112,6 @@ object CommandLineParser extends RegexParsers with ParserUtil {
override def skipWhitespace = false
def elemExcept(xs: Elem*): Parser[Elem] = elem("elemExcept", x => x != EofCh && !(xs contains x))
- def elemOf(xs: Elem*): Parser[Elem] = elem("elemOf", xs contains _)
def escaped(ch: Char): Parser[String] = "\\" + ch
def mkQuoted(ch: Char): Parser[String] = (
elem(ch) !~> rep(escaped(ch) | elemExcept(ch)) <~ ch ^^ (_.mkString)
diff --git a/src/compiler/scala/tools/nsc/util/Exceptional.scala b/src/compiler/scala/tools/nsc/util/Exceptional.scala
index 34344263e8..1608ffa425 100644
--- a/src/compiler/scala/tools/nsc/util/Exceptional.scala
+++ b/src/compiler/scala/tools/nsc/util/Exceptional.scala
@@ -3,8 +3,6 @@ package util
import java.util.concurrent.ExecutionException
import java.lang.reflect.{ InvocationTargetException, UndeclaredThrowableException }
-import scala.reflect.internal.util.StringOps._
-import scala.language.implicitConversions
object Exceptional {
def unwrap(x: Throwable): Throwable = x match {
diff --git a/src/compiler/scala/tools/nsc/util/FreshNameCreator.scala b/src/compiler/scala/tools/nsc/util/FreshNameCreator.scala
index 5421843438..e877c990f0 100644
--- a/src/compiler/scala/tools/nsc/util/FreshNameCreator.scala
+++ b/src/compiler/scala/tools/nsc/util/FreshNameCreator.scala
@@ -14,11 +14,6 @@ trait FreshNameCreator {
*/
def newName(): String
def newName(prefix: String): String
-
- @deprecated("use newName(prefix)", "2.9.0")
- def newName(pos: scala.reflect.internal.util.Position, prefix: String): String = newName(prefix)
- @deprecated("use newName()", "2.9.0")
- def newName(pos: scala.reflect.internal.util.Position): String = newName()
}
object FreshNameCreator {
diff --git a/src/compiler/scala/tools/nsc/util/JavaCharArrayReader.scala b/src/compiler/scala/tools/nsc/util/JavaCharArrayReader.scala
index b7ed7903bc..fc3dd2bac2 100644
--- a/src/compiler/scala/tools/nsc/util/JavaCharArrayReader.scala
+++ b/src/compiler/scala/tools/nsc/util/JavaCharArrayReader.scala
@@ -14,74 +14,32 @@ class JavaCharArrayReader(buf: IndexedSeq[Char], start: Int, /* startline: int,
def this(buf: IndexedSeq[Char], decodeUni: Boolean, error: String => Unit) =
this(buf, 0, /* 1, 1, */ decodeUni, error)
- /** produce a duplicate of this char array reader which starts reading
- * at current position, independent of what happens to original reader
- */
- def dup: JavaCharArrayReader = clone().asInstanceOf[JavaCharArrayReader]
-
- /** layout constant
- */
- val tabinc = 8
-
/** the line and column position of the current character
*/
var ch: Char = _
var bp = start
- var oldBp = -1
- var oldCh: Char = _
-
- //private var cline: Int = _
- //private var ccol: Int = _
def cpos = bp
var isUnicode: Boolean = _
- var lastLineStartPos: Int = 0
- var lineStartPos: Int = 0
- var lastBlankLinePos: Int = 0
-
- private var onlyBlankChars = false
- //private var nextline = startline
- //private var nextcol = startcol
-
- private def markNewLine() {
- lastLineStartPos = lineStartPos
- if (onlyBlankChars) lastBlankLinePos = lineStartPos
- lineStartPos = bp
- onlyBlankChars = true
- //nextline += 1
- //nextcol = 1
- }
-
- def hasNext: Boolean = if (bp < buf.length) true
- else {
- false
- }
- def last: Char = if (bp > start + 2) buf(bp - 2) else ' ' // XML literals
+ def hasNext = bp < buf.length
def next(): Char = {
- //cline = nextline
- //ccol = nextcol
val buf = this.buf.asInstanceOf[collection.mutable.WrappedArray[Char]].array
if(!hasNext) {
ch = SU
return SU // there is an endless stream of SU's at the end
}
- oldBp = bp
- oldCh = ch
ch = buf(bp)
isUnicode = false
bp = bp + 1
ch match {
case '\t' =>
- // nextcol = ((nextcol - 1) / tabinc * tabinc) + tabinc + 1;
case CR =>
if (bp < buf.size && buf(bp) == LF) {
ch = LF
bp += 1
}
- markNewLine()
case LF | FF =>
- markNewLine()
case '\\' =>
def evenSlashPrefix: Boolean = {
var p = bp - 2
@@ -90,11 +48,10 @@ class JavaCharArrayReader(buf: IndexedSeq[Char], start: Int, /* startline: int,
}
def udigit: Int = {
val d = digit2int(buf(bp), 16)
- if (d >= 0) { bp += 1; /* nextcol = nextcol + 1 */ }
+ if (d >= 0) bp += 1
else error("error in unicode escape");
d
}
- // nextcol += 1
if (buf(bp) == 'u' && decodeUni && evenSlashPrefix) {
do {
bp += 1 //; nextcol += 1
@@ -104,20 +61,10 @@ class JavaCharArrayReader(buf: IndexedSeq[Char], start: Int, /* startline: int,
isUnicode = true
}
case _ =>
- if (ch > ' ') onlyBlankChars = false
- // nextcol += 1
}
ch
}
- def rewind() {
- if (oldBp == -1) throw new IllegalArgumentException
- bp = oldBp
- ch = oldCh
- oldBp = -1
- oldCh = 'x'
- }
-
def copy: JavaCharArrayReader =
new JavaCharArrayReader(buf, bp, /* nextcol, nextline, */ decodeUni, error)
}
diff --git a/src/compiler/scala/tools/nsc/util/MsilClassPath.scala b/src/compiler/scala/tools/nsc/util/MsilClassPath.scala
deleted file mode 100644
index aa3b7c286d..0000000000
--- a/src/compiler/scala/tools/nsc/util/MsilClassPath.scala
+++ /dev/null
@@ -1,169 +0,0 @@
-/* NSC -- new Scala compiler
- * Copyright 2006-2013 LAMP/EPFL
- * @author Martin Odersky
- */
-
-// $Id$
-
-package scala.tools.nsc
-package util
-
-import java.io.File
-import java.net.URL
-import java.util.StringTokenizer
-import scala.util.Sorting
-import scala.collection.mutable
-import scala.tools.nsc.io.{ AbstractFile, MsilFile }
-import ch.epfl.lamp.compiler.msil.{ Type => MSILType, Assembly }
-import ClassPath.{ ClassPathContext, isTraitImplementation }
-
-/** Keeping the MSIL classpath code in its own file is important to make sure
- * we don't accidentally introduce a dependency on msil.jar in the jvm.
- */
-
-object MsilClassPath {
- def collectTypes(assemFile: AbstractFile) = {
- var res: Array[MSILType] = MSILType.EmptyTypes
- val assem = Assembly.LoadFrom(assemFile.path)
- if (assem != null) {
- // DeclaringType == null: true for non-inner classes
- res = assem.GetTypes() filter (_.DeclaringType == null)
- Sorting.stableSort(res, (t1: MSILType, t2: MSILType) => (t1.FullName compareTo t2.FullName) < 0)
- }
- res
- }
-
- /** On the java side this logic is in PathResolver, but as I'm not really
- * up to folding MSIL into that, I am encapsulating it here.
- */
- def fromSettings(settings: Settings): MsilClassPath = {
- val context =
- if (settings.inline.value) new MsilContext
- else new MsilContext { override def isValidName(name: String) = !isTraitImplementation(name) }
-
- import settings._
- new MsilClassPath(assemextdirs.value, assemrefs.value, sourcepath.value, context)
- }
-
- class MsilContext extends ClassPathContext[MsilFile] {
- def toBinaryName(rep: MsilFile) = rep.msilType.Name
- def newClassPath(assemFile: AbstractFile) = new AssemblyClassPath(MsilClassPath collectTypes assemFile, "", this)
- }
-
- private def assembleEntries(ext: String, user: String, source: String, context: MsilContext): List[ClassPath[MsilFile]] = {
- import ClassPath._
- val etr = new mutable.ListBuffer[ClassPath[MsilFile]]
- val names = new mutable.HashSet[String]
-
- // 1. Assemblies from -Xassem-extdirs
- for (dirName <- expandPath(ext, expandStar = false)) {
- val dir = AbstractFile.getDirectory(dirName)
- if (dir ne null) {
- for (file <- dir) {
- val name = file.name.toLowerCase
- if (name.endsWith(".dll") || name.endsWith(".exe")) {
- names += name
- etr += context.newClassPath(file)
- }
- }
- }
- }
-
- // 2. Assemblies from -Xassem-path
- for (fileName <- expandPath(user, expandStar = false)) {
- val file = AbstractFile.getFile(fileName)
- if (file ne null) {
- val name = file.name.toLowerCase
- if (name.endsWith(".dll") || name.endsWith(".exe")) {
- names += name
- etr += context.newClassPath(file)
- }
- }
- }
-
- def check(n: String) {
- if (!names.contains(n))
- throw new AssertionError("Cannot find assembly "+ n +
- ". Use -Xassem-extdirs or -Xassem-path to specify its location")
- }
- check("mscorlib.dll")
- check("scalaruntime.dll")
-
- // 3. Source path
- for (dirName <- expandPath(source, expandStar = false)) {
- val file = AbstractFile.getDirectory(dirName)
- if (file ne null) etr += new SourcePath[MsilFile](file, context)
- }
-
- etr.toList
- }
-}
-import MsilClassPath._
-
-/**
- * A assembly file (dll / exe) containing classes and namespaces
- */
-class AssemblyClassPath(types: Array[MSILType], namespace: String, val context: MsilContext) extends ClassPath[MsilFile] {
- def name = {
- val i = namespace.lastIndexOf('.')
- if (i < 0) namespace
- else namespace drop (i + 1)
- }
- def asURLs = List(new java.net.URL(name))
- def asClasspathString = sys.error("Unknown") // I don't know what if anything makes sense here?
-
- private lazy val first: Int = {
- var m = 0
- var n = types.length - 1
- while (m < n) {
- val l = (m + n) / 2
- val res = types(l).FullName.compareTo(namespace)
- if (res < 0) m = l + 1
- else n = l
- }
- if (types(m).FullName.startsWith(namespace)) m else types.length
- }
-
- lazy val classes = {
- val cls = new mutable.ListBuffer[ClassRep]
- var i = first
- while (i < types.length && types(i).Namespace.startsWith(namespace)) {
- // CLRTypes used to exclude java.lang.Object and java.lang.String (no idea why..)
- if (types(i).Namespace == namespace)
- cls += ClassRep(Some(new MsilFile(types(i))), None)
- i += 1
- }
- cls.toIndexedSeq
- }
-
- lazy val packages = {
- val nsSet = new mutable.HashSet[String]
- var i = first
- while (i < types.length && types(i).Namespace.startsWith(namespace)) {
- val subns = types(i).Namespace
- if (subns.length > namespace.length) {
- // example: namespace = "System", subns = "System.Reflection.Emit"
- // => find second "." and "System.Reflection" to nsSet.
- val end = subns.indexOf('.', namespace.length + 1)
- nsSet += (if (end < 0) subns
- else subns.substring(0, end))
- }
- i += 1
- }
- val xs = for (ns <- nsSet.toList)
- yield new AssemblyClassPath(types, ns, context)
-
- xs.toIndexedSeq
- }
-
- val sourcepaths: IndexedSeq[AbstractFile] = IndexedSeq()
-
- override def toString() = "assembly classpath "+ namespace
-}
-
-/**
- * The classpath when compiling with target:msil. Binary files are represented as
- * MSILType values.
- */
-class MsilClassPath(ext: String, user: String, source: String, context: MsilContext)
-extends MergedClassPath[MsilFile](MsilClassPath.assembleEntries(ext, user, source, context), context) { } \ No newline at end of file
diff --git a/src/compiler/scala/tools/nsc/util/ScalaClassLoader.scala b/src/compiler/scala/tools/nsc/util/ScalaClassLoader.scala
index 1f6fa68f57..1d2cc73c6b 100644
--- a/src/compiler/scala/tools/nsc/util/ScalaClassLoader.scala
+++ b/src/compiler/scala/tools/nsc/util/ScalaClassLoader.scala
@@ -46,9 +46,6 @@ trait ScalaClassLoader extends JClassLoader {
def create(path: String): AnyRef =
tryToInitializeClass[AnyRef](path) map (_.newInstance()) orNull
- def constructorsOf[T <: AnyRef : ClassTag]: List[Constructor[T]] =
- classTag[T].runtimeClass.getConstructors.toList map (_.asInstanceOf[Constructor[T]])
-
/** The actual bytes for a class file, or an empty array if it can't be found. */
def classBytes(className: String): Array[Byte] = classAsStream(className) match {
case null => Array()
@@ -71,14 +68,6 @@ trait ScalaClassLoader extends JClassLoader {
try asContext(method.invoke(null, Array(arguments.toArray: AnyRef): _*)) // !!! : AnyRef shouldn't be necessary
catch unwrapHandler({ case ex => throw ex })
}
-
- /** A list comprised of this classloader followed by all its
- * (non-null) parent classloaders, if any.
- */
- def loaderChain: List[ScalaClassLoader] = this :: (getParent match {
- case null => Nil
- case p => p.loaderChain
- })
}
/** Methods for obtaining various classloaders.
@@ -99,35 +88,6 @@ object ScalaClassLoader {
}
def contextLoader = apply(Thread.currentThread.getContextClassLoader)
def appLoader = apply(JClassLoader.getSystemClassLoader)
- def extLoader = apply(appLoader.getParent)
- def bootLoader = apply(null)
- def contextChain = loaderChain(contextLoader)
-
- def pathToErasure[T: ClassTag] = pathToClass(classTag[T].runtimeClass)
- def pathToClass(clazz: Class[_]) = clazz.getName.replace('.', JFile.separatorChar) + ".class"
- def locate[T: ClassTag] = contextLoader getResource pathToErasure[T]
-
- /** Tries to guess the classpath by type matching the context classloader
- * and its parents, looking for any classloaders which will reveal their
- * classpath elements as urls. It it can't find any, creates a classpath
- * from the supplied string.
- */
- def guessClassPathString(default: String = ""): String = {
- val classpathURLs = contextChain flatMap {
- case x: HasClassPath => x.classPathURLs
- case x: JURLClassLoader => x.getURLs.toSeq
- case _ => Nil
- }
- if (classpathURLs.isEmpty) default
- else JavaClassPath.fromURLs(classpathURLs).asClasspathString
- }
-
- def loaderChain(head: JClassLoader) = {
- def loop(cl: JClassLoader): List[JClassLoader] =
- if (cl == null) Nil else cl :: loop(cl.getParent)
-
- loop(head)
- }
def setContext(cl: JClassLoader) =
Thread.currentThread.setContextClassLoader(cl)
def savingContextLoader[T](body: => T): T = {
@@ -142,16 +102,13 @@ object ScalaClassLoader {
with HasClassPath {
private var classloaderURLs: Seq[URL] = urls
- private def classpathString = ClassPath.fromURLs(urls: _*)
def classPathURLs: Seq[URL] = classloaderURLs
- def classPath: ClassPath[_] = JavaClassPath fromURLs classPathURLs
/** Override to widen to public */
override def addURL(url: URL) = {
classloaderURLs :+= url
super.addURL(url)
}
- def toLongString = urls.mkString("URLClassLoader(\n ", "\n ", "\n)\n")
}
def fromURLs(urls: Seq[URL], parent: ClassLoader = null): URLClassLoader =
@@ -162,7 +119,6 @@ object ScalaClassLoader {
fromURLs(urls) tryToLoadClass name isDefined
/** Finding what jar a clazz or instance came from */
- def origin(x: Any): Option[URL] = originOfClass(x.getClass)
def originOfClass(x: Class[_]): Option[URL] =
Option(x.getProtectionDomain.getCodeSource) flatMap (x => Option(x.getLocation))
}
diff --git a/src/compiler/scala/tools/nsc/util/ShowPickled.scala b/src/compiler/scala/tools/nsc/util/ShowPickled.scala
index 2b87280c24..759c06dc0f 100644
--- a/src/compiler/scala/tools/nsc/util/ShowPickled.scala
+++ b/src/compiler/scala/tools/nsc/util/ShowPickled.scala
@@ -7,7 +7,7 @@ package scala.tools
package nsc
package util
-import java.io.{File, FileInputStream, PrintStream}
+import java.io.PrintStream
import java.lang.Long.toHexString
import java.lang.Float.intBitsToFloat
import java.lang.Double.longBitsToDouble
@@ -94,7 +94,6 @@ object ShowPickled extends Names {
case ANNOTATEDtpe => "ANNOTATEDtpe"
case ANNOTINFO => "ANNOTINFO"
case ANNOTARGARRAY => "ANNOTARGARRAY"
- // case DEBRUIJNINDEXtpe => "DEBRUIJNINDEXtpe"
case EXISTENTIALtpe => "EXISTENTIALtpe"
case TREE => "TREE"
case MODIFIERS => "MODIFIERS"
diff --git a/src/compiler/scala/tools/nsc/util/SimpleTracer.scala b/src/compiler/scala/tools/nsc/util/SimpleTracer.scala
index b103ae9cb0..6997dbd402 100644
--- a/src/compiler/scala/tools/nsc/util/SimpleTracer.scala
+++ b/src/compiler/scala/tools/nsc/util/SimpleTracer.scala
@@ -6,7 +6,7 @@ package util
import java.io.PrintStream
/** A simple tracer
- * @param out: The print stream where trace info shoul be sent
+ * @param out: The print stream where trace info should be sent
* @param enabled: A condition that must be true for trace info to be produced.
*/
class SimpleTracer(out: PrintStream, enabled: Boolean = true) {
@@ -14,6 +14,5 @@ class SimpleTracer(out: PrintStream, enabled: Boolean = true) {
if (enabled) out.println(msg+value)
value
}
- def withOutput(out: PrintStream) = new SimpleTracer(out, enabled)
def when(enabled: Boolean): SimpleTracer = new SimpleTracer(out, enabled)
}
diff --git a/src/compiler/scala/tools/nsc/util/WorkScheduler.scala b/src/compiler/scala/tools/nsc/util/WorkScheduler.scala
index b1f4696d3e..4f7a9ff878 100644
--- a/src/compiler/scala/tools/nsc/util/WorkScheduler.scala
+++ b/src/compiler/scala/tools/nsc/util/WorkScheduler.scala
@@ -7,9 +7,9 @@ class WorkScheduler {
type Action = () => Unit
- private var todo = new mutable.Queue[Action]
- private var throwables = new mutable.Queue[Throwable]
- private var interruptReqs = new mutable.Queue[InterruptReq]
+ private val todo = new mutable.Queue[Action]
+ private val throwables = new mutable.Queue[Throwable]
+ private val interruptReqs = new mutable.Queue[InterruptReq]
/** Called from server: block until one of todo list, throwables or interruptReqs is nonempty */
def waitForMoreWork() = synchronized {
diff --git a/src/compiler/scala/tools/nsc/util/package.scala b/src/compiler/scala/tools/nsc/util/package.scala
index d34d4ee092..792a659ad6 100644
--- a/src/compiler/scala/tools/nsc/util/package.scala
+++ b/src/compiler/scala/tools/nsc/util/package.scala
@@ -18,16 +18,9 @@ package object util {
type HashSet[T >: Null <: AnyRef] = scala.reflect.internal.util.HashSet[T]
val HashSet = scala.reflect.internal.util.HashSet
- def onull[T](value: T, orElse: => T): T = if (value == null) orElse else value
-
/** Apply a function and return the passed value */
def returning[T](x: T)(f: T => Unit): T = { f(x) ; x }
- /** Frequency counter */
- def freq[T](xs: Traversable[T]): Map[T, Int] = xs groupBy identity mapValues (_.size)
-
- def freqrank[T](xs: Traversable[(T, Int)]): List[(Int, T)] = xs.toList map (_.swap) sortBy (-_._1)
-
/** Execute code and then wait for all non-daemon Threads
* created and begun during its execution to complete.
*/
@@ -54,18 +47,6 @@ package object util {
(result, ts2 filterNot (ts1 contains _))
}
- /** Given a function and a block of code, evaluates code block,
- * calls function with milliseconds elapsed, and returns block result.
- */
- def millisElapsedTo[T](f: Long => Unit)(body: => T): T = {
- val start = System.currentTimeMillis
- val result = body
- val end = System.currentTimeMillis
-
- f(end - start)
- result
- }
-
/** Generate a string using a routine that wants to write on a stream. */
def stringFromWriter(writer: PrintWriter => Unit): String = {
val stringWriter = new StringWriter()
@@ -83,8 +64,19 @@ package object util {
}
def stackTraceString(ex: Throwable): String = stringFromWriter(ex printStackTrace _)
+ /** A one line string which contains the class of the exception, the
+ * message if any, and the first non-Predef location in the stack trace
+ * (to exclude assert, require, etc.)
+ */
+ def stackTraceHeadString(ex: Throwable): String = {
+ val frame = ex.getStackTrace.dropWhile(_.getClassName contains "Predef").head
+ val msg = ex.getMessage match { case null | "" => "" ; case s => s"""("$s")""" }
+ val clazz = ex.getClass.getName.split('.').last
+
+ s"$clazz$msg @ $frame"
+ }
+
lazy val trace = new SimpleTracer(System.out)
- lazy val errtrace = new SimpleTracer(System.err)
@deprecated("Moved to scala.reflect.internal.util.StringOps", "2.10.0")
val StringOps = scala.reflect.internal.util.StringOps
diff --git a/src/compiler/scala/tools/reflect/MacroImplementations.scala b/src/compiler/scala/tools/reflect/MacroImplementations.scala
index 86cd845c54..d7c50504a8 100644
--- a/src/compiler/scala/tools/reflect/MacroImplementations.scala
+++ b/src/compiler/scala/tools/reflect/MacroImplementations.scala
@@ -1,6 +1,5 @@
package scala.tools.reflect
-import scala.reflect.macros.{ReificationException, UnexpectedReificationException}
import scala.reflect.macros.runtime.Context
import scala.collection.mutable.ListBuffer
import scala.collection.mutable.Stack
@@ -147,4 +146,4 @@ abstract class MacroImplementations {
Block(evals.toList, atPos(origApplyPos.focus)(expr)) setPos origApplyPos.makeTransparent
}
-} \ No newline at end of file
+}
diff --git a/src/compiler/scala/tools/reflect/ReflectMain.scala b/src/compiler/scala/tools/reflect/ReflectMain.scala
index 116ae24cdd..3ae21b6b98 100644
--- a/src/compiler/scala/tools/reflect/ReflectMain.scala
+++ b/src/compiler/scala/tools/reflect/ReflectMain.scala
@@ -4,7 +4,6 @@ package reflect
import scala.tools.nsc.Driver
import scala.tools.nsc.Global
import scala.tools.nsc.Settings
-import scala.tools.nsc.util.ClassPath.DefaultJavaContext
import scala.tools.nsc.util.ScalaClassLoader
import scala.tools.util.PathResolver
@@ -16,4 +15,4 @@ object ReflectMain extends Driver {
}
override def newCompiler(): Global = new ReflectGlobal(settings, reporter, classloaderFromSettings(settings))
-} \ No newline at end of file
+}
diff --git a/src/compiler/scala/tools/reflect/StdTags.scala b/src/compiler/scala/tools/reflect/StdTags.scala
index a3bc9b9bd1..5c62819f04 100644
--- a/src/compiler/scala/tools/reflect/StdTags.scala
+++ b/src/compiler/scala/tools/reflect/StdTags.scala
@@ -1,7 +1,6 @@
package scala.tools
package reflect
-import java.lang.{Class => jClass}
import scala.reflect.{ClassTag, classTag}
import scala.reflect.api.{Mirror, TypeCreator, Universe => ApiUniverse}
diff --git a/src/compiler/scala/tools/reflect/ToolBoxFactory.scala b/src/compiler/scala/tools/reflect/ToolBoxFactory.scala
index 0125f1b189..834f5436dc 100644
--- a/src/compiler/scala/tools/reflect/ToolBoxFactory.scala
+++ b/src/compiler/scala/tools/reflect/ToolBoxFactory.scala
@@ -3,12 +3,8 @@ package reflect
import scala.tools.nsc.reporters._
import scala.tools.nsc.CompilerCommand
-import scala.tools.nsc.Global
-import scala.tools.nsc.typechecker.Modes
import scala.tools.nsc.io.VirtualDirectory
import scala.tools.nsc.interpreter.AbstractFileClassLoader
-import scala.tools.nsc.util.FreshNameCreator
-import scala.reflect.internal.Flags
import scala.reflect.internal.util.{BatchSourceFile, NoSourceFile, NoFile}
import java.lang.{Class => jClass}
import scala.compat.Platform.EOL
@@ -29,8 +25,8 @@ abstract class ToolBoxFactory[U <: JavaUniverse](val u: U) { factorySelf =>
lazy val classLoader = new AbstractFileClassLoader(virtualDirectory, factorySelf.mirror.classLoader)
lazy val mirror: u.Mirror = u.runtimeMirror(classLoader)
- class ToolBoxGlobal(settings: scala.tools.nsc.Settings, reporter: Reporter)
- extends ReflectGlobal(settings, reporter, toolBoxSelf.classLoader) {
+ class ToolBoxGlobal(settings: scala.tools.nsc.Settings, reporter0: Reporter)
+ extends ReflectGlobal(settings, reporter0, toolBoxSelf.classLoader) {
import definitions._
private val trace = scala.tools.nsc.util.trace when settings.debug.value
@@ -73,13 +69,14 @@ abstract class ToolBoxFactory[U <: JavaUniverse](val u: U) { factorySelf =>
val typed = expr filter (t => t.tpe != null && t.tpe != NoType && !t.isInstanceOf[TypeTree])
if (!typed.isEmpty) throw ToolBoxError("reflective toolbox has failed: cannot operate on trees that are already typed")
- val freeTypes = expr.freeTypes
- if (freeTypes.length > 0) {
- var msg = "reflective toolbox has failed:" + EOL
- msg += "unresolved free type variables (namely: " + (freeTypes map (ft => "%s %s".format(ft.name, ft.origin)) mkString ", ") + "). "
- msg += "have you forgot to use TypeTag annotations for type parameters external to a reifee? "
- msg += "if you have troubles tracking free type variables, consider using -Xlog-free-types"
- throw ToolBoxError(msg)
+ if (expr.freeTypes.nonEmpty) {
+ val ft_s = expr.freeTypes map (ft => s" ${ft.name} ${ft.origin}") mkString "\n "
+ throw ToolBoxError(s"""
+ |reflective toolbox failed due to unresolved free type variables:
+ |$ft_s
+ |have you forgotten to use TypeTag annotations for type parameters external to a reifee?
+ |if you have troubles tracking free type variables, consider using -Xlog-free-types
+ """.stripMargin.trim)
}
}
@@ -100,9 +97,9 @@ abstract class ToolBoxFactory[U <: JavaUniverse](val u: U) { factorySelf =>
if (namesakes.length > 0) name += ("$" + (namesakes.length + 1))
freeTermNames += (ft -> newTermName(name + nme.REIFY_FREE_VALUE_SUFFIX))
})
- var expr = new Transformer {
+ val expr = new Transformer {
override def transform(tree: Tree): Tree =
- if (tree.hasSymbol && tree.symbol.isFreeTerm) {
+ if (tree.hasSymbolField && tree.symbol.isFreeTerm) {
tree match {
case Ident(_) =>
val freeTermRef = Ident(freeTermNames(tree.symbol.asFreeTerm))
@@ -132,7 +129,7 @@ abstract class ToolBoxFactory[U <: JavaUniverse](val u: U) { factorySelf =>
val ownerClass = rootMirror.EmptyPackageClass.newClassSymbol(newTypeName("<expression-owner>"))
build.setTypeSignature(ownerClass, ClassInfoType(List(ObjectClass.tpe), newScope, ownerClass))
val owner = ownerClass.newLocalDummy(expr.pos)
- var currentTyper = analyzer.newTyper(analyzer.rootContext(NoCompilationUnit, EmptyTree).make(expr, owner))
+ val currentTyper = analyzer.newTyper(analyzer.rootContext(NoCompilationUnit, EmptyTree).make(expr, owner))
val wrapper1 = if (!withImplicitViewsDisabled) (currentTyper.context.withImplicitsEnabled[Tree] _) else (currentTyper.context.withImplicitsDisabled[Tree] _)
val wrapper2 = if (!withMacrosDisabled) (currentTyper.context.withMacrosEnabled[Tree] _) else (currentTyper.context.withMacrosDisabled[Tree] _)
def wrapper (tree: => Tree) = wrapper1(wrapper2(tree))
@@ -146,18 +143,18 @@ abstract class ToolBoxFactory[U <: JavaUniverse](val u: U) { factorySelf =>
case Block(dummies, unwrapped) => (dummies, unwrapped)
case unwrapped => (Nil, unwrapped)
}
- var invertedIndex = freeTerms map (_.swap)
+ val invertedIndex = freeTerms map (_.swap)
// todo. also fixup singleton types
unwrapped = new Transformer {
override def transform(tree: Tree): Tree =
tree match {
- case Ident(name) if invertedIndex contains name =>
+ case Ident(name: TermName) if invertedIndex contains name =>
Ident(invertedIndex(name)) setType tree.tpe
case _ =>
super.transform(tree)
}
}.transform(unwrapped)
- new TreeTypeSubstituter(dummies1 map (_.symbol), dummies1 map (dummy => SingleType(NoPrefix, invertedIndex(dummy.symbol.name)))).traverse(unwrapped)
+ new TreeTypeSubstituter(dummies1 map (_.symbol), dummies1 map (dummy => SingleType(NoPrefix, invertedIndex(dummy.symbol.name.toTermName)))).traverse(unwrapped)
unwrapped = if (expr0.isTerm) unwrapped else unwrapFromTerm(unwrapped)
unwrapped
}
@@ -202,7 +199,7 @@ abstract class ToolBoxFactory[U <: JavaUniverse](val u: U) { factorySelf =>
def wrap(expr0: Tree): ModuleDef = {
val (expr, freeTerms) = extractFreeTerms(expr0, wrapFreeTermRefs = true)
- val (obj, mclazz) = rootMirror.EmptyPackageClass.newModuleAndClassSymbol(
+ val (obj, _) = rootMirror.EmptyPackageClass.newModuleAndClassSymbol(
nextWrapperModuleName())
val minfo = ClassInfoType(List(ObjectClass.tpe), newScope, obj.moduleClass)
@@ -234,7 +231,7 @@ abstract class ToolBoxFactory[U <: JavaUniverse](val u: U) { factorySelf =>
NoPosition))
trace("wrapped: ")(showAttributed(moduledef, true, true, settings.Yshowsymkinds.value))
- var cleanedUp = resetLocalAttrs(moduledef)
+ val cleanedUp = resetLocalAttrs(moduledef)
trace("cleaned up: ")(showAttributed(cleanedUp, true, true, settings.Yshowsymkinds.value))
cleanedUp.asInstanceOf[ModuleDef]
}
@@ -311,11 +308,9 @@ abstract class ToolBoxFactory[U <: JavaUniverse](val u: U) { factorySelf =>
// reporter doesn't accumulate errors, but the front-end does
def throwIfErrors() = {
- if (frontEnd.hasErrors) {
- var msg = "reflective compilation has failed: " + EOL + EOL
- msg += frontEnd.infos map (_.msg) mkString EOL
- throw ToolBoxError(msg)
- }
+ if (frontEnd.hasErrors) throw ToolBoxError(
+ "reflective compilation has failed: " + EOL + EOL + (frontEnd.infos map (_.msg) mkString EOL)
+ )
}
}
@@ -335,15 +330,15 @@ abstract class ToolBoxFactory[U <: JavaUniverse](val u: U) { factorySelf =>
command.settings.outputDirs setSingleOutput virtualDirectory
val instance = new ToolBoxGlobal(command.settings, frontEndToReporter(frontEnd, command.settings))
if (frontEnd.hasErrors) {
- var msg = "reflective compilation has failed: cannot initialize the compiler: " + EOL + EOL
- msg += frontEnd.infos map (_.msg) mkString EOL
- throw ToolBoxError(msg)
+ throw ToolBoxError(
+ "reflective compilation has failed: cannot initialize the compiler: " + EOL + EOL +
+ (frontEnd.infos map (_.msg) mkString EOL)
+ )
}
instance
} catch {
case ex: Throwable =>
- var msg = "reflective compilation has failed: cannot initialize the compiler due to %s".format(ex.toString)
- throw ToolBoxError(msg, ex)
+ throw ToolBoxError(s"reflective compilation has failed: cannot initialize the compiler due to $ex", ex)
}
}
@@ -352,8 +347,8 @@ abstract class ToolBoxFactory[U <: JavaUniverse](val u: U) { factorySelf =>
def typeCheck(tree: u.Tree, expectedType: u.Type, silent: Boolean = false, withImplicitViewsDisabled: Boolean = false, withMacrosDisabled: Boolean = false): u.Tree = compiler.withCleanupCaches {
if (compiler.settings.verbose.value) println("importing "+tree+", expectedType = "+expectedType)
- var ctree: compiler.Tree = importer.importTree(tree)
- var cexpectedType: compiler.Type = importer.importType(expectedType)
+ val ctree: compiler.Tree = importer.importTree(tree)
+ val cexpectedType: compiler.Type = importer.importType(expectedType)
if (compiler.settings.verbose.value) println("typing "+ctree+", expectedType = "+expectedType)
val ttree: compiler.Tree = compiler.typeCheck(ctree, cexpectedType, silent = silent, withImplicitViewsDisabled = withImplicitViewsDisabled, withMacrosDisabled = withMacrosDisabled)
@@ -372,9 +367,9 @@ abstract class ToolBoxFactory[U <: JavaUniverse](val u: U) { factorySelf =>
private def inferImplicit(tree: u.Tree, pt: u.Type, isView: Boolean, silent: Boolean, withMacrosDisabled: Boolean, pos: u.Position): u.Tree = compiler.withCleanupCaches {
if (compiler.settings.verbose.value) println("importing "+pt, ", tree = "+tree+", pos = "+pos)
- var ctree: compiler.Tree = importer.importTree(tree)
- var cpt: compiler.Type = importer.importType(pt)
- var cpos: compiler.Position = importer.importPosition(pos)
+ val ctree: compiler.Tree = importer.importTree(tree)
+ val cpt: compiler.Type = importer.importType(pt)
+ val cpos: compiler.Position = importer.importPosition(pos)
if (compiler.settings.verbose.value) println("inferring implicit %s of type %s, macros = %s".format(if (isView) "view" else "value", pt, !withMacrosDisabled))
val itree: compiler.Tree = compiler.inferImplicit(ctree, cpt, isView = isView, silent = silent, withMacrosDisabled = withMacrosDisabled, pos = cpos)
@@ -396,9 +391,6 @@ abstract class ToolBoxFactory[U <: JavaUniverse](val u: U) { factorySelf =>
uttree
}
- def showAttributed(tree: u.Tree, printTypes: Boolean = true, printIds: Boolean = true, printKinds: Boolean = false): String =
- compiler.showAttributed(importer.importTree(tree), printTypes, printIds, printKinds)
-
def parse(code: String): u.Tree = {
if (compiler.settings.verbose.value) println("parsing "+code)
val ctree: compiler.Tree = compiler.parse(code)
@@ -408,7 +400,7 @@ abstract class ToolBoxFactory[U <: JavaUniverse](val u: U) { factorySelf =>
def compile(tree: u.Tree): () => Any = {
if (compiler.settings.verbose.value) println("importing "+tree)
- var ctree: compiler.Tree = importer.importTree(tree)
+ val ctree: compiler.Tree = importer.importTree(tree)
if (compiler.settings.verbose.value) println("compiling "+ctree)
compiler.compile(ctree)
diff --git a/src/compiler/scala/tools/reflect/package.scala b/src/compiler/scala/tools/reflect/package.scala
index 3f880bf7f8..bf533766d0 100644
--- a/src/compiler/scala/tools/reflect/package.scala
+++ b/src/compiler/scala/tools/reflect/package.scala
@@ -76,7 +76,6 @@ package object reflect {
private[reflect] def frontEndToReporter(frontEnd: FrontEnd, settings0: Settings): Reporter = new AbstractReporter {
val settings = settings0
- import frontEnd.{Severity => ApiSeverity}
val API_INFO = frontEnd.INFO
val API_WARNING = frontEnd.WARNING
val API_ERROR = frontEnd.ERROR
diff --git a/src/compiler/scala/tools/util/Javap.scala b/src/compiler/scala/tools/util/Javap.scala
index c3264d0787..269cfa5dd4 100644
--- a/src/compiler/scala/tools/util/Javap.scala
+++ b/src/compiler/scala/tools/util/Javap.scala
@@ -6,14 +6,25 @@
package scala.tools
package util
-import java.lang.reflect.{ GenericSignatureFormatError, Method, Constructor }
-import java.lang.{ ClassLoader => JavaClassLoader }
+import java.lang.{ ClassLoader => JavaClassLoader, Iterable => JIterable }
import scala.tools.nsc.util.ScalaClassLoader
-import java.io.{ InputStream, PrintWriter, ByteArrayInputStream, FileNotFoundException }
+import scala.tools.nsc.interpreter.IMain
+import java.io.{ ByteArrayInputStream, CharArrayWriter, FileNotFoundException, InputStream,
+ PrintWriter, Writer }
+import java.util.{ Locale }
+import javax.tools.{ Diagnostic, DiagnosticCollector, DiagnosticListener,
+ ForwardingJavaFileManager, JavaFileManager, JavaFileObject,
+ SimpleJavaFileObject, StandardLocation }
import scala.tools.nsc.io.File
-import Javap._
+import scala.io.Source
+import scala.util.{ Try, Success, Failure }
+import scala.util.Properties.lineSeparator
+import scala.collection.JavaConverters
+import scala.collection.generic.Clearable
import scala.language.reflectiveCalls
+import Javap._
+
trait Javap {
def loader: ScalaClassLoader
def printWriter: PrintWriter
@@ -31,86 +42,404 @@ object NoJavap extends Javap {
}
class JavapClass(
- val loader: ScalaClassLoader = ScalaClassLoader.appLoader,
- val printWriter: PrintWriter = new PrintWriter(System.out, true)
+ val loader: ScalaClassLoader,
+ val printWriter: PrintWriter,
+ intp: Option[IMain] = None
) extends Javap {
+ import JavapTool.ToolArgs
- lazy val parser = new JpOptions
-
- val EnvClass = loader.tryToInitializeClass[FakeEnvironment](Env).orNull
- val PrinterClass = loader.tryToInitializeClass[FakePrinter](Printer).orNull
- private def failed = (EnvClass eq null) || (PrinterClass eq null)
-
- val PrinterCtr = (
- if (failed) null
- else PrinterClass.getConstructor(classOf[InputStream], classOf[PrintWriter], EnvClass)
- )
-
- def findBytes(path: String): Array[Byte] =
- tryFile(path) getOrElse tryClass(path)
+ lazy val tool = JavapTool()
+ /** Run the tool. Option args start with "-".
+ * The default options are "-protected -verbose".
+ * Byte data for filename args is retrieved with findBytes.
+ */
def apply(args: Seq[String]): List[JpResult] = {
- if (failed) Nil
- else args.toList filterNot (_ startsWith "-") map { path =>
- val bytes = findBytes(path)
- if (bytes.isEmpty) new JpError("Could not find class bytes for '%s'".format(path))
- else new JpSuccess(newPrinter(new ByteArrayInputStream(bytes), newEnv(args)))
- }
+ val (options, claases) = args partition (s => (s startsWith "-") && s.length > 1)
+ val (flags, upgraded) = upgrade(options)
+ if (flags.help || claases.isEmpty) List(JpResult(JavapTool.helper(printWriter)))
+ else tool(flags.raw, upgraded)(claases map (claas => claas -> bytesFor(claas)))
}
- def newPrinter(in: InputStream, env: FakeEnvironment): FakePrinter =
- if (failed) null
- else PrinterCtr.newInstance(in, printWriter, env)
-
- def newEnv(opts: Seq[String]): FakeEnvironment = {
- lazy val env: FakeEnvironment = EnvClass.newInstance()
-
- if (failed) null
- else parser(opts) foreach { case (name, value) =>
- val field = EnvClass getDeclaredField name
- field setAccessible true
- field.set(env, value.asInstanceOf[AnyRef])
- }
+ /** Cull our tool options. */
+ private def upgrade(options: Seq[String]): (ToolArgs, Seq[String]) = ToolArgs fromArgs options match {
+ case (t,s) if s.nonEmpty => (t,s)
+ case (t,s) => (t, JavapTool.DefaultOptions)
+ }
- env
+ private def bytesFor(path: String) = Try {
+ def last = intp.get.mostRecentVar // fail if no intp
+ val bytes = findBytes(if (path == "-") last else path)
+ if (bytes.isEmpty) throw new FileNotFoundException(s"Could not find class bytes for '${path}'")
+ else bytes
}
+ def findBytes(path: String): Array[Byte] = tryFile(path) getOrElse tryClass(path)
+
/** Assume the string is a path and try to find the classfile
* it represents.
*/
def tryFile(path: String): Option[Array[Byte]] = {
- val file = File(
+ val file =
if (path.endsWith(".class")) path
else path.replace('.', '/') + ".class"
- )
- if (!file.exists) None
- else try Some(file.toByteArray) catch { case x: Exception => None }
+ (Try (File(file)) filter (_.exists) map (_.toByteArray)).toOption
}
/** Assume the string is a fully qualified class name and try to
* find the class object it represents.
*/
def tryClass(path: String): Array[Byte] = {
- val extName = (
- if (path endsWith ".class") (path dropRight 6).replace('/', '.')
- else path
+ def pathology(p: String) =
+ if (p endsWith ".class") (p dropRight 6).replace('/', '.')
+ else p
+ def load(name: String) = loader classBytes pathology(name)
+ // if repl, translate the name to something replish
+ if (intp.isDefined) {
+ val claas = load(intp.get.translatePath(path) getOrElse path)
+ if (!claas.isEmpty) claas
+ // take path as a Name in scope and find its enclosing class
+ else intp.get.translateEnclosingClass(path) match {
+ case Some(encl) => load(encl)
+ case _ => claas // empty
+ }
+ } else load(path)
+ }
+
+ abstract class JavapTool {
+ type ByteAry = Array[Byte]
+ type Input = Pair[String, Try[ByteAry]]
+ def apply(raw: Boolean, options: Seq[String])(inputs: Seq[Input]): List[JpResult]
+ // Since the tool is loaded by reflection, check for catastrophic failure.
+ protected def failed: Boolean
+ implicit protected class Failer[A](a: =>A) {
+ def orFailed[B >: A](b: =>B) = if (failed) b else a
+ }
+ protected def noToolError = new JpError(s"No javap tool available: ${getClass.getName} failed to initialize.")
+ }
+
+ class JavapTool6 extends JavapTool {
+ import JavapTool._
+ val EnvClass = loader.tryToInitializeClass[FakeEnvironment](Env).orNull
+ val PrinterClass = loader.tryToInitializeClass[FakePrinter](Printer).orNull
+ override protected def failed = (EnvClass eq null) || (PrinterClass eq null)
+
+ val PrinterCtr = PrinterClass.getConstructor(classOf[InputStream], classOf[PrintWriter], EnvClass) orFailed null
+ def newPrinter(in: InputStream, env: FakeEnvironment): FakePrinter =
+ PrinterCtr.newInstance(in, printWriter, env) orFailed null
+ def showable(fp: FakePrinter) = new Showable {
+ def show() = fp.asInstanceOf[{ def print(): Unit }].print()
+ }
+
+ lazy val parser = new JpOptions
+ def newEnv(opts: Seq[String]): FakeEnvironment = {
+ def result = {
+ val env: FakeEnvironment = EnvClass.newInstance()
+ parser(opts) foreach { case (name, value) =>
+ val field = EnvClass getDeclaredField name
+ field setAccessible true
+ field.set(env, value.asInstanceOf[AnyRef])
+ }
+ env
+ }
+ result orFailed null
+ }
+
+ override def apply(raw: Boolean, options: Seq[String])(inputs: Seq[Input]): List[JpResult] =
+ (inputs map {
+ case (_, Success(ba)) => JpResult(showable(newPrinter(new ByteArrayInputStream(ba), newEnv(options))))
+ case (_, Failure(e)) => JpResult(e.toString)
+ }).toList orFailed List(noToolError)
+ }
+
+ class JavapTool7 extends JavapTool {
+
+ import JavapTool._
+ type Task = {
+ def call(): Boolean // true = ok
+ //def run(args: Array[String]): Int // all args
+ //def handleOptions(args: Array[String]): Unit // options, then run() or call()
+ }
+ // result of Task.run
+ //object TaskResult extends Enumeration {
+ // val Ok, Error, CmdErr, SysErr, Abnormal = Value
+ //}
+ val TaskClaas = loader.tryToInitializeClass[Task](JavapTool.Tool).orNull
+ override protected def failed = TaskClaas eq null
+
+ val TaskCtor = TaskClaas.getConstructor(
+ classOf[Writer],
+ classOf[JavaFileManager],
+ classOf[DiagnosticListener[_]],
+ classOf[JIterable[String]],
+ classOf[JIterable[String]]
+ ) orFailed null
+
+ class JavaReporter extends DiagnosticListener[JavaFileObject] with Clearable {
+ import scala.collection.mutable.{ ArrayBuffer, SynchronizedBuffer }
+ type D = Diagnostic[_ <: JavaFileObject]
+ val diagnostics = new ArrayBuffer[D] with SynchronizedBuffer[D]
+ override def report(d: Diagnostic[_ <: JavaFileObject]) {
+ diagnostics += d
+ }
+ override def clear() = diagnostics.clear()
+ /** All diagnostic messages.
+ * @param locale Locale for diagnostic messages, null by default.
+ */
+ def messages(implicit locale: Locale = null) = (diagnostics map (_ getMessage locale)).toList
+
+ def reportable(raw: Boolean): String = {
+ // don't filter this message if raw, since the names are likely to differ
+ val container = "Binary file .* contains .*".r
+ val m = if (raw) messages
+ else messages filter (_ match { case container() => false case _ => true })
+ clear()
+ if (m.nonEmpty) m mkString ("", lineSeparator, lineSeparator)
+ else ""
+ }
+ }
+ val reporter = new JavaReporter
+
+ // DisassemblerTool.getStandardFileManager(reporter,locale,charset)
+ val defaultFileManager: JavaFileManager =
+ (loader.tryToLoadClass[JavaFileManager]("com.sun.tools.javap.JavapFileManager").get getMethod (
+ "create",
+ classOf[DiagnosticListener[_]],
+ classOf[PrintWriter]
+ ) invoke (null, reporter, new PrintWriter(System.err, true))).asInstanceOf[JavaFileManager] orFailed null
+
+ // manages named arrays of bytes, which might have failed to load
+ class JavapFileManager(val managed: Seq[Input])(delegate: JavaFileManager = defaultFileManager)
+ extends ForwardingJavaFileManager[JavaFileManager](delegate) {
+ import JavaFileObject.Kind
+ import Kind._
+ import StandardLocation._
+ import JavaFileManager.Location
+ import java.net.URI
+ def uri(name: String): URI = new URI(name) // new URI("jfo:" + name)
+
+ def inputNamed(name: String): Try[ByteAry] = (managed find (_._1 == name)).get._2
+ def managedFile(name: String, kind: Kind) = kind match {
+ case CLASS => fileObjectForInput(name, inputNamed(name), kind)
+ case _ => null
+ }
+ // todo: just wrap it as scala abstractfile and adapt it uniformly
+ def fileObjectForInput(name: String, bytes: Try[ByteAry], kind: Kind): JavaFileObject =
+ new SimpleJavaFileObject(uri(name), kind) {
+ override def openInputStream(): InputStream = new ByteArrayInputStream(bytes.get)
+ // if non-null, ClassWriter wrongly requires scheme non-null
+ override def toUri: URI = null
+ override def getName: String = name
+ // suppress
+ override def getLastModified: Long = -1L
+ }
+ override def getJavaFileForInput(location: Location, className: String, kind: Kind): JavaFileObject =
+ location match {
+ case CLASS_PATH => managedFile(className, kind)
+ case _ => null
+ }
+ override def hasLocation(location: Location): Boolean =
+ location match {
+ case CLASS_PATH => true
+ case _ => false
+ }
+ }
+ val writer = new CharArrayWriter
+ def fileManager(inputs: Seq[Input]) = new JavapFileManager(inputs)()
+ def showable(raw: Boolean): Showable = {
+ val written = {
+ writer.flush()
+ val w = writer.toString
+ writer.reset()
+ w
+ }
+ val msgs = reporter.reportable(raw)
+ new Showable {
+ val mw = msgs + written
+ // ReplStrippingWriter clips and scrubs on write(String)
+ // circumvent it by write(mw, 0, mw.length) or wrap it in withoutUnwrapping
+ def show() =
+ if (raw && intp.isDefined) intp.get withoutUnwrapping { writeLines() }
+ else writeLines()
+ private def writeLines() {
+ for (line <- Source.fromString(mw).getLines) printWriter write line+lineSeparator
+ printWriter.flush()
+ }
+ }
+ }
+ // eventually, use the tool interface
+ def task(options: Seq[String], claases: Seq[String], inputs: Seq[Input]): Task = {
+ //ServiceLoader.load(classOf[javax.tools.DisassemblerTool]).
+ //getTask(writer, fileManager, reporter, options.asJava, claases.asJava)
+ import JavaConverters.asJavaIterableConverter
+ TaskCtor.newInstance(writer, fileManager(inputs), reporter, options.asJava, claases.asJava)
+ .orFailed (throw new IllegalStateException)
+ }
+ // a result per input
+ private def applyOne(raw: Boolean, options: Seq[String], claas: String, inputs: Seq[Input]): Try[JpResult] =
+ Try {
+ task(options, Seq(claas), inputs).call()
+ } map {
+ case true => JpResult(showable(raw))
+ case _ => JpResult(reporter.reportable(raw))
+ } recoverWith {
+ case e: java.lang.reflect.InvocationTargetException => e.getCause match {
+ case t: IllegalArgumentException => Success(JpResult(t.getMessage)) // bad option
+ case x => Failure(x)
+ }
+ } lastly {
+ reporter.clear
+ }
+ override def apply(raw: Boolean, options: Seq[String])(inputs: Seq[Input]): List[JpResult] = (inputs map {
+ case (claas, Success(_)) => applyOne(raw, options, claas, inputs).get
+ case (_, Failure(e)) => JpResult(e.toString)
+ }).toList orFailed List(noToolError)
+ }
+
+ object JavapTool {
+ // >= 1.7
+ val Tool = "com.sun.tools.javap.JavapTask"
+
+ // < 1.7
+ val Env = "sun.tools.javap.JavapEnvironment"
+ val Printer = "sun.tools.javap.JavapPrinter"
+ // "documentation"
+ type FakeEnvironment = AnyRef
+ type FakePrinter = AnyRef
+
+ // support JavapEnvironment
+ class JpOptions {
+ private object Access {
+ final val PRIVATE = 0
+ final val PROTECTED = 1
+ final val PACKAGE = 2
+ final val PUBLIC = 3
+ }
+ private val envActionMap: Map[String, (String, Any)] = {
+ val map = Map(
+ "-l" -> (("showLineAndLocal", true)),
+ "-c" -> (("showDisassembled", true)),
+ "-s" -> (("showInternalSigs", true)),
+ "-verbose" -> (("showVerbose", true)),
+ "-private" -> (("showAccess", Access.PRIVATE)),
+ "-package" -> (("showAccess", Access.PACKAGE)),
+ "-protected" -> (("showAccess", Access.PROTECTED)),
+ "-public" -> (("showAccess", Access.PUBLIC)),
+ "-all" -> (("showallAttr", true))
+ )
+ map ++ List(
+ "-v" -> map("-verbose"),
+ "-p" -> map("-private")
+ )
+ }
+ def apply(opts: Seq[String]): Seq[(String, Any)] = {
+ opts flatMap { opt =>
+ envActionMap get opt match {
+ case Some(pair) => List(pair)
+ case _ =>
+ val charOpts = opt.tail.toSeq map ("-" + _)
+ if (charOpts forall (envActionMap contains _))
+ charOpts map envActionMap
+ else Nil
+ }
+ }
+ }
+ }
+
+ case class ToolArgs(raw: Boolean = false, help: Boolean = false)
+
+ object ToolArgs {
+ def fromArgs(args: Seq[String]): (ToolArgs, Seq[String]) = ((ToolArgs(), Seq[String]()) /: (args flatMap massage)) {
+ case ((t,others), s) => s match {
+ case "-help" => (t copy (help=true), others)
+ case "-raw" => (t copy (raw=true), others)
+ case _ => (t, others :+ s)
+ }
+ }
+ }
+
+ val helps = List(
+ "usage" -> ":javap [opts] [path or class or -]...",
+ "-help" -> "Prints this help message",
+ "-raw" -> "Don't unmangle REPL names",
+ "-verbose/-v" -> "Stack size, number of locals, method args",
+ "-private/-p" -> "Private classes and members",
+ "-package" -> "Package-private classes and members",
+ "-protected" -> "Protected classes and members",
+ "-public" -> "Public classes and members",
+ "-l" -> "Line and local variable tables",
+ "-c" -> "Disassembled code",
+ "-s" -> "Internal type signatures",
+ "-sysinfo" -> "System info of class",
+ "-constants" -> "Static final constants"
)
- loader.classBytes(extName)
+
+ // match prefixes and unpack opts, or -help on failure
+ def massage(arg: String): Seq[String] = {
+ require(arg startsWith "-")
+ // arg matches opt "-foo/-f" if prefix of -foo or exactly -f
+ val r = """(-[^/]*)(/(-.))?""".r
+ def maybe(opt: String, s: String): Option[String] = opt match {
+ // disambiguate by preferring short form
+ case r(lf,_,sf) if s == sf => Some(sf)
+ case r(lf,_,sf) if lf startsWith s => Some(lf)
+ case _ => None
+ }
+ def candidates(s: String) = (helps map (h => maybe(h._1, s))).flatten
+ // one candidate or one single-char candidate
+ def uniqueOf(maybes: Seq[String]) = {
+ def single(s: String) = s.length == 2
+ if (maybes.length == 1) maybes
+ else if ((maybes count single) == 1) maybes filter single
+ else Nil
+ }
+ // each optchar must decode to exactly one option
+ def unpacked(s: String): Try[Seq[String]] = {
+ val ones = (s drop 1) map { c =>
+ val maybes = uniqueOf(candidates(s"-$c"))
+ if (maybes.length == 1) Some(maybes.head) else None
+ }
+ Try(ones) filter (_ forall (_.isDefined)) map (_.flatten)
+ }
+ val res = uniqueOf(candidates(arg))
+ if (res.nonEmpty) res
+ else (unpacked(arg)
+ getOrElse (Seq("-help"))) // or else someone needs help
+ }
+
+ def helper(pw: PrintWriter) = new Showable {
+ def show() = helps foreach (p => pw write "%-12.12s%s%n".format(p._1,p._2))
+ }
+
+ val DefaultOptions = List("-protected", "-verbose")
+
+ def isAvailable = Seq(Env, Tool) exists (cn => hasClass(loader, cn))
+
+ private def hasClass(cl: ScalaClassLoader, cn: String) = cl.tryToInitializeClass[AnyRef](cn).isDefined
+
+ private def isTaskable(cl: ScalaClassLoader) = hasClass(cl, Tool)
+
+ def apply() = if (isTaskable(loader)) new JavapTool7 else new JavapTool6
}
}
-object Javap {
- val Env = "sun.tools.javap.JavapEnvironment"
- val Printer = "sun.tools.javap.JavapPrinter"
+object JavapClass {
+ def apply(
+ loader: ScalaClassLoader = ScalaClassLoader.appLoader,
+ printWriter: PrintWriter = new PrintWriter(System.out, true),
+ intp: Option[IMain] = None
+ ) = new JavapClass(loader, printWriter, intp)
+}
- def isAvailable(cl: ScalaClassLoader = ScalaClassLoader.appLoader) =
- cl.tryToInitializeClass[AnyRef](Env).isDefined
+object Javap {
- // "documentation"
- type FakeEnvironment = AnyRef
- type FakePrinter = AnyRef
+ def isAvailable(cl: ScalaClassLoader = ScalaClassLoader.appLoader) = JavapClass(cl).JavapTool.isAvailable
def apply(path: String): Unit = apply(Seq(path))
- def apply(args: Seq[String]): Unit = new JavapClass() apply args foreach (_.show())
+ def apply(args: Seq[String]): Unit = JavapClass() apply args foreach (_.show())
+
+ trait Showable {
+ def show(): Unit
+ }
sealed trait JpResult {
type ResultType
@@ -123,53 +452,23 @@ object Javap {
// def methods(): List[String]
// def signatures(): List[String]
}
+ object JpResult {
+ def apply(msg: String) = new JpError(msg)
+ def apply(res: Showable) = new JpSuccess(res)
+ }
class JpError(msg: String) extends JpResult {
type ResultType = String
def isError = true
def value = msg
- def show() = println(msg)
+ def show() = println(msg) // makes sense for :javap, less for -Ygen-javap
}
- class JpSuccess(val value: AnyRef) extends JpResult {
+ class JpSuccess(val value: Showable) extends JpResult {
type ResultType = AnyRef
def isError = false
- def show() = value.asInstanceOf[{ def print(): Unit }].print()
+ def show() = value.show() // output to tool's PrintWriter
}
-
- class JpOptions {
- private object Access {
- final val PRIVATE = 0
- final val PROTECTED = 1
- final val PACKAGE = 2
- final val PUBLIC = 3
- }
- private val envActionMap: Map[String, (String, Any)] = {
- val map = Map(
- "-l" -> (("showLineAndLocal", true)),
- "-c" -> (("showDisassembled", true)),
- "-s" -> (("showInternalSigs", true)),
- "-verbose" -> (("showVerbose", true)),
- "-private" -> (("showAccess", Access.PRIVATE)),
- "-package" -> (("showAccess", Access.PACKAGE)),
- "-protected" -> (("showAccess", Access.PROTECTED)),
- "-public" -> (("showAccess", Access.PUBLIC)),
- "-all" -> (("showallAttr", true))
- )
- map ++ List(
- "-v" -> map("-verbose"),
- "-p" -> map("-private")
- )
- }
- def apply(opts: Seq[String]): Seq[(String, Any)] = {
- opts flatMap { opt =>
- envActionMap get opt match {
- case Some(pair) => List(pair)
- case _ =>
- val charOpts = opt.tail.toSeq map ("-" + _)
- if (charOpts forall (envActionMap contains _))
- charOpts map envActionMap
- else Nil
- }
- }
- }
+ implicit class Lastly[A](val t: Try[A]) extends AnyVal {
+ private def effect[X](last: =>Unit)(a: X): Try[A] = { last; t }
+ def lastly(last: =>Unit): Try[A] = t transform (effect(last) _, effect(last) _)
}
}
diff --git a/src/compiler/scala/tools/util/PathResolver.scala b/src/compiler/scala/tools/util/PathResolver.scala
index 0af1011bda..5d79a7d6cd 100644
--- a/src/compiler/scala/tools/util/PathResolver.scala
+++ b/src/compiler/scala/tools/util/PathResolver.scala
@@ -6,7 +6,6 @@
package scala.tools
package util
-import java.net.{ URL, MalformedURLException }
import scala.tools.reflect.WrappedProperties.AccessControl
import nsc.{ Settings, GenericRunnerSettings }
import nsc.util.{ ClassPath, JavaClassPath, ScalaClassLoader }
@@ -19,16 +18,9 @@ import scala.language.postfixOps
// https://wiki.scala-lang.org/display/SW/Classpath
object PathResolver {
- // Imports property/environment functions which suppress
- // security exceptions.
+ // Imports property/environment functions which suppress security exceptions.
import AccessControl._
- def firstNonEmpty(xs: String*) = xs find (_ != "") getOrElse ""
-
- /** Map all classpath elements to absolute paths and reconstruct the classpath.
- */
- def makeAbsolute(cp: String) = ClassPath.map(cp, x => Path(x).toAbsolute.path)
-
/** pretty print class path */
def ppcp(s: String) = split(s) match {
case Nil => ""
@@ -46,7 +38,6 @@ object PathResolver {
/** Environment variables which java pays attention to so it
* seems we do as well.
*/
- def classPathEnv = envOrElse("CLASSPATH", "")
def sourcePathEnv = envOrElse("SOURCEPATH", "")
def javaBootClassPath = propOrElse("sun.boot.class.path", searchForBootClasspath)
@@ -86,7 +77,6 @@ object PathResolver {
def scalaHome = Environment.scalaHome
def scalaHomeDir = Directory(scalaHome)
- def scalaHomeExists = scalaHomeDir.isDirectory
def scalaLibDir = Directory(scalaHomeDir / "lib")
def scalaClassesDir = Directory(scalaHomeDir / "classes")
@@ -109,15 +99,7 @@ object PathResolver {
// classpath as set up by the runner (or regular classpath under -nobootcp)
// and then again here.
def scalaBootClassPath = ""
- // scalaLibDirFound match {
- // case Some(dir) if scalaHomeExists =>
- // val paths = ClassPath expandDir dir.path
- // join(paths: _*)
- // case _ => ""
- // }
-
def scalaExtDirs = Environment.scalaExtDirs
-
def scalaPluginPath = (scalaHomeDir / "misc" / "scala-devel" / "plugins").path
override def toString = """
@@ -136,7 +118,7 @@ object PathResolver {
)
}
- def fromPathString(path: String, context: JavaContext = DefaultJavaContext): JavaClassPath = {
+ def fromPathString(path: String, context: JavaContext = DefaultJavaContext): JavaClassPath = { // called from scalap
val s = new Settings()
s.classpath.value = path
new PathResolver(s, context) result
@@ -161,7 +143,7 @@ object PathResolver {
}
}
}
-import PathResolver.{ Defaults, Environment, firstNonEmpty, ppcp }
+import PathResolver.{ Defaults, Environment, ppcp }
class PathResolver(settings: Settings, context: JavaContext) {
def this(settings: Settings) = this(settings, if (settings.inline.value) new JavaContext else DefaultJavaContext)
diff --git a/src/continuations/library/scala/util/continuations/ControlContext.scala b/src/continuations/library/scala/util/continuations/ControlContext.scala
index 44a5b537b6..c196809da9 100644
--- a/src/continuations/library/scala/util/continuations/ControlContext.scala
+++ b/src/continuations/library/scala/util/continuations/ControlContext.scala
@@ -183,7 +183,7 @@ final class ControlContext[+A,-B,+C](val fun: (A => B, Exception => B) => C, val
// need filter or other functions?
- final def flatMapCatch[A1>:A,B1<:B,C1>:C<:B1](pf: PartialFunction[Exception, ControlContext[A1,B1,C1]]): ControlContext[A1,B1,C1] = {
+ final def flatMapCatch[A1>:A,B1<:B,C1>:C<:B1](pf: PartialFunction[Exception, ControlContext[A1,B1,C1]]): ControlContext[A1,B1,C1] = { // called by codegen from SelectiveCPSTransform
if (fun eq null)
this
else {
@@ -209,7 +209,7 @@ final class ControlContext[+A,-B,+C](val fun: (A => B, Exception => B) => C, val
}
}
- final def mapFinally(f: () => Unit): ControlContext[A,B,C] = {
+ final def mapFinally(f: () => Unit): ControlContext[A,B,C] = { // called in code generated by SelectiveCPSTransform
if (fun eq null) {
try {
f()
diff --git a/src/continuations/library/scala/util/continuations/package.scala b/src/continuations/library/scala/util/continuations/package.scala
index 90bab56805..573fae85e7 100644
--- a/src/continuations/library/scala/util/continuations/package.scala
+++ b/src/continuations/library/scala/util/continuations/package.scala
@@ -166,8 +166,8 @@ package object continuations {
throw new NoSuchMethodException("this code has to be compiled with the Scala continuations plugin enabled")
}
- def shiftUnitR[A,B](x: A): ControlContext[A,B,B] = {
- new ControlContext(null, x)
+ def shiftUnitR[A,B](x: A): ControlContext[A,B,B] = { // called in code generated by SelectiveCPSTransform
+ new ControlContext[A, B, B](null, x)
}
/**
@@ -176,11 +176,11 @@ package object continuations {
* a final result.
* @see shift
*/
- def shiftR[A,B,C](fun: (A => B) => C): ControlContext[A,B,C] = {
+ def shiftR[A,B,C](fun: (A => B) => C): ControlContext[A,B,C] = { // called in code generated by SelectiveCPSTransform
new ControlContext((f:A=>B,g:Exception=>B) => fun(f), null.asInstanceOf[A])
}
- def reifyR[A,B,C](ctx: => ControlContext[A,B,C]): ControlContext[A,B,C] = {
+ def reifyR[A,B,C](ctx: => ControlContext[A,B,C]): ControlContext[A,B,C] = { // called in code generated by SelectiveCPSTransform
ctx
}
diff --git a/src/continuations/plugin/scala/tools/selectivecps/CPSAnnotationChecker.scala b/src/continuations/plugin/scala/tools/selectivecps/CPSAnnotationChecker.scala
index 15025f85e3..c147dc483d 100644
--- a/src/continuations/plugin/scala/tools/selectivecps/CPSAnnotationChecker.scala
+++ b/src/continuations/plugin/scala/tools/selectivecps/CPSAnnotationChecker.scala
@@ -96,7 +96,7 @@ abstract class CPSAnnotationChecker extends CPSUtils with Modes {
if (!cpsEnabled) return bounds
val anyAtCPS = newCpsParamsMarker(NothingClass.tpe, AnyClass.tpe)
- if (isFunctionType(tparams.head.owner.tpe) || isPartialFunctionType(tparams.head.owner.tpe)) {
+ if (isFunctionType(tparams.head.owner.tpe_*) || isPartialFunctionType(tparams.head.owner.tpe_*)) {
vprintln("function bound: " + tparams.head.owner.tpe + "/"+bounds+"/"+targs)
if (hasCpsParamTypes(targs.last))
bounds.reverse match {
@@ -356,7 +356,7 @@ abstract class CPSAnnotationChecker extends CPSUtils with Modes {
global.globalError("not a single cps annotation: " + xs)
xs(0)
}
-
+
def emptyOrSingleList(xs: List[AnnotationInfo]) = if (xs.isEmpty) Nil else List(single(xs))
def transChildrenInOrder(tree: Tree, tpe: Type, childTrees: List[Tree], byName: List[Tree]) = {
diff --git a/src/continuations/plugin/scala/tools/selectivecps/CPSUtils.scala b/src/continuations/plugin/scala/tools/selectivecps/CPSUtils.scala
index 46c644bcd6..4924e056af 100644
--- a/src/continuations/plugin/scala/tools/selectivecps/CPSUtils.scala
+++ b/src/continuations/plugin/scala/tools/selectivecps/CPSUtils.scala
@@ -7,7 +7,6 @@ import scala.tools.nsc.Global
trait CPSUtils {
val global: Global
import global._
- import definitions._
var cpsEnabled = false
val verbose: Boolean = System.getProperty("cpsVerbose", "false") == "true"
@@ -36,7 +35,7 @@ trait CPSUtils {
lazy val MarkerCPSAdaptMinus = rootMirror.getRequiredClass("scala.util.continuations.cpsMinus")
lazy val Context = rootMirror.getRequiredClass("scala.util.continuations.ControlContext")
- lazy val ModCPS = rootMirror.getRequiredPackage("scala.util.continuations")
+ lazy val ModCPS = rootMirror.getPackage("scala.util.continuations")
lazy val MethShiftUnit = definitions.getMember(ModCPS, cpsNames.shiftUnit)
lazy val MethShiftUnit0 = definitions.getMember(ModCPS, cpsNames.shiftUnit0)
@@ -57,7 +56,7 @@ trait CPSUtils {
protected def newMarker(sym: Symbol): AnnotationInfo = AnnotationInfo marker sym.tpe
protected def newCpsParamsMarker(tp1: Type, tp2: Type) =
- newMarker(appliedType(MarkerCPSTypes.tpe, List(tp1, tp2)))
+ newMarker(appliedType(MarkerCPSTypes, tp1, tp2))
// annotation checker
diff --git a/src/continuations/plugin/scala/tools/selectivecps/SelectiveANFTransform.scala b/src/continuations/plugin/scala/tools/selectivecps/SelectiveANFTransform.scala
index 8b39bf3961..5775c662da 100644
--- a/src/continuations/plugin/scala/tools/selectivecps/SelectiveANFTransform.scala
+++ b/src/continuations/plugin/scala/tools/selectivecps/SelectiveANFTransform.scala
@@ -2,13 +2,10 @@
package scala.tools.selectivecps
-import scala.tools.nsc._
import scala.tools.nsc.transform._
import scala.tools.nsc.symtab._
import scala.tools.nsc.plugins._
-import scala.tools.nsc.ast._
-
/**
* In methods marked @cps, explicitly name results of calls to other @cps methods
*/
@@ -131,7 +128,7 @@ abstract class SelectiveANFTransform extends PluginComponent with Transform with
def transformPureMatch(tree: Tree, selector: Tree, cases: List[CaseDef]) = {
val caseVals = cases map { case cd @ CaseDef(pat, guard, body) =>
- // if (!hasPlusMarker(body.tpe)) body.tpe = body.tpe withAnnotation newPlusMarker() // TODO: to avoid warning
+ // if (!hasPlusMarker(body.tpe)) body modifyType (_ withAnnotation newPlusMarker()) // TODO: to avoid warning
val bodyVal = transExpr(body, None, ext) // ??? triggers "cps-transformed unexpectedly" warning in transTailValue
treeCopy.CaseDef(cd, transform(pat), transform(guard), bodyVal)
}
@@ -172,7 +169,7 @@ abstract class SelectiveANFTransform extends PluginComponent with Transform with
debuglog("transforming valdef " + vd.symbol)
if (getExternalAnswerTypeAnn(tpt.tpe).isEmpty) {
-
+
atOwner(vd.symbol) {
val rhs1 = transExpr(rhs, None, None)
@@ -471,7 +468,7 @@ abstract class SelectiveANFTransform extends PluginComponent with Transform with
val sym: Symbol = (
currentOwner.newValue(newTermName(unit.fresh.newName("tmp")), tree.pos, Flags.SYNTHETIC)
setInfo valueTpe
- setAnnotations List(AnnotationInfo(MarkerCPSSym.tpe, Nil, Nil))
+ setAnnotations List(AnnotationInfo(MarkerCPSSym.tpe_*, Nil, Nil))
)
expr.changeOwner(currentOwner -> sym)
@@ -503,9 +500,7 @@ abstract class SelectiveANFTransform extends PluginComponent with Transform with
// TODO: better yet: do without annotations on symbols
val spcVal = getAnswerTypeAnn(anfRhs.tpe)
- if (spcVal.isDefined) {
- tree.symbol.setAnnotations(List(AnnotationInfo(MarkerCPSSym.tpe, Nil, Nil)))
- }
+ spcVal foreach (_ => tree.symbol setAnnotations List(AnnotationInfo(MarkerCPSSym.tpe_*, Nil, Nil)))
(stms:::List(treeCopy.ValDef(tree, mods, name, tpt, anfRhs)), linearize(spc, spcVal)(unit, tree.pos))
diff --git a/src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSPlugin.scala b/src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSPlugin.scala
index 8a500d6c4d..90e64d8171 100644
--- a/src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSPlugin.scala
+++ b/src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSPlugin.scala
@@ -3,15 +3,11 @@
package scala.tools.selectivecps
import scala.tools.nsc
-import scala.tools.nsc.typechecker._
import nsc.Global
-import nsc.Phase
import nsc.plugins.Plugin
import nsc.plugins.PluginComponent
class SelectiveCPSPlugin(val global: Global) extends Plugin {
- import global._
-
val name = "continuations"
val description = "applies selective cps conversion"
@@ -26,7 +22,6 @@ class SelectiveCPSPlugin(val global: Global) extends Plugin {
override val runsBefore = List("uncurry")
}
-
val components = List[PluginComponent](anfPhase, cpsPhase)
val checker = new CPSAnnotationChecker {
diff --git a/src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSTransform.scala b/src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSTransform.scala
index 4482bf2b7c..2a6c1e1967 100644
--- a/src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSTransform.scala
+++ b/src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSTransform.scala
@@ -2,13 +2,8 @@
package scala.tools.selectivecps
-import scala.collection._
-
-import scala.tools.nsc._
import scala.tools.nsc.transform._
import scala.tools.nsc.plugins._
-
-import scala.tools.nsc.ast.TreeBrowsers
import scala.tools.nsc.ast._
/**
@@ -56,7 +51,7 @@ abstract class SelectiveCPSTransform extends PluginComponent with
case _ =>
getExternalAnswerTypeAnn(tp) match {
case Some((res, outer)) =>
- appliedType(Context.tpe, List(removeAllCPSAnnotations(tp), res, outer))
+ appliedType(Context.tpeHK, List(removeAllCPSAnnotations(tp), res, outer))
case _ =>
removeAllCPSAnnotations(tp)
}
@@ -90,7 +85,7 @@ abstract class SelectiveCPSTransform extends PluginComponent with
//gen.mkAttributedSelect(gen.mkAttributedSelect(gen.mkAttributedSelect(gen.mkAttributedIdent(ScalaPackage),
//ScalaPackage.tpe.member("util")), ScalaPackage.tpe.member("util").tpe.member("continuations")), MethShiftR)
//gen.mkAttributedRef(ModCPS.tpe, MethShiftR) // TODO: correct?
- debuglog("funR.tpe = " + funR.tpe)
+ debuglog("funR.tpe: " + funR.tpe)
Apply(
TypeApply(funR, targs).setType(appliedType(funR.tpe, targs.map((t:Tree) => t.tpe))),
args.map(transform(_))
@@ -102,12 +97,12 @@ abstract class SelectiveCPSTransform extends PluginComponent with
debuglog("found shiftUnit: " + tree)
atPos(tree.pos) {
val funR = gen.mkAttributedRef(MethShiftUnitR) // TODO: correct?
- debuglog("funR.tpe = " + funR.tpe)
+ debuglog("funR.tpe: " + funR.tpe)
Apply(
TypeApply(funR, List(targs(0), targs(1))).setType(appliedType(funR.tpe,
List(targs(0).tpe, targs(1).tpe))),
args.map(transform(_))
- ).setType(appliedType(Context.tpe, List(targs(0).tpe,targs(1).tpe,targs(1).tpe)))
+ ).setType(appliedType(Context.tpeHK, List(targs(0).tpe,targs(1).tpe,targs(1).tpe)))
}
case Apply(TypeApply(fun, targs), args)
@@ -115,7 +110,7 @@ abstract class SelectiveCPSTransform extends PluginComponent with
log("found reify: " + tree)
atPos(tree.pos) {
val funR = gen.mkAttributedRef(MethReifyR) // TODO: correct?
- debuglog("funR.tpe = " + funR.tpe)
+ debuglog("funR.tpe: " + funR.tpe)
Apply(
TypeApply(funR, targs).setType(appliedType(funR.tpe, targs.map((t:Tree) => t.tpe))),
args.map(transform(_))
@@ -192,7 +187,7 @@ abstract class SelectiveCPSTransform extends PluginComponent with
val targettp = transformCPSType(tree.tpe)
val pos = catches.head.pos
- val funSym = currentOwner.newValueParameter(cpsNames.catches, pos).setInfo(appliedType(PartialFunctionClass.tpe, List(ThrowableClass.tpe, targettp)))
+ val funSym = currentOwner.newValueParameter(cpsNames.catches, pos).setInfo(appliedType(PartialFunctionClass, ThrowableClass.tpe, targettp))
val funDef = localTyper.typedPos(pos) {
ValDef(funSym, Match(EmptyTree, catches1))
}
@@ -350,7 +345,7 @@ abstract class SelectiveCPSTransform extends PluginComponent with
val ctxSym = currentOwner.newValue(newTermName("" + vd.symbol.name + cpsNames.shiftSuffix)).setInfo(rhs1.tpe)
val ctxDef = localTyper.typed(ValDef(ctxSym, rhs1))
def ctxRef = localTyper.typed(Ident(ctxSym))
- val argSym = currentOwner.newValue(vd.symbol.name).setInfo(tpe)
+ val argSym = currentOwner.newValue(vd.symbol.name.toTermName).setInfo(tpe)
val argDef = localTyper.typed(ValDef(argSym, Select(ctxRef, ctxRef.tpe.member(cpsNames.getTrivialValue))))
val switchExpr = localTyper.typedPos(vd.symbol.pos) {
val body2 = mkBlock(bodyStms, bodyExpr).duplicate // dup before typing!
diff --git a/src/detach/library/scala/remoting/Channel.scala b/src/detach/library/scala/remoting/Channel.scala
deleted file mode 100644
index e60d16c0d5..0000000000
--- a/src/detach/library/scala/remoting/Channel.scala
+++ /dev/null
@@ -1,190 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2007-2013, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id: Channel.scala 18365 2009-07-21 11:00:42Z michelou $
-
-package scala.remoting
-
-import java.io._
-import java.net._
-import java.rmi.server.RMIClassLoader
-
-/** <p>
- * The class <code>Channel</code> implements (basic) typed channels
- * which use <a href="http://java.sun.com/docs/books/tutorial/networking/sockets/"
- * target="_top"/>Java socket</a> communication and Scala type manifests to
- * provide type-safe send/receive operations between a localhost and another
- * remote machine by specifying some <code>host</code> and <code>port</code>.
- * </p>
- *
- * @author Stephane Micheloud
- * @version 1.1
- */
-class Channel protected (socket: Socket) {
-
- // Create a socket without a timeout
- def this(host: String, port: Int) = this(new Socket(host, port))
-
- // // Create a socket with a timeout
- // val sockaddr: SocketAddress = new InetSocketAddress(addr, port)
- // val socket = new Socket()
- // // If the timeout occurs, SocketTimeoutException is thrown.
- // socket.connect(sockaddr, 2000) // 2 seconds
-
- /** Returns the local address of this channel. */
- val host = socket.getInetAddress.getHostAddress
-
- /** Returns the port on which this channel is listening. */
- val port = socket.getLocalPort
-
- private var cl: ClassLoader =
- try {
- // requires permission in Java policy file
- val codebase = System.getProperty("java.rmi.server.codebase")
- if (codebase != null) info("codebase="+codebase)
- RMIClassLoader.getClassLoader(codebase)
- }
- catch {
- case e: Exception =>
- sys.error("Class loader undefined: " + e.getMessage)
- null
- }
- def classLoader: ClassLoader = cl
- def classLoader_=(x: ClassLoader) { cl = x }
-
- info(""+this)
-
- private class CustomObjectInputStream(in: InputStream)
- extends ObjectInputStream(in) {
- override def resolveClass(desc: ObjectStreamClass): Class[_] =
- if (cl eq null)
- super.resolveClass(desc)
- else
- try {
- info("resolve class "+desc.getName)
- cl loadClass desc.getName
- }
- catch {
- case e: ClassNotFoundException =>
- super.resolveClass(desc)
- }
- }
-
- // lazy modifier is required!
- private lazy val in =
- try {
- new CustomObjectInputStream(socket.getInputStream)
- }
- catch {
- case e: IOException =>
- sys.error("Input stream undefined: "+e.getMessage+" ("+this+")")
- null
- }
- private lazy val out =
- try {
- new ObjectOutputStream(socket.getOutputStream)
- }
- catch {
- case e: IOException =>
- sys.error("Output stream undefined: "+e.getMessage+" ("+this+")")
- null
- }
-
- /** <code>receive&lt;primtype&gt;</code> methods may throw an
- * <code>IOException</code>.
- */
- def receiveUnit = receive[Unit]
- def receiveBoolean = receive[Boolean]
- def receiveByte = receive[Byte]
- def receiveChar = receive[Char]
- def receiveShort = receive[Short]
- def receiveInt = receive[Int]
- def receiveLong = receive[Long]
- def receiveFloat = receive[Float]
- def receiveDouble = receive[Double]
- def receiveString = receive[String]
-
- /** <code>receive</code> method may throw either an
- * <code>ClassNotFoundException</code> or an <code>IOException</code>.
- *
- * @throw <code>ChannelException</code> if received value has not
- * the expected type.
- */
- @throws(classOf[ChannelException])
- def receive[T](implicit expected: scala.reflect.ClassTag[T]): T = {
- val found = in.readObject().asInstanceOf[reflect.ClassTag[_]]
- info("receive: found="+found+", expected="+expected)
- import scala.reflect.ClassTag
- val x = found match {
- case ClassTag.Unit => ()
- case ClassTag.Boolean => in.readBoolean()
- case ClassTag.Byte => in.readByte()
- case ClassTag.Char => in.readChar()
- case ClassTag.Short => in.readShort()
- case ClassTag.Int => in.readInt()
- case ClassTag.Long => in.readLong()
- case ClassTag.Float => in.readFloat()
- case ClassTag.Double => in.readDouble()
- case _ => in.readObject()
- }
- val res = if (found <:< expected)
- x.asInstanceOf[T]
- else
- throw new ChannelException(
- "\n\tfound \""+found+"\"\n\texpected \""+expected+"\"")
- info("received "+res+" (available="+in.available+")")
- res
- }
-
- /** <code>?</code> method may throw either an
- * <code>ClassNotFoundException</code> or an <code>IOException</code>.
- */
- def ?[T](implicit t: scala.reflect.ClassTag[T]): T = receive[T](t)
-
- /** <code>send</code> method may throw an <code>IOException</code>.
- */
- def send[T](x: T)(implicit t: scala.reflect.ClassTag[T]) {
- out writeObject t
- x match {
- case x: Unit => // nop
- case x: Boolean => out writeBoolean x
- case x: Byte => out writeByte x
- case x: Char => out writeChar x
- case x: Short => out writeShort x
- case x: Int => out writeInt x
- case x: Long => out writeLong x
- case x: Float => out writeFloat x
- case x: Double => out writeDouble x
- case x => out writeObject x
- }
- out.flush()
- info("sent "+x)
- }
-
- /** <code>!</code> method may throw an <code>IOException</code>.
- */
- def ![T](x: T)(implicit m: scala.reflect.ClassTag[T]) { send(x)(m) }
-
- def close() {
- try { socket.close() }
- catch { case e: IOException => }
- info(this+" closed")
- }
-
- override def toString: String = socket.toString
-
- private def info(msg: String) {
- runtime.remoting.Debug.info("[Channel] "+msg)
- }
-}
-
-/** <code>ChannelException</code> may be thrown by the operation
- * <code>receive</code> when the received data has not the expected type.
- */
-case class ChannelException(msg: String) extends IOException(msg)
-
diff --git a/src/detach/library/scala/remoting/Debug.scala b/src/detach/library/scala/remoting/Debug.scala
deleted file mode 100644
index 79f2bcedde..0000000000
--- a/src/detach/library/scala/remoting/Debug.scala
+++ /dev/null
@@ -1,27 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2007-2013, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id: Debug.scala 17412 2009-03-31 10:08:25Z michelou $
-
-package scala.remoting
-
-/**
- * @author Stephane Micheloud
- * @version 1.0
- */
-object Debug extends runtime.remoting.Debug {
- private val f = new java.text.SimpleDateFormat("HH:mm:ss")
- private val c = new java.util.GregorianCalendar
-
- def getTime: String = f format c.getTime
-
- def getLocation(obj: AnyRef): String = {
- val s = obj.getClass().getClassLoader().toString()
- s substring s.indexOf('[')
- }
-}
diff --git a/src/detach/library/scala/remoting/ServerChannel.scala b/src/detach/library/scala/remoting/ServerChannel.scala
deleted file mode 100644
index 7828f85a1d..0000000000
--- a/src/detach/library/scala/remoting/ServerChannel.scala
+++ /dev/null
@@ -1,68 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2007-2013, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id: ServerChannel.scala 18365 2009-07-21 11:00:42Z michelou $
-
-package scala.remoting
-
-import java.net.{ServerSocket, Socket}
-
-/** <p>
- * Creates a server channel and binds its associated socket to the
- * specified port number.<br/>
- * Example:
- * </p><pre>
- * <b>class</b> ComputeChannel(s: Socket) <b>extends</b> Channel(s) {
- * <b>def</b> receiveFunc = receive[Int => Int]
- * }
- * <b>class</b> ComputeServer(p: Int)
- * <b>extends</b> AbstractServerChannel[ComputeChannel](p) {
- * <b>def</b> newChannel(s: Socket) = <b>new</b> ComputeChannel(s)
- * }</pre>
- *
- * @author Stephane Micheloud
- * @version 1.0
- */
-class ServerChannel(p: Int) extends AbstractServerChannel[Channel](p) {
- def newChannel(s: Socket) = new Channel(s)
-}
-
-abstract class AbstractServerChannel[T <: Channel](_port: Int) {
-
- /** Creates an input channel and binds its associated socket to any
- * free port.
- */
- def this() = this(0)
-
- // The maximum queue length for incoming requests to connect is set to 50.
- private val serverSocket = new ServerSocket(_port)
-
- /** Returns the local address of this channel. */
- val host = serverSocket.getInetAddress.getHostAddress
-
- /** Returns the port on which this channel is listening. */
- val port = serverSocket.getLocalPort
- info("Listening on port "+port)
-
- protected def newChannel(socket: Socket): T
-
- def accept: T = {
- System.gc() // required!
- newChannel(serverSocket.accept)
- }
-
- def close() {
- try { serverSocket.close() }
- catch { case e: java.io.IOException => }
- info("Server socket "+host+":"+port+" closed")
- }
-
- protected def info(msg: String) {
- runtime.remoting.Debug.info("[ServerChannel] "+msg)
- }
-}
diff --git a/src/detach/library/scala/remoting/detach.scala b/src/detach/library/scala/remoting/detach.scala
deleted file mode 100644
index 51a3ac515d..0000000000
--- a/src/detach/library/scala/remoting/detach.scala
+++ /dev/null
@@ -1,49 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2002-2013, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://www.scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id: detach.scala 16901 2009-01-13 15:37:05Z michelou $
-
-package scala.remoting
-
-
-/** The <code>detach</code> object is a <em>marker object</em> which informs
- * the Scala compiler that arguments whose type is a function type are
- * eligible for remote closure generation.
- *
- * @author Stephane Micheloud
- * @version 1.0, 13/07/2005
- */
-object detach {
-
- def apply[R](f: Function0[R]): Function0[R] = f
- def apply[T0, R](f: Function1[T0, R]): Function1[T0, R] = f
- def apply[T0, T1, R](f: Function2[T0, T1, R]): Function2[T0, T1, R] = f
- def apply[T0, T1, T2, R](f: Function3[T0, T1, T2, R]): Function3[T0, T1, T2, R] = f
- def apply[T0, T1, T2, T3, R](f: Function4[T0, T1, T2, T3, R]): Function4[T0, T1, T2, T3, R] = f
- def apply[T0, T1, T2, T3, T4, R](f: Function5[T0, T1, T2, T3, T4, R]): Function5[T0, T1, T2, T3, T4, R] = f
- def apply[T0, T1, T2, T3, T4, T5, R](f: Function6[T0, T1, T2, T3, T4, T5, R]): Function6[T0, T1, T2, T3, T4, T5, R] = f
- def apply[T0, T1, T2, T3, T4, T5, T6, R](f: Function7[T0, T1, T2, T3, T4, T5, T6, R]): Function7[T0, T1, T2, T3, T4, T5, T6, R] = f
- def apply[T0, T1, T2, T3, T4, T5, T6, T7, R](f: Function8[T0, T1, T2, T3, T4, T5, T6, T7, R]): Function8[T0, T1, T2, T3, T4, T5, T6, T7, R] = f
- def apply[T0, T1, T2, T3, T4, T5, T6, T7, T8, R](f: Function9[T0, T1, T2, T3, T4, T5, T6, T7, T8, R]): Function9[T0, T1, T2, T3, T4, T5, T6, T7, T8, R] = f
-
- // since 2.7.0
- def apply[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, R](f: Function10[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, R]): Function10[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, R] = f
- def apply[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R](f: Function11[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R]): Function11[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R] = f
- def apply[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R](f: Function12[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R]): Function12[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R] = f
- def apply[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R](f: Function13[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R]): Function13[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R] = f
- def apply[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R](f: Function14[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R]): Function14[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R] = f
- def apply[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R](f: Function15[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R]): Function15[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R] = f
- def apply[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R](f: Function16[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R]): Function16[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R] = f
- def apply[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R](f: Function17[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R]): Function17[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R] = f
- def apply[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, R](f: Function18[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, R]): Function18[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, R] = f
- def apply[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, R](f: Function19[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, R]): Function19[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, R] = f
- def apply[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, R](f: Function20[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, R]): Function20[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, R] = f
- def apply[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, R](f: Function21[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, R]): Function21[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, R] = f
- def apply[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, R](f: Function22[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, R]): Function22[T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, R] = f
-}
-
diff --git a/src/detach/library/scala/runtime/RemoteRef.scala b/src/detach/library/scala/runtime/RemoteRef.scala
deleted file mode 100644
index e65b22cb71..0000000000
--- a/src/detach/library/scala/runtime/RemoteRef.scala
+++ /dev/null
@@ -1,182 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2002-2013, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id: RemoteRef.scala 18365 2009-07-21 11:00:42Z michelou $
-
-package scala.runtime
-
-import java.net.{InetAddress, MalformedURLException}
-import java.rmi.{NoSuchObjectException, NotBoundException, Remote}
-import java.rmi.registry.{LocateRegistry, Registry}
-import java.rmi.server.{ExportException, RemoteObject, UnicastRemoteObject}
-
-import scala.runtime.remoting.{Debug, RemoteGC}
-
-/**
- *
- * @author Stephane Micheloud
- * @version 1.0
- */
-object RemoteRef { /*extends Thread {
- start()
-
- private class QuitException extends Exception
- private var isTerminated = false
-
- // keeps track of live remote objects
- val remoteGC = new RemoteGC
-
- override def run() {
- info("started thread")
- try {
- while (!isTerminated) {
- this.synchronized {
- try {
- wait(200)
- } catch {
- case _: InterruptedException =>
- if (isTerminated) throw new QuitException
- }
- remoteGC.gc()
- if (remoteGC.allClosed)
- throw new QuitException
- } // synchronized
-
- }
- } catch {
- case _: QuitException =>
- // allow thread to exit
- }
- }
-*/
- try {
- val prop = System.getProperty("sun.rmi.dgc.server.gcInterval")
- if (prop eq null)
- System.setProperty("sun.rmi.dgc.server.gcInterval", "10000")
- }
- catch {
- case e =>
- error(e.getMessage)
- }
-
- private val host =
- try {
- val prop = System.getProperty("java.rmi.server.hostname")
- if (prop ne null) prop else InetAddress.getLocalHost.getHostAddress
- }
- catch {
- case e =>
- warning(e.getMessage)
- InetAddress.getLocalHost.getHostAddress
- }
-
- private val port =
- try {
- val prop = System.getProperty("scala.remoting.port")
- if (prop ne null) prop.toInt else Registry.REGISTRY_PORT
- }
- catch {
- case e =>
- warning(e.getMessage)
- Registry.REGISTRY_PORT // default port
- }
-
- private val registry =
- try {
- LocateRegistry.createRegistry(port)
- }
- catch {
- case e =>
- warning(e.getMessage)
- LocateRegistry.getRegistry(host, port)
- }
-
- private val prefix = "//"+host+":"+port+"/"
- printDebugInfos
-
- // Variant 1: rebind/unbind
- def bind(name: String, x: Remote): Remote =
- try {
- registry.rebind(prefix+name, x)
- info("\""+prefix+name+"\" bound")
- val stub = RemoteObject.toStub(x)
- //remoteGC.newRef(stub)
- stub
- } catch {
- case e: MalformedURLException =>
- error(e.getMessage); null
- case e: ExportException =>
- info(""+e); null
- case e: Exception => // AlreadyBoundException, etc..
- throw e
- }
-
- def unbind(name: String) =
- try {
- registry.unbind(prefix+name)
- info("\""+name+"\" unbound")
- } catch {
- case e: java.io.EOFException =>
- warning(e.getMessage)
- case e: NotBoundException =>
- warning(e.getMessage+" already unbound")
- case e: MalformedURLException =>
- error(e.getMessage)
- case e: Exception =>
- throw e
- }
-/*
- // Variant 2: un-/exportObject
- def bind(name: String, x: Remote): Remote =
- try {
- val ex = UnicastRemoteObject.exportObject(x)
- registry.rebind(prefix+name, ex)
- info("\""+prefix+name+"\" bound")
- //val stub = RemoteObject.toStub(ex)
- //remoteGC.newRef(ex)
- ex //stub
- } catch {
- case e: MalformedURLException =>
- error(e.getMessage); null
- case e: ExportException =>
- info(""+e); null
- case e: Exception => // AlreadyBoundException, etc..
- throw e
- }
-
- def unbind(x: Remote) {
- try {
- UnicastRemoteObject.unexportObject(x, false)
- info("\""+x+"\" unbound")
- } catch {
- case e: java.io.EOFException =>
- warning(e.getMessage)
- case e: NotBoundException =>
- warning(e.getMessage+" already unbound")
- case e: MalformedURLException =>
- error(e.getMessage)
- case e: Exception =>
- throw e
- }
- }
-*/
- private def info(msg: String) { Debug.info("[RemoteRef] "+msg) }
- private def warning(msg: String) { Debug.warning("[RemoteRef] "+msg) }
- private def error(msg: String) { Debug.error("[RemoteRef] "+msg) }
-
- private def printDebugInfos() {
- def property(name: String): String =
- name+"="+(
- try { System.getProperty(name, "") }
- catch { case e => warning(e.getMessage); "?" })
- info(property("java.rmi.server.hostname"))
- info(property("sun.rmi.dgc.server.gcInterval"))
- info("registry="+registry)
- info("prefix="+prefix)
- }
-}
diff --git a/src/detach/library/scala/runtime/remoting/Debug.scala b/src/detach/library/scala/runtime/remoting/Debug.scala
deleted file mode 100644
index 06cdc67997..0000000000
--- a/src/detach/library/scala/runtime/remoting/Debug.scala
+++ /dev/null
@@ -1,85 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2007-2013, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id: Debug.scala 17777 2009-05-19 18:16:25Z michelou $
-
-package scala.runtime.remoting
-
-/**
- * @author Stephane Micheloud
- * @version 1.0
- */
-object Debug extends Debug {
- override def info (msg: String) { if (lib) super.info(msg) }
- override def verbose(msg: String) { if (lib) super.verbose(msg) }
- override def warning(msg: String) { if (lib) super.warning(msg) }
- override def error (msg: String) { if (lib) super.error(msg) }
-}
-
-/**
- * @author Stephane Micheloud
- * @version 1.0
- */
-class Debug(tag: String) {
-
- def this() = this("")
-
- object Level extends Enumeration {
- type Level = Value
- val SILENT, ERROR, WARNING, VERBOSE, INFO = Value
- }
-
- private val level0 =
- try {
- val prop = System.getProperty("scala.remoting.logLevel")
- if (prop ne null) prop.toLowerCase else ""
- }
- catch {
- case e =>
- Console.err.println(e.getMessage)
- ""
- }
-
- import Level._
- protected var (lev, lib) = {
- val p = java.util.regex.Pattern.compile("(error|warning|verbose|info)(\\,lib)?(.*)")
- val m = p matcher level0
- val (s, b) =
- if (m.matches) (m.group(1), m.group(2) ne null)
- else ("", false)
- s match {
- case "error" => (ERROR , b)
- case "warning" => (WARNING, b)
- case "verbose" => (VERBOSE, b)
- case "info" => (INFO , b)
- case _ => (SILENT , false)
- }
- }
-
- def level = lev
- def level_= (lev: Level) = { this.lev = lev }
-
- private val tag0: String =
- if (tag != null & tag.length > 0) tag+" " else ""
-
- def info(msg: String) {
- if (lev >= INFO) Console.println(tag0 + "(info): " + msg)
- }
-
- def verbose(msg: String) {
- if (lev >= VERBOSE) Console.println(tag0 + "(verb): " + msg)
- }
-
- def warning(msg: String) {
- if (lev >= WARNING) Console.err.println(tag0 + "(warn): " + msg)
- }
-
- def error(msg: String) {
- if (lev >= ERROR) Console.err.println(tag0 + "(erro): " + msg)
- }
-}
diff --git a/src/detach/library/scala/runtime/remoting/RegistryDelegate.scala b/src/detach/library/scala/runtime/remoting/RegistryDelegate.scala
deleted file mode 100644
index 1105832ef7..0000000000
--- a/src/detach/library/scala/runtime/remoting/RegistryDelegate.scala
+++ /dev/null
@@ -1,192 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2002-2013, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id: RegistryDelegate.scala 18234 2009-07-07 13:21:57Z michelou $
-
-package scala.runtime.remoting
-
-import java.rmi.{RMISecurityManager, Remote, RemoteException}
-import java.rmi.registry.{LocateRegistry, Registry}
-import java.rmi.server.UnicastRemoteObject
-
-/**
- * <p>
- * This class implements the registry delegate concept
- * (see http://www.genady.net/rmi/v20/docs/delegate/RegistryDelegate.html)
- * </p>
- * <p>
- * In order to enforce some level of security, the standard RMI registry
- * implementation (e.g. <code>rmiregistry.exe</code>) only allows processes
- * on the same host to register objects in the registry (think of a bank
- * running a registry on one of its servers, and doesn't want anybody
- * modifying it). So, by design, if a process tries to
- * <code>bind(String, Remote)</code> an object to a remote registry,
- * an exception will be thrown.
- * </p>
- * <p>
- * However, the design of a distributed system may require remote clients to
- * register themselves in a central registry. If such system is deployed in a
- * controlled and trusted environment (e.g., a firewalled intranet with tight
- * access control), the security risk may be acceptable.
- * </p>
- * <p>
- * The simplest technical solution to the remote registration problem is to
- * have a registry delegate. A registry delegate is an object that serves as
- * a proxy for the real registry. The delegate itself usually appears in the
- * registry under a well known name. It implements the Registry interface and
- * simply delegates all method calls to the appropriate methods of the real
- * registry. The delegate is allowed to perform bind and unbind operations
- * because it is running on the same host as the registry.
- * </p>
- * <p>
- * The common scenario for starting a registry and creating the delegate is
- * starting a class with the following <code>main(Array[String])</code> method:
- * </p>
- * <pre>
- * @throws(classOf[AccessException], classOf[RemoteException], classOf[AlreadyBoundException])
- * <b>object</b> namingService {
- * <b>def</b> main(args: Array[String]) {
- * <b>if</b> (System.getSecurityManager() == <b>null</b>)
- * System.setSecurityManager(<b>new</b> RMISecurityManager())
- *
- * <b>val</b> registry = LocateRegistry.createRegistry(REGISTRY_PORT)
- * registry.bind(DELEGATE_NAME, <b>new</b> RegistryDelegate());
- *
- * do {
- * <b>try</b> {
- * Thread.sleep(Long.MAX_VALUE)
- * } <b>catch</b> {
- * <b>case</b> e: InterruptedException => // do nothing
- * <b>case</b> e: Throwable => e.printStackTrace(); sys.exit(1)
- * }
- * } while (<b>true</b>)
- * }
- * }</pre>
- * <p>
- * The common usage scenario looks something like:
- * </p><pre>
- * Registry remoteRegistry = LocateRegistry.getRegistry("remotehost.mycompany.com");
- * Registry delegate = (Registry) remoteRegistry.lookup(DELEGATE_NAME);
- * delegate.bind("someName", <b>new</b> SomeRemoteObject());</pre>
- * <p>
- * The <code>getRegistryDelegate(String)</code> method is a helper method
- * that fetches the registry delegate for you.
- * </p>
- * <p>
- * The <code>main(Array[String])</code> method of this class will create a
- * local registry on the default port, create a registry delegate and bind
- * it under the well known name that you chose in the wizard
- * (<code>DELEGATE_NAME</code>).
- * </p>
- *
- * @author Genady Beryozkin, rmi-info@genady.net
- */
-
-object RMIDelegate {
- /** The name under which the delegate appears in the registry. */
- val DELEGATE_NAME = "foo"
-
- /** This method retrieves the registry delegate from a registry that is
- * running on a remote host.
- */
- @throws(classOf[RemoteException])
- def getRegistryDelegate(remoteHost: String): Registry =
- getRegistryDelegate(remoteHost, Registry.REGISTRY_PORT)
-
- /** This method retrieves the registry delegate from a registry that is
- * running on a remote host.
- */
- @throws(classOf[RemoteException])
- def getRegistryDelegate(remoteHost: String, remotePort: Int): Registry = {
- val registry = LocateRegistry.getRegistry(remoteHost, remotePort)
- (registry lookup DELEGATE_NAME).asInstanceOf[Registry]
- }
-
- /** A simple way to run a registry and bind a registry delegate. */
- @throws(classOf[RemoteException])
- def main(args: Array[String]) {
- var port = Registry.REGISTRY_PORT
-
- if (args.length > 0) {
- if (args(0) equals "-help") {
- println("Usage: rmidelegate <options> <port>")
- sys.exit(0)
- }
- try {
- port = args(0).toInt
- } catch {
- case e: NumberFormatException =>
- println("Usage: rmidelegate <options> <port>")
- sys.exit(1)
- }
- val opts = args filter (_ startsWith "-J-D")
- for (opt <- opts) {
- val x = opt.substring(4) split "="
- if (x.length == 2) System.setProperty(x(0), x(1))
- else System.setProperty(x(0), "")
- }
- }
-
- if (System.getSecurityManager() == null)
- System.setSecurityManager(new RMISecurityManager() {
- override def checkPermission(p: java.security.Permission) {}
- })
-
-
- val registry = LocateRegistry.createRegistry(port)
- registry.bind(DELEGATE_NAME, new RegistryDelegate())
-
- do {
- try {
- Thread.sleep(Long.MaxValue)
- } catch {
- case e: InterruptedException =>
- // do nothing
- case e: Throwable =>
- e.printStackTrace()
- sys.exit(1)
- }
- } while (true)
- }
-
-}
-
-/** Create a delegate for a user provided registry instance. The registry is
- * assumed to be a local registry, as there is no point in creating a delegate
- * for a remote registry.
- */
-class RegistryDelegate(reg: Registry) extends UnicastRemoteObject with Registry {
- /** The local registry */
- private val localRegistry: Registry = reg
-
- /** Create a delegate for a local registry that is bound to the default
- * local port (1099).
- */
- def this() = this(LocateRegistry.getRegistry())
-
- /** Create a delegate for a local registry that is bound to a user
- * specified port.
- */
- def this(port: Int) = this(LocateRegistry.getRegistry(port))
-
- @throws(classOf[RemoteException])
- def bind(name: String, obj: Remote) { localRegistry.bind(name, obj) }
-
- @throws(classOf[RemoteException])
- def list(): Array[String] = localRegistry.list()
-
- @throws(classOf[RemoteException])
- def lookup(name: String): Remote = localRegistry.lookup(name)
-
- @throws(classOf[RemoteException])
- def rebind(name: String, obj: Remote) { localRegistry.rebind(name, obj) }
-
- @throws(classOf[RemoteException])
- def unbind(name: String) { localRegistry.unbind(name) }
-
-}
diff --git a/src/detach/library/scala/runtime/remoting/RemoteBooleanRef.scala b/src/detach/library/scala/runtime/remoting/RemoteBooleanRef.scala
deleted file mode 100644
index ff6c8f6b6c..0000000000
--- a/src/detach/library/scala/runtime/remoting/RemoteBooleanRef.scala
+++ /dev/null
@@ -1,51 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2002-2013, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id: RemoteBooleanRef.scala 18398 2009-07-28 14:26:36Z michelou $
-
-package scala.runtime.remoting
-
-import java.rmi.server.{UnicastRemoteObject, Unreferenced}
-import scala.runtime.{BooleanRef, RemoteRef}
-
-/**
- * The trait Remote<code>RemoteBooleanRef</code> provides a remote interface
- * for manipulating boolean references.
- *
- * @author Stephane Micheloud
- * @version 1.0
- */
-@remote
-trait RemoteBooleanRef {
- def elem_=(value: Boolean)
- def elem: Boolean
-}
-
-/**
- * The class <code>RemoteBooleanRefImpl</code> implements a remote (global)
- * boolean reference by inheriting from the class
- * <code>UnicastRemoteObject</code>.
- *
- * In particular, it forwards method invocations to the <code>elem</code>
- * accessors of class <code>runtime.BooleanRef</code> and implements the
- * <code>java.rmi.server.Unreferenced</code> interface to automatically
- * remove the no more referenced binding from the registry.
- *
- * @author Stephane Micheloud
- * @version 1.0
- */
-class RemoteBooleanRefImpl(name: String, x: BooleanRef)
-extends UnicastRemoteObject with RemoteBooleanRef with Unreferenced {
- def elem_=(value: Boolean) { x.elem = value }
- def elem: Boolean = x.elem
- override def toString() = x.elem.toString
- def unreferenced() {
- Debug.info("[RemoteBooleanRefImpl] unreferenced: "+this)
- RemoteRef.unbind(name)
- }
-}
diff --git a/src/detach/library/scala/runtime/remoting/RemoteByteRef.scala b/src/detach/library/scala/runtime/remoting/RemoteByteRef.scala
deleted file mode 100644
index 335f0d9019..0000000000
--- a/src/detach/library/scala/runtime/remoting/RemoteByteRef.scala
+++ /dev/null
@@ -1,51 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2002-2013, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id: RemoteByteRef.scala 18398 2009-07-28 14:26:36Z michelou $
-
-package scala.runtime.remoting
-
-import java.rmi.server.{UnicastRemoteObject, Unreferenced}
-import scala.runtime.{ByteRef, RemoteRef}
-
-/**
- * The trait Remote<code>RemoteByteRef</code> provides a remote interface
- * for manipulating byte references.
- *
- * @author Stephane Micheloud
- * @version 1.0
- */
-@remote
-trait RemoteByteRef {
- def elem_=(value: Byte)
- def elem: Byte
-}
-
-/**
- * The class <code>RemoteByteRefImpl</code> implements a remote (global)
- * byte reference by inheriting from the class
- * <code>UnicastRemoteObject</code>.
- *
- * In particular, it forwards method invocations to the <code>elem</code>
- * accessors of class <code>runtime.ByteRef</code> and implements the
- * <code>java.rmi.server.Unreferenced</code> interface to automatically
- * remove the no more referenced binding from the registry.
- *
- * @author Stephane Micheloud
- * @version 1.0
- */
-class RemoteByteRefImpl(name: String, x: ByteRef)
-extends UnicastRemoteObject with RemoteByteRef with Unreferenced {
- def elem_=(value: Byte) { x.elem = value }
- def elem: Byte = x.elem
- override def toString() = x.elem.toString
- def unreferenced() {
- Debug.info("[RemoteByteRefImpl] unreferenced: "+this)
- RemoteRef.unbind(name)
- }
-}
diff --git a/src/detach/library/scala/runtime/remoting/RemoteCharRef.scala b/src/detach/library/scala/runtime/remoting/RemoteCharRef.scala
deleted file mode 100644
index e0f48eb970..0000000000
--- a/src/detach/library/scala/runtime/remoting/RemoteCharRef.scala
+++ /dev/null
@@ -1,51 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2002-2013, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id: RemoteCharRef.scala 18398 2009-07-28 14:26:36Z michelou $
-
-package scala.runtime.remoting
-
-import java.rmi.server.{UnicastRemoteObject, Unreferenced}
-import scala.runtime.{CharRef, RemoteRef}
-
-/**
- * The trait Remote<code>RemoteCharRef</code> provides a remote interface
- * for manipulating character references.
- *
- * @author Stephane Micheloud
- * @version 1.0
- */
-@remote
-trait RemoteCharRef {
- def elem_=(value: Char)
- def elem: Char
-}
-
-/**
- * The class <code>RemoteCharRefImpl</code> implements a remote (global)
- * character reference by inheriting from the class
- * <code>UnicastRemoteObject</code>.
- *
- * In particular, it forwards method invocations to the <code>elem</code>
- * accessors of class <code>runtime.CharRef</code> and implements the
- * <code>java.rmi.server.Unreferenced</code> interface to automatically
- * remove the no more referenced binding from the registry.
- *
- * @author Stephane Micheloud
- * @version 1.0
- */
-class RemoteCharRefImpl(name: String, x: CharRef)
-extends UnicastRemoteObject with RemoteCharRef with Unreferenced {
- def elem_=(value: Char) { x.elem = value }
- def elem: Char = x.elem
- override def toString() = x.elem.toString
- def unreferenced() {
- Debug.info("[RemoteCharRefImpl] unreferenced: "+this)
- RemoteRef.unbind(name)
- }
-}
diff --git a/src/detach/library/scala/runtime/remoting/RemoteDoubleRef.scala b/src/detach/library/scala/runtime/remoting/RemoteDoubleRef.scala
deleted file mode 100644
index 2e1319595a..0000000000
--- a/src/detach/library/scala/runtime/remoting/RemoteDoubleRef.scala
+++ /dev/null
@@ -1,50 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2002-2013, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id: RemoteDoubleRef.scala 18398 2009-07-28 14:26:36Z michelou $
-
-package scala.runtime.remoting
-
-import java.rmi.server.{UnicastRemoteObject, Unreferenced}
-import scala.runtime.{DoubleRef, RemoteRef}
-
-/**
- * The trait Remote<code>RemoteDoubleRef</code> provides..
- *
- * @author Stephane Micheloud
- * @version 1.0
- */
-@remote
-trait RemoteDoubleRef {
- def elem_=(value: Double)
- def elem: Double
-}
-
-/**
- * The class <code>RemoteDoubleRefImpl</code> implements a remote (global)
- * double reference by inheriting from the class
- * <code>UnicastRemoteObject</code>.
- *
- * In particular, it forwards method invocations to the <code>elem</code>
- * accessors of class <code>runtime.DoubleRef</code> and implements the
- * <code>java.rmi.server.Unreferenced</code> interface to automatically
- * remove the no more referenced binding from the registry.
- *
- * @author Stephane Micheloud
- * @version 1.0
- */
-class RemoteDoubleRefImpl(name: String, x: DoubleRef)
-extends UnicastRemoteObject with RemoteDoubleRef with Unreferenced {
- def elem_=(value: Double) { x.elem = value }
- def elem: Double = x.elem
- override def toString() = x.elem.toString
- def unreferenced() {
- Debug.info("[RemoteDoubleRefImpl] unreferenced: "+this)
- RemoteRef.unbind(name)
- }
-}
diff --git a/src/detach/library/scala/runtime/remoting/RemoteFloatRef.scala b/src/detach/library/scala/runtime/remoting/RemoteFloatRef.scala
deleted file mode 100644
index f4e61ea6da..0000000000
--- a/src/detach/library/scala/runtime/remoting/RemoteFloatRef.scala
+++ /dev/null
@@ -1,50 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2002-2013, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id: RemoteFloatRef.scala 18398 2009-07-28 14:26:36Z michelou $
-
-package scala.runtime.remoting
-
-import java.rmi.server.{UnicastRemoteObject, Unreferenced}
-import scala.runtime.{FloatRef, RemoteRef}
-
-/**
- * The trait Remote<code>RemoteFloatRef</code> provides a remote interface
- * for manipulating float references.
- *
- * @author Stephane Micheloud
- * @version 1.0
- */
-@remote
-trait RemoteFloatRef {
- def elem_=(value: Float)
- def elem: Float
-}
-
-/**
- * The class <code>RemoteFloatRefImpl</code> implements a remote (global)
- * float reference by inheriting from the class
- * <code>UnicastRemoteObject</code>.
- *
- * In particular, it forwards method invocations to the <code>elem</code>
- * accessors of class <code>runtime.FloatRef</code> and implements the
- * <code>java.rmi.server.Unreferenced</code> interface.
- *
- * @author Stephane Micheloud
- * @version 1.0
- */
-class RemoteFloatRefImpl(name: String, x: FloatRef)
-extends UnicastRemoteObject with RemoteFloatRef with Unreferenced {
- def elem_=(value: Float) { x.elem = value }
- def elem: Float = x.elem
- override def toString() = x.elem.toString
- def unreferenced() {
- Debug.info("[RemoteIntFloatImpl] unreferenced: "+this)
- RemoteRef.unbind(name)
- }
-}
diff --git a/src/detach/library/scala/runtime/remoting/RemoteGC.scala b/src/detach/library/scala/runtime/remoting/RemoteGC.scala
deleted file mode 100644
index 393c031bfc..0000000000
--- a/src/detach/library/scala/runtime/remoting/RemoteGC.scala
+++ /dev/null
@@ -1,66 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2002-2013, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id: RemoteGC.scala 17547 2009-04-21 13:56:28Z michelou $
-
-package scala.runtime.remoting
-
-import java.lang.ref.{Reference, WeakReference, ReferenceQueue}
-import java.rmi.{NoSuchObjectException, Remote}
-import java.rmi.server.UnicastRemoteObject
-import scala.collection.mutable
-
-/**
- *
- * @author Stephane Micheloud
- * @version 1.0
- */
-// Adapted from scala.actors.ActorGC
-private [runtime] class RemoteGC {
-
- private val refQueue = new ReferenceQueue[Remote]
- private val refSet = new mutable.HashSet[Reference[T] forSome { type T <: Remote }]
-
- private var liveRefs = 0
-
- def newRef(a: Remote) = synchronized {
- refSet += new WeakReference(a, refQueue)
- liveRefs += 1
- info("added object reference \""+a+"\" ("+liveRefs+")")
- }
-
- def gc() = synchronized {
- info("GC called ("+liveRefs+")")
- // check for unreachable object references
- def drain() {
- val wr = refQueue.poll
- if (wr != null) {
- val msg = try {
- UnicastRemoteObject.unexportObject(wr.get, true/*force*/)
- "removed object reference"
- }
- catch {
- case e: NoSuchObjectException =>
- "object already unbound"
- }
- info(msg+" ("+liveRefs+")")
- liveRefs -= 1
- refSet -= wr
- // continue draining
- drain()
- }
- }
- drain()
- }
-
- def allClosed: Boolean = synchronized {
- liveRefs <= 0
- }
-
- private def info(msg: String) { Debug.info("[RemoteGC] "+msg) }
-}
diff --git a/src/detach/library/scala/runtime/remoting/RemoteIntRef.scala b/src/detach/library/scala/runtime/remoting/RemoteIntRef.scala
deleted file mode 100644
index b14403f6ca..0000000000
--- a/src/detach/library/scala/runtime/remoting/RemoteIntRef.scala
+++ /dev/null
@@ -1,51 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2002-2013, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id: RemoteIntRef.scala 18398 2009-07-28 14:26:36Z michelou $
-
-package scala.runtime.remoting
-
-import java.rmi.server.{UnicastRemoteObject, Unreferenced}
-import scala.runtime.{IntRef, RemoteRef}
-
-/**
- * The trait Remote<code>RemoteIntRef</code> provides a remote interface
- * for manipulating integer references.
- *
- * @author Stephane Micheloud
- * @version 1.0
- */
-@remote
-trait RemoteIntRef {
- def elem_=(value: Int)
- def elem: Int
-}
-
-/**
- * The class <code>RemoteIntRefImpl</code> implements a remote (global)
- * integer reference by inheriting from the class
- * <code>UnicastRemoteObject</code>.
- *
- * In particular, it forwards method invocations to the <code>elem</code>
- * accessors of class <code>runtime.IntRef</code> and implements the
- * <code>java.rmi.server.Unreferenced</code> interface to automatically
- * remove the no more referenced binding from the registry.
- *
- * @author Stephane Micheloud
- * @version 1.0
- */
-class RemoteIntRefImpl(name: String, x: IntRef)
-extends UnicastRemoteObject with RemoteIntRef with Unreferenced {
- def elem_=(value: Int) { x.elem = value }
- def elem: Int = x.elem
- override def toString() = x.elem.toString
- def unreferenced() {
- Debug.info("[RemoteIntRefImpl] unreferenced: "+this)
- RemoteRef.unbind(name)
- }
-}
diff --git a/src/detach/library/scala/runtime/remoting/RemoteLongRef.scala b/src/detach/library/scala/runtime/remoting/RemoteLongRef.scala
deleted file mode 100644
index da83491489..0000000000
--- a/src/detach/library/scala/runtime/remoting/RemoteLongRef.scala
+++ /dev/null
@@ -1,51 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2002-2013, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id: RemoteLongRef.scala 18398 2009-07-28 14:26:36Z michelou $
-
-package scala.runtime.remoting
-
-import java.rmi.server.{UnicastRemoteObject, Unreferenced}
-import scala.runtime.{LongRef, RemoteRef}
-
-/**
- * The trait Remote<code>RemoteLongRef</code> provides a remote interface
- * for manipulating long integer references.
- *
- * @author Stephane Micheloud
- * @version 1.0
- */
-@remote
-trait RemoteLongRef {
- def elem_=(value: Long)
- def elem: Long
-}
-
-/**
- * The class <code>RemoteLongRefImpl</code> implements a remote (global)
- * long integer reference by inheriting from the class
- * <code>UnicastRemoteObject</code>.
- *
- * In particular, it forwards method invocations to the <code>elem</code>
- * accessors of class <code>runtime.LongRef</code> and implements the
- * <code>java.rmi.server.Unreferenced</code> interface to automatically
- * remove the no more referenced binding from the registry.
- *
- * @author Stephane Micheloud
- * @version 1.0
- */
-class RemoteLongRefImpl(name: String, x: LongRef)
-extends UnicastRemoteObject with RemoteLongRef with Unreferenced {
- def elem_=(value: Long) { x.elem = value }
- def elem: Long = x.elem
- override def toString() = x.elem.toString
- def unreferenced() {
- Debug.info("[RemoteLongRefImpl] unreferenced: "+this)
- RemoteRef.unbind(name)
- }
-}
diff --git a/src/detach/library/scala/runtime/remoting/RemoteObjectRef.scala b/src/detach/library/scala/runtime/remoting/RemoteObjectRef.scala
deleted file mode 100644
index 9f27b26114..0000000000
--- a/src/detach/library/scala/runtime/remoting/RemoteObjectRef.scala
+++ /dev/null
@@ -1,51 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2002-2013, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id: RemoteObjectRef.scala 18398 2009-07-28 14:26:36Z michelou $
-
-package scala.runtime.remoting
-
-import java.rmi.server.{UnicastRemoteObject, Unreferenced}
-import scala.runtime.{ObjectRef, RemoteRef}
-
-/**
- * The trait Remote<code>RemoteObjectRef</code> provides a remote interface
- * for manipulating object references.
- *
- * @author Stephane Micheloud
- * @version 1.0
- */
-@remote
-trait RemoteObjectRef {
- def elem_=(value: AnyRef)
- def elem: AnyRef
-}
-
-/**
- * The class <code>RemoteObjectRefImpl</code> implements a remote (global)
- * object reference by inheriting from the class
- * <code>UnicastRemoteObject</code>.
- *
- * In particular, it forwards method invocations to the <code>elem</code>
- * accessors of class <code>runtime.ObjectRef</code> and implements the
- * <code>java.rmi.server.Unreferenced</code> interface to automatically
- * remove the no more referenced binding from the registry.
- *
- * @author Stephane Micheloud
- * @version 1.0
- */
-class RemoteObjectRefImpl(name: String, x: ObjectRef)
-extends UnicastRemoteObject with RemoteObjectRef with Unreferenced {
- def elem_=(value: AnyRef) { x.elem = value }
- def elem: AnyRef = x.elem
- override def toString() = x.elem.toString
- def unreferenced() {
- Debug.info("[RemoteObjectRefImpl] unreferenced: "+this)
- RemoteRef.unbind(name)
- }
-}
diff --git a/src/detach/library/scala/runtime/remoting/RemoteShortRef.scala b/src/detach/library/scala/runtime/remoting/RemoteShortRef.scala
deleted file mode 100644
index 2ced9dbc83..0000000000
--- a/src/detach/library/scala/runtime/remoting/RemoteShortRef.scala
+++ /dev/null
@@ -1,50 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2002-2013, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id: RemoteShortRef.scala 18398 2009-07-28 14:26:36Z michelou $
-
-package scala.runtime.remoting
-
-import java.rmi.server.{UnicastRemoteObject, Unreferenced}
-import scala.runtime.{ShortRef, RemoteRef}
-
-/**
- * The trait Remote<code>RemoteShortRef</code> provides a remote interface
- * for manipulating short integer references.
- *
- * @author Stephane Micheloud
- * @version 1.0
- */
-@remote
-trait RemoteShortRef {
- def elem_=(value: Short)
- def elem: Short
-}
-
-/**
- * The class <code>RemoteShortRefImpl</code> implements a remote (global)
- * short integer reference by inheriting from the class
- * <code>UnicastRemoteObject</code>.
- *
- * In particular, it forwards method invocations to the <code>elem</code>
- * accessors of class <code>runtime.ShortRef</code> and implements the
- * <code>java.rmi.server.Unreferenced</code> interface.
- *
- * @author Stephane Micheloud
- * @version 1.0
- */
-class RemoteShortRefImpl(name: String, x: ShortRef)
-extends UnicastRemoteObject with RemoteShortRef with Unreferenced {
- def elem_=(value: Short) { x.elem = value }
- def elem: Short = x.elem
- override def toString() = x.elem.toString
- def unreferenced() {
- Debug.info("[RemoteShortRefImpl] unreferenced: "+this)
- RemoteRef.unbind(name)
- }
-}
diff --git a/src/detach/plugin/scala/tools/detach/Detach.scala b/src/detach/plugin/scala/tools/detach/Detach.scala
deleted file mode 100644
index f9a3d80da4..0000000000
--- a/src/detach/plugin/scala/tools/detach/Detach.scala
+++ /dev/null
@@ -1,1190 +0,0 @@
-/* NSC -- new Scala compiler
- * Copyright 2005-2013 LAMP/EPFL
- * @author Stephane Micheloud
- */
-
-package scala.tools.detach
-
-import scala.collection.{ mutable, immutable }
-import scala.collection.mutable.ListBuffer
-import scala.tools.nsc._
-import scala.tools.nsc.plugins.PluginComponent
-import scala.tools.nsc.symtab.Flags._
-import scala.tools.nsc.transform._
-
-abstract class Detach extends PluginComponent
- with Transform with TypingTransformers {
- import global._
- import definitions._
-
- /** the following two members override abstract members in Transform */
- val phaseName: String = "detach"
-
- protected def newTransformer(unit: CompilationUnit): Transformer =
- new DetachTransformer(unit)
-
- // set with the `-P:detach:enable` plugin option (see DetachPlugin) */
- protected[detach] var isEnabled = false
-
- private class DetachTransformer(unit: CompilationUnit)
- extends TypingTransformer(unit) {
- private val DEBUG = settings.debug.value
- private val PROXY_PREFIX = "proxy$" // local proxy objects
- private val PROXY_SUFFIX = "$proxy" // top-level proxy classes
- private val DETACH_SUFFIX = "$detach" // detached closures
- private val IMPL_SUFFIX = "Impl" // follows Java convention
-
- private val nme_bind = newTermName("bind")
- private val nme_unbind = newTermName("unbind")
- private val nme_unreferenced = newTermName("unreferenced")
-
- private val Functions = FunctionClass.toList // see method isFuncType
-
- private val RemoteClass =
- definitions.getClass("java.rmi.Remote")
-
- private val UIDClass =
- definitions.getClass("java.rmi.server.UID")
-
- private val UnicastRemoteObjectClass =
- definitions.getClass("java.rmi.server.UnicastRemoteObject")
-
- private val UnreferencedClass =
- definitions.getClass("java.rmi.server.Unreferenced")
-
- private val DetachModule =
- definitions.getModule("scala.remoting.detach")
-
- private val DebugModule =
- definitions.getModule("scala.remoting.Debug")
-
- private val RemoteRefModule =
- definitions.getModule("scala.runtime.RemoteRef")
-
- private val ThreadModule =
- definitions.getModule("java.lang.Thread")
-
- private val UnicastRemoteObjectModule =
- definitions.getModule("java.rmi.server.UnicastRemoteObject")
-
- private val remoteAnnotationInfo = {
- val RemoteAttr: Symbol = definitions.getClass("scala.remote")
- AnnotationInfo(RemoteAttr.tpe, List(), List())
- }
-
- private val serializableAnnotationInfo =
- AnnotationInfo(SerializableAttr.tpe, List(), List())
-/*
- private val throwsAnnotationInfo = {
- val RemoteExceptionClass = definitions.getClass("java.rmi.RemoteException")
- val ThrowsAttr = definitions.getClass("scala.throws")
- AnnotationInfo(
- ThrowsAttr.tpe,
- List(Literal(Constant(RemoteExceptionClass.tpe))),
- List()
- )
- }
-*/
- // todo: see generation of Java version UID
- private def serialVersionUIDAnnotationInfo(clazz: Symbol) = {
- def genHash(sym: Symbol): Long = {
- val sym1 = if (sym.isConstructor) sym.owner else sym
- val ts = sym.tpe match {
- case MethodType(params, rt) => (params map (_.tpe)) ::: List(rt)
- case t => List(t)
- }
- val hashes = sym1.nameString.hashCode ::
- (ts map (_.typeSymbol.nameString.hashCode))
- (0L /: hashes)((acc, h) => acc ^ h)
- }
- val hashes = for (sym <- clazz.info.decls.toList) yield genHash(sym)
- val uid: Long = (0L /: hashes) ((acc, h) => acc * 41 + h)
- val serialVersionUIDAttr = definitions.getClass("scala.SerialVersionUID")
- AnnotationInfo(
- serialVersionUIDAttr.tpe,
- List(Literal(Constant(uid))),
- List()
- )
- }
-
- private def elems(suffix: String): List[(Symbol, Symbol)] =
- for (clazz <- ObjectRefClass :: refClass.valuesIterator.toList) yield {
- val name = "scala.runtime.remoting.Remote" + clazz.name + suffix
- (clazz, definitions.getClass(name))
- }
- private val remoteRefClass = immutable.HashMap(elems(""): _*)
- private val remoteRefImpl = immutable.HashMap(elems("Impl"): _*)
-
- private val proxyInterfaceDefs = new mutable.HashMap[Symbol/*owner*/, ListBuffer[Tree]]
- private val detachedClosureApply = new mutable.HashMap[Tree, Apply]
-
- private type SymSet = mutable.HashSet[Symbol]
- private val capturedObjects = new mutable.HashMap[Symbol/*clazz*/, SymSet]
- private val capturedFuncs = new mutable.HashMap[Symbol/*clazz*/, SymSet]
- private val capturedCallers = new mutable.HashMap[Symbol/*clazz*/, SymSet]
- private val capturedThisClass = new mutable.HashMap[Symbol, Symbol]
-
- private val proxies = new mutable.HashMap[
- Symbol, //clazz
- (Symbol, Symbol, mutable.HashMap[Symbol, Symbol]) //iface, impl, accessor map
- ]
- def toInterface(clazz: Symbol) = proxies(clazz)._1
- private val classdefs = new mutable.HashMap[Symbol/*clazz*/, ClassDef]
- // detachedClosure gathers class definitions containing a "detach" apply
- private val detachedClosure = new mutable.HashMap[Symbol/*clazz*/, ClassDef]
-
- /** <p>
- * The method <code>freeObjTraverser.traverse</code> is invoked
- * in the method <code>DetachPlugin.transformUnit</code> in order to
- * gather information about objects referenced inside a detached
- * closure and which will be accessed remotely through object proxies.
- * </p>
- * <p>
- * Object proxies are generated in method <code>mkClosureApply</code>
- * and their definitions are generated in method <code>genProxy</code>.
- * </p>
- */
- private val freeObjTraverser = new Traverser {
- def symSet(f: mutable.HashMap[Symbol, SymSet], sym: Symbol): SymSet = f.get(sym) match {
- case Some(ss) => ss
- case None => val ss = new mutable.HashSet[Symbol]; f(sym) = ss; ss
- }
- def getClosureApply(tree: Tree): Apply = tree match {
- case Block(_, expr) => getClosureApply(expr)
- case Typed(expr, _) => getClosureApply(expr)
- case apply @ Apply(Select(_, _), _) => apply // sel="<init>" or some "f$0"
- case Apply(fun, _) => getClosureApply(fun)
- case _ =>
- throw new Error("getClosureApply: unhandled case " + tree)
- }
- def isFuncType(tp: Type): Boolean = tp match {
- case TypeRef(pre, sym, args) =>
- Functions contains sym.tpe.typeSymbol
- case _ =>
- false
- }
- def isOuterMember(sym: Symbol): Boolean =
- sym.isOuterAccessor ||
- sym.name.endsWith(nme.OUTER/*, nme.OUTER.length*/)
- override def traverse(tree: Tree) {
- val sym = tree.symbol
- val owner =
- if (currentOwner.isModule) currentOwner
- else currentOwner.enclClass
- tree match {
- case cdef @ ClassDef(_, _, _, impl) =>
- classdefs(sym) = cdef
- super.traverse(impl)
- if (detachedClosure contains sym) {
- detachedClosure(sym) = cdef
- symSet(capturedObjects, sym) += capturedThisClass(sym)
- }
-
- case Apply(Select(qual, _), List(arg))
- if (qual.tpe <:< DetachModule.tpe) =>
- assert(isFuncType(arg.tpe))//debug
- val t = getClosureApply(arg)
- if (!t.fun.symbol.isConstructor)
- unit.error(t.pos, "detach inapplicable for " +t.fun.symbol)
- val sym = t.fun.symbol.owner
- capturedThisClass(sym) = owner
- symSet(capturedFuncs, sym)
- detachedClosureApply(tree) = t
- classdefs get sym match {
- case None =>
- detachedClosure(sym) = null // set later in case ClassDef
- case Some(cdef) =>
- detachedClosure(sym) = cdef
- symSet(capturedObjects, sym) += capturedThisClass(sym)
- }
- super.traverse(arg)
-
- case Select(qual @ This(_), name)
- if qual.symbol.isModuleClass && !qual.symbol.isPackageClass =>
- val qsym = qual.symbol
- symSet(capturedFuncs, owner) += sym
- symSet(capturedObjects, owner) += qsym
-
- case Select(qual, name)
- if (qual.hasSymbol &&
- (sym.owner != owner) &&
- !(sym.ownerChain contains ScalaPackageClass) &&
- !(sym.owner hasFlag JAVA)) =>
- val qsym = qual.symbol
- symSet(capturedFuncs, owner) += sym
- if (qsym.isStaticModule && !qsym.isPackage) {
- //println("*****1******* capturedObjects("+owner+") += "+qsym)
- symSet(capturedObjects, owner) += qsym
- }
- else if (!isOuterMember(qsym) && !(qsym isNestedIn owner)) {
- //println("*****3******* capturedCallers("+sym+") += "+qsym)
- symSet(capturedCallers, sym) += qsym
- }
-
- case _ =>
- super.traverse(tree)
- }
- }
- } //freeObjTraverser
-
- private val valueClass = immutable.HashMap(
- (for ((sym, ref) <- refClass.toList) yield (ref, sym)): _*
- ) + (ObjectRefClass -> ObjectClass)
-
- private def toValueClass(tp: Type): Type =
- if (isRefClass(tp)) valueClass(tp.typeSymbol).tpe
- else if (proxies contains tp.typeSymbol) toInterface(tp.typeSymbol).tpe
- else tp
-
- private def isRefClass(tp: Type): Boolean =
- (tp ne null) &&
- ((refClass.valuesIterator contains tp.typeSymbol) || (ObjectRefClass eq tp.typeSymbol))
-
- private def isRemoteRefClass(tp: Type): Boolean =
- (tp ne null) && (remoteRefClass.valuesIterator contains tp.typeSymbol)
-
- private def mkRemoteRefClass(tp: Type): Type = {
- assert(isRefClass(tp))
- val tp1 = remoteRefClass(tp.typeSymbol)
- typeRef(tp1.typeConstructor.prefix, tp1, Nil) // after erasure, no type anymore!
- }
-
- class TreeOuterSubstituter(from: List[Symbol], to: List[Symbol]) extends Traverser {
- if (DEBUG)
- println("\nTreeOuterSubstituter:"+
- "\n\tfrom="+from.mkString(",")+
- "\n\tto="+to.mkString(","))
- val substMap = new mutable.HashMap[Symbol, Symbol]
- override def traverse(tree: Tree) {
- def subst(from: List[Symbol], to: List[Symbol]) {
- if (!from.isEmpty)
- if (tree.symbol.tpe == from.head.tpe) {
- if (DEBUG)
- println("\nTreeOuterSubstituter\n\tsym="+tree.symbol+
- ", tpe="+tree.symbol.tpe+
- "\n\towner="+tree.symbol.owner)
- tree.symbol updateInfo to.head.tpe
- }
- else tree.symbol.tpe match {
- case MethodType(params, restp) =>
- for (p <- params if p.tpe == from.head.tpe) {
- p updateInfo to.head.tpe
- }
- if (restp == from.head.tpe) {
- if (DEBUG)
- println("\nTreeOuterSubstituter(2)\n\tsym="+tree.symbol+
- ", tpe="+tree.symbol.tpe+
- ", owner="+tree.symbol.owner)
- tree.symbol updateInfo MethodType(params, to.head.tpe)
- }
- case _ =>
- subst(from.tail, to.tail)
- }
- }
- def isOuter(sym: Symbol): Boolean =
- sym.isOuterAccessor ||
- sym.name.endsWith(nme.OUTER/*, nme.OUTER.length*/)
- if (tree.hasSymbol && isOuter(tree.symbol)) subst(from, to)
- super.traverse(tree)
- }
- }
-
- // based on class Trees.TreeTypeSubstituter
- private class TreeTypeRefSubstituter(clazz: Symbol) extends Traverser {
- override def traverse(tree: Tree) {
- val sym = tree.symbol
- if (tree.hasSymbol && isRefClass(sym.tpe) &&
- (sym.owner.enclClass == clazz) &&
- (sym.isValueParameter || sym.hasFlag(PARAMACCESSOR))) {
- sym setInfo mkRemoteRefClass(sym.tpe)
- tree.tpe = sym.tpe
- }
- if (isRefClass(tree.tpe))
- tree.tpe = mkRemoteRefClass(tree.tpe)
- super.traverse(tree)
- }
- override def apply[T <: Tree](tree: T): T = super.apply(tree)
- }
-
- private class TreeOwnerSubstituter(from: Symbol, to: Symbol) extends Traverser {
- def substType(sym: Symbol): Type = {
- def subst(tpe: Type): Type = tpe match {
- case MethodType(params, restp) =>
- println("TreeOwnerSubstituter[1]: tpe="+tpe+
- ", tpe.typeSymbol="+tpe.typeSymbol+", sym="+sym)//debug
- for (p <- params if p.tpe == from.tpe) {
- println("TreeOwnerSubstituter[2]: sym="+sym+
- ", sym.owner="+sym.owner+", p.tpe="+p.tpe)//debug
- p updateInfo to.tpe
- }
- MethodType(params, subst(restp))
- case _ =>
- if (sym.owner == from && tpe == from.tpe) {
- println("TreeOwnerSubstituter[3]: sym="+sym+
- ", owner="+sym.owner+", tpe="+tpe)//debug
- to.tpe
- } else tpe
- }
- subst(sym.tpe)
- }
- val map = new mutable.HashMap[Symbol, Symbol]
- override def traverse(tree: Tree) {
- if (tree.hasSymbol && tree.symbol != NoSymbol) {
- val sym = tree.symbol
- if (sym.owner == from) {
- val sym1 = map get sym match {
- case Some(s) => s
- case None => val s = sym.cloneSymbol(to); map(sym) = s; s
- }
- tree setSymbol sym1
- }
- val sym1 = tree.symbol
- val tp = substType(sym1)
- if (tp != sym1.tpe) {
- if (sym1.owner == to)
- println("\n%%%%%1%%%%%%% TreeOwnerSubst: tree="+tree+", sym1="+sym1+", sym1.owner="+sym1.owner)//debug
- sym1 setInfo tp
- tree setSymbol sym1
- }
- }
- super.traverse(tree)
- }
- //override def apply[T <: Tree](tree: T): T = super.apply(tree/*.duplicate*/)
- }
-
- private var inConstructorFlag = 0L
-
- private def isCaptured(clazz: Symbol, sym: Symbol): Boolean =
- if (capturedFuncs contains clazz) {
- //log("**1** isCaptured: clazz="+clazz+", sym="+sym+", ")
- capturedFuncs(clazz) contains sym
- }
- else {
- //log("**2** isCaptured: clazz="+clazz+", sym="+sym)
- sym.isMethod && !sym.isConstructor
- }
-
- private class TreeAccessorSubstituter(clazz: Symbol, objs: List[Symbol], proxySyms: List[Symbol])
- extends Transformer {
- def removeAccessors(tree: Tree): Tree = tree match {
- case Apply(fun, _) =>
- removeAccessors(fun)
- case Select(qual, _) if tree.hasSymbol && tree.symbol.isOuterAccessor =>
- removeAccessors(qual)
- case _ =>
- tree
- }
- if (DEBUG)
- println("\nTreeAccessorSubstituter: "+
- "\n\tobjs="+objs.mkString(",")+
- "\n\tproxies="+proxySyms.mkString(","))
- override def transform(tree: Tree): Tree = tree match {
- // transforms field assignment $outer.i$1.elem=..
- // into setter $outer.i$1_=(..)
- case Assign(lhs @ Select(qual1 @ Select(qual, name), name1), rhs)
- if qual1.hasSymbol && !qual1.symbol.isPrivateLocal &&
- isRemoteRefClass(qual1.tpe) =>
- if (DEBUG)
- println("\nTreeAccessorSubstituter: Assign1\n\tqual1="+qual1+", sel.tpe="+lhs.tpe+
- "\n\tqual1.tpe="+qual1.tpe+", name1="+name1+
- "\n\tqual.tpe="+qual.tpe+", tree.tpe="+tree.tpe)//debug
- val iface = toInterface(qual.tpe.typeSymbol)
- val sym = iface.tpe.decls lookup nme.getterToSetter(name)
- atPos(tree.pos)(Apply(
- Select(super.transform(qual), sym) setType lhs.tpe,
- List(super.transform(rhs))
- ) setType tree.tpe)
-
- // transforms local assignment this.x$1.elem=..
- // into setter method this.x$1_=(..)
- case Assign(lhs @ Select(qual, name), rhs)
- if qual.hasSymbol && qual.symbol.isPrivateLocal &&
- isRemoteRefClass(qual.tpe) =>
- if (DEBUG)
- println("\nTreeAccessorSubstituter: Assign2"+
- "\n\tqual="+qual+", qual.tpe="+qual.tpe+
- "\n\tname="+name)
- // substitute the 'elem' member of the reference class with
- // the corresponding setter method of the remote reference class.
- val qual1 = super.transform(qual)
- val sym = qual1.tpe.decls lookup nme.getterToSetter(name)
- val fun = gen.mkAttributedSelect(qual1, sym)
- Apply(fun, List(super.transform(rhs))) setType lhs.tpe
-
- case Assign(Select(qual, name), rhs)
- if qual.hasSymbol && (objs contains qual.symbol) =>
- val sym = qual.symbol
- val proxy = proxySyms(objs indexOf sym)
- if (DEBUG)
- println("\nTreeAccessorSubstituter: Assign3"+
- "\n\tqual="+qual+", qual.tpe="+qual.tpe+
- "\n\tproxy="+proxy+", proxy.tpe="+proxy.tpe+
- "\n\tname="+name)//debug
- // substitute the member accessor of the enclosing class with
- // the corresponding setter method of the detached interface.
- val iface = toInterface(sym)
- val substSymbols = new TreeSymSubstituter(
- sym.info.decls.toList filter { isCaptured(sym, _) },
- iface.info.decls.toList)
- substSymbols(Apply(
- Select(Ident(proxy), nme.getterToSetter(name)),
- List(super.transform(rhs))))
-
- // transforms setter invocation this.i$1_=(..)
- // into setter invocation $outer.i$1_=(..)
- case Apply(Select(qual @ This(_), name), args)
- if (objs contains qual.symbol) && nme.isSetterName(name) =>
- val proxy = proxySyms(objs indexOf qual.symbol)
- if (DEBUG)
- println("\nTreeAccessorSubstituter: Apply"+
- "\n\tqual="+qual+", qual.tpe="+qual.tpe+
- "\n\tproxy="+proxy+", proxy.tpe="+proxy.tpe+
- "\n\tname="+name+", decoded="+name.decode)
- val qual1 = gen.mkAttributedSelect(gen.mkAttributedThis(proxy.owner), proxy)
- val sym1 = proxy.info.decls lookup name.decode
- val fun = gen.mkAttributedSelect(qual1, sym1)
- Apply(fun, args map (super.transform(_))) setType tree.tpe
-
- // transforms access to field this.name$1
- // into invocation of getter method $outer.name$1()
- case Select(qual @ This(_), name)
- if objs contains qual.symbol =>
- val proxy = proxySyms(objs indexOf qual.symbol)
- if (DEBUG)
- println("\nTreeAccessorSubstituter: Select"+
- "\n\tqual="+qual+", qual.tpe="+qual.tpe+
- "\n\tproxy="+proxy+", proxy.tpe="+proxy.tpe+
- "\n\tname="+name+", decoded="+name.decode)
- val qual1 = gen.mkAttributedSelect(gen.mkAttributedThis(proxy.owner), proxy)
- val sym1 = proxy.info.decls lookup nme.originalName(name) //name
- gen.mkAttributedSelect(qual1, sym1)
-
- // transforms field $outer.name$1 into getter method $outer.name$1()
- case Select(qual @ Select(_, name1), name)
- if qual.hasSymbol && name1.endsWith(nme.OUTER/*, nme.OUTER.length*/) &&
- !tree.symbol.isMethod =>
- if (DEBUG)
- println("\nTreeAccessorSubstituter: Select0\n\tqual="+qual+
- ", qual.tpe="+qual.tpe+", name="+name)//debug
- val sym = qual.symbol
- val qual1 = gen.mkAttributedSelect(gen.mkAttributedThis(sym.owner), sym)
- val iface = toInterface(qual.tpe.typeSymbol)
- val sym1 = iface.tpe.decls lookup name
- val fun = gen.mkAttributedSelect(qual1, sym1)
- Apply(fun, List()) setType tree.tpe
-
- case Select(apply @ Apply(fun @ Select(qual, _), _), name)
- if fun.symbol.isOuterAccessor =>
- val tsym = fun.symbol.tpe.resultType.typeSymbol
- val funcs = capturedFuncs(clazz).toList filter (sym =>
- (tsym.ownerChain contains sym.owner) || (tsym isSubClass sym.owner))
- if (DEBUG)
- println("\nTreeAccessorSubstituter: Select1\n\tfun="+fun+
- ",\n\tfun.tpe="+fun.tpe+", name="+name+
- ",\n\tfuncs="+funcs)//debug
- funcs find (tree.symbol.==) match {
- case Some(sym) =>
- val qual1 =
- if (currentOwner.enclClass isNestedIn clazz) apply
- else removeAccessors(qual)
- val name1 =
- (if (tsym isSubClass qual1.tpe.typeSymbol) ""
- else tsym.fullName('$')+"$")+sym.name
- val iface = toInterface(qual1.tpe.typeSymbol)
- val sym1 = iface.tpe.decls lookup name1
- gen.mkAttributedSelect(qual1, sym1)
- case None =>
- super.transform(tree)
- }
-
- // transforms field access $outer.i$1.elem
- // into invocation of getter method $outer.i$1()
- case Select(qual @ Select(qual1, name1), name)
- if qual.hasSymbol && !qual.symbol.isPrivateLocal &&
- isRemoteRefClass(qual.tpe) =>
- if (DEBUG)
- println("\nTreeAccessorSubstituter: Select2\n\tqual="+qual+
- "\n\tqual.tpe="+qual.tpe+", tree.tpe="+tree.tpe)//debug
- val iface = toInterface(qual.symbol.owner)
- val sym1 = iface.tpe.decls lookup name1
- val fun = gen.mkAttributedSelect(qual1, sym1)
- Apply(fun, List()) setType tree.tpe
-
- // transforms local access this.i$1.elem
- // into invocation of getter method this.i$1()
- case Select(qual, name)
- if qual.hasSymbol && qual.symbol.isPrivateLocal &&
- isRemoteRefClass(qual.tpe) =>
- if (DEBUG)
- println("\nTreeAccessorSubstituter: Select3\n\tqual="+qual+
- "\n\tqual.tpe="+qual.tpe)//debug
- val sym = qual.tpe.decls lookup name
- val fun = gen.mkAttributedSelect(qual, sym)
- Apply(fun, List()) setType tree.tpe
-
- case Select(qual, name)
- if qual.hasSymbol && (objs contains qual.symbol) =>
- if (DEBUG)
- println("\nTreeAccessorSubstituter: Select4\n\tqual="+qual+
- ", qual.tpe="+qual.tpe+", name="+name)//debug
- val sym = qual.symbol
- val proxy = proxySyms(objs indexOf sym)
- // substitute the accessor of a member of the enclosing class
- // with the corresponding accessor of the detached interface
- val qual1 = gen.mkAttributedSelect(gen.mkAttributedThis(proxy.owner), proxy)
- val iface = toInterface(sym)
- val sym1 = iface.tpe.decls lookup name.decode
- gen.mkAttributedSelect(qual1, sym1)
-
- case _ =>
- super.transform(tree)
- }
- def apply[T <: Tree](tree: T): T = transform(tree).asInstanceOf[T]
- } // TreeAccessorSubstituter
-/*
- private class TreeNameSubstituter(from: Name, to: Symbol) extends Transformer {
- override def transform(tree: Tree): Tree = tree match {
- case Super(qual, mix) if tree.symbol.name == from =>
- Super(qual, mix) setSymbol to
- case This(name) if name == from =>
- This(to.name) setSymbol to
- case _ =>
- super.transform(tree)
- }
- def apply[T <: Tree](tree: T): T = transform(tree).asInstanceOf[T]
- }
-*/
- /** <p>
- * Given the closure definition (generated by previous phases)
- * </p><pre>
- * class $anonfun$1 extends Object with Function1 {
- * def this($outer: C, x$1: Int): $anonfun$1 = ..
- * def apply(x: Int): Int = x + this.$outer.x() + this.x$1
- * }</pre>
- * <p>
- * the method <code>mkClosureDef</code> transforms the above code
- * to the following:
- * </p><pre>
- * @serializable
- * class $anonfun$1$detach extends Object with Function1 {
- * def this($outer: C$proxy, x$1: Int): $anonfun$1$detach = ..
- * def apply(x: Int): Int = x + this.$outer.x() + this.x$1
- * }</pre>
- * <p>
- * In particular, it performs the following operations:
- * 1) add constructor parameter <code>proxy_n</code> to access
- * proxy of the enclosing class
- * 2) change reference types in constructor arguments to type
- * <code<Remote_type_Ref</code>'
- * 3) change occurences of <code>this</code> identifier to
- * <code>proxy_n</code> in template code
- * 4) change reference types of local value definitions associated
- * to updated constructor arguments to type <code>Remote_type_Ref</code>
- * </p>
- *
- * @param clazz the symbol of the original closure definition
- * @return the typed class definition for the detached closure.
- */
- private def mkClosureDef(clazz: Symbol): Tree = {
- val cdef = detachedClosure(clazz)
- val name = cdef.symbol.name
- if (name endsWith DETACH_SUFFIX)
- return cdef // closure already detached
-
- clazz.name = encode(clazz.name.decode + DETACH_SUFFIX)
- clazz addAnnotation serialVersionUIDAnnotationInfo(clazz)
- clazz addAnnotation serializableAnnotationInfo
-
- val thiz = capturedThisClass(clazz)
- val (List(outer), captured) =
- capturedObjects(clazz).toList partition (thiz.==)
-
- /** <p>
- * Method <code>updateConstructorParams</code> updates the class
- * symbol of the detached closure as follows:
- * 1) it appends the "$detach" suffix to the class name,
- * 2) it adds the "@serializable" annotation to class attributes,
- * 3) it adds a parameter symbol for each element of "captured".
- * </p>
- * <p>
- * and also updates the signature of the constructor symbol:
- * 1) it adds a parameter type for each element of "captured",
- * 2) it changes reference types to remote reference types.
- * </p>
- */
- def updateConstructorParams(vparams: List[ValDef]): List[Symbol] = {
- val hasOuter = !vparams.isEmpty && (vparams.head.symbol.tpe == thiz.tpe)
- val ctor = clazz.primaryConstructor
- val params = (for (sym <- captured) yield {
- val iface = toInterface(sym)
- val param = ctor.newValueParameter(ctor.pos, freshProxyName)
- .setFlag(SYNTHETIC)
- .setInfo(iface.tpe)
- param.owner = ctor
- param
- }) ::: (
- if (hasOuter) Nil
- else {
- val iface = toInterface(thiz)
- val param = ctor.newValueParameter(ctor.pos, nme.OUTER)
- .setFlag(SYNTHETIC)
- .setInfo(iface.tpe)
- param.owner = ctor
- List(param)
- }
- )
- val tp = ctor.tpe match {
- case mt @ MethodType(params1, restp) =>
- val params2 = if (hasOuter) {
- val iface = toInterface(params1.head.tpe.typeSymbol)
- ctor.newSyntheticValueParam(iface.tpe) :: params1.tail
- }
- else params1
- for (p <- params2 if isRefClass(p.tpe)) {
- p updateInfo mkRemoteRefClass(p.tpe)
- }
- MethodType(params ::: params2, restp)
- case tp =>
- tp
- }
- ctor updateInfo tp
- params
- } //updateConstructorParams
-
- /**
- */
- def updateConstructorDef(ctor: DefDef): (List[Tree], List[Symbol]) = {
- val DefDef(mods, name, tparams, List(vparams), tpt, rhs) = ctor
- val newparams = updateConstructorParams(vparams)
- val vparams0 = newparams map (sym => ValDef(sym) setType sym.tpe)
- val ctorDef = treeCopy.DefDef(ctor, mods, name, tparams, List(vparams0 ::: vparams), tpt, rhs)
- val accessors = for (sym <- newparams) yield {
- val acc = clazz.newValue(sym.pos, sym.name)
- .setFlag(SYNTHETIC | PARAMACCESSOR | PRIVATE | LOCAL)
- .setInfo(sym.tpe)
- clazz.info.decls enter acc
- acc
- }
- val accDefs = accessors map (sym => ValDef(sym) setType sym.tpe)
- (ctorDef :: accDefs, accessors)
- } //updateConstructorDef
-
- val impl = cdef.impl
- val (List(ctor: DefDef), body1) = impl.body partition (t =>
- t.isDef && t.symbol.isPrimaryConstructor)
- val (defs, accessors) = updateConstructorDef(ctor)
- val impl1 = treeCopy.Template(impl, impl.parents, impl.self, defs ::: body1)
- val (from, to) = /*List.unzip*/(
- for (obj <- captured ::: List(outer))
- yield (obj, toInterface(obj))
- ) unzip
- //val substNames = new TreeNameSubstituter(name, clazz)
- val substTypeRefs = new TreeTypeRefSubstituter(clazz)
- val substAccs = new TreeAccessorSubstituter(clazz, from, accessors)
- val substTypes = new TreeOuterSubstituter(from, to)
- val substSyms = new TreeSymSubstituter(from, to)
- val t1 = ClassDef(clazz, substSyms(substTypes(substAccs(substTypeRefs(impl1)))))
- //println("mkClosureDef: t(untyped)=\n"+nodeToString(t1))
- val t = localTyper typed t1
- detachedClosure(clazz) = t.asInstanceOf[ClassDef]
- //println("mkClosureDef: t(typed)=\n"+nodeToString(t))
- t
- } //mkClosureDef
-
- /** <p>
- * Given a class <code>C</code> with member <code>x</code>
- * which is (remotely) referenced from inside a detached closure:
- * </p><pre>
- * class C extends .. {
- * var x: Int
- * }</pre>
- * <p>
- * the method <code>addProxy</code> generates the following two
- * proxy definitions (used later in method <code>mkClosureApply</code>
- * to generate object proxies):
- * </p><pre>
- * trait C$proxy extends java.rmi.Remote {
- * def x(): Int
- * def x_=(x$1: Int): Unit
- * }
- * class C$proxyImpl
- * extends java.rmi.server.UnicastRemoteObject
- * with C$proxy with java.rmi.server.Unreferenced {
- * def this(x$0: String, x$1: C): C$ProxyImpl = ..
- * def x(): Int = this.x$1.x()
- * def x_=(x$1: Int): Unit = this.x$1.x_=(x$1)
- * def unreferenced(): Unit = RemoteRef.unbind(this.x$0)
- * }</pre>
- */
- private def addProxy(closure: Symbol, clazz: Symbol) {
- // the Sun RMI compiler crashes with the error message
- // "error: An error has occurred in the compiler; ..." with trace
- // "sun.tools.java.CompilerError: getInnerClassField" if the
- // generated proxy class does not belong to the top-level scope.
- val proxyOwner = clazz.toplevelClass.owner //clazz.owner
-
- if (DEBUG)
- println("\nadd proxy for "+clazz+" in "+proxyOwner)//debug
-
- val (proxyIntf, proxyImpl, proxyMap) = proxies get clazz match {
- case Some(proxy) =>
- proxy
- case None =>
- val iface =
- proxyOwner.newClass(clazz.pos, encode(clazz.name.decode + PROXY_SUFFIX))
- iface.sourceFile = clazz.sourceFile
- iface setFlag (ABSTRACT | TRAIT | INTERFACE) // Java interface
- val iparents = List(ObjectClass.tpe, RemoteClass.tpe)
- iface setInfo ClassInfoType(iparents, newScope, iface)
- // methods must throw RemoteException
- iface addAnnotation remoteAnnotationInfo
-
- val iclaz =
- proxyOwner.newClass(clazz.pos, encode(iface.name.decode + IMPL_SUFFIX))
- iclaz.sourceFile = clazz.sourceFile
- iclaz setFlag (SYNTHETIC | FINAL)
- // Variant 1: rebind/unbind
- val cparents = List(UnicastRemoteObjectClass.tpe, iface.tpe, UnreferencedClass.tpe)
- // Variant 2: un-/exportObject
- //val cparents = List(ObjectClass.tpe, iface.tpe, UnreferencedClass.tpe)
- iclaz setInfo ClassInfoType(cparents, newScope, iclaz)
- val proxy = (iface, iclaz, new mutable.HashMap[Symbol, Symbol])
- proxies(clazz) = proxy
- proxy
- }
-
- def addAccessors() {
- def mkGetter(sym: Symbol, name: String): Symbol = {
- val getter = if (sym.isMethod) {
- val meth = sym.cloneSymbol(proxyIntf)
- meth.name = name
- val tsym = meth.tpe.resultType.typeSymbol
- if (proxies contains tsym)
- meth updateInfo MethodType(List(), toInterface(tsym).tpe)
- meth
- }
- else {
- val meth = proxyIntf.newMethod(sym.pos, nme.getterName(sym.originalName))
- meth setFlag ACCESSOR
- meth setInfo MethodType(List(), toValueClass(sym.tpe))
- meth
- }
- getter setFlag ABSTRACT
- getter resetFlag FINAL
- getter
- }
- def mkSetter(sym: Symbol): Symbol = {
- val setter = proxyIntf.newMethod(sym.pos, nme.getterToSetter(sym.originalName))
- setter setFlag (sym.flags & ~(PRIVATE | LOCAL) | ACCESSOR | lateDEFERRED)
- val param = setter.newSyntheticValueParam(toValueClass(sym.tpe))
- setter setInfo MethodType(List(param), UnitClass.tpe)
- setter setFlag ABSTRACT
- setter resetFlag FINAL
- setter
- }
- def create(owner: Symbol, clazz: Symbol) {
- val funcs = capturedFuncs(owner).toList
- funcs find (_.isConstructor) match {
- case Some(sym) if capturedFuncs contains sym.owner =>
- create(sym.owner, clazz)
- case _ =>
- }
- val newfuncs = funcs filterNot (proxyMap.valuesIterator.toList contains)
- val (members, others) = newfuncs partition (clazz isSubClass _.owner)
- val outers = others filter (sym =>
- (clazz isNestedIn sym.owner) && clazz.isClass)
- for (sym <- outers) {
- val sym1 = mkGetter(sym, sym.fullName('$'))
- proxyIntf.info.decls enter sym1
- proxyMap(sym1) = sym
- }/*
- for (sym <- outers if capturedCallers contains sym;
- caller <- capturedCallers(sym)) {
- val sym1 = mkGetter(sym, caller.nameString+'$'+sym.nameString)
- if (clazz.isAnonymousClass)
- println("[2] clazz="+clazz+", sym1="+sym1)
- proxyIntf.info.decls enter sym1
- proxyMap(sym1) = sym
- }*/
- for (sym <- members if !sym.isConstructor) {
- val sym1 = mkGetter(sym, sym.originalName.decode)
- proxyIntf.info.decls enter sym1
- proxyMap(sym1) = sym
- }
- for (sym <- members if isRefClass(sym.tpe)) {
- val sym1 = mkSetter(sym)
- proxyIntf.info.decls enter sym1
- proxyMap(sym1) = sym
- }
- }
- create(closure, clazz)
- }
-
- addAccessors
- if (DEBUG) {
- val xs = proxyMap.keysIterator.toList
- println("\tadded "+proxyIntf+
- "\n\twith "+xs.mkString(", ")+" ["+xs.length+"]")
- }
- } //addProxy
-
- def genProxy(clazz: Symbol) {
- val (proxyIntf, proxyImpl, proxyMap) = proxies(clazz)
-
- // generate proxy interface
- val ifaceBody = proxyMap.keysIterator.toList map { DefDef(_, EmptyTree) }
- val ifaceParents =
- proxyIntf.info.parents map (t => TypeTree(t) setPos proxyIntf.pos)
- val ifaceTmpl = Template(ifaceParents, emptyValDef, ifaceBody)
- val ifaceDef = localTyper typed ClassDef(proxyIntf, ifaceTmpl)
-
- // generated proxy implementation
- // Variant 1: rebind/unbind
- val param1 =
- proxyImpl.newValueParameter(proxyImpl.pos, freshName("x$"))
- .setFlag(SYNTHETIC | PARAMACCESSOR | PRIVATE | LOCAL)
- .setInfo(StringClass.tpe)
- proxyImpl.info.decls enter param1
-
- val param2 =
- proxyImpl.newValueParameter(proxyImpl.pos, freshName("x$"))
- .setFlag(SYNTHETIC | PARAMACCESSOR | PRIVATE | LOCAL)
- .setInfo(clazz.tpe)
- proxyImpl.info.decls enter param2
-
- val unreferenced =
- proxyImpl.newMethod(proxyImpl.pos, nme_unreferenced)
- .setInfo(MethodType(List(), UnitClass.tpe))
- proxyImpl.info.decls enter unreferenced
-
- val proxyBody =
- DefDef(unreferenced, List(List()), Block(
- List(Apply( //stats
- Select(gen.mkAttributedRef(DebugModule), "info"),
- List(Apply(
- Select(Literal(Constant("unreferenced: ")), "$plus"),
- // Variant 1: rebind/unbind
- List(Select(This(proxyImpl), param1.name))
- // Variant 2: un-/exportObject
- //List(This(proxyImpl))
- ))
- )),
- Apply( //expr
- Select(gen.mkAttributedRef(RemoteRefModule), nme_unbind),
- // Variant 1: rebind/unbind
- List(Select(This(proxyImpl), param1.name))
- // Variant 2: un-/exportObject
- //List(This(proxyImpl))
- )
- )) :: (
- for (sym <- proxyIntf.info.decls.toList) yield {
- val sym1 = sym.cloneSymbol(proxyImpl)
- sym1 resetFlag (ABSTRACT | DEFERRED | lateDEFERRED)
- proxyImpl.info.decls enter sym1
- DefDef(sym1, {
- val sym2 = proxyMap(sym)
- var t = Select(This(proxyImpl), param2)
- var outerAcc =
- if (sym2.owner isSubClass param2) None
- else param2.info.decls.toList find (_.isOuterAccessor)
- while (!outerAcc.isEmpty) {
- t = Select(t, outerAcc.get)
- val outerClass = outerAcc.get.tpe.resultType.typeSymbol
- outerAcc =
- if (sym2.owner == outerClass) None
- else outerClass.info.decls.toList find (_.isOuterAccessor)
- }
- val sel = Select(t, sym2)
- if (sym2.isMethod) {
- Apply(sel, sym1.paramss(0) map { Ident(_) })
- }
- else if (isRefClass(sym2.tpe)) {
- val sel1 = Select(sel, nme.elem)
- if (sym1.tpe.paramTypes.length == 0) sel1
- else Assign(sel1, Ident(sym1.paramss(0)(0)))
- }
- else
- sel
- })
- })
- val proxyParents =
- proxyImpl.info.parents map (t => TypeTree(t) setPos proxyImpl.pos)
- val proxyTmpl = Template(proxyParents,
- emptyValDef, NoMods,
- // Variant 1: rebind/unbind
- /*vparamss*/ List(List(ValDef(param1), ValDef(param2))),
- // Variant 2: un-/exportObject
- ///*vparamss*/ List(List(ValDef(param2))),
- /*argss*/ List(List()), proxyBody, NoPosition)
- val proxyDef = localTyper typed ClassDef(proxyImpl, proxyTmpl)
-
- // remember definitions to be added by transformStats
- val proxyOwner = proxyIntf.owner
- if (! (proxyInterfaceDefs contains proxyOwner))
- proxyInterfaceDefs(proxyOwner) = new ListBuffer
- proxyInterfaceDefs(proxyOwner) += ifaceDef
- proxyInterfaceDefs(proxyOwner) += proxyDef
- } //genProxy
-
- private def freshName(s: String): Name =
- unit.fresh.newName(s)
-
- private def freshProxyName: Name =
- unit.fresh.newName(PROXY_PREFIX)
-
- /** <p>
- * Given a detached closure applied in some environment consisting
- * of an enclosing class <code>C</code> and some local variables
- * <code>x$1</code> (immutable) and <code>y$1</code> (mutable):
- * </p><pre>
- * scala.remoting.detach.apply({
- * (new $anonfun$1(C.this, x$1, y$1): Function1)
- * })</pre>
- * <p>
- * the above code is transformed to the following block:
- * </p><pre>
- * {
- * val proxy$1: C$Proxy =
- * RemoteRef.bind("C/proxy$1", new C$ProxyImpl(C.this))
- * val proxy$2: RemoteIntRef =
- * RemoteRef.bind("C/proxy$2", new RemoteIntRefImpl(y$1))
- * (new $anonfun$1detach(proxy$1, x$1, proxy$2): Function1)
- * }
- * </pre>
- */
- private def mkClosureApply(tree: Tree): Tree = {
- val apply @ Apply(fun, args) = detachedClosureApply(tree)
- assert(fun.symbol.isConstructor, fun.symbol+" is not a constructor")//debug
- val clazz = apply.tpe.typeSymbol
- val thiz = capturedThisClass(clazz)
- val cdef = mkClosureDef(clazz)
- val uid = localTyper typed {
- val sym = currentOwner.newValue(tree.pos, freshName("uid$"))
- .setFlag(SYNTHETIC)
- .setInfo(StringClass.tpe)
- val rhs = Apply(Select(
- Apply(
- Select(New(TypeTree(UIDClass.tpe)), nme.CONSTRUCTOR),
- List()
- ),
- "toString"
- ), List())
- ValDef(sym, rhs)
- }
- def cast(tree: Tree, tpe: Type): Tree =
- Apply(
- TypeApply(
- Select(tree, Object_asInstanceOf),
- List(TypeTree(tpe))
- ),
- List()
- )
-
- def mkProxy(csym: Symbol): ValDef = {
- val (iface, proxy, _) = proxies(csym)
- val sym = currentOwner.newValue(csym.pos, freshProxyName)
- .setFlag(SYNTHETIC)
- .setInfo(iface.tpe)
- val bind = Select(gen.mkAttributedRef(RemoteRefModule), nme_bind)
- val name = Apply(
- Select(Literal(Constant(sym.fullName('/')+"$")), String_+),
- List(Ident(uid.symbol))
- )
- val thiz =
- if (csym.isModule) gen.mkAttributedIdent(csym)
- else gen.mkAttributedThis(csym)
- val args = List(name,
- Apply(Select(New(TypeTree(proxy.tpe)), nme.CONSTRUCTOR),
- // Variant 1: rebind/unbind
- List(name, thiz)))
- // Variant 2: un-/exportObject
- //List(thiz)))
- val rhs = cast(Apply(bind, args), iface.tpe)
- ValDef(sym, rhs)
- }
-
- def mkObjProxies: List[ValDef] = {
- val (outer, captured) =
- capturedObjects(clazz).toList partition (thiz.==)
- (captured ::: outer) map mkProxy
- }
-
- def mkArgProxies: Map[Symbol, ValDef] = {
- def retRefs(t: Tree): List[Tree] = t match {
- case Apply(fun, args) =>
- args flatMap retRefs
- case id @ Ident(_) =>
- if (isRefClass(id.tpe)) List(id) else Nil
- case Template(_, _, body) =>
- body flatMap retRefs
- case New(tpt) =>
- retRefs(tpt)
- case thiz @ This(_) =>
- if (isRefClass(thiz.tpe)) List(thiz) else Nil
- case _ =>
- throw new Error("Internal error: " + t.getClass)
- }
- new immutable.HashMap[Symbol, ValDef] ++ (
- for (variable <- retRefs(apply)) yield {
- val param = variable.symbol
- assert(isRefClass(param.tpe), param)
- val proxy = currentOwner.newValue(param.pos, freshProxyName)
- .setFlag(SYNTHETIC)
- .setInfo(mkRemoteRefClass(param.tpe))
- val bind = Select(gen.mkAttributedRef(RemoteRefModule), nme_bind)
- //val name = Literal(Constant(proxy.fullName('/')))
- val name = Apply(
- Select(Literal(Constant(proxy.fullName('/')+"$")), String_+),
- List(Ident(uid.symbol))
- )
- val ts = param.tpe.typeSymbol
- val args = List(name,
- Apply(
- Select(New(TypeTree(remoteRefImpl(ts).tpe)), nme.CONSTRUCTOR),
- // Variant 1: rebind/unbind
- List(name, variable)))
- // Variant 2: un-/exportObject
- //List(variable)))
- val rhs = cast(Apply(bind, args), remoteRefClass(ts).tpe)
- (param, ValDef(proxy, rhs))
- }
- )
- } //mkArgProxies
-
- /** <p>
- * Method <code>mkClosureInstance</code> updates the list of actual
- * parameters passed to the closure instance.
- * </p>
- */
- def mkClosureInstance(objProxies: List[ValDef],
- argProxies: Map[Symbol, ValDef]): Tree = {
- fun.tpe = fun.symbol.tpe
- val args0 = objProxies map (tree => Ident(tree.symbol))
- val hasOuter = !args.isEmpty && (args.head.symbol.tpe == thiz.tpe)
- val args1 = (if (hasOuter) args.tail else args) map (arg =>
- argProxies get arg.symbol match {
- case Some(t) => Ident(t.symbol)
- case None => arg
- }
- )
- if (DEBUG)
- println("\nmkClosureInstance:\n\targs0="+args0+"\n\targs1="+args1)
- val t = Typed(
- Apply(fun, args0 ::: args1),
- //TypeTree(clazz.info.parents.tail.head) //interface (2.7.x)
- TypeTree(clazz.info.parents.head) //interface (2.8.x)
- )
- localTyper typed t
- } //mkClosureInstance
-
- val objProxies = mkObjProxies
- val argProxies = mkArgProxies
- val stats = uid :: objProxies ::: argProxies.valuesIterator.toList
- val expr = mkClosureInstance(objProxies, argProxies)
- localTyper typed Block(stats, expr)
- } //mkClosureApply
-
- override def transform(tree: Tree): Tree = {
- def withInConstructorFlag(inConstructorFlag: Long)(f: => Tree): Tree = {
- val savedInConstructorFlag = this.inConstructorFlag
- this.inConstructorFlag = inConstructorFlag
- val t = f
- this.inConstructorFlag = savedInConstructorFlag
- t
- }
- if (!isEnabled) return tree
- tree match {
- case ClassDef(mods, name, tparams, impl) =>
- val tree1 = super.transform(tree)
- if (!reporter.hasErrors && (capturedThisClass contains tree1.symbol))
- mkClosureDef(tree1.symbol)
- else
- tree1
-
- case Apply(Select(_, _), _) =>
- val tree1 = super.transform(tree)
- if (!reporter.hasErrors && (detachedClosureApply contains tree1))
- atPos(tree1.pos)(mkClosureApply(tree1))
- else
- tree1
-
- case Template(_, _, _) =>
- withInConstructorFlag(0) { super.transform(tree) }
-
- case _ =>
- super.transform(tree)
- }
- }
-
- /** Transform statements and add detached definitions to them. */
- override def transformStats(stats: List[Tree], exprOwner: Symbol): List[Tree] = {
- val stats1 = super.transformStats(stats, exprOwner)
- val newDefs = {
- val buf = new ListBuffer[Tree]
- if (proxyInterfaceDefs contains currentOwner)
- buf ++= proxyInterfaceDefs(currentOwner).toList
- buf.toList
- }
- if (newDefs.isEmpty) stats1 else stats1 ::: newDefs
- }
-
- private def genProxies() {
- def printDebugInfo() {
- println("\ncompilation unit : "+unit)
- for ((sym, _) <- detachedClosure) {
- println("closure to detach: "+sym+" (owner: "+sym.owner+")")
- println("captured this : "+capturedThisClass(sym))
- val objs = capturedObjects get sym match {
- case Some(ss) => ss.toList
- case None => Nil
- }
- println("captured objects : "+objs.mkString(", ")+" ["+objs.length+"]")
- }
- println("\ncalled functions :")
- for (sym <- capturedFuncs.keysIterator) {
- val xs = capturedFuncs(sym).toList map (s => {
- val callers = capturedCallers get s match {
- case Some(ss) => "|"+ss.toList.mkString(",")
- case None => ""
- }
- s+"("+s.owner.name+callers+")"
- })
- println("\t"+sym+" -> "+xs.mkString(", ")+" ["+xs.length+"]")
- }
- }
- def printDebugInfo2() {
- println("\nproxy classes :")
- for (sym <- proxies.keysIterator)
- println("\t"+sym+"("+sym.tpe+") -> "+proxies(sym))
- }
- if (DEBUG)
- printDebugInfo
- for ((closure, _) <- detachedClosure;
- captured <- capturedObjects(closure))
- addProxy(closure, captured)
- if (DEBUG)
- printDebugInfo2
- for (sym <- proxies.keysIterator)
- genProxy(sym)
- } //genProxies
-
- /** <p>
- * Method <code>transformUnit</code> performs three successive operations:
- * </p>
- * <ol>
- * <li>it first gathers infos about free objects and detached
- * closures;</li>
- * <li>it then adds proxies for free objects;</li>
- * <li>finally, if transforms detached closures (both definition and
- * instantiation).</li>
- * </ol>
- */
- override def transformUnit(unit: CompilationUnit) {
- freeObjTraverser.traverse(unit.body)
- if (!reporter.hasErrors) genProxies
- super.transformUnit(unit)
- }
- }
-
-}
-
diff --git a/src/detach/plugin/scala/tools/detach/DetachPlugin.scala b/src/detach/plugin/scala/tools/detach/DetachPlugin.scala
deleted file mode 100644
index c6e18b7abe..0000000000
--- a/src/detach/plugin/scala/tools/detach/DetachPlugin.scala
+++ /dev/null
@@ -1,41 +0,0 @@
-/* NSC -- new Scala compiler
- * Copyright 2005-2013 LAMP/EPFL
- * @author Stephane Micheloud
- */
-
-package scala.tools.detach
-
-import scala.tools.nsc.{Global, Phase}
-import scala.tools.nsc.plugins.{Plugin, PluginComponent}
-
-class DetachPlugin(val global: Global) extends Plugin {
- import global._
-
- val name = "detach"
- val description = "Perform detaching of remote closures"
-
- object detach extends {
- val global = DetachPlugin.this.global
- val runsAfter = List("lambdalift")
- override val runsBefore = List("constructors")
- } with Detach
-
- val components = List[PluginComponent](detach)
-
- def setEnabled(flag: Boolean) { detach.isEnabled = flag }
-
- override def processOptions(options: List[String], error: String => Unit) = {
- var enabled = false
- for (option <- options) {
- if (option == "enable") {
- enabled = true
- } else {
- error("Option not understood: "+option)
- }
- }
- setEnabled(enabled)
- }
-
- override val optionsHelp: Option[String] =
- Some(" -P:detach:enable Enable detaching of remote closures")
-}
diff --git a/src/detach/plugin/scalac-plugin.xml b/src/detach/plugin/scalac-plugin.xml
deleted file mode 100644
index 6c8600e331..0000000000
--- a/src/detach/plugin/scalac-plugin.xml
+++ /dev/null
@@ -1,4 +0,0 @@
-<plugin>
- <name>detach</name>
- <classname>scala.tools.detach.DetachPlugin</classname>
-</plugin>
diff --git a/src/eclipse/README.md b/src/eclipse/README.md
index 39a3f457a0..d135f99418 100644
--- a/src/eclipse/README.md
+++ b/src/eclipse/README.md
@@ -44,7 +44,7 @@ If you want to go back to normal (for instance, to commit your changes to projec
DETAILS
=======
-The compiler project depends on the library, reflect, asm and fjbg projects. The
+The compiler project depends on the library, reflect, and asm projects. The
builder will take care of the correct ordering, and changes in one project will
be picked up by the dependent projects.
diff --git a/src/eclipse/fjbg/.classpath b/src/eclipse/fjbg/.classpath
deleted file mode 100644
index 3e2f55f48a..0000000000
--- a/src/eclipse/fjbg/.classpath
+++ /dev/null
@@ -1,7 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" path="fjbg"/>
- <classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
- <classpathentry kind="output" path="libs-classes-fjbg"/>
-</classpath>
diff --git a/src/eclipse/fjbg/.project b/src/eclipse/fjbg/.project
deleted file mode 100644
index 8acea9f5fe..0000000000
--- a/src/eclipse/fjbg/.project
+++ /dev/null
@@ -1,30 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>fjbg</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.scala-ide.sdt.core.scalabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.scala-ide.sdt.core.scalanature</nature>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
- <linkedResources>
- <link>
- <name>fjbg</name>
- <type>2</type>
- <locationURI>SCALA_BASEDIR/src/fjbg</locationURI>
- </link>
- <link>
- <name>libs-classes-fjbg</name>
- <type>2</type>
- <locationURI>SCALA_BASEDIR/build/libs/classes/fjbg</locationURI>
- </link>
- </linkedResources>
-</projectDescription>
diff --git a/src/eclipse/partest/.classpath b/src/eclipse/partest/.classpath
index 7936d4d4b4..75a9fae19a 100644
--- a/src/eclipse/partest/.classpath
+++ b/src/eclipse/partest/.classpath
@@ -8,7 +8,6 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="lib/ant/ant.jar"/>
<classpathentry kind="lib" path="lib/jline.jar"/>
- <classpathentry kind="lib" path="lib/msil.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/asm"/>
<classpathentry combineaccessrules="false" kind="src" path="/continuations-library"/>
<classpathentry kind="output" path="build-quick-partest"/>
diff --git a/src/eclipse/scala-compiler/.classpath b/src/eclipse/scala-compiler/.classpath
index d438d3e610..0488a0dc39 100644
--- a/src/eclipse/scala-compiler/.classpath
+++ b/src/eclipse/scala-compiler/.classpath
@@ -3,12 +3,10 @@
<classpathentry kind="src" path="compiler"/>
<classpathentry combineaccessrules="false" kind="src" path="/reflect"/>
<classpathentry combineaccessrules="false" kind="src" path="/scala-library"/>
- <classpathentry combineaccessrules="false" kind="src" path="/fjbg"/>
<classpathentry combineaccessrules="false" kind="src" path="/asm"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="lib/ant/ant.jar"/>
<classpathentry kind="lib" path="lib/jline.jar"/>
- <classpathentry kind="lib" path="lib/msil.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/continuations-library"/>
<classpathentry kind="output" path="build-quick-compiler"/>
</classpath>
diff --git a/src/eclipse/scalap/.classpath b/src/eclipse/scalap/.classpath
index 16737bd9cd..0a55745702 100644
--- a/src/eclipse/scalap/.classpath
+++ b/src/eclipse/scalap/.classpath
@@ -7,7 +7,6 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="lib/ant/ant.jar"/>
<classpathentry kind="lib" path="lib/jline.jar"/>
- <classpathentry kind="lib" path="lib/msil.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/continuations-library"/>
<classpathentry kind="output" path="build-quick-scalap"/>
</classpath>
diff --git a/src/fjbg/ch/epfl/lamp/fjbg/FJBGContext.java b/src/fjbg/ch/epfl/lamp/fjbg/FJBGContext.java
deleted file mode 100644
index 9856dc7311..0000000000
--- a/src/fjbg/ch/epfl/lamp/fjbg/FJBGContext.java
+++ /dev/null
@@ -1,195 +0,0 @@
-/* FJBG -- Fast Java Bytecode Generator
- * Copyright 2002-2013 LAMP/EPFL
- * @author Michel Schinz
- */
-
-package ch.epfl.lamp.fjbg;
-
-import java.io.DataInputStream;
-import java.io.IOException;
-
-/**
- * Context in which FJBG executes. Used both as a factory for most
- * FJBG classes and as a repository for other factories.
- *
- * @author Michel Schinz
- * @version 1.0
- */
-
-public class FJBGContext {
- /** Class file major version */
- final int MAJOR_VERSION;
-
- /** Class file minor version */
- final int MINOR_VERSION;
-
- public FJBGContext() {
- this(45, 3);
- }
-
- public FJBGContext(int major, int minor) {
- MAJOR_VERSION = major;
- MINOR_VERSION = minor;
- }
-
- // Factory methods
- //////////////////////////////////////////////////////////////////////
-
- public JClass JClass(int accessFlags,
- String name,
- String superclassName,
- String[] interfaceNames,
- String sourceFileName) {
- return new JClass(this,
- accessFlags,
- name,
- superclassName,
- interfaceNames,
- sourceFileName);
- }
-
- public JClass JClass(DataInputStream stream)
- throws IOException {
- return new JClass(this, stream);
- }
-
- public JConstantPool JConstantPool() {
- return new JConstantPool(this);
- }
-
- public JConstantPool JConstantPool(DataInputStream stream)
- throws IOException {
- return new JConstantPool(this, stream);
- }
-
- public JField JField(JClass owner,
- int accessFlags,
- String name,
- JType type) {
- return new JField(this,
- owner,
- accessFlags,
- name,
- type);
- }
-
- public JField JField(JClass owner, DataInputStream stream)
- throws IOException {
- return new JField(this, owner, stream);
- }
-
- public JMethod JMethod(JClass owner,
- int accessFlags,
- String name,
- JType returnType,
- JType[] argTypes,
- String[] argNames) {
- return new JMethod(this,
- owner,
- accessFlags,
- name,
- returnType,
- argTypes,
- argNames);
- }
-
- public JMethod JMethod(JClass owner,
- int accessFlags,
- String name,
- JMethodType type,
- String[] argNames) {
- return JMethod(owner,
- accessFlags,
- name,
- type.getReturnType(),
- type.getArgumentTypes(),
- argNames);
- }
-
- public JMethod JMethod(JClass owner, DataInputStream stream)
- throws IOException {
- return new JMethod(this, owner, stream);
- }
-
- public JLocalVariable JLocalVariable(JMethod owner,
- JType type,
- String name,
- int index) {
- return new JLocalVariable(this, owner, type, name, index);
- }
-
- public JCode JCode(JClass clazz, JMethod owner) {
- return new JExtendedCode(this, clazz, owner);
- }
-
- public JCode JCode(JClass clazz, JMethod owner, DataInputStream stream)
- throws IOException {
- return new JCode(this, clazz, owner, stream);
- }
-
- public JAttributeFactory JAttributeFactory() {
- return new JAttributeFactory(this);
- }
-
- // Attributes
- public JCodeAttribute JCodeAttribute(JClass clazz, JMethod owner) {
- return new JCodeAttribute(this, clazz, owner);
- }
-
- public JEnclosingMethodAttribute JEnclosingMethodAttribute(JClass clazz,
- String className,
- String methodName,
- JType methodType) {
- return new JEnclosingMethodAttribute(this, clazz, className, methodName, methodType);
- }
-
- public JExceptionsAttribute JExceptionsAttribute(JClass clazz,
- JMethod owner) {
- return new JExceptionsAttribute(this, clazz, owner);
- }
-
- public JLineNumberTableAttribute JLineNumberTableAttribute(JClass clazz,
- JCode owner) {
- return new JLineNumberTableAttribute(this, clazz, owner);
- }
-
- public JLocalVariableTableAttribute JLocalVariableTableAttribute(JClass clazz,
- JCode owner) {
- return new JLocalVariableTableAttribute(this, clazz, owner);
- }
-
- public JOtherAttribute JOtherAttribute(JClass clazz,
- Object owner,
- String name,
- byte[] contents,
- int length) {
- return new JOtherAttribute(this, clazz, owner, name, contents, length);
- }
-
- public JOtherAttribute JOtherAttribute(JClass clazz,
- Object owner,
- String name,
- byte[] contents) {
- return JOtherAttribute(clazz, owner, name, contents, contents.length);
- }
-
- public JSourceFileAttribute JSourceFileAttribute(JClass clazz,
- String sourceFileName) {
- return new JSourceFileAttribute(this, clazz, sourceFileName);
- }
-
- public JStackMapTableAttribute JStackMapTableAttribute(JClass clazz,
- JCode owner) {
- return new JStackMapTableAttribute(this, clazz, owner);
- }
-
- /// Repository
- //////////////////////////////////////////////////////////////////////
-
- protected JAttributeFactory jAttributeFactory = null;
- public JAttributeFactory getJAttributeFactory() {
- if (jAttributeFactory == null)
- jAttributeFactory = JAttributeFactory();
- return jAttributeFactory;
- }
-}
diff --git a/src/fjbg/ch/epfl/lamp/fjbg/JAccessFlags.java b/src/fjbg/ch/epfl/lamp/fjbg/JAccessFlags.java
deleted file mode 100644
index 01d8cc9a7e..0000000000
--- a/src/fjbg/ch/epfl/lamp/fjbg/JAccessFlags.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/* FJBG -- Fast Java Bytecode Generator
- * Copyright 2002-2013 LAMP/EPFL
- * @author Michel Schinz
- */
-
-package ch.epfl.lamp.fjbg;
-
-/**
- * Definition of access flags for fields, methods and classes.
- *
- * @author Michel Schinz
- * @version 1.0
- */
-
-public interface JAccessFlags {
- public static int ACC_PUBLIC = 0x0001;
- public static int ACC_PRIVATE = 0x0002;
- public static int ACC_PROTECTED = 0x0004;
- public static int ACC_STATIC = 0x0008;
- public static int ACC_FINAL = 0x0010;
- public static int ACC_SUPER = 0x0020;
- public static int ACC_VOLATILE = 0x0040;
- public static int ACC_TRANSIENT = 0x0080;
- public static int ACC_NATIVE = 0x0100;
- public static int ACC_INTERFACE = 0x0200;
- public static int ACC_ABSTRACT = 0x0400;
- public static int ACC_STRICT = 0x0800;
- public static int ACC_SYNTHETIC = 0x1000;
- public static int ACC_ANNOTATION= 0x2000;
- public static int ACC_ENUM = 0x4000;
-
- // 1.5 specifics
- public static int ACC_BRIDGE = 0x0040;
- public static int ACC_VARARGS = 0x0080;
-}
diff --git a/src/fjbg/ch/epfl/lamp/fjbg/JArrayType.java b/src/fjbg/ch/epfl/lamp/fjbg/JArrayType.java
deleted file mode 100644
index 61a04523ca..0000000000
--- a/src/fjbg/ch/epfl/lamp/fjbg/JArrayType.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/* FJBG -- Fast Java Bytecode Generator
- * Copyright 2002-2013 LAMP/EPFL
- * @author Michel Schinz
- */
-
-package ch.epfl.lamp.fjbg;
-
-/**
- * Types for Java arrays.
- *
- * @author Michel Schinz
- * @version 1.0
- */
-
-public class JArrayType extends JReferenceType {
- protected final JType elementType;
- protected String signature = null;
-
- public JArrayType(JType elementType) {
- this.elementType = elementType;
- }
-
- public int getSize() { return 1; }
-
- public String getSignature() {
- if (signature == null)
- signature = "[" + elementType.getSignature();
- return signature;
- }
-
- public String getDescriptor() {
- return getSignature();
- }
-
- public int getTag() { return T_ARRAY; }
-
- public JType getElementType() { return elementType; }
-
- public String toString() {
- return elementType.toString() + "[]";
- }
-
- public boolean isArrayType() { return true; }
-
- public boolean isCompatibleWith(JType other) {
- if (other instanceof JObjectType)
- return (JObjectType)other == JObjectType.JAVA_LANG_OBJECT;
- else if (other instanceof JArrayType)
- return elementType.isCompatibleWith(((JArrayType)other).elementType);
- else return other == JType.REFERENCE;
- }
-
- public static JArrayType BOOLEAN = new JArrayType(JType.BOOLEAN);
- public static JArrayType BYTE = new JArrayType(JType.BYTE);
- public static JArrayType CHAR = new JArrayType(JType.CHAR);
- public static JArrayType SHORT = new JArrayType(JType.SHORT);
- public static JArrayType INT = new JArrayType(JType.INT);
- public static JArrayType FLOAT = new JArrayType(JType.FLOAT);
- public static JArrayType LONG = new JArrayType(JType.LONG);
- public static JArrayType DOUBLE = new JArrayType(JType.DOUBLE);
- public static JArrayType REFERENCE = new JArrayType(JType.REFERENCE);
-}
diff --git a/src/fjbg/ch/epfl/lamp/fjbg/JAttribute.java b/src/fjbg/ch/epfl/lamp/fjbg/JAttribute.java
deleted file mode 100644
index 6a825beb18..0000000000
--- a/src/fjbg/ch/epfl/lamp/fjbg/JAttribute.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/* FJBG -- Fast Java Bytecode Generator
- * Copyright 2002-2013 LAMP/EPFL
- * @author Michel Schinz
- */
-
-package ch.epfl.lamp.fjbg;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.*;
-
-/**
- * Abstract superclass for attributes which can be attached to various
- * parts of a class file.
- *
- * Attributes are used for classes (section 4.2), fields (section 4.6),
- * methods (section 4.7) and the Code attribute (section 4.8.3).
- * See sections 4.2 and later of the JVM specification.
- *
- * @author Michel Schinz
- * @version 1.0
- */
-
-public abstract class JAttribute {
- protected final int nameIdx;
-
- static public void writeTo(List/*<JAttribute>*/ attrs, DataOutputStream stream)
- throws IOException {
- stream.writeShort(attrs.size());
- Iterator attrsIt = attrs.iterator();
- while (attrsIt.hasNext()) {
- JAttribute attr = (JAttribute)attrsIt.next();
- attr.writeTo(stream);
- }
- }
-
- static public List/*<JAttribute>*/ readFrom(FJBGContext context,
- JClass clazz,
- Object owner,
- DataInputStream stream)
- throws IOException {
- JAttributeFactory factory = context.getJAttributeFactory();
- int count = stream.readShort();
- ArrayList list = new ArrayList(count);
- for (int i = 0; i < count; ++i)
- list.add(factory.newInstance(clazz, owner, stream));
- return list;
- }
-
- public JAttribute(FJBGContext context, JClass clazz) {
- this.nameIdx = clazz.getConstantPool().addUtf8(getName());
- }
-
- public JAttribute(FJBGContext context, JClass clazz, String name) {
- this.nameIdx = clazz.getConstantPool().addUtf8(name);
- }
-
- abstract public String getName();
-
- /**
- * Write the attribute to a stream.
- */
- public void writeTo(DataOutputStream stream) throws IOException {
- int contentsSize = getSize();
-
- stream.writeShort(nameIdx);
- stream.writeInt(contentsSize);
- int streamSizeBefore = stream.size();
- writeContentsTo(stream);
- int streamSizeDiff = stream.size() - streamSizeBefore;
-
- assert contentsSize == streamSizeDiff
- : "invalid size for attribute " + getName()
- + " given: " + contentsSize
- + " actual: " + streamSizeDiff;
- }
-
- // Note: it is not legal to add data to the constant pool during
- // the execution of any of the following two methods.
- protected abstract int getSize();
- protected abstract void writeContentsTo(DataOutputStream stream)
- throws IOException;
-}
diff --git a/src/fjbg/ch/epfl/lamp/fjbg/JAttributeFactory.java b/src/fjbg/ch/epfl/lamp/fjbg/JAttributeFactory.java
deleted file mode 100644
index 33cdce2760..0000000000
--- a/src/fjbg/ch/epfl/lamp/fjbg/JAttributeFactory.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/* FJBG -- Fast Java Bytecode Generator
- * Copyright 2002-2013 LAMP/EPFL
- * @author Michel Schinz
- */
-
-package ch.epfl.lamp.fjbg;
-
-import java.io.DataInputStream;
-import java.io.IOException;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.util.HashMap;
-
-/**
- * Extensible factory to build subclasses of JAttribute based on an
- * attribute name.
- *
- * @author Michel Schinz
- * @version 1.0
- */
-
-public class JAttributeFactory {
- protected FJBGContext context;
- protected HashMap/*<String, Constructor>*/ constructors = new HashMap();
-
- protected final static Class[] CONSTRUCTOR_ARGS = new Class[] {
- FJBGContext.class,
- JClass.class,
- Object.class,
- String.class,
- int.class,
- DataInputStream.class
- };
-
- protected final static Constructor defaultDefaultConstructor;
- static {
- try {
- defaultDefaultConstructor =
- JOtherAttribute.class.getConstructor(CONSTRUCTOR_ARGS);
- } catch (NoSuchMethodException e) {
- throw new RuntimeException(e);
- }
- }
-
- protected final Constructor defaultConstructor;
-
- public JAttributeFactory(FJBGContext context,
- Constructor defaultConstructor) {
- this.context = context;
- this.defaultConstructor = defaultConstructor;
- registerClass("Code", JCodeAttribute.class);
- registerClass("ConstantValue", JConstantValueAttribute.class);
- registerClass("EnclosingMethod", JEnclosingMethodAttribute.class);
- registerClass("Exceptions", JExceptionsAttribute.class);
- registerClass("InnerClasses", JInnerClassesAttribute.class);
- registerClass("LineNumberTable", JLineNumberTableAttribute.class);
- registerClass("LocalVariableTable", JLocalVariableTableAttribute.class);
- registerClass("SourceFile", JSourceFileAttribute.class);
- registerClass("StackMapTable", JStackMapTableAttribute.class);
- }
-
- public JAttributeFactory(FJBGContext context) {
- this(context, defaultDefaultConstructor);
- }
-
- public void registerClass(String attributeName,
- Class clazz) {
- if (! JAttribute.class.isAssignableFrom(clazz))
- throw new IllegalArgumentException("Not a subclass of JAttribute: "
- + clazz);
-
- try {
- Constructor constr = clazz.getConstructor(CONSTRUCTOR_ARGS);
- constructors.put(attributeName, constr);
- } catch (NoSuchMethodException e) {
- throw new IllegalArgumentException("No appropriate constructor for "
- + clazz);
- }
- }
-
- public JAttribute newInstance(JClass clazz,
- Object owner,
- DataInputStream stream)
- throws IOException {
- String name = clazz.getConstantPool().lookupUtf8(stream.readShort());
- Integer size = new Integer(stream.readInt());
- Constructor constr = (Constructor)constructors.get(name);
- if (constr == null) constr = defaultConstructor;
-
- Object[] args = new Object[] { context, clazz, owner, name, size, stream };
- try {
- return (JAttribute)constr.newInstance(args);
- } catch (InstantiationException e) {
- throw new RuntimeException(e);
- } catch (IllegalAccessException e) {
- throw new RuntimeException(e);
- } catch (InvocationTargetException e) {
- throw new RuntimeException(e);
- }
- }
-}
diff --git a/src/fjbg/ch/epfl/lamp/fjbg/JClass.java b/src/fjbg/ch/epfl/lamp/fjbg/JClass.java
deleted file mode 100644
index bb1538ec23..0000000000
--- a/src/fjbg/ch/epfl/lamp/fjbg/JClass.java
+++ /dev/null
@@ -1,420 +0,0 @@
-/* FJBG -- Fast Java Bytecode Generator
- * Copyright 2002-2013 LAMP/EPFL
- * @author Michel Schinz
- */
-
-package ch.epfl.lamp.fjbg;
-
-import java.util.*;
-import java.io.*;
-
-/**
- * Representation of a Java class.
- *
- * @author Michel Schinz, Stephane Micheloud
- * @version 1.1
- */
-public class JClass extends JMember {
-
- /** Magic number for Java class files. */
- public final static int MAGIC_NUMBER = 0xCAFEBABE;
-
- protected final JAttributeFactory attributeFactory;
-
- protected final String superclassName;
- protected final String[] interfaceNames;
- protected final String sourceFileName;
- protected final JConstantPool pool;
-
- public final static String[] NO_INTERFACES = new String[0];
-
- protected final LinkedList/*<JMethod>*/ methods = new LinkedList();
- protected final LinkedList/*<JField>*/ fields = new LinkedList();
-
- protected JInnerClassesAttribute innerClasses;
-
- protected int major;
- protected int minor;
-
- /**
- * Creates a new class with its access flags, name, superclass name,
- * interfaces names and source file name initialized to a given value.
- * The constructor also initializes the pool and adds a sourceFileName
- * attribute to the class.
- * @param accessFlags the int representing the access flags of the class.
- * @param name the string representing the name of the class.
- * @param superclassName the string representing the name of the class'
- * superclass.
- * @param interfaceNames the list of strings representing the names of the
- * interfaces implemented by the class.
- * @param sourceFileName name of the file from which the class was compiled.
- */
- protected JClass(FJBGContext context,
- int accessFlags,
- String name,
- String superclassName,
- String[] interfaceNames,
- String sourceFileName) {
- super(context, accessFlags, name);
- this.attributeFactory = context.getJAttributeFactory();
-
- this.major = context.MAJOR_VERSION;
- this.minor = context.MINOR_VERSION;
-
- this.superclassName = superclassName;
- this.interfaceNames = interfaceNames;
- this.sourceFileName = sourceFileName;
- this.pool = context.JConstantPool();
- if (sourceFileName != null)
- addAttribute(context.JSourceFileAttribute(this, sourceFileName));
- }
-
- protected JClass(FJBGContext context, DataInputStream stream)
- throws IOException {
- super(context);
- this.attributeFactory = context.getJAttributeFactory();
-
- int magic = stream.readInt();
- if (magic != MAGIC_NUMBER)
- throw new IllegalArgumentException("invalid magic number: "+magic);
-
- minor = stream.readShort();
- major = stream.readShort();
- pool = context.JConstantPool(stream);
- accessFlags = stream.readShort();
-
- // This class, super class and interfaces
- name = pool.lookupClass(stream.readShort());
- superclassName = pool.lookupClass(stream.readShort());
- interfaceNames = new String[stream.readShort()];
- for (int i = 0; i < interfaceNames.length; ++i)
- interfaceNames[i] = pool.lookupClass(stream.readShort());
-
- // Fields, methods and attributes
- int fieldsCount = stream.readShort();
- for (int i = 0; i < fieldsCount; ++i)
- addField(context.JField(this, stream));
-
- int methodsCount = stream.readShort();
- for (int i = 0; i < methodsCount; ++i)
- addMethod(context.JMethod(this, stream));
-
- String fileName = null;
- int attributesCount = stream.readShort();
- for (int i = 0; i < attributesCount; ++i) {
- JAttribute attr = attributeFactory.newInstance(this, this, stream);
- if (attr instanceof JSourceFileAttribute)
- fileName = ((JSourceFileAttribute)attr).getFileName();
- else if (attr instanceof JInnerClassesAttribute)
- innerClasses = (JInnerClassesAttribute)attr;
- addAttribute(attr);
- }
- sourceFileName = fileName;
- }
-
- /**
- * Gets the name of the class' superclass.
- * @return The string representing the name of the class' superclass.
- */
- public String getSuperclassName() { return superclassName; }
-
- /**
- * Gets the names of the interfaces implemented by the class.
- * @return The array containing the string representations of the
- * names of the interfaces implemented by the class.
- */
- public String[] getInterfaceNames() { return interfaceNames; }
-
- /**
- * Gets the source file name of this class.
- * @return The string representing the source file name of this class.
- */
- public String getSourceFileName() { return sourceFileName; }
-
- /**
- * Gets the type of the objects that are instances of the class.
- * @return The type of the instances of the class.
- */
- public JType getType() { return new JObjectType(name); }
-
- public JClass getJClass() { return this; }
-
- public boolean isPublic() {
- return (accessFlags & JAccessFlags.ACC_PUBLIC) != 0;
- }
-
- public boolean isPrivate() {
- return (accessFlags & JAccessFlags.ACC_PRIVATE) != 0;
- }
-
- public boolean isProtected() {
- return (accessFlags & JAccessFlags.ACC_PROTECTED) != 0;
- }
-
- public boolean isStatic() {
- return (accessFlags & JAccessFlags.ACC_STATIC) != 0;
- }
-
- public boolean isFinal() {
- return (accessFlags & JAccessFlags.ACC_FINAL) != 0;
- }
-
- public boolean isAbstract() {
- return (accessFlags & JAccessFlags.ACC_ABSTRACT) != 0;
- }
-
- /**
- * Gets the version number of the class.
- * @param major The int representing the major part of the version number
- * of the class.
- * @param minor The int representing the minor part of the version number
- * of the class.
- */
- public void setVersion(int major, int minor) {
- assert !frozen;
- this.major = major;
- this.minor = minor;
- }
-
- /**
- * Gets the major part of the number describing the version of the class.
- * @return The int representing the major part of the version number of
- * the class.
- */
- public int getMajorVersion() { return major; }
-
- /**
- * Gets the minor part of the number describing the version of the class.
- * @return The int representing the minor part of the version number of
- * the class.
- */
- public int getMinorVersion() { return minor; }
-
- /**
- * Gets the constant pool of the class.
- * @return The constant pool of the class.
- */
- public JConstantPool getConstantPool() { return pool; }
-
- public JInnerClassesAttribute getInnerClasses() {
- if (innerClasses == null) {
- innerClasses = new JInnerClassesAttribute(context, this);
- addAttribute(innerClasses);
- }
- return innerClasses;
- }
-
- /**
- * Decides if the class is an interface.
- * @return The boolean representing if the class is an interface or not.
- */
- public boolean isInterface() {
- return (accessFlags & JAccessFlags.ACC_INTERFACE) != 0;
- }
-
- public void addField(JField field) {
- assert !frozen;
- fields.add(field);
- }
-
- /**
- * Create and add a new field to the class.
- */
- public JField addNewField(int accessFlags, String name, JType type) {
- assert !frozen;
- JField f = context.JField(this, accessFlags, name, type);
- addField(f);
- return f;
- }
-
- protected void addMethod(JMethod method) {
- assert !frozen;
- methods.add(method);
- }
-
- /**
- * Create and add a new method to the class.
- */
- public JMethod addNewMethod(int accessFlags,
- String name,
- JType returnType,
- JType[] argTypes,
- String[] argNames) {
- assert !frozen;
- JMethod m = context.JMethod(this,
- accessFlags,
- name,
- returnType,
- argTypes,
- argNames);
- addMethod(m);
- return m;
- }
-
- /**
- * Remove a previously-added method. This makes no attempt at
- * minimising the constant pool by removing all constants which
- * were used only by this method.
- */
- public void removeMethod(JMethod m) {
- assert !frozen;
- methods.remove(m);
- }
-
- public JField[] getFields() {
- return (JField[])fields.toArray(new JField[fields.size()]);
- }
-
- public JMethod[] getMethods() {
- return (JMethod[])methods.toArray(new JMethod[methods.size()]);
- }
-
- /**
- * Freeze the contents of this class so that it can be written to
- * a file.
- */
- public void freeze() {
- assert !frozen;
- frozen = true;
- }
-
- /**
- * Writes the contents of the class to a file referenced by its name.
- * @param fileName The name of the file in which the class must be written.
- */
- public void writeTo(String fileName) throws IOException {
- writeTo(new File(fileName));
- }
-
- /**
- * Writes the contents of the class to a file.
- * @param file The file in which the class must be written.
- */
- public void writeTo(File file) throws IOException {
- File parent = file.getParentFile();
- if (parent != null && !parent.isDirectory())
- if (!parent.mkdirs())
- throw new IOException("cannot create directory " + parent);
-
- FileOutputStream fStream = new FileOutputStream(file);
- BufferedOutputStream bStream = new BufferedOutputStream(fStream);
- DataOutputStream dStream = new DataOutputStream(bStream);
- writeTo(dStream);
- dStream.close();
- bStream.close();
- fStream.close();
- }
-
- /**
- * Writes the contents of the class to a data stream.
- * @param stream The data stream in which the class must be written.
- */
- public void writeTo(DataOutputStream stream) throws IOException {
- if (!frozen) freeze();
-
- int thisClassIdx = pool.addClass(name);
- int superClassIdx = pool.addClass(superclassName);
- int[] interfacesIdx = new int[interfaceNames.length];
-
- for (int i = 0; i < interfaceNames.length; ++i)
- interfacesIdx[i] = pool.addClass(interfaceNames[i]);
-
- pool.freeze();
-
- // Magic number.
- stream.writeInt(MAGIC_NUMBER);
- // Version
- stream.writeShort(minor);
- stream.writeShort(major);
- // Constant pool
- pool.writeTo(stream);
- // Access flags
- stream.writeShort(accessFlags);
-
- // This class, super class and interfaces
- stream.writeShort(thisClassIdx);
- stream.writeShort(superClassIdx);
- stream.writeShort(interfacesIdx.length);
- for (int i = 0; i < interfacesIdx.length; ++i)
- stream.writeShort(interfacesIdx[i]);
-
- // Fields and methods
- stream.writeShort(fields.size());
- Iterator fieldsIt = fields.iterator();
- while (fieldsIt.hasNext())
- ((JField)fieldsIt.next()).writeTo(stream);
-
- stream.writeShort(methods.size());
- Iterator methodsIt = methods.iterator();
- while (methodsIt.hasNext())
- ((JMethod)methodsIt.next()).writeTo(stream);
-
- // Attributes
- JAttribute.writeTo(attributes, stream);
- }
-
- // Follows javap output format for ClassFile.
- /*@Override*/ public String toString() {
- StringBuffer buf = new StringBuffer();
- if (sourceFileName != null) {
- buf.append("Compiled from \"");
- buf.append(sourceFileName);
- buf.append("\"\n");
- }
- buf.append(getMemberName());
- buf.append(toExternalName(getName()));
- if (!isInterface()) {
- buf.append(" extends ");
- buf.append(toExternalName(getSuperclassName()));
- }
- if (interfaceNames.length > 0) {
- if (isInterface()) buf.append(" extends ");
- else buf.append(" implements ");
- for (int i = 0; i < interfaceNames.length; ++i) {
- if (i > 0) buf.append(",");
- buf.append(toExternalName(interfaceNames[i]));
- }
- }
- buf.append("\n");
- Iterator attrsIt = attributes.iterator();
- while (attrsIt.hasNext()) {
- JAttribute attr = (JAttribute)attrsIt.next();
- buf.append(attr);
- }
- buf.append(" minor version: ");
- buf.append(minor);
- buf.append("\n major version: ");
- buf.append(major);
- buf.append("\n");
- buf.append(pool);
- buf.append("\n{\n");
- JField[] jfields = getFields();
- for (int i = 0; i < jfields.length; ++i) {
- if (i > 0) buf.append("\n");
- buf.append(jfields[i]);
- }
- buf.append("\n");
- JMethod[] jmethods = getMethods();
- for (int i = 0; i < jmethods.length; ++i) {
- if (i > 0) buf.append("\n");
- buf.append(jmethods[i]);
- }
- buf.append("\n}\n");
- return buf.toString();
- }
-
- private String getMemberName() {
- StringBuffer buf = new StringBuffer();
- if (isPublic()) buf.append("public ");
- else if (isProtected()) buf.append("protected ");
- else if (isPrivate()) buf.append("private ");
- if (isInterface())
- buf.append("interface ");
- else {
- if (isAbstract()) buf.append("abstract ");
- else if (isFinal()) buf.append("final ");
- buf.append("class ");
- }
- return buf.toString();
- }
-}
diff --git a/src/fjbg/ch/epfl/lamp/fjbg/JCode.java b/src/fjbg/ch/epfl/lamp/fjbg/JCode.java
deleted file mode 100644
index ab6934ab30..0000000000
--- a/src/fjbg/ch/epfl/lamp/fjbg/JCode.java
+++ /dev/null
@@ -1,1308 +0,0 @@
-/* FJBG -- Fast Java Bytecode Generator
- * Copyright 2002-2013 LAMP/EPFL
- * @author Michel Schinz
- */
-
-package ch.epfl.lamp.fjbg;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.*;
-
-import ch.epfl.lamp.util.ByteArray;
-
-/**
- * List of instructions, to which Java byte-code instructions can be added.
- *
- * @author Michel Schinz, Thomas Friedli
- * @version 1.0
- */
-
-public class JCode {
- protected boolean frozen = false;
-
- public static int MAX_CODE_SIZE = 65535;
-
- protected final FJBGContext context;
- protected final JMethod owner;
-
- protected final ByteArray codeArray;
-
- protected final LinkedList/*<ExceptionHandler>*/ exceptionHandlers =
- new LinkedList();
-
- protected final JConstantPool pool;
-
- protected final ArrayList/*<OffsetToPatch>*/ offsetToPatch =
- new ArrayList();
-
- protected static int UNKNOWN_STACK_SIZE = Integer.MIN_VALUE;
- protected int maxStackSize = UNKNOWN_STACK_SIZE;
- protected int[] stackProduction = null;
- protected int[] stackSizes;
-
- protected JCode(FJBGContext context, JClass clazz, JMethod owner) {
- this.context = context;
- this.pool = clazz.getConstantPool();
- this.owner = owner;
- this.codeArray = new ByteArray();
- }
-
- protected JCode(FJBGContext context,
- JClass clazz,
- JMethod owner,
- DataInputStream stream)
- throws IOException {
- this.context = context;
- this.pool = clazz.getConstantPool();
- this.owner = owner;
- owner.setCode(this);
- int size = stream.readInt();
- if (size > MAX_CODE_SIZE) // section 4.10
- throw new Error("code size must be less than " + MAX_CODE_SIZE + ": " + size);
- this.codeArray = new ByteArray(stream, size);
- }
-
- /**
- * Gets the program counter, which is defined as the address of the
- * next instruction.
- * @return The int representing the value of the program counter
- */
- public int getPC() {
- return codeArray.getSize();
- }
-
- /**
- * Gets the size of the code
- * @return The number of bytes of the code
- */
- public int getSize() {
- return codeArray.getSize();
- }
-
- /**
- * Gets the method to which the code belongs
- * @return The method to which the code belongs
- */
- public JMethod getOwner() {
- return owner;
- }
-
- // Stack size
- public int getMaxStackSize() {
- if (maxStackSize == UNKNOWN_STACK_SIZE)
- maxStackSize = computeMaxStackSize();
- return maxStackSize;
- }
-
- // Freezing
- //////////////////////////////////////////////////////////////////////
-
- public static class CodeSizeTooBigException extends OffsetTooBigException {
- public int codeSize;
-
- public CodeSizeTooBigException(int size) {
- codeSize = size;
- }
- }
-
- public void freeze() throws OffsetTooBigException {
- assert !frozen;
-
- if (getSize() > MAX_CODE_SIZE) throw new CodeSizeTooBigException(getSize());
-
- patchAllOffset();
- codeArray.freeze();
- frozen = true;
- }
-
- // Attributes
- //////////////////////////////////////////////////////////////////////
-
- protected final LinkedList/*<JAttribute>*/ attributes = new LinkedList();
-
- public void addAttribute(JAttribute attr) {
- attributes.add(attr);
- }
-
- public List/*<JAttribute>*/ getAttributes() {
- return attributes;
- }
-
- // Emitting code
- //////////////////////////////////////////////////////////////////////
-
- public void emit(JOpcode opcode) {
- setStackProduction(getPC(), opcode);
- codeArray.addU1(opcode.code);
- }
-
- public void emitNOP() { emit(JOpcode.NOP); }
-
- // Constant loading.
- public void emitACONST_NULL() { emit(JOpcode.ACONST_NULL); }
- public void emitICONST_M1() { emit(JOpcode.ICONST_M1); }
- public void emitICONST_0() { emit(JOpcode.ICONST_0); }
- public void emitICONST_1() { emit(JOpcode.ICONST_1); }
- public void emitICONST_2() { emit(JOpcode.ICONST_2); }
- public void emitICONST_3() { emit(JOpcode.ICONST_3); }
- public void emitICONST_4() { emit(JOpcode.ICONST_4); }
- public void emitICONST_5() { emit(JOpcode.ICONST_5); }
- public void emitLCONST_0() { emit(JOpcode.LCONST_0); }
- public void emitLCONST_1() { emit(JOpcode.LCONST_1); }
- public void emitFCONST_0() { emit(JOpcode.FCONST_0); }
- public void emitFCONST_1() { emit(JOpcode.FCONST_1); }
- public void emitFCONST_2() { emit(JOpcode.FCONST_2); }
- public void emitDCONST_0() { emit(JOpcode.DCONST_0); }
- public void emitDCONST_1() { emit(JOpcode.DCONST_1); }
-
- public void emitBIPUSH(int b) { emitU1(JOpcode.BIPUSH, b); }
- public void emitSIPUSH(int s) { emitU2(JOpcode.SIPUSH, s); }
- public void emitLDC(int value) {
- emitU1(JOpcode.LDC, pool.addInteger(value));
- }
- public void emitLDC(float value) {
- emitU1(JOpcode.LDC, pool.addFloat(value));
- }
- public void emitLDC(String value) {
- emitU1(JOpcode.LDC, pool.addString(value));
- }
- public void emitLDC_W(int value) {
- emitU1(JOpcode.LDC_W, pool.addInteger(value));
- }
- public void emitLDC_W(float value) {
- emitU1(JOpcode.LDC_W, pool.addFloat(value));
- }
- public void emitLDC_W(String value) {
- emitU1(JOpcode.LDC_W, pool.addString(value));
- }
- public void emitLDC2_W(long value) {
- emitU2(JOpcode.LDC2_W, pool.addLong(value));
- }
- public void emitLDC2_W(double value) {
- emitU2(JOpcode.LDC2_W, pool.addDouble(value));
- }
-
- // Loading variables.
- public void emitILOAD(int index) { emitU1(JOpcode.ILOAD, index); }
- public void emitLLOAD(int index) { emitU1(JOpcode.LLOAD, index); }
- public void emitFLOAD(int index) { emitU1(JOpcode.FLOAD, index); }
- public void emitDLOAD(int index) { emitU1(JOpcode.DLOAD, index); }
- public void emitALOAD(int index) { emitU1(JOpcode.ALOAD, index); }
-
- public void emitILOAD_0() { emit(JOpcode.ILOAD_0); }
- public void emitILOAD_1() { emit(JOpcode.ILOAD_1); }
- public void emitILOAD_2() { emit(JOpcode.ILOAD_2); }
- public void emitILOAD_3() { emit(JOpcode.ILOAD_3); }
- public void emitLLOAD_0() { emit(JOpcode.LLOAD_0); }
- public void emitLLOAD_1() { emit(JOpcode.LLOAD_1); }
- public void emitLLOAD_2() { emit(JOpcode.LLOAD_2); }
- public void emitLLOAD_3() { emit(JOpcode.LLOAD_3); }
- public void emitFLOAD_0() { emit(JOpcode.FLOAD_0); }
- public void emitFLOAD_1() { emit(JOpcode.FLOAD_1); }
- public void emitFLOAD_2() { emit(JOpcode.FLOAD_2); }
- public void emitFLOAD_3() { emit(JOpcode.FLOAD_3); }
- public void emitDLOAD_0() { emit(JOpcode.DLOAD_0); }
- public void emitDLOAD_1() { emit(JOpcode.DLOAD_1); }
- public void emitDLOAD_2() { emit(JOpcode.DLOAD_2); }
- public void emitDLOAD_3() { emit(JOpcode.DLOAD_3); }
- public void emitALOAD_0() { emit(JOpcode.ALOAD_0); }
- public void emitALOAD_1() { emit(JOpcode.ALOAD_1); }
- public void emitALOAD_2() { emit(JOpcode.ALOAD_2); }
- public void emitALOAD_3() { emit(JOpcode.ALOAD_3); }
-
- public void emitIALOAD() { emit(JOpcode.IALOAD); }
- public void emitLALOAD() { emit(JOpcode.LALOAD); }
- public void emitFALOAD() { emit(JOpcode.FALOAD); }
- public void emitDALOAD() { emit(JOpcode.DALOAD); }
- public void emitAALOAD() { emit(JOpcode.AALOAD); }
- public void emitBALOAD() { emit(JOpcode.BALOAD); }
- public void emitCALOAD() { emit(JOpcode.CALOAD); }
- public void emitSALOAD() { emit(JOpcode.SALOAD); }
-
- // Storing variables.
- public void emitISTORE(int index) { emitU1(JOpcode.ISTORE, index); }
- public void emitLSTORE(int index) { emitU1(JOpcode.LSTORE, index); }
- public void emitFSTORE(int index) { emitU1(JOpcode.FSTORE, index); }
- public void emitDSTORE(int index) { emitU1(JOpcode.DSTORE, index); }
- public void emitASTORE(int index) { emitU1(JOpcode.ASTORE, index); }
-
- public void emitISTORE_0() { emit(JOpcode.ISTORE_0); }
- public void emitISTORE_1() { emit(JOpcode.ISTORE_1); }
- public void emitISTORE_2() { emit(JOpcode.ISTORE_2); }
- public void emitISTORE_3() { emit(JOpcode.ISTORE_3); }
- public void emitLSTORE_0() { emit(JOpcode.LSTORE_0); }
- public void emitLSTORE_1() { emit(JOpcode.LSTORE_1); }
- public void emitLSTORE_2() { emit(JOpcode.LSTORE_2); }
- public void emitLSTORE_3() { emit(JOpcode.LSTORE_3); }
- public void emitFSTORE_0() { emit(JOpcode.FSTORE_0); }
- public void emitFSTORE_1() { emit(JOpcode.FSTORE_1); }
- public void emitFSTORE_2() { emit(JOpcode.FSTORE_2); }
- public void emitFSTORE_3() { emit(JOpcode.FSTORE_3); }
- public void emitDSTORE_0() { emit(JOpcode.DSTORE_0); }
- public void emitDSTORE_1() { emit(JOpcode.DSTORE_1); }
- public void emitDSTORE_2() { emit(JOpcode.DSTORE_2); }
- public void emitDSTORE_3() { emit(JOpcode.DSTORE_3); }
- public void emitASTORE_0() { emit(JOpcode.ASTORE_0); }
- public void emitASTORE_1() { emit(JOpcode.ASTORE_1); }
- public void emitASTORE_2() { emit(JOpcode.ASTORE_2); }
- public void emitASTORE_3() { emit(JOpcode.ASTORE_3); }
-
- public void emitIASTORE() { emit(JOpcode.IASTORE); }
- public void emitLASTORE() { emit(JOpcode.LASTORE); }
- public void emitFASTORE() { emit(JOpcode.FASTORE); }
- public void emitDASTORE() { emit(JOpcode.DASTORE); }
- public void emitAASTORE() { emit(JOpcode.AASTORE); }
- public void emitBASTORE() { emit(JOpcode.BASTORE); }
- public void emitCASTORE() { emit(JOpcode.CASTORE); }
- public void emitSASTORE() { emit(JOpcode.SASTORE); }
-
- // Stack manipulation.
- public void emitPOP() { emit(JOpcode.POP); }
- public void emitPOP2() { emit(JOpcode.POP2); }
- public void emitDUP() { emit(JOpcode.DUP); }
- public void emitDUP_X1() { emit(JOpcode.DUP_X1); }
- public void emitDUP_X2() { emit(JOpcode.DUP_X2); }
- public void emitDUP2() { emit(JOpcode.DUP2); }
- public void emitDUP2_X1() { emit(JOpcode.DUP2_X1); }
- public void emitDUP2_X2() { emit(JOpcode.DUP2_X2); }
- public void emitSWAP() { emit(JOpcode.SWAP); }
-
- // Artithmetic and logic operations.
- public void emitIADD() { emit(JOpcode.IADD); }
- public void emitLADD() { emit(JOpcode.LADD); }
- public void emitFADD() { emit(JOpcode.FADD); }
- public void emitDADD() { emit(JOpcode.DADD); }
-
- public void emitISUB() { emit(JOpcode.ISUB); }
- public void emitLSUB() { emit(JOpcode.LSUB); }
- public void emitFSUB() { emit(JOpcode.FSUB); }
- public void emitDSUB() { emit(JOpcode.DSUB); }
-
- public void emitIMUL() { emit(JOpcode.IMUL); }
- public void emitLMUL() { emit(JOpcode.LMUL); }
- public void emitFMUL() { emit(JOpcode.FMUL); }
- public void emitDMUL() { emit(JOpcode.DMUL); }
-
- public void emitIDIV() { emit(JOpcode.IDIV); }
- public void emitLDIV() { emit(JOpcode.LDIV); }
- public void emitFDIV() { emit(JOpcode.FDIV); }
- public void emitDDIV() { emit(JOpcode.DDIV); }
-
- public void emitIREM() { emit(JOpcode.IREM); }
- public void emitLREM() { emit(JOpcode.LREM); }
- public void emitFREM() { emit(JOpcode.FREM); }
- public void emitDREM() { emit(JOpcode.DREM); }
-
- public void emitINEG() { emit(JOpcode.INEG); }
- public void emitLNEG() { emit(JOpcode.LNEG); }
- public void emitFNEG() { emit(JOpcode.FNEG); }
- public void emitDNEG() { emit(JOpcode.DNEG); }
-
- public void emitISHL() { emit(JOpcode.ISHL); }
- public void emitLSHL() { emit(JOpcode.LSHL); }
-
- public void emitISHR() { emit(JOpcode.ISHR); }
- public void emitLSHR() { emit(JOpcode.LSHR); }
-
- public void emitIUSHR() { emit(JOpcode.IUSHR); }
- public void emitLUSHR() { emit(JOpcode.LUSHR); }
-
- public void emitIAND() { emit(JOpcode.IAND); }
- public void emitLAND() { emit(JOpcode.LAND); }
-
- public void emitIOR() { emit(JOpcode.IOR); }
- public void emitLOR() { emit(JOpcode.LOR); }
-
- public void emitIXOR() { emit(JOpcode.IXOR); }
- public void emitLXOR() { emit(JOpcode.LXOR); }
-
- public void emitIINC(int index, int increment) {
- emitU1U1(JOpcode.IINC, index, increment);
- }
-
- // (Numeric) type conversions.
- public void emitI2L() { emit(JOpcode.I2L); }
- public void emitI2F() { emit(JOpcode.I2F); }
- public void emitI2D() { emit(JOpcode.I2D); }
- public void emitL2I() { emit(JOpcode.L2I); }
- public void emitL2F() { emit(JOpcode.L2F); }
- public void emitL2D() { emit(JOpcode.L2D); }
- public void emitF2I() { emit(JOpcode.F2I); }
- public void emitF2L() { emit(JOpcode.F2L); }
- public void emitF2D() { emit(JOpcode.F2D); }
- public void emitD2I() { emit(JOpcode.D2I); }
- public void emitD2L() { emit(JOpcode.D2L); }
- public void emitD2F() { emit(JOpcode.D2F); }
- public void emitI2B() { emit(JOpcode.I2B); }
- public void emitI2C() { emit(JOpcode.I2C); }
- public void emitI2S() { emit(JOpcode.I2S); }
-
- // Comparisons and tests.
- public void emitLCMP() { emit(JOpcode.LCMP); }
- public void emitFCMPL() { emit(JOpcode.FCMPL); }
- public void emitFCMPG() { emit(JOpcode.FCMPG); }
- public void emitDCMPL() { emit(JOpcode.DCMPL); }
- public void emitDCMPG() { emit(JOpcode.DCMPG); }
-
- protected void emitGenericIF(JOpcode opcode, Label label)
- throws OffsetTooBigException {
- emitU2(opcode, label.getOffset16(getPC() + 1, getPC()));
- }
-
- public void emitIFEQ(Label label) throws OffsetTooBigException {
- emitGenericIF(JOpcode.IFEQ, label);
- }
- public void emitIFEQ(int targetPC) throws OffsetTooBigException {
- emitU2(JOpcode.IFEQ, targetPC - getPC());
- }
- public void emitIFEQ() {
- emitU2(JOpcode.IFEQ, 0);
- }
-
- public void emitIFNE(Label label) throws OffsetTooBigException {
- emitGenericIF(JOpcode.IFNE, label);
- }
- public void emitIFNE(int targetPC) throws OffsetTooBigException {
- emitU2(JOpcode.IFNE, targetPC - getPC());
- }
- public void emitIFNE() {
- emitU2(JOpcode.IFNE, 0);
- }
-
- public void emitIFLT(Label label) throws OffsetTooBigException {
- emitGenericIF(JOpcode.IFLT, label);
- }
- public void emitIFLT(int targetPC) throws OffsetTooBigException {
- emitU2(JOpcode.IFLT, targetPC - getPC());
- }
- public void emitIFLT() {
- emitU2(JOpcode.IFLT, 0);
- }
-
- public void emitIFGE(Label label) throws OffsetTooBigException {
- emitGenericIF(JOpcode.IFGE, label);
- }
- public void emitIFGE(int targetPC) throws OffsetTooBigException {
- emitU2(JOpcode.IFGE, targetPC - getPC());
- }
- public void emitIFGE() {
- emitU2(JOpcode.IFGE, 0);
- }
-
- public void emitIFGT(Label label) throws OffsetTooBigException {
- emitGenericIF(JOpcode.IFGT, label);
- }
- public void emitIFGT(int targetPC) throws OffsetTooBigException {
- emitU2(JOpcode.IFGT, targetPC - getPC());
- }
- public void emitIFGT() {
- emitU2(JOpcode.IFGT, 0);
- }
-
- public void emitIFLE(Label label) throws OffsetTooBigException {
- emitGenericIF(JOpcode.IFLE, label);
- }
- public void emitIFLE(int targetPC) throws OffsetTooBigException {
- emitU2(JOpcode.IFLE, targetPC - getPC());
- }
- public void emitIFLE() {
- emitU2(JOpcode.IFLE, 0);
- }
-
- public void emitIF_ICMPEQ(Label label) throws OffsetTooBigException {
- emitGenericIF(JOpcode.IF_ICMPEQ, label);
- }
- public void emitIF_ICMPEQ(int targetPC) throws OffsetTooBigException {
- emitU2(JOpcode.IF_ICMPEQ, targetPC - getPC());
- }
- public void emitIF_ICMPEQ() {
- emitU2(JOpcode.IF_ICMPEQ, 0);
- }
-
- public void emitIF_ICMPNE(Label label) throws OffsetTooBigException {
- emitGenericIF(JOpcode.IF_ICMPNE, label);
- }
- public void emitIF_ICMPNE(int targetPC) throws OffsetTooBigException {
- emitU2(JOpcode.IF_ICMPNE, targetPC - getPC());
- }
- public void emitIF_ICMPNE() {
- emitU2(JOpcode.IF_ICMPNE, 0);
- }
-
- public void emitIF_ICMPLT(Label label) throws OffsetTooBigException {
- emitGenericIF(JOpcode.IF_ICMPLT, label);
- }
- public void emitIF_ICMPLT(int targetPC) throws OffsetTooBigException {
- emitU2(JOpcode.IF_ICMPLT, targetPC - getPC());
- }
- public void emitIF_ICMPLT() {
- emitU2(JOpcode.IF_ICMPLT, 0);
- }
-
- public void emitIF_ICMPGE(Label label) throws OffsetTooBigException {
- emitGenericIF(JOpcode.IF_ICMPGE, label);
- }
- public void emitIF_ICMPGE(int targetPC) throws OffsetTooBigException {
- emitU2(JOpcode.IF_ICMPGE, targetPC - getPC());
- }
- public void emitIF_ICMPGE() {
- emitU2(JOpcode.IF_ICMPGE, 0);
- }
-
- public void emitIF_ICMPGT(Label label) throws OffsetTooBigException {
- emitGenericIF(JOpcode.IF_ICMPGT, label);
- }
- public void emitIF_ICMPGT(int targetPC) throws OffsetTooBigException {
- emitU2(JOpcode.IF_ICMPGT, targetPC - getPC());
- }
- public void emitIF_ICMPGT() {
- emitU2(JOpcode.IF_ICMPGT, 0);
- }
-
- public void emitIF_ICMPLE(Label label) throws OffsetTooBigException {
- emitGenericIF(JOpcode.IF_ICMPLE, label);
- }
- public void emitIF_ICMPLE(int targetPC) throws OffsetTooBigException {
- emitU2(JOpcode.IF_ICMPLE, targetPC - getPC());
- }
- public void emitIF_ICMPLE() {
- emitU2(JOpcode.IF_ICMPLE, 0);
- }
-
- public void emitIF_ACMPEQ(Label label) throws OffsetTooBigException {
- emitGenericIF(JOpcode.IF_ACMPEQ, label);
- }
- public void emitIF_ACMPEQ(int targetPC) throws OffsetTooBigException {
- emitU2(JOpcode.IF_ACMPEQ, targetPC - getPC());
- }
- public void emitIF_ACMPEQ() {
- emitU2(JOpcode.IF_ACMPEQ, 0);
- }
-
- public void emitIF_ACMPNE(Label label) throws OffsetTooBigException {
- emitGenericIF(JOpcode.IF_ACMPNE, label);
- }
- public void emitIF_ACMPNE(int targetPC) throws OffsetTooBigException {
- emitU2(JOpcode.IF_ACMPNE, targetPC - getPC());
- }
- public void emitIF_ACMPNE() {
- emitU2(JOpcode.IF_ACMPNE, 0);
- }
-
- public void emitIFNULL(Label label) throws OffsetTooBigException {
- emitGenericIF(JOpcode.IFNULL, label);
- }
- public void emitIFNULL(int targetPC) throws OffsetTooBigException {
- emitU2(JOpcode.IFNULL, targetPC - getPC());
- }
- public void emitIFNULL() {
- emitU2(JOpcode.IFNULL, 0);
- }
-
- public void emitIFNONNULL(Label label) throws OffsetTooBigException {
- emitGenericIF(JOpcode.IFNONNULL, label);
- }
- public void emitIFNONNULL(int targetPC) throws OffsetTooBigException {
- emitU2(JOpcode.IFNONNULL, targetPC - getPC());
- }
- public void emitIFNONNULL() {
- emitU2(JOpcode.IFNONNULL, 0);
- }
-
- public void emitGOTO(Label label) throws OffsetTooBigException {
- emitU2(JOpcode.GOTO, label.getOffset16(getPC() + 1, getPC()));
- }
- public void emitGOTO(int targetPC) throws OffsetTooBigException {
- int offset = targetPC - getPC();
- checkOffset16(offset);
- emitU2(JOpcode.GOTO, offset);
- }
- public void emitGOTO() {
- emitU2(JOpcode.GOTO, 0);
- }
-
- public void emitGOTO_W(Label label) {
- emitU4(JOpcode.GOTO_W, label.getOffset32(getPC() + 1, getPC()));
- }
- public void emitGOTO_W(int targetPC) {
- emitU4(JOpcode.GOTO_W, targetPC - getPC());
- }
- public void emitGOTO_W() {
- emitU4(JOpcode.GOTO_W, 0);
- }
-
- public void emitJSR(Label label) throws OffsetTooBigException {
- emitU2(JOpcode.JSR, label.getOffset16(getPC() + 1, getPC()));
- }
- public void emitJSR(int targetPC) {
- emitU2(JOpcode.JSR, targetPC - getPC());
- }
- public void emitJSR() {
- emitU2(JOpcode.JSR, 0);
- }
-
- public void emitJSR_W(Label label) {
- emitU4(JOpcode.JSR_W, label.getOffset32(getPC() + 1, getPC()));
- }
- public void emitJSR_W(int targetPC) {
- emitU4(JOpcode.JSR_W, targetPC - getPC());
- }
- public void emitJSR_W() {
- emitU4(JOpcode.JSR_W, 0);
- }
-
- /*
- public void emitRET(Label label) throws OffsetTooBigException {
- emitU2(JOpcode.RET, label.getOffset16(getPC() + 1, getPC()));
- }
- public void emitRET(int targetPC) {
- emitU1(JOpcode.RET, targetPC);
- }
- public void emitRET() {
- emitU1(JOpcode.RET, 0);
- }
- */
-
- public void emitRET(int index) {
- emitU1(JOpcode.RET, index);
- }
-
- public void emitRET(JLocalVariable var) {
- emitRET(var.getIndex());
- }
-
- public void emitTABLESWITCH(int[] keys,
- Label[] branches,
- Label defaultBranch) {
- assert keys.length == branches.length;
-
- int low = keys[0], high = keys[keys.length - 1];
- int instrPC = getPC();
-
- setStackProduction(instrPC, JOpcode.TABLESWITCH);
- codeArray.addU1(JOpcode.cTABLESWITCH);
- while (getPC() % 4 != 0) codeArray.addU1(0);
-
- codeArray.addU4(defaultBranch.getOffset32(getPC(), instrPC));
- codeArray.addU4(low);
- codeArray.addU4(high);
- for (int i = 0; i < branches.length; i++) {
- assert keys[i] == low + i;
- codeArray.addU4(branches[i].getOffset32(getPC(), instrPC));
- }
- }
-
- public void emitLOOKUPSWITCH(int[] keys,
- Label[] branches,
- Label defaultBranch) {
- assert keys.length == branches.length;
-
- int instrPC = getPC();
- setStackProduction(getPC(), JOpcode.LOOKUPSWITCH);
- codeArray.addU1(JOpcode.cLOOKUPSWITCH);
- while (getPC() % 4 != 0) codeArray.addU1(0);
-
- codeArray.addU4(defaultBranch.getOffset32(getPC(), instrPC));
- codeArray.addU4(branches.length);
- for (int i = 0; i < branches.length; i++) {
- codeArray.addU4(keys[i]);
- codeArray.addU4(branches[i].getOffset32(getPC(), instrPC));
- }
- }
-
- public void emitIRETURN() { emit(JOpcode.IRETURN); }
- public void emitLRETURN() { emit(JOpcode.LRETURN); }
- public void emitFRETURN() { emit(JOpcode.FRETURN); }
- public void emitDRETURN() { emit(JOpcode.DRETURN); }
- public void emitARETURN() { emit(JOpcode.ARETURN); }
- public void emitRETURN() { emit(JOpcode.RETURN); }
-
- // Field access
- public void emitGETSTATIC(String className, String name, JType type) {
- setStackProduction(getPC(), type.getSize());
- int index = pool.addFieldRef(className, name, type.getSignature());
- emitU2(JOpcode.GETSTATIC, index);
- }
- public void emitPUTSTATIC(String className, String name, JType type) {
- setStackProduction(getPC(), -type.getSize());
- int index = pool.addFieldRef(className, name, type.getSignature());
- emitU2(JOpcode.PUTSTATIC, index);
- }
- public void emitGETFIELD(String className, String name, JType type) {
- setStackProduction(getPC(), type.getSize() - 1);
- int index = pool.addFieldRef(className, name, type.getSignature());
- emitU2(JOpcode.GETFIELD, index);
- }
- public void emitPUTFIELD(String className, String name, JType type) {
- setStackProduction(getPC(), -(type.getSize() + 1));
- int index = pool.addFieldRef(className, name, type.getSignature());
- emitU2(JOpcode.PUTFIELD, index);
- }
-
- // Method invocation
- public void emitINVOKEVIRTUAL(String className,
- String name,
- JMethodType type) {
- setStackProduction(getPC(), type.getProducedStack() - 1);
- int index =
- pool.addClassMethodRef(className, name, type.getSignature());
- emitU2(JOpcode.INVOKEVIRTUAL, index);
- }
- public void emitINVOKESPECIAL(String className,
- String name,
- JMethodType type) {
- setStackProduction(getPC(), type.getProducedStack() - 1);
- int index =
- pool.addClassMethodRef(className, name, type.getSignature());
- emitU2(JOpcode.INVOKESPECIAL, index);
- }
- public void emitINVOKESTATIC(String className,
- String name,
- JMethodType type) {
- setStackProduction(getPC(), type.getProducedStack());
- int index =
- pool.addClassMethodRef(className, name, type.getSignature());
- emitU2(JOpcode.INVOKESTATIC, index);
- }
- public void emitINVOKEINTERFACE(String className,
- String name,
- JMethodType type) {
- setStackProduction(getPC(), type.getProducedStack() - 1);
- int index =
- pool.addInterfaceMethodRef(className, name, type.getSignature());
- emitU2U1U1(JOpcode.INVOKEINTERFACE, index, type.getArgsSize() + 1, 0);
- }
-
- // Object creation
- public void emitNEW(String className) {
- emitU2(JOpcode.NEW, pool.addClass(className));
- }
- public void emitNEWARRAY(JType elemType) {
- emitU1(JOpcode.NEWARRAY, elemType.getTag());
- }
- public void emitANEWARRAY(JReferenceType elemType) {
- emitU2(JOpcode.ANEWARRAY, pool.addDescriptor(elemType));
- }
- public void emitMULTIANEWARRAY(JReferenceType elemType, int dimensions) {
- setStackProduction(getPC(), -dimensions + 1);
- emitU2U1(JOpcode.MULTIANEWARRAY,
- pool.addDescriptor(elemType),
- dimensions);
- }
- public void emitARRAYLENGTH() { emit(JOpcode.ARRAYLENGTH); }
-
- // Exception throwing
- public void emitATHROW() { emit(JOpcode.ATHROW); }
-
- // Dynamic typing
- public void emitCHECKCAST(JReferenceType type) {
- emitU2(JOpcode.CHECKCAST, pool.addDescriptor(type));
- }
- public void emitINSTANCEOF(JReferenceType type) {
- emitU2(JOpcode.INSTANCEOF, pool.addDescriptor(type));
- }
-
- // Monitors
- public void emitMONITORENTER() { emit(JOpcode.MONITORENTER); }
- public void emitMONITOREXIT() { emit(JOpcode.MONITOREXIT); }
-
- // Wide variants
- // FIXME setStackProd. will here raise an exception
- public void emitWIDE(JOpcode opcode, int index) {
- assert (opcode.code == JOpcode.cILOAD)
- || (opcode.code == JOpcode.cLLOAD)
- || (opcode.code == JOpcode.cFLOAD)
- || (opcode.code == JOpcode.cDLOAD)
- || (opcode.code == JOpcode.cALOAD)
- || (opcode.code == JOpcode.cISTORE)
- || (opcode.code == JOpcode.cLSTORE)
- || (opcode.code == JOpcode.cFSTORE)
- || (opcode.code == JOpcode.cDSTORE)
- || (opcode.code == JOpcode.cASTORE)
- || (opcode.code == JOpcode.cRET)
- : "invalide opcode for WIDE: " + opcode;
-
- setStackProduction(getPC(), opcode);
- codeArray.addU1(JOpcode.WIDE.code);
- codeArray.addU1(opcode.code);
- codeArray.addU2(index);
- }
- public void emitWIDE(JOpcode opcode, int index, int constant) {
- assert opcode.code == JOpcode.cIINC
- : "invalid opcode for WIDE: " + opcode;
-
- setStackProduction(getPC(), opcode);
- codeArray.addU1(JOpcode.cWIDE);
- codeArray.addU1(opcode.code);
- codeArray.addU2(index);
- codeArray.addU2(constant);
- }
-
- protected void emitU1(JOpcode opcode, int i1) {
- setStackProduction(getPC(), opcode);
- codeArray.addU1(opcode.code);
- codeArray.addU1(i1);
- }
-
- protected void emitU1U1(JOpcode opcode, int i1, int i2) {
- setStackProduction(getPC(), opcode);
- codeArray.addU1(opcode.code);
- codeArray.addU1(i1);
- codeArray.addU1(i2);
- }
-
- protected void emitU2(JOpcode opcode, int i1) {
- setStackProduction(getPC(), opcode);
- codeArray.addU1(opcode.code);
- codeArray.addU2(i1);
- }
-
- protected void emitU2U1(JOpcode opcode, int i1, int i2) {
- setStackProduction(getPC(), opcode);
- codeArray.addU1(opcode.code);
- codeArray.addU2(i1);
- codeArray.addU1(i2);
- }
-
- protected void emitU2U1U1(JOpcode opcode, int i1, int i2, int i3) {
- setStackProduction(getPC(), opcode);
- codeArray.addU1(opcode.code);
- codeArray.addU2(i1);
- codeArray.addU1(i2);
- codeArray.addU1(i3);
- }
-
- protected void emitU4(JOpcode opcode, int i1) {
- setStackProduction(getPC(), opcode);
- codeArray.addU1(opcode.code);
- codeArray.addU4(i1);
- }
-
- protected int getU1(int sourcePos) {
- return codeArray.getU1(sourcePos);
- }
-
- protected int getU2(int sourcePos) {
- return codeArray.getU2(sourcePos);
- }
-
- protected int getU4(int sourcePos) {
- return codeArray.getU4(sourcePos);
- }
-
- protected int getS1(int sourcePos) {
- return codeArray.getS1(sourcePos);
- }
-
- protected int getS2(int sourcePos) {
- return codeArray.getS2(sourcePos);
- }
-
- protected int getS4(int sourcePos) {
- return codeArray.getS4(sourcePos);
- }
-
- // Stack size computation
- //////////////////////////////////////////////////////////////////////
-
- protected int getStackProduction(int pc) {
- if (stackProduction == null || pc >= stackProduction.length)
- return UNKNOWN_STACK_SIZE;
- else
- return stackProduction[pc];
- }
-
- protected void setStackProduction(int pc, int production) {
- if (stackProduction == null) {
- stackProduction = new int[256];
- Arrays.fill(stackProduction, UNKNOWN_STACK_SIZE);
- } else {
- while (pc >= stackProduction.length) {
- int[] newStackProduction = new int[stackProduction.length * 2];
- System.arraycopy(stackProduction, 0,
- newStackProduction, 0,
- stackProduction.length);
- Arrays.fill(newStackProduction,
- stackProduction.length,
- newStackProduction.length,
- UNKNOWN_STACK_SIZE);
- stackProduction = newStackProduction;
- }
- }
- stackProduction[pc] = production;
- }
-
- protected void setStackProduction(int pc, JOpcode opcode) {
- // TODO we should instead check whether the opcode has known
- // stack consumption/production.
- if (getStackProduction(pc) == UNKNOWN_STACK_SIZE)
-// && opcode.hasKnownProducedDataSize()
-// && opcode.hasKnownConsumedDataSize())
- setStackProduction(pc,
- opcode.getProducedDataSize()
- - opcode.getConsumedDataSize());
- }
-
- protected int computeMaxStackSize() {
- if (stackSizes == null) {
- stackSizes = new int[getSize()];
- Arrays.fill(stackSizes, UNKNOWN_STACK_SIZE);
- stackSizes[0] = 0;
- }
- int size = computeMaxStackSize(0, 0, 0);
-
- // compute stack sizes for exception handlers too
- ExceptionHandler exh = null;
- for (Iterator it = exceptionHandlers.iterator();
- it.hasNext();) {
- exh = (ExceptionHandler)it.next();
- int exhSize = computeMaxStackSize(exh.getHandlerPC(), 1, 1);
- if (size < exhSize)
- size = exhSize;
- }
-
- return size;
- }
-
- protected int computeMaxStackSize(int pc, int stackSize, int maxStackSize) {
- JCodeIterator iterator = new JCodeIterator(this, pc);
- for (;;) {
- int successors = iterator.getSuccessorCount();
- if (successors == 0)
- return maxStackSize;
- else {
- assert stackProduction[iterator.getPC()] != UNKNOWN_STACK_SIZE
- : "unknown stack production, pc=" + iterator.getPC()
- + " in method " + owner.getName();
- stackSize += stackProduction[iterator.getPC()];
- if (stackSize > maxStackSize)
- maxStackSize = stackSize;
- int nextPC = -1;
- for (int i = 0; i < successors; ++i) {
- int succPC = iterator.getSuccessorPC(i);
- assert succPC >= 0 && succPC < stackSizes.length
- : iterator.getPC() + ": invalid pc: " + succPC
- + " op: " + iterator.getOpcode();
- if (stackSizes[succPC] == UNKNOWN_STACK_SIZE) {
- stackSizes[succPC] = stackSize;
- if (nextPC == -1)
- nextPC = succPC;
- else
- maxStackSize = computeMaxStackSize(succPC,
- stackSize,
- maxStackSize);
- }
- }
- if (nextPC == -1)
- return maxStackSize;
- else
- iterator.moveTo(nextPC);
- }
- }
- }
-
- // Labels
- //////////////////////////////////////////////////////////////////////
-
- public static class OffsetTooBigException extends Exception {
- public OffsetTooBigException() { super(); }
- public OffsetTooBigException(String message) { super(message); }
- }
-
- protected void checkOffset16(int offset) throws OffsetTooBigException {
- if (offset < Short.MIN_VALUE || offset > Short.MAX_VALUE)
- throw new OffsetTooBigException("offset too big to fit"
- + " in 16 bits: " + offset);
- }
-
- public class Label {
- protected boolean anchored = false;
- protected int targetPC = 0;
-
- public void anchorToNext() {
- assert !anchored;
- this.targetPC = getPC();
- anchored = true;
- }
-
- public int getAnchor() {
- assert anchored;
- return targetPC;
- }
-
- protected int getOffset16(int pc, int instrPC)
- throws OffsetTooBigException {
- if (anchored) {
- int offset = targetPC - instrPC;
- checkOffset16(offset);
- return offset;
- } else {
- recordOffsetToPatch(pc, 16, instrPC, this);
- return 0;
- }
- }
-
- protected int getOffset32(int pc, int instrPC) {
- if (anchored)
- return targetPC - instrPC;
- else {
- recordOffsetToPatch(pc, 32, instrPC, this);
- return 0;
- }
- }
- }
-
- public Label newLabel() {
- return new Label();
- }
-
- public Label[] newLabels(int count) {
- Label[] labels = new Label[count];
- for (int i = 0; i < labels.length; ++i)
- labels[i] = newLabel();
- return labels;
- }
-
- protected static class OffsetToPatch {
- public final int pc;
- public final int size;
- public final int instrPC;
- public final Label label;
-
- public OffsetToPatch(int pc, int size, int instrPC, Label label) {
- this.pc = pc;
- this.size = size;
- this.instrPC = instrPC;
- this.label = label;
- }
- }
-
- protected void recordOffsetToPatch(int offsetPC,
- int size,
- int instrPC,
- Label label) {
- offsetToPatch.add(new OffsetToPatch(offsetPC, size, instrPC, label));
- }
-
- protected void patchAllOffset() throws OffsetTooBigException {
- Iterator offsetIt = offsetToPatch.iterator();
- while (offsetIt.hasNext()) {
- OffsetToPatch offset = (OffsetToPatch)offsetIt.next();
- int offsetValue = offset.label.getAnchor() - offset.instrPC;
- if (offset.size == 16) {
- checkOffset16(offsetValue);
- codeArray.putU2(offset.pc, offsetValue);
- } else
- codeArray.putU4(offset.pc, offsetValue);
- }
- }
-
- // Exception handling
- //////////////////////////////////////////////////////////////////////
-
- public class ExceptionHandler {
- protected int startPC, endPC, handlerPC;
- protected final String catchType;
- protected final int catchTypeIndex;
-
- public void setStartPC(int pc) {
- this.startPC = pc;
- }
-
- public int getStartPC() {
- return this.startPC;
- }
-
- public void setEndPC(int pc) {
- this.endPC = pc;
- }
-
- public int getEndPC() {
- return this.endPC;
- }
-
- public void setHandlerPC(int pc) {
- this.handlerPC = pc;
- }
-
- public int getHandlerPC() {
- return this.handlerPC;
- }
-
- public ExceptionHandler(String catchType) {
- this(0, 0, 0, catchType);
- }
-
- public ExceptionHandler(int startPC,
- int endPC,
- int handlerPC,
- String catchType) {
- this.startPC = startPC;
- this.endPC = endPC;
- this.handlerPC = handlerPC;
- this.catchType = catchType;
- this.catchTypeIndex = (catchType == null
- ? 0
- : pool.addClass(catchType));
- }
-
- public ExceptionHandler(DataInputStream stream) throws IOException {
- this.startPC = stream.readShort();
- this.endPC = stream.readShort();
- this.handlerPC = stream.readShort();
- this.catchTypeIndex = stream.readShort();
- this.catchType = (catchTypeIndex == 0
- ? null
- : pool.lookupClass(catchTypeIndex));
- }
-
- public void writeTo(DataOutputStream stream) throws IOException {
- stream.writeShort(startPC);
- stream.writeShort(endPC);
- stream.writeShort(handlerPC);
- stream.writeShort(catchTypeIndex);
- }
-
- // Follows javap output format for exception handlers.
- /*@Override*/public String toString() {
- StringBuffer buf = new StringBuffer(" ");
- if (startPC < 10) buf.append(" ");
- buf.append(startPC);
- buf.append(" ");
- if (endPC < 10) buf.append(" ");
- buf.append(endPC);
- buf.append(" ");
- buf.append(handlerPC);
- buf.append(" ");
- if (catchType != null) {
- buf.append("Class ");
- buf.append(catchType);
- }
- else
- buf.append("any");
- return buf.toString();
- }
-
- }
-
- public void addExceptionHandler(ExceptionHandler handler) {
- assert !frozen;
- exceptionHandlers.add(handler);
- }
-
- public void addExceptionHandler(int startPC,
- int endPC,
- int handlerPC,
- String catchType) {
- addExceptionHandler(new ExceptionHandler(startPC,
- endPC,
- handlerPC,
- catchType));
- }
-
- public void addFinallyHandler(int startPC, int endPC, int handlerPC) {
- assert !frozen;
- addExceptionHandler(startPC, endPC, handlerPC, null);
- }
-
- public List/*<ExceptionHandler>*/ getExceptionHandlers() {
- return exceptionHandlers;
- }
-
- // Line numbers
- //////////////////////////////////////////////////////////////////////
-
- protected int[] lineNumbers = null;
- protected void ensureLineNumberCapacity(int endPC) {
- assert !frozen;
- if (lineNumbers == null) {
- lineNumbers = new int[endPC];
- addAttribute(context.JLineNumberTableAttribute(owner.getOwner(),
- this));
- } else if (lineNumbers.length < endPC) {
- int[] newLN = new int[Math.max(endPC, lineNumbers.length * 2)];
- System.arraycopy(lineNumbers, 0, newLN, 0, lineNumbers.length);
- lineNumbers = newLN;
- }
- }
-
- /**
- * Set all line numbers in the interval [startPC, endPC) to
- * line, overwriting existing line numbers.
- */
- public void setLineNumber(int startPC, int endPC, int line) {
- ensureLineNumberCapacity(endPC);
- Arrays.fill(lineNumbers, startPC, endPC, line);
- }
-
- public void setLineNumber(int instrPC, int line) {
- setLineNumber(instrPC, instrPC + 1, line);
- }
-
- /** Sets all non-filled line numbers in the interval [startPC, endPC)
- * to 'line'.
- */
- public void completeLineNumber(int startPC, int endPC, int line) {
- ensureLineNumberCapacity(endPC);
- for (int pc = startPC; pc < endPC; ++pc)
- if (lineNumbers[pc] == 0) lineNumbers[pc] = line;
- }
-
- public int[] getLineNumbers() {
- assert frozen;
- if (lineNumbers == null) return new int[0];
- else if (lineNumbers.length == getPC()) return lineNumbers;
- else {
- int[] trimmedLN = new int[getPC()];
- System.arraycopy(lineNumbers, 0,
- trimmedLN, 0,
- Math.min(lineNumbers.length, trimmedLN.length));
- return trimmedLN;
- }
- }
-
- // Output
- //////////////////////////////////////////////////////////////////////
-
- public void writeTo(DataOutputStream stream) throws IOException {
- assert frozen;
- stream.writeInt(getSize());
- codeArray.writeTo(stream);
- }
-
- // Follows javap output format for opcodes.
- /*@Override*/ public String toString() {
- StringBuffer buf = new StringBuffer();
- JOpcode opcode = null;
- int pc = 0, addr = 0;
- while (pc < codeArray.getSize()) {
- buf.append("\n ");
- buf.append(pc);
- buf.append(":\t");
- opcode = JOpcode.OPCODES[codeArray.getU1(pc)];
- buf.append(decode(opcode, pc));
- if (opcode.code == JOpcode.cTABLESWITCH ||
- opcode.code == JOpcode.cLOOKUPSWITCH) {
- addr = ((pc / 4 + 1) + 1) * 4; // U4 aligned data
- int low = codeArray.getU4(addr);
- int high = codeArray.getU4(addr+4);
- pc = addr + (2/*low+high*/ + (high - low + 1)/*targets*/) * 4;
- } else
- pc += opcode.getSize();
- }
- if (exceptionHandlers.size() > 0) {
- buf.append("\n Exception table:\n from to target type\n");
- Iterator it = exceptionHandlers.iterator();
- while (it.hasNext()) {
- ExceptionHandler exh = (ExceptionHandler)it.next();
- buf.append(exh);
- buf.append("\n");
- }
- }
- return buf.toString();
- }
-
- private String decode(JOpcode opcode, int pc) {
- String ownerClassName = owner.getOwner().getName();
- int data, data2;
- StringBuilder buf = new StringBuilder();
- buf.append(opcode.name.toLowerCase());
- switch (opcode.code) {
- case JOpcode.cALOAD: case JOpcode.cASTORE: case JOpcode.cBIPUSH:
- case JOpcode.cDLOAD: case JOpcode.cDSTORE:
- case JOpcode.cFLOAD: case JOpcode.cFSTORE:
- case JOpcode.cILOAD: case JOpcode.cISTORE:
- case JOpcode.cLLOAD: case JOpcode.cLSTORE:
- data = codeArray.getU1(pc+1);
- buf.append("\t");
- buf.append(data);
- break;
- case JOpcode.cLDC:
- data = codeArray.getU1(pc+1);
- buf.append("\t#");
- buf.append(data);
- buf.append("; ");
- buf.append(pool.lookupEntry(data).toComment(ownerClassName));
- break;
- case JOpcode.cNEWARRAY:
- data = codeArray.getU1(pc+1);
- buf.append(" ");
- buf.append(JType.tagToString(data));
- break;
- case JOpcode.cIINC:
- data = codeArray.getU1(pc+1);
- data2 = codeArray.getU1(pc+2);
- buf.append("\t");
- buf.append(data);
- buf.append(", ");
- buf.append(data2);
- break;
- case JOpcode.cSIPUSH:
- data = codeArray.getU2(pc+1);
- buf.append("\t");
- buf.append(data);
- break;
- case JOpcode.cANEWARRAY: case JOpcode.cCHECKCAST:
- case JOpcode.cGETFIELD: case JOpcode.cGETSTATIC:
- case JOpcode.cINSTANCEOF:
- case JOpcode.cINVOKESPECIAL: case JOpcode.cINVOKESTATIC:
- case JOpcode.cINVOKEVIRTUAL:
- case JOpcode.cLDC_W: case JOpcode.cLDC2_W: case JOpcode.cNEW:
- case JOpcode.cPUTFIELD: case JOpcode.cPUTSTATIC:
- data = codeArray.getU2(pc+1);
- buf.append("\t#");
- buf.append(data);
- buf.append("; ");
- buf.append(pool.lookupEntry(data).toComment(ownerClassName));
- break;
- case JOpcode.cIF_ACMPEQ: case JOpcode.cIF_ACMPNE:
- case JOpcode.cIFEQ: case JOpcode.cIFGE: case JOpcode.cIFGT:
- case JOpcode.cIFLE: case JOpcode.cIFLT: case JOpcode.cIFNE:
- case JOpcode.cIFNONNULL: case JOpcode.cIFNULL:
- case JOpcode.cIF_ICMPEQ: case JOpcode.cIF_ICMPGE:
- case JOpcode.cIF_ICMPGT: case JOpcode.cIF_ICMPLE:
- case JOpcode.cIF_ICMPLT: case JOpcode.cIF_ICMPNE:
- data = codeArray.getU2(pc+1); // maybe S2 offset
- buf.append("\t");
- buf.append(pc+data);
- break;
- case JOpcode.cGOTO:
- data = codeArray.getS2(pc+1); // always S2 offset
- buf.append("\t");
- buf.append(pc+data);
- break;
- case JOpcode.cINVOKEINTERFACE:
- data = codeArray.getU2(pc+1);
- data2 = codeArray.getU1(pc+3);
- buf.append("\t#");
- buf.append(data);
- buf.append(", ");
- buf.append(data2);
- buf.append("; ");
- buf.append(pool.lookupEntry(data).toComment(ownerClassName));
- break;
- case JOpcode.cTABLESWITCH:
- buf.append("{ //");
- int addr = ((pc / 4 + 1) + 1) * 4; // U4 aligned data
- int low = codeArray.getU4(addr);
- int high = codeArray.getU4(addr+4);
- buf.append(low);
- buf.append(" to ");
- buf.append(high);
- for (int i = low; i <= high; ++i) {
- buf.append("\n\t\t");
- buf.append(i);
- buf.append(": ");
- buf.append(pc+codeArray.getU4(addr+(i-1)*4));
- buf.append(";");
- }
- buf.append("\n\t\tdefault: ");
- buf.append(pc+codeArray.getU4(addr-4));
- buf.append(" }");
- default:
- }
- return buf.toString();
- }
-}
diff --git a/src/fjbg/ch/epfl/lamp/fjbg/JCodeAttribute.java b/src/fjbg/ch/epfl/lamp/fjbg/JCodeAttribute.java
deleted file mode 100644
index 9f3fcf8c6a..0000000000
--- a/src/fjbg/ch/epfl/lamp/fjbg/JCodeAttribute.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/* FJBG -- Fast Java Bytecode Generator
- * Copyright 2002-2013 LAMP/EPFL
- * @author Michel Schinz
- */
-
-package ch.epfl.lamp.fjbg;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * Code attribute, containing code of methods.
- *
- * A Code attribute contains the JVM instructions and auxiliary information
- * for a single method, instance initialization method, or class or interface
- * initialization method. See section 4.8.3 of the JVM specification.
- *
- * @author Michel Schinz, Stephane Micheloud
- * @version 1.1
- */
-
-public class JCodeAttribute extends JAttribute {
- protected final JCode code;
- protected final JMethod owner;
- protected static int UNKNOWN_STACK_SIZE = Integer.MIN_VALUE;
- protected final int maxStackSize;
- protected final int maxLocals;
-
- public JCodeAttribute(FJBGContext context, JClass clazz, JMethod owner) {
- super(context, clazz);
- this.owner = owner;
-
- this.maxStackSize = UNKNOWN_STACK_SIZE;
- this.maxLocals = 0; // unknown
- this.code = owner.getCode();
-
- assert clazz == owner.getOwner();
- }
-
- public JCodeAttribute(FJBGContext context,
- JClass clazz,
- Object owner,
- String name,
- int size,
- DataInputStream stream)
- throws IOException {
- super(context, clazz, name);
- this.owner = (JMethod)owner;
-
- this.maxStackSize = stream.readShort();
- this.maxLocals = stream.readShort();
- this.code = context.JCode(clazz, (JMethod)owner, stream);
-
- int handlersCount = stream.readShort();
- for (int i = 0; i < handlersCount; ++i)
- code.addExceptionHandler(code.new ExceptionHandler(stream));
- List/*<JAttribute>*/ attributes =
- JAttribute.readFrom(context, clazz, code, stream);
- Iterator attrIt = attributes.iterator();
- while (attrIt.hasNext())
- code.addAttribute((JAttribute)attrIt.next());
-
- assert name.equals(getName());
- }
-
- public String getName() { return "Code"; }
-
- // Follows javap output format for Code attribute.
- /*@Override*/ public String toString() {
- StringBuffer buf = new StringBuffer(" Code:");
- buf.append("\n Stack=");
- buf.append(maxStackSize);
- buf.append(", Locals=");
- buf.append(maxLocals);
- buf.append(", Args_size=");
- buf.append(owner.getArgsSize());
- buf.append(code);
- buf.append("\n");
- Iterator it = code.getAttributes().iterator();
- while (it.hasNext()) {
- JAttribute attr = (JAttribute)it.next();
- buf.append(attr);
- buf.append("\n");
- }
- return buf.toString();
- }
-
- protected int getSize() {
- int handlersNum = code.getExceptionHandlers().size();
-
- int attrsSize = 0;
- Iterator attrsIt = code.getAttributes().iterator();
- while (attrsIt.hasNext()) {
- JAttribute attr = (JAttribute)attrsIt.next();
- attrsSize += attr.getSize() + 6;
- }
-
- return 2 // max stack
- + 2 // max locals
- + 4 // code size
- + code.getSize() // code
- + 2 // exception table size
- + 8 * handlersNum // exception table
- + 2 // attributes count
- + attrsSize; // attributes
- }
-
- protected void writeContentsTo(DataOutputStream stream) throws IOException {
- List/*<ExceptionHandler>*/ handlers = code.getExceptionHandlers();
-
- stream.writeShort(code.getMaxStackSize());
- stream.writeShort(owner.getMaxLocals());
-
- code.writeTo(stream);
-
- stream.writeShort(handlers.size());
- Iterator handlerIt = handlers.iterator();
- while (handlerIt.hasNext())
- ((JCode.ExceptionHandler)handlerIt.next()).writeTo(stream);
- JAttribute.writeTo(code.getAttributes(), stream);
- }
-}
diff --git a/src/fjbg/ch/epfl/lamp/fjbg/JCodeIterator.java b/src/fjbg/ch/epfl/lamp/fjbg/JCodeIterator.java
deleted file mode 100644
index d09dfd19a4..0000000000
--- a/src/fjbg/ch/epfl/lamp/fjbg/JCodeIterator.java
+++ /dev/null
@@ -1,377 +0,0 @@
-/* FJBG -- Fast Java Bytecode Generator
- * Copyright 2002-2013 LAMP/EPFL
- * @author Michel Schinz
- */
-
-package ch.epfl.lamp.fjbg;
-
-import ch.epfl.lamp.util.ByteArray;
-
-/**
- * Iterator used to examine the contents of an instruction list.
- *
- * @author Michel Schinz, Thomas Friedli
- * @version 1.0
- */
-
-public class JCodeIterator {
- protected final JCode code;
- protected final JConstantPool pool;
- protected final ByteArray codeArray;
-
- protected int pc;
- protected JOpcode opcode;
-
- /**
- * Creates a new code iterator with its instruction list
- * and its pc initialized to a given value.
- */
- public JCodeIterator(JCode code, int pc) {
- this.code = code;
- this.pool = code.getOwner().getOwner().getConstantPool();
- this.codeArray = code.codeArray;
- this.pc = pc;
- setOpcode();
- }
-
- public JCodeIterator(JCode code) {
- this(code, 0);
- }
-
- /**
- * Get the current program counter.
- * @return The current program counter.
- */
- public int getPC() { return pc; }
-
- /**
- * Searches the type of the instruction positionned at the
- * current address and updates the current instruction.
- */
- protected void setOpcode() {
- // TODO : check if the current pc is the beginning
- // of an instruction
- opcode = isValid() ? JOpcode.OPCODES[codeArray.getU1(pc)] : null;
- }
-
- /**
- * Returns the opcode of the current instruction.
- * @return The opcode of the current instruction.
- */
- public JOpcode getOpcode() {
- return opcode;
- }
-
- /**
- * Updates the program counter to an given value.
- * @param pc The new value of the program counter.
- */
- public void moveTo(int pc) {
- this.pc = pc;
- setOpcode();
- }
-
- /**
- * Check the validity of the iterator.
- * @return true iff the iterator points to a valid address.
- */
- public boolean isValid() {
- return pc < codeArray.getSize();
- }
-
- /**
- * Updates the current instruction with the next one in the
- * sense of their position in the code.
- */
- public void moveToNext() {
- moveTo(pc + getInstructionSize());
- }
-
- /**
- * Updates the current instruction with a specific successor
- * of it.
- * @param succ The index of the wanted successor in the list of
- * the successors of the current instruction.
- */
- public void moveToSuccessor(int succ) {
- moveTo(getSuccessorPC(succ));
- }
-
- /**
- * Updates the current instruction with the one positionned
- * at a given index relatively to the actual program counter
- * @param offset The relative position of the instruction
- * compared with the position of the current one
- */
- public void moveRelatively(int offset) {
- moveTo(pc + offset);
- }
-
- /**
- * Returns the size in bytes of the current instruction.
- * @return The size in bytes of the current instruction.
- */
- public int getInstructionSize() {
- if (opcode.size != JOpcode.UNKNOWN) {
- return opcode.size;
- } else if (opcode == JOpcode.TABLESWITCH) {
- int lowOffset = 1 + pad4(pc + 1) + 4;
- int low = codeArray.getS4(pc + lowOffset);
- int high = codeArray.getS4(pc + lowOffset + 4);
- return lowOffset + 8 + 4 * (high - low + 1);
- } else if (opcode == JOpcode.LOOKUPSWITCH) {
- int npairsOffset = 1 + pad4(pc + 1) + 4;
- int npairs = codeArray.getS4(pc + npairsOffset);
- return npairsOffset + 4 + 8 * npairs;
- } else if (opcode == JOpcode.WIDE) {
- if (codeArray.getU1(pc + 1) == JOpcode.cIINC)
- return 6;
- else
- return 4;
- } else
- throw new Error("Unknown size for instruction " + opcode);
- }
-
- /**
- * Returns the number of successors of the current instruction.
- * @return The number of successors of the current instruction.
- */
- public int getSuccessorCount() {
- if (opcode.successorCount != JOpcode.UNKNOWN) {
- return opcode.successorCount;
- } else if (opcode == JOpcode.TABLESWITCH) {
- int lowPos = pc + 1 + pad4(pc + 1) + 4;
- return 1 // default case
- + codeArray.getS4(lowPos + 4) // value of HIGH field
- - codeArray.getS4(lowPos) + 1; // value of LOW field
- } else if (opcode == JOpcode.LOOKUPSWITCH) {
- int npairsPos = pc + 1 + pad4(pc + 1) + 4;
- return 1 + codeArray.getS4(npairsPos);
- } else
- throw new Error("Unknown successors for instruction " + opcode);
- }
-
- /**
- * Returns the address of the successor of the current instruction
- * given its index in the list of successors of the current
- * instruction.
- * @param index The index of the wanted successor in the list of
- * the successors of the current instruction.
- * @return The address of the specific successor.
- */
- public int getSuccessorPC(int index) {
- assert (index >= 0) && (index < getSuccessorCount()) : index;
-
- switch (opcode.jumpKind) {
- case JOpcode.JMP_NEXT:
- return pc + getInstructionSize();
- case JOpcode.JMP_ALWAYS_S2_OFFSET:
- return pc + codeArray.getS2(pc + 1);
- case JOpcode.JMP_ALWAYS_S4_OFFSET:
- return pc + codeArray.getS4(pc + 1);
- case JOpcode.JMP_MAYBE_S2_OFFSET:
- if (index == 0)
- return pc + getInstructionSize();
- else
- return pc + codeArray.getS2(pc + 1);
- case JOpcode.JMP_TABLE: {
- int defaultPos = pc + 1 + pad4(pc + 1);
- if (index == 0)
- return pc + codeArray.getS4(defaultPos);
- else
- return pc + codeArray.getS4(defaultPos + 3*4 + 4 * (index - 1));
- }
- case JOpcode.JMP_LOOKUP: {
- int defaultPos = pc + 1 + pad4(pc + 1);
- if (index == 0)
- return pc + codeArray.getS4(defaultPos);
- else
- return pc + codeArray.getS4(defaultPos + 2*4 + 4 + 8 * (index - 1));
- }
- default:
- throw new Error();
- }
- }
-
- /**
- * Returns the total size of data words put on the stack by the current
- * instruction.
- * @return The total size of data words put on the stack by the current
- * instruction.
- */
- public int getProducedDataSize() {
- if (opcode.getProducedDataTypes() == JOpcode.UNKNOWN_TYPE) {
- switch (opcode.code) {
- case JOpcode.cLDC: case JOpcode.cLDC_W: case JOpcode.cBALOAD:
- return 1;
- case JOpcode.cLDC2_W: case JOpcode.cDUP: case JOpcode.cSWAP:
- return 2;
- case JOpcode.cDUP_X1:
- return 3;
- case JOpcode.cDUP_X2: case JOpcode.cDUP2:
- return 4;
- case JOpcode.cDUP2_X1:
- return 5;
- case JOpcode.cDUP2_X2:
- return 6;
- case JOpcode.cGETSTATIC: case JOpcode.cGETFIELD: {
- JConstantPool.FieldOrMethodRefEntry entry =
- (JConstantPool.FieldOrMethodRefEntry)
- pool.lookupEntry(codeArray.getU2(pc + 1));
- return JType.parseSignature(entry.getSignature()).getSize();
- }
- case JOpcode.cWIDE : {
- int op = codeArray.getU1(pc + 1);
- if (op >= JOpcode.cILOAD && op <= JOpcode.cALOAD) {
- JOpcode opcode2 = JOpcode.OPCODES[op];
- return JType.getTotalSize(opcode2.getProducedDataTypes());
- } else if (op >= JOpcode.cISTORE && op <= JOpcode.cASTORE)
- return 0;
- else return 0; // (IINC)
- }
- default :
- throw new Error(opcode.toString());
- }
- } else
- return JType.getTotalSize(opcode.getProducedDataTypes());
- }
-
- /**
- * Returns the total size of data words taken from the stack by the current
- * instruction.
- * @return The total size of data words taken from the stack by the current
- * instruction.
- */
- public int getConsumedDataSize() {
- if (opcode.getConsumedDataTypes() != JOpcode.UNKNOWN_TYPE)
- return JType.getTotalSize(opcode.getConsumedDataTypes());
- else {
- switch (opcode.code) {
- case JOpcode.cPOP: case JOpcode.cDUP:
- return 1;
- case JOpcode.cPOP2: case JOpcode.cSWAP:
- case JOpcode.cDUP_X1: case JOpcode.cDUP2:
- return 2;
- case JOpcode.cDUP_X2: case JOpcode.cDUP2_X1:
- return 3;
- case JOpcode.cDUP2_X2:
- return 4;
- case JOpcode.cPUTSTATIC: case JOpcode.cPUTFIELD: {
- JConstantPool.FieldOrMethodRefEntry entry =
- (JConstantPool.FieldOrMethodRefEntry)
- pool.lookupEntry(codeArray.getU2(pc + 1));
- return JType.parseSignature(entry.getSignature()).getSize();
- }
- case JOpcode.cINVOKEVIRTUAL: case JOpcode.cINVOKESPECIAL:
- case JOpcode.cINVOKESTATIC: case JOpcode.cINVOKEINTERFACE : {
- JConstantPool.FieldOrMethodRefEntry entry =
- (JConstantPool.FieldOrMethodRefEntry)
- pool.lookupEntry(codeArray.getU2(pc + 1));
- JMethodType tp = (JMethodType)
- JType.parseSignature(entry.getSignature());
- return tp.getArgsSize()
- + (opcode == JOpcode.INVOKESTATIC ? 0 : 1);
- }
- case JOpcode.cWIDE : {
- int op = codeArray.getU1(pc + 1);
- if (op >= JOpcode.cILOAD && op <= JOpcode.cALOAD)
- return 0;
- else if (op >= JOpcode.cISTORE && op <= JOpcode.cASTORE) {
- JOpcode opcode2 = JOpcode.OPCODES[op];
- return JType.getTotalSize(opcode2.getConsumedDataTypes());
- } else
- return 0; // (IINC)
- }
- case JOpcode.cMULTIANEWARRAY :
- return codeArray.getU1(pc + 3);
- default:
- throw new Error(opcode.toString());
- }
- }
- }
-
- /**
- * Returns the number of data types put on the stack by the current
- * instruction.
- * @return The number of data types put on the stack by the current
- * instruction.
- */
- public int getProducedDataTypesNumber() {
- if (opcode.getProducedDataTypes() != JOpcode.UNKNOWN_TYPE)
- return opcode.getProducedDataTypes().length;
- else {
- switch (opcode.code) {
- case JOpcode.cLDC: case JOpcode.cLDC_W: case JOpcode.cLDC2_W:
- case JOpcode.cBALOAD: case JOpcode.cGETSTATIC:
- case JOpcode.cGETFIELD:
- return 1;
- case JOpcode.cDUP: case JOpcode.cSWAP:
- return 2;
- case JOpcode.cDUP_X1:
- return 3;
- case JOpcode.cWIDE: {
- int op = codeArray.getU1(pc + 1);
- if (op >= JOpcode.cILOAD && op <= JOpcode.cALOAD)
- return 1;
- else if (op >= JOpcode.cISTORE && op <= JOpcode.cASTORE)
- return 0;
- else
- return 0; // (IINC)
- }
- default:
- throw new Error("JOpcode implementation error");
- }
- }
- }
-
- /**
- * Returns the number of data types taken from the stack by the current
- * instruction.
- * @return The number of data types taken from the stack by the current
- * instruction.
- */
-// public int getConsumedDataTypesNumber() {
-// if (opcode.getConsumedDataTypes() == JOpcode.UNKNOWN_TYPE) {
-// switch (opcode.code) {
-// case 87 : return 1; // POP
-// case 88 : return 2; // POP2
-// case 89 : return 1; // DUP
-// case 90 : return 2; // DUP_X1
-// case 91 : // DUP_X2
-// case 92 : // DUP2
-// case 93 : // DUP2_X1
-// case 94 : // DUP2_X2
-// throw new UnsupportedOperationException("Opcode " + opcode.name
-// + " has a stack-dependant"
-// + " data types consumption");
-// case 95 : return 2; // SWAP
-// case 179 : return 1; // PUTSTATIC
-// case 181 : return 1; // PUTFIELD
-// case 182 : // INVOKEVIRTUAL
-// case 183 : // INVOKESPECIAL
-// case 185 : // INVOKEINTERFACE
-// s = epool.getClassMethodRef(codeArray.getU2(pc + 1)).split(" ")[3];
-// return ((JMethodType)JType.parseSignature(s)).argTypes.length + 1;
-// case 184 : // INVOKESTATIC
-// s = epool.getClassMethodRef(codeArray.getU2(pc + 1)).split(" ")[3];
-// return ((JMethodType)JType.parseSignature(s)).argTypes.length;
-// case 196 : // WIDE
-// int op = codeArray.getU1(pc + 1);
-// if (op >= 21 && op <= 25) return 0; // (xLOAD)
-// else if (op >= 54 && op <= 58) // (xSTORE)
-// return JOpcode.OPCODES[op].getConsumedDataTypes().length;
-// else return 0; // (IINC)
-// case 197 : return codeArray.getU1(pc + 3); // MULTIANEWARRAY
-// default : throw new Error("JOpcode implementation error");
-// }
-// } else return opcode.getConsumedDataTypes().length;
-// }
-
-
- // Return the number between 0 and 3 which, if added to the given
- // value, would yield a multiple of 4.
- protected int[] padding = { 0, 3, 2, 1 };
- protected int pad4(int value) {
- return padding[value % 4];
- }
-}
diff --git a/src/fjbg/ch/epfl/lamp/fjbg/JConstantPool.java b/src/fjbg/ch/epfl/lamp/fjbg/JConstantPool.java
deleted file mode 100644
index 9867e01b25..0000000000
--- a/src/fjbg/ch/epfl/lamp/fjbg/JConstantPool.java
+++ /dev/null
@@ -1,771 +0,0 @@
-/* FJBG -- Fast Java Bytecode Generator
- * Copyright 2002-2013 LAMP/EPFL
- * @author Michel Schinz
- */
-
-package ch.epfl.lamp.fjbg;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.HashMap;
-
-/**
- * Constant pool, holding constants for a Java class file.
- *
- * @author Michel Schinz
- * @version 2.0
- */
-
-public class JConstantPool {
- protected boolean frozen = false;
-
- protected HashMap/*<Entry,Integer>*/ entryToIndex = new HashMap();
- protected Entry[] indexToEntry;
- protected int currIndex;
-
- public static final short CONSTANT_Utf8 = 1;
- public static final short CONSTANT_Integer = 3;
- public static final short CONSTANT_Float = 4;
- public static final short CONSTANT_Long = 5;
- public static final short CONSTANT_Double = 6;
- public static final short CONSTANT_Class = 7;
- public static final short CONSTANT_String = 8;
- public static final short CONSTANT_Fieldref = 9;
- public static final short CONSTANT_Methodref = 10;
- public static final short CONSTANT_InterfaceMethodref = 11;
- public static final short CONSTANT_NameAndType = 12;
-
- protected JConstantPool(FJBGContext context) {
- indexToEntry = new Entry[8];
- currIndex = 1;
- }
-
- protected JConstantPool(FJBGContext context, DataInputStream stream)
- throws IOException {
- int count = stream.readShort();
- indexToEntry = new EntryIndex[count];
-
- currIndex = 1;
- while (currIndex < count) {
- EntryIndex e;
- int tag = stream.readByte();
-
- switch (tag) {
- case CONSTANT_Utf8:
- e = new Utf8Entry(stream);
- // no duplicates
- entryToIndex.put(e, new Integer(currIndex));
- break;
- case CONSTANT_Integer:
- e = new IntegerEntry(stream);
- break;
- case CONSTANT_Float:
- e = new FloatEntry(stream);
- break;
- case CONSTANT_Long:
- e = new LongEntry(stream);
- break;
- case CONSTANT_Double:
- e = new DoubleEntry(stream);
- break;
- case CONSTANT_Class:
- e = new DescriptorEntryIndex(stream);
- break;
- case CONSTANT_String:
- e = new StringEntryIndex(stream);
- break;
- case CONSTANT_Fieldref:
- case CONSTANT_Methodref:
- case CONSTANT_InterfaceMethodref:
- e = new FieldOrMethodRefEntryIndex(tag, stream);
- break;
- case CONSTANT_NameAndType:
- e = new NameAndTypeEntryIndex(stream);
- break;
- default:
- throw new IllegalArgumentException("unknown entry in pool: " + tag);
- }
- indexToEntry[currIndex] = e;
- currIndex += e.getSize();
- }
- }
-
- public void freeze() { frozen = true; }
-
- /**
- * Returns a string representing the type of an entry
- * knowing its tag
- * @param tag The tag representing the type of the
- * constant pool entry
- */
- public String getEntryType(int tag) {
- switch (tag) {
- case CONSTANT_Utf8 : return "Utf8";
- case CONSTANT_Integer : return "Integer";
- case CONSTANT_Float : return "Float";
- case CONSTANT_Long : return "Long";
- case CONSTANT_Double : return "Double";
- case CONSTANT_Class : return "Class";
- case CONSTANT_String : return "String";
- case CONSTANT_Fieldref : return "Field";
- case CONSTANT_Methodref : return "Method";
- case CONSTANT_InterfaceMethodref : return "InterfaceMethod";
- case CONSTANT_NameAndType : return "NameAndType";
- default : throw new Error("invalid constant pool tag : " + tag);
- }
- }
-
- public int addClass(String className) {
- return addDescriptor(className.replace('.', '/'));
- }
-
- public int addDescriptor(JReferenceType type) {
- return addDescriptor(type.getDescriptor());
- }
-
- protected int addDescriptor(String name) {
- return addEntry(new DescriptorEntryValue(name));
- }
-
- public int addClassMethodRef(String className,
- String methodName,
- String signature) {
- return addMethodRef(true, className, methodName, signature);
- }
-
- public int addInterfaceMethodRef(String className,
- String methodName,
- String signature) {
- return addMethodRef(false, className, methodName, signature);
- }
-
- public int addMethodRef(boolean isClass,
- String className,
- String methodName,
- String signature) {
- return addEntry(new FieldOrMethodRefEntryValue(isClass
- ? CONSTANT_Methodref
- : CONSTANT_InterfaceMethodref,
- className,
- methodName,
- signature));
- }
-
- public int addFieldRef(String className,
- String fieldName,
- String signature) {
- return addEntry(new FieldOrMethodRefEntryValue(CONSTANT_Fieldref,
- className,
- fieldName,
- signature));
- }
-
- public int addInteger(int value) {
- return addEntry(new IntegerEntry(value));
- }
-
- public int addFloat(float value) {
- return addEntry(new FloatEntry(value));
- }
-
- public int addLong(long value) {
- return addEntry(new LongEntry(value));
- }
-
- public int addDouble(double value) {
- return addEntry(new DoubleEntry(value));
- }
-
- public int addString(String value) {
- return addEntry(new StringEntryValue(value));
- }
-
- public int addNameAndType(String name, String descriptor) {
- return addEntry(new NameAndTypeEntryValue(name, descriptor));
- }
-
- public int addUtf8(String value) {
- return addEntry(new Utf8Entry(value));
- }
-
- public int addUtf8(byte[] value) {
- return addEntry(new Utf8Entry(value));
- }
-
- protected int addEntry(EntryValue e) {
- assert !frozen;
- Integer idx = (Integer)entryToIndex.get(e);
- if (idx != null)
- return idx.intValue();
-
- e.addChildren();
-
- int index = currIndex;
- currIndex += e.getSize();
-
- entryToIndex.put(e, new Integer(index));
- if (index >= indexToEntry.length) {
- Entry[] newI2E = new Entry[indexToEntry.length * 2];
- System.arraycopy(indexToEntry, 0, newI2E, 0, indexToEntry.length);
- indexToEntry = newI2E;
- }
- indexToEntry[index] = e;
- return index;
- }
-
- /// Lookup methods
- //////////////////////////////////////////////////////////////////////
-
- public Entry lookupEntry(int index) {
- assert index > 0 && index < currIndex
- : "invalid index: " + index;
- assert indexToEntry[index] != null
- : "invalid index (null contents): " + index;
- return indexToEntry[index];
- }
-
- public String lookupClass(int index) {
- DescriptorEntry entry = (DescriptorEntry)lookupEntry(index);
- return entry.getValue();
- }
-
- public String lookupNameAndType(int index) {
- NameAndTypeEntry entry = (NameAndTypeEntry)lookupEntry(index);
- return entry.getName()+":"+entry.getDescriptor();
- }
-
- public String lookupUtf8(int index) {
- Utf8Entry entry = (Utf8Entry)lookupEntry(index);
- return entry.getValue();
- }
-
- /// Output
- //////////////////////////////////////////////////////////////////////
-
- public void writeTo(DataOutputStream stream) throws IOException {
- if (! frozen) freeze();
-
- stream.writeShort(currIndex);
- for (int i = 0; i < currIndex; ++i) {
- Entry entry = indexToEntry[i];
- if (entry != null) {
- stream.writeByte(entry.getTag());
- entry.writeContentsTo(stream);
- }
- }
- }
-
- // Follows javap output format for constant pool.
- /*@Override*/ public String toString() {
- StringBuffer buf = new StringBuffer(" Constant pool:");
- for (int i = 0; i < currIndex; ++i) {
- Entry entry = indexToEntry[i];
- if (entry != null) {
- if (i > 0) buf.append("\n");
- buf.append("const #");
- buf.append(i);
- buf.append(" = ");
- buf.append(entry);
- }
- }
- buf.append("\n");
- return buf.toString();
- }
-
- /// Classes for the various kinds of entries
- //////////////////////////////////////////////////////////////////////
-
- public interface Entry {
- public int getTag();
-
- int getSize();
- void writeContentsTo(DataOutputStream stream) throws IOException;
- String toComment(String ownerClassName);
- }
-
- protected interface EntryValue extends Entry {
- abstract void addChildren();
- }
-
- protected interface EntryIndex extends Entry {
- abstract void fetchChildren();
- }
-
- abstract protected class ChildlessEntry implements EntryValue, EntryIndex {
- public void addChildren() {}
- public void fetchChildren() {}
- }
-
- public class IntegerEntry extends ChildlessEntry implements Entry {
- private final int value;
- public IntegerEntry(int value) { this.value = value; }
- public IntegerEntry(DataInputStream stream) throws IOException {
- this(stream.readInt());
- }
-
- public int hashCode() { return value; }
- public boolean equals(Object o) {
- return o instanceof IntegerEntry && ((IntegerEntry)o).value == value;
- }
-
- public int getTag() { return CONSTANT_Integer; }
- public int getValue() { return value; }
-
- public int getSize() { return 1; }
- public void writeContentsTo(DataOutputStream stream) throws IOException {
- stream.writeInt(value);
- }
- /*@Override*/ public String toString() {
- StringBuffer buf = new StringBuffer("int\t");
- buf.append(getValue());
- buf.append(";");
- return buf.toString();
- }
- public String toComment(String ownerClassname) {
- return "//int "+getValue();
- }
- }
-
- public class FloatEntry extends ChildlessEntry implements Entry {
- private final float value;
- public FloatEntry(float value) { this.value = value; }
- public FloatEntry(DataInputStream stream) throws IOException {
- this(stream.readFloat());
- }
-
- public int hashCode() { return (int)value; }
- public boolean equals(Object o) {
- return o instanceof FloatEntry && ((FloatEntry)o).value == value;
- }
-
- public int getTag() { return CONSTANT_Float; }
- public float getValue() { return value; }
-
- public int getSize() { return 1; }
- public void writeContentsTo(DataOutputStream stream) throws IOException {
- stream.writeFloat(value);
- }
- /*@Override*/ public String toString() {
- StringBuffer buf = new StringBuffer("float\t");
- buf.append(getValue());
- buf.append("f");
- return buf.toString();
- }
- public String toComment(String ownerClassname) {
- return "//float "+getValue()+"f";
- }
- }
-
- public class LongEntry extends ChildlessEntry implements Entry {
- private final long value;
- public LongEntry(long value) { this.value = value; }
- public LongEntry(DataInputStream stream) throws IOException {
- this(stream.readLong());
- }
-
- public int hashCode() { return (int)value; }
- public boolean equals(Object o) {
- return o instanceof LongEntry && ((LongEntry)o).value == value;
- }
-
- public int getTag() { return CONSTANT_Long; }
- public long getValue() { return value; }
-
- public int getSize() { return 2; }
- public void writeContentsTo(DataOutputStream stream) throws IOException {
- stream.writeLong(value);
- }
- /*@Override*/ public String toString() {
- StringBuffer buf = new StringBuffer("long\t");
- buf.append(getValue());
- buf.append("l;");
- return buf.toString();
- }
- public String toComment(String ownerClassname) {
- return "//long "+getValue()+"l";
- }
- }
-
- public class DoubleEntry extends ChildlessEntry implements Entry {
- private final double value;
- public DoubleEntry(double value) { this.value = value; }
- public DoubleEntry(DataInputStream stream) throws IOException {
- this(stream.readDouble());
- }
-
- public int hashCode() { return (int)value; }
- public boolean equals(Object o) {
- return o instanceof DoubleEntry && ((DoubleEntry)o).value == value;
- }
-
- public int getTag() { return CONSTANT_Double; }
- public double getValue() { return value; }
-
- public int getSize() { return 2; }
- public void writeContentsTo(DataOutputStream stream) throws IOException {
- stream.writeDouble(value);
- }
- /*@Override*/ public String toString() {
- StringBuffer buf = new StringBuffer("double\t");
- buf.append(getValue());
- return buf.toString();
- }
- public String toComment(String ownerClassname) {
- return "//double "+getValue();
- }
- }
-
- public class Utf8Entry extends ChildlessEntry implements Entry {
- private final String value;
- private final byte[] bytes;
- public Utf8Entry(String value) {
- this.value = value.intern();
- this.bytes = null;
- }
- public Utf8Entry(DataInputStream stream) throws IOException {
- this(stream.readUTF());
- }
- public Utf8Entry(byte[] bytes) {
- this.bytes = bytes;
- this.value = null;
- }
-
- public int hashCode() {
- if (bytes != null) return bytes.hashCode();
- return value.hashCode();
- }
- public boolean equals(Object o) {
- boolean isEqual = o instanceof Utf8Entry;
- if (bytes != null) {
- isEqual = isEqual && ((Utf8Entry)o).bytes == bytes;
- }
- else {
- isEqual = isEqual && ((Utf8Entry)o).value == value;
- }
- return isEqual;
- }
-
- public int getTag() { return CONSTANT_Utf8; }
- public String getValue() { return value; }
- public byte[] getBytes() { return bytes; }
-
- public int getSize() { return 1; }
- public void writeContentsTo(DataOutputStream stream) throws IOException {
- if (bytes != null) {
- if (bytes.length > 65535) {
- throw new IOException("String literal of length " + bytes.length + " does not fit in Classfile");
- }
- stream.writeShort(bytes.length);
- stream.write(bytes);
- }
- else
- stream.writeUTF(value);
- }
- // Follows javap output format for Utf8 pool entries.
- public String toString() { return "Asciz\t"+escaped(getValue())+";"; }
- public String toComment(String ownerClassname) {
- return "//Asciz "+escaped(getValue());
- }
- private String escaped(String s) {
- return s.replace("\n", "\\n");
- }
- }
-
- abstract public class StringEntry implements Entry {
- protected String value;
- protected int valueIndex;
-
- public int hashCode() {
- assert value != null;
- return value.hashCode();
- }
- public boolean equals(Object o) {
- return o instanceof StringEntry && ((StringEntry)o).value == value;
- }
-
- public int getTag() { return CONSTANT_String; }
- public String getValue() { return value; }
-
- public int getSize() { return 1; }
- public void writeContentsTo(DataOutputStream stream) throws IOException {
- stream.writeShort(valueIndex);
- }
- // Follows javap output format for String pool entries.
- public String toString() {
- return "String\t#"+valueIndex+";\t// "+escaped(getValue());
- }
- public String toComment(String ownerClassname) {
- return "//String "+escaped(getValue());
- }
- private String escaped(String s) {
- return s.replace("\n", "\\n");
- }
- }
-
- public class StringEntryValue extends StringEntry implements EntryValue {
- public StringEntryValue(String value) {
- this.value = value.intern();
- }
- public void addChildren() {
- valueIndex = addUtf8(value);
- }
- }
-
- public class StringEntryIndex extends StringEntry implements EntryIndex {
- public StringEntryIndex(int valueIndex) {
- this.valueIndex = valueIndex;
- }
- public StringEntryIndex(DataInputStream stream) throws IOException {
- this(stream.readShort());
- }
- public String getValue() {
- if (value == null) fetchChildren();
- return super.getValue();
- }
- public void fetchChildren() {
- value = lookupUtf8(valueIndex);
- }
- }
-
- abstract public class DescriptorEntry implements Entry {
- protected String name;
- protected int nameIndex;
-
- public int hashCode() {
- assert name != null;
- return name.hashCode();
- }
- public boolean equals(Object o) {
- return o instanceof DescriptorEntry && ((DescriptorEntry)o).name == name;
- }
-
- public int getTag() { return CONSTANT_Class; }
- public String getValue() { return name; }
-
- public int getSize() { return 1; }
- public void writeContentsTo(DataOutputStream stream) throws IOException {
- stream.writeShort(nameIndex);
- }
- // Follows javap output format for class pool entries.
- public String toString() {
- StringBuffer buf = new StringBuffer("class\t#");
- buf.append(nameIndex);
- buf.append(";\t// ");
- buf.append(getClassName());
- return buf.toString();
- }
- public String toComment(String ownerClassname) {
- return "//class "+getClassName();
- }
- private String getClassName() {
- StringBuffer buf = new StringBuffer();
- String value = getValue();
- if (value.startsWith("[")) buf.append("\"");
- buf.append(value);
- if (value.startsWith("[")) buf.append("\"");
- return buf.toString();
- }
- }
-
- protected class DescriptorEntryValue
- extends DescriptorEntry
- implements EntryValue {
- public DescriptorEntryValue(String name) { this.name = name.intern(); }
- public void addChildren() {
- nameIndex = addUtf8(name);
- }
- }
-
- protected class DescriptorEntryIndex
- extends DescriptorEntry
- implements EntryIndex {
- public DescriptorEntryIndex(int nameIndex) { this.nameIndex = nameIndex; }
- public DescriptorEntryIndex(DataInputStream stream) throws IOException {
- this(stream.readShort());
- }
- public String getValue() {
- if (name == null) fetchChildren();
- return super.getValue();
- }
- public void fetchChildren() {
- name = lookupUtf8(nameIndex);
- }
- }
-
- abstract public class FieldOrMethodRefEntry implements Entry {
- private final int tag;
- protected String className, thingName, signature;
- protected int classIndex, nameAndTypeIndex;
-
- public FieldOrMethodRefEntry(int tag) {
- assert tag == CONSTANT_Fieldref
- || tag == CONSTANT_Methodref
- || tag == CONSTANT_InterfaceMethodref;
-
- this.tag = tag;
- }
-
- public int hashCode() {
- return tag
- + className.hashCode()
- + thingName.hashCode()
- + signature.hashCode();
- }
- public boolean equals(Object o) {
- return o instanceof FieldOrMethodRefEntry
- && ((FieldOrMethodRefEntry)o).tag == tag
- && ((FieldOrMethodRefEntry)o).className == className
- && ((FieldOrMethodRefEntry)o).thingName == thingName
- && ((FieldOrMethodRefEntry)o).signature == signature;
- }
-
- public int getTag() { return tag; }
- public String getClassName() { return className; }
- public String getFieldOrMethodName() { return thingName; }
- public String getSignature() { return signature; }
-
- public int getSize() { return 1; }
- public void writeContentsTo(DataOutputStream stream) throws IOException {
- stream.writeShort(classIndex);
- stream.writeShort(nameAndTypeIndex);
- }
- // Follows javap output format for field/method pool entries.
- public String toString() {
- return getEntryType(tag)+"\t#"+classIndex+".#"+nameAndTypeIndex+
- ";\t// "+getName("")+":"+signature;
- }
- public String toComment(String ownerClassName) {
- return "//"+getEntryType(tag)+" "+getName(ownerClassName)+":"+signature;
- }
- private String getName(String ownerClassName) {
- String name = getFieldOrMethodName();
- if (JMethod.INSTANCE_CONSTRUCTOR_NAME.equals(name))
- name = "\""+name+"\"";
- if (!getClassName().equals(ownerClassName))
- name = getClassName()+"."+name;
- return name;
- }
- }
-
- protected class FieldOrMethodRefEntryValue
- extends FieldOrMethodRefEntry
- implements EntryValue {
- public FieldOrMethodRefEntryValue(int tag,
- String className,
- String thingName,
- String signature) {
- super(tag);
- this.className = className.intern();
- this.thingName = thingName.intern();
- this.signature = signature.intern();
- }
-
- public void addChildren() {
- classIndex = addClass(className);
- nameAndTypeIndex = addNameAndType(thingName, signature);
- }
- }
-
- protected class FieldOrMethodRefEntryIndex
- extends FieldOrMethodRefEntry
- implements EntryIndex {
- public FieldOrMethodRefEntryIndex(int tag,
- int classIndex,
- int nameAndTypeIndex) {
- super(tag);
- this.classIndex = classIndex;
- this.nameAndTypeIndex = nameAndTypeIndex;
- }
- public FieldOrMethodRefEntryIndex(int tag, DataInputStream stream)
- throws IOException {
- this(tag, stream.readShort(), stream.readShort());
- }
- public String getClassName() {
- if (className == null) fetchChildren();
- return super.getClassName();
- }
- public String getFieldOrMethodName() {
- if (thingName == null) fetchChildren();
- return super.getFieldOrMethodName();
- }
- public String getSignature() {
- if (signature == null) fetchChildren();
- return super.getSignature();
- }
- public void fetchChildren() {
- className = lookupClass(classIndex);
- NameAndTypeEntry nat = (NameAndTypeEntry)lookupEntry(nameAndTypeIndex);
- thingName = nat.getName();
- signature = nat.getDescriptor();
- }
- }
-
- abstract public class NameAndTypeEntry implements Entry {
- protected String name, descriptor;
- protected int nameIndex, descriptorIndex;
-
- public int hashCode() { return name.hashCode() + descriptor.hashCode(); }
- public boolean equals(Object o) {
- return o instanceof NameAndTypeEntry
- && ((NameAndTypeEntry)o).name == name
- && ((NameAndTypeEntry)o).descriptor == descriptor;
- }
-
- public int getTag() { return CONSTANT_NameAndType; }
- public String getName() { return name; }
- public String getDescriptor() { return descriptor; }
-
- public int getSize() { return 1; }
- public void writeContentsTo(DataOutputStream stream) throws IOException {
- stream.writeShort(nameIndex);
- stream.writeShort(descriptorIndex);
- }
- // Follows javap output format for name/type pool entries.
- public String toString() {
- String natName = getName();
- if (JMethod.INSTANCE_CONSTRUCTOR_NAME.equals(natName))
- natName = "\""+natName+"\"";
- return "NameAndType\t#"+nameIndex+":#"+descriptorIndex+
- ";// "+natName+":"+getDescriptor();
- }
- public String toComment(String ownerClassname) { return ""; }
- }
-
- protected class NameAndTypeEntryValue
- extends NameAndTypeEntry
- implements EntryValue {
- public NameAndTypeEntryValue(String name, String descriptor) {
- this.name = name.intern();
- this.descriptor = descriptor.intern();
- }
- public void addChildren() {
- nameIndex = addUtf8(name);
- descriptorIndex = addUtf8(descriptor);
- }
- }
-
- protected class NameAndTypeEntryIndex
- extends NameAndTypeEntry
- implements EntryIndex {
- public NameAndTypeEntryIndex(int nameIndex, int descriptorIndex) {
- this.nameIndex = nameIndex;
- this.descriptorIndex = descriptorIndex;
- }
- public NameAndTypeEntryIndex(DataInputStream stream) throws IOException {
- this(stream.readShort(), stream.readShort());
- }
- public String getName() {
- if (name == null) fetchChildren();
- return super.getName();
- }
- public String getDescriptor() {
- if (descriptor == null) fetchChildren();
- return super.getDescriptor();
- }
- public void fetchChildren() {
- name = lookupUtf8(nameIndex);
- descriptor = lookupUtf8(descriptorIndex);
- }
- }
-}
diff --git a/src/fjbg/ch/epfl/lamp/fjbg/JConstantValueAttribute.java b/src/fjbg/ch/epfl/lamp/fjbg/JConstantValueAttribute.java
deleted file mode 100644
index 6ee05e43c7..0000000000
--- a/src/fjbg/ch/epfl/lamp/fjbg/JConstantValueAttribute.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/* FJBG -- Fast Java Bytecode Generator
- * Copyright 2002-2013 LAMP/EPFL
- * @author Michel Schinz
- */
-
-package ch.epfl.lamp.fjbg;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-
-/**
- * ConstantValue attribute representing the value of a constant field.
- *
- * There can be no more than one ConstantValue attribute in the attributes
- * table of a given field_info structure.. See section 4.8.2 of the JVM
- * specification.
- *
- * @author Stephane Micheloud
- * @version 1.0
- */
-
-public class JConstantValueAttribute extends JAttribute {
- /** Constant pool of the current classfile. */
- private JConstantPool pool;
-
- protected int constantValueIndex;
-
- public JConstantValueAttribute(FJBGContext context,
- JClass clazz,
- JField field) {
- super(context, clazz);
- this.pool = clazz.pool;
-
- assert field.getOwner() == clazz;
- }
-
- public JConstantValueAttribute(FJBGContext context,
- JClass clazz,
- Object owner, // JField
- String name,
- int size,
- DataInputStream stream)
- throws IOException {
- super(context, clazz, name);
- this.pool = clazz.pool;
-
- this.constantValueIndex = stream.readShort();
-
- assert name.equals(getName());
- }
-
- public String getName() { return "ConstantValue"; }
-
- // Follows javap output format for ConstantValue attribute.
- /*@Override*/ public String toString() {
- StringBuffer buf = new StringBuffer(" Constant value: ");
- buf.append(pool.lookupEntry(constantValueIndex));
- return buf.toString();
- }
-
- protected int getSize() {
- return 2; // Short.SIZE
- }
-
- protected void writeContentsTo(DataOutputStream stream) throws IOException {
- stream.writeShort(constantValueIndex);
- }
-}
diff --git a/src/fjbg/ch/epfl/lamp/fjbg/JEnclosingMethodAttribute.java b/src/fjbg/ch/epfl/lamp/fjbg/JEnclosingMethodAttribute.java
deleted file mode 100644
index f663f00ae1..0000000000
--- a/src/fjbg/ch/epfl/lamp/fjbg/JEnclosingMethodAttribute.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/* FJBG -- Fast Java Bytecode Generator
- * Copyright 2002-2013 LAMP/EPFL
- * @author Michel Schinz
- */
-
-package ch.epfl.lamp.fjbg;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-
-/**
- * EclosingMethod attribute
-
- * A class must have an EnclosingMethod attribute if and only if it is a
- * local class or an anonymous class. A class may have no more than one
- * EnclosingMethod attribute. See section 4.8.6 of the JVM specification.
- *
- * @author Michel Schinz
- * @version 1.0
- */
-
-public class JEnclosingMethodAttribute extends JAttribute {
- /** Constant pool of the current classfile. */
- private JConstantPool pool;
-
- protected final int classIdx;
- protected final int nameAndTypeIdx;
-
- public JEnclosingMethodAttribute(FJBGContext context,
- JClass clazz,
- String className,
- String methodName,
- JType methodType) {
- super(context, clazz);
- this.pool = clazz.pool;
-
- this.classIdx = pool.addClass(className);
- this.nameAndTypeIdx = pool.addNameAndType(methodName, methodType.getSignature());
- }
-
- public JEnclosingMethodAttribute(FJBGContext context,
- JClass clazz,
- Object owner,
- String name,
- int size,
- DataInputStream stream)
- throws IOException {
- super(context, clazz, name);
- this.pool = clazz.pool;
-
- this.classIdx = stream.readShort();
- this.nameAndTypeIdx = stream.readShort();
-
- assert name.equals(getName());
- }
-
- public String getName() { return "EnclosingMethod"; }
-
- // Follows javap output format for EnclosingMethod attribute.
- /*@Override*/ public String toString() {
- StringBuffer buf = new StringBuffer(" EnclosingMethod:");
- buf.append("\n #");
- buf.append(classIdx);
- if (nameAndTypeIdx != 0) {
- buf.append(" of #");
- buf.append(nameAndTypeIdx);
- }
- buf.append(";\t// ");
- buf.append(pool.lookupEntry(classIdx));
- buf.append("\n");
- return buf.toString();
- }
-
- protected int getSize() {
- return 4; // 2 * Short.SIZE
- }
-
- protected void writeContentsTo(DataOutputStream stream) throws IOException {
- stream.writeShort(classIdx);
- stream.writeShort(nameAndTypeIdx);
- }
-}
diff --git a/src/fjbg/ch/epfl/lamp/fjbg/JExceptionsAttribute.java b/src/fjbg/ch/epfl/lamp/fjbg/JExceptionsAttribute.java
deleted file mode 100644
index b91d0f2e93..0000000000
--- a/src/fjbg/ch/epfl/lamp/fjbg/JExceptionsAttribute.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/* FJBG -- Fast Java Bytecode Generator
- * Copyright 2002-2013 LAMP/EPFL
- * @author Michel Schinz
- */
-
-package ch.epfl.lamp.fjbg;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-
-/**
- * Exceptions attribute
-
- * This table is used by compilers to indicate which Exceptions a method
- * is declared to throw. See section 2.6.4 of the JVM specification.
- *
- * @author Stephane Micheloud
- * @version 1.0
- */
-
-public class JExceptionsAttribute extends JAttribute {
- /** Constant pool of the current classfile. */
- private JConstantPool pool;
-
- protected int[] indexTable;
- protected int count;
-
- public JExceptionsAttribute(FJBGContext context,
- JClass clazz,
- JMethod owner) {
- super(context, clazz);
- this.pool = clazz.pool;
-
- this.count = 0;
- this.indexTable = new int[8]; // some size > count
-
- assert clazz == owner.getOwner();
- }
-
- public JExceptionsAttribute(FJBGContext context,
- JClass clazz,
- Object owner, //JMethod
- String name,
- int size,
- DataInputStream stream)
- throws IOException {
- super(context, clazz, name);
- this.pool = clazz.pool;
-
- this.count = stream.readShort();
- this.indexTable = new int[count];
- for (int i = 0; i < count; ++i)
- indexTable[i] = stream.readShort();
-
- assert name.equals(getName());
- }
-
- public void addEntry(int classIndex) {
- if (count >= indexTable.length) {
- int[] newIT = new int[indexTable.length * 2];
- System.arraycopy(indexTable, 0, newIT, 0, indexTable.length);
- indexTable = newIT;
- }
- indexTable[count++] = classIndex;
- }
-
- public String getName() { return "Exceptions"; }
-
- // Follows javap output format for Exceptions attribute.
- /*@Override*/ public String toString() {
- StringBuffer buf = new StringBuffer(" Exceptions: ");
- for (int i = 0; i < indexTable.length; ++i) {
- buf.append("\n throws ");
- buf.append(JClass.toExternalName(pool.lookupClass(indexTable[i])));
- }
- buf.append("\n");
- return buf.toString();
- }
-
- protected int getSize() {
- return 2 + indexTable.length * 2;
- }
-
- protected void writeContentsTo(DataOutputStream stream) throws IOException {
- stream.writeShort(count);
- for (int i = 0; i < count; ++i)
- stream.writeShort(indexTable[i]);
- }
-}
diff --git a/src/fjbg/ch/epfl/lamp/fjbg/JExtendedCode.java b/src/fjbg/ch/epfl/lamp/fjbg/JExtendedCode.java
deleted file mode 100644
index d82db8289f..0000000000
--- a/src/fjbg/ch/epfl/lamp/fjbg/JExtendedCode.java
+++ /dev/null
@@ -1,667 +0,0 @@
-/* FJBG -- Fast Java Bytecode Generator
- * Copyright 2002-2013 LAMP/EPFL
- * @author Michel Schinz
- */
-
-package ch.epfl.lamp.fjbg;
-
-/**
- * Extended list of instructions, providing pseudo-instructions which
- * are easier to use than the standard ones.
- *
- * @author Michel Schinz, Thomas Friedli
- * @version 1.0
- */
-
-public class JExtendedCode extends JCode {
- public final static int COND_EQ = 0;
- public final static int COND_NE = 1;
- public final static int COND_LT = 2;
- public final static int COND_GE = 3;
- public final static int COND_GT = 4;
- public final static int COND_LE = 5;
-
- private final JOpcode[] forbidden = new JOpcode[0];
- private final JOpcode[] nothingToDo = new JOpcode[0];
-
- private final JOpcode[][][] typeConversions = {
- {
- /* T_BOOLEAN -> T_BOOLEAN */ nothingToDo,
- /* T_BOOLEAN -> T_CHAR */ forbidden,
- /* T_BOOLEAN -> T_FLOAT */ forbidden,
- /* T_BOOLEAN -> T_DOUBLE */ forbidden,
- /* T_BOOLEAN -> T_BYTE */ forbidden,
- /* T_BOOLEAN -> T_SHORT */ forbidden,
- /* T_BOOLEAN -> T_INT */ forbidden,
- /* T_BOOLEAN -> T_LONG */ forbidden
- },
- {
- /* T_CHAR -> T_BOOLEAN */ forbidden,
- /* T_CHAR -> T_CHAR */ nothingToDo,
- /* T_CHAR -> T_FLOAT */ {JOpcode.I2F},
- /* T_CHAR -> T_DOUBLE */ {JOpcode.I2D},
- /* T_CHAR -> T_BYTE */ {JOpcode.I2B},
- /* T_CHAR -> T_SHORT */ {JOpcode.I2S},
- /* T_CHAR -> T_INT */ nothingToDo,
- /* T_CHAR -> T_LONG */ {JOpcode.I2L}
- },
- {
- /* T_FLOAT -> T_BOOLEAN */ forbidden,
- /* T_FLOAT -> T_CHAR */ {JOpcode.F2I, JOpcode.I2C},
- /* T_FLOAT -> T_FLOAT */ nothingToDo,
- /* T_FLOAT -> T_DOUBLE */ {JOpcode.F2D},
- /* T_FLOAT -> T_BYTE */ {JOpcode.F2I, JOpcode.I2B},
- /* T_FLOAT -> T_SHORT */ {JOpcode.F2I, JOpcode.I2S},
- /* T_FLOAT -> T_INT */ {JOpcode.F2I},
- /* T_FLOAT -> T_LONG */ {JOpcode.F2L}
- },
- {
- /* T_DOUBLE -> T_BOOLEAN */ forbidden,
- /* T_DOUBLE -> T_CHAR */ {JOpcode.D2I, JOpcode.I2C},
- /* T_DOUBLE -> T_FLOAT */ {JOpcode.D2F},
- /* T_DOUBLE -> T_DOUBLE */ nothingToDo,
- /* T_DOUBLE -> T_BYTE */ {JOpcode.D2I, JOpcode.I2B},
- /* T_DOUBLE -> T_SHORT */ {JOpcode.D2I, JOpcode.I2S},
- /* T_DOUBLE -> T_INT */ {JOpcode.D2I},
- /* T_DOUBLE -> T_LONG */ {JOpcode.D2L}
- },
- {
- /* T_BYTE -> T_BOOLEAN */ forbidden,
- /* T_BYTE -> T_CHAR */ {JOpcode.I2C},
- /* T_BYTE -> T_FLOAT */ {JOpcode.I2F},
- /* T_BYTE -> T_DOUBLE */ {JOpcode.I2D},
- /* T_BYTE -> T_BYTE */ nothingToDo,
- /* T_BYTE -> T_SHORT */ nothingToDo,
- /* T_BYTE -> T_INT */ nothingToDo,
- /* T_BYTE -> T_LONG */ {JOpcode.I2L}
- },
- {
- /* T_SHORT -> T_BOOLEAN */ forbidden,
- /* T_SHORT -> T_CHAR */ {JOpcode.I2C},
- /* T_SHORT -> T_FLOAT */ {JOpcode.I2F},
- /* T_SHORT -> T_DOUBLE */ {JOpcode.I2D},
- /* T_SHORT -> T_BYTE */ {JOpcode.I2B},
- /* T_SHORT -> T_SHORT */ nothingToDo,
- /* T_SHORT -> T_INT */ nothingToDo,
- /* T_SHORT -> T_LONG */ {JOpcode.I2L}
- },
- {
- /* T_INT -> T_BOOLEAN */ forbidden,
- /* T_INT -> T_CHAR */ {JOpcode.I2C},
- /* T_INT -> T_FLOAT */ {JOpcode.I2F},
- /* T_INT -> T_DOUBLE */ {JOpcode.I2D},
- /* T_INT -> T_BYTE */ {JOpcode.I2B},
- /* T_INT -> T_SHORT */ {JOpcode.I2S},
- /* T_INT -> T_INT */ nothingToDo,
- /* T_INT -> T_LONG */ {JOpcode.I2L}
- },
- {
- /* T_LONG -> T_BOOLEAN */ forbidden,
- /* T_LONG -> T_CHAR */ {JOpcode.L2I, JOpcode.I2C},
- /* T_LONG -> T_FLOAT */ {JOpcode.L2F},
- /* T_LONG -> T_DOUBLE */ {JOpcode.L2D},
- /* T_LONG -> T_BYTE */ {JOpcode.L2I, JOpcode.I2B},
- /* T_LONG -> T_SHORT */ {JOpcode.L2I, JOpcode.I2S},
- /* T_LONG -> T_INT */ {JOpcode.L2I},
- /* T_LONG -> T_LONG */ nothingToDo
- }
- };
-
- public JExtendedCode(FJBGContext context,
- JClass clazz,
- JMethod owner) {
- super(context, clazz, owner);
- }
-
- public void emitPUSH(boolean value) { emitPUSH(value ? 1 : 0); }
- public void emitPUSH(Boolean value) { emitPUSH(value.booleanValue()); }
-
- public void emitPUSH(byte value) {
- switch (value) {
- case -1: emitICONST_M1(); break;
- case 0: emitICONST_0(); break;
- case 1: emitICONST_1(); break;
- case 2: emitICONST_2(); break;
- case 3: emitICONST_3(); break;
- case 4: emitICONST_4(); break;
- case 5: emitICONST_5(); break;
- default:
- emitBIPUSH(value);
- }
- }
- public void emitPUSH(Byte value) { emitPUSH(value.byteValue()); }
-
- public void emitPUSH(short value) {
- switch (value) {
- case -1: emitICONST_M1(); break;
- case 0: emitICONST_0(); break;
- case 1: emitICONST_1(); break;
- case 2: emitICONST_2(); break;
- case 3: emitICONST_3(); break;
- case 4: emitICONST_4(); break;
- case 5: emitICONST_5(); break;
- default:
- if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE)
- emitBIPUSH((byte)value);
- else
- emitSIPUSH(value);
- }
- }
- public void emitPUSH(Short value) { emitPUSH(value.shortValue()); }
-
- // TODO check that we do the right thing here
- public void emitPUSH(char value) { emitPUSH((int)value); }
- public void emitPUSH(Character value) { emitPUSH(value.charValue()); }
-
- public void emitPUSH(int value) {
- switch (value) {
- case -1: emitICONST_M1(); break;
- case 0: emitICONST_0(); break;
- case 1: emitICONST_1(); break;
- case 2: emitICONST_2(); break;
- case 3: emitICONST_3(); break;
- case 4: emitICONST_4(); break;
- case 5: emitICONST_5(); break;
- default:
- if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE)
- emitBIPUSH((byte)value);
- else if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE)
- emitSIPUSH((short)value);
- else
- emitPUSH_index(pool.addInteger(value));
- break;
- }
- }
- public void emitPUSH(Integer value) { emitPUSH(value.intValue()); }
-
- public void emitPUSH(long value) {
- if (value == 0L)
- emitLCONST_0();
- else if (value == 1L)
- emitLCONST_1();
- else
- emitLDC2_W(value);
- }
- public void emitPUSH(Long value) { emitPUSH(value.longValue()); }
-
- private static final Float ZEROF = Float.valueOf(0f);
- private static final Float ONEF = Float.valueOf(1f);
- private static final Float TWOF = Float.valueOf(2f);
- public void emitPUSH(Float value) {
- if (ZEROF.equals(value))
- emitFCONST_0();
- else if (ONEF.equals(value))
- emitFCONST_1();
- else if (TWOF.equals(value))
- emitFCONST_2();
- else
- emitPUSH_index(pool.addFloat(value.floatValue()));
- }
- public void emitPUSH(float value) { emitPUSH(Float.valueOf(value)); }
-
- private static final Double ZEROD = Double.valueOf(0d);
- private static final Double ONED = Double.valueOf(1d);
- public void emitPUSH(Double value) {
- if (ZEROD.equals(value))
- emitDCONST_0();
- else if (ONED.equals(value))
- emitDCONST_1();
- else
- emitLDC2_W(value.doubleValue());
- }
- public void emitPUSH(double value) { emitPUSH(Double.valueOf(value)); }
-
- public void emitPUSH(String s) {
- emitPUSH_index(pool.addString(s));
- }
-
- /** Pushes a class literal on the stack */
- public void emitPUSH(JReferenceType type) {
- assert owner.owner.major >= 49;
- emitPUSH_index(pool.addClass(type.getDescriptor()));
- }
-
- protected void emitPUSH_index(int index) {
- if (index <= 0xFF)
- emitU1(JOpcode.LDC, index);
- else
- emitU2(JOpcode.LDC_W, index);
- }
-
- public void emitLOAD(int index, JType type) {
- JOpcode opcode;
-
- switch (type.getTag()) {
- case JType.T_BOOLEAN: case JType.T_BYTE: case JType.T_CHAR:
- case JType.T_SHORT: case JType.T_INT:
- switch (index) {
- case 0: emitILOAD_0(); return;
- case 1: emitILOAD_1(); return;
- case 2: emitILOAD_2(); return;
- case 3: emitILOAD_3(); return;
- default: opcode = JOpcode.ILOAD;
- } break;
- case JType.T_FLOAT:
- switch (index) {
- case 0: emitFLOAD_0(); return;
- case 1: emitFLOAD_1(); return;
- case 2: emitFLOAD_2(); return;
- case 3: emitFLOAD_3(); return;
- default: opcode = JOpcode.FLOAD;
- } break;
- case JType.T_LONG:
- switch (index) {
- case 0: emitLLOAD_0(); return;
- case 1: emitLLOAD_1(); return;
- case 2: emitLLOAD_2(); return;
- case 3: emitLLOAD_3(); return;
- default: opcode = JOpcode.LLOAD;
- } break;
- case JType.T_DOUBLE:
- switch (index) {
- case 0: emitDLOAD_0(); return;
- case 1: emitDLOAD_1(); return;
- case 2: emitDLOAD_2(); return;
- case 3: emitDLOAD_3(); return;
- default: opcode = JOpcode.DLOAD;
- } break;
- case JType.T_ARRAY: case JType.T_OBJECT:
- switch (index) {
- case 0: emitALOAD_0(); return;
- case 1: emitALOAD_1(); return;
- case 2: emitALOAD_2(); return;
- case 3: emitALOAD_3(); return;
- default: opcode = JOpcode.ALOAD;
- } break;
- default:
- throw new IllegalArgumentException("invalid type for load "+type);
- }
-
- if (index > 0xFF)
- emitWIDE(opcode, index);
- else
- emitU1(opcode, index);
- }
- public void emitLOAD(JLocalVariable var) {
- emitLOAD(var.index, var.type);
- }
-
- public void emitSTORE(int index, JType type) {
- JOpcode opcode;
-
- switch (type.getTag()) {
- case JType.T_BOOLEAN: case JType.T_BYTE: case JType.T_CHAR:
- case JType.T_SHORT: case JType.T_INT:
- switch (index) {
- case 0: emitISTORE_0(); return;
- case 1: emitISTORE_1(); return;
- case 2: emitISTORE_2(); return;
- case 3: emitISTORE_3(); return;
- default: opcode = JOpcode.ISTORE;
- } break;
- case JType.T_FLOAT:
- switch (index) {
- case 0: emitFSTORE_0(); return;
- case 1: emitFSTORE_1(); return;
- case 2: emitFSTORE_2(); return;
- case 3: emitFSTORE_3(); return;
- default: opcode = JOpcode.FSTORE;
- } break;
- case JType.T_LONG:
- switch (index) {
- case 0: emitLSTORE_0(); return;
- case 1: emitLSTORE_1(); return;
- case 2: emitLSTORE_2(); return;
- case 3: emitLSTORE_3(); return;
- default: opcode = JOpcode.LSTORE;
- } break;
- case JType.T_DOUBLE:
- switch (index) {
- case 0: emitDSTORE_0(); return;
- case 1: emitDSTORE_1(); return;
- case 2: emitDSTORE_2(); return;
- case 3: emitDSTORE_3(); return;
- default: opcode = JOpcode.DSTORE;
- } break;
- case JType.T_ARRAY: case JType.T_OBJECT: case JType.T_ADDRESS:
- switch (index) {
- case 0: emitASTORE_0(); return;
- case 1: emitASTORE_1(); return;
- case 2: emitASTORE_2(); return;
- case 3: emitASTORE_3(); return;
- default: opcode = JOpcode.ASTORE;
- } break;
- default:
- throw new IllegalArgumentException("invalid type for store "+type);
- }
-
- if (index > 0xFF)
- emitWIDE(opcode, index);
- else
- emitU1(opcode, index);
- }
- public void emitSTORE(JLocalVariable var) {
- emitSTORE(var.index, var.type);
- }
-
- public void emitALOAD(JType type) {
- switch (type.getTag()) {
- case JType.T_BOOLEAN:
- case JType.T_BYTE:
- emitBALOAD();
- break;
- case JType.T_CHAR:
- emitCALOAD();
- break;
- case JType.T_SHORT:
- emitSALOAD();
- break;
- case JType.T_INT:
- emitIALOAD();
- break;
- case JType.T_FLOAT:
- emitFALOAD();
- break;
- case JType.T_LONG:
- emitLALOAD();
- break;
- case JType.T_DOUBLE:
- emitDALOAD();
- break;
- case JType.T_ARRAY:
- case JType.T_OBJECT:
- emitAALOAD();
- break;
- default:
- throw new IllegalArgumentException("invalid type for aload " + type);
- }
- }
-
- public void emitASTORE(JType type) {
- switch (type.getTag()) {
- case JType.T_BOOLEAN:
- case JType.T_BYTE:
- emitBASTORE();
- break;
- case JType.T_CHAR:
- emitCASTORE();
- break;
- case JType.T_SHORT:
- emitSASTORE();
- break;
- case JType.T_INT:
- emitIASTORE();
- break;
- case JType.T_FLOAT:
- emitFASTORE();
- break;
- case JType.T_LONG:
- emitLASTORE();
- break;
- case JType.T_DOUBLE:
- emitDASTORE();
- break;
- case JType.T_ARRAY:
- case JType.T_OBJECT:
- emitAASTORE();
- break;
- default:
- throw new IllegalArgumentException("invalid type for astore " + type);
- }
- }
-
- public void emitRETURN(JType type) {
- if (type.isValueType()) {
- switch (type.getTag()) {
- case JType.T_BOOLEAN:
- case JType.T_BYTE:
- case JType.T_CHAR:
- case JType.T_SHORT:
- case JType.T_INT:
- emitIRETURN();
- break;
- case JType.T_FLOAT:
- emitFRETURN();
- break;
- case JType.T_LONG:
- emitLRETURN();
- break;
- case JType.T_DOUBLE:
- emitDRETURN();
- break;
- }
- } else if (type.isArrayType() || type.isObjectType())
- emitARETURN();
- else if (type == JType.VOID)
- emitRETURN();
- else
- throw new IllegalArgumentException("invalid type for RETURN " + type);
- }
-
- public void emitADD(JType type) {
- switch (type.getTag()) {
- case JType.T_BOOLEAN: case JType.T_BYTE: case JType.T_CHAR:
- case JType.T_SHORT: case JType.T_INT:
- emitIADD(); break;
- case JType.T_FLOAT:
- emitFADD(); break;
- case JType.T_LONG:
- emitLADD(); break;
- case JType.T_DOUBLE:
- emitDADD(); break;
- }
- }
-
- /**
- * Emits a basic type conversion instruction choosen according to the
- * types given in parameter.
- *
- * @param fromType The type of the value to be cast into another type.
- * @param toType The type the value will be cast into.
- */
- public void emitT2T(JType fromType, JType toType) {
- assert fromType.getTag() >= JType.T_BOOLEAN
- && fromType.getTag() <= JType.T_LONG
- && toType.getTag() >= JType.T_BOOLEAN
- && toType.getTag() <= JType.T_LONG;
-
- JOpcode[] conv = typeConversions[fromType.getTag() - 4][toType.getTag() - 4];
- if (conv == forbidden) {
- throw new Error("inconvertible types : " + fromType.toString()
- + " -> " + toType.toString());
- } else if (conv != nothingToDo) {
- for (int i = 0; i < conv.length; i++) {
- emit(conv[i]);
- }
- }
- }
-
- public void emitIF(int cond, Label label) throws OffsetTooBigException {
- assert cond >= COND_EQ && cond <= COND_LE;
- emitU2(JOpcode.OPCODES[153 + cond], label.getOffset16(getPC() + 1, getPC()));
- }
- public void emitIF(int cond, int targetPC) throws OffsetTooBigException {
- int offset = targetPC - getPC();
- emitU2(JOpcode.OPCODES[153 + cond], offset);
- }
- public void emitIF(int cond) throws OffsetTooBigException {
- emitIF(cond, 0);
- }
-
- public void emitIF_ICMP(int cond, Label label) throws OffsetTooBigException {
- assert cond >= COND_EQ && cond <= COND_LE;
- emitU2(JOpcode.OPCODES[159 + cond], label.getOffset16(getPC() + 1, getPC()));
- }
- public void emitIF_ICMP(int cond, int targetPC) throws OffsetTooBigException {
- int offset = targetPC - getPC();
- emitU2(JOpcode.OPCODES[159 + cond], offset);
- }
- public void emitIF_ICMP(int cond) throws OffsetTooBigException {
- emitIF_ICMP(cond, 0);
- }
-
- public void emitIF_ACMP(int cond, Label label) throws OffsetTooBigException {
- assert cond == COND_EQ || cond == COND_NE;
- emitU2(JOpcode.OPCODES[165 + cond], label.getOffset16(getPC() + 1, getPC()));
- }
- public void emitIF_ACMP(int cond, int targetPC) throws OffsetTooBigException {
- int offset = targetPC - getPC();
- emitU2(JOpcode.OPCODES[165 + cond], offset);
- }
- public void emitIF_ACMP(int cond) throws OffsetTooBigException {
- emitIF_ACMP(cond, 0);
- }
-
- public void emitGOTO_maybe_W(Label label, boolean defaultToWide) {
- if (label.anchored)
- emitGOTO_maybe_W(label.targetPC);
- else {
- if (defaultToWide)
- emitGOTO_W(label);
- else {
- try {
- emitGOTO(label);
- } catch (OffsetTooBigException e) {
- throw new Error(e);
- }
- }
- }
- }
-
- public void emitGOTO_maybe_W(int targetPC) {
- int offset = targetPC - (getPC() + 1);
- if (offset < Short.MIN_VALUE || offset > Short.MAX_VALUE)
- emitGOTO_W(targetPC);
- else {
- try {
- emitGOTO(targetPC);
- } catch (OffsetTooBigException e) {
- throw new Error(e);
- }
- }
- }
-
- /**
- * Emits a switch instruction choosen according to the caracteristics
- * of the given list of keys and a default maxRate.
- *
- * @param keySets The array of all keys that must be compared to the
- * value on stack.
- * @param branches The labels representing the jump addresses linked
- * with the corresponding keys.
- * @param defaultBranch The label representing the default branch
- * address.
- */
- public void emitSWITCH(int[][] keySets,
- Label[] branches,
- Label defaultBranch,
- double minDensity) {
- assert keySets.length == branches.length;
-
- int flatSize = 0;
- for (int i = 0; i < keySets.length; ++i)
- flatSize += keySets[i].length;
-
- int[] flatKeys = new int[flatSize];
- Label[] flatBranches = new Label[flatSize];
- int flatI = 0;
- for (int i = 0; i < keySets.length; ++i) {
- Label branch = branches[i];
- int[] keys = keySets[i];
- for (int j = 0; j < keys.length; ++j) {
- flatKeys[flatI] = keys[j];
- flatBranches[flatI] = branch;
- }
- ++flatI;
- }
- assert flatI == flatSize;
- emitSWITCH(flatKeys, flatBranches, defaultBranch, minDensity);
- }
-
- /**
- * Emits a switch instruction choosen according to the caracteristics
- * of the given list of keys and a given maxRate.
- *
- * @param keys The array of all keys that must be compared to the
- * value on stack.
- * @param branches The labels representing the jump addresses linked
- * with the corresponding keys.
- * @param defaultBranch The label representing the default branch
- * address.
- * @param minDensity The minimum density to use for TABLESWITCH.
- */
- public void emitSWITCH(int[] keys,
- Label[] branches,
- Label defaultBranch,
- double minDensity) {
- assert keys.length == branches.length;
-
- //The special case for empty keys. It makes sense to allow
- //empty keys and generate LOOKUPSWITCH with defaultBranch
- //only. This is exactly what javac does for switch statement
- //that has only a default case.
- if (keys.length == 0) {
- emitLOOKUPSWITCH(keys, branches, defaultBranch);
- return;
- }
- //the rest of the code assumes that keys.length > 0
-
- // sorting the tables
- // FIXME use quicksort
- for (int i = 1; i < keys.length; i++) {
- for (int j = 1; j <= keys.length - i; j++) {
- if (keys[j] < keys[j - 1]) {
- int tmp = keys[j];
- keys[j] = keys[j - 1];
- keys[j - 1] = tmp;
-
- Label tmp_l = branches[j];
- branches[j] = branches[j - 1];
- branches[j - 1] = tmp_l;
- }
- }
- }
-
- int keyMin = keys[0], keyMax = keys[keys.length - 1];
- /** Calculate in long to guard against overflow. */
- long keyRange = (long)keyMax - keyMin + 1;
- if ((double)keys.length / (double)keyRange >= minDensity) {
- // Keys are dense enough, use a table in which holes are
- // filled with defaultBranch.
- int[] newKeys = new int[(int)keyRange];
- Label[] newBranches = new Label[(int)keyRange];
- int oldPos = 0;
- for (int i = 0; i < keyRange; ++i) {
- int key = keyMin + i;
- newKeys[i] = key;
- if (keys[oldPos] == key) {
- newBranches[i] = branches[oldPos];
- ++oldPos;
- } else
- newBranches[i] = defaultBranch;
- }
- assert oldPos == keys.length;
- emitTABLESWITCH(newKeys, newBranches, defaultBranch);
- } else
- emitLOOKUPSWITCH(keys, branches, defaultBranch);
- }
-
- /**
- * Emits a method invocation instruction choosen according to
- * the caracteristics of the given method.
- *
- * @param method The method to be invoked.
- */
- public void emitINVOKE(JMethod method) {
- String mName = method.getName();
- String cName = method.getOwner().getName();
- JMethodType mType = (JMethodType)method.getType();
- if (method.isStatic())
- emitINVOKESTATIC(cName, mName, mType);
- else if (method.getOwner().isInterface())
- emitINVOKEINTERFACE(cName, mName, mType);
- else
- emitINVOKEVIRTUAL(cName, mName, mType);
- }
-
-}
diff --git a/src/fjbg/ch/epfl/lamp/fjbg/JField.java b/src/fjbg/ch/epfl/lamp/fjbg/JField.java
deleted file mode 100644
index 29d826ba99..0000000000
--- a/src/fjbg/ch/epfl/lamp/fjbg/JField.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/* FJBG -- Fast Java Bytecode Generator
- * Copyright 2002-2013 LAMP/EPFL
- * @author Michel Schinz
- */
-
-package ch.epfl.lamp.fjbg;
-
-import java.io.DataInputStream;
-import java.io.IOException;
-
-/**
- * Java class field.
- *
- * @author Michel Schinz
- * @version 1.0
- */
-
-public class JField extends JFieldOrMethod {
-
- protected JField(FJBGContext context,
- JClass owner,
- int accessFlags,
- String name,
- JType type) {
- super(context, owner, accessFlags, name, type);
- }
-
- protected JField(FJBGContext context,
- JClass owner,
- DataInputStream stream)
- throws IOException {
- super(context, owner, stream);
- }
-
- // Follows javap output format for fields.
- /*@Override*/ public String toString() {
- StringBuffer buf = new StringBuffer(flagsToString());
- buf.append(toExternalName(getType()));
- buf.append(" ");
- buf.append(getName());
- buf.append(";\n");
- java.util.Iterator attrsIt = attributes.iterator();
- while (attrsIt.hasNext()) {
- JAttribute attrs = (JAttribute)attrsIt.next();
- buf.append(attrs);
- }
- return buf.toString();
- }
-
- private String flagsToString() {
- StringBuffer buf = new StringBuffer();
- if (isPublic()) buf.append("public ");
- else if (isProtected()) buf.append("protected ");
- else if (isPrivate()) buf.append("private ");
- if (isStatic()) buf.append("static ");
- else if (isTransient()) buf.append("transient ");
- else if (isVolatile()) buf.append("volatile ");
- if (isAbstract()) buf.append("abstract ");
- else if (isFinal()) buf.append("final ");
- return buf.toString();
- }
-}
diff --git a/src/fjbg/ch/epfl/lamp/fjbg/JFieldOrMethod.java b/src/fjbg/ch/epfl/lamp/fjbg/JFieldOrMethod.java
deleted file mode 100644
index 794c0f13b5..0000000000
--- a/src/fjbg/ch/epfl/lamp/fjbg/JFieldOrMethod.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/* FJBG -- Fast Java Bytecode Generator
- * Copyright 2002-2013 LAMP/EPFL
- * @author Michel Schinz
- */
-
-package ch.epfl.lamp.fjbg;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-
-/**
- * Abstract superclass for a Java field or method.
- *
- * No two methods of fields in one class file may have the same name and
- * descriptor. See sections 4.6 and 4.7 of the JVM specification.
- *
- * @author Michel Schinz
- * @version 1.0
- */
-
-abstract public class JFieldOrMethod extends JMember {
-
- protected final JClass owner;
- protected final JType type;
-
- protected final int nameIndex, signatureIndex;
-
- protected JFieldOrMethod(FJBGContext context,
- JClass owner,
- int accessFlags,
- String name,
- JType type) {
- super(context, accessFlags, name);
- this.owner = owner;
- this.type = type;
-
- nameIndex = owner.pool.addUtf8(name);
- signatureIndex = owner.pool.addUtf8(type.getSignature());
- }
-
- protected JFieldOrMethod(FJBGContext context,
- JClass owner,
- DataInputStream stream)
- throws IOException {
- super(context);
- this.owner = owner;
- this.accessFlags = stream.readShort();
- this.nameIndex = stream.readShort();
- this.name = owner.pool.lookupUtf8(nameIndex);
- this.signatureIndex = stream.readShort();
- this.type = JType.parseSignature(owner.pool.lookupUtf8(signatureIndex));
- this.attributes.addAll(JAttribute.readFrom(context, owner, this, stream));
- }
-
- public void freeze() throws JCode.OffsetTooBigException {
- assert !frozen;
- frozen = true;
- }
-
- public JClass getOwner() { return owner; }
-
- public JType getType() { return type; }
-
- public JClass getJClass() { return owner; }
-
- public boolean isPublic() {
- return (accessFlags & JAccessFlags.ACC_PUBLIC) != 0;
- }
-
- public boolean isPrivate() {
- return (accessFlags & JAccessFlags.ACC_PRIVATE) != 0;
- }
-
- public boolean isProtected() {
- return (accessFlags & JAccessFlags.ACC_PROTECTED) != 0;
- }
-
- public boolean isStatic() {
- return (accessFlags & JAccessFlags.ACC_STATIC) != 0;
- }
-
- public boolean isFinal() {
- return (accessFlags & JAccessFlags.ACC_FINAL) != 0;
- }
-
- public boolean isSuper() {
- return (accessFlags & JAccessFlags.ACC_SUPER) != 0;
- }
-
- public boolean isVolatile() {
- return (accessFlags & JAccessFlags.ACC_VOLATILE) != 0;
- }
-
- public boolean isTransient() {
- return (accessFlags & JAccessFlags.ACC_TRANSIENT) != 0;
- }
-
- public boolean isNative() {
- return (accessFlags & JAccessFlags.ACC_NATIVE) != 0;
- }
-
- public boolean isInterface() {
- return (accessFlags & JAccessFlags.ACC_INTERFACE) != 0;
- }
-
- public boolean isAbstract() {
- return (accessFlags & JAccessFlags.ACC_ABSTRACT) != 0;
- }
-
- public boolean isStrict() {
- return (accessFlags & JAccessFlags.ACC_STRICT) != 0;
- }
-
- // 1.5 specifics
- public boolean isBridge() {
- return (accessFlags & JAccessFlags.ACC_BRIDGE) != 0;
- }
-
- public boolean hasVarargs() {
- return (accessFlags & JAccessFlags.ACC_VARARGS) != 0;
- }
-
- public void writeTo(DataOutputStream stream) throws IOException {
- if (! frozen) {
- try {
- freeze();
- }
- catch (JCode.OffsetTooBigException e) {
- throw new Error(e);
- }
- }
- stream.writeShort(accessFlags);
- stream.writeShort(nameIndex);
- stream.writeShort(signatureIndex);
- JAttribute.writeTo(getAttributes(), stream);
- }
-}
diff --git a/src/fjbg/ch/epfl/lamp/fjbg/JInnerClassesAttribute.java b/src/fjbg/ch/epfl/lamp/fjbg/JInnerClassesAttribute.java
deleted file mode 100644
index 1c1ced500d..0000000000
--- a/src/fjbg/ch/epfl/lamp/fjbg/JInnerClassesAttribute.java
+++ /dev/null
@@ -1,201 +0,0 @@
-/* FJBG -- Fast Java Bytecode Generator
- * Copyright 2002-2013 LAMP/EPFL
- * @author Michel Schinz
- */
-
-package ch.epfl.lamp.fjbg;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-/**
- * InnerClasses attribute.
- *
- * The ClassFile structure of a class/interface C must have exactly one
- * InnerClasses attribute in its attributes table if the constant pool of C
- * contains a CONSTANT_Class_info entry which represents a class or interface
- * that is not a member of a package. See section 4.8.5 of the JVM Specification.
- *
- * @author Iulian Dragos, Stephane Micheloud
- * @version 1.1
- */
-public class JInnerClassesAttribute extends JAttribute {
- /** Constant pool of the current classfile. */
- private JConstantPool pool;
-
- /** InnerClass entries */
- private Map/*<String, Entry>*/ entries = new LinkedHashMap();
-
- public JInnerClassesAttribute(FJBGContext context, JClass clazz) {
- super(context, clazz);
- this.pool = clazz.pool;
- }
-
- public JInnerClassesAttribute(FJBGContext context,
- JClass clazz,
- Object owner,
- String name,
- int size,
- DataInputStream stream)
- throws IOException {
- super(context, clazz, name);
- this.pool = clazz.pool;
-
- String inner = null;
- int count = stream.readShort();
- for (int i = 0; i < count; ++i) {
- int innerIdx = stream.readShort();
- int outerIdx = stream.readShort();
- int nameIdx = stream.readShort();
- int flags = stream.readShort();
- inner = pool.lookupClass(innerIdx);
- entries.put(inner, new Entry(innerIdx, outerIdx, nameIdx, flags));
- }
-
- assert name.equals(getName());
- }
-
- public void addEntry(String inner, String outer, String name, int flags) {
- int innerIdx = pool.addClass(inner);
- int outerIdx = 0;
- if (outer != null) outerIdx = pool.addClass(outer);
- int nameIdx = 0;
- if (name != null) nameIdx = pool.addUtf8(name);
-
- Entry e = new Entry(innerIdx, outerIdx, nameIdx, flags);
-
- if (entries.containsKey(inner)) {
- Entry other = (Entry) entries.get(inner);
- assert other.outerInfo == e.outerInfo && other.originalName == e.originalName && other.innerFlags == e.innerFlags
- : inner + " already declared as " + other;
- } else
- entries.put(inner, e);
- }
-
- public String getName() { return "InnerClasses"; }
-
- // Follows javap output format for the InnerClass attribute.
- /*@Override*/ public String toString() {
- // Here we intentionally use "InnerClass" as javap :-(
- StringBuffer buf = new StringBuffer(" InnerClass: ");
- for (Iterator it = entries.values().iterator(); it.hasNext(); ) {
- Entry e = (Entry)it.next();
- buf.append("\n ");
- buf.append(e.innerFlagsToString());
- buf.append("#");
- if (e.originalName != 0) {
- buf.append(e.originalName);
- buf.append("= #");
- }
- buf.append(e.innerInfo);
- if (e.outerInfo != 0) {
- buf.append(" of #");
- buf.append(e.outerInfo);
- }
- buf.append("; //");
- if (e.originalName != 0) {
- buf.append(pool.lookupUtf8(e.originalName));
- buf.append("=");
- }
- buf.append("class ");
- buf.append(pool.lookupClass(e.innerInfo));
- if (e.outerInfo != 0) {
- buf.append(" of class ");
- buf.append(pool.lookupClass(e.outerInfo));
- }
- }
- buf.append("\n");
- return buf.toString();
- }
-
- protected int getSize() {
- return 2 + entries.size() * 8;
- }
-
- protected void writeContentsTo(DataOutputStream stream) throws IOException {
- stream.writeShort(entries.size());
- for (Iterator it = entries.values().iterator(); it.hasNext(); ) {
- Entry e = (Entry)it.next();
- stream.writeShort(e.innerInfo);
- stream.writeShort(e.outerInfo);
- stream.writeShort(e.originalName);
- stream.writeShort(e.innerFlags);
- }
- }
-
- /** An entry in the InnerClasses attribute, as defined by the JVM Spec. */
- private class Entry {
- /** CONSTANT_Class_info index in the pool for the inner class (mangled). */
- int innerInfo;
-
- /** CONSTANT_Class_info index in the pool for the outer class (mangled). */
- int outerInfo;
-
- /** CONSTANT_Utf8_info index in the pool for the original name of the inner class. */
- int originalName;
-
- /** Short int for modifier flags. */
- int innerFlags;
-
- public Entry(int iI, int oI, int oN, int f) {
- this.innerInfo = iI;
- this.outerInfo = oI;
- this.originalName = oN;
- this.innerFlags = f;
- }
-
- public Entry(String innerClass, String outerClass, String name, int flags) {
- this(pool.addClass(innerClass), pool.addClass(outerClass), pool.addUtf8(name), flags);
- }
-
- /** Two entries are equal if they refer to the same inner class.
- * innerInfo represents a unique name (mangled).
- */
- public boolean equals(Object other) {
- if (other instanceof Entry) {
- Entry otherEntry = (Entry) other;
- return otherEntry.innerInfo == this.innerInfo;
- }
- return false;
- }
-
- public String innerFlagsToString() {
- StringBuffer buf = new StringBuffer();
- if (isPublic()) buf.append("public ");
- else if (isProtected()) buf.append("protected ");
- else if (isPrivate()) buf.append("private ");
- //if (isStatic()) buf.append("static "); // as javap
- if (isAbstract()) buf.append("abstract ");
- else if (isFinal()) buf.append("final ");
- return buf.toString();
- }
-
- private boolean isPublic() {
- return (innerFlags & JAccessFlags.ACC_PUBLIC) != 0;
- }
-
- private boolean isPrivate() {
- return (innerFlags & JAccessFlags.ACC_PRIVATE) != 0;
- }
-
- private boolean isProtected() {
- return (innerFlags & JAccessFlags.ACC_PROTECTED) != 0;
- }
-
- private boolean isStatic() {
- return (innerFlags & JAccessFlags.ACC_STATIC) != 0;
- }
-
- private boolean isFinal() {
- return (innerFlags & JAccessFlags.ACC_FINAL) != 0;
- }
-
- private boolean isAbstract() {
- return (innerFlags & JAccessFlags.ACC_ABSTRACT) != 0;
- }
- }
-}
diff --git a/src/fjbg/ch/epfl/lamp/fjbg/JLabel.java b/src/fjbg/ch/epfl/lamp/fjbg/JLabel.java
deleted file mode 100644
index 96f3b4ebef..0000000000
--- a/src/fjbg/ch/epfl/lamp/fjbg/JLabel.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/* FJBG -- Fast Java Bytecode Generator
- * Copyright 2002-2013 LAMP/EPFL
- * @author Michel Schinz
- */
-
-package ch.epfl.lamp.fjbg;
-
-/**
- * Labels which can be attached to instructions.
- *
- * @author Michel Schinz
- * @version 1.0
- */
-
-public class JLabel {
- public final static int UNDEFINED_ANCHOR = -1;
- protected int anchor = UNDEFINED_ANCHOR;
-
- public boolean isAnchored() { return anchor != UNDEFINED_ANCHOR; }
-
- public int getAnchor() {
- assert isAnchored();
- return anchor;
- }
-
- public void setAnchor(int anchor) {
- assert !isAnchored();
- this.anchor = anchor;
- }
-}
diff --git a/src/fjbg/ch/epfl/lamp/fjbg/JLineNumberTableAttribute.java b/src/fjbg/ch/epfl/lamp/fjbg/JLineNumberTableAttribute.java
deleted file mode 100644
index f8c09b8ef8..0000000000
--- a/src/fjbg/ch/epfl/lamp/fjbg/JLineNumberTableAttribute.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/* FJBG -- Fast Java Bytecode Generator
- * Copyright 2002-2013 LAMP/EPFL
- * @author Michel Schinz
- */
-
-package ch.epfl.lamp.fjbg;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-
-/**
- * Attribute storing correspondance between instructions and source
- * line numbers.
- *
- * @author Michel Schinz
- * @version 1.0
- */
-
-public class JLineNumberTableAttribute extends JAttribute {
- protected final JCode code;
-
- public JLineNumberTableAttribute(FJBGContext context,
- JClass clazz,
- JCode owner) {
- super(context, clazz);
- this.code = owner;
-
- assert owner.getOwner().getOwner() == clazz;
- }
-
- public JLineNumberTableAttribute(FJBGContext context,
- JClass clazz,
- Object owner,
- String name,
- int size,
- DataInputStream stream)
- throws IOException {
- super(context, clazz, name);
- this.code = (JCode)owner;
-
- int[] mapping = new int[code.getSize()];
-
- int count = stream.readShort();
- for (int i = 0; i < count; ++i) {
- int startPC = stream.readShort();
- int lineNum = stream.readShort();
- mapping[startPC] = lineNum;
- }
-
- // Avoids duplication of LineNumberTable attribute
- // (see method ensureLineNumberCapacity in class JCode).
- assert code.lineNumbers == null;
- code.lineNumbers = new int[0];
-
- int lineNum = 0;
- for (int pc = 0; pc < mapping.length; ++pc) {
- if (mapping[pc] != 0) lineNum = mapping[pc];
- if (lineNum != 0) code.setLineNumber(pc, lineNum);
- }
-
- assert name.equals(getName());
- }
-
- public String getName() { return "LineNumberTable"; }
-
- // Follows javap output format for LineNumberTable attribute.
- /*@Override*/ public String toString() {
- StringBuffer buf = new StringBuffer(" LineNumberTable: ");
- int[] encoding = encode();
- for (int i = 0; i < encoding.length/2; ++i) {
- buf.append("\n line ");
- buf.append(encoding[i * 2 + 1]);
- buf.append(": ");
- buf.append(encoding[i * 2]);
- }
- buf.append("\n");
- return buf.toString();
- }
-
- protected int[] encoding;
- protected int[] encode() {
- if (encoding == null) {
- int[] lineNumbers = code.getLineNumbers();
- int[] preEncoding = new int[lineNumbers.length * 2];
- int prevLineNum = 0;
-
- int i = 0;
- for (int pc = 0; pc < lineNumbers.length; ++pc) {
- int lineNum = lineNumbers[pc];
- if (lineNum != 0 & lineNum != prevLineNum) {
- preEncoding[i++] = pc;
- preEncoding[i++] = lineNum;
- prevLineNum = lineNum;
- }
- }
- if (i == preEncoding.length)
- encoding = preEncoding;
- else {
- encoding = new int[i];
- System.arraycopy(preEncoding, 0, encoding, 0, i);
- }
- }
- return encoding;
- }
-
- protected int getSize() {
- int[] encoding = encode();
- return 2 + encoding.length * 2;
- }
-
- protected void writeContentsTo(DataOutputStream stream) throws IOException {
- int[] encoding = encode();
- int entries = encoding.length / 2;
- stream.writeShort(entries);
- for (int i = 0; i < entries; ++i) {
- stream.writeShort(encoding[i * 2]);
- stream.writeShort(encoding[i * 2 + 1]);
- }
- }
-}
diff --git a/src/fjbg/ch/epfl/lamp/fjbg/JLocalVariable.java b/src/fjbg/ch/epfl/lamp/fjbg/JLocalVariable.java
deleted file mode 100644
index af7980656f..0000000000
--- a/src/fjbg/ch/epfl/lamp/fjbg/JLocalVariable.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/* FJBG -- Fast Java Bytecode Generator
- * Copyright 2002-2013 LAMP/EPFL
- * @author Michel Schinz
- */
-
-package ch.epfl.lamp.fjbg;
-
-/**
- * Representation of a local variable or method argument.
- *
- * @author Michel Schinz
- * @version 1.0
- */
-
-public class JLocalVariable {
- protected final JMethod owner;
- protected final JType type;
- protected final String name;
- protected final int index;
-
- protected JLocalVariable(FJBGContext context,
- JMethod owner,
- JType type,
- String name,
- int index) {
- this.owner = owner;
- this.type = type;
- this.name = name;
- this.index = index;
-
- assert index < 0xFFFF : "index too big for local variable: " + index;
- }
-
- public JMethod getOwner() { return owner; }
- public int getIndex() { return index; }
- public String getName() { return name; }
- public JType getType() { return type; }
-
- /*@Override*/ public String toString() {
- return "0\t"+type.getSize()+"\t"+index+"\t"+name+"\t"+type;
- }
-}
diff --git a/src/fjbg/ch/epfl/lamp/fjbg/JLocalVariableTableAttribute.java b/src/fjbg/ch/epfl/lamp/fjbg/JLocalVariableTableAttribute.java
deleted file mode 100644
index b277cc71c0..0000000000
--- a/src/fjbg/ch/epfl/lamp/fjbg/JLocalVariableTableAttribute.java
+++ /dev/null
@@ -1,167 +0,0 @@
-/* FJBG -- Fast Java Bytecode Generator
- * Copyright 2002-2013 LAMP/EPFL
- * @author Michel Schinz
- */
-
-package ch.epfl.lamp.fjbg;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.Iterator;
-import java.util.LinkedList;
-
-import ch.epfl.lamp.fjbg.JConstantPool.*;
-
-/**
- * Attribute storing local variables.
- *
- * @author Stephane Micheloud
- * @version 1.0
- */
-
-public class JLocalVariableTableAttribute extends JAttribute {
- /** Constant pool of the current classfile. */
- private JConstantPool pool;
-
- protected final LinkedList/*<Entry>*/ entries = new LinkedList();
- protected int localVariableIndex = 0;
-
- public JLocalVariableTableAttribute(FJBGContext context,
- JClass clazz,
- JCode code) {
- super(context, clazz);
- this.pool = clazz.pool;
-
- assert code.getOwner().getOwner() == clazz;
- }
-
- public JLocalVariableTableAttribute(FJBGContext context,
- JClass clazz,
- Object owner,
- String name,
- int size,
- DataInputStream stream)
- throws IOException {
- super(context, clazz, name);
- this.pool = clazz.pool;
-
- int count = stream.readShort();
- for (int i = 0; i < count; ++i) {
- int startPc = stream.readShort();
- int length = stream.readShort();
- int nameIndex = stream.readShort();
- int descIndex = stream.readShort();
- int index = stream.readShort();
- addEntry(startPc, length, nameIndex, descIndex, index);
- }
-
- assert name.equals(getName());
- }
-
- public void addEntry(int startPc, int length, int nameIndex,
- int descIndex, int index) {
- entries.add(new Entry(startPc, length, nameIndex, descIndex, index));
- }
-
- public void addEntry(int startPc, int length, String name,
- String desc, int index) {
- Entry e = new Entry(startPc, length, name, desc, index);
- Entry other = getEntry(index);
- if (other != null) {
- assert other.nameIndex == e.nameIndex && other.descIndex == e.descIndex
- : e + " already declared as " + other;
- } else
- entries.add(e);
- }
-
- public void addEntry(int startPc, int length, String name, String desc) {
- entries.add(new Entry(startPc, length, name, desc));
- }
-
- public String getName() { return "LocalVariableTable"; }
-
- // Follows javap output format for LocalVariableTable attribute.
- /*@Override*/ public String toString() {
- StringBuffer buf = new StringBuffer(" LocalVariableTable: ");
- buf.append("\n Start Length Slot Name Signature");
- for (Iterator it = entries.iterator(); it.hasNext(); ) {
- buf.append("\n ");
- Entry e = (Entry)it.next();
- Utf8Entry name = (Utf8Entry)pool.lookupEntry(e.nameIndex);
- Utf8Entry sig = (Utf8Entry)pool.lookupEntry(e.descIndex);
- buf.append(e.startPc);
- buf.append(" ");
- buf.append(e.length);
- buf.append(" ");
- buf.append(e.index);
- buf.append(" ");
- buf.append(name.getValue());
- buf.append(" ");
- buf.append(sig.getValue());
- }
- buf.append("\n");
- return buf.toString();
- }
-
- public int getMaxLocals() {
- return localVariableIndex;
- }
-
- public int getSize() {
- return 2 + entries.size() * 10;
- }
-
- protected void writeContentsTo(DataOutputStream stream) throws IOException {
- stream.writeShort(entries.size());
- for (Iterator it = entries.iterator(); it.hasNext(); ) {
- Entry e = (Entry)it.next();
- stream.writeShort(e.startPc);
- stream.writeShort(e.length);
- stream.writeShort(e.nameIndex);
- stream.writeShort(e.descIndex);
- stream.writeShort(e.index);
- }
- }
-
- private Entry getEntry(int index) {
- Entry e = null;
- try { e = (Entry)entries.get(index); } catch (Exception ex) {}
- return e;
- }
-
- private class Entry {
- int startPc;
- int length;
- int nameIndex;
- int descIndex;
- int index;
-
- public Entry(int startPc, int length, int nameIndex, int descIndex, int index) {
- this.startPc = startPc;
- this.length = length;
- this.nameIndex = nameIndex;
- this.descIndex = descIndex;
- this.index = index;
- localVariableIndex += length;
- }
-
- public Entry(int startPc, int length, String name, String desc, int index) {
- this(startPc, length, pool.addUtf8(name), pool.addUtf8(desc), index);
- }
-
- public Entry(int startPc, int length, String name, String desc) {
- this(startPc, length, pool.addUtf8(name), pool.addUtf8(desc), localVariableIndex);
- }
-
- /** Two entries are equal if they refer to the same index.
- */
- public boolean equals(Object other) {
- if (other instanceof Entry) {
- Entry otherEntry = (Entry) other;
- return otherEntry.index == this.index;
- }
- return false;
- }
- }
-}
diff --git a/src/fjbg/ch/epfl/lamp/fjbg/JMember.java b/src/fjbg/ch/epfl/lamp/fjbg/JMember.java
deleted file mode 100644
index 6356cc874d..0000000000
--- a/src/fjbg/ch/epfl/lamp/fjbg/JMember.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/* FJBG -- Fast Java Bytecode Generator
- * Copyright 2002-2013 LAMP/EPFL
- * @author Michel Schinz
- */
-
-package ch.epfl.lamp.fjbg;
-
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-
-/**
- * Abstract superclass for a Java class, field or method.
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-
-abstract public class JMember {
-
- protected boolean frozen = false;
-
- protected final FJBGContext context;
-
- protected String name;
-
- protected int accessFlags;
-
- protected final List/*<JAttribute>*/ attributes = new LinkedList();
-
- protected JMember(FJBGContext context) { this.context = context; }
-
- protected JMember(FJBGContext context, int accessFlags, String name) {
- this(context);
- this.name = name;
- this.accessFlags = accessFlags;
- }
-
- /**
- * Gets the access flags of the class.
- * @return The int representing the access flags of the class.
- */
- public int getAccessFlags() { return accessFlags; }
-
- /**
- * Gets the name of the member.
- * @return The string representing the name of the member.
- */
- public String getName() { return name; }
-
- /**
- * Gets the type of the objects that are instances of the class.
- * @return The type of the instances of the class.
- */
- public abstract JType getType();
-
- /**
- * Gets the class corresponding to/owning this member
- * @return The class owning this member or the class itself.
- */
- public abstract JClass getJClass();
-
- /**
- * Gets the constant pool of the class.
- * @return The constant pool of the class.
- */
- public JConstantPool getConstantPool() { return getJClass().getConstantPool(); }
-
- public FJBGContext getContext() { return context; }
-
- /**
- * Adds an attribute to the class.
- * @param attr The attribute to be added.
- */
- public void addAttribute(JAttribute attr) {
- assert !frozen;
- attributes.add(attr);
- }
-
- /**
- * Gets the list of all attributes of the class.
- * @return The list of the attributes of the class representation.
- */
- public List/*<JAttribute>*/ getAttributes() {
- return attributes;
- }
-
- /**
- * Get the attribute with the given name, or null if it doesn't
- * exist.
- */
- public JAttribute getAttribute(String name) {
- Iterator attrIt = getAttributes().iterator();
- while (attrIt.hasNext()) {
- JAttribute attr = (JAttribute)attrIt.next();
- if (attr.getName().equals(name))
- return attr;
- }
- return null;
- }
-
- protected static String toExternalName(String name) {
- return name.replace('/', '.');
- }
-
- protected static String toExternalName(JType tpe) {
- return tpe.toString().replace(':', '.');
- }
-}
diff --git a/src/fjbg/ch/epfl/lamp/fjbg/JMethod.java b/src/fjbg/ch/epfl/lamp/fjbg/JMethod.java
deleted file mode 100644
index 01d58a45c7..0000000000
--- a/src/fjbg/ch/epfl/lamp/fjbg/JMethod.java
+++ /dev/null
@@ -1,199 +0,0 @@
-/* FJBG -- Fast Java Bytecode Generator
- * Copyright 2002-2013 LAMP/EPFL
- * @author Michel Schinz
- */
-
-package ch.epfl.lamp.fjbg;
-
-import java.io.DataInputStream;
-import java.io.IOException;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-
-/**
- * Representation of a Java method.
- *
- * @author Michel Schinz
- * @version 1.0
- */
-
-public class JMethod extends JFieldOrMethod {
- public final static String CLASS_CONSTRUCTOR_NAME = "<clinit>";
- public final static String INSTANCE_CONSTRUCTOR_NAME = "<init>";
-
- protected /*final*/ JCode code;
- protected final String[] argNames;
-
- protected final LinkedList/*<JLocalVariable>*/ localVariables =
- new LinkedList();
- protected int localVariableIndex = 0;
-
-
- protected JMethod(FJBGContext context,
- JClass owner,
- int accessFlags,
- String name,
- JType returnType,
- JType[] argTypes,
- String[] argNames) {
- super(context,
- owner,
- accessFlags,
- name,
- new JMethodType(returnType, argTypes));
- this.argNames = argNames;
-
- assert argTypes.length == argNames.length;
-
- if (isAbstract() || isNative()) {
- code = null;
- } else {
- code = context.JCode(owner, this);
- addAttribute(context.JCodeAttribute(owner, this));
-
- if (!isStatic())
- addNewLocalVariable(owner.getType(), "this");
-
- for (int i = 0; i < argTypes.length; ++i)
- addNewLocalVariable(argTypes[i], argNames[i]);
- }
- }
-
- protected JMethod(FJBGContext context,
- JClass owner,
- DataInputStream stream)
- throws IOException {
- super(context, owner, stream);
-
- assert isAbstract() || isNative() || code != null;
-
- int n = 0;
- if (code != null) {
- for (Iterator it = code.getAttributes().iterator(); it.hasNext(); ) {
- JAttribute attr = (JAttribute)it.next();
- if (attr instanceof JLocalVariableTableAttribute)
- n = ((JLocalVariableTableAttribute)attr).getMaxLocals();
- }
- }
- this.localVariableIndex = n;
-
-
- JType[] argTypes = ((JMethodType)getType()).getArgumentTypes();
- argNames = new String[argTypes.length]; // TODO get from attribute
- for (int i = 0; i < argNames.length; ++i)
- argNames[i] = "v"+i;
- }
-
- public void freeze() throws JCode.OffsetTooBigException {
- if (code != null) code.freeze();
- super.freeze();
- }
-
- public JType getReturnType() {
- return ((JMethodType)type).getReturnType();
- }
-
- public JType[] getArgumentTypes() {
- return ((JMethodType)type).getArgumentTypes();
- }
-
- public int getArgsSize() {
- int size = ((JMethodType)type).getArgsSize();
- if (!isStatic()) size += 1; // for this
- return size;
- }
-
- public String[] getArgumentNames() {
- return argNames;
- }
-
- public JCode getCode() {
- assert !isAbstract();
- return code;
- }
-
- // Invoked by the JCode constructor
- protected void setCode(JCode code) {
- assert null == this.code;
- this.code = code;
- }
-
- public JCodeIterator codeIterator() {
- return new JCodeIterator(code);
- }
-
- // Local variables
- // FIXME : find a better management method for local variables
- public JLocalVariable addNewLocalVariable(JType type, String name) {
- assert !frozen;
- JLocalVariable var =
- context.JLocalVariable(this, type, name, localVariableIndex);
- localVariableIndex += type.getSize();
- localVariables.add(var);
- return var;
- }
-
- public JLocalVariable getLocalVariable(int index) {
- for (int i = 0; i < localVariables.size(); i++) {
- if (((JLocalVariable)localVariables.get(i)).index == index)
- return (JLocalVariable)localVariables.get(i);
- }
- return null;
- }
-
- public JLocalVariable[] getLocalVariables() {
- return (JLocalVariable[])localVariables
- .toArray(new JLocalVariable[localVariables.size()]);
- }
-
-
- public int getMaxLocals() {
- return localVariableIndex;
- }
-
- // Follows javap output format for methods.
- /*@Override*/ public String toString() {
- StringBuffer buf = new StringBuffer(flagsToString());
- String name = getName();
- if (CLASS_CONSTRUCTOR_NAME.equals(name))
- buf.append("{}");
- else {
- if (INSTANCE_CONSTRUCTOR_NAME.equals(name))
- name = getOwner().getName();
- else {
- buf.append(toExternalName(getReturnType()));
- buf.append(" ");
- }
- buf.append(toExternalName(name));
- buf.append("(");
- JType[] ts = getArgumentTypes();
- for (int i = 0; i < ts.length; ++i) {
- if (i > 0) buf.append(", ");
- buf.append(toExternalName(ts[i]));
- }
- buf.append(")");
- }
- buf.append(";\n");
- Iterator it = attributes.iterator();
- while(it.hasNext()) {
- JAttribute attr = (JAttribute)it.next();
- buf.append(attr);
- }
- return buf.toString();
- }
-
- private String flagsToString() {
- StringBuffer buf = new StringBuffer();
- if (isPublic()) buf.append("public ");
- else if (isProtected()) buf.append("protected ");
- else if (isPrivate()) buf.append("private ");
- if (isBridge()) buf.append("<bridge> ");
- if (hasVarargs()) buf.append("<varargs> ");
- if (isStatic()) buf.append("static ");
- else if (isNative()) buf.append("native ");
- if (isAbstract()) buf.append("abstract ");
- else if (isFinal()) buf.append("final ");
- return buf.toString();
- }
-}
diff --git a/src/fjbg/ch/epfl/lamp/fjbg/JMethodType.java b/src/fjbg/ch/epfl/lamp/fjbg/JMethodType.java
deleted file mode 100644
index cd3d71fd9c..0000000000
--- a/src/fjbg/ch/epfl/lamp/fjbg/JMethodType.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/* FJBG -- Fast Java Bytecode Generator
- * Copyright 2002-2013 LAMP/EPFL
- * @author Michel Schinz
- */
-
-package ch.epfl.lamp.fjbg;
-
-/**
- * Type for Java methods. These types do not really exist in Java, but
- * are provided here because they are useful in several places.
- *
- * @author Michel Schinz
- * @version 1.0
- */
-
-public class JMethodType extends JType {
- protected final JType returnType;
- protected final JType[] argTypes;
- protected String signature = null;
-
- public final static JMethodType ARGLESS_VOID_FUNCTION =
- new JMethodType(JType.VOID, JType.EMPTY_ARRAY);
-
- public JMethodType(JType returnType, JType[] argTypes) {
- this.returnType = returnType;
- this.argTypes = argTypes;
- }
-
- public JType getReturnType() { return returnType; }
- public JType[] getArgumentTypes() { return argTypes; }
-
- public int getSize() {
- throw new UnsupportedOperationException();
- }
-
- public String getSignature() {
- if (signature == null) {
- StringBuffer buf = new StringBuffer();
- buf.append('(');
- for (int i = 0; i < argTypes.length; ++i)
- buf.append(argTypes[i].getSignature());
- buf.append(')');
- buf.append(returnType.getSignature());
- signature = buf.toString();
- }
- return signature;
- }
-
- public int getTag() { return T_UNKNOWN; }
-
- public String toString() {
- StringBuffer buf = new StringBuffer();
- buf.append('(');
- for (int i = 0; i < argTypes.length; ++i)
- buf.append(argTypes[i].toString());
- buf.append(')');
- buf.append(returnType.toString());
- return buf.toString();
- }
-
- public int getArgsSize() {
- int size = 0;
- for (int i = 0; i < argTypes.length; ++i)
- size += argTypes[i].getSize();
- return size;
- }
-
- public int getProducedStack() {
- return returnType.getSize() - getArgsSize();
- }
-
- public boolean isCompatibleWith(JType other) {
- return false;
- }
- public boolean equals(Object o) {
- if (o instanceof JMethodType)
- return ((JMethodType)o).getSignature().equals(this.getSignature());
- else
- return false;
- }
- public int hashCode() {
- if (signature == null)
- return 0;
- else
- return signature.hashCode();
- }
-}
diff --git a/src/fjbg/ch/epfl/lamp/fjbg/JObjectType.java b/src/fjbg/ch/epfl/lamp/fjbg/JObjectType.java
deleted file mode 100644
index 06db5b115a..0000000000
--- a/src/fjbg/ch/epfl/lamp/fjbg/JObjectType.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/* FJBG -- Fast Java Bytecode Generator
- * Copyright 2002-2013 LAMP/EPFL
- * @author Michel Schinz
- */
-
-package ch.epfl.lamp.fjbg;
-
-/**
- * Types for Java objects.
- *
- * @author Michel Schinz
- * @version 1.0
- */
-
-public class JObjectType extends JReferenceType {
- protected final String name;
- protected String signature = null;
-
- public final static JObjectType JAVA_LANG_OBJECT =
- new JObjectType("java.lang.Object");
- public final static JObjectType JAVA_LANG_STRING =
- new JObjectType("java.lang.String");
- public final static JObjectType CLONEABLE =
- new JObjectType("Cloneable");
- public final static JObjectType JAVA_IO_SERIALIZABLE =
- new JObjectType("java.io.Serializable");
-
- public JObjectType(String name) {
- this.name = name;
- }
-
- public int getSize() { return 1; }
-
- public String getName() { return name; }
-
- public String getSignature() {
- if (signature == null)
- signature = "L" + name.replace('.','/') + ";";
- return signature;
- }
-
- public String getDescriptor() {
- return name.replace('.','/');
- }
-
- public int getTag() { return T_OBJECT; }
-
- public String toString() { return name; }
-
- public boolean isObjectType() { return true; }
-
- public boolean isCompatibleWith(JType other) {
- return other instanceof JObjectType
- || other == JType.REFERENCE;
- }
- public boolean equals(Object o) {
- if (o instanceof JObjectType)
- return ((JObjectType)o).getSignature().equals(this.getSignature());
- else
- return false;
- }
- public int hashCode() {
- return name.hashCode();
- }
-}
diff --git a/src/fjbg/ch/epfl/lamp/fjbg/JOpcode.java b/src/fjbg/ch/epfl/lamp/fjbg/JOpcode.java
deleted file mode 100644
index cc68681a96..0000000000
--- a/src/fjbg/ch/epfl/lamp/fjbg/JOpcode.java
+++ /dev/null
@@ -1,1267 +0,0 @@
-/* FJBG -- Fast Java Bytecode Generator
- * Copyright 2002-2013 LAMP/EPFL
- * @author Michel Schinz
- */
-
-package ch.epfl.lamp.fjbg;
-
-/**
- * Definition of opcodes for the JVM.
- *
- * @author Michel Schinz, Thomas Friedli
- * @version 1.0
- */
-
-public class JOpcode {
- public final String name;
- public final int code;
-
- // The following attributes can be (statically) unknown for some
- // instructions, and are therefore not public. To know their value,
- // functions have to be used (see JCodeIterator).
- protected final int size;
- protected final JType[] producedDataTypes;
- protected final JType[] consumedDataTypes;
- protected final int jumpKind;
- protected final int successorCount;
-
- protected final static int UNKNOWN = Integer.MIN_VALUE;
-
- protected final static int JMP_NONE = 0;
- protected final static int JMP_NEXT = 1;
- protected final static int JMP_ALWAYS_S2_OFFSET = 2;
- protected final static int JMP_ALWAYS_S4_OFFSET = 3;
- protected final static int JMP_MAYBE_S2_OFFSET = 4;
- protected final static int JMP_TABLE = 5;
- protected final static int JMP_LOOKUP = 6;
-
- protected final static JType[] NO_DATA = new JType[0];
-
- protected final static JType[] INT_TYPE =
- new JType[] { JType.INT };
- protected final static JType[] FLOAT_TYPE =
- new JType[] { JType.FLOAT };
- protected final static JType[] LONG_TYPE =
- new JType[] { JType.LONG };
- protected final static JType[] DOUBLE_TYPE =
- new JType[] { JType.DOUBLE };
- protected final static JType[] OBJECT_REF_TYPE =
- new JType[] { JObjectType.JAVA_LANG_OBJECT };
- protected final static JType[] ARRAY_REF_TYPE =
- new JType[] { new JArrayType(JType.VOID) };
- protected final static JType[] REFERENCE_TYPE =
- new JType[] { JType.REFERENCE };
- protected final static JType[] ADDRESS_TYPE =
- new JType[] { JType.ADDRESS };
- protected final static JType[] UNKNOWN_TYPE =
- new JType[] { JType.UNKNOWN };
-
- /// Instruction codes
- public final static int cNOP = 0;
- public final static int cACONST_NULL = 1;
- public final static int cICONST_M1 = 2;
- public final static int cICONST_0 = 3;
- public final static int cICONST_1 = 4;
- public final static int cICONST_2 = 5;
- public final static int cICONST_3 = 6;
- public final static int cICONST_4 = 7;
- public final static int cICONST_5 = 8;
- public final static int cLCONST_0 = 9;
- public final static int cLCONST_1 = 10;
- public final static int cFCONST_0 = 11;
- public final static int cFCONST_1 = 12;
- public final static int cFCONST_2 = 13;
- public final static int cDCONST_0 = 14;
- public final static int cDCONST_1 = 15;
- public final static int cBIPUSH = 16;
- public final static int cSIPUSH = 17;
- public final static int cLDC = 18;
- public final static int cLDC_W = 19;
- public final static int cLDC2_W = 20;
- public final static int cILOAD = 21;
- public final static int cLLOAD = 22;
- public final static int cFLOAD = 23;
- public final static int cDLOAD = 24;
- public final static int cALOAD = 25;
- public final static int cILOAD_0 = 26;
- public final static int cILOAD_1 = 27;
- public final static int cILOAD_2 = 28;
- public final static int cILOAD_3 = 29;
- public final static int cLLOAD_0 = 30;
- public final static int cLLOAD_1 = 31;
- public final static int cLLOAD_2 = 32;
- public final static int cLLOAD_3 = 33;
- public final static int cFLOAD_0 = 34;
- public final static int cFLOAD_1 = 35;
- public final static int cFLOAD_2 = 36;
- public final static int cFLOAD_3 = 37;
- public final static int cDLOAD_0 = 38;
- public final static int cDLOAD_1 = 39;
- public final static int cDLOAD_2 = 40;
- public final static int cDLOAD_3 = 41;
- public final static int cALOAD_0 = 42;
- public final static int cALOAD_1 = 43;
- public final static int cALOAD_2 = 44;
- public final static int cALOAD_3 = 45;
- public final static int cIALOAD = 46;
- public final static int cLALOAD = 47;
- public final static int cFALOAD = 48;
- public final static int cDALOAD = 49;
- public final static int cAALOAD = 50;
- public final static int cBALOAD = 51;
- public final static int cCALOAD = 52;
- public final static int cSALOAD = 53;
- public final static int cISTORE = 54;
- public final static int cLSTORE = 55;
- public final static int cFSTORE = 56;
- public final static int cDSTORE = 57;
- public final static int cASTORE = 58;
- public final static int cISTORE_0 = 59;
- public final static int cISTORE_1 = 60;
- public final static int cISTORE_2 = 61;
- public final static int cISTORE_3 = 62;
- public final static int cLSTORE_0 = 63;
- public final static int cLSTORE_1 = 64;
- public final static int cLSTORE_2 = 65;
- public final static int cLSTORE_3 = 66;
- public final static int cFSTORE_0 = 67;
- public final static int cFSTORE_1 = 68;
- public final static int cFSTORE_2 = 69;
- public final static int cFSTORE_3 = 70;
- public final static int cDSTORE_0 = 71;
- public final static int cDSTORE_1 = 72;
- public final static int cDSTORE_2 = 73;
- public final static int cDSTORE_3 = 74;
- public final static int cASTORE_0 = 75;
- public final static int cASTORE_1 = 76;
- public final static int cASTORE_2 = 77;
- public final static int cASTORE_3 = 78;
- public final static int cIASTORE = 79;
- public final static int cLASTORE = 80;
- public final static int cFASTORE = 81;
- public final static int cDASTORE = 82;
- public final static int cAASTORE = 83;
- public final static int cBASTORE = 84;
- public final static int cCASTORE = 85;
- public final static int cSASTORE = 86;
- public final static int cPOP = 87;
- public final static int cPOP2 = 88;
- public final static int cDUP = 89;
- public final static int cDUP_X1 = 90;
- public final static int cDUP_X2 = 91;
- public final static int cDUP2 = 92;
- public final static int cDUP2_X1 = 93;
- public final static int cDUP2_X2 = 94;
- public final static int cSWAP = 95;
- public final static int cIADD = 96;
- public final static int cLADD = 97;
- public final static int cFADD = 98;
- public final static int cDADD = 99;
- public final static int cISUB = 100;
- public final static int cLSUB = 101;
- public final static int cFSUB = 102;
- public final static int cDSUB = 103;
- public final static int cIMUL = 104;
- public final static int cLMUL = 105;
- public final static int cFMUL = 106;
- public final static int cDMUL = 107;
- public final static int cIDIV = 108;
- public final static int cLDIV = 109;
- public final static int cFDIV = 110;
- public final static int cDDIV = 111;
- public final static int cIREM = 112;
- public final static int cLREM = 113;
- public final static int cFREM = 114;
- public final static int cDREM = 115;
- public final static int cINEG = 116;
- public final static int cLNEG = 117;
- public final static int cFNEG = 118;
- public final static int cDNEG = 119;
- public final static int cISHL = 120;
- public final static int cLSHL = 121;
- public final static int cISHR = 122;
- public final static int cLSHR = 123;
- public final static int cIUSHR = 124;
- public final static int cLUSHR = 125;
- public final static int cIAND = 126;
- public final static int cLAND = 127;
- public final static int cIOR = 128;
- public final static int cLOR = 129;
- public final static int cIXOR = 130;
- public final static int cLXOR = 131;
- public final static int cIINC = 132;
- public final static int cI2L = 133;
- public final static int cI2F = 134;
- public final static int cI2D = 135;
- public final static int cL2I = 136;
- public final static int cL2F = 137;
- public final static int cL2D = 138;
- public final static int cF2I = 139;
- public final static int cF2L = 140;
- public final static int cF2D = 141;
- public final static int cD2I = 142;
- public final static int cD2L = 143;
- public final static int cD2F = 144;
- public final static int cI2B = 145;
- public final static int cI2C = 146;
- public final static int cI2S = 147;
- public final static int cLCMP = 148;
- public final static int cFCMPL = 149;
- public final static int cFCMPG = 150;
- public final static int cDCMPL = 151;
- public final static int cDCMPG = 152;
- public final static int cIFEQ = 153;
- public final static int cIFNE = 154;
- public final static int cIFLT = 155;
- public final static int cIFGE = 156;
- public final static int cIFGT = 157;
- public final static int cIFLE = 158;
- public final static int cIF_ICMPEQ = 159;
- public final static int cIF_ICMPNE = 160;
- public final static int cIF_ICMPLT = 161;
- public final static int cIF_ICMPGE = 162;
- public final static int cIF_ICMPGT = 163;
- public final static int cIF_ICMPLE = 164;
- public final static int cIF_ACMPEQ = 165;
- public final static int cIF_ACMPNE = 166;
- public final static int cGOTO = 167;
- public final static int cJSR = 168;
- public final static int cRET = 169;
- public final static int cTABLESWITCH = 170;
- public final static int cLOOKUPSWITCH = 171;
- public final static int cIRETURN = 172;
- public final static int cLRETURN = 173;
- public final static int cFRETURN = 174;
- public final static int cDRETURN = 175;
- public final static int cARETURN = 176;
- public final static int cRETURN = 177;
- public final static int cGETSTATIC = 178;
- public final static int cPUTSTATIC = 179;
- public final static int cGETFIELD = 180;
- public final static int cPUTFIELD = 181;
- public final static int cINVOKEVIRTUAL = 182;
- public final static int cINVOKESPECIAL = 183;
- public final static int cINVOKESTATIC = 184;
- public final static int cINVOKEINTERFACE = 185;
- public final static int cNEW = 187;
- public final static int cNEWARRAY = 188;
- public final static int cANEWARRAY = 189;
- public final static int cARRAYLENGTH = 190;
- public final static int cATHROW = 191;
- public final static int cCHECKCAST = 192;
- public final static int cINSTANCEOF = 193;
- public final static int cMONITORENTER = 194;
- public final static int cMONITOREXIT = 195;
- public final static int cWIDE = 196;
- public final static int cMULTIANEWARRAY = 197;
- public final static int cIFNULL = 198;
- public final static int cIFNONNULL = 199;
- public final static int cGOTO_W = 200;
- public final static int cJSR_W = 201;
-
- // Objects representing instructions
- public final static JOpcode NOP =
- new JOpcode("NOP", cNOP, 1, NO_DATA, NO_DATA, JMP_NEXT);
- public final static JOpcode ACONST_NULL = new JOpcode("ACONST_NULL",
- cACONST_NULL,
- 1,
- REFERENCE_TYPE,
- NO_DATA,
- JMP_NEXT);
- public final static JOpcode ICONST_M1 =
- new JOpcode("ICONST_M1", cICONST_M1, 1, INT_TYPE, NO_DATA, JMP_NEXT);
- public final static JOpcode ICONST_0 =
- new JOpcode("ICONST_0", cICONST_0, 1, INT_TYPE, NO_DATA, JMP_NEXT);
- public final static JOpcode ICONST_1 =
- new JOpcode("ICONST_1", cICONST_1, 1, INT_TYPE, NO_DATA, JMP_NEXT);
- public final static JOpcode ICONST_2 =
- new JOpcode("ICONST_2", cICONST_2, 1, INT_TYPE, NO_DATA, JMP_NEXT);
- public final static JOpcode ICONST_3 =
- new JOpcode("ICONST_3", cICONST_3, 1, INT_TYPE, NO_DATA, JMP_NEXT);
- public final static JOpcode ICONST_4 =
- new JOpcode("ICONST_4", cICONST_4, 1, INT_TYPE, NO_DATA, JMP_NEXT);
- public final static JOpcode ICONST_5 =
- new JOpcode("ICONST_5", cICONST_5, 1, INT_TYPE, NO_DATA, JMP_NEXT);
- public final static JOpcode LCONST_0 =
- new JOpcode("LCONST_0", cLCONST_0, 1, LONG_TYPE, NO_DATA, JMP_NEXT);
- public final static JOpcode LCONST_1 =
- new JOpcode("LCONST_1", cLCONST_1, 1, LONG_TYPE, NO_DATA, JMP_NEXT);
- public final static JOpcode FCONST_0 =
- new JOpcode("FCONST_0", cFCONST_0, 1, FLOAT_TYPE, NO_DATA, JMP_NEXT);
- public final static JOpcode FCONST_1 =
- new JOpcode("FCONST_1", cFCONST_1, 1, FLOAT_TYPE, NO_DATA, JMP_NEXT);
- public final static JOpcode FCONST_2 =
- new JOpcode("FCONST_2", cFCONST_2, 1, FLOAT_TYPE, NO_DATA, JMP_NEXT);
- public final static JOpcode DCONST_0 =
- new JOpcode("DCONST_0", cDCONST_0, 1, DOUBLE_TYPE, NO_DATA, JMP_NEXT);
- public final static JOpcode DCONST_1 =
- new JOpcode("DCONST_1", cDCONST_1, 1, DOUBLE_TYPE, NO_DATA, JMP_NEXT);
- public final static JOpcode BIPUSH =
- new JOpcode("BIPUSH", cBIPUSH, 2, INT_TYPE, NO_DATA, JMP_NEXT);
- public final static JOpcode SIPUSH =
- new JOpcode("SIPUSH", cSIPUSH, 3, INT_TYPE, NO_DATA, JMP_NEXT);
- public final static JOpcode LDC =
- new JOpcode("LDC", cLDC, 2, UNKNOWN_TYPE, NO_DATA, JMP_NEXT);
- public final static JOpcode LDC_W =
- new JOpcode("LDC_W", cLDC_W, 3, UNKNOWN_TYPE, NO_DATA, JMP_NEXT);
- public final static JOpcode LDC2_W =
- new JOpcode("LDC2_W", cLDC2_W, 3, UNKNOWN_TYPE, NO_DATA, JMP_NEXT);
- public final static JOpcode ILOAD =
- new JOpcode("ILOAD", cILOAD, 2, INT_TYPE, NO_DATA, JMP_NEXT);
- public final static JOpcode LLOAD =
- new JOpcode("LLOAD", cLLOAD, 2, LONG_TYPE, NO_DATA, JMP_NEXT);
- public final static JOpcode FLOAD =
- new JOpcode("FLOAD", cFLOAD, 2, FLOAT_TYPE, NO_DATA, JMP_NEXT);
- public final static JOpcode DLOAD =
- new JOpcode("DLOAD", cDLOAD, 2, DOUBLE_TYPE, NO_DATA, JMP_NEXT);
- public final static JOpcode ALOAD =
- new JOpcode("ALOAD", cALOAD, 2, REFERENCE_TYPE, NO_DATA, JMP_NEXT);
- public final static JOpcode ILOAD_0 =
- new JOpcode("ILOAD_0", cILOAD_0, 1, INT_TYPE, NO_DATA, JMP_NEXT);
- public final static JOpcode ILOAD_1 =
- new JOpcode("ILOAD_1", cILOAD_1, 1, INT_TYPE, NO_DATA, JMP_NEXT);
- public final static JOpcode ILOAD_2 =
- new JOpcode("ILOAD_2", cILOAD_2, 1, INT_TYPE, NO_DATA, JMP_NEXT);
- public final static JOpcode ILOAD_3 =
- new JOpcode("ILOAD_3", cILOAD_3, 1, INT_TYPE, NO_DATA, JMP_NEXT);
- public final static JOpcode LLOAD_0 =
- new JOpcode("LLOAD_0", cLLOAD_0, 1, LONG_TYPE, NO_DATA, JMP_NEXT);
- public final static JOpcode LLOAD_1 =
- new JOpcode("LLOAD_1", cLLOAD_1, 1, LONG_TYPE, NO_DATA, JMP_NEXT);
- public final static JOpcode LLOAD_2 =
- new JOpcode("LLOAD_2", cLLOAD_2, 1, LONG_TYPE, NO_DATA, JMP_NEXT);
- public final static JOpcode LLOAD_3 =
- new JOpcode("LLOAD_3", cLLOAD_3, 1, LONG_TYPE, NO_DATA, JMP_NEXT);
- public final static JOpcode FLOAD_0 =
- new JOpcode("FLOAD_0", cFLOAD_0, 1, FLOAT_TYPE, NO_DATA, JMP_NEXT);
- public final static JOpcode FLOAD_1 =
- new JOpcode("FLOAD_1", cFLOAD_1, 1, FLOAT_TYPE, NO_DATA, JMP_NEXT);
- public final static JOpcode FLOAD_2 =
- new JOpcode("FLOAD_2", cFLOAD_2, 1, FLOAT_TYPE, NO_DATA, JMP_NEXT);
- public final static JOpcode FLOAD_3 =
- new JOpcode("FLOAD_3", cFLOAD_3, 1, FLOAT_TYPE, NO_DATA, JMP_NEXT);
- public final static JOpcode DLOAD_0 =
- new JOpcode("DLOAD_0", cDLOAD_0, 1, DOUBLE_TYPE, NO_DATA, JMP_NEXT);
- public final static JOpcode DLOAD_1 =
- new JOpcode("DLOAD_1", cDLOAD_1, 1, DOUBLE_TYPE, NO_DATA, JMP_NEXT);
- public final static JOpcode DLOAD_2 =
- new JOpcode("DLOAD_2", cDLOAD_2, 1, DOUBLE_TYPE, NO_DATA, JMP_NEXT);
- public final static JOpcode DLOAD_3 =
- new JOpcode("DLOAD_3", cDLOAD_3, 1, DOUBLE_TYPE, NO_DATA, JMP_NEXT);
- public final static JOpcode ALOAD_0 =
- new JOpcode("ALOAD_0", cALOAD_0, 1, REFERENCE_TYPE, NO_DATA, JMP_NEXT);
- public final static JOpcode ALOAD_1 =
- new JOpcode("ALOAD_1", cALOAD_1, 1, REFERENCE_TYPE, NO_DATA, JMP_NEXT);
- public final static JOpcode ALOAD_2 =
- new JOpcode("ALOAD_2", cALOAD_2, 1, REFERENCE_TYPE, NO_DATA, JMP_NEXT);
- public final static JOpcode ALOAD_3 =
- new JOpcode("ALOAD_3", cALOAD_3, 1, REFERENCE_TYPE, NO_DATA, JMP_NEXT);
- public final static JOpcode IALOAD =
- new JOpcode("IALOAD",
- cIALOAD,
- 1,
- INT_TYPE,
- new JType[] {JType.INT, JArrayType.INT},
- JMP_NEXT);
- public final static JOpcode LALOAD =
- new JOpcode("LALOAD",
- cLALOAD,
- 1,
- LONG_TYPE,
- new JType[] {JType.INT, JArrayType.LONG},
- JMP_NEXT);
- public final static JOpcode FALOAD =
- new JOpcode("FALOAD",
- cFALOAD,
- 1,
- FLOAT_TYPE,
- new JType[] {JType.INT, JArrayType.FLOAT},
- JMP_NEXT);
- public final static JOpcode DALOAD =
- new JOpcode("DALOAD",
- cDALOAD,
- 1,
- DOUBLE_TYPE,
- new JType[] {JType.INT, JArrayType.DOUBLE},
- JMP_NEXT);
- public final static JOpcode AALOAD =
- new JOpcode("AALOAD",
- cAALOAD,
- 1,
- REFERENCE_TYPE,
- new JType[] {JType.INT, JArrayType.REFERENCE},
- JMP_NEXT);
- public final static JOpcode BALOAD =
- new JOpcode("BALOAD",
- cBALOAD,
- 1,
- INT_TYPE,
- new JType[] {JType.INT, new JArrayType(JType.UNKNOWN)},
- JMP_NEXT);
- public final static JOpcode CALOAD =
- new JOpcode("CALOAD",
- cCALOAD,
- 1,
- INT_TYPE,
- new JType[] {JType.INT, JArrayType.CHAR},
- JMP_NEXT);
- public final static JOpcode SALOAD =
- new JOpcode("SALOAD",
- cSALOAD,
- 1,
- INT_TYPE,
- new JType[] {JType.INT, JArrayType.SHORT},
- JMP_NEXT);
- public final static JOpcode ISTORE =
- new JOpcode("ISTORE", cISTORE, 2, NO_DATA, INT_TYPE, JMP_NEXT);
- public final static JOpcode LSTORE =
- new JOpcode("LSTORE", cLSTORE, 2, NO_DATA, LONG_TYPE, JMP_NEXT);
- public final static JOpcode FSTORE =
- new JOpcode("FSTORE", cFSTORE, 2, NO_DATA, FLOAT_TYPE, JMP_NEXT);
- public final static JOpcode DSTORE =
- new JOpcode("DSTORE", cDSTORE, 2, NO_DATA, DOUBLE_TYPE, JMP_NEXT);
- public final static JOpcode ASTORE =
- new JOpcode("ASTORE", cASTORE, 2, NO_DATA, REFERENCE_TYPE, JMP_NEXT);
- public final static JOpcode ISTORE_0 =
- new JOpcode("ISTORE_0", cISTORE_0, 1, NO_DATA, INT_TYPE, JMP_NEXT);
- public final static JOpcode ISTORE_1 =
- new JOpcode("ISTORE_1", cISTORE_1, 1, NO_DATA, INT_TYPE, JMP_NEXT);
- public final static JOpcode ISTORE_2 =
- new JOpcode("ISTORE_2", cISTORE_2, 1, NO_DATA, INT_TYPE, JMP_NEXT);
- public final static JOpcode ISTORE_3 =
- new JOpcode("ISTORE_3", cISTORE_3, 1, NO_DATA, INT_TYPE, JMP_NEXT);
- public final static JOpcode LSTORE_0 =
- new JOpcode("LSTORE_0", cLSTORE_0, 1, NO_DATA, LONG_TYPE, JMP_NEXT);
- public final static JOpcode LSTORE_1 =
- new JOpcode("LSTORE_1", cLSTORE_1, 1, NO_DATA, LONG_TYPE, JMP_NEXT);
- public final static JOpcode LSTORE_2 =
- new JOpcode("LSTORE_2", cLSTORE_2, 1, NO_DATA, LONG_TYPE, JMP_NEXT);
- public final static JOpcode LSTORE_3 =
- new JOpcode("LSTORE_3", cLSTORE_3, 1, NO_DATA, LONG_TYPE, JMP_NEXT);
- public final static JOpcode FSTORE_0 =
- new JOpcode("FSTORE_0", cFSTORE_0, 1, NO_DATA, FLOAT_TYPE, JMP_NEXT);
- public final static JOpcode FSTORE_1 =
- new JOpcode("FSTORE_1", cFSTORE_1, 1, NO_DATA, FLOAT_TYPE, JMP_NEXT);
- public final static JOpcode FSTORE_2 =
- new JOpcode("FSTORE_2", cFSTORE_2, 1, NO_DATA, FLOAT_TYPE, JMP_NEXT);
- public final static JOpcode FSTORE_3 =
- new JOpcode("FSTORE_3", cFSTORE_3, 1, NO_DATA, FLOAT_TYPE, JMP_NEXT);
- public final static JOpcode DSTORE_0 =
- new JOpcode("DSTORE_0", cDSTORE_0, 1, NO_DATA, DOUBLE_TYPE, JMP_NEXT);
- public final static JOpcode DSTORE_1 =
- new JOpcode("DSTORE_1", cDSTORE_1, 1, NO_DATA, DOUBLE_TYPE, JMP_NEXT);
- public final static JOpcode DSTORE_2 =
- new JOpcode("DSTORE_2", cDSTORE_2, 1, NO_DATA, DOUBLE_TYPE, JMP_NEXT);
- public final static JOpcode DSTORE_3 =
- new JOpcode("DSTORE_3", cDSTORE_3, 1, NO_DATA, DOUBLE_TYPE, JMP_NEXT);
- public final static JOpcode ASTORE_0 = new JOpcode("ASTORE_0",
- cASTORE_0,
- 1,
- NO_DATA,
- REFERENCE_TYPE,
- JMP_NEXT);
- public final static JOpcode ASTORE_1 = new JOpcode("ASTORE_1",
- cASTORE_1,
- 1,
- NO_DATA,
- REFERENCE_TYPE,
- JMP_NEXT);
- public final static JOpcode ASTORE_2 = new JOpcode("ASTORE_2",
- cASTORE_2,
- 1,
- NO_DATA,
- REFERENCE_TYPE,
- JMP_NEXT);
- public final static JOpcode ASTORE_3 = new JOpcode("ASTORE_3",
- cASTORE_3,
- 1,
- NO_DATA,
- REFERENCE_TYPE,
- JMP_NEXT);
- public final static JOpcode IASTORE =
- new JOpcode("IASTORE",
- cIASTORE,
- 1,
- NO_DATA,
- new JType[] { JType.INT,
- JType.INT,
- JArrayType.INT},
- JMP_NEXT);
- public final static JOpcode LASTORE =
- new JOpcode("LASTORE",
- cLASTORE,
- 1,
- NO_DATA,
- new JType[] { JType.LONG,
- JType.INT,
- JArrayType.LONG},
- JMP_NEXT);
- public final static JOpcode FASTORE =
- new JOpcode("FASTORE",
- cFASTORE,
- 1,
- NO_DATA,
- new JType[] { JType.FLOAT,
- JType.INT,
- JArrayType.FLOAT},
- JMP_NEXT);
- public final static JOpcode DASTORE =
- new JOpcode("DASTORE",
- cDASTORE,
- 1,
- NO_DATA,
- new JType[] { JType.DOUBLE,
- JType.INT,
- JArrayType.DOUBLE},
- JMP_NEXT);
- public final static JOpcode AASTORE =
- new JOpcode("AASTORE",
- cAASTORE,
- 1,
- NO_DATA,
- new JType[] { JType.REFERENCE,
- JType.INT,
- JArrayType.REFERENCE},
- JMP_NEXT);
- public final static JOpcode BASTORE =
- new JOpcode("BASTORE",
- cBASTORE,
- 1,
- NO_DATA,
- new JType[] { JType.INT,
- JType.INT,
- new JArrayType(JType.UNKNOWN)},
- JMP_NEXT);
- public final static JOpcode CASTORE =
- new JOpcode("CASTORE",
- cCASTORE,
- 1,
- NO_DATA,
- new JType[] { JType.INT,
- JType.INT,
- JArrayType.CHAR},
- JMP_NEXT);
- public final static JOpcode SASTORE =
- new JOpcode("SASTORE",
- cSASTORE,
- 1,
- NO_DATA,
- new JType[] { JType.INT,
- JType.INT,
- JArrayType.SHORT},
- JMP_NEXT);
- public final static JOpcode POP =
- new JOpcode("POP", cPOP, 1, NO_DATA, UNKNOWN_TYPE, JMP_NEXT);
- public final static JOpcode POP2 =
- new JOpcode("POP2", cPOP2, 1, NO_DATA, UNKNOWN_TYPE, JMP_NEXT);
- public final static JOpcode DUP =
- new JOpcode("DUP", cDUP, 1, UNKNOWN_TYPE, UNKNOWN_TYPE, JMP_NEXT);
- public final static JOpcode DUP_X1 = new JOpcode("DUP_X1",
- cDUP_X1,
- 1,
- UNKNOWN_TYPE,
- UNKNOWN_TYPE,
- JMP_NEXT);
- public final static JOpcode DUP_X2 = new JOpcode("DUP_X2",
- cDUP_X2,
- 1,
- UNKNOWN_TYPE,
- UNKNOWN_TYPE,
- JMP_NEXT);
- public final static JOpcode DUP2 =
- new JOpcode("DUP2", cDUP2, 1, UNKNOWN_TYPE, UNKNOWN_TYPE, JMP_NEXT);
- public final static JOpcode DUP2_X1 = new JOpcode("DUP2_X1",
- cDUP2_X1,
- 1,
- UNKNOWN_TYPE,
- UNKNOWN_TYPE,
- JMP_NEXT);
- public final static JOpcode DUP2_X2 = new JOpcode("DUP2_X2",
- cDUP2_X2,
- 1,
- UNKNOWN_TYPE,
- UNKNOWN_TYPE,
- JMP_NEXT);
- public final static JOpcode SWAP =
- new JOpcode("SWAP", cSWAP, 1, UNKNOWN_TYPE, UNKNOWN_TYPE, JMP_NEXT);
- public final static JOpcode IADD =
- new JOpcode("IADD",
- cIADD,
- 1,
- INT_TYPE,
- new JType[] { JType.INT, JType.INT },
- JMP_NEXT);
- public final static JOpcode LADD =
- new JOpcode("LADD",
- cLADD,
- 1,
- LONG_TYPE,
- new JType[] { JType.LONG, JType.LONG },
- JMP_NEXT);
- public final static JOpcode FADD =
- new JOpcode("FADD",
- cFADD,
- 1,
- FLOAT_TYPE,
- new JType[] { JType.FLOAT, JType.FLOAT },
- JMP_NEXT);
- public final static JOpcode DADD =
- new JOpcode("DADD",
- cDADD,
- 1,
- DOUBLE_TYPE,
- new JType[] { JType.DOUBLE, JType.DOUBLE },
- JMP_NEXT);
- public final static JOpcode ISUB =
- new JOpcode("ISUB",
- cISUB,
- 1,
- INT_TYPE,
- new JType[] {JType.INT, JType.INT },
- JMP_NEXT);
- public final static JOpcode LSUB =
- new JOpcode("LSUB",
- cLSUB,
- 1,
- LONG_TYPE,
- new JType[] { JType.LONG, JType.LONG },
- JMP_NEXT);
- public final static JOpcode FSUB =
- new JOpcode("FSUB",
- cFSUB,
- 1,
- FLOAT_TYPE,
- new JType[] { JType.FLOAT, JType.FLOAT },
- JMP_NEXT);
- public final static JOpcode DSUB =
- new JOpcode("DSUB",
- cDSUB,
- 1,
- DOUBLE_TYPE,
- new JType[] { JType.DOUBLE, JType.DOUBLE },
- JMP_NEXT);
- public final static JOpcode IMUL =
- new JOpcode("IMUL",
- cIMUL,
- 1,
- INT_TYPE,
- new JType[] {JType.INT, JType.INT },
- JMP_NEXT);
- public final static JOpcode LMUL =
- new JOpcode("LMUL",
- cLMUL,
- 1,
- LONG_TYPE,
- new JType[] { JType.LONG, JType.LONG },
- JMP_NEXT);
- public final static JOpcode FMUL =
- new JOpcode("FMUL",
- cFMUL,
- 1,
- FLOAT_TYPE,
- new JType[] { JType.FLOAT, JType.FLOAT },
- JMP_NEXT);
- public final static JOpcode DMUL =
- new JOpcode("DMUL",
- cDMUL,
- 1,
- DOUBLE_TYPE,
- new JType[] { JType.DOUBLE, JType.DOUBLE },
- JMP_NEXT);
- public final static JOpcode IDIV =
- new JOpcode("IDIV",
- cIDIV,
- 1,
- INT_TYPE,
- new JType[] {JType.INT, JType.INT },
- JMP_NEXT);
- public final static JOpcode LDIV =
- new JOpcode("LDIV",
- cLDIV,
- 1,
- LONG_TYPE,
- new JType[] { JType.LONG, JType.LONG },
- JMP_NEXT);
- public final static JOpcode FDIV =
- new JOpcode("FDIV",
- cFDIV,
- 1,
- FLOAT_TYPE,
- new JType[] { JType.FLOAT, JType.FLOAT },
- JMP_NEXT);
- public final static JOpcode DDIV =
- new JOpcode("DDIV",
- cDDIV,
- 1,
- DOUBLE_TYPE,
- new JType[] { JType.DOUBLE, JType.DOUBLE },
- JMP_NEXT);
- public final static JOpcode IREM =
- new JOpcode("IREM",
- cIREM,
- 1,
- INT_TYPE,
- new JType[] {JType.INT, JType.INT },
- JMP_NEXT);
- public final static JOpcode LREM =
- new JOpcode("LREM",
- cLREM,
- 1,
- LONG_TYPE,
- new JType[] { JType.LONG, JType.LONG },
- JMP_NEXT);
- public final static JOpcode FREM =
- new JOpcode("FREM",
- cFREM,
- 1,
- FLOAT_TYPE,
- new JType[] { JType.FLOAT, JType.FLOAT },
- JMP_NEXT);
- public final static JOpcode DREM =
- new JOpcode("DREM",
- cDREM,
- 1,
- DOUBLE_TYPE,
- new JType[] { JType.DOUBLE, JType.DOUBLE },
- JMP_NEXT);
- public final static JOpcode INEG =
- new JOpcode("INEG", cINEG, 1, INT_TYPE, INT_TYPE, JMP_NEXT);
- public final static JOpcode LNEG =
- new JOpcode("LNEG", cLNEG, 1, LONG_TYPE, LONG_TYPE, JMP_NEXT);
- public final static JOpcode FNEG =
- new JOpcode("FNEG", cFNEG, 1, FLOAT_TYPE, FLOAT_TYPE, JMP_NEXT);
- public final static JOpcode DNEG =
- new JOpcode("DNEG", cDNEG, 1, DOUBLE_TYPE, DOUBLE_TYPE, JMP_NEXT);
- public final static JOpcode ISHL =
- new JOpcode("ISHL", cISHL,
- 1,
- INT_TYPE,
- new JType[] { JType.INT, JType.INT },
- JMP_NEXT);
- public final static JOpcode LSHL =
- new JOpcode("LSHL",
- cLSHL,
- 1,
- LONG_TYPE,
- new JType [] { JType.INT, JType.LONG },
- JMP_NEXT);
- public final static JOpcode ISHR =
- new JOpcode("ISHR",
- cISHR,
- 1,
- INT_TYPE,
- new JType[] { JType.INT, JType.INT },
- JMP_NEXT);
- public final static JOpcode LSHR =
- new JOpcode("LSHR",
- cLSHR,
- 1,
- LONG_TYPE,
- new JType[] { JType.INT, JType.LONG },
- JMP_NEXT);
- public final static JOpcode IUSHR =
- new JOpcode("IUSHR",
- cIUSHR,
- 1,
- INT_TYPE,
- new JType[] { JType.INT, JType.INT },
- JMP_NEXT);
- public final static JOpcode LUSHR =
- new JOpcode("LUSHR",
- cLUSHR,
- 1,
- LONG_TYPE,
- new JType[] { JType.INT, JType.LONG },
- JMP_NEXT);
- public final static JOpcode IAND =
- new JOpcode("IAND",
- cIAND,
- 1,
- INT_TYPE,
- new JType[] { JType.INT, JType.INT },
- JMP_NEXT);
- public final static JOpcode LAND =
- new JOpcode("LAND",
- cLAND,
- 1,
- LONG_TYPE,
- new JType[] { JType.LONG, JType.LONG },
- JMP_NEXT);
- public final static JOpcode IOR =
- new JOpcode("IOR",
- cIOR,
- 1,
- INT_TYPE,
- new JType[] { JType.INT, JType.INT },
- JMP_NEXT);
- public final static JOpcode LOR =
- new JOpcode("LOR",
- cLOR,
- 1,
- LONG_TYPE,
- new JType[] { JType.LONG, JType.LONG },
- JMP_NEXT);
- public final static JOpcode IXOR =
- new JOpcode("IXOR",
- cIXOR,
- 1,
- INT_TYPE,
- new JType[] { JType.INT, JType.INT },
- JMP_NEXT);
- public final static JOpcode LXOR =
- new JOpcode("LXOR",
- cLXOR,
- 1,
- LONG_TYPE,
- new JType[] { JType.LONG, JType.LONG },
- JMP_NEXT);
- public final static JOpcode IINC =
- new JOpcode("IINC", cIINC, 3, NO_DATA, NO_DATA, JMP_NEXT);
- public final static JOpcode I2L =
- new JOpcode("I2L", cI2L, 1, LONG_TYPE, INT_TYPE, JMP_NEXT);
- public final static JOpcode I2F =
- new JOpcode("I2F", cI2F, 1, FLOAT_TYPE, INT_TYPE, JMP_NEXT);
- public final static JOpcode I2D =
- new JOpcode("I2D", cI2D, 1, DOUBLE_TYPE, INT_TYPE, JMP_NEXT);
- public final static JOpcode L2I =
- new JOpcode("L2I", cL2I, 1, INT_TYPE, LONG_TYPE, JMP_NEXT);
- public final static JOpcode L2F =
- new JOpcode("L2F", cL2F, 1, FLOAT_TYPE, LONG_TYPE, JMP_NEXT);
- public final static JOpcode L2D =
- new JOpcode("L2D", cL2D, 1, DOUBLE_TYPE, LONG_TYPE, JMP_NEXT);
- public final static JOpcode F2I =
- new JOpcode("F2I", cF2I, 1, INT_TYPE, FLOAT_TYPE, JMP_NEXT);
- public final static JOpcode F2L =
- new JOpcode("F2L", cF2L, 1, LONG_TYPE, FLOAT_TYPE, JMP_NEXT);
- public final static JOpcode F2D =
- new JOpcode("F2D", cF2D, 1, DOUBLE_TYPE, FLOAT_TYPE, JMP_NEXT);
- public final static JOpcode D2I =
- new JOpcode("D2I", cD2I, 1, INT_TYPE, DOUBLE_TYPE, JMP_NEXT);
- public final static JOpcode D2L =
- new JOpcode("D2L", cD2L, 1, LONG_TYPE, DOUBLE_TYPE, JMP_NEXT);
- public final static JOpcode D2F =
- new JOpcode("D2F", cD2F, 1, FLOAT_TYPE, DOUBLE_TYPE, JMP_NEXT);
- public final static JOpcode I2B =
- new JOpcode("I2B", cI2B, 1, INT_TYPE, INT_TYPE, JMP_NEXT);
- public final static JOpcode I2C =
- new JOpcode("I2C", cI2C, 1, INT_TYPE, INT_TYPE, JMP_NEXT);
- public final static JOpcode I2S =
- new JOpcode("I2S", cI2S, 1, INT_TYPE, INT_TYPE, JMP_NEXT);
- public final static JOpcode LCMP =
- new JOpcode("LCMP",
- cLCMP,
- 1,
- INT_TYPE,
- new JType[] { JType.LONG, JType.LONG },
- JMP_NEXT);
- public final static JOpcode FCMPL =
- new JOpcode("FCMPL",
- cFCMPL,
- 1,
- INT_TYPE,
- new JType[] { JType.FLOAT, JType.FLOAT },
- JMP_NEXT);
- public final static JOpcode FCMPG =
- new JOpcode("FCMPG",
- cFCMPG,
- 1,
- INT_TYPE,
- new JType[] { JType.FLOAT, JType.FLOAT },
- JMP_NEXT);
- public final static JOpcode DCMPL =
- new JOpcode("DCMPL",
- cDCMPL,
- 1,
- INT_TYPE,
- new JType[] { JType.LONG, JType.LONG },
- JMP_NEXT);
- public final static JOpcode DCMPG =
- new JOpcode("DCMPG",
- cDCMPG,
- 1,
- INT_TYPE,
- new JType[] { JType.DOUBLE, JType.DOUBLE },
- JMP_NEXT);
- public final static JOpcode IFEQ =
- new JOpcode("IFEQ", cIFEQ, 3, NO_DATA, INT_TYPE, JMP_MAYBE_S2_OFFSET);
- public final static JOpcode IFNE =
- new JOpcode("IFNE", cIFNE, 3, NO_DATA, INT_TYPE, JMP_MAYBE_S2_OFFSET);
- public final static JOpcode IFLT =
- new JOpcode("IFLT", cIFLT, 3, NO_DATA, INT_TYPE, JMP_MAYBE_S2_OFFSET);
- public final static JOpcode IFGE =
- new JOpcode("IFGE", cIFGE, 3, NO_DATA, INT_TYPE, JMP_MAYBE_S2_OFFSET);
- public final static JOpcode IFGT =
- new JOpcode("IFGT", cIFGT, 3, NO_DATA, INT_TYPE, JMP_MAYBE_S2_OFFSET);
- public final static JOpcode IFLE =
- new JOpcode("IFLE", cIFLE, 3, NO_DATA, INT_TYPE, JMP_MAYBE_S2_OFFSET);
- public final static JOpcode IF_ICMPEQ =
- new JOpcode("IF_ICMPEQ",
- cIF_ICMPEQ,
- 3,
- NO_DATA,
- new JType[] { JType.INT, JType.INT },
- JMP_MAYBE_S2_OFFSET);
- public final static JOpcode IF_ICMPNE =
- new JOpcode("IF_ICMPNE",
- cIF_ICMPNE,
- 3,
- NO_DATA,
- new JType[] { JType.INT, JType.INT },
- JMP_MAYBE_S2_OFFSET);
- public final static JOpcode IF_ICMPLT =
- new JOpcode("IF_ICMPLT",
- cIF_ICMPLT,
- 3,
- NO_DATA,
- new JType[] { JType.INT, JType.INT },
- JMP_MAYBE_S2_OFFSET);
- public final static JOpcode IF_ICMPGE =
- new JOpcode("IF_ICMPGE",
- cIF_ICMPGE,
- 3,
- NO_DATA,
- new JType[] { JType.INT, JType.INT },
- JMP_MAYBE_S2_OFFSET);
- public final static JOpcode IF_ICMPGT =
- new JOpcode("IF_ICMPGT",
- cIF_ICMPGT,
- 3,
- NO_DATA,
- new JType[] { JType.INT, JType.INT },
- JMP_MAYBE_S2_OFFSET);
- public final static JOpcode IF_ICMPLE =
- new JOpcode("IF_ICMPLE",
- cIF_ICMPLE,
- 3,
- NO_DATA,
- new JType[] { JType.INT, JType.INT },
- JMP_MAYBE_S2_OFFSET);
- public final static JOpcode IF_ACMPEQ =
- new JOpcode("IF_ACMPEQ",
- cIF_ACMPEQ,
- 3,
- NO_DATA,
- new JType[] { JType.REFERENCE, JType.REFERENCE },
- JMP_MAYBE_S2_OFFSET);
- public final static JOpcode IF_ACMPNE =
- new JOpcode("IF_ACMPNE",
- cIF_ACMPNE,
- 3,
- NO_DATA,
- new JType[] { JType.REFERENCE, JType.REFERENCE },
- JMP_MAYBE_S2_OFFSET);
- public final static JOpcode GOTO =
- new JOpcode("GOTO", cGOTO, 3, NO_DATA, NO_DATA, JMP_ALWAYS_S2_OFFSET);
- public final static JOpcode JSR =
- new JOpcode("JSR", cJSR, 3, ADDRESS_TYPE, NO_DATA, JMP_ALWAYS_S2_OFFSET);
- public final static JOpcode RET =
- new JOpcode("RET", cRET, 2, NO_DATA, NO_DATA, JMP_NONE);
- public final static JOpcode TABLESWITCH = new JOpcode("TABLESWITCH",
- cTABLESWITCH,
- UNKNOWN,
- NO_DATA,
- INT_TYPE,
- JMP_TABLE);
- public final static JOpcode LOOKUPSWITCH = new JOpcode("LOOKUPSWITCH",
- cLOOKUPSWITCH,
- UNKNOWN,
- NO_DATA,
- INT_TYPE,
- JMP_LOOKUP);
- public final static JOpcode IRETURN =
- new JOpcode("IRETURN", cIRETURN, 1, NO_DATA, INT_TYPE, JMP_NONE);
- public final static JOpcode LRETURN =
- new JOpcode("LRETURN", cLRETURN, 1, NO_DATA, LONG_TYPE, JMP_NONE);
- public final static JOpcode FRETURN =
- new JOpcode("FRETURN", cFRETURN, 1, NO_DATA, FLOAT_TYPE, JMP_NONE);
- public final static JOpcode DRETURN =
- new JOpcode("DRETURN", cDRETURN, 1, NO_DATA, DOUBLE_TYPE, JMP_NONE);
- public final static JOpcode ARETURN = new JOpcode("ARETURN",
- cARETURN,
- 1,
- NO_DATA,
- OBJECT_REF_TYPE,
- JMP_NONE);
- public final static JOpcode RETURN =
- new JOpcode("RETURN", cRETURN, 1, NO_DATA, NO_DATA, JMP_NONE);
- public final static JOpcode GETSTATIC = new JOpcode("GETSTATIC",
- cGETSTATIC,
- 3,
- UNKNOWN_TYPE,
- NO_DATA,
- JMP_NEXT);
- public final static JOpcode PUTSTATIC = new JOpcode("PUTSTATIC",
- cPUTSTATIC,
- 3,
- NO_DATA,
- UNKNOWN_TYPE,
- JMP_NEXT);
- public final static JOpcode GETFIELD = new JOpcode("GETFIELD",
- cGETFIELD,
- 3,
- UNKNOWN_TYPE,
- OBJECT_REF_TYPE,
- JMP_NEXT);
- public final static JOpcode PUTFIELD =
- new JOpcode("PUTFIELD", cPUTFIELD, 3, NO_DATA, UNKNOWN_TYPE, JMP_NEXT);
- public final static JOpcode INVOKEVIRTUAL = new JOpcode("INVOKEVIRTUAL",
- cINVOKEVIRTUAL,
- 3,
- NO_DATA,
- UNKNOWN_TYPE,
- JMP_NEXT);
- public final static JOpcode INVOKESPECIAL = new JOpcode("INVOKESPECIAL",
- cINVOKESPECIAL,
- 3,
- NO_DATA,
- UNKNOWN_TYPE,
- JMP_NEXT);
- public final static JOpcode INVOKESTATIC = new JOpcode("INVOKESTATIC",
- cINVOKESTATIC,
- 3,
- NO_DATA,
- UNKNOWN_TYPE,
- JMP_NEXT);
- public final static JOpcode INVOKEINTERFACE =
- new JOpcode("INVOKEINTERFACE",
- cINVOKEINTERFACE,
- 5,
- NO_DATA,
- UNKNOWN_TYPE,
- JMP_NEXT);
- public final static JOpcode NEW =
- new JOpcode("NEW", cNEW, 3, OBJECT_REF_TYPE, NO_DATA, JMP_NEXT);
- public final static JOpcode NEWARRAY =
- new JOpcode("NEWARRAY",
- cNEWARRAY,
- 2,
- ARRAY_REF_TYPE,
- INT_TYPE,
- JMP_NEXT);
- public final static JOpcode ANEWARRAY =
- new JOpcode("ANEWARRAY",
- cANEWARRAY,
- 3,
- ARRAY_REF_TYPE,
- INT_TYPE,
- JMP_NEXT);
- public final static JOpcode ARRAYLENGTH = new JOpcode("ARRAYLENGTH",
- cARRAYLENGTH,
- 1,
- INT_TYPE,
- ARRAY_REF_TYPE,
- JMP_NEXT);
- public final static JOpcode ATHROW = new JOpcode("ATHROW",
- cATHROW,
- 1,
- OBJECT_REF_TYPE,
- OBJECT_REF_TYPE,
- JMP_NONE);
- public final static JOpcode CHECKCAST = new JOpcode("CHECKCAST",
- cCHECKCAST,
- 3,
- OBJECT_REF_TYPE,
- OBJECT_REF_TYPE,
- JMP_NEXT);
- public final static JOpcode INSTANCEOF = new JOpcode("INSTANCEOF",
- cINSTANCEOF,
- 3,
- INT_TYPE,
- OBJECT_REF_TYPE,
- JMP_NEXT);
- public final static JOpcode MONITORENTER = new JOpcode("MONITORENTER",
- cMONITORENTER,
- 1,
- NO_DATA,
- OBJECT_REF_TYPE,
- JMP_NEXT);
- public final static JOpcode MONITOREXIT = new JOpcode("MONITOREXIT",
- cMONITOREXIT,
- 1,
- NO_DATA,
- OBJECT_REF_TYPE,
- JMP_NEXT);
- public final static JOpcode WIDE = new JOpcode("WIDE",
- cWIDE,
- UNKNOWN,
- UNKNOWN_TYPE,
- UNKNOWN_TYPE,
- JMP_NEXT);
- public final static JOpcode MULTIANEWARRAY = new JOpcode("MULTIANEWARRAY",
- cMULTIANEWARRAY,
- 4,
- ARRAY_REF_TYPE,
- UNKNOWN_TYPE,
- JMP_NEXT);
- public final static JOpcode IFNULL = new JOpcode("IFNULL",
- cIFNULL,
- 3,
- NO_DATA,
- REFERENCE_TYPE,
- JMP_MAYBE_S2_OFFSET);
- public final static JOpcode IFNONNULL = new JOpcode("IFNONNULL",
- cIFNONNULL,
- 3,
- NO_DATA,
- REFERENCE_TYPE,
- JMP_MAYBE_S2_OFFSET);
- public final static JOpcode GOTO_W = new JOpcode("GOTO_W",
- cGOTO_W,
- 5,
- NO_DATA,
- NO_DATA,
- JMP_ALWAYS_S4_OFFSET);
- public final static JOpcode JSR_W =
- new JOpcode("JSR_W", cJSR_W, 5, ADDRESS_TYPE, NO_DATA, JMP_NEXT);
-
- public final static JOpcode[] OPCODES = {
- NOP, ACONST_NULL, ICONST_M1, ICONST_0, ICONST_1,
- ICONST_2, ICONST_3, ICONST_4, ICONST_5, LCONST_0,
- LCONST_1, FCONST_0, FCONST_1, FCONST_2, DCONST_0,
- DCONST_1, BIPUSH, SIPUSH, LDC, LDC_W,
- LDC2_W, ILOAD, LLOAD, FLOAD, DLOAD,
- ALOAD, ILOAD_0, ILOAD_1, ILOAD_2, ILOAD_3,
- LLOAD_0, LLOAD_1, LLOAD_2, LLOAD_3, FLOAD_0,
- FLOAD_1, FLOAD_2, FLOAD_3, DLOAD_0, DLOAD_1,
- DLOAD_2, DLOAD_3, ALOAD_0, ALOAD_1, ALOAD_2,
- ALOAD_3, IALOAD, LALOAD, FALOAD, DALOAD,
- AALOAD, BALOAD, CALOAD, SALOAD, ISTORE,
- LSTORE, FSTORE, DSTORE, ASTORE, ISTORE_0,
- ISTORE_1, ISTORE_2, ISTORE_3, LSTORE_0, LSTORE_1,
- LSTORE_2, LSTORE_3, FSTORE_0, FSTORE_1, FSTORE_2,
- FSTORE_3, DSTORE_0, DSTORE_1, DSTORE_2, DSTORE_3,
- ASTORE_0, ASTORE_1, ASTORE_2, ASTORE_3, IASTORE,
- LASTORE, FASTORE, DASTORE, AASTORE, BASTORE,
- CASTORE, SASTORE, POP, POP2, DUP,
- DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2,
- SWAP, IADD, LADD, FADD, DADD,
- ISUB, LSUB, FSUB, DSUB, IMUL,
- LMUL, FMUL, DMUL, IDIV, LDIV,
- FDIV, DDIV, IREM, LREM, FREM,
- DREM, INEG, LNEG, FNEG, DNEG,
- ISHL, LSHL, ISHR, LSHR, IUSHR,
- LUSHR, IAND, LAND, IOR, LOR,
- IXOR, LXOR, IINC, I2L, I2F,
- I2D, L2I, L2F, L2D, F2I,
- F2L, F2D, D2I, D2L, D2F,
- I2B, I2C, I2S, LCMP, FCMPL,
- FCMPG, DCMPL, DCMPG, IFEQ, IFNE,
- IFLT, IFGE, IFGT, IFLE, IF_ICMPEQ,
- IF_ICMPNE, IF_ICMPLT, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE,
- IF_ACMPEQ, IF_ACMPNE, GOTO, JSR, RET,
- TABLESWITCH, LOOKUPSWITCH, IRETURN, LRETURN, FRETURN,
- DRETURN, ARETURN, RETURN, GETSTATIC, PUTSTATIC,
- GETFIELD, PUTFIELD, INVOKEVIRTUAL, INVOKESPECIAL, INVOKESTATIC,
- INVOKEINTERFACE, null, NEW, NEWARRAY, ANEWARRAY,
- ARRAYLENGTH, ATHROW, CHECKCAST, INSTANCEOF, MONITORENTER,
- MONITOREXIT, WIDE, MULTIANEWARRAY, IFNULL, IFNONNULL,
- GOTO_W, JSR_W
- };
-
- protected JOpcode(String name,
- int code,
- int size,
- JType[] producedDataTypes,
- JType[] consumedDataTypes,
- int jumpKind) {
- this.name = name;
- this.code = code;
- this.size = size;
- this.producedDataTypes = producedDataTypes;
- this.consumedDataTypes = consumedDataTypes;
- this.jumpKind = jumpKind;
- switch (jumpKind) {
- case JMP_NONE: successorCount = 0; break;
- case JMP_NEXT: successorCount = 1; break;
- case JMP_ALWAYS_S2_OFFSET: successorCount = 1; break;
- case JMP_ALWAYS_S4_OFFSET: successorCount = 1; break;
- case JMP_MAYBE_S2_OFFSET: successorCount = 2; break;
- case JMP_TABLE: successorCount = UNKNOWN; break;
- case JMP_LOOKUP: successorCount = UNKNOWN; break;
- default: successorCount = UNKNOWN; break;
- }
- }
-
- public String toString() { return name; }
- protected int getSize() { return size; }
- protected JType[] getProducedDataTypes() { return producedDataTypes; }
- protected JType[] getConsumedDataTypes() { return consumedDataTypes; }
-
- protected int getProducedDataSize() {
- if (producedDataTypes != UNKNOWN_TYPE)
- return JType.getTotalSize(producedDataTypes);
- else {
- switch (code) {
- case cLDC: case cLDC_W: case cBALOAD:
- return 1;
- case cLDC2_W: case cDUP: case cSWAP:
- return 2;
- case cDUP_X1:
- return 3;
- case cDUP_X2: case cDUP2:
- return 4;
- case cDUP2_X1:
- return 5;
- case cDUP2_X2:
- return 6;
- default:
- throw new Error(this.toString());
- }
- }
- }
-
- protected int getConsumedDataSize() {
- if (consumedDataTypes != UNKNOWN_TYPE)
- return JType.getTotalSize(consumedDataTypes);
- else {
- switch (code) {
- case cPOP: case cDUP:
- return 1;
- case cPOP2: case cDUP_X1: case cDUP2: case cSWAP:
- return 2;
- case cDUP_X2: case cDUP2_X1:
- return 3;
- case cDUP2_X2:
- return 4;
- default:
- throw new Error(this.toString());
- }
- }
- }
-
- protected int getProducedDataTypesNumber() {
- if (producedDataTypes != UNKNOWN_TYPE)
- return producedDataTypes.length;
- else {
- switch (code) {
- case cLDC: case cLDC_W: case cLDC2_W: case cBALOAD:
- case cGETSTATIC: case cGETFIELD:
- return 1;
- case cDUP: case cSWAP:
- return 2;
- case cDUP_X2: case cDUP2: case cDUP2_X1: case cDUP2_X2:
- return 2;
- case cDUP_X1:
- return 3;
- default:
- throw new Error(this.toString());
- }
- }
- }
-
- protected int getConsumedDataTypesNumber() {
- if (consumedDataTypes != UNKNOWN_TYPE)
- return consumedDataTypes.length;
- else {
- switch (code) {
- case cPOP: case cDUP: case cPUTSTATIC:
- return 1;
- case cPUTFIELD: case cDUP_X1: case cDUP_X2:
- case cDUP2: case cDUP2_X1: case cPOP2: case cSWAP:
- return 2;
- default:
- throw new Error(this.toString());
- }
- }
- }
-}
diff --git a/src/fjbg/ch/epfl/lamp/fjbg/JOtherAttribute.java b/src/fjbg/ch/epfl/lamp/fjbg/JOtherAttribute.java
deleted file mode 100644
index 50aa9d3636..0000000000
--- a/src/fjbg/ch/epfl/lamp/fjbg/JOtherAttribute.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/* FJBG -- Fast Java Bytecode Generator
- * Copyright 2002-2013 LAMP/EPFL
- * @author Michel Schinz
- */
-
-package ch.epfl.lamp.fjbg;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-
-/**
- * Attributes which are unknown to the JVM (or at least to this library).
- *
- * @author Michel Schinz
- * @version 1.0
- */
-
-public class JOtherAttribute extends JAttribute {
- protected final String name;
- protected final byte[] contents;
- protected final int length;
-
- public JOtherAttribute(FJBGContext context,
- JClass clazz,
- Object owner,
- String name,
- byte[] contents,
- int length) {
- super(context, clazz, name);
- this.name = name;
- this.contents = contents;
- this.length = length;
- }
-
- public JOtherAttribute(FJBGContext context,
- JClass clazz,
- Object owner,
- String name,
- int size,
- DataInputStream stream)
- throws IOException {
- super(context, clazz, name);
- this.name = name;
- this.contents = new byte[size];
- this.length = size;
-
- stream.read(contents, 0, length);
- }
-
- public String getName() { return name; }
-
- // Follows javap output format for user-defined attributes.
- /*@Override*/ public String toString() {
- StringBuffer buf = new StringBuffer(" ");
- buf.append(name);
- buf.append(": length = 0x");
- buf.append(Integer.toHexString(length).toUpperCase());
- for (int i = 0; i < length; ++i) {
- if (i % 16 == 0) buf.append("\n ");
- buf.append(hexString(contents[i]));
- buf.append(" ");
- }
- buf.append("\n");
- return buf.toString();
- }
-
- protected int getSize() { return length; }
-
- protected void writeContentsTo(DataOutputStream stream) throws IOException {
- stream.write(contents, 0, length);
- }
-
- private static final String hexString(int i) {
- return ((0 <= i && i < 16) ? "0" : "")+Integer.toHexString(i).toUpperCase();
- }
-}
diff --git a/src/fjbg/ch/epfl/lamp/fjbg/JReferenceType.java b/src/fjbg/ch/epfl/lamp/fjbg/JReferenceType.java
deleted file mode 100644
index 73d1026c04..0000000000
--- a/src/fjbg/ch/epfl/lamp/fjbg/JReferenceType.java
+++ /dev/null
@@ -1,19 +0,0 @@
-/* FJBG -- Fast Java Bytecode Generator
- * Copyright 2002-2013 LAMP/EPFL
- * @author Michel Schinz
- */
-
-package ch.epfl.lamp.fjbg;
-
-/**
- * Types for Java references, i.e. arrays and objects.
- *
- * @author Michel Schinz
- * @version 1.0
- */
-
-abstract public class JReferenceType extends JType {
- public boolean isReferenceType() { return true; }
-
- abstract public String getDescriptor();
-}
diff --git a/src/fjbg/ch/epfl/lamp/fjbg/JSourceFileAttribute.java b/src/fjbg/ch/epfl/lamp/fjbg/JSourceFileAttribute.java
deleted file mode 100644
index 3a17cb2c44..0000000000
--- a/src/fjbg/ch/epfl/lamp/fjbg/JSourceFileAttribute.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/* FJBG -- Fast Java Bytecode Generator
- * Copyright 2002-2013 LAMP/EPFL
- * @author Michel Schinz
- */
-
-package ch.epfl.lamp.fjbg;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-
-/**
- * Sourcefile attribute, which can be attached to class files to
- * associate them with their source file.
- *
- * There can be no more than one SourceFile attribute in the attributes table
- * of a given ClassFile structure. See section 4.8.9 of the JVM specification.
- *
- * @author Michel Schinz
- * @version 1.0
- */
-
-public class JSourceFileAttribute extends JAttribute {
- protected final String sourceFileName;
- protected final int sourceFileIndex;
-
- public JSourceFileAttribute(FJBGContext context,
- JClass clazz,
- String sourceFileName) {
- super(context, clazz);
- this.sourceFileName = sourceFileName;
- this.sourceFileIndex = clazz.getConstantPool().addUtf8(sourceFileName);
- }
-
- public JSourceFileAttribute(FJBGContext context,
- JClass clazz,
- Object owner,
- String name,
- int size,
- DataInputStream stream)
- throws IOException {
- super(context, clazz, name);
-
- this.sourceFileIndex = stream.readShort();
- this.sourceFileName = clazz.getConstantPool().lookupUtf8(sourceFileIndex);
-
- assert name.equals(getName());
- }
-
- public String getName() { return "SourceFile"; }
-
- public String getFileName() { return sourceFileName; }
-
- // Follows javap output format for SourceFile attribute.
- /*@Override*/ public String toString() {
- StringBuffer buf = new StringBuffer(" SourceFile: \"");
- buf.append(sourceFileName);
- buf.append("\"\n");
- return buf.toString();
- }
-
- protected int getSize() {
- return 2; // Short.SIZE
- }
-
- protected void writeContentsTo(DataOutputStream stream) throws IOException {
- stream.writeShort(sourceFileIndex);
- }
-}
diff --git a/src/fjbg/ch/epfl/lamp/fjbg/JStackMapTableAttribute.java b/src/fjbg/ch/epfl/lamp/fjbg/JStackMapTableAttribute.java
deleted file mode 100644
index 72a5484d40..0000000000
--- a/src/fjbg/ch/epfl/lamp/fjbg/JStackMapTableAttribute.java
+++ /dev/null
@@ -1,282 +0,0 @@
-/* FJBG -- Fast Java Bytecode Generator
- * Copyright 2002-2013 LAMP/EPFL
- * @author Michel Schinz
- */
-
-package ch.epfl.lamp.fjbg;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- *
- * @author Stephane Micheloud
- * @version 1.0
- */
-
-public class JStackMapTableAttribute extends JAttribute {
- /** Constant pool of the current classfile. */
- private JConstantPool pool;
-
- /** StackMapTable entries */
- protected final List/*<Frame>*/ entries = new ArrayList();
- protected int entriesSize = 0;
- protected boolean usesU2;
-
- public JStackMapTableAttribute(FJBGContext context,
- JClass clazz,
- JCode code) {
- super(context, clazz);
- this.pool = clazz.pool;
-
- assert code.getOwner().getOwner() == clazz;
- }
-
- public JStackMapTableAttribute(FJBGContext context,
- JClass clazz,
- Object owner,
- String name,
- int size,
- DataInputStream stream)
- throws IOException {
- super(context, clazz, name);
- this.pool = clazz.pool;
-
- int count = stream.readShort();
- this.usesU2 = count < 65536;
- for (int i = 0; i < count; ++i)
- this.entries.add(new Frame(stream));
- this.entriesSize = computeSize();
-
- assert name.equals(getName());
- }
-
- public String getName() { return "StackMapTable"; }
-
- // Follows javap output format for StackMapTable attribute.
- /*@Override*/ public String toString() {
- Frame frame = null;
- StringBuffer buf = new StringBuffer(" StackMapTable: number_of_entries = ");
- buf.append(entries.size());
- Iterator it = entries.iterator();
- while (it.hasNext()) {
- frame = (Frame)it.next();
- buf.append("\n frame_type = ");
- buf.append(frame.tag);
- buf.append(" /* ");
- buf.append(getFrameType(frame.tag));
- buf.append(" */");
- if (frame.offsetDelta != -1)
- buf.append("\n offset_delta = "+frame.offsetDelta);
- if (frame.locals != null)
- appendTypeInfoArray(buf, "locals", frame.locals);
- if (frame.stackItems != null)
- appendTypeInfoArray(buf, "stack", frame.stackItems);
- }
- buf.append("\n");
- return buf.toString();
- }
-
- protected int getSize() {
- return entriesSize;
- }
-
- protected void writeContentsTo(DataOutputStream stream) throws IOException {
- stream.writeShort(entriesSize);
- Iterator it = entries.iterator();
- while (it.hasNext()) {
- Frame frame = (Frame)it.next();
- frame.writeContentsTo(stream);
- }
- }
-
- private class TypeInfo {
- final int tag;
- final int poolIndexOrOffset; // tag == 7 => poolIndex, tag = 8 => offset
- private int bytes;
- TypeInfo(DataInputStream stream) throws IOException {
- int size = 1;
- this.tag = stream.readByte();
- if (tag == 7) { // ITEM_Object; // 7
- poolIndexOrOffset = stream.readShort();
- size += 2;
- } else if (tag == 8) { // ITEM_Uninitialized // 8
- poolIndexOrOffset = (usesU2) ? stream.readShort() : stream.readInt();
- size += (usesU2) ? 2 : 4;
- } else
- poolIndexOrOffset = -1;
- this.bytes += size;
- }
- int getSize() { return bytes; }
- void writeContentsTo(DataOutputStream stream) throws IOException {
- stream.writeByte(tag);
- if (tag == 7) { // ITEM_Object; // 7
- stream.writeShort(poolIndexOrOffset);
- } else if (tag == 8) { // ITEM_Uninitialized // 8
- if (usesU2) stream.writeShort(poolIndexOrOffset);
- else stream.writeInt(poolIndexOrOffset);
- }
- }
- /*@Override*/ public String toString() {
- switch (tag) {
- case 0: // ITEM_Top
- return "<top>";
- case 1: // ITEM_Integer
- return "int";
- case 2: // ITEM_Float
- return "float";
- case 3: // ITEM_Double
- return "double";
- case 4: // ITEM_Long
- return "long";
- case 5: // ITEM_Null
- return "null";
- case 6: // ITEM_UninializedThis
- return "this";
- case 7: // ITEM_Object
- String name = pool.lookupClass(poolIndexOrOffset);
- if (name.startsWith("[")) name = "\""+name+"\"";
- return "class "+name;
- case 8: // ITEM_Uninitialized
- return "<uninitialized>";
- default:
- return String.valueOf(tag);
- }
- }
- }
-
- private class Frame {
- final int tag;
- int offsetDelta = -1;
- TypeInfo[] stackItems = null;
- TypeInfo[] locals = null;
- private int bytes;
- Frame(DataInputStream stream) throws IOException {
- // The stack_map_frame structure consists of a one-byte tag
- // followed by zero or more bytes.
- this.tag = stream.readUnsignedByte();
- if (tag < 64) { // SAME; // 0-63
- //done
- } else if (tag < 128) { // SAME_LOCALS_1_STACK_ITEM; // 64-127
- this.offsetDelta = tag - 64;
- readStackItems(stream, 1);
- } else if (tag < 248) { // reserved for future use.
- assert false : "Tags in the range [128-247] are reserved for future use.";
- } else if (tag < 251) { // CHOP; // 248-250
- int k = 251 - tag;
- readOffsetDelta(stream);
- } else if (tag == 251) { // SAME_FRAME_EXTENDED
- readOffsetDelta(stream);
- } else if (tag < 255) { // APPEND; // 252-254
- readOffsetDelta(stream);
- readLocals(stream, tag - 251);
- } else { // FULL_FRAME; // 255
- readOffsetDelta(stream);
- readLocals(stream);
- readStackItems(stream);
- }
- }
- int getSize() { return bytes; }
- void readOffsetDelta(DataInputStream stream) throws IOException {
- this.offsetDelta = (usesU2) ? stream.readShort() : stream.readInt();
- this.bytes += (usesU2) ? 2 : 4;
- }
- int getOffsetDelta() { return offsetDelta; }
- void readStackItems(DataInputStream stream, int k) throws IOException {
- this.stackItems = new TypeInfo[k];
- for (int i = 0; i < k; ++i) {
- stackItems[i] = new TypeInfo(stream);
- this.bytes += stackItems[i].getSize();
- }
- }
- void readStackItems(DataInputStream stream) throws IOException {
- int k = (usesU2) ? stream.readShort() : stream.readInt();
- this.bytes += (usesU2) ? 2 : 4;
- readStackItems(stream, k);
- }
- void readLocals(DataInputStream stream, int k) throws IOException {
- this.locals = new TypeInfo[k];
- for (int i = 0; i < k; ++i) {
- locals[i] = new TypeInfo(stream);
- this.bytes += locals[i].getSize();
- }
- }
- void readLocals(DataInputStream stream) throws IOException {
- int k = (usesU2) ? stream.readShort() : stream.readInt();
- this.bytes += (usesU2) ? 2 : 4;
- readLocals(stream, k);
- }
- void writeContentsTo(DataOutputStream stream) throws IOException {
- stream.writeByte(tag);
- if (tag < 64) {
- //done
- } else if (tag < 128) { // SAME; // 0-63
- assert stackItems.length == 1;
- stackItems[0].writeContentsTo(stream);
- } else if (tag < 248) {
- assert false : "Tags in the range [128-247] are reserved for future use.";
- } else if (tag < 251) {
- if (usesU2) stream.writeShort(offsetDelta);
- else stream.writeInt(offsetDelta);
- } else if (tag == 251) {
- if (usesU2) stream.writeShort(offsetDelta);
- else stream.writeInt(offsetDelta);
- } else if (tag < 255) { // APPEND; // 252-254
- if (usesU2) stream.writeShort(offsetDelta);
- else stream.writeInt(offsetDelta);
- for (int i = 0; i < locals.length; ++i)
- locals[i].writeContentsTo(stream);
- } else {
- if (usesU2) stream.writeShort(offsetDelta);
- else stream.writeInt(offsetDelta);
- for (int i = 0; i < locals.length; ++i)
- locals[i].writeContentsTo(stream);
- for (int i = 0; i < stackItems.length; ++i)
- stackItems[i].writeContentsTo(stream);
- }
- }
- }
-
- private int computeSize() {
- int size = (usesU2) ? 2 : 4; // number of frames
- Iterator it = entries.iterator();
- while (it.hasNext()) {
- Frame frame = (Frame)it.next();
- size += frame.getSize();
- }
- return size;
- }
-
- private static final String getFrameType(int tag) {
- if (tag < 64) return "same";
- else if (tag < 128) return "same locals 1 stack item";
- else if (tag < 248) return "<reserved>";
- else if (tag < 251) return "chop";
- else if (tag == 251) return "same frame extended";
- else if (tag < 255) return "append";
- else return "full frame";
- }
-
- private static StringBuffer appendTypeInfoArray(StringBuffer buf,
- String s, TypeInfo[] a) {
- buf.append("\n ");
- buf.append(s);
- buf.append(" = ");
- if (a.length > 0) {
- buf.append("[ ");
- for (int i = 0; i < a.length; ++i) {
- if (i > 0) buf.append(", ");
- buf.append(a[i]);
- }
- buf.append(" ]");
- }
- else
- buf.append("[]");
- return buf;
- }
-
-}
diff --git a/src/fjbg/ch/epfl/lamp/fjbg/JType.java b/src/fjbg/ch/epfl/lamp/fjbg/JType.java
deleted file mode 100644
index 298a2b0565..0000000000
--- a/src/fjbg/ch/epfl/lamp/fjbg/JType.java
+++ /dev/null
@@ -1,316 +0,0 @@
-/* FJBG -- Fast Java Bytecode Generator
- * Copyright 2002-2013 LAMP/EPFL
- * @author Michel Schinz
- */
-
-package ch.epfl.lamp.fjbg;
-
-import java.io.IOException;
-import java.io.StringReader;
-import java.util.ArrayList;
-
-/**
- * Representation of Java types.
- *
- * @version 1.0
- * @author Michel Schinz
- */
-
-abstract public class JType {
- abstract public int getSize();
- abstract public String getSignature();
- abstract public int getTag();
- abstract public String toString();
- abstract public boolean isCompatibleWith(JType other);
-
- public boolean isValueType() { return false; }
- public boolean isObjectType() { return false; }
- public boolean isArrayType() { return false; }
- public boolean isReferenceType() { return false; }
-
- // Tags for types. Taken from BCEL.
- public static final int T_BOOLEAN = 4;
- public static final int T_CHAR = 5;
- public static final int T_FLOAT = 6;
- public static final int T_DOUBLE = 7;
- public static final int T_BYTE = 8;
- public static final int T_SHORT = 9;
- public static final int T_INT = 10;
- public static final int T_LONG = 11;
- public static final int T_VOID = 12; // Non-standard
- public static final int T_ARRAY = 13;
- public static final int T_OBJECT = 14;
- public static final int T_UNKNOWN = 15;
- public static final int T_ADDRESS = 16;
-
- public static final int T_REFERENCE = 17; // type compatible with references
-
- public static final JType[] EMPTY_ARRAY = new JType[0];
-
- protected static JType parseSig(StringReader s) throws IOException {
- int nextChar = s.read();
- if (nextChar == -1) throw new IllegalArgumentException();
-
- switch ((char)nextChar) {
- case 'V' : return VOID;
- case 'Z' : return BOOLEAN;
- case 'B' : return BYTE;
- case 'C' : return CHAR;
- case 'S' : return SHORT;
- case 'I' : return INT;
- case 'F' : return FLOAT;
- case 'J' : return LONG;
- case 'D' : return DOUBLE;
- case 'L': {
- StringBuffer className = new StringBuffer();
- for (;;) {
- nextChar = s.read();
- if (nextChar == -1 || nextChar == ';') break;
- className.append(nextChar == '/' ? ':' : ((char)nextChar));
- }
- if (nextChar != ';') throw new IllegalArgumentException();
- return new JObjectType(className.toString());
- }
- case '[': {
- JType elemType = parseSig(s);
- return new JArrayType(elemType);
- }
- case '(': {
- ArrayList argTps = new ArrayList();
- for (;;) {
- s.mark(1);
- nextChar = s.read();
- if (nextChar == -1 || nextChar == ')') break;
- s.reset();
- argTps.add(parseSig(s));
- }
- if (nextChar != ')') throw new IllegalArgumentException("a");
- JType[] argTpsA = (JType[])argTps.toArray(new JType[argTps.size()]);
- JType returnType = parseSig(s);
- return new JMethodType(returnType, argTpsA);
- }
- default:
- throw new IllegalArgumentException();
- }
- }
-
- /**
- * A signature is a string representing the generic type of a field or
- * method, or generic type information for a class declaration.
- * See section 4.4.4 of the JVM specification.
- */
- public static JType parseSignature(String signature) {
- try {
- StringReader sigReader = new StringReader(signature);
- JType parsed = parseSig(sigReader);
- if (sigReader.read() != -1)
- throw new IllegalArgumentException();
- return parsed;
- } catch (IllegalArgumentException e) {
- throw new IllegalArgumentException("invalid signature " + signature);
- } catch (IOException e) {
- throw new Error(e);
- }
- }
-
- public static int getTotalSize(JType[] types) {
- int size = 0;
- for (int i = 0; i < types.length; ++i)
- size += types[i].getSize();
- return size;
- }
-
- protected JType() {}
-
- public static JType VOID = new JType() {
- public int getSize() { return 0; }
- public String getSignature() { return "V"; }
- public int getTag() { return T_VOID; }
- public String toString() { return "void"; }
- public boolean isCompatibleWith(JType other) {
- throw new UnsupportedOperationException("type VOID is no real "
- + "data type therefore "
- + "cannot be assigned to "
- + other.toString());
- }
- };
-
- public static JType BOOLEAN = new JType() {
- public int getSize() { return 1; }
- public String getSignature() { return "Z"; }
- public int getTag() { return T_BOOLEAN; }
- public String toString() { return "boolean"; }
- public boolean isValueType() { return true; }
- public boolean isCompatibleWith(JType other) {
- return other == BOOLEAN
- || other == INT
- || other == BYTE
- || other == CHAR
- || other == SHORT;
- }
- };
-
- public static JType BYTE = new JType() {
- public int getSize() { return 1; }
- public String getSignature() { return "B"; }
- public int getTag() { return T_BYTE; }
- public String toString() { return "byte"; }
- public boolean isValueType() { return true; }
- public boolean isCompatibleWith(JType other) {
- return other == BOOLEAN
- || other == INT
- || other == BYTE
- || other == CHAR
- || other == SHORT;
- }
- };
-
- public static JType CHAR = new JType() {
- public int getSize() { return 1; }
- public String getSignature() { return "C"; }
- public int getTag() { return T_CHAR; }
- public String toString() { return "char"; }
- public boolean isValueType() { return true; }
- public boolean isCompatibleWith(JType other) {
- return other == BOOLEAN
- || other == INT
- || other == BYTE
- || other == CHAR
- || other == SHORT;
- }
- };
-
- public static JType SHORT = new JType() {
- public int getSize() { return 1; }
- public String getSignature() { return "S"; }
- public int getTag() { return T_SHORT; }
- public String toString() { return "short"; }
- public boolean isValueType() { return true; }
- public boolean isCompatibleWith(JType other) {
- return other == BOOLEAN
- || other == INT
- || other == BYTE
- || other == CHAR
- || other == SHORT;
- }
- };
-
- public static JType INT = new JType() {
- public int getSize() { return 1; }
- public String getSignature() { return "I"; }
- public int getTag() { return T_INT; }
- public String toString() { return "int"; }
- public boolean isValueType() { return true; }
- public boolean isCompatibleWith(JType other) {
- return other == BOOLEAN
- || other == INT
- || other == BYTE
- || other == CHAR
- || other == SHORT;
- }
- };
-
- public static JType FLOAT = new JType() {
- public int getSize() { return 1; }
- public String getSignature() { return "F"; }
- public int getTag() { return T_FLOAT; }
- public String toString() { return "float"; }
- public boolean isValueType() { return true; }
- public boolean isCompatibleWith(JType other) {
- return other == FLOAT;
- }
- };
-
- public static JType LONG = new JType() {
- public int getSize() { return 2; }
- public String getSignature() { return "J"; }
- public int getTag() { return T_LONG; }
- public String toString() { return "long"; }
- public boolean isValueType() { return true; }
- public boolean isCompatibleWith(JType other) {
- return other == LONG;
- }
- };
-
- public static JType DOUBLE = new JType() {
- public int getSize() { return 2; }
- public String getSignature() { return "D"; }
- public int getTag() { return T_DOUBLE; }
- public String toString() { return "double"; }
- public boolean isValueType() { return true; }
- public boolean isCompatibleWith(JType other) {
- return other == DOUBLE;
- }
- };
-
- public static JType REFERENCE = new JType() {
- public int getSize() { return 1; }
- public String getSignature() {
- throw new UnsupportedOperationException("type REFERENCE is no real "
- + "data type and therefore "
- + "has no signature");
- }
- public int getTag() { return T_REFERENCE; }
- public String toString() { return "<reference>"; }
- public boolean isCompatibleWith(JType other) {
- throw new UnsupportedOperationException("type REFERENCE is no real "
- + "data type and therefore "
- + "cannot be assigned to "
- + other.toString());
- }
- };
-
- public static JType ADDRESS = new JType() {
- public int getSize() { return 1; }
- public String getSignature() {
- throw new UnsupportedOperationException("type ADDRESS is no usable "
- + "data type and therefore "
- + "has no signature");
- }
- public int getTag() { return T_ADDRESS; }
- public String toString() { return "<address>"; }
- public boolean isCompatibleWith(JType other) {
- return other == ADDRESS;
- }
- };
-
- public static JType UNKNOWN = new JType() {
- public int getSize() {
- throw new UnsupportedOperationException("type UNKNOWN is no real "
- + "data type and therefore "
- + "has no size");
- }
- public String getSignature() {
- throw new UnsupportedOperationException("type UNKNOWN is no real "
- + "data type and therefore "
- + "has no signature");
- }
- public int getTag() { return T_UNKNOWN; }
- public String toString() { return "<unknown>"; }
- public boolean isCompatibleWith(JType other) {
- throw new UnsupportedOperationException("type UNKNOWN is no real "
- + "data type and therefore "
- + "cannot be assigned to "
- + other.toString());
- }
- };
-
- protected static String tagToString(int tag) {
- switch (tag) {
- case T_BOOLEAN : return "boolean";
- case T_CHAR : return "char";
- case T_FLOAT : return "float";
- case T_DOUBLE : return "double";
- case T_BYTE : return "byte";
- case T_SHORT : return "short";
- case T_INT : return "int";
- case T_LONG : return "long";
- case T_VOID : return "void"; // Non-standard
- case T_ARRAY : return "[]";
- case T_OBJECT : return "Object";
- case T_UNKNOWN : return "<unknown>";
- case T_ADDRESS : return "<address>";
- default: return String.valueOf(tag);
- }
- }
-}
diff --git a/src/fjbg/ch/epfl/lamp/fjbg/Main.java b/src/fjbg/ch/epfl/lamp/fjbg/Main.java
deleted file mode 100644
index 810ee7c400..0000000000
--- a/src/fjbg/ch/epfl/lamp/fjbg/Main.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/* FJBG -- Fast Java Bytecode Generator
- * Copyright 2002-2013 LAMP/EPFL
- * @author Michel Schinz
- */
-
-package ch.epfl.lamp.fjbg;
-
-import java.io.DataInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.jar.JarFile;
-import java.util.zip.ZipEntry;
-
-/**
- * Main program entry to execute the FJBG reader from the command line.
- *
- * The reader prints out the decoded data in the same output format as
- * javap, the Java bytecode disassembler of the Sun J2SE SDK.
- *
- * @author Stephane Micheloud
- * @version 1.1
- */
-
-public class Main {
- private static final String PRODUCT_STRING = "Fast Java Bytecode Generator";
- private static final String VERSION_STRING = "version 1.1";
-
- private static final int ACTION_USAGE = 0;
- private static final int ACTION_DONE = 1;
- private static final int ACTION_PROCEED = 2;
-
- private static String classPath = ".";
- private static String[] classNames = null;
-
- public static void main(String[] args) {
- switch (parseArgs(args)) {
- case ACTION_USAGE: printUsage(); break;
- case ACTION_PROCEED: processClasses(); break;
- default:
- }
- }
-
- private static void processClasses() {
- FJBGContext fjbgContext = new FJBGContext(49, 0);
- if (classNames.length > 0)
- try {
- for (int i = 0; i < classNames.length; ++i)
- processClass(fjbgContext, classNames[i]);
- } catch (IOException e) {
- System.err.println(e.getMessage());
- }
- else
- System.err.println(
- "No classes were specified on the command line. Try -help.");
- }
-
- private static void processClass(FJBGContext fjbgContext, String className)
- throws IOException {
- InputStream in = getInputStream(className);
- JClass jclass = fjbgContext.JClass(new DataInputStream(in));
- System.out.println(jclass);
- in.close();
- }
-
- private static InputStream getInputStream(String className) throws IOException {
- String name = null;
- String[] paths = classPath.split(File.pathSeparator);
- for (int i = 0; i < paths.length; ++i) {
- File parent = new File(paths[i]);
- if (parent.isDirectory()) {
- name = className.replace('.', File.separatorChar)+".class";
- File f = new File(parent, name);
- if (f.isFile()) return new FileInputStream(f);
- } else if (paths[i].endsWith(".jar")) {
- JarFile f = new JarFile(parent);
- name = className.replace('.', '/')+".class";
- ZipEntry e = f.getEntry(name);
- if (e != null) return f.getInputStream(e);
- }
- }
- throw new IOException("ERROR:Could not find "+className);
- }
-
- private static int parseArgs(String[] args) {
- ArrayList/*<String>*/ classes = new ArrayList();
- String arg = null;
- int action = ACTION_USAGE;
- int i = 0, n = args.length;
- while (i < n) {
- arg = args[i];
- if (arg.equals("-classpath") && (i+1) < n) {
- classPath = args[i+1]; i += 2;
- } else if (arg.equals("-cp") && (i+1) < n) {
- classPath = args[i+1]; i += 2;
- } else if (arg.equals("-help")) {
- i = n+1;
- //} else if (arg.equals("-v")) {
- // verbose = true; i += 1;
- } else if (arg.equals("-version")) {
- System.err.println(PRODUCT_STRING+" "+VERSION_STRING);
- action = ACTION_DONE; i = n+1;
- } else if (arg.startsWith("-")) {
- System.err.println("invalid flag: "+arg);
- i = n+1;
- } else {
- classes.add(arg); i += 1;
- }
- }
- if (i == n && i > 0) {
- classNames = (String[])classes.toArray(new String[classes.size()]);
- action = ACTION_PROCEED;
- }
- return action;
- }
-
- private static void printUsage() {
- System.out.println("Usage: fjbg <options> <classes>");
- System.out.println();
- System.out.println("where possible options include:");
- System.out.println(" -cp <path> Specify where to find user class files");
- System.out.println(" -classpath <path> Specify where to find user class files");
- System.out.println(" -help Print a synopsis of standard options");
- System.out.println(" -version Version information");
- System.out.println();
- System.exit(1);
- }
-}
-
diff --git a/src/fjbg/ch/epfl/lamp/util/ByteArray.java b/src/fjbg/ch/epfl/lamp/util/ByteArray.java
deleted file mode 100644
index b852e1ac1f..0000000000
--- a/src/fjbg/ch/epfl/lamp/util/ByteArray.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/* FJBG -- Fast Java Bytecode Generator
- * Copyright 2002-2013 LAMP/EPFL
- * @author Michel Schinz
- */
-
-package ch.epfl.lamp.util;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-/**
- * Array of bytes.
- *
- * @author Michel Schinz
- * @version 1.0
- */
-
-public class ByteArray {
- protected final static int BYTE_BLOCK_BITS = 8;
- protected final static int BYTE_BLOCK_SIZE = 1 << BYTE_BLOCK_BITS;
- protected final static int BYTE_BLOCK_MASK = BYTE_BLOCK_SIZE - 1;
-
- protected byte[][] data = new byte[][] { new byte[BYTE_BLOCK_SIZE] };
- protected int pos = 0; // The next free position.
-
- protected boolean frozen = false;
-
- public ByteArray() { }
-
- public ByteArray(InputStream stream, int size) throws IOException {
- pos = size;
- for (int i = 0; size > 0; ++i) {
- int sizeToRead = Math.min(BYTE_BLOCK_SIZE, size);
- stream.read(data[i], 0, sizeToRead);
-
- size -= sizeToRead;
- if (size > 0) addNewBlock();
- }
- }
-
- public void freeze() { frozen = true; }
-
- public int nextBytePosition() {
- return pos;
- }
-
- public int getSize() {
- return pos;
- }
-
- protected void addNewBlock() {
- int nextBlockPos = pos >>> BYTE_BLOCK_BITS;
- if (nextBlockPos == data.length) {
- byte[][] newData = new byte[data.length * 2][];
- System.arraycopy(data, 0, newData, 0, data.length);
- data = newData;
- }
- assert data[nextBlockPos] == null : pos + " " + nextBlockPos;
- data[nextBlockPos] = new byte[BYTE_BLOCK_SIZE];
- }
-
- protected void addByte(int b) {
- assert !frozen;
-
- if ((pos & BYTE_BLOCK_MASK) == 0 && pos > 0)
- addNewBlock();
- int currPos = pos++;
- data[currPos >>> BYTE_BLOCK_BITS][currPos & BYTE_BLOCK_MASK] = (byte)b;
- }
-
- public void addU1(int i) {
- assert i <= 0xFF : i;
- addByte(i);
- }
-
- public void addU2(int i) {
- assert i <= 0xFFFF : i;
-
- addByte(i >>> 8);
- addByte(i & 0xFF);
- }
-
- public void addU4(int i) {
- addByte(i >>> 24);
- addByte((i >>> 16) & 0xFF);
- addByte((i >>> 8) & 0xFF);
- addByte(i & 0xFF);
- }
-
- public void putByte(int targetPos, int b) {
- assert !frozen;
- assert targetPos < pos : targetPos + " >= " + pos;
-
- data[targetPos >>> BYTE_BLOCK_BITS][targetPos & BYTE_BLOCK_MASK] = (byte)b;
- }
-
- public void putU2(int targetPos, int i) {
- assert i < 0xFFFF : i;
- putByte(targetPos, i >>> 8);
- putByte(targetPos + 1, i & 0xFF);
- }
-
- public void putU4(int targetPos, int i) {
- putByte(targetPos, i >>> 24);
- putByte(targetPos + 1, (i >>> 16) & 0xFF);
- putByte(targetPos + 2, (i >>> 8) & 0xFF);
- putByte(targetPos + 3, i & 0xFF);
- }
-
- public int getU1(int sourcePos) {
- assert sourcePos < pos : sourcePos + " >= " + pos;
- return data[sourcePos >>> BYTE_BLOCK_BITS][sourcePos & BYTE_BLOCK_MASK] & 0xFF;
- }
-
- public int getU2(int sourcePos) {
- return (getU1(sourcePos) << 8) | getU1(sourcePos + 1);
- }
-
- public int getU4(int sourcePos) {
- return (getU2(sourcePos) << 16) | getU2(sourcePos + 2);
- }
-
- public int getS1(int sourcePos) {
- assert sourcePos < pos : sourcePos + " >= " + pos;
- return data[sourcePos >>> BYTE_BLOCK_BITS][sourcePos & BYTE_BLOCK_MASK];
- }
-
- public int getS2(int sourcePos) {
- return (getS1(sourcePos) << 8) | getU1(sourcePos + 1);
- }
-
- public int getS4(int sourcePos) {
- return (getS2(sourcePos) << 16) | getU2(sourcePos + 2);
- }
-
- public void writeTo(OutputStream stream) throws IOException {
- if (!frozen) freeze();
-
- for (int i = 0; i < data.length && data[i] != null; ++i) {
- int len = Math.min(BYTE_BLOCK_SIZE, pos - (i << BYTE_BLOCK_BITS));
- stream.write(data[i], 0, len);
- }
- }
-}
diff --git a/src/intellij/compiler.iml.SAMPLE b/src/intellij/compiler.iml.SAMPLE
index 696c347b7b..f8b1f31327 100644
--- a/src/intellij/compiler.iml.SAMPLE
+++ b/src/intellij/compiler.iml.SAMPLE
@@ -20,8 +20,6 @@
<orderEntry type="module" module-name="library" />
<orderEntry type="module" module-name="reflect" />
<orderEntry type="module" module-name="asm" />
- <orderEntry type="module" module-name="fjbg" />
- <orderEntry type="module" module-name="msil" />
<orderEntry type="library" name="ant" level="application" />
<orderEntry type="library" name="jline" level="project" />
</component>
diff --git a/src/intellij/fjbg.iml.SAMPLE b/src/intellij/fjbg.iml.SAMPLE
deleted file mode 100644
index 03eca69246..0000000000
--- a/src/intellij/fjbg.iml.SAMPLE
+++ /dev/null
@@ -1,12 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<module type="JAVA_MODULE" version="4">
- <component name="NewModuleRootManager" inherit-compiler-output="true">
- <exclude-output />
- <content url="file://$MODULE_DIR$/../fjbg">
- <sourceFolder url="file://$MODULE_DIR$/../fjbg" isTestSource="false" />
- </content>
- <orderEntry type="inheritedJdk" />
- <orderEntry type="sourceFolder" forTests="false" />
- </component>
-</module>
-
diff --git a/src/intellij/msil.iml.SAMPLE b/src/intellij/msil.iml.SAMPLE
deleted file mode 100644
index 56f794785f..0000000000
--- a/src/intellij/msil.iml.SAMPLE
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<module type="JAVA_MODULE" version="4">
- <component name="FacetManager">
- <facet type="scala" name="Scala">
- <configuration>
- <option name="compilerLibraryLevel" value="Project" />
- <option name="compilerLibraryName" value="compiler-locker" />
- <option name="maximumHeapSize" value="1536" />
- <option name="vmOptions" value="-Xms1536m -Xss1m -XX:MaxPermSize=512M -XX:ReservedCodeCacheSize=256m -XX:+CMSClassUnloadingEnabled -XX:+UseCompressedOops -XX:+UseParallelGC" />
- </configuration>
- </facet>
- </component>
- <component name="NewModuleRootManager" inherit-compiler-output="true">
- <exclude-output />
- <content url="file://$MODULE_DIR$/../msil">
- <sourceFolder url="file://$MODULE_DIR$/../msil" isTestSource="false" />
- <excludeFolder url="file://$MODULE_DIR$/../msil/ch/epfl/lamp/compiler/msil/tests" />
- </content>
- <orderEntry type="inheritedJdk" />
- <orderEntry type="sourceFolder" forTests="false" />
- <orderEntry type="module" module-name="library" />
- </component>
-</module>
-
diff --git a/src/intellij/scala-lang.ipr.SAMPLE b/src/intellij/scala-lang.ipr.SAMPLE
index 37307c2029..a8cb5eacc1 100644
--- a/src/intellij/scala-lang.ipr.SAMPLE
+++ b/src/intellij/scala-lang.ipr.SAMPLE
@@ -198,11 +198,9 @@
<module fileurl="file://$PROJECT_DIR$/actors.iml" filepath="$PROJECT_DIR$/actors.iml" />
<module fileurl="file://$PROJECT_DIR$/asm.iml" filepath="$PROJECT_DIR$/asm.iml" />
<module fileurl="file://$PROJECT_DIR$/compiler.iml" filepath="$PROJECT_DIR$/compiler.iml" />
- <module fileurl="file://$PROJECT_DIR$/fjbg.iml" filepath="$PROJECT_DIR$/fjbg.iml" />
<module fileurl="file://$PROJECT_DIR$/forkjoin.iml" filepath="$PROJECT_DIR$/forkjoin.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$/msil.iml" filepath="$PROJECT_DIR$/msil.iml" />
<module fileurl="file://$PROJECT_DIR$/partest.iml" filepath="$PROJECT_DIR$/partest.iml" />
<module fileurl="file://$PROJECT_DIR$/reflect.iml" filepath="$PROJECT_DIR$/reflect.iml" />
<module fileurl="file://$PROJECT_DIR$/scala.iml" filepath="$PROJECT_DIR$/scala.iml" />
@@ -230,7 +228,6 @@
<root url="file://$PROJECT_DIR$/../../build/locker/classes/library" />
<root url="file://$PROJECT_DIR$/../../build/locker/classes/compiler" />
<root url="file://$PROJECT_DIR$/../../build/locker/classes/reflect" />
- <root url="file://$PROJECT_DIR$/../../build/libs/classes/fjbg" />
<root url="file://$PROJECT_DIR$/../../build/asm/classes" />
</CLASSES>
<JAVADOC />
diff --git a/src/intellij/test.iml.SAMPLE b/src/intellij/test.iml.SAMPLE
index 112fec428f..3ce369be05 100644
--- a/src/intellij/test.iml.SAMPLE
+++ b/src/intellij/test.iml.SAMPLE
@@ -12,9 +12,7 @@
<orderEntry type="module" module-name="swing" />
<orderEntry type="module" module-name="partest" />
<orderEntry type="module" module-name="asm" />
- <orderEntry type="module" module-name="fjbg" />
<orderEntry type="module" module-name="forkjoin" />
- <orderEntry type="module" module-name="msil" />
</component>
</module>
diff --git a/src/library/scala/Application.scala b/src/library/scala/Application.scala
deleted file mode 100644
index e7db0d2db8..0000000000
--- a/src/library/scala/Application.scala
+++ /dev/null
@@ -1,79 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2002-2013, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-package scala
-
-import scala.compat.Platform.currentTime
-
-/** The `Application` trait can be used to quickly turn objects
- * into executable programs, but is ''not recommended''.
- * Here is an example:
- * {{{
- * object Main extends Application {
- * Console.println("Hello World!")
- * }
- * }}}
- * Here, object `Main` inherits the `main` method of `Application`.
- * The body of the `Main` object defines the main program. This technique
- * does not work if the main program depends on command-line arguments
- * (which are not accessible with the technique presented here).
- *
- * It is possible to time the execution of objects that inherit from class
- * `Application` by setting the global `scala.time`
- * property. Here is an example for benchmarking object `Main`:
- * {{{
- * java -Dscala.time Main
- * }}}
- * In practice the `Application` trait has a number of serious pitfalls:
- *
- * - Threaded code that references the object will block until static
- * initialization is complete. However, because the entire execution
- * of an `object` extending `Application` takes place during
- * static initialization, concurrent code will ''always'' deadlock if
- * it must synchronize with the enclosing object.
- * - As described above, there is no way to obtain the
- * command-line arguments because all code in body of an `object`
- * extending `Application` is run as part of the static initialization
- * which occurs before `Application`'s `main` method
- * even begins execution.
- * - Static initializers are run only once during program execution, and
- * JVM authors usually assume their execution to be relatively short.
- * Therefore, certain JVM configurations may become confused, or simply
- * fail to optimize or JIT the code in the body of an `object` extending
- * `Application`. This can lead to a significant performance degradation.
- *
- * It is recommended to use the [[scala.App]] trait instead.
- * {{{
- * object Main {
- * def main(args: Array[String]) {
- * //..
- * }
- * }
- * }}}
- *
- * @author Matthias Zenger
- * @version 1.0, 10/09/2003
- */
-@deprecated("use App instead", "2.9.0")
-trait Application {
-
- /** The time when the execution of this program started,
- * in milliseconds since 1 January 1970 UTC. */
- val executionStart: Long = currentTime
-
- /** The default main method.
- *
- * @param args the arguments passed to the main method
- */
- def main(args: Array[String]) {
- if (util.Properties propIsSet "scala.time") {
- val total = currentTime - executionStart
- Console.println("[total " + total + "ms]")
- }
- }
-}
diff --git a/src/library/scala/Array.scala b/src/library/scala/Array.scala
index 90684b5fdd..b9f51803ec 100644
--- a/src/library/scala/Array.scala
+++ b/src/library/scala/Array.scala
@@ -115,6 +115,8 @@ object Array extends FallbackArrayBuilding {
* @param xs the elements to put in the array
* @return an array containing all elements from xs.
*/
+ // Subject to a compiler optimization in Cleanup.
+ // Array(e0, ..., en) is translated to { val a = new Array(3); a(i) = ei; a }
def apply[T: ClassTag](xs: T*): Array[T] = {
val array = new Array[T](xs.length)
var i = 0
@@ -123,6 +125,7 @@ object Array extends FallbackArrayBuilding {
}
/** Creates an array of `Boolean` objects */
+ // Subject to a compiler optimization in Cleanup, see above.
def apply(x: Boolean, xs: Boolean*): Array[Boolean] = {
val array = new Array[Boolean](xs.length + 1)
array(0) = x
@@ -132,6 +135,7 @@ object Array extends FallbackArrayBuilding {
}
/** Creates an array of `Byte` objects */
+ // Subject to a compiler optimization in Cleanup, see above.
def apply(x: Byte, xs: Byte*): Array[Byte] = {
val array = new Array[Byte](xs.length + 1)
array(0) = x
@@ -141,6 +145,7 @@ object Array extends FallbackArrayBuilding {
}
/** Creates an array of `Short` objects */
+ // Subject to a compiler optimization in Cleanup, see above.
def apply(x: Short, xs: Short*): Array[Short] = {
val array = new Array[Short](xs.length + 1)
array(0) = x
@@ -150,6 +155,7 @@ object Array extends FallbackArrayBuilding {
}
/** Creates an array of `Char` objects */
+ // Subject to a compiler optimization in Cleanup, see above.
def apply(x: Char, xs: Char*): Array[Char] = {
val array = new Array[Char](xs.length + 1)
array(0) = x
@@ -159,6 +165,7 @@ object Array extends FallbackArrayBuilding {
}
/** Creates an array of `Int` objects */
+ // Subject to a compiler optimization in Cleanup, see above.
def apply(x: Int, xs: Int*): Array[Int] = {
val array = new Array[Int](xs.length + 1)
array(0) = x
@@ -168,6 +175,7 @@ object Array extends FallbackArrayBuilding {
}
/** Creates an array of `Long` objects */
+ // Subject to a compiler optimization in Cleanup, see above.
def apply(x: Long, xs: Long*): Array[Long] = {
val array = new Array[Long](xs.length + 1)
array(0) = x
@@ -177,6 +185,7 @@ object Array extends FallbackArrayBuilding {
}
/** Creates an array of `Float` objects */
+ // Subject to a compiler optimization in Cleanup, see above.
def apply(x: Float, xs: Float*): Array[Float] = {
val array = new Array[Float](xs.length + 1)
array(0) = x
@@ -186,6 +195,7 @@ object Array extends FallbackArrayBuilding {
}
/** Creates an array of `Double` objects */
+ // Subject to a compiler optimization in Cleanup, see above.
def apply(x: Double, xs: Double*): Array[Double] = {
val array = new Array[Double](xs.length + 1)
array(0) = x
diff --git a/src/library/scala/Option.scala b/src/library/scala/Option.scala
index 3873df99e9..4b071166c7 100644
--- a/src/library/scala/Option.scala
+++ b/src/library/scala/Option.scala
@@ -209,6 +209,15 @@ sealed abstract class Option[+A] extends Product with Serializable {
def withFilter(q: A => Boolean): WithFilter = new WithFilter(x => p(x) && q(x))
}
+ /** Tests whether the option contains a given value as an element.
+ *
+ * @param elem the element to test.
+ * @return `true` if the option has an element that is equal (as
+ * determined by `==`) to `elem`, `false` otherwise.
+ */
+ final def contains[A1 >: A](elem: A1): Boolean =
+ !isEmpty && this.get == elem
+
/** Returns true if this option is nonempty '''and''' the predicate
* $p returns true when applied to this $option's value.
* Otherwise, returns false.
@@ -247,7 +256,7 @@ sealed abstract class Option[+A] extends Product with Serializable {
* value (if possible), or $none.
*/
@inline final def collect[B](pf: PartialFunction[A, B]): Option[B] =
- if (!isEmpty && pf.isDefinedAt(this.get)) Some(pf(this.get)) else None
+ if (!isEmpty) pf.lift(this.get) else None
/** Returns this $option if it is nonempty,
* otherwise return the result of evaluating `alternative`.
diff --git a/src/library/scala/SerialVersionUID.scala b/src/library/scala/SerialVersionUID.scala
index 1f7d047060..77094f0bbf 100644
--- a/src/library/scala/SerialVersionUID.scala
+++ b/src/library/scala/SerialVersionUID.scala
@@ -12,4 +12,4 @@ package scala
* Annotation for specifying the `static SerialVersionUID` field
* of a serializable class.
*/
-class SerialVersionUID(uid: Long) extends scala.annotation.StaticAnnotation
+class SerialVersionUID(value: Long) extends scala.annotation.ClassfileAnnotation
diff --git a/src/library/scala/UninitializedFieldError.scala b/src/library/scala/UninitializedFieldError.scala
index 10c6cccf15..0dfba2a187 100644
--- a/src/library/scala/UninitializedFieldError.scala
+++ b/src/library/scala/UninitializedFieldError.scala
@@ -18,8 +18,6 @@ package scala
*
* @since 2.7
*/
-final case class UninitializedFieldError(msg: String)
- extends RuntimeException(msg) {
- def this(obj: Any) =
- this(if (null != obj) obj.toString() else "null")
+final case class UninitializedFieldError(msg: String) extends RuntimeException(msg) {
+ def this(obj: Any) = this("" + obj)
}
diff --git a/src/library/scala/collection/BitSetLike.scala b/src/library/scala/collection/BitSetLike.scala
index 4a1c0beaa6..d0f4e323c7 100644
--- a/src/library/scala/collection/BitSetLike.scala
+++ b/src/library/scala/collection/BitSetLike.scala
@@ -11,7 +11,6 @@
package scala.collection
import BitSetLike._
-import generic._
import mutable.StringBuilder
/** A template trait for bitsets.
diff --git a/src/library/scala/collection/DefaultMap.scala b/src/library/scala/collection/DefaultMap.scala
index 5c91183891..cbd7e3f8b9 100644
--- a/src/library/scala/collection/DefaultMap.scala
+++ b/src/library/scala/collection/DefaultMap.scala
@@ -6,12 +6,8 @@
** |/ **
\* */
-
-
package scala.collection
-import generic._
-
/** A default map which implements the `+` and `-` methods of maps.
*
* Instances that inherit from `DefaultMap[A, B]` still have to define:
@@ -27,7 +23,7 @@ import generic._
* @since 2.8
*/
trait DefaultMap[A, +B] extends Map[A, B] { self =>
-
+
/** A default implementation which creates a new immutable map.
*/
override def +[B1 >: B](kv: (A, B1)): Map[A, B1] = {
diff --git a/src/library/scala/collection/GenIterableLike.scala b/src/library/scala/collection/GenIterableLike.scala
index 2ba9a7283d..ceb97707e1 100644
--- a/src/library/scala/collection/GenIterableLike.scala
+++ b/src/library/scala/collection/GenIterableLike.scala
@@ -8,7 +8,7 @@
package scala.collection
-import generic.{ CanBuildFrom => CBF, _ }
+import generic.{ CanBuildFrom => CBF }
/** A template trait for all iterable collections which may possibly
* have their operations implemented in parallel.
diff --git a/src/library/scala/collection/GenIterableView.scala b/src/library/scala/collection/GenIterableView.scala
index ca0332e9ad..5ab48efdf3 100644
--- a/src/library/scala/collection/GenIterableView.scala
+++ b/src/library/scala/collection/GenIterableView.scala
@@ -8,11 +8,4 @@
package scala.collection
-
-import generic._
-
-
-
trait GenIterableView[+A, +Coll] extends GenIterableViewLike[A, Coll, GenIterableView[A, Coll]] { }
-
-
diff --git a/src/library/scala/collection/GenIterableViewLike.scala b/src/library/scala/collection/GenIterableViewLike.scala
index 4e4ceb4cea..e8d264cdd4 100644
--- a/src/library/scala/collection/GenIterableViewLike.scala
+++ b/src/library/scala/collection/GenIterableViewLike.scala
@@ -8,13 +8,6 @@
package scala.collection
-
-
-import generic._
-import TraversableView.NoBuilder
-
-
-
trait GenIterableViewLike[+A,
+Coll,
+This <: GenIterableView[A, Coll] with GenIterableViewLike[A, Coll, This]]
diff --git a/src/library/scala/collection/GenSeqView.scala b/src/library/scala/collection/GenSeqView.scala
index 92c8b779e9..423f8e305e 100644
--- a/src/library/scala/collection/GenSeqView.scala
+++ b/src/library/scala/collection/GenSeqView.scala
@@ -8,11 +8,4 @@
package scala.collection
-
-import generic._
-
-
-
trait GenSeqView[+A, +Coll] extends GenSeqViewLike[A, Coll, GenSeqView[A, Coll]] { }
-
-
diff --git a/src/library/scala/collection/GenTraversableOnce.scala b/src/library/scala/collection/GenTraversableOnce.scala
index 093db2a972..afaced4264 100644
--- a/src/library/scala/collection/GenTraversableOnce.scala
+++ b/src/library/scala/collection/GenTraversableOnce.scala
@@ -261,11 +261,12 @@ trait GenTraversableOnce[+A] extends Any {
* @tparam B the type of accumulated results
* @param z the initial value for the accumulated result of the partition - this
* will typically be the neutral element for the `seqop` operator (e.g.
- * `Nil` for list concatenation or `0` for summation)
+ * `Nil` for list concatenation or `0` for summation) and may be evaluated
+ * more than once
* @param seqop an operator used to accumulate results within a partition
* @param combop an associative operator used to combine results from different partitions
*/
- def aggregate[B](z: B)(seqop: (B, A) => B, combop: (B, B) => B): B
+ def aggregate[B](z: =>B)(seqop: (B, A) => B, combop: (B, B) => B): B
/** Applies a binary operator to all elements of this $coll, going right to left.
* $willNotTerminateInf
diff --git a/src/library/scala/collection/GenTraversableView.scala b/src/library/scala/collection/GenTraversableView.scala
index cceb06882e..1d98eff8c1 100644
--- a/src/library/scala/collection/GenTraversableView.scala
+++ b/src/library/scala/collection/GenTraversableView.scala
@@ -8,11 +8,4 @@
package scala.collection
-
-import generic._
-
-
-
trait GenTraversableView[+A, +Coll] extends GenTraversableViewLike[A, Coll, GenTraversableView[A, Coll]] { }
-
-
diff --git a/src/library/scala/collection/GenTraversableViewLike.scala b/src/library/scala/collection/GenTraversableViewLike.scala
index 77fe0802bf..8c9607663b 100644
--- a/src/library/scala/collection/GenTraversableViewLike.scala
+++ b/src/library/scala/collection/GenTraversableViewLike.scala
@@ -11,8 +11,6 @@ package scala.collection
import generic._
import mutable.{ Builder, ArrayBuffer }
-import TraversableView.NoBuilder
-
trait GenTraversableViewLike[+A,
+Coll,
diff --git a/src/library/scala/collection/IndexedSeq.scala b/src/library/scala/collection/IndexedSeq.scala
index 63e5adf428..0b6e640537 100644
--- a/src/library/scala/collection/IndexedSeq.scala
+++ b/src/library/scala/collection/IndexedSeq.scala
@@ -6,8 +6,6 @@
** |/ **
\* */
-
-
package scala.collection
import generic._
@@ -38,4 +36,3 @@ object IndexedSeq extends IndexedSeqFactory[IndexedSeq] {
implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, IndexedSeq[A]] =
ReusableCBF.asInstanceOf[GenericCanBuildFrom[A]]
}
-
diff --git a/src/library/scala/collection/IndexedSeqLike.scala b/src/library/scala/collection/IndexedSeqLike.scala
index 9d0e9cbaea..1d8e2b1583 100644
--- a/src/library/scala/collection/IndexedSeqLike.scala
+++ b/src/library/scala/collection/IndexedSeqLike.scala
@@ -8,7 +8,6 @@
package scala.collection
-import generic._
import mutable.ArrayBuffer
import scala.annotation.tailrec
@@ -53,7 +52,6 @@ trait IndexedSeqLike[+A, +Repr] extends Any with SeqLike[A, Repr] {
// pre: start >= 0, end <= self.length
@SerialVersionUID(1756321872811029277L)
protected class Elements(start: Int, end: Int) extends AbstractIterator[A] with BufferedIterator[A] with Serializable {
- private def initialSize = if (end <= start) 0 else end - start
private var index = start
private def available = (end - index) max 0
diff --git a/src/library/scala/collection/Iterable.scala b/src/library/scala/collection/Iterable.scala
index 5b73d720a8..09c9ce122c 100644
--- a/src/library/scala/collection/Iterable.scala
+++ b/src/library/scala/collection/Iterable.scala
@@ -11,7 +11,6 @@
package scala.collection
import generic._
-import scala.util.control.Breaks._
import mutable.Builder
/** A base trait for iterable collections.
diff --git a/src/library/scala/collection/IterableProxy.scala b/src/library/scala/collection/IterableProxy.scala
index 2d041928cc..ddb2502965 100644
--- a/src/library/scala/collection/IterableProxy.scala
+++ b/src/library/scala/collection/IterableProxy.scala
@@ -8,8 +8,6 @@
package scala.collection
-import generic._
-
/** This trait implements a proxy for iterable objects. It forwards all calls
* to a different iterable object.
*
diff --git a/src/library/scala/collection/IterableViewLike.scala b/src/library/scala/collection/IterableViewLike.scala
index 3a81a3422f..b195ae4bc7 100644
--- a/src/library/scala/collection/IterableViewLike.scala
+++ b/src/library/scala/collection/IterableViewLike.scala
@@ -9,7 +9,6 @@
package scala.collection
import generic._
-import TraversableView.NoBuilder
import immutable.Stream
import scala.language.implicitConversions
diff --git a/src/library/scala/collection/Iterator.scala b/src/library/scala/collection/Iterator.scala
index cbf8cc4931..d7dc202fad 100644
--- a/src/library/scala/collection/Iterator.scala
+++ b/src/library/scala/collection/Iterator.scala
@@ -562,7 +562,6 @@ trait Iterator[+A] extends TraversableOnce[A] {
* handling of structural calls. It's not what's intended here.
*/
class Leading extends AbstractIterator[A] {
- private var isDone = false
val lookahead = new mutable.Queue[A]
def advance() = {
self.hasNext && p(self.head) && {
@@ -572,7 +571,6 @@ trait Iterator[+A] extends TraversableOnce[A] {
}
def finish() = {
while (advance()) ()
- isDone = true
}
def hasNext = lookahead.nonEmpty || advance()
def next() = {
diff --git a/src/library/scala/collection/JavaConversions.scala b/src/library/scala/collection/JavaConversions.scala
index 59d4259c70..7ff29650fa 100644
--- a/src/library/scala/collection/JavaConversions.scala
+++ b/src/library/scala/collection/JavaConversions.scala
@@ -8,7 +8,6 @@
package scala.collection
-import java.{ lang => jl, util => ju }, java.util.{ concurrent => juc }
import convert._
/** A collection of implicit conversions supporting interoperability between
@@ -91,42 +90,6 @@ object JavaConversions extends WrapAsScala with WrapAsJava {
@deprecated("Use a member of scala.collection.convert.Wrappers", "2.10.0") val MutableSeqWrapper = Wrappers.MutableSeqWrapper
@deprecated("Use a member of scala.collection.convert.Wrappers", "2.10.0") val MutableSetWrapper = Wrappers.MutableSetWrapper
@deprecated("Use a member of scala.collection.convert.Wrappers", "2.10.0") val SeqWrapper = Wrappers.SeqWrapper
-
- // Note to implementors: the cavalcade of deprecated methods herein should
- // serve as a warning to any who follow: don't overload implicit methods.
-
- @deprecated("use bufferAsJavaList instead", "2.9.0")
- def asJavaList[A](b : mutable.Buffer[A]): ju.List[A] = bufferAsJavaList[A](b)
-
- @deprecated("use mutableSeqAsJavaList instead", "2.9.0")
- def asJavaList[A](b : mutable.Seq[A]): ju.List[A] = mutableSeqAsJavaList[A](b)
-
- @deprecated("use seqAsJavaList instead", "2.9.0")
- def asJavaList[A](b : Seq[A]): ju.List[A] = seqAsJavaList[A](b)
-
- @deprecated("use mutableSetAsJavaSet instead", "2.9.0")
- def asJavaSet[A](s : mutable.Set[A]): ju.Set[A] = mutableSetAsJavaSet[A](s)
-
- @deprecated("use setAsJavaSet instead", "2.9.0")
- def asJavaSet[A](s: Set[A]): ju.Set[A] = setAsJavaSet[A](s)
-
- @deprecated("use mutableMapAsJavaMap instead", "2.9.0")
- def asJavaMap[A, B](m : mutable.Map[A, B]): ju.Map[A, B] = mutableMapAsJavaMap[A, B](m)
-
- @deprecated("use mapAsJavaMap instead", "2.9.0")
- def asJavaMap[A, B](m : Map[A, B]): ju.Map[A, B] = mapAsJavaMap[A, B](m)
-
- @deprecated("use iterableAsScalaIterable instead", "2.9.0")
- def asScalaIterable[A](i : jl.Iterable[A]): Iterable[A] = iterableAsScalaIterable[A](i)
-
- @deprecated("use collectionAsScalaIterable instead", "2.9.0")
- def asScalaIterable[A](i : ju.Collection[A]): Iterable[A] = collectionAsScalaIterable[A](i)
-
- @deprecated("use mapAsScalaMap instead", "2.9.0")
- def asScalaMap[A, B](m: ju.Map[A, B]): mutable.Map[A, B] = mapAsScalaMap[A, B](m)
-
- @deprecated("use propertiesAsScalaMap instead", "2.9.0")
- def asScalaMap(p: ju.Properties): mutable.Map[String, String] = propertiesAsScalaMap(p)
}
diff --git a/src/library/scala/collection/JavaConverters.scala b/src/library/scala/collection/JavaConverters.scala
index ab3ac8925c..439991708e 100755
--- a/src/library/scala/collection/JavaConverters.scala
+++ b/src/library/scala/collection/JavaConverters.scala
@@ -8,14 +8,12 @@
package scala.collection
-import java.{ lang => jl, util => ju }, java.util.{ concurrent => juc }
import convert._
// TODO: I cleaned all this documentation up in JavaConversions, but the
// documentation in here is basically the pre-cleaned-up version with minor
// additions. Would be nice to have in one place.
-
/** A collection of decorators that allow converting between
* Scala and Java collections using `asScala` and `asJava` methods.
*
@@ -67,37 +65,4 @@ object JavaConverters extends DecorateAsJava with DecorateAsScala {
type AsJavaEnumeration[A] = Decorators.AsJavaEnumeration[A]
@deprecated("Don't access these decorators directly.", "2.10.0")
type AsJavaDictionary[A, B] = Decorators.AsJavaDictionary[A, B]
-
- @deprecated("Use bufferAsJavaListConverter instead", "2.9.0")
- def asJavaListConverter[A](b : mutable.Buffer[A]): AsJava[ju.List[A]] = bufferAsJavaListConverter(b)
-
- @deprecated("Use mutableSeqAsJavaListConverter instead", "2.9.0")
- def asJavaListConverter[A](b : mutable.Seq[A]): AsJava[ju.List[A]] = mutableSeqAsJavaListConverter(b)
-
- @deprecated("Use seqAsJavaListConverter instead", "2.9.0")
- def asJavaListConverter[A](b : Seq[A]): AsJava[ju.List[A]] = seqAsJavaListConverter(b)
-
- @deprecated("Use mutableSetAsJavaSetConverter instead", "2.9.0")
- def asJavaSetConverter[A](s : mutable.Set[A]): AsJava[ju.Set[A]] = mutableSetAsJavaSetConverter(s)
-
- @deprecated("Use setAsJavaSetConverter instead", "2.9.0")
- def asJavaSetConverter[A](s : Set[A]): AsJava[ju.Set[A]] = setAsJavaSetConverter(s)
-
- @deprecated("use mutableMapAsJavaMapConverter instead", "2.9.0")
- def asJavaMapConverter[A, B](m : mutable.Map[A, B]): AsJava[ju.Map[A, B]] = mutableMapAsJavaMapConverter(m)
-
- @deprecated("Use mapAsJavaMapConverter instead", "2.9.0")
- def asJavaMapConverter[A, B](m : Map[A, B]): AsJava[ju.Map[A, B]] = mapAsJavaMapConverter(m)
-
- @deprecated("Use iterableAsScalaIterableConverter instead", "2.9.0")
- def asScalaIterableConverter[A](i : jl.Iterable[A]): AsScala[Iterable[A]] = iterableAsScalaIterableConverter(i)
-
- @deprecated("Use collectionAsScalaIterableConverter instead", "2.9.0")
- def asScalaIterableConverter[A](i : ju.Collection[A]): AsScala[Iterable[A]] = collectionAsScalaIterableConverter(i)
-
- @deprecated("Use mapAsScalaMapConverter instead", "2.9.0")
- def asScalaMapConverter[A, B](m : ju.Map[A, B]): AsScala[mutable.Map[A, B]] = mapAsScalaMapConverter(m)
-
- @deprecated("Use propertiesAsScalaMapConverter instead", "2.9.0")
- def asScalaMapConverter(p: ju.Properties): AsScala[mutable.Map[String, String]] = propertiesAsScalaMapConverter(p)
}
diff --git a/src/library/scala/collection/LinearSeqLike.scala b/src/library/scala/collection/LinearSeqLike.scala
index 78108a9c0f..2a824bcff3 100644
--- a/src/library/scala/collection/LinearSeqLike.scala
+++ b/src/library/scala/collection/LinearSeqLike.scala
@@ -6,13 +6,9 @@
** |/ **
\* */
-
package scala.collection
-import generic._
-import mutable.ListBuffer
import immutable.List
-import scala.util.control.Breaks._
import scala.annotation.tailrec
/** A template trait for linear sequences of type `LinearSeq[A]`.
diff --git a/src/library/scala/collection/LinearSeqOptimized.scala b/src/library/scala/collection/LinearSeqOptimized.scala
index 0f0a405a85..f71fd227cd 100755
--- a/src/library/scala/collection/LinearSeqOptimized.scala
+++ b/src/library/scala/collection/LinearSeqOptimized.scala
@@ -8,10 +8,8 @@
package scala.collection
-import generic._
import mutable.ListBuffer
import immutable.List
-import scala.util.control.Breaks._
/** A template trait for linear sequences of type `LinearSeq[A]` which optimizes
* the implementation of several methods under the assumption of fast linear access.
@@ -83,7 +81,7 @@ trait LinearSeqOptimized[+A, +Repr <: LinearSeqOptimized[A, Repr]] extends Linea
}
override /*SeqLike*/
- def contains(elem: Any): Boolean = {
+ def contains[A1 >: A](elem: A1): Boolean = {
var these = this
while (!these.isEmpty) {
if (these.head == elem) return true
@@ -91,7 +89,7 @@ trait LinearSeqOptimized[+A, +Repr <: LinearSeqOptimized[A, Repr]] extends Linea
}
false
}
-
+
override /*IterableLike*/
def find(p: A => Boolean): Option[A] = {
var these = this
@@ -112,7 +110,7 @@ trait LinearSeqOptimized[+A, +Repr <: LinearSeqOptimized[A, Repr]] extends Linea
}
acc
}
-
+
override /*IterableLike*/
def foldRight[B](z: B)(f: (A, B) => B): B =
if (this.isEmpty) z
diff --git a/src/library/scala/collection/MapProxyLike.scala b/src/library/scala/collection/MapProxyLike.scala
index 44b39f65da..ad09f7b970 100644
--- a/src/library/scala/collection/MapProxyLike.scala
+++ b/src/library/scala/collection/MapProxyLike.scala
@@ -8,8 +8,6 @@
package scala.collection
-import generic._
-
// Methods could be printed by cat MapLike.scala | egrep '^ (override )?def'
/** This trait implements a proxy for Map objects. It forwards
diff --git a/src/library/scala/collection/Searching.scala b/src/library/scala/collection/Searching.scala
new file mode 100644
index 0000000000..33e50365ee
--- /dev/null
+++ b/src/library/scala/collection/Searching.scala
@@ -0,0 +1,116 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2003-2012, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+package scala.collection
+
+import scala.annotation.tailrec
+import scala.collection.generic.IsSeqLike
+import scala.math.Ordering
+
+/** A collection of wrappers that provide sequence classes with search functionality.
+ *
+ * Example usage:
+ * {{{
+ * import scala.collection.Searching._
+ * val l = List(1, 2, 3, 4, 5)
+ * l.search(3)
+ * // == Found(2)
+ * }}}
+ */
+object Searching {
+ sealed abstract class SearchResult {
+ def insertionPoint: Int
+ }
+
+ case class Found(foundIndex: Int) extends SearchResult {
+ override def insertionPoint = foundIndex
+ }
+ case class InsertionPoint(insertionPoint: Int) extends SearchResult
+
+ class SearchImpl[A, Repr](val coll: SeqLike[A, Repr]) {
+ /** Search the sorted sequence for a specific element. If the sequence is an
+ * `IndexedSeq`, a binary search is used. Otherwise, a linear search is used.
+ *
+ * The sequence should be sorted with the same `Ordering` before calling; otherwise,
+ * the results are undefined.
+ *
+ * @see [[scala.collection.IndexedSeq]]
+ * @see [[scala.math.Ordering]]
+ * @see [[scala.collection.SeqLike]], method `sorted`
+ *
+ * @param elem the element to find.
+ * @param ord the ordering to be used to compare elements.
+ *
+ * @return a `Found` value containing the index corresponding to the element in the
+ * sequence, or the `InsertionPoint` where the element would be inserted if
+ * the element is not in the sequence.
+ */
+ final def search[B >: A](elem: B)(implicit ord: Ordering[B]): SearchResult =
+ coll match {
+ case _: IndexedSeq[A] => binarySearch(elem, -1, coll.length)(ord)
+ case _ => linearSearch(coll.view, elem, 0)(ord)
+ }
+
+ /** Search within an interval in the sorted sequence for a specific element. If the
+ * sequence is an IndexedSeq, a binary search is used. Otherwise, a linear search
+ * is used.
+ *
+ * The sequence should be sorted with the same `Ordering` before calling; otherwise,
+ * the results are undefined.
+ *
+ * @see [[scala.collection.IndexedSeq]]
+ * @see [[scala.math.Ordering]]
+ * @see [[scala.collection.SeqLike]], method `sorted`
+ *
+ * @param elem the element to find.
+ * @param from the index where the search starts.
+ * @param to the index following where the search ends.
+ * @param ord the ordering to be used to compare elements.
+ *
+ * @return a `Found` value containing the index corresponding to the element in the
+ * sequence, or the `InsertionPoint` where the element would be inserted if
+ * the element is not in the sequence.
+ */
+ final def search[B >: A](elem: B, from: Int, to: Int)
+ (implicit ord: Ordering[B]): SearchResult =
+ coll match {
+ case _: IndexedSeq[A] => binarySearch(elem, from-1, to)(ord)
+ case _ => linearSearch(coll.view(from, to), elem, from)(ord)
+ }
+
+ @tailrec
+ private def binarySearch[B >: A](elem: B, from: Int, to: Int)
+ (implicit ord: Ordering[B]): SearchResult = {
+ if ((to-from) == 1) InsertionPoint(from) else {
+ val idx = from+(to-from)/2
+ math.signum(ord.compare(elem, coll(idx))) match {
+ case -1 => binarySearch(elem, from, idx)(ord)
+ case 1 => binarySearch(elem, idx, to)(ord)
+ case _ => Found(idx)
+ }
+ }
+ }
+
+ private def linearSearch[B >: A](c: SeqView[A, Repr], elem: B, offset: Int)
+ (implicit ord: Ordering[B]): SearchResult = {
+ var idx = offset
+ val it = c.iterator
+ while (it.hasNext) {
+ val cur = it.next()
+ if (ord.equiv(elem, cur)) return Found(idx)
+ else if (ord.lt(elem, cur)) return InsertionPoint(idx-1)
+ idx += 1
+ }
+ InsertionPoint(idx)
+ }
+
+ }
+
+ implicit def search[Repr, A](coll: Repr)
+ (implicit fr: IsSeqLike[Repr]): SearchImpl[fr.A, Repr] = new SearchImpl(fr.conversion(coll))
+}
diff --git a/src/library/scala/collection/SeqLike.scala b/src/library/scala/collection/SeqLike.scala
index f65e2ef9cd..955ebce6bd 100644
--- a/src/library/scala/collection/SeqLike.scala
+++ b/src/library/scala/collection/SeqLike.scala
@@ -103,7 +103,7 @@ trait SeqLike[+A, +Repr] extends Any with IterableLike[A, Repr] with GenSeqLike[
def segmentLength(p: A => Boolean, from: Int): Int = {
var i = 0
- var it = iterator.drop(from)
+ val it = iterator.drop(from)
while (it.hasNext && p(it.next()))
i += 1
i
@@ -111,7 +111,7 @@ trait SeqLike[+A, +Repr] extends Any with IterableLike[A, Repr] with GenSeqLike[
def indexWhere(p: A => Boolean, from: Int): Int = {
var i = from
- var it = iterator.drop(from)
+ val it = iterator.drop(from)
while (it.hasNext) {
if (p(it.next())) return i
else i += 1
@@ -177,10 +177,10 @@ trait SeqLike[+A, +Repr] extends Any with IterableLike[A, Repr] with GenSeqLike[
result
}
private def swap(i: Int, j: Int) {
- var tmpI = idxs(i)
+ val tmpI = idxs(i)
idxs(i) = idxs(j)
idxs(j) = tmpI
- var tmpE = elms(i)
+ val tmpE = elms(i)
elms(i) = elms(j)
elms(j) = tmpE
}
@@ -386,7 +386,7 @@ trait SeqLike[+A, +Repr] extends Any with IterableLike[A, Repr] with GenSeqLike[
* @return `true` if this $coll has an element that is equal (as
* determined by `==`) to `elem`, `false` otherwise.
*/
- def contains(elem: Any): Boolean = exists (_ == elem)
+ def contains[A1 >: A](elem: A1): Boolean = exists (_ == elem)
/** Produces a new sequence which contains all elements of this $coll and also all elements of
* a given sequence. `xs union ys` is equivalent to `xs ++ ys`.
@@ -776,7 +776,7 @@ object SeqLike {
val iter = S.iterator.drop(m0)
val Wopt = kmpOptimizeWord(W, n0, n1, true)
val T = kmpJumpTable(Wopt, n1-n0)
- var cache = new Array[AnyRef](n1-n0) // Ring buffer--need a quick way to do a look-behind
+ val cache = new Array[AnyRef](n1-n0) // Ring buffer--need a quick way to do a look-behind
var largest = 0
var i, m = 0
var answer = -1
diff --git a/src/library/scala/collection/SeqProxyLike.scala b/src/library/scala/collection/SeqProxyLike.scala
index 5e8030d1e4..ee88ee3da3 100644
--- a/src/library/scala/collection/SeqProxyLike.scala
+++ b/src/library/scala/collection/SeqProxyLike.scala
@@ -50,7 +50,7 @@ trait SeqProxyLike[+A, +Repr <: SeqLike[A, Repr] with Seq[A]] extends SeqLike[A,
override def lastIndexOfSlice[B >: A](that: GenSeq[B]): Int = self.lastIndexOfSlice(that)
override def lastIndexOfSlice[B >: A](that: GenSeq[B], end: Int): Int = self.lastIndexOfSlice(that, end)
override def containsSlice[B](that: GenSeq[B]): Boolean = self.indexOfSlice(that) != -1
- override def contains(elem: Any): Boolean = self.contains(elem)
+ override def contains[A1 >: A](elem: A1): Boolean = self.contains(elem)
override def union[B >: A, That](that: GenSeq[B])(implicit bf: CanBuildFrom[Repr, B, That]): That = self.union(that)(bf)
override def diff[B >: A](that: GenSeq[B]): Repr = self.diff(that)
override def intersect[B >: A](that: GenSeq[B]): Repr = self.intersect(that)
diff --git a/src/library/scala/collection/SeqViewLike.scala b/src/library/scala/collection/SeqViewLike.scala
index 5f2bf902b1..27536791a2 100644
--- a/src/library/scala/collection/SeqViewLike.scala
+++ b/src/library/scala/collection/SeqViewLike.scala
@@ -10,7 +10,6 @@ package scala.collection
import generic._
import Seq.fill
-import TraversableView.NoBuilder
/** A template trait for non-strict views of sequences.
* $seqViewInfo
diff --git a/src/library/scala/collection/Sequentializable.scala.disabled b/src/library/scala/collection/Sequentializable.scala.disabled
deleted file mode 100644
index df457671a6..0000000000
--- a/src/library/scala/collection/Sequentializable.scala.disabled
+++ /dev/null
@@ -1,10 +0,0 @@
-package scala.collection
-
-
-
-
-trait Sequentializable[+T, +Repr] {
-
- def seq: Repr
-
-}
diff --git a/src/library/scala/collection/SetProxyLike.scala b/src/library/scala/collection/SetProxyLike.scala
index 5196f39917..265d1c4806 100644
--- a/src/library/scala/collection/SetProxyLike.scala
+++ b/src/library/scala/collection/SetProxyLike.scala
@@ -6,11 +6,8 @@
** |/ **
\* */
-
package scala.collection
-import generic._
-
// Methods could be printed by cat SetLike.scala | egrep '^ (override )?def'
/** This trait implements a proxy for sets. It forwards
diff --git a/src/library/scala/collection/Traversable.scala b/src/library/scala/collection/Traversable.scala
index 36ef230a42..4ca2095f4c 100644
--- a/src/library/scala/collection/Traversable.scala
+++ b/src/library/scala/collection/Traversable.scala
@@ -6,12 +6,10 @@
** |/ **
\* */
-
-
package scala.collection
import generic._
-import mutable.{Builder, Buffer, ArrayBuffer, ListBuffer}
+import mutable.Builder
import scala.util.control.Breaks
/** A trait for traversable collections.
diff --git a/src/library/scala/collection/TraversableLike.scala b/src/library/scala/collection/TraversableLike.scala
index 5f193eb211..c1a68b6b16 100644
--- a/src/library/scala/collection/TraversableLike.scala
+++ b/src/library/scala/collection/TraversableLike.scala
@@ -86,7 +86,7 @@ trait TraversableLike[+A, +Repr] extends Any
def repr: Repr = this.asInstanceOf[Repr]
final def isTraversableAgain: Boolean = true
-
+
/** The underlying collection seen as an instance of `$Coll`.
* By default this is implemented as the current collection object itself,
* but this can be overridden.
@@ -174,7 +174,7 @@ trait TraversableLike[+A, +Repr] extends Any
*
* @usecase def ++:[B](that: TraversableOnce[B]): $Coll[B]
* @inheritdoc
- *
+ *
* Example:
* {{{
* scala> val x = List(1)
@@ -275,7 +275,7 @@ trait TraversableLike[+A, +Repr] extends Any
def collect[B, That](pf: PartialFunction[A, B])(implicit bf: CanBuildFrom[Repr, B, That]): That = {
val b = bf(repr)
- for (x <- this) if (pf.isDefinedAt(x)) b += pf(x)
+ foreach(pf.runWith(b += _))
b.result
}
diff --git a/src/library/scala/collection/TraversableOnce.scala b/src/library/scala/collection/TraversableOnce.scala
index d53d000e90..82cf1d1198 100644
--- a/src/library/scala/collection/TraversableOnce.scala
+++ b/src/library/scala/collection/TraversableOnce.scala
@@ -128,10 +128,8 @@ trait TraversableOnce[+A] extends Any with GenTraversableOnce[A] {
* @example `Seq("a", 1, 5L).collectFirst({ case x: Int => x*10 }) = Some(10)`
*/
def collectFirst[B](pf: PartialFunction[A, B]): Option[B] = {
- for (x <- self.toIterator) { // make sure to use an iterator or `seq`
- if (pf isDefinedAt x)
- return Some(pf(x))
- }
+ // make sure to use an iterator or `seq`
+ self.toIterator.foreach(pf.runWith(b => return Some(b)))
None
}
@@ -184,7 +182,7 @@ trait TraversableOnce[+A] extends Any with GenTraversableOnce[A] {
def fold[A1 >: A](z: A1)(op: (A1, A1) => A1): A1 = foldLeft(z)(op)
- def aggregate[B](z: B)(seqop: (B, A) => B, combop: (B, B) => B): B = foldLeft(z)(seqop)
+ def aggregate[B](z: =>B)(seqop: (B, A) => B, combop: (B, B) => B): B = foldLeft(z)(seqop)
def sum[B >: A](implicit num: Numeric[B]): B = foldLeft(num.zero)(num.plus)
diff --git a/src/library/scala/collection/TraversableView.scala b/src/library/scala/collection/TraversableView.scala
index cce6b72257..af219084b8 100644
--- a/src/library/scala/collection/TraversableView.scala
+++ b/src/library/scala/collection/TraversableView.scala
@@ -10,7 +10,6 @@ package scala.collection
import generic._
import mutable.Builder
-import TraversableView.NoBuilder
/** A base trait for non-strict views of traversable collections.
* $traversableViewInfo
diff --git a/src/library/scala/collection/TraversableViewLike.scala b/src/library/scala/collection/TraversableViewLike.scala
index 14f865c2f0..36f6210ef4 100644
--- a/src/library/scala/collection/TraversableViewLike.scala
+++ b/src/library/scala/collection/TraversableViewLike.scala
@@ -10,7 +10,6 @@ package scala.collection
import generic._
import mutable.{ Builder, ArrayBuffer }
-import TraversableView.NoBuilder
import scala.annotation.migration
import scala.language.implicitConversions
@@ -59,7 +58,7 @@ trait ViewMkString[+A] {
* $viewInfo
*
* All views for traversable collections are defined by creating a new `foreach` method.
- *
+ *
* @author Martin Odersky
* @version 2.8
* @since 2.8
@@ -162,7 +161,7 @@ trait TraversableViewLike[+A,
// if (b.isInstanceOf[NoBuilder[_]]) newFlatMapped(f).asInstanceOf[That]
// else super.flatMap[B, That](f)(bf)
}
- override def flatten[B](implicit asTraversable: A => /*<:<!!!*/ GenTraversableOnce[B]) =
+ override def flatten[B](implicit asTraversable: A => /*<:<!!!*/ GenTraversableOnce[B]) =
newFlatMapped(asTraversable)
private[this] implicit def asThis(xs: Transformed[A]): This = xs.asInstanceOf[This]
diff --git a/src/library/scala/collection/concurrent/TrieMap.scala b/src/library/scala/collection/concurrent/TrieMap.scala
index 6c11c5bcb5..14b475dd1f 100644
--- a/src/library/scala/collection/concurrent/TrieMap.scala
+++ b/src/library/scala/collection/concurrent/TrieMap.scala
@@ -545,7 +545,7 @@ private[collection] final class CNode[K, V](val bitmap: Int, val array: Array[Ba
// removed (those existing when the op began)
// - if there are only null-i-nodes below, returns null
def toCompressed(ct: TrieMap[K, V], lev: Int, gen: Gen) = {
- var bmp = bitmap
+ val bmp = bitmap
var i = 0
val arr = array
val tmparray = new Array[BasicNode](arr.length)
@@ -920,8 +920,8 @@ object TrieMap extends MutableMapFactory[TrieMap] {
private[collection] class TrieMapIterator[K, V](var level: Int, private var ct: TrieMap[K, V], mustInit: Boolean = true) extends Iterator[(K, V)] {
- private var stack = new Array[Array[BasicNode]](7)
- private var stackpos = new Array[Int](7)
+ private val stack = new Array[Array[BasicNode]](7)
+ private val stackpos = new Array[Int](7)
private var depth = -1
private var subiter: Iterator[(K, V)] = null
private var current: KVNode[K, V] = null
diff --git a/src/library/scala/collection/convert/Decorators.scala b/src/library/scala/collection/convert/Decorators.scala
index e2c46c1e4f..f004e4712b 100644
--- a/src/library/scala/collection/convert/Decorators.scala
+++ b/src/library/scala/collection/convert/Decorators.scala
@@ -9,7 +9,7 @@
package scala.collection
package convert
-import java.{ lang => jl, util => ju }, java.util.{ concurrent => juc }
+import java.{ util => ju }
private[collection] trait Decorators {
/** Generic class containing the `asJava` converter method */
diff --git a/src/library/scala/collection/generic/GenTraversableFactory.scala b/src/library/scala/collection/generic/GenTraversableFactory.scala
index a43862abaf..b36dd3ccaf 100644
--- a/src/library/scala/collection/generic/GenTraversableFactory.scala
+++ b/src/library/scala/collection/generic/GenTraversableFactory.scala
@@ -249,4 +249,3 @@ extends GenericCompanion[CC] {
b.result
}
}
-
diff --git a/src/library/scala/collection/generic/IsSeqLike.scala b/src/library/scala/collection/generic/IsSeqLike.scala
new file mode 100644
index 0000000000..9467510a2c
--- /dev/null
+++ b/src/library/scala/collection/generic/IsSeqLike.scala
@@ -0,0 +1,57 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2003-2012, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+package scala.collection
+package generic
+
+/** Type class witnessing that a collection representation type `Repr` has
+ * elements of type `A` and has a conversion to `SeqLike[A, Repr]`.
+ *
+ * This type enables simple enrichment of `Seq`s with extension methods which
+ * can make full use of the mechanics of the Scala collections framework in
+ * their implementation.
+ *
+ * Example usage:
+ * {{{
+ * class FilterMapImpl[A, Repr](val r: SeqLike[A, Repr]) {
+ * final def filterMap[B, That](f: A => Option[B])(implicit cbf: CanBuildFrom[Repr, B, That]): That =
+ * r.flatMap(f(_))
+ * }
+ * implicit def filterMap[Repr, A](r: Repr)(implicit fr: IsSeqLike[Repr]): FilterMapImpl[fr.A,Repr] =
+ * new FilterMapImpl(fr.conversion(r))
+ *
+ * val l = List(1, 2, 3, 4, 5)
+ * List(1, 2, 3, 4, 5) filterMap (i => if(i % 2 == 0) Some(i) else None)
+ * // == List(2, 4)
+ * }}}
+ *
+ * @see [[scala.collection.Seq]]
+ * @see [[scala.collection.generic.IsTraversableLike]]
+ */
+trait IsSeqLike[Repr] {
+ /** The type of elements we can traverse over. */
+ type A
+ /** A conversion from the representation type `Repr` to a `SeqLike[A,Repr]`. */
+ val conversion: Repr => SeqLike[A, Repr]
+}
+
+object IsSeqLike {
+ import language.higherKinds
+
+ implicit val stringRepr: IsSeqLike[String] { type A = Char } =
+ new IsSeqLike[String] {
+ type A = Char
+ val conversion = implicitly[String => SeqLike[Char, String]]
+ }
+
+ implicit def seqLikeRepr[C[_], A0](implicit conv: C[A0] => SeqLike[A0,C[A0]]): IsSeqLike[C[A0]] { type A = A0 } =
+ new IsSeqLike[C[A0]] {
+ type A = A0
+ val conversion = conv
+ }
+}
diff --git a/src/library/scala/collection/generic/IterableForwarder.scala b/src/library/scala/collection/generic/IterableForwarder.scala
index 90ebcace84..8feace3f8b 100644
--- a/src/library/scala/collection/generic/IterableForwarder.scala
+++ b/src/library/scala/collection/generic/IterableForwarder.scala
@@ -6,12 +6,9 @@
** |/ **
\* */
-
-
package scala.collection.generic
-import scala.collection._
-import scala.collection.mutable.Buffer
+import scala.collection._
/** This trait implements a forwarder for iterable objects. It forwards
* all calls to a different iterable object, except for
diff --git a/src/library/scala/collection/generic/SeqForwarder.scala b/src/library/scala/collection/generic/SeqForwarder.scala
index e8b15ec450..aafaffc159 100644
--- a/src/library/scala/collection/generic/SeqForwarder.scala
+++ b/src/library/scala/collection/generic/SeqForwarder.scala
@@ -50,7 +50,7 @@ trait SeqForwarder[+A] extends Seq[A] with IterableForwarder[A] {
override def lastIndexOfSlice[B >: A](that: GenSeq[B]): Int = underlying lastIndexOfSlice that
override def lastIndexOfSlice[B >: A](that: GenSeq[B], end: Int): Int = underlying.lastIndexOfSlice(that, end)
override def containsSlice[B](that: GenSeq[B]): Boolean = underlying containsSlice that
- override def contains(elem: Any): Boolean = underlying contains elem
+ override def contains[A1 >: A](elem: A1): Boolean = underlying contains elem
override def corresponds[B](that: GenSeq[B])(p: (A,B) => Boolean): Boolean = underlying.corresponds(that)(p)
override def indices: Range = underlying.indices
}
diff --git a/src/library/scala/collection/immutable/DefaultMap.scala b/src/library/scala/collection/immutable/DefaultMap.scala
index 4a0503adfd..620baec9a8 100755
--- a/src/library/scala/collection/immutable/DefaultMap.scala
+++ b/src/library/scala/collection/immutable/DefaultMap.scala
@@ -6,13 +6,9 @@
** |/ **
\* */
-
-
package scala.collection
package immutable
-import generic._
-
/** A default map which implements the `+` and `-`
* methods of maps. It does so using the default builder for
* maps defined in the `Map` object.
diff --git a/src/library/scala/collection/immutable/GenIterable.scala.disabled b/src/library/scala/collection/immutable/GenIterable.scala.disabled
deleted file mode 100644
index d34f7fd856..0000000000
--- a/src/library/scala/collection/immutable/GenIterable.scala.disabled
+++ /dev/null
@@ -1,37 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2003-2013, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-package scala.collection
-package immutable
-
-
-import generic._
-import mutable.Builder
-
-
-/** A base trait for iterable collections that can be mutated.
- *
- * $possiblyparinfo
- *
- * $iterableInfo
- */
-trait GenIterable[+A] extends GenTraversable[A]
- with scala.collection.GenIterable[A]
- with scala.collection.GenIterableLike[A, GenIterable[A]]
-// with GenericTraversableTemplate[A, GenIterable]
-{
- def seq: Iterable[A]
- //override def companion: GenericCompanion[GenIterable] = GenIterable
-}
-
-
-// object GenIterable extends TraversableFactory[GenIterable] {
-// implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, GenIterable[A]] = ReusableCBF.asInstanceOf[GenericCanBuildFrom[A]]
-// def newBuilder[A]: Builder[A, GenIterable[A]] = Iterable.newBuilder
-// }
-
diff --git a/src/library/scala/collection/immutable/GenMap.scala.disabled b/src/library/scala/collection/immutable/GenMap.scala.disabled
deleted file mode 100644
index 73557a4a66..0000000000
--- a/src/library/scala/collection/immutable/GenMap.scala.disabled
+++ /dev/null
@@ -1,36 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2003-2013, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-package scala.collection
-package immutable
-
-import generic._
-
-
-/** A base trait for maps that can be mutated.
- * $possiblyparinfo
- * $mapNote
- * $mapTags
- * @since 1.0
- * @author Matthias Zenger
- */
-trait GenMap[A, +B]
-extends GenIterable[(A, B)]
- with scala.collection.GenMap[A, B]
- with scala.collection.GenMapLike[A, B, GenMap[A, B]]
-{
- def seq: Map[A, B]
-}
-
-
-// object GenMap extends MapFactory[GenMap] {
-// def empty[A, B]: Map[A, B] = Map.empty
-
-// /** $mapCanBuildFromInfo */
-// implicit def canBuildFrom[A, B]: CanBuildFrom[Coll, (A, B), GenMap[A, B]] = new MapCanBuildFrom[A, B]
-// }
diff --git a/src/library/scala/collection/immutable/GenSeq.scala.disabled b/src/library/scala/collection/immutable/GenSeq.scala.disabled
deleted file mode 100644
index 713529f3db..0000000000
--- a/src/library/scala/collection/immutable/GenSeq.scala.disabled
+++ /dev/null
@@ -1,49 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2003-2013, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-
-
-package scala.collection
-package immutable
-
-
-import generic._
-import mutable.Builder
-
-
-/** A subtrait of `collection.GenSeq` which represents sequences
- * that can be mutated.
- *
- * $possiblyparinfo
- *
- * $seqInfo
- *
- * The class adds an `update` method to `collection.Seq`.
- *
- * @define Coll `mutable.Seq`
- * @define coll mutable sequence
- */
-trait GenSeq[+A] extends GenIterable[A]
- with scala.collection.GenSeq[A]
- with scala.collection.GenSeqLike[A, GenSeq[A]]
-// with GenericTraversableTemplate[A, GenSeq]
-{
- def seq: Seq[A]
- //override def companion: GenericCompanion[GenSeq] = GenSeq
-}
-
-
-// object GenSeq extends SeqFactory[GenSeq] {
-// implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, GenSeq[A]] = ReusableCBF.asInstanceOf[GenericCanBuildFrom[A]]
-// def newBuilder[A]: Builder[A, GenSeq[A]] = Seq.newBuilder
-// }
-
-
-
-
-
diff --git a/src/library/scala/collection/immutable/GenSet.scala.disabled b/src/library/scala/collection/immutable/GenSet.scala.disabled
deleted file mode 100644
index 56bd2738fd..0000000000
--- a/src/library/scala/collection/immutable/GenSet.scala.disabled
+++ /dev/null
@@ -1,43 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2003-2013, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-
-
-package scala.collection
-package immutable
-
-
-import generic._
-import mutable.Builder
-
-
-/** A generic trait for mutable sets.
- *
- * $possiblyparinfo
- * $setNote
- * $setTags
- *
- * @since 1.0
- * @author Matthias Zenger
- * @define Coll `mutable.Set`
- * @define coll mutable set
- */
-trait GenSet[A] extends GenIterable[A]
- with scala.collection.GenSet[A]
- with scala.collection.GenSetLike[A, GenSet[A]]
-// with GenericSetTemplate[A, GenSet]
-{
- //override def companion: GenericCompanion[GenSet] = GenSet
- def seq: Set[A]
-}
-
-
-// object GenSet extends TraversableFactory[GenSet] {
-// implicit def canBuildFrom[A] = ReusableCBF.asInstanceOf[GenericCanBuildFrom[A]]
-// def newBuilder[A] = Set.newBuilder
-// }
diff --git a/src/library/scala/collection/immutable/GenTraversable.scala.disabled b/src/library/scala/collection/immutable/GenTraversable.scala.disabled
deleted file mode 100644
index e5b609f9ed..0000000000
--- a/src/library/scala/collection/immutable/GenTraversable.scala.disabled
+++ /dev/null
@@ -1,41 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2003-2013, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-
-
-package scala.collection
-package immutable
-
-
-import generic._
-import mutable.Builder
-
-
-/** A trait for traversable collections that can be mutated.
- *
- * $possiblyparinfo
- *
- * $traversableInfo
- * @define mutability mutable
- */
-trait GenTraversable[+A] extends scala.collection.GenTraversable[A]
- with scala.collection.GenTraversableLike[A, GenTraversable[A]]
-// with GenericTraversableTemplate[A, GenTraversable]
- with Mutable
-{
- def seq: Traversable[A]
- //override def companion: GenericCompanion[GenTraversable] = GenTraversable
-}
-
-
-// object GenTraversable extends TraversableFactory[GenTraversable] {
-// implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, GenTraversable[A]] = ReusableCBF.asInstanceOf[GenericCanBuildFrom[A]]
-// def newBuilder[A]: Builder[A, GenTraversable[A]] = Traversable.newBuilder
-// }
-
-
diff --git a/src/library/scala/collection/immutable/HashMap.scala b/src/library/scala/collection/immutable/HashMap.scala
index 84416a62d2..29267f22dc 100644
--- a/src/library/scala/collection/immutable/HashMap.scala
+++ b/src/library/scala/collection/immutable/HashMap.scala
@@ -471,9 +471,6 @@ time { mNew.iterator.foreach( p => ()) }
// condition below is due to 2 things:
// 1) no unsigned int compare on JVM
// 2) 0 (no lsb) should always be greater in comparison
- val a = thislsb - 1
- val b = thatlsb - 1
-
if (unsignedCompare(thislsb - 1, thatlsb - 1)) {
val m = thiselems(thisi)
totalelems += m.size
diff --git a/src/library/scala/collection/immutable/IndexedSeq.scala b/src/library/scala/collection/immutable/IndexedSeq.scala
index bf4ba3a381..9316ff5e72 100644
--- a/src/library/scala/collection/immutable/IndexedSeq.scala
+++ b/src/library/scala/collection/immutable/IndexedSeq.scala
@@ -37,6 +37,7 @@ object IndexedSeq extends IndexedSeqFactory[IndexedSeq] {
def apply(idx: Int) = buf.apply(idx)
}
def newBuilder[A]: Builder[A, IndexedSeq[A]] = Vector.newBuilder[A]
+
implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, IndexedSeq[A]] =
ReusableCBF.asInstanceOf[GenericCanBuildFrom[A]]
}
diff --git a/src/library/scala/collection/immutable/List.scala b/src/library/scala/collection/immutable/List.scala
index 56e386ad67..aeaa479e2f 100644
--- a/src/library/scala/collection/immutable/List.scala
+++ b/src/library/scala/collection/immutable/List.scala
@@ -152,7 +152,7 @@ sealed abstract class List[+A] extends AbstractSeq[A]
* @usecase def mapConserve(f: A => A): List[A]
* @inheritdoc
*/
- def mapConserve[B >: A <: AnyRef](f: A => B): List[B] = {
+ @inline final def mapConserve[B >: A <: AnyRef](f: A => B): List[B] = {
@tailrec
def loop(mapped: ListBuffer[B], unchanged: List[A], pending: List[A]): List[B] =
if (pending.isEmpty) {
@@ -257,7 +257,7 @@ sealed abstract class List[+A] extends AbstractSeq[A]
(b.toList, these)
}
- override def takeWhile(p: A => Boolean): List[A] = {
+ @inline final override def takeWhile(p: A => Boolean): List[A] = {
val b = new ListBuffer[A]
var these = this
while (!these.isEmpty && p(these.head)) {
@@ -267,7 +267,7 @@ sealed abstract class List[+A] extends AbstractSeq[A]
b.toList
}
- override def dropWhile(p: A => Boolean): List[A] = {
+ @inline final override def dropWhile(p: A => Boolean): List[A] = {
@tailrec
def loop(xs: List[A]): List[A] =
if (xs.isEmpty || !p(xs.head)) xs
@@ -276,7 +276,7 @@ sealed abstract class List[+A] extends AbstractSeq[A]
loop(this)
}
- override def span(p: A => Boolean): (List[A], List[A]) = {
+ @inline final override def span(p: A => Boolean): (List[A], List[A]) = {
val b = new ListBuffer[A]
var these = this
while (!these.isEmpty && p(these.head)) {
@@ -286,6 +286,16 @@ sealed abstract class List[+A] extends AbstractSeq[A]
(b.toList, these)
}
+ // Overridden with an implementation identical to the inherited one (at this time)
+ // solely so it can be finalized and thus inlinable.
+ @inline final override def foreach[U](f: A => U) {
+ var these = this
+ while (!these.isEmpty) {
+ f(these.head)
+ these = these.tail
+ }
+ }
+
override def reverse: List[A] = {
var result: List[A] = Nil
var these = this
@@ -301,18 +311,6 @@ sealed abstract class List[+A] extends AbstractSeq[A]
override def toStream : Stream[A] =
if (isEmpty) Stream.Empty
else new Stream.Cons(head, tail.toStream)
-
- @inline override final
- def foreach[B](f: A => B) {
- var these = this
- while (!these.isEmpty) {
- f(these.head)
- these = these.tail
- }
- }
-
- @deprecated("use `distinct` instead", "2.8.0")
- def removeDuplicates: List[A] = distinct
}
/** The empty list.
@@ -381,12 +379,6 @@ final case class ::[B](private var hd: B, private[scala] var tl: List[B]) extend
current = list
}
}
-
- private def oldWriteObject(out: ObjectOutputStream) {
- var xs: List[B] = this
- while (!xs.isEmpty) { out.writeObject(xs.head); xs = xs.tail }
- out.writeObject(ListSerializeEnd)
- }
}
/** $factoryInfo
@@ -394,9 +386,6 @@ final case class ::[B](private var hd: B, private[scala] var tl: List[B]) extend
* @define Coll `List`
*/
object List extends SeqFactory[List] {
-
- import scala.collection.{Iterable, Seq, IndexedSeq}
-
/** $genericCanBuildFromInfo */
implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, List[A]] =
ReusableCBF.asInstanceOf[GenericCanBuildFrom[A]]
@@ -406,248 +395,6 @@ object List extends SeqFactory[List] {
override def empty[A]: List[A] = Nil
override def apply[A](xs: A*): List[A] = xs.toList
-
- /** Create a sorted list with element values `v,,>n+1,, = step(v,,n,,)`
- * where `v,,0,, = start` and elements are in the range between `start`
- * (inclusive) and `end` (exclusive).
- *
- * @param start the start value of the list
- * @param end the end value of the list
- * @param step the increment function of the list, which given `v,,n,,`,
- * computes `v,,n+1,,`. Must be monotonically increasing
- * or decreasing.
- * @return the sorted list of all integers in range `[start;end)`.
- */
- @deprecated("use `iterate` instead", "2.8.0")
- def range(start: Int, end: Int, step: Int => Int): List[Int] = {
- val up = step(start) > start
- val down = step(start) < start
- val b = new ListBuffer[Int]
- var i = start
- while ((!up || i < end) && (!down || i > end)) {
- b += i
- val next = step(i)
- if (i == next)
- throw new IllegalArgumentException("the step function did not make any progress on "+ i)
- i = next
- }
- b.toList
- }
-
- /** Create a list containing several copies of an element.
- *
- * @param n the length of the resulting list
- * @param elem the element composing the resulting list
- * @return a list composed of `n` elements all equal to `elem`
- */
- @deprecated("use `fill` instead", "2.8.0")
- def make[A](n: Int, elem: A): List[A] = {
- val b = new ListBuffer[A]
- var i = 0
- while (i < n) {
- b += elem
- i += 1
- }
- b.toList
- }
-
- /** Concatenate all the elements of a given list of lists.
- *
- * @param xss the list of lists that are to be concatenated
- * @return the concatenation of all the lists
- */
- @deprecated("use `xss.flatten` instead of `List.flatten(xss)`", "2.8.0")
- def flatten[A](xss: List[List[A]]): List[A] = {
- val b = new ListBuffer[A]
- for (xs <- xss) {
- var xc = xs
- while (!xc.isEmpty) {
- b += xc.head
- xc = xc.tail
- }
- }
- b.toList
- }
-
- /** Transforms a list of pairs into a pair of lists.
- *
- * @param xs the list of pairs to unzip
- * @return a pair of lists.
- */
- @deprecated("use `xs.unzip` instead of `List.unzip(xs)`", "2.8.0")
- def unzip[A,B](xs: List[(A,B)]): (List[A], List[B]) = {
- val b1 = new ListBuffer[A]
- val b2 = new ListBuffer[B]
- var xc = xs
- while (!xc.isEmpty) {
- b1 += xc.head._1
- b2 += xc.head._2
- xc = xc.tail
- }
- (b1.toList, b2.toList)
- }
-
- /** Transforms an iterable of pairs into a pair of lists.
- *
- * @param xs the iterable of pairs to unzip
- * @return a pair of lists.
- */
- @deprecated("use `xs.unzip` instead of `List.unzip(xs)`", "2.8.0")
- def unzip[A,B](xs: Iterable[(A,B)]): (List[A], List[B]) =
- xs.foldRight[(List[A], List[B])]((Nil, Nil)) {
- case ((x, y), (xs, ys)) => (x :: xs, y :: ys)
- }
-
- /**
- * Returns the `Left` values in the given `Iterable` of `Either`s.
- */
- @deprecated("use `xs collect { case Left(x: A) => x }` instead of `List.lefts(xs)`", "2.8.0")
- def lefts[A, B](es: Iterable[Either[A, B]]) =
- es.foldRight[List[A]](Nil)((e, as) => e match {
- case Left(a) => a :: as
- case Right(_) => as
- })
-
- /**
- * Returns the `Right` values in the given `Iterable` of `Either`s.
- */
- @deprecated("use `xs collect { case Right(x: B) => x }` instead of `List.rights(xs)`", "2.8.0")
- def rights[A, B](es: Iterable[Either[A, B]]) =
- es.foldRight[List[B]](Nil)((e, bs) => e match {
- case Left(_) => bs
- case Right(b) => b :: bs
- })
-
- /** Transforms an Iterable of Eithers into a pair of lists.
- *
- * @param es the iterable of Eithers to separate
- * @return a pair of lists.
- */
- @deprecated("use `(for (Left(x) <- es) yield x, for (Right(x) <- es) yield x)` instead", "2.8.0")
- def separate[A,B](es: Iterable[Either[A, B]]): (List[A], List[B]) =
- es.foldRight[(List[A], List[B])]((Nil, Nil)) {
- case (Left(a), (lefts, rights)) => (a :: lefts, rights)
- case (Right(b), (lefts, rights)) => (lefts, b :: rights)
- }
-
- /** Converts an iterator to a list.
- *
- * @param it the iterator to convert
- * @return a list that contains the elements returned by successive
- * calls to `it.next`
- */
- @deprecated("use `it.toList` instead of `List.toList(it)`", "2.8.0")
- def fromIterator[A](it: Iterator[A]): List[A] = it.toList
-
- /** Converts an array into a list.
- *
- * @param arr the array to convert
- * @return a list that contains the same elements than `arr`
- * in the same order
- */
- @deprecated("use `array.toList` instead of `List.fromArray(array)`", "2.8.0")
- def fromArray[A](arr: Array[A]): List[A] = fromArray(arr, 0, arr.length)
-
- /** Converts a range of an array into a list.
- *
- * @param arr the array to convert
- * @param start the first index to consider
- * @param len the length of the range to convert
- * @return a list that contains the same elements than `arr`
- * in the same order
- */
- @deprecated("use `array.view(start, end).toList` instead of `List.fromArray(array, start, end)`", "2.8.0")
- def fromArray[A](arr: Array[A], start: Int, len: Int): List[A] = {
- var res: List[A] = Nil
- var i = start + len
- while (i > start) {
- i -= 1
- res = arr(i) :: res
- }
- res
- }
-
- /** Returns the list resulting from applying the given function `f`
- * to corresponding elements of the argument lists.
- *
- * @param f function to apply to each pair of elements.
- * @return `[f(a,,0,,,b,,0,,), ..., f(a,,n,,,b,,n,,)]` if the lists are
- * `[a,,0,,, ..., a,,k,,]`, `[b,,0,,, ..., b,,l,,]` and
- * `n = min(k,l)`
- */
- @deprecated("use `(xs, ys).zipped.map(f)` instead of `List.map2(xs, ys)(f)`", "2.8.0")
- def map2[A,B,C](xs: List[A], ys: List[B])(f: (A, B) => C): List[C] = {
- val b = new ListBuffer[C]
- var xc = xs
- var yc = ys
- while (!xc.isEmpty && !yc.isEmpty) {
- b += f(xc.head, yc.head)
- xc = xc.tail
- yc = yc.tail
- }
- b.toList
- }
-
- /** Tests whether the given predicate `p` holds
- * for all corresponding elements of the argument lists.
- *
- * @param f function to apply to each pair of elements.
- * @return `(p(a<sub>0</sub>,b<sub>0</sub>) &amp;&amp;
- * ... &amp;&amp; p(a<sub>n</sub>,b<sub>n</sub>))]`
- * if the lists are `[a<sub>0</sub>, ..., a<sub>k</sub>]`;
- * `[b<sub>0</sub>, ..., b<sub>l</sub>]`
- * and `n = min(k,l)`
- */
- @deprecated("use `(xs, ys).zipped.forall(f)` instead of `List.forall2(xs, ys)(f)`", "2.8.0")
- def forall2[A,B](xs: List[A], ys: List[B])(f: (A, B) => Boolean): Boolean = {
- var xc = xs
- var yc = ys
- while (!xc.isEmpty && !yc.isEmpty) {
- if (!f(xc.head, yc.head)) return false
- xc = xc.tail
- yc = yc.tail
- }
- true
- }
-
- /** Tests whether the given predicate `p` holds
- * for some corresponding elements of the argument lists.
- *
- * @param f function to apply to each pair of elements.
- * @return `n != 0 &amp;&amp; (p(a<sub>0</sub>,b<sub>0</sub>) ||
- * ... || p(a<sub>n</sub>,b<sub>n</sub>))]` if the lists are
- * `[a<sub>0</sub>, ..., a<sub>k</sub>]`,
- * `[b<sub>0</sub>, ..., b<sub>l</sub>]` and
- * `n = min(k,l)`
- */
- @deprecated("use `(xs, ys).zipped.exists(f)` instead of `List.exists2(xs, ys)(f)`", "2.8.0")
- def exists2[A,B](xs: List[A], ys: List[B])(f: (A, B) => Boolean): Boolean = {
- var xc = xs
- var yc = ys
- while (!xc.isEmpty && !yc.isEmpty) {
- if (f(xc.head, yc.head)) return true
- xc = xc.tail
- yc = yc.tail
- }
- false
- }
-
- /** Transposes a list of lists.
- * pre: All element lists have the same length.
- *
- * @param xss the list of lists
- * @return the transposed list of lists
- */
- @deprecated("use `xss.transpose` instead of `List.transpose(xss)`", "2.8.0")
- def transpose[A](xss: List[List[A]]): List[List[A]] = {
- val buf = new ListBuffer[List[A]]
- var yss = xss
- while (!yss.head.isEmpty) {
- buf += (yss map (_.head))
- yss = (yss map (_.tail))
- }
- buf.toList
- }
}
/** Only used for list serialization */
diff --git a/src/library/scala/collection/immutable/LongMap.scala b/src/library/scala/collection/immutable/LongMap.scala
index 2a2910439a..fab1b7f00b 100644
--- a/src/library/scala/collection/immutable/LongMap.scala
+++ b/src/library/scala/collection/immutable/LongMap.scala
@@ -77,8 +77,6 @@ object LongMap {
}
}
-import LongMap._
-
// Iterator over a non-empty LongMap.
private[immutable] abstract class LongMapIterator[V, T](it: LongMap[V]) extends AbstractIterator[T] {
diff --git a/src/library/scala/collection/immutable/NumericRange.scala b/src/library/scala/collection/immutable/NumericRange.scala
index d3be299f89..195aeed281 100644
--- a/src/library/scala/collection/immutable/NumericRange.scala
+++ b/src/library/scala/collection/immutable/NumericRange.scala
@@ -6,12 +6,10 @@
** |/ **
\* */
-
package scala.collection
package immutable
import mutable.{ Builder, ListBuffer }
-import generic._
/** `NumericRange` is a more generic version of the
* `Range` class which works with arbitrary types.
@@ -81,17 +79,6 @@ extends AbstractSeq[T] with IndexedSeq[T] with Serializable {
// to guard against any (most likely illusory) performance drop. They should
// be eliminated one way or another.
- // Counts how many elements from the start meet the given test.
- private def skipCount(p: T => Boolean): Int = {
- var current = start
- var counted = 0
-
- while (counted < length && p(current)) {
- counted += 1
- current += step
- }
- counted
- }
// Tests whether a number is within the endpoints, without testing
// whether it is a member of the sequence (i.e. when step > 1.)
private def isWithinBoundaries(elem: T) = !isEmpty && (
@@ -124,21 +111,21 @@ extends AbstractSeq[T] with IndexedSeq[T] with Serializable {
if (idx < 0 || idx >= length) throw new IndexOutOfBoundsException(idx.toString)
else locationAfterN(idx)
}
-
+
import NumericRange.defaultOrdering
-
+
override def min[T1 >: T](implicit ord: Ordering[T1]): T =
if (ord eq defaultOrdering(num)) {
if (num.signum(step) > 0) start
else last
} else super.min(ord)
-
- override def max[T1 >: T](implicit ord: Ordering[T1]): T =
+
+ override def max[T1 >: T](implicit ord: Ordering[T1]): T =
if (ord eq defaultOrdering(num)) {
if (num.signum(step) > 0) last
else start
} else super.max(ord)
-
+
// Motivated by the desire for Double ranges with BigDecimal precision,
// we need some way to map a Range and get another Range. This can't be
// done in any fully general way because Ranges are not arbitrary
@@ -182,12 +169,11 @@ extends AbstractSeq[T] with IndexedSeq[T] with Serializable {
def containsTyped(x: T): Boolean =
isWithinBoundaries(x) && (((x - start) % step) == zero)
- override def contains(x: Any): Boolean =
+ override def contains[A1 >: T](x: A1): Boolean =
try containsTyped(x.asInstanceOf[T])
catch { case _: ClassCastException => false }
final override def sum[B >: T](implicit num: Numeric[B]): B = {
- import num.Ops
if (isEmpty) this.num fromInt 0
else if (numRangeElements == 1) head
else ((this.num fromInt numRangeElements) * (head + last) / (this.num fromInt 2))
@@ -213,7 +199,7 @@ extends AbstractSeq[T] with IndexedSeq[T] with Serializable {
/** A companion object for numeric ranges.
*/
object NumericRange {
-
+
/** Calculates the number of elements in a range given start, end, step, and
* whether or not it is inclusive. Throws an exception if step == 0 or
* the number of elements exceeds the maximum Int.
@@ -272,7 +258,7 @@ object NumericRange {
new Exclusive(start, end, step)
def inclusive[T](start: T, end: T, step: T)(implicit num: Integral[T]): Inclusive[T] =
new Inclusive(start, end, step)
-
+
private[collection] val defaultOrdering = Map[Numeric[_], Ordering[_]](
Numeric.BigIntIsIntegral -> Ordering.BigInt,
Numeric.IntIsIntegral -> Ordering.Int,
@@ -284,6 +270,6 @@ object NumericRange {
Numeric.DoubleAsIfIntegral -> Ordering.Double,
Numeric.BigDecimalAsIfIntegral -> Ordering.BigDecimal
)
-
+
}
diff --git a/src/library/scala/collection/immutable/Range.scala b/src/library/scala/collection/immutable/Range.scala
index 802e16605d..02c10700b1 100644
--- a/src/library/scala/collection/immutable/Range.scala
+++ b/src/library/scala/collection/immutable/Range.scala
@@ -77,6 +77,7 @@ extends scala.collection.AbstractSeq[Int]
final val terminalElement = start + numRangeElements * step
override def last = if (isEmpty) Nil.last else lastElement
+ override def head = if (isEmpty) Nil.head else start
override def min[A1 >: Int](implicit ord: Ordering[A1]): Int =
if (ord eq Ordering.Int) {
diff --git a/src/library/scala/collection/immutable/RedBlackTree.scala b/src/library/scala/collection/immutable/RedBlackTree.scala
index 0254e9ca3a..99f8d95517 100644
--- a/src/library/scala/collection/immutable/RedBlackTree.scala
+++ b/src/library/scala/collection/immutable/RedBlackTree.scala
@@ -18,7 +18,7 @@ import scala.annotation.meta.getter
/** An object containing the RedBlack tree implementation used by for `TreeMaps` and `TreeSets`.
*
* Implementation note: since efficiency is important for data structures this implementation
- * uses <code>null</code> to represent empty trees. This also means pattern matching cannot
+ * uses `null` to represent empty trees. This also means pattern matching cannot
* easily be used. The API represented by the RedBlackTree object tries to hide these
* optimizations behind a reasonably clean API.
*
@@ -74,15 +74,21 @@ object RedBlackTree {
result
}
- def foreach[A, B, U](tree: Tree[A, B], f: ((A, B)) => U): Unit = if (tree ne null) {
- if (tree.left ne null) foreach(tree.left, f)
+
+ def foreach[A,B,U](tree:Tree[A,B], f:((A,B)) => U):Unit = if (tree ne null) _foreach(tree,f)
+
+ private[this] def _foreach[A, B, U](tree: Tree[A, B], f: ((A, B)) => U) {
+ if (tree.left ne null) _foreach(tree.left, f)
f((tree.key, tree.value))
- if (tree.right ne null) foreach(tree.right, f)
+ if (tree.right ne null) _foreach(tree.right, f)
}
- def foreachKey[A, U](tree: Tree[A, _], f: A => U): Unit = if (tree ne null) {
- if (tree.left ne null) foreachKey(tree.left, f)
- f(tree.key)
- if (tree.right ne null) foreachKey(tree.right, f)
+
+ def foreachKey[A, U](tree:Tree[A,_], f: A => U):Unit = if (tree ne null) _foreachKey(tree,f)
+
+ private[this] def _foreachKey[A, U](tree: Tree[A, _], f: A => U) {
+ if (tree.left ne null) _foreachKey(tree.left, f)
+ f((tree.key))
+ if (tree.right ne null) _foreachKey(tree.right, f)
}
def iterator[A, B](tree: Tree[A, B]): Iterator[(A, B)] = new EntriesIterator(tree)
diff --git a/src/library/scala/collection/immutable/Stream.scala b/src/library/scala/collection/immutable/Stream.scala
index be2cd91c68..3f7d27981b 100644
--- a/src/library/scala/collection/immutable/Stream.scala
+++ b/src/library/scala/collection/immutable/Stream.scala
@@ -181,6 +181,7 @@ import scala.language.implicitConversions
* @define coll stream
* @define orderDependent
* @define orderDependentFold
+ * @define willTerminateInf Note: lazily evaluated; will terminate for infinite-sized collections.
*/
abstract class Stream[+A] extends AbstractSeq[A]
with LinearSeq[A]
@@ -286,9 +287,8 @@ self =>
len
}
- /** It's an imperfect world, but at least we can bottle up the
- * imperfection in a capsule.
- */
+ // It's an imperfect world, but at least we can bottle up the
+ // imperfection in a capsule.
@inline private def asThat[That](x: AnyRef): That = x.asInstanceOf[That]
@inline private def asStream[B](x: AnyRef): Stream[B] = x.asInstanceOf[Stream[B]]
@inline private def isStreamBuilder[B, That](bf: CanBuildFrom[Stream[A], B, That]) =
@@ -385,12 +385,17 @@ self =>
// 1) stackoverflows (could be achieved with tailrec, too)
// 2) out of memory errors for big streams (`this` reference can be eliminated from the stack)
var rest: Stream[A] = this
- while (rest.nonEmpty && !pf.isDefinedAt(rest.head)) rest = rest.tail
+
+ // Avoids calling both `pf.isDefined` and `pf.apply`.
+ var newHead: B = null.asInstanceOf[B]
+ val runWith = pf.runWith((b: B) => newHead = b)
+
+ while (rest.nonEmpty && !runWith(rest.head)) rest = rest.tail
// without the call to the companion object, a thunk is created for the tail of the new stream,
// and the closure of the thunk will reference `this`
if (rest.isEmpty) Stream.Empty.asInstanceOf[That]
- else Stream.collectedTail(rest, pf, bf).asInstanceOf[That]
+ else Stream.collectedTail(newHead, rest, pf, bf).asInstanceOf[That]
}
}
@@ -725,10 +730,15 @@ self =>
* // produces: "5, 6, 7, 8, 9"
* }}}
*/
- override def take(n: Int): Stream[A] =
+ override def take(n: Int): Stream[A] = (
+ // Note that the n == 1 condition appears redundant but is not.
+ // It prevents "tail" from being referenced (and its head being evaluated)
+ // when obtaining the last element of the result. Such are the challenges
+ // of working with a lazy-but-not-really sequence.
if (n <= 0 || isEmpty) Stream.empty
else if (n == 1) cons(head, Stream.empty)
else cons(head, tail take n-1)
+ )
@tailrec final override def drop(n: Int): Stream[A] =
if (n <= 0 || isEmpty) this
@@ -784,8 +794,23 @@ self =>
these
}
- // there's nothing we can do about dropRight, so we just keep the definition
- // in LinearSeq
+ /**
+ * @inheritdoc
+ * $willTerminateInf
+ */
+ override def dropRight(n: Int): Stream[A] = {
+ // We make dropRight work for possibly infinite streams by carrying
+ // a buffer of the dropped size. As long as the buffer is full and the
+ // rest is non-empty, we can feed elements off the buffer head. When
+ // the rest becomes empty, the full buffer is the dropped elements.
+ def advance(stub0: List[A], stub1: List[A], rest: Stream[A]): Stream[A] = {
+ if (rest.isEmpty) Stream.empty
+ else if (stub0.isEmpty) advance(stub1.reverse, Nil, rest)
+ else cons(stub0.head, advance(stub0.tail, rest.head :: stub1, rest.tail))
+ }
+ if (n <= 0) this
+ else advance((this take n).toList, Nil, this drop n)
+ }
/** Returns the longest prefix of this `Stream` whose elements satisfy the
* predicate `p`.
@@ -841,9 +866,16 @@ self =>
* // produces: "1, 2, 3, 4, 5, 6"
* }}}
*/
- override def distinct: Stream[A] =
- if (isEmpty) this
- else cons(head, tail.filter(head != _).distinct)
+ override def distinct: Stream[A] = {
+ // This should use max memory proportional to N, whereas
+ // recursively calling distinct on the tail is N^2.
+ def loop(seen: Set[A], rest: Stream[A]): Stream[A] = {
+ if (rest.isEmpty) rest
+ else if (seen(rest.head)) loop(seen, rest.tail)
+ else cons(rest.head, loop(seen + rest.head, rest.tail))
+ }
+ loop(Set(), this)
+ }
/** Returns a new sequence of given length containing the elements of this
* sequence followed by zero or more occurrences of given elements.
@@ -1142,8 +1174,8 @@ object Stream extends SeqFactory[Stream] {
cons(stream.head, stream.tail filter p)
}
- private[immutable] def collectedTail[A, B, That](stream: Stream[A], pf: PartialFunction[A, B], bf: CanBuildFrom[Stream[A], B, That]) = {
- cons(pf(stream.head), stream.tail.collect(pf)(bf).asInstanceOf[Stream[B]])
+ private[immutable] def collectedTail[A, B, That](head: B, stream: Stream[A], pf: PartialFunction[A, B], bf: CanBuildFrom[Stream[A], B, That]) = {
+ cons(head, stream.tail.collect(pf)(bf).asInstanceOf[Stream[B]])
}
}
diff --git a/src/library/scala/collection/immutable/StringLike.scala b/src/library/scala/collection/immutable/StringLike.scala
index edea89b555..663318330c 100644
--- a/src/library/scala/collection/immutable/StringLike.scala
+++ b/src/library/scala/collection/immutable/StringLike.scala
@@ -9,7 +9,6 @@
package scala.collection
package immutable
-import generic._
import mutable.Builder
import scala.util.matching.Regex
import scala.math.ScalaNumber
@@ -19,12 +18,11 @@ import scala.reflect.ClassTag
* @since 2.8
*/
object StringLike {
-
// just statics for companion class.
- private final val LF: Char = 0x0A
- private final val FF: Char = 0x0C
- private final val CR: Char = 0x0D
- private final val SU: Char = 0x1A
+ private final val LF = 0x0A
+ private final val FF = 0x0C
+ private final val CR = 0x0D
+ private final val SU = 0x1A
}
import StringLike._
diff --git a/src/library/scala/collection/immutable/StringOps.scala b/src/library/scala/collection/immutable/StringOps.scala
index a650d98697..16c1f96cc2 100644
--- a/src/library/scala/collection/immutable/StringOps.scala
+++ b/src/library/scala/collection/immutable/StringOps.scala
@@ -6,8 +6,6 @@
** |/ **
\* */
-
-
package scala.collection
package immutable
diff --git a/src/library/scala/collection/immutable/TrieIterator.scala b/src/library/scala/collection/immutable/TrieIterator.scala
index ae427852d4..f117bddb8c 100644
--- a/src/library/scala/collection/immutable/TrieIterator.scala
+++ b/src/library/scala/collection/immutable/TrieIterator.scala
@@ -177,7 +177,6 @@ private[collection] abstract class TrieIterator[+T](elems: Array[Iterable[T]]) e
if (depth > 0) {
// 2) topmost comes before (is not) arrayD
// steal a portion of top to create a new iterator
- val topmost = arrayStack(0)
if (posStack(0) == arrayStack(0).length - 1) {
// 2a) only a single entry left on top
// this means we have to modify this iterator - pop topmost
diff --git a/src/library/scala/collection/immutable/Vector.scala b/src/library/scala/collection/immutable/Vector.scala
index f083e80175..abaffd9d6a 100644
--- a/src/library/scala/collection/immutable/Vector.scala
+++ b/src/library/scala/collection/immutable/Vector.scala
@@ -139,7 +139,7 @@ override def companion: GenericCompanion[Vector] = Vector
if (bf eq IndexedSeq.ReusableCBF) appendFront(elem).asInstanceOf[That] // just ignore bf
else super.+:(elem)(bf)
- override def :+[B >: A, That](elem: B)(implicit bf: CanBuildFrom[Vector[A], B, That]): That =
+ override def :+[B >: A, That](elem: B)(implicit bf: CanBuildFrom[Vector[A], B, That]): That =
if (bf eq IndexedSeq.ReusableCBF) appendBack(elem).asInstanceOf[That] // just ignore bf
else super.:+(elem)(bf)
@@ -242,8 +242,8 @@ override def companion: GenericCompanion[Vector] = Vector
private[immutable] def appendFront[B>:A](value: B): Vector[B] = {
if (endIndex != startIndex) {
- var blockIndex = (startIndex - 1) & ~31
- var lo = (startIndex - 1) & 31
+ val blockIndex = (startIndex - 1) & ~31
+ val lo = (startIndex - 1) & 31
if (startIndex != blockIndex + 32) {
val s = new Vector(startIndex - 1, endIndex, blockIndex)
@@ -339,8 +339,8 @@ override def companion: GenericCompanion[Vector] = Vector
// //println("------- append " + value)
// debug()
if (endIndex != startIndex) {
- var blockIndex = endIndex & ~31
- var lo = endIndex & 31
+ val blockIndex = endIndex & ~31
+ val lo = endIndex & 31
if (endIndex != blockIndex) {
//println("will make writable block (from "+focus+") at: " + blockIndex)
@@ -574,9 +574,7 @@ override def companion: GenericCompanion[Vector] = Vector
}
private def dropFront0(cutIndex: Int): Vector[A] = {
- var blockIndex = cutIndex & ~31
- var lo = cutIndex & 31
-
+ val blockIndex = cutIndex & ~31
val xor = cutIndex ^ (endIndex - 1)
val d = requiredDepth(xor)
val shift = (cutIndex & ~((1 << (5*d))-1))
@@ -606,9 +604,7 @@ override def companion: GenericCompanion[Vector] = Vector
}
private def dropBack0(cutIndex: Int): Vector[A] = {
- var blockIndex = (cutIndex - 1) & ~31
- var lo = ((cutIndex - 1) & 31) + 1
-
+ val blockIndex = (cutIndex - 1) & ~31
val xor = startIndex ^ (cutIndex - 1)
val d = requiredDepth(xor)
val shift = (startIndex & ~((1 << (5*d))-1))
@@ -630,14 +626,13 @@ override def companion: GenericCompanion[Vector] = Vector
}
-class VectorIterator[+A](_startIndex: Int, _endIndex: Int)
+class VectorIterator[+A](_startIndex: Int, endIndex: Int)
extends AbstractIterator[A]
with Iterator[A]
with VectorPointer[A @uncheckedVariance] {
private var blockIndex: Int = _startIndex & ~31
private var lo: Int = _startIndex & 31
- private var endIndex: Int = _endIndex
private var endLo = math.min(endIndex - blockIndex, 32)
@@ -667,13 +662,13 @@ extends AbstractIterator[A]
res
}
- private[collection] def remainingElementCount: Int = (_endIndex - (blockIndex + lo)) max 0
+ private[collection] def remainingElementCount: Int = (endIndex - (blockIndex + lo)) max 0
/** Creates a new vector which consists of elements remaining in this iterator.
* Such a vector can then be split into several vectors using methods like `take` and `drop`.
*/
private[collection] def remainingVector: Vector[A] = {
- val v = new Vector(blockIndex + lo, _endIndex, blockIndex + lo)
+ val v = new Vector(blockIndex + lo, endIndex, blockIndex + lo)
v.initFrom(this)
v
}
diff --git a/src/library/scala/collection/mutable/ArrayBuilder.scala b/src/library/scala/collection/mutable/ArrayBuilder.scala
index 0ce2cda32c..2fe3e91d68 100644
--- a/src/library/scala/collection/mutable/ArrayBuilder.scala
+++ b/src/library/scala/collection/mutable/ArrayBuilder.scala
@@ -6,12 +6,9 @@
** |/ **
\* */
-
-
package scala.collection
package mutable
-import generic._
import scala.reflect.ClassTag
import scala.runtime.ScalaRunTime
diff --git a/src/library/scala/collection/mutable/ArrayLike.scala b/src/library/scala/collection/mutable/ArrayLike.scala
index 31f3d2a497..40017aa08e 100644
--- a/src/library/scala/collection/mutable/ArrayLike.scala
+++ b/src/library/scala/collection/mutable/ArrayLike.scala
@@ -6,11 +6,8 @@
** |/ **
\* */
-
-
package scala.collection
package mutable
-import generic._
/** A common supertrait of `ArrayOps` and `WrappedArray` that factors out most
* operations on arrays and wrapped arrays.
diff --git a/src/library/scala/collection/mutable/BufferProxy.scala b/src/library/scala/collection/mutable/BufferProxy.scala
index 37aa1862fa..ade0b94230 100644
--- a/src/library/scala/collection/mutable/BufferProxy.scala
+++ b/src/library/scala/collection/mutable/BufferProxy.scala
@@ -6,12 +6,9 @@
** |/ **
\* */
-
-
package scala.collection
package mutable
-import generic._
import script._
/** This is a simple proxy class for <a href="Buffer.html"
diff --git a/src/library/scala/collection/mutable/FlatHashTable.scala b/src/library/scala/collection/mutable/FlatHashTable.scala
index 91e95e039b..7ab99fcda2 100644
--- a/src/library/scala/collection/mutable/FlatHashTable.scala
+++ b/src/library/scala/collection/mutable/FlatHashTable.scala
@@ -265,7 +265,7 @@ trait FlatHashTable[A] extends FlatHashTable.HashUtils[A] {
val totalbuckets = totalSizeMapBuckets
var bucketidx = 0
var tableidx = 0
- var tbl = table
+ val tbl = table
var tableuntil = sizeMapBucketSize min tbl.length
while (bucketidx < totalbuckets) {
var currbucketsz = 0
diff --git a/src/library/scala/collection/mutable/GenIterable.scala.disabled b/src/library/scala/collection/mutable/GenIterable.scala.disabled
deleted file mode 100644
index 9acfccdae8..0000000000
--- a/src/library/scala/collection/mutable/GenIterable.scala.disabled
+++ /dev/null
@@ -1,37 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2003-2013, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-package scala.collection
-package mutable
-
-
-import generic._
-
-
-/** A base trait for iterable collections that can be mutated.
- *
- * $possiblyparinfo
- *
- * $iterableInfo
- */
-trait GenIterable[A] extends GenTraversable[A]
- with scala.collection.GenIterable[A]
- with scala.collection.GenIterableLike[A, GenIterable[A]]
-// with GenericTraversableTemplate[A, GenIterable]
-{
- def seq: Iterable[A]
- //override def companion: GenericCompanion[GenIterable] = GenIterable
-}
-
-
-// object GenIterable extends TraversableFactory[GenIterable] {
-// implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, GenIterable[A]] = ReusableCBF.asInstanceOf[GenericCanBuildFrom[A]]
-// def newBuilder[A]: Builder[A, GenIterable[A]] = Iterable.newBuilder
-// }
-
-
diff --git a/src/library/scala/collection/mutable/GenMap.scala.disabled b/src/library/scala/collection/mutable/GenMap.scala.disabled
deleted file mode 100644
index e4fd1dad64..0000000000
--- a/src/library/scala/collection/mutable/GenMap.scala.disabled
+++ /dev/null
@@ -1,40 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2003-2013, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-
-
-package scala.collection
-package mutable
-
-
-import generic._
-
-
-/** A base trait for maps that can be mutated.
- * $possiblyparinfo
- * $mapNote
- * $mapTags
- * @since 1.0
- * @author Matthias Zenger
- */
-trait GenMap[A, B]
-extends GenIterable[(A, B)]
- with scala.collection.GenMap[A, B]
- with scala.collection.GenMapLike[A, B, GenMap[A, B]]
-{
- def seq: Map[A, B]
-}
-
-
-// object GenMap extends MapFactory[GenMap] {
-// def empty[A, B]: Map[A, B] = Map.empty
-
-// /** $mapCanBuildFromInfo */
-// implicit def canBuildFrom[A, B]: CanBuildFrom[Coll, (A, B), GenMap[A, B]] = new MapCanBuildFrom[A, B]
-// }
-
diff --git a/src/library/scala/collection/mutable/GenSeq.scala.disabled b/src/library/scala/collection/mutable/GenSeq.scala.disabled
deleted file mode 100644
index ec904723a5..0000000000
--- a/src/library/scala/collection/mutable/GenSeq.scala.disabled
+++ /dev/null
@@ -1,44 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2003-2013, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-
-
-package scala.collection
-package mutable
-
-
-import generic._
-
-
-/** A subtrait of `collection.GenSeq` which represents sequences
- * that can be mutated.
- *
- * $possiblyparinfo
- *
- * $seqInfo
- *
- * The class adds an `update` method to `collection.Seq`.
- *
- * @define Coll `mutable.Seq`
- * @define coll mutable sequence
- */
-trait GenSeq[A] extends GenIterable[A]
- with scala.collection.GenSeq[A]
- with scala.collection.GenSeqLike[A, GenSeq[A]]
-// with GenericTraversableTemplate[A, GenSeq]
-{
- //override def companion: GenericCompanion[GenSeq] = GenSeq
- def seq: Seq[A]
-}
-
-
-// object GenSeq extends SeqFactory[GenSeq] {
-// implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, GenSeq[A]] = ReusableCBF.asInstanceOf[GenericCanBuildFrom[A]]
-// def newBuilder[A]: Builder[A, GenSeq[A]] = Seq.newBuilder
-// }
-
diff --git a/src/library/scala/collection/mutable/GenSet.scala.disabled b/src/library/scala/collection/mutable/GenSet.scala.disabled
deleted file mode 100644
index dec20e2a46..0000000000
--- a/src/library/scala/collection/mutable/GenSet.scala.disabled
+++ /dev/null
@@ -1,46 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2003-2013, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-
-
-package scala.collection
-package mutable
-
-
-
-import generic._
-
-
-/** A generic trait for mutable sets.
- *
- * $possiblyparinfo
- * $setNote
- * $setTags
- *
- * @since 1.0
- * @author Matthias Zenger
- * @define Coll `mutable.Set`
- * @define coll mutable set
- */
-trait GenSet[A] extends GenIterable[A]
- with Growable[A]
- with scala.collection.GenSet[A]
- with scala.collection.GenSetLike[A, GenSet[A]]
-// with GenericSetTemplate[A, GenSet]
-{
- //override def companion: GenericCompanion[GenSet] = GenSet
- def seq: Set[A]
-}
-
-
-// object GenSet extends TraversableFactory[GenSet] {
-// implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, GenSet[A]] = ReusableCBF.asInstanceOf[GenericCanBuildFrom[A]]
-// def newBuilder[A]: Builder[A, GenSet[A]] = Set.newBuilder
-// }
-
-
diff --git a/src/library/scala/collection/mutable/GenTraversable.scala.disabled b/src/library/scala/collection/mutable/GenTraversable.scala.disabled
deleted file mode 100644
index 2453e2ce87..0000000000
--- a/src/library/scala/collection/mutable/GenTraversable.scala.disabled
+++ /dev/null
@@ -1,38 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2003-2013, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-
-
-package scala.collection
-package mutable
-
-
-import generic._
-
-
-/** A trait for traversable collections that can be mutated.
- *
- * $possiblyparinfo
- *
- * $traversableInfo
- * @define mutability mutable
- */
-trait GenTraversable[A] extends scala.collection.GenTraversable[A]
- with scala.collection.GenTraversableLike[A, GenTraversable[A]]
-// with GenericTraversableTemplate[A, GenTraversable]
- with Mutable
-{
- def seq: Traversable[A]
- //override def companion: GenericCompanion[GenTraversable] = GenTraversable
-}
-
-// object GenTraversable extends TraversableFactory[GenTraversable] {
-// implicit def canBuildFrom[A] = ReusableCBF.asInstanceOf[GenericCanBuildFrom[A]]
-// def newBuilder[A] = Traversable.newBuilder
-// }
-
diff --git a/src/library/scala/collection/mutable/IndexedSeqLike.scala b/src/library/scala/collection/mutable/IndexedSeqLike.scala
index f0c31ec7fb..7b582eb5cb 100644
--- a/src/library/scala/collection/mutable/IndexedSeqLike.scala
+++ b/src/library/scala/collection/mutable/IndexedSeqLike.scala
@@ -6,11 +6,8 @@
** |/ **
\* */
-
-
package scala.collection
package mutable
-import generic._
/** A subtrait of scala.collection.IndexedSeq which represents sequences
* that can be mutated.
diff --git a/src/library/scala/collection/mutable/IndexedSeqOptimized.scala b/src/library/scala/collection/mutable/IndexedSeqOptimized.scala
index cb7e8efdc7..80b527a7b9 100755
--- a/src/library/scala/collection/mutable/IndexedSeqOptimized.scala
+++ b/src/library/scala/collection/mutable/IndexedSeqOptimized.scala
@@ -6,11 +6,8 @@
** |/ **
\* */
-
-
package scala.collection
package mutable
-import generic._
/** A subtrait of scala.collection.IndexedSeq which represents sequences
* that can be mutated.
diff --git a/src/library/scala/collection/mutable/IndexedSeqView.scala b/src/library/scala/collection/mutable/IndexedSeqView.scala
index cf5166eea8..a88ed8f123 100644
--- a/src/library/scala/collection/mutable/IndexedSeqView.scala
+++ b/src/library/scala/collection/mutable/IndexedSeqView.scala
@@ -82,8 +82,6 @@ self =>
protected override def newTakenWhile(p: A => Boolean): Transformed[A] = new { val pred = p } with AbstractTransformed[A] with TakenWhile
protected override def newReversed: Transformed[A] = new AbstractTransformed[A] with Reversed
- private implicit def asThis(xs: Transformed[A]): This = xs.asInstanceOf[This]
-
override def filter(p: A => Boolean): This = newFiltered(p)
override def init: This = newSliced(SliceInterval(0, self.length - 1))
override def drop(n: Int): This = newSliced(SliceInterval(n, self.length))
diff --git a/src/library/scala/collection/mutable/LinkedListLike.scala b/src/library/scala/collection/mutable/LinkedListLike.scala
index 4f63ede7ca..b3470ed3cd 100644
--- a/src/library/scala/collection/mutable/LinkedListLike.scala
+++ b/src/library/scala/collection/mutable/LinkedListLike.scala
@@ -6,12 +6,9 @@
** |/ **
\* */
-
-
package scala.collection
package mutable
-import generic._
import scala.annotation.tailrec
/** This extensible class may be used as a basis for implementing linked
diff --git a/src/library/scala/collection/mutable/ListBuffer.scala b/src/library/scala/collection/mutable/ListBuffer.scala
index 67af4a6bd6..b7b487964c 100644
--- a/src/library/scala/collection/mutable/ListBuffer.scala
+++ b/src/library/scala/collection/mutable/ListBuffer.scala
@@ -56,12 +56,18 @@ final class ListBuffer[A]
import scala.collection.Traversable
import scala.collection.immutable.ListSerializeEnd
+ /** Expected invariants:
+ * If start.isEmpty, last0 == null
+ * If start.nonEmpty, last0 != null
+ * If len == 0, start.isEmpty
+ * If len > 0, start.nonEmpty
+ */
private var start: List[A] = Nil
private var last0: ::[A] = _
private var exported: Boolean = false
private var len = 0
- protected def underlying: immutable.Seq[A] = start
+ protected def underlying: List[A] = start
private def writeObject(out: ObjectOutputStream) {
// write start
@@ -160,7 +166,7 @@ final class ListBuffer[A]
*/
def += (x: A): this.type = {
if (exported) copy()
- if (start.isEmpty) {
+ if (isEmpty) {
last0 = new :: (x, Nil)
start = last0
} else {
@@ -182,6 +188,7 @@ final class ListBuffer[A]
*/
def clear() {
start = Nil
+ last0 = null
exported = false
len = 0
}
@@ -195,7 +202,7 @@ final class ListBuffer[A]
def +=: (x: A): this.type = {
if (exported) copy()
val newElem = new :: (x, start)
- if (start.isEmpty) last0 = newElem
+ if (isEmpty) last0 = newElem
start = newElem
len += 1
this
@@ -238,6 +245,15 @@ final class ListBuffer[A]
}
}
+ /** Reduce the length of the buffer, and null out last0
+ * if this reduces the length to 0.
+ */
+ private def reduceLengthBy(num: Int) {
+ len -= num
+ if (len <= 0) // obviously shouldn't be < 0, but still better not to leak
+ last0 = null
+ }
+
/** Removes a given number of elements on a given index position. May take
* time linear in the buffer size.
*
@@ -253,7 +269,6 @@ final class ListBuffer[A]
if (exported) copy()
val n1 = n max 0
val count1 = count min (len - n1)
- var old = start.head
if (n1 == 0) {
var c = count1
while (c > 0) {
@@ -274,7 +289,7 @@ final class ListBuffer[A]
c -= 1
}
}
- len -= count1
+ reduceLengthBy(count1)
}
// Implementation of abstract method in Builder
@@ -285,7 +300,7 @@ final class ListBuffer[A]
* copied lazily, the first time it is mutated.
*/
override def toList: List[A] = {
- exported = !start.isEmpty
+ exported = !isEmpty
start
}
@@ -296,7 +311,7 @@ final class ListBuffer[A]
* @param xs the list to which elements are prepended
*/
def prependToList(xs: List[A]): List[A] = {
- if (start.isEmpty) xs
+ if (isEmpty) xs
else {
if (exported) copy()
last0.tl = xs
@@ -331,7 +346,7 @@ final class ListBuffer[A]
if (last0 eq cursor.tail) last0 = cursor.asInstanceOf[::[A]]
cursor.asInstanceOf[::[A]].tl = cursor.tail.tail
}
- len -= 1
+ reduceLengthBy(1)
old
}
@@ -343,11 +358,12 @@ final class ListBuffer[A]
*/
override def -= (elem: A): this.type = {
if (exported) copy()
- if (start.isEmpty) {}
+ if (isEmpty) {}
else if (start.head == elem) {
start = start.tail
- len -= 1
- } else {
+ reduceLengthBy(1)
+ }
+ else {
var cursor = start
while (!cursor.tail.isEmpty && cursor.tail.head != elem) {
cursor = cursor.tail
@@ -357,7 +373,7 @@ final class ListBuffer[A]
if (z.tl == last0)
last0 = z
z.tl = cursor.tail.tail
- len -= 1
+ reduceLengthBy(1)
}
}
this
@@ -397,6 +413,7 @@ final class ListBuffer[A]
/** Copy contents of this buffer */
private def copy() {
+ if (isEmpty) return
var cursor = start
val limit = last0.tail
clear()
diff --git a/src/library/scala/collection/mutable/MapLike.scala b/src/library/scala/collection/mutable/MapLike.scala
index a53aa3b76a..49d1e039f0 100644
--- a/src/library/scala/collection/mutable/MapLike.scala
+++ b/src/library/scala/collection/mutable/MapLike.scala
@@ -11,7 +11,7 @@ package scala.collection
package mutable
import generic._
-import scala.annotation.{migration, bridge}
+import scala.annotation.migration
import parallel.mutable.ParMap
/** A template trait for mutable maps.
@@ -50,8 +50,6 @@ trait MapLike[A, B, +This <: MapLike[A, B, This] with Map[A, B]]
with Parallelizable[(A, B), ParMap[A, B]]
{ self =>
- import scala.collection.Traversable
-
/** A common implementation of `newBuilder` for all mutable maps
* in terms of `empty`.
*
diff --git a/src/library/scala/collection/mutable/SeqLike.scala b/src/library/scala/collection/mutable/SeqLike.scala
index 447100cf4c..ddfde536c9 100644
--- a/src/library/scala/collection/mutable/SeqLike.scala
+++ b/src/library/scala/collection/mutable/SeqLike.scala
@@ -9,7 +9,6 @@
package scala.collection
package mutable
-import generic._
import parallel.mutable.ParSeq
/** A template trait for mutable sequences of type `mutable.Seq[A]`.
diff --git a/src/library/scala/collection/mutable/SetBuilder.scala b/src/library/scala/collection/mutable/SetBuilder.scala
index 42fd651d41..40f0b8932c 100644
--- a/src/library/scala/collection/mutable/SetBuilder.scala
+++ b/src/library/scala/collection/mutable/SetBuilder.scala
@@ -6,12 +6,9 @@
** |/ **
\* */
-
package scala.collection
package mutable
-import generic._
-
/** The canonical builder for mutable Sets.
*
* @tparam A The type of the elements that will be contained in this set.
diff --git a/src/library/scala/collection/mutable/SetLike.scala b/src/library/scala/collection/mutable/SetLike.scala
index 01f87447ae..4a907e7dc4 100644
--- a/src/library/scala/collection/mutable/SetLike.scala
+++ b/src/library/scala/collection/mutable/SetLike.scala
@@ -11,7 +11,7 @@ package mutable
import generic._
import script._
-import scala.annotation.{ migration, bridge }
+import scala.annotation.migration
import parallel.mutable.ParSet
/** A template trait for mutable sets of type `mutable.Set[A]`.
diff --git a/src/library/scala/collection/mutable/SynchronizedPriorityQueue.scala b/src/library/scala/collection/mutable/SynchronizedPriorityQueue.scala
index 8dfc40b9c8..0065d4c556 100644
--- a/src/library/scala/collection/mutable/SynchronizedPriorityQueue.scala
+++ b/src/library/scala/collection/mutable/SynchronizedPriorityQueue.scala
@@ -73,14 +73,6 @@ class SynchronizedPriorityQueue[A](implicit ord: Ordering[A]) extends PriorityQu
*/
override def head: A = synchronized { super.head }
- /** Returns the element with the highest priority in the queue,
- * or throws an error if there is no element contained in the queue.
- *
- * @return the element with the highest priority.
- */
- @deprecated("Use `head` instead.", "2.9.0")
- override def max: A = synchronized { super.max }
-
/** Removes all elements from the queue. After this operation is completed,
* the queue will be empty.
*/
diff --git a/src/library/scala/collection/mutable/SynchronizedQueue.scala b/src/library/scala/collection/mutable/SynchronizedQueue.scala
index 9559d5eaa5..c5f133eec7 100644
--- a/src/library/scala/collection/mutable/SynchronizedQueue.scala
+++ b/src/library/scala/collection/mutable/SynchronizedQueue.scala
@@ -25,8 +25,6 @@ package mutable
* @define coll synchronized queue
*/
class SynchronizedQueue[A] extends Queue[A] {
- import scala.collection.Traversable
-
/** Checks if the queue is empty.
*
* @return true, iff there is no element in the queue.
diff --git a/src/library/scala/collection/mutable/SynchronizedSet.scala b/src/library/scala/collection/mutable/SynchronizedSet.scala
index e4a44993ff..bc9873880c 100644
--- a/src/library/scala/collection/mutable/SynchronizedSet.scala
+++ b/src/library/scala/collection/mutable/SynchronizedSet.scala
@@ -24,8 +24,6 @@ import script._
* @define coll synchronized set
*/
trait SynchronizedSet[A] extends Set[A] {
- import scala.collection.Traversable
-
abstract override def size: Int = synchronized {
super.size
}
diff --git a/src/library/scala/collection/mutable/WrappedArrayBuilder.scala b/src/library/scala/collection/mutable/WrappedArrayBuilder.scala
index 7e0210311c..55328a5d3d 100644
--- a/src/library/scala/collection/mutable/WrappedArrayBuilder.scala
+++ b/src/library/scala/collection/mutable/WrappedArrayBuilder.scala
@@ -11,7 +11,6 @@
package scala.collection
package mutable
-import generic._
import scala.reflect.ClassTag
import scala.runtime.ScalaRunTime._
diff --git a/src/library/scala/collection/parallel/ParIterable.scala b/src/library/scala/collection/parallel/ParIterable.scala
index 2b24c88139..f170b944eb 100644
--- a/src/library/scala/collection/parallel/ParIterable.scala
+++ b/src/library/scala/collection/parallel/ParIterable.scala
@@ -11,7 +11,6 @@ package scala.collection.parallel
import scala.collection.GenIterable
import scala.collection.generic._
import scala.collection.parallel.mutable.ParArrayCombiner
-import scala.collection.parallel.mutable.ParArray
/** A template trait for parallel iterable collections.
*
diff --git a/src/library/scala/collection/parallel/ParIterableLike.scala b/src/library/scala/collection/parallel/ParIterableLike.scala
index 0f06ff37af..d77e5a6744 100644
--- a/src/library/scala/collection/parallel/ParIterableLike.scala
+++ b/src/library/scala/collection/parallel/ParIterableLike.scala
@@ -171,9 +171,9 @@ self: ParIterableLike[T, Repr, Sequential] =>
/** The task support object which is responsible for scheduling and
* load-balancing tasks to processors.
- *
+ *
* @see [[scala.collection.parallel.TaskSupport]]
- */
+ */
def tasksupport = {
val ts = _tasksupport
if (ts eq null) {
@@ -188,18 +188,18 @@ self: ParIterableLike[T, Repr, Sequential] =>
* A task support object can be changed in a parallel collection after it
* has been created, but only during a quiescent period, i.e. while there
* are no concurrent invocations to parallel collection methods.
- *
- * Here is a way to change the task support of a parallel collection:
- *
- * {{{
- * import scala.collection.parallel._
- * val pc = mutable.ParArray(1, 2, 3)
- * pc.tasksupport = new ForkJoinTaskSupport(
- * new scala.concurrent.forkjoin.ForkJoinPool(2))
- * }}}
+ *
+ * Here is a way to change the task support of a parallel collection:
+ *
+ * {{{
+ * import scala.collection.parallel._
+ * val pc = mutable.ParArray(1, 2, 3)
+ * pc.tasksupport = new ForkJoinTaskSupport(
+ * new scala.concurrent.forkjoin.ForkJoinPool(2))
+ * }}}
*
* @see [[scala.collection.parallel.TaskSupport]]
- */
+ */
def tasksupport_=(ts: TaskSupport) = _tasksupport = ts
def seq: Sequential
@@ -433,12 +433,13 @@ self: ParIterableLike[T, Repr, Sequential] =>
* @tparam S the type of accumulated results
* @param z the initial value for the accumulated result of the partition - this
* will typically be the neutral element for the `seqop` operator (e.g.
- * `Nil` for list concatenation or `0` for summation)
+ * `Nil` for list concatenation or `0` for summation) and may be evaluated
+ * more than once
* @param seqop an operator used to accumulate results within a partition
* @param combop an associative operator used to combine results from different partitions
*/
- def aggregate[S](z: S)(seqop: (S, T) => S, combop: (S, S) => S): S = {
- tasksupport.executeAndWaitResult(new Aggregate(z, seqop, combop, splitter))
+ def aggregate[S](z: =>S)(seqop: (S, T) => S, combop: (S, S) => S): S = {
+ tasksupport.executeAndWaitResult(new Aggregate(() => z, seqop, combop, splitter))
}
def foldLeft[S](z: S)(op: (S, T) => S): S = seq.foldLeft(z)(op)
@@ -877,13 +878,13 @@ self: ParIterableLike[T, Repr, Sequential] =>
override def toSet[U >: T]: immutable.ParSet[U] = toParCollection[U, immutable.ParSet[U]](() => immutable.ParSet.newCombiner[U])
override def toMap[K, V](implicit ev: T <:< (K, V)): immutable.ParMap[K, V] = toParMap[K, V, immutable.ParMap[K, V]](() => immutable.ParMap.newCombiner[K, V])
-
+
override def toVector: Vector[T] = to[Vector]
override def to[Col[_]](implicit cbf: CanBuildFrom[Nothing, T, Col[T @uncheckedVariance]]): Col[T @uncheckedVariance] = if (cbf().isCombiner) {
toParCollection[T, Col[T]](() => cbf().asCombiner)
} else seq.to(cbf)
-
+
/* tasks */
protected trait StrictSplitterCheckTask[R, Tp] extends Task[R, Tp] {
@@ -935,8 +936,8 @@ self: ParIterableLike[T, Repr, Sequential] =>
(f: First, s: Second)
extends Composite[FR, SR, R, First, Second](f, s) {
def leaf(prevr: Option[R]) = {
- tasksupport.executeAndWaitResult(ft)
- tasksupport.executeAndWaitResult(st)
+ tasksupport.executeAndWaitResult(ft) : Any
+ tasksupport.executeAndWaitResult(st) : Any
mergeSubtasks
}
}
@@ -946,8 +947,8 @@ self: ParIterableLike[T, Repr, Sequential] =>
(f: First, s: Second)
extends Composite[FR, SR, R, First, Second](f, s) {
def leaf(prevr: Option[R]) = {
- val ftfuture = tasksupport.execute(ft)
- tasksupport.executeAndWaitResult(st)
+ val ftfuture: () => Any = tasksupport.execute(ft)
+ tasksupport.executeAndWaitResult(st) : Any
ftfuture()
mergeSubtasks
}
@@ -1005,10 +1006,10 @@ self: ParIterableLike[T, Repr, Sequential] =>
override def merge(that: Fold[U]) = result = op(result, that.result)
}
- protected[this] class Aggregate[S](z: S, seqop: (S, T) => S, combop: (S, S) => S, protected[this] val pit: IterableSplitter[T])
+ protected[this] class Aggregate[S](z: () => S, seqop: (S, T) => S, combop: (S, S) => S, protected[this] val pit: IterableSplitter[T])
extends Accessor[S, Aggregate[S]] {
@volatile var result: S = null.asInstanceOf[S]
- def leaf(prevr: Option[S]) = result = pit.foldLeft(z)(seqop)
+ def leaf(prevr: Option[S]) = result = pit.foldLeft(z())(seqop)
protected[this] def newSubtask(p: IterableSplitter[T]) = new Aggregate(z, seqop, combop, p)
override def merge(that: Aggregate[S]) = result = combop(result, that.result)
}
@@ -1504,31 +1505,3 @@ self: ParIterableLike[T, Repr, Sequential] =>
})
}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/library/scala/collection/parallel/ParSeq.scala b/src/library/scala/collection/parallel/ParSeq.scala
index b905d1d41f..dee523ad89 100644
--- a/src/library/scala/collection/parallel/ParSeq.scala
+++ b/src/library/scala/collection/parallel/ParSeq.scala
@@ -18,9 +18,6 @@ import scala.collection.generic.ParFactory
import scala.collection.generic.CanCombineFrom
import scala.collection.GenSeq
import scala.collection.parallel.mutable.ParArrayCombiner
-import scala.collection.parallel.mutable.ParArray
-
-
/** A template trait for parallel sequences.
*
diff --git a/src/library/scala/collection/parallel/ParSeqView.scala b/src/library/scala/collection/parallel/ParSeqView.scala
index 3e3c497352..9acc4b0b73 100644
--- a/src/library/scala/collection/parallel/ParSeqView.scala
+++ b/src/library/scala/collection/parallel/ParSeqView.scala
@@ -6,10 +6,9 @@
** |/ **
\* */
-
package scala.collection.parallel
-import scala.collection.{ TraversableView, SeqView, Parallel, Iterator }
+import scala.collection.{ SeqView, Parallel, Iterator }
import scala.collection.generic.CanCombineFrom
/** A template view of a non-strict view of a parallel sequence.
diff --git a/src/library/scala/collection/parallel/ParSet.scala b/src/library/scala/collection/parallel/ParSet.scala
index 6e5e9b4387..bc6d5c6245 100644
--- a/src/library/scala/collection/parallel/ParSet.scala
+++ b/src/library/scala/collection/parallel/ParSet.scala
@@ -17,14 +17,8 @@ package scala.collection.parallel
import scala.collection.Set
import scala.collection.GenSet
-import scala.collection.mutable.Builder
import scala.collection.generic._
-
-
-
-
-
/** A template trait for parallel sets.
*
* $sideeffects
diff --git a/src/library/scala/collection/parallel/ParSetLike.scala b/src/library/scala/collection/parallel/ParSetLike.scala
index c80b5ded26..20a5f693ce 100644
--- a/src/library/scala/collection/parallel/ParSetLike.scala
+++ b/src/library/scala/collection/parallel/ParSetLike.scala
@@ -15,14 +15,6 @@ import scala.collection.SetLike
import scala.collection.GenSetLike
import scala.collection.GenSet
import scala.collection.Set
-import scala.collection.mutable.Builder
-
-
-
-
-
-
-
/** A template trait for parallel sets. This trait is mixed in with concrete
* parallel sets to override the representation type.
diff --git a/src/library/scala/collection/parallel/RemainsIterator.scala b/src/library/scala/collection/parallel/RemainsIterator.scala
index 3150b0d763..732ebc3709 100644
--- a/src/library/scala/collection/parallel/RemainsIterator.scala
+++ b/src/library/scala/collection/parallel/RemainsIterator.scala
@@ -123,9 +123,10 @@ private[collection] trait AugmentedIterableIterator[+T] extends RemainsIterator[
def collect2combiner[S, That](pf: PartialFunction[T, S], cb: Combiner[S, That]): Combiner[S, That] = {
//val cb = pbf(repr)
+ val runWith = pf.runWith(cb += _)
while (hasNext) {
val curr = next
- if (pf.isDefinedAt(curr)) cb += pf(curr)
+ runWith(curr)
}
cb
}
diff --git a/src/library/scala/collection/parallel/Tasks.scala b/src/library/scala/collection/parallel/Tasks.scala
index cec9e294c1..12f8012a5b 100644
--- a/src/library/scala/collection/parallel/Tasks.scala
+++ b/src/library/scala/collection/parallel/Tasks.scala
@@ -66,20 +66,10 @@ trait Task[R, +Tp] {
private[parallel] def tryMerge(t: Tp @uncheckedVariance) {
val that = t.asInstanceOf[Task[R, Tp]]
- val local = result // ensure that any effects of modifying `result` are detected
- // checkMerge(that)
if (this.throwable == null && that.throwable == null) merge(t)
mergeThrowables(that)
}
- private def checkMerge(that: Task[R, Tp] @uncheckedVariance) {
- if (this.throwable == null && that.throwable == null && (this.result == null || that.result == null)) {
- println("This: " + this + ", thr=" + this.throwable + "; merged with " + that + ", thr=" + that.throwable)
- } else if (this.throwable != null || that.throwable != null) {
- println("merging this: " + this + " with thr: " + this.throwable + " with " + that + ", thr=" + that.throwable)
- }
- }
-
private[parallel] def mergeThrowables(that: Task[_, _]) {
if (this.throwable != null && that.throwable != null) {
// merge exceptions, since there were multiple exceptions
@@ -176,7 +166,6 @@ trait AdaptiveWorkStealingTasks extends Tasks {
while (last.next != null) {
// val lastresult = Option(last.body.result)
- val beforelast = last
last = last.next
if (last.tryCancel()) {
// println("Done with " + beforelast.body + ", next direct is " + last.body)
diff --git a/src/library/scala/collection/parallel/immutable/ParIterable.scala b/src/library/scala/collection/parallel/immutable/ParIterable.scala
index 142f07ff26..ec07e44c4d 100644
--- a/src/library/scala/collection/parallel/immutable/ParIterable.scala
+++ b/src/library/scala/collection/parallel/immutable/ParIterable.scala
@@ -15,8 +15,6 @@ import scala.collection.generic._
import scala.collection.parallel.ParIterableLike
import scala.collection.parallel.Combiner
-import scala.collection.GenIterable
-
/** A template trait for immutable parallel iterable collections.
*
diff --git a/src/library/scala/collection/parallel/immutable/ParNumericRange.scala.disabled b/src/library/scala/collection/parallel/immutable/ParNumericRange.scala.disabled
deleted file mode 100644
index 5f9c9c3d3d..0000000000
--- a/src/library/scala/collection/parallel/immutable/ParNumericRange.scala.disabled
+++ /dev/null
@@ -1,128 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2003-2013, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-
-package scala.collection.parallel.immutable
-
-
-
-import scala.collection.immutable.NumericRange
-import scala.collection.parallel.Combiner
-import scala.collection.generic.CanCombineFrom
-import scala.collection.parallel.ParIterableIterator
-
-
-
-/** Parallel ranges for numeric types.
- *
- * $paralleliterableinfo
- *
- * $sideeffects
- *
- * @param range the sequential range this parallel range was obtained from
- *
- * @author Aleksandar Prokopec
- * @since 2.9
- *
- * @define Coll `immutable.ParRange`
- * @define coll immutable parallel range
- */
-@SerialVersionUID(1L)
-class ParNumericRange[T](val range: NumericRange[T])(implicit num: Integral[T])
-extends ParSeq[T]
- with Serializable
-{
-self =>
-
- def seq = range
-
- @inline final def length = range.length
-
- @inline final def apply(idx: Int) = range.apply(idx);
-
- def parallelIterator = new ParNumericRangeIterator with SCPI
-
- type SCPI = SignalContextPassingIterator[ParNumericRangeIterator]
-
- class ParNumericRangeIterator(range: NumericRange[T] = self.range, num: Integral[T] = self.num)
- extends ParIterator {
- me: SignalContextPassingIterator[ParNumericRangeIterator] =>
- override def toString = "ParNumericRangeIterator(over: " + range + ")"
- private var ind = 0
- private val len = range.length
-
- final def remaining = len - ind
-
- final def hasNext = ind < len
-
- final def next = if (hasNext) {
- val r = range.apply(ind)
- ind += 1
- r
- } else Iterator.empty.next
-
- private def rangeleft: NumericRange[T] = range.drop(ind)
-
- def dup = new ParNumericRangeIterator(rangeleft) with SCPI
-
- def split = {
- val rleft = rangeleft
- val elemleft = rleft.length
- if (elemleft < 2) Seq(new ParNumericRangeIterator(rleft) with SCPI)
- else Seq(
- new ParNumericRangeIterator(rleft.take(elemleft / 2)) with SCPI,
- new ParNumericRangeIterator(rleft.drop(elemleft / 2)) with SCPI
- )
- }
-
- def psplit(sizes: Int*) = {
- var rleft = rangeleft
- for (sz <- sizes) yield {
- val fronttaken = rleft.take(sz)
- rleft = rleft.drop(sz)
- new ParNumericRangeIterator(fronttaken) with SCPI
- }
- }
-
- /* accessors */
-
- override def foreach[U](f: T => U): Unit = {
- rangeleft.foreach(f)
- ind = len
- }
-
- override def reduce[U >: T](op: (U, U) => U): U = {
- val r = rangeleft.reduceLeft(op)
- ind = len
- r
- }
-
- /* transformers */
-
- override def map2combiner[S, That](f: T => S, cb: Combiner[S, That]): Combiner[S, That] = {
- while (hasNext) {
- cb += f(next)
- }
- cb
- }
- }
-
-}
-
-
-object ParNumericRange {
- def apply[T](start: T, end: T, step: T, inclusive: Boolean)(implicit num: Integral[T]) = new ParNumericRange[T](
- if (inclusive) NumericRange.inclusive(start, end, step)(num)
- else NumericRange.apply(start, end, step)(num)
- )
-}
-
-
-
-
-
diff --git a/src/library/scala/collection/parallel/immutable/ParSeq.scala b/src/library/scala/collection/parallel/immutable/ParSeq.scala
index aa19307387..b54a5f0205 100644
--- a/src/library/scala/collection/parallel/immutable/ParSeq.scala
+++ b/src/library/scala/collection/parallel/immutable/ParSeq.scala
@@ -18,9 +18,6 @@ import scala.collection.generic.CanCombineFrom
import scala.collection.generic.ParFactory
import scala.collection.parallel.ParSeqLike
import scala.collection.parallel.Combiner
-import scala.collection.GenSeq
-
-
/** An immutable variant of `ParSeq`.
*
diff --git a/src/library/scala/collection/parallel/immutable/ParSet.scala b/src/library/scala/collection/parallel/immutable/ParSet.scala
index 3622377a55..aba8486ab5 100644
--- a/src/library/scala/collection/parallel/immutable/ParSet.scala
+++ b/src/library/scala/collection/parallel/immutable/ParSet.scala
@@ -9,7 +9,6 @@
package scala.collection
package parallel.immutable
-import scala.collection.GenSet
import scala.collection.generic._
import scala.collection.parallel.ParSetLike
import scala.collection.parallel.Combiner
diff --git a/src/library/scala/collection/parallel/mutable/ParArray.scala b/src/library/scala/collection/parallel/mutable/ParArray.scala
index e4c8e5fae2..db4a59f6ba 100644
--- a/src/library/scala/collection/parallel/mutable/ParArray.scala
+++ b/src/library/scala/collection/parallel/mutable/ParArray.scala
@@ -181,10 +181,10 @@ self =>
override def fold[U >: T](z: U)(op: (U, U) => U): U = foldLeft[U](z)(op)
- override def aggregate[S](z: S)(seqop: (S, T) => S, combop: (S, S) => S): S = foldLeft[S](z)(seqop)
+ override def aggregate[S](z: =>S)(seqop: (S, T) => S, combop: (S, S) => S): S = foldLeft[S](z)(seqop)
override def sum[U >: T](implicit num: Numeric[U]): U = {
- var s = sum_quick(num, arr, until, i, num.zero)
+ val s = sum_quick(num, arr, until, i, num.zero)
i = until
s
}
@@ -200,7 +200,7 @@ self =>
}
override def product[U >: T](implicit num: Numeric[U]): U = {
- var p = product_quick(num, arr, until, i, num.one)
+ val p = product_quick(num, arr, until, i, num.one)
i = until
p
}
@@ -405,9 +405,10 @@ self =>
private def collect2combiner_quick[S, That](pf: PartialFunction[T, S], a: Array[Any], cb: Builder[S, That], ntil: Int, from: Int) {
var j = from
+ val runWith = pf.runWith(b => cb += b)
while (j < ntil) {
val curr = a(j).asInstanceOf[T]
- if (pf.isDefinedAt(curr)) cb += pf(curr)
+ runWith(curr)
j += 1
}
}
@@ -432,7 +433,7 @@ self =>
private def filter2combiner_quick[U >: T, This](pred: T => Boolean, cb: Builder[U, This], a: Array[Any], ntil: Int, from: Int) {
var j = i
while(j < ntil) {
- var curr = a(j).asInstanceOf[T]
+ val curr = a(j).asInstanceOf[T]
if (pred(curr)) cb += curr
j += 1
}
@@ -447,7 +448,7 @@ self =>
private def filterNot2combiner_quick[U >: T, This](pred: T => Boolean, cb: Builder[U, This], a: Array[Any], ntil: Int, from: Int) {
var j = i
while(j < ntil) {
- var curr = a(j).asInstanceOf[T]
+ val curr = a(j).asInstanceOf[T]
if (!pred(curr)) cb += curr
j += 1
}
@@ -579,8 +580,6 @@ self =>
/* operations */
- private def asTask[R, Tp](t: Any) = t.asInstanceOf[Task[R, Tp]]
-
private def buildsArray[S, That](c: Builder[S, That]) = c.isInstanceOf[ParArrayCombiner[_]]
override def map[S, That](f: T => S)(implicit bf: CanBuildFrom[ParArray[T], S, That]) = if (buildsArray(bf(repr))) {
diff --git a/src/library/scala/collection/parallel/mutable/ParFlatHashTable.scala b/src/library/scala/collection/parallel/mutable/ParFlatHashTable.scala
index 8bc108a738..b151e45d65 100644
--- a/src/library/scala/collection/parallel/mutable/ParFlatHashTable.scala
+++ b/src/library/scala/collection/parallel/mutable/ParFlatHashTable.scala
@@ -38,10 +38,6 @@ trait ParFlatHashTable[T] extends scala.collection.mutable.FlatHashTable[T] {
}
}
- private def checkbounds() = if (idx >= itertable.length) {
- throw new IndexOutOfBoundsException(idx.toString)
- }
-
def newIterator(index: Int, until: Int, totalsize: Int): IterableSplitter[T]
def remaining = totalsize - traversed
@@ -102,11 +98,5 @@ trait ParFlatHashTable[T] extends scala.collection.mutable.FlatHashTable[T] {
}
count
}
-
- private def check() = if (table.slice(idx, until).count(_ != null) != remaining) {
- println("Invariant broken: " + debugInformation)
- assert(false)
- }
}
-
}
diff --git a/src/library/scala/collection/parallel/mutable/ParHashMap.scala b/src/library/scala/collection/parallel/mutable/ParHashMap.scala
index 11588e555b..541d75290b 100644
--- a/src/library/scala/collection/parallel/mutable/ParHashMap.scala
+++ b/src/library/scala/collection/parallel/mutable/ParHashMap.scala
@@ -166,9 +166,8 @@ private[mutable] abstract class ParHashMapCombiner[K, V](private val tableLoadFa
extends scala.collection.parallel.BucketCombiner[(K, V), ParHashMap[K, V], DefaultEntry[K, V], ParHashMapCombiner[K, V]](ParHashMapCombiner.numblocks)
with scala.collection.mutable.HashTable.HashUtils[K]
{
- private var mask = ParHashMapCombiner.discriminantmask
- private var nonmasklen = ParHashMapCombiner.nonmasklength
- private var seedvalue = 27
+ private val nonmasklen = ParHashMapCombiner.nonmasklength
+ private val seedvalue = 27
def +=(elem: (K, V)) = {
sz += 1
@@ -232,8 +231,7 @@ extends scala.collection.parallel.BucketCombiner[(K, V), ParHashMap[K, V], Defau
def setSize(sz: Int) = tableSize = sz
def insertEntry(/*block: Int, */e: DefaultEntry[K, V]) = {
var h = index(elemHashCode(e.key))
- // assertCorrectBlock(h, block)
- var olde = table(h).asInstanceOf[DefaultEntry[K, V]]
+ val olde = table(h).asInstanceOf[DefaultEntry[K, V]]
// check if key already exists
var ce = olde
@@ -252,13 +250,6 @@ extends scala.collection.parallel.BucketCombiner[(K, V), ParHashMap[K, V], Defau
true
} else false
}
- private def assertCorrectBlock(h: Int, block: Int) {
- val blocksize = table.length / (1 << ParHashMapCombiner.discriminantbits)
- if (!(h >= block * blocksize && h < (block + 1) * blocksize)) {
- println("trying to put " + h + " into block no.: " + block + ", range: [" + block * blocksize + ", " + (block + 1) * blocksize + ">")
- assert(h >= block * blocksize && h < (block + 1) * blocksize)
- }
- }
protected def createNewEntry[X](key: K, x: X) = ???
}
@@ -288,7 +279,6 @@ extends scala.collection.parallel.BucketCombiner[(K, V), ParHashMap[K, V], Defau
val chunksz = unrolled.size
while (i < chunksz) {
val elem = chunkarr(i)
- // assertCorrectBlock(block, elem.key)
if (t.insertEntry(elem)) insertcount += 1
i += 1
}
@@ -297,13 +287,6 @@ extends scala.collection.parallel.BucketCombiner[(K, V), ParHashMap[K, V], Defau
}
insertcount
}
- private def assertCorrectBlock(block: Int, k: K) {
- val hc = improve(elemHashCode(k), seedvalue)
- if ((hc >>> nonmasklen) != block) {
- println(hc + " goes to " + (hc >>> nonmasklen) + ", while expected block is " + block)
- assert((hc >>> nonmasklen) == block)
- }
- }
def split = {
val fp = howmany / 2
List(new FillBlocks(buckets, table, offset, fp), new FillBlocks(buckets, table, offset + fp, howmany - fp))
diff --git a/src/library/scala/collection/parallel/mutable/ParHashSet.scala b/src/library/scala/collection/parallel/mutable/ParHashSet.scala
index 3b1278f3be..f1377fb0a7 100644
--- a/src/library/scala/collection/parallel/mutable/ParHashSet.scala
+++ b/src/library/scala/collection/parallel/mutable/ParHashSet.scala
@@ -120,9 +120,8 @@ private[mutable] abstract class ParHashSetCombiner[T](private val tableLoadFacto
extends scala.collection.parallel.BucketCombiner[T, ParHashSet[T], Any, ParHashSetCombiner[T]](ParHashSetCombiner.numblocks)
with scala.collection.mutable.FlatHashTable.HashUtils[T] {
//self: EnvironmentPassingCombiner[T, ParHashSet[T]] =>
- private var mask = ParHashSetCombiner.discriminantmask
- private var nonmasklen = ParHashSetCombiner.nonmasklength
- private var seedvalue = 27
+ private val nonmasklen = ParHashSetCombiner.nonmasklength
+ private val seedvalue = 27
def +=(elem: T) = {
sz += 1
@@ -264,12 +263,12 @@ with scala.collection.mutable.FlatHashTable.HashUtils[T] {
(elemsIn + leftoversIn, elemsLeft concat leftoversLeft)
}
private def insertAll(atPos: Int, beforePos: Int, elems: UnrolledBuffer[Any]): (Int, UnrolledBuffer[Any]) = {
- var leftovers = new UnrolledBuffer[Any]
+ val leftovers = new UnrolledBuffer[Any]
var inserted = 0
var unrolled = elems.headPtr
var i = 0
- var t = table
+ val t = table
while (unrolled ne null) {
val chunkarr = unrolled.array
val chunksz = unrolled.size
diff --git a/src/library/scala/collection/parallel/mutable/ParHashTable.scala b/src/library/scala/collection/parallel/mutable/ParHashTable.scala
index 66ddef6a1e..5aa1dba17c 100644
--- a/src/library/scala/collection/parallel/mutable/ParHashTable.scala
+++ b/src/library/scala/collection/parallel/mutable/ParHashTable.scala
@@ -110,7 +110,7 @@ trait ParHashTable[K, Entry >: Null <: HashEntry[K, Entry]] extends scala.collec
} else Seq(this.asInstanceOf[IterRepr])
private def convertToArrayBuffer(chainhead: Entry): mutable.ArrayBuffer[T] = {
- var buff = mutable.ArrayBuffer[Entry]()
+ val buff = mutable.ArrayBuffer[Entry]()
var curr = chainhead
while (curr ne null) {
buff += curr
diff --git a/src/library/scala/collection/parallel/mutable/ParIterable.scala b/src/library/scala/collection/parallel/mutable/ParIterable.scala
index 7090c510a0..d76e4b1745 100644
--- a/src/library/scala/collection/parallel/mutable/ParIterable.scala
+++ b/src/library/scala/collection/parallel/mutable/ParIterable.scala
@@ -12,8 +12,6 @@ package scala.collection.parallel.mutable
import scala.collection.generic._
import scala.collection.parallel.ParIterableLike
import scala.collection.parallel.Combiner
-import scala.collection.GenIterable
-
/** A template trait for mutable parallel iterable collections.
*
diff --git a/src/library/scala/collection/parallel/mutable/ParMapLike.scala b/src/library/scala/collection/parallel/mutable/ParMapLike.scala
index cdcfc59f8f..08bc706c8a 100644
--- a/src/library/scala/collection/parallel/mutable/ParMapLike.scala
+++ b/src/library/scala/collection/parallel/mutable/ParMapLike.scala
@@ -12,13 +12,10 @@ package mutable
import scala.collection.generic._
-import scala.collection.mutable.Builder
import scala.collection.mutable.Cloneable
import scala.collection.generic.Growable
import scala.collection.generic.Shrinkable
-
-
/** A template trait for mutable parallel maps. This trait is to be mixed in
* with concrete parallel maps to override the representation type.
*
diff --git a/src/library/scala/collection/parallel/mutable/ParSeq.scala b/src/library/scala/collection/parallel/mutable/ParSeq.scala
index 95a4d4a13a..8a55ab83f1 100644
--- a/src/library/scala/collection/parallel/mutable/ParSeq.scala
+++ b/src/library/scala/collection/parallel/mutable/ParSeq.scala
@@ -17,12 +17,6 @@ import scala.collection.generic.CanCombineFrom
import scala.collection.generic.ParFactory
import scala.collection.parallel.ParSeqLike
import scala.collection.parallel.Combiner
-import scala.collection.GenSeq
-
-
-
-
-
/** A mutable variant of `ParSeq`.
*
diff --git a/src/library/scala/collection/parallel/mutable/ParSet.scala b/src/library/scala/collection/parallel/mutable/ParSet.scala
index d8f821746c..ca41852512 100644
--- a/src/library/scala/collection/parallel/mutable/ParSet.scala
+++ b/src/library/scala/collection/parallel/mutable/ParSet.scala
@@ -13,11 +13,6 @@ package scala.collection.parallel.mutable
import scala.collection.generic._
import scala.collection.parallel.Combiner
-import scala.collection.GenSet
-
-
-
-
/** A mutable variant of `ParSet`.
*
diff --git a/src/library/scala/collection/parallel/mutable/ParSetLike.scala b/src/library/scala/collection/parallel/mutable/ParSetLike.scala
index 609888f1a9..0941229124 100644
--- a/src/library/scala/collection/parallel/mutable/ParSetLike.scala
+++ b/src/library/scala/collection/parallel/mutable/ParSetLike.scala
@@ -10,17 +10,11 @@
package scala.collection
package parallel.mutable
-
-
-import scala.collection.mutable.Set
-import scala.collection.mutable.Builder
import scala.collection.mutable.Cloneable
import scala.collection.GenSetLike
import scala.collection.generic.Growable
import scala.collection.generic.Shrinkable
-
-
/** A template trait for mutable parallel sets. This trait is mixed in with concrete
* parallel sets to override the representation type.
*
diff --git a/src/library/scala/collection/parallel/mutable/ResizableParArrayCombiner.scala b/src/library/scala/collection/parallel/mutable/ResizableParArrayCombiner.scala
index dc31d1bc25..0b9b51bc5b 100644
--- a/src/library/scala/collection/parallel/mutable/ResizableParArrayCombiner.scala
+++ b/src/library/scala/collection/parallel/mutable/ResizableParArrayCombiner.scala
@@ -26,7 +26,7 @@ trait ResizableParArrayCombiner[T] extends LazyCombiner[T, ParArray[T], ExposedA
override def sizeHint(sz: Int) = if (chain.length == 1) chain(0).sizeHint(sz)
// public method with private[mutable] type ExposedArrayBuffer in parameter type; cannot be overridden.
- def newLazyCombiner(c: ArrayBuffer[ExposedArrayBuffer[T]]) = ResizableParArrayCombiner(c)
+ final def newLazyCombiner(c: ArrayBuffer[ExposedArrayBuffer[T]]) = ResizableParArrayCombiner(c)
def allocateAndCopy = if (chain.size > 1) {
val arrayseq = new ArraySeq[T](size)
diff --git a/src/library/scala/collection/script/Message.scala b/src/library/scala/collection/script/Message.scala
index 2ab7ea726a..7428cd2b81 100644
--- a/src/library/scala/collection/script/Message.scala
+++ b/src/library/scala/collection/script/Message.scala
@@ -69,7 +69,7 @@ class Script[A] extends ArrayBuffer[Message[A]] with Message[A] {
override def toString(): String = {
var res = "Script("
- var it = this.iterator
+ val it = this.iterator
var i = 1
while (it.hasNext) {
if (i > 1)
diff --git a/src/library/scala/concurrent/FutureTaskRunner.scala b/src/library/scala/concurrent/FutureTaskRunner.scala
index eeadaddb5e..cb4f8687f3 100644
--- a/src/library/scala/concurrent/FutureTaskRunner.scala
+++ b/src/library/scala/concurrent/FutureTaskRunner.scala
@@ -10,7 +10,7 @@ package scala.concurrent
import scala.language.{implicitConversions, higherKinds}
-/** The `FutureTaskRunner</code> trait is a base trait of task runners
+/** The `FutureTaskRunner` trait is a base trait of task runners
* that provide some sort of future abstraction.
*
* @author Philipp Haller
diff --git a/src/library/scala/concurrent/JavaConversions.scala b/src/library/scala/concurrent/JavaConversions.scala
index d6a7c1f1bb..573882ee34 100644
--- a/src/library/scala/concurrent/JavaConversions.scala
+++ b/src/library/scala/concurrent/JavaConversions.scala
@@ -41,10 +41,6 @@ object JavaConversions {
exec.execute(task)
}
- def managedBlock(blocker: ManagedBlocker) {
- blocker.block()
- }
-
def shutdown() {
// do nothing
}
diff --git a/src/library/scala/concurrent/impl/Future.scala b/src/library/scala/concurrent/impl/Future.scala
index 8c2a77c75f..055ce6e4fa 100644
--- a/src/library/scala/concurrent/impl/Future.scala
+++ b/src/library/scala/concurrent/impl/Future.scala
@@ -12,7 +12,7 @@ package scala.concurrent.impl
import scala.concurrent.ExecutionContext
import scala.util.control.NonFatal
-import scala.util.{Try, Success, Failure}
+import scala.util.{ Success, Failure }
private[concurrent] object Future {
diff --git a/src/library/scala/io/Position.scala b/src/library/scala/io/Position.scala
index daa4e103be..b96349803d 100644
--- a/src/library/scala/io/Position.scala
+++ b/src/library/scala/io/Position.scala
@@ -68,14 +68,6 @@ abstract class Position {
}
object Position extends Position {
- /** The undefined position */
- @deprecated("This will be removed", "2.9.0")
- final val NOPOS = 0
-
- /** The first position in a source file */
- @deprecated("This will be removed", "2.9.0")
- final val FIRSTPOS = encode(1, 1)
-
def checkInput(line: Int, column: Int) {
if (line < 0)
throw new IllegalArgumentException(line + " < 0")
diff --git a/src/library/scala/math/BigDecimal.scala b/src/library/scala/math/BigDecimal.scala
index 7c14ed3a9e..f3aabc2974 100644
--- a/src/library/scala/math/BigDecimal.scala
+++ b/src/library/scala/math/BigDecimal.scala
@@ -25,12 +25,6 @@ object BigDecimal {
private val maxCached = 512
val defaultMathContext = MathContext.DECIMAL128
- @deprecated("Use Long.MinValue", "2.9.0")
- val MinLong = new BigDecimal(BigDec valueOf Long.MinValue, defaultMathContext)
-
- @deprecated("Use Long.MaxValue", "2.9.0")
- val MaxLong = new BigDecimal(BigDec valueOf Long.MaxValue, defaultMathContext)
-
/** Cache ony for defaultMathContext using BigDecimals in a small range. */
private lazy val cache = new Array[BigDecimal](maxCached - minCached + 1)
diff --git a/src/library/scala/math/BigInt.scala b/src/library/scala/math/BigInt.scala
index 441bf5aa4d..0cddd71721 100644
--- a/src/library/scala/math/BigInt.scala
+++ b/src/library/scala/math/BigInt.scala
@@ -23,12 +23,6 @@ object BigInt {
private val cache = new Array[BigInt](maxCached - minCached + 1)
private val minusOne = BigInteger.valueOf(-1)
- @deprecated("Use Long.MinValue", "2.9.0")
- val MinLong = BigInt(Long.MinValue)
-
- @deprecated("Use Long.MaxValue", "2.9.0")
- val MaxLong = BigInt(Long.MaxValue)
-
/** Constructs a `BigInt` whose value is equal to that of the
* specified integer value.
*
diff --git a/src/library/scala/math/ScalaNumericConversions.scala b/src/library/scala/math/ScalaNumericConversions.scala
index 6ddf48d03b..59fc7f27b2 100644
--- a/src/library/scala/math/ScalaNumericConversions.scala
+++ b/src/library/scala/math/ScalaNumericConversions.scala
@@ -8,8 +8,6 @@
package scala.math
-import java.{ lang => jl }
-
/** A slightly more specific conversion trait for classes which
* extend ScalaNumber (which excludes value classes.)
*/
diff --git a/src/library/scala/package.scala b/src/library/scala/package.scala
index d3f8df9110..15d6dce8a7 100644
--- a/src/library/scala/package.scala
+++ b/src/library/scala/package.scala
@@ -34,9 +34,6 @@ package object scala {
override def toString = "object AnyRef"
}
- @deprecated("instead of `@serializable class C`, use `class C extends Serializable`", "2.9.0")
- type serializable = annotation.serializable
-
@deprecated("instead of `@cloneable class C`, use `class C extends Cloneable`", "2.10.0")
type cloneable = annotation.cloneable
@@ -129,9 +126,8 @@ package object scala {
type deprecatedName = annotation.deprecatedName
type inline = annotation.inline
type native = annotation.native
- type noinline = noannotation.inline
+ type noinline = annotation.noinline
type remote = annotation.remote
- type serializable = annotation.serializable
type specialized = annotation.specialized
type transient = annotation.transient
type throws = annotation.throws
diff --git a/src/library/scala/parallel/package.scala.disabled b/src/library/scala/parallel/package.scala.disabled
deleted file mode 100644
index 45f5470d03..0000000000
--- a/src/library/scala/parallel/package.scala.disabled
+++ /dev/null
@@ -1,178 +0,0 @@
-package scala
-
-
-
-import scala.concurrent.forkjoin._
-
-
-/** This package object contains various parallel operations.
- *
- * @define invokingPar
- * Invoking a parallel computation creates a future which will
- * hold the result of the computation once it completes. Querying
- * the result of a future before its parallel computation has completed
- * will block the caller. For all practical concerns, the dependency
- * chain obtained by querying results of unfinished futures can have
- * arbitrary lengths. However, care must be taken not to create a
- * circular dependency, as this will result in a deadlock.
- *
- * Additionally, if the parallel computation performs a blocking call
- * (e.g. an I/O operation or waiting for a lock) other than waiting for a future,
- * it should do so by invoking the `block` method. This is another
- * form of waiting that could potentially create a circular dependency,
- * an the user should take care not to do this.
- *
- * Users should be aware that invoking a parallel computation has a
- * certain overhead. Parallel computations should not be invoked for
- * small computations, as this can lead to bad performance. A rule of the
- * thumb is having parallel computations equivalent to a loop
- * with 50000 arithmetic operations (at least). If a parallel computation
- * is invoked within another parallel computation, then it should be
- * computationally equivalent to a loop with 10000 arithmetic operations.
- */
-package object parallel {
-
- private[scala] val forkjoinpool = new ForkJoinPool()
-
- private class Task[T](body: =>T) extends RecursiveTask[T] with Future[T] {
- def compute = body
- def apply() = join()
- }
-
- private final def newTask[T](body: =>T) = new Task[T](body)
-
- private final def executeTask[T](task: RecursiveTask[T]) {
- if (Thread.currentThread().isInstanceOf[ForkJoinWorkerThread]) task.fork
- else forkjoinpool.execute(task)
- }
-
- /* public methods */
-
- /** Performs a call which can potentially block execution.
- *
- * Example:
- * {{{
- * val lock = new ReentrantLock
- *
- * // ... do something ...
- *
- * blocking {
- * if (!lock.hasLock) lock.lock()
- * }
- * }}}
- *
- * '''Note:''' calling methods that wait arbitrary amounts of time
- * (e.g. for I/O operations or locks) may severely decrease performance
- * or even result in deadlocks. This does not include waiting for
- * results of futures.
- */
- def blocking[T](body: =>T): T = {
- if (Thread.currentThread().isInstanceOf[ForkJoinWorkerThread]) {
- val blocker = new ForkJoinPool.ManagedBlocker {
- @volatile var done = false
- @volatile var result: Any = _
- def block() = {
- result = body
- done = true
- true
- }
- def isReleasable() = done
- }
- ForkJoinPool.managedBlock(blocker, true)
- blocker.result.asInstanceOf[T]
- } else body
- }
-
- /** Starts a parallel computation and returns a future.
- *
- * $invokingPar
- *
- * @tparam T the type of the result of the parallel computation
- * @param body the computation to be invoked in parallel
- * @return a future with the result
- */
- def par[T](body: =>T): Future[T] = {
- val task = newTask(body)
- executeTask(task)
- task
- }
-
- /** Starts 2 parallel computations and returns a future.
- *
- * $invokingPar
- *
- * @tparam T1 the type of the result of 1st the parallel computation
- * @tparam T2 the type of the result of 2nd the parallel computation
- * @param b1 the 1st computation to be invoked in parallel
- * @param b2 the 2nd computation to be invoked in parallel
- * @return a tuple of futures corresponding to parallel computations
- */
- def par[T1, T2](b1: =>T1, b2: =>T2): (Future[T1], Future[T2]) = {
- val t1 = newTask(b1)
- executeTask(t1)
- val t2 = newTask(b2)
- executeTask(t2)
- (t1, t2)
- }
-
- /** Starts 3 parallel computations and returns a future.
- *
- * $invokingPar
- *
- * @tparam T1 the type of the result of 1st the parallel computation
- * @tparam T2 the type of the result of 2nd the parallel computation
- * @tparam T3 the type of the result of 3rd the parallel computation
- * @param b1 the 1st computation to be invoked in parallel
- * @param b2 the 2nd computation to be invoked in parallel
- * @param b3 the 3rd computation to be invoked in parallel
- * @return a tuple of futures corresponding to parallel computations
- */
- def par[T1, T2, T3](b1: =>T1, b2: =>T2, b3: =>T3): (Future[T1], Future[T2], Future[T3]) = {
- val t1 = newTask(b1)
- executeTask(t1)
- val t2 = newTask(b2)
- executeTask(t2)
- val t3 = newTask(b3)
- executeTask(t3)
- (t1, t2, t3)
- }
-
- /** Starts 4 parallel computations and returns a future.
- *
- * $invokingPar
- *
- * @tparam T1 the type of the result of 1st the parallel computation
- * @tparam T2 the type of the result of 2nd the parallel computation
- * @tparam T3 the type of the result of 3rd the parallel computation
- * @tparam T4 the type of the result of 4th the parallel computation
- * @param b1 the 1st computation to be invoked in parallel
- * @param b2 the 2nd computation to be invoked in parallel
- * @param b3 the 3rd computation to be invoked in parallel
- * @param b4 the 4th computation to be invoked in parallel
- * @return a tuple of futures corresponding to parallel computations
- */
- def par[T1, T2, T3, T4](b1: =>T1, b2: =>T2, b3: =>T3, b4: =>T4): (Future[T1], Future[T2], Future[T3], Future[T4]) = {
- val t1 = newTask(b1)
- executeTask(t1)
- val t2 = newTask(b2)
- executeTask(t2)
- val t3 = newTask(b3)
- executeTask(t3)
- val t4 = newTask(b4)
- executeTask(t4)
- (t1, t2, t3, t4)
- }
-
-}
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/library/scala/runtime/ScalaRunTime.scala b/src/library/scala/runtime/ScalaRunTime.scala
index 1d8fe5e9ad..1a79e6da73 100644
--- a/src/library/scala/runtime/ScalaRunTime.scala
+++ b/src/library/scala/runtime/ScalaRunTime.scala
@@ -26,8 +26,7 @@ import java.lang.reflect.{ Modifier, Method => JMethod }
* outside the API and subject to change or removal without notice.
*/
object ScalaRunTime {
- def isArray(x: AnyRef): Boolean = isArray(x, 1)
- def isArray(x: Any, atLevel: Int): Boolean =
+ def isArray(x: Any, atLevel: Int = 1): Boolean =
x != null && isArrayClass(x.getClass, atLevel)
private def isArrayClass(clazz: jClass[_], atLevel: Int): Boolean =
diff --git a/src/library/scala/sys/SystemProperties.scala b/src/library/scala/sys/SystemProperties.scala
index da9adb3dc2..294be5cd71 100644
--- a/src/library/scala/sys/SystemProperties.scala
+++ b/src/library/scala/sys/SystemProperties.scala
@@ -64,7 +64,6 @@ object SystemProperties {
propertyHelp(p.key) = helpText
p
}
- private def str(key: String, helpText: String) = addHelp(Prop[String](key), helpText)
private def bool(key: String, helpText: String): BooleanProp = addHelp[BooleanProp](
if (key startsWith "java.") BooleanProp.valueIsTrue(key) else BooleanProp.keyExists(key),
helpText
diff --git a/src/library/scala/util/automata/WordBerrySethi.scala b/src/library/scala/util/automata/WordBerrySethi.scala
index 12448f595d..2f4625da44 100644
--- a/src/library/scala/util/automata/WordBerrySethi.scala
+++ b/src/library/scala/util/automata/WordBerrySethi.scala
@@ -21,7 +21,7 @@ import scala.util.regexp.WordExp
abstract class WordBerrySethi extends BaseBerrySethi {
override val lang: WordExp
- import lang.{ Alt, Eps, Letter, Meta, RegExp, Sequ, Star, _labelT }
+ import lang.{ Alt, Eps, Letter, RegExp, Sequ, Star, _labelT }
protected var labels: mutable.HashSet[_labelT] = _
// don't let this fool you, only labelAt is a real, surjective mapping
@@ -140,7 +140,6 @@ abstract class WordBerrySethi extends BaseBerrySethi {
val delta1 = immutable.Map(deltaq.zipWithIndex map (_.swap): _*)
val finalsArr = (0 until pos map (k => finals.getOrElse(k, 0))).toArray // 0 == not final
- val initialsArr = initials.toArray
val deltaArr: Array[mutable.Map[_labelT, immutable.BitSet]] =
(0 until pos map { x =>
@@ -152,7 +151,6 @@ abstract class WordBerrySethi extends BaseBerrySethi {
new NondetWordAutom[_labelT] {
val nstates = pos
val labels = WordBerrySethi.this.labels.toList
- val initials = initialsArr
val finals = finalsArr
val delta = deltaArr
val default = defaultArr
diff --git a/src/library/scala/util/matching/Regex.scala b/src/library/scala/util/matching/Regex.scala
index 716d746552..830710432c 100644
--- a/src/library/scala/util/matching/Regex.scala
+++ b/src/library/scala/util/matching/Regex.scala
@@ -131,7 +131,7 @@ import java.util.regex.{ Pattern, Matcher }
* @author Martin Odersky
* @version 1.1, 29/01/2008
*
- * @param regex A string representing a regular expression
+ * @param pattern The compiled pattern
* @param groupNames A mapping from names to indices in capture groups
*
* @define replacementString
@@ -144,41 +144,67 @@ import java.util.regex.{ Pattern, Matcher }
* to automatically escape these characters.
*/
@SerialVersionUID(-2094783597747625537L)
-class Regex(regex: String, groupNames: String*) extends Serializable {
+class Regex private[matching](val pattern: Pattern, groupNames: String*) extends Serializable {
outer =>
import Regex._
- /** The compiled pattern */
- val pattern = Pattern.compile(regex)
+ /**
+ * @param regex A string representing a regular expression
+ * @param groupNames A mapping from names to indices in capture groups
+ */
+ def this(regex: String, groupNames: String*) = this(Pattern.compile(regex), groupNames: _*)
- /** Tries to match target (whole match) and returns the matching subgroups.
- * if the pattern has no subgroups, then it returns an empty list on a
- * successful match.
- *
- * Note, however, that if some subgroup has not been matched, a `null` will
- * be returned for that subgroup.
+ /** Tries to match a [[java.lang.CharSequence]].
+ * If the match succeeds, the result is a list of the matching
+ * groups (or a `null` element if a group did not match any input).
+ * If the pattern specifies no groups, then the result will be an empty list
+ * on a successful match.
*
+ * This method attempts to match the entire input by default; to find the next
+ * matching subsequence, use an unanchored Regex.
+
* For example:
*
* {{{
* val p1 = "ab*c".r
- * val p2 = "a(b*)c".r
- *
* val p1Matches = "abbbc" match {
* case p1() => true
* case _ => false
* }
- *
+ * val p2 = "a(b*)c".r
* val numberOfB = "abbbc" match {
* case p2(b) => Some(b.length)
* case _ => None
* }
+ * val p3 = "b*".r.unanchored
+ * val p3Matches = "abbbc" match {
+ * case p3() => true
+ * case _ => false
+ * }
* }}}
*
- * @param target The string to match
+ * @param s The string to match
* @return The matches
*/
+ def unapplySeq(s: CharSequence): Option[Seq[String]] = {
+ val m = pattern matcher s
+ if (runMatcher(m)) Some(1 to m.groupCount map m.group)
+ else None
+ }
+
+ /** Tries to match on a [[scala.util.matching.Regex.Match]].
+ * A previously failed match results in None.
+ * If a successful match was made against the current pattern, then that result is used.
+ * Otherwise, this Regex is applied to the previously matched input,
+ * and the result of that match is used.
+ */
+ def unapplySeq(m: Match): Option[Seq[String]] =
+ if (m.matched == null) None
+ else if (m.matcher.pattern == this.pattern) Some(1 to m.groupCount map m.group)
+ else unapplySeq(m.matched)
+
+ @deprecated("Extracting a match result from anything but a CharSequence or Match is deprecated", "2.10.0")
def unapplySeq(target: Any): Option[List[String]] = target match {
case s: CharSequence =>
val m = pattern matcher s
@@ -187,6 +213,8 @@ class Regex(regex: String, groupNames: String*) extends Serializable {
case m: Match => unapplySeq(m.matched)
case _ => None
}
+
+ // @see UnanchoredRegex
protected def runMatcher(m: Matcher) = m.matches()
/** Return all matches of this regexp in given character sequence as a [[scala.util.matching.Regex.MatchIterator]],
@@ -200,7 +228,7 @@ class Regex(regex: String, groupNames: String*) extends Serializable {
* @return A [[scala.util.matching.Regex.MatchIterator]] of all matches.
* @example {{{for (words <- """\w+""".r findAllIn "A simple example.") yield words}}}
*/
- def findAllIn(source: java.lang.CharSequence) = new Regex.MatchIterator(source, this, groupNames)
+ def findAllIn(source: CharSequence) = new Regex.MatchIterator(source, this, groupNames)
/** Return all matches of this regexp in given character sequence as a
@@ -210,7 +238,7 @@ class Regex(regex: String, groupNames: String*) extends Serializable {
* @return A [[scala.collection.Iterator]] of [[scala.util.matching.Regex.Match]] for all matches.
* @example {{{for (words <- """\w+""".r findAllMatchIn "A simple example.") yield words.start}}}
*/
- def findAllMatchIn(source: java.lang.CharSequence): Iterator[Match] = {
+ def findAllMatchIn(source: CharSequence): Iterator[Match] = {
val matchIterator = findAllIn(source)
new Iterator[Match] {
def hasNext = matchIterator.hasNext
@@ -228,7 +256,7 @@ class Regex(regex: String, groupNames: String*) extends Serializable {
* @return An [[scala.Option]] of the first matching string in the text.
* @example {{{"""\w+""".r findFirstIn "A simple example." foreach println // prints "A"}}}
*/
- def findFirstIn(source: java.lang.CharSequence): Option[String] = {
+ def findFirstIn(source: CharSequence): Option[String] = {
val m = pattern.matcher(source)
if (m.find) Some(m.group) else None
}
@@ -245,7 +273,7 @@ class Regex(regex: String, groupNames: String*) extends Serializable {
* @return A [[scala.Option]] of [[scala.util.matching.Regex.Match]] of the first matching string in the text.
* @example {{{("""[a-z]""".r findFirstMatchIn "A simple example.") map (_.start) // returns Some(2), the index of the first match in the text}}}
*/
- def findFirstMatchIn(source: java.lang.CharSequence): Option[Match] = {
+ def findFirstMatchIn(source: CharSequence): Option[Match] = {
val m = pattern.matcher(source)
if (m.find) Some(new Match(source, m, groupNames)) else None
}
@@ -262,7 +290,7 @@ class Regex(regex: String, groupNames: String*) extends Serializable {
* @return A [[scala.Option]] of the matched prefix.
* @example {{{"""[a-z]""".r findPrefixOf "A simple example." // returns None, since the text does not begin with a lowercase letter}}}
*/
- def findPrefixOf(source: java.lang.CharSequence): Option[String] = {
+ def findPrefixOf(source: CharSequence): Option[String] = {
val m = pattern.matcher(source)
if (m.lookingAt) Some(m.group) else None
}
@@ -279,7 +307,7 @@ class Regex(regex: String, groupNames: String*) extends Serializable {
* @return A [[scala.Option]] of the [[scala.util.matching.Regex.Match]] of the matched string.
* @example {{{"""\w+""".r findPrefixMatchOf "A simple example." map (_.after) // returns Some(" simple example.")}}}
*/
- def findPrefixMatchOf(source: java.lang.CharSequence): Option[Match] = {
+ def findPrefixMatchOf(source: CharSequence): Option[Match] = {
val m = pattern.matcher(source)
if (m.lookingAt) Some(new Match(source, m, groupNames)) else None
}
@@ -293,7 +321,7 @@ class Regex(regex: String, groupNames: String*) extends Serializable {
* @return The resulting string
* @example {{{"""\d+""".r replaceAllIn ("July 15", "<NUMBER>") // returns "July <NUMBER>"}}}
*/
- def replaceAllIn(target: java.lang.CharSequence, replacement: String): String = {
+ def replaceAllIn(target: CharSequence, replacement: String): String = {
val m = pattern.matcher(target)
m.replaceAll(replacement)
}
@@ -316,7 +344,7 @@ class Regex(regex: String, groupNames: String*) extends Serializable {
* @param replacer The function which maps a match to another string.
* @return The target string after replacements.
*/
- def replaceAllIn(target: java.lang.CharSequence, replacer: Match => String): String = {
+ def replaceAllIn(target: CharSequence, replacer: Match => String): String = {
val it = new Regex.MatchIterator(target, this, groupNames).replacementData
it foreach (md => it replace replacer(md))
it.replaced
@@ -343,7 +371,7 @@ class Regex(regex: String, groupNames: String*) extends Serializable {
* @param replacer The function which optionally maps a match to another string.
* @return The target string after replacements.
*/
- def replaceSomeIn(target: java.lang.CharSequence, replacer: Match => Option[String]): String = {
+ def replaceSomeIn(target: CharSequence, replacer: Match => Option[String]): String = {
val it = new Regex.MatchIterator(target, this, groupNames).replacementData
for (matchdata <- it ; replacement <- replacer(matchdata))
it replace replacement
@@ -359,7 +387,7 @@ class Regex(regex: String, groupNames: String*) extends Serializable {
* @param replacement The string that will replace the match
* @return The resulting string
*/
- def replaceFirstIn(target: java.lang.CharSequence, replacement: String): String = {
+ def replaceFirstIn(target: CharSequence, replacement: String): String = {
val m = pattern.matcher(target)
m.replaceFirst(replacement)
}
@@ -370,7 +398,7 @@ class Regex(regex: String, groupNames: String*) extends Serializable {
* @return The array of strings computed by splitting the
* input around matches of this regexp
*/
- def split(toSplit: java.lang.CharSequence): Array[String] =
+ def split(toSplit: CharSequence): Array[String] =
pattern.split(toSplit)
/** Create a new Regex with the same pattern, but no requirement that
@@ -390,9 +418,11 @@ class Regex(regex: String, groupNames: String*) extends Serializable {
*
* @return The new unanchored regex
*/
- def unanchored: UnanchoredRegex = new Regex(regex, groupNames: _*) with UnanchoredRegex { override def anchored = outer }
+ def unanchored: UnanchoredRegex = new Regex(pattern, groupNames: _*) with UnanchoredRegex { override def anchored = outer }
def anchored: Regex = this
+ def regex: String = pattern.pattern
+
/** The string defining the regular expression */
override def toString = regex
}
@@ -421,7 +451,7 @@ object Regex {
trait MatchData {
/** The source from where the match originated */
- val source: java.lang.CharSequence
+ val source: CharSequence
/** The names of the groups, or some empty sequence if one defined */
val groupNames: Seq[String]
@@ -459,25 +489,25 @@ object Regex {
/** The char sequence before first character of match,
* or `null` if nothing was matched */
- def before: java.lang.CharSequence =
+ def before: CharSequence =
if (start >= 0) source.subSequence(0, start)
else null
/** The char sequence before first character of match in group `i`,
* or `null` if nothing was matched for that group */
- def before(i: Int): java.lang.CharSequence =
+ def before(i: Int): CharSequence =
if (start(i) >= 0) source.subSequence(0, start(i))
else null
/** Returns char sequence after last character of match,
* or `null` if nothing was matched */
- def after: java.lang.CharSequence =
+ def after: CharSequence =
if (end >= 0) source.subSequence(end, source.length)
else null
/** The char sequence after last character of match in group `i`,
* or `null` if nothing was matched for that group */
- def after(i: Int): java.lang.CharSequence =
+ def after(i: Int): CharSequence =
if (end(i) >= 0) source.subSequence(end(i), source.length)
else null
@@ -501,8 +531,8 @@ object Regex {
/** Provides information about a succesful match.
*/
- class Match(val source: java.lang.CharSequence,
- matcher: Matcher,
+ class Match(val source: CharSequence,
+ private[matching] val matcher: Matcher,
val groupNames: Seq[String]) extends MatchData {
/** The index of the first matched character */
@@ -563,7 +593,7 @@ object Regex {
/** A class to step through a sequence of regex matches
*/
- class MatchIterator(val source: java.lang.CharSequence, val regex: Regex, val groupNames: Seq[String])
+ class MatchIterator(val source: CharSequence, val regex: Regex, val groupNames: Seq[String])
extends AbstractIterator[String] with Iterator[String] with MatchData { self =>
protected[Regex] val matcher = regex.pattern.matcher(source)
@@ -620,7 +650,7 @@ object Regex {
private[matching] trait Replacement {
protected def matcher: Matcher
- private var sb = new java.lang.StringBuffer
+ private val sb = new java.lang.StringBuffer
def replaced = {
val newsb = new java.lang.StringBuffer(sb)
diff --git a/src/library/scala/util/parsing/combinator/JavaTokenParsers.scala b/src/library/scala/util/parsing/combinator/JavaTokenParsers.scala
index 78817cfb67..89832d3fb2 100644
--- a/src/library/scala/util/parsing/combinator/JavaTokenParsers.scala
+++ b/src/library/scala/util/parsing/combinator/JavaTokenParsers.scala
@@ -21,11 +21,12 @@ import scala.annotation.migration
* - `floatingPointNumber`
*/
trait JavaTokenParsers extends RegexParsers {
- /** Anything starting with an ASCII alphabetic character or underscore,
- * followed by zero or more repetitions of regex's `\w`.
+ /** Anything that is a valid Java identifier, according to
+ * <a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-3.html#jls-3.8">The Java Language Spec</a>.
+ * Generally, this means a letter, followed by zero or more letters or numbers.
*/
def ident: Parser[String] =
- """[a-zA-Z_]\w*""".r
+ """\p{javaJavaIdentifierStart}\p{javaJavaIdentifierPart}*""".r
/** An integer, without sign or with a negative sign. */
def wholeNumber: Parser[String] =
"""-?\d+""".r
diff --git a/src/library/scala/util/parsing/combinator/PackratParsers.scala b/src/library/scala/util/parsing/combinator/PackratParsers.scala
index 16705d45f9..cd0907e40f 100644
--- a/src/library/scala/util/parsing/combinator/PackratParsers.scala
+++ b/src/library/scala/util/parsing/combinator/PackratParsers.scala
@@ -8,7 +8,6 @@
package scala.util.parsing.combinator
-import scala.util.parsing.combinator._
import scala.util.parsing.input.{ Reader, Position }
import scala.collection.mutable
import scala.language.implicitConversions
diff --git a/src/library/scala/util/parsing/combinator/lexical/Scanners.scala b/src/library/scala/util/parsing/combinator/lexical/Scanners.scala
index 5c23ad70cd..f6a8daabd9 100644
--- a/src/library/scala/util/parsing/combinator/lexical/Scanners.scala
+++ b/src/library/scala/util/parsing/combinator/lexical/Scanners.scala
@@ -6,13 +6,10 @@
** |/ **
\* */
-
-
package scala.util.parsing
package combinator
package lexical
-import token._
import input._
/** This component provides core functionality for lexical parsers.
diff --git a/src/library/scala/util/parsing/combinator/lexical/StdLexical.scala b/src/library/scala/util/parsing/combinator/lexical/StdLexical.scala
index f3491c096f..2fbc1ec136 100644
--- a/src/library/scala/util/parsing/combinator/lexical/StdLexical.scala
+++ b/src/library/scala/util/parsing/combinator/lexical/StdLexical.scala
@@ -50,7 +50,7 @@ class StdLexical extends Lexical with StdTokens {
def identChar = letter | elem('_')
// see `whitespace in `Scanners`
- def whitespace: Parser[Any] = rep(
+ def whitespace: Parser[Any] = rep[Any](
whitespaceChar
| '/' ~ '*' ~ comment
| '/' ~ '/' ~ rep( chrExcept(EofCh, '\n') )
diff --git a/src/library/scala/util/parsing/combinator/testing/Tester.scala b/src/library/scala/util/parsing/combinator/testing/Tester.scala
index 95730ee292..3cdab2a885 100644
--- a/src/library/scala/util/parsing/combinator/testing/Tester.scala
+++ b/src/library/scala/util/parsing/combinator/testing/Tester.scala
@@ -7,7 +7,6 @@
\* */
package scala.util.parsing.combinator.testing
-import scala.util.parsing.combinator._
import scala.util.parsing.combinator.lexical.Lexical
import scala.util.parsing.combinator.syntactical.TokenParsers
diff --git a/src/library/scala/util/parsing/input/OffsetPosition.scala b/src/library/scala/util/parsing/input/OffsetPosition.scala
index 01d9ea5cb8..6b00af4ce2 100644
--- a/src/library/scala/util/parsing/input/OffsetPosition.scala
+++ b/src/library/scala/util/parsing/input/OffsetPosition.scala
@@ -22,7 +22,7 @@ case class OffsetPosition(source: java.lang.CharSequence, offset: Int) extends P
/** An index that contains all line starts, including first line, and eof. */
private lazy val index: Array[Int] = {
- var lineStarts = new ArrayBuffer[Int]
+ val lineStarts = new ArrayBuffer[Int]
lineStarts += 0
for (i <- 0 until source.length)
if (source.charAt(i) == '\n') lineStarts += (i + 1)
diff --git a/src/library/scala/util/parsing/json/JSON.scala b/src/library/scala/util/parsing/json/JSON.scala
index 2f450ed864..8f951d519a 100644
--- a/src/library/scala/util/parsing/json/JSON.scala
+++ b/src/library/scala/util/parsing/json/JSON.scala
@@ -7,9 +7,6 @@
\* */
package scala.util.parsing.json
-import scala.util.parsing.combinator._
-import scala.util.parsing.combinator.syntactical._
-import scala.util.parsing.combinator.lexical._
/**
* This object provides a simple interface to the JSON parser class.
diff --git a/src/library/scala/util/parsing/json/Lexer.scala b/src/library/scala/util/parsing/json/Lexer.scala
index 991b5d5c6c..762c1352a7 100644
--- a/src/library/scala/util/parsing/json/Lexer.scala
+++ b/src/library/scala/util/parsing/json/Lexer.scala
@@ -11,7 +11,6 @@
package scala.util.parsing.json
import scala.util.parsing.combinator._
-import scala.util.parsing.combinator.syntactical._
import scala.util.parsing.combinator.lexical._
import scala.util.parsing.input.CharArrayReader.EofCh
diff --git a/src/library/scala/util/parsing/json/Parser.scala b/src/library/scala/util/parsing/json/Parser.scala
index cb87866f07..bf1162000b 100644
--- a/src/library/scala/util/parsing/json/Parser.scala
+++ b/src/library/scala/util/parsing/json/Parser.scala
@@ -12,7 +12,6 @@ package scala.util.parsing.json
import scala.util.parsing.combinator._
import scala.util.parsing.combinator.syntactical._
-import scala.util.parsing.combinator.lexical._
/**
* A marker class for the JSON result types.
diff --git a/src/library/scala/xml/Elem.scala b/src/library/scala/xml/Elem.scala
index b9e665e292..fc32e45a5e 100755
--- a/src/library/scala/xml/Elem.scala
+++ b/src/library/scala/xml/Elem.scala
@@ -17,7 +17,7 @@ package scala.xml
* @author Burak Emir <bqe@google.com>
*/
object Elem {
- /** Build an Elem, setting its minimizeEmpty property to <code>true</code> if it has no children. Note that this
+ /** Build an Elem, setting its minimizeEmpty property to `true` if it has no children. Note that this
* default may not be exactly what you want, as some XML dialects don't permit some elements to be minimized.
*
* @deprecated This factory method is retained for backward compatibility; please use the other one, with which you
diff --git a/src/library/scala/xml/Node.scala b/src/library/scala/xml/Node.scala
index 6b6c962692..dcd4c15969 100755
--- a/src/library/scala/xml/Node.scala
+++ b/src/library/scala/xml/Node.scala
@@ -55,7 +55,7 @@ abstract class Node extends NodeSeq {
def scope: NamespaceBinding = TopScope
/**
- * convenience, same as <code>getNamespace(this.prefix)</code>
+ * convenience, same as `getNamespace(this.prefix)`
*/
def namespace = getNamespace(this.prefix)
@@ -64,8 +64,8 @@ abstract class Node extends NodeSeq {
* checks if scope is `'''null'''`.
*
* @param pre the prefix whose namespace name we would like to obtain
- * @return the namespace if <code>scope != null</code> and prefix was
- * found, else <code>null</code>
+ * @return the namespace if `scope != null` and prefix was
+ * found, else `null`
*/
def getNamespace(pre: String): String = if (scope eq null) null else scope.getURI(pre)
@@ -74,8 +74,8 @@ abstract class Node extends NodeSeq {
* Same as `attributes.getValue(key)`
*
* @param key of queried attribute.
- * @return value of <code>UnprefixedAttribute</code> with given key
- * in attributes, if it exists, otherwise <code>null</code>.
+ * @return value of `UnprefixedAttribute` with given key
+ * in attributes, if it exists, otherwise `null`.
*/
final def attribute(key: String): Option[Seq[Node]] = attributes.get(key)
diff --git a/src/library/scala/xml/NodeSeq.scala b/src/library/scala/xml/NodeSeq.scala
index decf60dad7..d2efc947b1 100644
--- a/src/library/scala/xml/NodeSeq.scala
+++ b/src/library/scala/xml/NodeSeq.scala
@@ -145,6 +145,11 @@ abstract class NodeSeq extends AbstractSeq[Node] with immutable.Seq[Node] with S
}
}
+ /** Convenience method which returns string text of the named attribute. Use:
+ * - `that \@ "foo"` to get the string text of attribute `"foo"`;
+ */
+ def \@(attributeName: String): String = (this \ ("@" + attributeName)).text
+
override def toString(): String = theSeq.mkString
def text: String = (this map (_.text)).mkString
diff --git a/src/library/scala/xml/PrettyPrinter.scala b/src/library/scala/xml/PrettyPrinter.scala
index 39ff8c35ec..f9157802c6 100755
--- a/src/library/scala/xml/PrettyPrinter.scala
+++ b/src/library/scala/xml/PrettyPrinter.scala
@@ -47,7 +47,6 @@ class PrettyPrinter(width: Int, step: Int) {
val tmp = width - cur
if (s.length <= tmp)
return List(Box(ind, s))
- val sb = new StringBuilder()
var i = s indexOf ' '
if (i > tmp || i == -1) throw new BrokenException() // cannot break
diff --git a/src/library/scala/xml/XML.scala b/src/library/scala/xml/XML.scala
index d101684459..ec5e5e9e1c 100755
--- a/src/library/scala/xml/XML.scala
+++ b/src/library/scala/xml/XML.scala
@@ -45,8 +45,6 @@ object MinimizeMode extends Enumeration {
val Never = Value
}
-import Source._
-
/** The object `XML` provides constants, and functions to load
* and save XML elements. Use this when data binding is not desired, i.e.
* when XML is handled using `Symbol` nodes.
diff --git a/src/library/scala/xml/dtd/DocType.scala b/src/library/scala/xml/dtd/DocType.scala
index 79f8f9fe8b..ce067bee79 100644
--- a/src/library/scala/xml/dtd/DocType.scala
+++ b/src/library/scala/xml/dtd/DocType.scala
@@ -15,7 +15,7 @@ package dtd
* @author Burak Emir
*
* @param name name of this DOCTYPE
- * @param extID None, or Some(external ID of this doctype)
+ * @param extID NoExternalID or the external ID of this doctype
* @param intSubset sequence of internal subset declarations
*/
case class DocType(name: String, extID: ExternalID, intSubset: Seq[dtd.Decl])
@@ -32,3 +32,9 @@ case class DocType(name: String, extID: ExternalID, intSubset: Seq[dtd.Decl])
"""<!DOCTYPE %s %s%s>""".format(name, extID.toString, intString)
}
}
+
+object DocType
+{
+ /** Creates a doctype with no external id, nor internal subset declarations. */
+ def apply(name: String): DocType = apply(name, NoExternalID, Nil)
+}
diff --git a/src/library/scala/xml/dtd/ElementValidator.scala b/src/library/scala/xml/dtd/ElementValidator.scala
index bfc85f48a9..66951bf390 100644
--- a/src/library/scala/xml/dtd/ElementValidator.scala
+++ b/src/library/scala/xml/dtd/ElementValidator.scala
@@ -61,7 +61,7 @@ class ElementValidator() extends Function1[Node,Boolean] {
*/
def check(md: MetaData): Boolean = {
val len: Int = exc.length
- var ok = new mutable.BitSet(adecls.length)
+ val ok = new mutable.BitSet(adecls.length)
for (attr <- md) {
def attrStr = attr.value.toString
diff --git a/src/library/scala/xml/dtd/ExternalID.scala b/src/library/scala/xml/dtd/ExternalID.scala
index 7a7463569e..e346f89d0a 100644
--- a/src/library/scala/xml/dtd/ExternalID.scala
+++ b/src/library/scala/xml/dtd/ExternalID.scala
@@ -73,3 +73,14 @@ case class PublicID(publicId: String, systemId: String) extends ExternalID {
/** always empty */
def child = Nil
}
+
+/** A marker used when a `DocType` contains no external id.
+ *
+ * @author Michael Bayne
+ */
+object NoExternalID extends ExternalID {
+ val publicId = null
+ val systemId = null
+
+ override def toString = ""
+}
diff --git a/src/library/scala/xml/factory/XMLLoader.scala b/src/library/scala/xml/factory/XMLLoader.scala
index 72e4c51b11..efa241e388 100644
--- a/src/library/scala/xml/factory/XMLLoader.scala
+++ b/src/library/scala/xml/factory/XMLLoader.scala
@@ -12,7 +12,7 @@ package factory
import javax.xml.parsers.SAXParserFactory
import parsing.{ FactoryAdapter, NoBindingFactoryAdapter }
-import java.io.{ InputStream, Reader, StringReader, File, FileDescriptor, FileInputStream }
+import java.io.{ InputStream, Reader, File, FileDescriptor }
import java.net.URL
/** Presents collection of XML loading methods which use the parser
diff --git a/src/library/scala/xml/include/sax/EncodingHeuristics.scala b/src/library/scala/xml/include/sax/EncodingHeuristics.scala
index 1340689cae..8d8ce5b290 100644
--- a/src/library/scala/xml/include/sax/EncodingHeuristics.scala
+++ b/src/library/scala/xml/include/sax/EncodingHeuristics.scala
@@ -6,10 +6,8 @@
** |/ **
\* */
-
package scala.xml
package include.sax
-import scala.xml.include._
import java.io.InputStream
import scala.util.matching.Regex
diff --git a/src/library/scala/xml/include/sax/XIncludeFilter.scala b/src/library/scala/xml/include/sax/XIncludeFilter.scala
index 729769366e..103cddcb11 100644
--- a/src/library/scala/xml/include/sax/XIncludeFilter.scala
+++ b/src/library/scala/xml/include/sax/XIncludeFilter.scala
@@ -275,7 +275,7 @@ class XIncludeFilter extends XMLFilterImpl {
try {
val uc = source.openConnection()
val in = new BufferedInputStream(uc.getInputStream())
- var encodingFromHeader = uc.getContentEncoding()
+ val encodingFromHeader = uc.getContentEncoding()
var contentType = uc.getContentType()
if (encodingFromHeader != null)
encoding = encodingFromHeader
diff --git a/src/library/scala/xml/include/sax/XIncluder.scala b/src/library/scala/xml/include/sax/XIncluder.scala
index 5064d6b3d8..81c5613541 100644
--- a/src/library/scala/xml/include/sax/XIncluder.scala
+++ b/src/library/scala/xml/include/sax/XIncluder.scala
@@ -6,11 +6,9 @@
** |/ **
\* */
-
package scala.xml
package include.sax
-import scala.xml.include._
import scala.collection.mutable
import org.xml.sax.{ ContentHandler, XMLReader, Locator, Attributes }
import org.xml.sax.ext.LexicalHandler
diff --git a/src/library/scala/xml/parsing/MarkupParser.scala b/src/library/scala/xml/parsing/MarkupParser.scala
index f9ff54d054..6b8f58dca3 100755
--- a/src/library/scala/xml/parsing/MarkupParser.scala
+++ b/src/library/scala/xml/parsing/MarkupParser.scala
@@ -154,7 +154,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests
var info_enc: Option[String] = None
var info_stdl: Option[Boolean] = None
- var m = xmlProcInstr()
+ val m = xmlProcInstr()
var n = 0
if (isProlog)
@@ -303,10 +303,8 @@ trait MarkupParser extends MarkupParserCommon with TokenTests
var scope: NamespaceBinding = pscope
var aMap: MetaData = Null
while (isNameStart(ch)) {
- val pos = this.pos
-
val qname = xName
- val _ = xEQ
+ xEQ // side effect
val value = xAttributeValue()
Utility.prefix(qname) match {
@@ -423,7 +421,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests
* content1 ::= '<' content1 | '&' charref ...
* }}} */
def content(pscope: NamespaceBinding): NodeSeq = {
- var ts = new NodeBuffer
+ val ts = new NodeBuffer
var exit = eof
// todo: optimize seq repr.
def done = new NodeSeq { val theSeq = ts.toList }
@@ -582,7 +580,6 @@ trait MarkupParser extends MarkupParserCommon with TokenTests
var exit = false
while (! exit) {
putChar(ch)
- val opos = pos
nextch
exit = eof || ( ch == '<' ) || ( ch == '&' )
@@ -828,7 +825,6 @@ trait MarkupParser extends MarkupParserCommon with TokenTests
* }}} */
def entityDecl() = {
var isParameterEntity = false
- var entdef: EntityDef = null
xToken("NTITY")
xSpace
if ('%' == ch) {
diff --git a/src/library/scala/xml/parsing/MarkupParserCommon.scala b/src/library/scala/xml/parsing/MarkupParserCommon.scala
index da640484e0..43ec539931 100644
--- a/src/library/scala/xml/parsing/MarkupParserCommon.scala
+++ b/src/library/scala/xml/parsing/MarkupParserCommon.scala
@@ -10,7 +10,6 @@ package scala.xml
package parsing
import scala.io.Source
-import scala.xml.dtd._
import scala.annotation.switch
import Utility.Escapes.{ pairs => unescape }
diff --git a/src/library/scala/xml/persistent/SetStorage.scala b/src/library/scala/xml/persistent/SetStorage.scala
index 20a5bb6767..d16c71c9f7 100644
--- a/src/library/scala/xml/persistent/SetStorage.scala
+++ b/src/library/scala/xml/persistent/SetStorage.scala
@@ -20,16 +20,14 @@ import java.io.File
*/
class SetStorage(file: File) extends CachedFileStorage(file) {
- private var theSet: mutable.HashSet[Node] = new mutable.HashSet[Node]
+ private val theSet = mutable.HashSet[Node]()
// initialize
{
val it = super.initialNodes
dirty = it.hasNext
- for(x <- it) {
- theSet += x;
- }
+ theSet ++= it
}
/* forwarding methods to hashset*/
diff --git a/src/library/scala/xml/transform/RewriteRule.scala b/src/library/scala/xml/transform/RewriteRule.scala
index 1dca495a10..13210a6fd2 100644
--- a/src/library/scala/xml/transform/RewriteRule.scala
+++ b/src/library/scala/xml/transform/RewriteRule.scala
@@ -11,8 +11,8 @@
package scala.xml
package transform
-/** a RewriteRule, when applied to a term, yields either
- * the resulting of rewriting or the term itself it the rule
+/** A RewriteRule, when applied to a term, yields either
+ * the result of rewriting the term or the term itself if the rule
* is not applied.
*
* @author Burak Emir
diff --git a/src/manual/scala/man1/scalac.scala b/src/manual/scala/man1/scalac.scala
index 13b1fd58e0..1c0c7c4a96 100644
--- a/src/manual/scala/man1/scalac.scala
+++ b/src/manual/scala/man1/scalac.scala
@@ -146,13 +146,6 @@ object scalac extends Command {
CmdOption("sourcepath", Argument("path")),
"Specify location(s) of source files."),
Definition(
- CmdOptionBound("target:", Argument("target")),
- SeqPara(
- "Specify which backend to use (" & Mono("jvm-1.5," &
- "msil") & ").",
- "The default value is " & Mono("\"jvm-1.5\"") & " (was " &
- Mono("\"jvm-1.4\"") & " up to Scala version 2.6.1).")),
- Definition(
CmdOption("toolcp", Argument("path")),
"Add to the runner classpath."),
Definition(
@@ -182,19 +175,6 @@ object scalac extends Command {
Section("Advanced Options",
DefinitionList(
Definition(
- CmdOption("Xassem-extdirs", Argument("dirs")),
- "(Requires " & Mono("-target:msil") &
- ") List of directories containing assemblies." &
- " default:" & Mono("lib") & "."),
- Definition(
- CmdOption("Xassem-name", Argument("file")),
- "(Requires " & Mono("-target:msil") &
- ") Name of the output assembly."),
- Definition(
- CmdOption("Xassem-path", Argument("path")),
- "(Requires " & Mono("-target:msil") &
- ") List of assemblies referenced by the program."),
- Definition(
CmdOption("Xcheck-null"),
"Warn upon selection of nullable reference"),
Definition(
@@ -290,10 +270,6 @@ object scalac extends Command {
CmdOption("Xsource-reader", Argument("classname")),
"Specify a custom method for reading source files."),
Definition(
- CmdOption("Xsourcedir", Argument("path")),
- "(Requires " & Mono("-target:msil") &
- ") Mirror source folder structure in output directory.."),
- Definition(
CmdOption("Xverify"),
"Verify generic signatures in generated bytecode."),
Definition(
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/Assembly.java b/src/msil/ch/epfl/lamp/compiler/msil/Assembly.java
deleted file mode 100644
index 59bbeee3a4..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/Assembly.java
+++ /dev/null
@@ -1,253 +0,0 @@
-/*
- * System.Reflection-like API for access to .NET assemblies (DLL & EXE)
- */
-
-
-package ch.epfl.lamp.compiler.msil;
-
-import ch.epfl.lamp.compiler.msil.util.Table;
-import ch.epfl.lamp.compiler.msil.util.Table.AssemblyDef;
-import ch.epfl.lamp.compiler.msil.util.Table.ModuleDef;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.io.File;
-import java.io.FileNotFoundException;
-
-/**
- * Defines an Assembly, which is a reusable, versionable, and self-describing
- * building block of a common language runtime application.
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-public abstract class Assembly extends CustomAttributeProvider {
-
- //##########################################################################
- // static members
-
- // all the assemblies
- public static final HashMap assemblies = new HashMap();
-
- /** Loads an assembly from the specified path. */
- public static Assembly LoadFrom(String assemblyFileName) {
- File afile = new File(assemblyFileName);
- return LoadFrom(afile.getParentFile(), afile.getName());
- }
-
- /** Loads an assembly with the given name from the given directory. */
- public static Assembly LoadFrom(File dir, String name) {
- File file = null;
- PEFile pefile = null;
-// try {
-// if (dir == null)
-// dir = new File(".");
-// dir = dir.getCanonicalFile();
-// } catch (java.io.IOException e) {}
-
- if (name.toUpperCase().endsWith(".EXE") || name.toUpperCase().endsWith(".DLL")) {
- file = new File(dir, name);
- pefile = getPEFile(file);
- name = name.substring(0, name.length() - 4);
- }
-
- File adir = pefile == null ? new File(dir, name) : null;
-
- if (pefile == null) {
- file = new File(dir, name + ".dll");
- pefile = getPEFile(file);
- }
- if (pefile == null) {
- file = new File(dir, name + ".DLL");
- pefile = getPEFile(file);
- }
- if (pefile == null && adir.exists()) {
- file = new File(adir, name + ".dll");
- pefile = getPEFile(file);
- }
- if (pefile == null && adir.exists()) {
- file = new File(adir, name + ".DLL");
- pefile = getPEFile(file);
- }
-
- if (pefile == null) {
- file = new File(dir, name + ".exe");
- pefile = getPEFile(file);
- }
- if (pefile == null) {
- file = new File(dir, name + ".EXE");
- pefile = getPEFile(file);
- }
- if (pefile == null && adir.exists()) {
- file = new File(adir, name + ".exe");
- pefile = getPEFile(file);
- }
- if (pefile == null && adir.exists()) {
- file = new File(adir, name + ".EXE");
- pefile = getPEFile(file);
- }
-
- if (pefile == null)
- throw new RuntimeException("Cannot find assembly " + new File(dir, name));
- return getPEAssembly(pefile);
- }
-
- private static Assembly getPEAssembly(PEFile pefile) {
- AssemblyDef assem = pefile.AssemblyDef;
- if (assem == null)
- throw new RuntimeException("File " + pefile
- + " does not contain a manifest");
- assem.readRow(1);
- String name = pefile.getString(assem.Name);
- Assembly a = (Assembly) assemblies.get(name);
- if (a != null) {
- return a;
- }
-
- AssemblyName an = new AssemblyName();
- an.Name = pefile.getString(assem.Name);
- an.Version = new Version(assem.MajorVersion, assem.MinorVersion,
- assem.BuildNumber, assem.RevisionNumber);
- an.SetPublicKey(pefile.getBlob(assem.PublicKey));
- return new PEAssembly(pefile, an);
- }
-
- protected static PEFile getPEFile(File f) {
- PEFile pefile = null;
- try { pefile = new PEFile(f.getAbsolutePath()); }
- catch (FileNotFoundException e) {}
- catch (RuntimeException e) {
- java.lang.System.out.println("swallowed RuntimeException at getPEFile");
- }
- return pefile;
- }
-
- //##########################################################################
- // public fields
-
- /** The entry point of this assembly. */
- public MethodInfo EntryPoint;
-
- /** the display name of the assembly. */
- public final String FullName;
-
- //##########################################################################
- // constructor
-
- protected Assembly(AssemblyName an, boolean external) {
- assemblyName = an;
- FullName = an.toString();
- if(external) {
- assemblies.put(an.Name, this);
- }
- //System.out.println("assemblies after adding the current one: " + assemblies);
- }
-
- protected Assembly(AssemblyName an) {
- this(an, false);
- }
-
- protected static Assembly getAssembly(String name) {
- return (Assembly) assemblies.get(name);
- }
-
- //##########################################################################
- // instrumental methods
-
- /** @return the file from which this assembly was loaded. */
- public File getFile() {
- throw new RuntimeException("Not supported");
- }
-
- /** Gets the specified module in this assembly. Works on filenames. */
- public Module GetModule(String name) {
- initModules();
- return (Module)modulesMap.get(name);
- }
-
- /** Get all the modules of the assembly. */
- public Module[] GetModules() {
- initModules();
- return (Module[])modulesMap.values().
- toArray(new Module[modulesMap.size()]);
- }
-
- /** Get the corresponding type. */
- public Type GetType(String name) {
- initModules();
- Iterator modules = modulesMap.values().iterator();
- Type t = null;
- while (t == null && modules.hasNext()) {
- t = ((Module)modules.next()).GetType(name);
- }
- return t;
- }
-
- /** @return an array of all types defined in the assembly. */
- public synchronized Type[] GetTypes() {
- if (types != null)
- return (Type[])types.clone();
- initModules();
-
- Iterator modules = modulesMap.values().iterator();
- Type[] newTypes = ((Module)modules.next()).GetTypes();
- while (modules.hasNext()) {
- Module module = (Module)modules.next();
- Type[] mtypes = module.GetTypes();
- Type[] oldTypes = newTypes;
- newTypes = new Type[oldTypes.length + mtypes.length];
- System.arraycopy(oldTypes, 0, newTypes, 0, oldTypes.length);
- System.arraycopy(mtypes, 0, newTypes, oldTypes.length, mtypes.length);
- }
- types = newTypes;
- return (Type[]) types.clone();
- }
-
- public AssemblyName GetName() {
- return assemblyName;
- }
-
- public String toString() {
- return FullName;
- }
-
- //##########################################################################
- // protected members
-
- // the assembly name
- protected final AssemblyName assemblyName;
-
- // all the types exported by the assembly
- protected Type[] types = null;
-
- // the module defined in this assembly (only one right now)
- private final HashMap/*<String, Module>*/ modulesMap = new HashMap();
-
- protected void addType(Type type) {
- Type.addType(type);
- }
-
- protected void addModule(String name, Module module) {
- modulesMap.put(name, module);
- }
-
- private boolean initModules = true;
- protected final void initModules() {
- if (initModules) {
- loadModules();
- initModules = false;
- }
- }
-
- /** used for lazy construction of the Assembly. */
- protected abstract void loadModules();
-
- void dumpTypes() {
- Type[] types = GetTypes();
- for (int i = 0; i < types.length; i++)
- System.out.println(types[i]);
- }
-
- //##########################################################################
-
-} // class Assembly
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/AssemblyName.java b/src/msil/ch/epfl/lamp/compiler/msil/AssemblyName.java
deleted file mode 100644
index acdcb32e33..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/AssemblyName.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * System.Reflection-like API for access to .NET assemblies (DLL & EXE)
- */
-
-
-package ch.epfl.lamp.compiler.msil;
-
-import javax.crypto.Mac;
-
-import java.security.MessageDigest;
-
-import ch.epfl.lamp.compiler.msil.util.Table;
-
-/**
- * Fully describes an assembly's unique identity.
- * Right now it's only the name
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-public class AssemblyName {
-
- //##########################################################################
- // public interface
-
- /** The simple, unencrypted name of the assembly. */
- public String Name;
-
- /**
- * Gets or sets the major, minor, revision, and build numbers
- * of the assembly.
- */
- public Version Version;
-
- /**
- * Gets a strong name consisting of a public key, a given name,
- * and version parts.
- */
- public byte[] GetPublicKeyToken() {
- return publicKeyToken == null ? null : (byte[]) publicKeyToken.clone();
- }
-
- /**
- * Sets a strong name consisting of a public key, a given name,
- * and version parts.
- */
- public void SetPublicKeyToken(byte[] key) {
- this.publicKeyToken = key.length == 0 ? null : (byte[]) key.clone();
- }
-
- /**
- * Returns the public key identifying the originator of the assembly.
- */
- public byte[] GetPublicKey() {
- return publicKey == null ? null : (byte[]) publicKey.clone();
- }
-
- /**
- * Sets the public key identifying the originator of the assembly.
- */
- public void SetPublicKey(byte[] key) {
- if (key.length > 0) {
- this.publicKey = (byte[]) key.clone();
- byte[] hash = sha.digest(key);
- byte[] keyToken = new byte[8];
- for (int i = 0; i < keyToken.length; i++)
- keyToken[i] = hash[hash.length - 1 - i];
- this.publicKeyToken = keyToken;
- //System.out.println("Pubic key and key token of assembly " + this + ":");
- //System.out.println("\tPublic key = " + Table.bytes2hex(key));
- //System.out.println("\tKey token = " + Table.bytes2hex(keyToken));
- }
- }
-
- public String toString() {
- return Name + ", Version=" + Version;
- }
-
- //##########################################################################
-
- private byte[] publicKeyToken;
-
- private byte[] publicKey;
-
- private static final MessageDigest sha;
- static {
- MessageDigest md = null;
- try {
- md = MessageDigest.getInstance("SHA");
- } catch (java.security.NoSuchAlgorithmException e) {}
- sha = md;
- }
-
- //##########################################################################
-
-} // class AssemblyName
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/Attribute.java b/src/msil/ch/epfl/lamp/compiler/msil/Attribute.java
deleted file mode 100644
index 0f2c4e6764..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/Attribute.java
+++ /dev/null
@@ -1,654 +0,0 @@
-/*
- * System.Reflection-like API for access to .NET assemblies (DLL & EXE)
- */
-
-
-package ch.epfl.lamp.compiler.msil;
-
-import ch.epfl.lamp.compiler.msil.util.Signature;
-
-import java.util.Map;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.Iterator;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.io.UnsupportedEncodingException;
-
-/**
- * Describes custom attribute instances.
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-public class Attribute {
-
- //##########################################################################
-
- private final ConstructorInfo constr;
-
- private final byte[] value;
-
- Attribute(ConstructorInfo constr, byte[] value) {
- assert constr != null;
- this.constr = constr;
- assert value != null : constr.toString();
- this.value = value;
- }
-
- //##########################################################################
- // public interface
-
- /** @return the type (class) of the attribute. */
- public Type GetType() { return constr.DeclaringType; }
-
- /** @return the constructor of this attribute. */
- public ConstructorInfo getConstructor() {
- return constr;
- }
-
- /** @return the Blob with serialized constructor & named arguments. */
- public byte[] getValue() {
- byte[] value = new byte[this.value.length];
- System.arraycopy(this.value, 0, value, 0, value.length);
- return value;
- }
-
- /**@return an array with the arguments to the attribute's constructor. */
- public Object[] getConstructorArguments() {
- parseBlob();
- Object[] cas = new Object[constrArgs.length];
- System.arraycopy(constrArgs, 0, cas, 0, cas.length);
- return cas;
- }
-
- /** @return the named argument with the given name. */
- public NamedArgument getNamedArgument(String name) {
- return (NamedArgument)namedArgs.get(name);
- }
-
- /** @return an array of all named arguments for this attribute. */
- public NamedArgument[] getNamedArguments() {
- NamedArgument[] nargs =
- (NamedArgument[])namedArgs.values().toArray(NamedArgument.EMPTY);
- return nargs;
- }
-
- /** @return a string representation of this attribute. */
- public String toString() {
- parseBlob();
- ParameterInfo[] params = constr.GetParameters();
- assert params.length == constrArgs.length : this.constr;
- StringBuffer str = new StringBuffer();
- str.append('[');
- str.append(constr.DeclaringType.FullName);
- str.append('(');
- for (int i = 0; i < constrArgs.length; i++) {
- if (i > 0)
- str.append(", ");
- Type t = params[i].ParameterType;
- if (t.IsEnum()) {
- str.append('(');
- str.append(t.FullName);
- str.append(')');
- }
- formatValue(str, constrArgs[i]);
- }
- NamedArgument[] nargs = getNamedArguments();
- for (int i = 0; i < nargs.length; i++) {
- str.append(", ").append(nargs[i]);
- }
- str.append(")]");
- return str.toString();
- }
-
- //#########################################################################
-
- private static final Map type2id = new HashMap();
- private static final Map id2type = new HashMap();
- static {
- map("Boolean", Signature.ELEMENT_TYPE_BOOLEAN);
- map("Char", Signature.ELEMENT_TYPE_CHAR);
- map("SByte", Signature.ELEMENT_TYPE_I1);
- map("Byte", Signature.ELEMENT_TYPE_U1);
- map("Int16", Signature.ELEMENT_TYPE_I2);
- map("UInt16", Signature.ELEMENT_TYPE_U2);
- map("Int32", Signature.ELEMENT_TYPE_I4);
- map("UInt32", Signature.ELEMENT_TYPE_U4);
- map("Int64", Signature.ELEMENT_TYPE_I8);
- map("UInt64", Signature.ELEMENT_TYPE_U8);
- map("Single", Signature.ELEMENT_TYPE_R4);
- map("Double", Signature.ELEMENT_TYPE_R8);
- map("String", Signature.ELEMENT_TYPE_STRING);
- map("Type", Signature.X_ELEMENT_TYPE_TYPE);
- map("Object", Signature.ELEMENT_TYPE_OBJECT);
- }
- private static void map(String type, int id) {
- Type t = Type.GetType("System." + type);
- assert type != null : type + " -> " + id;
- Integer i = new Integer(id);
- type2id.put(t, i);
- id2type.put(i, t);
- }
- private static int getTypeId(Type type) {
- Integer id = (Integer)type2id.get(type);
- assert id != null : type;
- return id.intValue();
- }
-
- private Object[] constrArgs;
- private Map namedArgs;
- private ByteBuffer buf;
-
- private void parseBlob() {
- try { parseBlob0(); }
- catch (RuntimeException e) {
- throw new RuntimeException(PEFile.bytes2hex(value), e);
- }
- }
-
- private void parseBlob0() {
- if (buf != null)
- return;
- buf = ByteBuffer.wrap(value); // Sec. 23.3 in Partition II of CLR Spec.
- buf.order(ByteOrder.LITTLE_ENDIAN);
-
- short sig = buf.getShort(); // Prolog
- assert sig == 1 : PEFile.bytes2hex(value);
- ParameterInfo[] params = constr.GetParameters();
- constrArgs = new Object[params.length];
- for (int i = 0; i < params.length; i++) {
- constrArgs[i] = parseFixedArg(params[i].ParameterType); // FixedArg
- }
-
- int ncount = buf.getShort(); // NumNamed
- namedArgs = new LinkedHashMap();
- for (int i = 0; i < ncount; i++) {
- int designator = buf.get(); // designator one of 0x53 (FIELD) or 0x54 (PROPERTY)
- assert designator == Signature.X_ELEMENT_KIND_FIELD
- || designator == Signature.X_ELEMENT_KIND_PROPERTY
- : "0x" + PEFile.byte2hex(designator);
- Type type = parseFieldOrPropTypeInNamedArg(); // FieldOrPropType
- String name = parseString(); // FieldOrPropName
- Object value = parseFixedArg(type); // FixedArg
- NamedArgument narg =
- new NamedArgument(designator, name, type, value);
- namedArgs.put(name, narg);
- }
- }
-
- private Object parseFixedArg(Type type) {
- if (type.IsArray())
- return parseArray(type.GetElementType());
- else
- return parseElem(type);
- }
-
- /* indicates whether the "simple" case (the other is "enum") of the first row
- in the Elem production should be taken. */
- private boolean isSimpleElem(Type type) {
- if(!type2id.containsKey(type)) return false;
- int id = getTypeId(type);
- switch(id){
- case Signature.ELEMENT_TYPE_STRING:
- case Signature.X_ELEMENT_TYPE_TYPE:
- case Signature.ELEMENT_TYPE_OBJECT:
- return false;
- default:
- return true;
- }
- }
-
- /* indicates whether the second row in the Elem production
- should be taken (and more specifically, "string" case within that row). */
- private boolean isStringElem(Type type) {
- if(!type2id.containsKey(type)) return false;
- int id = getTypeId(type);
- return id == Signature.ELEMENT_TYPE_STRING;
- }
-
- /* indicates whether the second row in the Elem production
- should be taken (and more specifically, "type" case within that row). */
- private boolean isTypeElem(Type type) {
- if(!type2id.containsKey(type)) return false;
- int id = getTypeId(type);
- return id == Signature.X_ELEMENT_TYPE_TYPE;
- }
-
- /* indicates whether the third row in the Elem production
- should be taken (and more specifically, "boxed" case within that row). */
- private boolean isSystemObject(Type type) {
- if(!type2id.containsKey(type)) return false;
- int id = getTypeId(type);
- return id == Signature.ELEMENT_TYPE_OBJECT;
- }
-
- private Object parseElem(Type type) {
- // simple or enum
- if (isSimpleElem(type)) return parseVal(getTypeId(type));
- if (type.IsEnum()) return parseVal(getTypeId(type.getUnderlyingType()));
- // string or type
- if (isStringElem(type)) return parseString();
- if (isTypeElem(type)) return getTypeFromSerString();
- // boxed valuetype, please notice that a "simple" boxed valuetype is preceded by 0x51
- if (isSystemObject(type)) {
- Type boxedT = parse0x51();
- if(boxedT.IsEnum()) {
- return new BoxedArgument(boxedT, parseVal(getTypeId(boxedT.getUnderlyingType())));
- } else {
- return new BoxedArgument(boxedT, parseVal(getTypeId(boxedT))); // TODO dead code?
- }
- } else {
- Type boxedT = parseType();
- return parseVal(getTypeId(boxedT));
- }
- }
-
- /* this does not parse an Elem, but a made-up production (Element). Don't read too much into this method name! */
- private Object parseVal(int id) {
- switch (id) {
- case Signature.ELEMENT_TYPE_BOOLEAN:
- return new Boolean(buf.get() == 0 ? false : true);
- case Signature.ELEMENT_TYPE_CHAR:
- return new Character(buf.getChar());
- case Signature.ELEMENT_TYPE_I1:
- case Signature.ELEMENT_TYPE_U1:
- return new Byte(buf.get()); // TODO U1 not the same as I1
- case Signature.ELEMENT_TYPE_I2:
- case Signature.ELEMENT_TYPE_U2:
- return new Short(buf.getShort()); // TODO U2 not the same as I2
- case Signature.ELEMENT_TYPE_I4:
- case Signature.ELEMENT_TYPE_U4:
- return new Integer(buf.getInt()); // TODO U4 not the same as I4
- case Signature.ELEMENT_TYPE_I8:
- case Signature.ELEMENT_TYPE_U8:
- return new Long(buf.getLong()); // TODO U8 not the same as I8
- case Signature.ELEMENT_TYPE_R4:
- return new Float(buf.getFloat());
- case Signature.ELEMENT_TYPE_R8:
- return new Double(buf.getDouble());
- case Signature.X_ELEMENT_TYPE_TYPE:
- return getTypeFromSerString();
- case Signature.ELEMENT_TYPE_STRING:
- return parseString();
- default:
- throw new RuntimeException("Shouldn't have called parseVal with: " + id);
- }
- }
-
- private Object parseArray(Type type) {
- if (type.IsEnum())
- return parseArray(type.getUnderlyingType());
- return parseArray(getTypeId(type));
- }
-
- private Object parseArray(int id) {
- switch (id) {
- case Signature.ELEMENT_TYPE_BOOLEAN:
- return parseBooleanArray();
- case Signature.ELEMENT_TYPE_CHAR:
- return parseCharArray();
- case Signature.ELEMENT_TYPE_I1:
- case Signature.ELEMENT_TYPE_U1: // TODO U1 not the same as I1
- return parseByteArray();
- case Signature.ELEMENT_TYPE_I2:
- case Signature.ELEMENT_TYPE_U2:
- return parseShortArray();
- case Signature.ELEMENT_TYPE_I4:
- case Signature.ELEMENT_TYPE_U4:
- return parseIntArray();
- case Signature.ELEMENT_TYPE_I8:
- case Signature.ELEMENT_TYPE_U8:
- return parseLongArray();
- case Signature.ELEMENT_TYPE_R4:
- return parseFloatArray();
- case Signature.ELEMENT_TYPE_R8:
- return parseDoubleArray();
- case Signature.ELEMENT_TYPE_STRING:
- return parseStringArray();
- case Signature.X_ELEMENT_TYPE_ENUM:
- return parseArray(getTypeFromSerString());
- default:
- throw new RuntimeException("Unknown type id: " + id);
- }
- }
-
- private Type parseType() { // FieldOrPropType, Sec. 23.3 in Partition II of CLR Spec.
- int id = buf.get();
- switch (id) {
- case Signature.ELEMENT_TYPE_SZARRAY:
- Type arrT = Type.mkArray(parseType(), 1);
- return arrT;
- case Signature.X_ELEMENT_TYPE_ENUM:
- String enumName = parseString();
- Type enumT = Type.getType(enumName);
- return enumT;
- default:
- Type t = (Type)id2type.get(new Integer(id));
- assert t != null : PEFile.byte2hex(id);
- return t;
- }
- }
-
- private Type parse0x51() {
- int id = buf.get();
- switch (id) {
- case 0x51:
- return parse0x51();
- case Signature.ELEMENT_TYPE_SZARRAY:
- Type arrT = Type.mkArray(parseType(), 1);
- return arrT;
- case Signature.X_ELEMENT_TYPE_ENUM:
- String enumName = parseString();
- Type enumT = Type.getType(enumName);
- return enumT;
- default:
- Type t = (Type)id2type.get(new Integer(id));
- assert t != null : PEFile.byte2hex(id);
- return t;
- }
- }
-
-
- private Type parseFieldOrPropTypeInNamedArg() { // FieldOrPropType, Sec. 23.3 in Partition II of CLR Spec.
- int id = buf.get();
- switch (id) {
- case 0x51:
- return (Type)(id2type.get(new Integer(Signature.ELEMENT_TYPE_OBJECT)));
- // TODO remove case Signature.ELEMENT_TYPE_SZARRAY:
- // Type arrT = Type.mkArray(parseType(), 1);
- // return arrT;
- case Signature.X_ELEMENT_TYPE_ENUM:
- String enumName = parseString();
- Type enumT = Type.getType(enumName); // TODO this "lookup" only covers already-loaded assemblies.
- return enumT; // TODO null as return value (due to the above) spells trouble later.
- default:
- Type t = (Type)id2type.get(new Integer(id));
- assert t != null : PEFile.byte2hex(id);
- return t;
- }
- }
-
- private Type getTypeFromSerString() {
- String typename = parseString();
- int i = typename.indexOf(',');
- /* fully qualified assembly name follows. Just strip it on the assumption that
- the assembly is referenced in the externs and the type will be found. */
- String name = (i < 0) ? typename : typename.substring(0, i);
- Type t = Type.GetType(name);
- if (t == null && i > 0) {
- int j = typename.indexOf(',', i + 1);
- if (j > 0) {
- String assemName = typename.substring(i + 1, j);
- try {
- Assembly.LoadFrom(assemName);
- } catch (Throwable e) {
- throw new RuntimeException(typename, e);
- }
- t = Type.GetType(name);
- }
- }
- assert t != null : typename;
- return t;
- }
-
- private boolean[] parseBooleanArray() {
- boolean[] arr = new boolean[buf.getInt()];
- for (int i = 0; i < arr.length; i++)
- arr[i] = buf.get() == 0 ? false : true;
- return arr;
- }
-
- private char[] parseCharArray() {
- char[] arr = new char[buf.getInt()];
- for (int i = 0; i < arr.length; i++)
- arr[i] = buf.getChar();
- return arr;
- }
-
- private byte[] parseByteArray() {
- byte[] arr = new byte[buf.getInt()];
- for (int i = 0; i < arr.length; i++)
- arr[i] = buf.get();
- return arr;
- }
-
- private short[] parseShortArray() {
- short[] arr = new short[buf.getInt()];
- for (int i = 0; i < arr.length; i++)
- arr[i] = buf.getShort();
- return arr;
- }
-
- private int[] parseIntArray() {
- int[] arr = new int[buf.getInt()];
- for (int i = 0; i < arr.length; i++)
- arr[i] = buf.getInt();
- return arr;
- }
-
- private long[] parseLongArray() {
- long[] arr = new long[buf.getInt()];
- for (int i = 0; i < arr.length; i++)
- arr[i] = buf.getLong();
- return arr;
- }
-
- private float[] parseFloatArray() {
- float[] arr = new float[buf.getInt()];
- for (int i = 0; i < arr.length; i++)
- arr[i] = buf.getFloat();
- return arr;
- }
-
- private double[] parseDoubleArray() {
- double[] arr = new double[buf.getInt()];
- for (int i = 0; i < arr.length; i++)
- arr[i] = buf.getDouble();
- return arr;
- }
-
- private String[] parseStringArray() {
- String[] arr = new String[buf.getInt()];
- for (int i = 0; i < arr.length; i++)
- arr[i] = parseString();
- return arr;
- }
-
- private String parseString() { // SerString convention
- String str = null;
- int length = parseLength();
- if (length < 0)
- return null;
- try { str = new String(value, buf.position(), length, "UTF-8" ); }
- catch (UnsupportedEncodingException e) { throw new Error(e); }
- buf.position(buf.position() + length);
- return str;
- }
-
- private int getByte() {
- return (buf.get() + 0x0100) & 0xff;
- }
-
- public int parseLength() {
- int length = getByte();
- // check for invalid length format: the first, second or third
- // most significant bits should be 0; if all are 1 the length is invalid.
- if ((length & 0xe0) == 0xe0)
- return -1;
- if ((length & 0x80) != 0) {
- length = ((length & 0x7f) << 8) | getByte();
- if ((length & 0x4000) != 0)
- length = ((length & 0x3fff) << 16) | (getByte()<<8) | getByte();
- }
- return length;
- }
-
- //##########################################################################
- private static void formatValue(StringBuffer str, Object o) {
- Class c = (o == null) ? null : o.getClass();
- if (c == null) {
- str.append("<null>");
- } else if (c == String.class) {
- str.append('"');
- str.append(o);
- str.append('"');
- } else if (c == Character.class) {
- str.append('\'');
- str.append(o);
- str.append('\'');
- } else if (c == boolean[].class) {
- str.append("new boolean[] {");
- boolean[] arr = (boolean[])o;
- for (int i = 0; i < arr.length; i++) {
- if (i > 0) str.append(", ");
- str.append(arr[i]);
- }
- str.append('}');
- } else if (c == char[].class) {
- str.append("new short[] {");
- short[] arr = (short[])o;
- for (int i = 0; i < arr.length; i++) {
- if (i > 0) str.append(", ");
- str.append(arr[i]);
- }
- str.append('}');
- } else if (c == byte[].class) {
- str.append("new byte[] {");
- byte[] arr = (byte[])o;
- for (int i = 0; i < arr.length; i++) {
- if (i > 0) str.append(", ");
- str.append(arr[i]);
- }
- str.append('}');
- } else if (c == short[].class) {
- str.append("new short[] {");
- short[] arr = (short[])o;
- for (int i = 0; i < arr.length; i++) {
- if (i > 0) str.append(", ");
- str.append(arr[i]);
- }
- str.append('}');
- } else if (c == int[].class) {
- str.append("new int[] {");
- int[] arr = (int[])o;
- for (int i = 0; i < arr.length; i++) {
- if (i > 0) str.append(", ");
- str.append(arr[i]);
- }
- str.append('}');
- } else if (c == long[].class) {
- str.append("new long[] {");
- long[] arr = (long[])o;
- for (int i = 0; i < arr.length; i++) {
- if (i > 0) str.append(", ");
- str.append(arr[i]);
- }
- str.append('}');
- } else if (c == float[].class) {
- str.append("new float[] {");
- float[] arr = (float[])o;
- for (int i = 0; i < arr.length; i++) {
- if (i > 0) str.append(", ");
- str.append(arr[i]);
- }
- str.append('}');
- } else if (c == double[].class) {
- str.append("new double[] {");
- double[] arr = (double[])o;
- for (int i = 0; i < arr.length; i++) {
- if (i > 0) str.append(", ");
- str.append(arr[i]);
- }
- str.append('}');
- } else if (c == String[].class) {
- str.append("new String[] {");
- String[] arr = (String[])o;
- for (int i = 0; i < arr.length; i++) {
- if (i > 0) str.append(", ");
- formatValue(str, arr[i]);
- }
- str.append('}');
- } else if (o instanceof Type) {
- str.append("typeof(");
- str.append(o);
- str.append(")");
- } else
- str.append(o);
- }
-
- //##########################################################################
-
- /** Represents named arguments (assigned outside of the constructor)
- * of a custom attribute
- */
- public static class NamedArgument {
-
- /** Designates if the named argument corresponds to a field or property.
- * Possible values:
- * Signature.X_ELEMENT_KIND_FIELD = 0x53
- * Signature.X_ELEMENT_KIND_PROPERTY = 0x54
- */
- public final int designator;
-
- /** The name of the field/property. */
- public final String name;
-
- /** Type of the field/property. */
- public final Type type;
-
- /** The value for the field/property. */
- public final Object value;
-
- /** An empty array NamedArgument. */
- public static final NamedArgument[] EMPTY = new NamedArgument[0];
-
- public NamedArgument(int designator, String name,Type type,Object value)
- {
- this.designator = designator;
- this.name = name;
- this.type = type;
- this.value = value;
- }
-
- /** @return <b>true</b> if the named argument specifies a field;
- * <b>false<b> otherwise.
- */
- public boolean isField() {
- return designator == Signature.X_ELEMENT_KIND_FIELD;
- }
-
- /** @return <b>true</b> if the named argument specifies a property;
- * <b>false<b> otherwise.
- */
- public boolean isProperty() {
- return designator == Signature.X_ELEMENT_KIND_PROPERTY;
- }
-
- /** @return a string representation of the named argument. */
- public String toString() {
- StringBuffer str = new StringBuffer(name);
- str.append(" = ");
- if (type.IsEnum())
- str.append('(').append(type.FullName).append(')');
- formatValue(str, value);
- return str.toString();
- }
- }
-
- //##########################################################################
-
- public static class BoxedArgument {
- public final Type type;
- public final Object value;
- public BoxedArgument(Type type, Object value) {
- this.type = type; this.value = value;
- }
- public String toString() {
- return "(" + type.FullName + ")" + value;
- }
- }
-
- //##########################################################################
-
-} // class Attribute
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/BindingFlags.java b/src/msil/ch/epfl/lamp/compiler/msil/BindingFlags.java
deleted file mode 100644
index cac2319b50..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/BindingFlags.java
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- * System.Reflection-like API for access to .NET assemblies (DLL & EXE)
- */
-
-
-package ch.epfl.lamp.compiler.msil;
-
-/**
- * Specifies flags that control binding and the way in which
- * the search for members and types is conducted by reflection.
- *
- * Note: You must specify Instance or Static along with Public or NonPublic
- * or no members will be returned.
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-public abstract class BindingFlags {
-
- //##########################################################################
-
- // disallows extending the class;
- private BindingFlags() {}
-
- /**
- * Specifies no binding flag.
- */
- public static final int Default = 0x0000;
-
- /**
- * Specifies that the case of the member name should not be considered
- * when binding.
- */
- public static final int IgnoreCase = 0x0001;
-
- /**
- * Specifies that only members declared at the level of the supplied type's
- * hierarchy should be considered. Inherited members are not considered.
- */
- public static final int DeclaredOnly = 0x0002;
-
- /**
- * Specifies that instance members are to be included in the search.
- */
- public static final int Instance = 0x0004;
-
- /**
- * Specifies that static members are to be included in the search.
- */
- public static final int Static = 0x0008;
-
- /**
- * Specifies that public members are to be included in the search.
- */
- public static final int Public = 0x0010;
-
- /**
- * Specifies that non-public members are to be included in the search.
- */
- public static final int NonPublic = 0x0020;
-
- /**
- * Specifies that static members up the hierarchy should be returned.
- * Static members include fields, methods, events, and properties.
- * Nested types are not returned.
- */
- public static final int FlattenHierarchy = 0x0040;
-
- /**
- * Specifies that a method is to be invoked. This may not be a constructor
- * or a type initializer.
- */
- public static final int InvokeMethod = 0x0100;
-
- /**
- * Specifies that Reflection should create an instance of
- * the specified type. Calls the constructor that matches
- * the given arguments. The supplied member name is ignored.
- * If the type of lookup is not specified, (Instance | Public)
- * will apply. It is not possible to call a type initializer.
- */
- public static final int CreateInstance = 0x0200;
-
- /**
- * Specifies that the value of the specified field should be returned.
- */
- public static final int GetField = 0x0400;
-
- /**
- * Specifies that the value of the specified field should be set.
- */
- public static final int SetField = 0x0800;
-
- /**
- * Specifies that the value of the specified property should be returned.
- */
- public static final int GetProperty = 0x1000;
-
- /**
- * Specifies that the value of the specified property should be set.
- * For COM properties, specifying this binding flag is equivalent to
- * specifying PutDispProperty and PutRefDispProperty.
- */
- public static final int SetProperty = 0x2000;
-
- /**
- * Specifies that the PROPPUT member on a COM object should be invoked.
- * PROPPUT specifies a property-setting function that uses a value.
- * Use PutDispProperty if a property has both PROPPUT and PROPPUTREF
- * and you need to distinguish which one is called.
- */
- public static final int PutDispProperty = 0x4000;
-
-
- /**
- * Specifies that the PROPPUTREF member on a COM object should be invoked.
- * PROPPUTREF specifies a property-setting function that uses a reference
- * instead of a value. Use PutRefDispProperty if a property has both
- * PROPPUT and PROPPUTREF and you need to distinguish which one is called.
- */
- public static final int PutRefDispProperty = 0x8000;
-
- /**
- * Specifies that types of the supplied arguments must exactly match
- * the types of the corresponding formal parameters. Reflection
- * throws an exception if the caller supplies a non-null Binder object,
- * since that implies that the caller is supplying BindToXXX
- * implementations that will pick the appropriate method.
- * Reflection models the accessibility rules of the common type system.
- * For example, if the caller is in the same assembly, the caller
- * does not need special permissions for internal members. Otherwise,
- * the caller needs ReflectionPermission. This is consistent with
- * lookup of members that are protected, private, and so on.
- * The general principle is that ChangeType should perform only
- * widening coercions, which never lose data. An example of a
- * widening coercion is coercing a value that is a 32-bit signed integer
- * to a value that is a 64-bit signed integer. This is distinguished
- * from a narrowing coercion, which may lose data. An example of
- * a narrowing coercion is coercing a 64-bit signed integer to
- * a 32-bit signed integer.
- * The default binder ignores this flag, while custom binders can
- * implement the semantics of this flag.
- */
- public static final int ExactBinding = 0x10000;
-
- /**
- * Used in COM interop to specify that the return value of the member
- * can be ignored.
- */
- public static final int IgnoreReturn = 0x100000 ;
-
- /**
- * Returns the set of members whose parameter count matches the number
- * of supplied arguments. This binding flag is used for methods with
- * parameters that have default values and methods with variable arguments
- * (varargs). This flag should only be used with Type.InvokeMember.
- * Parameters with default values are used only in calls where trailing
- * arguments are omitted. They must be the last arguments.
- */
- public static final int OptionalParamBinding = 0x40000;
-
- /**
- * Not implemented.
- */
- public static final int SuppressChangeType = 0x20000;
-
- //##########################################################################
-
-} // class BindingFlags
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/CallingConventions.java b/src/msil/ch/epfl/lamp/compiler/msil/CallingConventions.java
deleted file mode 100644
index 50bf9fb5d5..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/CallingConventions.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * System.Reflection-like API for access to .NET assemblies (DLL & EXE)
- */
-
-
-package ch.epfl.lamp.compiler.msil;
-
-
-/**
- * Calling conventions
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-public abstract class CallingConventions {
-
- //########################################################################
-
- /**
- * Specifies the default calling convention as determined by the
- * common language runtime.
- */
- public static final short Standard = (short) 0x0001;
-
- /**
- * Specifies the calling convention for methods with variable arguments.
- */
- public static final short VarArgs = (short) 0x0002;
-
- /**
- * Specifies that either the Standard or the VarArgs calling
- * convention may be used.
- */
- public static final short Any = Standard | VarArgs;
-
- /**
- * Specifies an instance or virtual method (not a static method).
- * At run-time, the called method is passed a pointer to the target
- * object as its first argument (the this pointer). The signature
- * stored in metadata does not include the type of this first argument,
- * because the method is known and its owner class can be discovered
- * from metadata.
- */
- public static final short HasThis = (short) 0x0020;
-
- /**
- * Specifies that the signature is a function-pointer signature,
- * representing a call to an instance or virtual method (not a static
- * method). If ExplicitThis is set, HasThis must also be set. The first
- * argument passed to the called method is still a this pointer, but the
- * type of the first argument is now unknown. Therefore, a token that
- * describes the type (or class) of the this pointer is explicitly stored
- * into its metadata signature.
- */
- public static final short ExplicitThis = (short) 0x0040;
-
- //########################################################################
-
- private CallingConventions() {}
-
- public static String toString(int callConv) {
- StringBuffer s = new StringBuffer();
-
- if ((callConv & HasThis) != 0) {
- s.append("instance");
- if ((callConv & ExplicitThis) != 0)
- s.append(" explicit");
- }
-
- return s.toString();
- }
-
- //##########################################################################
-
-} // class CallingConventions
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/ConstructedType.java b/src/msil/ch/epfl/lamp/compiler/msil/ConstructedType.java
deleted file mode 100644
index 8c82cb4876..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/ConstructedType.java
+++ /dev/null
@@ -1,48 +0,0 @@
-package ch.epfl.lamp.compiler.msil;
-
-import java.util.Arrays;
-
-/* The only reason for ConstructedType to extend Type is complying with existing code
- (e.g., caseFieldBuilder in ILPrinterVisitor) expecting a Type.
- */
-public class ConstructedType extends Type {
-
- public final Type instantiatedType;
- public final Type[] typeArgs;
-
- public ConstructedType(Type instantiatedType, Type[] typeArgs) {
- super(instantiatedType.Module, instantiatedType.Attributes, "", null, null, null, instantiatedType.auxAttr /*AuxAttr.None*/ , null);
- this.instantiatedType = instantiatedType;
- this.typeArgs = typeArgs;
- }
-
- public String toString() {
- String res = instantiatedType.toString() + "[";
- for (int i = 0; i < typeArgs.length; i++) {
- res = res + typeArgs[i].toString();
- if(i + 1 < typeArgs.length) {
- res = res + ", ";
- }
- }
- return res + "]";
- }
-
-
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
-
- ConstructedType that = (ConstructedType) o;
-
- if (!instantiatedType.equals(that.instantiatedType)) return false;
- if (!Arrays.equals(typeArgs, that.typeArgs)) return false;
-
- return true;
- }
-
- public int hashCode() {
- int result = instantiatedType.hashCode();
- result = 31 * result + Arrays.hashCode(typeArgs);
- return result;
- }
-}
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/ConstructorInfo.java b/src/msil/ch/epfl/lamp/compiler/msil/ConstructorInfo.java
deleted file mode 100644
index 69f5d6d32a..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/ConstructorInfo.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * System.Reflection-like API for access to .NET assemblies (DLL & EXE)
- */
-
-
-package ch.epfl.lamp.compiler.msil;
-
-/**
- * Discovers the attributes of a class constructor and provides
- * access to constructor metadata.
- * ConstructorInfo is used to discover the attributes of a constructor
- * as well as to invoke a constructor. Objects are created by invoking
- * either the GetConstructors or GetConstructor method of a Type object.
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-public class ConstructorInfo extends MethodBase {
- //##########################################################################
-
- public final int MemberType() { return MemberTypes.Constructor; }
-
- public final boolean IsConstructor() { return true; }
-
- protected static final String CTOR = ".ctor";
- protected static final String CCTOR = ".cctor";
- protected static final ConstructorInfo[] EMPTY_ARRAY = new ConstructorInfo[0];
-
- protected static String getName(int attrs) {
- return (attrs & MethodAttributes.Static) == 0 ? CTOR : CCTOR;
- }
-
- /** Public constructors */
-
- public ConstructorInfo(Type declType, int attrs, Type[] paramTypes) {
- super(getName(attrs), declType, attrs, paramTypes);
- assert declType != null : "Owner can't be 'null' for a constructor!";
- }
-
- public ConstructorInfo(Type declType, int attrs, ParameterInfo[] params)
- {
- super(getName(attrs), declType, attrs, params);
- assert declType != null : "Owner can't be 'null' for a constructor!";
- }
-
-
- public String toString() {
- return MethodAttributes.toString(Attributes) + " " + Type.VOID() +
- " " + DeclaringType.FullName + "::" + Name + params2String();
- }
-
- //##########################################################################
-
-} // class ConstructorInfo
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/CustomAttributeProvider.java b/src/msil/ch/epfl/lamp/compiler/msil/CustomAttributeProvider.java
deleted file mode 100644
index 0e58c18114..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/CustomAttributeProvider.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * System.Reflection-like API for access to .NET assemblies (DLL & EXE)
- */
-
-
-package ch.epfl.lamp.compiler.msil;
-
-import java.util.List;
-import java.util.LinkedList;
-import java.util.Iterator;
-
-/**
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-public abstract class CustomAttributeProvider implements ICustomAttributeProvider {
-
- //##########################################################################
-
- protected List/*<Attribute>*/ custAttrs;
- private static final Object[] EMPTY = new Object[0];
-
- //TODO: take inherit into account
- public Object[] GetCustomAttributes(boolean inherit) {
- initAttributes(null);
- return custAttrs.size() == 0 ? EMPTY
- : custAttrs.toArray(new Attribute[custAttrs.size()]);
- }
-
- //TODO: take inherit into account
- public Object[] GetCustomAttributes(Type attributeType, boolean inherit) {
- initAttributes(attributeType);
- List tAttrs = null;
- if (constrType == attributeType)
- tAttrs = custAttrs;
- else {
- tAttrs = new LinkedList();
- for (Iterator attrs = custAttrs.iterator(); attrs.hasNext(); ) {
- Attribute a = (Attribute) attrs.next();
- if (a.GetType() == attributeType) tAttrs.add(a);
- }
- }
- return tAttrs.size() == 0 ? EMPTY
- : tAttrs.toArray(new Attribute[tAttrs.size()]);
- }
-
- //TODO: take inherit into account
- public boolean IsDefined(Type attributeType, boolean inherit) {
- initAttributes(attributeType);
- if (constrType == attributeType)
- return custAttrs.size() > 0;
- Iterator attrs = custAttrs.iterator();
- while (attrs.hasNext()) {
- if (((Attribute)attrs.next()).GetType() == attributeType)
- return true;
- }
- return false;
-// return inherit && (DeclaringClass.BaseType != null)
-// && DeclaringClass.BaseType.IsDefined(inherit);
- }
-
- protected void addCustomAttribute(ConstructorInfo constr, byte[] value) {
- Attribute attr = new Attribute(constr, value);
- assert constrType == null || constrType == attr.GetType();
- if (custAttrs == null)
- custAttrs = new LinkedList();
- custAttrs.add(attr);
- }
-
- private void initAttributes(Type atype) {
- if (custAttrs != null
- && (constrType == null || constrType == atype))
- return;
- custAttrs = new LinkedList();
- constrType = atype;
- loadCustomAttributes(atype);
- }
-
- protected void loadCustomAttributes(Type atype) {}
-
- private Type constrType;
-}
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/CustomModifier.java b/src/msil/ch/epfl/lamp/compiler/msil/CustomModifier.java
deleted file mode 100644
index cf30008c60..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/CustomModifier.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package ch.epfl.lamp.compiler.msil;
-
-/**
- * Quoting from the CIL spec, Partition II, Sec. 7.1.1:
- *
- * Custom modifiers, defined using `modreq` (required modifier) and `modopt` (optional modifier), are
- * similar to custom attributes (Sec. 21) except that modifiers are part of a signature rather than being attached to a
- * declaration. Each modifer associates a type reference with an item in the signature.
- *
- */
-public class CustomModifier {
-
- public boolean isReqd;
- public Type marker;
-
- public CustomModifier(boolean isReqd, Type marker) {
- this.isReqd = isReqd;
- this.marker = marker;
- }
-
- public String toString() {
- String res = (isReqd ? "modreq( " : "modopt( ") + marker.toString() + " )";
- return res;
- }
-
- public static Type[] helperCustomMods(boolean isReqd, CustomModifier[] cmods) {
- if(cmods == null) return null;
- int count = 0;
- for (int idx = 0; idx < cmods.length; idx++) {
- if(cmods[idx].isReqd == isReqd) count++;
- }
- Type[] res = new Type[count];
- int residx = 0;
- for (int idx = 0; idx < cmods.length; idx++) {
- res[residx] = cmods[idx].marker;
- residx++;
- }
- return res;
- }
-
- public static Type VolatileMarker() {
- return Type.GetType("System.Runtime.CompilerServices.IsVolatile");
- }
-
-}
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/EventAttributes.java b/src/msil/ch/epfl/lamp/compiler/msil/EventAttributes.java
deleted file mode 100644
index a183993cb9..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/EventAttributes.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * System.Reflection-like API for access to .NET assemblies (DLL & EXE)
- */
-
-
-package ch.epfl.lamp.compiler.msil;
-
-/**
- * Specifies flags that describe the attributes of a an event.
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-public final class EventAttributes {
-
- //##########################################################################
-
- /** Specifies that the event has no attributes. */
- public static final short None = 0x000;
-
- /** Specifies a reserved flag for CLR use only. */
- public static final short ReservedMask = 0x0400;
-
- /** Specifies that the event is special in a way described by the name. */
- public static final short SpecialName = 0x0200;
-
- /** Specifies the the CLR should check name encoding. */
- public static final short RTSpecialName = 0x0400;
-
- //##########################################################################
-
-} // class EventAttributes
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/EventInfo.java b/src/msil/ch/epfl/lamp/compiler/msil/EventInfo.java
deleted file mode 100644
index 3ccba7900b..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/EventInfo.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * System.Reflection-like API for access to .NET assemblies (DLL & EXE)
- */
-
-
-package ch.epfl.lamp.compiler.msil;
-
-
-/**
- * Discovers the attributes of an event
- * and provides access to event metadata.
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-public class EventInfo extends MemberInfo {
-
- //##########################################################################
-
- public final int MemberType() { return MemberTypes.Event; }
-
- /** Attributes associated with the event. */
- public final short Attributes;
-
- /** The Type object for the underlying event-handler delegate
- * associated with this event.
- */
- public final Type EventHandlerType;
-
- public MethodInfo GetAddMethod() { return addMethod; }
-
- public MethodInfo GetRemoveMethod() { return removeMethod; }
-
- public String toString() {
- return "" + EventHandlerType + " " + Name;
- }
-
- //##########################################################################
-
- protected static final EventInfo[] EMPTY_ARRAY = new EventInfo[0];
-
- protected MethodInfo addMethod;
-
- protected MethodInfo removeMethod;
-
- protected EventInfo(String name, Type declType, short attr,
- Type handlerType, MethodInfo add, MethodInfo remove)
- {
- super(name, declType);
- Attributes = attr;
- EventHandlerType = handlerType;
- this.addMethod = add;
- this.removeMethod = remove;
- }
-
- //##########################################################################
-
-} // class EventInfo
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/FieldAttributes.java b/src/msil/ch/epfl/lamp/compiler/msil/FieldAttributes.java
deleted file mode 100644
index d7d1bb3d54..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/FieldAttributes.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * System.Reflection-like API for access to .NET assemblies (DLL & EXE)
- */
-
-
-package ch.epfl.lamp.compiler.msil;
-
-/**
- * Specifies flags that describe the attributes of a field.
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-public final class FieldAttributes {
-
- //##########################################################################
-
- /** Specifies the access level of a given field. */
- public static final short FieldAccessMask = 0x0007;
-
- /** Member not refereneceable. */
- public static final short CompilerControlled = 0x0000;
-
- /** Field is accessible only by the parent type. */
- public static final short Private = 0x0001;
-
- /** Field is accessible only by subtypes in this assembly. */
- public static final short FamANDAssem = 0x0002;
-
- /** Field is accessible throughout the assembly. */
- public static final short Assembly = 0x0003;
-
- /** Field is accessible only by type and subtypes. */
- public static final short Family = 0x0004;
-
- /** Field is accessible by subtypes anywhere,
- * as well as throughout this assembly. */
- public static final short FamORAssem = 0x0005;
-
- /** Specifies that the field is accessible by any member
- * for whom this scope is visible. */
- public static final short Public = 0x0006;
-
- //##########################################################################
- //
-
- /** Field represents the defined type, or else it is per-instance. */
- public static final short Static = 0x0010;
-
- /** Field is initialized only and cannot be written after initialization. */
- public static final short InitOnly = 0x0020;
-
- /** Value is compile-time constant. */
- public static final short Literal = 0x0040;
-
- /** Field does not have to be serialized when the type is remoted. */
- public static final short NotSerialized = 0x0080;
-
- /** Field is special. */
- public static final short SpecialName = 0x0200;
-
- //##########################################################################
- // Interop attributes
-
- /** Implementation is forwarded through PInvoke */
- public static final short PinvokeImpl = 0x2000;
-
-
- //##########################################################################
- // Additional flags
-
- /** CLI provides 'special' behavior depending upon the name of the field */
- public static final short RTSpecialName = 0x0400;
-
- /** Field has marshalling information. */
- public static final short HasFieldMarshal = 0x1000;
-
- /** Field has a default value. */
- public static final short HasDefault = (short)0x8000;
-
- /** Field has a Relative Virtual Address (RVA). The RVA is the location
- * of the method body in the current image, as an address relative
- * to the start of the image file in which it is located. */
- public static final short HasFieldRVA = 0x0100;
-
- //##########################################################################
- //
-
- public static String toString(short attrs) {
- StringBuffer str = new StringBuffer();
- switch (attrs & FieldAccessMask) {
- case CompilerControlled: str.append("compilercontrolled"); break;
- case Private: str.append("private"); break;
- case FamANDAssem: str.append("famandassem"); break;
- case Assembly: str.append("assembly"); break;
- case Family: str.append("family"); break;
- case FamORAssem: str.append("famorassem"); break;
- case Public: str.append("public"); break;
- }
- if ((attrs & Static) != 0) str.append(" static");
- if ((attrs & InitOnly) != 0) str.append(" initonly");
- if ((attrs & Literal) != 0) str.append(" literal");
- if ((attrs & NotSerialized) != 0) str.append(" notserialized");
- if ((attrs & SpecialName) != 0) str.append(" specialname");
- if ((attrs & PinvokeImpl) != 0) str.append("");
- if ((attrs & RTSpecialName) != 0) str.append(" rtspecialname");
- if ((attrs & HasFieldMarshal) != 0) str.append(" marshal(<native type>)");
- //if ((attrs & HasDefault) != 0) str.append(" default(???)");
- return str.toString();
- }
-
- //##########################################################################
-
- // makes the class uninstantiable
- private FieldAttributes() {}
-
- //##########################################################################
-
-} // class FieldAttributes
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/FieldInfo.java b/src/msil/ch/epfl/lamp/compiler/msil/FieldInfo.java
deleted file mode 100644
index 536a67e9a8..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/FieldInfo.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * System.Reflection-like API for access to .NET assemblies (DLL & EXE)
- */
-
-
-package ch.epfl.lamp.compiler.msil;
-
-import ch.epfl.lamp.compiler.msil.util.PECustomMod;
-
-/**
- * Discovers the attributes of a field and provides access to field metadata.
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-public class FieldInfo extends MemberInfo implements HasCustomModifiers {
-
- //##########################################################################
- // public interface
-
- public final int MemberType() { return MemberTypes.Field; }
-
- /** Attributes associated with this field. */
- public final short Attributes;
-
- /** Type of the field represented by this FieldInfo object. */
- public final Type FieldType;
-
- /** can be null */
- public final CustomModifier[] cmods;
-
- protected final Object value;
-
- public final boolean IsStatic() {
- return (Attributes & FieldAttributes.Static) != 0;
- }
-
- public final boolean IsInitOnly() {
- return (Attributes & FieldAttributes.InitOnly) != 0;
- }
-
- public final boolean IsLiteral() {
- return (Attributes & FieldAttributes.Literal) != 0;
-
- }
-
- public final boolean IsPublic() {
- return (Attributes & FieldAttributes.FieldAccessMask)
- == FieldAttributes.Public;
- }
-
- public final boolean IsPrivate() {
- return (Attributes & FieldAttributes.FieldAccessMask)
- == FieldAttributes.Private;
- }
-
- public final boolean IsFamily() {
- return (Attributes & FieldAttributes.FieldAccessMask)
- == FieldAttributes.Family;
- }
-
- public final boolean IsAssembly() {
- return (Attributes & FieldAttributes.FieldAccessMask)
- == FieldAttributes.Assembly;
- }
-
- public final boolean IsFamilyOrAssembly() {
- return (Attributes & FieldAttributes.FieldAccessMask)
- == FieldAttributes.FamORAssem;
- }
-
- public final boolean IsFamilyAndAssembly() {
- return (Attributes & FieldAttributes.FieldAccessMask)
- == FieldAttributes.FamANDAssem;
- }
- public final boolean IsSpecialName() {
- return (Attributes & FieldAttributes.SpecialName) != 0;
- }
-
- public final boolean IsPinvokeImpl() {
- return (Attributes & FieldAttributes.PinvokeImpl) != 0;
- }
-
- public final boolean IsNotSerialized() {
- return (Attributes & FieldAttributes.NotSerialized) != 0;
- }
-
- private boolean knownVolatile = false;
- private boolean cachedVolatile = false;
- public final boolean IsVolatile() {
- if(knownVolatile) return cachedVolatile;
- knownVolatile = true;
- if(cmods == null) {
- cachedVolatile = false;
- return cachedVolatile;
- }
- for (int idx = 0; idx < cmods.length; idx++) {
- if(cmods[idx].marker == CustomModifier.VolatileMarker()) {
- cachedVolatile = true;
- return cachedVolatile;
- }
- }
- cachedVolatile = false;
- return cachedVolatile;
- }
-
- public final Type[] GetOptionalCustomModifiers () {
- return CustomModifier.helperCustomMods(false, cmods);
- }
-
- public final Type[] GetRequiredCustomModifiers() {
- return CustomModifier.helperCustomMods(true, cmods);
- }
-
- public String toString() {
- return FieldAttributes.toString(Attributes) + " " +
- FieldType + " " + DeclaringType.FullName + "::" + Name;
- }
-
- //##########################################################################
-
- protected static final FieldInfo[] EMPTY_ARRAY = new FieldInfo[0];
-
- /** Initializes a new instance of the FieldInfo class. */
- protected FieldInfo(String name, Type declType,
- int attrs, PECustomMod fieldTypeWithMods, Object value)
- {
- super(name, declType);
- FieldType = fieldTypeWithMods.marked;
- cmods = fieldTypeWithMods.cmods;
- Attributes = (short) attrs;
- this.value = value;
- }
-
- /**
- */
- public Object getValue() { return value; }
-
- //##########################################################################
-
-} // class FieldInfo
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/GenericParamAndConstraints.java b/src/msil/ch/epfl/lamp/compiler/msil/GenericParamAndConstraints.java
deleted file mode 100644
index 6237fbafee..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/GenericParamAndConstraints.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package ch.epfl.lamp.compiler.msil;
-
-/**
- * @author Miguel Garcia
- */
-public class GenericParamAndConstraints {
-
- public GenericParamAndConstraints(int Number, String Name, Type[] Constraints,
- boolean isInvariant, boolean isCovariant, boolean isContravariant,
- boolean isReferenceType, boolean isValueType, boolean hasDefaultConstructor) {
- this.Number = Number;
- this.Name = Name;
- this.Constraints = Constraints; // TODO representation for the class and new() constraints missing
- this.isInvariant = isInvariant;
- this.isCovariant = isCovariant;
- this.isContravariant = isContravariant;
- this.isReferenceType = isReferenceType;
- this.isValueType = isValueType;
- this.hasDefaultConstructor = hasDefaultConstructor;
-
- }
-
- public final int Number;
- public final String Name; // can be null
- public final Type[] Constraints; // can be empty array
- public final boolean isInvariant; // only relevant for TVars, not for an MVar
- public final boolean isCovariant; // only relevant for TVars, not for an MVar
- public final boolean isContravariant; // only relevant for TVars, not for an MVar
- public final boolean isReferenceType;
- public final boolean isValueType;
- public final boolean hasDefaultConstructor;
-
- public String toString() {
- String res = Name == null ? "<NoName>" : (Name.equals("") ? "<NoName>" : Name);
- res = res + " <: " + Constraints;
- return res;
- }
-
-}
-
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/HasCustomModifiers.java b/src/msil/ch/epfl/lamp/compiler/msil/HasCustomModifiers.java
deleted file mode 100644
index 5ead087350..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/HasCustomModifiers.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package ch.epfl.lamp.compiler.msil;
-
-public interface HasCustomModifiers {
-
- public Type[] GetOptionalCustomModifiers();
-
- public Type[] GetRequiredCustomModifiers();
-
-}
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/ICustomAttributeProvider.java b/src/msil/ch/epfl/lamp/compiler/msil/ICustomAttributeProvider.java
deleted file mode 100644
index 927185962c..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/ICustomAttributeProvider.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * System.Reflection-like API for access to .NET assemblies (DLL & EXE)
- */
-
-
-package ch.epfl.lamp.compiler.msil;
-
-/**
- * Provides custom attributes for reflection objects that support them.
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-public interface ICustomAttributeProvider {
-
- //##########################################################################
- // interface method definitions
-
- /** Returns an array of all of the custom attributes
- * defined on this member, excluding named attributes,
- * or an empty array if there are no custom attributes.
- *
- * @param inherit - When true, look up the hierarchy chain
- * for the inherited custom attribute.
- * @return - An array of Objects representing custom attributes,
- * or an empty array.
- */
- public Object[] GetCustomAttributes(boolean inherit);
-
-
- /** Returns an array of custom attributes defined on this member,
- * identified by type, or an empty array
- * if there are no custom attributes of that type.
- *
- * @param attributeType - The type of the custom attributes.
- * @param inherit - When true, look up the hierarchy chain
- * for the inherited custom attribute.
- * @return - An array of Objects representing custom attributes,
- * or an empty array.
- */
- public Object[] GetCustomAttributes(Type attributeType, boolean inherit);
-
-
- /** Indicates whether one or more instance of attributeType
- * is defined on this member
- *
- * @param attributeType - The type of the custom attributes
- * @param inherit - When true, look up the hierarchy chain
- * for the inherited custom attribute.
- * @return - true if the attributeType is defined on this member;
- * false otherwise.
- */
- public boolean IsDefined(Type attributeType, boolean inherit);
-
- //##########################################################################
-
-} // interface ICustomAttributeProvider
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/MemberInfo.java b/src/msil/ch/epfl/lamp/compiler/msil/MemberInfo.java
deleted file mode 100644
index 65ff1b290b..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/MemberInfo.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * System.Reflection-like API for access to .NET assemblies (DLL & EXE)
- */
-
-
-package ch.epfl.lamp.compiler.msil;
-
-/**
- * The root class of the Reflection hierarchy.
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-public abstract class MemberInfo extends CustomAttributeProvider {
-
- //##########################################################################
-
- /** The name of this member. */
- public final String Name;
-
- /**
- * The class that declares this member.
- * Note: if the MemberInfo object is a global member,
- * (that is, it was obtained from Module.GetMethods,
- * which returns global methods on a module), then DeclaringType
- * will be a null reference.
- */
- public final Type DeclaringType;
-
- /** An enumerated value from the MemberTypes class,
- * specifying a constructor, event, field, method,
- * property, type information, all, or custom. */
- public abstract int MemberType();
-
- //##########################################################################
- // protected members
-
- protected static final MemberInfo[] EMPTY_ARRAY = new MemberInfo[0];
-
- protected MemberInfo(String name, Type declType) {
- Name = name;
- DeclaringType = declType;
- }
-
- //########################################################################
-
-} // class MemberInfo
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/MemberTypes.java b/src/msil/ch/epfl/lamp/compiler/msil/MemberTypes.java
deleted file mode 100644
index 5f49ad3323..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/MemberTypes.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * System.Reflection-like API for access to .NET assemblies (DLL & EXE)
- */
-
-
-package ch.epfl.lamp.compiler.msil;
-
-/**
- * Marks each type of member that is defined as a derived class of MemberInfo.
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-public final class MemberTypes {
-
- //##########################################################################
-
- /** Specifies that the member is a constructor,
- * representing a ConstructorInfo member. */
- public static final int Constructor = 0x01;
-
-
- /** Specifies that the member is an event,
- * representing an EventInfo member. */
- public static final int Event = 0x02;
-
-
- /** Specifies that the member is a field,
- * representing a FieldInfo member. */
- public static final int Field = 0x04;
-
-
- /** Specifies that the member is a method,
- * representing a MethodInfo member. */
- public static final int Method = 0x08;
-
-
- /** Specifies that the member is a property,
- * representing a PropertyInfo member.
- */
- public static final int Property = 0x10;
-
- /** Specifies that the member is a type,
- * representing a TypeInfo member. */
- public static final int TypeInfo = 0x20;
-
-
- /** Specifies that the member is a custom member type. */
- public static final int Custom = 0x40;
-
-
- /** Specifies that the member is a nested type,
- * extending MemberInfo. */
- public static final int NestedType = 0x80;
-
-
- /** Specifies all member types. */
- public static final int All =
- Constructor | Event | Field | Method | Property | TypeInfo | NestedType;
-
-
- public static String toString(int memberType) {
- if ((memberType & Constructor) != 0) return "Constructor";
- if ((memberType & Event) != 0) return "Event";
- if ((memberType & Field) != 0) return "Field";
- if ((memberType & Method) != 0) return "Method";
- if ((memberType & Property) != 0) return "Property";
- if ((memberType & TypeInfo) != 0) return "TypeInfo";
- if ((memberType & Custom) != 0) return "Custom";
- if ((memberType & NestedType) != 0) return "NestedType";
- return "Unknown MemberType: " + memberType;
- }
-
- //##########################################################################
-
- // makes the class uninstantiable
- private MemberTypes() {}
-
- //##########################################################################
-
-} // class MemberTypes
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/MethodAttributes.java b/src/msil/ch/epfl/lamp/compiler/msil/MethodAttributes.java
deleted file mode 100644
index a703c38fb8..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/MethodAttributes.java
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * System.Reflection-like API for access to .NET assemblies (DLL & EXE)
- */
-
-
-package ch.epfl.lamp.compiler.msil;
-
-/** Specifies flags for method attributes.
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-public final class MethodAttributes {
-
- //##########################################################################
- // Method access attributes
-
- /** Bitmask used to retrieve accessibility information. */
- public static final short MemberAccessMask = 0x0007;
-
- ///** Member not referenceable*/
- //public static final short CompilerConstrolled = 0x0000;
-
- /** Indicates that the member cannot be referenced. */
- public static final short PrivateScope = 0x0000;
-
- /** Method is accessible only by the current class. */
- public static final short Private = 0x0001;
-
- /** Method is accessible to members of this type
- * and its derived types that are in this assembly only. */
- public static final short FamANDAssem = 0x0002;
-
- /** Method is accessible to any class of this assembly. */
- public static final short Assembly = 0x0003;
-
- /** Method is accessible only to members of this class
- * and its derived classes. */
- public static final short Family = 0x0004;
-
- /** Method is accessible to derived classes anywhere,
- * as well as to any class in the assembly. */
- public static final short FamORAssem = 0x0005;
-
- /** Method is accessible to any object for which this object is in scope. */
- public static final short Public = 0x0006;
-
-
- //##########################################################################
- // Flags
-
- /** Method is defined on the type; otherwise, it is defined per instance. */
- public static final short Static = 0x0010;
-
- /** Method cannot be overridden. */
- public static final short Final = 0x0020;
-
- /** Method is virtual. */
- public static final short Virtual = 0x0040;
-
- /** Method hides by name and signature; otherwise, by name only. */
- public static final short HideBySig = 0x0080;
-
-
- //##########################################################################
- // vtable attributes
-
- /** Bitmask used to retrieve vtable attributes. */
- public static final short VtableLayoutMask = 0x0100;
-
- /** Method reuses existing slot in the vtable. */
- public static final short ReuseSlot = 0x0000;
-
-
- /** Method always gets a new slot in the vtable. */
- public static final short NewSlot = 0x0100;
-
-
- //##########################################################################
- // Flags
-
- /** Method does not provide implementation. */
- public static final short Abstract = 0x0400;
-
- /** Method is special. */
- public static final short SpecialName = 0x0800;
-
-
- //##########################################################################
- // Interop attributes
-
- /** Method implementation is forwarded through PInvoke. */
- public static final short PInvokeImpl = 0x2000;
-
- /** Reserved: shall be zero for conforming implementations.
- * Managed method is exported by thunk to unmanaged code. */
- public static final short UnmanagedExport = 0x0008;
-
-
- //##########################################################################
- // Additional flags
-
- /** CLI provides special behavior, depending on the name of the method. */
- public static final short RTSpecialName = 0x1000;
-
- /** Method has security associated with it.
- * Reserved flag for runtime use only.
- */
- public static final short HasSecurity = 0x00000040;
-
- /**
- * Indicates that the method calls another method containing security code.
- * Reserved flag for runtime use only.
- */
- public static final short RequireSecObject = 0x00004000;
-
- /** Indicates a reserved flag for runtime use only. */
- public static final short ReservedMask = 0x0000;
-
-
- //##########################################################################
-
- public static String toString(short attrs) {
- StringBuffer str = new StringBuffer(accessFlagsToString(attrs));
- if ((attrs & Static) != 0) str.append(" static");
- if ((attrs & Final) != 0) str.append(" final");
- if ((attrs & Virtual) != 0) str.append(" virtual");
- if ((attrs & Abstract) != 0) str.append(" abstract");
- if ((attrs & HideBySig) != 0) str.append(" hidebysig");
- if ((attrs & NewSlot) != 0) str.append(" newslot");
- if ((attrs & SpecialName) != 0) str.append(" specialname");
- if ((attrs & PInvokeImpl) != 0) str.append(" pinvokeimpl(?!?)");
- if ((attrs & RTSpecialName) != 0) str.append(" rtspecialname");
- return str.toString();
-
- }
-
- public static String accessFlagsToString(short attrs) {
- switch (attrs & MemberAccessMask) {
- case PrivateScope: return "compilercontrolled";
- case Private: return "private";
- case FamANDAssem: return "famandassem";
- case Assembly: return "assembly";
- case Family: return "family";
- case FamORAssem: return "famorassem";
- case Public: return "public";
- default: return "xxx";
- }
- }
-
- //##########################################################################
-
- // makes the class uninstantiable
- private MethodAttributes() {}
-
- //##########################################################################
-
-} // class Method Attributes
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/MethodBase.java b/src/msil/ch/epfl/lamp/compiler/msil/MethodBase.java
deleted file mode 100644
index fe6404346e..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/MethodBase.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/*
- * System.Reflection-like API for access to .NET assemblies (DLL & EXE)
- */
-
-
-package ch.epfl.lamp.compiler.msil;
-
-import java.util.Iterator;
-
-/**
- * The common superclass of MemberInfo and ConstructorInfo
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-public abstract class MethodBase extends MemberInfo {
-
- //##########################################################################
- // public interface
-
- private java.util.List /* GenericParamAndConstraints */ mVars = new java.util.LinkedList();
- private GenericParamAndConstraints[] sortedMVars = null;
-
- public void addMVar(GenericParamAndConstraints tvarAndConstraints) {
- sortedMVars = null;
- mVars.add(tvarAndConstraints);
- }
-
- public GenericParamAndConstraints[] getSortedMVars() {
- if(sortedMVars == null) {
- sortedMVars = new GenericParamAndConstraints[mVars.size()];
- for (int i = 0; i < sortedMVars.length; i ++){
- Iterator iter = mVars.iterator();
- while(iter.hasNext()) {
- GenericParamAndConstraints tvC = (GenericParamAndConstraints)iter.next();
- if(tvC.Number == i) {
- sortedMVars[i] = tvC;
- }
- }
- }
- }
- return sortedMVars;
- }
-
- public final boolean IsGeneric() {
- return mVars.size() > 0;
- }
-
- /** The attributes associated with this method/constructor. */
- public final short Attributes;
-
- /***/
- public final short CallingConvention;
-
- public abstract boolean IsConstructor();
-
- public final boolean IsAbstract() {
- return (Attributes & MethodAttributes.Abstract) != 0;
- }
-
- public final boolean IsFinal() {
- return (Attributes& MethodAttributes.Final) != 0;
- }
-
- public final boolean IsVirtual() {
- return (Attributes& MethodAttributes.Virtual) != 0;
- }
-
- public final boolean IsInstance() {
- return !IsStatic() && !IsVirtual();
- }
-
- public final boolean IsStatic() {
- return (Attributes & MethodAttributes.Static) != 0;
- }
-
- public final boolean IsHideBySig() {
- return (Attributes & MethodAttributes.HideBySig) != 0;
- }
-
- public final boolean IsSpecialName() {
- return (Attributes & MethodAttributes.SpecialName) != 0;
- }
-
-
- public final boolean IsPublic() {
- return (Attributes & MethodAttributes.MemberAccessMask)
- == MethodAttributes.Public;
- }
-
- public final boolean IsPrivate() {
- return (Attributes & MethodAttributes.MemberAccessMask)
- == MethodAttributes.Private;
- }
-
- public final boolean IsFamily() {
- return (Attributes & MethodAttributes.MemberAccessMask)
- == MethodAttributes.Family;
- }
-
- public final boolean IsAssembly() {
- return (Attributes & MethodAttributes.MemberAccessMask)
- == MethodAttributes.Assembly;
- }
-
- public final boolean IsFamilyOrAssembly() {
- return (Attributes & MethodAttributes.MemberAccessMask)
- == MethodAttributes.FamORAssem;
- }
-
- public final boolean IsFamilyAndAssembly() {
- return (Attributes & MethodAttributes.MemberAccessMask)
- == MethodAttributes.FamANDAssem;
- }
-
- public boolean HasPtrParamOrRetType() {
- // the override in MethodInfo checks the return type
- ParameterInfo[] ps = GetParameters();
- for (int i = 0; i < ps.length; i++) {
- Type pT = ps[i].ParameterType;
- if(pT.IsPointer()) {
- // Type.mkPtr creates a msil.Type for a pointer type
- return true;
- }
- if(pT.IsByRef() && !pT.GetElementType().CanBeTakenAddressOf()) {
- /* TODO Cases where GenMSIL (so far) con't emit good bytecode:
- the type being taken address of IsArray(), IsGeneric(), or IsTMVarUsage.
- For example, System.Enum declares
- public static bool TryParse<TEnum>(string value, out TEnum result) where TEnum : struct, new();
- */
- return true;
- }
- }
- return false;
- }
-
- /** Returns the parameters of the method/constructor. */
- public ParameterInfo[] GetParameters() {
- return (ParameterInfo[]) params.clone();
- }
-
- public int GetMethodImplementationFlags() { return implAttributes; }
-
- //##########################################################################
-
- /** Method parameters. */
- protected ParameterInfo[] params;
-
- protected short implAttributes;
-
- protected MethodBase(String name, Type declType, int attrs, Type[] paramTypes)
- {
- this(name, declType, attrs);
- assert paramTypes != null;
- params = new ParameterInfo[paramTypes.length];
- for (int i = 0; i < params.length; i++)
- params[i] = new ParameterInfo(null, paramTypes[i], 0, i);
- }
-
- protected MethodBase(String name, Type declType, int attrs,
- ParameterInfo[] params)
- {
- this(name, declType, attrs);
- this.params = params;
- }
-
- /**
- */
- private MethodBase(String name, Type declType, int attrs) {
- super(name, declType);
-
- Attributes = (short) attrs;
-
- if (IsConstructor()) {
- attrs |= MethodAttributes.SpecialName;
- attrs |= MethodAttributes.RTSpecialName;
- }
-
- CallingConvention = (short) (CallingConventions.Standard
- | (IsStatic() ? (short)0 : CallingConventions.HasThis));
- }
-
- //##########################################################################
- // internal methods
-
- protected String params2String() {
- StringBuffer s = new StringBuffer("(");
- for (int i = 0; i < params.length; i++) {
- if (i > 0) s.append(", ");
- s.append(params[i].ParameterType);
- }
- s.append(")");
- return s.toString();
- }
-
- //##########################################################################
-
-} // class MethodBase
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/MethodImplAttributes.java b/src/msil/ch/epfl/lamp/compiler/msil/MethodImplAttributes.java
deleted file mode 100644
index 8e8d879593..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/MethodImplAttributes.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * System.Reflection-like API for access to .NET assemblies (DLL & EXE)
- */
-
-
-package ch.epfl.lamp.compiler.msil;
-
-/**
- * Method implementation attributes
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-public abstract class MethodImplAttributes {
-
- //##########################################################################
-
- /**
- * Specifies flags about code type. 3
- */
- public static final short CodeTypeMask = (short) 0x0003;
-
- /**
- * Specifies that the method implementation is in MSIL. 0
- */
- public static final short IL = (short) 0x0000;
-
- /**
- * Specifies that the method implementation is native. 1
- */
- public static final short Native = (short) 0x0001;
-
- /**
- * This member supports the .NET Framework infrastructure and
- * is not intended to be used directly from your code. 2
- */
- public static final short OPTIL = (short) 0x0002;
-
- /**
- * Specifies that the method implementation is provided by the runtime. 3
- */
- public static final short Runtime = (short) 0x0003;
-
-
-
- /**
- * Specifies whether the code is managed or unmanaged. 4
- */
- public static final short ManagedMask = (short) 0x0004;
-
- /**
- * Specifies that the method implementation is managed, otherwise unmanaged.
- */
- public static final short Managed = (short) 0x0000;
-
- /**
- * Specifies that the method implementation is unmanaged, otherwise managed.
- */
- public static final short Unmanaged = (short) 0x0004;
-
-
-
- /**
- * Specifies that the method cannot be inlined. 8
- */
- public static final short NoInlining = (short) 0x0008;
-
- /**
- * Specifies that the method is not defined. 16
- */
- public static final short ForwardRef = (short) 0x0010;
-
- /**
- * Specifies that the method is single-threaded through the body.
- * You can also use the C# lock statement or the Visual Basic
- * Lock function for this purpose. 32
- */
- public static final short Synchronized = (short) 0x0020;
-
- /**
- * Specifies that the method signature is exported exactly as declared. 128
- */
- public static final short PreserveSig = (short) 0x0080;
-
- /**
- * Specifies an internal call. 4096
- */
- public static final short InternalCall = (short) 0x1000;
-
- /**
- * Specifies a range check value. 65535
- */
- public static final short MaxMethodImplVal = (short) 0xffff;
-
- //##########################################################################
-
- public static String toString(int implAttr) {
- StringBuffer s = new StringBuffer();
- switch (implAttr & CodeTypeMask) {
- case IL: s.append("cil"); break;
- case Native: s.append("native"); break;
- case Runtime: s.append("runtime"); break;
- }
- switch (implAttr & ManagedMask) {
- case Managed: s.append(" managed"); break;
- case Unmanaged: s.append(" unmanaged"); break;
- }
- if ((implAttr & NoInlining) != 0) s.append(" noinlining");
- if ((implAttr & ForwardRef) != 0) s.append(" forwardref");
- if ((implAttr & Synchronized) != 0) s.append(" synchronized");
- if ((implAttr & InternalCall) != 0) s.append(" internalcall");
- return s.toString();
- }
-
- //##########################################################################
-
-} // class MethodImplAttributes
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/MethodInfo.java b/src/msil/ch/epfl/lamp/compiler/msil/MethodInfo.java
deleted file mode 100644
index a415e7551f..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/MethodInfo.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * System.Reflection-like API for access to .NET assemblies (DLL & EXE)
- */
-
-
-package ch.epfl.lamp.compiler.msil;
-
-import java.util.Iterator;
-
-/**
- * Discovers the attributes of a method and provides access to method metadata.
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-public class MethodInfo extends MethodBase {
-
- public boolean HasPtrParamOrRetType() {
- if(ReturnType.IsByRef() && !(ReturnType.GetElementType().IsValueType())) {
- /* A method returning ByRef won't pass peverify, so I guess this is dead code. */
- return true;
- }
- if(ReturnType.IsPointer()) {
- return true;
- }
- return super.HasPtrParamOrRetType();
- }
-
- //##########################################################################
- // public members
-
- public final int MemberType() { return MemberTypes.Method; }
-
- public final boolean IsConstructor() { return false; }
-
- /** The return type of this method.
- */
- public final Type ReturnType;
-
- //##########################################################################
- // protected members
-
- protected static final MethodInfo[] EMPTY_ARRAY = new MethodInfo[0];
-
- /**
- * Constructor Initializes a new instance of the MethodInfo class.
- */
- protected MethodInfo(String name, Type declType,
- int attrs, Type returnType, Type[] paramTypes )
- {
- super(name, declType, attrs, paramTypes);
- ReturnType = returnType;
- }
-
- protected MethodInfo(String name, Type declType,
- int attrs, Type returnType, ParameterInfo[] params )
- {
- super(name, declType, attrs, params);
- ReturnType = returnType;
- }
-
- public String toString() {
- return MethodAttributes.toString(Attributes) + " " + ReturnType +
- " " + DeclaringType + "::" + Name + params2String();
- }
-
- //##########################################################################
-
-} // class MethodInfo
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/Module.java b/src/msil/ch/epfl/lamp/compiler/msil/Module.java
deleted file mode 100644
index 8dd5e7119f..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/Module.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * System.Reflection-like API for access to .NET assemblies (DLL & EXE)
- */
-
-
-package ch.epfl.lamp.compiler.msil;
-
-import java.util.Map;
-import java.util.HashMap;
-
-/**
- * Defines and represents a module. Get an instance of ModuleBuilder
- * by calling DefineDynamicModule
- * A module is a portable executable file of type .dll or .exe consisting
- * of one or more classes and interfaces. There may be multiple namespaces
- * contained in a single module, and a namespace may span multiple modules.
- * One or more modules deployed as a unit compose an assembly.
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-public abstract class Module extends CustomAttributeProvider {
-
- //##########################################################################
- // public fields
-
- /** String representing the name of the module with the path removed. */
- public final String Name;
-
- /** String representing the fully qualified name and path to this module. */
- public final String FullyQualifiedName;
-
- /** String representing the name of the module. */
- public String ScopeName;
-
- /** The Assembly the Module belongs to. */
- public final Assembly Assembly;
-
- //##########################################################################
- // constructor
-
- protected Module(String name, String filename,
- String scopeName, Assembly assembly)
- {
- this.Name = name;
- this.FullyQualifiedName = filename;
- this.ScopeName = scopeName;
- this.Assembly = assembly;
- }
-
- //##########################################################################
- // public methods
-
- /** Returns the specified class, performing a case-sensitive search. */
- public Type GetType(String name) {
- initTypes();
- return (Type) typesMap.get(name);
- }
-
- /**
- * @return all the classes defined within this module.
- */
- public Type[] GetTypes() {
- initTypes();
- return (Type[]) types.clone();
- }
-
- /**
- * @return the global field with the specified name.
- */
- public FieldInfo GetField(String name) {
- for (int i = 0; i < fields.length; i++)
- if (fields[i].Name.equals(name))
- return fields[i];
- return null;
- }
-
- /**
- * @return an array of the global fields of the module
- */
- public FieldInfo[] GetFields() {
- return (FieldInfo[]) fields.clone();
- }
-
- /**
- * @return - the global method with the specified name
- */
- public MethodInfo GetMethod(String name) {
- for (int i = 0; i < methods.length; i++)
- if (methods[i].Name.equals(name))
- return methods[i];
- return null;
- }
-
- /**
- * @return - an array of all the global methods defined in this modules.
- */
- public MethodInfo[] GetMethods() {
- return (MethodInfo[]) methods.clone();
- }
-
- /**
- */
- public String toString() { return Name; }
-
- //########################################################################
- // protected members
-
- // all the types defined in this module
- protected final Map typesMap = new HashMap();
-
- // all the types defined in this module
- protected Type[] types;
-
- // the global fields of the module
- protected FieldInfo[] fields = FieldInfo.EMPTY_ARRAY;
-
- // the global methods of the module
- protected MethodInfo[] methods = MethodInfo.EMPTY_ARRAY;
-
- protected Type addType(Type type) {
- addType(type.FullName, type);
- Assembly.addType(type);
- return type;
- }
-
- protected Type addType(String name, Type type) {
- assert type!= null;
- typesMap.put(name, type);
- return type;
- }
-
- private boolean initTypes = true;
- protected final void initTypes() {
- if (initTypes) {
- loadTypes();
- initTypes = false;
- }
- }
-
- protected void loadTypes() {}
-
- private boolean initGlobals = true;
- protected final void initGlobals() {
- if (initGlobals) {
- loadGlobals();
- initGlobals = false;
- }
- }
-
- protected void loadGlobals() {}
-
- //##########################################################################
-
-} // class Module
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/PEAssembly.java b/src/msil/ch/epfl/lamp/compiler/msil/PEAssembly.java
deleted file mode 100644
index a31db16c92..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/PEAssembly.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * System.Reflection-like API for access to .NET assemblies (DLL & EXE)
- */
-
-
-package ch.epfl.lamp.compiler.msil;
-
-import ch.epfl.lamp.compiler.msil.util.Table;
-import ch.epfl.lamp.compiler.msil.util.Table.*;
-
-import java.io.File;
-
-import java.util.Map;
-import java.util.HashMap;
-
-/** Represents an assembly that resides in a real .NET assembly
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-final class PEAssembly extends Assembly {
-
- private final PEFile pefile;
-
- private PEModule mainModule;
-
- public PEAssembly(PEFile pefile, AssemblyName an) {
- super(an, true);
- this.pefile = pefile;
- String name = pefile.ModuleDef(1).getName();
- mainModule = new PEModule(pefile, 1, name, this);
- addModule(name, mainModule);
- //initModules();
- }
-
- protected void loadModules() {
- File parentDir = pefile.getParentFile();
- FileDef fd = pefile.FileDef;
- for (int row = 1; row <= fd.rows; row++) {
- fd.readRow(row);
- String filename = fd.getName();
- File f = new File(parentDir, filename);
- PEFile pe = Assembly.getPEFile(f);
- if (pe == null) {
- f = new File(filename);
- pe = Assembly.getPEFile(f);
- if (pe == null)
- continue;
-// throw new RuntimeException("Cannot find file " + filename +
-// " referenced by assembly " + this);
- }
- String name = pe.ModuleDef(1).getName();
- PEModule module = new PEModule(pe, 1, name, this);
- addModule(name, module);
- }
- }
-
- public File getFile() {
- return pefile.getUnderlyingFile();
- }
-
- protected void loadCustomAttributes(Type attributeType) {
- initModules();
- mainModule.initAttributes(this, 1, Table.AssemblyDef.ID, attributeType);
- }
-
- //##########################################################################
-
-} // class PEAssembly
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/PEFile.java b/src/msil/ch/epfl/lamp/compiler/msil/PEFile.java
deleted file mode 100644
index 3eb22b9985..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/PEFile.java
+++ /dev/null
@@ -1,941 +0,0 @@
-/*
- * System.Reflection-like API for access to .NET assemblies (DLL & EXE)
- */
-
-
-package ch.epfl.lamp.compiler.msil;
-
-import ch.epfl.lamp.compiler.msil.util.*;
-import ch.epfl.lamp.compiler.msil.util.Table.*;
-
-import ch.epfl.lamp.compiler.msil.Type;
-import ch.epfl.lamp.compiler.msil.Module;
-
-import java.io.File;
-import java.io.RandomAccessFile;
-import java.io.PrintStream;
-import java.io.IOException;
-import java.io.FileNotFoundException;
-
-import java.nio.ByteBuffer;
-import java.nio.channels.FileChannel;
-import java.nio.MappedByteBuffer;
-
-import java.util.Date;
-
-/**
- * A class that represents a .NET PE/COFF image.
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- * @see <a href="http://www.ecma-international.org/publications/standards/Ecma-335.htm">Standard ECMA-335: Common Language Infrastructure (CLI), 4th edition (June 2006)</a>
- */
-public class PEFile {
-
- //##########################################################################
-
- public static final int INT_SIZE = 4;
-
- protected final int PE_SIGNATURE_OFFSET;
- protected final int COFF_HEADER_OFFSET;
- protected final int PE_HEADER_OFFSET;
-
- protected final int numOfSections;
- protected final int CLI_RVA;
- protected final int CLI_Length;
- public final int rvaMetadata;
- public final int posMetadata;
- protected final int numOfStreams;
- protected final int optHeaderSize;
-
- protected final File underlyingFile;
- protected final RandomAccessFile file;
- protected final MappedByteBuffer buf;
-
- protected final PESection [] sections;
-
- public PEStream Meta, Strings, US, Blob, GUID;
-
- private final Table [] tables = new Table[Table.MAX_NUMBER];
-
- public final boolean isDLL;
-
- protected final int heapSizes;
- public final boolean StringIsShort, BlobIsShort, GUIDIsShort;
-
- protected PEModule pemodule = null;
-
- //##########################################################################
- // PEFile constructor
-
- private static void fileFormatCheck(boolean cond, String s) {
- if (cond)
- throw new RuntimeException(s);
- }
-
- /**
- */
- public PEFile(String filename) throws FileNotFoundException {
- this.underlyingFile = new File(filename);
- this.file = new RandomAccessFile(underlyingFile, "r");
- FileChannel fc = file.getChannel();
- MappedByteBuffer bb = null;
- try {
- bb = fc.map(FileChannel.MapMode.READ_ONLY, 0L, fc.size());
- } catch (IOException e) { throw new RuntimeException(e); }
-
- /** Ecma 335, 25 File format extensions to PE:
- *
- * "Unless stated otherwise, all binary values are stored in little-endian format."
- */
-
- bb.order(java.nio.ByteOrder.LITTLE_ENDIAN);
- this.buf = bb;
-
- /** Ecma 335, 25.2.1 MS-DOS header:
- *
- * "The PE format starts with an MS-DOS stub of exactly the following 128 bytes to
- * be placed at the front of the module."
- *
- * We are only checking for MZ (Mark Zbikowski)
- */
-
- seek(0);
- fileFormatCheck(readByte() != 0x4d, "Invalid PE file format: " + filename); // 'M'
- fileFormatCheck(readByte() != 0x5a, "Invalid PE file format: " + filename); // 'Z'
-
- /** Ecma 335, 25.2.1 MS-DOS header:
- *
- * "At offset 0x3c in the DOS header is a 4-byte unsigned integer offset, lfanew,
- * to the PE signature (shall be "PE\0\0"), immediately followed by the PE file header."
- */
-
- seek(0x3c);
- PE_SIGNATURE_OFFSET = readInt();
- seek(PE_SIGNATURE_OFFSET);
- // start of PE signature (a signature that is just 4 bytes long)
- fileFormatCheck(readByte() != 0x50, "Invalid PE file format: " + filename); // 'P'
- fileFormatCheck(readByte() != 0x45, "Invalid PE file format: " + filename); // 'E'
- fileFormatCheck(readByte() != 0x00, "Invalid PE file format: " + filename); // 0
- fileFormatCheck(readByte() != 0x00, "Invalid PE file format: " + filename); // 0
-
- //trace("PE signature offset = 0x" + Table.int2hex(PE_SIGNATURE_OFFSET));
-
- COFF_HEADER_OFFSET = PE_SIGNATURE_OFFSET + 4;
- PE_HEADER_OFFSET = COFF_HEADER_OFFSET + 20;
-
- seek(COFF_HEADER_OFFSET);
-
- /* start of PE file header, Sec. 25.2.2 in Partition II */
- skip(2); // Machine (always 0x14c)
- numOfSections = readShort(); // Number of sections; indicates size of the Section Table
- Date timeStamp = new Date(readInt() * 1000L);
- skip(2 * INT_SIZE); // skip Pointer to Symbol Table (always 0) and Number of Symbols (always 0)
- optHeaderSize = readShort();
- int characteristics = readShort();
- isDLL = (characteristics & 0x2000) != 0;
-
- seek(PE_HEADER_OFFSET + 208); // p.157, Partition II
-
- CLI_RVA = readInt(); // called "Data Directory Table" in Ch. 4 of Expert IL book
- CLI_Length = readInt();
- //trace("CLI_RVA = 0x" + Table.int2hex(CLI_RVA));
- //trace("CLI_Length = 0x" + Table.int2hex(CLI_Length));
-
- sections = new PESection[numOfSections];
-
- seek(PE_HEADER_OFFSET + optHeaderSize); // go to the sections descriptors
-
- for (int i = 0; i < numOfSections; i++) {
- seek(PE_HEADER_OFFSET + optHeaderSize + i * 40);
- sections[i] = new PESection(this);
- //sections[i].dump(System.out);
- }
-
- seek(fromRVA(CLI_RVA));
- skip(8);
- rvaMetadata = readInt();
- posMetadata = fromRVA(rvaMetadata);
- //trace("rvaMetadata = 0x" + Table.int2hex(rvaMetadata));
- //trace("posMetadata = 0x" + Table.int2hex(posMetadata));
-
- seek(posMetadata);
- int magic = readInt();
- //trace("Magic metadata signature = 0x" + Table.int2hex(magic));
- fileFormatCheck(magic != 0x424a5342, "Invalid metadata signature!");
- skip(8);
-
- int strlength = readInt();
- //trace("version name string length = " + strlength);
- skip(strlength);
- align(INT_SIZE, posMetadata);
- //trace("position of flags = 0x" + Table.int2hex((int)pos()));
- skip(2); // ignore the flags
- numOfStreams = readShort();
- //trace("Number of metadata streams = " + numOfStreams);
-
- for (int i = 0; i < numOfStreams; i++) {
- PEStream strm = new PEStream(this);
- //strm.dump(System.out);
- if (strm.name.equals("#~")
- || strm.name.equals("#-")) Meta = strm;
- if (strm.name.equals("#Strings")) Strings = strm;
- if (strm.name.equals("#US")) US = strm;
- if (strm.name.equals("#Blob")) Blob = strm;
- if (strm.name.equals("#GUID")) GUID = strm;
- }
-
- seek(Meta.offset);
- skip(6);
- heapSizes = readByte();
- StringIsShort = (heapSizes & 0x01) == 0;
- GUIDIsShort = (heapSizes & 0x02) == 0;
- BlobIsShort = (heapSizes & 0x04) == 0;
-
- skip(1);
- long tablesMask = readLong();
- long nonStandardTables = tablesMask & ~Table.VALID_TABLES_MASK;
- skip(8); //go to the list of number of rows
- for (int i = 0; i < tables.length; i++) {
- tables[i] = Table.newTable
- (this, i, ((tablesMask >> i) & 0x01) != 0 ? readInt() : 0);
- }
-
- initIndexSize();
- initTableRefs();
- // populate the tables from the CLI image file
- long start = pos();
- for (int i = 0; i < tables.length; i++)
- start = tables[i].init(start);
-
- } // PEFile()
-
-
- public final int[] indexSize = new int[Table.TABLE_SET_LENGTH];
-
- private void initIndexSize() {
- for (int i = 0; i < Table.TABLE_SET_LENGTH; i++) {
- indexSize[i] = 2;
- int[] tableSet = Table.TableSet[i];
- int treshold = (65536 >> Table.NoBits[i]);
- for (int j = 0; j < tableSet.length; j++) {
- if (tableSet[j] >= 0) {
- Table t = tables[tableSet[j]];
- if (t.rows >= treshold) {
- indexSize[i] = 4;
- break;
- }
- }
- }
- }
- }
-
- protected void initModule(PEModule module) {
- if (pemodule != null)
- throw new RuntimeException("File " + this
- + " has already been assigned module "
- + pemodule + "; new module is " + module);
- this.pemodule = module;
- }
-
- //##########################################################################
-
- public ModuleDef ModuleDef;
- public ModuleDef ModuleDef(int i) {
- ModuleDef.readRow(i);
- return ModuleDef;
- }
-
- public TypeRef TypeRef;
-
- public TypeDef TypeDef;
- public TypeDef TypeDef(int i) {
- TypeDef.readRow(i);
- return TypeDef;
- }
-
- public FieldTrans FieldTrans;
- public FieldTrans FieldTrans(int i) {
- FieldTrans.readRow(i);
- return FieldTrans;
- }
-
- public FieldDef FieldDef;
- public FieldDef FieldDef(int i) {
- FieldDef.readRow(i);
- return FieldDef;
- }
-
- public MethodTrans MethodTrans;
- public MethodTrans MethodTrans(int i) {
- MethodTrans.readRow(i);
- return MethodTrans;
- }
-
- public MethodDef MethodDef;
- public MethodDef MethodDef(int i) { MethodDef.readRow(i); return MethodDef; }
-
-
- public ParamDef ParamDef;
- public ParamDef ParamDef(int i) { ParamDef.readRow(i); return ParamDef; }
-
- public GenericParam GenericParam;
-
- public GenericParam GenericParam(int i) {
- GenericParam.readRow(i);
- return GenericParam;
- }
-
- public MethodSpec MethodSpec;
-
- public MethodSpec MethodSpec(int i) {
- MethodSpec.readRow(i);
- return MethodSpec;
- }
-
- public GenericParamConstraint GenericParamConstraint;
-
- public GenericParamConstraint GenericParamConstraint(int i) {
- GenericParamConstraint.readRow(i);
- return GenericParamConstraint;
- }
-
- public InterfaceImpl InterfaceImpl;
- public MemberRef MemberRef;
- public Constant Constant;
- public CustomAttribute CustomAttribute;
- public FieldMarshal FieldMarshal;
- public DeclSecurity DeclSecurity;
- public ClassLayout ClassLayout;
- public FieldLayout FieldLayout;
- public StandAloneSig StandAloneSig;
- public EventMap EventMap;
- public EventDef EventDef;
- public PropertyMap PropertyMap;
- public PropertyDef PropertyDef;
- public MethodSemantics MethodSemantics;
- public MethodImpl MethodImpl;
- public ModuleRef ModuleRef;
- public TypeSpec TypeSpec;
- public ImplMap ImplMap;
- public FieldRVA FieldRVA;
- public AssemblyDef AssemblyDef;
- public AssemblyRef AssemblyRef;
- public FileDef FileDef;
- public ExportedType ExportedType;
- public ManifestResource ManifestResource;
- public NestedClass NestedClass;
-
-
- private void initTableRefs() {
- ModuleDef = (ModuleDef) getTable(Table.ModuleDef.ID);
- TypeRef = (TypeRef) getTable(Table.TypeRef.ID);
- TypeDef = (TypeDef) getTable(Table.TypeDef.ID);
- FieldTrans = (FieldTrans) getTable(Table.FieldTrans.ID);
- FieldDef = (FieldDef) getTable(Table.FieldDef.ID);
- MethodTrans = (MethodTrans) getTable(Table.MethodTrans.ID);
- MethodDef = (MethodDef) getTable(Table.MethodDef.ID);
- ParamDef = (ParamDef) getTable(Table.ParamDef.ID);
- InterfaceImpl = (InterfaceImpl) getTable(Table.InterfaceImpl.ID);
- MemberRef = (MemberRef) getTable(Table.MemberRef.ID);
- Constant = (Constant) getTable(Table.Constant.ID);
- CustomAttribute = (CustomAttribute) getTable(Table.CustomAttribute.ID);
- FieldMarshal = (FieldMarshal) getTable(Table.FieldMarshal.ID);
- DeclSecurity = (DeclSecurity) getTable(Table.DeclSecurity.ID);
- ClassLayout = (ClassLayout) getTable(Table.ClassLayout.ID);
- FieldLayout = (FieldLayout) getTable(Table.FieldLayout.ID);
- StandAloneSig = (StandAloneSig) getTable(Table.StandAloneSig.ID);
- EventMap = (EventMap) getTable(Table.EventMap.ID);
- EventDef = (EventDef) getTable(Table.EventDef.ID);
- PropertyMap = (PropertyMap) getTable(Table.PropertyMap.ID);
- PropertyDef = (PropertyDef) getTable(Table.PropertyDef.ID);
- MethodSemantics = (MethodSemantics) getTable(Table.MethodSemantics.ID);
- MethodImpl = (MethodImpl) getTable(Table.MethodImpl.ID);
- ModuleRef = (ModuleRef) getTable(Table.ModuleRef.ID);
- TypeSpec = (TypeSpec) getTable(Table.TypeSpec.ID);
- ImplMap = (ImplMap) getTable(Table.ImplMap.ID);
- FieldRVA = (FieldRVA) getTable(Table.FieldRVA.ID);
- AssemblyDef = (AssemblyDef) getTable(Table.AssemblyDef.ID);
- AssemblyRef = (AssemblyRef) getTable(Table.AssemblyRef.ID);
- FileDef = (FileDef) getTable(Table.FileDef.ID);
- ExportedType = (ExportedType) getTable(Table.ExportedType.ID);
- NestedClass = (NestedClass) getTable(Table.NestedClass.ID);
- ManifestResource =
- (ManifestResource) getTable(Table.ManifestResource.ID);
- GenericParam = (GenericParam) getTable(Table.GenericParam.ID);
- MethodSpec = (MethodSpec) getTable(Table.MethodSpec.ID);
- GenericParamConstraint = (GenericParamConstraint) getTable(Table.GenericParamConstraint.ID);
- }
-
- public static String long2hex(long a) {
- StringBuffer str = new StringBuffer("0000000000000000");
- str.append(Long.toHexString(a));
- int l = str.length();
- return str.substring(l - 16, l);
- }
-
- public static String int2hex(int a) {
- StringBuffer str = new StringBuffer("00000000");
- str.append(Integer.toHexString(a));
- int l = str.length();
- return str.substring(l - 8, l);
- }
-
- public static String short2hex(int a) {
- StringBuffer str = new StringBuffer("0000");
- str.append(Integer.toHexString(a));
- int l = str.length();
- return str.substring(l - 4, l);
- }
-
- public static String byte2hex(int a) {
- StringBuffer str = new StringBuffer("00");
- str.append(Integer.toHexString(a));
- int l = str.length();
- return str.substring(l - 2, l);
- }
-
- public static String bytes2hex(byte[] buf) {
- StringBuffer str = new StringBuffer();
- for (int i = 0; i < buf.length; i++) {
- str.append(byte2hex(buf[i]));
- if (i < buf.length - 1)
- str.append(" ");
- }
- return str.toString();
- }
-
- //##########################################################################
- // filename
-
- public File getUnderlyingFile() {
- return underlyingFile;
- }
-
- /**
- * @return the absolute path of the file
- */
- public String getAbsolutePath() {
- return underlyingFile.getAbsolutePath();
- }
-
- /**
- * @return the name of this file
- */
- public String getName() {
- return underlyingFile.getName();
- }
-
- /**
- * @return
- */
- public String getParent() {
- return underlyingFile.getParent();
- }
-
- /**
- * @return the file representing the directory the file belongs to
- */
- public File getParentFile() {
- return underlyingFile.getParentFile();
- }
-
- public String toString() {
- return getAbsolutePath();
- }
-
- //##########################################################################
- // file pointer manipulation methods
-
- /** Returns the current position in the file. */
- public int pos() {
- return buf.position();
- }
-
- /** Go to the specified position in the file. */
- public void seek(int pos) {
- buf.position(pos);
- }
-
-
- /** Align the current position in the file. */
- public void align(int base) { align(base, 0); }
-
- /** Align the current position in a section starting at offset. */
- public void align(int base, int offset) {
- int p = pos() - offset;
- seek( offset + ((p % base) == 0 ? p : (p/base + 1) * base));
- }
-
- /** Computes the position in the file that corresponds to the given RVA. */
- public int fromRVA(int rva) {
- int i;
- for(i = 0; i < numOfSections; i++)
- if(sections[i].virtAddr <= rva &&
- rva <= (sections[i].virtAddr + sections[i].virtSize))
- return rva - sections[i].virtAddr + sections[i].realAddr;
- throw new RuntimeException("RVA 0x" + Integer.toHexString(rva) +
- " is not within this file's sections!");
- }
-
- /** Go to the specified RVA (Relative Virtual Address). */
- public void gotoRVA(int rva) {
- seek(fromRVA(rva));
- }
-
- /** Move the forward in the file by the specified number of bytes. */
- public void skip(int n) {
- buf.position(buf.position() + n);
- }
-
- /**
- * Returns a memory mapped little-endian buffer
- * for the specified region of the file.
- */
- public MappedByteBuffer mapBuffer(long offset, int size) {
- try {
- MappedByteBuffer b = file.getChannel()
- .map(FileChannel.MapMode.READ_ONLY, offset, size);
- b.order(java.nio.ByteOrder.LITTLE_ENDIAN);
- return b;
- } catch (IOException e) { throw new RuntimeException(e); }
- }
-
- /** Returns a buffer from the given offset to the end of the file. */
- public ByteBuffer getBuffer(long offset, int size) {
- buf.mark();
- buf.position((int)offset);
- ByteBuffer bb = buf.slice();
- buf.reset();
- bb.limit(size);
- bb.order(java.nio.ByteOrder.LITTLE_ENDIAN);
- return bb;
- }
-
- //##########################################################################
- // file read methods
-
- /**
- * Read bs.length number of bytes
- */
- public void read(byte[] bs) {
- buf.get(bs);
- }
-
- /**
- * Read 1-byte integer from the current position in the file.
- */
- public int readByte() {
- return buf.get();
- }
-
- /**
- * Read 2-byte integer from the current position in the file.
- */
- public int readShort() {
- return buf.getShort();
- }
-
- /**
- * Read 4-byte integer from the current position in the file.
- */
- public int readInt() {
- return buf.getInt();
- }
-
- /**
- * Read 8-byte integer from the current position in the file.
- */
- public long readLong() {
- return buf.getLong();
- }
-
- /**
- * @return the size of string indeces for this file.
- */
- public int getStringIndexSize() {
- return StringIsShort ? 2 : 4;
- }
-
- /**
- * @return the size of GUID indeces for this file.
- */
- public int getGUIDIndexSize() {
- return GUIDIsShort ? 2 : 4;
- }
-
- /**
- * @return the size of Blob indeces for this file.
- */
- public int getBlobIndexSize() {
- return BlobIsShort ? 2 : 4;
- }
-
- /**
- * @return the size of the index to tableID for this file;
- * @param tableID the ID of the table
- */
- public int getTableIndexSize(int tableID) {
- return tables[tableID].isShort ? 2 : 4;
- }
-
- /**
- * @return the size of the index to a set of tables with the given @param TableSetID
- * @param tableSetID the ID of the table set
- */
- public int getTableSetIndexSize(int tableSetID) {
- return indexSize[tableSetID];
- }
-
- /**
- * Read a String index from the current position in the file.
- * @return an index into the String stream
- */
- public int readStringIndex() {
- return StringIsShort ? readShort() : readInt();
- }
-
- /**
- * Read a GUID index from the current position in the file.
- * @return an index in to the GUID stream
- */
- public int readGUIDIndex() {
- return GUIDIsShort ? readShort() : readInt();
- }
-
- /**
- * Read a Blob index from the current position in the file.
- * @return an index into the Blob stream
- */
- public int readBlobIndex() {
- return BlobIsShort ? readShort() : readInt();
- }
-
- /** Read an entry interpreted as index into table @param tableID. */
- public int readTableIndex(int tableId) {
- return tables[tableId].isShort ? readShort() : readInt();
- }
-
- /***/
- public int readTableSetIndex(int tableSetId) {
- return indexSize[tableSetId] == 2 ? readShort() : readInt();
- }
-
- /**
- * Read a string from the String stream
- * @return the string at the given position
- * @param pos the position of the string in the String stream
- */
- public String getString(int pos) {
- String s = Strings.getString(pos);
- return s;//.length() == 0 ? null : s;
- }
-
- /**
- * Read a string from the US (User Strings) stream
- * @return the string at the given position
- * @param pos the position of the string in the US stream
- */
- public String getUString(int pos) {
- return US.getString(pos);
- }
-
- /**
- * Read a blob from the Blob Stream
- * @return the blob at the given position
- * @param pos the position of the blob in the Blob stream
- */
- public byte[] getBlob(int pos) {
- return Blob.getBlob(pos);
- }
-
- /***/
- public Sig getSignature(int pos) {
- //return new Sig(getBlob(pos));
- return Blob.getSignature(pos);
- }
-
- /***/
- public byte[] getGUID(int pos) {
- return GUID.getGUID(pos);
- }
-
- /**
- * @return the table with the corresponding ID.
- */
- public final Table getTable(int tableID) {
- return tables[tableID];
- }
-
- //##########################################################################
-
- /***/
- void trace(String msg) {
- System.out.println("[trace] " + msg);
- }
-
- //##########################################################################
-
- public Sig newSignature(ByteBuffer buf) {
- return new Sig(buf);
- }
-
- /**
- */
- public class Sig implements Signature {
-
- //######################################################################
- // instance members
-
- protected final ByteBuffer buf;
- protected final int pos;
- protected final int length;
-
- public Sig(ByteBuffer buf) {
- this.buf = buf;
- //int tmpPos = buf.position();
- length = decodeInt();
- this.pos = buf.position();
- }
-
- public String toString() {
- StringBuffer b = new StringBuffer("(");
- int savedPos = buf.position();
- reset();
- for (int i = 0; i < length; i++) {
- b.append(byte2hex(readByte()));
- if (i < length - 1)
- b.append(" ");
- }
- buf.position(savedPos);
- return b.append(")").toString();
- }
-
- public Sig reset() { buf.position(pos); return this; }
-
- public int pos() { return buf.position() - pos; }
-
- /** @return the byte at the current position in the signature Blob.
- * Stay at the same position
- */
- public int getByte() {
- return (buf.get(buf.position()) + 0x100) & 0xff;
- }
-
- /** @return the byte at the current position in the signature Blob.
- * Move to the next byte.
- */
- public int readByte() { return (buf.get() + 0x100) & 0xff; }
-
- /** Skip the current byte if equal to the given value. */
- public void skipByte(int b) { if (b == getByte()) buf.get(); }
-
- /** Decodes an integer from the signature Blob.
- * @return the decoded integer
- */
- public int decodeInt() {
- int res = readByte();
- if ((res & 0x80) != 0) {
- res = ((res & 0x7f) << 8) | readByte();
- if ((res & 0x4000) != 0)
- res = ((res & 0x3fff)<<16) | (readByte()<<8) | readByte();
- }
- return res;
- }
-
- /** @return - the type encoded at the current position in the signature
- * according to 23.2.12
- */
- public Type decodeType() {
- try { return decodeType0(); }
- catch (RuntimeException e) {
- System.out.println("" + pos() + "@" + this);
- throw e;
- }
- }
-
- public Type decodeType0() {
- Type type = null;
- int desc = readByte();
- switch (desc) {
- case ELEMENT_TYPE_BOOLEAN:type = Type.GetType("System.Boolean"); break;
- case ELEMENT_TYPE_CHAR: type = Type.GetType("System.Char"); break;
- case ELEMENT_TYPE_I1: type = Type.GetType("System.SByte"); break;
- case ELEMENT_TYPE_U1: type = Type.GetType("System.Byte"); break;
- case ELEMENT_TYPE_I2: type = Type.GetType("System.Int16"); break;
- case ELEMENT_TYPE_U2: type = Type.GetType("System.UInt16"); break;
- case ELEMENT_TYPE_I4: type = Type.GetType("System.Int32"); break;
- case ELEMENT_TYPE_U4: type = Type.GetType("System.UInt32"); break;
- case ELEMENT_TYPE_I8: type = Type.GetType("System.Int64"); break;
- case ELEMENT_TYPE_U8: type = Type.GetType("System.UInt64"); break;
- case ELEMENT_TYPE_R4: type = Type.GetType("System.Single"); break;
- case ELEMENT_TYPE_R8: type = Type.GetType("System.Double"); break;
- case ELEMENT_TYPE_OBJECT: type = Type.GetType("System.Object"); break;
- case ELEMENT_TYPE_STRING: type = Type.GetType("System.String"); break;
- case ELEMENT_TYPE_I: type = Type.GetType("System.IntPtr"); break;
- case ELEMENT_TYPE_U: type = Type.GetType("System.UIntPtr"); break;
- case ELEMENT_TYPE_PTR: // Followed by <type> token.
- if (getByte() == ELEMENT_TYPE_VOID) {
- readByte();
- type = Type.mkPtr(Type.GetType("System.Void"));
- } else type = Type.mkPtr(decodeType());
- break;
- case ELEMENT_TYPE_BYREF: /* although BYREF is not listed in 23.2.12. as possible alternative, this method is also called when parsing the signatures of a method param and a method return, which do allow for BYREF */
- type = Type.mkByRef(decodeType());
- break;
- case ELEMENT_TYPE_VALUETYPE: // Followed by TypeDefOrRefEncoded
- assert true;
- case ELEMENT_TYPE_CLASS:
- // Followed by <type> token
- type = pemodule.getTypeDefOrRef(decodeInt());
- if (type == null) throw new RuntimeException();
- break;
-
- case ELEMENT_TYPE_SZARRAY: // Single-dim array with 0 lower bound.
- skipCustomMods();
- type = Type.mkArray(decodeType(), 1);
- break;
- case ELEMENT_TYPE_ARRAY:
- // <type> <rank> <boundsCount> <bound1> ... <loCount> <lo1> ...
- // ArrayShape defined in 23.2.13 ArrayShape
- Type elem = decodeType();
- int rank = decodeInt();
- int numSizes = decodeInt();
- for (int i = 0; i < numSizes; i++)
- decodeInt(); // TODO don't ignore
- int numLoBounds = decodeInt();
- for (int i = 0; i < numLoBounds; i++)
- decodeInt(); // TODO don't ignore
- type = Type.mkArray(elem, rank);
- break;
-
- // a grammar production from 23.2.12 Type
- // GENERICINST (CLASS | VALUETYPE) TypeDefOrRefEncoded GenArgCount Type*
- case ELEMENT_TYPE_GENERICINST:
- int b = readByte();
- /*- TODO don't ignore b as done above. Should .NET valuetypes be represented as Scala case classes? */
- Type instantiatedType = pemodule.getTypeDefOrRef(decodeInt());
- int numberOfTypeArgs = decodeInt();
- Type[] typeArgs = new Type[numberOfTypeArgs];
- for (int iarg = 0; iarg < numberOfTypeArgs; iarg++) {
- typeArgs[iarg] = decodeType();
- }
- type = new ConstructedType(instantiatedType, typeArgs);
- break;
-
- // another grammar production from 23.2.12 Type
- // ELEMENT_TYPE_VAR number The number non-terminal following MVAR
- // or VAR is an unsigned integer value (compressed).
- /* See also duplicate code in PEModule.java */
- case ELEMENT_TYPE_VAR:
- int typeArgAsZeroBased = decodeInt();
- type = new Type.TMVarUsage(typeArgAsZeroBased, true);
- break;
-
- // another grammar production from 23.2.12 Type
- // ELEMENT_TYPE_MVAR number The number non-terminal following MVAR
- // or VAR is an unsigned integer value (compressed).
- /* See also duplicate code in PEModule.java */
- case ELEMENT_TYPE_MVAR:
- typeArgAsZeroBased = decodeInt();
- type = new Type.TMVarUsage(typeArgAsZeroBased, false);
- break;
-
- case ELEMENT_TYPE_FNPTR:
- // Followed MethodDefSig or by MethodRefSig.
- case ELEMENT_TYPE_END:
- // Marks end of a list
- case ELEMENT_TYPE_CMOD_REQD:
- // Required modifier : followed by a TypeDef or TypeRef token.
- case ELEMENT_TYPE_CMOD_OPT:
- // Optional modifier : followed by a TypeDef or TypeRef token.
- case ELEMENT_TYPE_INTERNAL:
- // Implemented within the CLI.
- case ELEMENT_TYPE_MODIFIER:
- // Or'd with following element types.
- case ELEMENT_TYPE_SENTINEL:
- // Sentinel for varargs method signature.
- case ELEMENT_TYPE_PINNED:
- // Denotes a local variable that points at a pinned object.
- default:
- throw new RuntimeException(byte2hex(desc) +
- "@" + pos() + " in " + this);
-
- }
- if (type == null) throw new RuntimeException();
- return type;
- } // decodeType0()
-
- public PECustomMod decodeFieldType() {
- skipByte(FIELD); // 0x06
- CustomModifier[] cmods = getCustomMods();
- Type fieldType = decodeType();
- return new PECustomMod(fieldType, cmods);
- }
-
- /** decodes the return type of a method signature (22.2.11). */
- public Type decodeRetType() {
- skipCustomMods();
- switch (getByte()) {
- case ELEMENT_TYPE_VOID:
- readByte();
- return Type.GetType("System.Void");
- case ELEMENT_TYPE_TYPEDBYREF:
- return Type.GetType("System.TypedReference");
- case ELEMENT_TYPE_BYREF:
- return decodeType();
- default:
- return decodeType();
- }
- }
-
- public Type decodeParamType() {
- skipCustomMods();
- switch (getByte()) {
- case ELEMENT_TYPE_BYREF:
- return decodeType();
- case ELEMENT_TYPE_TYPEDBYREF:
- return Type.GetType("System.TypedReference");
- default:
- return decodeType();
- }
- }
-
- public void skipCustomMods() {
- while (getByte() == ELEMENT_TYPE_CMOD_OPT /* 0x20 */
- || getByte() == ELEMENT_TYPE_CMOD_REQD /* 0x1f */ )
- {
- boolean isREQD = (getByte() == ELEMENT_TYPE_CMOD_REQD); // 0x1f
- // skip the tag 23.2.7
- readByte();
- // skip the TypeDefOrRefEncoded (23.2.8)
- Type ignored = pemodule.getTypeDefOrRef(decodeInt());
- if(isREQD) {
- // System.err.println("ELEMENT_TYPE_CMOD_REQD: " + ignored);
- // throw new RuntimeException("Reqired CMOD: " + ignored);
- }
- }
- }
-
- /**
- * @see CustomModifier
- */
- public CustomModifier[] getCustomMods() {
- java.util.List/*<CustomModifier>*/ cmods = new java.util.LinkedList();
- while (getByte() == ELEMENT_TYPE_CMOD_OPT || getByte() == ELEMENT_TYPE_CMOD_REQD) {
- boolean isReqd = (getByte() == ELEMENT_TYPE_CMOD_REQD);
- readByte(); // tag 23.2.7
- Type t = pemodule.getTypeDefOrRef(decodeInt()); // TypeDefOrRefEncoded (23.2.8)
- cmods.add(new CustomModifier(isReqd, t));
- }
- CustomModifier[] res = (CustomModifier[])cmods.toArray(new CustomModifier[0]);
- return res;
- }
-
- //######################################################################
-
- } // class Sig
-
- //##########################################################################
-
-} // class PEFile
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/PEModule.java b/src/msil/ch/epfl/lamp/compiler/msil/PEModule.java
deleted file mode 100644
index cb8cd8f098..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/PEModule.java
+++ /dev/null
@@ -1,456 +0,0 @@
-/*
- * System.Reflection-like API for access to .NET assemblies (DLL & EXE)
- */
-
-
-package ch.epfl.lamp.compiler.msil;
-
-import ch.epfl.lamp.compiler.msil.PEFile;
-import ch.epfl.lamp.compiler.msil.PEFile.Sig;
-import ch.epfl.lamp.compiler.msil.util.Signature;
-import ch.epfl.lamp.compiler.msil.util.Table;
-import ch.epfl.lamp.compiler.msil.util.Table.*;
-
-import java.nio.ByteBuffer;
-
-/** Represents a module corresponding to a PE/COFF file
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-final class PEModule extends Module {
-
- //##########################################################################
-
- protected final PEFile pefile;
-
- private final int definingRow;
-
- private Type[] typeRefs = null;
-
- protected PEModule(PEFile pefile, int definingRow, String scopeName,
- Assembly assem)
- {
- super(pefile.getName(), pefile.getAbsolutePath(), scopeName, assem);
- this.pefile = pefile;
- this.definingRow = definingRow;
- pefile.initModule(this);
- pefile.TypeDef.load(); // load into memory
- //loadTypes();
- //pefile.FieldDef.load();
- //pefile.MethodDef.load();
- loadGlobals();
- }
-
- //##########################################################################
-
- public Type GetType(String typeName) {
- initTypes();
- Object o = typesMap.get(typeName);
- if (o == null) {
- //System.out.println("PEModule.GetType(): Unable to find type "
- // + typeName + " int module " + this);
- return null;
- }
- return o instanceof Type ? (Type)o
- : getTypeDef(((Integer)o).intValue());
- }
-
-
- /** Load information about the types defined in this module.
- */
- protected void loadTypes() {
- typeRefs = new Type[pefile.TypeRef.rows];
- final int nbTypes = pefile.TypeDef.rows;
- for (int row = 2; row <= nbTypes; row++) {
- String name = pefile.TypeDef(row).getFullName();
- typesMap.put(name, new Integer(row));
- }
- this.types = new Type[nbTypes - 1];
- for (int row = 2; row <= nbTypes; row++) {
- getTypeDef(row);
- }
- }
-
- /** Return the type defined at the given row in the TypeDef table.
- */
- Type getTypeDef(int row) {
- if (this.types[row - 2] != null)
- return this.types[row - 2];
-
- TypeDef type = pefile.TypeDef(row);
- int attrs = type.Flags;
- String name = type.getFullName();
-
- Type declType = null;
- if (TypeAttributes.isNested(attrs)) {
- for (int i = 1; i <= pefile.NestedClass.rows; i++) {
- pefile.NestedClass.readRow(i);
- if (pefile.NestedClass.NestedClass == row)
- declType = getTypeDef
- (pefile.NestedClass.EnclosingClass);
- }
- }
- Type t = new PEType
- (this, attrs, name, declType, Type.AuxAttr.None, pefile, row);
- types[row - 2] = t;
- addType(t);
- int[] tvarIdxes = pefile.GenericParam.getTVarIdxes(row);
- // if(tvarIdxes.length > 0) { System.out.println("Type: " + t); }
- for(int i = 0; i < tvarIdxes.length; i++) {
- GenericParamAndConstraints tvarAndConstraints = getTypeConstraints(tvarIdxes[i]);
- // add tvarAndConstraints as i-th TVar in t
- t.addTVar(tvarAndConstraints);
- }
- return t;
- }
-
- public GenericParamAndConstraints getTypeConstraints(int genParamIdx) {
- int tvarNumber = pefile.GenericParam(genParamIdx).Number;
- // tvarName can be null
- String tvarName = pefile.GenericParam.getName();
- boolean isInvariant = pefile.GenericParam.isInvariant();
- boolean isCovariant = pefile.GenericParam.isCovariant();
- boolean isContravariant = pefile.GenericParam.isContravariant();
- boolean isReferenceType = pefile.GenericParam.isReferenceType();
- boolean isValueType = pefile.GenericParam.isValueType();
- boolean hasDefaultConstructor = pefile.GenericParam.hasDefaultConstructor();
- // grab constraints
- int[] TypeDefOrRefIdxes = pefile.GenericParamConstraint.getTypeDefOrRefIdxes(genParamIdx);
- Type[] tCtrs = new Type[TypeDefOrRefIdxes.length];
- for(int i = 0; i < TypeDefOrRefIdxes.length; i++) {
- Type tConstraint = getTypeDefOrRef(TypeDefOrRefIdxes[i]);
- tCtrs[i] = tConstraint;
- // System.out.println("\t\tConstraint: " + tConstraint);
- }
- GenericParamAndConstraints res = new GenericParamAndConstraints(tvarNumber, tvarName, tCtrs,
- isInvariant, isCovariant, isContravariant,
- isReferenceType, isValueType, hasDefaultConstructor);
- return res;
- }
-
- /**
- * Load the desription of the module-global fields and methods
- */
- protected void loadGlobals() {
- //TODO:
- }
-
- protected void loadCustomAttributes(Type attributeType) {
- initAttributes(this, 1, Table.ModuleDef.ID, attributeType);
- }
-
- /** Return the type referenced by the given row in the TypeRef table.
- */
- Type getTypeRef(int row) {
- return getTypeRef(row, null);
- }
-
- /** Return the type referenced by the given row in the TypeRef table
- * only if it resides in the given assembly.
- * <i>Used by initCustomAttributes to avoid unnecessary loading
- * of referenced assemblies.</i>
- */
- Type getTypeRef(int row, Assembly inAssembly) {
- Type type = typeRefs[row - 1];
- if (type != null)
- return type;
-
- Table.TypeRef tr = pefile.TypeRef;
- tr.readRow(row);
- int tableId = Table.getTableId(Table._ResolutionScope,
- tr.ResolutionScope);
- int refRow = tr.ResolutionScope >> Table.NoBits[Table._ResolutionScope];
- final String typeName = tr.getFullName();
- pefile.getTable(tableId).readRow(refRow);
- switch (tableId) {
- case AssemblyRef.ID:
- String name = pefile.AssemblyRef.getName();
- if (inAssembly != null && !inAssembly.GetName().Name.equals(name))
- return null;
- Assembly assem = getAssembly(name);
- type = assem.GetType(typeName);
- if (type == null) {
- // HACK: the IKVM.OpenJDK.Core assembly is compiled against mscorlib.dll v2.0
- // The MSIL library cannot parse the v2.0 mscorlib because of generics, so we
- // use the v1.0
- // However, the java.io.FileDescriptor.FlushFileBuffers method uses a type
- // Microsoft.Win32.SafeHandles.SafeFileHandle, which only exists in mscorlib
- // v2.0
- // For now, jsut return Object (fine as long as we don't use that method).
- Assembly asmb = getAssembly("mscorlib");
- type = asmb.GetType("System.Object");
- //throw new RuntimeException("Failed to locate type " +
- //typeName + " in assembly " + assem);
- }
- break;
- case ModuleDef.ID:
- assert refRow == 1;
- type = this.GetType(typeName);
- //assert type != null;
- break;
- case TypeRef.ID:
- Type nestingType = getTypeRef(refRow);
- String nestedName = typeName;
- type = nestingType.GetNestedType(nestedName);
- break;
- case ModuleRef.ID:
- type = getAssembly(pefile.ModuleRef.getName()).GetType(typeName);
- default:
- throw new RuntimeException(refRow + "@" + pefile.getTable(tableId).getTableName()/* PEFile.byte2hex(tableId)*/);
- }
- if (typeRefs[row - 1] != null)
- System.out.println("TypeRef[" + PEFile.short2hex(row) + "] " +
- "changing type " + typeRefs[row - 1] +
- " for type " + type);
- typeRefs[row - 1] = type;
- assert type != null : "Couldn't find type " + typeName;
- return type;
- }
-
- private Assembly getAssembly(String name) {
- Assembly assem = Assembly.getAssembly(name);
- if (assem != null)
- return assem;
- java.io.File dir = pefile.getParentFile();
- assem = Assembly.LoadFrom(dir, name);
- if (assem != null)
- return assem;
- try {
- dir = pefile.getUnderlyingFile().getCanonicalFile().getParentFile();
- } catch (java.io.IOException e) {
- throw new RuntimeException(e);
- }
- assem = Assembly.LoadFrom(dir, name);
- if (assem != null)
- return assem;
- throw new RuntimeException("Cannot find assembly: " + name);
-
- }
-
- /** Return the type corresponding to TypeDefOrRef coded index.
- * @param index - TypeDefOrRef coded index according to 23.2.6.
- */
- public Type getTypeDefOrRef(int index) {
- int tableId = Table.getTableId(Table._TypeDefOrRef, index);
- int row = index >> Table.NoBits[Table._TypeDefOrRef];
- Type type = null;
- switch (tableId) {
- case Table.TypeDef.ID:
- type = getTypeDef(row);
- break;
- case Table.TypeRef.ID:
- return getTypeRef(row);
- case Table.TypeSpec.ID:
- Table.TypeSpec ts = pefile.TypeSpec;
- ts.readRow(row);
- int posInBlobStream = ts.Signature;
- byte[] blobArrWithLengthStripped = pefile.Blob.getBlob(posInBlobStream);
- byte[] compressedUInt = compressUInt(blobArrWithLengthStripped.length);
- byte[] byteArr = new byte[blobArrWithLengthStripped.length + compressedUInt.length];
- System.arraycopy(compressedUInt, 0, byteArr, 0, compressedUInt.length);
- System.arraycopy(blobArrWithLengthStripped, 0, byteArr, compressedUInt.length, blobArrWithLengthStripped.length);
- ByteBuffer buf = ByteBuffer.wrap(byteArr);
- Sig sig = pefile.new Sig(buf);
- int desc = sig.readByte();
-
- switch (desc) {
-
- // GENERICINST (CLASS | VALUETYPE) TypeDefOrRefEncodred GenArgCount Type*
- case Signature.ELEMENT_TYPE_GENERICINST: // i.e. 0x15
- int b = sig.readByte(); // i.e. (0x12 | 0x11)
- /* TODO don't ignore b as done above */
- Type instantiatedType = getTypeDefOrRef(sig.decodeInt()); // TypeDefOrRefEncoded
- int numberOfTypeArgs = sig.decodeInt(); // GenArgCount
- Type[] typeArgs = new Type[numberOfTypeArgs];
- for (int iarg = 0; iarg < numberOfTypeArgs; iarg++) {
- typeArgs[iarg] = sig.decodeType(); // Type*
- }
- type = new ConstructedType(instantiatedType, typeArgs);
- break;
-
- /* Miguel says: Actually the following grammar rule production is not among those for a TypeSpecBlob
- but I've found it in assemblies compiled from C# 3.0.
- See also duplicate code in PEFile.java */
- case Signature.ELEMENT_TYPE_VAR:
- int typeArgAsZeroBased = sig.decodeInt();
- type = new Type.TMVarUsage(typeArgAsZeroBased, true);
- break;
-
- /* Miguel says: Actually the following grammar rule production is not among those for a TypeSpecBlob
- but I've found it in assemblies compiled from C# 3.0.
- See also duplicate code in PEFile.java */
- case Signature.ELEMENT_TYPE_MVAR:
- typeArgAsZeroBased = sig.decodeInt();
- type = new Type.TMVarUsage(typeArgAsZeroBased, false);
- break;
-
- case Signature.ELEMENT_TYPE_SZARRAY: // Single-dim array with 0 lower bound.
- sig.skipCustomMods();
- type = Type.mkArray(sig.decodeType(), 1);
- break;
-
- case Signature.ELEMENT_TYPE_ARRAY:
- // <type> <rank> <boundsCount> <bound1> ... <loCount> <lo1> ...
- // ArrayShape defined in 23.2.13 ArrayShape
- Type elem = sig.decodeType();
- int rank = sig.decodeInt();
- int numSizes = sig.decodeInt();
- for (int i = 0; i < numSizes; i++)
- sig.decodeInt(); // TODO don't ignore
- int numLoBounds = sig.decodeInt();
- for (int i = 0; i < numLoBounds; i++)
- sig.decodeInt(); // TODO don't ignore
- type = Type.mkArray(elem, rank);
- break;
-
- default:
- // TODO remaining grammar productions in 23.2.14 are for PTR and FNPTR only
- throw new RuntimeException("PEModule.getTypeDefOrRef(): TypeSpec");
- }
- break;
- default:
- throw new RuntimeException("PEModule.getTypeDefOrRef(): oops!");
- }
- return type;
- }
-
- private byte[] compressUInt(int u) {
- // 23.2 in Partition II
- // TODO add tests based on the examples in 23.2 in Partition II
- // the CCI implementation is WriteCompressedUInt
-
- /* informal discussion at http://www.cnblogs.com/AndersLiu/archive/2010/02/09/en-compressed-integer-in-metadata.html */
- if (u <= 127 && 0 <= u) {
- return new byte[]{(byte) u};
- } else if (u > 127 && u <= (2 ^ 14 - 1)) {
- byte loByte = (byte)(u & 0xff);
- byte hiByte = (byte)((u >> 8) | 0x80);
- byte[] res = new byte[] { hiByte, loByte };
- return res;
- } else {
- byte b0 = (byte)(u & 0xff);
- byte b1 = (byte)((u & 0xff00)>>8);
- byte b2 = (byte)((u & 0xff0000)>>16);
- byte b3 = (byte)((u >> 24)|0xc0);
- byte[] res = new byte[] { b3, b2, b1, b0 };
- return res;
- }
- }
-
- /**
- * Returns the method defined at the given row of the MethodDef table
- * by looking up the type that defines the method.
- */
- MethodBase getMethod(int row) {
- for (int i = 0; i < types.length; i++) {
- PEType type = (PEType)types[i];
- if ((type.methodListBeg <= row) && (row < type.methodListEnd)) {
- type.initMethods();
- return type.methoddefs[row - type.methodListBeg];
- }
- }
- throw new RuntimeException("In module " + this
- + ": cannot find type defining method 0x"
- + PEFile.int2hex(row));
- }
-
- /** Returns the member referenced by the given row of the MemberRef table.
- */
- protected MemberInfo getMemberRef(int row) {
- return getMemberRef(row, null);
- }
-
- /** Returns the member referenced by the given row of the MemberRef table
- * if defined in the given assembly.
- * <i>Used by initCustomAttributes to avoid unnecessary loading of
- * referenced assemblies</i>
- */
- protected MemberInfo getMemberRef(int row, Assembly inAssembly) {
- MemberInfo member = null;
- MemberRef mref = pefile.MemberRef;
- mref.readRow(row);
- int mtbl = Table.getTableId(Table._MemberRefParent, mref.Class);
- int mind = Table.getTableIndex(Table._MemberRefParent, mref.Class);
- switch (mtbl) {
- case TypeRef.ID:
- Type type = getTypeRef(mind, inAssembly);
- if (type == null)
- return null;
- Sig sig = mref.getSignature();
- int callconv = sig.readByte(); // should be 0x20
- int paramCount = sig.decodeInt();
- //sig.skipByte(Signature.ELEMENT_TYPE_BYREF); //from MethodDef
- Type retType = sig.decodeRetType();
- Type[] paramType = new Type[paramCount];
- for (int i = 0; i < paramCount; i++)
- paramType[i] = sig.decodeParamType();
-
- String memberName = mref.getName();
- if (memberName.equals(ConstructorInfo.CTOR) ||
- memberName.equals(ConstructorInfo.CCTOR))
- {
- member = type.GetConstructor(paramType);
- } else {
- member = type.GetMethod(memberName, paramType);
- }
- assert member != null : type + "::" + memberName;
- break;
- case ModuleRef.ID:
- case MethodDef.ID:
- case TypeSpec.ID:
- throw new RuntimeException("initCustomAttributes: "
- + pefile.getTable(mtbl).getTableName());
- }
- return member;
- }
-
- protected void initCustomAttributes(Type attributeType) {
- initAttributes(this, definingRow, Table.ModuleDef.ID, attributeType);
- }
-
- // explicitly only package-visible
- void initAttributes(CustomAttributeProvider cap, int definingRow,
- int sourceTableId, Type attributeType)
- {
- int parentIndex = Table.encodeIndex(definingRow,
- Table._HasCustomAttribute,
- sourceTableId);
- Table.CustomAttribute attrs = pefile.CustomAttribute;
- for (int row = 1; row <= attrs.rows; row++) {
- ConstructorInfo attrConstr = null;
- attrs.readRow(row);
- if (attrs.Parent == parentIndex) {
- int tableId = Table.getTableId(Table._CustomAttributeType,
- attrs.Type);
- int ind = Table.getTableIndex(Table._CustomAttributeType,
- attrs.Type);
- switch (tableId) {
- case MethodDef.ID:
- attrConstr = (ConstructorInfo)this.getMethod(ind);
- break;
- case MemberRef.ID:
- //System.out.println(PEFile.short2hex(ind) + "@MemberRef");
- Assembly attrAssem =
- attributeType == null ? null : attributeType.Assembly();
- MemberInfo mi = this.getMemberRef(ind, attrAssem);
- if (mi != null) {
- assert mi instanceof ConstructorInfo
- : "Expected ConstructorInfo; found " + mi;
- attrConstr = (ConstructorInfo)mi;
- }
- break;
- default:
- throw new RuntimeException();
- }
- if (attrConstr != null
- && (attrConstr.DeclaringType == attributeType
- || attributeType == null))
- cap.addCustomAttribute(attrConstr, attrs.getValue());
- }
- }
- }
-
- //##########################################################################
-
-} // class PEModule
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/PEType.java b/src/msil/ch/epfl/lamp/compiler/msil/PEType.java
deleted file mode 100644
index 418c6603b3..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/PEType.java
+++ /dev/null
@@ -1,419 +0,0 @@
-/*
- * System.Reflection-like API for access to .NET assemblies (DLL & EXE)
- */
-
-
-package ch.epfl.lamp.compiler.msil;
-
-import ch.epfl.lamp.compiler.msil.PEFile.Sig;
-
-import ch.epfl.lamp.compiler.msil.util.Table;
-import ch.epfl.lamp.compiler.msil.util.Table.*;
-import ch.epfl.lamp.compiler.msil.util.Signature;
-import ch.epfl.lamp.compiler.msil.util.PECustomMod;
-
-import java.util.ArrayList;
-
-/**
- * Represents a type from a .NET assembly
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-final class PEType extends Type implements Signature {
-
- //##########################################################################
-
- /** The PEFile that holds the description of the type. */
- final PEFile file;
-
- /** The number of the row in the TypeDef table defining the type. */
- final int definingRow;
-
- /** The row of the first method in the MethodDef table. */
- final int methodListBeg;
-
- /** The row of the last method in the MethodDef table + 1. */
- final int methodListEnd;
-
- /** @param definingRow - the index in the TypeDef table where
- * the type description is.
- */
- PEType(PEModule module,
- int attributes,
- String fullName,
- Type declType,
- int auxAttr,
- PEFile file,
- int definingRow)
- {
- super(module, attributes, fullName, null, null, declType, auxAttr);
- this.file = file;
- this.definingRow = definingRow;
- methodListBeg = file.TypeDef(definingRow).MethodList;
- methodListEnd = definingRow < file.TypeDef.rows
- ? file.TypeDef(definingRow + 1).MethodList
- : file.MethodDef.rows + 1;
- }
-
- //##########################################################################
- // lazy type construction methods
-
- protected void loadBaseType() {
- TypeDef type = file.TypeDef(definingRow);
- baseType = type.Extends == 0 ? null
- : ((PEModule)Module).getTypeDefOrRef(type.Extends);
- }
-
- protected void loadFields() {
- // the list of the declared fields starts from the
- // FieldList index in the TypeDef table up to the smaller of the:
- // - the last row of the FieldDef table
- // - the start of the next list of fields determined by the
- // FieldList index of the next row in the TypeDef table
- final ArrayList fields = new ArrayList();
- int fieldListBeg = file.TypeDef(definingRow).FieldList;
- int fieldListEnd = file.FieldDef.rows + 1;
- if (definingRow < file.TypeDef.rows)
- fieldListEnd = file.TypeDef(definingRow + 1).FieldList;
-
- for (int row = fieldListBeg; row < fieldListEnd; row++) {
- int frow = file.FieldTrans.rows == 0
- ? row : file.FieldTrans(row).Field;
- int attrs = file.FieldDef(frow).Flags;
- String name = file.FieldDef.getName();
- //System.out.println("\t-->Loading field: " + name);
- Sig sig = file.FieldDef.getSignature();
- PECustomMod pecmod = sig.decodeFieldType();
- Object val = null;
- Table.Constant consts = file.Constant;
- for (int i = 1; i <= consts.rows; i++) {
- consts.readRow(i);
- int tableId = Table.getTableId(Table._HasConstant,consts.Parent);
- int refRow = consts.Parent >> Table.NoBits[Table._HasConstant];
- if (tableId == Table.FieldDef.ID && refRow == frow)
- val = consts.getValue();
- }
- FieldInfo field = new PEFieldInfo(row, name, attrs, pecmod, val);
- if (field.Name.equals("value__") && field.IsSpecialName()) {
- assert underlyingType == null : underlyingType.toString();
- underlyingType = field.FieldType;
- }
- fields.add(field);
- }
- this.fields = (FieldInfo[])
- fields.toArray(FieldInfo.EMPTY_ARRAY);
- fields.clear();
- }
-
- protected MethodBase[] methoddefs;
-
- protected MethodInfo getMethod(int n) {
- return (MethodInfo)methoddefs[n - methodListBeg];
- }
-
- protected void loadMethods() {
- methoddefs = new MethodBase[methodListEnd - methodListBeg];
-
- final ArrayList methods = new ArrayList();
- final ArrayList constrs = new ArrayList();
- PEModule pemodule = (PEModule) Module;
- for (int row = methodListBeg; row < methodListEnd; row++) {
- int mrow = file.MethodTrans.rows == 0
- ? row : file.MethodTrans(row).Method;
- int attrs = file.MethodDef(mrow).Flags;
- String name = file.MethodDef.getName();
- Sig sig = file.MethodDef.getSignature();
- /* we're about to parse a MethodDefSig, defined in Sec. 23.2.1 of Partition II () */
-
- int callConv = sig.readByte();
- // TODO decode HASTHIS from high byte of calling convention
- // TODO decode EXPLICITTHIS from high byte of calling convention
- // TODO handle VARARG calling convention (not CLS but may show up )
- if((callConv & 0x1F) == Signature.GENERIC) {
- int genParamCount = sig.decodeInt();
- /* genParamCount is ignored because the method's type params will be obtained below
- (see: file.GenericParam.getMVarIdxes(row) ) */
- }
- int paramCount = sig.decodeInt();
- Type retType = sig.decodeRetType();
- Type[] paramType = new Type[paramCount];
- for (int i = 0; i < paramCount; i++)
- paramType[i] = sig.decodeParamType();
-
- ParameterInfo[] params = new ParameterInfo[paramCount];
- int paramListBeg = file.MethodDef.ParamList;
- int paramListEnd = paramListBeg + paramCount;
- if (paramListEnd > file.ParamDef.rows) {
- /* don't try to read param names past ParamDef's row count
- Some assembly-writers don't bother to give names for all params. */
- paramListEnd = file.ParamDef.rows + 1;
- }
- for (int i = paramListBeg; i < paramListEnd; i++) {
- int pattr = file.ParamDef(i).Flags;
- String paramName = file.ParamDef.getName();
- int seq = file.ParamDef.Sequence;
- if (seq == 0) {
- //System.out.println("Retval attributes 0x" +
- // PEFile.short2hex(pattr));
- } else {
- params[seq - 1] = new ParameterInfo(paramName, paramType[seq - 1], pattr, seq - 1);
- }
- }
- for (int i = 0; i < params.length; i++) {
- if (params[i] == null)
- params[i] = new ParameterInfo(null, paramType[i], 0, 0);
- }
- MethodBase method = null;
- if ((attrs & MethodAttributes.SpecialName) != 0
- && (attrs & MethodAttributes.RTSpecialName) != 0
- && (name.equals(ConstructorInfo.CTOR)
- || name.equals(ConstructorInfo.CCTOR)))
- {
- method = new PEConstructorInfo(row, attrs, params);
- }
- else {
- method = new PEMethodInfo(row, name, attrs, retType, params);
- int[] mvarIdxes = file.GenericParam.getMVarIdxes(row);
- // if(mvarIdxes.length > 0) { System.out.println("Method: " + method); }
- for(int i = 0; i < mvarIdxes.length; i++) {
- GenericParamAndConstraints mvarAndConstraints = pemodule.getTypeConstraints(mvarIdxes[i]);
- // add mvarAndConstraints as i-th MVar in method
- ((PEMethodInfo)method).addMVar(mvarAndConstraints);
- }
- }
- (method.IsConstructor() ? constrs : methods).add(method);
- methoddefs[row - methodListBeg] = method;
- }
-
- this.constructors = (ConstructorInfo[])
- constrs.toArray(ConstructorInfo.EMPTY_ARRAY);
- this.methods = (MethodInfo[])
- methods.toArray(MethodInfo.EMPTY_ARRAY);
- constrs.clear(); methods.clear();
- }
-
- protected void loadProperties() {
- final PropertyMap pmap = file.PropertyMap;
- if (pmap == null) {
- properties = PropertyInfo.EMPTY_ARRAY;
- return;
- }
-
- final PropertyDef pdef = file.PropertyDef;
- int propListBeg = -1;
- int propListEnd = pdef.rows + 1;
- for (int i = 1; i <= pmap.rows; i++) {
- pmap.readRow(i);
- if (pmap.Parent == this.definingRow) {
- propListBeg = pmap.PropertyList;
- if (i < pmap.rows) {
- pmap.readRow(i + 1);
- propListEnd = pmap.PropertyList;
- }
- break;
- }
- }
- if (propListBeg < 0) {
- properties = PropertyInfo.EMPTY_ARRAY;
- return;
- }
-
- final ArrayList properties = new ArrayList();
- for (int i = propListBeg; i < propListEnd; i++) {
- pdef.readRow(i);
- Sig sig = pdef.getSignature();
- int b = sig.readByte();
- b &= ~HASTHIS;
- int paramCount = sig.readByte();
- assert b == PROPERTY;
- Type propType = sig.decodeType();
- int index = Table.encodeIndex(i, Table._HasSemantics,
- Table.PropertyDef.ID);
- MethodSemantics msem = file.MethodSemantics;
- MethodInfo getter = null, setter = null;
- for (int j = 1; j <= msem.rows; j++) {
- msem.readRow(j);
- if (msem.Association != index)
- continue;
- if (msem.isGetter())
- getter = getMethod(msem.Method);
- else if (msem.isSetter())
- setter = getMethod(msem.Method);
- else
- System.err.println("PEType.loadProperties(): !?!");
- }
- properties.add
- (new PEPropertyInfo(i, pdef.getName(), (short)pdef.Flags,
- propType, getter, setter));
- }
- this.properties = (PropertyInfo[]) properties
- .toArray(PropertyInfo.EMPTY_ARRAY);
- }
-
- protected void loadEvents() {
- EventMap emap = file.EventMap;
- if (emap == null) {
- this.events = EventInfo.EMPTY_ARRAY;
- return;
- }
-
- final EventDef edef = file.EventDef;
- int eventListBeg = -1;
- int eventListEnd = edef.rows + 1;
- for (int i = 1; i <= emap.rows; i++) {
- emap.readRow(i);
- if (emap.Parent == this.definingRow) {
- eventListBeg = emap.EventList;
- if (i < emap.rows) {
- emap.readRow(i + 1);
- eventListEnd = emap.EventList;
- }
- break;
- }
- }
- if (eventListBeg < 0) {
- this.events = EventInfo.EMPTY_ARRAY;
- return;
- }
-
- final ArrayList events = new ArrayList();
- final MethodSemantics msem = file.MethodSemantics;
- for (int i = eventListBeg; i < eventListEnd; i++) {
- edef.readRow(i);
- final Type handler =
- ((PEModule)Module).getTypeDefOrRef(edef.EventType);
- int index =
- Table.encodeIndex(i, Table._HasSemantics, Table.EventDef.ID);
- MethodInfo add = null, remove = null;
- for (int j = 1; j <= msem.rows; j++) {
- msem.readRow(j);
- if (msem.Association != index)
- continue;
- if (msem.isAddOn())
- add = getMethod(msem.Method);
- else if (msem.isRemoveOn())
- remove = getMethod(msem.Method);
- else {
- }
- }
- events.add(new PEEventInfo(i, edef.getName(),
- (short)edef.EventFlags,
- handler, add, remove));
- }
- this.events = (EventInfo[]) events
- .toArray(EventInfo.EMPTY_ARRAY);
- }
-
- protected void loadNestedTypes() {
- final ArrayList nested = new ArrayList();
- for (int i = 1; i <= file.NestedClass.rows; i++) {
- file.NestedClass.readRow(i);
- if (file.NestedClass.EnclosingClass == this.definingRow)
- nested.add(((PEModule)Module)
- .getTypeDef(file.NestedClass.NestedClass));
- }
- this.nestedTypes = (Type[]) nested.toArray(Type.EmptyTypes);
- }
-
- protected void loadInterfaces() {
- // get the interfaces implemented by this class
- interfaces = Type.EmptyTypes;
- int index = file.InterfaceImpl.findType(definingRow);
- if (index > 0) {
- ArrayList ifaces = new ArrayList();
- for (int i = index; i <= file.InterfaceImpl.rows; i++) {
- file.InterfaceImpl.readRow(i);
- if (file.InterfaceImpl.Class != definingRow)
- break;
- ifaces.add(((PEModule)Module)
- .getTypeDefOrRef(file.InterfaceImpl.Interface));
- }
- interfaces = (Type[]) ifaces.toArray(new Type[ifaces.size()]);
- }
- }
-
- protected void loadCustomAttributes(Type attributeType) {
- initAttributes(this, definingRow, Table.TypeDef.ID, attributeType);
- }
-
- private void initAttributes(CustomAttributeProvider cap, int definingRow,
- int sourceTableId, Type attributeType)
- {
- ((PEModule)this.Module).initAttributes
- (cap, definingRow, sourceTableId, attributeType);
- }
-
- //##########################################################################
-
- private class PEFieldInfo extends FieldInfo {
- private final int definingRow;
- public PEFieldInfo(int definingRow, String name,
- int attrs, PECustomMod pecmod, Object value)
- {
- super(name, PEType.this, attrs, pecmod, value);
- this.definingRow = definingRow;
- }
- protected void loadCustomAttributes(Type attributeType) {
- PEType.this.initAttributes
- (this, definingRow, Table.FieldDef.ID, attributeType);
- }
- }
-
- private class PEMethodInfo extends MethodInfo {
- private final int definingRow;
- public PEMethodInfo(int row, String name,
- int attrs, Type retType, ParameterInfo[] params)
- {
- super(name, PEType.this, attrs, retType, params);
- this.definingRow = row;
- }
- protected void loadCustomAttributes(Type attributeType) {
- PEType.this.initAttributes
- (this, definingRow, Table.MethodDef.ID, attributeType);
- }
- }
-
- private class PEConstructorInfo extends ConstructorInfo {
- private final int definingRow;
- public PEConstructorInfo(int row, int attrs, ParameterInfo[] params) {
- super(PEType.this, attrs, params);
- this.definingRow = row;
- }
- protected void loadCustomAttributes(Type attributeType) {
- PEType.this.initAttributes
- (this, definingRow, Table.MethodDef.ID, attributeType);
- }
- }
-
- private class PEPropertyInfo extends PropertyInfo {
- private final int definingRow;
- public PEPropertyInfo(int row, String name, short attrs, Type propType,
- MethodInfo getter, MethodInfo setter)
- {
- super(name, PEType.this, attrs, propType, getter, setter);
- this.definingRow = row;
- }
- protected void loadCustomAttributes(Type attributeType) {
- PEType.this.initAttributes
- (this, definingRow, Table.PropertyDef.ID, attributeType);
- }
- }
-
- private class PEEventInfo extends EventInfo {
- private final int definingRow;
- public PEEventInfo(int row, String name, short attrs, Type handler,
- MethodInfo add, MethodInfo remove)
- {
- super(name, PEType.this, attrs, handler, add, remove);
- this.definingRow = row;
- }
- protected void loadCustomAttributes(Type attributeType) {
- PEType.this.initAttributes
- (this, definingRow, Table.EventDef.ID, attributeType);
- }
- }
-
- //##########################################################################
-
-} // class PEType
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/ParameterAttributes.java b/src/msil/ch/epfl/lamp/compiler/msil/ParameterAttributes.java
deleted file mode 100644
index d4360363fc..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/ParameterAttributes.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * System.Reflection-like API for access to .NET assemblies (DLL & EXE)
- */
-
-
-package ch.epfl.lamp.compiler.msil;
-
-/**
- * Defines the attributes that may be associated with a parameter.
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-public final class ParameterAttributes {
-
- // just to make the class uninstantiable
- private ParameterAttributes() {}
-
- //##########################################################################
-
- /** Specifies that there is no parameter attribute. */
- public static final short None = 0x0000;
-
- /** Specifies that the parameter is an input parameter. */
- public static final short In = 0x0001;
-
- /** Specifies that the parameter is an output parameter. */
- public static final short Out = 0x0002;
-
- /** Specifies that the parameter is a locale identifier. */
- public static final short Lcid = 0x0004;
-
- /** Specifies that the parameter is a return value. */
- public static final short Retval = 0x0008;
-
- /** Specifies that the parameter is optional.
- * Attention: In the specification the value is 0x0004 but
- * in mscorlib.dll that it Lcid and Optional is 0x0010
- */
- public static final short Optional = 0x0010;
-
- /** Specifies that the parameter has a default value. */
- public static final short HasDefault = 0x1000;
-
- /** Specifies that the parameter has field marshaling information. */
- public static final short HasFieldMarshal = 0x2000;
-
- /** Reserved. */
- public static final short Reserved3 = 0x4000;
-
- /** Reserved. */
- public static final short Reserved4 = (short)0x8000;
-
- /** Specifies that the parameter is reserved. */
- public static final short ReservedMask = (short)0xf000;
-
- /** Reserved: shall be zero in all conforming implementations. */
- public static final short Unused = (short) 0xcfe0;
-
- public static final String toString(int attrs) {
- StringBuffer s = new StringBuffer();
- if ((attrs & In) != 0) s.append("in ");
- if ((attrs & Out) != 0) s.append("out ");
- if ((attrs & Optional) != 0) s.append("opt ");
- if ((attrs & HasDefault) != 0) s.append("default(???) ");
- if ((attrs & HasFieldMarshal) != 0) s.append("marshal(???) ");
- return s.toString();
- }
-
- //##########################################################################
-
-} // class ParameterAttributes
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/ParameterInfo.java b/src/msil/ch/epfl/lamp/compiler/msil/ParameterInfo.java
deleted file mode 100644
index 877d7aa8a5..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/ParameterInfo.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * System.Reflection-like API for access to .NET assemblies (DLL & EXE)
- */
-
-
-package ch.epfl.lamp.compiler.msil;
-
-/**
- * Discovers the attributes of a parameter and provides access to
- * parameter metadata.
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-public class ParameterInfo extends CustomAttributeProvider {
-
- //##########################################################################
-
- /** Attributes of the parameter. */
- public final short Attributes;
-
- /** Name of the parameter. */
- public final String Name;
-
- /** Type of the parameter. */
- public final Type ParameterType;
-
- /** Position of the parameter in the parameter list. */
- public final int Position;
-
- //##########################################################################
-
- /** Is this an input parameter? */
- public final boolean IsIn() {
- return (Attributes & ParameterAttributes.In) != 0;
- }
-
- /** Is this an output parameter? */
- public final boolean IsOut() {
- return (Attributes & ParameterAttributes.Out) != 0;
- }
-
- /** Is this an Lcid? */
- public final boolean IsLcid() {
- return (Attributes & ParameterAttributes.Lcid) != 0;
- }
-
- /** Is this a return value? */
- public final boolean IsRetval() {
- return (Attributes & ParameterAttributes.Retval) != 0;
- }
-
- /** Is this an optional parameter? */
- public final boolean IsOptional() {
- return (Attributes & ParameterAttributes.Optional) != 0;
- }
-
- //##########################################################################
- // members not part of the public Reflection.ParameterInfo interface
-
- /** Initializes a new instance of the ParameterInfo class. */
- protected ParameterInfo(String name, Type type, int attr, int pos) {
- Name = name;
- ParameterType = type;
- Attributes = (short)attr;
- Position = pos;
- }
-
- public String toString() {
- return ParameterAttributes.toString(Attributes) + ParameterType + " "
- + Name;
- }
-
- //##########################################################################
-
-} // class ParameterInfo
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/PrimitiveType.java b/src/msil/ch/epfl/lamp/compiler/msil/PrimitiveType.java
deleted file mode 100644
index b19fe29869..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/PrimitiveType.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package ch.epfl.lamp.compiler.msil;
-
-import ch.epfl.lamp.compiler.msil.util.PECustomMod;
-
-public final class PrimitiveType extends Type {
- public PrimitiveType(Module module,
- int attributes,
- String fullName,
- Type baseType,
- Type[] interfaces,
- Type declType,
- int auxAttr,
- Type elemType) {
- super(module, attributes, fullName,
- baseType, interfaces, declType, auxAttr, elemType);
- clearMembers();
- }
-
- public void clearMembers() {
- fields = FieldInfo.EMPTY_ARRAY;
- methods = MethodInfo.EMPTY_ARRAY;
- constructors = ConstructorInfo.EMPTY_ARRAY;
- events = EventInfo.EMPTY_ARRAY;
-
- initBaseType();
- initInterfaces();
-
- initFields();
- initMethods();
- initEvents();
- initProperties();
- initNestedTypes();
- }
-
- public FieldInfo addField(String name, int attrs, Type fieldType) {
- PECustomMod fieldTypeWithMods = new PECustomMod(fieldType, null);
- FieldInfo res = new FieldInfo(name, this, attrs, fieldTypeWithMods, null);
- FieldInfo[] ms = new FieldInfo[fields.length + 1];
- System.arraycopy(fields, 0, ms, 0, fields.length);
- ms[ms.length - 1] = res;
- fields = ms;
- return res;
- }
-
- public MethodInfo addMethod(String name, int attrs, Type returnType, Type[] paramTypes) {
- MethodInfo res = new MethodInfo(name, this, attrs, returnType, paramTypes);
- MethodInfo[] ms = new MethodInfo[methods.length + 1];
- System.arraycopy(methods, 0, ms, 0, methods.length);
- ms[ms.length - 1] = res;
- return res;
- }
-
- public ConstructorInfo addConstructor(int attrs, Type[] paramTypes) {
- ConstructorInfo res = new ConstructorInfo(this, attrs, paramTypes);
- ConstructorInfo[] ms = new ConstructorInfo[constructors.length + 1];
- System.arraycopy(constructors, 0, ms, 0, constructors.length);
- ms[ms.length - 1] = res;
- return res;
- }
-
-}
-
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/PropertyAttributes.java b/src/msil/ch/epfl/lamp/compiler/msil/PropertyAttributes.java
deleted file mode 100644
index b1bec64aff..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/PropertyAttributes.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * System.Reflection-like API for access to .NET assemblies (DLL & EXE)
- */
-
-
-package ch.epfl.lamp.compiler.msil;
-
-/**
- * Attributes applcicable to properties
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-public final class PropertyAttributes {
-
- // makes the class uninstantiable
- private PropertyAttributes() {}
-
- //##########################################################################
-
- /** Specifies that the property is special, with the name describing
- * how the property is special.
- */
- public static final short SpecialName = 0x0200;
-
- /** Specifies that the metadata internal APIs check the name encoding.
- */
- public static final short RTSpecialName = 0x0400;
-
- /** Specifies that the property has a default value.
- */
- public static final short HasDefault = 0x1000;
-
- //##########################################################################
-
- public static String toString(short attrs) {
- StringBuffer str = new StringBuffer();
- if ((attrs & SpecialName) != 0) str.append("specialname ");
- if ((attrs & RTSpecialName) != 0) str.append("rtspecialname ");
- return str.toString();
- }
-
- //##########################################################################
-
-} // class PropertyAttributes
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/PropertyInfo.java b/src/msil/ch/epfl/lamp/compiler/msil/PropertyInfo.java
deleted file mode 100644
index 4b7cef8bc1..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/PropertyInfo.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * System.Reflection-like API for access to .NET assemblies (DLL & EXE)
- */
-
-
-package ch.epfl.lamp.compiler.msil;
-
-/**
- * Discovers the attributes of a property
- * and provides access to property metadata.
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-public class PropertyInfo extends MemberInfo {
-
- //##########################################################################
-
- public final int MemberType() { return MemberTypes.Property; }
-
- public final short Attributes;
-
- public final boolean CanRead;
-
- public final boolean CanWrite;
-
- public final Type PropertyType;
-
- /** Returns an array of the public get and set accessors for this property.
- */
- public MethodInfo[] GetAccessors() {
- return GetAccessors(false);
- }
-
- /** Returns an array of the public or non-public <b>get</b>
- * and <b>set</b> accessors for this property.
- */
- public MethodInfo[] GetAccessors(boolean nonPublic) {
- MethodInfo getter = GetGetMethod(nonPublic);
- MethodInfo setter = GetSetMethod(nonPublic);
- if (getter == null)
- if (setter == null) return MethodInfo.EMPTY_ARRAY;
- else return new MethodInfo[]{setter};
- else if (setter == null) return new MethodInfo[] {getter};
- else return new MethodInfo[] {getter, setter};
- }
-
- /** Returns the public <b>get</b> accessor for this property.
- */
- public MethodInfo GetGetMethod() {
- return GetGetMethod(false);
- }
-
- /** Returns the public or non-public <b>get</b> accessor for this property.
- */
- public MethodInfo GetGetMethod(boolean nonPublic) {
- return nonPublic ? getter
- : getter == null || getter.IsPublic() ? getter : null;
- }
-
- /** Returns the public <b>set</b> accessor for this property.
- */
- public MethodInfo GetSetMethod() {
- return GetSetMethod(false);
- }
-
- /** Returns the public or non-public <b>set</b> accessor for this property.
- */
- public MethodInfo GetSetMethod(boolean nonPublic) {
- return nonPublic ? setter
- : setter == null || setter.IsPublic() ? setter : null;
- }
-
- public String toString() {
- MethodInfo m = getter != null ? getter : setter;
- return MethodAttributes.accessFlagsToString
- ((getter != null ? getter : setter).Attributes)
- + " " + PropertyAttributes.toString(Attributes)
- + DeclaringType + "::" + Name;
- }
-
- //##########################################################################
- // protected members
-
- protected static final PropertyInfo[] EMPTY_ARRAY = new PropertyInfo[0];
-
- protected MethodInfo getter;
- protected MethodInfo setter;
-
- protected PropertyInfo(String name, Type declType, short attr,
- Type propType, MethodInfo getter, MethodInfo setter)
- {
- super(name, declType);
- Attributes = attr;
- PropertyType = propType;
- this.getter = getter;
- this.setter = setter;
- CanRead = getter != null;
- CanWrite = setter != null;
- }
-
- //##########################################################################
-
-} // class PropertyInfo
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/Type.java b/src/msil/ch/epfl/lamp/compiler/msil/Type.java
deleted file mode 100644
index 830632ce45..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/Type.java
+++ /dev/null
@@ -1,1142 +0,0 @@
-/*
- * System.Reflection-like API for access to .NET assemblies (DLL & EXE)
- */
-
-
-package ch.epfl.lamp.compiler.msil;
-
-import java.util.Map;
-import java.util.HashMap;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.Arrays;
-
-/**
- * Represents type declarations: class types, interface types, array types,
- * value types, and enumeration types.
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-public abstract class Type extends MemberInfo {
-
- private java.util.List /* GenericParamAndConstraints */ tVars = new java.util.LinkedList();
- private GenericParamAndConstraints[] sortedTVars = null;
-
- public void addTVar(GenericParamAndConstraints tvarAndConstraints) {
- sortedTVars = null;
- tVars.add(tvarAndConstraints);
- }
-
- public GenericParamAndConstraints[] getSortedTVars() {
- if(sortedTVars == null) {
- sortedTVars = new GenericParamAndConstraints[tVars.size()];
- for (int i = 0; i < sortedTVars.length; i ++){
- Iterator iter = tVars.iterator();
- while(iter.hasNext()) {
- GenericParamAndConstraints tvC = (GenericParamAndConstraints)iter.next();
- if(tvC.Number == i) {
- sortedTVars[i] = tvC;
- }
- }
- }
- }
- return sortedTVars;
- }
-
-
- //##########################################################################
- // public static members
-
- /** Empty array of type Type. */
- public static final Type[] EmptyTypes = new Type[0];
-
- /** Separates names in the namespace of the Type. */
- public static final char Delimiter = '.';
-
- //##########################################################################
- // public properties
-
- /** The fully qualified name of the Type. */
- public final String FullName;
-
- /** The namespace of the Type. */
- public final String Namespace;
-
- /** The type from which the current Type directly inherits. */
- public final Type BaseType() {
- initBaseType();
- return baseType;
- }
- protected Type baseType;
-
- /** The attributes associated with the Type. */
- public final int Attributes;
-
- /** The sssembly that the type is declared in. */
- public final Assembly Assembly() { return Module.Assembly; }
-
- /** The module (the EXE/DLL) in which the current Type is defined. */
- public final Module Module;
-
- public final int MemberType() {
- return DeclaringType == null
- ? MemberTypes.TypeInfo : MemberTypes.NestedType;
- }
-
- //##########################################################################
- // internal members
-
- // Fields declared by this class
- protected FieldInfo[] fields;
-
- // Methods declared by this class
- protected MethodInfo[] methods;
-
- // Constructors of this class
- protected ConstructorInfo[] constructors;
-
- // Properties of the class
- protected PropertyInfo[] properties;
-
- // Events of the class
- protected EventInfo[] events;
-
- // Interfaces implemented by this class
- protected Type[] interfaces;
-
- // Nested types declared by this class
- protected Type[] nestedTypes;
-
- // holds the element type of array, pointer and byref types
- private final Type elemType;
-
- // the underlying type of an enumeration. null if the type is not enum.
- protected Type underlyingType;
-
- protected int auxAttr;
-
- //##########################################################################
- // Map with all the types known so far and operations on it
-
- private static final Map types = new HashMap();
-
- protected static Type getType(String name) {
- return (Type) types.get(name);
- }
-
- protected static Type addType(Type t) {
- assert(!(t instanceof TMVarUsage));
- assert(!(t instanceof ConstructedType));
- Type oldType = (Type) types.put(t.FullName, t);
-// if (oldType != null)
-// throw new RuntimeException("The type: [" + t.Assembly + "]" + t
-// + " replaces the type: [" +
-// oldType.Assembly + "]" + oldType);
- return t;
- }
-
- //##########################################################################
-
- /** The main constructor. */
- protected Type(Module module,
- int attr,
- String fullName,
- Type baseType,
- Type[] interfaces,
- Type declType,
- int auxAttr,
- Type elemType)
- {
- super(fullName.lastIndexOf(Delimiter) < 0 ? fullName :
- fullName.substring(fullName.lastIndexOf(Delimiter) + 1,
- fullName.length()),
- declType);
-
- Module = module; // null only for TMVarUsage and for PrimitiveType
- Attributes = attr;
- this.baseType = baseType;
- if (DeclaringType == null) {
- FullName = fullName;
- int i = FullName.lastIndexOf(Delimiter);
- Namespace = (i < 0) ? "" : FullName.substring(0,i);
- } else {
- FullName = declType.FullName + "+" + fullName;
- Namespace = DeclaringType.Namespace;
- }
-
- this.interfaces = interfaces;
- this.elemType = elemType;
- this.auxAttr = auxAttr;
- }
-
- public final boolean IsAbstract() {
- return (Attributes & TypeAttributes.Abstract) != 0;
-
- }
- public final boolean IsPublic() {
- return (Attributes & TypeAttributes.VisibilityMask)
- == TypeAttributes.Public;
- }
-
- public final boolean IsNotPublic() {
- return (Attributes & TypeAttributes.VisibilityMask)
- == TypeAttributes.NotPublic;
- }
-
- public final boolean IsNestedPublic() {
- return (Attributes & TypeAttributes.VisibilityMask)
- == TypeAttributes.NestedPublic;
- }
-
- public final boolean IsNestedPrivate() {
- return (Attributes & TypeAttributes.VisibilityMask)
- == TypeAttributes.NestedPrivate;
- }
-
- public final boolean IsNestedFamily() {
- return (Attributes & TypeAttributes.VisibilityMask)
- == TypeAttributes.NestedFamily;
- }
-
- public final boolean IsNestedAssembly() {
- return (Attributes & TypeAttributes.VisibilityMask)
- == TypeAttributes.NestedAssembly;
- }
-
- public final boolean IsNestedFamORAssem() {
- return (Attributes & TypeAttributes.VisibilityMask)
- == TypeAttributes.NestedFamORAssem;
- }
-
- public final boolean IsNestedFamANDAssem() {
- return (Attributes & TypeAttributes.VisibilityMask)
- == TypeAttributes.NestedFamANDAssem;
- }
-
- public final boolean IsSealed() {
- return (Attributes & TypeAttributes.Sealed) != 0;
- }
-
- public final boolean IsSpecialName() {
- return (Attributes & TypeAttributes.SpecialName) != 0;
- }
-
- public final boolean IsClass() {
- return (Attributes & TypeAttributes.ClassSemanticsMask)
- == TypeAttributes.Class;
- }
-
- public final boolean IsInterface(){
- return (Attributes & TypeAttributes.ClassSemanticsMask)
- == TypeAttributes.Interface;
- }
-
- public final boolean IsAutoLayout() {
- return (Attributes & TypeAttributes.LayoutMask)
- == TypeAttributes.AutoLayout;
- }
- public final boolean IsExplictitLayout() {
- return (Attributes & TypeAttributes.LayoutMask)
- == TypeAttributes.ExplicitLayout;
- }
- public final boolean IsLayoutSequential() {
- return (Attributes & TypeAttributes.LayoutMask)
- == TypeAttributes.SequentialLayout;
- }
-
- public final boolean IsImport() {
- return (Attributes & TypeAttributes.Import) != 0;
- }
- public final boolean IsSerializable() {
- return (Attributes & TypeAttributes.Serializable) != 0;
- }
-
- public final boolean IsAnsiClass() {
- return (Attributes & TypeAttributes.StringFormatMask)
- == TypeAttributes.AnsiClass;
- }
-
- public final boolean IsUnicodeClass() {
- return (Attributes & TypeAttributes.StringFormatMask)
- == TypeAttributes.UnicodeClass;
- }
- public final boolean IsAutoClass() {
- return (Attributes & TypeAttributes.StringFormatMask)
- == TypeAttributes.AutoClass;
- }
-
- public final boolean IsArray() {
- return (auxAttr & AuxAttr.Array) != 0;
- }
- public final boolean IsByRef() {
- return (auxAttr & AuxAttr.ByRef) != 0;
- }
- public final boolean IsPointer() {
- return (auxAttr & AuxAttr.Pointer) != 0;
- }
- public final boolean IsPrimitive() {
- return (auxAttr & AuxAttr.Primitive) != 0;
- }
- public final boolean IsValueType() {
- return BaseType() == VALUE_TYPE() || IsEnum();
- }
- public final boolean IsEnum() {
- return BaseType() == ENUM();
- }
- public boolean CanBeTakenAddressOf() {
- /* TODO should be overridden in TMVarUsage,
- but there's currently no way to bind a TMVarUsage to its GenericParamAndConstraints definition. Why?
- Because of the way the msil library is organized (e.g., mkArray() returns the same !0[] representation
- for all !0[] usages, irrespective of the scope of the !0 type-param)
- This in turn is so because without generics there's no harm in using a type-def instance
- where a type-ref should go (e.g., the ParameterType of a ParameterInfo nowadays may point to a PEType).
- The net effect is that this method (CanBeTakenAddressOf) is conservative, it will answer "no"
- for example for !0 where !0 refers to a type-param with the isValuetype constraint set.
- The whole thing is ok at this point in time, where generics are not supported at the backend. */
- return IsValueType() && (this != ENUM());
- /* ENUM() is a singleton, i.e. System.Enum is not generic */
- }
-
- /** IsGeneric, true for a PEType or TypeBuilder (i.e., a type definition)
- * containing one or more type params. Not to be called on a reference
- * to a constructed type. */
- public final boolean IsGeneric() {
- return tVars.size() > 0;
- }
-
- public final boolean HasElementType() {
- return IsArray() || IsPointer() || IsByRef();
- }
-
- public boolean IsTMVarUsage() {
- // overridden in TMVarUsage
- return false;
- }
-
- public boolean IsNestedType() {
- return DeclaringType != null;
- }
-
- public boolean IsDefinitelyInternal() {
- if(IsNestedType()) {
- return IsNestedPrivate();
- } else {
- return IsNotPublic();
- }
- }
-
- //public final boolean IsCOMObject;
- //public final boolean IsContextful;
- //public final boolean IsMarshalByRef;
-
- protected Type(Module module,
- int attr,
- String fullName,
- Type baseType,
- Type[] interfaces,
- Type declType,
- int auxAttr)
- {
- this(module, attr, fullName, baseType, interfaces,
- declType, auxAttr, null);
- }
-
- //##########################################################################
-
- public static final class TMVarUsage extends Type {
-
- public final int Number;
- public final boolean isTVar;
-
- /** Non-defining reference to either a TVar or an MVar.
- * An instance of GenericParamAndConstraints represents a TVar or an MVar definition. */
- public TMVarUsage(int Number, boolean isTVar) {
- super(null, 0, ((isTVar ? "!" : "!!") + Number), null, null, null, AuxAttr.None, null);
- this.Number = Number;
- this.isTVar = isTVar;
- }
-
- public String toString() {
- return (isTVar ? "!" : "!!") + Number;
- }
-
- public final boolean IsTMVarUsage() {
- return true;
- }
-
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
-
- TMVarUsage that = (TMVarUsage) o;
-
- if (Number != that.Number) return false;
- if (isTVar != that.isTVar) return false;
-
- return true;
- }
-
- public int hashCode() {
- int result = Number;
- result = 31 * result + (isTVar ? 1 : 0);
- return result;
- }
- }
-
- protected static final class AuxAttr {
- public static final int None = 0x0000;
- public static final int Array = 0x0001;
- public static final int ByRef = 0x0002;
- public static final int Pointer = 0x0008;
- public static final int Primitive = 0x0010;
- }
-
- /***/
- public static Type mkArray(Type elemType, int rank) {
- StringBuffer arrSig = new StringBuffer("[");
- for (int i = 0; i < rank; i++) {
- if (i > 0) arrSig.append(',');
- }
- arrSig.append(']');
- Type array = getType(elemType.FullName + arrSig);
- if (array != null)
- return array;
- array = new PrimitiveType(elemType.Module,
- elemType.Attributes
- | TypeAttributes.Sealed
- | TypeAttributes.Serializable,
- elemType.FullName + arrSig,
- ARRAY(), EmptyTypes, null,
- AuxAttr.Array, elemType);
- return addType(array);
- }
-
- /***/
- public static Type mkPtr(Type elemType) {
- String name = elemType.FullName + "*";
- Type type = getType(name);
- if (type != null) return type;
- type = new PrimitiveType(elemType.Module,
- elemType.Attributes,
- name, null, EmptyTypes, null,
- AuxAttr.Pointer, elemType);
- return addType(type);
- }
-
- /***/
- public static Type mkByRef(Type elemType) {
- String name = elemType.FullName + "&";
- Type type = getType(name);
- if (type != null) return type;
- type = new PrimitiveType(elemType.Module,
- elemType.Attributes,
- name, null, EmptyTypes, null,
- AuxAttr.ByRef, elemType);
- return addType(type);
- }
-
- //##########################################################################
- // public methods
-
- /**
- * Return the type with the specified signature parameters.
- * For example, the fully qualified name for a class might look like this:
- * TopNamespace.SubNameSpace.ContainingClass+NestedClass,MyAssembly
- */
- public static Type GetType(String fullName) {
- Type type = getType(fullName);
- if (type != null) return type;
-
- // check if it's an array type; TODO: make array type handling more robust
- int i = fullName.lastIndexOf('[');
- int j = fullName.lastIndexOf(']');
- if (i >= 0)
- if (j > i && j == (fullName.length() - 1)) {
- String elementTypeName = fullName.substring(0, i);
- Type elementType = GetType(elementTypeName);
- if (elementType == null)
- throw new RuntimeException
- ("Unknown element type '" + elementTypeName +
- "' for the array type: " + fullName);
- int rank = j - i;
- for (int k = i + 1; k < j; k++) {
- if (fullName.charAt(k) != ',')
- throw new RuntimeException
- ("Malformed type name: " + fullName);
- }
- return mkArray(elementType, rank);
- } else
- throw new RuntimeException("Malformed type name: " + fullName);
-
- // check if it's a pointer type
- if (fullName.charAt(fullName.length() - 1) == '*')
- return addType
- (mkPtr(GetType(fullName.substring(0, fullName.length()-1))));
-
- // check if it's a nested class
- i = fullName.lastIndexOf('+');
- if (i > 0) {
- if (i == 0 || i == (fullName.length() - 1))
- throw new RuntimeException("malformedTypeName");
- Type enclosing = GetType(fullName.substring(0, i));
- return enclosing == null ? null
- : enclosing.GetNestedType(fullName.substring(i + 1));
- }
-
- //System.out.println("Looking for type: " + fullName + " (" + fullName.length() + ")");
- // try in the assemblies
- Iterator assems = ch.epfl.lamp.compiler.msil.Assembly.
- assemblies.values().iterator();
- while (type == null && assems.hasNext()) {
- Assembly assem = ((Assembly) assems.next());
- type = assem.GetType(fullName);
- //System.out.println("\tin assemby " + assem + " -> " + type);
- }
-
- Type type2 = getType(fullName);
- if (type == type2) return type;
- return type == null ? null : addType(type);
- }
-
- /**
- * @return the type of the object encompassed or referenced to
- * by the current array, pointer or reference type.
- */
- public Type GetElementType() {
- return elemType;
- }
-
- /**
- * @return the type underlying an enumeration type.
- */
- public Type getUnderlyingType() {
- if (!IsEnum()) return null;
- // this would force the loading of the underlying type from the
- // the type of the value__ field of the enumeration
- initFields();
- return underlyingType;
- }
-
- //##########################################################################
- // GetField/s/
-
- /** Searches for the field with the specified name. */
- public FieldInfo GetField(String name) {
- initFields();
- for (int i = 0; i < fields.length; i++)
- if (fields[i].Name.equals(name) && !fields[i].IsPrivate())
- return fields[i];
- return null;
- }
-
- /**
- */
- public FieldInfo GetField(String name, int bindingFlags) {
- FieldInfo[] fields = this.GetFields(bindingFlags);
- for (int i = 0; i < fields.length; i++)
- if (name.equals(fields[i].Name))
- return fields[i];
- return null;
- }
-
- /** Gets the fields of the current Type. */
- public FieldInfo[] GetFields() {
- return GetFields(BindingFlags.Instance | BindingFlags.Public);
- }
-
- /**
- */
- public FieldInfo[] GetFields(int bindingFlags) {
- initFields();
- final FieldInfo[] fields =
- getAllFields((bindingFlags & BindingFlags.DeclaredOnly) != 0);
- final boolean getInstance = (bindingFlags & BindingFlags.Instance) != 0;
- final boolean getStatic = (bindingFlags & BindingFlags.Static) != 0;
- final boolean getPublic = (bindingFlags & BindingFlags.Public) != 0;
- final boolean getNonPublic =
- (bindingFlags & BindingFlags.NonPublic) != 0;
-
- int cnt = 0;
- for (int i = 0; i < fields.length; i++) {
- FieldInfo field = fields[i];
- boolean accessible = (getPublic && field.IsPublic())
- || (getNonPublic && !field.IsPublic());
- if (accessible
- // strip off the private fields up the hierarchy
- && ((field.DeclaringType == this)
- || ((field.DeclaringType != this) && !field.IsPrivate()))
- && ((getInstance && !field.IsStatic())
- || ((getStatic && field.IsStatic()) &&
- (field.DeclaringType == this
- || (bindingFlags & BindingFlags.FlattenHierarchy) != 0))
- )
- )
- fields[cnt++] = field;
- }
- FieldInfo [] resFields = new FieldInfo[cnt];
- System.arraycopy(fields, 0, resFields, 0, cnt);
- return resFields;
- }
-
- protected FieldInfo[] getAllFields(boolean declaredOnly) {
- initFields();
- FieldInfo [] inherited = BaseType() == null || declaredOnly
- ? FieldInfo.EMPTY_ARRAY
- : BaseType().getAllFields(declaredOnly);
- FieldInfo[] allFields =
- new FieldInfo[inherited.length + this.fields.length];
- System.arraycopy(inherited, 0, allFields, 0, inherited.length);
- System.arraycopy(this.fields, 0,
- allFields, inherited.length, this.fields.length);
- return allFields;
- }
-
- //##########################################################################
- // GetConstructor/s/
-
- /** Searches for a public instance constructor whose parameters
- * match the types in the specified array. */
- public ConstructorInfo GetConstructor(Type[] paramTypes) {
- initMethods();
- for (int i = 0; i < constructors.length; i++) {
- if (equalParameters(constructors[i].GetParameters(), paramTypes))
- return constructors[i];
- }
- return null;
- }
-
- /** Returns all public instance constructors defined for the current Type.*/
- public ConstructorInfo[] GetConstructors() {
- return GetConstructors(BindingFlags.Instance | BindingFlags.Public);
- }
-
- /***/
- public ConstructorInfo[] GetConstructors(int bindingFlags) {
- initMethods();
- final boolean getInstance = (bindingFlags & BindingFlags.Instance) != 0;
- final boolean getStatic = (bindingFlags & BindingFlags.Static) != 0;
- final boolean getPublic = (bindingFlags & BindingFlags.Public) != 0;
- final boolean getNonPublic =
- (bindingFlags & BindingFlags.NonPublic) != 0;
-
- ConstructorInfo[] constrs =
- new ConstructorInfo[this.constructors.length];
- int cnt = 0;
- for (int i = 0; i < this.constructors.length; i++) {
- ConstructorInfo constr = this.constructors[i];
- boolean accessible = (getPublic && constr.IsPublic())
- || (getNonPublic && !constr.IsPublic());
- if (accessible
- && ((getInstance && !constr.IsStatic())
- || (getStatic && constr.IsStatic())))
- constrs[cnt++] = constr;
- }
- ConstructorInfo [] resConstrs = new ConstructorInfo[cnt];
- System.arraycopy(constrs, 0, resConstrs, 0, cnt);
- return resConstrs;
- }
-
- //##########################################################################
- // GetMethod/s/
-
- /** Searches for the specified public method whose parameters
- * match the specified argument types. */
- public MethodInfo GetMethod(String name, Type[] paramTypes) {
- return GetMethod(name, paramTypes, null);
- }
-
- public MethodInfo GetMethod(String name, Type[] paramTypes, Type retType) {
- initMethods();
- MethodInfo method = findMethod(methods, name, paramTypes, retType);
- if (method != null)
- return method;
- if (BaseType() != null) {
- method = BaseType().GetMethod(name, paramTypes, retType);
- if (method != null)
- return method;
- }
-// StringBuffer str = new StringBuffer(name);
-// str.append('(');
-// for (int i = 0; i < paramTypes.length; i++) {
-// if (i > 0) str.append(", ");
-// str.append(paramTypes[i]);
-// }
-// str.append(')');
-// System.out.println("Cannot find method " + str + ":");
-// System.out.println("Methods of class " + this);
-// for (int i = 0; i < methods.length; i++)
-// System.out.println("\t" + methods[i]);
- return null;
- }
-
- /**
- */
- protected static MethodInfo findMethod(MethodInfo[] methods,
- String name,
- Type[] paramTypes,
- Type retType)
- {
- for (int i = 0; i < methods.length; i++)
- if (name.equals(methods[i].Name)
- && equalParameters(methods[i].GetParameters(), paramTypes)
- && (retType == null || methods[i].ReturnType == retType))
- return methods[i];
- return null;
- }
-
- /**
- */
- protected static boolean equalParameters(ParameterInfo[] params,
- Type[] paramTypes)
- {
- if (params.length != paramTypes.length)
- return false;
- for (int i = 0; i < params.length; i++) {
-// System.out.println(params[i].ParameterType + " == " + paramTypes[i]
-// + " = " + (params[i].ParameterType == paramTypes[i]));
- if (params[i].ParameterType != paramTypes[i])
- return false;
- }
- return true;
- }
-
- /**
- */
- public MethodInfo GetMethod(String name, Type[] paramTypes, int bindingFlags) {
- MethodInfo[] methods = GetMethods(bindingFlags);
- MethodInfo method = findMethod(methods, name, paramTypes, null);
- if (method == null) {
- StringBuffer str = new StringBuffer(name);
- str.append('(');
- for (int i = 0; i < paramTypes.length; i++) {
- if (i > 0) str.append(", ");
- str.append(paramTypes[i]);
- }
- str.append(')');
- System.out.println("Cannot find method " + str + ":");
- System.out.println("Methods of class " + this);
- for (int i = 0; i < methods.length; i++)
- System.out.println("\t" + methods[i]);
- }
- return method;
- }
-
- /** Returns all public methods of the current Type. */
- public MethodInfo[] GetMethods() {
- return GetMethods(BindingFlags.Instance | BindingFlags.Public);
- }
-
- /**
- */
- public MethodInfo[] GetMethods(int bindingFlags) {
- initMethods();
- final MethodInfo[] methods =
- getAllMethods((bindingFlags & BindingFlags.DeclaredOnly) != 0);
- //System.out.println("" + this + ".GetMethods(int) -> " + methods.length);
- final boolean getInstance = (bindingFlags & BindingFlags.Instance) != 0;
- final boolean getStatic = (bindingFlags & BindingFlags.Static) != 0;
- final boolean getPublic = (bindingFlags & BindingFlags.Public) != 0;
- final boolean getNonPublic =
- (bindingFlags & BindingFlags.NonPublic) != 0;
-
- int cnt = 0;
- for (int i = 0; i < methods.length; i++) {
- MethodInfo method = methods[i];
- boolean accessible = (getPublic && method.IsPublic())
- || (getNonPublic && !method.IsPublic());
- if (accessible
- // strip off the private methods up the hierarchy
- && ((method.DeclaringType == this)
- || ((method.DeclaringType != this) && !method.IsPrivate()))
- && ((getInstance && !method.IsStatic())
- || ((getStatic && method.IsStatic()) &&
- (method.DeclaringType == this
- || (bindingFlags & BindingFlags.FlattenHierarchy) != 0))
- )
- )
- methods[cnt++] = method;
- }
- MethodInfo [] resMethods = new MethodInfo[cnt];
- System.arraycopy(methods, 0, resMethods, 0, cnt);
- return resMethods;
- }
-
- protected MethodInfo[] getAllMethods(boolean declaredOnly) {
- initMethods();
- MethodInfo[] inherited = BaseType() == null || declaredOnly
- ? MethodInfo.EMPTY_ARRAY
- : BaseType().getAllMethods(declaredOnly);
- MethodInfo[] allMethods =
- new MethodInfo[inherited.length + this.methods.length];
- System.arraycopy(inherited, 0, allMethods, 0, inherited.length);
- System.arraycopy(this.methods, 0,
- allMethods, inherited.length, this.methods.length);
- return allMethods;
- }
-
- //##########################################################################
- // GetProperty/ies/
-
- /** Returns all public properties of the current Type.
- */
- public PropertyInfo[] GetProperties() {
- initProperties();
- return (PropertyInfo[]) properties.clone();
- }
-
- /** Returns the properties of the current class
- * that satisfy the binding constrints.
- */
- public PropertyInfo[] GetProperties(int bindingFlags) {
- initProperties();
- return (PropertyInfo[]) properties.clone();
- }
-
- /** Returns the public property with the given name.
- */
- public PropertyInfo GetProperty(String name) {
- initProperties();
- for (int i = 0; i < properties.length; i++)
- if (name.equals(properties[i].Name))
- return properties[i];
- return null;
- }
-
- /** Returns the property with the given name
- * that satisfies the binding constraints.
- */
- public PropertyInfo GetProperty(String name, int bindingFlags) {
- throw new RuntimeException("Method not implemented yet");
- }
-
- //##########################################################################
- // GetEvent(s)
-
- public EventInfo[] GetEvents() {
- initEvents();
- return (EventInfo[]) events.clone();
- }
-
- //##########################################################################
- // GetNestedType/s/
-
- /** Searches for nested type with the specified name. */
- public Type GetNestedType(String name) {
- initNestedTypes();
- for (int i = 0; i < nestedTypes.length; i++)
- if (nestedTypes[i].Name.equals(name))
- return nestedTypes[i];
- return null;
- }
-
- /** Returns all types nested within the current Type. */
- public Type[] GetNestedTypes() {
- initNestedTypes();
- return (Type[]) nestedTypes.clone();
- }
-
- //##########################################################################
- // GetInterface/s/
-
- /** Searches for an Interface with the given name implemented by this type
- */
- public Type GetInterface(String name) {
- return GetInterface(name, false);
- }
-
- /** Searches for the specified interface,
- * specifying whether to do a case-sensitive search.
- * @param name - the name of the interface to get
- * @param ignoreCase <b>true</b> to perform a case-insensitive search for name
- * <b>false</b> to perform a case-sensitive search for name
- * @return A Type object representing the interface with the specified name,
- * implemented or inherited by the current Type, if found;
- * otherwise, a null reference
- */
- public Type GetInterface(String name, boolean ignoreCase) {
- initInterfaces();
- for (int i = 0; i < interfaces.length; i++) {
- Type iface = interfaces[i];
- if (ignoreCase) {
- if (name.equalsIgnoreCase(iface.Name)) return iface;
- if (name.equalsIgnoreCase(iface.FullName)) return iface;
- } else {
- if (name.equals(iface.Name)) return iface;
- if (name.equals(iface.FullName)) return iface;
- }
- }
- return BaseType() == null ? null
- : BaseType().GetInterface(name, ignoreCase);
- }
-
- /** Returns the interfaces implemented or inherited by the current Type. */
- public Type[] GetInterfaces() {
- initInterfaces();
- if (BaseType() == null) return interfaces;
-
- Type[] ifaces = interfaces;
- int count = 0;
- for (int i = 0; i < interfaces.length; i++) {
- if (BaseType().GetInterface(interfaces[i].FullName) == null)
- ifaces[count++] = ifaces[i];
- }
- Type[] baseTypeIfaces = BaseType().GetInterfaces();
-
- Type[] res = new Type[baseTypeIfaces.length + count];
- System.arraycopy(baseTypeIfaces, 0, res, 0, baseTypeIfaces.length);
- System.arraycopy(ifaces, 0, res, baseTypeIfaces.length, count);
-
- return res;
- }
-
-
- public boolean isSubtypeOf(Type that) {
- if (this == that || BaseType() == that || that == OBJECT()) return true;
- initInterfaces();
- for (int i = 0; i < interfaces.length; i++)
- if (interfaces[i].isSubtypeOf(that))
- return true;
- boolean res = BaseType() == null ? false : BaseType().isSubtypeOf(that);
-// if (!res) {
-// System.out.println(dumpType(this) + " not a subtype of " +
-// dumpType(that));
-// }
- return res;
- }
-
- private static String formatType(Type t) {
- if (t == null) return "<null>";
- String cname = t.getClass().getName();
- int k = cname.lastIndexOf(".");
- if (k >= 0)
- cname = cname.substring(k + 1);
- return "[" + t.Assembly().GetName() + "]" + t +
- "(" + cname + "#" + Integer.toHexString(t.hashCode()) + ")";
- }
- private static String dumpType(Type t) {
- StringBuffer str = new StringBuffer();
- str.append(formatType(t) + " : ");
- str.append(formatType(t.BaseType()));
- Type[] ifaces = t.GetInterfaces();
- for (int i = 0; i < ifaces.length; i++)
- str.append(", " + formatType(ifaces[i]));
- return str.toString();
- }
-
- //##########################################################################
- // GetMember/s/
-
- protected MemberInfo[] members;
-
- public MemberInfo[] GetMember(String name) {
- aggregateMembers();
- List l = new ArrayList();
- for (int i = 0; i < members.length; i++) {
- if (name.equals(members[i].Name))
- l.add(members[i]);
- }
- return (MemberInfo[])l.toArray(MemberInfo.EMPTY_ARRAY);
- }
-
- protected void aggregateMembers() {
- if (members != null)
- return;
- initFields();
- initMethods();
- initProperties();
- initNestedTypes();
- // the List returned by Arrays.asList doesn't support the addAll method
- // so we have to wrap it in ArrayList
- List l = new ArrayList(Arrays.asList(fields));
- l.addAll(Arrays.asList(constructors));
- l.addAll(Arrays.asList(methods));
- l.addAll(Arrays.asList(properties));
- l.addAll(Arrays.asList(nestedTypes));
- members = (MemberInfo[]) l.toArray(MemberInfo.EMPTY_ARRAY);
- }
-
- //##########################################################################
- // non-standard methods that return only members declared in this type
-
- /**
- * Return only the fields declared in this type.
- */
- public FieldInfo[] getFields() {
- initFields();
- FieldInfo[] fields = new FieldInfo[this.fields.length];
- System.arraycopy(this.fields, 0, fields, 0, fields.length);
- return fields;
- }
-
- /**
- * Return only the conrtuctors declared in this type.
- */
- public ConstructorInfo[] getConstructors() {
- initMethods();
- ConstructorInfo[] ctors = new ConstructorInfo[constructors.length];
- System.arraycopy(constructors, 0, ctors, 0, ctors.length);
- return ctors;
- }
-
- /**
- * Return only the methods declared in this type.
- */
- public MethodInfo[] getMethods() {
- initMethods();
- MethodInfo[] methods = new MethodInfo[this.methods.length];
- System.arraycopy(this.methods, 0, methods, 0, methods.length);
- return methods;
- }
-
- /**
- * Return only the properties declared in this type.
- */
- public PropertyInfo[] getProperties() {
- initProperties();
- PropertyInfo[] props = new PropertyInfo[properties.length];
- System.arraycopy(properties, 0, props, 0, props.length);
- return props;
- }
-
- /**
- * Return only the interfaces directly implemented by this type.
- */
- public Type[] getInterfaces() {
- initInterfaces();
- Type[] ifaces = new Type[interfaces.length];
- System.arraycopy(interfaces, 0, ifaces, 0, ifaces.length);
- return ifaces;
- }
-
- /**
- * Return the types declared in this type.
- */
- public Type[] getNestedTypes() {
- initNestedTypes();
- Type[] nested = new Type[nestedTypes.length];
- System.arraycopy(nestedTypes, 0, nested, 0, nested.length);
- return nested;
- }
-
- //##########################################################################
-
- public String toString() {
- return FullName;
- }
-
- //##########################################################################
- // lazy type construction members
-
- private boolean initBaseType = true;
- protected final void initBaseType() {
- if (initBaseType) {
- loadBaseType();
- initBaseType = false;
- }
- }
- protected void loadBaseType() {}
-
- private boolean initInterfaces = true;
- protected void initInterfaces() {
- if (initInterfaces) {
- loadInterfaces();
- initInterfaces = false;
- }
- assert interfaces != null : "In type " + this;
- }
- protected void loadInterfaces() {}
-
- private boolean initNestedTypes = true;
- protected void initNestedTypes() {
- if (initNestedTypes) {
- loadNestedTypes();
- initNestedTypes = false;
- }
- assert nestedTypes != null : "In type " + this;
- }
- protected void loadNestedTypes() {}
-
- private boolean initFields = true;
- protected void initFields() {
- if (initFields) {
- loadFields();
- initFields = false;
- }
- assert fields != null : "In type " + this;
- }
- protected void loadFields() {}
-
- private boolean initMethods = true;
- protected void initMethods() {
- if (initMethods) {
- loadMethods();
- initMethods = false;
- }
- assert constructors != null : "In type " + this;
- assert methods != null : "In type " + this;
- }
- protected void loadMethods() {}
-
- private boolean initProperties = true;
- protected void initProperties() {
- if (initProperties) {
- initMethods();
- loadProperties();
- initProperties = false;
- }
- assert properties != null : "In type " + this;
- }
- protected void loadProperties() {}
-
- private boolean initEvents = true;
- protected void initEvents() {
- if (initEvents) {
- initMethods();
- loadEvents();
- initEvents = false;
- }
- assert events != null : "In type " + this;
- }
- protected void loadEvents() {}
-
- //##########################################################################
-
- //##########################################################################
- // static members
-
- private static Assembly MSCORLIB;
- private static Module MSCORLIB_DLL;
-
- public static Type OBJECT() { return __OBJECT; }
- public static Type STRING() { return __STRING; }
- public static Type ARRAY() { return __ARRAY; }
- public static Type VOID() { return __VOID; }
- public static Type ENUM() { return __ENUM; }
- public static Type VALUE_TYPE() { return __VALUE_TYPE; }
-
- private static Type __OBJECT;
- private static Type __STRING;
- private static Type __ARRAY;
- private static Type __VOID;
- private static Type __ENUM;
- private static Type __VALUE_TYPE;
-
- public static void initMSCORLIB(Assembly mscorlib) {
- if (MSCORLIB != null)
- throw new RuntimeException("mscorlib already initialized");
- MSCORLIB = mscorlib;
- MSCORLIB_DLL = MSCORLIB.GetModules()[0];
-
- __OBJECT = mscorlib.GetType("System.Object");
- __STRING = mscorlib.GetType("System.String");
- __ARRAY = mscorlib.GetType("System.Array");
- __VOID = mscorlib.GetType("System.Void");
- __ENUM = mscorlib.GetType("System.Enum");
- __VALUE_TYPE = mscorlib.GetType("System.ValueType");
- }
-
- //##########################################################################
-
-} // class Type
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/TypeAttributes.java b/src/msil/ch/epfl/lamp/compiler/msil/TypeAttributes.java
deleted file mode 100644
index 8f489fa46f..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/TypeAttributes.java
+++ /dev/null
@@ -1,190 +0,0 @@
-/*
- * System.Reflection-like API for access to .NET assemblies (DLL & EXE)
- */
-
-
-package ch.epfl.lamp.compiler.msil;
-
-/**
- * Specifies type attributes.
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-public final class TypeAttributes {
-
- //##########################################################################
- // Visibilty attributes
-
- /** Bitmask used to retrieve visibility information. */
- public static final int VisibilityMask = 0x00000007;
-
- /** Class has no public scope. */
- public static final int NotPublic = 0x00000000;
-
- /** Class has public scope. */
- public static final int Public = 0x00000001;
-
- /** Class is nested with public visibility. */
- public static final int NestedPublic = 0x00000002;
-
- /** Class is nested with private visibility. */
- public static final int NestedPrivate = 0x00000003;
-
- /** Class is nested with family visibility, and is thus accessible
- * only by methods within its own type and any subtypes. */
- public static final int NestedFamily = 0x00000004;
-
- /** Class is nested with assembly visibility, and is thus accessible
- * only by methods within its assembly. */
- public static final int NestedAssembly = 0x00000005;
-
- /** Class is nested with assembly and family visibility, and is thus accessible
- * only by methods lying in the intersection of its family and assembly. */
- public static final int NestedFamANDAssem = 0x00000006;
-
- /** Class is nested with family or assembly visibility, and is thus accessible
- * only by methods lying in the union of its family and assembly. */
- public static final int NestedFamORAssem = 0x00000007;
-
- //##########################################################################
- // Class layout attributes
-
- /** Bitmask used to retrieve class layout information. */
- public static final int LayoutMask = 0x00000018;
-
- /** Class fields are automatically laid out by the CLR. */
- public static final int AutoLayout = 0x00000000;
-
- /** Class fields are laid out sequentially, in the order that the fields
- * were emitted to the metadata. */
- public static final int SequentialLayout = 0x00000008;
-
- /** Class fields are laid out at the specified offsets. */
- public static final int ExplicitLayout = 0x00000010;
-
- //##########################################################################
- // Class semantics attributes
-
- /** Bitmask used to retrieve class semantics information. */
- public static final int ClassSemanticsMask = 0x00000020;
-
- /** Type is a class. */
- public static final int Class = 0x00000000;
-
- /** Type is an interface. */
- public static final int Interface = 0x00000020;
-
- //##########################################################################
- // Special semantics in addition to class semantics
-
- /** Class is abstract. */
- public static final int Abstract = 0x00000080;
-
- /** Class is cannot be extended. */
- public static final int Sealed = 0x00000100;
-
- /** Class is special in a way denoted by the name. */
- public static final int SpecialName = 0x00000400;
-
- //##########################################################################
- // Implementation attributes
-
- /** Class/interface is imported from another module. */
- public static final int Import = 0x00001000;
-
- /** Class can be serialized. */
- public static final int Serializable = 0x00002000;
-
- //##########################################################################
- // String formatting attributes
-
- /** Bitmask used to retrieve string information for native interop. */
- public static final int StringFormatMask = 0x00030000;
-
- /** LPTSTR is interpreted as ANSI. */
- public static final int AnsiClass = 0x00000000;
-
- /** LPTSTR is interpreted as UNICODE. */
- public static final int UnicodeClass = 0x00010000;
-
- /** LPTSTR is interpreted automatically. */
- public static final int AutoClass = 0x00020000;
-
- //##########################################################################
- // Class initialization attributes
-
- /** Initialize the class before first static field access. */
- public static final int BeforeFieldInit = 0x00100000;
-
- //##########################################################################
- // Additional flags
-
- /** CLI provides 'special' behavior, depending upon the name of the type. */
- public static final int RTSpecialName = 0x00000800;
-
- /** Type has security associate with it. */
- public static final int HasSecurity = 0x00040000;
-
- //##########################################################################
-
- public static String accessModsToString(int attrs) {
- switch (attrs & VisibilityMask) {
- case NotPublic: return "private";
- case Public: return "public";
- case NestedPublic: return "nested public";
- case NestedPrivate: return "nested private";
- case NestedFamily: return "nested family";
- case NestedAssembly: return "nested assembly";
- case NestedFamANDAssem: return "nested famandassem";
- case NestedFamORAssem: return "nested famorassem";
- default:
- throw new RuntimeException();
- }
- }
-
- /** Returns a string representation of the given attributes. */
- public static String toString(int attrs) {
- StringBuffer str = new StringBuffer(accessModsToString(attrs));
- switch (attrs & LayoutMask) {
- case AutoLayout: str.append(" auto"); break;
- case SequentialLayout: str.append(" sequential"); break;
- case ExplicitLayout: str.append(" explicit"); break;
- }
- switch (attrs & StringFormatMask) {
- case AnsiClass: str.append(" ansi"); break;
- case UnicodeClass: str.append(" unicode"); break;
- case AutoClass: str.append(" autochar"); break;
- }
- if ((attrs & Interface) != 0) str.append(" interface");
- if ((attrs & Abstract) != 0) str.append(" abstract");
- if ((attrs & Sealed) != 0) str.append(" sealed");
- if ((attrs & BeforeFieldInit) != 0) str.append(" beforefieldinit");
- if ((attrs & Serializable) != 0) str.append(" serializable");
- if ((attrs & SpecialName) != 0) str.append(" specialname");
- if ((attrs & RTSpecialName) != 0) str.append(" rtspecialname");
- return str.toString();
- }
-
- /***/
- public static final boolean isNested(int attrs) {
- switch (attrs & VisibilityMask) {
- case NestedPublic:
- case NestedPrivate:
- case NestedFamily:
- case NestedAssembly:
- case NestedFamANDAssem:
- case NestedFamORAssem:
- return true;
- default: return false;
- }
- }
-
- //##########################################################################
-
- // makes the class uninstantiable
- private TypeAttributes() {}
-
- //##########################################################################
-
-} // class TypeAttributes
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/Version.java b/src/msil/ch/epfl/lamp/compiler/msil/Version.java
deleted file mode 100644
index ad4b09b163..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/Version.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * System.Reflection-like API for access to .NET assemblies (DLL & EXE)
- */
-
-
-package ch.epfl.lamp.compiler.msil;
-
-
-/**
- * Represents the version number for a common language runtime assembly
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-public final class Version {
-
- //##########################################################################
- // public interface
-
- /**
- * Gets the value of the major component of the version
- * number for this instance.
- */
- public final int Major;
-
- /**
- * Gets the value of the minor component of the version
- * number for this instance.
- */
- public final int Minor;
-
- /**
- * Gets the value of the build component of the version
- * number for this instance.
- */
- public final int Build;
-
- /**
- * Gets the value of the revision component of the version
- * number for this instance.
- */
- public final int Revision;
-
- /**
- * Initializes a new instance of the Version class.
- */
- public Version() {
- this(0,0,0,0);
- }
-
- /**
- * Initializes a new instance of the Version class with
- * the specified major, minor, build, and revision numbers.
- */
- public Version(int major, int minor, int build, int revision) {
- this.Major = major;
- this.Minor = minor;
- this.Build = build;
- this.Revision = revision;
- }
-
- /**
- * Converts the value of this instance to its equivalent String representation
- */
- public String toString() {
- return "" + Major + "." + Minor + "." + Build + "." + Revision;
- }
-
- //##########################################################################
-
-} // class Version
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/emit/AssemblyBuilder.scala b/src/msil/ch/epfl/lamp/compiler/msil/emit/AssemblyBuilder.scala
deleted file mode 100644
index 3110ccd1ce..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/emit/AssemblyBuilder.scala
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * System.Reflection.Emit-like API for writing .NET assemblies to MSIL
- */
-
-
-package ch.epfl.lamp.compiler.msil.emit
-
-import ch.epfl.lamp.compiler.msil._
-import java.io.IOException
-
-/**
- * Defines and represents a dynamic assembly.
- * A dynamic assembly is an assembly that is created using the compiler.msil
- * emit APIs. The dynamic modules in the assembly are saved when the dynamic
- * assembly is saved using the Save method. To generate an executable, the
- * SetEntryPoint method must be called to identify the method that is the
- * entry point to the assembly. Assemblies are saved as DLL by default,
- * unless SetEntryPoint requests the generation of a console application
- * or a Windows-based application.
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-class AssemblyBuilder(name: AssemblyName)
- extends Assembly(name)
- with ICustomAttributeSetter
- with Visitable
-{
- //##########################################################################
- // public methods
-
- /**
- * Defines a dynamic module with the given name that will be saved
- * to the specified file. No symbol information is emitted.
- */
- def DefineDynamicModule(name: String, fileName: String): ModuleBuilder = {
- val module = new ModuleBuilder(name, fileName, "" + null, this)
- addModule(name, module)
- return module
- }
-
- /** Returns the dynamic module with the specified name. */
- def GetDynamicModule(name: String): ModuleBuilder = {
- return GetModule(name).asInstanceOf[ModuleBuilder]
- }
-
- /** Saves this dynamic assembly to disk. */
- @throws(classOf[IOException])
- def Save(fileName: String) {
- generatedFiles = scala.collection.mutable.ArrayBuffer.empty[String]
- ILPrinterVisitor.printAssembly(this, fileName)
- }
-
- @throws(classOf[IOException])
- def Save(destPath: String, sourceFilesPath: String) {
- generatedFiles = scala.collection.mutable.ArrayBuffer.empty[String]
- ILPrinterVisitor.printAssembly(this, destPath, sourceFilesPath)
- }
-
- /** Returns the list of generated files from calling Save(). */
- def GetGeneratedFiles(): Array[String] = {
- return generatedFiles.toArray // (new Array[String](generatedFiles.size())).asInstanceOf[Array[String]]
- }
-
- /** Sets the entry point for this dynamic assembly. */
- def SetEntryPoint(entryMethod: MethodInfo) {
- EntryPoint = entryMethod
- }
-
- /** Sets a custom attribute. */
- def SetCustomAttribute(constr: ConstructorInfo, value: Array[Byte]) {
- addCustomAttribute(constr, value)
- }
-
- //##########################################################################
- // protected members
-
- // the access properties - Save, Run, RunAndSave
- private var access : Int = _
-
- // all extern assemblies used in this assembly builder
- protected var externAssemblies = scala.collection.mutable.Set.empty[Assembly]
-
- // register an extern assembly
- protected def registerExternAssembly(assembly: Assembly) {
- externAssemblies += assembly
- }
-
- // get all extern Assemblies used in this Assembly Builder
- def getExternAssemblies(): Array[Assembly] = {
- externAssemblies = scala.collection.mutable.Set[Assembly]()
- val iter = Assembly.assemblies.values().iterator
- while (iter.hasNext) {
- externAssemblies += iter.next.asInstanceOf[Assembly]
- }
- externAssemblies -= this
- return externAssemblies.toArray
- }
-
- def loadModules() {}
-
- // contains list of generated .msil files after calling Save()
- var generatedFiles = scala.collection.mutable.ArrayBuffer.empty[String]
-
- //##########################################################################
- //##########################################################################
-
- /** the apply method for a visitor */
- @throws(classOf[IOException])
- def apply(v: Visitor) {
- v.caseAssemblyBuilder(this)
- }
-
- //##########################################################################
-}
-
-object AssemblyBuilderFactory {
- /**
- * Defines a dynamic assembly with the specified name.
- */
- def DefineDynamicAssembly(name: AssemblyName): AssemblyBuilder = {
- //Assembly.reset()
- return new AssemblyBuilder(name)
- }
-}
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/emit/ConstructorBuilder.scala b/src/msil/ch/epfl/lamp/compiler/msil/emit/ConstructorBuilder.scala
deleted file mode 100644
index ddd4708ecd..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/emit/ConstructorBuilder.scala
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * System.Reflection.Emit-like API for writing .NET assemblies to MSIL
- */
-
-
-package ch.epfl.lamp.compiler.msil.emit
-
-import ch.epfl.lamp.compiler.msil.ConstructorInfo
-import ch.epfl.lamp.compiler.msil.Type
-import java.io.IOException
-
-/**
- * Defines and represents a constructor of a dynamic class.
- * ConstructorBuilder is used to fully describe a constructor in
- * Microsoft intermediate language (MSIL), including the name, attributes,
- * signature, and constructor body. It is used in conjunction with the
- * TypeBuilder class to create classes at run time. Call DefineConstructor
- * to get an instance of ConstructorBuilder.
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-class ConstructorBuilder(declType: Type, attrs: Int, paramTypes: Array[Type])
- extends ConstructorInfo(declType, attrs, paramTypes)
- with ICustomAttributeSetter
- with Visitable
-{
-
- //##########################################################################
- // public interface
-
- /** Defines a parameter of this constructor. */
- def DefineParameter(pos: Int, attr: Int, name: String): ParameterBuilder = {
- val param = new ParameterBuilder(name, params(pos).ParameterType, attr, pos)
- params(pos) = param
- return param
- }
-
- /** Returns an ILGenerator for this constructor. */
- def GetILGenerator(): ILGenerator = {
- return ilGenerator
- }
-
- /** Sets a custom attribute. */
- def SetCustomAttribute(constr: ConstructorInfo, value: Array[Byte]) {
- addCustomAttribute(constr, value)
- }
-
- //##########################################################################
-
- /** The apply method for a visitor. */
- @throws(classOf[IOException])
- def apply(v: Visitor) {
- v.caseConstructorBuilder(this)
- }
-
- //##########################################################################
-
- // the Intermediate Language Generator
- // it contains the method's body
- protected var ilGenerator: ILGenerator = new ILGenerator(this)
-
- //##########################################################################
-}
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/emit/FieldBuilder.scala b/src/msil/ch/epfl/lamp/compiler/msil/emit/FieldBuilder.scala
deleted file mode 100644
index 7ef9dc7a5b..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/emit/FieldBuilder.scala
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * System.Reflection.Emit-like API for writing .NET assemblies to MSIL
- */
-
-
-package ch.epfl.lamp.compiler.msil.emit
-
-import ch.epfl.lamp.compiler.msil.FieldInfo
-import ch.epfl.lamp.compiler.msil.Type
-import ch.epfl.lamp.compiler.msil.FieldAttributes
-import ch.epfl.lamp.compiler.msil.ConstructorInfo
-
-import ch.epfl.lamp.compiler.msil.util.PECustomMod
-
-import java.io.IOException
-
-/**
- * Discovers the attributes of a field and provides access to field metadata.
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-class FieldBuilder(name: String, declType: Type, attrs: Int, fieldTypeWithMods: PECustomMod)
- extends FieldInfo(name, declType, attrs, fieldTypeWithMods, null)
- with ICustomAttributeSetter
- with Visitable
-{
-
- //##########################################################################
- // public interface
-
- /** Sets a custom attribute. */
- def SetCustomAttribute(constr: ConstructorInfo, value: Array[Byte]) {
- addCustomAttribute(constr, value)
- }
-
- //##########################################################################
-
- /** the apply method for a visitor */
- @throws(classOf[IOException])
- def apply(v: Visitor) {
- v.caseFieldBuilder(this)
- }
-
- //##########################################################################
-
- protected var defaultValue: Object = _
-
- /** Sets the default value of this field. */
- def SetConstant(defaultValue: Object) {
- this.defaultValue = defaultValue
- }
-
- /** Specifies the field layout. */
- def SetOffset(iOffset: Int) {
- //this.fieldOffset = FieldAttributes.Offset.Value(iOffset)
- }
-
- //##########################################################################
-}
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/emit/ICustomAttributeSetter.scala b/src/msil/ch/epfl/lamp/compiler/msil/emit/ICustomAttributeSetter.scala
deleted file mode 100644
index 5d74d3aa95..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/emit/ICustomAttributeSetter.scala
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * System.Reflection.Emit-like API for writing .NET assemblies to MSIL
- */
-
-
-package ch.epfl.lamp.compiler.msil.emit
-
-import ch.epfl.lamp.compiler.msil.ConstructorInfo
-
-/**
- * Declares the possibility to set a custom attribute for a member
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-trait ICustomAttributeSetter {
- def SetCustomAttribute(constr: ConstructorInfo, value: Array[Byte])
-}
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/emit/ILGenerator.scala b/src/msil/ch/epfl/lamp/compiler/msil/emit/ILGenerator.scala
deleted file mode 100644
index 2aa9a99054..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/emit/ILGenerator.scala
+++ /dev/null
@@ -1,539 +0,0 @@
-/*
- * System.Reflection.Emit-like API for writing .NET assemblies to MSIL
- */
-
-
-package ch.epfl.lamp.compiler.msil.emit
-
-import ch.epfl.lamp.compiler.msil._
-import ch.epfl.lamp.compiler.msil.util.Table
-import java.util.Stack
-import java.io.IOException
-import ILGenerator._
-
-/**
- * Generates Microsoft intermediate language (MSIL) instructions.
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
- final class ILGenerator(_owner: MethodBase) extends Visitable {
-
- //##########################################################################
- // public interface
-
- /**
- * Puts the specified instruction onto the stream of instructions.
- */
- def Emit(opcode: OpCode) {
- // switch opcode
- if (opcode == OpCode.Ret) {
- emit(opcode, null, 0)
- } else {
- emit(opcode, null)
- }
- }
-
- /**
- * Puts the specified instruction and character argument onto
- * the Microsoft intermediate language (MSIL) stream of instructions.
- */
- def Emit(opcode: OpCode, arg: Char) {
- emit(opcode,new Character(arg))
- }
-
- /**
- * Puts the specified instruction and metadata token for the
- * specified constructor onto the Microsoft intermediate language
- * (MSIL) stream of instructions.
- */
- def Emit(opcode: OpCode, arg: ConstructorInfo) {
- assert(arg != null)
- // newobj
- // pop size is the number of parameters
- emit(opcode,arg, OpCode.PUSH_size(opcode.CEE_push) -
- arg.GetParameters().length)
- }
-
- /**
- * Puts the specified instruction onto the Microsoft intermediate language (MSIL)
- * stream followed by the index of the given local variable.
- */
- def Emit(opcode: OpCode, arg: LocalBuilder) {
- assert(arg != null)
- // ldarg | ldarg.s | ldarga
- // ldarga.s | ldloc | ldloc.s | ldloca
- // ldloca.s | starg | starg.s | stloc
- // stloc.s
-
- // <instr_var> <localname>
- emit(opcode, arg)
- }
-
-
- /**
- * Puts the specified instruction and numerical argument onto
- * the Microsoft intermediate language (MSIL) stream of instructions.
- */
- def Emit(opcode: OpCode, arg: Double) {
- // ldc.r4 | ldc.r8
- emit(opcode, new java.lang.Double(arg))
- }
-
- /**
- * Puts the specified instruction and metadata token for the
- * specified field onto the Microsoft intermediate language (MSIL)
- * stream of instructions.
- */
- def Emit(opcode: OpCode,arg: FieldInfo) {
- assert(arg != null)
- // ldfld | ldflda | ldsfld | ldsflda | stfld | stsfld
- emit(opcode,arg)
- }
-
- /**
- * Puts the specified instruction and numerical argument onto
- * the Microsoft intermediate language (MSIL) stream of instructions.
- */
- def Emit(opcode: OpCode, arg: Short ) {
- emit(opcode, new java.lang.Short(arg))
- }
-
- /**
- * Puts the specified instruction and numerical argument onto
- * the Microsoft intermediate language (MSIL) stream of instructions.
- */
- def Emit(opcode: OpCode, arg: Int) {
- // ldc.i4 | ldc.i4.s | unaligned
- emit(opcode, new java.lang.Integer(arg))
- }
-
- /**
- * Puts the specified instruction and numerical argument onto
- * the Microsoft intermediate language (MSIL) stream of instructions.
- */
- def Emit(opcode: OpCode, arg: Long) {
- // ldc.i8
- emit(opcode, new java.lang.Long(arg))
- }
-
- /**
- * Puts the specified instruction onto the Microsoft intermediate
- * language (MSIL) stream and leaves space to include a label when
- * fixes are done.
- */
- def Emit(opcode: OpCode,label: Label) {
- assert(label != null)
- // beq | beq.s | bge | bge.s |
- // bge.un | bge.un.s | bgt | bgt.s | bgt.un | bgt.un.s |
- // ble | ble.s | ble.un | ble.un.s | blt | blt.s |
- // blt.un | blt.un.s | bne.un | bne.un.s | br | br.s |
- // brfalse | brfalse.s | brtrue | brtrue.s | leave | leave.s
-
- emit(opcode, label)
- // is the label initialized ? if true backward jump else forward jump
- if (label.isInitialized()) {
-// if (arg.stacksize != lastLabel.stacksize) {
-// System.err.println("ILGenerator.Emit: Stack depth differs depending on path:");
-// System.err.println("\tmethod = " + owner);
-// System.err.println("\tPC = 0x" + Table.short2hex(lastLabel.address));
-// }
- //assert arg.stacksize == lastLabel.stacksize;
- }
- else {
- label.setStacksize(lastLabel.getStacksize())
- }
- }
-
- /**
- * Puts the specified instruction onto the Microsoft intermediate
- * language (MSIL) stream and leaves space to include a label when
- * fixes are done.
- */
- def Emit(opcode: OpCode, arg: Array[Label] ) {
- assert(arg != null)
- // switch
-
- // <instr> ::= <instr_switch> ( <labels> )
- // Examples:
- // switch (0x3, -14, Label1)
- // switch (5, Label2)
- emit(opcode, arg, arg.length)
- }
-
- /**
- * Puts the specified instruction onto the Microsoft intermediate
- * language (MSIL) stream followed by the metadata token for the
- * given method.
- */
- def Emit(opcode: OpCode,arg: MethodInfo) {
- assert(arg != null)
- // call | callvirt | jmp | ldftn | ldvirtftn
- // pop size is the number of parameters
- // pop 1 more if method is not static !
- // push size is either 0 (void Method) either 1
- assert(arg.ReturnType != null, "No ReturnType: " + arg.DeclaringType + "::" + arg.Name)
-
- val popush: Int = if (opcode == OpCode.Ldftn ||
- opcode == OpCode.Ldvirtftn ||
- opcode == OpCode.Jmp)
- {
- OpCode.PUSH_size(opcode.CEE_push) - OpCode.POP_size(opcode.CEE_pop)
- } else if (opcode == OpCode.Calli || opcode == OpCode.Callvirt) {
- (if(arg.ReturnType == VOID) 0 else 1) - arg.GetParameters().length - 1
- } else {
- (if(arg.ReturnType == VOID) 0 else 1) - arg.GetParameters().length
- }
- emit(opcode, arg, popush)
- }
-
- /**
- * Puts the specified instruction and numerical argument onto
- * the Microsoft intermediate language (MSIL) stream of instructions.
- */
- def Emit(opcode: OpCode, arg: Float ) {
- emit(opcode, new java.lang.Float(arg))
- }
-
- /**
- * Puts the specified instruction onto the Microsoft intermediate
- * language (MSIL) stream followed by the metadata token for the
- * given string.
- */
- def Emit(opcode: OpCode, arg: String ) {
- assert(arg != null)
- // ldstr
- emit(opcode, arg)
- }
-
- /**
- * Puts the specified instruction onto the Microsoft intermediate
- * language (MSIL) stream followed by the metadata token for the
- * given type.
- */
- def Emit(opcode: OpCode, arg: Type) {
- assert(arg != null)
- // box | castclass | cpobj | initobj | isinst |
- // ldelema | ldobj | mkrefany | newarr | refanyval |
- // sizeof | stobj | unbox
-
- emit(opcode, arg)
- }
-
- /**
- * Puts a call or callvirt instruction onto the Microsoft intermediate
- * language (MSIL) stream.
- */
- def EmitCall(opcode: OpCode, arg: MethodInfo,
- optionalParameterTypes: Array[Type]) {
- assert(arg != null)
- // pop size is the number of parameters
- // push size is either 0 (void Method) either 1
- //System.out.println(arg.ReturnType.Size + " " + arg.GetParameters().length);
- emit(opcode, arg, (if(arg.ReturnType == VOID) 0 else 1) -
- arg.GetParameters().length)
- }
-
- /**
- * Emits the Microsoft intermediate language (MSIL) necessary to
- * call WriteLine with the given field.
- */
- def EmitWriteLine(arg: FieldInfo) {
- // first load field info
- // if static use OpCode.Ldsfld
- if (arg.IsStatic())
- Emit(OpCodes.Ldsfld, arg)
- else
- Emit(OpCodes.Ldfld, arg)
- // then call System.Console.WriteLine(arg.Type)
- val t: Type = Type.GetType("System.Console")
- val argsType: Array[Type] = new Array[Type](1)
- argsType(0) = arg.FieldType
- val m: MethodInfo = t.GetMethod("WriteLine", argsType)
- EmitCall(OpCode.Call, m, null)
- }
-
- /**
- * Emits the Microsoft intermediate language (MSIL) necessary
- * to call WriteLine with the given local variable.
- */
- def EmitWriteLine(arg: LocalBuilder) {
- // first load local variable
- Emit(OpCodes.Ldloc, arg)
- // then call System.Console.WriteLine(arg.Type)
- val t: Type = Type.GetType("System.Console")
- val argsType: Array[Type] = new Array[Type](1)
- argsType(0) = arg.LocalType
- val m: MethodInfo = t.GetMethod("WriteLine", argsType)
- EmitCall(OpCode.Call, m, null)
- }
-
- /**
- * Emits the Microsoft intermediate language (MSIL) to call
- * WriteLine with a string.
- */
- def EmitWriteLine(arg: String) {
- // first load string
- Emit(OpCode.Ldstr, arg)
- // then call System.Console.WriteLine(string)
- val t: Type = Type.GetType("System.Console")
- val argsType: Array[Type] = new Array[Type](1)
- argsType(0) = Type.GetType("System.String")
- val m: MethodInfo = t.GetMethod("WriteLine", argsType)
- EmitCall(OpCode.Call, m, null)
- }
-
- /**
- * Declares a local variable.
- */
- def DeclareLocal(localType: Type): LocalBuilder = {
- val l: LocalBuilder = new LocalBuilder(locals, localType)
- locals = locals + 1
- localList += l
- return l
- }
-
- /**
- * Returns a new label that can be used as a token for branching.
- * In order to set the position of the label within the stream, you
- * must call MarkLabel. This is just a token and does not yet represent
- * any particular location within the stream.
- */
- def DefineLabel():Label = {
- new Label.NormalLabel()
- }
-
- /**
- * Marks the Microsoft intermediate language (MSIL) stream's
- * current position with the given label.
- */
- def MarkLabel(label: Label) {
- label.mergeWith(lastLabel)
- /*
- label.address = lastLabel.address;
- //label.stacksize = lastLabel.stacksize;
- if (label.stacksize >= 0)
- lastLabel.stacksize = label.stacksize;
- */
- }
-
- /** Begins a lexical scope. */
- def BeginScope() {
- emitSpecialLabel(Label.NewScope)
- }
-
- /** Ends a lexical scope. */
- def EndScope() {
- emitSpecialLabel(Label.EndScope)
- }
-
- /**
- * Begins an exception block for a non-filtered exception.
- * The label for the end of the block. This will leave you in the correct
- * place to execute finally blocks or to finish the try.
- */
- def BeginExceptionBlock() {
- emitSpecialLabel(Label.Try)
- val endExc: Label = new Label.NormalLabel() // new Label(lastLabel) ???
- excStack.push(Label.Try, endExc)
- }
-
- /** Begins a catch block. */
- def BeginCatchBlock(exceptionType: Type) {
- val kind = excStack.peekKind()
- if (kind == Label.Kind.Try ||
- kind == Label.Kind.Catch) {
- /* ok */
- } else {
- throw new RuntimeException("Catch should follow either a try or catch")
- }
- val endExc: Label = excStack.popLabel()
- Emit(OpCodes.Leave, endExc)
- // the CLI automatically provide the exception object on the evaluation stack
- // we adjust the stacksize
- lastLabel.incStacksize()
- excStack.push(Label.Catch, endExc)
- emitSpecialLabel(Label.Catch, exceptionType)
- }
-
- /** Ends an exception block. */
- def EndExceptionBlock() {
- val kind = excStack.peekKind()
- if (kind == Label.Kind.Try) {
- throw new RuntimeException("Try block with neither catch nor finally")
- } else if (kind == Label.Kind.Catch) {
- Emit(OpCodes.Leave, excStack.peekLabel())
- } else if (kind == Label.Kind.Finally) {
- Emit(OpCodes.Endfinally)
- }
- MarkLabel(excStack.popLabel())
- emitSpecialLabel(Label.EndTry)
- }
-
- /**
- * Begins a finally block in the Microsoft intermediate language
- * (MSIL) instruction stream.
- */
- def BeginFinallyBlock() {
- val endExc: Label = excStack.popLabel()
- Emit(OpCodes.Leave, endExc)
- excStack.push(Label.Finally, endExc)
- emitSpecialLabel(Label.Finally)
- }
-
- /**
- * Emits an instruction to throw an exception.
- */
- def ThrowException(exceptionType: Type) {
- assert(exceptionType != null)
- if (!exceptionType.isSubtypeOf(Type.GetType("System.Exception")))
- throw new RuntimeException
- (exceptionType + " doesn't extend System.Exception" )
- val ctor: ConstructorInfo = exceptionType.GetConstructor(Type.EmptyTypes)
- if (ctor == null)
- throw new RuntimeException("Type " + exceptionType
- + "doesn't have a default constructor")
- Emit(OpCodes.Newobj, ctor)
- Emit(OpCodes.Throw)
- }
-
- /**
- * sets the line of the source file corresponding to the next instruction
- */
- def setPosition(line: Int) {
- if (line != 0) lineNums.put(lastLabel, Integer.toString(line))
- }
-
- def setPosition(line: Int, filename: String) {
- if (line != 0) lineNums.put(lastLabel, line + " '" + filename + "'")
- }
-
- def setPosition(startLine: Int, endLine: Int, startCol: Int, endCol: Int, filename: String) {
- val lineRange = startLine + "," + endLine
- val colRange = startCol + "," + endCol
- lineNums.put(lastLabel, lineRange + ":" + colRange + " '" + filename + "'")
- }
-
- def getLocals(): Array[LocalBuilder] = localList.toArray
-
- def getLabelIterator() = labelList.iterator
-
- def getOpcodeIterator() = opcodeList.iterator
-
- def getArgumentIterator() = argumentList.iterator
-
- //##########################################################################
- // private implementation details
-
-
-
- // the local variable list
- private final val localList = scala.collection.mutable.ArrayBuffer.empty[LocalBuilder]
-
- // the label list, the opcode list and the opcode argument list
- // labelList is an array of Label
- // opcodeList is an array of OpCode
- // argumentList is an array of Object (null if no argument)
- private final val labelList = scala.collection.mutable.ArrayBuffer.empty[Label]
- private final val opcodeList = scala.collection.mutable.ArrayBuffer.empty[OpCode]
- private final val argumentList = scala.collection.mutable.ArrayBuffer.empty[Object]
-
- // the program counter (pc)
- // also called the stream's current position
- private var pc: Int = 0
-
- // last label
- private var lastLabel: Label = new Label.NormalLabel(pc,0)
-
- // the maximum size of stack
- private var maxstack: Int = 0
-
- // the number of the locals
- private var locals: Int = 0
-
- // stack of label for exception mechanism
- private var excStack: ExceptionStack = new ExceptionStack()
-
- // the method info owner of this ILGenerator
- var owner: MethodBase = _owner
-
- val lineNums = scala.collection.mutable.Map.empty[Label, String]
-
-
- def getMaxStacksize(): Int = { this.maxstack }
-
- // private emit with Object Argument
- private def emit(opcode: OpCode, arg: Object) {
- emit(opcode, arg, opcode.CEE_popush)
- }
-
- // private emit with Object Argument and override POPUSH
- private def emit(opcode: OpCode, arg: Object, overridePOPUSH: Int) {
- // add label, opcode and argument
- labelList += lastLabel
- opcodeList += opcode
- argumentList += arg
- // compute new lastLabel (next label)
- val stackSize: Int = lastLabel.getStacksize() + overridePOPUSH
- if (stackSize < 0) {
- val msg = "ILGenerator.emit(): Stack underflow in method: " + owner
- scala.Console.println(msg)
- // throw new RuntimeException(msg)
- }
- if (stackSize > maxstack)
- maxstack = stackSize
- var address: Int = lastLabel.getAddress() + opcode.CEE_length
- if (opcode.CEE_opcode == OpCode.CEE_SWITCH) {
- address = address + 4*arg.asInstanceOf[Array[Label]].length
- }
- lastLabel = new Label.NormalLabel(address, stackSize)
- pc = pc + 1
- }
-
- def Ldarg0WasJustEmitted() : Boolean = {
- if(opcodeList.isEmpty)
- return false
- val lastEmitted = opcodeList(opcodeList.size - 1)
- lastEmitted eq OpCode.Ldarg_0
- }
-
- private def emitSpecialLabel(l: Label) {
- emitSpecialLabel(l, null)
- }
- private def emitSpecialLabel(l: Label, catchType: Type) {
- labelList += l
- opcodeList += null
- argumentList += catchType
- }
-
- //##########################################################################
- //
- @throws(classOf[IOException])
- def apply(v: Visitor) {
- v.caseILGenerator(this)
- }
-
- //##########################################################################
-} // class ILGenerator
-
-
-object ILGenerator {
-
- val VOID: Type = Type.GetType("System.Void")
- val NO_LABEL: String = ""
-
- private final class ExceptionStack {
- private val labels = new scala.collection.mutable.Stack[Label]()
- private val kinds = new scala.collection.mutable.Stack[Label]()
- def ExceptionStack() {}
- def pop() { labels.pop; kinds.pop }
- def push(kind: Label, label: Label) {
- kinds.push(kind); labels.push(label)
- }
- def peekKind(): Label.Kind = kinds.top.getKind
- def peekLabel(): Label = labels.top
- def popLabel(): Label = { kinds.pop(); labels.pop() }
- }
-
-}
-
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/emit/ILPrinterVisitor.scala b/src/msil/ch/epfl/lamp/compiler/msil/emit/ILPrinterVisitor.scala
deleted file mode 100644
index 0ed5e3f3bb..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/emit/ILPrinterVisitor.scala
+++ /dev/null
@@ -1,861 +0,0 @@
-/*
- * System.Reflection.Emit-like API for writing .NET assemblies in MSIL
- */
-
-
-package ch.epfl.lamp.compiler.msil.emit
-
-import java.io.File
-import java.io.FileWriter
-import java.io.BufferedWriter
-import java.io.PrintWriter
-import java.io.IOException
-import java.util.Comparator
-
-import ch.epfl.lamp.compiler.msil._
-import ch.epfl.lamp.compiler.msil.util.Table
-
-/**
- * The MSIL printer Visitor. It prints a complete
- * assembly in a single or multiple files. Then this file can be compiled by ilasm.
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-abstract class ILPrinterVisitor extends Visitor {
-
- import ILPrinterVisitor._
- import OpCode._
-
- //##########################################################################
-
- protected final val assemblyNameComparator =
- new scala.math.Ordering[Assembly]() {
- override def compare(o1: Assembly, o2: Assembly): Int = {
- val a1 = o1.asInstanceOf[Assembly]
- val a2 = o2.asInstanceOf[Assembly]
- return a1.GetName().Name.compareTo(a2.GetName().Name)
- }
- }
-
- // the output file writer
- protected var out: PrintWriter = null
-
- // the left margin
- private var lmargin = 0
-
- // indicate a newline
- private var newline = true
-
- // print types without or with members?
- protected var nomembers: Boolean = false
-
- // external assemblies
- protected var as: Array[Assembly] = null
-
- private def align() {
- if (newline)
- padding = lmargin
- printPadding()
- newline = false
- }
- private def indent() {
- lmargin += TAB
- }
- private def undent() {
- lmargin -= TAB
- assert(lmargin >= 0)
- }
-
- private var padding = 0
- private def pad(n: Int) {
- assert(n >= 0, "negative padding: " + n)
- padding += n
- }
- private def printPadding() {
- if (padding <= 0)
- return
- while (padding > SPACES_LEN) {
- out.print(SPACES)
- padding -= SPACES_LEN
- }
- out.print(SPACES.substring(0, padding))
- padding = 0
- }
-
- // methods to print code
- protected def print(s: String) { align(); out.print(s)}
- protected def print(o: Object) { align(); out.print(o) }
- protected def print(c: Char) { align(); out.print(c) }
- protected def print(`val`: Int) { align(); out.print(`val`)}
- protected def print(`val`: Long){ align(); out.print(`val`)}
- protected def println() { out.println(); newline = true; padding = 0 }
- protected def println(c: Char) { print(c); println() }
- protected def println(i: Int) { print(i); println() }
- protected def println(l: Long) { print(l); println() }
- protected def println(s: String){ print(s); println() }
- protected def println(o: Object){ print(o); println() }
- protected def printName(name: String) {
- var ch = name.charAt(0)
- //if (Character.isLetter(ch) && Character.isLowerCase(ch)) {
- if ((ch != '.') && (ch != '!')) {
- print('\''); print(name); print('\'')
- } else
- print(name)
- }
-
- protected def printAssemblyBoilerplate() {
- // print all the external assemblies
- for (j <- 0 until as.length) {
- printAssemblySignature(as(j), true)
- }
- // print assembly declaration
- printAssemblySignature(currAssembly, false)
- }
-
- // the entrypoint method
- protected var entryPoint: MethodInfo = null
-
- // current opcode argument
- protected var argument: Object = null
-
- /***/
- @throws(classOf[IOException])
- protected def print(vAble: Visitable) {
- if (vAble != null)
- vAble.apply(this)
- }
-
- /**
- * Visit an AssemblyBuilder
- */
- @throws(classOf[IOException])
- def caseAssemblyBuilder(assemblyBuilder: AssemblyBuilder)
-
- protected var currentModule: Module = null
- /**
- * Visit a ModuleBuilder
- */
- @throws(classOf[IOException])
- def caseModuleBuilder(module: ModuleBuilder)
-
- protected var currentType: Type = null
-
- def printTypeParams(sortedTVars : Array[GenericParamAndConstraints]) {
-
- def constraintFlags(tVar : GenericParamAndConstraints) = {
- val varianceDirective = (if (tVar.isCovariant) "+ " else (if (tVar.isContravariant) "- " else ""))
- val typeKindDirective = (if (tVar.isReferenceType) "class " else (if (tVar.isValueType) "valuetype " else ""))
- val dfltConstrDirective = (if (tVar.hasDefaultConstructor) ".ctor " else "")
- varianceDirective + typeKindDirective + dfltConstrDirective
- }
-
- def tparamName(tVar : GenericParamAndConstraints) = {
- /* TODO Type-params in referenced assemblies may lack a name (those in a TypeBuilder or MethodBuilder shouldn't).
- Given that we need not list (in ilasm syntax) the original type-params' names when
- providing type arguments to it, the only type-param-names we'll serialize into a .msil file
- are those for type-params in a TypeBuilder or MethodBuilder. Still, more details on this
- appear in Sec. 4.5 "Faulty metadata in XMLReaderFactory" of
- http://lamp.epfl.ch/~magarcia/ScalaCompilerCornerReloaded/Libs4Lib.pdf
-
- To avoid name clashes when choosing a param name,
- first collect all existing tparam-names from a type (and its nested types).
- Not that those names are needed (ordinal positions can be used instead)
- but will look better when disassembling with ildasm. */
- assert(tVar.Name != null)
- tVar.Name
- }
-
- if(sortedTVars.length == 0) { return }
- print('<')
- val lastIdx = sortedTVars.length - 1
- for (it <- 0 until sortedTVars.length) {
- val tVar = sortedTVars(it)
- print(constraintFlags(tVar))
- if(tVar.Constraints.length > 0) {
- print('(')
- val lastCnstrtIdx = tVar.Constraints.length - 1
- for (ic <- 0 until tVar.Constraints.length) {
- val cnstrt = tVar.Constraints(ic)
- printReference(cnstrt)
- if (ic < lastIdx) { print(", ") }
- }
- print(')')
- }
- print(" " + tparamName(tVar))
- if (it < lastIdx) { print(", ") }
- }
- print('>')
- }
-
- /**
- * Visit a TypeBuilder
- */
- @throws(classOf[IOException])
- def caseTypeBuilder(`type`: TypeBuilder) {
- currentType = `type`
- if (!`type`.Namespace.equals("") && `type`.DeclaringType == null) {
- print(".namespace \'" ); print(`type`.Namespace); println("\'")
- println("{"); indent()
- }
- print(".class ")
- // <classHead> ::=
- // <classAttr>* <id>
- // [extends <typeReference>]
- // [implements <typeReference> [, <typeReference>]*]
- print(TypeAttributes.toString(`type`.Attributes))
- print(" \'"); print(`type`.Name); print("\'")
- printTypeParams(`type`.getSortedTVars())
- if (`type`.BaseType() != null) {
- println()
- print(" extends ")
- printReference(`type`.BaseType())
- }
- var ifaces: Array[Type] = `type`.getInterfaces()
- if (ifaces.length > 0) {
- println()
- print(" implements ")
- for (i <- 0 until ifaces.length) {
- if (i > 0) {
- println(",")
- print(" ")
- }
- printReference(ifaces(i))
- }
- }
- println()
- println("{")
- indent()
- if (!nomembers && `type`.sourceFilename != null)
- println(".line " + `type`.sourceLine
- + " '" + `type`.sourceFilename + "'")
- if (!nomembers) {
- printAttributes(`type`)
- }
- // print nested classes
- val nested = `type`.nestedTypeBuilders.iterator
- while(nested.hasNext)
- print(nested.next().asInstanceOf[TypeBuilder])
-
- // print each field
- val fields = `type`.fieldBuilders.iterator
- while(fields.hasNext)
- print(fields.next().asInstanceOf[FieldBuilder])
-
- // print each constructor
- val constrs = `type`.constructorBuilders.iterator
- while (constrs.hasNext)
- print(constrs.next().asInstanceOf[ConstructorBuilder])
-
- // print each method
- val methods = `type`.methodBuilders.iterator
- while (methods.hasNext) {
- val method = methods.next().asInstanceOf[MethodBuilder]
- assert(method.DeclaringType == `type`)
- print(method)
- }
-
- undent(); println("}")
- if (!`type`.Namespace.equals("") && `type`.DeclaringType == null) {
- undent(); println("}")
- }
- currentType = null
- }
-
- /**
- * Visit a FieldBuilder
- */
- @throws(classOf[IOException])
- def caseFieldBuilder(field: FieldBuilder) {
- if (nomembers) return
- // [[int32]] <fieldAttr>* <type> <id> [= <fieldInit> | at <dataLabel>]
- print(".field ")
- print(FieldAttributes.toString(field.Attributes))
- print(" "); printSignature(field.FieldType, field.cmods)
- print(" \'"); print(field.Name); print("\'")
- if (field.IsLiteral()) {
- print(" = ")
- val value = field.getValue()
- if (value == null) {
- print("nullref")
- } else if (value.isInstanceOf[String]) {
- print(msilString(value.asInstanceOf[String]))
- } else if (value.isInstanceOf[Boolean]) {
- print("bool (")
- print(if((value.asInstanceOf[Boolean]).booleanValue()) { "true" } else { "false" })
- print(")")
- } else if (value.isInstanceOf[Byte]) {
- print("int8 (")
- print(value)
- print(")")
- } else if (value.isInstanceOf[java.lang.Short]) {
- print("int16 (")
- print(value)
- print(")")
- } else if (value.isInstanceOf[Character]) {
- print("char (")
- print((value.asInstanceOf[Character]).charValue())
- print(")")
- } else if (value.isInstanceOf[Integer]) {
- print("int32 (")
- print((value.asInstanceOf[Integer]).intValue())
- print(")")
- } else if (value.isInstanceOf[Long]) {
- print("int64 (")
- print((value.asInstanceOf[Long]).longValue())
- print(")")
- } else if (value.isInstanceOf[Float]) {
- print(msilSyntaxFloat(value.asInstanceOf[Float]))
- } else if (value.isInstanceOf[Double]) {
- print(msilSyntaxDouble(value.asInstanceOf[Double]))
- } else {
- throw new Error("ILPrinterVisitor: Illegal default value: "
- + value.getClass())
- }
- }
- println()
- printAttributes(field)
- }
-
- def msilSyntaxFloat(valFlo: java.lang.Float) : String = {
- // !!! check if encoding is correct
- val bits = java.lang.Float.floatToRawIntBits(valFlo.floatValue())
- /* see p. 170 in Lidin's book Expert .NET 2.0 IL Assembler */
- /* Note: no value is equal to Nan, including NaN. Thus, x == Float.NaN always evaluates to false. */
- val res = if (valFlo.isNaN) "0xFFC00000 /* NaN */ " /* TODO this is 'quiet NaN, http://www.savrola.com/resources/NaN.html , what's the difference with a 'signaling NaN'?? */
- else if (java.lang.Float.NEGATIVE_INFINITY == valFlo.floatValue) "0xFF800000 /* NEGATIVE_INFINITY */ "
- else if (java.lang.Float.POSITIVE_INFINITY == valFlo.floatValue) "0x7F800000 /* POSITIVE_INFINITY */ "
- else bits
- "float32 (" + res + ")"
- }
-
- def msilSyntaxDouble(valDou: java.lang.Double) : String = {
- // !!! check if encoding is correct
- var bits = java.lang.Double.doubleToRawLongBits(valDou.doubleValue())
- /* see p. 170 in Lidin's book Expert .NET 2.0 IL Assembler */
- /* Note: no value is equal to Nan, including NaN. Thus, x == Double.NaN always evaluates to false. */
- val res = if (valDou.isNaN) "0xffffffffffffffff /* NaN */ " /* TODO this is 'quiet NaN, http://www.savrola.com/resources/NaN.html , what's the difference with a 'signaling NaN'?? */
- else if (java.lang.Double.NEGATIVE_INFINITY == valDou.doubleValue) "0xfff0000000000000 /* NEGATIVE_INFINITY */ "
- else if (java.lang.Double.POSITIVE_INFINITY == valDou.doubleValue) "0x7ff0000000000000 /* POSITIVE_INFINITY */ "
- else bits
- // float64(float64(...)) != float64(...)
- "float64 (" + res + ")"
- }
-
- /**
- * Visit a ConstructorBuilder
- */
- @throws(classOf[IOException])
- def caseConstructorBuilder(constr: ConstructorBuilder) {
- if (nomembers) return
- print(".method "); printHeader(constr, VOID)
- println(); println("{"); indent()
- printAttributes(constr)
- try {
- print(constr.GetILGenerator())
- } catch {
- case e : RuntimeException => {
- System.err.println("In method " + constr)
- e.printStackTrace()
- }
- }
- undent(); println("}")
- }
-
- /**
- * Visit a MethodBuilder
- */
- @throws(classOf[IOException])
- def caseMethodBuilder(method: MethodBuilder) {
- if (nomembers) return
- print(".method "); printHeader(method, method.ReturnType)
- if (method.IsAbstract()
- || (method.DeclaringType != null
- && method.DeclaringType.IsInterface()
- && !method.IsStatic()))
- {
- println(" {"); indent()
- printAttributes(method)
- undent(); println("}")
- } else {
- println(); println("{"); indent()
- printAttributes(method)
- if (method == entryPoint)
- println(".entrypoint")
- try {
- print(method.GetILGenerator())
- } catch {
- case e: RuntimeException =>
- System.err.println("In method " + method)
- e.printStackTrace()
- }
- undent(); println("}")
- }
- }
-
- /**
- * Visit a ParameterBuilder
- */
- @throws(classOf[IOException])
- def caseParameterBuilder(param: ParameterBuilder) {
- print(ParameterAttributes.toString(param.Attributes))
- printSignature(param.ParameterType)
- //print(' ') print(marshal)
- print(' '); printName(param.Name)
- }
-
- var locals: Array[LocalBuilder] = null
- /**
- * Visit an ILGenerator
- */
- @throws(classOf[IOException])
- def caseILGenerator(code: ILGenerator) {
- // print maxstack
- println(".maxstack " + code.getMaxStacksize())
- // get the local variables
- locals = code.getLocals()
- if (locals.length > 0) {
- println(".locals init (")
- indent()
- for (i <- 0 until locals.length) {
- if (i > 0) println(",")
- print(locals(i))
- } // end while
- undent()
- println(")")
- }
- // get 3 iterators for the 3 lists
- val itL = code.getLabelIterator()
- val itO = code.getOpcodeIterator()
- val itA = code.getArgumentIterator()
- // iterate over each opcode
- while (itO.hasNext) {
- // first print label
- val label = itL.next
- val oOpt = code.lineNums.get(label)
- if (oOpt.isDefined) {
- println(".line " + oOpt.get)
- }
- argument = itA.next.asInstanceOf[Object]
- printLabel(label)
- val o2 = itO.next
- if (o2 != null) {
- print(" ")
- print(o2.asInstanceOf[OpCode])
- }
- println()
- } // end while
- }
-
- /**
- * visit an OpCode
- */
- @throws(classOf[IOException])
- def caseOpCode(opCode: OpCode) {
- var opString = opCode.toString()
- print(opString)
- pad(14 - opString.length())
-
- // switch opcode
- if (opCode == OpCode.Ldstr) {
- print(msilString(argument.toString()))
- } else if(opCode == OpCode.Switch) {
- // switch ( <labels> )
- print("(")
- val targets = argument.asInstanceOf[Array[Label]]
- val m = targets.length
- for (i <- 0 until m) {
- if (i != 0) print(", ")
- print(targets(i))
- } // end for
- print(")")
- } else if(opCode == OpCode.Call || opCode == OpCode.Callvirt || opCode == OpCode.Jmp || opCode == OpCode.Ldftn || opCode == OpCode.Ldvirtftn) {
- // call | callvirt | jmp | ldftn | ldvirtftn
- // <instr_method> <callConv> <type> [ <typeSpec> :: ] <methodName>
- printSignature(argument.asInstanceOf[MethodBase])
- } else if (opCode == OpCode.Newobj) {
- printSignature(argument.asInstanceOf[ConstructorInfo])
- // ldfld | ldflda | ldsfld | ldsflda | stfld | stsfld
- } else if (opCode == OpCode.Ldfld || opCode == OpCode.Ldflda || opCode == OpCode.Ldsfld || opCode == OpCode.Ldsflda || opCode == OpCode.Stfld || opCode == OpCode.Stsfld) {
- printSignature(argument.asInstanceOf[FieldInfo])
- } else if (opCode == OpCode.Castclass || opCode == OpCode.Isinst || opCode == OpCode.Ldobj || opCode == OpCode.Newarr) {
- printSignature(argument.asInstanceOf[Type])
- } else if (opCode == OpCode.Box || opCode == OpCode.Unbox || opCode == OpCode.Ldtoken || opCode == OpCode.Initobj) {
- printReference(argument.asInstanceOf[Type])
- } else if (opCode == OpCode.Ldloc || opCode == OpCode.Ldloc_S || opCode == OpCode.Ldloca || opCode == OpCode.Ldloca_S || opCode == OpCode.Stloc || opCode == OpCode.Stloc_S) {
- val loc = argument.asInstanceOf[LocalBuilder]
- print(loc.slot); print("\t// "); printSignature(loc.LocalType)
- print(" \'"); print(loc.name); print("\'")
- //print("'") print(((LocalBuilder)argument).name) print("'")
- } else if (opCode == OpCode.Ldloc_0 || opCode == OpCode.Ldloc_1 || opCode == OpCode.Ldloc_2 || opCode == OpCode.Ldloc_3 ) {
- val loc = locals(opCode.CEE_opcode - OpCode.CEE_LDLOC_0)
- print("\t// "); printSignature(loc.LocalType)
- print(" \'"); print(loc.name); print("\'")
- } else if (opCode == OpCode.Stloc_0 || opCode == OpCode.Stloc_1 || opCode == OpCode.Stloc_2 || opCode == OpCode.Stloc_3 ) {
- val loc = locals(opCode.CEE_opcode - OpCode.CEE_STLOC_0)
- print("\t// "); printSignature(loc.LocalType)
- print(" \'"); print(loc.name); print("\'")
- } else if (opCode == OpCode.Readonly) {
- // nothing to do
- } else if (opCode == OpCode.Constrained) {
- printReference(argument.asInstanceOf[Type])
- } else if (opCode == OpCode.Ldelema) {
- printReference(argument.asInstanceOf[Type])
- } else {
- // by default print toString argument if any
- if (argument != null) {
- val strArgument = java.lang.String.valueOf(argument)
- if ( argument.isInstanceOf[java.lang.Float]
- && ( strArgument.equals("NaN")
- || strArgument.equals("-Infinity")
- || strArgument.equals("Infinity")))
- print(msilSyntaxFloat(argument.asInstanceOf[java.lang.Float]))
- else if ( argument.isInstanceOf[java.lang.Double]
- && ( strArgument.equals("NaN")
- || strArgument.equals("-Infinity")
- || strArgument.equals("Infinity")))
- print(msilSyntaxDouble(argument.asInstanceOf[java.lang.Double]))
- else print(strArgument)
- }
-
- } // end switch
- }
-
- /**
- * Visit a Label
- */
- def printLabel(label: Label) {
- val kind = label.getKind()
- if (kind == Label.Kind.Normal) {
- print(label+ ": ")
- } else if (kind == Label.Kind.NewScope) {
- print("{"); indent()
- } else if (kind == Label.Kind.EndScope) {
- undent(); print("}")
- } else if (kind == Label.Kind.Try) {
- print(".try {"); indent()
- } else if (kind == Label.Kind.Catch) {
- undent()
- println("}")
- print("catch ")
- printReference(argument.asInstanceOf[Type])
- print(" {")
- indent()
- } else if (kind == Label.Kind.Filter) {
- undent()
- println("}")
- print("filter {")
- indent()
- } else if (kind == Label.Kind.EndFilter) {
- print("endfilter")
- undent()
- println("}")
- } else if (kind == Label.Kind.Finally) {
- undent()
- println("}")
- print("finally {")
- indent()
- } else if (kind == Label.Kind.EndTry) {
- undent()
- print("}")
- }
- }
-
- /**
- * Visit a LocalBuilder
- */
- @throws(classOf[IOException])
- def caseLocalBuilder(localBuilder: LocalBuilder) {
- // print type
- printSignature(localBuilder.LocalType)
- // space
- print(" \'")
- // print name
- print(localBuilder.name)
- print("\'")
- }
-
-
- //##########################################################################
-
- def printAssemblySignature(assem: Assembly, extern: Boolean) {
- print(".assembly ")
- if (extern)
- print("extern ")
- val an = assem.GetName()
- printName(an.Name); println()
- println("{")
- if (!extern)
- printAttributes(assem)
- val v = an.Version
- if (v != null) {
- print(" .ver "); print(v.Major); print(':'); print(v.Minor)
- print(':'); print(v.Build); print(':')
- print(v.Revision); println()
- }
- var key = an.GetPublicKeyToken()
- if (key != null) {
- print(" .publickeytoken = ("); print(PEFile.bytes2hex(key))
- println(")")
- } else {
- key = an.GetPublicKey()
- if (key != null) {
- print(" .publickey = ("); print(PEFile.bytes2hex(key))
- println(")")
- }
- }
- println("}")
- }
-
-
- def printSignature(field: FieldInfo) {
- printSignature(field.FieldType, field.cmods)
- //print(' ') print(owner)
- print(' ')
- //if (field.IsStatic && field.DeclaringType != currentType) {
- printReference(field.DeclaringType)
- print("::")
- //}
- printName(field.Name)
- }
-
- // print method head
- @throws(classOf[IOException])
- def printHeader(method: MethodBase, returnType: Type) {
- print(MethodAttributes.toString(method.Attributes))
- print(' '); print(CallingConventions.toString(method.CallingConvention))
- print(' '); printSignature(returnType)
- //print(' ') print(marshal)
- print(' '); printName(method.Name)
- if(method.isInstanceOf[MethodInfo]) {
- val mthdInfo = method.asInstanceOf[MethodInfo]
- printTypeParams(mthdInfo.getSortedMVars())
- }
- val params = method.GetParameters()
- print('(')
- for (i <- 0 until params.length) {
- if (i > 0) print(", ")
- print(params(i).asInstanceOf[ParameterBuilder])
- }
- print(") ")
-
- print(MethodImplAttributes
- .toString(method.GetMethodImplementationFlags()))
- }
-
-
- def printSignature(method: MethodBase) {
- var returnType: Type = null
- if (method.isInstanceOf[MethodInfo])
- returnType = (method.asInstanceOf[MethodInfo]).ReturnType
- else if (method.isInstanceOf[ConstructorInfo])
- returnType = VOID
- else
- throw new RuntimeException()
-
- val s = CallingConventions.toString(method.CallingConvention)
- print(s)
- if (s.length() > 0) print(' ')
- printSignature(returnType)
- //print(' ') print(owner)
- print(' '); printReference(method.DeclaringType)
- print("::"); printName(method.Name)
-
- var params = method.GetParameters()
- print("(")
- for (i <- 0 until params.length) {
- if (i > 0) print(", ")
- printSignature(params(i).ParameterType)
- }
- print(")")
- }
-
- def printSignature(marked: Type, cmods: Array[CustomModifier]) {
- printSignature(marked)
- if( (cmods != null) && !cmods.isEmpty ) {
- print(" ")
- for(cm <- cmods) {
- print(if (cm.isReqd) "modreq( " else "modopt( ")
- printReference(cm.marker)
- print(" ) ")
- }
- }
- }
-
- def printSignature(`type`: Type) {
- val sigOpt = primitive.get(`type`)
- if (sigOpt.isDefined) {
- print(sigOpt.get)
- return
- }
- if (`type`.HasElementType()) {
- printSignature(`type`.GetElementType())
- if (`type`.IsArray())
- print("[]")
- else if (`type`.IsPointer())
- print('*')
- else if (`type`.IsByRef())
- print('&')
- } else {
- val preref = if (`type`.isInstanceOf[Type.TMVarUsage]) ""
- else if(`type`.IsValueType()) "valuetype "
- else "class "
- print(preref)
- printReference(`type`)
- }
- }
-
- def printReference(`type`: Type) {
- if (`type`.Module != null) { // i.e. not PrimitiveType and not TMVarUsage
- if (`type`.Assembly() != currentModule.Assembly) {
- print('['); print(`type`.Assembly().GetName().Name); print("]")
- } else if (`type`.Module != currentModule) {
- print("[.module "); print(`type`.Module.Name); print("]")
- }
- }
- printTypeName(`type`)
- }
-
- def printTypeName(`type`: Type) {
- if (`type`.isInstanceOf[ConstructedType]) {
- val ct = `type`.asInstanceOf[ConstructedType]
- printTypeName(ct.instantiatedType)
- print("<")
- var i = 0
- while (i < ct.typeArgs.length) {
- val ta = ct.typeArgs(i)
- val sigOpt = primitive.get(ta)
- if (sigOpt.isDefined) print(sigOpt.get)
- else printTypeName(ta); /* should be printSignature, but don't want `class` or `valuetype`
- appearing before a type param usage. */
- i = i + 1;
- if (i < ct.typeArgs.length) {
- print(", ")
- }
- }
- print(">")
- } else if (`type`.DeclaringType != null) {
- printTypeName(`type`.DeclaringType)
- print('/')
- printName(`type`.Name)
- } else {
- printName(`type`.FullName)
- }
- }
-
- def printAttributes(icap: ICustomAttributeProvider) {
- var attrs = icap.GetCustomAttributes(false)
- for (i <- 0 until attrs.length) {
- print(".custom ")
- printSignature((attrs(i).asInstanceOf[Attribute]).getConstructor())
- print(" = (")
- print(PEFile.bytes2hex((attrs(i).asInstanceOf[Attribute]).getValue()))
- println(")")
- }
- }
-
- //##########################################################################
-
-} // class ILPrinterVisitor
-
-object ILPrinterVisitor {
- final val VOID: Type = Type.GetType("System.Void")
- protected final val TAB = 4
-
- protected final val SPACES = " "
- protected final val SPACES_LEN = SPACES.length()
-
- def hasControlChars(str: String): Boolean = {
- for(i <- 0 until str.length()) {
- var ch = str.charAt(i)
- ch match {
- case '\b' =>
- case '\t' =>
- case '\n' =>
- case '\f' =>
- case '\r' =>
- case _ => if(Character.isISOControl(ch)) return true
- }
- }
- return false
- }
-
- final val EMPTY: String = ""
- def msilString(s: String): String = {
- if (hasControlChars(s)) {
- try {
- return "bytearray (" + PEFile.bytes2hex(s.getBytes("UTF-16LE")) + ")"
- } catch {
- case e : java.io.UnsupportedEncodingException => throw new RuntimeException(e)
- }
- }
- var str = new StringBuffer(s)
- var ss = EMPTY
- var i = 0
- while(i < str.length()) {
- ss = EMPTY
- val c = str.charAt(i)
- c match {
- case '\b' => ss = "\\b"
- case '\t' => ss = "\\t"
- case '\n' => ss = "\\n"
- case '\f' => ss = "\\f"
- case '\r' => ss = "\\r"
- case '\"' => ss = "\\\""
- case '\'' => ss = "\\\'"
- case '\\' => ss = "\\\\"
- case _ => if (Character.isISOControl(c))
- ss = "\\u" + PEFile.int2hex(Character.getNumericValue(c))
- }
- if (ss != EMPTY) {
- str.replace(i, i + 1, ss)
- i = i + ss.length() - 1
- }
- i = i + 1
- }
- return "\"" + str.toString() + "\""
- }
-
- /**
- * the main printer method
- */
- @throws(classOf[IOException])
- def printAssembly(assemblyBuilder: AssemblyBuilder, fileName: String) {
- assemblyBuilder.apply(new SingleFileILPrinterVisitor(fileName))
- }
-
- @throws(classOf[IOException])
- def printAssembly(assemblyBuilder: AssemblyBuilder, destPath: String, sourceFilesPath: String) {
- assemblyBuilder.apply(new MultipleFilesILPrinterVisitor(destPath, sourceFilesPath))
- }
-
- /** The current assembly */
- var currAssembly: Assembly = _
-
- final var primitive = scala.collection.mutable.Map.empty[Type, String]
- def addPrimitive(name: String, sig: String) {
- var `type` =
- Type.GetType(name)
- assert(`type` != null, "Cannot lookup primitive type " + `type`)
- primitive.put(`type`, sig)
- }
-
- addPrimitive("System.Object", "object")
- addPrimitive("System.String", "string")
- addPrimitive("System.Void", "void")
- addPrimitive("System.Boolean", "bool")
- addPrimitive("System.Char", "char")
- addPrimitive("System.SByte", "int8")
- addPrimitive("System.Byte", "unsigned int8")
- addPrimitive("System.Int16", "int16")
- addPrimitive("System.UInt16", "unsigned int16")
- addPrimitive("System.Int32", "int32")
- addPrimitive("System.UInt32", "unsigned int32")
- addPrimitive("System.Int64", "int64")
- addPrimitive("System.UInt64", "unsigned int64")
- addPrimitive("System.IntPtr", "native int")
- addPrimitive("System.UIntPtr", "unsigned native int")
- addPrimitive("System.Single", "float32")
- addPrimitive("System.Double", "float64")
- addPrimitive("System.TypedReference", "typedref")
-}
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/emit/Label.scala b/src/msil/ch/epfl/lamp/compiler/msil/emit/Label.scala
deleted file mode 100644
index 22c1b1150b..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/emit/Label.scala
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * System.Reflection.Emit-like API for writing .NET assemblies to MSIL
- */
-
-
-package ch.epfl.lamp.compiler.msil.emit
-
-import ch.epfl.lamp.compiler.msil.Type
-
-/**
- * Represents a label in the instruction stream. Label is used in conjunction
- * with the ILGenerator class.
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-abstract class Label protected {
- import Label._
- def isInitialized(): Boolean
- def getKind(): Kind
- def getAddress(): Int
- def getStacksize(): Int
- def setStacksize(stacksize: Int): Unit
- def incStacksize(): Unit
- def mergeWith(that: Label): Unit
-}
-
-object Label {
- final val DUMMY: Int = -((1<<31)-1)
-
- //##########################################################################
-
- final class NormalLabel(_address: Int, _stacksize: Int) extends Label {
-
- //##########################################################################
- // protected constructors
-
- //the position of the label
- private var address: Int = _address
-
- //the stacksize at the label
- private var stacksize: Int = _stacksize
-
- def this() {
- this(-1, DUMMY)
- }
-
- def this(that: NormalLabel) {
- this(that.getAddress(), that.getStacksize())
- }
-
- //##########################################################################
- // instrumental methods only used by ILGenerator
-
- def isInitialized() = (getAddress() != -1) || (stacksize != DUMMY)
-
- def getAddress() = address
-
- def getStacksize() = stacksize
-
- def setStacksize(stacksize: Int) {
- assert(stacksize >= 0)
- this.stacksize = stacksize
- }
-
- def incStacksize() {
- stacksize = stacksize + 1
- }
-
- def getKind(): Kind = Kind.Normal
-
- def mergeWith(that: Label) {
- //assert address < 0 : "this.address = " + address + " that.address = " + that.address
- address = that.getAddress()
-
- // assert stacksize == that.stacksize
- // : "this.stacksize = " + stacksize + " that.stacksize = "
- // + that.stacksize
- // stacksize = that.stacksize
- val ss: Int = math.max(stacksize, that.getStacksize())
- stacksize = ss
- that.setStacksize(ss)
- }
-
- //##########################################################################
- //
-
- /**
- * the toString Method return the label name
- * it's "IL" + address
- */
- override def toString(): String = {
- var pad: String = ""
- if (address < 16) pad = "000"
- else if (address < 256) pad = "00"
- else if (address < 4096) pad = "0"
- return "IL_" + pad + Integer.toHexString(address)
- }
-
- def getString(): String = {
- val name = super.toString()
- val i: Int = name.lastIndexOf('.')
- return name.substring(i+1, name.length())
- }
- }
-
- //########################################################################
- // Special Labels
-
- final class SpecialLabel(_kind: Label.Kind) extends Label {
- private final var kind: Label.Kind = _kind
- def isInitialized() = true
- def getAddress(): Int = { throw new RuntimeException("" + kind.toString()) }
- def getStacksize(): Int = { throw new RuntimeException("" + kind.toString()) }
- def setStacksize(stacksize: Int) { throw new RuntimeException(kind.toString()) }
- def incStacksize() { throw new RuntimeException(kind.toString()) }
- def getKind(): Kind = kind
- def mergeWith(that: Label) { throw new RuntimeException(kind.toString()) }
- override def toString(): String = "Label(" + kind.toString() + ")"
- }
-
- final val NewScope: Label = new SpecialLabel(Kind.NewScope)
- final val EndScope: Label = new SpecialLabel(Kind.EndScope)
- final val Try: Label = new SpecialLabel(Kind.Try)
- final val Catch: Label = new SpecialLabel(Kind.Catch)
- final val Filter: Label = new SpecialLabel(Kind.Filter)
- final val EndFilter: Label = new SpecialLabel(Kind.EndFilter)
- final val Finally: Label = new SpecialLabel(Kind.Finally)
- final val EndTry: Label = new SpecialLabel(Kind.EndTry)
-
- final class Kind() {}
-
- final object Kind {
- final val Normal: Kind = new Kind()
-
- final val NewScope: Kind = new Kind()
- final val EndScope: Kind = new Kind()
-
- final val Try: Kind = new Kind()
- final val Catch: Kind = new Kind()
- final val Filter: Kind = new Kind()
- final val EndFilter: Kind = new Kind()
- final val Finally: Kind = new Kind()
- final val EndTry: Kind = new Kind()
- }
-
- //##########################################################################
-}
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/emit/LocalBuilder.scala b/src/msil/ch/epfl/lamp/compiler/msil/emit/LocalBuilder.scala
deleted file mode 100644
index 73bca4639f..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/emit/LocalBuilder.scala
+++ /dev/null
@@ -1,44 +0,0 @@
-/**
- * System.Reflection.Emit-like API for writing .NET assemblies to MSIL
- */
-
-
-package ch.epfl.lamp.compiler.msil.emit
-
-import ch.epfl.lamp.compiler.msil.Type
-
-/**
- * Represents a local variable within a method or constructor.
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-class LocalBuilder(_slot : Int, localType : Type) extends Visitable {
-
- /**
- * the type of the local variable.
- */
- var LocalType : Type = localType
-
- // the name of the local variable
- var name : String = "L_" + slot
-
- // the slot occupied by this local in the corresponding ILGenerator
- var slot : Int = _slot
-
- /**
- * Sets the name of this local variable.
- */
- def SetLocalSymInfo(name : String) {
- this.name = name
- }
-
- override def toString() : String = name
-
- /**
- * the apply method for a visitor
- */
- def apply(v : Visitor) {
- v.caseLocalBuilder(this)
- }
-}
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/emit/MethodBuilder.scala b/src/msil/ch/epfl/lamp/compiler/msil/emit/MethodBuilder.scala
deleted file mode 100644
index 237d8fd728..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/emit/MethodBuilder.scala
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * System.Reflection.Emit-like API for writing .NET assemblies to MSIL
- */
-
-
-package ch.epfl.lamp.compiler.msil.emit
-
-import ch.epfl.lamp.compiler.msil.MethodInfo
-import ch.epfl.lamp.compiler.msil.ParameterInfo
-import ch.epfl.lamp.compiler.msil.Type
-import ch.epfl.lamp.compiler.msil.ConstructorInfo
-import java.io.IOException
-
-/**
- * Defines and represents a method of a dynamic class.
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-class MethodBuilder(name: String, declType: Type, attrs: Int, returnType: Type, paramTypes: Array[Type])
- extends MethodInfo(name, declType, attrs, returnType, paramTypes)
- with ICustomAttributeSetter
- with Visitable
-{
-
- //##########################################################################
- // public interface
-
- /** Defines a parameter of this method. TODO: Parameters are indexed staring
- * from number 1 for the first parameter
- */
- def DefineParameter(pos: Int, attr: Int, name: String): ParameterBuilder = {
- val param = new ParameterBuilder(name, params(pos).ParameterType, attr, pos)
- params(pos) = param
- return param
- }
-
- /** Returns an ILGenerator for this method. */
- def GetILGenerator(): ILGenerator = {
- if (ilGenerator == null)
- throw new RuntimeException
- ("No code generator available for this method: " + this)
- return ilGenerator
- }
-
- /** Sets a custom attribute. */
- def SetCustomAttribute(constr: ConstructorInfo, value: Array[Byte]) {
- addCustomAttribute(constr, value)
- }
-
- //##########################################################################
-
- /** The apply method for a visitor. */
- @throws(classOf[IOException])
- def apply(v: Visitor) {
- v.caseMethodBuilder(this)
- }
-
- //##########################################################################
-
- // the Intermediate Language Generator
- // it contains the method's body
- protected final val ilGenerator : ILGenerator =
- if (DeclaringType == null // global method
- || !DeclaringType.IsInterface())
- new ILGenerator(this)
- else null
-
- //##########################################################################
-}
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/emit/ModuleBuilder.scala b/src/msil/ch/epfl/lamp/compiler/msil/emit/ModuleBuilder.scala
deleted file mode 100644
index 981e855e0e..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/emit/ModuleBuilder.scala
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * System.Reflection.Emit-like API for writing .NET assemblies to MSIL
- */
-
-
-package ch.epfl.lamp.compiler.msil.emit
-
-import ch.epfl.lamp.compiler.msil._
-import java.io.IOException
-
-/**
- * Defines and represents a module. Get an instance of ModuleBuilder
- * by calling DefineDynamicModule
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-class ModuleBuilder(name: String, fullname: String, scopeName: String, assembly: Assembly)
- extends Module(name, fullname, scopeName, assembly)
- with ICustomAttributeSetter
- with Visitable
-{
-
- //##########################################################################
- // public interface
-
- /**
- * Complete the global function definitions for this dynamic module.
- * This method should be called when the user is done with defining
- * all of the global functions within this dynamic module. After calling
- * this function, no more new global functions or new global data are
- * allowed.
- */
- def CreateGlobalFunctions() {
- if (globalsCreated)
- throw new RuntimeException("Global functions are already created")
- this.fields = fieldBuilders.toArray // (fields).asInstanceOf[Array[FieldInfo]]
- this.methods = methodBuilders.toArray // (methods).asInstanceOf[Array[MethodInfo]]
- globalsCreated = true
- }
-
- /**
- * Constructs a TypeBuilder for a type with the specified name
- */
- def DefineType(typeName: String): TypeBuilder = {
- return DefineType(typeName, 0, null, Type.EmptyTypes)
- }
-
- /**
- * Constructs a TypeBuilder for a type with the specified name
- * and specified attributes
- */
- def DefineType(typeName: String, attributes: Int): TypeBuilder = {
- return DefineType(typeName, attributes, null, Type.EmptyTypes)
- }
-
- /**
- * Constructs a TypeBuilder given type name, its attributes,
- * and the type that the defined type extends.
- */
- def DefineType(typeName: String, attributes: Int,
- baseType: Type): TypeBuilder = {
- return DefineType(typeName, attributes, baseType, Type.EmptyTypes)
- }
-
- /**
- * Constructs a TypeBuilder given the Full specification of a type,
- * Given the type name, attributes, the type that the defined type
- * extends, and the interfaces that the defined type implements.
- */
- def DefineType(typeName: String,
- attributes: Int,
- baseType: Type,
- interfaces: Array[Type]): TypeBuilder =
- {
- var t: Type = GetType(typeName) // Module.GetType(String)
- if (t != null)
- throw new RuntimeException
- ("Type [" + Assembly + "]" + typeName + "' already exists!")
- val `type` =
- new TypeBuilder(this, attributes, typeName, baseType, interfaces, null)
- addType(`type`)
- return `type`
- }
-
- /**
- * Defines a global method given its name, attributes, return type, and
- * parameter types.
- */
- def DefineGlobalMethod(name: String, attributes: Int,
- returnType: Type, paramTypes: Array[Type]): MethodBuilder =
- {
- val method =
- new MethodBuilder(name, null, attributes, returnType, paramTypes)
- methodBuilders += method
- return method
- }
-
-
- override def GetTypes(): Array[Type] = {
- val res = scala.collection.mutable.ArrayBuffer.empty[Type]
- val iter = typesMap.values().iterator
- while (iter.hasNext) {
- res += iter.next.asInstanceOf[Type]
- }
- return res.toArray
- }
-
- /** Sets a custom attribute. */
- def SetCustomAttribute(constr: ConstructorInfo, value: Array[Byte]) {
- addCustomAttribute(constr, value)
- }
-
- //##########################################################################
- // internal members
-
- var globalsCreated = false
- protected var fieldBuilders = scala.collection.mutable.ArrayBuffer.empty[FieldInfo]
- protected var methodBuilders = scala.collection.mutable.ArrayBuffer.empty[MethodInfo]
-
- override def addType(t: Type): Type = {
- return super.addType(t)
- }
-
- //##########################################################################
-
- /**
- * the apply method for a visitor
- */
- @throws(classOf[IOException])
- def apply(v: Visitor) {
- v.caseModuleBuilder(this)
- }
-
- //##########################################################################
-}
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/emit/MultipleFilesILPrinterVisitor.scala b/src/msil/ch/epfl/lamp/compiler/msil/emit/MultipleFilesILPrinterVisitor.scala
deleted file mode 100644
index 55c52109b6..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/emit/MultipleFilesILPrinterVisitor.scala
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * System.Reflection.Emit-like API for writing .NET assemblies in MSIL
- */
-
-
-package ch.epfl.lamp.compiler.msil.emit
-
-import java.io.File
-import java.io.FileWriter
-import java.io.BufferedWriter
-import java.io.PrintWriter
-import java.io.IOException
-import java.util.Iterator
-import java.util.Arrays
-
-import ch.epfl.lamp.compiler.msil._
-import ch.epfl.lamp.compiler.msil.emit
-import ch.epfl.lamp.compiler.msil.util.Table
-
-/**
- * The MSIL printer Visitor. It prints a complete
- * assembly into separate files. Then these files can be compiled by ilasm.
- *
- * @author Nikolay Mihaylov
- * @author Daniel Lorch
- * @version 1.0
- */
-final class MultipleFilesILPrinterVisitor(destPath: String, sourceFilesPath: String) extends ILPrinterVisitor {
- /**
- * Visit an AssemblyBuilder
- */
- @throws(classOf[IOException])
- def caseAssemblyBuilder(assemblyBuilder: AssemblyBuilder) {
- ILPrinterVisitor.currAssembly = assemblyBuilder
-
- // first get the entryPoint
- this.entryPoint = assemblyBuilder.EntryPoint
-
- // all external assemblies
- as = assemblyBuilder.getExternAssemblies()
- scala.util.Sorting.quickSort(as)(assemblyNameComparator) // Arrays.sort(as, assemblyNameComparator)
-
- // print each module
- var m: Array[Module] = assemblyBuilder.GetModules()
- nomembers = true
- for(i <- 0 until m.length) {
- print(m(i).asInstanceOf[ModuleBuilder])
- }
-
- nomembers = false
- for(i <- 0 until m.length) {
- print(m(i).asInstanceOf[ModuleBuilder])
- }
- ILPrinterVisitor.currAssembly = null
- }
-
- /**
- * Visit a ModuleBuilder
- */
- @throws(classOf[IOException])
- def caseModuleBuilder(module: ModuleBuilder) {
- val assemblyBuilder = ILPrinterVisitor.currAssembly.asInstanceOf[AssemblyBuilder]
-
- // print module declaration
- currentModule = module
-
- // global methods typically contain the main method
- if (!module.globalsCreated)
- module.CreateGlobalFunctions()
-
- var m: Array[MethodInfo] = module.GetMethods()
-
- // "Types" contain all the classes
- var t: Array[Type] = module.GetTypes()
- for(i <- 0 until t.length) {
- val tBuilder = t(i).asInstanceOf[TypeBuilder]
- val sourceFilename = tBuilder.sourceFilename
- val sourceFilepath = new File(tBuilder.sourceFilepath).getCanonicalPath
- val sourcePath = new File(sourceFilesPath).getCanonicalPath
- var append = false
-
- if(!sourceFilepath.startsWith(sourcePath)) {
- throw new IOException("Source file " + sourceFilename + " must lie inside sourcepath " + sourcePath)
- }
-
- assert(sourceFilepath.endsWith(".scala"), "Source file doesn't end with .scala")
- val relativeFilename = sourceFilepath.substring(sourcePath.length, sourceFilepath.length() - 6) + ".msil"
- val fileName = new File(destPath, relativeFilename)
- if(assemblyBuilder.generatedFiles.contains(fileName.getPath)) {
- append = true
- } else {
- fileName.getParentFile().mkdirs()
- assemblyBuilder.generatedFiles += (fileName.getPath)
- }
-
- out = new PrintWriter(new BufferedWriter(new FileWriter(fileName, append)))
- // only write assembly boilerplate and class prototypes
- if (!append && nomembers) {
- printAssemblyBoilerplate()
-
- print(".module \'"); print(module.Name); println("\'")
- printAttributes(module)
- }
-
- print(t(i).asInstanceOf[TypeBuilder])
- out.close()
- }
-
- // now write the global methods (typically contains the "main" method)
- if(!nomembers) {
- var globalMethods: File = new File(destPath, ILPrinterVisitor.currAssembly.GetName().Name + ".msil")
- val append = assemblyBuilder.generatedFiles.contains(globalMethods.getPath)
-
- out = new PrintWriter(new BufferedWriter(new FileWriter(globalMethods, append)))
-
- // make sure we're the first in the list (ilasm uses the first file name to guess the output file name)
- assemblyBuilder.generatedFiles.insert(0, globalMethods.getPath)
-
- // if this file hasn't been created by one of the classes, write boilerplate
- if(!append) {
- printAssemblyBoilerplate()
-
- print(".module \'"); print(module.Name); println("\'")
- printAttributes(module)
- }
-
- for(i <- 0 until m.length) {
- print(m(i).asInstanceOf[MethodBuilder])
- }
-
- out.close()
- }
-
- currentModule = null
- }
-
-} // class MultipleFilesILPrinterVisitor
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/emit/OpCode.scala b/src/msil/ch/epfl/lamp/compiler/msil/emit/OpCode.scala
deleted file mode 100644
index b0c26884af..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/emit/OpCode.scala
+++ /dev/null
@@ -1,1948 +0,0 @@
-/*
- * System.Reflection.Emit-like API for writing .NET assemblies to MSIL
- */
-
-
-package ch.epfl.lamp.compiler.msil.emit
-
-import java.io.IOException
-
-/** Describes a Microsoft intermediate language (MSIL) instruction.
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-class OpCode extends Visitable {
- import OpCode._
-
- /** The Operation Code of Microsoft intermediate language (MSIL) instruction. */
- var CEE_opcode : Int = _
-
- /** The name of the Microsoft intermediate language (MSIL) instruction. */
- var CEE_string: String = _
-
- /** The type of Microsoft intermediate language (MSIL) instruction. */
- var CEE_code: Short = _
-
- /** How the Microsoft intermediate language (MSIL) instruction pops the stack. */
- var CEE_pop: Byte = _
-
- /** How the Microsoft intermediate language (MSIL) instruction pushes operand onto the stack. */
- var CEE_push: Byte = _
-
- /** Describes the type of flow control. */
- var CEE_flow: Byte = _
-
- /** ????? */
- var CEE_inline: Byte = _
-
- var CEE_length: Byte = _
-
- var CEE_popush: Byte = _
-
- /**
- * the apply method for a visitor
- */
- @throws(classOf[IOException])
- def apply(v: Visitor) {
- v.caseOpCode(this)
- }
-
- protected def length(): Byte = {
- val code = OpCode.length(CEE_code)
- val inline = OpCode.INLINE_length(CEE_inline)
- return if(inline < 0) { -1 } else { (code + inline).toByte }
- }
-
- protected def popush(): Byte = {
- val pop = OpCode.POP_size(CEE_pop)
- val push = OpCode.PUSH_size(CEE_push)
- return if(pop < 0 || push < 0) { OpCode.POPUSH_SPECIAL } else { (push - pop).toByte }
- }
-
- override def toString(): String = {
- return CEE_string
- }
-}
-
-object OpCode {
-
- //########################################################################
- // Common Execution Environment opcodes
-
- final val CEE_NOP : Int = 0x0000
- final val CEE_BREAK : Int = 0x0001
- final val CEE_LDARG_0 : Int = 0x0002
- final val CEE_LDARG_1 : Int = 0x0003
- final val CEE_LDARG_2 : Int = 0x0004
- final val CEE_LDARG_3 : Int = 0x0005
- final val CEE_LDLOC_0 : Int = 0x0006
- final val CEE_LDLOC_1 : Int = 0x0007
- final val CEE_LDLOC_2 : Int = 0x0008
- final val CEE_LDLOC_3 : Int = 0x0009
- final val CEE_STLOC_0 : Int = 0x000A
- final val CEE_STLOC_1 : Int = 0x000B
- final val CEE_STLOC_2 : Int = 0x000C
- final val CEE_STLOC_3 : Int = 0x000D
- final val CEE_LDARG_S : Int = 0x000E
- final val CEE_LDARGA_S : Int = 0x000F
- final val CEE_STARG_S : Int = 0x0010
- final val CEE_LDLOC_S : Int = 0x0011
- final val CEE_LDLOCA_S : Int = 0x0012
- final val CEE_STLOC_S : Int = 0x0013
- final val CEE_LDNULL : Int = 0x0014
- final val CEE_LDC_I4_M1 : Int = 0x0015
- final val CEE_LDC_I4_0 : Int = 0x0016
- final val CEE_LDC_I4_1 : Int = 0x0017
- final val CEE_LDC_I4_2 : Int = 0x0018
- final val CEE_LDC_I4_3 : Int = 0x0019
- final val CEE_LDC_I4_4 : Int = 0x001A
- final val CEE_LDC_I4_5 : Int = 0x001B
- final val CEE_LDC_I4_6 : Int = 0x001C
- final val CEE_LDC_I4_7 : Int = 0x001D
- final val CEE_LDC_I4_8 : Int = 0x001E
- final val CEE_LDC_I4_S : Int = 0x001F
- final val CEE_LDC_I4 : Int = 0x0020
- final val CEE_LDC_I8 : Int = 0x0021
- final val CEE_LDC_R4 : Int = 0x0022
- final val CEE_LDC_R8 : Int = 0x0023
- final val CEE_UNUSED49 : Int = 0x0024
- final val CEE_DUP : Int = 0x0025
- final val CEE_POP : Int = 0x0026
- final val CEE_JMP : Int = 0x0027
- final val CEE_CALL : Int = 0x0028
- final val CEE_CALLI : Int = 0x0029
- final val CEE_RET : Int = 0x002A
- final val CEE_BR_S : Int = 0x002B
- final val CEE_BRFALSE_S : Int = 0x002C
- final val CEE_BRTRUE_S : Int = 0x002D
- final val CEE_BEQ_S : Int = 0x002E
- final val CEE_BGE_S : Int = 0x002F
- final val CEE_BGT_S : Int = 0x0030
- final val CEE_BLE_S : Int = 0x0031
- final val CEE_BLT_S : Int = 0x0032
- final val CEE_BNE_UN_S : Int = 0x0033
- final val CEE_BGE_UN_S : Int = 0x0034
- final val CEE_BGT_UN_S : Int = 0x0035
- final val CEE_BLE_UN_S : Int = 0x0036
- final val CEE_BLT_UN_S : Int = 0x0037
- final val CEE_BR : Int = 0x0038
- final val CEE_BRFALSE : Int = 0x0039
- final val CEE_BRTRUE : Int = 0x003A
- final val CEE_BEQ : Int = 0x003B
- final val CEE_BGE : Int = 0x003C
- final val CEE_BGT : Int = 0x003D
- final val CEE_BLE : Int = 0x003E
- final val CEE_BLT : Int = 0x003F
- final val CEE_BNE_UN : Int = 0x0040
- final val CEE_BGE_UN : Int = 0x0041
- final val CEE_BGT_UN : Int = 0x0042
- final val CEE_BLE_UN : Int = 0x0043
- final val CEE_BLT_UN : Int = 0x0044
- final val CEE_SWITCH : Int = 0x0045
- final val CEE_LDIND_I1 : Int = 0x0046
- final val CEE_LDIND_U1 : Int = 0x0047
- final val CEE_LDIND_I2 : Int = 0x0048
- final val CEE_LDIND_U2 : Int = 0x0049
- final val CEE_LDIND_I4 : Int = 0x004A
- final val CEE_LDIND_U4 : Int = 0x004B
- final val CEE_LDIND_I8 : Int = 0x004C
- final val CEE_LDIND_I : Int = 0x004D
- final val CEE_LDIND_R4 : Int = 0x004E
- final val CEE_LDIND_R8 : Int = 0x004F
- final val CEE_LDIND_REF : Int = 0x0050
- final val CEE_STIND_REF : Int = 0x0051
- final val CEE_STIND_I1 : Int = 0x0052
- final val CEE_STIND_I2 : Int = 0x0053
- final val CEE_STIND_I4 : Int = 0x0054
- final val CEE_STIND_I8 : Int = 0x0055
- final val CEE_STIND_R4 : Int = 0x0056
- final val CEE_STIND_R8 : Int = 0x0057
- final val CEE_ADD : Int = 0x0058
- final val CEE_SUB : Int = 0x0059
- final val CEE_MUL : Int = 0x005A
- final val CEE_DIV : Int = 0x005B
- final val CEE_DIV_UN : Int = 0x005C
- final val CEE_REM : Int = 0x005D
- final val CEE_REM_UN : Int = 0x005E
- final val CEE_AND : Int = 0x005F
- final val CEE_OR : Int = 0x0060
- final val CEE_XOR : Int = 0x0061
- final val CEE_SHL : Int = 0x0062
- final val CEE_SHR : Int = 0x0063
- final val CEE_SHR_UN : Int = 0x0064
- final val CEE_NEG : Int = 0x0065
- final val CEE_NOT : Int = 0x0066
- final val CEE_CONV_I1 : Int = 0x0067
- final val CEE_CONV_I2 : Int = 0x0068
- final val CEE_CONV_I4 : Int = 0x0069
- final val CEE_CONV_I8 : Int = 0x006A
- final val CEE_CONV_R4 : Int = 0x006B
- final val CEE_CONV_R8 : Int = 0x006C
- final val CEE_CONV_U4 : Int = 0x006D
- final val CEE_CONV_U8 : Int = 0x006E
- final val CEE_CALLVIRT : Int = 0x006F
- final val CEE_CPOBJ : Int = 0x0070
- final val CEE_LDOBJ : Int = 0x0071
- final val CEE_LDSTR : Int = 0x0072
- final val CEE_NEWOBJ : Int = 0x0073
- final val CEE_CASTCLASS : Int = 0x0074
- final val CEE_ISINST : Int = 0x0075
- final val CEE_CONV_R_UN : Int = 0x0076
- final val CEE_UNUSED58 : Int = 0x0077
- final val CEE_UNUSED1 : Int = 0x0078
- final val CEE_UNBOX : Int = 0x0079
- final val CEE_THROW : Int = 0x007A
- final val CEE_LDFLD : Int = 0x007B
- final val CEE_LDFLDA : Int = 0x007C
- final val CEE_STFLD : Int = 0x007D
- final val CEE_LDSFLD : Int = 0x007E
- final val CEE_LDSFLDA : Int = 0x007F
- final val CEE_STSFLD : Int = 0x0080
- final val CEE_STOBJ : Int = 0x0081
- final val CEE_CONV_OVF_I1_UN : Int = 0x0082
- final val CEE_CONV_OVF_I2_UN : Int = 0x0083
- final val CEE_CONV_OVF_I4_UN : Int = 0x0084
- final val CEE_CONV_OVF_I8_UN : Int = 0x0085
- final val CEE_CONV_OVF_U1_UN : Int = 0x0086
- final val CEE_CONV_OVF_U2_UN : Int = 0x0087
- final val CEE_CONV_OVF_U4_UN : Int = 0x0088
- final val CEE_CONV_OVF_U8_UN : Int = 0x0089
- final val CEE_CONV_OVF_I_UN : Int = 0x008A
- final val CEE_CONV_OVF_U_UN : Int = 0x008B
- final val CEE_BOX : Int = 0x008C
- final val CEE_NEWARR : Int = 0x008D
- final val CEE_LDLEN : Int = 0x008E
- final val CEE_LDELEMA : Int = 0x008F
- final val CEE_LDELEM_I1 : Int = 0x0090
- final val CEE_LDELEM_U1 : Int = 0x0091
- final val CEE_LDELEM_I2 : Int = 0x0092
- final val CEE_LDELEM_U2 : Int = 0x0093
- final val CEE_LDELEM_I4 : Int = 0x0094
- final val CEE_LDELEM_U4 : Int = 0x0095
- final val CEE_LDELEM_I8 : Int = 0x0096
- final val CEE_LDELEM_I : Int = 0x0097
- final val CEE_LDELEM_R4 : Int = 0x0098
- final val CEE_LDELEM_R8 : Int = 0x0099
- final val CEE_LDELEM_REF : Int = 0x009A
- final val CEE_STELEM_I : Int = 0x009B
- final val CEE_STELEM_I1 : Int = 0x009C
- final val CEE_STELEM_I2 : Int = 0x009D
- final val CEE_STELEM_I4 : Int = 0x009E
- final val CEE_STELEM_I8 : Int = 0x009F
- final val CEE_STELEM_R4 : Int = 0x00A0
- final val CEE_STELEM_R8 : Int = 0x00A1
- final val CEE_STELEM_REF : Int = 0x00A2
- final val CEE_UNUSED2 : Int = 0x00A3
- final val CEE_UNUSED3 : Int = 0x00A4
- final val CEE_UNUSED4 : Int = 0x00A5
- final val CEE_UNUSED5 : Int = 0x00A6
- final val CEE_UNUSED6 : Int = 0x00A7
- final val CEE_UNUSED7 : Int = 0x00A8
- final val CEE_UNUSED8 : Int = 0x00A9
- final val CEE_UNUSED9 : Int = 0x00AA
- final val CEE_UNUSED10 : Int = 0x00AB
- final val CEE_UNUSED11 : Int = 0x00AC
- final val CEE_UNUSED12 : Int = 0x00AD
- final val CEE_UNUSED13 : Int = 0x00AE
- final val CEE_UNUSED14 : Int = 0x00AF
- final val CEE_UNUSED15 : Int = 0x00B0
- final val CEE_UNUSED16 : Int = 0x00B1
- final val CEE_UNUSED17 : Int = 0x00B2
- final val CEE_CONV_OVF_I1 : Int = 0x00B3
- final val CEE_CONV_OVF_U1 : Int = 0x00B4
- final val CEE_CONV_OVF_I2 : Int = 0x00B5
- final val CEE_CONV_OVF_U2 : Int = 0x00B6
- final val CEE_CONV_OVF_I4 : Int = 0x00B7
- final val CEE_CONV_OVF_U4 : Int = 0x00B8
- final val CEE_CONV_OVF_I8 : Int = 0x00B9
- final val CEE_CONV_OVF_U8 : Int = 0x00BA
- final val CEE_UNUSED50 : Int = 0x00BB
- final val CEE_UNUSED18 : Int = 0x00BC
- final val CEE_UNUSED19 : Int = 0x00BD
- final val CEE_UNUSED20 : Int = 0x00BE
- final val CEE_UNUSED21 : Int = 0x00BF
- final val CEE_UNUSED22 : Int = 0x00C0
- final val CEE_UNUSED23 : Int = 0x00C1
- final val CEE_REFANYVAL : Int = 0x00C2
- final val CEE_CKFINITE : Int = 0x00C3
- final val CEE_UNUSED24 : Int = 0x00C4
- final val CEE_UNUSED25 : Int = 0x00C5
- final val CEE_MKREFANY : Int = 0x00C6
- final val CEE_UNUSED59 : Int = 0x00C7
- final val CEE_UNUSED60 : Int = 0x00C8
- final val CEE_UNUSED61 : Int = 0x00C9
- final val CEE_UNUSED62 : Int = 0x00CA
- final val CEE_UNUSED63 : Int = 0x00CB
- final val CEE_UNUSED64 : Int = 0x00CC
- final val CEE_UNUSED65 : Int = 0x00CD
- final val CEE_UNUSED66 : Int = 0x00CE
- final val CEE_UNUSED67 : Int = 0x00CF
- final val CEE_LDTOKEN : Int = 0x00D0
- final val CEE_CONV_U2 : Int = 0x00D1
- final val CEE_CONV_U1 : Int = 0x00D2
- final val CEE_CONV_I : Int = 0x00D3
- final val CEE_CONV_OVF_I : Int = 0x00D4
- final val CEE_CONV_OVF_U : Int = 0x00D5
- final val CEE_ADD_OVF : Int = 0x00D6
- final val CEE_ADD_OVF_UN : Int = 0x00D7
- final val CEE_MUL_OVF : Int = 0x00D8
- final val CEE_MUL_OVF_UN : Int = 0x00D9
- final val CEE_SUB_OVF : Int = 0x00DA
- final val CEE_SUB_OVF_UN : Int = 0x00DB
- final val CEE_ENDFINALLY : Int = 0x00DC
- final val CEE_LEAVE : Int = 0x00DD
- final val CEE_LEAVE_S : Int = 0x00DE
- final val CEE_STIND_I : Int = 0x00DF
- final val CEE_CONV_U : Int = 0x00E0
- final val CEE_UNUSED26 : Int = 0x00E1
- final val CEE_UNUSED27 : Int = 0x00E2
- final val CEE_UNUSED28 : Int = 0x00E3
- final val CEE_UNUSED29 : Int = 0x00E4
- final val CEE_UNUSED30 : Int = 0x00E5
- final val CEE_UNUSED31 : Int = 0x00E6
- final val CEE_UNUSED32 : Int = 0x00E7
- final val CEE_UNUSED33 : Int = 0x00E8
- final val CEE_UNUSED34 : Int = 0x00E9
- final val CEE_UNUSED35 : Int = 0x00EA
- final val CEE_UNUSED36 : Int = 0x00EB
- final val CEE_UNUSED37 : Int = 0x00EC
- final val CEE_UNUSED38 : Int = 0x00ED
- final val CEE_UNUSED39 : Int = 0x00EE
- final val CEE_UNUSED40 : Int = 0x00EF
- final val CEE_UNUSED41 : Int = 0x00F0
- final val CEE_UNUSED42 : Int = 0x00F1
- final val CEE_UNUSED43 : Int = 0x00F2
- final val CEE_UNUSED44 : Int = 0x00F3
- final val CEE_UNUSED45 : Int = 0x00F4
- final val CEE_UNUSED46 : Int = 0x00F5
- final val CEE_UNUSED47 : Int = 0x00F6
- final val CEE_UNUSED48 : Int = 0x00F7
- final val CEE_PREFIX7 : Int = 0x00F8
- final val CEE_PREFIX6 : Int = 0x00F9
- final val CEE_PREFIX5 : Int = 0x00FA
- final val CEE_PREFIX4 : Int = 0x00FB
- final val CEE_PREFIX3 : Int = 0x00FC
- final val CEE_PREFIX2 : Int = 0x00FD
- final val CEE_PREFIX1 : Int = 0x00FE
- final val CEE_PREFIXREF : Int = 0x00FF
-
- final val CEE_ARGLIST : Int = 0x0100
- final val CEE_CEQ : Int = 0x0101
- final val CEE_CGT : Int = 0x0102
- final val CEE_CGT_UN : Int = 0x0103
- final val CEE_CLT : Int = 0x0104
- final val CEE_CLT_UN : Int = 0x0105
- final val CEE_LDFTN : Int = 0x0106
- final val CEE_LDVIRTFTN : Int = 0x0107
- final val CEE_UNUSED56 : Int = 0x0108
- final val CEE_LDARG : Int = 0x0109
- final val CEE_LDARGA : Int = 0x010A
- final val CEE_STARG : Int = 0x010B
- final val CEE_LDLOC : Int = 0x010C
- final val CEE_LDLOCA : Int = 0x010D
- final val CEE_STLOC : Int = 0x010E
- final val CEE_LOCALLOC : Int = 0x010F
- final val CEE_UNUSED57 : Int = 0x0110
- final val CEE_ENDFILTER : Int = 0x0111
- final val CEE_UNALIGNED : Int = 0x0112
- final val CEE_VOLATILE : Int = 0x0113
- final val CEE_TAILCALL : Int = 0x0114
- final val CEE_INITOBJ : Int = 0x0115
- final val CEE_CONSTRAINED : Int = 0xFE16
- final val CEE_READONLY : Int = 0xFE1E
- final val CEE_UNUSED68 : Int = 0x0116
- final val CEE_CPBLK : Int = 0x0117
- final val CEE_INITBLK : Int = 0x0118
- final val CEE_UNUSED69 : Int = 0x0119
- final val CEE_RETHROW : Int = 0x011A
- final val CEE_UNUSED51 : Int = 0x011B
- final val CEE_SIZEOF : Int = 0x011C
- final val CEE_REFANYTYPE : Int = 0x011D
- final val CEE_UNUSED52 : Int = 0x011E
- final val CEE_UNUSED53 : Int = 0x011F
- final val CEE_UNUSED54 : Int = 0x0120
- final val CEE_UNUSED55 : Int = 0x0121
- final val CEE_UNUSED70 : Int = 0x0122
-
- final val CEE_ILLEGAL : Int = 0x0140
- final val CEE_MACRO_END : Int = 0x0141
-
- final val CEE_BRNULL : Int = 0x0180 // CEE_BRFALSE
- final val CEE_BRNULL_S : Int = 0x0181 // CEE_BRFALSE_S
- final val CEE_BRZERO : Int = 0x0182 // CEE_BRFALSE
- final val CEE_BRZERO_S : Int = 0x0183 // CEE_BRFALSE_S
- final val CEE_BRINST : Int = 0x0184 // CEE_BRTRUE
- final val CEE_BRINST_S : Int = 0x0185 // CEE_BRTRUE_S
- final val CEE_LDIND_U8 : Int = 0x0186 // CEE_LDIND_I8
- final val CEE_LDELEM_U8 : Int = 0x0187 // CEE_LDELEM_I8
- final val CEE_LDC_I4_M1x : Int = 0x0188 // CEE_LDC_I4_M1
- final val CEE_ENDFAULT : Int = 0x0189 // CEE_ENDFINALLY
-
- final val CEE_BRNONZERO : Int = 0x01C0 // CEE_BRTRUE
- final val CEE_BRNONZERO_S : Int = 0x01C1 // CEE_BRTRUE_S
-
- final val CEE_BRNOT : Int = 0x01C2
- final val CEE_BRNOT_S : Int = 0x01C3
- final val CEE_NOCODE : Int = 0x01C4
-
- final val CEE_count : Int = 0x0200
-
-
- //########################################################################
- // Opcode's amount and type of poped data
-
- final val POP_NONE : Byte = 0x00
- final val POP_1 : Byte = 0x01
- final val POP_1_1 : Byte = 0x02
- final val POP_I : Byte = 0x03
- final val POP_I_1 : Byte = 0x04
- final val POP_I_I : Byte = 0x05
- final val POP_I_I8 : Byte = 0x06
- final val POP_I_R4 : Byte = 0x07
- final val POP_I_R8 : Byte = 0x08
- final val POP_I_I_I : Byte = 0x09
- final val POP_REF : Byte = 0x0A
- final val POP_REF_1 : Byte = 0x0B
- final val POP_REF_I : Byte = 0x0C
- final val POP_REF_I_I : Byte = 0x0D
- final val POP_REF_I_I8 : Byte = 0x0E
- final val POP_REF_I_R4 : Byte = 0x0F
- final val POP_REF_I_R8 : Byte = 0x10
- final val POP_REF_I_REF : Byte = 0x11
- final val POP_SPECIAL : Byte = 0x12
- final val POP_count : Int = 0x13
- final val POP_size : Array[Byte] = new Array[Byte](POP_count)
-
- POP_size(POP_NONE) = 0
- POP_size(POP_1) = 1
- POP_size(POP_1_1) = 2
- POP_size(POP_I) = 1
- POP_size(POP_I_1) = 2
- POP_size(POP_I_I) = 2
- POP_size(POP_I_I8) = 2
- POP_size(POP_I_R4) = 2
- POP_size(POP_I_R8) = 2
- POP_size(POP_I_I_I) = 3
- POP_size(POP_REF) = 1
- POP_size(POP_REF_1) = 2
- POP_size(POP_REF_I) = 2
- POP_size(POP_REF_I_I) = 3
- POP_size(POP_REF_I_I8) = 3
- POP_size(POP_REF_I_R4) = 3
- POP_size(POP_REF_I_R8) = 3
- POP_size(POP_REF_I_REF) = 3
- POP_size(POP_SPECIAL) = -1
-
- //########################################################################
- // Opcode's amount and type of pushed data
-
- final val PUSH_NONE : Byte = 0x00
- final val PUSH_1 : Byte = 0x01
- final val PUSH_1_1 : Byte = 0x02
- final val PUSH_I : Byte = 0x03
- final val PUSH_I8 : Byte = 0x04
- final val PUSH_R4 : Byte = 0x05
- final val PUSH_R8 : Byte = 0x06
- final val PUSH_REF : Byte = 0x07
- final val PUSH_SPECIAL : Byte = 0x08
- final val PUSH_count : Int = 0x09
- final val PUSH_size : Array[Byte] = new Array[Byte](PUSH_count)
-
- PUSH_size(PUSH_NONE) = 0
- PUSH_size(PUSH_1) = 1
- PUSH_size(PUSH_1_1) = 2
- PUSH_size(PUSH_I) = 1
- PUSH_size(PUSH_I8) = 1
- PUSH_size(PUSH_R4) = 1
- PUSH_size(PUSH_R8) = 1
- PUSH_size(PUSH_REF) = 1
- PUSH_size(PUSH_SPECIAL) = -1
-
- //########################################################################
- // Opcode's amount of moved data
-
- final val POPUSH_SPECIAL : Byte = -128
-
- //########################################################################
- // Opcode's inline argument types
-
- final val INLINE_NONE : Byte = 0x00
- final val INLINE_VARIABLE_S : Byte = 0x01
- final val INLINE_TARGET_S : Byte = 0x02
- final val INLINE_I_S : Byte = 0x03
- final val INLINE_VARIABLE : Byte = 0x04
- final val INLINE_TARGET : Byte = 0x05
- final val INLINE_I : Byte = 0x06
- final val INLINE_I8 : Byte = 0x07
- final val INLINE_R : Byte = 0x08
- final val INLINE_R8 : Byte = 0x09
- final val INLINE_STRING : Byte = 0x0A
- final val INLINE_TYPE : Byte = 0x0B
- final val INLINE_FIELD : Byte = 0x0C
- final val INLINE_METHOD : Byte = 0x0D
- final val INLINE_SIGNATURE : Byte = 0x0E
- final val INLINE_TOKEN : Byte = 0x0F
- final val INLINE_SWITCH : Byte = 0x10
- final val INLINE_count : Int = 0x11
- final val INLINE_length : Array[Byte] = new Array[Byte](INLINE_count)
-
- INLINE_length(INLINE_NONE) = 0
- INLINE_length(INLINE_VARIABLE_S) = 1
- INLINE_length(INLINE_TARGET_S) = 1
- INLINE_length(INLINE_I_S) = 1
- INLINE_length(INLINE_VARIABLE) = 2
- INLINE_length(INLINE_TARGET) = 4
- INLINE_length(INLINE_I) = 4
- INLINE_length(INLINE_I8) = 8
- INLINE_length(INLINE_R) = 4
- INLINE_length(INLINE_R8) = 8
- INLINE_length(INLINE_STRING) = 4
- INLINE_length(INLINE_TYPE) = 4
- INLINE_length(INLINE_FIELD) = 4
- INLINE_length(INLINE_METHOD) = 4
- INLINE_length(INLINE_SIGNATURE) = 4
- INLINE_length(INLINE_SWITCH) = 4
- INLINE_length(INLINE_TOKEN) = 4
-
- //########################################################################
- // Opcode's control flow implications
-
- final val FLOW_META : Byte = 0x00
- final val FLOW_NEXT : Byte = 0x01
- final val FLOW_BRANCH : Byte = 0x02
- final val FLOW_COND_BRANCH : Byte = 0x03
- final val FLOW_BREAK : Byte = 0x04
- final val FLOW_CALL : Byte = 0x05
- final val FLOW_RETURN : Byte = 0x06
- final val FLOW_THROW : Byte = 0x07
- final val FLOW_count : Int = 0x08
-
- //########################################################################
- // Init methods for Opcode
-
- def opcode(that: OpCode, opcode: Int, string: String, code: Int,
- pop: Byte, push: Byte, inline: Byte, flow: Byte) {
- that.CEE_opcode = opcode
- that.CEE_string = string
- that.CEE_code = code.toShort
- that.CEE_pop = pop
- that.CEE_push = push
- that.CEE_inline = inline
- that.CEE_flow = flow
- that.CEE_length = that.length()
- that.CEE_popush = that.popush()
- }
-
- def length(code: Int): Byte = {
- if ((code & 0xFFFFFF00) == 0xFFFFFF00) return 1
- if ((code & 0xFFFFFF00) == 0xFFFFFE00) return 2
- return 0
- }
-
- //########################################################################
- // case OpCode
-
- /**
- * Adds two values and pushes the result onto the evaluation stack.
- */
- final val Add = new OpCode()
- opcode(Add, CEE_ADD, "add", 0xFFFFFF58, POP_1_1, PUSH_1, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Fills space if bytecodes are patched. No meaningful operation is performed
- * although a processing cycle can be consumed.
- */
- final val Nop = new OpCode()
- opcode(Nop, CEE_NOP, "nop", 0xFFFFFF00, POP_NONE, PUSH_NONE, INLINE_NONE , FLOW_NEXT)
-
- /**
- * Signals the Common Language Infrastructure (CLI) to inform the debugger that
- * a break point has been tripped.
- */
- final val Break = new OpCode()
- opcode(Break, CEE_BREAK, "break" , 0xFFFFFF01, POP_NONE, PUSH_NONE , INLINE_NONE , FLOW_BREAK)
-
- /**
- * Loads the argument at index 0 onto the evaluation stack.
- */
- final val Ldarg_0 = new OpCode()
- opcode(Ldarg_0, CEE_LDARG_0 , "ldarg.0" , 0xFFFFFF02, POP_NONE, PUSH_1 , INLINE_NONE , FLOW_NEXT)
-
- /**
- * Loads the argument at index 1 onto the evaluation stack.
- */
- final val Ldarg_1 = new OpCode()
- opcode(Ldarg_1, CEE_LDARG_1 , "ldarg.1" , 0xFFFFFF03, POP_NONE, PUSH_1 , INLINE_NONE , FLOW_NEXT)
-
- /**
- * Loads the argument at index 2 onto the evaluation stack.
- */
- final val Ldarg_2 = new OpCode()
- opcode(Ldarg_2, CEE_LDARG_2 , "ldarg.2" , 0xFFFFFF04, POP_NONE, PUSH_1 , INLINE_NONE , FLOW_NEXT)
-
- /**
- * Loads the argument at index 3 onto the evaluation stack.
- */
- final val Ldarg_3 = new OpCode()
- opcode(Ldarg_3, CEE_LDARG_3 , "ldarg.3" , 0xFFFFFF05, POP_NONE, PUSH_1 , INLINE_NONE , FLOW_NEXT)
-
- /**
- * Loads the local variable at index 0 onto the evaluation stack.
- */
- final val Ldloc_0 = new OpCode()
- opcode(Ldloc_0, CEE_LDLOC_0 , "ldloc.0" , 0xFFFFFF06, POP_NONE, PUSH_1 , INLINE_NONE , FLOW_NEXT)
-
- /**
- * Loads the local variable at index 1 onto the evaluation stack.
- */
- final val Ldloc_1 = new OpCode()
- opcode(Ldloc_1, CEE_LDLOC_1 , "ldloc.1" , 0xFFFFFF07, POP_NONE, PUSH_1 , INLINE_NONE , FLOW_NEXT)
-
- /**
- * Loads the local variable at index 2 onto the evaluation stack.
- */
- final val Ldloc_2 = new OpCode()
- opcode(Ldloc_2, CEE_LDLOC_2 , "ldloc.2" , 0xFFFFFF08, POP_NONE, PUSH_1 , INLINE_NONE , FLOW_NEXT)
-
- /**
- * Loads the local variable at index 3 onto the evaluation stack.
- */
- final val Ldloc_3 = new OpCode()
- opcode(Ldloc_3, CEE_LDLOC_3 , "ldloc.3" , 0xFFFFFF09, POP_NONE, PUSH_1 , INLINE_NONE , FLOW_NEXT)
-
- /**
- * Pops the current value from the top of the evaluation stack and
- * stores it in a the local variable list at index 0.
- */
- final val Stloc_0 = new OpCode()
- opcode(Stloc_0, CEE_STLOC_0 , "stloc.0" , 0xFFFFFF0A, POP_1 , PUSH_NONE, INLINE_NONE , FLOW_NEXT)
-
- /**
- * Pops the current value from the top of the evaluation stack and
- * stores it in a the local variable list at index 1.
- */
- final val Stloc_1 = new OpCode()
- opcode(Stloc_1, CEE_STLOC_1 , "stloc.1" , 0xFFFFFF0B, POP_1 , PUSH_NONE, INLINE_NONE , FLOW_NEXT)
-
- /**
- * Pops the current value from the top of the evaluation stack and
- * stores it in a the local variable list at index 2.
- */
- final val Stloc_2 = new OpCode()
- opcode(Stloc_2, CEE_STLOC_2 , "stloc.2" , 0xFFFFFF0C, POP_1 , PUSH_NONE, INLINE_NONE , FLOW_NEXT)
-
- /**
- * Pops the current value from the top of the evaluation stack and
- * stores it in a the local variable list at index 3.
- */
- final val Stloc_3 = new OpCode()
- opcode(Stloc_3, CEE_STLOC_3 , "stloc.3" , 0xFFFFFF0D, POP_1 , PUSH_NONE, INLINE_NONE , FLOW_NEXT)
-
- /**
- * Loads the argument (referenced by a specified short form index)
- * onto the evaluation stack.
- */
- final val Ldarg_S = new OpCode()
- opcode(Ldarg_S, CEE_LDARG_S , "ldarg.s" , 0xFFFFFF0E, POP_NONE, PUSH_1 , INLINE_VARIABLE_S, FLOW_NEXT)
-
- /**
- * Load an argument address, in short form, onto the evaluation stack.
- */
- final val Ldarga_S = new OpCode()
- opcode(Ldarga_S, CEE_LDARGA_S , "ldarga.s" , 0xFFFFFF0F, POP_NONE, PUSH_I , INLINE_VARIABLE_S, FLOW_NEXT)
-
- /**
- * Loads the local variable at a specific index onto the evaluation stack,
- * short form.
- */
- final val Ldloc_S = new OpCode()
- opcode(Ldloc_S, CEE_LDLOC_S , "ldloc.s" , 0xFFFFFF11, POP_NONE, PUSH_1 , INLINE_VARIABLE_S, FLOW_NEXT)
-
- /**
- * Loads the address of the local variable at a specific index onto
- * the evaluation stack, short form.
- */
- final val Ldloca_S = new OpCode()
- opcode(Ldloca_S, CEE_LDLOCA_S , "ldloca.s" , 0xFFFFFF12, POP_NONE, PUSH_I , INLINE_VARIABLE_S, FLOW_NEXT)
-
- /**
- * Stores the value on top of the evaluation stack in the argument slot
- * at a specified index, short form.
- */
- final val Starg_S = new OpCode()
- opcode(Starg_S, CEE_STARG_S , "starg.s" , 0xFFFFFF10, POP_1 , PUSH_NONE , INLINE_VARIABLE_S, FLOW_NEXT)
-
- /**
- * Pops the current value from the top of the evaluation stack and stores it
- * in a the local variable list at index (short form).
- */
- final val Stloc_S = new OpCode()
- opcode(Stloc_S, CEE_STLOC_S , "stloc.s" , 0xFFFFFF13, POP_1 , PUSH_NONE, INLINE_VARIABLE_S, FLOW_NEXT)
-
- /**
- * Pushes a null reference (type O) onto the evaluation stack.
- */
- final val Ldnull = new OpCode()
- opcode(Ldnull, CEE_LDNULL , "ldnull" , 0xFFFFFF14, POP_NONE, PUSH_REF , INLINE_NONE, FLOW_NEXT)
-
- /**
- * Pushes the integer value of -1 onto the evaluation stack as an int32.
- */
- final val Ldc_I4_M1 = new OpCode()
- opcode(Ldc_I4_M1, CEE_LDC_I4_M1, "ldc.i4.m1", 0xFFFFFF15, POP_NONE, PUSH_I, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Pushes the integer value of 0 onto the evaluation stack as an int32.
- */
- final val Ldc_I4_0 = new OpCode()
- opcode(Ldc_I4_0, CEE_LDC_I4_0 , "ldc.i4.0" , 0xFFFFFF16, POP_NONE, PUSH_I, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Pushes the integer value of 1 onto the evaluation stack as an int32.
- */
- final val Ldc_I4_1 = new OpCode()
- opcode(Ldc_I4_1, CEE_LDC_I4_1 , "ldc.i4.1" , 0xFFFFFF17, POP_NONE, PUSH_I, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Pushes the integer value of 2 onto the evaluation stack as an int32.
- */
- final val Ldc_I4_2 = new OpCode()
- opcode(Ldc_I4_2, CEE_LDC_I4_2 , "ldc.i4.2" , 0xFFFFFF18, POP_NONE, PUSH_I, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Pushes the integer value of 3 onto the evaluation stack as an int32.
- */
- final val Ldc_I4_3 = new OpCode()
- opcode(Ldc_I4_3, CEE_LDC_I4_3 , "ldc.i4.3" , 0xFFFFFF19, POP_NONE, PUSH_I, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Pushes the integer value of 4 onto the evaluation stack as an int32.
- */
- final val Ldc_I4_4 = new OpCode()
- opcode(Ldc_I4_4, CEE_LDC_I4_4 , "ldc.i4.4" , 0xFFFFFF1A, POP_NONE, PUSH_I, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Pushes the integer value of 5 onto the evaluation stack as an int32.
- */
- final val Ldc_I4_5 = new OpCode()
- opcode(Ldc_I4_5, CEE_LDC_I4_5 , "ldc.i4.5" , 0xFFFFFF1B, POP_NONE, PUSH_I, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Pushes the integer value of 6 onto the evaluation stack as an int32.
- */
- final val Ldc_I4_6 = new OpCode()
- opcode(Ldc_I4_6, CEE_LDC_I4_6 , "ldc.i4.6", 0xFFFFFF1C, POP_NONE, PUSH_I, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Pushes the integer value of 7 onto the evaluation stack as an int32.
- */
- final val Ldc_I4_7 = new OpCode()
- opcode(Ldc_I4_7, CEE_LDC_I4_7 , "ldc.i4.7", 0xFFFFFF1D, POP_NONE , PUSH_I, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Pushes the integer value of 8 onto the evaluation stack as an int32.
- */
- final val Ldc_I4_8 = new OpCode()
- opcode(Ldc_I4_8, CEE_LDC_I4_8 , "ldc.i4.8", 0xFFFFFF1E, POP_NONE , PUSH_I, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Pushes the supplied int8 value onto the evaluation stack as an int32, short form.
- */
- final val Ldc_I4_S = new OpCode()
- opcode(Ldc_I4_S, CEE_LDC_I4_S , "ldc.i4.s", 0xFFFFFF1F, POP_NONE , PUSH_I, INLINE_I_S, FLOW_NEXT)
-
- /**
- * Pushes a supplied value of type int32 onto the evaluation stack as an int32.
- */
- final val Ldc_I4 = new OpCode()
- opcode(Ldc_I4, CEE_LDC_I4, "ldc.i4" , 0xFFFFFF20, POP_NONE , PUSH_I, INLINE_I , FLOW_NEXT)
-
- /**
- * Pushes a supplied value of type int64 onto the evaluation stack as an int64.
- */
- final val Ldc_I8 = new OpCode()
- opcode(Ldc_I8, CEE_LDC_I8, "ldc.i8" , 0xFFFFFF21, POP_NONE , PUSH_I8, INLINE_I8 , FLOW_NEXT)
-
- /**
- * Pushes a supplied value of type float32 onto the evaluation stack as type F (float).
- */
- final val Ldc_R4 = new OpCode()
- opcode(Ldc_R4, CEE_LDC_R4, "ldc.r4" , 0xFFFFFF22, POP_NONE , PUSH_R4, INLINE_R , FLOW_NEXT)
-
- /**
- * Pushes a supplied value of type float64 onto the evaluation stack as type F (float).
- */
- final val Ldc_R8 = new OpCode()
- opcode(Ldc_R8, CEE_LDC_R8, "ldc.r8" , 0xFFFFFF23, POP_NONE , PUSH_R8, INLINE_R8 , FLOW_NEXT)
-
- /**
- * Copies the current topmost value on the evaluation stack, and then pushes the copy
- * onto the evaluation stack.
- */
- final val Dup = new OpCode()
- opcode(Dup, CEE_DUP , "dup" , 0xFFFFFF25, POP_1 , PUSH_1_1 , INLINE_NONE , FLOW_NEXT)
-
- /**
- * Removes the value currently on top of the evaluation stack.
- */
- final val Pop = new OpCode()
- opcode(Pop, CEE_POP , "pop" , 0xFFFFFF26, POP_1 , PUSH_NONE , INLINE_NONE , FLOW_NEXT)
-
- /**
- * Exits current method and jumps to specified method.
- */
- final val Jmp = new OpCode()
- opcode(Jmp, CEE_JMP , "jmp" , 0xFFFFFF27, POP_NONE , PUSH_NONE , INLINE_METHOD, FLOW_CALL)
-
- /**
- * Calls the method indicated by the passed method descriptor.
- */
- final val Call = new OpCode()
- opcode(Call, CEE_CALL , "call" , 0xFFFFFF28, POP_SPECIAL, PUSH_SPECIAL, INLINE_METHOD , FLOW_CALL)
-
- /**
- * constrained prefix
- */
- final val Constrained = new OpCode()
-opcode(Constrained, CEE_CONSTRAINED , "constrained." , 0xFFFFFE16, POP_NONE, PUSH_NONE, INLINE_NONE , FLOW_NEXT)
-
- /**
- * readonly prefix
- */
- final val Readonly = new OpCode()
-opcode(Readonly, CEE_READONLY , "readonly." , 0xFFFFFE1E, POP_NONE, PUSH_NONE, INLINE_NONE , FLOW_NEXT)
-
- /**
- * Calls the method indicated on the evaluation stack (as a pointer to an entry point)
- * with arguments described by a calling convention.
- */
- final val Calli = new OpCode()
- opcode(Calli, CEE_CALLI, "calli" , 0xFFFFFF29, POP_SPECIAL, PUSH_SPECIAL, INLINE_SIGNATURE , FLOW_CALL)
-
- /**
- * Returns from the current method, pushing a return value (if present) from the caller's
- * evaluation stack onto the callee's evaluation stack.
- */
- final val Ret = new OpCode()
- opcode(Ret, CEE_RET , "ret" , 0xFFFFFF2A, POP_SPECIAL, PUSH_NONE, INLINE_NONE , FLOW_RETURN)
-
- /**
- * Unconditionally transfers control to a target instruction (short form).
- */
- final val Br_S = new OpCode()
- opcode(Br_S, CEE_BR_S , "br.s" , 0xFFFFFF2B, POP_NONE, PUSH_NONE, INLINE_TARGET_S , FLOW_BRANCH)
-
- /**
- * Transfers control to a target instruction if value is false, a null reference, or zero.
- */
- final val Brfalse_S = new OpCode()
- opcode(Brfalse_S, CEE_BRFALSE_S,"brfalse.s", 0xFFFFFF2C, POP_I, PUSH_NONE, INLINE_TARGET_S, FLOW_COND_BRANCH)
-
- /**
- * Transfers control to a target instruction (short form) if value is true, not null, or non-zero.
- */
- final val Brtrue_S = new OpCode()
- opcode(Brtrue_S, CEE_BRTRUE_S , "brtrue.s", 0xFFFFFF2D, POP_I, PUSH_NONE, INLINE_TARGET_S, FLOW_COND_BRANCH)
-
- /**
- * Transfers control to a target instruction (short form) if two values are equal.
- */
- final val Beq_S = new OpCode()
- opcode(Beq_S, CEE_BEQ_S, "beq.s", 0xFFFFFF2E, POP_1_1 , PUSH_NONE, INLINE_TARGET_S , FLOW_COND_BRANCH)
-
- /**
- * Transfers control to a target instruction (short form) if the first value is greater than
- * or equal to the second value.
- */
- final val Bge_S = new OpCode()
- opcode(Bge_S, CEE_BGE_S, "bge.s", 0xFFFFFF2F, POP_1_1 , PUSH_NONE, INLINE_TARGET_S, FLOW_COND_BRANCH)
-
- /**
- * Transfers control to a target instruction (short form) if the first value is greater than
- * the second value.
- */
- final val Bgt_S = new OpCode()
- opcode(Bgt_S, CEE_BGT_S, "bgt.s" , 0xFFFFFF30, POP_1_1 , PUSH_NONE, INLINE_TARGET_S , FLOW_COND_BRANCH)
-
- /**
- * Transfers control to a target instruction (short form) if the first value is less than
- * or equal to the second value.
- */
- final val Ble_S = new OpCode()
- opcode(Ble_S, CEE_BLE_S, "ble.s" , 0xFFFFFF31, POP_1_1 , PUSH_NONE, INLINE_TARGET_S , FLOW_COND_BRANCH)
-
- /**
- * Transfers control to a target instruction (short form) if the first value is less than
- * the second value.
- */
- final val Blt_S = new OpCode()
- opcode(Blt_S, CEE_BLT_S, "blt.s", 0xFFFFFF32, POP_1_1, PUSH_NONE, INLINE_TARGET_S, FLOW_COND_BRANCH)
-
- /**
- * Transfers control to a target instruction (short form) when two unsigned integer values
- * or unordered float values are not equal.
- */
- final val Bne_Un_S = new OpCode()
- opcode(Bne_Un_S, CEE_BNE_UN_S, "bne.un.s", 0xFFFFFF33, POP_1_1 , PUSH_NONE, INLINE_TARGET_S, FLOW_COND_BRANCH)
-
- /**
- * Transfers control to a target instruction (short form) if the first value is greather
- * than the second value, when comparing unsigned integer values or unordered float values.
- */
- final val Bge_Un_S = new OpCode()
- opcode(Bge_Un_S, CEE_BGE_UN_S, "bge.un.s", 0xFFFFFF34, POP_1_1, PUSH_NONE, INLINE_TARGET_S, FLOW_COND_BRANCH)
-
- /**
- * Transfers control to a target instruction (short form) if the first value is greater than
- * the second value, when comparing unsigned integer values or unordered float values.
- */
- final val Bgt_Un_S = new OpCode()
- opcode(Bgt_Un_S, CEE_BGT_UN_S, "bgt.un.s", 0xFFFFFF35, POP_1_1, PUSH_NONE, INLINE_TARGET_S, FLOW_COND_BRANCH)
-
- /**
- * Transfers control to a target instruction (short form) if the first value is less than
- * or equal to the second value, when comparing unsigned integer values or unordered float values.
- */
- final val Ble_Un_S = new OpCode()
- opcode(Ble_Un_S, CEE_BLE_UN_S , "ble.un.s", 0xFFFFFF36, POP_1_1, PUSH_NONE, INLINE_TARGET_S, FLOW_COND_BRANCH)
-
- /**
- * Transfers control to a target instruction (short form) if the first value is less than
- * the second value, when comparing unsigned integer values or unordered float values.
- */
- final val Blt_Un_S = new OpCode()
- opcode(Blt_Un_S, CEE_BLT_UN_S, "blt.un.s", 0xFFFFFF37, POP_1_1, PUSH_NONE, INLINE_TARGET_S, FLOW_COND_BRANCH)
-
- /**
- * Unconditionally transfers control to a target instruction.
- */
- final val Br = new OpCode()
- opcode(Br, CEE_BR , "br" , 0xFFFFFF38, POP_NONE, PUSH_NONE, INLINE_TARGET, FLOW_BRANCH)
-
- /**
- * Transfers control to a target instruction if value is false, a null reference
- * (Nothing in Visual Basic), or zero.
- */
- final val Brfalse = new OpCode()
- opcode(Brfalse, CEE_BRFALSE, "brfalse", 0xFFFFFF39, POP_I, PUSH_NONE, INLINE_TARGET, FLOW_COND_BRANCH)
-
- /**
- * Transfers control to a target instruction if value is true, not null, or non-zero.
- */
- final val Brtrue = new OpCode()
- opcode(Brtrue, CEE_BRTRUE , "brtrue", 0xFFFFFF3A, POP_I , PUSH_NONE, INLINE_TARGET, FLOW_COND_BRANCH)
-
- /**
- * Transfers control to a target instruction if two values are equal.
- */
- final val Beq = new OpCode()
- opcode(Beq, CEE_BEQ, "beq", 0xFFFFFF3B, POP_1_1 , PUSH_NONE, INLINE_TARGET, FLOW_COND_BRANCH)
-
- /**
- * Transfers control to a target instruction if the first value is greater than or
- * equal to the second value.
- */
- final val Bge = new OpCode()
- opcode(Bge, CEE_BGE, "bge", 0xFFFFFF3C, POP_1_1 , PUSH_NONE, INLINE_TARGET, FLOW_COND_BRANCH)
-
- /**
- * Transfers control to a target instruction if the first value is greater than the second value.
- */
- final val Bgt = new OpCode()
- opcode(Bgt, CEE_BGT, "bgt", 0xFFFFFF3D, POP_1_1 , PUSH_NONE, INLINE_TARGET, FLOW_COND_BRANCH)
-
- /**
- * Transfers control to a target instruction if the first value is less than or equal
- * to the second value.
- */
- final val Ble = new OpCode()
- opcode(Ble, CEE_BLE, "ble", 0xFFFFFF3E, POP_1_1 , PUSH_NONE, INLINE_TARGET, FLOW_COND_BRANCH)
-
- /**
- * Transfers control to a target instruction if the first value is less than the second value.
- */
- final val Blt = new OpCode()
- opcode(Blt, CEE_BLT, "blt", 0xFFFFFF3F, POP_1_1 , PUSH_NONE, INLINE_TARGET, FLOW_COND_BRANCH)
-
- /**
- * Transfers control to a target instruction when two unsigned integer values or
- * unordered float values are not equal.
- */
- final val Bne_Un = new OpCode()
- opcode(Bne_Un, CEE_BNE_UN , "bne.un", 0xFFFFFF40, POP_1_1 , PUSH_NONE, INLINE_TARGET, FLOW_COND_BRANCH)
-
- /**
- * Transfers control to a target instruction if the first value is greather than
- * the second value, when comparing unsigned integer values or unordered float values.
- */
- final val Bge_Un = new OpCode()
- opcode(Bge_Un, CEE_BGE_UN , "bge.un", 0xFFFFFF41, POP_1_1 , PUSH_NONE, INLINE_TARGET, FLOW_COND_BRANCH)
-
- /**
- * Transfers control to a target instruction if the first value is greater than the
- * second value, when comparing unsigned integer values or unordered float values.
- */
- final val Bgt_Un = new OpCode()
- opcode(Bgt_Un, CEE_BGT_UN , "bgt.un", 0xFFFFFF42, POP_1_1 , PUSH_NONE, INLINE_TARGET, FLOW_COND_BRANCH)
-
- /**
- * Transfers control to a target instruction if the first value is less than or equal to
- * the second value, when comparing unsigned integer values or unordered float values.
- */
- final val Ble_Un = new OpCode()
- opcode(Ble_Un, CEE_BLE_UN , "ble.un" , 0xFFFFFF43, POP_1_1 , PUSH_NONE, INLINE_TARGET, FLOW_COND_BRANCH)
-
- /**
- * Transfers control to a target instruction if the first value is less than the second value,
- * when comparing unsigned integer values or unordered float values.
- */
- final val Blt_Un = new OpCode()
- opcode(Blt_Un, CEE_BLT_UN , "blt.un", 0xFFFFFF44, POP_1_1 , PUSH_NONE, INLINE_TARGET, FLOW_COND_BRANCH)
-
- /**
- * Implements a jump table.
- */
- final val Switch = new OpCode()
- opcode(Switch, CEE_SWITCH , "switch", 0xFFFFFF45, POP_I , PUSH_NONE, INLINE_SWITCH, FLOW_COND_BRANCH)
-
- /**
- * Loads a value of type int8 as an int32 onto the evaluation stack indirectly.
- */
- final val Ldind_I1 = new OpCode()
- opcode(Ldind_I1, CEE_LDIND_I1 , "ldind.i1" , 0xFFFFFF46, POP_I , PUSH_I , INLINE_NONE, FLOW_NEXT)
-
- /**
- * Loads a value of type int16 as an int32 onto the evaluation stack indirectly.
- */
- final val Ldind_I2 = new OpCode()
- opcode(Ldind_I2, CEE_LDIND_I2 , "ldind.i2" , 0xFFFFFF48, POP_I , PUSH_I , INLINE_NONE, FLOW_NEXT)
-
- /**
- * Loads a value of type int32 as an int32 onto the evaluation stack indirectly.
- */
- final val Ldind_I4 = new OpCode()
- opcode(Ldind_I4, CEE_LDIND_I4 , "ldind.i4" , 0xFFFFFF4A, POP_I , PUSH_I , INLINE_NONE, FLOW_NEXT)
-
- /**
- * Loads a value of type int64 as an int64 onto the evaluation stack indirectly.
- */
- final val Ldind_I8 = new OpCode()
- opcode(Ldind_I8, CEE_LDIND_I8 , "ldind.i8" , 0xFFFFFF4C, POP_I , PUSH_I8 , INLINE_NONE, FLOW_NEXT)
-
- /**
- * Loads a value of type natural int as a natural int onto the evaluation stack indirectly.
- */
- final val Ldind_I = new OpCode()
- opcode(Ldind_I, CEE_LDIND_I , "ldind.i" , 0xFFFFFF4D, POP_I , PUSH_I , INLINE_NONE, FLOW_NEXT)
-
- /**
- * Loads a value of type float32 as a type F (float) onto the evaluation stack indirectly.
- */
- final val Ldind_R4 = new OpCode()
- opcode(Ldind_R4, CEE_LDIND_R4 , "ldind.r4" , 0xFFFFFF4E, POP_I , PUSH_R4 , INLINE_NONE, FLOW_NEXT)
-
- /**
- * Loads a value of type float64 as a type F (float) onto the evaluation stack indirectly.
- */
- final val Ldind_R8 = new OpCode()
- opcode(Ldind_R8, CEE_LDIND_R8 , "ldind.r8" , 0xFFFFFF4F, POP_I , PUSH_R8 , INLINE_NONE, FLOW_NEXT)
-
- /**
- * Loads an object reference as a type O (object reference) onto the evaluation stack indirectly.
- */
- final val Ldind_Ref = new OpCode()
- opcode(Ldind_Ref, CEE_LDIND_REF, "ldind.ref", 0xFFFFFF50, POP_I , PUSH_REF, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Loads a value of type unsigned int8 as an int32 onto the evaluation stack indirectly.
- */
- final val Ldind_U1 = new OpCode()
- opcode(Ldind_U1, CEE_LDIND_U1 , "ldind.u1" , 0xFFFFFF47, POP_I , PUSH_I , INLINE_NONE, FLOW_NEXT)
-
- /**
- * Loads a value of type unsigned int16 as an int32 onto the evaluation stack indirectly.
- */
- final val Ldind_U2 = new OpCode()
- opcode(Ldind_U2, CEE_LDIND_U2 , "ldind.u2" , 0xFFFFFF49, POP_I , PUSH_I , INLINE_NONE, FLOW_NEXT)
-
- /**
- * Loads a value of type unsigned int32 as an int32 onto the evaluation stack indirectly.
- */
- final val Ldind_U4 = new OpCode()
- opcode(Ldind_U4, CEE_LDIND_U4 , "ldind.u4" , 0xFFFFFF4B, POP_I , PUSH_I , INLINE_NONE, FLOW_NEXT)
-
- /**
- * Stores a object reference value at a supplied address.
- */
- final val Stind_Ref = new OpCode()
- opcode(Stind_Ref, CEE_STIND_REF, "stind.ref", 0xFFFFFF51, POP_I_I , PUSH_NONE, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Stores a value of type int8 at a supplied address.
- */
- final val Stind_I1 = new OpCode()
- opcode(Stind_I1, CEE_STIND_I1 , "stind.i1", 0xFFFFFF52, POP_I_I , PUSH_NONE, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Stores a value of type int16 at a supplied address.
- */
- final val Stind_I2 = new OpCode()
- opcode(Stind_I2, CEE_STIND_I2 , "stind.i2", 0xFFFFFF53, POP_I_I , PUSH_NONE, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Stores a value of type int32 at a supplied address.
- */
- final val Stind_I4 = new OpCode()
- opcode(Stind_I4, CEE_STIND_I4 , "stind.i4", 0xFFFFFF54, POP_I_I , PUSH_NONE, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Stores a value of type int64 at a supplied address.
- */
- final val Stind_I8 = new OpCode()
- opcode(Stind_I8, CEE_STIND_I8 , "stind.i8", 0xFFFFFF55, POP_I_I8, PUSH_NONE, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Stores a value of type float32 at a supplied address.
- */
- final val Stind_R4 = new OpCode()
- opcode(Stind_R4, CEE_STIND_R4 , "stind.r4", 0xFFFFFF56, POP_I_R4, PUSH_NONE, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Stores a value of type float64 at a supplied address.
- */
- final val Stind_R8 = new OpCode()
- opcode(Stind_R8, CEE_STIND_R8 , "stind.r8", 0xFFFFFF57, POP_I_R8, PUSH_NONE, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Subtracts one value from another and pushes the result onto the evaluation stack.
- */
- final val Sub = new OpCode()
- opcode(Sub, CEE_SUB, "sub" , 0xFFFFFF59, POP_1_1, PUSH_1 , INLINE_NONE, FLOW_NEXT)
-
- /**
- * Multiplies two values and pushes the result on the evaluation stack.
- */
- final val Mul = new OpCode()
- opcode(Mul, CEE_MUL, "mul" , 0xFFFFFF5A, POP_1_1, PUSH_1 , INLINE_NONE, FLOW_NEXT)
-
- /**
- * Divides two values and pushes the result as a floating-point (type F) or
- * quotient (type int32) onto the evaluation stack.
- */
- final val Div = new OpCode()
- opcode(Div, CEE_DIV, "div" , 0xFFFFFF5B, POP_1_1, PUSH_1 , INLINE_NONE, FLOW_NEXT)
-
- /**
- * Divides two unsigned integer values and pushes the result (int32) onto the evaluation stack.
- */
- final val Div_Un = new OpCode()
- opcode(Div_Un, CEE_DIV_UN, "div.un" , 0xFFFFFF5C, POP_1_1, PUSH_1 , INLINE_NONE, FLOW_NEXT)
-
- /**
- * Divides two values and pushes the remainder onto the evaluation stack.
- */
- final val Rem = new OpCode()
- opcode(Rem, CEE_REM , "rem" , 0xFFFFFF5D, POP_1_1, PUSH_1 , INLINE_NONE, FLOW_NEXT)
-
- /**
- * Divides two unsigned values and pushes the remainder onto the evaluation stack.
- */
- final val Rem_Un = new OpCode()
- opcode(Rem_Un, CEE_REM_UN, "rem.un" , 0xFFFFFF5E, POP_1_1, PUSH_1 , INLINE_NONE, FLOW_NEXT)
-
- /**
- * Computes the bitwise AND of two values and pushes the result onto the evaluation stack.
- */
- final val And = new OpCode()
- opcode(And, CEE_AND, "and" , 0xFFFFFF5F, POP_1_1, PUSH_1 , INLINE_NONE, FLOW_NEXT)
-
- /**
- * Compute the bitwise complement of the two integer values on top of the stack and
- * pushes the result onto the evaluation stack.
- */
- final val Or = new OpCode()
- opcode(Or, CEE_OR , "or" , 0xFFFFFF60, POP_1_1, PUSH_1 , INLINE_NONE, FLOW_NEXT)
-
- /**
- * Computes the bitwise XOR of the top two values on the evaluation stack,
- * pushing the result onto the evaluation stack.
- */
- final val Xor = new OpCode()
- opcode(Xor, CEE_XOR, "xor" , 0xFFFFFF61, POP_1_1, PUSH_1 , INLINE_NONE, FLOW_NEXT)
-
- /**
- * Shifts an integer value to the left (in zeroes) by a specified number of bits,
- * pushing the result onto the evaluation stack.
- */
- final val Shl = new OpCode()
- opcode(Shl, CEE_SHL, "shl" , 0xFFFFFF62, POP_1_1, PUSH_1 , INLINE_NONE, FLOW_NEXT)
-
- /**
- * Shifts an integer value (in sign) to the right by a specified number of bits,
- * pushing the result onto the evaluation stack.
- */
- final val Shr = new OpCode()
- opcode(Shr, CEE_SHR, "shr" , 0xFFFFFF63, POP_1_1, PUSH_1 , INLINE_NONE, FLOW_NEXT)
-
- /**
- * Shifts an unsigned integer value (in zeroes) to the right by a specified number of bits,
- * pushing the result onto the evaluation stack.
- */
- final val Shr_Un = new OpCode()
- opcode(Shr_Un, CEE_SHR_UN, "shr.un" , 0xFFFFFF64, POP_1_1, PUSH_1 , INLINE_NONE, FLOW_NEXT)
-
- /**
- * Negates a value and pushes the result onto the evaluation stack.
- */
- final val Neg = new OpCode()
- opcode(Neg, CEE_NEG , "neg" , 0xFFFFFF65, POP_1 , PUSH_1 , INLINE_NONE, FLOW_NEXT)
-
- /**
- * Computes the bitwise complement of the integer value on top of the stack and pushes
- * the result onto the evaluation stack as the same type.
- */
- final val Not = new OpCode()
- opcode(Not, CEE_NOT , "not" , 0xFFFFFF66, POP_1 , PUSH_1 , INLINE_NONE, FLOW_NEXT)
-
- /**
- * Converts the value on top of the evaluation stack to int8, then extends (pads) it to int32.
- */
- final val Conv_I1 = new OpCode()
- opcode(Conv_I1, CEE_CONV_I1, "conv.i1", 0xFFFFFF67, POP_1 , PUSH_I , INLINE_NONE, FLOW_NEXT)
-
- /**
- * Converts the value on top of the evaluation stack to int16, then extends (pads) it to int32.
- */
- final val Conv_I2 = new OpCode()
- opcode(Conv_I2, CEE_CONV_I2, "conv.i2", 0xFFFFFF68, POP_1 , PUSH_I , INLINE_NONE, FLOW_NEXT)
-
- /**
- * Converts the value on top of the evaluation stack to int32.
- */
- final val Conv_I4 = new OpCode()
- opcode(Conv_I4, CEE_CONV_I4, "conv.i4", 0xFFFFFF69, POP_1 , PUSH_I , INLINE_NONE, FLOW_NEXT)
-
- /**
- * Converts the value on top of the evaluation stack to int64.
- */
- final val Conv_I8 = new OpCode()
- opcode(Conv_I8, CEE_CONV_I8, "conv.i8", 0xFFFFFF6A, POP_1 , PUSH_I8, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Converts the value on top of the evaluation stack to float32.
- */
- final val Conv_R4 = new OpCode()
- opcode(Conv_R4, CEE_CONV_R4, "conv.r4", 0xFFFFFF6B, POP_1 , PUSH_R4, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Converts the value on top of the evaluation stack to float64.
- */
- final val Conv_R8 = new OpCode()
- opcode(Conv_R8, CEE_CONV_R8, "conv.r8", 0xFFFFFF6C, POP_1 , PUSH_R8, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Converts the value on top of the evaluation stack to unsigned int32, and extends it to int32.
- */
- final val Conv_U4 = new OpCode()
- opcode(Conv_U4, CEE_CONV_U4, "conv.u4", 0xFFFFFF6D, POP_1 , PUSH_I , INLINE_NONE, FLOW_NEXT)
-
- /**
- * Converts the value on top of the evaluation stack to unsigned int64, and extends it to int64.
- */
- final val Conv_U8 = new OpCode()
- opcode(Conv_U8, CEE_CONV_U8, "conv.u8", 0xFFFFFF6E, POP_1 , PUSH_I8, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Calls a late-bound method on an object, pushing the return value onto the evaluation stack.
- */
- final val Callvirt = new OpCode()
- opcode(Callvirt, CEE_CALLVIRT, "callvirt", 0xFFFFFF6F,POP_SPECIAL,PUSH_SPECIAL,INLINE_METHOD,FLOW_CALL)
-
- /**
- * Copies the value type located at the address of an object (type &, * or natural int)
- * to the address of the destination object (type &, * or natural int).
- */
- final val Cpobj = new OpCode()
- opcode(Cpobj, CEE_CPOBJ , "cpobj" , 0xFFFFFF70, POP_I_I , PUSH_NONE, INLINE_TYPE , FLOW_NEXT)
-
- /**
- * Copies the value type object pointed to by an address to the top of the evaluation stack.
- */
- final val Ldobj = new OpCode()
- opcode(Ldobj, CEE_LDOBJ , "ldobj" , 0xFFFFFF71, POP_I , PUSH_1 , INLINE_TYPE , FLOW_NEXT)
-
- /**
- * Pushes a new object reference to a string literal stored in the metadata.
- */
- final val Ldstr = new OpCode()
- opcode(Ldstr, CEE_LDSTR , "ldstr" , 0xFFFFFF72, POP_NONE , PUSH_REF , INLINE_STRING, FLOW_NEXT)
-
- /**
- * Creates a new object or a new instance of a value type, pushing an object reference
- * (type O) onto the evaluation stack.
- */
- final val Newobj = new OpCode()
- opcode(Newobj, CEE_NEWOBJ, "newobj", 0xFFFFFF73, POP_SPECIAL , PUSH_REF , INLINE_METHOD, FLOW_CALL)
-
- /**
- * Attempts to cast an object passed by reference to the specified class.
- */
- final val Castclass = new OpCode()
- opcode(Castclass, CEE_CASTCLASS, "castclass", 0xFFFFFF74, POP_REF , PUSH_REF , INLINE_TYPE , FLOW_NEXT)
-
- /**
- * Tests whether an object reference (type O) is an instance of a particular class.
- */
- final val Isinst = new OpCode()
- opcode(Isinst, CEE_ISINST , "isinst" , 0xFFFFFF75, POP_REF , PUSH_I , INLINE_TYPE , FLOW_NEXT)
-
- /**
- * Converts the unsigned integer value on top of the evaluation stack to float32.
- */
- final val Conv_R_Un = new OpCode()
- opcode(Conv_R_Un, CEE_CONV_R_UN, "conv.r.un", 0xFFFFFF76, POP_1 , PUSH_R8 , INLINE_NONE , FLOW_NEXT)
-
- /**
- * Converts the boxed representation of a value type to its unboxed form.
- */
- final val Unbox = new OpCode()
- opcode(Unbox, CEE_UNBOX , "unbox" , 0xFFFFFF79, POP_REF , PUSH_I , INLINE_TYPE , FLOW_NEXT)
-
- /**
- * Throws the exception object currently on the evaluation stack.
- */
- final val Throw = new OpCode()
- opcode(Throw, CEE_THROW , "throw" , 0xFFFFFF7A, POP_REF , PUSH_NONE, INLINE_NONE , FLOW_THROW)
-
- /**
- * Finds the value of a field in the object whose reference is currently
- * on the evaluation stack.
- */
- final val Ldfld = new OpCode()
- opcode(Ldfld, CEE_LDFLD , "ldfld" , 0xFFFFFF7B, POP_REF , PUSH_1 , INLINE_FIELD , FLOW_NEXT)
-
- /**
- * Finds the address of a field in the object whose reference is currently
- * on the evaluation stack.
- */
- final val Ldflda = new OpCode()
- opcode(Ldflda, CEE_LDFLDA , "ldflda" , 0xFFFFFF7C, POP_REF , PUSH_I , INLINE_FIELD , FLOW_NEXT)
-
- /**
- * Pushes the value of a static field onto the evaluation stack.
- */
- final val Ldsfld = new OpCode()
- opcode(Ldsfld, CEE_LDSFLD , "ldsfld" , 0xFFFFFF7E, POP_NONE , PUSH_1 , INLINE_FIELD , FLOW_NEXT)
-
- /**
- * Pushes the address of a static field onto the evaluation stack.
- */
- final val Ldsflda = new OpCode()
- opcode(Ldsflda, CEE_LDSFLDA, "ldsflda", 0xFFFFFF7F, POP_NONE , PUSH_I , INLINE_FIELD , FLOW_NEXT)
-
- /**
- * Replaces the value stored in the field of an object reference or pointer with a new value.
- */
- final val Stfld = new OpCode()
- opcode(Stfld, CEE_STFLD , "stfld" , 0xFFFFFF7D, POP_REF_1, PUSH_NONE, INLINE_FIELD , FLOW_NEXT)
-
- /**
- * Replaces the value of a static field with a value from the evaluation stack.
- */
- final val Stsfld = new OpCode()
- opcode(Stsfld, CEE_STSFLD , "stsfld" , 0xFFFFFF80, POP_1 , PUSH_NONE, INLINE_FIELD , FLOW_NEXT)
-
- /**
- * Copies a value of a specified type from the evaluation stack into a supplied memory address.
- */
- final val Stobj = new OpCode()
- opcode(Stobj, CEE_STOBJ , "stobj" , 0xFFFFFF81, POP_I_1, PUSH_NONE, INLINE_TYPE , FLOW_NEXT)
-
- /**
- * Converts the unsigned value on top of the evaluation stack to signed int8 and
- * extends it to int32, throwing OverflowException on overflow.
- */
- final val Conv_Ovf_I1_Un = new OpCode()
- opcode(Conv_Ovf_I1_Un, CEE_CONV_OVF_I1_UN, "conv.ovf.i1.un", 0xFFFFFF82, POP_1,PUSH_I,INLINE_NONE, FLOW_NEXT)
-
- /**
- * Converts the unsigned value on top of the evaluation stack to signed int16 and
- * extends it to int32, throwing OverflowException on overflow.
- */
- final val Conv_Ovf_I2_Un = new OpCode()
- opcode(Conv_Ovf_I2_Un, CEE_CONV_OVF_I2_UN, "conv.ovf.i2.un", 0xFFFFFF83,POP_1,PUSH_I, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Converts the unsigned value on top of the evaluation stack to signed int32,
- * throwing OverflowException on overflow.
- */
- final val Conv_Ovf_I4_Un = new OpCode()
- opcode(Conv_Ovf_I4_Un, CEE_CONV_OVF_I4_UN, "conv.ovf.i4.un", 0xFFFFFF84,POP_1,PUSH_I, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Converts the unsigned value on top of the evaluation stack to signed int64,
- * throwing OverflowException on overflow.
- */
- final val Conv_Ovf_I8_Un = new OpCode()
- opcode(Conv_Ovf_I8_Un, CEE_CONV_OVF_I8_UN, "conv.ovf.i8.un", 0xFFFFFF85,POP_1,PUSH_I8, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Converts the unsigned value on top of the evaluation stack to signed natural int,
- * throwing OverflowException on overflow.
- */
- final val Conv_Ovf_I_Un = new OpCode()
- opcode(Conv_Ovf_I_Un, CEE_CONV_OVF_I_UN , "conv.ovf.i.un" , 0xFFFFFF8A,POP_1,PUSH_I, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Converts the unsigned value on top of the evaluation stack to unsigned int8 and
- * extends it to int32, throwing OverflowException on overflow.
- */
- final val Conv_Ovf_U1_Un = new OpCode()
- opcode(Conv_Ovf_U1_Un, CEE_CONV_OVF_U1_UN, "conv.ovf.u1.un", 0xFFFFFF86,POP_1,PUSH_I, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Converts the unsigned value on top of the evaluation stack to unsigned int16 and
- * extends it to int32, throwing OverflowException on overflow.
- */
- final val Conv_Ovf_U2_Un = new OpCode()
- opcode(Conv_Ovf_U2_Un, CEE_CONV_OVF_U2_UN, "conv.ovf.u2.un", 0xFFFFFF87,POP_1,PUSH_I, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Converts the unsigned value on top of the evaluation stack to unsigned int32,
- * throwing OverflowException on overflow.
- */
- final val Conv_Ovf_U4_Un = new OpCode()
- opcode(Conv_Ovf_U4_Un, CEE_CONV_OVF_U4_UN, "conv.ovf.u4.un", 0xFFFFFF88,POP_1,PUSH_I, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Converts the unsigned value on top of the evaluation stack to unsigned int64,
- * throwing OverflowException on overflow.
- */
- final val Conv_Ovf_U8_Un = new OpCode()
- opcode(Conv_Ovf_U8_Un, CEE_CONV_OVF_U8_UN, "conv.ovf.u8.un", 0xFFFFFF89,POP_1,PUSH_I8, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Converts the unsigned value on top of the evaluation stack to unsigned natural int,
- * throwing OverflowException on overflow.
- */
- final val Conv_Ovf_U_Un = new OpCode()
- opcode(Conv_Ovf_U_Un, CEE_CONV_OVF_U_UN , "conv.ovf.u.un" , 0xFFFFFF8B,POP_1,PUSH_I, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Converts a value type to an object reference (type O).
- */
- final val Box = new OpCode()
- opcode(Box, CEE_BOX , "box" , 0xFFFFFF8C, POP_1 , PUSH_REF , INLINE_TYPE , FLOW_NEXT)
-
- /**
- * Pushes an object reference to a new zero-based, one-dimensional array whose elements
- * are of a specific type onto the evaluation stack.
- */
- final val Newarr = new OpCode()
- opcode(Newarr, CEE_NEWARR, "newarr" , 0xFFFFFF8D, POP_I , PUSH_REF , INLINE_TYPE , FLOW_NEXT)
-
- /**
- * Pushes the number of elements of a zero-based, one-dimensional array
- * onto the evaluation stack.
- */
- final val Ldlen = new OpCode()
- opcode(Ldlen, CEE_LDLEN, "ldlen", 0xFFFFFF8E, POP_REF, PUSH_I,INLINE_NONE , FLOW_NEXT)
-
- /**
- * Loads the address of the array element at a specified array index onto
- * the top of the evaluation stack as type & (managed pointer).
- */
- final val Ldelema = new OpCode()
- opcode(Ldelema, CEE_LDELEMA, "ldelema" , 0xFFFFFF8F, POP_REF_I, PUSH_I, INLINE_TYPE , FLOW_NEXT)
-
- /**
- * Loads the element with type natural int at a specified array index onto the top
- * of the evaluation stack as a natural int.
- */
- final val Ldelem_I = new OpCode()
- opcode(Ldelem_I, CEE_LDELEM_I, "ldelem.i" , 0xFFFFFF97, POP_REF_I, PUSH_I, INLINE_NONE , FLOW_NEXT)
-
- /**
- * Loads the element with type int8 at a specified array index onto the top of the
- * evaluation stack as an int32.
- */
- final val Ldelem_I1 = new OpCode()
- opcode(Ldelem_I1, CEE_LDELEM_I1, "ldelem.i1" , 0xFFFFFF90, POP_REF_I, PUSH_I, INLINE_NONE , FLOW_NEXT)
-
- /**
- * Loads the element with type int16 at a specified array index onto the top of
- * the evaluation stack as an int32.
- */
- final val Ldelem_I2 = new OpCode()
- opcode(Ldelem_I2, CEE_LDELEM_I2, "ldelem.i2" , 0xFFFFFF92, POP_REF_I, PUSH_I, INLINE_NONE , FLOW_NEXT)
-
- /**
- * Loads the element with type int32 at a specified array index onto the top of the
- * evaluation stack as an int32.
- */
- final val Ldelem_I4 = new OpCode()
- opcode(Ldelem_I4, CEE_LDELEM_I4, "ldelem.i4" , 0xFFFFFF94, POP_REF_I, PUSH_I, INLINE_NONE , FLOW_NEXT)
-
- /**
- * Loads the element with type int64 at a specified array index onto the top of the
- * evaluation stack as an int64.
- */
- final val Ldelem_I8 = new OpCode()
- opcode(Ldelem_I8, CEE_LDELEM_I8, "ldelem.i8" , 0xFFFFFF96, POP_REF_I, PUSH_I8, INLINE_NONE , FLOW_NEXT)
-
- /**
- * Loads the element with type float32 at a specified array index onto the top of the
- * evaluation stack as type F (float)
- */
- final val Ldelem_R4 = new OpCode()
- opcode(Ldelem_R4, CEE_LDELEM_R4, "ldelem.r4" , 0xFFFFFF98, POP_REF_I, PUSH_R4, INLINE_NONE , FLOW_NEXT)
-
- /**
- * Loads the element with type float64 at a specified array index onto the top of the
- * evaluation stack as type F (float) .
- */
- final val Ldelem_R8 = new OpCode()
- opcode(Ldelem_R8, CEE_LDELEM_R8, "ldelem.r8" , 0xFFFFFF99, POP_REF_I, PUSH_R8, INLINE_NONE , FLOW_NEXT)
-
- /**
- * Loads the element containing an object reference at a specified array index onto
- * the top of the evaluation stack as type O (object reference).
- */
- final val Ldelem_Ref = new OpCode()
- opcode(Ldelem_Ref, CEE_LDELEM_REF, "ldelem.ref", 0xFFFFFF9A, POP_REF_I, PUSH_REF, INLINE_NONE , FLOW_NEXT)
-
- /**
- * Loads the element with type unsigned int8 at a specified array index onto the top
- * of the evaluation stack as an int32.
- */
- final val Ldelem_U1 = new OpCode()
- opcode(Ldelem_U1, CEE_LDELEM_U1, "ldelem.u1" , 0xFFFFFF91, POP_REF_I, PUSH_I, INLINE_NONE , FLOW_NEXT)
-
- /**
- * Loads the element with type unsigned int16 at a specified array index onto the top
- * of the evaluation stack as an int32.
- */
- final val Ldelem_U2 = new OpCode()
- opcode(Ldelem_U2, CEE_LDELEM_U2, "ldelem.u2" , 0xFFFFFF93, POP_REF_I, PUSH_I, INLINE_NONE , FLOW_NEXT)
-
- /**
- * Loads the element with type unsigned int32 at a specified array index onto the top
- * of the evaluation stack as an int32.
- */
- final val Ldelem_U4 = new OpCode()
- opcode(Ldelem_U4, CEE_LDELEM_U4, "ldelem.u4" , 0xFFFFFF95, POP_REF_I, PUSH_I, INLINE_NONE , FLOW_NEXT)
-
- /**
- * Replaces the array element at a given index with the natural int value on
- * the evaluation stack.
- */
- final val Stelem_I = new OpCode()
- opcode(Stelem_I, CEE_STELEM_I, "stelem.i", 0xFFFFFF9B, POP_REF_I_I, PUSH_NONE, INLINE_NONE , FLOW_NEXT)
-
- /**
- * Replaces the array element at a given index with the int8 value on the evaluation stack.
- */
- final val Stelem_I1 = new OpCode()
- opcode(Stelem_I1, CEE_STELEM_I1, "stelem.i1", 0xFFFFFF9C, POP_REF_I_I, PUSH_NONE, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Replaces the array element at a given index with the int16 value on the evaluation stack.
- */
- final val Stelem_I2 = new OpCode()
- opcode(Stelem_I2, CEE_STELEM_I2, "stelem.i2", 0xFFFFFF9D, POP_REF_I_I, PUSH_NONE, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Replaces the array element at a given index with the int32 value on the evaluation stack.
- */
- final val Stelem_I4 = new OpCode()
- opcode(Stelem_I4, CEE_STELEM_I4, "stelem.i4", 0xFFFFFF9E, POP_REF_I_I, PUSH_NONE, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Replaces the array element at a given index with the int64 value on the evaluation stack.
- */
- final val Stelem_I8 = new OpCode()
- opcode(Stelem_I8, CEE_STELEM_I8,"stelem.i8", 0xFFFFFF9F, POP_REF_I_I8, PUSH_NONE, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Replaces the array element at a given index with the float32 value on the evaluation stack.
- */
- final val Stelem_R4 = new OpCode()
- opcode(Stelem_R4, CEE_STELEM_R4,"stelem.r4", 0xFFFFFFA0, POP_REF_I_R4, PUSH_NONE, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Replaces the array element at a given index with the float64 value on the evaluation stack.
- */
- final val Stelem_R8 = new OpCode()
- opcode(Stelem_R8, CEE_STELEM_R8,"stelem.r8", 0xFFFFFFA1, POP_REF_I_R8, PUSH_NONE, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Replaces the array element at a given index with the object ref value (type O)
- * on the evaluation stack.
- */
- final val Stelem_Ref = new OpCode()
- opcode(Stelem_Ref, CEE_STELEM_REF,"stelem.ref",0xFFFFFFA2,POP_REF_I_REF,PUSH_NONE, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Converts the signed value on top of the evaluation stack to signed int8 and
- * extends it to int32, throwing OverflowException on overflow.
- */
- final val Conv_Ovf_I1 = new OpCode()
- opcode(Conv_Ovf_I1, CEE_CONV_OVF_I1, "conv.ovf.i1", 0xFFFFFFB3, POP_1, PUSH_I , INLINE_NONE , FLOW_NEXT)
-
- /**
- * Converts the signed value on top of the evaluation stack to signed int16 and
- * extending it to int32, throwing OverflowException on overflow.
- */
- final val Conv_Ovf_I2 = new OpCode()
- opcode(Conv_Ovf_I2, CEE_CONV_OVF_I2, "conv.ovf.i2", 0xFFFFFFB5, POP_1, PUSH_I , INLINE_NONE , FLOW_NEXT)
-
- /**
- * Converts the signed value on top of the evaluation stack to signed int32,
- * throwing OverflowException on overflow.
- */
- final val Conv_Ovf_I4 = new OpCode()
- opcode(Conv_Ovf_I4, CEE_CONV_OVF_I4, "conv.ovf.i4", 0xFFFFFFB7, POP_1, PUSH_I , INLINE_NONE , FLOW_NEXT)
-
- /**
- * Converts the signed value on top of the evaluation stack to signed int64,
- * throwing OverflowException on overflow.
- */
- final val Conv_Ovf_I8 = new OpCode()
- opcode(Conv_Ovf_I8, CEE_CONV_OVF_I8, "conv.ovf.i8", 0xFFFFFFB9, POP_1, PUSH_I8, INLINE_NONE , FLOW_NEXT)
-
- /**
- * Converts the signed value on top of the evaluation stack to unsigned int8 and
- * extends it to int32, throwing OverflowException on overflow.
- */
- final val Conv_Ovf_U1 = new OpCode()
- opcode(Conv_Ovf_U1, CEE_CONV_OVF_U1, "conv.ovf.u1", 0xFFFFFFB4, POP_1, PUSH_I , INLINE_NONE , FLOW_NEXT)
-
- /**
- * Converts the signed value on top of the evaluation stack to unsigned int16 and
- * extends it to int32, throwing OverflowException on overflow.
- */
- final val Conv_Ovf_U2 = new OpCode()
- opcode(Conv_Ovf_U2, CEE_CONV_OVF_U2, "conv.ovf.u2", 0xFFFFFFB6, POP_1, PUSH_I , INLINE_NONE , FLOW_NEXT)
-
- /**
- * Converts the signed value on top of the evaluation stack to unsigned int32,
- * throwing OverflowException on overflow.
- */
- final val Conv_Ovf_U4 = new OpCode()
- opcode(Conv_Ovf_U4, CEE_CONV_OVF_U4, "conv.ovf.u4", 0xFFFFFFB8, POP_1, PUSH_I , INLINE_NONE , FLOW_NEXT)
-
- /**
- * Converts the signed value on top of the evaluation stack to unsigned int64,
- * throwing OverflowException on overflow.
- */
- final val Conv_Ovf_U8 = new OpCode()
- opcode(Conv_Ovf_U8, CEE_CONV_OVF_U8, "conv.ovf.u8", 0xFFFFFFBA, POP_1, PUSH_I8, INLINE_NONE , FLOW_NEXT)
-
- /**
- * Retrieves the address (type &) embedded in a typed reference.
- */
- final val Refanyval = new OpCode()
- opcode(Refanyval, CEE_REFANYVAL, "refanyval", 0xFFFFFFC2, POP_1, PUSH_I , INLINE_TYPE , FLOW_NEXT)
-
- /**
- * Retrieves the type token embedded in a typed reference .
- */
- final val Refanytype = new OpCode()
- opcode(Refanytype, CEE_REFANYTYPE, "refanytype", 0xFFFFFE1D, POP_1 , PUSH_I , INLINE_NONE, FLOW_NEXT)
-
- /**
- * Throws ArithmeticException if value is not a finite number.
- */
- final val Ckfinite = new OpCode()
- opcode(Ckfinite, CEE_CKFINITE, "ckfinite" , 0xFFFFFFC3, POP_1, PUSH_R8 , INLINE_NONE , FLOW_NEXT)
-
- /**
- * Pushes a typed reference to an instance of a specific type onto the evaluation stack.
- */
- final val Mkrefany = new OpCode()
- opcode(Mkrefany, CEE_MKREFANY, "mkrefany" , 0xFFFFFFC6, POP_I, PUSH_1 , INLINE_TYPE , FLOW_NEXT)
-
- /**
- * Converts a metadata token to its runtime representation, pushing it onto the evaluation stack.
- */
- final val Ldtoken = new OpCode()
- opcode(Ldtoken, CEE_LDTOKEN , "ldtoken" , 0xFFFFFFD0, POP_NONE, PUSH_I, INLINE_TOKEN , FLOW_NEXT)
-
- /**
- * Converts the value on top of the evaluation stack to unsigned int8, and extends it to int32.
- */
- final val Conv_U1 = new OpCode()
- opcode(Conv_U1, CEE_CONV_U1 , "conv.u1" , 0xFFFFFFD2, POP_1, PUSH_I, INLINE_NONE , FLOW_NEXT)
-
- /**
- * Converts the value on top of the evaluation stack to unsigned int16, and extends it to int32.
- */
- final val Conv_U2 = new OpCode()
- opcode(Conv_U2, CEE_CONV_U2 , "conv.u2" , 0xFFFFFFD1, POP_1, PUSH_I, INLINE_NONE , FLOW_NEXT)
-
- /**
- * Converts the value on top of the evaluation stack to natural int.
- */
- final val Conv_I = new OpCode()
- opcode(Conv_I, CEE_CONV_I , "conv.i" , 0xFFFFFFD3, POP_1, PUSH_I, INLINE_NONE , FLOW_NEXT)
-
- /**
- * Converts the signed value on top of the evaluation stack to signed natural int,
- * throwing OverflowException on overflow.
- */
- final val Conv_Ovf_I = new OpCode()
- opcode(Conv_Ovf_I, CEE_CONV_OVF_I , "conv.ovf.i", 0xFFFFFFD4, POP_1, PUSH_I, INLINE_NONE , FLOW_NEXT)
-
- /**
- * Converts the signed value on top of the evaluation stack to unsigned natural int,
- * throwing OverflowException on overflow.
- */
- final val Conv_Ovf_U = new OpCode()
- opcode(Conv_Ovf_U, CEE_CONV_OVF_U , "conv.ovf.u", 0xFFFFFFD5, POP_1, PUSH_I, INLINE_NONE , FLOW_NEXT)
-
- /**
- * Adds two integers, performs an overflow check, and pushes the result
- * onto the evaluation stack.
- */
- final val Add_Ovf = new OpCode()
- opcode(Add_Ovf, CEE_ADD_OVF , "add.ovf" , 0xFFFFFFD6, POP_1_1, PUSH_1, INLINE_NONE , FLOW_NEXT)
-
- /**
- * Adds two unsigned integer values, performs an overflow check, and pushes the result
- * onto the evaluation stack.
- */
- final val Add_Ovf_Un = new OpCode()
- opcode(Add_Ovf_Un, CEE_ADD_OVF_UN , "add.ovf.un", 0xFFFFFFD7, POP_1_1, PUSH_1, INLINE_NONE , FLOW_NEXT)
-
- /**
- * Multiplies two integer values, performs an overflow check, and pushes the result
- * onto the evaluation stack.
- */
- final val Mul_Ovf = new OpCode()
- opcode(Mul_Ovf, CEE_MUL_OVF , "mul.ovf" , 0xFFFFFFD8, POP_1_1, PUSH_1, INLINE_NONE , FLOW_NEXT)
-
- /**
- * Multiplies two unsigned integer values , performs an overflow check ,
- * and pushes the result onto the evaluation stack.
- */
- final val Mul_Ovf_Un = new OpCode()
- opcode(Mul_Ovf_Un, CEE_MUL_OVF_UN , "mul.ovf.un", 0xFFFFFFD9, POP_1_1, PUSH_1, INLINE_NONE , FLOW_NEXT)
-
- /**
- * Subtracts one integer value from another, performs an overflow check,
- * and pushes the result onto the evaluation stack.
- */
- final val Sub_Ovf = new OpCode()
- opcode(Sub_Ovf, CEE_SUB_OVF , "sub.ovf" , 0xFFFFFFDA, POP_1_1, PUSH_1, INLINE_NONE , FLOW_NEXT)
-
- /**
- * Subtracts one unsigned integer value from another, performs an overflow check,
- * and pushes the result onto the evaluation stack.
- */
- final val Sub_Ovf_Un = new OpCode()
- opcode(Sub_Ovf_Un, CEE_SUB_OVF_UN, "sub.ovf.un", 0xFFFFFFDB, POP_1_1, PUSH_1, INLINE_NONE , FLOW_NEXT)
-
- /**
- * Transfers control from the fault or finally clause of an exception block back to
- * the Common Language Infrastructure (CLI) exception handler.
- */
- final val Endfinally = new OpCode()
- opcode(Endfinally, CEE_ENDFINALLY, "endfinally", 0xFFFFFFDC, POP_NONE, PUSH_NONE, INLINE_NONE, FLOW_RETURN)
-
- /**
- * Exits a protected region of code, unconditionally tranferring control
- * to a specific target instruction.
- */
- final val Leave = new OpCode()
- opcode(Leave, CEE_LEAVE, "leave", 0xFFFFFFDD, POP_NONE, PUSH_NONE, INLINE_TARGET, FLOW_BRANCH)
-
- /**
- * Exits a protected region of code, unconditionally tranferring control
- * to a target instruction (short form).
- */
- final val Leave_S = new OpCode()
- opcode(Leave_S, CEE_LEAVE_S, "leave.s", 0xFFFFFFDE, POP_NONE, PUSH_NONE, INLINE_TARGET_S, FLOW_BRANCH)
-
- /**
- * Stores a value of type natural int at a supplied address.
- */
- final val Stind_I = new OpCode()
- opcode(Stind_I, CEE_STIND_I, "stind.i", 0xFFFFFFDF, POP_I_I , PUSH_NONE, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Converts the value on top of the evaluation stack to unsigned natural int,
- * and extends it to natural int.
- */
- final val Conv_U = new OpCode()
- opcode(Conv_U, CEE_CONV_U, "conv.u", 0xFFFFFFE0, POP_1 , PUSH_I , INLINE_NONE, FLOW_NEXT)
-
- /**
- * Returns an unmanaged pointer to the argument list of the current method.
- */
- final val Arglist = new OpCode()
- opcode(Arglist, CEE_ARGLIST, "arglist" , 0xFFFFFE00, POP_NONE, PUSH_I , INLINE_NONE, FLOW_NEXT)
-
- /**
- * Compares two values. If they are equal, the integer value 1 (int32) is pushed
- * onto the evaluation stack otherwise 0 (int32) is pushed onto the evaluation stack.
- */
- final val Ceq = new OpCode()
- opcode(Ceq, CEE_CEQ, "ceq", 0xFFFFFE01, POP_1_1 , PUSH_I, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Compares two values. If the first value is greater than the second,
- * the integer value 1 (int32) is pushed onto the evaluation stack
- * otherwise 0 (int32) is pushed onto the evaluation stack.
- */
- final val Cgt = new OpCode()
- opcode(Cgt, CEE_CGT, "cgt", 0xFFFFFE02, POP_1_1 , PUSH_I, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Compares two unsigned or unordered values. If the first value is greater than
- * the second, the integer value 1 (int32) is pushed onto the evaluation stack
- * otherwise 0 (int32) is pushed onto the evaluation stack.
- */
- final val Cgt_Un = new OpCode()
- opcode(Cgt_Un, CEE_CGT_UN, "cgt.un", 0xFFFFFE03, POP_1_1 , PUSH_I, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Compares two values. If the first value is less than the second,
- * the integer value 1 (int32) is pushed onto the evaluation stack
- * otherwise 0 (int32) is pushed onto the evaluation stack.
- */
- final val Clt = new OpCode()
- opcode(Clt, CEE_CLT, "clt" , 0xFFFFFE04, POP_1_1 , PUSH_I , INLINE_NONE, FLOW_NEXT)
-
- /**
- * Compares the unsigned or unordered values value1 and value2. If value1 is
- * less than value2, then the integer value 1 (int32) is pushed onto the
- * evaluation stack otherwise 0 (int32) is pushed onto the evaluation stack.
- */
- final val Clt_Un = new OpCode()
- opcode(Clt_Un, CEE_CLT_UN , "clt.un" , 0xFFFFFE05, POP_1_1 , PUSH_I , INLINE_NONE, FLOW_NEXT)
-
- /**
- * Pushes an unmanaged pointer (type natural int) to the native code implementing
- * a specific method onto the evaluation stack.
- */
- final val Ldftn = new OpCode()
- opcode(Ldftn, CEE_LDFTN , "ldftn" , 0xFFFFFE06, POP_NONE, PUSH_I , INLINE_METHOD, FLOW_NEXT)
-
- /**
- * Pushes an unmanaged pointer (type natural int) to the native code implementing
- * a particular virtual method associated with a specified object onto the evaluation stack.
- */
- final val Ldvirtftn = new OpCode()
- opcode(Ldvirtftn, CEE_LDVIRTFTN, "ldvirtftn", 0xFFFFFE07, POP_REF , PUSH_I , INLINE_METHOD, FLOW_NEXT)
-
- /**
- * Loads an argument (referenced by a specified index value) onto the stack.
- */
- final val Ldarg = new OpCode()
- opcode(Ldarg, CEE_LDARG , "ldarg" , 0xFFFFFE09, POP_NONE, PUSH_1 , INLINE_VARIABLE , FLOW_NEXT)
-
- /**
- * Load an argument address onto the evaluation stack.
- */
- final val Ldarga = new OpCode()
- opcode(Ldarga, CEE_LDARGA , "ldarga", 0xFFFFFE0A, POP_NONE, PUSH_I, INLINE_VARIABLE , FLOW_NEXT)
-
- /**
- * Loads the local variable at a specific index onto the evaluation stack.
- */
- final val Ldloc = new OpCode()
- opcode(Ldloc, CEE_LDLOC, "ldloc", 0xFFFFFE0C, POP_NONE, PUSH_1 , INLINE_VARIABLE , FLOW_NEXT)
-
- /**
- * Loads the address of the local variable at a specific index onto the evaluation stack.
- */
- final val Ldloca = new OpCode()
- opcode(Ldloca, CEE_LDLOCA, "ldloca", 0xFFFFFE0D, POP_NONE, PUSH_I, INLINE_VARIABLE , FLOW_NEXT)
-
- /**
- * Stores the value on top of the evaluation stack in the argument slot at a specified index.
- */
- final val Starg = new OpCode()
- opcode(Starg, CEE_STARG, "starg", 0xFFFFFE0B, POP_1 , PUSH_NONE, INLINE_VARIABLE , FLOW_NEXT)
-
- /**
- * Pops the current value from the top of the evaluation stack and stores it in a
- * the local variable list at a specified index.
- */
- final val Stloc = new OpCode()
- opcode(Stloc, CEE_STLOC, "stloc", 0xFFFFFE0E, POP_1 , PUSH_NONE, INLINE_VARIABLE , FLOW_NEXT)
-
- /**
- * Allocates a certain number of bytes from the local dynamic memory pool and pushes the
- * address (a transient pointer, type *) of the first allocated Byte onto the evaluation stack.
- */
- final val Localloc = new OpCode()
- opcode(Localloc, CEE_LOCALLOC, "localloc" , 0xFFFFFE0F, POP_I, PUSH_I, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Transfers control from the filter clause of an exception back to the
- * Common Language Infrastructure (CLI) exception handler.
- */
- final val Endfilter = new OpCode()
- opcode(Endfilter, CEE_ENDFILTER, "endfilter" , 0xFFFFFE11, POP_I , PUSH_NONE, INLINE_NONE, FLOW_RETURN)
-
- /**
- * Indicates that an address currently atop the evaluation stack might not be aligned
- * to the natural size of the immediately following ldind, stind, ldfld, stfld, ldobj,
- * stobj, initblk, or cpblk instruction.
- */
- final val Unaligned = new OpCode()
- opcode(Unaligned, CEE_UNALIGNED, "unaligned.", 0xFFFFFE12, POP_NONE, PUSH_NONE, INLINE_I_S , FLOW_META)
-
- /**
- * Specifies that an address currently atop the evaluation stack might be volatile,
- * and the results of reading that location cannot be cached or that multiple stores
- * to that location cannot be suppressed.
- */
- final val Volatile = new OpCode()
- opcode(Volatile, CEE_VOLATILE, "volatile." , 0xFFFFFE13, POP_NONE, PUSH_NONE, INLINE_NONE, FLOW_META)
-
- /**
- * Performs a postfixed method call instruction such that the current method's stack
- * frame is removed before the actual call instruction is executed.
- */
- final val Tailcall = new OpCode()
- opcode(Tailcall, CEE_TAILCALL, "tail." , 0xFFFFFE14, POP_NONE, PUSH_NONE, INLINE_NONE, FLOW_META)
-
- /**
- * Initializes all the fields of the object at a specific address to a null reference
- * or a 0 of the appropriate primitive type.
- */
- final val Initobj = new OpCode()
- opcode(Initobj, CEE_INITOBJ , "initobj" , 0xFFFFFE15, POP_I , PUSH_NONE, INLINE_TYPE, FLOW_NEXT)
-
- /**
- * Copies a specified number bytes from a source address to a destination address .
- */
- final val Cpblk = new OpCode()
- opcode(Cpblk, CEE_CPBLK , "cpblk" , 0xFFFFFE17, POP_I_I_I, PUSH_NONE, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Initializes a specified block of memory at a specific address to a given size
- * and initial value.
- */
- final val Initblk = new OpCode()
- opcode(Initblk, CEE_INITBLK , "initblk" , 0xFFFFFE18, POP_I_I_I, PUSH_NONE, INLINE_NONE, FLOW_NEXT)
-
- /**
- * Rethrows the current exception.
- */
- final val Rethrow = new OpCode()
- opcode(Rethrow, CEE_RETHROW , "rethrow", 0xFFFFFE1A, POP_NONE , PUSH_NONE, INLINE_NONE, FLOW_THROW)
-
- /**
- * Pushes the size, in bytes, of a supplied value type onto the evaluation stack.
- */
- final val Sizeof = new OpCode()
- opcode(Sizeof, CEE_SIZEOF, "sizeof", 0xFFFFFE1C, POP_NONE , PUSH_I , INLINE_TYPE, FLOW_NEXT)
-
-
-
- //##########################################################################
-}
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/emit/OpCodes.scala b/src/msil/ch/epfl/lamp/compiler/msil/emit/OpCodes.scala
deleted file mode 100644
index 80e4267436..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/emit/OpCodes.scala
+++ /dev/null
@@ -1,1205 +0,0 @@
-/*
- * System.Reflection.Emit-like API for writing .NET assemblies to MSIL
- */
-
-
-package ch.epfl.lamp.compiler.msil.emit
-
-
-/**
- * Provides field representations of the Microsoft Intermediate Language (MSIL)
- * instructions for emission by the ILGenerator class members (such as Emit).
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-object OpCodes {
-
- //##########################################################################
-
- /**
- * Adds two values and pushes the result onto the evaluation stack.
- */
- final val Add = OpCode.Add
-
- /**
- * Fills space if bytecodes are patched. No meaningful operation is performed
- * although a processing cycle can be consumed.
- */
- final val Nop = OpCode.Nop
-
- /**
- * Signals the Common Language Infrastructure (CLI) to inform the debugger that
- * a break point has been tripped.
- */
- final val Break = OpCode.Break
-
- /**
- * Loads the argument at index 0 onto the evaluation stack.
- */
- final val Ldarg_0 = OpCode.Ldarg_0
-
- /**
- * Loads the argument at index 1 onto the evaluation stack.
- */
- final val Ldarg_1 = OpCode.Ldarg_1
-
- /**
- * Loads the argument at index 2 onto the evaluation stack.
- */
- final val Ldarg_2 = OpCode.Ldarg_2
-
- /**
- * Loads the argument at index 3 onto the evaluation stack.
- */
- final val Ldarg_3 = OpCode.Ldarg_3
-
- /**
- * Loads the local variable at index 0 onto the evaluation stack.
- */
- final val Ldloc_0 = OpCode.Ldloc_0
-
- /**
- * Loads the local variable at index 1 onto the evaluation stack.
- */
- final val Ldloc_1 = OpCode.Ldloc_1
-
- /**
- * Loads the local variable at index 2 onto the evaluation stack.
- */
- final val Ldloc_2 = OpCode.Ldloc_2
-
- /**
- * Loads the local variable at index 3 onto the evaluation stack.
- */
- final val Ldloc_3 = OpCode.Ldloc_3
-
- /**
- * Pops the current value from the top of the evaluation stack and
- * stores it in a the local variable list at index 0.
- */
- final val Stloc_0 = OpCode.Stloc_0
-
- /**
- * Pops the current value from the top of the evaluation stack and
- * stores it in a the local variable list at index 1.
- */
- final val Stloc_1 = OpCode.Stloc_1
-
- /**
- * Pops the current value from the top of the evaluation stack and
- * stores it in a the local variable list at index 2.
- */
- final val Stloc_2 = OpCode.Stloc_2
-
- /**
- * Pops the current value from the top of the evaluation stack and
- * stores it in a the local variable list at index 3.
- */
- final val Stloc_3 = OpCode.Stloc_3
-
- /**
- * Loads the argument (referenced by a specified short form index)
- * onto the evaluation stack.
- */
- final val Ldarg_S = OpCode.Ldarg_S
-
- /**
- * Load an argument address, in short form, onto the evaluation stack.
- */
- final val Ldarga_S = OpCode.Ldarga_S
-
- /**
- * Loads the local variable at a specific index onto the evaluation stack,
- * short form.
- */
- final val Ldloc_S = OpCode.Ldloc_S
-
- /**
- * Loads the address of the local variable at a specific index onto
- * the evaluation stack, short form.
- */
- final val Ldloca_S = OpCode.Ldloca_S
-
- /**
- * Stores the value on top of the evaluation stack in the argument slot
- * at a specified index, short form.
- */
- final val Starg_S = OpCode.Starg_S
-
- /**
- * Pops the current value from the top of the evaluation stack and stores it
- * in a the local variable list at index (short form).
- */
- final val Stloc_S = OpCode.Stloc_S
-
- /**
- * Pushes a null reference (type O) onto the evaluation stack.
- */
- final val Ldnull = OpCode.Ldnull
-
- /**
- * Pushes the integer value of -1 onto the evaluation stack as an int32.
- */
- final val Ldc_I4_M1 = OpCode.Ldc_I4_M1
-
- /**
- * Pushes the integer value of 0 onto the evaluation stack as an int32.
- */
- final val Ldc_I4_0 = OpCode.Ldc_I4_0
-
- /**
- * Pushes the integer value of 1 onto the evaluation stack as an int32.
- */
- final val Ldc_I4_1 = OpCode.Ldc_I4_1
-
- /**
- * Pushes the integer value of 2 onto the evaluation stack as an int32.
- */
- final val Ldc_I4_2 = OpCode.Ldc_I4_2
-
- /**
- * Pushes the integer value of 3 onto the evaluation stack as an int32.
- */
- final val Ldc_I4_3 = OpCode.Ldc_I4_3
-
- /**
- * Pushes the integer value of 4 onto the evaluation stack as an int32.
- */
- final val Ldc_I4_4 = OpCode.Ldc_I4_4
-
- /**
- * Pushes the integer value of 5 onto the evaluation stack as an int32.
- */
- final val Ldc_I4_5 = OpCode.Ldc_I4_5
-
- /**
- * Pushes the integer value of 6 onto the evaluation stack as an int32.
- */
- final val Ldc_I4_6 = OpCode.Ldc_I4_6
-
- /**
- * Pushes the integer value of 7 onto the evaluation stack as an int32.
- */
- final val Ldc_I4_7 = OpCode.Ldc_I4_7
-
- /**
- * Pushes the integer value of 8 onto the evaluation stack as an int32.
- */
- final val Ldc_I4_8 = OpCode.Ldc_I4_8
-
- /**
- * Pushes the supplied int8 value onto the evaluation stack as an int32, short form.
- */
- final val Ldc_I4_S = OpCode.Ldc_I4_S
-
- /**
- * Pushes a supplied value of type int32 onto the evaluation stack as an int32.
- */
- final val Ldc_I4 = OpCode.Ldc_I4
-
- /**
- * Pushes a supplied value of type int64 onto the evaluation stack as an int64.
- */
- final val Ldc_I8 = OpCode.Ldc_I8
-
- /**
- * Pushes a supplied value of type float32 onto the evaluation stack as type F (float).
- */
- final val Ldc_R4 = OpCode.Ldc_R4
-
- /**
- * Pushes a supplied value of type float64 onto the evaluation stack as type F (float).
- */
- final val Ldc_R8 = OpCode.Ldc_R8
-
- /**
- * Copies the current topmost value on the evaluation stack, and then pushes the copy
- * onto the evaluation stack.
- */
- final val Dup = OpCode.Dup
-
- /**
- * Removes the value currently on top of the evaluation stack.
- */
- final val Pop = OpCode.Pop
-
- /**
- * Exits current method and jumps to specified method.
- */
- final val Jmp = OpCode.Jmp
-
- /**
- * Calls the method indicated by the passed method descriptor.
- */
- final val Call = OpCode.Call
-
- /**
- * constrained. prefix
- */
- final val Constrained = OpCode.Constrained
-
- /**
- * readonly. prefix
- */
- final val Readonly = OpCode.Readonly
-
- /**
- * Calls the method indicated on the evaluation stack (as a pointer to an entry point)
- * with arguments described by a calling convention.
- */
- final val Calli = OpCode.Calli
-
- /**
- * Returns from the current method, pushing a return value (if present) from the caller's
- * evaluation stack onto the callee's evaluation stack.
- */
- final val Ret = OpCode.Ret
-
- /**
- * Unconditionally transfers control to a target instruction (short form).
- */
- final val Br_S = OpCode.Br_S
-
- /**
- * Transfers control to a target instruction if value is false, a null reference, or zero.
- */
- final val Brfalse_S = OpCode.Brfalse_S
-
- /**
- * Transfers control to a target instruction (short form) if value is true, not null, or non-zero.
- */
- final val Brtrue_S = OpCode.Brtrue_S
-
- /**
- * Transfers control to a target instruction (short form) if two values are equal.
- */
- final val Beq_S = OpCode.Beq_S
-
- /**
- * Transfers control to a target instruction (short form) if the first value is greater than
- * or equal to the second value.
- */
- final val Bge_S = OpCode.Bge_S
-
- /**
- * Transfers control to a target instruction (short form) if the first value is greater than
- * the second value.
- */
- final val Bgt_S = OpCode.Bgt_S
-
- /**
- * Transfers control to a target instruction (short form) if the first value is less than
- * or equal to the second value.
- */
- final val Ble_S = OpCode.Ble_S
-
- /**
- * Transfers control to a target instruction (short form) if the first value is less than
- * the second value.
- */
- final val Blt_S = OpCode.Blt_S
-
- /**
- * Transfers control to a target instruction (short form) when two unsigned integer values
- * or unordered float values are not equal.
- */
- final val Bne_Un_S = OpCode.Bne_Un_S
-
- /**
- * Transfers control to a target instruction (short form) if the first value is greather
- * than the second value, when comparing unsigned integer values or unordered float values.
- */
- final val Bge_Un_S = OpCode.Bge_Un_S
-
- /**
- * Transfers control to a target instruction (short form) if the first value is greater than
- * the second value, when comparing unsigned integer values or unordered float values.
- */
- final val Bgt_Un_S = OpCode.Bgt_Un_S
-
- /**
- * Transfers control to a target instruction (short form) if the first value is less than
- * or equal to the second value, when comparing unsigned integer values or unordered float values.
- */
- final val Ble_Un_S = OpCode.Ble_Un_S
-
- /**
- * Transfers control to a target instruction (short form) if the first value is less than
- * the second value, when comparing unsigned integer values or unordered float values.
- */
- final val Blt_Un_S = OpCode.Blt_Un_S
-
- /**
- * Unconditionally transfers control to a target instruction.
- */
- final val Br = OpCode.Br
-
- /**
- * Transfers control to a target instruction if value is false, a null reference
- * (Nothing in Visual Basic), or zero.
- */
- final val Brfalse = OpCode.Brfalse
-
- /**
- * Transfers control to a target instruction if value is true, not null, or non-zero.
- */
- final val Brtrue = OpCode.Brtrue
-
- /**
- * Transfers control to a target instruction if two values are equal.
- */
- final val Beq = OpCode.Beq
-
- /**
- * Transfers control to a target instruction if the first value is greater than or
- * equal to the second value.
- */
- final val Bge = OpCode.Bge
-
- /**
- * Transfers control to a target instruction if the first value is greater than the second value.
- */
- final val Bgt = OpCode.Bgt
-
- /**
- * Transfers control to a target instruction if the first value is less than or equal
- * to the second value.
- */
- final val Ble = OpCode.Ble
-
- /**
- * Transfers control to a target instruction if the first value is less than the second value.
- */
- final val Blt = OpCode.Blt
-
- /**
- * Transfers control to a target instruction when two unsigned integer values or
- * unordered float values are not equal.
- */
- final val Bne_Un = OpCode.Bne_Un
-
- /**
- * Transfers control to a target instruction if the first value is greather than
- * the second value, when comparing unsigned integer values or unordered float values.
- */
- final val Bge_Un = OpCode.Bge_Un
-
- /**
- * Transfers control to a target instruction if the first value is greater than the
- * second value, when comparing unsigned integer values or unordered float values.
- */
- final val Bgt_Un = OpCode.Bgt_Un
-
- /**
- * Transfers control to a target instruction if the first value is less than or equal to
- * the second value, when comparing unsigned integer values or unordered float values.
- */
- final val Ble_Un = OpCode.Ble_Un
-
- /**
- * Transfers control to a target instruction if the first value is less than the second value,
- * when comparing unsigned integer values or unordered float values.
- */
- final val Blt_Un = OpCode.Blt_Un
-
- /**
- * Implements a jump table.
- */
- final val Switch = OpCode.Switch
-
- /**
- * Loads a value of type int8 as an int32 onto the evaluation stack indirectly.
- */
- final val Ldind_I1 = OpCode.Ldind_I1
-
- /**
- * Loads a value of type int16 as an int32 onto the evaluation stack indirectly.
- */
- final val Ldind_I2 = OpCode.Ldind_I2
-
- /**
- * Loads a value of type int32 as an int32 onto the evaluation stack indirectly.
- */
- final val Ldind_I4 = OpCode.Ldind_I4
-
- /**
- * Loads a value of type int64 as an int64 onto the evaluation stack indirectly.
- */
- final val Ldind_I8 = OpCode.Ldind_I8
-
- /**
- * Loads a value of type natural int as a natural int onto the evaluation stack indirectly.
- */
- final val Ldind_I = OpCode.Ldind_I
-
- /**
- * Loads a value of type float32 as a type F (float) onto the evaluation stack indirectly.
- */
- final val Ldind_R4 = OpCode.Ldind_R4
-
- /**
- * Loads a value of type float64 as a type F (float) onto the evaluation stack indirectly.
- */
- final val Ldind_R8 = OpCode.Ldind_R8
-
- /**
- * Loads an object reference as a type O (object reference) onto the evaluation stack indirectly.
- */
- final val Ldind_Ref = OpCode.Ldind_Ref
-
- /**
- * Loads a value of type unsigned int8 as an int32 onto the evaluation stack indirectly.
- */
- final val Ldind_U1 = OpCode.Ldind_U1
-
- /**
- * Loads a value of type unsigned int16 as an int32 onto the evaluation stack indirectly.
- */
- final val Ldind_U2 = OpCode.Ldind_U2
-
- /**
- * Loads a value of type unsigned int32 as an int32 onto the evaluation stack indirectly.
- */
- final val Ldind_U4 = OpCode.Ldind_U4
-
- /**
- * Stores a object reference value at a supplied address.
- */
- final val Stind_Ref = OpCode.Stind_Ref
-
- /**
- * Stores a value of type int8 at a supplied address.
- */
- final val Stind_I1 = OpCode.Stind_I1
-
- /**
- * Stores a value of type int16 at a supplied address.
- */
- final val Stind_I2 = OpCode.Stind_I2
-
- /**
- * Stores a value of type int32 at a supplied address.
- */
- final val Stind_I4 = OpCode.Stind_I4
-
- /**
- * Stores a value of type int64 at a supplied address.
- */
- final val Stind_I8 = OpCode.Stind_I8
-
- /**
- * Stores a value of type float32 at a supplied address.
- */
- final val Stind_R4 = OpCode.Stind_R4
-
- /**
- * Stores a value of type float64 at a supplied address.
- */
- final val Stind_R8 = OpCode.Stind_R8
-
- /**
- * Subtracts one value from another and pushes the result onto the evaluation stack.
- */
- final val Sub = OpCode.Sub
-
- /**
- * Multiplies two values and pushes the result on the evaluation stack.
- */
- final val Mul = OpCode.Mul
-
- /**
- * Divides two values and pushes the result as a floating-point (type F) or
- * quotient (type int32) onto the evaluation stack.
- */
- final val Div = OpCode.Div
-
- /**
- * Divides two unsigned integer values and pushes the result (int32) onto the evaluation stack.
- */
- final val Div_Un = OpCode.Div_Un
-
- /**
- * Divides two values and pushes the remainder onto the evaluation stack.
- */
- final val Rem = OpCode.Rem
-
- /**
- * Divides two unsigned values and pushes the remainder onto the evaluation stack.
- */
- final val Rem_Un = OpCode.Rem_Un
-
- /**
- * Computes the bitwise AND of two values and pushes the result onto the evaluation stack.
- */
- final val And = OpCode.And
-
- /**
- * Compute the bitwise complement of the two integer values on top of the stack and
- * pushes the result onto the evaluation stack.
- */
- final val Or = OpCode.Or
-
- /**
- * Computes the bitwise XOR of the top two values on the evaluation stack,
- * pushing the result onto the evaluation stack.
- */
- final val Xor = OpCode.Xor
-
- /**
- * Shifts an integer value to the left (in zeroes) by a specified number of bits,
- * pushing the result onto the evaluation stack.
- */
- final val Shl = OpCode.Shl
-
- /**
- * Shifts an integer value (in sign) to the right by a specified number of bits,
- * pushing the result onto the evaluation stack.
- */
- final val Shr = OpCode.Shr
-
- /**
- * Shifts an unsigned integer value (in zeroes) to the right by a specified number of bits,
- * pushing the result onto the evaluation stack.
- */
- final val Shr_Un = OpCode.Shr_Un
-
- /**
- * Negates a value and pushes the result onto the evaluation stack.
- */
- final val Neg = OpCode.Neg
-
- /**
- * Computes the bitwise complement of the integer value on top of the stack and pushes
- * the result onto the evaluation stack as the same type.
- */
- final val Not = OpCode.Not
-
- /**
- * Converts the value on top of the evaluation stack to int8, then extends (pads) it to int32.
- */
- final val Conv_I1 = OpCode.Conv_I1
-
- /**
- * Converts the value on top of the evaluation stack to int16, then extends (pads) it to int32.
- */
- final val Conv_I2 = OpCode.Conv_I2
-
- /**
- * Converts the value on top of the evaluation stack to int32.
- */
- final val Conv_I4 = OpCode.Conv_I4
-
- /**
- * Converts the value on top of the evaluation stack to int64.
- */
- final val Conv_I8 = OpCode.Conv_I8
-
- /**
- * Converts the value on top of the evaluation stack to float32.
- */
- final val Conv_R4 = OpCode.Conv_R4
-
- /**
- * Converts the value on top of the evaluation stack to float64.
- */
- final val Conv_R8 = OpCode.Conv_R8
-
- /**
- * Converts the value on top of the evaluation stack to unsigned int32, and extends it to int32.
- */
- final val Conv_U4 = OpCode.Conv_U4
-
- /**
- * Converts the value on top of the evaluation stack to unsigned int64, and extends it to int64.
- */
- final val Conv_U8 = OpCode.Conv_U8
-
- /**
- * Calls a late-bound method on an object, pushing the return value onto the evaluation stack.
- */
- final val Callvirt = OpCode.Callvirt
-
- /**
- * Copies the value type located at the address of an object (type &, * or natural int)
- * to the address of the destination object (type &, * or natural int).
- */
- final val Cpobj = OpCode.Cpobj
-
- /**
- * Copies the value type object pointed to by an address to the top of the evaluation stack.
- */
- final val Ldobj = OpCode.Ldobj
-
- /**
- * Pushes a new object reference to a string literal stored in the metadata.
- */
- final val Ldstr = OpCode.Ldstr
-
- /**
- * Creates a new object or a new instance of a value type, pushing an object reference
- * (type O) onto the evaluation stack.
- */
- final val Newobj = OpCode.Newobj
-
- /**
- * Attempts to cast an object passed by reference to the specified class.
- */
- final val Castclass = OpCode.Castclass
-
- /**
- * Tests whether an object reference (type O) is an instance of a particular class.
- */
- final val Isinst = OpCode.Isinst
-
- /**
- * Converts the unsigned integer value on top of the evaluation stack to float32.
- */
- final val Conv_R_Un = OpCode.Conv_R_Un
-
- /**
- * Converts the boxed representation of a value type to its unboxed form.
- */
- final val Unbox = OpCode.Unbox
-
- /**
- * Throws the exception object currently on the evaluation stack.
- */
- final val Throw = OpCode.Throw
-
- /**
- * Finds the value of a field in the object whose reference is currently
- * on the evaluation stack.
- */
- final val Ldfld = OpCode.Ldfld
-
- /**
- * Finds the address of a field in the object whose reference is currently
- * on the evaluation stack.
- */
- final val Ldflda = OpCode.Ldflda
-
- /**
- * Pushes the value of a static field onto the evaluation stack.
- */
- final val Ldsfld = OpCode.Ldsfld
-
- /**
- * Pushes the address of a static field onto the evaluation stack.
- */
- final val Ldsflda = OpCode.Ldsflda
-
- /**
- * Replaces the value stored in the field of an object reference or pointer with a new value.
- */
- final val Stfld = OpCode.Stfld
-
- /**
- * Replaces the value of a static field with a value from the evaluation stack.
- */
- final val Stsfld = OpCode.Stsfld
-
- /**
- * Copies a value of a specified type from the evaluation stack into a supplied memory address.
- */
- final val Stobj = OpCode.Stobj
-
- /**
- * Converts the unsigned value on top of the evaluation stack to signed int8 and
- * extends it to int32, throwing OverflowException on overflow.
- */
- final val Conv_Ovf_I1_Un = OpCode.Conv_Ovf_I1_Un
-
- /**
- * Converts the unsigned value on top of the evaluation stack to signed int16 and
- * extends it to int32, throwing OverflowException on overflow.
- */
- final val Conv_Ovf_I2_Un = OpCode.Conv_Ovf_I2_Un
-
- /**
- * Converts the unsigned value on top of the evaluation stack to signed int32,
- * throwing OverflowException on overflow.
- */
- final val Conv_Ovf_I4_Un = OpCode.Conv_Ovf_I4_Un
-
- /**
- * Converts the unsigned value on top of the evaluation stack to signed int64,
- * throwing OverflowException on overflow.
- */
- final val Conv_Ovf_I8_Un = OpCode.Conv_Ovf_I8_Un
-
- /**
- * Converts the unsigned value on top of the evaluation stack to signed natural int,
- * throwing OverflowException on overflow.
- */
- final val Conv_Ovf_I_Un = OpCode.Conv_Ovf_I_Un
-
- /**
- * Converts the unsigned value on top of the evaluation stack to unsigned int8 and
- * extends it to int32, throwing OverflowException on overflow.
- */
- final val Conv_Ovf_U1_Un = OpCode.Conv_Ovf_U1_Un
-
- /**
- * Converts the unsigned value on top of the evaluation stack to unsigned int16 and
- * extends it to int32, throwing OverflowException on overflow.
- */
- final val Conv_Ovf_U2_Un = OpCode.Conv_Ovf_U2_Un
-
- /**
- * Converts the unsigned value on top of the evaluation stack to unsigned int32,
- * throwing OverflowException on overflow.
- */
- final val Conv_Ovf_U4_Un = OpCode.Conv_Ovf_U4_Un
-
- /**
- * Converts the unsigned value on top of the evaluation stack to unsigned int64,
- * throwing OverflowException on overflow.
- */
- final val Conv_Ovf_U8_Un = OpCode.Conv_Ovf_U8_Un
-
- /**
- * Converts the unsigned value on top of the evaluation stack to unsigned natural int,
- * throwing OverflowException on overflow.
- */
- final val Conv_Ovf_U_Un = OpCode.Conv_Ovf_U_Un
-
- /**
- * Converts a value type to an object reference (type O).
- */
- final val Box = OpCode.Box
-
- /**
- * Pushes an object reference to a new zero-based, one-dimensional array whose elements
- * are of a specific type onto the evaluation stack.
- */
- final val Newarr = OpCode.Newarr
-
- /**
- * Pushes the number of elements of a zero-based, one-dimensional array
- * onto the evaluation stack.
- */
- final val Ldlen = OpCode.Ldlen
-
- /**
- * Loads the address of the array element at a specified array index onto
- * the top of the evaluation stack as type & (managed pointer).
- */
- final val Ldelema = OpCode.Ldelema
-
- /**
- * Loads the element with type natural int at a specified array index onto the top
- * of the evaluation stack as a natural int.
- */
- final val Ldelem_I = OpCode.Ldelem_I
-
- /**
- * Loads the element with type int8 at a specified array index onto the top of the
- * evaluation stack as an int32.
- */
- final val Ldelem_I1 = OpCode.Ldelem_I1
-
- /**
- * Loads the element with type int16 at a specified array index onto the top of
- * the evaluation stack as an int32.
- */
- final val Ldelem_I2 = OpCode.Ldelem_I2
-
- /**
- * Loads the element with type int32 at a specified array index onto the top of the
- * evaluation stack as an int32.
- */
- final val Ldelem_I4 = OpCode.Ldelem_I4
-
- /**
- * Loads the element with type int64 at a specified array index onto the top of the
- * evaluation stack as an int64.
- */
- final val Ldelem_I8 = OpCode.Ldelem_I8
-
- /**
- * Loads the element with type float32 at a specified array index onto the top of the
- * evaluation stack as type F (float)
- */
- final val Ldelem_R4 = OpCode.Ldelem_R4
-
- /**
- * Loads the element with type float64 at a specified array index onto the top of the
- * evaluation stack as type F (float) .
- */
- final val Ldelem_R8 = OpCode.Ldelem_R8
-
- /**
- * Loads the element containing an object reference at a specified array index onto
- * the top of the evaluation stack as type O (object reference).
- */
- final val Ldelem_Ref = OpCode.Ldelem_Ref
-
- /**
- * Loads the element with type unsigned int8 at a specified array index onto the top
- * of the evaluation stack as an int32.
- */
- final val Ldelem_U1 = OpCode.Ldelem_U1
-
- /**
- * Loads the element with type unsigned int16 at a specified array index onto the top
- * of the evaluation stack as an int32.
- */
- final val Ldelem_U2 = OpCode.Ldelem_U2
-
- /**
- * Loads the element with type unsigned int32 at a specified array index onto the top
- * of the evaluation stack as an int32.
- */
- final val Ldelem_U4 = OpCode.Ldelem_U4
-
- /**
- * Replaces the array element at a given index with the natural int value on
- * the evaluation stack.
- */
- final val Stelem_I = OpCode.Stelem_I
-
- /**
- * Replaces the array element at a given index with the int8 value on the evaluation stack.
- */
- final val Stelem_I1 = OpCode.Stelem_I1
-
- /**
- * Replaces the array element at a given index with the int16 value on the evaluation stack.
- */
- final val Stelem_I2 = OpCode.Stelem_I2
-
- /**
- * Replaces the array element at a given index with the int32 value on the evaluation stack.
- */
- final val Stelem_I4 = OpCode.Stelem_I4
-
- /**
- * Replaces the array element at a given index with the int64 value on the evaluation stack.
- */
- final val Stelem_I8 = OpCode.Stelem_I8
-
- /**
- * Replaces the array element at a given index with the float32 value on the evaluation stack.
- */
- final val Stelem_R4 = OpCode.Stelem_R4
-
- /**
- * Replaces the array element at a given index with the float64 value on the evaluation stack.
- */
- final val Stelem_R8 = OpCode.Stelem_R8
-
- /**
- * Replaces the array element at a given index with the object ref value (type O)
- * on the evaluation stack.
- */
- final val Stelem_Ref = OpCode.Stelem_Ref
-
- /**
- * Converts the signed value on top of the evaluation stack to signed int8 and
- * extends it to int32, throwing OverflowException on overflow.
- */
- final val Conv_Ovf_I1 = OpCode.Conv_Ovf_I1
-
- /**
- * Converts the signed value on top of the evaluation stack to signed int16 and
- * extending it to int32, throwing OverflowException on overflow.
- */
- final val Conv_Ovf_I2 = OpCode.Conv_Ovf_I2
-
- /**
- * Converts the signed value on top of the evaluation stack to signed int32,
- * throwing OverflowException on overflow.
- */
- final val Conv_Ovf_I4 = OpCode.Conv_Ovf_I4
-
- /**
- * Converts the signed value on top of the evaluation stack to signed int64,
- * throwing OverflowException on overflow.
- */
- final val Conv_Ovf_I8 = OpCode.Conv_Ovf_I8
-
- /**
- * Converts the signed value on top of the evaluation stack to unsigned int8 and
- * extends it to int32, throwing OverflowException on overflow.
- */
- final val Conv_Ovf_U1 = OpCode.Conv_Ovf_U1
-
- /**
- * Converts the signed value on top of the evaluation stack to unsigned int16 and
- * extends it to int32, throwing OverflowException on overflow.
- */
- final val Conv_Ovf_U2 = OpCode.Conv_Ovf_U2
-
- /**
- * Converts the signed value on top of the evaluation stack to unsigned int32,
- * throwing OverflowException on overflow.
- */
- final val Conv_Ovf_U4 = OpCode.Conv_Ovf_U4
-
- /**
- * Converts the signed value on top of the evaluation stack to unsigned int64,
- * throwing OverflowException on overflow.
- */
- final val Conv_Ovf_U8 = OpCode.Conv_Ovf_U8
-
- /**
- * Retrieves the address (type &) embedded in a typed reference.
- */
- final val Refanyval = OpCode.Refanyval
-
- /**
- * Retrieves the type token embedded in a typed reference .
- */
- final val Refanytype = OpCode.Refanytype
-
- /**
- * Throws ArithmeticException if value is not a finite number.
- */
- final val Ckfinite = OpCode.Ckfinite
-
- /**
- * Pushes a typed reference to an instance of a specific type onto the evaluation stack.
- */
- final val Mkrefany = OpCode.Mkrefany
-
- /**
- * Converts a metadata token to its runtime representation, pushing it onto the evaluation stack.
- */
- final val Ldtoken = OpCode.Ldtoken
-
- /**
- * Converts the value on top of the evaluation stack to unsigned int8, and extends it to int32.
- */
- final val Conv_U1 = OpCode.Conv_U1
-
- /**
- * Converts the value on top of the evaluation stack to unsigned int16, and extends it to int32.
- */
- final val Conv_U2 = OpCode.Conv_U2
-
- /**
- * Converts the value on top of the evaluation stack to natural int.
- */
- final val Conv_I = OpCode.Conv_I
-
- /**
- * Converts the signed value on top of the evaluation stack to signed natural int,
- * throwing OverflowException on overflow.
- */
- final val Conv_Ovf_I = OpCode.Conv_Ovf_I
-
- /**
- * Converts the signed value on top of the evaluation stack to unsigned natural int,
- * throwing OverflowException on overflow.
- */
- final val Conv_Ovf_U = OpCode.Conv_Ovf_U
-
- /**
- * Adds two integers, performs an overflow check, and pushes the result
- * onto the evaluation stack.
- */
- final val Add_Ovf = OpCode.Add_Ovf
-
- /**
- * Adds two unsigned integer values, performs an overflow check, and pushes the result
- * onto the evaluation stack.
- */
- final val Add_Ovf_Un = OpCode.Add_Ovf_Un
-
- /**
- * Multiplies two integer values, performs an overflow check, and pushes the result
- * onto the evaluation stack.
- */
- final val Mul_Ovf = OpCode.Mul_Ovf
-
- /**
- * Multiplies two unsigned integer values , performs an overflow check ,
- * and pushes the result onto the evaluation stack.
- */
- final val Mul_Ovf_Un = OpCode.Mul_Ovf_Un
-
- /**
- * Subtracts one integer value from another, performs an overflow check,
- * and pushes the result onto the evaluation stack.
- */
- final val Sub_Ovf = OpCode.Sub_Ovf
-
- /**
- * Subtracts one unsigned integer value from another, performs an overflow check,
- * and pushes the result onto the evaluation stack.
- */
- final val Sub_Ovf_Un = OpCode.Sub_Ovf_Un
-
- /**
- * Transfers control from the fault or finally clause of an exception block back to
- * the Common Language Infrastructure (CLI) exception handler.
- */
- final val Endfinally = OpCode.Endfinally
-
- /**
- * Exits a protected region of code, unconditionally tranferring control
- * to a specific target instruction.
- */
- final val Leave = OpCode.Leave
-
- /**
- * Exits a protected region of code, unconditionally tranferring control
- * to a target instruction (short form).
- */
- final val Leave_S = OpCode.Leave_S
-
- /**
- * Stores a value of type natural int at a supplied address.
- */
- final val Stind_I = OpCode.Stind_I
-
- /**
- * Converts the value on top of the evaluation stack to unsigned natural int,
- * and extends it to natural int.
- */
- final val Conv_U = OpCode.Conv_U
-
- /**
- * Returns an unmanaged pointer to the argument list of the current method.
- */
- final val Arglist = OpCode.Arglist
-
- /**
- * Compares two values. If they are equal, the integer value 1 (int32) is pushed
- * onto the evaluation stack otherwise 0 (int32) is pushed onto the evaluation stack.
- */
- final val Ceq = OpCode.Ceq
-
- /**
- * Compares two values. If the first value is greater than the second,
- * the integer value 1 (int32) is pushed onto the evaluation stack
- * otherwise 0 (int32) is pushed onto the evaluation stack.
- */
- final val Cgt = OpCode.Cgt
-
- /**
- * Compares two unsigned or unordered values. If the first value is greater than
- * the second, the integer value 1 (int32) is pushed onto the evaluation stack
- * otherwise 0 (int32) is pushed onto the evaluation stack.
- */
- final val Cgt_Un = OpCode.Cgt_Un
-
- /**
- * Compares two values. If the first value is less than the second,
- * the integer value 1 (int32) is pushed onto the evaluation stack
- * otherwise 0 (int32) is pushed onto the evaluation stack.
- */
- final val Clt = OpCode.Clt
-
- /**
- * Compares the unsigned or unordered values value1 and value2. If value1 is
- * less than value2, then the integer value 1 (int32) is pushed onto the
- * evaluation stack otherwise 0 (int32) is pushed onto the evaluation stack.
- */
- final val Clt_Un = OpCode.Clt_Un
-
- /**
- * Pushes an unmanaged pointer (type natural int) to the native code implementing
- * a specific method onto the evaluation stack.
- */
- final val Ldftn = OpCode.Ldftn
-
- /**
- * Pushes an unmanaged pointer (type natural int) to the native code implementing
- * a particular virtual method associated with a specified object onto the evaluation stack.
- */
- final val Ldvirtftn = OpCode.Ldvirtftn
-
- /**
- * Loads an argument (referenced by a specified index value) onto the stack.
- */
- final val Ldarg = OpCode.Ldarg
-
- /**
- * Load an argument address onto the evaluation stack.
- */
- final val Ldarga = OpCode.Ldarga
-
- /**
- * Loads the local variable at a specific index onto the evaluation stack.
- */
- final val Ldloc = OpCode.Ldloc
-
- /**
- * Loads the address of the local variable at a specific index onto the evaluation stack.
- */
- final val Ldloca = OpCode.Ldloca
-
- /**
- * Stores the value on top of the evaluation stack in the argument slot at a specified index.
- */
- final val Starg = OpCode.Starg
-
- /**
- * Pops the current value from the top of the evaluation stack and stores it in a
- * the local variable list at a specified index.
- */
- final val Stloc = OpCode.Stloc
-
- /**
- * Allocates a certain number of bytes from the local dynamic memory pool and pushes the
- * address (a transient pointer, type *) of the first allocated Byte onto the evaluation stack.
- */
- final val Localloc = OpCode.Localloc
-
- /**
- * Transfers control from the filter clause of an exception back to the
- * Common Language Infrastructure (CLI) exception handler.
- */
- final val Endfilter = OpCode.Endfilter
-
- /**
- * Indicates that an address currently atop the evaluation stack might not be aligned
- * to the natural size of the immediately following ldind, stind, ldfld, stfld, ldobj,
- * stobj, initblk, or cpblk instruction.
- */
- final val Unaligned = OpCode.Unaligned
-
- /**
- * Specifies that an address currently atop the evaluation stack might be volatile,
- * and the results of reading that location cannot be cached or that multiple stores
- * to that location cannot be suppressed.
- */
- final val Volatile = OpCode.Volatile
-
- /**
- * Performs a postfixed method call instruction such that the current method's stack
- * frame is removed before the actual call instruction is executed.
- */
- final val Tailcall = OpCode.Tailcall
-
- /**
- * Initializes all the fields of the object at a specific address to a null reference
- * or a 0 of the appropriate primitive type.
- */
- final val Initobj = OpCode.Initobj
-
- /**
- * Copies a specified number bytes from a source address to a destination address .
- */
- final val Cpblk = OpCode.Cpblk
-
- /**
- * Initializes a specified block of memory at a specific address to a given size
- * and initial value.
- */
- final val Initblk = OpCode.Initblk
-
- /**
- * Rethrows the current exception.
- */
- final val Rethrow = OpCode.Rethrow
-
- /**
- * Pushes the size, in bytes, of a supplied value type onto the evaluation stack.
- */
- final val Sizeof = OpCode.Sizeof
-
- //##########################################################################
-}
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/emit/ParameterBuilder.scala b/src/msil/ch/epfl/lamp/compiler/msil/emit/ParameterBuilder.scala
deleted file mode 100644
index 8f9d81a8b0..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/emit/ParameterBuilder.scala
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * System.Reflection.Emit-like API for writing .NET assemblies to MSIL
- */
-
-
-package ch.epfl.lamp.compiler.msil.emit
-
-import ch.epfl.lamp.compiler.msil.Type
-import ch.epfl.lamp.compiler.msil.ConstructorInfo
-import ch.epfl.lamp.compiler.msil.ParameterInfo
-import java.io.IOException
-
-/**
- * Creates or associates parameter information.
- * Parameter attributes need to consistent with the method signature.
- * If you specify Out attributes for a parameter, you should ensure that
- * the type of that method parameter is a ByRef type
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-class ParameterBuilder(name: String, tpe: Type, attr: Int, pos: Int)
- extends ParameterInfo(name, tpe, attr, pos)
- with ICustomAttributeSetter
- with Visitable
-{
-
- //##########################################################################
-
- /** Sets a custom attribute. */
- def SetCustomAttribute(constr: ConstructorInfo, value: Array[Byte]) {
- addCustomAttribute(constr, value)
- }
-
- //##########################################################################
-
- /** The apply method for a visitor */
- @throws(classOf[IOException])
- def apply(v: Visitor) {
- v.caseParameterBuilder(this)
- }
-
- //##########################################################################
-}
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/emit/SingleFileILPrinterVisitor.scala b/src/msil/ch/epfl/lamp/compiler/msil/emit/SingleFileILPrinterVisitor.scala
deleted file mode 100644
index 5d59d4d25a..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/emit/SingleFileILPrinterVisitor.scala
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * System.Reflection.Emit-like API for writing .NET assemblies in MSIL
- */
-
-
-package ch.epfl.lamp.compiler.msil.emit
-
-import java.io.FileWriter
-import java.io.BufferedWriter
-import java.io.PrintWriter
-import java.io.IOException
-import java.util.Iterator
-import java.util.HashMap
-import java.util.Arrays
-
-import ch.epfl.lamp.compiler.msil._
-import ch.epfl.lamp.compiler.msil.emit
-import ch.epfl.lamp.compiler.msil.util.Table
-
-/**
- * The MSIL printer Visitor. It prints a complete
- * assembly in a single file that can be compiled by ilasm.
- *
- * @author Nikolay Mihaylov
- * @author Daniel Lorch
- * @version 1.0
- */
-final class SingleFileILPrinterVisitor(_fileName: String) extends ILPrinterVisitor {
- var fileName: String = _fileName
-
- out = new PrintWriter(new BufferedWriter(new FileWriter(fileName)))
-
- /**
- * Visit an AssemblyBuilder
- */
- @throws(classOf[IOException])
- def caseAssemblyBuilder(assemblyBuilder: AssemblyBuilder) {
- ILPrinterVisitor.currAssembly = assemblyBuilder
-
- // first get the entryPoint
- this.entryPoint = assemblyBuilder.EntryPoint
-
- // all external assemblies
- as = assemblyBuilder.getExternAssemblies()
- scala.util.Sorting.quickSort(as)(assemblyNameComparator) // Arrays.sort(as, assemblyNameComparator)
-
- assemblyBuilder.generatedFiles += fileName
- printAssemblyBoilerplate()
-
- // print each module
- var m: Array[Module] = assemblyBuilder.GetModules()
- nomembers = true
- for(i <- 0 until m.length) {
- print(m(i).asInstanceOf[ModuleBuilder])
- }
-
- nomembers = false
- for(i <- 0 until m.length) {
- print(m(i).asInstanceOf[ModuleBuilder])
- }
- // close out file
- out.close()
- ILPrinterVisitor.currAssembly = null
- }
-
- /**
- * Visit a ModuleBuilder
- */
- @throws(classOf[IOException])
- def caseModuleBuilder(module: ModuleBuilder) {
- // print module declaration
- currentModule = module
- if (nomembers) {
- print(".module \'"); print(module.Name); println("\'")
- printAttributes(module)
- }
-
- if (!module.globalsCreated)
- module.CreateGlobalFunctions()
-
- var m: Array[MethodInfo] = module.GetMethods()
- for(i <- 0 until m.length) {
- print(m(i).asInstanceOf[MethodBuilder])
- }
-
- var t: Array[Type] = module.GetTypes()
- for(i <- 0 until t.length) {
- print(t(i).asInstanceOf[TypeBuilder])
- }
- currentModule = null
- }
-
-} // class SingleFileILPrinterVisitor
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/emit/TypeBuilder.scala b/src/msil/ch/epfl/lamp/compiler/msil/emit/TypeBuilder.scala
deleted file mode 100644
index 57dc883898..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/emit/TypeBuilder.scala
+++ /dev/null
@@ -1,261 +0,0 @@
-/*
- * System.Reflection.Emit-like API for writing .NET assemblies to MSIL
- */
-
-
-package ch.epfl.lamp.compiler.msil.emit
-
-import ch.epfl.lamp.compiler.msil._
-
-import ch.epfl.lamp.compiler.msil.util.PECustomMod
-
-import java.io.IOException
-
-/**
- * Defines and creates new instances of classes during runtime.
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-class TypeBuilder (module: Module, attributes: Int, fullName: String, baseType: Type, interfaces: Array[Type], declType: Type)
- extends Type(module, attributes, fullName, baseType, interfaces, declType, 0)
- with ICustomAttributeSetter
- with Visitable
-{
- import TypeBuilder._
-
- //##########################################################################
- // public members
-
- /** 'Bakes' the type. */
- def CreateType(): Type = {
- fields = fieldBuilders.toArray // (new Array[FieldInfo](fieldBuilders.size())).asInstanceOf[Array[FieldInfo]]
- methods = methodBuilders.toArray // (new Array[MethodInfo](methodBuilders.size())).asInstanceOf[Array[MethodInfo]]
- constructors = constructorBuilders.toArray // (new Array[ConstructorInfo](constructorBuilders.size())).asInstanceOf[Array[ConstructorInfo]]
- nestedTypes = nestedTypeBuilders.toArray // (new Array[Type](nestedTypeBuilders.size())).asInstanceOf[Array[Type]]
-
- raw = false
- if (DeclaringType == null)
- Module.asInstanceOf[ModuleBuilder].addType(this)
- return this
- }
-
- /**
- * Adds a new field to the class, with the given name, attributes and field type. The location has no custom mods.
- */
- def DefineField(name: String, fieldType: Type, attrs: Short): FieldBuilder = {
- val fieldTypeWithCustomMods = new PECustomMod(fieldType, null)
- DefineField(name, fieldTypeWithCustomMods, attrs)
- }
-
- /**
- * Adds a new field to the class, with the given name, attributes and (field type , custom mods) combination.
- */
- def DefineField(name: String, fieldTypeWithMods: PECustomMod, attrs: Short): FieldBuilder = {
- val field: FieldBuilder = new FieldBuilder(name, this, attrs, fieldTypeWithMods)
- fieldBuilders += field
- return field
- }
-
- /**
- * Adds a new method to the class, with the given name and
- * method signature.
- */
- def DefineMethod(name: String, attrs: Short, returnType: Type, paramTypes: Array[Type]): MethodBuilder = {
- val method = new MethodBuilder(name, this, attrs, returnType, paramTypes)
- val methods = methodBuilders.iterator
- while(methods.hasNext) {
- val m = methods.next().asInstanceOf[MethodInfo]
- if (methodsEqual(m, method)) {
- throw new RuntimeException("["+ Assembly() + "] Method has already been defined: " + m)
- }
- }
- methodBuilders += method
- return method
- }
-
- /**
- * Adds a new constructor to the class, with the given attributes
- * and signature.
- */
- def DefineConstructor(attrs: Short, callingConvention: Short, paramTypes: Array[Type]): ConstructorBuilder = {
- val constr = new ConstructorBuilder(this, attrs, paramTypes)
- val iter = constructorBuilders.iterator
- while(iter.hasNext) {
- val c = iter.next().asInstanceOf[ConstructorInfo]
- if (constructorsEqual(c, constr)) {
- throw new RuntimeException("["+ Assembly() + "] Constructor has already been defined: " + c)
- }
- }
- constructorBuilders += constr
- return constr
- }
-
- /**
- * Defines a nested type given its name.
- */
- def DefineNestedType(name: String, attributes: Int, baseType: Type, interfaces: Array[Type]): TypeBuilder = {
- val nested = nestedTypeBuilders.iterator
- while(nested.hasNext) {
- val nt = nested.next
- if (nt.Name.equals(name)) {
- val message = "Nested type " + name + " has already been defined: " + nt
- throw new RuntimeException(message)
- }
- }
- val t = new TypeBuilder(Module, attributes, name, baseType, interfaces, this)
- nestedTypeBuilders += t
- return t
- }
-
- /** Get the field with the corresponding name. */
- override def GetField(name: String): FieldInfo = {
- testRaw(name)
- return super.GetField(name)
- }
-
- /** Get all fields of the current Type. */
- override def GetFields(): Array[FieldInfo] = {
- testRaw("<GetFields>")
- return super.GetFields()
- }
-
- /**
- * Searches for a public instance constructor whose parameters
- * match the types in the specified array.
- */
- override def GetConstructor(params: Array[Type]): ConstructorInfo = {
- testRaw(".ctor" + types2String(params))
- return super.GetConstructor(params)
- }
-
- /**
- * Returns all the public constructors defined for the current Type.
- */
- override def GetConstructors(): Array[ConstructorInfo] = {
- testRaw("<GetConstructors>")
- return super.GetConstructors()
- }
-
- /**
- * Searches for the specified public method whose parameters
- * match the specified argument types.
- */
- override def GetMethod(name: String, params: Array[Type]): MethodInfo = {
- testRaw(name + types2String(params))
- return super.GetMethod(name, params)
- }
-
- /** Returns all the public methods of the current Type. */
- override def GetMethods(): Array[MethodInfo] = {
- testRaw("<GetMethods>")
- return super.GetMethods()
- }
-
- /** Searches for the nested type with the specified name. */
- override def GetNestedType(name: String): Type = {
- testRaw(name)
- super.GetNestedType(name)
- }
-
- /** Returns all the types nested within the current Type. */
- override def GetNestedTypes(): Array[Type] = {
- testRaw("<GetNestedTypes>")
- super.GetNestedTypes()
- }
-
- /** Returns a Type object that represents a one-dimensional array of the current type */
- def MakeArrayType(): Type = {
- Type.mkArray(this, 1)
- }
-
- /** Sets a custom attribute. */
- def SetCustomAttribute(constr: ConstructorInfo, value: Array[Byte]) {
- addCustomAttribute(constr, value)
- }
-
- def setPosition(sourceLine: Int, sourceFilename: String) {
- this.sourceLine = sourceLine
- this.sourceFilename = sourceFilename
- }
-
- def setSourceFilepath(sourceFilepath: String) {
- this.sourceFilepath = sourceFilepath
- }
-
- //##########################################################################
- // protected members
-
- var sourceLine: Int = _
- var sourceFilename: String = _
- var sourceFilepath: String = _
-
- var fieldBuilders = scala.collection.mutable.ArrayBuffer.empty[FieldBuilder]
- var methodBuilders = scala.collection.mutable.ArrayBuffer.empty[MethodBuilder]
- var constructorBuilders = scala.collection.mutable.ArrayBuffer.empty[ConstructorBuilder]
- var nestedTypeBuilders = scala.collection.mutable.ArrayBuffer.empty[TypeBuilder]
-
- // shows if the type is 'raw', i.e. still subject to changes
- private var raw = true
-
- // throws an exception if the type is 'raw',
- // i.e. not finalized by call to CreateType
- protected def testRaw(member: String) {
- if (raw)
- throw new RuntimeException("Not supported for TypeBuilder before CreateType(): " +
- FullName + "::" + member)
- }
-
- //##########################################################################
- // public members not part of the Reflection.Emit.TypeBuilder interface.
-
- /** The apply method for a visitor. */
- @throws(classOf[IOException])
- def apply(v: Visitor) {
- v.caseTypeBuilder(this)
- }
-
- //##########################################################################
-
-} // class TypeBuilder
-
-object TypeBuilder {
- def types2String(types: Array[Type]): String = {
- var s = new StringBuffer("(")
- for(i <- 0 until types.length) {
- if (i > 0) s.append(", ")
- s.append(types(i))
- }
- s.append(")")
- return s.toString()
- }
-
- def methodsEqual(m1: MethodInfo, m2: MethodInfo): Boolean = {
- if (!m1.Name.equals(m2.Name))
- return false
- if (m1.ReturnType != m2.ReturnType)
- return false
- val p1 = m1.GetParameters()
- val p2 = m2.GetParameters()
- if (p1.length != p2.length)
- return false
- for(i <- 0 until p1.length)
- if (p1(i).ParameterType != p2(i).ParameterType)
- return false
- return true
- }
-
- def constructorsEqual(c1: ConstructorInfo, c2: ConstructorInfo): Boolean = {
- if (c1.IsStatic != c2.IsStatic)
- return false
- val p1 = c1.GetParameters()
- val p2 = c2.GetParameters()
- if (p1.length != p2.length)
- return false
- for(i <- 0 until p1.length)
- if (p1(i).ParameterType != p2(i).ParameterType)
- return false
- return true
-}
-
-}
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/emit/Visitable.scala b/src/msil/ch/epfl/lamp/compiler/msil/emit/Visitable.scala
deleted file mode 100644
index 28ec801dd4..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/emit/Visitable.scala
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * System.Reflection.Emit-like API for writing .NET assemblies to MSIL
- */
-
-
-package ch.epfl.lamp.compiler.msil.emit
-
-import java.io.IOException
-
-/**
- * The Visitable interface
- */
-trait Visitable {
-
- //##########################################################################
-
- /**
- * the visitable method to apply a visitor
- */
- @throws(classOf[IOException])
- def apply(v: Visitor): Unit
-
- //##########################################################################
-}
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/emit/Visitor.scala b/src/msil/ch/epfl/lamp/compiler/msil/emit/Visitor.scala
deleted file mode 100644
index d4b84cdd4e..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/emit/Visitor.scala
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * System.Reflection.Emit-like API for writing .NET assemblies to MSIL
- */
-
-
-package ch.epfl.lamp.compiler.msil.emit
-
-import java.io.IOException
-
-/**
- * The Visitor interface to walk through the MSIL code Builder hierarchy.
- */
-trait Visitor {
-
- //##########################################################################
-
- /** Visit an AssemblyBuilder */
- @throws(classOf[IOException])
- def caseAssemblyBuilder(assemblyBuilder: AssemblyBuilder): Unit
-
- /** Visit a ModuleBuilder */
- @throws(classOf[IOException])
- def caseModuleBuilder(moduleBuilder: ModuleBuilder): Unit
-
- /** Visit a TypeBuilder */
- @throws(classOf[IOException])
- def caseTypeBuilder(typeBuilder: TypeBuilder): Unit
-
- /** Visit a FieldBuilder */
- @throws(classOf[IOException])
- def caseFieldBuilder(fieldBuilder: FieldBuilder): Unit
-
- /** Visit a ConstructorBuilder */
- @throws(classOf[IOException])
- def caseConstructorBuilder(constructorBuilder: ConstructorBuilder): Unit
-
- /** Visit a MethodBuilder */
- @throws(classOf[IOException])
- def caseMethodBuilder(methodBuilder: MethodBuilder): Unit
-
- /** Visit a ParameterBuilder */
- @throws(classOf[IOException])
- def caseParameterBuilder(parameterBuilder: ParameterBuilder): Unit
-
- /** Visit an ILGenerator */
- @throws(classOf[IOException])
- def caseILGenerator(iLGenerator: ILGenerator): Unit
-
- /** Visit an OpCode */
- @throws(classOf[IOException])
- def caseOpCode(opCode: OpCode): Unit
-
- /** Visit a LocalBuilder */
- @throws(classOf[IOException])
- def caseLocalBuilder(localBuilder: LocalBuilder): Unit
-
- //##########################################################################
-}
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/tests/CustomAttributesTest.java b/src/msil/ch/epfl/lamp/compiler/msil/tests/CustomAttributesTest.java
deleted file mode 100644
index 9a6e28a545..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/tests/CustomAttributesTest.java
+++ /dev/null
@@ -1,31 +0,0 @@
-
-package ch.epfl.lamp.compiler.msil.tests;
-
-import ch.epfl.lamp.compiler.msil.*;
-import ch.epfl.lamp.compiler.msil.util.Table;
-
-import java.io.PrintStream;
-
-public class CustomAttributesTest {
- public static void main(String[] args) {
- if (args.length < 1) {
- System.err.println("You must supply a filename!");
- System.exit(1);
- }
-
- Assembly assem = Assembly.LoadFrom(args[0]);
- Type.initMSCORLIB(assem);
-
- testCustomAttributes();
- }
-
- public static void testCustomAttributes() {
- Object[] attrs = Type.GetType("System.ObsoleteAttribute")
- .GetCustomAttributes(false);
- assert attrs != null;
- for (int i = 0; i < attrs.length; i++) {
- System.out.println("\t" + attrs[i]);
- }
- }
-
-}
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/tests/JavaTypeTest.java b/src/msil/ch/epfl/lamp/compiler/msil/tests/JavaTypeTest.java
deleted file mode 100644
index 96ec1bfeea..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/tests/JavaTypeTest.java
+++ /dev/null
@@ -1,18 +0,0 @@
-
-package ch.epfl.lamp.compiler.msil.tests;
-
-import ch.epfl.lamp.compiler.msil.*;
-import ch.epfl.lamp.compiler.msil.util.VJSAssembly;
-
-public class JavaTypeTest {
-
- public static void main(String[] args) {
- if (args.length < 1) {
- System.err.println("usage: java test.JavaTypeTest classname");
- System.exit(1);
- }
-
- Type type = VJSAssembly.VJSLIB.GetType(args[0]);
- MembersTest.dumpType(System.out, type);
- }
-}
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/tests/MembersTest.java b/src/msil/ch/epfl/lamp/compiler/msil/tests/MembersTest.java
deleted file mode 100644
index 37a5c6ea90..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/tests/MembersTest.java
+++ /dev/null
@@ -1,100 +0,0 @@
-
-package ch.epfl.lamp.compiler.msil.tests;
-
-import ch.epfl.lamp.compiler.msil.*;
-import ch.epfl.lamp.compiler.msil.util.Table;
-
-import java.io.PrintStream;
-
-public class MembersTest {
-
- public static void main(String[] args) {
- if (args.length < 1) {
- System.err.println
- ("usage: java test.MembersTest assembly [classname]");
- System.exit(1);
- }
-
- Assembly mscorlib = Assembly.LoadFrom("mscorlib.dll");
- Type.initMSCORLIB(mscorlib);
- Assembly assem = Assembly.LoadFrom(args[0]);
- if (args.length > 1) {
- Type type = assem.GetType(args[1]);
- if (type != null)
- dumpMember(System.out, type);
- else System.err.println("Cannot find type " + args[1]
- + " in " + assem);
- } else {
- Type[] types = assem.GetTypes();
- System.out.println("Number of types in assembly " + assem
- + " -> " + types.length);
- dumpCustomAttributes(System.out, "assembly: ", assem);
- Module[] modules = assem.GetModules();
- for (int i = 0; i < modules.length; i++) {
- dumpCustomAttributes(System.out, "module " + modules[i] + ": ",
- modules[i]);
- }
- dumpMembers(System.out, types);
- }
- }
-
- public static final void dumpMember(PrintStream out, MemberInfo member) {
- try {
- if (member.MemberType() == MemberTypes.TypeInfo
- || member.MemberType() == MemberTypes.NestedType) {
- Type type = (Type)member;
- dumpCustomAttributes(out, "", type);
- out.print(TypeAttributes.accessModsToString(type.Attributes));
- out.print(type.IsInterface() ? " interface " : " class ");
- out.print(type);
- if (type.BaseType() != null)
- out.println(" extends " + type.BaseType());
- Type[] ifaces = type.GetInterfaces();
- if (ifaces.length > 0) {
- out.print("\timplements ");
- for (int i = 0; i < ifaces.length; i++) {
- out.print(ifaces[i]);
- if (i < (ifaces.length - 1))
- out.print(", ");
- }
- out.println();
- }
- out.println("{");
- int all = BindingFlags.Public | BindingFlags.DeclaredOnly// | BindingFlags.NonPublic
- | BindingFlags.Instance | BindingFlags.Static;
- dumpMembers(out, type.GetNestedTypes());
- dumpMembers(out, type.GetFields(all));
- dumpMembers(out, type.GetConstructors(all));
- dumpMembers(out, type.GetMethods(all));
- dumpMembers(out, type.GetProperties(all));
- dumpMembers(out, type.GetEvents());
- out.println("}");
- } else {
- dumpCustomAttributes(out, "", member);
- out.print(MemberTypes.toString(member.MemberType()));
- out.print(": "); out.print(member);
- out.println();
- }
- } catch (Throwable e) {
- String message = MemberTypes.toString(member.MemberType())
- + ": " + member;
- throw new RuntimeException(message, e);
- }
- }
-
- public static void dumpCustomAttributes(PrintStream out,
- String prefix,
- ICustomAttributeProvider att)
- {
- Object[] attrs = att.GetCustomAttributes(false);
- for (int j = 0; j < attrs.length; j++)
- out.println(prefix + attrs[j]);
- }
-
- public static void dumpMembers(PrintStream out, MemberInfo[] members) {
- for (int i = 0; i < members.length; i++) {
- dumpMember(out, members[i]);
- }
- }
-
-}
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/tests/TableDump.java b/src/msil/ch/epfl/lamp/compiler/msil/tests/TableDump.java
deleted file mode 100644
index 1df389b011..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/tests/TableDump.java
+++ /dev/null
@@ -1,311 +0,0 @@
-
-package ch.epfl.lamp.compiler.msil.tests;
-
-import ch.epfl.lamp.compiler.msil.PEFile;
-import ch.epfl.lamp.compiler.msil.util.Table;
-import ch.epfl.lamp.compiler.msil.util.Table.*;
-
-import java.io.PrintStream;
-import java.io.FileNotFoundException;
-
-public class TableDump extends PEFile {
-
- //##########################################################################
-
- public TableDump(String filename) throws FileNotFoundException {
- super(filename);
- }
-
- /***/
- public void dump(PrintStream out) {
- out.println("CLI RVA: " + CLI_RVA);
- out.println("Optional header size: " + optHeaderSize);
- out.println("Number of sections: " + numOfSections);
- out.println();
-
- for (int i = 0; i < sections.length; i++) {
- sections[i].dump(out);
- out.println();
- }
-
- out.println("MetaData Offset: 0x" + Integer.toHexString(posMetadata));
- out.println("Number of streams: " + numOfStreams);
-
- out.println("#~ stream"); Meta.dump(out); out.println();
- out.println("#Strings stream"); Strings.dump(out); out.println();
- if (US != null) {
- out.println("#US stream"); US.dump(out); out.println();
- }
- out.println("#GUID stream"); GUID.dump(out); out.println();
- out.println("#Blob stream"); Blob.dump(out); out.println();
-
- out.println("Heap Sizes IndexedSeq = 0x0" + Integer.toHexString(heapSizes));
- out.println();
-
- for(int i = 0; i < Table.MAX_NUMBER; i++)
- if(getTable(i).rows > 0) {
- dump(out, getTable(i));
- out.println();
- }
-
- }
-
- /** Dumps the contents of this table. */
- public void dump(PrintStream out, Table table) {
- out.println("Table:" + " ID = 0x" + byte2hex(table.id));
- out.println("\tname = " + table.getTableName());
- out.println("\trows = " + table.rows);
- //out.println("\tStart pos in file = 0x" + Long.toHexString(table.start));
- for (int i = 1; i <= table.rows; i++)
- dumpRow(out, table, i);
- }
-
- public void dumpIndex(PrintStream out, int tableSetId, int index) {
- int tableId = Table.getTableId(tableSetId, index);
- int row = Table.getTableIndex(tableSetId, index);
- out.print(getTable(tableId).getTableName());
- out.print('[');
- out.print(getTable(tableId).isShort ? short2hex(row) : int2hex(row));
- out.print(']');
- }
-
- public void dumpRow(PrintStream out, Table table, int row) {
- table.readRow(row);
- out.print(table.getTableName());
- out.print("[" + short2hex(row) + "]: ");
- dumpRow(out, table);
- out.println();
- }
-
- /** Prints the current content of the fields of the class. */
- public void dumpRow(PrintStream out, Table table) {
- if (table instanceof ModuleDef) {
- ModuleDef t = (ModuleDef)table;
- out.print("Generation = 0x" + short2hex(t.Generation));
- out.print("; Name = " + getString(t.Name));
- //out.print("; Mvid = (" + bytes2hex(getGUID(Mvid)) + ")");
- } else if (table instanceof TypeRef) {
- TypeRef t = (TypeRef)table;
- out.print("FullName = " + t.getFullName());
- out.print("; ResolutionScope = 0x" + int2hex(t.ResolutionScope));
- } else if (table instanceof TypeDef) {
- TypeDef t = (TypeDef)table;
- out.print("Flags = 0x"); out.print(int2hex(t.Flags));
- out.print("; FullName = "); out.print(t.getFullName());
- out.print("; Extends = ");
- dumpIndex(out, Table._TypeDefOrRef, t.Extends);
- out.print("; FieldList = "); out.print(t.FieldList);
- out.print("; MethodList = "); out.print(t.MethodList);
- } else if (table instanceof FieldTrans) {
- FieldTrans t = (FieldTrans)table;
- out.print("Field = "); out.print(t.Field);
- } else if (table instanceof FieldDef) {
- FieldDef t = (FieldDef)table;
- out.print("Flags = 0x" + short2hex(t.Flags));
- out.print("; Name = " + t.getName());
- out.print("; Signature = (" +
- bytes2hex(getBlob(t.Signature)) + ")");
- } else if (table instanceof MethodTrans) {
- MethodTrans t = (MethodTrans)table;
- out.print("Method = "); out.print(t.Method);
- } else if (table instanceof MethodDef) {
- MethodDef t = (MethodDef)table;
- out.print("Flags = 0x" + short2hex(t.Flags));
- out.print("; Name = " + t.getName());
- out.print("; ParamList = " + t.ParamList);
- out.print("; Signature = (" +
- bytes2hex(getBlob(t.Signature)) + ")");
- } else if (table instanceof ParamDef) {
- ParamDef t = (ParamDef)table;
- out.print("Flags = 0x" + short2hex(t.Flags));
- out.print("; Name = " + t.getName());
- out.print("; Sequence = " + t.Sequence);
- } else if (table instanceof InterfaceImpl) {
- InterfaceImpl t = (InterfaceImpl)table;
- out.print("Class = 0x" + short2hex(t.Class));// + " (ref to: ");
- //TypeDef td = (TypeDef) getTable(TypeDef.ID);
- //td.readRow(Class);
- //td.dumpRow(out);
- out.print("; Interface = 0x" + short2hex(t.Interface));
- } else if (table instanceof MemberRef) {
- MemberRef t = (MemberRef)table;
- out.print("Name = " + t.getName());
- out.print("; Signature = (" +
- bytes2hex(getBlob(t.Signature)) + ")");
- out.print("; Class = " + t.Class);
- } else if (table instanceof Constant) {
- Constant t = (Constant)table;
- out.print("Parent = "); dumpIndex(out, Table._HasConstant, t.Parent);
- out.print("; Type = 0x" + byte2hex(t.Type));
- out.print("; Value = (" + bytes2hex(getBlob(t.Value)));
- out.print("); Value = " + t.getValue());
- } else if (table instanceof CustomAttribute) {
- CustomAttribute t = (CustomAttribute)table;
- //out.print("Parent = 0x" + int2hex(t.Parent));
- out.print("Parent = ");
- dumpIndex(out, Table._HasCustomAttribute, t.Parent);
- //out.print("; Type = 0x" + short2hex(t.Type));
- out.print("; Type = ");
- dumpIndex(out, Table._CustomAttributeType, t.Type);
- out.print("; Value = (" + bytes2hex(t.getValue()) + ")");
- } else if (table instanceof FieldMarshal) {
- FieldMarshal t = (FieldMarshal)table;
- out.print("NativeType = (");
- out.print(bytes2hex(getBlob(t.NativeType)) + ")");
- } else if (table instanceof DeclSecurity) {
- DeclSecurity t = (DeclSecurity)table;
- out.print("Action = 0x" + short2hex(t.Action));
- out.print("; PermissionSet = (" +
- bytes2hex(getBlob(t.PermissionSet)) + ")");
- } else if (table instanceof ClassLayout) {
- ClassLayout t = (ClassLayout)table;
- out.print("PackingSize = 0x" + short2hex(t.PackingSize));
- out.print("; ClassSize = 0x" + int2hex(t.ClassSize));
- out.print(": Parent = " + t.Parent + " (ref to: ");
- dumpRow(out, this.TypeDef(t.Parent));
- out.print(")");
- } else if (table instanceof FieldLayout) {
- FieldLayout t = (FieldLayout)table;
- out.print("Offset = 0x" + int2hex(t.Offset));
- out.print("; Field = (ref to: ");
- dumpRow(out, this.FieldDef(t.Field));
- out.print(")");
- } else if (table instanceof StandAloneSig) {
- StandAloneSig t = (StandAloneSig)table;
- out.print("StandAloneSig: Signature = (" +
- bytes2hex(getBlob(t.Signature)) + ")");
- } else if (table instanceof EventMap) {
- EventMap t = (EventMap)table;
- out.print("Parent = 0x" + int2hex(t.Parent) + " (ref to: ");
- dumpRow(out, this.TypeDef(t.Parent));
- out.print("); EventList = 0x"); out.print(int2hex(t.EventList));
- } else if (table instanceof EventDef) {
- EventDef t = (EventDef)table;
- out.print("EventFlags = 0x" + short2hex(t.EventFlags));
- out.print("; Name = " + t.getName());
- out.print("; EventType = 0x" + int2hex(t.EventType));
- } else if (table instanceof PropertyMap) {
- PropertyMap t = (PropertyMap)table;
- out.print("Parent = " + t.Parent + " (ref to: ");
- dumpRow(out, this.TypeDef(t.Parent));
- out.print(")");
- } else if (table instanceof PropertyDef) {
- PropertyDef t = (PropertyDef)table;
- out.print("Flags = 0x" + short2hex(t.Flags));
- out.print("; Name = " + t.getName());
- out.print("; Type = (" + bytes2hex(getBlob(t.Type)) + ")");
- } else if (table instanceof MethodSemantics) {
- MethodSemantics t = (MethodSemantics)table;
- out.print("Semantics = 0x" + short2hex(t.Semantics));
- out.print("; Method = 0x" + int2hex(t.Method) + " (ref to: ");
- dumpRow(out, this.MethodDef(t.Method));
- out.print("); Association = 0x" + int2hex(t.Association));
- } else if (table instanceof MethodImpl) {
- MethodImpl t = (MethodImpl)table;
- out.print("Class = (ref to: ");
- dumpRow(out, this.TypeDef(t.Class));
- out.print(")");
- } else if (table instanceof ModuleRef) {
- ModuleRef t = (ModuleRef)table;
- out.print("Name = " + t.getName());
- } else if (table instanceof TypeSpec) {
- TypeSpec t = (TypeSpec)table;
- out.print("Signature = (" +
- bytes2hex(getBlob(t.Signature)) + ")");
- } else if (table instanceof ImplMap) {
- ImplMap t = (ImplMap)table;
- out.print("ImportName = " + getString(t.ImportName));
- } else if (table instanceof FieldRVA) {
- FieldRVA t = (FieldRVA)table;
- out.print("RVA = 0x" + int2hex(t.RVA));
- out.print("; Field = (ref to: ");
- dumpRow(out, this.FieldDef(t.Field));
- out.print(")");
- } else if (table instanceof AssemblyDef) {
- AssemblyDef t = (AssemblyDef)table;
- out.print("Flags = 0x" + int2hex(t.Flags));
- out.print(" ; Name = " + getString(t.Name));
- out.print("; Culture = " + getString(t.Culture));
- out.print(" ; Version = " + t.MajorVersion + ".");
- out.print(t.MinorVersion + "." + t.BuildNumber);
- out.print("." + t.RevisionNumber);
- out.print("; HashAlgId = 0x" + int2hex(t.HashAlgId));
- out.print("; PublicKey = (");
- out.print(bytes2hex(getBlob(t.PublicKey)) + ")");
- } else if (table instanceof AssemblyProcessor) {
- AssemblyProcessor t = (AssemblyProcessor)table;
- out.print("Processor = 0x" + int2hex(t.Processor));
- } else if (table instanceof AssemblyOS) {
- AssemblyOS t = (AssemblyOS)table;
- out.print("!?!");
- } else if (table instanceof AssemblyRef) {
- AssemblyRef t = (AssemblyRef)table;
- out.print("Flags = 0x" + int2hex(t.Flags));
- out.print("; Name = " + getString(t.Name));
- out.print("; Culture = " + getString(t.Culture));
- out.print("; Version = " + t.MajorVersion + "." + t.MinorVersion);
- out.print("." + t.BuildNumber + "." + t.RevisionNumber);
- out.print("; PublicKeyOrToken = (" +
- bytes2hex(getBlob(t.PublicKeyOrToken)) + ")");
- out.print("; HashValue = (" +
- bytes2hex(getBlob(t.HashValue)) + ")");
- } else if (table instanceof AssemblyRefProcessor) {
- AssemblyRefProcessor t = (AssemblyRefProcessor)table;
- out.print("!?!");
- } else if (table instanceof AssemblyRefOS) {
- AssemblyRefOS t = (AssemblyRefOS)table;
- out.print("!?!");
- } else if (table instanceof FileDef) {
- FileDef t = (FileDef)table;
- out.print("Flags = 0x" + int2hex(t.Flags));
- out.print("; Name = " + t.getName());
- out.print("; HashValue = (" + bytes2hex(getBlob(t.HashValue)) +")");
- } else if (table instanceof ExportedType) {
- ExportedType t = (ExportedType)table;
- out.print("FullName = " + t.getFullName());
- } else if (table instanceof ManifestResource) {
- ManifestResource t = (ManifestResource)table;
- out.print("Name = " + getString(t.Name));
- out.print("; Flags = 0x" + int2hex(t.Flags));
- } else if (table instanceof NestedClass) {
- NestedClass t = (NestedClass)table;
- out.print(this.TypeDef(t.EnclosingClass).getFullName());
- out.print("/");
- out.print(this.TypeDef(t.NestedClass).getFullName());
- } else
- throw new RuntimeException("Unknown table " + table.getClass());
- }
-
- //##########################################################################
-
- public static void main(String[] args) {
- if (args.length < 1) {
- System.err.println("You must supply a filename!");
- System.exit(1);
- }
-
- TableDump file = null;
- try {
- file = new TableDump(args[0]);
- } catch (FileNotFoundException e) { e.printStackTrace(); }
-
- if (args.length > 1) {
- nextarg:
- for (int i = 1; i < args.length; i++) {
- String name = args[i];
- for (int tableId = 0; tableId < Table.MAX_NUMBER; tableId++) {
- Table table = file.getTable(tableId);
- if ((table.rows > 0) && name.equals(table.getTableName())) {
- file.dump(System.out, table);
- System.out.println();
- continue nextarg;
- }
- }
- System.err.println("No such table: " + name);
- }
- } else
- file.dump(System.out);
- }
-
- //##########################################################################
-}
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/tests/Test.java b/src/msil/ch/epfl/lamp/compiler/msil/tests/Test.java
deleted file mode 100644
index 2c5946a734..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/tests/Test.java
+++ /dev/null
@@ -1,92 +0,0 @@
-
-package test;
-
-import ch.epfl.lamp.compiler.msil.*;
-import ch.epfl.lamp.compiler.msil.util.Table;
-
-import java.io.PrintStream;
-
-public class Test {
- public static void main(String[] args) {
- if (args.length < 1) {
- System.err.println("You must supply a filename!");
- System.exit(1);
- }
-
- Assembly assem = Assembly.LoadFrom(args[0]);
- Type.initMSCORLIB(assem);
-
- //"System.Collections.ArrayList"
- if (args.length >= 2) {
- Type t = Type.GetType(args[1]);
- dumpType(System.out, t);
- } else {
- dumpAssembly(assem);
- }
- }
-
-
- public static void dumpAssembly(Assembly assem) {
- Module[] modules = assem.GetModules();
-// System.out.println("Modules in assembly " + assem +
-// " (" + modules.length + ")");
-// for (int i = 0; i < modules.length; i++) {
-// System.out.println("\t" + modules[i]);
-// }
-
- Type[] types = modules[0].GetTypes();
-// System.out.println("Types in assembly " + assem +
-// " (" + types.length + ")");
- for (int i = 0; i < types.length; i++) {
- System.out.println("#" + i + " -> " + types[i]);
- types[i].completeType();
- }
- }
-
- public static final void dumpType(PrintStream out, Type type) {
- out.println("Type = " + type);
- out.println("Name = " + type.Name);
- out.println("Namespace = " + type.Namespace);
- out.println("FullName = " + type.FullName);
- out.println("Attributes = " + TypeAttributes.toString(type.Attributes));
- out.println("BaseType = " + type.BaseType);
- Type[] ifaces = type.GetInterfaces();
- if (ifaces != null) {
- for (int i = 0; i < ifaces.length; i++)
- out.println("\timplements " + ifaces[i]);
- }
- out.println("Assembly = " + type.Assembly);
- out.println("Module = " + type.Module);
- out.println("DeclaringType = " + type.DeclaringType);
- out.println("IsInterface = " + type.IsInterface);
- out.println("IsAbstract = " + type.IsAbstract);
-
- FieldInfo[] fields = type.GetFields(BindingFlags.Instance
- | BindingFlags.Static
- | BindingFlags.NonPublic);
- out.println("\nFields (" + fields.length + "):");
- for (int i = 0; i < fields.length; i++) {
- out.println("\t" + fields[i]);
- out.println("\t\tDeclaringType = " + fields[i].DeclaringType);
- out.println("\t\tReflectedType = " + fields[i].ReflectedType);
- }
-
- ConstructorInfo[] constrs = type.GetConstructors();
- out.println("\nConstructors (" + constrs.length + "):");
- for (int i = 0; i < constrs.length; i++) {
- out.println("\t" + constrs[i]);
- }
-
-// MethodInfo[] methods = type.GetMethods(BindingFlags.Instance
-// | BindingFlags.Static
-// | BindingFlags.Public
-// | BindingFlags.NonPublic);
- MethodInfo[] methods = type.GetMethods();
- out.println("\nMethods (" + methods.length + "):");
- for (int i = 0; i < methods.length; i++) {
- out.println("\t" + methods[i]);
- out.println("\t\tDeclaringType = " + methods[i].DeclaringType);
- out.println("\t\tReflectedType = " + methods[i].ReflectedType);
- }
- }
-}
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/util/PECustomMod.java b/src/msil/ch/epfl/lamp/compiler/msil/util/PECustomMod.java
deleted file mode 100644
index 56519e8487..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/util/PECustomMod.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package ch.epfl.lamp.compiler.msil.util;
-
-import ch.epfl.lamp.compiler.msil.Type;
-import ch.epfl.lamp.compiler.msil.CustomModifier;
-
-/**
- * A PECustomMod holds the info parsed from metadata per the CustomMod production in Sec. 23.2.7, Partition II.
- * */
-public final class PECustomMod {
-
- public final Type marked;
- public final CustomModifier[] cmods;
-
- /** Terminology:
- the CustomModifier(s) are markers,
- and the msil.Type is a type marked by those markers. */
- public PECustomMod(Type marked, CustomModifier[] cmods) {
- this.marked = marked;
- this.cmods = cmods;
- }
-
-}
-
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/util/PESection.java b/src/msil/ch/epfl/lamp/compiler/msil/util/PESection.java
deleted file mode 100644
index 454a94e55c..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/util/PESection.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * System.Reflection-like API for acces to .NET assemblies (DLL & EXE)
- */
-
-
-package ch.epfl.lamp.compiler.msil.util;
-
-import ch.epfl.lamp.compiler.msil.PEFile;
-
-import java.io.PrintStream;
-
-/** Describes a section from a PE/COFF file
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-public final class PESection {
-
- private final PEFile file;
- private final long sectionStart;
-
- public final String name;
- public final int virtAddr;
- public final int virtSize;
- public final int realAddr;
- public final int realSize;
- public final int flags;
-
- private static final byte[] buf = new byte[8];
-
- public PESection(PEFile file) {
- this.file = file;
- sectionStart = file.pos();
- file.read(buf);
- int i;
- for(i = 7; (i >= 0) && (0 == buf[i]); i--);
- name = new String(buf, 0, i + 1);
- virtSize = file.readInt();
- virtAddr = file.readInt();
- realSize = file.readInt();
- realAddr = file.readInt();
- file.skip(3 * PEFile.INT_SIZE);
- flags = file.readInt();
- }
-
-
- public void dump(PrintStream out) {
- out.println("Section name: " + name +
- " (name.length=" + name.length() + ")");
- out.println("Virtual Address: 0x" + PEFile.int2hex(virtAddr));
- out.println("Virtual Size: 0x" + PEFile.int2hex(virtSize));
- out.println("Real Address: 0x" + PEFile.int2hex(realAddr));
- out.println("Real Size: 0x" + PEFile.int2hex(realSize));
- out.println("Flags: 0x" + PEFile.int2hex(flags));
- }
-
-} // class PESection
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/util/PEStream.java b/src/msil/ch/epfl/lamp/compiler/msil/util/PEStream.java
deleted file mode 100644
index 649d9e74f2..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/util/PEStream.java
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- * System.Reflection-like API for acces to .NET assemblies (DLL & EXE)
- */
-
-
-package ch.epfl.lamp.compiler.msil.util;
-
-import ch.epfl.lamp.compiler.msil.PEFile;
-import ch.epfl.lamp.compiler.msil.PEFile.Sig;
-
-import java.io.PrintStream;
-import java.io.IOException;
-
-import java.nio.ByteBuffer;
-import java.nio.channels.FileChannel;
-
-/**
- * Implements support for CLI streams within a PE file.
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-public final class PEStream implements Signature {
-
- //##########################################################################
- // Members
-
- /** The name of the stream. */
- public final String name;
-
- /** The offset of the stream from the beginning of the file. */
- public final int offset;
-
- /** The size of the stream in bytes; shall be multiple of 4. */
- public final int size;
-
- private final PEFile file;
-
- private final ByteBuffer buffer;
-
- //##########################################################################
-
- /** The PEStream class constructor.
- * @param file - the PEFile to which this stream belongs
- */
- public PEStream(PEFile file) {
- this.file = file;
- offset = file.fromRVA(file.rvaMetadata + file.readInt());
- size = file.readInt();
- buffer = file.getBuffer(offset, size);
-
- int i = 0;
- byte [] _buf = new byte [16];
- do {
- _buf[i] = (byte) file.readByte();
- i++;
- } while(0 != _buf[i-1]);
- name = new String(_buf, 0, i - 1);
-
- file.align(PEFile.INT_SIZE, file.posMetadata);
- //assert size % 4 == 0;
- }
-
- /** Move to the specified position in the stream. */
- private void seek(int pos) {
- try {
- buffer.position(pos);
- } catch (IllegalArgumentException e) {
- System.err.println("\nSeek failed in file " + file
- + " for position " + pos
- + " of stream " + name + " (" + buffer + ")");
- throw e;
- }
- }
-
- /** Return a string from the specified position in the stream. */
- public String getString(int pos) {
- seek(pos);
- buffer.mark();
- int i;
- for (i = 0; getByte() != 0; i++);
- byte[] buf = new byte[i];
- buffer.reset(); // go back to the marked position
- buffer.get(buf);
- try {
- return new String(buf, "UTF-8");
- } catch (java.io.UnsupportedEncodingException e) {
- throw new RuntimeException(e);
- }
- }
-
- /** Read a byte from the stream. */
- public int getByte() {
- return (buffer.get() + 0x0100) & 0xff;
- }
-
- /** Return the GUID at the given position in the stream. */
- public byte[] getGUID(int pos) {
- seek(pos);
- byte[] buf = new byte[32]; // 128-bit GUID
- try {
- buffer.get(buf);
- } catch (Exception e) {
- System.err.println();
- System.err.println("PEStream.getBlob(): Exception for pos = " +
- pos + " and buf.length = " + buf.length);
- System.err.println("\tbuffer = " + buffer);
- e.printStackTrace();
- throw new RuntimeException();
- }
- return buf;
- }
-
- public int readLength() {
- int length = getByte();
- if ((length & 0x80) != 0) {
- length = ((length & 0x7f) << 8) | getByte();
- if ((length & 0x4000) != 0)
- length = ((length & 0x3fff) << 16) | (getByte()<<8) | getByte();
- }
- return length;
- }
-
- /** Return a blob from the specified position in the stream. */
- public byte[] getBlob(int pos) {
- seek(pos);
- // the length indicates the number of bytes
- // AFTER the encoded size of the blob
- int length = readLength();
- byte[] buf = new byte[length];
- buffer.get(buf);
- return buf;
- }
-
- /***/
- public Sig getSignature(int pos) {
- seek(pos);
- return file.newSignature(buffer);
- }
-
- /**
- */
- public Object getConstant(int type, int pos) {
- Object val = null;
- seek(pos);
- int length = readLength(); // skip over the blob length field
- switch (type) {
- case ELEMENT_TYPE_BOOLEAN:
- assert length == 1;
- return buffer.get() == 0 ? Boolean.FALSE : Boolean.TRUE;
- case ELEMENT_TYPE_CHAR:
- assert length == 2 : "length == " + length;
- return new Character(buffer.getChar());
- case ELEMENT_TYPE_I1:
- case ELEMENT_TYPE_U1: // TODO U1 not the same as I1
- assert length == 1;
- return new Byte(buffer.get());
- case ELEMENT_TYPE_I2:
- case ELEMENT_TYPE_U2:
- assert length == 2;
- return new Short(buffer.getShort());
- case ELEMENT_TYPE_I4:
- case ELEMENT_TYPE_U4:
- assert length == 4;
- return new Integer(buffer.getInt());
- case ELEMENT_TYPE_I8:
- case ELEMENT_TYPE_U8:
- assert length == 8;
- return new Long(buffer.getLong());
- case ELEMENT_TYPE_R4:
- assert length == 4;
- return new Float(buffer.getFloat());
- case ELEMENT_TYPE_R8:
- assert length == 8;
- return new Double(buffer.getDouble());
- case ELEMENT_TYPE_STRING:
-// length /= 2;
-// char[] chars = new char[length];
-// for (int i = 0; i < length; i++)
-// chars[i] = buffer.getChar();
-// val = new String(chars);
- try {
- return new String(getBlob(pos), "UTF-16LE");
- } catch(java.io.UnsupportedEncodingException e) {
- throw new RuntimeException(e);
- }
- default: throw new RuntimeException("Illegal constant type: " + type);
- }
- }
-
- public void dump(PrintStream out) {
- out.println("Stream name: " + name + " (length " +
- name.length() + " characters)");
- out.println("Stream offset: 0x" + PEFile.int2hex(offset));
- out.println("Stream size: 0x" + PEFile.int2hex(size));
- }
-
- //##########################################################################
-} // class PEStream
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/util/Signature.java b/src/msil/ch/epfl/lamp/compiler/msil/util/Signature.java
deleted file mode 100644
index d5dc0ff32c..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/util/Signature.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * System.Reflection-like API for acces to .NET assemblies (DLL & EXE)
- */
-
-
-package ch.epfl.lamp.compiler.msil.util;
-
-import ch.epfl.lamp.compiler.msil.Type;
-
-/**
- * Signatures
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-public interface Signature {
-
- //##########################################################################
-
- /** Marks end of a list. */
- public static final int ELEMENT_TYPE_END = 0x00;
- /** void */
- public static final int ELEMENT_TYPE_VOID = 0x01;
- /** boolean */
- public static final int ELEMENT_TYPE_BOOLEAN = 0x02;
- /** char */
- public static final int ELEMENT_TYPE_CHAR = 0x03;
- /** signed byte */
- public static final int ELEMENT_TYPE_I1 = 0x04;
- /** byte */
- public static final int ELEMENT_TYPE_U1 = 0x05;
- /** short */
- public static final int ELEMENT_TYPE_I2 = 0x06;
- /** unsigned short */
- public static final int ELEMENT_TYPE_U2 = 0x07;
- /** int */
- public static final int ELEMENT_TYPE_I4 = 0x08;
- /** unsigned int */
- public static final int ELEMENT_TYPE_U4 = 0x09;
- /** long */
- public static final int ELEMENT_TYPE_I8 = 0x0a;
- /** unsigned long */
- public static final int ELEMENT_TYPE_U8 = 0x0b;
- /** float */
- public static final int ELEMENT_TYPE_R4 = 0x0c;
- /** double */
- public static final int ELEMENT_TYPE_R8 = 0x0d;
- /** string */
- public static final int ELEMENT_TYPE_STRING = 0x0e;
- /** Followed by <type> token. */
- public static final int ELEMENT_TYPE_PTR = 0x0f;
- /** Followed by <type> token. */
- public static final int ELEMENT_TYPE_BYREF = 0x10;
- /** Followed by <type> token */
- public static final int ELEMENT_TYPE_VALUETYPE = 0x11;
- /** Followed by <type> token */
- public static final int ELEMENT_TYPE_CLASS = 0x12;
-
- public static final int ELEMENT_TYPE_VAR = 0x13;
-
- /**
- * <type> <rank> <boundsCount> <bound1> ... <loCount> <lo1> ...
- */
- public static final int ELEMENT_TYPE_ARRAY = 0x14;
-
- public static final int ELEMENT_TYPE_GENERICINST = 0x15;
- /***/
- public static final int ELEMENT_TYPE_TYPEDBYREF = 0x16;
- /** System.IntPtr */
- public static final int ELEMENT_TYPE_I = 0x18;
- /** System.UIntPtr */
- public static final int ELEMENT_TYPE_U = 0x19;
- /** Followed by full method signature. */
- public static final int ELEMENT_TYPE_FNPTR = 0x1b;
- /** System.Object. */
- public static final int ELEMENT_TYPE_OBJECT = 0x1c;
- /** Single-dim array with 0 lower bound. */
- public static final int ELEMENT_TYPE_SZARRAY = 0x1d;
-
- public static final int ELEMENT_TYPE_MVAR = 0x1e;
-
- /** Required modifier : followed by a TypeDef or TypeRef token. */
- public static final int ELEMENT_TYPE_CMOD_REQD = 0x1f;
- /** Optional modifier : followed by a TypeDef or TypeRef token. */
- public static final int ELEMENT_TYPE_CMOD_OPT = 0x20;
- /** Implemented within the CLI. */
- public static final int ELEMENT_TYPE_INTERNAL = 0x21;
- /** Or'd with following element types. */
- public static final int ELEMENT_TYPE_MODIFIER = 0x40;
- /** Sentinel for varargs method signature. */
- public static final int ELEMENT_TYPE_SENTINEL = 0x41;
- /**Denotes a local variable that points at a pinned object. */
- public static final int ELEMENT_TYPE_PINNED = 0x45;
-
- //##########################################################################
- // signature designators
-
- public static final int HASTHIS = 0x20;
- public static final int EXPLICITTHIS = 0x40;
- public static final int DEFAULT = 0x00;
- public static final int VARARG = 0x05;
- public static final int GENERIC = 0x10;
- public static final int SENTINEL = 0x41;
- public static final int C = 0x01;
- public static final int STDCALL = 0x02;
- public static final int THISCALL = 0x03;
- public static final int FASTCALL = 0x04;
- public static final int FIELD = 0x06;
- public static final int PROPERTY = 0x08;
- public static final int LOCAL_SIG = 0x07;
-
- //##########################################################################
- // extra IDs used in the serialization format of named arguments
- // to custom attributes. Reverse-engineered from compiled C# example
-
- /** What follows is a string with the full name of the type. */
- public static final int X_ELEMENT_TYPE_TYPE = 0x50;
-
- /** What follows is a string with the full name of the enumeration type*/
- public static final int X_ELEMENT_TYPE_ENUM = 0x55;
-
- /** The named argument specifies a field. */
- public static final int X_ELEMENT_KIND_FIELD = 0x53;
-
- /** The named argument specifies a property. */
- public static final int X_ELEMENT_KIND_PROPERTY = 0x54;
-
- //##########################################################################
-} // interface Signature
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/util/Table.java b/src/msil/ch/epfl/lamp/compiler/msil/util/Table.java
deleted file mode 100644
index 1f43b8c2fa..0000000000
--- a/src/msil/ch/epfl/lamp/compiler/msil/util/Table.java
+++ /dev/null
@@ -1,1859 +0,0 @@
-/*
- * System.Reflection-like API for acces to .NET Assemblies
- */
-
-
-package ch.epfl.lamp.compiler.msil.util;
-
-import ch.epfl.lamp.compiler.msil.PEFile;
-import ch.epfl.lamp.compiler.msil.PEFile.Sig;
-
-import java.io.PrintStream;
-import java.nio.ByteBuffer;
-import java.nio.MappedByteBuffer;
-
-/**
- * Represents a table in a .NET assembly
- *
- * @author Nikolay Mihaylov
- * @version 1.0
- */
-public abstract class Table {
-
- //##########################################################################
-
- public static final int MAX_NUMBER = 64;
-
- public static final long VALID_TABLES_MASK = 0x03ff3fb7ff57L;
-
- //##########################################################################
- // fields and methods for handling predefined sets of tables
-
- public static final int TABLE_SET_LENGTH = 13;
-
- public static final int _TypeDefOrRef = 0;
- public static final int _HasConstant = 1;
- public static final int _HasCustomAttribute = 2;
- public static final int _HasFieldMarshal = 3;
- public static final int _HasDeclSecurity = 4;
- public static final int _MemberRefParent = 5;
- public static final int _HasSemantics = 6;
- public static final int _MethodDefOrRef = 7;
- public static final int _MemberForwarded = 8;
- public static final int _Implementation = 9;
- public static final int _CustomAttributeType = 10;
- public static final int _ResolutionScope = 11;
- public static final int _TypeOrMethodDef = 12;
-
-
- public static final int[][] TableSet = new int[TABLE_SET_LENGTH][];
-
- static {
- TableSet[_TypeDefOrRef] =
- new int[] {TypeDef.ID, TypeRef.ID, TypeSpec.ID};
- TableSet[_HasConstant] =
- new int[] {FieldDef.ID, ParamDef.ID, PropertyDef.ID};
- TableSet[_HasCustomAttribute] =
- new int[] {MethodDef.ID, FieldDef.ID, TypeRef.ID, TypeDef.ID,
- ParamDef.ID, InterfaceImpl.ID, MemberRef.ID, ModuleDef.ID,
- -1, PropertyDef.ID, EventDef.ID, -1, ModuleRef.ID,
- TypeSpec.ID, AssemblyDef.ID, AssemblyRef.ID,
- FileDef.ID, ExportedType.ID, ManifestResource.ID};
- TableSet[_HasFieldMarshal] =
- new int[] {FieldDef.ID, ParamDef.ID};
- TableSet[_HasDeclSecurity] =
- new int[] {TypeDef.ID, MethodDef.ID, AssemblyDef.ID};
- TableSet[_MemberRefParent] =
- new int[] {-1, TypeRef.ID, ModuleRef.ID, MethodDef.ID, TypeSpec.ID};
- TableSet[_HasSemantics] =
- new int[] {EventDef.ID, PropertyDef.ID};
- TableSet[_MethodDefOrRef] =
- new int[] {MethodDef.ID, MemberRef.ID};
- TableSet[_MemberForwarded] =
- new int[] {FieldDef.ID, MethodDef.ID};
- TableSet[_Implementation] =
- new int[] {FileDef.ID, AssemblyRef.ID, ExportedType.ID};
- TableSet[_CustomAttributeType] =
- new int[] {-1, -1, MethodDef.ID, MemberRef.ID, -1};
- TableSet[_ResolutionScope] =
- new int[] {ModuleDef.ID, ModuleRef.ID, AssemblyRef.ID, TypeRef.ID};
- TableSet[_TypeOrMethodDef] =
- new int[]{TypeDef.ID, MethodDef.ID};
- }
-
- public static final int[] NoBits =
- new int[]{2, 2, 5, 1, 2, 3, 1, 1, 1, 2, 3, 2, 1};
-
- public static int getMask(int tableSetId) {
- return (1 << NoBits[tableSetId]) - 1;
- }
-
- public static int getTableId(int tableSet, int index) {
- return TableSet[tableSet][index & getMask(tableSet)];
- }
-
- public static int getTableIndex(int tableSet, int index) {
- return index >> NoBits[tableSet];
- }
-
- public static int encodeIndex(int index, int tableSetId, int tableId) {
- int[] tableSet = TableSet[tableSetId];
- for (int i = 0; i < tableSet.length; i++) {
- if (tableSet[i] == tableId)
- return (index << NoBits[tableSetId]) | i;
- }
- throw new RuntimeException("Cannot find table #" + tableId +
- " in table set #" + tableSetId);
- }
-
- //##########################################################################
-
- private static final String [] tableName = {
- "Module", "TypeRef", "TypeDef", " FieldTrans",
- "Field", "MethodTrans", "Method", "",
- "Param", "InterfaceImpl", "MemberRef", "Constant",
- "CustomAttribute", "FieldMarshal", "DeclSecurity","ClassLayout",
- "FieldLayout", "StandAloneSig", "EventMap", "",
- "Event", "PropertyMap", "", "Property",
- "MethodSemantics", "MethodImpl", "ModuleRef", "TypeSpec",
- "ImplMap", "FieldRVA", "", "",
- "Assembly", "AssemblyProcessor","AssemblyOS", "AssemblyRef",
- "AssemblyRefProcessor","AssemblyRefOS", "File", "ExportedType",
- "ManifestResource", "NestedClass", "GenericParam", "MethodSpec",
- "GenericParamConstraint", "", "", "",
- "", "", "", "",
- "", "", "", "",//0x30-0x37
- "", "", "", "",
- "", "", "", "" //0x37-0x3f
- };
-
- /** Creates a table with the given id and number of rows.
- */
- public static Table newTable(PEFile file, int id, int rows) {
- Table table = null;
- switch(id) {
- case ModuleDef.ID: table = new ModuleDef(file, rows); break;
- case TypeRef.ID: table = new TypeRef(file, rows); break;
- case TypeDef.ID: table = new TypeDef(file, rows); break;
- case FieldTrans.ID: table = new FieldTrans(file, rows); break;
- case FieldDef.ID: table = new FieldDef(file, rows); break;
- case MethodTrans.ID: table = new MethodTrans(file, rows); break;
- case MethodDef.ID: table = new MethodDef(file, rows); break;
- case ParamDef.ID: table = new ParamDef(file, rows); break;
- case InterfaceImpl.ID: table = new InterfaceImpl(file, rows); break;
- case MemberRef.ID: table = new MemberRef(file, rows); break;
- case Constant.ID: table = new Constant(file, rows); break;
- case CustomAttribute.ID: table = new CustomAttribute(file, rows); break;
- case FieldMarshal.ID: table = new FieldMarshal(file, rows); break;
- case DeclSecurity.ID: table = new DeclSecurity(file, rows); break;
- case ClassLayout.ID: table = new ClassLayout(file, rows); break;
- case FieldLayout.ID: table = new FieldLayout(file, rows); break;
- case StandAloneSig.ID: table = new StandAloneSig(file, rows); break;
- case EventMap.ID: table = new EventMap(file, rows); break;
- case EventDef.ID: table = new EventDef(file, rows); break;
- case PropertyMap.ID: table = new PropertyMap(file, rows); break;
- case PropertyDef.ID: table = new PropertyDef(file, rows); break;
- case MethodSemantics.ID: table = new MethodSemantics(file, rows); break;
- case MethodImpl.ID: table = new MethodImpl(file, rows); break;
- case ModuleRef.ID: table = new ModuleRef(file, rows); break;
- case TypeSpec.ID: table = new TypeSpec(file, rows); break;
- case ImplMap.ID: table = new ImplMap(file, rows); break;
- case FieldRVA.ID: table = new FieldRVA(file, rows); break;
- case AssemblyDef.ID: table = new AssemblyDef(file, rows); break;
- case AssemblyProcessor.ID: table = new AssemblyProcessor(file, rows); break;
- case AssemblyOS.ID: table = new AssemblyOS(file, rows); break;
- case AssemblyRef.ID: table = new AssemblyRef(file, rows); break;
- case AssemblyRefProcessor.ID:
- table = new AssemblyRefProcessor(file, rows); break;
- case AssemblyRefOS.ID: table = new AssemblyRefOS(file, rows); break;
- case FileDef.ID: table = new FileDef(file, rows); break;
- case ExportedType.ID: table = new ExportedType(file, rows); break;
- case ManifestResource.ID: table = new ManifestResource(file, rows); break;
- case NestedClass.ID: table = new NestedClass(file, rows); break;
- case GenericParam.ID:
- table = new GenericParam(file, rows);
- break;
- case MethodSpec.ID:
- table = new MethodSpec(file, rows);
- break;
- case GenericParamConstraint.ID:
- table = new GenericParamConstraint(file, rows);
- break;
- default:
- table = new Empty(id);
- }
-// System.out.println("created table " + table.getName() + " with "
-// + table.rows + " rows");
- return table;
- }
-
-
- //##########################################################################
- // public fields
-
- /** Number of rows in the table. */
- public final int rows;
-
- /** Table ID as specified in Partition II. */
- public final int id;
-
- /** The file to which the table belongs. */
- protected final PEFile file;
-
- /** Memory mapped buffer wrapping the table. */
- protected ByteBuffer buffer;
-
- /**
- * specified wheter a new memory-mapped byte buffer should be created
- * for this table.
- */
- protected boolean newMapping = false;
-
- /** Tells wheter the table is indexed by 2-byte (short) integer
- * or by 4-byte integer. */
- public final boolean isShort;
-
- private int rowSize = -1;
-
- // the starting position of the table relative to the beginning of the file
- private long start = -1;
-
- // the number of the row who can be accessed via the fields of the table
- private int currentRow = 0;
-
- //##########################################################################
-
- protected Table(PEFile file, int id, int rows) {
- this.file = file;
- this.id = id;
- this.rows = rows;//file.readInt();
- this.isShort = rows < (1 << 16);
-// assert ((1L << id) & VALID_TABLES_MASK) != 0
-// : "Table does not have a vaid ID: " + byte2hex(id);
- }
-
- /**
- * Additional table initialization.
- * @return the starting position of the next table in the stream.
- */
- public final long init(long start) {
- if (rows < 1)
- return start;
- if (this.start == -1)
- this.start = start;
- else throw new RuntimeException
- ("Cannot re-initialize table \'" + getTableName() + "\'");
- rowSize = getRowSize();
- int size = rows * rowSize();
- buffer = this.newMapping ? file.mapBuffer(start, size)
- : file.getBuffer(start, size);
- return start + size;
- }
-
-
- public final String getTableName() {
- return 0 <= id && id < MAX_NUMBER ? tableName[id] : "<NoTable>";
- }
-
- /**
- * @return the size of the row in bytes
- */
- public final int rowSize() {
- return rowSize;
- }
-
- /**
- * if the underlying buffer is memory-mapped, load its contents into memory
- */
- public void load() {
- if (buffer instanceof MappedByteBuffer)
- ((MappedByteBuffer)buffer).load();
- }
-
- /***/
- public final int readByte() {
- return (buffer.get() + 0x100) & 0xff;
- }
-
- /***/
- public final int readShort() {
- return (buffer.getShort() + 0x10000) & 0xffff;
- }
-
- /***/
- public final int readInt() {
- return buffer.getInt();
- }
-
- /***/
- public final int readStringIndex() {
- return file.StringIsShort ? readShort() : readInt();
- }
-
- /***/
- public final int readBlobIndex() {
- return file.BlobIsShort ? readShort() : readInt();
- }
-
- /***/
- public final int readGUIDIndex() {
- return file.GUIDIsShort ? readShort() : readInt();
- }
-
- /***/
- public final int readTableIndex(int tableId) {
- return file.getTable(tableId).isShort ? readShort() : readInt();
- }
-
- /***/
- public final int readTableSetIndex(int tableSetId) {
- return file.indexSize[tableSetId] == 2 ? readShort() : readInt();
- }
-
- /** Read the specified row and populate the fields of the instance. */
- public final void readRow(int row) {
- seekRow(row);
- int lastSeek = buffer.position();
- populateFields();
- int rowSizeRead = (int) (buffer.position() - lastSeek);
- if (rowSizeRead != rowSize())
- throw new RuntimeException("Table ID=0x" + PEFile.byte2hex(id) +
- ": read row size = " + rowSizeRead +
- "; expected row size = " + rowSize());
- currentRow = row;
- }
-
- /** Seeks in the file the position of the specified row. */
- protected final void seekRow(int row) {
- assert row > 0 && row <= rows
- : "Index " + row + " is not within the table with #rows = " + rows;
- buffer.position((row - 1)* rowSize());
- }
-
- public final int currentRow() { return currentRow; }
-
- public final void nextRow() { readRow(currentRow() + 1); }
-
- //##########################################################################
- // abstract members
-
- /** Assigns values to the fields of the class. */
- protected abstract void populateFields();
-
- /** Returns the size of a row in bytes. */
- protected abstract int getRowSize();
-
- //##########################################################################
- // a table with 0 rows
-
- private static final class Empty extends Table {
- public Empty(int id) {
- super(null, id, 0);
- }
- protected int getRowSize() { return 0; }
- protected void populateFields() {
- throw new RuntimeException("Table 0x" + PEFile.byte2hex(id));
- }
- }
-
- //##########################################################################
- // table Module; ID=0x00; p115, 21.27
-
- public static final class ModuleDef extends Table {
- public static final int ID = 0x00;
-
- /** 2-byte value; reserved - shall be 0. */
- public int Generation;
-
- /** Index into #String. */
- public int Name;
-
- /** Index into #GUID; used to distinguish between
- * two version of the same module. */
- public int Mvid;
-
- /** Index into #GUID; reserved - shall be 0. */
- public int EncId;
-
- /** Index into #GUID; reseved - shall be 0. */
- public int EncBaseId;
-
- public ModuleDef(PEFile file, int rows) { super(file, ID, rows); }
-
- protected void populateFields() {
- Generation = readShort();
- Name = readStringIndex();
- Mvid = readGUIDIndex();
- EncId = readGUIDIndex();
- EncBaseId = readGUIDIndex();
- }
-
- protected int getRowSize() {
- return 2 + file.getStringIndexSize() + 3*file.getGUIDIndexSize();
- }
-
- public String getName() {
- return file.getString(Name);
- }
-
- } // class ModuleDef
-
- //##########################################################################
- // table TypeRef; ID=0x01; p125, 21.35
-
- public static final class TypeRef extends Table {
- public static final int ID = 0x1;
-
- /** A ResolutionScope coded index. */
- public int ResolutionScope;
-
- /** Index into #String. */
- public int Name;
-
- /** Index into #String. */
- public int Namespace;
-
- public TypeRef(PEFile file, int rows) { super(file, ID, rows); }
-
- protected void populateFields() {
- ResolutionScope = readTableSetIndex(_ResolutionScope);
- Name = readStringIndex();
- Namespace = readStringIndex();
- }
-
- protected int getRowSize() {
- return file.getTableSetIndexSize(_ResolutionScope) +
- 2 * file.getStringIndexSize();
- }
-
- public String getFullName() {
- String namespace = file.getString(Namespace);
- return namespace.length() == 0 ? file.getString(Name)
- : namespace + "." + file.getString(Name);
- }
-
- } // class TypeRef
-
- //##########################################################################
- // table TypeDef; ID=0x02; p120, 21.34
-
- public static final class TypeDef extends Table {
- public static final int ID = 0x02;
-
- /** 4-byte bitmask of type TypeAttributes (22.1.14). */
- public int Flags;
-
- /** Index into #String. */
- public int Name;
-
- /** Index into #String. */
- public int Namespace;
-
- /** TypeDefOrRef coded index. */
- public int Extends;
-
- /** Index into Field table.
- */
- public int FieldList;
-
- /** Index into Method table. */
- public int MethodList;
-
-
- public TypeDef(PEFile file, int rows) {
- super(file, ID, rows);
- this.newMapping = true;
- }
-
- public String getFullName() {
- String namespace = file.getString(Namespace);
- return namespace.length() == 0 ? file.getString(Name)
- : namespace + "." + file.getString(Name);
- }
-
- protected void populateFields() {
- Flags = readInt();
- Name = readStringIndex();
- Namespace = readStringIndex();
- Extends = readTableSetIndex(_TypeDefOrRef);
- FieldList = readTableIndex(FieldDef.ID);
- MethodList = readTableIndex(MethodDef.ID);
- }
-
- protected int getRowSize() {
- return 4 + 2*file.getStringIndexSize() +
- file.getTableSetIndexSize(_TypeDefOrRef) +
- file.getTableIndexSize(FieldDef.ID) +
- file.getTableIndexSize(MethodDef.ID);
- }
-
- } // class TypeDef
-
- //##########################################################################
- // Table FieldTrans; ID=0x03; undocumented
-
- /**
- * Undocumented table. Appears to be used for translating the Field entry
- * in the TypeDef(0x02) table into the real entry in the Fields(0x06) table
- */
- public static final class FieldTrans extends Table {
- public static final int ID = 0x03;
-
- public int Field;
-
- public FieldTrans(PEFile file, int rows) {
- super(file, ID, rows);
- newMapping = true;
- }
-
- protected void populateFields() {
- Field = readTableIndex(FieldDef.ID);
- }
-
- protected int getRowSize() {
- return file.getTableIndexSize(FieldDef.ID);
- }
-
- }
-
- //##########################################################################
- // table Field; ID=0x04; p102, 21.15
-
- public static final class FieldDef extends Table {
- public static final int ID = 0x04;
-
- /** 2-byte bitmask of type FieldAttributes (22.1.5). */
- public int Flags;
-
- /** Index into #String. */
- public int Name;
-
- /** Index into #Blob. */
- public int Signature;
-
- public FieldDef(PEFile file, int rows) {
- super(file, ID, rows);
- newMapping = true;
- }
-
- protected void populateFields() {
- Flags = readShort();
- Name = readStringIndex();
- Signature = readBlobIndex();
- }
-
- protected int getRowSize() {
- return 2 + file.getStringIndexSize() + file.getBlobIndexSize();
- }
-
- public String getName() { return file.getString(Name); }
-
- public Sig getSignature() { return file.getSignature(Signature); }
-
- } //class FieldDef
-
- //##########################################################################
- // Table MethodTrans; ID=0x05; undocumented
-
- /**
- * Undocumented table. Appears to be used for translating the Method entry
- * in the TypeDef(0x02) table into the real entry in the Methods(0x06) table
- */
- public static final class MethodTrans extends Table {
- public static final int ID = 0x05;
-
- public int Method;
-
- public MethodTrans(PEFile file, int rows) {
- super(file, ID, rows);
- newMapping = true;
- }
-
- protected void populateFields() {
- Method = readTableIndex(FieldDef.ID);
- }
-
- protected int getRowSize() {
- return file.getTableIndexSize(MethodDef.ID);
- }
-
- }
-
- //##########################################################################
- // table MethodDef; ID=0x06; p110, 21.24
-
- public static final class MethodDef extends Table {
- public static final int ID = 0x06;
-
- /** 4-byte constant. */
- public int RVA;
-
- /** 2-byte bitmask of type MethodImplAttributes (22.1.10). */
- public int ImplFlags;
-
- /** 2-byte bitmask of type MethodAttributes (22.1.9). */
- public int Flags;
-
- /** Index into #String. */
- public int Name;
-
- /** Index into #Blob. */
- public int Signature;
-
- /** Index into Param Table. */
- public int ParamList;
-
- public MethodDef(PEFile file, int rows) {
- super(file, ID, rows);
- newMapping = true;
- }
-
- protected void populateFields() {
- RVA = readInt();
- ImplFlags = readShort();
- Flags = readShort();
- Name = readStringIndex();
- Signature = readBlobIndex();
- ParamList = readTableIndex(ParamDef.ID);
- }
-
- protected int getRowSize() {
- return 8 + file.getStringIndexSize() + file.getBlobIndexSize() +
- file.getTableIndexSize(ParamDef.ID);
- }
-
- public String getName() { return file.getString(Name); }
-
- public Sig getSignature() { return file.getSignature(Signature); }
- } // class Method
-
- //##########################################################################
- // table Param; ID=0x08; p116, 21.30
-
- public static final class ParamDef extends Table {
- public static final int ID = 0x08;
-
- /** 2-byte bitmask of type ParamAttributes (22.1.12). */
- public int Flags;
-
- /** 2-byte constant. */
- public int Sequence;
-
- /** Index into #String. */
- public int Name;
-
- public ParamDef(PEFile file, int rows) {
- super(file, ID, rows);
- newMapping = true;
- }
-
- protected void populateFields() {
- Flags = readShort();
- Sequence = readShort();
- Name = readStringIndex();
- }
-
- protected int getRowSize() { return 4 + file.getStringIndexSize(); }
-
- public String getName() { return file.getString(Name); }
-
- } // class Param
-
- //##########################################################################
- // table InterfaceImpl, ID=0x09; p107, 21.21
-
- public static final class InterfaceImpl extends Table {
- public static final int ID = 0x09;
-
- /** Index into TypeDef table. */
- public int Class;
-
- /** Index into TypeDefOrRef table set. */
- public int Interface;
-
- public InterfaceImpl(PEFile file, int rows) { super(file, ID, rows); }
-
- protected void populateFields() {
- Class = readTableIndex(TypeDef.ID);
- Interface = readTableSetIndex(_TypeDefOrRef);
- }
-
- protected int getRowSize() {
- return file.getTableIndexSize(TypeDef.ID) +
- file.getTableSetIndexSize(_TypeDefOrRef);
- }
-
- /** finds the index of the first entry
- * @param targetIndex - index in the TypeDef table - the type to look for
- * @return the index of the first interface for the given type;
- * 0 if the type doesn't implement any interfaces
- */
-
- // binary search implementation
-// public int findType(int targetIndex) {
-// int l = 1, h = rows;
-// int classIndex;
-// while (l <= h) {
-// int mid = (l + h) / 2;
-// seekRow(mid);
-// classIndex = readTableIndex(TypeDef.ID);
-// if (targetIndex <= classIndex) h = mid - 1;
-// else l = mid + 1;
-// }
-// return (targetIndex == classIndex) ? h : 0;
-// }
-
- //linear search implementation
- public int findType(int targetIndex) {
- for (int i = 1; i <= rows; i++) {
- seekRow(i);
- if (targetIndex == readTableIndex(TypeDef.ID))
- return i;
- }
- return 0;
- }
-
- } // class InterfaceImpl
-
- //##########################################################################
- // table MemberRef; ID=0x0a; p109, 21.23
-
- public static final class MemberRef extends Table {
- public static final int ID = 0x0a;
-
- /** Index into MemberRefParent table set. */
- public int Class;
-
- /** Index into #String. */
- public int Name;
-
- /** Index into #Blob. */
- public int Signature;
-
- public MemberRef(PEFile file, int rows) { super(file, ID, rows); }
-
- protected void populateFields() {
- Class = readTableSetIndex(_MemberRefParent);
- Name = readStringIndex();
- Signature = readBlobIndex();
- }
-
- protected int getRowSize() {
- return file.getTableSetIndexSize(_MemberRefParent) +
- file.getStringIndexSize() + file.getBlobIndexSize();
- }
-
- public String getName() {
- return file.getString(Name);
- }
-
- public Sig getSignature() {
- return file.getSignature(Signature);
- }
-
- } // class MemberRef
-
- //##########################################################################
- // table Constant; ID=0x0b; p95, 21.9
-
- public static final class Constant extends Table {
- public static final int ID = 0x0b;
-
- /** 1-byte constant followed by 1-byte padding 0 (see 22.1.15). */
- public int Type;
-
- /** Index into HasConst table set. */
- public int Parent;
-
- /** Index into #Blob. */
- public int Value;
-
- public Constant(PEFile file, int rows) { super(file, ID, rows); }
-
- protected void populateFields() {
- Type = readShort();
- Parent = readTableSetIndex(_HasConstant);
- Value = readBlobIndex();
- }
-
- protected int getRowSize() {
- return 2 + file.getTableSetIndexSize(_HasConstant) +
- file.getBlobIndexSize();
- }
-
- public Object getValue() {
- if (Type == Signature.ELEMENT_TYPE_CLASS)
- return null;
- return file.Blob.getConstant(Type, Value);
- }
-
-
- } // class Constant
-
- //##########################################################################
- // table CustomAttribute; ID=0x0c; p95, 21.10
-
- public static final class CustomAttribute extends Table {
- public static final int ID = 0x0c;
-
- /** Index into any metadata table, except the CustomAttribute itself;
- * more precisely - index into HasCustomAttribute table set.
- */
- public int Parent;
-
- /** Index into the CustomAttributeType table set. */
- public int Type;
-
- /** Index into #Blob. */
- public int Value;
-
- public CustomAttribute(PEFile file, int rows) { super(file, ID, rows); }
-
- protected void populateFields() {
- Parent = readTableSetIndex(_HasCustomAttribute);
- Type = readTableSetIndex(_CustomAttributeType);
- Value = readBlobIndex();
- }
-
- protected int getRowSize() {
- return file.getTableSetIndexSize(_HasCustomAttribute) +
- file.getTableSetIndexSize(_CustomAttributeType) +
- file.getBlobIndexSize();
- }
-
- public byte[] getValue() {
- return Value == 0 ? null : file.getBlob(Value);
- }
- } // class CustomAttribute
-
- //##########################################################################
- // table FieldMarshal; ID=0x0d; p105, 21.17
-
- public static final class FieldMarshal extends Table {
- public static final int ID = 0x0d;
-
- /** Index into HasFieldMarshal table set. */
- public int Parent;
-
- /** Index into #Blob. */
- public int NativeType;
-
- public FieldMarshal(PEFile file, int rows) { super(file, ID, rows); }
-
- protected void populateFields() {
- Parent = readTableSetIndex(_HasFieldMarshal);
- NativeType = readBlobIndex();
- }
-
- protected int getRowSize() {
- return file.getTableSetIndexSize(_HasFieldMarshal) +
- file.getBlobIndexSize();
- }
-
- } // class FieldMarshal
-
- //##########################################################################
- // table DeclSecurity; ID=0x0e; p97, 21.11
-
- public static final class DeclSecurity extends Table {
- public static final int ID = 0x0e;
-
- /** 2-byte value. */
- public int Action;
-
- /** Index into HasDeclSecurity table set. */
- public int Parent;
-
- /** Index into #Blob. */
- public int PermissionSet;
-
- public DeclSecurity(PEFile file, int rows) { super(file, ID, rows); }
-
- protected void populateFields() {
- Action = readShort();
- Parent = readTableSetIndex(_HasDeclSecurity);
- PermissionSet = readBlobIndex();
- }
-
- protected int getRowSize() {
- return 2 + file.getTableSetIndexSize(_HasDeclSecurity) +
- file.getBlobIndexSize();
- }
-
- } // class DeclSecurity
-
- //##########################################################################
- // table ClassLayout; ID=0x0f, p92, 21.8
-
- public static final class ClassLayout extends Table {
- public static final int ID = 0x0f;
-
- /** 2-byte constant. */
- public int PackingSize;
-
- /** 4-byte constant. */
- public int ClassSize;
-
- /** Index into TypeDef table. */
- public int Parent;
-
- public ClassLayout(PEFile file, int rows) { super(file, ID, rows); }
-
- protected void populateFields() {
- PackingSize = readShort();
- ClassSize = readInt();
- Parent = readTableIndex(TypeDef.ID);
- }
-
- protected int getRowSize() {
- return 6 + file.getTableIndexSize(TypeDef.ID);
- }
-
- } // class ClassLayout
-
- //##########################################################################
- // table FieldLayout; ID=0x10; p104, 21.16
-
- public static final class FieldLayout extends Table {
- public static final int ID = 0x10;
-
- /** 4-byte constant. */
- public int Offset;
-
- /** Index into the Field table. */
- public int Field;
-
- public FieldLayout(PEFile file, int rows) { super(file, ID, rows); }
-
- protected void populateFields() {
- Offset = readInt();
- Field = readTableIndex(FieldDef.ID);
- }
-
- protected int getRowSize() {
- return 4 + file.getTableIndexSize(FieldDef.ID);
- }
-
- } // class FieldLayout
-
- //##########################################################################
- // table StandAloneSig; ID=0x11; p119, 21.33
-
- public static final class StandAloneSig extends Table {
- public static final int ID = 0x11;
-
- /** Index into #Blob. */
- public int Signature;
-
- public StandAloneSig(PEFile file, int rows) { super(file, ID, rows); }
-
- protected void populateFields() {
- Signature = readBlobIndex();
- }
-
- protected int getRowSize() { return file.getBlobIndexSize(); }
-
- } // class StandAloneSig
-
- //##########################################################################
- // table EventMap; ID=0x12; p99, 21.12
-
- public static final class EventMap extends Table {
- public static final int ID = 0x12;
-
- /** Index into the TypeDef table. */
- public int Parent;
-
- /** Index into the Event table. */
- public int EventList;
-
- public EventMap(PEFile file, int rows) { super(file, ID, rows); }
-
- protected void populateFields() {
- Parent = readTableIndex(TypeDef.ID);
- EventList = readTableIndex(EventDef.ID);
- }
-
- protected int getRowSize() {
- return file.getTableIndexSize(TypeDef.ID) +
- file.getTableIndexSize(EventDef.ID);
- }
-
- } // class EventMap
-
- //##########################################################################
- // table Event; ID=0x14; p99, 21.13
-
- public static final class EventDef extends Table {
- public static final int ID = 0x14;
-
- /** 2-byte bitmask of type EventAttribute (22.1.4). */
- public int EventFlags;
-
- /** Index into #String. */
- public int Name;
-
- /** Index into TypeDefOrRef table set. [This corresponds to the Type
- * of the event; it is not the Type that owns the event]
- */
- public int EventType;
-
- public EventDef(PEFile file, int rows) { super(file, ID, rows); }
-
- protected void populateFields() {
- EventFlags = readShort();
- Name = readStringIndex();
- EventType = readTableSetIndex(_TypeDefOrRef);
- }
-
- protected int getRowSize() {
- return 2 + file.getStringIndexSize() +
- file.getTableSetIndexSize(_TypeDefOrRef);
- }
-
- public String getName() { return file.getString(Name); }
-
- } // class EventDef
-
- //##########################################################################
- // table PropertyMap; ID=0x15; p119, 21.32
-
- public static final class PropertyMap extends Table {
- public static final int ID = 0x15;
-
- /** Index into the TypeDef table. */
- public int Parent;
-
- /** Index into the Property table. */
- public int PropertyList;
-
- public PropertyMap(PEFile file, int rows) { super(file, ID, rows); }
-
- protected void populateFields() {
- Parent = readTableIndex(TypeDef.ID);
- PropertyList = readTableIndex(PropertyDef.ID);
- }
-
- protected int getRowSize() {
- return file.getTableIndexSize(TypeDef.ID) +
- file.getTableIndexSize(PropertyDef.ID);
- }
-
- } // class PropertyMap
-
- //##########################################################################
- // table Property; ID=0x17; p117, 21.31
-
- public static final class PropertyDef extends Table {
- public static final int ID = 0x17;
-
- /** 2-byte bitmask of type PropertyAttributes (22.1.13). */
- public int Flags;
-
- /** Index into #String. */
- public int Name;
-
- /** Index into #Blob. (Indexes the signature in the #Blob) */
- public int Type;
-
- public PropertyDef(PEFile file, int rows) { super(file, ID, rows); }
-
- protected void populateFields() {
- Flags = readShort();
- Name = readStringIndex();
- Type = readBlobIndex();
- }
-
- protected int getRowSize() {
- return 2 + file.getStringIndexSize() +
- file.getBlobIndexSize();
- }
-
- public String getName() { return file.getString(Name); }
-
- public Sig getSignature() { return file.getSignature(Type); }
-
- } // class PropertyDef
-
- //##########################################################################
- // table MethodSemantics; ID=0x18; p114, 21.26
-
- public static final class MethodSemantics extends Table {
- public static final int ID = 0x18;
-
- /** 2-byte bitmaks of type MethodSemanticsAttribute (22.1.11). */
- public int Semantics;
-
- /** Index into the Method table. */
- public int Method;
-
- /** Index into Event or Property table (HasSemantics table set). */
- public int Association;
-
- public MethodSemantics(PEFile file, int rows) { super(file, ID, rows); }
-
- protected void populateFields() {
- Semantics = readShort();
- Method = readTableIndex(MethodDef.ID);
- Association = readTableSetIndex(_HasSemantics);
- }
-
- protected int getRowSize() {
- return 2 + file.getTableIndexSize(MethodDef.ID) +
- file.getTableSetIndexSize(_HasSemantics);
- }
-
- public boolean isGetter() { return (Semantics & Getter) != 0; }
- public boolean isSetter() { return (Semantics & Setter) != 0; }
- public boolean isOther() { return (Semantics & Other) != 0; }
- public boolean isAddOn() { return (Semantics & AddOn) != 0; }
- public boolean isRemoveOn() { return (Semantics & RemoveOn) != 0; }
- public boolean isFire() { return (Semantics & Fire) != 0; }
-
- private static final short Setter = (short)0x0001;
- private static final short Getter = (short)0x0002;
- private static final short Other = (short)0x0004;
- private static final short AddOn = (short)0x0008;
- private static final short RemoveOn = (short)0x0010;
- private static final short Fire = (short)0x0020;
-
- } // class MethodSemantics
-
-
- //##########################################################################
- // table MethodImpl; ID=0x19; p113, 21.25
-
- public static final class MethodImpl extends Table {
- public static final int ID = 0x19;
-
- /** Index into the TypeDef table. */
- public int Class;
-
- /** Index into MethodDefOrRef table set. */
- public int MethodBody;
-
- /** Index into MethodDefOrRef table set. */
- public int MethodDeclaration;
-
- public MethodImpl(PEFile file, int rows) { super(file, ID, rows); }
-
- protected void populateFields() {
- Class = readTableIndex(TypeDef.ID);
- MethodBody = readTableSetIndex(_MethodDefOrRef);
- MethodDeclaration = readTableSetIndex(_MethodDefOrRef);
- }
-
- protected int getRowSize() {
- return file.getTableIndexSize(TypeDef.ID) +
- 2 * file.getTableSetIndexSize(_MethodDefOrRef);
- }
-
- } // class MethodImpl
-
- //##########################################################################
- // table ModuleRef; ID=0x1a; p116, 21.28
-
- public static final class ModuleRef extends Table {
- public static final int ID = 0x1a;
-
- /** Index into #String. */
- public int Name;
-
- public ModuleRef(PEFile file, int rows) { super(file, ID, rows); }
-
- protected void populateFields() {
- Name = readStringIndex();
- }
-
- protected int getRowSize() { return file.getStringIndexSize(); }
-
- public String getName() { return file.getString(Name); }
-
- } // class ModuleRef
-
- //##########################################################################
- // table TypeSpec; ID=0x1b; p126, 21.36
-
- public static final class TypeSpec extends Table {
- public static final int ID = 0x1b;
-
- /** Index into #Blob, where the blob is formatted
- * as specified in 22.2.15
- */
- public int Signature;
-
- public TypeSpec(PEFile file, int rows) { super(file, ID, rows); }
-
- protected void populateFields() {
- Signature = readBlobIndex();
- }
-
- protected int getRowSize() { return file.getBlobIndexSize(); }
-
- public Sig getSignature() { return file.getSignature(Signature); }
- } // class TypeSpec
-
- //##########################################################################
- // table ImplMap; ID=0x1c; p107, 21.20
-
- public static final class ImplMap extends Table {
- public static final int ID = 0x1c;
-
- /** 2-byte bitmask of type PInvokeAttributes (22.1.7). */
- public int MappingFlags;
-
- /** Index into MemberForwarded table set. */
- public int MemberForwarded;
-
- /** Index into #String. */
- public int ImportName;
-
- /** Index into the ModuleRef table. */
- public int ImportScope;
-
- public ImplMap(PEFile file, int rows) { super(file, ID, rows); }
-
- protected void populateFields() {
- MappingFlags = readShort();
- MemberForwarded = readTableSetIndex(_MemberForwarded);
- ImportName = readStringIndex();
- ImportScope = readTableIndex(ModuleRef.ID);
- }
-
- protected int getRowSize() {
- return 2 + file.getTableSetIndexSize(_MemberForwarded) +
- file.getStringIndexSize() +
- file.getTableIndexSize(ModuleRef.ID);
- }
-
- } // class ImplMap
-
- //##########################################################################
- // table FieldRVA; ID=0x1d; p106, 21.18
-
- public static final class FieldRVA extends Table {
- public static final int ID = 0x1d;
-
- /** 4-byte constant. */
- public int RVA;
-
- /** Index into the Field table. */
- public int Field;
-
- public FieldRVA(PEFile file, int rows) { super(file, ID, rows); }
-
- protected void populateFields() {
- RVA = readInt();
- Field = readTableIndex(Table.FieldDef.ID);
- }
-
- protected int getRowSize() {
- return 4 + file.getTableIndexSize(FieldDef.ID);
- }
-
- }
-
- //##########################################################################
- // table Assembly; ID=0x20; p90, 21.2
-
- public static final class AssemblyDef extends Table {
- public static final int ID = 0x20;
-
- /** 4-byte constatnt of type AssemblyHashAlgorithm, clause 22.1.1 */
- public int HashAlgId;
-
- /** 2-byte constant */
- public int MajorVersion;
-
- /** 2-byte constant */
- public int MinorVersion;
-
- /** 2-byte constant */
- public int BuildNumber;
-
- /** 2-byte constant */
- public int RevisionNumber;
-
- /** 4-byte constant */
- public int Flags;
-
- /** index into #Blob */
- public int PublicKey;
-
- /** index into #String */
- public int Name;
-
- /** index into #String */
- public int Culture;
-
- public AssemblyDef(PEFile file, int rows) { super(file, ID, rows); }
-
- protected void populateFields() {
- HashAlgId = readInt();
- MajorVersion = readShort();
- MinorVersion = readShort();
- BuildNumber = readShort();
- RevisionNumber = readShort();
- Flags = readInt();
- PublicKey = readBlobIndex();
- Name = readStringIndex();
- Culture = readStringIndex();
- }
-
- protected int getRowSize() {
- return 16 + file.getBlobIndexSize() + 2*file.getStringIndexSize();
- }
-
- } // class AssemblyDef
-
- //##########################################################################
- // table AssemblyProcessor; ID=0x21; p91, 21.4
-
- public static final class AssemblyProcessor extends Table {
- public static final int ID = 0x21;
-
- /** 4-byte constant. */
- public int Processor;
-
- public AssemblyProcessor(PEFile file, int rows) { super(file, ID, rows); }
-
- protected void populateFields() {
- Processor = readInt();
- }
-
- protected int getRowSize() { return 4; }
-
- }
-
- //##########################################################################
- // table AssemblyOS; ID = 0x22; p90, 21.3
-
- public static final class AssemblyOS extends Table {
- public static final int ID = 0x22;
-
- /** 4-byte constant. */
- public int OSPlatformID;
-
- /** 4-byte constant. */
- public int OSMajorVersion;
-
- /** 4-byte constant. */
- public int OSMinorVersion;
-
- public AssemblyOS(PEFile file, int rows) { super(file, ID, rows); }
-
- protected void populateFields() {
- OSPlatformID = readInt();
- OSMajorVersion = readInt();
- OSMinorVersion = readInt();
- }
-
- protected int getRowSize() { return 12; }
-
- }
-
- //##########################################################################
- // table AssemblyRef; ID = 0x23; pp91, 21.5
-
- public static final class AssemblyRef extends Table {
- public static final int ID = 0x23;
-
- /** 2-byte constant. */
- public int MajorVersion;
-
- /** 2-byte constant. */
- public int MinorVersion;
-
- /** 2-byte constant. */
- public int BuildNumber;
-
- /** 2-byte constant. */
- public int RevisionNumber;
-
- /** 4-byte bitmask of type AssemblyFlags (22.1.2). */
- public int Flags;
-
- /** index into #Blob. */
- public int PublicKeyOrToken;
-
- /** index into #String. */
- public int Name;
-
- /** index into #String. */
- public int Culture;
-
- /** index into #Blob. */
- public int HashValue;
-
- public AssemblyRef(PEFile file, int rows) { super(file, ID, rows); }
-
- protected void populateFields() {
- MajorVersion = readShort();
- MinorVersion = readShort();
- BuildNumber = readShort();
- RevisionNumber = readShort();
- Flags = readInt();
- PublicKeyOrToken = readBlobIndex();
- Name = readStringIndex();
- Culture = readStringIndex();
- HashValue = readBlobIndex();
- }
-
- protected int getRowSize() {
- return 12 + 2*file.getBlobIndexSize() + 2*file.getStringIndexSize();
- }
-
- public String getName() { return file.getString(Name); }
- }
-
- //##########################################################################
- // table AssemblyRefProcessor; ID=0x24; p92, 21.7
-
- public static final class AssemblyRefProcessor extends Table {
- public static final int ID = 0x24;
-
- /** 4-byte constant. */
- public int Processor;
-
- /** Index into the AssemblyRef table. */
- public int AssemblyRef;
-
- public AssemblyRefProcessor(PEFile file, int rows) { super(file, ID, rows); }
-
- protected void populateFields() {
- Processor = readInt();
- AssemblyRef = readTableIndex(Table.AssemblyRef.ID);
- }
-
- protected int getRowSize() {
- return 4 + file.getTableIndexSize(Table.AssemblyRef.ID);
- }
-
- } // class AssemblyRefProcessor
-
- //##########################################################################
- // table AssemblyRefOS; ID=0x25; p92, 21.6
-
- public static final class AssemblyRefOS extends Table {
- public static final int ID = 0x25;
-
- /** 4-byte constant. */
- public int OSPlatformId;
-
- /** 4-byte constant. */
- public int OSMajorVersion;
-
- /** 4-byte constant. */
- public int OSMinorVersion;
-
- /** Index into the AssemblyRef table. */
- public int AssemblyRef;
-
- public AssemblyRefOS(PEFile file, int rows) { super(file, ID, rows); }
-
- protected void populateFields() {
- OSPlatformId = readInt();
- OSMajorVersion = readInt();
- OSMinorVersion = readInt();
- AssemblyRef = readTableIndex(Table.AssemblyRef.ID);
- }
-
- protected int getRowSize() {
- return 12 + file.getTableIndexSize(Table.AssemblyRef.ID);
- }
-
- } // class AssemblyRefOS
-
- //##########################################################################
- // table File; ID=0x26; p106, 21.19
-
- public static final class FileDef extends Table {
- public static final int ID = 0x26;
-
- /** 4-byte bitmask of type FileAttributes (22.1.6). */
- public int Flags;
-
- /** Index into #String. */
- public int Name;
-
- /** Index into #Blob. */
- public int HashValue;
-
- public FileDef(PEFile file, int rows) { super(file, ID, rows); }
-
- protected void populateFields() {
- Flags = readInt();
- Name = readStringIndex();
- HashValue = readBlobIndex();
- }
-
- protected int getRowSize() {
- return 4 + file.getStringIndexSize() + file.getBlobIndexSize();
- }
-
- public String getName() {
- return file.getString(Name);
- }
-
- } // class FileDef
-
- //##########################################################################
- // table ExportedType; ID=0x27; p100, 21.14
-
- public static final class ExportedType extends Table {
- public static final int ID = 0x27;
-
- /** 4-byte bitmask of type TypeAttribute (22.1.6). */
- public int Flags;
-
- /** 4-byte index into a TypeDef table of
- * another module in this assembly.
- */
- public int TypeDefId;
-
- /** Index into #String. */
- public int TypeName;
-
- /** Index into #Stream. */
- public int TypeNamespace;
-
- /** Index into one of two tables as follows:
- * - 'File' table, where that entry says which module
- * in the current assembly holds the TypeDef
- * - 'ExportedType' table, where that entry is
- * the enclosing Type of the current nested Type
- */
- public int Implementation;
-
- public ExportedType(PEFile file, int rows) { super(file, ID, rows); }
-
- protected void populateFields() {
- Flags = readInt();
- TypeDefId = readInt();
- TypeName = readStringIndex();
- TypeNamespace = readStringIndex();
- Implementation = readTableSetIndex(_Implementation);
- }
-
- protected int getRowSize() {
- return 8 + 2*file.getStringIndexSize() +
- file.getTableSetIndexSize(_Implementation);
- }
-
- public String getFullName() {
- String namespace = file.getString(TypeNamespace);
- return namespace.length() == 0 ? file.getString(TypeName)
- : namespace + "." + file.getString(TypeName);
- }
-
- } // class ExportedType
-
- //##########################################################################
- // table ManifestResource; ID=0x28; p108, 21.22
-
- public static final class ManifestResource extends Table {
- public static final int ID = 0x28;
-
- /** 4-byte constant. */
- public int Offset;
-
- /** 4-byte bitmask of type ManifestResourceAttributes (22.1.8). */
- public int Flags;
-
- /** Index into #String. */
- public int Name;
-
- /** Index into the Implementation table set. */
- public int Implementation;
-
- public ManifestResource(PEFile file, int rows) { super(file, ID, rows); }
-
- protected void populateFields() {
- Offset = readInt();
- Flags = readInt();
- Name = readStringIndex();
- Implementation = readTableSetIndex(_Implementation);
- }
-
- protected int getRowSize() {
- return 8 + file.getStringIndexSize() +
- file.getTableSetIndexSize(_Implementation);
- }
-
- } // class ManifestResource
-
- //##########################################################################
- // table NestedClass; ID=0x29; p116, 21.29
-
- public static final class NestedClass extends Table {
- public static final int ID = 0x29;
-
- /** Index into the TypeDef table. */
- public int NestedClass;
-
- /** Index into the TypeDef table. */
- public int EnclosingClass;
-
- public NestedClass(PEFile file, int rows) { super(file, ID, rows); }
-
- protected void populateFields() {
- NestedClass = readTableIndex(TypeDef.ID);
- EnclosingClass = readTableIndex(TypeDef.ID);
- }
-
- protected int getRowSize() {
- return 2 * file.getTableIndexSize(TypeDef.ID);
- }
-
- } // class NestedClass
-
- //##########################################################################
- // table GenericParam; ID=0x2a; p137, 22.20
-
- public static final class GenericParam extends Table {
- public static final int ID = 0x2a;
-
- public int Number;
- public int Flags;
- public int Owner; // a TypeOrMethodDef (Sec 24.2.6) coded index
- public int Name; // a non-null index into the String heap
-
- private java.util.Map /*<Integer, java.util.Set<Integer>>*/ GenericParamIdxesForMethodDefIdx =
- new java.util.HashMap();
- private java.util.Map /*<Integer, java.util.Set<Integer>>*/ GenericParamIdxesForTypeDefIdx =
- new java.util.HashMap();
-
- private void addToMap(int key, int value, java.util.Map IdxesForIdx) {
- java.util.Set /*<Integer>*/ bucket = (java.util.Set)IdxesForIdx.get(Integer.valueOf(key));
- if(bucket == null) {
- bucket = new java.util.HashSet();
- IdxesForIdx.put(Integer.valueOf(key), bucket);
- }
- bucket.add(Integer.valueOf(value));
- }
-
- /** Indexes of rows in the GenericParam table representing type parameters defined by the type given by
- * its row index TypeDefIdx (in the TypeDef table).
- * No need to position the current record before invoking this method. */
- public int[] getTVarIdxes(int TypeDefIdx) {
- if(!mapsPopulated) {
- initMaps();
- }
- java.util.Set bucket = (java.util.Set)GenericParamIdxesForTypeDefIdx.get(Integer.valueOf(TypeDefIdx));
- if(bucket == null) {
- bucket = java.util.Collections.EMPTY_SET;
- }
- int[] res = new int[bucket.size()];
- java.util.Iterator /*<Integer>*/ it = bucket.iterator();
- for(int i = 0; i < bucket.size(); i++) {
- res[i] = ((Integer)it.next()).intValue();
- }
- return res;
- }
-
- /** Indexes of rows in the GenericParam table representing type parameters defined by the method given by
- * its row index MethodDefIdx (in the MethodDef table)
- * No need to position the current record before invoking this method. */
- public int[] getMVarIdxes(int MethodDefIdx) {
- if(!mapsPopulated) {
- initMaps();
- }
- java.util.Set bucket = (java.util.Set)GenericParamIdxesForMethodDefIdx.get(Integer.valueOf(MethodDefIdx));
- if(bucket == null) {
- bucket = java.util.Collections.EMPTY_SET;
- }
- int[] res = new int[bucket.size()];
- java.util.Iterator /*<Integer>*/ it = bucket.iterator();
- for(int i = 0; i < bucket.size(); i++) {
- res[i] = ((Integer)it.next()).intValue();
- }
- return res;
- }
-
- private boolean mapsPopulated = false;
-
- private void initMaps() {
- mapsPopulated = true;
- for (int currentParamRow = 1; currentParamRow <= rows; currentParamRow++) {
- int currentOwner = file.GenericParam(currentParamRow).Owner;
- int targetTableId = Table.getTableId(Table._TypeOrMethodDef, currentOwner);
- int targetRow = currentOwner >> Table.NoBits[Table._TypeOrMethodDef];
- if(targetTableId == TypeDef.ID){
- addToMap(targetRow, currentParamRow, GenericParamIdxesForTypeDefIdx);
- } else if(targetTableId == MethodDef.ID) {
- addToMap(targetRow, currentParamRow, GenericParamIdxesForMethodDefIdx);
- } else {
- throw new RuntimeException();
- }
- }
- }
-
- public GenericParam(PEFile file, int rows) {
- super(file, ID, rows);
- this.newMapping = true;
- }
-
- protected void populateFields() {
- Number = readShort();
- Flags = readShort();
- Owner = readTableSetIndex(_TypeOrMethodDef);
- Name = readStringIndex();
- }
-
- /** This method assumes populateFields() has been just called to set Flags for the current record */
- public boolean isInvariant() {
- /* 23.1.7 Flags for Generic Parameters [GenericParamAttributes tributes] */
- return (Flags & 0x0003) == 0;
- }
-
- /** This method assumes populateFields() has been just called to set Flags for the current record */
- public boolean isCovariant() {
- /* 23.1.7 Flags for Generic Parameters [GenericParamAttributes tributes] */
- return (Flags & 0x0003) == 1;
- }
-
- /** This method assumes populateFields() has been just called to set Flags for the current record */
- public boolean isContravariant() {
- /* 23.1.7 Flags for Generic Parameters [GenericParamAttributes tributes] */
- return (Flags & 0x0003) == 2;
- }
-
- /** This method assumes populateFields() has been just called to set Flags for the current record */
- public boolean isReferenceType() {
- /* 23.1.7 Flags for Generic Parameters [GenericParamAttributes tributes] */
- return (Flags & 0x001C) == 4;
- }
-
- /** This method assumes populateFields() has been just called to set Flags for the current record */
- public boolean isValueType() {
- /* 23.1.7 Flags for Generic Parameters [GenericParamAttributes tributes] */
- return (Flags & 0x001C) == 8;
- }
-
- /** This method assumes populateFields() has been just called to set Flags for the current record */
- public boolean hasDefaultConstructor() {
- /* 23.1.7 Flags for Generic Parameters [GenericParamAttributes tributes] */
- return (Flags & 0x001C) == 0x0010;
- }
-
- protected int getRowSize() {
- return 2 + 2 + file.getTableSetIndexSize(_TypeOrMethodDef) + file.getStringIndexSize();
- /* Columns:
- Number (2 bytes),
- Flags (2 bytes),
- Owner (coded token of type TypeOrMethodDef),
- Name (offset in the #Strings stream).
- */
- }
-
- public String getName() {
- return file.getString(Name);
- }
-
- } // class GenericParam
-
-
- //##########################################################################
- // table GenericParamConstraint; ID=0x2c; p139, 22.20
-
- public static final class GenericParamConstraint extends Table {
- public static final int ID = 0x2c;
-
- public int Owner; // an index into the GenericParam table
- public int Constraint; // a TypeDefOrRef (Sec 24.2.6) coded index
-
- public GenericParamConstraint(PEFile file, int rows) {
- super(file, ID, rows);
- this.newMapping = true;
- }
-
- protected void populateFields() {
- Owner = readTableIndex(GenericParam.ID);
- Constraint = readTableSetIndex(_TypeDefOrRef);
- }
-
- protected int getRowSize() {
- return file.getTableIndexSize(GenericParam.ID) + file.getTableSetIndexSize(_TypeDefOrRef);
- /* Columns:
- Owner (RID in the GenericParam table),
- Constraint (coded token of type TypeDefOrRef).
- */
- }
-
- private boolean mapPopulated = false;
-
- /** Indexes of rows (in the TypeDef, TypeRef, or TypeSpec tables) denoting the base class (if any)
- * and interfaces (if any) that the generic parameter (of TVar or MVar kind) should support, where
- * that generic parameter is represented by its index into the GenericParam table. */
- public int[] getTypeDefOrRefIdxes(int genParamIdx) {
- if(!mapPopulated) {
- initMap();
- }
- java.util.Set bucket = (java.util.Set)TypeDefOrRefIdxesForGenParamIdx.get(Integer.valueOf(genParamIdx));
- if(bucket == null) {
- bucket = java.util.Collections.EMPTY_SET;
- }
- int[] res = new int[bucket.size()];
- java.util.Iterator /*<Integer>*/ it = bucket.iterator();
- for(int i = 0; i < bucket.size(); i++) {
- res[i] = ((Integer)it.next()).intValue();
- }
- return res;
- }
-
-
- private void initMap() {
- mapPopulated = true;
- for (int currentConstraintRow = 1; currentConstraintRow <= rows; currentConstraintRow++) {
- int targetGenericParam = file.GenericParamConstraint(currentConstraintRow).Owner;
- int value = file.GenericParamConstraint.Constraint;
- addToMap(targetGenericParam, value);
- }
- }
-
- private java.util.Map /*<Integer, java.util.Set<Integer>>*/ TypeDefOrRefIdxesForGenParamIdx =
- new java.util.HashMap();
-
- private void addToMap(int key, int value) {
- java.util.Set /*<Integer>*/ bucket = (java.util.Set)TypeDefOrRefIdxesForGenParamIdx.get(Integer.valueOf(key));
- if(bucket == null) {
- bucket = new java.util.HashSet();
- TypeDefOrRefIdxesForGenParamIdx.put(Integer.valueOf(key), bucket);
- }
- bucket.add(Integer.valueOf(value));
- }
-
- } // class GenericParamConstraint
-
- //##########################################################################
- // table MethodSpec; ID=0x2b; p149, in Sec. 22.29 of Partition II
-
- public static final class MethodSpec extends Table {
- public static final int ID = 0x2b;
-
- /* an index into the MethodDef or MemberRef table, specifying which generic method this row is an instantiation of.
- A MethodDefOrRef (Sec. 24.2.6) coded index */
- public int Method;
-
- /* an index into the Blob heap (Sec. 23.2.15), holding the signature of this instantiation */
- public int Instantiation;
-
- public MethodSpec(PEFile file, int rows) {
- super(file, ID, rows);
- this.newMapping = true;
- }
-
- protected void populateFields() {
- Method = readTableSetIndex(_MethodDefOrRef);
- Instantiation = readBlobIndex();
- }
-
- protected int getRowSize() {
- return file.getTableSetIndexSize(_MethodDefOrRef) + file.getBlobIndexSize();
- }
-
-
- } // class MethodSpec
- //##########################################################################
-
-} // class Table
diff --git a/src/partest/scala/tools/partest/CompilerTest.scala b/src/partest/scala/tools/partest/CompilerTest.scala
index d73d99bc89..7495f97efd 100644
--- a/src/partest/scala/tools/partest/CompilerTest.scala
+++ b/src/partest/scala/tools/partest/CompilerTest.scala
@@ -21,7 +21,7 @@ abstract class CompilerTest extends DirectTest {
lazy val global: Global = newCompiler()
lazy val units = compilationUnits(global)(sources: _ *)
import global._
- import definitions._
+ import definitions.{ compilerTypeFromTag }
override def extraSettings = "-usejavacp -d " + testOutput.path
@@ -32,7 +32,6 @@ abstract class CompilerTest extends DirectTest {
def sources: List[String] = List(code)
// Utility functions
-
class MkType(sym: Symbol) {
def apply[M](implicit t: ru.TypeTag[M]): Type =
if (sym eq NoSymbol) NoType
@@ -50,7 +49,7 @@ abstract class CompilerTest extends DirectTest {
}
class SymsInPackage(pkgName: String) {
- def pkg = rootMirror.getRequiredPackage(pkgName)
+ def pkg = rootMirror.getPackage(pkgName)
def classes = allMembers(pkg) filter (_.isClass)
def modules = allMembers(pkg) filter (_.isModule)
def symbols = classes ++ terms filterNot (_ eq NoSymbol)
diff --git a/src/partest/scala/tools/partest/PartestDefaults.scala b/src/partest/scala/tools/partest/PartestDefaults.scala
index b27ce6ff75..e3f1cb8bd9 100644
--- a/src/partest/scala/tools/partest/PartestDefaults.scala
+++ b/src/partest/scala/tools/partest/PartestDefaults.scala
@@ -8,8 +8,6 @@ import java.lang.Runtime.getRuntime
object PartestDefaults {
import nsc.Properties._
- private def wrapAccessControl[T](body: => Option[T]): Option[T] =
- try body catch { case _: java.security.AccessControlException => None }
def testRootName = propOrNone("partest.root")
def srcDirName = propOrElse("partest.srcdir", "files")
diff --git a/src/partest/scala/tools/partest/PartestTask.scala b/src/partest/scala/tools/partest/PartestTask.scala
index d9f2bfe765..41d69a5448 100644
--- a/src/partest/scala/tools/partest/PartestTask.scala
+++ b/src/partest/scala/tools/partest/PartestTask.scala
@@ -182,7 +182,6 @@ class PartestTask extends Task with CompilationPathProperty {
private var javaccmd: Option[File] = None
private var showDiff: Boolean = false
private var showLog: Boolean = false
- private var runFailed: Boolean = false
private var posFiles: Option[FileSet] = None
private var negFiles: Option[FileSet] = None
private var runFiles: Option[FileSet] = None
@@ -345,7 +344,6 @@ class PartestTask extends Task with CompilationPathProperty {
antFileManager.showDiff = showDiff
antFileManager.showLog = showLog
- antFileManager.failed = runFailed
antFileManager.CLASSPATH = ClassPath.join(classpath.list: _*)
antFileManager.LATEST_LIB = scalaLibrary.getAbsolutePath
antFileManager.LATEST_REFLECT = scalaReflect.getAbsolutePath
diff --git a/src/partest/scala/tools/partest/ScaladocModelTest.scala b/src/partest/scala/tools/partest/ScaladocModelTest.scala
index b9abff69d8..3db9f18484 100644
--- a/src/partest/scala/tools/partest/ScaladocModelTest.scala
+++ b/src/partest/scala/tools/partest/ScaladocModelTest.scala
@@ -5,8 +5,6 @@
package scala.tools.partest
-import scala.tools.partest._
-import java.io._
import scala.tools.nsc._
import scala.tools.nsc.util.CommandLineParser
import scala.tools.nsc.doc.{Settings, DocFactory, Universe}
@@ -87,7 +85,7 @@ abstract class ScaladocModelTest extends DirectTest {
settings = new Settings(_ => ())
settings.scaladocQuietRun = true // yaay, no more "model contains X documentable templates"!
val args = extraSettings + " " + scaladocSettings
- val command = new ScalaDoc.Command((CommandLineParser tokenize (args)), settings)
+ new ScalaDoc.Command((CommandLineParser tokenize (args)), settings) // side-effecting, I think
val docFact = new DocFactory(new ConsoleReporter(settings), settings)
docFact
}
diff --git a/src/partest/scala/tools/partest/SecurityTest.scala b/src/partest/scala/tools/partest/SecurityTest.scala
index 2d6f61d0b1..1f1c8a95ea 100644
--- a/src/partest/scala/tools/partest/SecurityTest.scala
+++ b/src/partest/scala/tools/partest/SecurityTest.scala
@@ -10,23 +10,10 @@ import java.util._
abstract class SecurityTest extends App {
def throwIt(x: Any) = throw new AccessControlException("" + x)
-
- def readPerm(p: PropertyPermission) = p.getActions contains "read"
- def writePerm(p: PropertyPermission) = p.getActions contains "write"
def propertyCheck(p: PropertyPermission): Unit = throwIt(p)
def check(perm: Permission): Unit = perm match {
case p: PropertyPermission => propertyCheck(p)
case _ => ()
}
-
- lazy val sm = new SecurityManager {
- // these two are the choke points for all permissions checks
- override def checkPermission(perm: Permission): Unit = check(perm)
- override def checkPermission(perm: Permission, context: Object): Unit = check(perm)
- }
- def securityOn(): Boolean = {
- try { System.setSecurityManager(sm) ; true }
- catch { case _: SecurityException => false }
- }
}
diff --git a/src/partest/scala/tools/partest/TestUtil.scala b/src/partest/scala/tools/partest/TestUtil.scala
index 9bfd444180..5c177ac962 100644
--- a/src/partest/scala/tools/partest/TestUtil.scala
+++ b/src/partest/scala/tools/partest/TestUtil.scala
@@ -24,14 +24,6 @@ trait TestUtil {
}
def nanos(body: => Unit): Long = alsoNanos(body)._1
- def verifySpeed(body1: => Unit, body2: => Unit, acceptableMultiple: Double) = {
- val t1 = nanos(body1).toDouble
- val t2 = nanos(body2).toDouble
- val mult = if (t1 > t2) t1 / t2 else t2 / t1
-
- assert(mult <= acceptableMultiple, "Performance difference too great: multiple = " + mult)
- }
-
def intercept[T <: Exception : ClassTag](code: => Unit): Unit =
try {
code
@@ -41,6 +33,6 @@ trait TestUtil {
}
}
+// Used in tests.
object TestUtil extends TestUtil {
-
}
diff --git a/src/partest/scala/tools/partest/instrumented/Instrumentation.scala b/src/partest/scala/tools/partest/instrumented/Instrumentation.scala
index 8a284b313b..18dd740208 100644
--- a/src/partest/scala/tools/partest/instrumented/Instrumentation.scala
+++ b/src/partest/scala/tools/partest/instrumented/Instrumentation.scala
@@ -78,6 +78,7 @@ object Instrumentation {
!t.className.startsWith("scala/util/DynamicVariable")
}
+ // Used in tests.
def printStatistics(stats: Statistics = getStatistics, filter: MethodCallTrace => Boolean = standardFilter): Unit = {
val stats = getStatistics
println("Method call statistics:")
diff --git a/src/partest/scala/tools/partest/javaagent/ASMTransformer.java b/src/partest/scala/tools/partest/javaagent/ASMTransformer.java
index 494a5a99be..878c8613d5 100644
--- a/src/partest/scala/tools/partest/javaagent/ASMTransformer.java
+++ b/src/partest/scala/tools/partest/javaagent/ASMTransformer.java
@@ -26,9 +26,18 @@ public class ASMTransformer implements ClassFileTransformer {
className.startsWith("instrumented/"));
}
- public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) {
+ public byte[] transform(final ClassLoader classLoader, final String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) {
if (shouldTransform(className)) {
- ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
+ ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS) {
+ @Override protected String getCommonSuperClass(final String type1, final String type2) {
+ // Since we are not recomputing stack frame map, this should never be called we override this method because
+ // default implementation uses reflection for implementation and might try to load the class that we are
+ // currently processing. That leads to weird results like swallowed exceptions and classes being not
+ // transformed.
+ throw new RuntimeException("Unexpected call to getCommonSuperClass(" + type1 + ", " + type2 +
+ ") while transforming " + className);
+ }
+ };
ProfilerVisitor visitor = new ProfilerVisitor(writer);
ClassReader reader = new ClassReader(classfileBuffer);
reader.accept(visitor, 0);
diff --git a/src/partest/scala/tools/partest/javaagent/ProfilerVisitor.java b/src/partest/scala/tools/partest/javaagent/ProfilerVisitor.java
index ac83f66506..8306327b14 100644
--- a/src/partest/scala/tools/partest/javaagent/ProfilerVisitor.java
+++ b/src/partest/scala/tools/partest/javaagent/ProfilerVisitor.java
@@ -33,6 +33,19 @@ public class ProfilerVisitor extends ClassVisitor implements Opcodes {
// only instrument non-abstract methods
if((access & ACC_ABSTRACT) == 0) {
assert(className != null);
+ /* The following instructions do not modify compressed stack frame map so
+ * we don't need to worry about recalculating stack frame map. Specifically,
+ * let's quote "ASM 4.0, A Java bytecode engineering library" guide (p. 40):
+ *
+ * In order to save space, a compiled method does not contain one frame per
+ * instruction: in fact it contains only the frames for the instructions
+ * that correspond to jump targets or exception handlers, or that follow
+ * unconditional jump instructions. Indeed the other frames can be easily
+ * and quickly inferred from these ones.
+ *
+ * Instructions below are just loading constants and calling a method so according
+ * to definition above they do not contribute to compressed stack frame map.
+ */
mv.visitLdcInsn(className);
mv.visitLdcInsn(name);
mv.visitLdcInsn(desc);
diff --git a/src/partest/scala/tools/partest/javaagent/ProfilingAgent.java b/src/partest/scala/tools/partest/javaagent/ProfilingAgent.java
index c2e4dc69f4..3b18987040 100644
--- a/src/partest/scala/tools/partest/javaagent/ProfilingAgent.java
+++ b/src/partest/scala/tools/partest/javaagent/ProfilingAgent.java
@@ -20,6 +20,6 @@ public class ProfilingAgent {
// and the test-case itself won't be loaded yet. We rely here on the fact that ASMTransformer does
// not depend on Scala library. In case our assumptions are wrong we can always insert call to
// inst.retransformClasses.
- inst.addTransformer(new ASMTransformer(), true);
+ inst.addTransformer(new ASMTransformer(), false);
}
}
diff --git a/src/partest/scala/tools/partest/nest/CompileManager.scala b/src/partest/scala/tools/partest/nest/CompileManager.scala
index 188ebf66ed..3f005d143e 100644
--- a/src/partest/scala/tools/partest/nest/CompileManager.scala
+++ b/src/partest/scala/tools/partest/nest/CompileManager.scala
@@ -71,7 +71,6 @@ class DirectCompiler(val fileManager: FileManager) extends SimpleCompiler {
}
private def updatePluginPath(options: String): String = {
- val dir = fileManager.testRootDir
def absolutize(path: String) = Path(path) match {
case x if x.isAbsolute => x.path
case x => (fileManager.testRootDir / x).toAbsolute.path
diff --git a/src/partest/scala/tools/partest/nest/ConsoleFileManager.scala b/src/partest/scala/tools/partest/nest/ConsoleFileManager.scala
index 08e709de90..0ec3f60bf5 100644
--- a/src/partest/scala/tools/partest/nest/ConsoleFileManager.scala
+++ b/src/partest/scala/tools/partest/nest/ConsoleFileManager.scala
@@ -18,8 +18,6 @@ import io.{ Path, Directory }
import File.pathSeparator
import ClassPath.{ join }
import PathResolver.{ Environment, Defaults }
-import RunnerUtils._
-
class ConsoleFileManager extends FileManager {
var testBuild: Option[String] = PartestDefaults.testBuild
@@ -81,29 +79,24 @@ class ConsoleFileManager extends FileManager {
testClassesDir = Path(testClasses.get).toCanonical.toDirectory
NestUI.verbose("Running with classes in "+testClassesDir)
- latestFile = testClassesDir.parent / "bin"
latestLibFile = testClassesDir / "library"
latestActorsFile = testClassesDir / "library" / "actors"
latestReflectFile = testClassesDir / "reflect"
latestCompFile = testClassesDir / "compiler"
latestPartestFile = testClassesDir / "partest"
- latestFjbgFile = testParent / "lib" / "fjbg.jar"
}
else if (testBuild.isDefined) {
val dir = Path(testBuild.get)
NestUI.verbose("Running on "+dir)
- latestFile = dir / "bin"
latestLibFile = dir / "lib/scala-library.jar"
latestActorsFile = dir / "lib/scala-actors.jar"
latestReflectFile = dir / "lib/scala-reflect.jar"
latestCompFile = dir / "lib/scala-compiler.jar"
latestPartestFile = dir / "lib/scala-partest.jar"
- latestFjbgFile = testParent / "lib" / "fjbg.jar"
}
else {
def setupQuick() {
NestUI.verbose("Running build/quick")
- latestFile = prefixFile("build/quick/bin")
latestLibFile = prefixFile("build/quick/classes/library")
latestActorsFile = prefixFile("build/quick/classes/library/actors")
latestReflectFile = prefixFile("build/quick/classes/reflect")
@@ -114,7 +107,6 @@ class ConsoleFileManager extends FileManager {
def setupInst() {
NestUI.verbose("Running dist (installed)")
val p = testParent.getParentFile
- latestFile = prefixFileWith(p, "bin")
latestLibFile = prefixFileWith(p, "lib/scala-library.jar")
latestActorsFile = prefixFileWith(p, "lib/scala-actors.jar")
latestReflectFile = prefixFileWith(p, "lib/scala-reflect.jar")
@@ -124,7 +116,6 @@ class ConsoleFileManager extends FileManager {
def setupDist() {
NestUI.verbose("Running dists/latest")
- latestFile = prefixFile("dists/latest/bin")
latestLibFile = prefixFile("dists/latest/lib/scala-library.jar")
latestActorsFile = prefixFile("dists/latest/lib/scala-actors.jar")
latestReflectFile = prefixFile("dists/latest/lib/scala-reflect.jar")
@@ -134,7 +125,6 @@ class ConsoleFileManager extends FileManager {
def setupPack() {
NestUI.verbose("Running build/pack")
- latestFile = prefixFile("build/pack/bin")
latestLibFile = prefixFile("build/pack/lib/scala-library.jar")
latestActorsFile = prefixFile("build/pack/lib/scala-actors.jar")
latestReflectFile = prefixFile("build/pack/lib/scala-reflect.jar")
@@ -142,11 +132,6 @@ class ConsoleFileManager extends FileManager {
latestPartestFile = prefixFile("build/pack/lib/scala-partest.jar")
}
- val dists = testParent / "dists"
- val build = testParent / "build"
- // in case of an installed dist, testRootDir is one level deeper
- val bin = testParent.parent / "bin"
-
def mostRecentOf(base: String, names: String*) =
names map (x => prefixFile(base + "/" + x).lastModified) reduceLeft (_ max _)
@@ -165,8 +150,6 @@ class ConsoleFileManager extends FileManager {
// run setup based on most recent time
pairs(pairs.keys max)()
-
- latestFjbgFile = prefixFile("lib/fjbg.jar")
}
LATEST_LIB = latestLibFile.getAbsolutePath
@@ -182,20 +165,16 @@ class ConsoleFileManager extends FileManager {
var LATEST_PARTEST: String = ""
var LATEST_ACTORS: String = ""
- var latestFile: File = _
var latestLibFile: File = _
var latestActorsFile: File = _
var latestReflectFile: File = _
var latestCompFile: File = _
var latestPartestFile: File = _
- var latestFjbgFile: File = _
def latestScalapFile: File = (latestLibFile.parent / "scalap.jar").jfile
var testClassesDir: Directory = _
// initialize above fields
findLatest()
- var testFiles: List[io.Path] = Nil
-
def getFiles(kind: String, cond: Path => Boolean): List[File] = {
def ignoreDir(p: Path) = List("svn", "obj") exists (p hasExtension _)
@@ -204,9 +183,7 @@ class ConsoleFileManager extends FileManager {
if (dir.isDirectory) NestUI.verbose("look in %s for tests" format dir)
else NestUI.failure("Directory '%s' not found" format dir)
- val files =
- if (testFiles.nonEmpty) testFiles filter (_.parent isSame dir)
- else dir.list filterNot ignoreDir filter cond toList
+ val files = dir.list filterNot ignoreDir filter cond toList
( if (failed) files filter (x => logFileExists(x, kind)) else files ) map (_.jfile)
}
diff --git a/src/partest/scala/tools/partest/nest/ConsoleRunner.scala b/src/partest/scala/tools/partest/nest/ConsoleRunner.scala
index e016fb7c92..d146618d0e 100644
--- a/src/partest/scala/tools/partest/nest/ConsoleRunner.scala
+++ b/src/partest/scala/tools/partest/nest/ConsoleRunner.scala
@@ -11,7 +11,6 @@ package nest
import java.io.{File, PrintStream, FileOutputStream, BufferedReader,
InputStreamReader, StringWriter, PrintWriter}
import utils.Properties._
-import RunnerUtils._
import scala.tools.nsc.Properties.{ versionMsg, setProp }
import scala.tools.nsc.util.CommandLineParser
import scala.tools.nsc.io
@@ -26,8 +25,6 @@ class ConsoleRunner extends DirectRunner {
private def antFilter(p: Path) = p.isFile && (p endsWith "build.xml")
val testSets = {
- val pathFilter: Path => Boolean = x => x.isDirectory || (x hasExtension "scala")
-
List(
TestSet("pos", stdFilter, "Testing compiler (on files whose compilation should succeed)"),
TestSet("neg", stdFilter, "Testing compiler (on files whose compilation should fail)"),
@@ -54,8 +51,6 @@ class ConsoleRunner extends DirectRunner {
private val testSetArgs = testSets map ("--" + _.kind)
private val testSetArgMap = testSetArgs zip testSets toMap
- def denotesTestSet(arg: String) = testSetArgs contains arg
-
private def printVersion() { NestUI outline (versionMsg + "\n") }
private val unaryArgs = List(
@@ -70,10 +65,11 @@ class ConsoleRunner extends DirectRunner {
// true if a test path matches the --grep expression.
private def pathMatchesExpr(path: Path, expr: String) = {
def pred(p: Path) = file2String(p.toFile) contains expr
- def srcs = path.toDirectory.deepList() filter (_.hasExtension("scala", "java"))
+ def greppable(f: Path) = f.isFile && (f hasExtension ("scala", "java"))
+ def any(d: Path) = d.toDirectory.deepList() exists (f => greppable(f) && pred(f))
(path.isFile && pred(path)) ||
- (path.isDirectory && srcs.exists(pred)) ||
+ (path.isDirectory && any(path)) ||
(pred(path changeExtension "check"))
}
@@ -94,8 +90,6 @@ class ConsoleRunner extends DirectRunner {
else if (parsed isSet "--pack") new ConsoleFileManager("build/pack")
else new ConsoleFileManager // auto detection, see ConsoleFileManager.findLatest
- def argNarrowsTests(x: String) = denotesTestSet(x) || denotesTestPath(x)
-
NestUI._verbose = parsed isSet "--verbose"
fileManager.showDiff = true
// parsed isSet "--show-diff"
@@ -121,7 +115,7 @@ class ConsoleRunner extends DirectRunner {
val grepOption = parsed get "--grep"
val grepPaths = grepOption.toList flatMap { expr =>
val subjectDirs = testSetKinds map (srcDir / _ toDirectory)
- val testPaths = subjectDirs flatMap (_.files filter stdFilter)
+ val testPaths = subjectDirs flatMap (_.list filter stdFilter)
val paths = testPaths filter (p => pathMatchesExpr(p, expr))
if (paths.isEmpty)
diff --git a/src/partest/scala/tools/partest/nest/DirectRunner.scala b/src/partest/scala/tools/partest/nest/DirectRunner.scala
index 32ef8b41ea..3aaf784cad 100644
--- a/src/partest/scala/tools/partest/nest/DirectRunner.scala
+++ b/src/partest/scala/tools/partest/nest/DirectRunner.scala
@@ -14,7 +14,6 @@ import scala.tools.nsc.util.ScalaClassLoader
import scala.tools.nsc.io.Path
import scala.collection.{ mutable, immutable }
import java.util.concurrent._
-import scala.collection.convert.decorateAll._
case class TestRunParams(val scalaCheckParentClassLoader: ScalaClassLoader)
diff --git a/src/partest/scala/tools/partest/nest/FileManager.scala b/src/partest/scala/tools/partest/nest/FileManager.scala
index 2823967ecf..a4c4e7e6a6 100644
--- a/src/partest/scala/tools/partest/nest/FileManager.scala
+++ b/src/partest/scala/tools/partest/nest/FileManager.scala
@@ -13,7 +13,6 @@ import java.io.{File, FilenameFilter, IOException, StringWriter,
FileReader, PrintWriter, FileWriter}
import java.net.URI
import scala.tools.nsc.io.{ Path, Directory, File => SFile }
-import scala.sys.process._
import scala.collection.mutable
trait FileUtil {
@@ -73,17 +72,11 @@ trait FileManager extends FileUtil {
var SCALAC_OPTS = PartestDefaults.scalacOpts.split(' ').toSeq
var JAVA_OPTS = PartestDefaults.javaOpts
var timeout = PartestDefaults.timeout
- // how can 15 minutes not be enough? What are you doing, run/lisp.scala?
- // You complete in 11 seconds on my machine.
- var oneTestTimeout = 60 * 60 * 1000
/** Only when --debug is given. */
lazy val testTimings = new mutable.HashMap[String, Long]
def recordTestTiming(name: String, milliseconds: Long) =
synchronized { testTimings(name) = milliseconds }
- def showTestTimings() {
- testTimings.toList sortBy (-_._2) foreach { case (k, v) => println("%s: %s".format(k, v)) }
- }
def getLogFile(dir: File, fileBase: String, kind: String): File =
new File(dir, fileBase + "-" + kind + ".log")
diff --git a/src/partest/scala/tools/partest/nest/NestUI.scala b/src/partest/scala/tools/partest/nest/NestUI.scala
index 70db6d0ed1..ab90d387d0 100644
--- a/src/partest/scala/tools/partest/nest/NestUI.scala
+++ b/src/partest/scala/tools/partest/nest/NestUI.scala
@@ -54,9 +54,6 @@ object NestUI {
}
def warning(msg: String) = print(_warning + msg + _default)
- def warning(msg: String, wr: PrintWriter) = synchronized {
- wr.print(_warning + msg + _default)
- }
def normal(msg: String) = print(_default + msg)
def normal(msg: String, wr: PrintWriter) = synchronized {
@@ -104,7 +101,6 @@ object NestUI {
}
var _verbose = false
- var _debug = false
def verbose(msg: String) {
if (_verbose) {
@@ -112,10 +108,4 @@ object NestUI {
println(msg)
}
}
- def debug(msg: String) {
- if (isPartestDebug) {
- outline("debug: ")
- println(msg)
- }
- }
}
diff --git a/src/partest/scala/tools/partest/nest/PathSettings.scala b/src/partest/scala/tools/partest/nest/PathSettings.scala
index a42c2219b1..02651c527b 100644
--- a/src/partest/scala/tools/partest/nest/PathSettings.scala
+++ b/src/partest/scala/tools/partest/nest/PathSettings.scala
@@ -9,7 +9,6 @@ import scala.tools.nsc.Properties.{ setProp, propOrEmpty, propOrNone, propOrElse
import scala.tools.nsc.util.ClassPath
import scala.tools.nsc.io
import io.{ Path, File, Directory }
-import RunnerUtils._
object PathSettings {
import PartestDefaults.{ testRootDir, srcDirName }
diff --git a/src/partest/scala/tools/partest/nest/ReflectiveRunner.scala b/src/partest/scala/tools/partest/nest/ReflectiveRunner.scala
index 5cb8589d66..d3a40718c6 100644
--- a/src/partest/scala/tools/partest/nest/ReflectiveRunner.scala
+++ b/src/partest/scala/tools/partest/nest/ReflectiveRunner.scala
@@ -3,8 +3,6 @@
* @author Philipp Haller
*/
-// $Id$
-
package scala.tools.partest
package nest
@@ -12,7 +10,6 @@ import scala.tools.nsc.Properties.{ setProp, propOrEmpty }
import scala.tools.nsc.util.ClassPath
import scala.tools.nsc.io
import io.Path
-import RunnerUtils._
import java.net.URLClassLoader
/* This class is used to load an instance of DirectRunner using
@@ -28,6 +25,12 @@ class ReflectiveRunner {
// was used to start the runner.
val sepRunnerClassName = "scala.tools.partest.nest.ConsoleRunner"
+ private def searchPath(option: String, as: List[String]): Option[String] = as match {
+ case `option` :: r :: _ => Some(r)
+ case _ :: rest => searchPath(option, rest)
+ case Nil => None
+ }
+
def main(args: String) {
val argList = (args.split("\\s")).toList
@@ -48,9 +51,9 @@ class ReflectiveRunner {
new ConsoleFileManager
import fileManager.
- { latestCompFile, latestReflectFile, latestLibFile, latestPartestFile, latestFjbgFile, latestScalapFile, latestActorsFile }
+ { latestCompFile, latestReflectFile, latestLibFile, latestPartestFile, latestScalapFile, latestActorsFile }
val files =
- Array(latestCompFile, latestReflectFile, latestLibFile, latestPartestFile, latestFjbgFile, latestScalapFile, latestActorsFile) map (x => io.File(x))
+ Array(latestCompFile, latestReflectFile, latestLibFile, latestPartestFile, latestScalapFile, latestActorsFile) map (x => io.File(x))
val sepUrls = files map (_.toURL)
var sepLoader = new URLClassLoader(sepUrls, null)
diff --git a/src/partest/scala/tools/partest/nest/RunnerManager.scala b/src/partest/scala/tools/partest/nest/RunnerManager.scala
index c5e944fbc0..f2ce19a950 100644
--- a/src/partest/scala/tools/partest/nest/RunnerManager.scala
+++ b/src/partest/scala/tools/partest/nest/RunnerManager.scala
@@ -260,13 +260,12 @@ class RunnerManager(kind: String, val fileManager: FileManager, params: TestRunP
runCommand(cmd, logFile)
}
- private def getCheckFilePath(dir: File, suffix: String = "") = {
+ private def getCheckFilePath(dir: File, suffix: String) = {
def chkFile(s: String) = (Directory(dir) / "%s%s.check".format(fileBase, s)).toFile
if (chkFile("").isFile || suffix == "") chkFile("")
else chkFile("-" + suffix)
}
- private def getCheckFile(dir: File) = Some(getCheckFilePath(dir, kind)) filter (_.canRead)
private def compareOutput(dir: File, logFile: File): String = {
val checkFile = getCheckFilePath(dir, kind)
@@ -287,15 +286,10 @@ class RunnerManager(kind: String, val fileManager: FileManager, params: TestRunP
def newTestWriters() = {
val swr = new StringWriter
val wr = new PrintWriter(swr, true)
- // diff = ""
((swr, wr))
}
- def fail(what: Any) = {
- NestUI.verbose("scalac: compilation of "+what+" failed\n")
- false
- }
def diffCheck(testFile: File, diff: String) = {
testDiff = diff
testDiff == ""
@@ -341,10 +335,34 @@ class RunnerManager(kind: String, val fileManager: FileManager, params: TestRunP
val (scalaFiles, javaFiles) = g partition isScala
val allFiles = javaFiles ++ scalaFiles
+ /* The test can contain both java and scala files, each of which should be compiled with the corresponding
+ * compiler. Since the source files can reference each other both ways (java referencing scala classes and
+ * vice versa, the partest compilation routine attempts to reach a "bytecode fixpoint" between the two
+ * compilers -- that's when bytecode generated by each compiler implements the signatures expected by the other.
+ *
+ * In theory this property can't be guaranteed, as neither compiler can know what signatures the other
+ * compiler expects and how to implement them. (see SI-1240 for the full story)
+ *
+ * In practice, this happens in 3 steps:
+ * STEP1: feed all the files to scalac
+ * it will parse java files and obtain their expected signatures and generate bytecode for scala files
+ * STEP2: feed the java files to javac
+ * it will generate the bytecode for the java files and link to the scalac-generated bytecode for scala
+ * STEP3: only if there are both scala and java files, recompile the scala sources so they link to the correct
+ * java signatures, in case the signatures deduced by scalac from the source files were wrong. Since the
+ * bytecode for java is already in place, we only feed the scala files to scalac so it will take the
+ * java signatures from the existing javac-generated bytecode
+ */
List(1, 2, 3).foldLeft(CompileSuccess: CompilationOutcome) {
- case (CompileSuccess, 1) if scalaFiles.nonEmpty => compileMgr.attemptCompile(Some(outDir), allFiles, kind, logFile) // java + scala
- case (CompileSuccess, 2) if javaFiles.nonEmpty => javac(outDir, javaFiles, logFile) // java
- case (CompileSuccess, 3) if scalaFiles.nonEmpty => compileMgr.attemptCompile(Some(outDir), scalaFiles, kind, logFile) // scala
+ case (CompileSuccess, 1) if scalaFiles.nonEmpty =>
+ compileMgr.attemptCompile(Some(outDir), allFiles, kind, logFile)
+ case (CompileSuccess, 2) if javaFiles.nonEmpty =>
+ javac(outDir, javaFiles, logFile)
+ case (CompileSuccess, 3) if scalaFiles.nonEmpty && javaFiles.nonEmpty =>
+ // TODO: Do we actually need this? SI-1240 is known to require this, but we don't know if other tests
+ // require it: https://groups.google.com/forum/?fromgroups#!topic/scala-internals/rFDKAcOKciU
+ compileMgr.attemptCompile(Some(outDir), scalaFiles, kind, logFile)
+
case (outcome, _) => outcome
}
}
@@ -832,9 +850,8 @@ class RunnerManager(kind: String, val fileManager: FileManager, params: TestRunP
if (fileManager.failed && !runner.logFile.canRead)
return TestState.Ok
- // sys addShutdownHook cleanup()
- val ((success, ctx), elapsed) = timed(runner.run())
- val state = if (success) TestState.Ok else TestState.Fail
+ val (success, ctx) = runner.run()
+ val state = if (success) TestState.Ok else TestState.Fail
runner.reportResult(ctx.writers)
state
diff --git a/src/partest/scala/tools/partest/nest/RunnerUtils.scala b/src/partest/scala/tools/partest/nest/RunnerUtils.scala
deleted file mode 100644
index 6707a9338a..0000000000
--- a/src/partest/scala/tools/partest/nest/RunnerUtils.scala
+++ /dev/null
@@ -1,29 +0,0 @@
-/* NEST (New Scala Test)
- * Copyright 2007-2013 LAMP/EPFL
- * @author Philipp Haller
- */
-
-// $Id$
-
-package scala.tools.partest
-package nest
-
-object RunnerUtils {
- def splitArgs(str: String) = str split "\\s" filterNot (_ == "") toList
-
- def searchPath(option: String, as: List[String]): Option[String] = as match {
- case `option` :: r :: _ => Some(r)
- case _ :: rest => searchPath(option, rest)
- case Nil => None
- }
-
- def searchAndRemovePath(option: String, as: List[String]) = (as indexOf option) match {
- case -1 => (None, as)
- case idx => (Some(as(idx + 1)), (as take idx) ::: (as drop (idx + 2)))
- }
-
- def searchAndRemoveOption(option: String, as: List[String]) = (as indexOf option) match {
- case -1 => (false, as)
- case idx => (true, (as take idx) ::: (as drop (idx + 1)))
- }
-}
diff --git a/src/partest/scala/tools/partest/package.scala b/src/partest/scala/tools/partest/package.scala
index d38ce692d7..2b2ce2e435 100644
--- a/src/partest/scala/tools/partest/package.scala
+++ b/src/partest/scala/tools/partest/package.scala
@@ -12,11 +12,7 @@ import scala.sys.process.javaVmArguments
import java.util.concurrent.Callable
package partest {
- class TestState {
- def isOk = this eq TestState.Ok
- def isFail = this eq TestState.Fail
- def isTimeout = this eq TestState.Timeout
- }
+ class TestState { }
object TestState {
val Ok = new TestState
val Fail = new TestState
@@ -43,9 +39,8 @@ package object partest {
def callable[T](body: => T): Callable[T] = new Callable[T] { override def call() = body }
- def path2String(path: String) = file2String(new JFile(path))
def file2String(f: JFile) =
- try SFile(f).slurp()
+ try SFile(f).slurp(scala.io.Codec.UTF8)
catch { case _: FileNotFoundException => "" }
def basename(name: String): String = Path(name).stripExtension
@@ -74,7 +69,6 @@ package object partest {
def isPartestDebug: Boolean =
propOrEmpty("partest.debug") == "true"
-
import scala.language.experimental.macros
/**
diff --git a/src/partest/scala/tools/partest/utils/PrintMgr.scala b/src/partest/scala/tools/partest/utils/PrintMgr.scala
deleted file mode 100644
index d25be87c1e..0000000000
--- a/src/partest/scala/tools/partest/utils/PrintMgr.scala
+++ /dev/null
@@ -1,52 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala Parallel Testing **
-** / __/ __// _ | / / / _ | (c) 2007-2013, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id$
-
-package scala.tools.partest
-package utils
-
-/**
- * @author Thomas Hofer
- */
-object PrintMgr {
-
- val NONE = 0
- val SOME = 1
- val MANY = 2
-
- var outline = ""
- var success = ""
- var failure = ""
- var warning = ""
- var default = ""
-
- def initialization(number: Int) = number match {
- case MANY =>
- outline = Console.BOLD + Console.BLACK
- success = Console.BOLD + Console.GREEN
- failure = Console.BOLD + Console.RED
- warning = Console.BOLD + Console.YELLOW
- default = Console.RESET
- case SOME =>
- outline = Console.BOLD + Console.BLACK
- success = Console.RESET
- failure = Console.BOLD + Console.BLACK
- warning = Console.BOLD + Console.BLACK
- default = Console.RESET
- case _ =>
- }
-
- def printOutline(msg: String) = print(outline + msg + default)
-
- def printSuccess(msg: String) = print(success + msg + default)
-
- def printFailure(msg: String) = print(failure + msg + default)
-
- def printWarning(msg: String) = print(warning + msg + default)
-}
diff --git a/src/reflect/scala/reflect/api/Printers.scala b/src/reflect/scala/reflect/api/Printers.scala
index 85ddcc6523..76df76cdc8 100644
--- a/src/reflect/scala/reflect/api/Printers.scala
+++ b/src/reflect/scala/reflect/api/Printers.scala
@@ -166,7 +166,7 @@ trait Printers { self: Universe =>
protected def render(what: Any, mkPrinter: PrintWriter => TreePrinter, printTypes: BooleanFlag = None, printIds: BooleanFlag = None, printKinds: BooleanFlag = None, printMirrors: BooleanFlag = None): String = {
val buffer = new StringWriter()
val writer = new PrintWriter(buffer)
- var printer = mkPrinter(writer)
+ val printer = mkPrinter(writer)
printTypes.value.map(printTypes => if (printTypes) printer.withTypes else printer.withoutTypes)
printIds.value.map(printIds => if (printIds) printer.withIds else printer.withoutIds)
printKinds.value.map(printKinds => if (printKinds) printer.withKinds else printer.withoutKinds)
diff --git a/src/reflect/scala/reflect/internal/AnnotationInfos.scala b/src/reflect/scala/reflect/internal/AnnotationInfos.scala
index 6a5a742cc7..cfa4bdf44c 100644
--- a/src/reflect/scala/reflect/internal/AnnotationInfos.scala
+++ b/src/reflect/scala/reflect/internal/AnnotationInfos.scala
@@ -6,7 +6,6 @@
package scala.reflect
package internal
-import util._
import pickling.ByteCodecs
import scala.annotation.tailrec
import scala.collection.immutable.ListMap
@@ -293,10 +292,6 @@ trait AnnotationInfos extends api.Annotations { self: SymbolTable =>
/** Check whether any of the arguments mention a symbol */
def refsSymbol(sym: Symbol) = hasArgWhich(_.symbol == sym)
- /** Change all ident's with Symbol "from" to instead use symbol "to" */
- def substIdentSyms(from: Symbol, to: Symbol) =
- AnnotationInfo(atp, args map (_ substituteSymbols (List(from), List(to))), assocs) setPos pos
-
def stringArg(index: Int) = constantAtIndex(index) map (_.stringValue)
def intArg(index: Int) = constantAtIndex(index) map (_.intValue)
def symbolArg(index: Int) = argAtIndex(index) collect {
@@ -330,14 +325,14 @@ trait AnnotationInfos extends api.Annotations { self: SymbolTable =>
implicit val AnnotationTag = ClassTag[AnnotationInfo](classOf[AnnotationInfo])
object UnmappableAnnotation extends CompleteAnnotationInfo(NoType, Nil, Nil)
-
+
/** Extracts symbol of thrown exception from AnnotationInfo.
- *
+ *
* Supports both “old-style” `@throws(classOf[Exception])`
* as well as “new-stye” `@throws[Exception]("cause")` annotations.
*/
object ThrownException {
- def unapply(ann: AnnotationInfo): Option[Symbol] =
+ def unapply(ann: AnnotationInfo): Option[Symbol] =
ann match {
case AnnotationInfo(tpe, _, _) if tpe.typeSymbol != ThrowsClass =>
None
diff --git a/src/reflect/scala/reflect/internal/BaseTypeSeqs.scala b/src/reflect/scala/reflect/internal/BaseTypeSeqs.scala
index 3c2b128c52..eba10e8ffb 100644
--- a/src/reflect/scala/reflect/internal/BaseTypeSeqs.scala
+++ b/src/reflect/scala/reflect/internal/BaseTypeSeqs.scala
@@ -115,7 +115,7 @@ trait BaseTypeSeqs {
def map(f: Type => Type): BaseTypeSeq = {
// inlined `elems map f` for performance
val len = length
- var arr = new Array[Type](len)
+ val arr = new Array[Type](len)
var i = 0
while (i < len) {
arr(i) = f(elems(i))
@@ -158,7 +158,7 @@ trait BaseTypeSeqs {
val parents = tp.parents
// Console.println("computing baseTypeSeq of " + tsym.tpe + " " + parents)//DEBUG
val buf = new mutable.ListBuffer[Type]
- buf += tsym.tpe
+ buf += tsym.tpe_*
var btsSize = 1
if (parents.nonEmpty) {
val nparents = parents.length
diff --git a/src/reflect/scala/reflect/internal/BuildUtils.scala b/src/reflect/scala/reflect/internal/BuildUtils.scala
index b1b0c5b60b..175943d264 100644
--- a/src/reflect/scala/reflect/internal/BuildUtils.scala
+++ b/src/reflect/scala/reflect/internal/BuildUtils.scala
@@ -1,8 +1,6 @@
package scala.reflect
package internal
-import Flags._
-
trait BuildUtils { self: SymbolTable =>
class BuildImpl extends BuildApi {
diff --git a/src/reflect/scala/reflect/internal/ClassfileConstants.scala b/src/reflect/scala/reflect/internal/ClassfileConstants.scala
index 7ccb661426..2ab3caa19d 100644
--- a/src/reflect/scala/reflect/internal/ClassfileConstants.scala
+++ b/src/reflect/scala/reflect/internal/ClassfileConstants.scala
@@ -342,7 +342,7 @@ object ClassfileConstants {
case JAVA_ACC_PRIVATE => PRIVATE
case JAVA_ACC_PROTECTED => PROTECTED
case JAVA_ACC_FINAL => FINAL
- case JAVA_ACC_SYNTHETIC => SYNTHETIC
+ case JAVA_ACC_SYNTHETIC => SYNTHETIC | ARTIFACT // maybe should be just artifact?
case JAVA_ACC_STATIC => STATIC
case JAVA_ACC_ABSTRACT => if (isAnnotation) 0L else if (isClass) ABSTRACT else DEFERRED
case JAVA_ACC_INTERFACE => if (isAnnotation) 0L else TRAIT | INTERFACE | ABSTRACT
@@ -372,7 +372,7 @@ object ClassfileConstants {
}
def methodFlags(jflags: Int): Long = {
initFields(jflags)
- translateFlags(jflags, if ((jflags & JAVA_ACC_BRIDGE) != 0) BRIDGE else 0)
+ translateFlags(jflags, if ((jflags & JAVA_ACC_BRIDGE) != 0) BRIDGE | ARTIFACT else 0)
}
}
object FlagTranslation extends FlagTranslation { }
@@ -380,11 +380,4 @@ object ClassfileConstants {
def toScalaMethodFlags(flags: Int): Long = FlagTranslation methodFlags flags
def toScalaClassFlags(flags: Int): Long = FlagTranslation classFlags flags
def toScalaFieldFlags(flags: Int): Long = FlagTranslation fieldFlags flags
-
- @deprecated("Use another method in this object", "2.10.0")
- def toScalaFlags(flags: Int, isClass: Boolean = false, isField: Boolean = false): Long = (
- if (isClass) toScalaClassFlags(flags)
- else if (isField) toScalaFieldFlags(flags)
- else toScalaMethodFlags(flags)
- )
}
diff --git a/src/reflect/scala/reflect/internal/Definitions.scala b/src/reflect/scala/reflect/internal/Definitions.scala
index 2a7b55cb5a..8c048ed7f8 100644
--- a/src/reflect/scala/reflect/internal/Definitions.scala
+++ b/src/reflect/scala/reflect/internal/Definitions.scala
@@ -9,13 +9,12 @@ package internal
import scala.annotation.{ switch, meta }
import scala.collection.{ mutable, immutable }
import Flags._
-import PartialFunction._
import scala.reflect.api.{Universe => ApiUniverse}
trait Definitions extends api.StandardDefinitions {
self: SymbolTable =>
- import rootMirror.{getModule, getClassByName, getRequiredClass, getRequiredModule, getRequiredPackage, getClassIfDefined, getModuleIfDefined, getPackageObject, getPackageObjectIfDefined, requiredClass, requiredModule}
+ import rootMirror.{getModule, getPackage, getClassByName, getRequiredClass, getRequiredModule, getClassIfDefined, getModuleIfDefined, getPackageObject, getPackageObjectIfDefined, requiredClass, requiredModule}
object definitions extends DefinitionsClass
@@ -31,7 +30,7 @@ trait Definitions extends api.StandardDefinitions {
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): MethodSymbol = {
+ private def newMethod(owner: Symbol, name: TermName, formals: List[Type], restpe: Type, flags: Long): MethodSymbol = {
val msym = owner.newMethod(name.encode, NoPosition, flags)
val params = msym.newSyntheticValueParams(formals)
msym setInfo MethodType(params, restpe)
@@ -149,7 +148,6 @@ trait Definitions extends api.StandardDefinitions {
FloatClass,
DoubleClass
)
- def ScalaValueClassCompanions: List[Symbol] = ScalaValueClasses map (_.companionSymbol)
def ScalaPrimitiveValueClasses: List[ClassSymbol] = ScalaValueClasses
}
@@ -157,9 +155,6 @@ trait Definitions extends api.StandardDefinitions {
private var isInitialized = false
def isDefinitionsInitialized = isInitialized
- // symbols related to packages
- var emptypackagescope: Scope = null //debug
-
@deprecated("Moved to rootMirror.RootPackage", "2.10.0")
val RootPackage: ModuleSymbol = rootMirror.RootPackage
@@ -174,15 +169,13 @@ trait Definitions extends api.StandardDefinitions {
// It becomes tricky to create dedicated objects for other symbols because
// of initialization order issues.
- lazy val JavaLangPackage = getRequiredPackage(sn.JavaLang)
+ lazy val JavaLangPackage = getPackage("java.lang")
lazy val JavaLangPackageClass = JavaLangPackage.moduleClass.asClass
- lazy val ScalaPackage = getRequiredPackage(nme.scala_)
+ lazy val ScalaPackage = getPackage("scala")
lazy val ScalaPackageClass = ScalaPackage.moduleClass.asClass
- lazy val RuntimePackage = getRequiredPackage("scala.runtime")
+ lazy val RuntimePackage = getPackage("scala.runtime")
lazy val RuntimePackageClass = RuntimePackage.moduleClass.asClass
- lazy val JavaLangEnumClass = requiredClass[java.lang.Enum[_]]
-
// convenient one-argument parameter lists
lazy val anyparam = List(AnyClass.tpe)
lazy val anyvalparam = List(AnyValClass.typeConstructor)
@@ -223,7 +216,7 @@ trait Definitions extends api.StandardDefinitions {
def fullyInitializeSymbol(sym: Symbol): Symbol = {
sym.initialize
fullyInitializeType(sym.info)
- fullyInitializeType(sym.tpe)
+ fullyInitializeType(sym.tpe_*)
sym
}
def fullyInitializeType(tp: Type): Type = {
@@ -235,14 +228,32 @@ trait Definitions extends api.StandardDefinitions {
scope.sorted foreach fullyInitializeSymbol
scope
}
+ /** Is this symbol a member of Object or Any? */
+ def isUniversalMember(sym: Symbol) = (
+ (sym ne NoSymbol)
+ && (ObjectClass isSubClass sym.owner)
+ )
+
+ /** Is this symbol unimportable? Unimportable symbols include:
+ * - constructors, because <init> is not a real name
+ * - private[this] members, which cannot be referenced from anywhere else
+ * - members of Any or Object, because every instance will inherit a
+ * definition which supersedes the imported one
+ */
+ def isUnimportable(sym: Symbol) = (
+ (sym eq NoSymbol)
+ || sym.isConstructor
+ || sym.isPrivateLocal
+ || isUniversalMember(sym)
+ )
+ def isImportable(sym: Symbol) = !isUnimportable(sym)
+
/** Is this type equivalent to Any, AnyVal, or AnyRef? */
def isTrivialTopType(tp: Type) = (
tp =:= AnyClass.tpe
|| tp =:= AnyValClass.tpe
|| tp =:= AnyRefClass.tpe
)
- /** Does this type have a parent which is none of Any, AnyVal, or AnyRef? */
- def hasNonTrivialParent(tp: Type) = tp.parents exists (t => !isTrivialTopType(tp))
private def fixupAsAnyTrait(tpe: Type): Type = tpe match {
case ClassInfoType(parents, decls, clazz) =>
@@ -253,7 +264,6 @@ trait Definitions extends api.StandardDefinitions {
}
case PolyType(tparams, restpe) =>
PolyType(tparams, fixupAsAnyTrait(restpe))
-// case _ => tpe
}
// top types
@@ -312,6 +322,9 @@ trait Definitions extends api.StandardDefinitions {
lazy val ThrowableClass = getClassByName(sn.Throwable)
lazy val UninitializedErrorClass = requiredClass[UninitializedFieldError]
+ lazy val NPEConstructor = getMemberMethod(NullPointerExceptionClass, nme.CONSTRUCTOR) suchThat (_.paramss.flatten.isEmpty)
+ lazy val UninitializedFieldConstructor = UninitializedErrorClass.primaryConstructor
+
// fundamental reference classes
lazy val PartialFunctionClass = requiredClass[PartialFunction[_,_]]
lazy val AbstractPartialFunctionClass = requiredClass[scala.runtime.AbstractPartialFunction[_,_]]
@@ -335,14 +348,11 @@ trait Definitions extends api.StandardDefinitions {
lazy val UnqualifiedOwners = UnqualifiedModules.toSet ++ UnqualifiedModules.map(_.moduleClass)
lazy val PredefModule = requiredModule[scala.Predef.type]
- lazy val PredefModuleClass = PredefModule.moduleClass
-
- def Predef_classOf = getMemberMethod(PredefModule, nme.classOf)
- def Predef_identity = getMemberMethod(PredefModule, nme.identity)
- def Predef_conforms = getMemberMethod(PredefModule, nme.conforms)
- def Predef_wrapRefArray = getMemberMethod(PredefModule, nme.wrapRefArray)
- def Predef_??? = getMemberMethod(PredefModule, nme.???)
- def Predef_implicitly = getMemberMethod(PredefModule, nme.implicitly)
+ def Predef_classOf = getMemberMethod(PredefModule, nme.classOf)
+ def Predef_wrapRefArray = getMemberMethod(PredefModule, nme.wrapRefArray)
+ def Predef_wrapArray(tp: Type) = getMemberMethod(PredefModule, wrapArrayMethodName(tp))
+ def Predef_??? = getMemberMethod(PredefModule, nme.???)
+ def Predef_implicitly = getMemberMethod(PredefModule, nme.implicitly)
/** 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`
@@ -358,7 +368,6 @@ trait Definitions extends api.StandardDefinitions {
lazy val SpecializableModule = requiredModule[Specializable]
lazy val GroupOfSpecializable = getMemberClass(SpecializableModule, tpnme.Group)
- lazy val ConsoleModule = requiredModule[scala.Console.type]
lazy val ScalaRunTimeModule = requiredModule[scala.runtime.ScalaRunTime.type]
lazy val SymbolModule = requiredModule[scala.Symbol.type]
lazy val Symbol_apply = getMemberMethod(SymbolModule, nme.apply)
@@ -368,9 +377,7 @@ trait Definitions extends api.StandardDefinitions {
def arrayLengthMethod = getMemberMethod(ScalaRunTimeModule, nme.array_length)
def arrayCloneMethod = getMemberMethod(ScalaRunTimeModule, nme.array_clone)
def ensureAccessibleMethod = getMemberMethod(ScalaRunTimeModule, nme.ensureAccessible)
- def scalaRuntimeSameElements = getMemberMethod(ScalaRunTimeModule, nme.sameElements)
def arrayClassMethod = getMemberMethod(ScalaRunTimeModule, nme.arrayClass)
- def arrayElementClassMethod = getMemberMethod(ScalaRunTimeModule, nme.arrayElementClass)
// classes with special meanings
lazy val StringAddClass = requiredClass[scala.runtime.StringAdd]
@@ -381,11 +388,6 @@ trait Definitions extends api.StandardDefinitions {
lazy val TraitSetterAnnotationClass = requiredClass[scala.runtime.TraitSetter]
lazy val DelayedInitClass = requiredClass[scala.DelayedInit]
def delayedInitMethod = getMemberMethod(DelayedInitClass, nme.delayedInit)
- // a dummy value that communicates that a delayedInit call is compiler-generated
- // from phase UnCurry to phase Constructors
- // !!! This is not used anywhere (it was checked in that way.)
- // def delayedInitArgVal = EmptyPackageClass.newValue(NoPosition, nme.delayedInitArg)
- // .setInfo(UnitClass.tpe)
lazy val TypeConstraintClass = requiredClass[scala.annotation.TypeConstraint]
lazy val SingletonClass = enterNewClass(ScalaPackageClass, tpnme.Singleton, anyparam, ABSTRACT | TRAIT | FINAL)
@@ -407,7 +409,8 @@ trait Definitions extends api.StandardDefinitions {
def isScalaRepeatedParamType(tp: Type) = tp.typeSymbol == RepeatedParamClass
def isJavaRepeatedParamType(tp: Type) = tp.typeSymbol == JavaRepeatedParamClass
def isRepeatedParamType(tp: Type) = isScalaRepeatedParamType(tp) || isJavaRepeatedParamType(tp)
- def isRepeated(param: Symbol) = isRepeatedParamType(param.tpe)
+ def isRepeated(param: Symbol) = isRepeatedParamType(param.tpe_*)
+ def isByName(param: Symbol) = isByNameParamType(param.tpe_*)
def isCastSymbol(sym: Symbol) = sym == Any_asInstanceOf || sym == Object_asInstanceOf
def isJavaVarArgsMethod(m: Symbol) = m.isMethod && isJavaVarArgs(m.info.params)
@@ -432,10 +435,6 @@ trait Definitions extends api.StandardDefinitions {
case _ => tp
}
- def isPrimitiveArray(tp: Type) = tp match {
- case TypeRef(_, ArrayClass, arg :: Nil) => isPrimitiveValueClass(arg.typeSymbol)
- case _ => false
- }
def isReferenceArray(tp: Type) = tp match {
case TypeRef(_, ArrayClass, arg :: Nil) => arg <:< AnyRefClass.tpe
case _ => false
@@ -445,11 +444,8 @@ trait Definitions extends api.StandardDefinitions {
case _ => false
}
- lazy val MatchingStrategyClass = getRequiredClass("scala.MatchingStrategy")
-
// collections classes
lazy val ConsClass = requiredClass[scala.collection.immutable.::[_]]
- lazy val IterableClass = requiredClass[scala.collection.Iterable[_]]
lazy val IteratorClass = requiredClass[scala.collection.Iterator[_]]
lazy val ListClass = requiredClass[scala.collection.immutable.List[_]]
lazy val SeqClass = requiredClass[scala.collection.Seq[_]]
@@ -460,12 +456,12 @@ trait Definitions extends api.StandardDefinitions {
lazy val List_apply = getMemberMethod(ListModule, nme.apply)
lazy val NilModule = requiredModule[scala.collection.immutable.Nil.type]
lazy val SeqModule = requiredModule[scala.collection.Seq.type]
- lazy val IteratorModule = requiredModule[scala.collection.Iterator.type]
- lazy val Iterator_apply = getMemberMethod(IteratorModule, nme.apply)
// arrays and their members
lazy val ArrayModule = requiredModule[scala.Array.type]
lazy val ArrayModule_overloadedApply = getMemberMethod(ArrayModule, nme.apply)
+ def ArrayModule_genericApply = ArrayModule_overloadedApply.suchThat(_.paramss.flatten.last.tpe.typeSymbol == ClassTagClass) // [T: ClassTag](xs: T*): Array[T]
+ def ArrayModule_apply(tp: Type) = ArrayModule_overloadedApply.suchThat(_.tpe.resultType =:= arrayType(tp)) // (p1: AnyVal1, ps: AnyVal1*): Array[AnyVal1]
lazy val ArrayClass = getRequiredClass("scala.Array") // requiredClass[scala.Array[_]]
lazy val Array_apply = getMemberMethod(ArrayClass, nme.apply)
lazy val Array_update = getMemberMethod(ArrayClass, nme.update)
@@ -474,9 +470,7 @@ trait Definitions extends api.StandardDefinitions {
// reflection / structural types
lazy val SoftReferenceClass = requiredClass[java.lang.ref.SoftReference[_]]
- lazy val WeakReferenceClass = requiredClass[java.lang.ref.WeakReference[_]]
lazy val MethodClass = getClassByName(sn.MethodAsObject)
- def methodClass_setAccessible = getMemberMethod(MethodClass, nme.setAccessible)
lazy val EmptyMethodCacheClass = requiredClass[scala.runtime.EmptyMethodCache]
lazy val MethodCacheClass = requiredClass[scala.runtime.MethodCache]
def methodCache_find = getMemberMethod(MethodCacheClass, nme.find_)
@@ -500,7 +494,6 @@ trait Definitions extends api.StandardDefinitions {
lazy val ExprClass = if (ExprsClass != NoSymbol) getMemberClass(ExprsClass, tpnme.Expr) else NoSymbol
def ExprSplice = if (ExprsClass != NoSymbol) getMemberMethod(ExprClass, nme.splice) else NoSymbol
def ExprValue = if (ExprsClass != NoSymbol) getMemberMethod(ExprClass, nme.value) else NoSymbol
- lazy val ExprModule = if (ExprsClass != NoSymbol) getMemberModule(ExprsClass, nme.Expr) else NoSymbol
lazy val ClassTagModule = requiredModule[scala.reflect.ClassTag[_]]
lazy val ClassTagClass = requiredClass[scala.reflect.ClassTag[_]]
@@ -526,7 +519,6 @@ trait Definitions extends api.StandardDefinitions {
def MacroContextPrefix = if (MacroContextClass != NoSymbol) getMemberMethod(MacroContextClass, nme.prefix) else NoSymbol
def MacroContextPrefixType = if (MacroContextClass != NoSymbol) getTypeMember(MacroContextClass, tpnme.PrefixType) else NoSymbol
def MacroContextUniverse = if (MacroContextClass != NoSymbol) getMemberMethod(MacroContextClass, nme.universe) else NoSymbol
- def MacroContextMirror = if (MacroContextClass != NoSymbol) getMemberMethod(MacroContextClass, nme.mirror) else NoSymbol
lazy val MacroImplAnnotation = requiredClass[scala.reflect.macros.internal.macroImpl]
lazy val StringContextClass = requiredClass[scala.StringContext]
@@ -536,17 +528,19 @@ trait Definitions extends api.StandardDefinitions {
lazy val ScalaLongSignatureAnnotation = requiredClass[scala.reflect.ScalaLongSignature]
// Option classes
- lazy val OptionClass: ClassSymbol = requiredClass[Option[_]]
- lazy val SomeClass: ClassSymbol = requiredClass[Some[_]]
- lazy val NoneModule: ModuleSymbol = requiredModule[scala.None.type]
- lazy val SomeModule: ModuleSymbol = requiredModule[scala.Some.type]
+ lazy val OptionClass: ClassSymbol = requiredClass[Option[_]]
+ lazy val OptionModule: ModuleSymbol = requiredModule[scala.Option.type]
+ lazy val Option_apply = getMemberMethod(OptionModule, nme.apply)
+ lazy val SomeClass: ClassSymbol = requiredClass[Some[_]]
+ lazy val NoneModule: ModuleSymbol = requiredModule[scala.None.type]
+ lazy val SomeModule: ModuleSymbol = requiredModule[scala.Some.type]
def compilerTypeFromTag(tt: ApiUniverse # WeakTypeTag[_]): Type = tt.in(rootMirror).tpe
def compilerSymbolFromTag(tt: ApiUniverse # WeakTypeTag[_]): Symbol = tt.in(rootMirror).tpe.typeSymbol
// The given symbol represents either String.+ or StringAdd.+
def isStringAddition(sym: Symbol) = sym == String_+ || sym == StringAdd_+
- def isArrowAssoc(sym: Symbol) = ArrowAssocClass.tpe.decls.toList contains sym
+ def isArrowAssoc(sym: Symbol) = sym.owner == ArrowAssocClass
// The given symbol is a method with the right name and signature to be a runnable java program.
def isJavaMainMethod(sym: Symbol) = (sym.name == nme.main) && (sym.info match {
@@ -556,12 +550,6 @@ trait Definitions extends api.StandardDefinitions {
// The given class has a main method.
def hasJavaMainMethod(sym: Symbol): Boolean =
(sym.tpe member nme.main).alternatives exists isJavaMainMethod
- def hasJavaMainMethod(path: String): Boolean =
- hasJavaMainMethod(getModuleIfDefined(path))
-
- def isOptionType(tp: Type) = tp.typeSymbol isSubClass OptionClass
- def isSomeType(tp: Type) = tp.typeSymbol eq SomeClass
- def isNoneType(tp: Type) = tp.typeSymbol eq NoneModule
// Product, Tuple, Function, AbstractFunction
private def mkArityArray(name: String, arity: Int, countFrom: Int): Array[ClassSymbol] = {
@@ -584,7 +572,6 @@ trait Definitions extends api.StandardDefinitions {
/** Creators for TupleN, ProductN, FunctionN. */
def tupleType(elems: List[Type]) = aritySpecificType(TupleClass, elems)
- def productType(elems: List[Type]) = aritySpecificType(ProductClass, elems)
def functionType(formals: List[Type], restpe: Type) = aritySpecificType(FunctionClass, formals, restpe)
def abstractFunctionType(formals: List[Type], restpe: Type) = aritySpecificType(AbstractFunctionClass, formals, restpe)
@@ -603,10 +590,6 @@ trait Definitions extends api.StandardDefinitions {
else nme.genericWrapArray
}
- @deprecated("Use isTupleType", "2.10.0")
- def isTupleTypeOrSubtype(tp: Type) = isTupleType(tp)
-
- def tupleField(n: Int, j: Int) = getMemberValue(TupleClass(n), nme.productAccessorName(j))
// NOTE: returns true for NoSymbol since it's included in the TupleClass array -- is this intensional?
def isTupleSymbol(sym: Symbol) = TupleClass contains unspecializedSymbol(sym)
def isProductNClass(sym: Symbol) = ProductClass contains sym
@@ -652,13 +635,8 @@ trait Definitions extends api.StandardDefinitions {
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): TermSymbol = getMemberValue(z, nme.productAccessorName(j))
- def productProj(n: Int, j: Int): TermSymbol = productProj(ProductClass(n), j)
-
- /** returns true if this type is exactly ProductN[T1,...,Tn], not some subclass */
- def isExactProductType(tp: Type): Boolean = isProductNClass(tp.typeSymbol)
/** if tpe <: ProductN[T1,...,TN], returns List(T1,...,TN) else Nil */
def getProductArgs(tpe: Type): List[Type] = tpe.baseClasses find isProductNClass match {
@@ -666,13 +644,16 @@ trait Definitions extends api.StandardDefinitions {
case _ => Nil
}
+ def dropNullaryMethod(tp: Type) = tp match {
+ case NullaryMethodType(restpe) => restpe
+ case _ => tp
+ }
+
def unapplyUnwrap(tpe:Type) = tpe.finalResultType.normalize match {
case RefinedType(p :: _, _) => p.normalize
case tp => tp
}
- def functionApply(n: Int) = getMemberMethod(FunctionClass(n), nme.apply)
-
def abstractFunctionForFunctionType(tp: Type) =
if (isFunctionType(tp)) abstractFunctionType(tp.typeArgs.init, tp.typeArgs.last)
else NoType
@@ -690,8 +671,6 @@ trait Definitions extends api.StandardDefinitions {
(sym eq PartialFunctionClass) || (sym eq AbstractPartialFunctionClass)
}
- def isSeqType(tp: Type) = elementType(SeqClass, tp.normalize) != NoType
-
def elementType(container: Symbol, tp: Type): Type = tp match {
case TypeRef(_, `container`, arg :: Nil) => arg
case _ => NoType
@@ -704,14 +683,8 @@ trait Definitions extends api.StandardDefinitions {
def optionType(tp: Type) = appliedType(OptionClass, tp)
def scalaRepeatedType(arg: Type) = appliedType(RepeatedParamClass, arg)
def seqType(arg: Type) = appliedType(SeqClass, arg)
- def someType(tp: Type) = appliedType(SomeClass, tp)
-
- def StringArray = arrayType(StringClass.tpe)
- lazy val ObjectArray = arrayType(ObjectClass.tpe)
- def ClassType(arg: Type) =
- if (phase.erasedTypes || forMSIL) ClassClass.tpe
- else appliedType(ClassClass, arg)
+ def ClassType(arg: Type) = if (phase.erasedTypes) ClassClass.tpe else appliedType(ClassClass, arg)
def EnumType(sym: Symbol) =
// given (in java): "class A { enum E { VAL1 } }"
@@ -720,9 +693,6 @@ trait Definitions extends api.StandardDefinitions {
// - .linkedClassOfClass: the ClassSymbol of the enumeration (class E)
sym.owner.linkedClassOfClass.tpe
- def vmClassType(arg: Type): Type = ClassType(arg)
- def vmSignature(sym: Symbol, info: Type): String = signature(info) // !!!
-
/** Given a class symbol C with type parameters T1, T2, ... Tn
* which have upper/lower bounds LB1/UB1, LB1/UB2, ..., LBn/UBn,
* returns an existential type of the form
@@ -730,48 +700,7 @@ trait Definitions extends api.StandardDefinitions {
* C[E1, ..., En] forSome { E1 >: LB1 <: UB1 ... en >: LBn <: UBn }.
*/
def classExistentialType(clazz: Symbol): Type =
- newExistentialType(clazz.typeParams, clazz.tpe)
-
- /** Given type U, creates a Type representing Class[_ <: U].
- */
- def boundedClassType(upperBound: Type) =
- appliedTypeAsUpperBounds(ClassClass.typeConstructor, List(upperBound))
-
- /** To avoid unchecked warnings on polymorphic classes, translate
- * a Foo[T] into a Foo[_] for use in the pattern matcher.
- */
- @deprecated("Use classExistentialType", "2.10.0")
- def typeCaseType(clazz: Symbol): Type = classExistentialType(clazz)
-
- //
- // .NET backend
- //
-
- lazy val ComparatorClass = getRequiredClass("scala.runtime.Comparator")
- // System.ValueType
- lazy val ValueTypeClass: ClassSymbol = getClassByName(sn.ValueType)
- // System.MulticastDelegate
- lazy val DelegateClass: ClassSymbol = getClassByName(sn.Delegate)
- var Delegate_scalaCallers: List[Symbol] = List() // Syncnote: No protection necessary yet as only for .NET where reflection is not supported.
- // Symbol -> (Symbol, Type): scalaCaller -> (scalaMethodSym, DelegateType)
- // var Delegate_scalaCallerInfos: HashMap[Symbol, (Symbol, Type)] = _
- lazy val Delegate_scalaCallerTargets: mutable.HashMap[Symbol, Symbol] = mutable.HashMap()
-
- def isCorrespondingDelegate(delegateType: Type, functionType: Type): Boolean = {
- isSubType(delegateType, DelegateClass.tpe) &&
- (delegateType.member(nme.apply).tpe match {
- case MethodType(delegateParams, delegateReturn) =>
- isFunctionType(functionType) &&
- (functionType.normalize match {
- case TypeRef(_, _, args) =>
- (delegateParams.map(pt => {
- if (pt.tpe == AnyClass.tpe) definitions.ObjectClass.tpe else pt})
- ::: List(delegateReturn)) == args
- case _ => false
- })
- case _ => false
- })
- }
+ newExistentialType(clazz.typeParams, clazz.tpe_*)
// members of class scala.Any
lazy val Any_== = enterNewMethod(AnyClass, nme.EQ, anyparam, booltype, FINAL)
@@ -841,12 +770,7 @@ trait Definitions extends api.StandardDefinitions {
else
x :: removeRedundantObjects(xs)
}
- /** Order a list of types with non-trait classes before others. */
- def classesFirst(tps: List[Type]): List[Type] = {
- val (classes, others) = tps partition (t => t.typeSymbol.isClass && !t.typeSymbol.isTrait)
- if (classes.isEmpty || others.isEmpty || (tps startsWith classes)) tps
- else classes ::: others
- }
+
/** The following transformations applied to a list of parents.
* If any parent is a class/trait, all parents which normalize to
* Object are discarded. Otherwise, all parents which normalize
@@ -859,6 +783,12 @@ trait Definitions extends api.StandardDefinitions {
removeRedundantObjects(parents)
}
+ /** Flatten curried parameter lists of a method type. */
+ def allParameters(tpe: Type): List[Symbol] = tpe match {
+ case MethodType(params, res) => params ::: allParameters(res)
+ case _ => Nil
+ }
+
def typeStringNoPackage(tp: Type) =
"" + tp stripPrefix tp.typeSymbol.enclosingPackage.fullName + "."
@@ -868,10 +798,6 @@ trait Definitions extends api.StandardDefinitions {
def parentsString(parents: List[Type]) =
normalizedParents(parents) mkString " with "
- def typeParamsString(tp: Type) = tp match {
- case PolyType(tparams, _) => tparams map (_.defString) mkString ("[", ",", "]")
- case _ => ""
- }
def valueParamsString(tp: Type) = tp match {
case MethodType(params, _) => params map (_.defString) mkString ("(", ",", ")")
case _ => ""
@@ -883,8 +809,8 @@ trait Definitions extends api.StandardDefinitions {
lazy val Object_!= = enterNewMethod(ObjectClass, nme.NE, anyrefparam, booltype, FINAL)
lazy val Object_eq = enterNewMethod(ObjectClass, nme.eq, anyrefparam, booltype, FINAL)
lazy val Object_ne = enterNewMethod(ObjectClass, nme.ne, anyrefparam, booltype, FINAL)
- lazy val Object_isInstanceOf = newT1NoParamsMethod(ObjectClass, nme.isInstanceOf_Ob, FINAL | SYNTHETIC)(_ => booltype)
- lazy val Object_asInstanceOf = newT1NoParamsMethod(ObjectClass, nme.asInstanceOf_Ob, FINAL | SYNTHETIC)(_.typeConstructor)
+ lazy val Object_isInstanceOf = newT1NoParamsMethod(ObjectClass, nme.isInstanceOf_Ob, FINAL | SYNTHETIC | ARTIFACT)(_ => booltype)
+ lazy val Object_asInstanceOf = newT1NoParamsMethod(ObjectClass, nme.asInstanceOf_Ob, FINAL | SYNTHETIC | ARTIFACT)(_.typeConstructor)
lazy val Object_synchronized = newPolyMethod(1, ObjectClass, nme.synchronized_, FINAL)(tps =>
(Some(List(tps.head.typeConstructor)), tps.head.typeConstructor)
)
@@ -908,12 +834,6 @@ trait Definitions extends api.StandardDefinitions {
lazy val BoxedNumberClass = getClassByName(sn.BoxedNumber)
lazy val BoxedCharacterClass = getClassByName(sn.BoxedCharacter)
lazy val BoxedBooleanClass = getClassByName(sn.BoxedBoolean)
- lazy val BoxedByteClass = requiredClass[java.lang.Byte]
- lazy val BoxedShortClass = requiredClass[java.lang.Short]
- lazy val BoxedIntClass = requiredClass[java.lang.Integer]
- lazy val BoxedLongClass = requiredClass[java.lang.Long]
- lazy val BoxedFloatClass = requiredClass[java.lang.Float]
- lazy val BoxedDoubleClass = requiredClass[java.lang.Double]
lazy val Boxes_isNumberOrBool = getDecl(BoxesRunTimeClass, nme.isBoxedNumberOrBoolean)
lazy val Boxes_isNumber = getDecl(BoxesRunTimeClass, nme.isBoxedNumber)
@@ -934,7 +854,6 @@ trait Definitions extends api.StandardDefinitions {
lazy val ImplicitNotFoundClass = requiredClass[scala.annotation.implicitNotFound]
lazy val MigrationAnnotationClass = requiredClass[scala.annotation.migration]
lazy val ScalaStrictFPAttr = requiredClass[scala.annotation.strictfp]
- lazy val SerializableAttr = requiredClass[scala.annotation.serializable] // @serializable is deprecated
lazy val SwitchClass = requiredClass[scala.annotation.switch]
lazy val TailrecClass = requiredClass[scala.annotation.tailrec]
lazy val VarargsClass = requiredClass[scala.annotation.varargs]
@@ -969,7 +888,6 @@ trait Definitions extends api.StandardDefinitions {
lazy val ParamTargetClass = requiredClass[meta.param]
lazy val SetterTargetClass = requiredClass[meta.setter]
lazy val ClassTargetClass = requiredClass[meta.companionClass]
- lazy val ObjectTargetClass = requiredClass[meta.companionObject]
lazy val MethodTargetClass = requiredClass[meta.companionMethod] // TODO: module, moduleClass? package, packageObject?
lazy val LanguageFeatureAnnot = requiredClass[meta.languageFeature]
@@ -1014,7 +932,6 @@ trait Definitions extends api.StandardDefinitions {
def getLanguageFeature(name: String, owner: Symbol = languageFeatureModule): Symbol = getMember(owner, newTypeName(name))
def termMember(owner: Symbol, name: String): Symbol = owner.info.member(newTermName(name))
- def typeMember(owner: Symbol, name: String): Symbol = owner.info.member(newTypeName(name))
def findNamedMember(fullName: Name, root: Symbol): Symbol = {
val segs = nme.segments(fullName.toString, fullName.isTermName)
@@ -1054,7 +971,6 @@ trait Definitions extends api.StandardDefinitions {
}
}
def getMemberClass(owner: Symbol, name: Name): ClassSymbol = {
- val y = getMember(owner, name.toTypeName)
getMember(owner, name.toTypeName) match {
case x: ClassSymbol => x
case _ => fatalMissingSymbol(owner, name, "member class")
@@ -1082,9 +998,6 @@ trait Definitions extends api.StandardDefinitions {
def getDeclIfDefined(owner: Symbol, name: Name): Symbol =
owner.info.nonPrivateDecl(name)
- def packageExists(packageName: String): Boolean =
- getModuleIfDefined(packageName).isPackage
-
private def newAlias(owner: Symbol, name: TypeName, alias: Type): AliasTypeSymbol =
owner.newAliasType(name) setInfoAndEnter alias
@@ -1116,7 +1029,6 @@ trait Definitions extends api.StandardDefinitions {
newPolyMethod(1, owner, name, flags)(tparams => (Some(Nil), createFn(tparams.head)))
}
- lazy val boxedClassValues = boxedClass.values.toSet[Symbol]
lazy val isUnbox = unboxMethod.values.toSet[Symbol]
lazy val isBox = boxMethod.values.toSet[Symbol]
@@ -1176,8 +1088,6 @@ trait Definitions extends api.StandardDefinitions {
/** Is symbol a value class? */
def isPrimitiveValueClass(sym: Symbol) = ScalaValueClasses contains sym
- def isNonUnitValueClass(sym: Symbol) = isPrimitiveValueClass(sym) && (sym != UnitClass)
- def isSpecializableClass(sym: Symbol) = isPrimitiveValueClass(sym) || (sym == AnyRefClass)
def isPrimitiveValueType(tp: Type) = isPrimitiveValueClass(tp.typeSymbol)
/** Is symbol a boxed value class, e.g. java.lang.Integer? */
@@ -1218,49 +1128,11 @@ trait Definitions extends api.StandardDefinitions {
else flatNameString(etp.typeSymbol, '.')
}
- /** Surgery on the value classes. Without this, AnyVals defined in source
- * files end up with an AnyRef parent. It is likely there is a better way
- * to evade that AnyRef.
- */
- private def setParents(sym: Symbol, parents: List[Type]): Symbol = sym.rawInfo match {
- case ClassInfoType(_, scope, clazz) =>
- sym setInfo ClassInfoType(parents, scope, clazz)
- case _ =>
- sym
- }
-
def init() {
if (isInitialized) return
// force initialization of every symbol that is synthesized or hijacked by the compiler
- val forced = symbolsNotPresentInBytecode
+ val _ = symbolsNotPresentInBytecode
isInitialized = true
} //init
-
- var nbScalaCallers: Int = 0
- def newScalaCaller(delegateType: Type): MethodSymbol = {
- assert(forMSIL, "scalaCallers can only be created if target is .NET")
- // object: reference to object on which to call (scala-)method
- val paramTypes: List[Type] = List(ObjectClass.tpe)
- val name = newTermName("$scalaCaller$$" + nbScalaCallers)
- // tparam => resultType, which is the resultType of PolyType, i.e. the result type after applying the
- // type parameter =-> a MethodType in this case
- // TODO: set type bounds manually (-> MulticastDelegate), see newTypeParam
- val newCaller = enterNewMethod(DelegateClass, name, paramTypes, delegateType, FINAL | STATIC)
- // val newCaller = newPolyMethod(DelegateClass, name,
- // tparam => MethodType(paramTypes, tparam.typeConstructor)) setFlag (FINAL | STATIC)
- Delegate_scalaCallers = Delegate_scalaCallers ::: List(newCaller)
- nbScalaCallers += 1
- newCaller
- }
-
- // def addScalaCallerInfo(scalaCaller: Symbol, methSym: Symbol, delType: Type) {
- // assert(Delegate_scalaCallers contains scalaCaller)
- // Delegate_scalaCallerInfos += (scalaCaller -> (methSym, delType))
- // }
-
- def addScalaCallerInfo(scalaCaller: Symbol, methSym: Symbol) {
- assert(Delegate_scalaCallers contains scalaCaller)
- Delegate_scalaCallerTargets += (scalaCaller -> methSym)
- }
}
}
diff --git a/src/reflect/scala/reflect/internal/ExistentialsAndSkolems.scala b/src/reflect/scala/reflect/internal/ExistentialsAndSkolems.scala
index 59c027868e..2a0fe9d19a 100644
--- a/src/reflect/scala/reflect/internal/ExistentialsAndSkolems.scala
+++ b/src/reflect/scala/reflect/internal/ExistentialsAndSkolems.scala
@@ -7,7 +7,6 @@ package scala.reflect
package internal
import scala.collection.{ mutable, immutable }
-import util._
/** The name of this trait defines the eventual intent better than
* it does the initial contents.
diff --git a/src/reflect/scala/reflect/internal/Flags.scala b/src/reflect/scala/reflect/internal/Flags.scala
index a0362c8921..654dbd76e7 100644
--- a/src/reflect/scala/reflect/internal/Flags.scala
+++ b/src/reflect/scala/reflect/internal/Flags.scala
@@ -116,6 +116,20 @@ class ModifierFlags {
final val LAZY = 1L << 31 // symbol is a lazy val. can't have MUTABLE unless transformed by typer
final val PRESUPER = 1L << 37 // value is evaluated before super call
final val DEFAULTINIT = 1L << 41 // symbol is initialized to the default value: used by -Xcheckinit
+ final val ARTIFACT = 1L << 46 // symbol should be ignored when typechecking; will be marked ACC_SYNTHETIC in bytecode
+
+ /** Symbols which are marked ARTIFACT. (Expand this list?)
+ *
+ * - $outer fields and accessors
+ * - super accessors
+ * - protected accessors
+ * - lazy local accessors
+ * - bridge methods
+ * - default argument getters
+ * - evaluation-order preserving locals for right-associative and out-of-order named arguments
+ * - catch-expression storing vals
+ * - anything else which feels a setFlag(ARTIFACT)
+ */
// Overridden.
def flagToString(flag: Long): String = ""
@@ -165,7 +179,6 @@ class Flags extends ModifierFlags {
// A Java method's type is ``cooked'' by transforming raw types to existentials
final val SYNCHRONIZED = 1L << 45 // symbol is a method which should be marked ACC_SYNCHRONIZED
- final val ARTIFACT = 1L << 46 // symbol should be ignored when typechecking; will be marked ACC_SYNTHETIC in bytecode
// ------- shift definitions -------------------------------------------------------
@@ -248,7 +261,7 @@ class Flags extends ModifierFlags {
/** These modifiers appear in TreePrinter output. */
final val PrintableFlags =
ExplicitFlags | BridgeFlags | LOCAL | SYNTHETIC | STABLE | CASEACCESSOR | MACRO |
- ACCESSOR | SUPERACCESSOR | PARAMACCESSOR | STATIC | SPECIALIZED | SYNCHRONIZED
+ ACCESSOR | SUPERACCESSOR | PARAMACCESSOR | STATIC | SPECIALIZED | SYNCHRONIZED | ARTIFACT
/** When a symbol for a field is created, only these flags survive
* from Modifiers. Others which may be applied at creation time are:
@@ -420,7 +433,7 @@ class Flags extends ModifierFlags {
case VARARGS => "<varargs>" // (1L << 43)
case TRIEDCOOKING => "<triedcooking>" // (1L << 44)
case SYNCHRONIZED => "<synchronized>" // (1L << 45)
- case 0x400000000000L => "" // (1L << 46)
+ case ARTIFACT => "<artifact>" // (1L << 46)
case 0x800000000000L => "" // (1L << 47)
case 0x1000000000000L => "" // (1L << 48)
case 0x2000000000000L => "" // (1L << 49)
diff --git a/src/reflect/scala/reflect/internal/HasFlags.scala b/src/reflect/scala/reflect/internal/HasFlags.scala
index 4a3663b8ea..6f8befd23e 100644
--- a/src/reflect/scala/reflect/internal/HasFlags.scala
+++ b/src/reflect/scala/reflect/internal/HasFlags.scala
@@ -158,13 +158,14 @@ trait HasFlags {
else nonAccess + " " + access
}
+ // Guess this can't be deprecated seeing as it's in the reflect API.
+ def isParameter = hasFlag(PARAM)
+
// Backward compat section
@deprecated( "Use isTrait", "2.10.0")
def hasTraitFlag = hasFlag(TRAIT)
@deprecated("Use hasDefault", "2.10.0")
def hasDefaultFlag = hasFlag(DEFAULTPARAM)
- @deprecated("Use isValueParameter or isTypeParameter", "2.10.0")
- def isParameter = hasFlag(PARAM)
@deprecated("Use flagString", "2.10.0")
def defaultFlagString = flagString
@deprecated("Use flagString(mask)", "2.10.0")
diff --git a/src/reflect/scala/reflect/internal/Importers.scala b/src/reflect/scala/reflect/internal/Importers.scala
index 2f2b02975c..53410b29c5 100644
--- a/src/reflect/scala/reflect/internal/Importers.scala
+++ b/src/reflect/scala/reflect/internal/Importers.scala
@@ -316,7 +316,6 @@ trait Importers extends api.Importers { self: SymbolTable =>
def importName(name: from.Name): Name =
if (name.isTypeName) newTypeName(name.toString) else newTermName(name.toString)
def importTypeName(name: from.TypeName): TypeName = importName(name).toTypeName
- def importTermName(name: from.TermName): TermName = importName(name).toTermName
def importModifiers(mods: from.Modifiers): Modifiers =
new Modifiers(mods.flags, importName(mods.privateWithin), mods.annotations map importTree)
@@ -429,18 +428,18 @@ trait Importers extends api.Importers { self: SymbolTable =>
}
addFixup({
if (mytree != null) {
- val mysym = if (tree.hasSymbol) importSymbol(tree.symbol) else NoSymbol
+ val mysym = if (tree.hasSymbolField) importSymbol(tree.symbol) else NoSymbol
val mytpe = importType(tree.tpe)
mytree match {
case mytt: TypeTree =>
val tt = tree.asInstanceOf[from.TypeTree]
- if (mytree.hasSymbol) mytt.symbol = mysym
+ if (mytree.hasSymbolField) mytt.symbol = mysym
if (tt.wasEmpty) mytt.defineType(mytpe) else mytt.setType(mytpe)
if (tt.original != null) mytt.setOriginal(importTree(tt.original))
case _ =>
- if (mytree.hasSymbol) mytree.symbol = importSymbol(tree.symbol)
- mytree.tpe = importType(tree.tpe)
+ if (mytree.hasSymbolField) mytree.symbol = importSymbol(tree.symbol)
+ mytree setType importType(tree.tpe)
}
}
})
diff --git a/src/reflect/scala/reflect/internal/Mirrors.scala b/src/reflect/scala/reflect/internal/Mirrors.scala
index 0beb8e368f..6e76a7afb3 100644
--- a/src/reflect/scala/reflect/internal/Mirrors.scala
+++ b/src/reflect/scala/reflect/internal/Mirrors.scala
@@ -19,6 +19,8 @@ trait Mirrors extends api.Mirrors {
trait RootSymbol extends Symbol { def mirror: Mirror }
abstract class RootsBase(rootOwner: Symbol) extends scala.reflect.api.Mirror[Mirrors.this.type] { thisMirror =>
+ private[this] var initialized = false
+ def isMirrorInitialized = initialized
protected[scala] def rootLoader: LazyType
@@ -40,7 +42,7 @@ trait Mirrors extends api.Mirrors {
if (point > 0) getModuleOrClass(path.toTermName, point)
else RootClass
val name = path subName (point + 1, len)
- var sym = owner.info member name
+ val sym = owner.info member name
val result = if (path.isTermName) sym.suchThat(_ hasFlag MODULE) else sym
if (result != NoSymbol) result
else {
@@ -76,7 +78,9 @@ trait Mirrors extends api.Mirrors {
protected def universeMissingHook(owner: Symbol, name: Name): Symbol = thisUniverse.missingHook(owner, name)
- private[scala] def missingHook(owner: Symbol, name: Name): Symbol = mirrorMissingHook(owner, name) orElse universeMissingHook(owner, name)
+ private[scala] def missingHook(owner: Symbol, name: Name): Symbol = logResult(s"missingHook($owner, $name)")(
+ mirrorMissingHook(owner, name) orElse universeMissingHook(owner, name)
+ )
// todo: get rid of most the methods here and keep just staticClass/Module/Package
@@ -168,14 +172,15 @@ trait Mirrors extends api.Mirrors {
case _ => MissingRequirementError.notFound("package " + fullname)
}
- def getPackage(fullname: Name): ModuleSymbol =
+ def getPackage(fullname: TermName): ModuleSymbol =
ensurePackageSymbol(fullname.toString, getModuleOrClass(fullname), allowModules = true)
- def getRequiredPackage(fullname: String): ModuleSymbol =
+ @deprecated("Use getPackage", "2.11.0") def getRequiredPackage(fullname: String): ModuleSymbol =
getPackage(newTermNameCached(fullname))
- def getPackageObject(fullname: String): ModuleSymbol =
- (getPackage(newTermName(fullname)).info member nme.PACKAGE) match {
+ def getPackageObject(fullname: String): ModuleSymbol = getPackageObject(newTermName(fullname))
+ def getPackageObject(fullname: TermName): ModuleSymbol =
+ (getPackage(fullname).info member nme.PACKAGE) match {
case x: ModuleSymbol => x
case _ => MissingRequirementError.notFound("package object " + fullname)
}
@@ -183,8 +188,8 @@ trait Mirrors extends api.Mirrors {
def getPackageObjectIfDefined(fullname: String): Symbol =
getPackageObjectIfDefined(newTermNameCached(fullname))
- def getPackageObjectIfDefined(fullname: Name): Symbol =
- wrapMissing(getPackageObject(fullname.toTermName))
+ def getPackageObjectIfDefined(fullname: TermName): Symbol =
+ wrapMissing(getPackageObject(fullname))
override def staticPackage(fullname: String): ModuleSymbol =
ensurePackageSymbol(fullname.toString, getModuleOrClass(newTermNameCached(fullname)), allowModules = false)
@@ -228,6 +233,7 @@ trait Mirrors extends api.Mirrors {
// }
def init() {
+ if (initialized) return
// Still fiddling with whether it's cleaner to do some of this setup here
// or from constructors. The latter approach tends to invite init order issues.
@@ -239,6 +245,8 @@ trait Mirrors extends api.Mirrors {
RootClass.info.decls enter EmptyPackage
RootClass.info.decls enter RootPackage
+
+ initialized = true
}
}
diff --git a/src/reflect/scala/reflect/internal/Names.scala b/src/reflect/scala/reflect/internal/Names.scala
index c78ba72dfb..cea9215ae2 100644
--- a/src/reflect/scala/reflect/internal/Names.scala
+++ b/src/reflect/scala/reflect/internal/Names.scala
@@ -10,22 +10,7 @@ import scala.io.Codec
import java.security.MessageDigest
import scala.language.implicitConversions
-trait LowPriorityNames {
- self: Names =>
-
- implicit def nameToNameOps(name: Name): NameOps[Name] = new NameOps[Name](name)
-}
-
-/** The class Names ...
- *
- * @author Martin Odersky
- * @version 1.0, 05/02/2005
- */
-trait Names extends api.Names with LowPriorityNames {
- implicit def promoteTermNamesAsNecessary(name: Name): TermName = name.toTermName
-
-// Operations -------------------------------------------------------------
-
+trait Names extends api.Names {
private final val HASH_SIZE = 0x8000
private final val HASH_MASK = 0x7FFF
private final val NAME_SIZE = 0x20000
@@ -135,9 +120,6 @@ trait Names extends api.Names with LowPriorityNames {
def newTypeName(bs: Array[Byte], offset: Int, len: Int): TypeName =
newTermName(bs, offset, len).toTypeName
- def nameChars: Array[Char] = chrs
- @deprecated("", "2.9.0") def view(s: String): TermName = newTermName(s)
-
// Classes ----------------------------------------------------------------------
/** The name class.
@@ -186,28 +168,20 @@ trait Names extends api.Names with LowPriorityNames {
scala.compat.Platform.arraycopy(chrs, index, cs, offset, len)
/** @return the ascii representation of this name */
- final def toChars: Array[Char] = {
+ final def toChars: Array[Char] = { // used by ide
val cs = new Array[Char](len)
copyChars(cs, 0)
cs
}
- /** Write to UTF8 representation of this name to given character array.
- * Start copying to index `to`. Return index of next free byte in array.
- * Array must have enough remaining space for all bytes
- * (i.e. maximally 3*length bytes).
- */
- final def copyUTF8(bs: Array[Byte], offset: Int): Int = {
- val bytes = Codec.toUTF8(chrs, index, len)
- scala.compat.Platform.arraycopy(bytes, 0, bs, offset, bytes.length)
- offset + bytes.length
- }
-
/** @return the hash value of this name */
final override def hashCode(): Int = index
- // Presently disabled.
- // override def equals(other: Any) = paranoidEquals(other)
+ /****
+ * This has been quite useful to find places where people are comparing
+ * a TermName and a TypeName, or a Name and a String.
+
+ override def equals(other: Any) = paranoidEquals(other)
private def paranoidEquals(other: Any): Boolean = {
val cmp = this eq other.asInstanceOf[AnyRef]
if (cmp || !nameDebug)
@@ -215,7 +189,7 @@ trait Names extends api.Names with LowPriorityNames {
other match {
case x: String =>
- Console.println("Compared " + debugString + " and String '" + x + "'")
+ Console.println(s"Compared $debugString and String '$x'")
case x: Name =>
if (this.isTermName != x.isTermName) {
val panic = this.toTermName == x.toTermName
@@ -228,6 +202,7 @@ trait Names extends api.Names with LowPriorityNames {
}
false
}
+ ****/
/** @return the i'th Char of this name */
final def charAt(i: Int): Char = chrs(index + i)
@@ -279,8 +254,6 @@ trait Names extends api.Names with LowPriorityNames {
*/
final def lastPos(c: Char): Int = lastPos(c, len - 1)
- final def lastPos(s: String): Int = lastPos(s, len - s.length)
-
/** Returns the index of the last occurrence of char c in this
* name from start, -1 if not found.
*
@@ -294,26 +267,6 @@ trait Names extends api.Names with LowPriorityNames {
i
}
- /** Returns the index of the last occurrence of string s in this
- * name from start, -1 if not found.
- *
- * @param s the string
- * @param start ...
- * @return the index of the last occurrence of s
- */
- final def lastPos(s: String, start: Int): Int = {
- var i = lastPos(s.charAt(0), start)
- while (i >= 0) {
- var j = 1;
- while (s.charAt(j) == chrs(index + i + j)) {
- j += 1
- if (j == s.length()) return i;
- }
- i = lastPos(s.charAt(0), i - 1)
- }
- -s.length()
- }
-
/** Does this name start with prefix? */
final def startsWith(prefix: Name): Boolean = startsWith(prefix, 0)
@@ -375,7 +328,6 @@ trait Names extends api.Names with LowPriorityNames {
if (idx == length) -1 else idx
}
def lastIndexOf(ch: Char) = lastPos(ch)
- def lastIndexOf(ch: Char, fromIndex: Int) = lastPos(ch, fromIndex)
/** Replace all occurrences of `from` by `to` in
* name; result is always a term name.
@@ -424,24 +376,25 @@ trait Names extends api.Names with LowPriorityNames {
def append(ch: Char) = newName("" + this + ch)
def append(suffix: String) = newName("" + this + suffix)
def append(suffix: Name) = newName("" + this + suffix)
- def prepend(ch: Char) = newName("" + ch + this)
def prepend(prefix: String) = newName("" + prefix + this)
- def prepend(prefix: Name) = newName("" + prefix + this)
def decodedName: ThisNameType = newName(decode)
- def isOperatorName: Boolean = decode != toString
+ def isOperatorName: Boolean = decode != toString // used by ide
def longString: String = nameKind + " " + decode
def debugString = { val s = decode ; if (isTypeName) s + "!" else s }
}
+ implicit def AnyNameOps(name: Name): NameOps[Name] = new NameOps(name)
implicit def TermNameOps(name: TermName): NameOps[TermName] = new NameOps(name)
implicit def TypeNameOps(name: TypeName): NameOps[TypeName] = new NameOps(name)
+ /** FIXME: This is a good example of something which is pure "value class" but cannot
+ * reap the benefits because an (unused) $outer pointer so it is not single-field.
+ */
final class NameOps[T <: Name](name: T) {
def stripSuffix(suffix: Name): T = if (name endsWith suffix) dropRight(suffix.length) else name
def dropRight(n: Int): T = name.subName(0, name.length - n).asInstanceOf[T]
def drop(n: Int): T = name.subName(n, name.length).asInstanceOf[T]
- def nonEmpty: Boolean = name.length > 0
}
implicit val NameTag = ClassTag[Name](classOf[Name])
@@ -485,7 +438,7 @@ trait Names extends api.Names with LowPriorityNames {
type ThisNameType = TermName
protected[this] def thisName: TermName = this
- var next: TermName = termHashtable(hash)
+ val next: TermName = termHashtable(hash)
termHashtable(hash) = this
def isTermName: Boolean = true
def isTypeName: Boolean = false
@@ -514,7 +467,7 @@ trait Names extends api.Names with LowPriorityNames {
type ThisNameType = TypeName
protected[this] def thisName: TypeName = this
- var next: TypeName = typeHashtable(hash)
+ val next: TypeName = typeHashtable(hash)
typeHashtable(hash) = this
def isTermName: Boolean = false
def isTypeName: Boolean = true
diff --git a/src/reflect/scala/reflect/internal/Printers.scala b/src/reflect/scala/reflect/internal/Printers.scala
index a8085a4c58..2a3525206f 100644
--- a/src/reflect/scala/reflect/internal/Printers.scala
+++ b/src/reflect/scala/reflect/internal/Printers.scala
@@ -168,7 +168,7 @@ trait Printers extends api.Printers { self: SymbolTable =>
)
def printFlags(flags: Long, privateWithin: String) {
- var mask: Long = if (settings.debug.value) -1L else PrintableFlags
+ val mask: Long = if (settings.debug.value) -1L else PrintableFlags
val s = flagsToString(flags & mask, privateWithin)
if (s != "") print(s + " ")
}
@@ -475,8 +475,6 @@ trait Printers extends api.Printers { self: SymbolTable =>
}
def newRawTreePrinter(writer: PrintWriter): RawTreePrinter = new RawTreePrinter(writer)
- def newRawTreePrinter(stream: OutputStream): RawTreePrinter = newRawTreePrinter(new PrintWriter(stream))
- def newRawTreePrinter(): RawTreePrinter = newRawTreePrinter(new PrintWriter(ConsoleWriter))
// provides footnotes for types and mirrors
import scala.collection.mutable.{Map, WeakHashMap, SortedSet}
@@ -525,7 +523,7 @@ trait Printers extends api.Printers { self: SymbolTable =>
private var depth = 0
private var printTypesInFootnotes = true
private var printingFootnotes = false
- private var footnotes = footnoteIndex.mkFootnotes()
+ private val footnotes = footnoteIndex.mkFootnotes()
def print(args: Any*): Unit = {
// don't print type footnotes if the argument is a mere type
@@ -547,8 +545,8 @@ trait Printers extends api.Printers { self: SymbolTable =>
case self.pendingSuperCall =>
print("pendingSuperCall")
case tree: Tree =>
- val hasSymbol = tree.hasSymbol && tree.symbol != NoSymbol
- val isError = hasSymbol && tree.symbol.name.toString == nme.ERROR.toString
+ val hasSymbolField = tree.hasSymbolField && tree.symbol != NoSymbol
+ val isError = hasSymbolField && tree.symbol.name.toString == nme.ERROR.toString
printProduct(
tree,
preamble = _ => {
@@ -561,7 +559,7 @@ trait Printers extends api.Printers { self: SymbolTable =>
if (isError) print("<")
print(name)
if (isError) print(": error>")
- } else if (hasSymbol) {
+ } else if (hasSymbolField) {
tree match {
case refTree: RefTree =>
if (tree.symbol.name != refTree.name) print("[", tree.symbol, " aka ", refTree.name, "]")
diff --git a/src/reflect/scala/reflect/internal/Scopes.scala b/src/reflect/scala/reflect/internal/Scopes.scala
index ab3b9b7ed7..b1cfaa4774 100644
--- a/src/reflect/scala/reflect/internal/Scopes.scala
+++ b/src/reflect/scala/reflect/internal/Scopes.scala
@@ -8,6 +8,14 @@ package internal
trait Scopes extends api.Scopes { self: SymbolTable =>
+ /** An ADT to represent the results of symbol name lookups.
+ */
+ sealed trait NameLookup { def symbol: Symbol ; def isSuccess = false }
+ case class LookupSucceeded(qualifier: Tree, symbol: Symbol) extends NameLookup { override def isSuccess = true }
+ case class LookupAmbiguous(msg: String) extends NameLookup { def symbol = NoSymbol }
+ case class LookupInaccessible(symbol: Symbol, msg: String) extends NameLookup
+ case object LookupNotFound extends NameLookup { def symbol = NoSymbol }
+
class ScopeEntry(val sym: Symbol, val owner: Scope) {
/** the next entry in the hash bucket
*/
@@ -17,15 +25,11 @@ trait Scopes extends api.Scopes { self: SymbolTable =>
*/
var next: ScopeEntry = null
+ def depth = owner.nestingLevel
override def hashCode(): Int = sym.name.start
- override def toString(): String = sym.toString()
+ override def toString() = s"$sym (depth=$depth)"
}
- /**
- * @param sym ...
- * @param owner ...
- * @return ...
- */
private def newScopeEntry(sym: Symbol, owner: Scope): ScopeEntry = {
val e = new ScopeEntry(sym, owner)
e.next = owner.elems
@@ -92,8 +96,6 @@ trait Scopes extends api.Scopes { self: SymbolTable =>
}
/** enter a scope entry
- *
- * @param e ...
*/
protected def enterEntry(e: ScopeEntry) {
elemsCache = null
@@ -110,8 +112,6 @@ trait Scopes extends api.Scopes { self: SymbolTable =>
}
/** enter a symbol
- *
- * @param sym ...
*/
def enter[T <: Symbol](sym: T): T = {
enterEntry(newScopeEntry(sym, this))
@@ -119,8 +119,6 @@ trait Scopes extends api.Scopes { self: SymbolTable =>
}
/** enter a symbol, asserting that no symbol with same name exists in scope
- *
- * @param sym ...
*/
def enterUnique(sym: Symbol) {
assert(lookup(sym.name) == NoSymbol, (sym.fullLocationString, lookup(sym.name).fullLocationString))
@@ -175,8 +173,6 @@ trait Scopes extends api.Scopes { self: SymbolTable =>
}
/** remove entry
- *
- * @param e ...
*/
def unlink(e: ScopeEntry) {
if (elems == e) {
@@ -208,14 +204,48 @@ trait Scopes extends api.Scopes { self: SymbolTable =>
}
}
- /** lookup a symbol
- *
- * @param name ...
- * @return ...
+ /** Lookup a module or a class, filtering out matching names in scope
+ * which do not match that requirement.
+ */
+ def lookupModule(name: Name): Symbol = lookupAll(name.toTermName) find (_.isModule) getOrElse NoSymbol
+ def lookupClass(name: Name): Symbol = lookupAll(name.toTypeName) find (_.isClass) getOrElse NoSymbol
+
+ /** True if the name exists in this scope, false otherwise. */
+ def containsName(name: Name) = lookupEntry(name) != null
+
+ /** Lookup a symbol.
*/
def lookup(name: Name): Symbol = {
val e = lookupEntry(name)
- if (e eq null) NoSymbol else e.sym
+ if (e eq null) NoSymbol
+ else if (lookupNextEntry(e) eq null) e.sym
+ else {
+ // We shouldn't get here: until now this method was picking a random
+ // symbol when there was more than one with the name, so this should
+ // only be called knowing that there are 0-1 symbols of interest. So, we
+ // can safely return an overloaded symbol rather than throwing away the
+ // rest of them. Most likely we still break, but at least we will break
+ // in an understandable fashion (unexpectedly overloaded symbol) rather
+ // than a non-deterministic bizarre one (see any bug involving overloads
+ // in package objects.)
+ val alts = lookupAll(name).toList
+ def alts_s = alts map (s => s.defString) mkString " <and> "
+ devWarning(s"scope lookup of $name found multiple symbols: $alts_s")
+ // FIXME - how is one supposed to create an overloaded symbol without
+ // knowing the correct owner? Using the symbol owner is not correct;
+ // say for instance this is List's scope and the symbols are its three
+ // mkString members. Those symbols are owned by TraversableLike, which
+ // is no more meaningful an owner than NoSymbol given that we're in
+ // List. Maybe it makes no difference who owns the overloaded symbol, in
+ // which case let's establish that and have a canonical creation method.
+ //
+ // FIXME - a similar question for prefix, although there are more
+ // clues from the symbols on that one, as implemented here. In general
+ // the distinct list is one type and lub becomes the identity.
+ // val prefix = lub(alts map (_.info.prefix) distinct)
+ // Now using NoSymbol and NoPrefix always to avoid forcing info (SI-6664)
+ NoSymbol.newOverloaded(NoPrefix, alts)
+ }
}
/** Returns an iterator yielding every symbol with given name in this scope.
@@ -223,7 +253,20 @@ trait Scopes extends api.Scopes { self: SymbolTable =>
def lookupAll(name: Name): Iterator[Symbol] = new Iterator[Symbol] {
var e = lookupEntry(name)
def hasNext: Boolean = e ne null
- def next(): Symbol = { val r = e.sym; e = lookupNextEntry(e); r }
+ def next(): Symbol = try e.sym finally e = lookupNextEntry(e)
+ }
+
+ def lookupAllEntries(name: Name): Iterator[ScopeEntry] = new Iterator[ScopeEntry] {
+ var e = lookupEntry(name)
+ def hasNext: Boolean = e ne null
+ def next(): ScopeEntry = try e finally e = lookupNextEntry(e)
+ }
+
+ def lookupUnshadowedEntries(name: Name): Iterator[ScopeEntry] = {
+ lookupEntry(name) match {
+ case null => Iterator.empty
+ case e => lookupAllEntries(name) filter (e1 => (e eq e1) || (e.depth == e1.depth && e.sym != e1.sym))
+ }
}
/** lookup a symbol entry matching given name.
@@ -287,36 +330,16 @@ trait Scopes extends api.Scopes { self: SymbolTable =>
*/
def iterator: Iterator[Symbol] = toList.iterator
-/*
- /** Does this scope contain an entry for `sym`?
- */
- def contains(sym: Symbol): Boolean = lookupAll(sym.name) contains sym
-
- /** A scope that contains all symbols of this scope and that also contains `sym`.
- */
- def +(sym: Symbol): Scope =
- if (contains(sym)) this
- else {
- val result = cloneScope
- result enter sym
- result
- }
-
- /** A scope that contains all symbols of this scope except `sym`.
- */
- def -(sym: Symbol): Scope =
- if (!contains(sym)) this
- else {
- val result = cloneScope
- result unlink sym
- result
- }
-*/
override def foreach[U](p: Symbol => U): Unit = toList foreach p
- override def filter(p: Symbol => Boolean): Scope =
- if (!(toList forall p)) newScopeWith(toList filter p: _*) else this
-
+ override def filterNot(p: Symbol => Boolean): Scope = (
+ if (toList exists p) newScopeWith(toList filterNot p: _*)
+ else this
+ )
+ override def filter(p: Symbol => Boolean): Scope = (
+ if (toList forall p) this
+ else newScopeWith(toList filter p: _*)
+ )
@deprecated("Use `toList.reverse` instead", "2.10.0")
def reverse: List[Symbol] = toList.reverse
diff --git a/src/reflect/scala/reflect/internal/StdNames.scala b/src/reflect/scala/reflect/internal/StdNames.scala
index c870d8972d..c5521ae650 100644
--- a/src/reflect/scala/reflect/internal/StdNames.scala
+++ b/src/reflect/scala/reflect/internal/StdNames.scala
@@ -18,8 +18,6 @@ trait StdNames {
def encode(str: String): TermName = newTermNameCached(NameTransformer.encode(str))
- implicit def lowerTermNames(n: TermName): String = n.toString
-
/** 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
@@ -37,11 +35,7 @@ trait StdNames {
kws = kws + result
result
}
- def result: Set[TermName] = {
- val result = kws
- kws = null
- result
- }
+ def result: Set[TermName] = try kws finally kws = null
}
private final object compactify extends (String => String) {
@@ -104,7 +98,6 @@ trait StdNames {
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"
@@ -121,16 +114,12 @@ trait StdNames {
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 WeakTypeTag: NameType = "WeakTypeTag"
final val TypeTag : NameType = "TypeTag"
final val Expr: NameType = "Expr"
@@ -206,6 +195,8 @@ trait StdNames {
}
abstract class TypeNames extends Keywords with TypeNamesApi {
+ override type NameType = TypeName
+
protected implicit def createNameType(name: String): TypeName = newTypeNameCached(name)
final val BYNAME_PARAM_CLASS_NAME: NameType = "<byname>"
@@ -220,12 +211,10 @@ trait StdNames {
final val Any: NameType = "Any"
final val AnyVal: NameType = "AnyVal"
- final val ExprApi: NameType = "ExprApi"
final val Mirror: NameType = "Mirror"
final val Nothing: NameType = "Nothing"
final val Null: NameType = "Null"
final val Object: NameType = "Object"
- final val PartialFunction: NameType = "PartialFunction"
final val PrefixType: NameType = "PrefixType"
final val Product: NameType = "Product"
final val Serializable: NameType = "Serializable"
@@ -239,7 +228,6 @@ trait StdNames {
final val Group: NameType = "Group"
final val Tree: NameType = "Tree"
final val Type : NameType = "Type"
- final val TypeTree: NameType = "TypeTree"
// Annotation simple names, used in Namer
final val BeanPropertyAnnot: NameType = "BeanProperty"
@@ -249,13 +237,11 @@ trait StdNames {
// Classfile Attributes
final val AnnotationDefaultATTR: NameType = "AnnotationDefault"
final val BridgeATTR: NameType = "Bridge"
- final val ClassfileAnnotationATTR: NameType = "RuntimeInvisibleAnnotations" // RetentionPolicy.CLASS. Currently not used (Apr 2009).
final val CodeATTR: NameType = "Code"
final val ConstantValueATTR: NameType = "ConstantValue"
final val DeprecatedATTR: NameType = "Deprecated"
final val ExceptionsATTR: NameType = "Exceptions"
final val InnerClassesATTR: NameType = "InnerClasses"
- final val LineNumberTableATTR: NameType = "LineNumberTable"
final val LocalVariableTableATTR: NameType = "LocalVariableTable"
final val RuntimeAnnotationATTR: NameType = "RuntimeVisibleAnnotations" // RetentionPolicy.RUNTIME
final val RuntimeParamAnnotationATTR: NameType = "RuntimeVisibleParameterAnnotations" // RetentionPolicy.RUNTIME (annotations on parameters)
@@ -272,6 +258,8 @@ trait StdNames {
}
abstract class TermNames extends Keywords with TermNamesApi {
+ override type NameType = TermName
+
protected implicit def createNameType(name: String): TermName = newTermNameCached(name)
/** Base strings from which synthetic names are derived. */
@@ -284,9 +272,6 @@ trait StdNames {
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"
@@ -304,7 +289,6 @@ trait StdNames {
val LAZY_SLOW_SUFFIX: NameType = "$lzycompute"
val LOCAL_SUFFIX_STRING = " "
val UNIVERSE_BUILD_PREFIX: NameType = "$u.build."
- val UNIVERSE_BUILD: NameType = "$u.build"
val UNIVERSE_PREFIX: NameType = "$u."
val UNIVERSE_SHORT: NameType = "$u"
val MIRROR_PREFIX: NameType = "$m."
@@ -339,7 +323,6 @@ trait StdNames {
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)
@@ -356,11 +339,6 @@ trait StdNames {
)
}
- def isDeprecatedIdentifierName(name: Name) = name.toTermName match {
- case nme.`then` | nme.`macro` => true
- case _ => false
- }
-
def isOpAssignmentName(name: Name) = name match {
case raw.NE | raw.LE | raw.GE | EMPTY => false
case _ =>
@@ -395,18 +373,6 @@ trait StdNames {
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,
* {{{
@@ -458,18 +424,6 @@ trait StdNames {
} 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.charAt(pos - 1).isDigit)
- pos -= 1
-
- if (pos <= 0 || pos == name.length || name.charAt(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
)
@@ -484,8 +438,6 @@ trait StdNames {
final val Nil: NameType = "Nil"
final val Predef: NameType = "Predef"
- final val ScalaRunTime: NameType = "ScalaRunTime"
- final val Some: NameType = "Some"
val _1 : NameType = "_1"
val _2 : NameType = "_2"
@@ -581,14 +533,10 @@ trait StdNames {
val Annotation: NameType = "Annotation"
val Any: NameType = "Any"
val AnyVal: NameType = "AnyVal"
- val AppliedTypeTree: NameType = "AppliedTypeTree"
- val Apply: NameType = "Apply"
val ArrayAnnotArg: NameType = "ArrayAnnotArg"
- val Constant: NameType = "Constant"
val ConstantType: NameType = "ConstantType"
val EmptyPackage: NameType = "EmptyPackage"
val EmptyPackageClass: NameType = "EmptyPackageClass"
- val ExistentialTypeTree: NameType = "ExistentialTypeTree"
val Flag : NameType = "Flag"
val Ident: NameType = "Ident"
val Import: NameType = "Import"
@@ -597,10 +545,8 @@ trait StdNames {
val Modifiers: NameType = "Modifiers"
val NestedAnnotArg: NameType = "NestedAnnotArg"
val NoFlags: NameType = "NoFlags"
- val NoPrefix: NameType = "NoPrefix"
val NoSymbol: NameType = "NoSymbol"
val Nothing: NameType = "Nothing"
- val NoType: NameType = "NoType"
val Null: NameType = "Null"
val Object: NameType = "Object"
val RootPackage: NameType = "RootPackage"
@@ -609,17 +555,14 @@ trait StdNames {
val StringContext: NameType = "StringContext"
val This: NameType = "This"
val ThisType: NameType = "ThisType"
- val Tree : NameType = "Tree"
val Tuple2: NameType = "Tuple2"
val TYPE_ : NameType = "TYPE"
- val TypeApply: NameType = "TypeApply"
val TypeRef: NameType = "TypeRef"
val TypeTree: NameType = "TypeTree"
val UNIT : NameType = "UNIT"
val add_ : NameType = "add"
val annotation: NameType = "annotation"
val anyValClass: NameType = "anyValClass"
- val append: NameType = "append"
val apply: NameType = "apply"
val applyDynamic: NameType = "applyDynamic"
val applyDynamicNamed: NameType = "applyDynamicNamed"
@@ -627,34 +570,24 @@ trait StdNames {
val args : NameType = "args"
val argv : NameType = "argv"
val arrayClass: NameType = "arrayClass"
- val arrayElementClass: NameType = "arrayElementClass"
- val arrayValue: NameType = "arrayValue"
val array_apply : NameType = "array_apply"
val array_clone : NameType = "array_clone"
val array_length : NameType = "array_length"
val array_update : NameType = "array_update"
- val arraycopy: NameType = "arraycopy"
- val asTerm: NameType = "asTerm"
val asModule: NameType = "asModule"
- val asMethod: NameType = "asMethod"
val asType: NameType = "asType"
- val asClass: NameType = "asClass"
val asInstanceOf_ : NameType = "asInstanceOf"
val asInstanceOf_Ob : NameType = "$asInstanceOf"
- val assert_ : NameType = "assert"
- val assume_ : NameType = "assume"
val box: NameType = "box"
val build : NameType = "build"
val bytes: NameType = "bytes"
val canEqual_ : NameType = "canEqual"
val checkInitialized: NameType = "checkInitialized"
- val ClassManifestFactory: NameType = "ClassManifestFactory"
val classOf: NameType = "classOf"
- val clone_ : NameType = if (forMSIL) "MemberwiseClone" else "clone" // sn.OClone causes checkinit failure
+ val clone_ : NameType = "clone"
val conforms: NameType = "conforms"
val copy: NameType = "copy"
val currentMirror: NameType = "currentMirror"
- val definitions: NameType = "definitions"
val delayedInit: NameType = "delayedInit"
val delayedInitArg: NameType = "delayedInit$body"
val drop: NameType = "drop"
@@ -665,30 +598,23 @@ trait StdNames {
val equalsNumChar : NameType = "equalsNumChar"
val equalsNumNum : NameType = "equalsNumNum"
val equalsNumObject : NameType = "equalsNumObject"
- val equals_ : NameType = if (forMSIL) "Equals" else "equals"
+ val equals_ : NameType = "equals"
val error: NameType = "error"
- val eval: NameType = "eval"
val ex: NameType = "ex"
val experimental: NameType = "experimental"
val f: NameType = "f"
val false_ : NameType = "false"
val filter: NameType = "filter"
- val finalize_ : NameType = if (forMSIL) "Finalize" else "finalize"
+ val finalize_ : NameType = "finalize"
val find_ : NameType = "find"
val flagsFromBits : NameType = "flagsFromBits"
val flatMap: NameType = "flatMap"
val foreach: NameType = "foreach"
- val genericArrayOps: NameType = "genericArrayOps"
val get: NameType = "get"
- val getOrElse: NameType = "getOrElse"
- val hasNext: NameType = "hasNext"
- val hashCode_ : NameType = if (forMSIL) "GetHashCode" else "hashCode"
+ val hashCode_ : NameType = "hashCode"
val hash_ : NameType = "hash"
- val head: NameType = "head"
- val identity: NameType = "identity"
val implicitly: NameType = "implicitly"
val in: NameType = "in"
- val info: NameType = "info"
val inlinedEquals: NameType = "inlinedEquals"
val isArray: NameType = "isArray"
val isDefinedAt: NameType = "isDefinedAt"
@@ -700,36 +626,25 @@ trait StdNames {
val lang: NameType = "lang"
val length: NameType = "length"
val lengthCompare: NameType = "lengthCompare"
- val liftedTree: NameType = "liftedTree"
- val `macro` : NameType = "macro"
- val macroThis : NameType = "_this"
val macroContext : NameType = "c"
val main: NameType = "main"
- val manifest: NameType = "manifest"
- val ManifestFactory: NameType = "ManifestFactory"
val manifestToTypeTag: NameType = "manifestToTypeTag"
val map: NameType = "map"
val materializeClassTag: NameType = "materializeClassTag"
val materializeWeakTypeTag: NameType = "materializeWeakTypeTag"
val materializeTypeTag: NameType = "materializeTypeTag"
- val mirror : NameType = "mirror"
val moduleClass : NameType = "moduleClass"
- val name: NameType = "name"
val ne: NameType = "ne"
val newArray: NameType = "newArray"
val newFreeTerm: NameType = "newFreeTerm"
val newFreeType: NameType = "newFreeType"
val newNestedSymbol: NameType = "newNestedSymbol"
val newScopeWith: NameType = "newScopeWith"
- val next: NameType = "next"
val nmeNewTermName: NameType = "newTermName"
val nmeNewTypeName: NameType = "newTypeName"
- val normalize: NameType = "normalize"
val notifyAll_ : NameType = "notifyAll"
val notify_ : NameType = "notify"
val null_ : NameType = "null"
- val ofDim: NameType = "ofDim"
- val origin: NameType = "origin"
val pendingSuperCall: NameType = "pendingSuperCall"
val prefix : NameType = "prefix"
val productArity: NameType = "productArity"
@@ -737,21 +652,17 @@ trait StdNames {
val productIterator: NameType = "productIterator"
val productPrefix: NameType = "productPrefix"
val readResolve: NameType = "readResolve"
- val reflect : NameType = "reflect"
val reify : NameType = "reify"
val rootMirror : NameType = "rootMirror"
- val runOrElse: NameType = "runOrElse"
val runtime: NameType = "runtime"
val runtimeClass: NameType = "runtimeClass"
val runtimeMirror: NameType = "runtimeMirror"
- val sameElements: NameType = "sameElements"
val scala_ : NameType = "scala"
val selectDynamic: NameType = "selectDynamic"
val selectOverloadedMethod: NameType = "selectOverloadedMethod"
val selectTerm: NameType = "selectTerm"
val selectType: NameType = "selectType"
val self: NameType = "self"
- val setAccessible: NameType = "setAccessible"
val setAnnotations: NameType = "setAnnotations"
val setSymbol: NameType = "setSymbol"
val setType: NameType = "setType"
@@ -761,16 +672,11 @@ trait StdNames {
val staticModule : NameType = "staticModule"
val staticPackage : NameType = "staticPackage"
val synchronized_ : NameType = "synchronized"
- val tail: NameType = "tail"
- val `then` : NameType = "then"
val this_ : NameType = "this"
val thisPrefix : NameType = "thisPrefix"
- val throw_ : NameType = "throw"
val toArray: NameType = "toArray"
- val toList: NameType = "toList"
val toObjectArray : NameType = "toObjectArray"
- val toSeq: NameType = "toSeq"
- val toString_ : NameType = if (forMSIL) "ToString" else "toString"
+ val toString_ : NameType = "toString"
val toTypeConstructor: NameType = "toTypeConstructor"
val tpe : NameType = "tpe"
val tree : NameType = "tree"
@@ -789,14 +695,9 @@ trait StdNames {
val view_ : NameType = "view"
val wait_ : NameType = "wait"
val withFilter: NameType = "withFilter"
- val wrap: NameType = "wrap"
- val zip: NameType = "zip"
-
- val synthSwitch: NameType = "$synthSwitch"
// unencoded operators
object raw {
- final val AMP : NameType = "&"
final val BANG : NameType = "!"
final val BAR : NameType = "|"
final val DOLLAR: NameType = "$"
@@ -805,7 +706,6 @@ trait StdNames {
final val MINUS: NameType = "-"
final val NE: NameType = "!="
final val PLUS : NameType = "+"
- final val SLASH: NameType = "/"
final val STAR : NameType = "*"
final val TILDE: NameType = "~"
@@ -861,14 +761,7 @@ trait StdNames {
// Grouped here so Cleanup knows what tests to perform.
val CommonOpNames = Set[Name](OR, XOR, AND, EQ, NE)
- val ConversionNames = Set[Name](toByte, toChar, toDouble, toFloat, toInt, toLong, toShort)
val BooleanOpNames = Set[Name](ZOR, ZAND, UNARY_!) ++ CommonOpNames
- val NumberOpNames = (
- Set[Name](ADD, SUB, MUL, DIV, MOD, LSL, LSR, ASR, LT, LE, GE, GT)
- ++ Set(UNARY_+, UNARY_-, UNARY_!)
- ++ ConversionNames
- ++ CommonOpNames
- )
val add: NameType = "add"
val complement: NameType = "complement"
@@ -1000,7 +893,6 @@ trait StdNames {
object fulltpnme extends TypeNames {
val RuntimeNothing: NameType = "scala.runtime.Nothing$"
val RuntimeNull: NameType = "scala.runtime.Null$"
- val JavaLangEnum: NameType = "java.lang.Enum"
}
/** Java binary names, like scala/runtime/Nothing$.
@@ -1015,16 +907,11 @@ trait StdNames {
val javanme = nme.javaKeywords
object nme extends TermNames {
-
- def isModuleVarName(name: Name): Boolean =
- stripAnonNumberSuffix(name) endsWith MODULE_VAR_SUFFIX
-
def moduleVarName(name: TermName): TermName =
newTermNameCached("" + name + MODULE_VAR_SUFFIX)
def getCause = sn.GetCause
def getClass_ = sn.GetClass
- def getComponentType = sn.GetComponentType
def getMethod_ = sn.GetMethod
def invoke_ = sn.Invoke
@@ -1037,55 +924,12 @@ trait StdNames {
val reflMethodCacheName: NameType = "reflMethod$Cache"
val reflMethodName: NameType = "reflMethod$Method"
- private val reflectionCacheNames = Set[NameType](
- reflPolyCacheName,
- reflClassCacheName,
- reflParamsCacheName,
- reflMethodCacheName,
- reflMethodName
- )
- def isReflectionCacheName(name: Name) = reflectionCacheNames exists (name startsWith _)
-
@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 {
- protected val stringToTermName = null
- protected val stringToTypeName = null
- protected implicit def createNameType(s: String): TypeName = newTypeNameCached(s)
-
- val BeanProperty : TypeName
- val BooleanBeanProperty : TypeName
- val BoxedBoolean : TypeName
- val BoxedCharacter : TypeName
- val BoxedNumber : TypeName
- val Class : TypeName
- val Delegate : TypeName
- val IOOBException : TypeName // IndexOutOfBoundsException
- val InvTargetException : TypeName // InvocationTargetException
- val JavaSerializable : TypeName
- val MethodAsObject : TypeName
- val NPException : TypeName // NullPointerException
- val Object : TypeName
- val String : TypeName
- val Throwable : TypeName
- val ValueType : TypeName
-
- val ForName : TermName
- val GetCause : TermName
- val GetClass : TermName
- val GetClassLoader : TermName
- val GetComponentType : TermName
- val GetMethod : TermName
- val Invoke : TermName
- val JavaLang : TermName
-
- val Boxed: immutable.Map[TypeName, TypeName]
- }
-
class JavaKeywords {
private val kw = new KeywordSetBuilder
@@ -1143,7 +987,11 @@ trait StdNames {
final val keywords = kw.result
}
- private abstract class JavaNames extends SymbolNames {
+ sealed abstract class SymbolNames {
+ protected val stringToTermName = null
+ protected val stringToTypeName = null
+ protected implicit def createNameType(s: String): TypeName = newTypeNameCached(s)
+
final val BoxedBoolean: TypeName = "java.lang.Boolean"
final val BoxedByte: TypeName = "java.lang.Byte"
final val BoxedCharacter: TypeName = "java.lang.Character"
@@ -1153,22 +1001,16 @@ trait StdNames {
final val BoxedLong: TypeName = "java.lang.Long"
final val BoxedNumber: TypeName = "java.lang.Number"
final val BoxedShort: TypeName = "java.lang.Short"
- final val Class: TypeName = "java.lang.Class"
- final val Delegate: TypeName = tpnme.NO_NAME
final val IOOBException: TypeName = "java.lang.IndexOutOfBoundsException"
final val InvTargetException: TypeName = "java.lang.reflect.InvocationTargetException"
final val MethodAsObject: TypeName = "java.lang.reflect.Method"
final val NPException: TypeName = "java.lang.NullPointerException"
final val Object: TypeName = "java.lang.Object"
- final val String: TypeName = "java.lang.String"
final val Throwable: TypeName = "java.lang.Throwable"
- final val ValueType: TypeName = tpnme.NO_NAME
- final val ForName: TermName = newTermName("forName")
final val GetCause: TermName = newTermName("getCause")
final val GetClass: TermName = newTermName("getClass")
final val GetClassLoader: TermName = newTermName("getClassLoader")
- final val GetComponentType: TermName = newTermName("getComponentType")
final val GetMethod: TermName = newTermName("getMethod")
final val Invoke: TermName = newTermName("invoke")
final val JavaLang: TermName = newTermName("java.lang")
@@ -1185,52 +1027,5 @@ trait StdNames {
)
}
- private class MSILNames extends SymbolNames {
- final val BeanProperty: TypeName = tpnme.NO_NAME
- final val BooleanBeanProperty: TypeName = tpnme.NO_NAME
- final val BoxedBoolean: TypeName = "System.IConvertible"
- final val BoxedCharacter: TypeName = "System.IConvertible"
- final val BoxedNumber: TypeName = "System.IConvertible"
- final val Class: TypeName = "System.Type"
- final val Delegate: TypeName = "System.MulticastDelegate"
- final val IOOBException: TypeName = "System.IndexOutOfRangeException"
- final val InvTargetException: TypeName = "System.Reflection.TargetInvocationException"
- final val JavaSerializable: TypeName = tpnme.NO_NAME
- final val MethodAsObject: TypeName = "System.Reflection.MethodInfo"
- final val NPException: TypeName = "System.NullReferenceException"
- final val Object: TypeName = "System.Object"
- final val String: TypeName = "System.String"
- final val Throwable: TypeName = "System.Exception"
- final val ValueType: TypeName = "System.ValueType"
-
- final val ForName: TermName = newTermName("GetType")
- final val GetCause: TermName = newTermName("InnerException") /* System.Reflection.TargetInvocationException.InnerException */
- final val GetClass: TermName = newTermName("GetType")
- final lazy val GetClassLoader: TermName = throw new UnsupportedOperationException("Scala reflection is not supported on this platform");
- final val GetComponentType: TermName = newTermName("GetElementType")
- final val GetMethod: TermName = newTermName("GetMethod")
- final val Invoke: TermName = newTermName("Invoke")
- final val JavaLang: TermName = newTermName("System")
-
- val Boxed = immutable.Map[TypeName, TypeName](
- tpnme.Boolean -> "System.Boolean",
- tpnme.Byte -> "System.SByte", // a scala.Byte is signed and a System.SByte too (unlike a System.Byte)
- tpnme.Char -> "System.Char",
- tpnme.Short -> "System.Int16",
- tpnme.Int -> "System.Int32",
- tpnme.Long -> "System.Int64",
- tpnme.Float -> "System.Single",
- tpnme.Double -> "System.Double"
- )
- }
-
- private class J2SENames extends JavaNames {
- final val BeanProperty: TypeName = "scala.beans.BeanProperty"
- final val BooleanBeanProperty: TypeName = "scala.beans.BooleanBeanProperty"
- final val JavaSerializable: TypeName = "java.io.Serializable"
- }
-
- lazy val sn: SymbolNames =
- if (forMSIL) new MSILNames
- else new J2SENames
+ lazy val sn: SymbolNames = new SymbolNames { }
}
diff --git a/src/reflect/scala/reflect/internal/SymbolTable.scala b/src/reflect/scala/reflect/internal/SymbolTable.scala
index 02ac59a461..540338dca7 100644
--- a/src/reflect/scala/reflect/internal/SymbolTable.scala
+++ b/src/reflect/scala/reflect/internal/SymbolTable.scala
@@ -49,24 +49,28 @@ abstract class SymbolTable extends macros.Universe
def abort(msg: String): Nothing = throw new FatalError(supplementErrorMessage(msg))
def shouldLogAtThisPhase = false
+ def isPastTyper = false
@deprecated("Give us a reason", "2.10.0")
def abort(): Nothing = abort("unknown error")
+ @deprecated("Use devWarning if this is really a warning; otherwise use log", "2.11.0")
+ def debugwarn(msg: => String): Unit = devWarning(msg)
+
/** Override with final implementation for inlining. */
def debuglog(msg: => String): Unit = if (settings.debug.value) log(msg)
- def debugwarn(msg: => String): Unit = if (settings.debug.value) Console.err.println(msg)
+ def devWarning(msg: => String): Unit = if (settings.debug.value) Console.err.println(msg)
def throwableAsString(t: Throwable): String = "" + t
/** Prints a stack trace if -Ydebug or equivalent was given, otherwise does nothing. */
- def debugStack(t: Throwable): Unit = debugwarn(throwableAsString(t))
+ def debugStack(t: Throwable): Unit = devWarning(throwableAsString(t))
/** Overridden when we know more about what was happening during a failure. */
def supplementErrorMessage(msg: String): String = msg
private[scala] def printCaller[T](msg: String)(result: T) = {
Console.err.println("%s: %s\nCalled from: %s".format(msg, result,
- (new Throwable).getStackTrace.drop(2).take(15).mkString("\n")))
+ (new Throwable).getStackTrace.drop(2).take(50).mkString("\n")))
result
}
@@ -113,12 +117,6 @@ abstract class SymbolTable extends macros.Universe
@elidable(elidable.WARNING)
def assertCorrectThread() {}
- /** Are we compiling for Java SE? */
- // def forJVM: Boolean
-
- /** Are we compiling for .NET? */
- def forMSIL: Boolean = false
-
/** A last effort if symbol in a select <owner>.<name> is not found.
* This is overridden by the reflection compiler to make up a package
* when it makes sense (i.e. <owner> is a package and <name> is a term name).
@@ -139,7 +137,7 @@ abstract class SymbolTable extends macros.Universe
type RunId = Int
final val NoRunId = 0
- // sigh, this has to be public or atPhase doesn't inline.
+ // sigh, this has to be public or enteringPhase doesn't inline.
var phStack: List[Phase] = Nil
private[this] var ph: Phase = NoPhase
private[this] var per = NoPeriod
@@ -182,9 +180,6 @@ abstract class SymbolTable extends macros.Universe
/** The phase identifier of the given period. */
final def phaseId(period: Period): Phase#Id = period & 0xFF
- /** The period at the start of run that includes `period`. */
- final def startRun(period: Period): Period = period & 0xFFFFFF00
-
/** The current period. */
final def currentPeriod: Period = {
//assert(per == (currentRunId << 8) + phase.id)
@@ -202,23 +197,17 @@ abstract class SymbolTable extends macros.Universe
p != NoPhase && phase.id > p.id
/** Perform given operation at given phase. */
- @inline final def atPhase[T](ph: Phase)(op: => T): T = {
+ @inline final def enteringPhase[T](ph: Phase)(op: => T): T = {
val saved = pushPhase(ph)
try op
finally popPhase(saved)
}
+ @inline final def exitingPhase[T](ph: Phase)(op: => T): T = enteringPhase(ph.next)(op)
+ @inline final def enteringPrevPhase[T](op: => T): T = enteringPhase(phase.prev)(op)
- /** Since when it is to be "at" a phase is inherently ambiguous,
- * a couple unambiguously named methods.
- */
- @inline final def beforePhase[T](ph: Phase)(op: => T): T = atPhase(ph)(op)
- @inline final def afterPhase[T](ph: Phase)(op: => T): T = atPhase(ph.next)(op)
- @inline final def afterCurrentPhase[T](op: => T): T = atPhase(phase.next)(op)
- @inline final def beforePrevPhase[T](op: => T): T = atPhase(phase.prev)(op)
-
- @inline final def atPhaseNotLaterThan[T](target: Phase)(op: => T): T =
- if (isAtPhaseAfter(target)) atPhase(target)(op) else op
+ @inline final def enteringPhaseNotLaterThan[T](target: Phase)(op: => T): T =
+ if (isAtPhaseAfter(target)) enteringPhase(target)(op) else op
final def isValid(period: Period): Boolean =
period != 0 && runId(period) == currentRunId && {
@@ -303,7 +292,6 @@ abstract class SymbolTable extends macros.Universe
object perRunCaches {
import java.lang.ref.WeakReference
- import scala.runtime.ScalaRunTime.stringOf
import scala.collection.generic.Clearable
// Weak references so the garbage collector will take care of
@@ -346,11 +334,15 @@ abstract class SymbolTable extends macros.Universe
*/
def isCompilerUniverse = false
+ @deprecated("Use enteringPhase", "2.10.0")
+ @inline final def atPhase[T](ph: Phase)(op: => T): T = enteringPhase(ph)(op)
+ @deprecated("Use enteringPhaseNotLaterThan", "2.10.0")
+ @inline final def atPhaseNotLaterThan[T](target: Phase)(op: => T): T = enteringPhaseNotLaterThan(target)(op)
+
/**
* Adds the `sm` String interpolator to a [[scala.StringContext]].
*/
implicit val StringContextStripMarginOps: StringContext => StringContextStripMarginOps = util.StringContextStripMarginOps
-
}
object SymbolTableStats {
diff --git a/src/reflect/scala/reflect/internal/Symbols.scala b/src/reflect/scala/reflect/internal/Symbols.scala
index a4287fb181..fd5c3909b8 100644
--- a/src/reflect/scala/reflect/internal/Symbols.scala
+++ b/src/reflect/scala/reflect/internal/Symbols.scala
@@ -8,7 +8,7 @@ package internal
import scala.collection.{ mutable, immutable }
import scala.collection.mutable.ListBuffer
-import util.Statistics
+import util.{ Statistics, shortClassOfInstance }
import Flags._
import scala.annotation.tailrec
import scala.reflect.io.AbstractFile
@@ -19,8 +19,6 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
protected var ids = 0
- val emptySymbolArray = new Array[Symbol](0)
-
protected def nextId() = { ids += 1; ids }
/** Used for deciding in the IDE whether we can interrupt the compiler */
@@ -182,7 +180,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
if (isGADTSkolem) " (this is a GADT skolem)"
else ""
- def shortSymbolClass = getClass.getName.split('.').last.stripPrefix("Symbols$")
+ def shortSymbolClass = shortClassOfInstance(this)
def symbolCreationString: String = (
"%s%25s | %-40s | %s".format(
if (settings.uniqid.value) "%06d | ".format(id) else "",
@@ -245,20 +243,29 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
final def newImport(pos: Position): TermSymbol =
newTermSymbol(nme.IMPORT, pos)
+ def newModuleVarSymbol(accessor: Symbol): TermSymbol = {
+ val newName = nme.moduleVarName(accessor.name.toTermName)
+ val newFlags = MODULEVAR | ( if (this.isClass) PrivateLocal | SYNTHETIC else 0 )
+ val newInfo = accessor.tpe.finalResultType
+ val mval = newVariable(newName, accessor.pos.focus, newFlags) addAnnotation VolatileAttr
+
+ if (this.isClass)
+ mval setInfoAndEnter newInfo
+ else
+ mval setInfo newInfo
+ }
+
final def newModuleSymbol(name: TermName, pos: Position = NoPosition, newFlags: Long = 0L): ModuleSymbol =
newTermSymbol(name, pos, newFlags).asInstanceOf[ModuleSymbol]
final def newModuleAndClassSymbol(name: Name, pos: Position, flags0: FlagSet): (ModuleSymbol, ClassSymbol) = {
val flags = flags0 | MODULE
- val m = newModuleSymbol(name, pos, flags)
+ val m = newModuleSymbol(name.toTermName, pos, flags)
val c = newModuleClass(name.toTypeName, pos, flags & ModuleToClassFlags)
connectModuleToClass(m, c)
(m, c)
}
- final def newPackageSymbol(name: TermName, pos: Position = NoPosition, newFlags: Long = 0L): ModuleSymbol =
- newTermSymbol(name, pos, newFlags).asInstanceOf[ModuleSymbol]
-
final def newModuleClassSymbol(name: TypeName, pos: Position = NoPosition, newFlags: Long = 0L): ModuleClassSymbol =
newClassSymbol(name, pos, newFlags).asInstanceOf[ModuleClassSymbol]
@@ -321,11 +328,6 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
() => { cnt += 1; nme.syntheticParamName(cnt) }
}
- /** Synthetic value parameters when parameter symbols are not available
- */
- final def newSyntheticValueParamss(argtypess: List[List[Type]]): List[List[TermSymbol]] =
- argtypess map (xs => newSyntheticValueParams(xs, freshNamer))
-
/** Synthetic value parameters when parameter symbols are not available.
* Calling this method multiple times will re-use the same parameter names.
*/
@@ -341,7 +343,6 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
final def newSyntheticValueParam(argtype: Type, name: TermName = nme.syntheticParamName(1)): TermSymbol =
newValueParameter(name, owner.pos.focus, SYNTHETIC) setInfo argtype
- 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))
@@ -405,14 +406,6 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
final def newRefinementClass(pos: Position): RefinementClassSymbol =
createRefinementClassSymbol(pos, 0L)
- /** Create a new getter for current symbol (which must be a field)
- */
- final def newGetter: MethodSymbol = (
- owner.newMethod(nme.getterName(name.toTermName), NoPosition, getterFlags(flags))
- setPrivateWithin privateWithin
- setInfo MethodType(Nil, tpe)
- )
-
final def newErrorSymbol(name: Name): Symbol = name match {
case x: TypeName => newErrorClass(x)
case x: TermName => newErrorValue(x)
@@ -528,14 +521,12 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
*/
def isContravariant = false
def isCovariant = false
- def isExistentialQuantified = false
def isExistentialSkolem = false
def isExistentiallyBound = false
def isGADTSkolem = false
def isTypeParameter = false
def isTypeParameterOrSkolem = false
def isTypeSkolem = false
- def isTypeMacro = false
def isInvariant = !isCovariant && !isContravariant
/** Qualities of Terms, always false for TypeSymbols.
@@ -642,7 +633,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
final def isStaticModule = isModule && isStatic && !isMethod
final def isThisSym = isTerm && owner.thisSym == this
final def isError = hasFlag(IS_ERROR)
- final def isErroneous = isError || isInitialized && tpe.isErroneous
+ final def isErroneous = isError || isInitialized && tpe_*.isErroneous
def isHigherOrderTypeParameter = owner.isTypeParameterOrSkolem
@@ -709,10 +700,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
}
def isStrictFP = hasAnnotation(ScalaStrictFPAttr) || (enclClass hasAnnotation ScalaStrictFPAttr)
- def isSerializable = (
- info.baseClasses.exists(p => p == SerializableClass || p == JavaSerializableClass)
- || hasAnnotation(SerializableAttr) // last part can be removed, @serializable annotation is deprecated
- )
+ def isSerializable = info.baseClasses.exists(p => p == SerializableClass || p == JavaSerializableClass)
def hasBridgeAnnotation = hasAnnotation(BridgeClass)
def isDeprecated = hasAnnotation(DeprecatedAttr)
def deprecationMessage = getAnnotation(DeprecatedAttr) flatMap (_ stringArg 0)
@@ -722,14 +710,10 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
= hasAnnotation(DeprecatedInheritanceAttr)
def deprecatedInheritanceMessage
= getAnnotation(DeprecatedInheritanceAttr) flatMap (_ stringArg 0)
- def deprecatedInheritanceVersion
- = getAnnotation(DeprecatedInheritanceAttr) flatMap (_ stringArg 1)
def hasDeprecatedOverridingAnnotation
= hasAnnotation(DeprecatedOverridingAttr)
def deprecatedOverridingMessage
= getAnnotation(DeprecatedOverridingAttr) flatMap (_ stringArg 0)
- def deprecatedOverridingVersion
- = getAnnotation(DeprecatedOverridingAttr) flatMap (_ stringArg 1)
// !!! when annotation arguments are not literal strings, but any sort of
// assembly of strings, there is a fair chance they will turn up here not as
@@ -809,7 +793,13 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
final def isStaticOwner: Boolean =
isPackageClass || isModuleClass && isStatic
- def isTopLevelModule = hasFlag(MODULE) && owner.isPackageClass
+ /** A helper function for isEffectivelyFinal. */
+ private def isNotOverridden = (
+ owner.isClass && (
+ owner.isEffectivelyFinal
+ || owner.isSealed && owner.children.forall(c => c.isEffectivelyFinal && (overridingSymbol(c) == NoSymbol))
+ )
+ )
/** Is this symbol effectively final? I.e, it cannot be overridden */
final def isEffectivelyFinal: Boolean = (
@@ -818,8 +808,8 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
|| isTerm && (
isPrivate
|| isLocal
- || owner.isClass && owner.isEffectivelyFinal
- )
+ || isNotOverridden
+ )
)
/** Is this symbol locally defined? I.e. not accessed from outside `this` instance */
@@ -839,12 +829,6 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
*/
def isLocalClass = false
- def isStableClass = false
-
-/* code for fixing nested objects
- override final def isModuleClass: Boolean =
- super.isModuleClass && !isExpandedModuleClass
-*/
/** Is this class or type defined as a structural refinement type?
*/
final def isStructuralRefinement: Boolean =
@@ -863,17 +847,10 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
final def isStructuralRefinementMember = owner.isStructuralRefinement && isPossibleInRefinement && isPublic
final def isPossibleInRefinement = !isConstructor && !isOverridingSymbol
- /** Is this symbol a member of class `clazz`? */
- def isMemberOf(clazz: Symbol) =
- clazz.info.member(name).alternatives contains this
-
/** A a member of class `base` is incomplete if
* (1) it is declared deferred or
* (2) it is abstract override and its super symbol in `base` is
* nonexistent or incomplete.
- *
- * @param base ...
- * @return ...
*/
final def isIncompleteIn(base: Symbol): Boolean =
this.isDeferred ||
@@ -967,6 +944,14 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
def ownerChain: List[Symbol] = this :: owner.ownerChain
def originalOwnerChain: List[Symbol] = this :: originalOwner.getOrElse(this, rawowner).originalOwnerChain
+ // All the symbols overridden by this symbol and this symbol at the head,
+ // or Nil if this is NoSymbol.
+ def overrideChain = (
+ if (this eq NoSymbol) Nil
+ else if (!owner.isClass) this :: Nil
+ else this :: allOverriddenSymbols
+ )
+
// Non-classes skip self and return rest of owner chain; overridden in ClassSymbol.
def enclClassChain: List[Symbol] = owner.enclClassChain
@@ -1076,9 +1061,6 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
protected def createImplClassSymbol(name: TypeName, pos: Position, newFlags: Long): ClassSymbol =
new ClassSymbol(this, pos, name) with ImplClassSymbol initFlags newFlags
- protected def createTermSymbol(name: TermName, pos: Position, newFlags: Long): TermSymbol =
- new TermSymbol(this, pos, name) initFlags newFlags
-
protected def createMethodSymbol(name: TermName, pos: Position, newFlags: Long): MethodSymbol =
new MethodSymbol(this, pos, name) initFlags newFlags
@@ -1181,16 +1163,57 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
}
}
- /** Get type. The type of a symbol is:
- * for a type symbol, the type corresponding to the symbol itself,
- * @M you should use tpeHK for a type symbol with type parameters if
- * the kind of the type need not be *, as tpe introduces dummy arguments
- * to generate a type of kind *
- * for a term symbol, its usual type.
- * See the tpe/tpeHK overrides in TypeSymbol for more.
+ /** The "type" of this symbol. The type of a term symbol is its usual
+ * type. A TypeSymbol is more complicated; see that class for elaboration.
+ * Since tpe forwards to tpe_*, if you call it on a type symbol with unapplied
+ * type parameters, the type returned will contain dummies types. These will
+ * hide legitimate errors or create spurious ones if used as normal types.
*/
- def tpe: Type = info
- def tpeHK: Type = tpe
+ final def tpe: Type = tpe_*
+
+ /** typeConstructor throws an exception when called on term
+ * symbols; this is a more forgiving alternative. Calls
+ * typeConstructor on TypeSymbols, returns info otherwise.
+ */
+ def tpeHK: Type = info
+
+ /** Only applicable to TypeSymbols, it is the type corresponding
+ * to the symbol itself. For instance, the type of a List might
+ * be List[Int] - the same symbol's typeConstructor is simply List.
+ * One might be tempted to write that as List[_], and in some
+ * contexts this is possible, but it is discouraged because it is
+ * syntactically indistinguishable from and easily confused with the
+ * type List[T] forSome { type T; }, which can also be written List[_].
+ */
+ def typeConstructor: Type = (
+ // Avoiding a third override in NoSymbol to preserve bimorphism
+ if (this eq NoSymbol)
+ abort("no-symbol does not have a type constructor (this may indicate scalac cannot find fundamental classes)")
+ else
+ abort("typeConstructor inapplicable for " + this)
+ )
+
+ /** The type of this symbol, guaranteed to be of kind *.
+ * If there are unapplied type parameters, they will be
+ * substituted with dummy type arguments derived from the
+ * type parameters. Such types are not valid in a general
+ * sense and will cause difficult-to-find bugs if allowed
+ * to roam free.
+ *
+ * If you call tpe_* explicitly to obtain these types,
+ * you are responsible for them as if it they were your own
+ * minor children.
+ */
+ def tpe_* : Type = info
+
+ // Alternate implementation of def tpe for warning about misuse,
+ // disabled to keep the method maximally hotspot-friendly:
+ // def tpe: Type = {
+ // val result = tpe_*
+ // if (settings.debug.value && result.typeArgs.nonEmpty)
+ // printCaller(s"""Call to ${this.tpe} created $result: call tpe_* or tpeHK""")("")
+ // result
+ // }
/** Get type info associated with symbol at current phase, after
* ensuring that symbol is initialized (i.e. type is completed).
@@ -1226,13 +1249,13 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
cnt += 1
// allow for two completions:
// one: sourceCompleter to LazyType, two: LazyType to completed type
- if (cnt == 3) abort("no progress in completing " + this + ":" + tp)
+ if (cnt == 3) abort(s"no progress in completing $this: $tp")
}
rawInfo
}
catch {
case ex: CyclicReference =>
- debugwarn("... hit cycle trying to complete " + this.fullLocationString)
+ devWarning("... hit cycle trying to complete " + this.fullLocationString)
throw ex
}
@@ -1244,9 +1267,9 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
}
/** Set initial info. */
- def setInfo(info: Type): this.type = { info_=(info); this }
+ def setInfo(info: Type): this.type = { info_=(info); this }
/** Modifies this symbol's info in place. */
- def modifyInfo(f: Type => Type): this.type = setInfo(f(info))
+ def modifyInfo(f: Type => Type): this.type = setInfo(f(info))
/** Substitute second list of symbols for first in current info. */
def substInfo(syms0: List[Symbol], syms1: List[Symbol]): this.type =
if (syms0.isEmpty) this
@@ -1357,6 +1380,10 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
if (!isInitialized) info
this
}
+ def maybeInitialize = {
+ try { initialize ; true }
+ catch { case _: CyclicReference => debuglog("Hit cycle in maybeInitialize of $this") ; false }
+ }
/** Called when the programmer requests information that might require initialization of the underlying symbol.
*
@@ -1399,14 +1426,6 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
!isInitialized && (flags & LOCKED) == 0 && shouldTriggerCompleter(this, if (infos ne null) infos.info else null, isFlagRelated, mask)
/** Was symbol's type updated during given phase? */
- final def isUpdatedAt(pid: Phase#Id): Boolean = {
- assert(isCompilerUniverse)
- var infos = this.infos
- while ((infos ne null) && phaseId(infos.validFrom) != pid + 1) infos = infos.prev
- infos ne null
- }
-
- /** Was symbol's type updated during given phase? */
final def hasTypeAt(pid: Phase#Id): Boolean = {
assert(isCompilerUniverse)
var infos = this.infos
@@ -1419,21 +1438,18 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
* This is done in checkAccessible and overriding checks in refchecks
* We can't do this on class loading because it would result in infinite cycles.
*/
- final def cookJavaRawInfo() {
- if (hasFlag(TRIEDCOOKING)) return else setFlag(TRIEDCOOKING) // only try once...
- val oldInfo = info
- doCookJavaRawInfo()
- }
-
- protected def doCookJavaRawInfo(): Unit
+ def cookJavaRawInfo(): Unit = {
+ // only try once...
+ if (this hasFlag TRIEDCOOKING)
+ return
- /** The type constructor of a symbol is:
- * For a type symbol, the type corresponding to the symbol itself,
- * excluding parameters.
- * Not applicable for term symbols.
- */
- def typeConstructor: Type =
- abort("typeConstructor inapplicable for " + this)
+ this setFlag TRIEDCOOKING
+ info // force the current info
+ if (isJavaDefined || isType && owner.isJavaDefined)
+ this modifyInfo rawToExistential
+ else if (isOverloaded)
+ alternatives withFilter (_.isJavaDefined) foreach (_ modifyInfo rawToExistential)
+ }
/** The logic approximately boils down to finding the most recent phase
* which immediately follows any of parser, namer, typer, or erasure.
@@ -1457,7 +1473,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
*/
def unsafeTypeParams: List[Symbol] =
if (isMonomorphicType) Nil
- else atPhase(unsafeTypeParamPhase)(rawInfo.typeParams)
+ else enteringPhase(unsafeTypeParamPhase)(rawInfo.typeParams)
/** The type parameters of this symbol.
* assumption: if a type starts out as monomorphic, it will not acquire
@@ -1469,9 +1485,9 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
// analogously to the "info" getter, here we allow for two completions:
// one: sourceCompleter to LazyType, two: LazyType to completed type
if (validTo == NoPeriod)
- atPhase(phaseOf(infos.validFrom))(rawInfo load this)
+ enteringPhase(phaseOf(infos.validFrom))(rawInfo load this)
if (validTo == NoPeriod)
- atPhase(phaseOf(infos.validFrom))(rawInfo load this)
+ enteringPhase(phaseOf(infos.validFrom))(rawInfo load this)
rawInfo.typeParams
}
@@ -1633,12 +1649,23 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
def filter(cond: Symbol => Boolean): Symbol =
if (isOverloaded) {
- val alts = alternatives
- val alts1 = alts filter cond
- if (alts1 eq alts) this
+ var changed = false
+ var alts0: List[Symbol] = alternatives
+ var alts1: List[Symbol] = Nil
+
+ while (alts0.nonEmpty) {
+ if (cond(alts0.head))
+ alts1 ::= alts0.head
+ else
+ changed = true
+
+ alts0 = alts0.tail
+ }
+
+ if (!changed) this
else if (alts1.isEmpty) NoSymbol
else if (alts1.tail.isEmpty) alts1.head
- else owner.newOverloaded(info.prefix, alts1)
+ else owner.newOverloaded(info.prefix, alts1.reverse)
}
else if (cond(this)) this
else NoSymbol
@@ -1717,10 +1744,10 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
def thisSym: Symbol = this
/** The type of `this` in a class, or else the type of the symbol itself. */
- def typeOfThis = thisSym.tpe
+ def typeOfThis = thisSym.tpe_*
- /** If symbol is a class, the type <code>this.type</code> in this class,
- * otherwise <code>NoPrefix</code>.
+ /** If symbol is a class, the type `this.type` in this class,
+ * otherwise `NoPrefix`.
* We always have: thisType <:< typeOfThis
*/
def thisType: Type = NoPrefix
@@ -1889,11 +1916,11 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
(this.rawInfo ne NoType)
&& (this.effectiveOwner == that.effectiveOwner)
&& ( !this.effectiveOwner.isPackageClass
- || (this.sourceFile eq null)
- || (that.sourceFile eq null)
- || (this.sourceFile.path == that.sourceFile.path) // Cheap possibly wrong check, then expensive normalization
- || (this.sourceFile.canonicalPath == that.sourceFile.canonicalPath)
- )
+ || (this.associatedFile eq null)
+ || (that.associatedFile eq null)
+ || (this.associatedFile.path == that.associatedFile.path) // Cheap possibly wrong check, then expensive normalization
+ || (this.associatedFile.canonicalPath == that.associatedFile.canonicalPath)
+ )
)
/** The internal representation of classes and objects:
@@ -2019,9 +2046,10 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
if (isClassConstructor) NoSymbol else matchingSymbol(ofclazz, ofclazz.thisType)
/** Returns all symbols overriden by this symbol. */
- final def allOverriddenSymbols: List[Symbol] =
- if (!owner.isClass) Nil
+ final def allOverriddenSymbols: List[Symbol] = (
+ if ((this eq NoSymbol) || !owner.isClass) Nil
else owner.ancestors map overriddenSymbol filter (_ != NoSymbol)
+ )
/** Equivalent to allOverriddenSymbols.nonEmpty, but more efficient. */
// !!! When if ever will this answer differ from .isOverride?
@@ -2032,7 +2060,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
)
/** Equivalent to allOverriddenSymbols.head (or NoSymbol if no overrides) but more efficient. */
def nextOverriddenSymbol: Symbol = {
- if (owner.isClass) owner.ancestors foreach { base =>
+ if ((this ne NoSymbol) && owner.isClass) owner.ancestors foreach { base =>
val sym = overriddenSymbol(base)
if (sym != NoSymbol)
return sym
@@ -2137,13 +2165,6 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
case p :: _ => p
case _ => NoSymbol
}
-/* code for fixing nested objects
- def expandModuleClassName() {
- name = newTypeName(name.toString + "$")
- }
-
- def isExpandedModuleClass: Boolean = name(name.length - 1) == '$'
-*/
/** Desire to re-use the field in ClassSymbol which stores the source
* file to also store the classfile, but without changing the behavior
@@ -2153,10 +2174,6 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
private def sourceFileOnly(file: AbstractFile): AbstractFile =
if ((file eq null) || (file.path endsWith ".class")) null else file
- private def binaryFileOnly(file: AbstractFile): AbstractFile =
- if ((file eq null) || !(file.path endsWith ".class")) null else file
-
- final def binaryFile: AbstractFile = binaryFileOnly(associatedFile)
final def sourceFile: AbstractFile = sourceFileOnly(associatedFile)
/** Overridden in ModuleSymbols to delegate to the module class. */
@@ -2180,9 +2197,6 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
// ------ toString -------------------------------------------------------------------
- /** A tag which (in the ideal case) uniquely identifies class symbols */
- final def tag: Int = fullName.##
-
/** The simple name of this Symbol */
final def simpleName: Name = name
@@ -2413,6 +2427,14 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
override def isMethod = this hasFlag METHOD
override def isModule = this hasFlag MODULE
override def isOverloaded = this hasFlag OVERLOADED
+ /*** !!! TODO: shouldn't we do something like the following:
+ override def isOverloaded = (
+ if (this.isInitialized)
+ this hasFlag OVERLOADED
+ else
+ (infos ne null) && infos.info.isInstanceOf[OverloadedType]
+ )
+ ***/
override def isPackage = this hasFlag PACKAGE
override def isValueParameter = this hasFlag PARAM
@@ -2509,36 +2531,6 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
name = nme.expandedName(name.toTermName, base)
}
}
-
- protected def doCookJavaRawInfo() {
- def cook(sym: Symbol) {
- require(sym.isJavaDefined, sym)
- // @M: I think this is more desirable, but Martin prefers to leave raw-types as-is as much as possible
- // object rawToExistentialInJava extends TypeMap {
- // def apply(tp: Type): Type = tp match {
- // // any symbol that occurs in a java sig, not just java symbols
- // // see http://lampsvn.epfl.ch/trac/scala/ticket/2454#comment:14
- // case TypeRef(pre, sym, List()) if !sym.typeParams.isEmpty =>
- // val eparams = typeParamsToExistentials(sym, sym.typeParams)
- // existentialAbstraction(eparams, TypeRef(pre, sym, eparams map (_.tpe)))
- // case _ =>
- // mapOver(tp)
- // }
- // }
- val tpe1 = rawToExistential(sym.tpe)
- // println("cooking: "+ sym +": "+ sym.tpe +" to "+ tpe1)
- if (tpe1 ne sym.tpe) {
- sym.setInfo(tpe1)
- }
- }
-
- if (isJavaDefined)
- cook(this)
- else if (isOverloaded)
- for (sym2 <- alternatives)
- if (sym2.isJavaDefined)
- cook(sym2)
- }
}
implicit val TermSymbolTag = ClassTag[TermSymbol](classOf[TermSymbol])
@@ -2630,6 +2622,20 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
owner.newNonClassSymbol(name, pos, newFlags)
}
+ /** Let's say you have a type definition
+ *
+ * {{{
+ * type T <: Number
+ * }}}
+ *
+ * and tsym is the symbol corresponding to T. Then
+ *
+ * {{{
+ * tsym is an instance of AbstractTypeSymbol
+ * tsym.info == TypeBounds(Nothing, Number)
+ * tsym.tpe == TypeRef(NoPrefix, T, List())
+ * }}}
+ */
class AbstractTypeSymbol protected[Symbols] (initOwner: Symbol, initPos: Position, initName: TypeName)
extends TypeSymbol(initOwner, initPos, initName) {
type TypeOfClonedSymbol = TypeSymbol
@@ -2658,7 +2664,6 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
final def asNameType(n: Name) = n.toTypeName
override def isNonClassType = true
- override def isTypeMacro = hasFlag(MACRO)
override def resolveOverloadedFlag(flag: Long) = flag match {
case TRAIT => "<trait>" // DEFAULTPARAM
@@ -2676,7 +2681,6 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
override def isAbstractType = this hasFlag DEFERRED
override def isContravariant = this hasFlag CONTRAVARIANT
override def isCovariant = this hasFlag COVARIANT
- override def isExistentialQuantified = isExistentiallyBound && !isSkolem
override def isExistentiallyBound = this hasFlag EXISTENTIAL
override def isTypeParameter = isTypeParameterOrSkolem && !isSkolem
override def isTypeParameterOrSkolem = this hasFlag PARAM
@@ -2698,63 +2702,57 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
private def newPrefix = if (this hasFlag EXISTENTIAL | PARAM) NoPrefix else owner.thisType
private def newTypeRef(targs: List[Type]) = typeRef(newPrefix, this, targs)
- /** Let's say you have a type definition
+ /** A polymorphic type symbol has two distinct "types":
*
- * {{{
- * type T <: Number
- * }}}
+ * tpe_* a TypeRef with: dummy type args, no unapplied type parameters, and kind *
+ * tpeHK a TypeRef with: no type args, unapplied type parameters, and
+ * kind (*,*,...,*) => * depending on the number of tparams.
*
- * and tsym is the symbol corresponding to T. Then
- *
- * {{{
- * tsym.info = TypeBounds(Nothing, Number)
- * tsym.tpe = TypeRef(NoPrefix, T, List())
- * }}}
- */
- override def tpe: Type = {
- if (tpeCache eq NoType) throw CyclicReference(this, typeConstructor)
- if (tpePeriod != currentPeriod) {
- if (isValid(tpePeriod)) {
- tpePeriod = currentPeriod
- } else {
- if (isInitialized) tpePeriod = currentPeriod
- tpeCache = NoType
- val targs =
- if (phase.erasedTypes && this != ArrayClass) List()
- else unsafeTypeParams map (_.typeConstructor)
- //@M! use typeConstructor to generate dummy type arguments,
- // sym.tpe should not be called on a symbol that's supposed to be a higher-kinded type
- // memberType should be used instead, that's why it uses tpeHK and not tpe
- tpeCache = newTypeRef(targs)
- }
- }
- assert(tpeCache ne null/*, "" + this + " " + phase*/)//debug
+ * The dummy type args in tpe_* are created by wrapping a TypeRef
+ * around the type parameter symbols. Types containing dummies will
+ * hide errors or introduce spurious ones if they are passed around
+ * as if normal types. They should only be used in local operations
+ * where they will either be discarded immediately after, or will
+ * undergo substitution in which the dummies are replaced by actual
+ * type arguments.
+ */
+ override def tpe_* : Type = {
+ maybeUpdateTypeCache()
tpeCache
}
-
- /** @M -- tpe vs tpeHK:
- *
- * tpe: creates a TypeRef with dummy type arguments and kind *
- * tpeHK: creates a TypeRef with no type arguments but with type parameters
- *
- * If typeParams is nonEmpty, calling tpe may hide errors or
- * introduce spurious ones. (For example, when deriving a type from
- * the symbol of a type argument that may be higher-kinded.) As far
- * as I can tell, it only makes sense to call tpe in conjunction
- * with a substitution that replaces the generated dummy type
- * arguments by their actual types.
- *
- * TODO: the above conditions desperately need to be enforced by code.
- */
- override def tpeHK = typeConstructor // @M! used in memberType
-
override def typeConstructor: Type = {
+ maybeUpdateTyconCache()
+ tyconCache
+ }
+ override def tpeHK: Type = typeConstructor
+
+ private def maybeUpdateTyconCache() {
if ((tyconCache eq null) || tyconRunId != currentRunId) {
tyconCache = newTypeRef(Nil)
tyconRunId = currentRunId
}
assert(tyconCache ne null)
- tyconCache
+ }
+ private def maybeUpdateTypeCache() {
+ if (tpePeriod != currentPeriod) {
+ if (isValid(tpePeriod))
+ tpePeriod = currentPeriod
+ else
+ updateTypeCache() // perform the actual update
+ }
+ }
+ private def updateTypeCache() {
+ if (tpeCache eq NoType)
+ throw CyclicReference(this, typeConstructor)
+
+ if (isInitialized)
+ tpePeriod = currentPeriod
+
+ tpeCache = NoType // cycle marker
+ tpeCache = newTypeRef(
+ if (phase.erasedTypes && this != ArrayClass || unsafeTypeParams.isEmpty) Nil
+ else unsafeTypeParams map (_.typeConstructor)
+ )
}
override def info_=(tp: Type) {
@@ -2780,15 +2778,6 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
* public class Test1<T extends Test3> {}
* info for T in Test1 should be >: Nothing <: Test3[_]
*/
- protected def doCookJavaRawInfo() {
- if (isJavaDefined || owner.isJavaDefined) {
- val tpe1 = rawToExistential(info)
- // println("cooking type: "+ this +": "+ info +" to "+ tpe1)
- if (tpe1 ne info) {
- setInfo(tpe1)
- }
- }
- }
if (Statistics.hotEnabled) Statistics.incCounter(typeSymbolCount)
}
@@ -2822,7 +2811,6 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
override def isTypeSkolem = this hasFlag PARAM
override def isAbstractType = this hasFlag DEFERRED
- override def isExistentialQuantified = false
override def existentialBound = if (isAbstractType) this.info else super.existentialBound
/** If typeskolem comes from a type parameter, that parameter, otherwise skolem itself */
@@ -2908,21 +2896,6 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
|| isLocal
|| !owner.isPackageClass && owner.isLocalClass
)
- override def isStableClass = (this hasFlag STABLE) || checkStable()
-
- private def checkStable() = {
- def hasNoAbstractTypeMember(clazz: Symbol): Boolean =
- (clazz hasFlag STABLE) || {
- var e = clazz.info.decls.elems
- while ((e ne null) && !(e.sym.isAbstractType && info.member(e.sym.name) == e.sym))
- e = e.next
- e == null
- }
- (info.baseClasses forall hasNoAbstractTypeMember) && {
- setFlag(STABLE)
- true
- }
- }
override def enclClassChain = this :: owner.enclClassChain
@@ -3108,6 +3081,8 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
)
}
trait StubSymbol extends Symbol {
+ devWarning("creating stub symbol to defer error: " + missingMessage)
+
protected def missingMessage: String
/** Fail the stub by throwing a [[scala.reflect.internal.MissingRequirementError]]. */
@@ -3135,8 +3110,6 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
override def info = fail(NoType)
override def rawInfo = fail(NoType)
override def companionSymbol = fail(NoSymbol)
-
- debugwarn("creating stub symbol to defer error: " + missingMessage)
}
class StubClassSymbol(owner0: Symbol, name0: TypeName, protected val missingMessage: String) extends ClassSymbol(owner0, owner0.pos, name0) with StubSymbol
class StubTermSymbol(owner0: Symbol, name0: TermName, protected val missingMessage: String) extends TermSymbol(owner0, owner0.pos, name0) with StubSymbol
@@ -3194,15 +3167,12 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
override def info: Type = NoType
override def existentialBound: Type = NoType
override def rawInfo: Type = NoType
- protected def doCookJavaRawInfo() {}
override def accessBoundary(base: Symbol): Symbol = enclosingRootClass
def cloneSymbolImpl(owner: Symbol, newFlags: Long) = abort("NoSymbol.clone()")
override def originalEnclosingMethod = this
override def owner: Symbol =
abort("no-symbol does not have an owner")
- override def typeConstructor: Type =
- abort("no-symbol does not have a type constructor (this may indicate scalac cannot find fundamental classes)")
}
protected def makeNoSymbol: NoSymbol = new NoSymbol
diff --git a/src/reflect/scala/reflect/internal/TreeGen.scala b/src/reflect/scala/reflect/internal/TreeGen.scala
index ebf0998573..0954432c77 100644
--- a/src/reflect/scala/reflect/internal/TreeGen.scala
+++ b/src/reflect/scala/reflect/internal/TreeGen.scala
@@ -11,10 +11,7 @@ abstract class TreeGen extends macros.TreeBuilder {
def rootScalaDot(name: Name) = Select(rootId(nme.scala_) setSymbol ScalaPackage, name)
def scalaDot(name: Name) = Select(Ident(nme.scala_) setSymbol ScalaPackage, name)
def scalaAnnotationDot(name: Name) = Select(scalaDot(nme.annotation), name)
- def scalaAnyRefConstr = scalaDot(tpnme.AnyRef) setSymbol AnyRefClass
- def scalaUnitConstr = scalaDot(tpnme.Unit) setSymbol UnitClass
- def productConstr = scalaDot(tpnme.Product) setSymbol ProductRootClass
- def serializableConstr = scalaDot(tpnme.Serializable) setSymbol SerializableClass
+ def scalaAnyRefConstr = scalaDot(tpnme.AnyRef) setSymbol AnyRefClass // used in ide
def scalaFunctionConstr(argtpes: List[Tree], restpe: Tree, abstractFun: Boolean = false): Tree = {
val cls = if (abstractFun)
@@ -130,15 +127,10 @@ abstract class TreeGen extends macros.TreeBuilder {
if (sym.owner.isClass) mkAttributedRef(sym.owner.thisType, sym)
else mkAttributedIdent(sym)
- /** Builds an untyped reference to given symbol. */
- def mkUnattributedRef(sym: Symbol): Tree =
- if (sym.owner.isClass) Select(This(sym.owner), sym)
- else Ident(sym)
-
/** Replaces tree type with a stable type if possible */
- def stabilize(tree: Tree): Tree = {
- for(tp <- stableTypeFor(tree)) tree.tpe = tp
- tree
+ def stabilize(tree: Tree): Tree = stableTypeFor(tree) match {
+ case Some(tp) => tree setType tp
+ case _ => tree
}
/** Computes stable type for a tree if possible */
@@ -165,17 +157,36 @@ abstract class TreeGen extends macros.TreeBuilder {
This(sym.name.toTypeName) setSymbol sym setType sym.thisType
def mkAttributedIdent(sym: Symbol): Tree =
- Ident(sym.name) setSymbol sym setType sym.tpe
+ Ident(sym.name) setSymbol sym setType sym.tpeHK
def mkAttributedSelect(qual: Tree, sym: Symbol): Tree = {
// Tests involving the repl fail without the .isEmptyPackage condition.
if (qual.symbol != null && (qual.symbol.isEffectiveRoot || qual.symbol.isEmptyPackage))
mkAttributedIdent(sym)
else {
+ // Have to recognize anytime a selection is made on a package
+ // so it can be rewritten to foo.bar.`package`.name rather than
+ // foo.bar.name if name is in the package object.
+ // TODO - factor out the common logic between this and
+ // the Typers method "isInPackageObject", used in typedIdent.
+ val qualsym = (
+ if (qual.tpe ne null) qual.tpe.typeSymbol
+ else if (qual.symbol ne null) qual.symbol
+ else NoSymbol
+ )
+ val needsPackageQualifier = (
+ (sym ne null)
+ && qualsym.isPackage
+ && !sym.isDefinedInPackage
+ )
val pkgQualifier =
- if (sym != null && sym.owner.isPackageObjectClass && sym.effectiveOwner == qual.tpe.typeSymbol) {
- val obj = sym.owner.sourceModule
- Select(qual, nme.PACKAGE) setSymbol obj setType singleType(qual.tpe, obj)
+ if (needsPackageQualifier) {
+ // The owner of a symbol which requires package qualification may be the
+ // package object iself, but it also could be any superclass of the package
+ // object. In the latter case, we must go through the qualifier's info
+ // to obtain the right symbol.
+ val packageObject = if (sym.owner.isModuleClass) sym.owner.sourceModule else qual.tpe member nme.PACKAGE
+ Select(qual, nme.PACKAGE) setSymbol packageObject setType singleType(qual.tpe, packageObject)
}
else qual
@@ -229,10 +240,6 @@ abstract class TreeGen extends macros.TreeBuilder {
Literal(Constant(tp)) setType ConstantType(Constant(tp))
/** Builds a list with given head and tail. */
- def mkNewCons(head: Tree, tail: Tree): Tree =
- New(Apply(mkAttributedRef(ConsClass), List(head, tail)))
-
- /** Builds a list with given head and tail. */
def mkNil: Tree = mkAttributedRef(NilModule)
/** Builds a tree representing an undefined local, as in
diff --git a/src/reflect/scala/reflect/internal/TreeInfo.scala b/src/reflect/scala/reflect/internal/TreeInfo.scala
index 8908036442..13b761086c 100644
--- a/src/reflect/scala/reflect/internal/TreeInfo.scala
+++ b/src/reflect/scala/reflect/internal/TreeInfo.scala
@@ -104,11 +104,32 @@ abstract class TreeInfo {
false
}
- @deprecated("Use isExprSafeToInline instead", "2.10.0")
- def isPureExpr(tree: Tree) = isExprSafeToInline(tree)
+ /** As if the name of the method didn't give it away,
+ * this logic is designed around issuing helpful
+ * warnings and minimizing spurious ones. That means
+ * don't reuse it for important matters like inlining
+ * decisions.
+ */
+ def isPureExprForWarningPurposes(tree: Tree) = tree match {
+ case EmptyTree | Literal(Constant(())) => false
+ case _ =>
+ def isWarnableRefTree = tree match {
+ case t: RefTree => isExprSafeToInline(t.qualifier) && t.symbol != null && t.symbol.isAccessor
+ case _ => false
+ }
+ def isWarnableSymbol = {
+ val sym = tree.symbol
+ (sym == null) || !(sym.isModule || sym.isLazy) || {
+ debuglog("'Pure' but side-effecting expression in statement position: " + tree)
+ false
+ }
+ }
- def zipMethodParamsAndArgs(params: List[Symbol], args: List[Tree]): List[(Symbol, Tree)] =
- mapMethodParamsAndArgs(params, args)((param, arg) => ((param, arg)))
+ ( !tree.isErrorTyped
+ && (isExprSafeToInline(tree) || isWarnableRefTree)
+ && isWarnableSymbol
+ )
+ }
def mapMethodParamsAndArgs[R](params: List[Symbol], args: List[Tree])(f: (Symbol, Tree) => R): List[R] = {
val b = List.newBuilder[R]
@@ -119,11 +140,10 @@ abstract class TreeInfo {
val plen = params.length
val alen = args.length
def fail() = {
- global.debugwarn(
- "Mismatch trying to zip method parameters and argument list:\n" +
- " params = " + params + "\n" +
- " args = " + args + "\n"
- )
+ global.devWarning(
+ s"""|Mismatch trying to zip method parameters and argument list:
+ | params = $params
+ | args = $args""".stripMargin)
false
}
@@ -147,37 +167,6 @@ abstract class TreeInfo {
true
}
- /**
- * Selects the correct parameter list when there are nested applications.
- * Given Apply(fn, args), args might correspond to any of fn.symbol's parameter
- * lists. To choose the correct one before uncurry, we have to unwrap any
- * applies: for instance Apply(fn @ Apply(Apply(_, _), _), args) implies args
- * correspond to the third parameter list.
- *
- * The argument fn is the function part of the apply node being considered.
- *
- * Also accounts for varargs.
- */
- private def applyMethodParameters(fn: Tree): List[Symbol] = {
- val depth = dissectApplied(fn).applyDepth
- // There could be applies which go beyond the parameter list(s),
- // being applied to the result of the method call.
- // !!! Note that this still doesn't seem correct, although it should
- // be closer than what it replaced.
- if (depth < fn.symbol.paramss.size) fn.symbol.paramss(depth)
- else if (fn.symbol.paramss.isEmpty) Nil
- else fn.symbol.paramss.last
- }
-
- def zipMethodParamsAndArgs(t: Tree): List[(Symbol, Tree)] = t match {
- case Apply(fn, args) => zipMethodParamsAndArgs(applyMethodParameters(fn), args)
- case _ => Nil
- }
- def foreachMethodParamAndArg(t: Tree)(f: (Symbol, Tree) => Unit): Unit = t match {
- case Apply(fn, args) => foreachMethodParamAndArg(applyMethodParameters(fn), args)(f)
- case _ =>
- }
-
/** Is symbol potentially a getter of a variable?
*/
def mayBeVarGetter(sym: Symbol): Boolean = sym.info match {
@@ -234,6 +223,20 @@ abstract class TreeInfo {
tree
}
+ /** Strips layers of `.asInstanceOf[T]` / `_.$asInstanceOf[T]()` from an expression */
+ def stripCast(tree: Tree): Tree = tree match {
+ case TypeApply(sel @ Select(inner, _), _) if isCastSymbol(sel.symbol) =>
+ stripCast(inner)
+ case Apply(TypeApply(sel @ Select(inner, _), _), Nil) if isCastSymbol(sel.symbol) =>
+ stripCast(inner)
+ case t =>
+ t
+ }
+
+ object StripCast {
+ def unapply(tree: Tree): Some[Tree] = Some(stripCast(tree))
+ }
+
/** Is tree a self or super constructor call? */
def isSelfOrSuperConstrCall(tree: Tree) = {
// stripNamedApply for SI-3584: adaptToImplicitMethod in Typers creates a special context
@@ -309,10 +312,6 @@ abstract class TreeInfo {
case x: Ident => !x.isBackquoted && nme.isVariableName(x.name)
case _ => false
}
- def isDeprecatedIdentifier(tree: Tree): Boolean = tree match {
- case x: Ident => !x.isBackquoted && nme.isDeprecatedIdentifierName(x.name)
- case _ => false
- }
/** The first constructor definitions in `stats` */
def firstConstructor(stats: List[Tree]): Tree = stats find {
@@ -374,12 +373,6 @@ abstract class TreeInfo {
/** Is name a left-associative operator? */
def isLeftAssoc(operator: Name) = operator.nonEmpty && (operator.endChar != ':')
- /** Is tree a `this` node which belongs to `enclClass`? */
- def isSelf(tree: Tree, enclClass: Symbol): Boolean = tree match {
- case This(_) => tree.symbol == enclClass
- case _ => false
- }
-
/** a Match(Typed(_, tpt), _) must be translated into a switch if isSwitchAnnotation(tpt.tpe) */
def isSwitchAnnotation(tpe: Type) = tpe hasAnnotation definitions.SwitchClass
@@ -425,15 +418,31 @@ abstract class TreeInfo {
case _ => false
}
- /** Does this CaseDef catch Throwable? */
- def catchesThrowable(cdef: CaseDef) = catchesAllOf(cdef, ThrowableClass.tpe)
+ private def hasNoSymbol(t: Tree) = t.symbol == null || t.symbol == NoSymbol
- /** Does this CaseDef catch everything of a certain Type? */
- def catchesAllOf(cdef: CaseDef, threshold: Type) =
- isDefaultCase(cdef) || (cdef.guard.isEmpty && (unbind(cdef.pat) match {
- case Typed(Ident(nme.WILDCARD), tpt) => (tpt.tpe != null) && (threshold <:< tpt.tpe)
- case _ => false
- }))
+ /** If this CaseDef assigns a name to its top-level pattern,
+ * in the form 'expr @ pattern' or 'expr: pattern', returns
+ * the name. Otherwise, nme.NO_NAME.
+ *
+ * Note: in the case of Constant patterns such as 'case x @ "" =>',
+ * the pattern matcher eliminates the binding and inlines the constant,
+ * so as far as this method is likely to be able to determine,
+ * the name is NO_NAME.
+ */
+ def assignedNameOfPattern(cdef: CaseDef): Name = cdef.pat match {
+ case Bind(name, _) => name
+ case Ident(name) => name
+ case _ => nme.NO_NAME
+ }
+
+ /** Does this CaseDef catch Throwable? */
+ def catchesThrowable(cdef: CaseDef) = (
+ cdef.guard.isEmpty && (unbind(cdef.pat) match {
+ case Ident(nme.WILDCARD) => true
+ case i@Ident(name) => hasNoSymbol(i)
+ case _ => false
+ })
+ )
/** Is this pattern node a catch-all or type-test pattern? */
def isCatchCase(cdef: CaseDef) = cdef match {
diff --git a/src/reflect/scala/reflect/internal/Trees.scala b/src/reflect/scala/reflect/internal/Trees.scala
index 431afd286d..9e737528d2 100644
--- a/src/reflect/scala/reflect/internal/Trees.scala
+++ b/src/reflect/scala/reflect/internal/Trees.scala
@@ -24,14 +24,17 @@ trait Trees extends api.Trees { self: SymbolTable =>
private[this] var rawtpe: Type = _
final def tpe = rawtpe
- def tpe_=(t: Type) = rawtpe = t
+ @deprecated("Use setType", "2.11.0") def tpe_=(t: Type): Unit = setType(t)
+
+ def clearType(): this.type = this setType null
def setType(tp: Type): this.type = { rawtpe = tp; this }
def defineType(tp: Type): this.type = setType(tp)
def symbol: Symbol = null //!!!OPT!!! symbol is about 3% of hot compile times -- megamorphic dispatch?
def symbol_=(sym: Symbol) { throw new UnsupportedOperationException("symbol_= inapplicable for " + this) }
def setSymbol(sym: Symbol): this.type = { symbol = sym; this }
- def hasSymbol = false
+ def hasSymbolField = false
+ @deprecated("Use hasSymbolField", "2.11.0") def hasSymbol = hasSymbolField
def isDef = false
@@ -63,7 +66,7 @@ trait Trees extends api.Trees { self: SymbolTable =>
private[scala] def copyAttrs(tree: Tree): this.type = {
rawatt = tree.rawatt
tpe = tree.tpe
- if (hasSymbol) symbol = tree.symbol
+ if (hasSymbolField) symbol = tree.symbol
this
}
@@ -211,7 +214,7 @@ trait Trees extends api.Trees { self: SymbolTable =>
trait TypTree extends Tree with TypTreeApi
abstract class SymTree extends Tree with SymTreeContextApi {
- override def hasSymbol = true
+ override def hasSymbolField = true
override var symbol: Symbol = NoSymbol
}
@@ -409,6 +412,16 @@ trait Trees extends api.Trees { self: SymbolTable =>
def ApplyConstructor(tpt: Tree, args: List[Tree]) = Apply(Select(New(tpt), nme.CONSTRUCTOR), args)
+ // Creates a constructor call from the constructor symbol. This is
+ // to avoid winding up with an OverloadedType for the constructor call.
+ def NewFromConstructor(constructor: Symbol, args: Tree*) = {
+ assert(constructor.isConstructor, constructor)
+ val instance = New(TypeTree(constructor.owner.tpe))
+ val init = Select(instance, nme.CONSTRUCTOR) setSymbol constructor
+
+ Apply(init, args.toList)
+ }
+
case class ApplyDynamic(qual: Tree, args: List[Tree]) extends SymTree with TermTree
case class Super(qual: Tree, mix: TypeName) extends TermTree with SuperApi {
@@ -856,7 +869,6 @@ trait Trees extends api.Trees { self: SymbolTable =>
/** Is the tree Predef, scala.Predef, or _root_.scala.Predef?
*/
def isReferenceToPredef(t: Tree) = isReferenceToScalaMember(t, nme.Predef)
- def isReferenceToAnyVal(t: Tree) = isReferenceToScalaMember(t, tpnme.AnyVal)
// --- modifiers implementation ---------------------------------------
@@ -1392,7 +1404,7 @@ trait Trees extends api.Trees { self: SymbolTable =>
class ThisSubstituter(clazz: Symbol, to: => Tree) extends Transformer {
val newtpe = to.tpe
override def transform(tree: Tree) = {
- if (tree.tpe ne null) tree.tpe = tree.tpe.substThis(clazz, newtpe)
+ tree modifyType (_.substThis(clazz, newtpe))
tree match {
case This(_) if tree.symbol == clazz => to
case _ => super.transform(tree)
@@ -1402,8 +1414,7 @@ trait Trees extends api.Trees { self: SymbolTable =>
class TypeMapTreeSubstituter(val typeMap: TypeMap) extends Traverser {
override def traverse(tree: Tree) {
- if (tree.tpe ne null)
- tree.tpe = typeMap(tree.tpe)
+ tree modifyType typeMap
if (tree.isDef)
tree.symbol modifyInfo typeMap
@@ -1435,9 +1446,9 @@ trait Trees extends api.Trees { self: SymbolTable =>
if (tree.symbol == from.head) tree setSymbol to.head
else subst(from.tail, to.tail)
}
+ tree modifyType symSubst
- if (tree.tpe ne null) tree.tpe = symSubst(tree.tpe)
- if (tree.hasSymbol) {
+ if (tree.hasSymbolField) {
subst(from, to)
tree match {
case Ident(name0) if tree.symbol != NoSymbol =>
diff --git a/src/reflect/scala/reflect/internal/TypeDebugging.scala b/src/reflect/scala/reflect/internal/TypeDebugging.scala
index 68b4fa69a1..d437b1b058 100644
--- a/src/reflect/scala/reflect/internal/TypeDebugging.scala
+++ b/src/reflect/scala/reflect/internal/TypeDebugging.scala
@@ -9,8 +9,6 @@ package internal
trait TypeDebugging {
self: SymbolTable =>
- import definitions._
-
// @M toString that is safe during debugging (does not normalize, ...)
object typeDebug {
private def to_s(x: Any): String = x match {
@@ -20,7 +18,6 @@ trait TypeDebugging {
case x: Product => x.productIterator mkString ("(", ", ", ")")
case _ => "" + x
}
- def ptIndent(x: Any) = ("" + x).replaceAll("\\n", " ")
def ptBlock(label: String, pairs: (String, Any)*): String = {
if (pairs.isEmpty) label + "{ }"
else {
diff --git a/src/reflect/scala/reflect/internal/Types.scala b/src/reflect/scala/reflect/internal/Types.scala
index 119a57d268..282d7e18ac 100644
--- a/src/reflect/scala/reflect/internal/Types.scala
+++ b/src/reflect/scala/reflect/internal/Types.scala
@@ -22,6 +22,8 @@ import util.ThreeValues._
// internal: error
case WildcardType =>
// internal: unknown
+ case BoundedWildcardType(bounds) =>
+ // internal: unknown
case NoType =>
case NoPrefix =>
case ThisType(sym) =>
@@ -66,9 +68,7 @@ import util.ThreeValues._
// a type variable
// Replace occurrences of type parameters with type vars, where
// inst is the instantiation and constr is a list of bounds.
- case DeBruijnIndex(level, index, args)
- // for dependent method types: a type referring to a method parameter.
- case ErasedValueType(tref)
+ case ErasedValueType(clazz, underlying)
// only used during erasure of derived value classes.
*/
@@ -91,6 +91,7 @@ trait Types extends api.Types { self: SymbolTable =>
private final val printLubs = sys.props contains "scalac.debug.lub"
private final val traceTypeVars = sys.props contains "scalac.debug.tvar"
+ private final val breakCycles = settings.breakCycles.value
/** In case anyone wants to turn off lub verification without reverting anything. */
private final val verifyLubs = true
/** In case anyone wants to turn off type parameter bounds being used
@@ -100,10 +101,6 @@ trait Types extends api.Types { self: SymbolTable =>
protected val enableTypeVarExperimentals = settings.Xexperimental.value
- /** Empty immutable maps to avoid allocations. */
- private val emptySymMap = immutable.Map[Symbol, Symbol]()
- private val emptySymCount = immutable.Map[Symbol, Int]()
-
/** The current skolemization level, needed for the algorithms
* in isSameType, isSubType that do constraint solving under a prefix.
*/
@@ -170,10 +167,6 @@ trait Types extends api.Types { self: SymbolTable =>
log = Nil
} finally unlock()
}
- def size = {
- lock()
- try log.size finally unlock()
- }
// `block` should not affect constraints on typevars
def undo[T](block: => T): T = {
@@ -185,20 +178,6 @@ trait Types extends api.Types { self: SymbolTable =>
finally undoTo(before)
} finally unlock()
}
-
- // if `block` evaluates to false, it should not affect constraints on typevars
- def undoUnless(block: => Boolean): Boolean = {
- lock()
- try {
- val before = log
- var result = false
-
- try result = block
- finally if (!result) undoTo(before)
-
- result
- } finally unlock()
- }
}
/** A map from lists to compound types that have the given list as parents.
@@ -295,7 +274,6 @@ trait Types extends api.Types { self: SymbolTable =>
abstract class TypeApiImpl extends TypeApi { this: Type =>
def declaration(name: Name): Symbol = decl(name)
- def nonPrivateDeclaration(name: Name): Symbol = nonPrivateDecl(name)
def declarations = decls
def typeArguments = typeArgs
def erasure = this match {
@@ -382,9 +360,6 @@ trait Types extends api.Types { self: SymbolTable =>
/** Is this type produced as a repair for an error? */
def isErroneous: Boolean = ErroneousCollector.collect(this)
- /** Does this type denote a reference type which can be null? */
- // def isNullable: Boolean = false
-
/** Can this type only be subtyped by bottom types?
* This is assessed to be the case if the class is final,
* and all type parameters (if any) are invariant.
@@ -522,11 +497,6 @@ trait Types extends api.Types { self: SymbolTable =>
/** Only used for dependent method types. */
def resultApprox: Type = ApproximateDependentMap(resultType)
- /** If this is a TypeRef `clazz`[`T`], return the argument `T`
- * otherwise return this type
- */
- def remove(clazz: Symbol): Type = this
-
/** For a curried/nullary method or poly type its non-method result type,
* the type itself for all other types */
def finalResultType: Type = this
@@ -664,16 +634,6 @@ trait Types extends api.Types { self: SymbolTable =>
def nonPrivateMember(name: Name): Symbol =
memberBasedOnName(name, BridgeAndPrivateFlags)
- /** All members with the given flags, excluding bridges.
- */
- def membersWithFlags(requiredFlags: Long): Scope =
- membersBasedOnFlags(BridgeFlags, requiredFlags)
-
- /** All non-private members with the given flags, excluding bridges.
- */
- def nonPrivateMembersWithFlags(requiredFlags: Long): Scope =
- membersBasedOnFlags(BridgeAndPrivateFlags, requiredFlags)
-
/** The non-private member with given name, admitting members with given flags `admit`.
* "Admitting" refers to the fact that members with a PRIVATE, BRIDGE, or VBRIDGE
* flag are usually excluded from findMember results, but supplying any of those flags
@@ -694,7 +654,6 @@ trait Types extends api.Types { self: SymbolTable =>
*/
def membersBasedOnFlags(excludedFlags: Long, requiredFlags: Long): Scope =
findMembers(excludedFlags, requiredFlags)
-// findMember(nme.ANYNAME, excludedFlags, requiredFlags, false).alternatives
def memberBasedOnName(name: Name, excludedFlags: Long): Symbol =
findMember(name, excludedFlags, 0, false)
@@ -748,6 +707,7 @@ trait Types extends api.Types { self: SymbolTable =>
* }}}
*/
def memberInfo(sym: Symbol): Type = {
+ require(sym ne NoSymbol, this)
sym.info.asSeenFrom(this, sym.owner)
}
@@ -808,7 +768,6 @@ trait Types extends api.Types { self: SymbolTable =>
else substThis(from, to).substSym(symsFrom, symsTo)
/** Returns all parts of this type which satisfy predicate `p` */
- def filter(p: Type => Boolean): List[Type] = new FilterTypeCollector(p) collect this
def withFilter(p: Type => Boolean) = new FilterMapForeach(p)
class FilterMapForeach(p: Type => Boolean) extends FilterTypeCollector(p){
@@ -838,9 +797,6 @@ trait Types extends api.Types { self: SymbolTable =>
/** Does this type contain a reference to this symbol? */
def contains(sym: Symbol): Boolean = new ContainsCollector(sym).collect(this)
- /** Does this type contain a reference to this type */
- def containsTp(tp: Type): Boolean = new ContainsTypeCollector(tp).collect(this)
-
/** Is this type a subtype of that type? */
def <:<(that: Type): Boolean = {
if (Statistics.canEnable) stat_<:<(that)
@@ -901,11 +857,6 @@ trait Types extends api.Types { self: SymbolTable =>
else isSameType(this, that))
);
- /** Does this type implement symbol `sym` with same or stronger type? */
- def specializes(sym: Symbol): Boolean =
- if (explainSwitch) explain("specializes", specializesSym, this, sym)
- else specializesSym(this, sym)
-
/** Is this type close enough to that type so that members
* with the two type would override each other?
* This means:
@@ -1050,69 +1001,66 @@ trait Types extends api.Types { self: SymbolTable =>
}
def findMembers(excludedFlags: Long, requiredFlags: Long): Scope = {
- // if this type contains type variables, put them to sleep for a while -- don't just wipe them out by
- // replacing them by the corresponding type parameter, as that messes up (e.g.) type variables in type refinements
- // without this, the matchesType call would lead to type variables on both sides
- // of a subtyping/equality judgement, which can lead to recursive types being constructed.
- // See (t0851) for a situation where this happens.
- val suspension: List[TypeVar] = if (this.isGround) null else suspendTypeVarsInType(this)
-
- if (Statistics.canEnable) Statistics.incCounter(findMembersCount)
- val start = if (Statistics.canEnable) Statistics.pushTimer(typeOpsStack, findMembersNanos) else null
-
- //Console.println("find member " + name.decode + " in " + this + ":" + this.baseClasses)//DEBUG
- var members: Scope = null
- var required = requiredFlags
- var excluded = excludedFlags | DEFERRED
- var continue = true
- var self: Type = null
- while (continue) {
- continue = false
- val bcs0 = baseClasses
- var bcs = bcs0
- while (!bcs.isEmpty) {
- val decls = bcs.head.info.decls
- var entry = decls.elems
- while (entry ne null) {
- val sym = entry.sym
- val flags = sym.flags
- if ((flags & required) == required) {
- val excl = flags & excluded
- if (excl == 0L &&
- (// omit PRIVATE LOCALS unless selector class is contained in class owning the def.
- (bcs eq bcs0) ||
- (flags & PrivateLocal) != PrivateLocal ||
- (bcs0.head.hasTransOwner(bcs.head)))) {
- if (members eq null) members = newFindMemberScope
- var others: ScopeEntry = members.lookupEntry(sym.name)
- var symtpe: Type = null
- while ((others ne null) && {
- val other = others.sym
- (other ne sym) &&
- ((other.owner eq sym.owner) ||
- (flags & PRIVATE) != 0 || {
- if (self eq null) self = narrowForFindMember(this)
- if (symtpe eq null) symtpe = self.memberType(sym)
- !(self.memberType(other) matches symtpe)
- })}) {
- others = members lookupNextEntry others
+ def findMembersInternal: Scope = {
+ var members: Scope = null
+ if (Statistics.canEnable) Statistics.incCounter(findMembersCount)
+ val start = if (Statistics.canEnable) Statistics.pushTimer(typeOpsStack, findMembersNanos) else null
+
+ //Console.println("find member " + name.decode + " in " + this + ":" + this.baseClasses)//DEBUG
+ var required = requiredFlags
+ var excluded = excludedFlags | DEFERRED
+ var continue = true
+ var self: Type = null
+ while (continue) {
+ continue = false
+ val bcs0 = baseClasses
+ var bcs = bcs0
+ while (!bcs.isEmpty) {
+ val decls = bcs.head.info.decls
+ var entry = decls.elems
+ while (entry ne null) {
+ val sym = entry.sym
+ val flags = sym.flags
+ if ((flags & required) == required) {
+ val excl = flags & excluded
+ if (excl == 0L &&
+ (// omit PRIVATE LOCALS unless selector class is contained in class owning the def.
+ (bcs eq bcs0) ||
+ (flags & PrivateLocal) != PrivateLocal ||
+ (bcs0.head.hasTransOwner(bcs.head)))) {
+ if (members eq null) members = newFindMemberScope
+ var others: ScopeEntry = members.lookupEntry(sym.name)
+ var symtpe: Type = null
+ while ((others ne null) && {
+ val other = others.sym
+ (other ne sym) &&
+ ((other.owner eq sym.owner) ||
+ (flags & PRIVATE) != 0 || {
+ if (self eq null) self = narrowForFindMember(this)
+ if (symtpe eq null) symtpe = self.memberType(sym)
+ !(self.memberType(other) matches symtpe)
+ })}) {
+ others = members lookupNextEntry others
+ }
+ if (others eq null) members enter sym
+ } else if (excl == DEFERRED) {
+ continue = true
}
- if (others eq null) members enter sym
- } else if (excl == DEFERRED) {
- continue = true
}
- }
- entry = entry.next
- } // while (entry ne null)
- // excluded = excluded | LOCAL
- bcs = bcs.tail
- } // while (!bcs.isEmpty)
- required |= DEFERRED
- excluded &= ~(DEFERRED.toLong)
- } // while (continue)
- if (Statistics.canEnable) Statistics.popTimer(typeOpsStack, start)
- if (suspension ne null) suspension foreach (_.suspended = false)
- if (members eq null) EmptyScope else members
+ entry = entry.next
+ } // while (entry ne null)
+ // excluded = excluded | LOCAL
+ bcs = bcs.tail
+ } // while (!bcs.isEmpty)
+ required |= DEFERRED
+ excluded &= ~(DEFERRED.toLong)
+ } // while (continue)
+ if (Statistics.canEnable) Statistics.popTimer(typeOpsStack, start)
+ if (members eq null) EmptyScope else members
+ }
+
+ if (this.isGround) findMembersInternal
+ else suspendingTypeVars(typeVarsInType(this))(findMembersInternal)
}
/**
@@ -1126,102 +1074,98 @@ trait Types extends api.Types { self: SymbolTable =>
*/
//TODO: use narrow only for modules? (correct? efficiency gain?)
def findMember(name: Name, excludedFlags: Long, requiredFlags: Long, stableOnly: Boolean): Symbol = {
- // if this type contains type variables, put them to sleep for a while -- don't just wipe them out by
- // replacing them by the corresponding type parameter, as that messes up (e.g.) type variables in type refinements
- // without this, the matchesType call would lead to type variables on both sides
- // of a subtyping/equality judgement, which can lead to recursive types being constructed.
- // See (t0851) for a situation where this happens.
- val suspension: List[TypeVar] = if (this.isGround) null else suspendTypeVarsInType(this)
-
- if (Statistics.canEnable) Statistics.incCounter(findMemberCount)
- val start = if (Statistics.canEnable) Statistics.pushTimer(typeOpsStack, findMemberNanos) else null
-
- //Console.println("find member " + name.decode + " in " + this + ":" + this.baseClasses)//DEBUG
- var member: Symbol = NoSymbol
- var members: List[Symbol] = null
- var lastM: ::[Symbol] = null
- var membertpe: Type = null
- var required = requiredFlags
- var excluded = excludedFlags | DEFERRED
- var continue = true
- var self: Type = null
-
- while (continue) {
- continue = false
- val bcs0 = baseClasses
- var bcs = bcs0
- while (!bcs.isEmpty) {
- val decls = bcs.head.info.decls
- var entry = decls.lookupEntry(name)
- while (entry ne null) {
- val sym = entry.sym
- val flags = sym.flags
- if ((flags & required) == required) {
- val excl = flags & excluded
- if (excl == 0L &&
- (// omit PRIVATE LOCALS unless selector class is contained in class owning the def.
- (bcs eq bcs0) ||
- (flags & PrivateLocal) != PrivateLocal ||
- (bcs0.head.hasTransOwner(bcs.head)))) {
- if (name.isTypeName || stableOnly && sym.isStable) {
- if (Statistics.canEnable) Statistics.popTimer(typeOpsStack, start)
- if (suspension ne null) suspension foreach (_.suspended = false)
- return sym
- } else if (member eq NoSymbol) {
- member = sym
- } else if (members eq null) {
- if ((member ne sym) &&
- ((member.owner eq sym.owner) ||
- (flags & PRIVATE) != 0 || {
- if (self eq null) self = narrowForFindMember(this)
- if (membertpe eq null) membertpe = self.memberType(member)
- !(membertpe matches self.memberType(sym))
- })) {
- lastM = new ::(sym, null)
- members = member :: lastM
- }
- } else {
- var others: List[Symbol] = members
- var symtpe: Type = null
- while ((others ne null) && {
- val other = others.head
- (other ne sym) &&
- ((other.owner eq sym.owner) ||
+ def findMemberInternal: Symbol = {
+ var member: Symbol = NoSymbol
+ var members: List[Symbol] = null
+ var lastM: ::[Symbol] = null
+ if (Statistics.canEnable) Statistics.incCounter(findMemberCount)
+ val start = if (Statistics.canEnable) Statistics.pushTimer(typeOpsStack, findMemberNanos) else null
+
+ //Console.println("find member " + name.decode + " in " + this + ":" + this.baseClasses)//DEBUG
+ var membertpe: Type = null
+ var required = requiredFlags
+ var excluded = excludedFlags | DEFERRED
+ var continue = true
+ var self: Type = null
+
+ while (continue) {
+ continue = false
+ val bcs0 = baseClasses
+ var bcs = bcs0
+ while (!bcs.isEmpty) {
+ val decls = bcs.head.info.decls
+ var entry = decls.lookupEntry(name)
+ while (entry ne null) {
+ val sym = entry.sym
+ val flags = sym.flags
+ if ((flags & required) == required) {
+ val excl = flags & excluded
+ if (excl == 0L &&
+ (// omit PRIVATE LOCALS unless selector class is contained in class owning the def.
+ (bcs eq bcs0) ||
+ (flags & PrivateLocal) != PrivateLocal ||
+ (bcs0.head.hasTransOwner(bcs.head)))) {
+ if (name.isTypeName || stableOnly && sym.isStable) {
+ if (Statistics.canEnable) Statistics.popTimer(typeOpsStack, start)
+ return sym
+ } else if (member eq NoSymbol) {
+ member = sym
+ } else if (members eq null) {
+ if ((member ne sym) &&
+ ((member.owner eq sym.owner) ||
(flags & PRIVATE) != 0 || {
if (self eq null) self = narrowForFindMember(this)
- if (symtpe eq null) symtpe = self.memberType(sym)
- !(self.memberType(other) matches symtpe)
- })}) {
- others = others.tail
- }
- if (others eq null) {
- val lastM1 = new ::(sym, null)
- lastM.tl = lastM1
- lastM = lastM1
+ if (membertpe eq null) membertpe = self.memberType(member)
+ !(membertpe matches self.memberType(sym))
+ })) {
+ lastM = new ::(sym, null)
+ members = member :: lastM
+ }
+ } else {
+ var others: List[Symbol] = members
+ var symtpe: Type = null
+ while ((others ne null) && {
+ val other = others.head
+ (other ne sym) &&
+ ((other.owner eq sym.owner) ||
+ (flags & PRIVATE) != 0 || {
+ if (self eq null) self = narrowForFindMember(this)
+ if (symtpe eq null) symtpe = self.memberType(sym)
+ !(self.memberType(other) matches symtpe)
+ })}) {
+ others = others.tail
+ }
+ if (others eq null) {
+ val lastM1 = new ::(sym, null)
+ lastM.tl = lastM1
+ lastM = lastM1
+ }
}
+ } else if (excl == DEFERRED) {
+ continue = true
}
- } else if (excl == DEFERRED) {
- continue = true
}
- }
- entry = decls lookupNextEntry entry
- } // while (entry ne null)
- // excluded = excluded | LOCAL
- bcs = if (name == nme.CONSTRUCTOR) Nil else bcs.tail
- } // while (!bcs.isEmpty)
- required |= DEFERRED
- excluded &= ~(DEFERRED.toLong)
- } // while (continue)
- if (Statistics.canEnable) Statistics.popTimer(typeOpsStack, start)
- if (suspension ne null) suspension foreach (_.suspended = false)
- if (members eq null) {
- if (member == NoSymbol) if (Statistics.canEnable) Statistics.incCounter(noMemberCount)
- member
- } else {
- if (Statistics.canEnable) Statistics.incCounter(multMemberCount)
- lastM.tl = Nil
- baseClasses.head.newOverloaded(this, members)
+ entry = decls lookupNextEntry entry
+ } // while (entry ne null)
+ // excluded = excluded | LOCAL
+ bcs = if (name == nme.CONSTRUCTOR) Nil else bcs.tail
+ } // while (!bcs.isEmpty)
+ required |= DEFERRED
+ excluded &= ~(DEFERRED.toLong)
+ } // while (continue)
+ if (Statistics.canEnable) Statistics.popTimer(typeOpsStack, start)
+ if (members eq null) {
+ if (member == NoSymbol) if (Statistics.canEnable) Statistics.incCounter(noMemberCount)
+ member
+ } else {
+ if (Statistics.canEnable) Statistics.incCounter(multMemberCount)
+ lastM.tl = Nil
+ baseClasses.head.newOverloaded(this, members)
+ }
}
+
+ if (this.isGround) findMemberInternal
+ else suspendingTypeVars(typeVarsInType(this))(findMemberInternal)
}
/** The (existential or otherwise) skolems and existentially quantified variables which are free in this type */
@@ -1250,10 +1194,6 @@ trait Types extends api.Types { self: SymbolTable =>
def setAnnotations(annots: List[AnnotationInfo]): Type = annotatedType(annots, this)
def withAnnotations(annots: List[AnnotationInfo]): Type = annotatedType(annots, this)
- /** Remove any annotations from this type and from any
- * types embedded in this type. */
- def stripAnnotations = StripAnnotationsMap(this)
-
/** Set the self symbol of an annotated type, or do nothing
* otherwise. */
def withSelfsym(sym: Symbol) = this
@@ -1346,7 +1286,6 @@ trait Types extends api.Types { self: SymbolTable =>
override def baseType(clazz: Symbol): Type = this
override def safeToString: String = "<error>"
override def narrow: Type = this
- // override def isNullable: Boolean = true
override def kind = "ErrorType"
}
@@ -1356,7 +1295,6 @@ trait Types extends api.Types { self: SymbolTable =>
case object WildcardType extends Type {
override def isWildcard = true
override def safeToString: String = "?"
- // override def isNullable: Boolean = true
override def kind = "WildcardType"
}
/** BoundedWildcardTypes, used only during type inference, are created in
@@ -1381,7 +1319,6 @@ trait Types extends api.Types { self: SymbolTable =>
case object NoType extends Type {
override def isTrivial: Boolean = true
override def safeToString: String = "<notype>"
- // override def isNullable: Boolean = true
override def kind = "NoType"
}
@@ -1391,7 +1328,6 @@ trait Types extends api.Types { self: SymbolTable =>
override def isStable: Boolean = true
override def prefixString = ""
override def safeToString: String = "<noprefix>"
- // override def isNullable: Boolean = true
override def kind = "NoPrefixType"
}
@@ -1404,7 +1340,6 @@ trait Types extends api.Types { self: SymbolTable =>
abort(s"ThisType($sym) for sym which is not a class")
}
- //assert(sym.isClass && !sym.isModuleClass || sym.isRoot, sym)
override def isTrivial: Boolean = sym.isPackageClass
override def isNotNull = true
override def typeSymbol = sym
@@ -1430,7 +1365,7 @@ trait Types extends api.Types { self: SymbolTable =>
def apply(sym: Symbol): Type = (
if (!phase.erasedTypes) unique(new UniqueThisType(sym))
else if (sym.isImplClass) sym.typeOfThis
- else sym.tpe
+ else sym.tpe_*
)
}
@@ -1445,7 +1380,6 @@ trait Types extends api.Types { self: SymbolTable =>
}
override def isGround = sym.isPackageClass || pre.isGround
- // override def isNullable = underlying.isNullable
override def isNotNull = underlying.isNotNull
private[reflect] var underlyingCache: Type = NoType
private[reflect] var underlyingPeriod = NoPeriod
@@ -1543,11 +1477,10 @@ trait Types extends api.Types { self: SymbolTable =>
}
private def lowerString = if (emptyLowerBound) "" else " >: " + lo
private def upperString = if (emptyUpperBound) "" else " <: " + hi
- private def emptyLowerBound = typeIsNothing(lo)
- private def emptyUpperBound = typeIsAny(hi)
+ private def emptyLowerBound = typeIsNothing(lo) || lo.isWildcard
+ private def emptyUpperBound = typeIsAny(hi) || hi.isWildcard
def isEmptyBounds = emptyLowerBound && emptyUpperBound
- // override def isNullable: Boolean = NullClass.tpe <:< lo;
override def safeToString = lowerString + upperString
override def kind = "TypeBoundsType"
}
@@ -1632,15 +1565,44 @@ trait Types extends api.Types { self: SymbolTable =>
override def isStructuralRefinement: Boolean =
typeSymbol.isAnonOrRefinementClass && (decls exists symbolIsPossibleInRefinement)
- // override def isNullable: Boolean =
- // parents forall (p => p.isNullable && !p.typeSymbol.isAbstractType);
-
override def safeToString: String = parentsString(parents) + (
(if (settings.debug.value || parents.isEmpty || (decls.elems ne null))
fullyInitializeScope(decls).mkString("{", "; ", "}") else "")
)
}
+ protected def computeBaseClasses(tpe: Type): List[Symbol] = {
+ val parents = tpe.parents // adriaan says tpe.parents does work sometimes, so call it only once
+ val baseTail = (
+ if (parents.isEmpty || parents.head.isInstanceOf[PackageTypeRef]) Nil
+ else {
+ //Console.println("computing base classes of " + typeSymbol + " at phase " + phase);//DEBUG
+ // optimized, since this seems to be performance critical
+ val superclazz = parents.head // parents.isEmpty was already excluded
+ var mixins = parents.tail
+ val sbcs = superclazz.baseClasses
+ var bcs = sbcs
+ def isNew(clazz: Symbol): Boolean = (
+ superclazz.baseTypeIndex(clazz) < 0 &&
+ { var p = bcs;
+ while ((p ne sbcs) && (p.head != clazz)) p = p.tail;
+ p eq sbcs
+ }
+ )
+ while (!mixins.isEmpty) {
+ def addMixinBaseClasses(mbcs: List[Symbol]): List[Symbol] =
+ if (mbcs.isEmpty) bcs
+ else if (isNew(mbcs.head)) mbcs.head :: addMixinBaseClasses(mbcs.tail)
+ else addMixinBaseClasses(mbcs.tail)
+ bcs = addMixinBaseClasses(mixins.head.baseClasses)
+ mixins = mixins.tail
+ }
+ bcs
+ }
+ )
+ tpe.typeSymbol :: baseTail
+ }
+
protected def defineBaseTypeSeqOfCompoundType(tpe: CompoundType) = {
val period = tpe.baseTypeSeqPeriod
if (period != currentPeriod) {
@@ -1660,7 +1622,7 @@ trait Types extends api.Types { self: SymbolTable =>
val paramToVarMap = varToParamMap map (_.swap)
val varToParam = new TypeMap {
def apply(tp: Type) = varToParamMap get tp match {
- case Some(sym) => sym.tpe
+ case Some(sym) => sym.tpe_*
case _ => mapOver(tp)
}
}
@@ -1679,7 +1641,7 @@ trait Types extends api.Types { self: SymbolTable =>
tpe.baseTypeSeqCache = undetBaseTypeSeq
tpe.baseTypeSeqCache =
if (tpe.typeSymbol.isRefinementClass)
- tpe.memo(compoundBaseTypeSeq(tpe))(_.baseTypeSeq updateHead tpe.typeSymbol.tpe)
+ tpe.memo(compoundBaseTypeSeq(tpe))(_.baseTypeSeq updateHead tpe.typeSymbol.tpe_*)
else
compoundBaseTypeSeq(tpe)
} finally {
@@ -1701,41 +1663,61 @@ trait Types extends api.Types { self: SymbolTable =>
throw new TypeError("illegal cyclic inheritance involving " + tpe.typeSymbol)
}
- protected def defineBaseClassesOfCompoundType(tpe: CompoundType) = {
- def computeBaseClasses: List[Symbol] =
- if (tpe.parents.isEmpty) List(tpe.typeSymbol)
- else {
- //Console.println("computing base classes of " + typeSymbol + " at phase " + phase);//DEBUG
- // optimized, since this seems to be performance critical
- val superclazz = tpe.firstParent
- var mixins = tpe.parents.tail
- val sbcs = superclazz.baseClasses
- var bcs = sbcs
- def isNew(clazz: Symbol): Boolean =
- superclazz.baseTypeIndex(clazz) < 0 &&
- { var p = bcs;
- while ((p ne sbcs) && (p.head != clazz)) p = p.tail;
- p eq sbcs
- }
- while (!mixins.isEmpty) {
- def addMixinBaseClasses(mbcs: List[Symbol]): List[Symbol] =
- if (mbcs.isEmpty) bcs
- else if (isNew(mbcs.head)) mbcs.head :: addMixinBaseClasses(mbcs.tail)
- else addMixinBaseClasses(mbcs.tail)
- bcs = addMixinBaseClasses(mixins.head.baseClasses)
- mixins = mixins.tail
+ object baseClassesCycleMonitor {
+ private var open: List[Symbol] = Nil
+ @inline private def cycleLog(msg: => String) {
+ if (settings.debug.value)
+ Console.err.println(msg)
+ }
+ def size = open.size
+ def push(clazz: Symbol) {
+ cycleLog("+ " + (" " * size) + clazz.fullNameString)
+ open ::= clazz
+ }
+ def pop(clazz: Symbol) {
+ assert(open.head eq clazz, (clazz, open))
+ open = open.tail
+ }
+ def isOpen(clazz: Symbol) = open contains clazz
+ }
+
+ protected def defineBaseClassesOfCompoundType(tpe: CompoundType) {
+ def define() = defineBaseClassesOfCompoundType(tpe, force = false)
+ if (!breakCycles || isPastTyper) define()
+ else tpe match {
+ // non-empty parents helpfully excludes all package classes
+ case tpe @ ClassInfoType(_ :: _, _, clazz) if !clazz.isAnonOrRefinementClass =>
+ // Cycle: force update
+ if (baseClassesCycleMonitor isOpen clazz)
+ defineBaseClassesOfCompoundType(tpe, force = true)
+ else {
+ baseClassesCycleMonitor push clazz
+ try define()
+ finally baseClassesCycleMonitor pop clazz
}
- tpe.typeSymbol :: bcs
- }
+ case _ =>
+ define()
+ }
+ }
+ private def defineBaseClassesOfCompoundType(tpe: CompoundType, force: Boolean) {
val period = tpe.baseClassesPeriod
- if (period != currentPeriod) {
+ if (period == currentPeriod) {
+ if (force && breakCycles) {
+ def what = tpe.typeSymbol + " in " + tpe.typeSymbol.owner.fullNameString
+ val bcs = computeBaseClasses(tpe)
+ tpe.baseClassesCache = bcs
+ warning(s"Breaking cycle in base class computation of $what ($bcs)")
+ }
+ }
+ else {
tpe.baseClassesPeriod = currentPeriod
if (!isValidForBaseClasses(period)) {
val start = if (Statistics.canEnable) Statistics.pushTimer(typeOpsStack, baseClassesNanos) else null
try {
tpe.baseClassesCache = null
- tpe.baseClassesCache = tpe.memo(computeBaseClasses)(tpe.typeSymbol :: _.baseClasses.tail)
- } finally {
+ tpe.baseClassesCache = tpe.memo(computeBaseClasses(tpe))(tpe.typeSymbol :: _.baseClasses.tail)
+ }
+ finally {
if (Statistics.canEnable) Statistics.popTimer(typeOpsStack, start)
}
}
@@ -1931,7 +1913,7 @@ trait Types extends api.Types { self: SymbolTable =>
case tr @ TypeRef(_, sym, args) if args.nonEmpty =>
val tparams = tr.initializedTypeParams
if (settings.debug.value && !sameLength(tparams, args))
- debugwarn("Mismatched zip in computeRefs(): " + sym.info.typeParams + ", " + args)
+ devWarning(s"Mismatched zip in computeRefs(): ${sym.info.typeParams}, $args")
foreach2(tparams, args) { (tparam1, arg) =>
if (arg contains tparam) {
@@ -1974,7 +1956,7 @@ trait Types extends api.Types { self: SymbolTable =>
var change = false
for ((from, targets) <- refs(NonExpansive).iterator)
for (target <- targets) {
- var thatInfo = classInfo(target)
+ val thatInfo = classInfo(target)
if (thatInfo.state != Initialized)
change = change | thatInfo.propagate()
addRefs(NonExpansive, from, thatInfo.getRefs(NonExpansive, target))
@@ -1982,7 +1964,7 @@ trait Types extends api.Types { self: SymbolTable =>
}
for ((from, targets) <- refs(Expansive).iterator)
for (target <- targets) {
- var thatInfo = classInfo(target)
+ val thatInfo = classInfo(target)
if (thatInfo.state != Initialized)
change = change | thatInfo.propagate()
addRefs(Expansive, from, thatInfo.getRefs(NonExpansive, target))
@@ -1993,11 +1975,6 @@ trait Types extends api.Types { self: SymbolTable =>
change
}
- // override def isNullable: Boolean =
- // symbol == AnyClass ||
- // symbol != NothingClass && (symbol isSubClass ObjectClass) && !(symbol isSubClass NonNullClass);
-
- // override def isNonNull: Boolean = symbol == NonNullClass || super.isNonNull;
override def kind = "ClassInfoType"
override def safeToString =
@@ -2022,8 +1999,6 @@ trait Types extends api.Types { self: SymbolTable =>
extends ClassInfoType(List(), decls, clazz)
/** A class representing a constant type.
- *
- * @param value ...
*/
abstract case class ConstantType(value: Constant) extends SingletonType with ConstantTypeApi {
override def underlying: Type = value.tpe
@@ -2033,8 +2008,6 @@ trait Types extends api.Types { self: SymbolTable =>
override def deconst: Type = underlying
override def safeToString: String =
underlying.toString + "(" + value.escapedStringValue + ")"
- // override def isNullable: Boolean = value.value eq null
- // override def isNonNull: Boolean = value.value ne null
override def kind = "ConstantType"
}
@@ -2064,7 +2037,7 @@ trait Types extends api.Types { self: SymbolTable =>
// it later turns out not to have kind *. See SI-4070. Only
// logging it for now.
if (sym.typeParams.size != args.size)
- log("!!! %s.transform(%s), but tparams.isEmpty and args=".format(this, tp, args))
+ devWarning(s"$this.transform($tp), but tparams.isEmpty and args=$args")
asSeenFromOwner(tp).instantiateTypeParams(sym.typeParams, args)
}
@@ -2296,7 +2269,6 @@ trait Types extends api.Types { self: SymbolTable =>
}
override def isStable = bounds.hi.typeSymbol isSubClass SingletonClass
override def bounds = thisInfo.bounds
- // def transformInfo(tp: Type): Type = appliedType(tp.asSeenFrom(pre, sym.owner), typeArgsOrDummies)
override protected[Types] def baseTypeSeqImpl: BaseTypeSeq = transform(bounds.hi).baseTypeSeq prepend this
override def kind = "AbstractTypeRef"
}
@@ -2833,9 +2805,13 @@ trait Types extends api.Types { self: SymbolTable =>
override def kind = "OverloadedType"
}
- def overloadedType(pre: Type, alternatives: List[Symbol]): Type =
- if (alternatives.tail.isEmpty) pre memberType alternatives.head
- else OverloadedType(pre, alternatives)
+ /** The canonical creator for OverloadedTypes.
+ */
+ def overloadedType(pre: Type, alternatives: List[Symbol]): Type = alternatives match {
+ case Nil => NoType
+ case alt :: Nil => pre memberType alt
+ case _ => OverloadedType(pre, alternatives)
+ }
/** A class remembering a type instantiation for some a set of overloaded
* polymorphic symbols.
@@ -2845,21 +2821,9 @@ trait Types extends api.Types { self: SymbolTable =>
override def safeToString =
pre.toString + targs.mkString("(with type arguments ", ", ", ")");
override def memberType(sym: Symbol) = appliedType(pre.memberType(sym), targs)
-// override def memberType(sym: Symbol) = pre.memberType(sym) match {
-// case PolyType(tparams, restp) =>
-// restp.subst(tparams, targs)
-// /* I don't think this is needed, as existential types close only over value types
-// case ExistentialType(tparams, qtpe) =>
-// existentialAbstraction(tparams, qtpe.memberType(sym))
-// */
-// case ErrorType =>
-// ErrorType
-// }
override def kind = "AntiPolyType"
}
- //private var tidCount = 0 //DEBUG
-
object HasTypeMember {
def apply(name: TypeName, tp: Type): Type = {
val bound = refinedType(List(WildcardType), NoSymbol)
@@ -2874,16 +2838,6 @@ trait Types extends api.Types { self: SymbolTable =>
}
}
- // Not used yet.
- object HasTypeParams {
- def unapply(tp: Type): Option[(List[Symbol], Type)] = tp match {
- case AnnotatedType(_, tp, _) => unapply(tp)
- case ExistentialType(tparams, qtpe) => Some((tparams, qtpe))
- case PolyType(tparams, restpe) => Some((tparams, restpe))
- case _ => None
- }
- }
-
//@M
// a TypeVar used to be a case class with only an origin and a constr
// then, constr became mutable (to support UndoLog, I guess),
@@ -2977,7 +2931,6 @@ trait Types extends api.Types { self: SymbolTable =>
require(params.nonEmpty, this)
override def isHigherKinded = true
- override protected def typeVarString = params.map(_.name).mkString("[", ", ", "]=>" + originName)
}
/** Precondition: zipped params/args nonEmpty. (Size equivalence enforced structurally.)
@@ -2992,10 +2945,6 @@ trait Types extends api.Types { self: SymbolTable =>
override def params: List[Symbol] = zippedArgs map (_._1)
override def typeArgs: List[Type] = zippedArgs map (_._2)
-
- override protected def typeVarString = (
- zippedArgs map { case (p, a) => p.name + "=" + a } mkString (origin + "[", ", ", "]")
- )
}
trait UntouchableTypeVar extends TypeVar {
@@ -3039,7 +2988,6 @@ trait Types extends api.Types { self: SymbolTable =>
* in operations that are exposed from types. Hence, no syncing of `constr`
* or `encounteredHigherLevel` or `suspended` accesses should be necessary.
*/
-// var constr = constr0
def instValid = constr.instValid
override def isGround = instValid && constr.inst.isGround
@@ -3092,7 +3040,10 @@ trait Types extends api.Types { self: SymbolTable =>
// invariant: before mutating constr, save old state in undoLog
// (undoLog is used to reset constraints to avoid piling up unrelated ones)
def setInst(tp: Type) {
-// assert(!(tp containsTp this), this)
+ if (tp eq this) {
+ log(s"TypeVar cycle: called setInst passing $this to itself.")
+ return
+ }
undoLog record this
// if we were compared against later typeskolems, repack the existential,
// because skolems are only compatible if they were created at the same level
@@ -3237,16 +3188,19 @@ trait Types extends api.Types { self: SymbolTable =>
def registerTypeEquality(tp: Type, typeVarLHS: Boolean): Boolean = {
// println("regTypeEq: "+(safeToString, debugString(tp), tp.getClass, if (typeVarLHS) "in LHS" else "in RHS", if (suspended) "ZZ" else if (constr.instValid) "IV" else "")) //@MDEBUG
-// println("constr: "+ constr)
- def checkIsSameType(tp: Type) =
- if(typeVarLHS) constr.inst =:= tp
- else tp =:= constr.inst
+ def checkIsSameType(tp: Type) = (
+ if (typeVarLHS) constr.inst =:= tp
+ else tp =:= constr.inst
+ )
if (suspended) tp =:= origin
else if (constr.instValid) checkIsSameType(tp)
else isRelatable(tp) && {
val newInst = wildcardToTypeVarMap(tp)
- (constr isWithinBounds newInst) && { setInst(tp); true }
+ (constr isWithinBounds newInst) && {
+ setInst(newInst)
+ true
+ }
}
}
@@ -3309,7 +3263,6 @@ trait Types extends api.Types { self: SymbolTable =>
).flatten map (s => s.decodedName + tparamsOfSym(s)) mkString "#"
}
private def levelString = if (settings.explaintypes.value) level else ""
- protected def typeVarString = originName
override def safeToString = (
if ((constr eq null) || (constr.inst eq null)) "TVar<" + originName + "=null>"
else if (constr.inst ne NoType) "=?" + constr.inst
@@ -3420,22 +3373,12 @@ trait Types extends api.Types { self: SymbolTable =>
case class NamedType(name: Name, tp: Type) extends Type {
override def safeToString: String = name.toString +": "+ tp
}
-
- /** A De Bruijn index referring to a previous type argument. Only used
- * as a serialization format.
- */
- case class DeBruijnIndex(level: Int, idx: Int, args: List[Type]) extends Type {
- override def safeToString: String = "De Bruijn index("+level+","+idx+")"
- }
-
- /** A binder defining data associated with De Bruijn indices. Only used
- * as a serialization format.
+ /** As with NamedType, used only when calling isApplicable.
+ * Records that the application has a wildcard star (aka _*)
+ * at the end of it.
*/
- case class DeBruijnBinder(pnames: List[Name], ptypes: List[Type], restpe: Type) extends Type {
- override def safeToString = {
- val kind = if (pnames.head.isTypeName) "poly" else "method"
- "De Bruijn "+kind+"("+(pnames mkString ",")+";"+(ptypes mkString ",")+";"+restpe+")"
- }
+ case class RepeatedType(tp: Type) extends Type {
+ override def safeToString: String = tp + ": _*"
}
/** A temporary type representing the erasure of a user-defined value type.
@@ -3480,11 +3423,6 @@ trait Types extends api.Types { self: SymbolTable =>
(if (typeParams.isEmpty) "" else typeParamsString(this)) + super.safeToString
}
- // def mkLazyType(tparams: Symbol*)(f: Symbol => Unit): LazyType = (
- // if (tparams.isEmpty) new LazyType { override def complete(sym: Symbol) = f(sym) }
- // else new LazyPolyType(tparams.toList) { override def complete(sym: Symbol) = f(sym) }
- // )
-
// Creators ---------------------------------------------------------------
/** Rebind symbol `sym` to an overriding member in type `pre`. */
@@ -3529,10 +3467,6 @@ trait Types extends api.Types { self: SymbolTable =>
}
/** The canonical creator for a refined type with an initially empty scope.
- *
- * @param parents ...
- * @param owner ...
- * @return ...
*/
def refinedType(parents: List[Type], owner: Symbol): Type =
refinedType(parents, owner, newScope, owner.pos)
@@ -3571,12 +3505,6 @@ trait Types extends api.Types { self: SymbolTable =>
val pre1 = pre match {
case x: SuperType if sym1.isEffectivelyFinal || sym1.isDeferred =>
x.thistpe
- case _: CompoundType if sym1.isClass =>
- // sharpen prefix so that it is maximal and still contains the class.
- pre.parents.reverse dropWhile (_.member(sym1.name) != sym1) match {
- case Nil => pre
- case parent :: _ => parent
- }
case _ => pre
}
if (pre eq pre1) TypeRef(pre, sym1, args)
@@ -3658,16 +3586,16 @@ trait Types extends api.Types { self: SymbolTable =>
tycon match {
case TypeRef(pre, sym @ (NothingClass|AnyClass), _) => copyTypeRef(tycon, pre, sym, Nil) //@M drop type args to Any/Nothing
- case TypeRef(pre, sym, _) => copyTypeRef(tycon, pre, sym, args)
+ case TypeRef(pre, sym, Nil) => copyTypeRef(tycon, pre, sym, args)
+ case TypeRef(pre, sym, bogons) => devWarning(s"Dropping $bogons from $tycon in appliedType.") ; copyTypeRef(tycon, pre, sym, args)
case PolyType(tparams, restpe) => restpe.instantiateTypeParams(tparams, args)
case ExistentialType(tparams, restpe) => newExistentialType(tparams, appliedType(restpe, args))
case st: SingletonType => appliedType(st.widen, args) // @M TODO: what to do? see bug1
- case RefinedType(parents, decls) => RefinedType(parents map (appliedType(_, args)), decls) // MO to AM: please check
- case TypeBounds(lo, hi) => TypeBounds(appliedType(lo, args), appliedType(hi, args))
+ case RefinedType(parents, decls) => RefinedType(parents map (appliedType(_, args)), decls) // @PP: Can this be right?
+ case TypeBounds(lo, hi) => TypeBounds(appliedType(lo, args), appliedType(hi, args)) // @PP: Can this be right?
case tv@TypeVar(_, _) => tv.applyArgs(args)
case AnnotatedType(annots, underlying, self) => AnnotatedType(annots, appliedType(underlying, args), self)
- case ErrorType => tycon
- case WildcardType => tycon // needed for neg/t0226
+ case ErrorType | WildcardType => tycon
case _ => abort(debugString(tycon))
}
}
@@ -3676,25 +3604,6 @@ trait Types extends api.Types { self: SymbolTable =>
def appliedType(tyconSym: Symbol, args: Type*): Type =
appliedType(tyconSym.typeConstructor, args.toList)
- /** A creator for existential types where the type arguments,
- * rather than being applied directly, are interpreted as the
- * upper bounds of unknown types. For instance if the type argument
- * list given is List(AnyRefClass), the resulting type would be
- * e.g. Set[_ <: AnyRef] rather than Set[AnyRef] .
- */
- def appliedTypeAsUpperBounds(tycon: Type, args: List[Type]): Type = {
- tycon match {
- case TypeRef(pre, sym, _) if sameLength(sym.typeParams, args) =>
- val eparams = typeParamsToExistentials(sym)
- val bounds = args map (TypeBounds upper _)
- foreach2(eparams, bounds)(_ setInfo _)
-
- newExistentialType(eparams, typeRef(pre, sym, eparams map (_.tpe)))
- case _ =>
- appliedType(tycon, args)
- }
- }
-
/** A creator and extractor for type parameterizations that strips empty type parameter lists.
* Use this factory method to indicate the type has kind * (it's a polymorphic value)
* until we start tracking explicit kinds equivalent to typeFun (except that the latter requires tparams nonEmpty).
@@ -3796,18 +3705,6 @@ trait Types extends api.Types { self: SymbolTable =>
}
}
- /** Substitutes the empty scope for any non-empty decls in the type. */
- object dropAllRefinements extends TypeMap {
- def apply(tp: Type): Type = tp match {
- case rt @ RefinedType(parents, decls) if !decls.isEmpty =>
- mapOver(copyRefinedType(rt, parents, EmptyScope))
- case ClassInfoType(parents, decls, clazz) if !decls.isEmpty =>
- mapOver(ClassInfoType(parents, EmptyScope, clazz))
- case _ =>
- mapOver(tp)
- }
- }
-
/** Type with all top-level occurrences of abstract types replaced by their bounds */
def abstractTypesToBounds(tp: Type): Type = tp match { // @M don't normalize here (compiler loops on pos/bug1090.scala )
case TypeRef(_, sym, _) if sym.isAbstractType =>
@@ -3830,12 +3727,16 @@ trait Types extends api.Types { self: SymbolTable =>
// This is the specified behavior.
protected def etaExpandKeepsStar = false
- object dropRepeatedParamType extends TypeMap {
+ /** Turn any T* types into Seq[T] except when
+ * in method parameter position.
+ */
+ object dropIllegalStarTypes extends TypeMap {
def apply(tp: Type): Type = tp match {
case MethodType(params, restpe) =>
- MethodType(params, apply(restpe))
- case PolyType(tparams, restpe) =>
- PolyType(tparams, apply(restpe))
+ // Not mapping over params
+ val restpe1 = apply(restpe)
+ if (restpe eq restpe1) tp
+ else MethodType(params, restpe1)
case TypeRef(_, RepeatedParamClass, arg :: Nil) =>
seqType(arg)
case _ =>
@@ -3843,50 +3744,6 @@ trait Types extends api.Types { self: SymbolTable =>
}
}
- object toDeBruijn extends TypeMap {
- private var paramStack: List[List[Symbol]] = Nil
- def mkDebruijnBinder(params: List[Symbol], restpe: Type) = {
- paramStack = params :: paramStack
- try {
- DeBruijnBinder(params map (_.name), params map (p => this(p.info)), this(restpe))
- } finally paramStack = paramStack.tail
- }
- def apply(tp: Type): Type = tp match {
- case PolyType(tparams, restpe) =>
- mkDebruijnBinder(tparams, restpe)
- case MethodType(params, restpe) =>
- mkDebruijnBinder(params, restpe)
- case TypeRef(NoPrefix, sym, args) =>
- val level = paramStack indexWhere (_ contains sym)
- if (level < 0) mapOver(tp)
- else DeBruijnIndex(level, paramStack(level) indexOf sym, args mapConserve this)
- case _ =>
- mapOver(tp)
- }
- }
-
- def fromDeBruijn(owner: Symbol) = new TypeMap {
- private var paramStack: List[List[Symbol]] = Nil
- def apply(tp: Type): Type = tp match {
- case DeBruijnBinder(pnames, ptypes, restpe) =>
- val isType = pnames.head.isTypeName
- val newParams = for (name <- pnames) yield
- if (isType) owner.newTypeParameter(name.toTypeName)
- else owner.newValueParameter(name.toTermName)
- paramStack = newParams :: paramStack
- try {
- foreach2(newParams, ptypes)((p, t) => p setInfo this(t))
- val restpe1 = this(restpe)
- if (isType) PolyType(newParams, restpe1)
- else MethodType(newParams, restpe1)
- } finally paramStack = paramStack.tail
- case DeBruijnIndex(level, idx, args) =>
- TypeRef(NoPrefix, paramStack(level)(idx), args map this)
- case _ =>
- mapOver(tp)
- }
- }
-
// Hash consing --------------------------------------------------------------
private val initialUniquesCapacity = 4096
@@ -4092,7 +3949,7 @@ trait Types extends api.Types { self: SymbolTable =>
variance = -variance
val tparams1 = mapOver(tparams)
variance = -variance
- var result1 = this(result)
+ val result1 = this(result)
if ((tparams1 eq tparams) && (result1 eq result)) tp
else PolyType(tparams1, result1.substSym(tparams, tparams1))
case TypeBounds(lo, hi) =>
@@ -4154,7 +4011,7 @@ trait Types extends api.Types { self: SymbolTable =>
else copyMethodType(tp, params1, result1.substSym(params, params1))
case PolyType(tparams, result) =>
val tparams1 = mapOver(tparams)
- var result1 = this(result)
+ val result1 = this(result)
if ((tparams1 eq tparams) && (result1 eq result)) tp
else PolyType(tparams1, result1.substSym(tparams, tparams1))
case NullaryMethodType(result) =>
@@ -4179,12 +4036,10 @@ trait Types extends api.Types { self: SymbolTable =>
case rtp @ RefinedType(parents, decls) =>
val parents1 = parents mapConserve this
val decls1 = mapOver(decls)
- //if ((parents1 eq parents) && (decls1 eq decls)) tp
- //else refinementOfClass(tp.typeSymbol, parents1, decls1)
copyRefinedType(rtp, parents1, decls1)
case ExistentialType(tparams, result) =>
val tparams1 = mapOver(tparams)
- var result1 = this(result)
+ val result1 = this(result)
if ((tparams1 eq tparams) && (result1 eq result)) tp
else newExistentialType(tparams1, result1.substSym(tparams, tparams1))
case OverloadedType(pre, alts) =>
@@ -4209,10 +4064,6 @@ trait Types extends api.Types { self: SymbolTable =>
if ((annots1 eq annots) && (atp1 eq atp)) tp
else if (annots1.isEmpty) atp1
else AnnotatedType(annots1, atp1, selfsym)
- case DeBruijnIndex(shift, idx, args) =>
- val args1 = args mapConserve this
- if (args1 eq args) tp
- else DeBruijnIndex(shift, idx, args1)
/*
case ErrorType => tp
case WildcardType => tp
@@ -4319,21 +4170,6 @@ trait Types extends api.Types { self: SymbolTable =>
}
}
- /** A collector that tests for existential types appearing at given variance in a type
- * @PP: Commenting out due to not being used anywhere.
- */
- // class ContainsVariantExistentialCollector(v: Int) extends TypeCollector(false) with VariantTypeMap {
- // variance = v
- //
- // def traverse(tp: Type) = tp match {
- // case ExistentialType(_, _) if (variance == v) => result = true
- // case _ => mapOver(tp)
- // }
- // }
- //
- // val containsCovariantExistentialCollector = new ContainsVariantExistentialCollector(1)
- // val containsContravariantExistentialCollector = new ContainsVariantExistentialCollector(-1)
-
def typeParamsToExistentials(clazz: Symbol, tparams: List[Symbol]): List[Symbol] = {
val eparams = mapWithIndex(tparams)((tparam, i) =>
clazz.newExistential(newTypeName("?"+i), clazz.pos) setInfo tparam.info.bounds)
@@ -4381,6 +4217,20 @@ trait Types extends api.Types { self: SymbolTable =>
mapOver(tp)
}
}
+ /***
+ *@M: I think this is more desirable, but Martin prefers to leave raw-types as-is as much as possible
+ object rawToExistentialInJava extends TypeMap {
+ def apply(tp: Type): Type = tp match {
+ // any symbol that occurs in a java sig, not just java symbols
+ // see http://lampsvn.epfl.ch/trac/scala/ticket/2454#comment:14
+ case TypeRef(pre, sym, List()) if !sym.typeParams.isEmpty =>
+ val eparams = typeParamsToExistentials(sym, sym.typeParams)
+ existentialAbstraction(eparams, TypeRef(pre, sym, eparams map (_.tpe)))
+ case _ =>
+ mapOver(tp)
+ }
+ }
+ */
/** Used by existentialAbstraction.
*/
@@ -4615,16 +4465,18 @@ trait Types extends api.Types { self: SymbolTable =>
tp
}
- def apply(tp0: Type): Type = if (from.isEmpty) tp0 else {
- @tailrec def subst(tp: Type, sym: Symbol, from: List[Symbol], to: List[T]): Type =
- if (from.isEmpty) tp
- // else if (to.isEmpty) error("Unexpected substitution on '%s': from = %s but to == Nil".format(tp, from))
- else if (matches(from.head, sym)) toType(tp, to.head)
- else subst(tp, sym, from.tail, to.tail)
+ @tailrec private def subst(tp: Type, sym: Symbol, from: List[Symbol], to: List[T]): Type = (
+ if (from.isEmpty) tp
+ // else if (to.isEmpty) error("Unexpected substitution on '%s': from = %s but to == Nil".format(tp, from))
+ else if (matches(from.head, sym)) toType(tp, to.head)
+ else subst(tp, sym, from.tail, to.tail)
+ )
- val boundSyms = tp0.boundSyms
- val tp1 = if (boundSyms.nonEmpty && (boundSyms exists from.contains)) renameBoundSyms(tp0) else tp0
- val tp = mapOver(tp1)
+ def apply(tp0: Type): Type = if (from.isEmpty) tp0 else {
+ val boundSyms = tp0.boundSyms
+ val tp1 = if (boundSyms.nonEmpty && (boundSyms exists from.contains)) renameBoundSyms(tp0) else tp0
+ val tp = mapOver(tp1)
+ def substFor(sym: Symbol) = subst(tp, sym, from, to)
tp match {
// @M
@@ -4639,9 +4491,11 @@ trait Types extends api.Types { self: SymbolTable =>
// (must not recurse --> loops)
// 3) replacing m by List in m[Int] should yield List[Int], not just List
case TypeRef(NoPrefix, sym, args) =>
- appliedType(subst(tp, sym, from, to), args) // if args.isEmpty, appliedType is the identity
+ val tcon = substFor(sym)
+ if ((tp eq tcon) || args.isEmpty) tcon
+ else appliedType(tcon.typeConstructor, args)
case SingleType(NoPrefix, sym) =>
- subst(tp, sym, from, to)
+ substFor(sym)
case _ =>
tp
}
@@ -4650,29 +4504,35 @@ trait Types extends api.Types { self: SymbolTable =>
/** A map to implement the `substSym` method. */
class SubstSymMap(from: List[Symbol], to: List[Symbol]) extends SubstMap(from, to) {
+ def this(pairs: (Symbol, Symbol)*) = this(pairs.toList.map(_._1), pairs.toList.map(_._2))
+
protected def toType(fromtp: Type, sym: Symbol) = fromtp match {
case TypeRef(pre, _, args) => copyTypeRef(fromtp, pre, sym, args)
case SingleType(pre, _) => singleType(pre, sym)
}
- override def apply(tp: Type): Type = if (from.isEmpty) tp else {
- @tailrec def subst(sym: Symbol, from: List[Symbol], to: List[Symbol]): Symbol =
- if (from.isEmpty) sym
- // else if (to.isEmpty) error("Unexpected substitution on '%s': from = %s but to == Nil".format(sym, from))
- else if (matches(from.head, sym)) to.head
- else subst(sym, from.tail, to.tail)
- tp match {
+ @tailrec private def subst(sym: Symbol, from: List[Symbol], to: List[Symbol]): Symbol = (
+ if (from.isEmpty) sym
+ // else if (to.isEmpty) error("Unexpected substitution on '%s': from = %s but to == Nil".format(sym, from))
+ else if (matches(from.head, sym)) to.head
+ else subst(sym, from.tail, to.tail)
+ )
+ private def substFor(sym: Symbol) = subst(sym, from, to)
+
+ override def apply(tp: Type): Type = (
+ if (from.isEmpty) tp
+ else tp match {
case TypeRef(pre, sym, args) if pre ne NoPrefix =>
- val newSym = subst(sym, from, to)
+ val newSym = substFor(sym)
// mapOver takes care of subst'ing in args
mapOver ( if (sym eq newSym) tp else copyTypeRef(tp, pre, newSym, args) )
// assert(newSym.typeParams.length == sym.typeParams.length, "typars mismatch in SubstSymMap: "+(sym, sym.typeParams, newSym, newSym.typeParams))
case SingleType(pre, sym) if pre ne NoPrefix =>
- val newSym = subst(sym, from, to)
+ val newSym = substFor(sym)
mapOver( if (sym eq newSym) tp else singleType(pre, newSym) )
case _ =>
super.apply(tp)
}
- }
+ )
override def mapOver(tree: Tree, giveup: ()=>Nothing): Tree = {
object trans extends TypeMapTransformer {
@@ -4843,15 +4703,6 @@ trait Types extends api.Types { self: SymbolTable =>
}
}
- object StripAnnotationsMap extends TypeMap {
- def apply(tp: Type): Type = tp match {
- case AnnotatedType(_, atp, _) =>
- mapOver(atp)
- case tp =>
- mapOver(tp)
- }
- }
-
/** A map to convert every occurrence of a wildcard type to a fresh
* type variable */
object wildcardToTypeVarMap extends TypeMap {
@@ -4913,8 +4764,6 @@ trait Types extends api.Types { self: SymbolTable =>
/** A map to implement the `filter` method. */
class FilterTypeCollector(p: Type => Boolean) extends TypeCollector[List[Type]](Nil) {
- def withFilter(q: Type => Boolean) = new FilterTypeCollector(tp => p(tp) && q(tp))
-
override def collect(tp: Type) = super.collect(tp).reverse
def traverse(tp: Type) {
@@ -5024,7 +4873,7 @@ trait Types extends api.Types { self: SymbolTable =>
else {
var rebind0 = pre.findMember(sym.name, BRIDGE, 0, true) orElse {
if (sym.isAliasType) throw missingAliasException
- debugwarn(pre+"."+sym+" does no longer exist, phase = "+phase)
+ devWarning(s"$pre.$sym no longer exist at phase $phase")
throw new MissingTypeControl // For build manager and presentation compiler purposes
}
/** The two symbols have the same fully qualified name */
@@ -5082,7 +4931,7 @@ trait Types extends api.Types { self: SymbolTable =>
if ((pre1 eq pre) && (sym1 eq sym) && (args1 eq args)/* && sym.isExternal*/) {
tp
} else if (sym1 == NoSymbol) {
- debugwarn("adapt fail: "+pre+" "+pre1+" "+sym)
+ devWarning(s"adapt to new run failed: pre=$pre pre1=$pre1 sym=$sym")
tp
} else {
copyTypeRef(tp, pre1, sym1, args1)
@@ -5133,28 +4982,18 @@ trait Types extends api.Types { self: SymbolTable =>
class SubTypePair(val tp1: Type, val tp2: Type) {
override def hashCode = tp1.hashCode * 41 + tp2.hashCode
- override def equals(other: Any) = other match {
+ override def equals(other: Any) = (this eq other.asInstanceOf[AnyRef]) || (other match {
+ // suspend TypeVars in types compared by =:=,
+ // since we don't want to mutate them simply to check whether a subtype test is pending
+ // in addition to making subtyping "more correct" for type vars,
+ // it should avoid the stackoverflow that's been plaguing us (https://groups.google.com/d/topic/scala-internals/2gHzNjtB4xA/discussion)
+ // this method is only called when subtyping hits a recursion threshold (subsametypeRecursions >= LogPendingSubTypesThreshold)
case stp: SubTypePair =>
- // suspend TypeVars in types compared by =:=,
- // since we don't want to mutate them simply to check whether a subtype test is pending
- // in addition to making subtyping "more correct" for type vars,
- // it should avoid the stackoverflow that's been plaguing us (https://groups.google.com/d/topic/scala-internals/2gHzNjtB4xA/discussion)
- // this method is only called when subtyping hits a recursion threshold (subsametypeRecursions >= LogPendingSubTypesThreshold)
- def suspend(tp: Type) =
- if (tp.isGround) null else suspendTypeVarsInType(tp)
- def revive(suspension: List[TypeVar]) =
- if (suspension ne null) suspension foreach (_.suspended = false)
-
- val suspensions = Array(tp1, stp.tp1, tp2, stp.tp2) map suspend
-
- val sameTypes = (tp1 =:= stp.tp1) && (tp2 =:= stp.tp2)
-
- suspensions foreach revive
-
- sameTypes
+ val tvars = List(tp1, stp.tp1, tp2, stp.tp2) flatMap (t => if (t.isGround) Nil else typeVarsInType(t))
+ suspendingTypeVars(tvars)(tp1 =:= stp.tp1 && tp2 =:= stp.tp2)
case _ =>
false
- }
+ })
override def toString = tp1+" <:<? "+tp2
}
@@ -5226,32 +5065,33 @@ trait Types extends api.Types { self: SymbolTable =>
def isPopulated(tp1: Type, tp2: Type): Boolean = {
def isConsistent(tp1: Type, tp2: Type): Boolean = (tp1, tp2) match {
case (TypeRef(pre1, sym1, args1), TypeRef(pre2, sym2, args2)) =>
- assert(sym1 == sym2)
+ assert(sym1 == sym2, (sym1, sym2))
pre1 =:= pre2 &&
- forall3(args1, args2, sym1.typeParams) { (arg1, arg2, tparam) =>
- //if (tparam.variance == 0 && !(arg1 =:= arg2)) Console.println("inconsistent: "+arg1+"!="+arg2)//DEBUG
+ forall3(args1, args2, sym1.typeParams)((arg1, arg2, tparam) =>
if (tparam.variance == 0) arg1 =:= arg2
- else if (arg1.isInstanceOf[TypeVar])
- // if left-hand argument is a typevar, make it compatible with variance
- // this is for more precise pattern matching
- // todo: work this in the spec of this method
- // also: think what happens if there are embedded typevars?
- if (tparam.variance < 0) arg1 <:< arg2 else arg2 <:< arg1
- else true
- }
+ // if left-hand argument is a typevar, make it compatible with variance
+ // this is for more precise pattern matching
+ // todo: work this in the spec of this method
+ // also: think what happens if there are embedded typevars?
+ else arg1 match {
+ case _: TypeVar => if (tparam.variance < 0) arg1 <:< arg2 else arg2 <:< arg1
+ case _ => true
+ }
+ )
case (et: ExistentialType, _) =>
et.withTypeVars(isConsistent(_, tp2))
case (_, et: ExistentialType) =>
et.withTypeVars(isConsistent(tp1, _))
}
- def check(tp1: Type, tp2: Type) =
+ def check(tp1: Type, tp2: Type) = (
if (tp1.typeSymbol.isClass && tp1.typeSymbol.hasFlag(FINAL))
tp1 <:< tp2 || isNumericValueClass(tp1.typeSymbol) && isNumericValueClass(tp2.typeSymbol)
else tp1.baseClasses forall (bc =>
tp2.baseTypeIndex(bc) < 0 || isConsistent(tp1.baseType(bc), tp2.baseType(bc)))
+ )
- check(tp1, tp2)/* && check(tp2, tp1)*/ // need to investgate why this can't be made symmetric -- neg/gadts1 fails, and run/existials also.
+ check(tp1, tp2) && check(tp2, tp1)
}
/** Does a pattern of type `patType` need an outer test when executed against
@@ -5334,13 +5174,15 @@ trait Types extends api.Types { self: SymbolTable =>
try {
val before = undoLog.log
var result = false
-
- try result = {
- isSameType1(tp1, tp2)
- } finally if (!result) undoLog.undoTo(before)
+ try {
+ result = isSameType1(tp1, tp2)
+ }
+ finally if (!result) undoLog.undoTo(before)
result
- } finally undoLog.unlock()
- } finally {
+ }
+ finally undoLog.unlock()
+ }
+ finally {
subsametypeRecursions -= 1
// XXX AM TODO: figure out when it is safe and needed to clear the log -- the commented approach below is too eager (it breaks #3281, #3866)
// it doesn't help to keep separate recursion counts for the three methods that now share it
@@ -5382,108 +5224,7 @@ trait Types extends api.Types { self: SymbolTable =>
case _ => tp.normalize
}
*/
-/*
- private def isSameType0(tp1: Type, tp2: Type): Boolean = {
- if (tp1 eq tp2) return true
- ((tp1, tp2) match {
- case (ErrorType, _) => true
- case (WildcardType, _) => true
- case (_, ErrorType) => true
- case (_, WildcardType) => true
-
- case (NoType, _) => false
- case (NoPrefix, _) => tp2.typeSymbol.isPackageClass
- case (_, NoType) => false
- case (_, NoPrefix) => tp1.typeSymbol.isPackageClass
-
- case (ThisType(sym1), ThisType(sym2))
- if (sym1 == sym2) =>
- true
- case (SingleType(pre1, sym1), SingleType(pre2, sym2))
- if (equalSymsAndPrefixes(sym1, pre1, sym2, pre2)) =>
- true
-/*
- case (SingleType(pre1, sym1), ThisType(sym2))
- if (sym1.isModule &&
- sym1.moduleClass == sym2 &&
- pre1 =:= sym2.owner.thisType) =>
- true
- case (ThisType(sym1), SingleType(pre2, sym2))
- if (sym2.isModule &&
- sym2.moduleClass == sym1 &&
- pre2 =:= sym1.owner.thisType) =>
- true
-*/
- case (ConstantType(value1), ConstantType(value2)) =>
- value1 == value2
- case (TypeRef(pre1, sym1, args1), TypeRef(pre2, sym2, args2)) =>
- equalSymsAndPrefixes(sym1, pre1, sym2, pre2) &&
- ((tp1.isHigherKinded && tp2.isHigherKinded && tp1.normalize =:= tp2.normalize) ||
- isSameTypes(args1, args2))
- // @M! normalize reduces higher-kinded case to PolyType's
- case (RefinedType(parents1, ref1), RefinedType(parents2, ref2)) =>
- def isSubScope(s1: Scope, s2: Scope): Boolean = s2.toList.forall {
- sym2 =>
- var e1 = s1.lookupEntry(sym2.name)
- (e1 ne null) && {
- val substSym = sym2.info.substThis(sym2.owner, e1.sym.owner.thisType)
- var isEqual = false
- while (!isEqual && (e1 ne null)) {
- isEqual = e1.sym.info =:= substSym
- e1 = s1.lookupNextEntry(e1)
- }
- isEqual
- }
- }
- //Console.println("is same? " + tp1 + " " + tp2 + " " + tp1.typeSymbol.owner + " " + tp2.typeSymbol.owner)//DEBUG
- isSameTypes(parents1, parents2) && isSubScope(ref1, ref2) && isSubScope(ref2, ref1)
- case (MethodType(params1, res1), MethodType(params2, res2)) =>
- // new dependent types: probably fix this, use substSym as done for PolyType
- (isSameTypes(tp1.paramTypes, tp2.paramTypes) &&
- res1 =:= res2 &&
- tp1.isImplicit == tp2.isImplicit)
- case (PolyType(tparams1, res1), PolyType(tparams2, res2)) =>
- // assert((tparams1 map (_.typeParams.length)) == (tparams2 map (_.typeParams.length)))
- (tparams1.length == tparams2.length) && (tparams1 corresponds tparams2)(_.info =:= _.info.substSym(tparams2, tparams1)) && // @M looks like it might suffer from same problem as #2210
- res1 =:= res2.substSym(tparams2, tparams1)
- case (ExistentialType(tparams1, res1), ExistentialType(tparams2, res2)) =>
- (tparams1.length == tparams2.length) && (tparams1 corresponds tparams2)(_.info =:= _.info.substSym(tparams2, tparams1)) && // @M looks like it might suffer from same problem as #2210
- res1 =:= res2.substSym(tparams2, tparams1)
- case (TypeBounds(lo1, hi1), TypeBounds(lo2, hi2)) =>
- lo1 =:= lo2 && hi1 =:= hi2
- case (BoundedWildcardType(bounds), _) =>
- bounds containsType tp2
- case (_, BoundedWildcardType(bounds)) =>
- bounds containsType tp1
- case (tv @ TypeVar(_,_), tp) =>
- tv.registerTypeEquality(tp, true)
- case (tp, tv @ TypeVar(_,_)) =>
- tv.registerTypeEquality(tp, false)
- case (AnnotatedType(_,_,_), _) =>
- annotationsConform(tp1, tp2) && annotationsConform(tp2, tp1) && tp1.withoutAnnotations =:= tp2.withoutAnnotations
- case (_, AnnotatedType(_,_,_)) =>
- annotationsConform(tp1, tp2) && annotationsConform(tp2, tp1) && tp1.withoutAnnotations =:= tp2.withoutAnnotations
- case (_: SingletonType, _: SingletonType) =>
- var origin1 = tp1
- while (origin1.underlying.isInstanceOf[SingletonType]) {
- assert(origin1 ne origin1.underlying, origin1)
- origin1 = origin1.underlying
- }
- var origin2 = tp2
- while (origin2.underlying.isInstanceOf[SingletonType]) {
- assert(origin2 ne origin2.underlying, origin2)
- origin2 = origin2.underlying
- }
- ((origin1 ne tp1) || (origin2 ne tp2)) && (origin1 =:= origin2)
- case _ =>
- false
- }) || {
- val tp1n = normalizePlus(tp1)
- val tp2n = normalizePlus(tp2)
- ((tp1n ne tp1) || (tp2n ne tp2)) && isSameType(tp1n, tp2n)
- }
- }
-*/
+
private def isSameType1(tp1: Type, tp2: Type): Boolean = {
if ((tp1 eq tp2) ||
(tp1 eq ErrorType) || (tp1 eq WildcardType) ||
@@ -5622,12 +5363,12 @@ trait Types extends api.Types { self: SymbolTable =>
}
tp1 match {
case tv @ TypeVar(_,_) =>
- return tv.registerTypeEquality(tp2, true)
+ return tv.registerTypeEquality(tp2, typeVarLHS = true)
case _ =>
}
tp2 match {
case tv @ TypeVar(_,_) =>
- return tv.registerTypeEquality(tp1, false)
+ return tv.registerTypeEquality(tp1, typeVarLHS = false)
case _ =>
}
tp1 match {
@@ -5756,18 +5497,6 @@ trait Types extends api.Types { self: SymbolTable =>
false
}
- @deprecated("The compiler doesn't use this so you shouldn't either - it will be removed", "2.10.0")
- def instTypeVar(tp: Type): Type = tp match {
- case TypeRef(pre, sym, args) =>
- copyTypeRef(tp, instTypeVar(pre), sym, args)
- case SingleType(pre, sym) =>
- singleType(instTypeVar(pre), sym)
- case TypeVar(_, constr) =>
- instTypeVar(constr.inst)
- case _ =>
- tp
- }
-
def isErrorOrWildcard(tp: Type) = (tp eq ErrorType) || (tp eq WildcardType)
def isSingleType(tp: Type) = tp match {
@@ -5805,10 +5534,11 @@ trait Types extends api.Types { self: SymbolTable =>
* types which are used internally in type applications and
* types which are not.
*/
+ /**** Not used right now, but kept around to document which Types
+ * land in which bucket.
private def isInternalTypeNotUsedAsTypeArg(tp: Type): Boolean = tp match {
case AntiPolyType(pre, targs) => true
case ClassInfoType(parents, defs, clazz) => true
- case DeBruijnIndex(level, index, args) => true
case ErasedValueType(tref) => true
case NoPrefix => true
case NoType => true
@@ -5816,6 +5546,7 @@ trait Types extends api.Types { self: SymbolTable =>
case TypeBounds(lo, hi) => true
case _ => false
}
+ ****/
private def isInternalTypeUsedAsTypeArg(tp: Type): Boolean = tp match {
case WildcardType => true
case BoundedWildcardType(_) => true
@@ -5861,7 +5592,7 @@ trait Types extends api.Types { self: SymbolTable =>
* useful as documentation; it is likely that !isNonValueType(tp)
* will serve better than isValueType(tp).
*/
- def isValueType(tp: Type) = isValueElseNonValue(tp)
+ /** def isValueType(tp: Type) = isValueElseNonValue(tp) */
/** SLS 3.3, Non-Value Types
* Is the given type definitely a non-value type, as defined in SLS 3.3?
@@ -5872,7 +5603,7 @@ trait Types extends api.Types { self: SymbolTable =>
* not designated non-value types because there is code which depends on using
* them as type arguments, but their precise status is unclear.
*/
- def isNonValueType(tp: Type) = !isValueElseNonValue(tp)
+ /** def isNonValueType(tp: Type) = !isValueElseNonValue(tp) */
def isNonRefinementClassType(tpe: Type) = tpe match {
case SingleType(_, sym) => sym.isModuleClass
@@ -5921,8 +5652,6 @@ trait Types extends api.Types { self: SymbolTable =>
corresponds3(tps1, tps2, tparams map (_.variance))(isSubArg)
}
- def differentOrNone(tp1: Type, tp2: Type) = if (tp1 eq tp2) NoType else tp1
-
/** Does type `tp1` conform to `tp2`? */
private def isSubType2(tp1: Type, tp2: Type, depth: Int): Boolean = {
if ((tp1 eq tp2) || isErrorOrWildcard(tp1) || isErrorOrWildcard(tp2)) return true
@@ -6126,18 +5855,6 @@ trait Types extends api.Types { self: SymbolTable =>
!(sym isNonBottomSubClass AnyValClass) &&
!(sym isNonBottomSubClass NotNullClass)
- /** Are `tps1` and `tps2` lists of equal length such that all elements
- * of `tps1` conform to corresponding elements of `tps2`?
- */
- def isSubTypes(tps1: List[Type], tps2: List[Type]): Boolean = (tps1 corresponds tps2)(_ <:< _)
-
- /** Does type `tp` implement symbol `sym` with same or
- * stronger type? Exact only if `sym` is a member of some
- * refinement type, otherwise we might return false negatives.
- */
- def specializesSym(tp: Type, sym: Symbol): Boolean =
- specializesSym(tp, sym, AnyDepth)
-
def specializesSym(tp: Type, sym: Symbol, depth: Int): Boolean =
tp.typeSymbol == NothingClass ||
tp.typeSymbol == NullClass && containsNull(sym.owner) || {
@@ -6156,6 +5873,7 @@ trait Types extends api.Types { self: SymbolTable =>
* than member `sym2` of `tp2`?
*/
private def specializesSym(tp1: Type, sym1: Symbol, tp2: Type, sym2: Symbol, depth: Int): Boolean = {
+ require((sym1 ne NoSymbol) && (sym2 ne NoSymbol), ((tp1, sym1, tp2, sym2, depth)))
val info1 = tp1.memberInfo(sym1)
val info2 = tp2.memberInfo(sym2).substThis(tp2.typeSymbol, tp1)
//System.out.println("specializes "+tp1+"."+sym1+":"+info1+sym1.locationString+" AND "+tp2+"."+sym2+":"+info2)//DEBUG
@@ -6470,25 +6188,27 @@ trait Types extends api.Types { self: SymbolTable =>
* @See baseTypeSeq for a definition of sorted and upwards closed.
*/
private def lubList(ts: List[Type], depth: Int): List[Type] = {
- // Matching the type params of one of the initial types means dummies.
- val initialTypeParams = ts map (_.typeParams)
- def isHotForTs(xs: List[Type]) = initialTypeParams contains (xs map (_.typeSymbol))
+ var lubListDepth = 0
+ // This catches some recursive situations which would otherwise
+ // befuddle us, e.g. pos/hklub0.scala
+ def isHotForTs(xs: List[Type]) = ts exists (_.typeParams == xs.map(_.typeSymbol))
def elimHigherOrderTypeParam(tp: Type) = tp match {
- case TypeRef(pre, sym, args) if args.nonEmpty && isHotForTs(args) => tp.typeConstructor
- case _ => tp
+ case TypeRef(_, _, args) if args.nonEmpty && isHotForTs(args) =>
+ logResult("Retracting dummies from " + tp + " in lublist")(tp.typeConstructor)
+ case _ => tp
}
- var lubListDepth = 0
- def loop(tsBts: List[List[Type]]): List[Type] = {
+ // pretypes is a tail-recursion-preserving accumulator.
+ @annotation.tailrec def loop(pretypes: List[Type], tsBts: List[List[Type]]): List[Type] = {
lubListDepth += 1
- if (tsBts.isEmpty || (tsBts exists typeListIsEmpty)) Nil
- else if (tsBts.tail.isEmpty) tsBts.head
+ if (tsBts.isEmpty || (tsBts exists typeListIsEmpty)) pretypes.reverse
+ else if (tsBts.tail.isEmpty) pretypes.reverse ++ tsBts.head
else {
// ts0 is the 1-dimensional frontier of symbols cutting through 2-dimensional tsBts.
// Invariant: all symbols "under" (closer to the first row) the frontier
// are smaller (according to _.isLess) than the ones "on and beyond" the frontier
- val ts0 = tsBts map (_.head)
+ val ts0 = tsBts map (_.head)
// Is the frontier made up of types with the same symbol?
val isUniformFrontier = (ts0: @unchecked) match {
@@ -6501,23 +6221,23 @@ trait Types extends api.Types { self: SymbolTable =>
// merging, strip targs that refer to bound tparams (when we're computing the lub of type
// constructors.) Also filter out all types that are a subtype of some other type.
if (isUniformFrontier) {
- if (settings.debug.value || printLubs) {
- val fbounds = findRecursiveBounds(ts0)
- if (fbounds.nonEmpty) {
- println("Encountered " + fbounds.size + " recursive bounds while lubbing " + ts0.size + " types.")
- for ((p0, p1) <- fbounds) {
- val desc = if (p0 == p1) "its own bounds" else "the bounds of " + p1
-
- println(" " + p0.fullLocationString + " appears in " + desc)
- println(" " + p1 + " " + p1.info.bounds)
+ val fbounds = findRecursiveBounds(ts0) map (_._2)
+ val tcLubList = typeConstructorLubList(ts0)
+ def isRecursive(tp: Type) = tp.typeSymbol.typeParams exists fbounds.contains
+
+ val ts1 = ts0 map { t =>
+ if (isRecursive(t)) {
+ tcLubList map (t baseType _.typeSymbol) find (t => !isRecursive(t)) match {
+ case Some(tp) => logResult(s"Breaking recursion in lublist, substituting weaker type.\n Was: $t\n Now")(tp)
+ case _ => t
}
- println("")
}
+ else t
}
val tails = tsBts map (_.tail)
- mergePrefixAndArgs(elimSub(ts0 map elimHigherOrderTypeParam, depth), 1, depth) match {
- case Some(tp) => tp :: loop(tails)
- case _ => loop(tails)
+ mergePrefixAndArgs(elimSub(ts1, depth) map elimHigherOrderTypeParam, 1, depth) match {
+ case Some(tp) => loop(tp :: pretypes, tails)
+ case _ => loop(pretypes, tails)
}
}
else {
@@ -6534,7 +6254,7 @@ trait Types extends api.Types { self: SymbolTable =>
printLubMatrix((ts zip tsBts).toMap, lubListDepth)
}
- loop(newtps)
+ loop(pretypes, newtps)
}
}
}
@@ -6543,7 +6263,7 @@ trait Types extends api.Types { self: SymbolTable =>
if (printLubs)
printLubMatrix((ts zip initialBTSes).toMap, depth)
- loop(initialBTSes)
+ loop(Nil, initialBTSes)
}
/** The minimal symbol of a list of types (as determined by `Symbol.isLess`). */
@@ -6576,10 +6296,6 @@ trait Types extends api.Types { self: SymbolTable =>
case _ =>
t
}
- def elimRefinement(t: Type) = t match {
- case RefinedType(parents, decls) if !decls.isEmpty => intersectionType(parents)
- case _ => t
- }
/** Eliminate from list of types all elements which are a subtype
* of some other element of the list. */
@@ -6624,28 +6340,12 @@ trait Types extends api.Types { self: SymbolTable =>
(annotationsLub(lub(ts map (_.withoutAnnotations)), ts), true)
else (lub(ts), false)
- def weakGlb(ts: List[Type]) = {
- if (ts.nonEmpty && (ts forall isNumericValueType)) {
- val nglb = numericGlb(ts)
- if (nglb != NoType) (nglb, true)
- else (glb(ts), false)
- } else if (ts exists typeHasAnnotations) {
- (annotationsGlb(glb(ts map (_.withoutAnnotations)), ts), true)
- } else (glb(ts), false)
- }
-
def numericLub(ts: List[Type]) =
ts reduceLeft ((t1, t2) =>
if (isNumericSubType(t1, t2)) t2
else if (isNumericSubType(t2, t1)) t1
else IntClass.tpe)
- def numericGlb(ts: List[Type]) =
- ts reduceLeft ((t1, t2) =>
- if (isNumericSubType(t1, t2)) t1
- else if (isNumericSubType(t2, t1)) t2
- else NoType)
-
def isWeakSubType(tp1: Type, tp2: Type) =
tp1.deconst.normalize match {
case TypeRef(_, sym1, _) if isNumericValueClass(sym1) =>
@@ -6681,6 +6381,23 @@ trait Types extends api.Types { self: SymbolTable =>
private val lubResults = new mutable.HashMap[(Int, List[Type]), Type]
private val glbResults = new mutable.HashMap[(Int, List[Type]), Type]
+ /** Given a list of types, finds all the base classes they have in
+ * common, then returns a list of type constructors derived directly
+ * from the symbols (so any more specific type information is ignored.)
+ * The list is filtered such that every type constructor in the list
+ * expects the same number of type arguments, which is chosen based
+ * on the deepest class among the common baseclasses.
+ */
+ def typeConstructorLubList(ts: List[Type]): List[Type] = {
+ val bcs = ts.flatMap(_.baseClasses).distinct sortWith (_ isLess _)
+ val tcons = bcs filter (clazz => ts forall (_.typeSymbol isSubClass clazz))
+
+ tcons map (_.typeConstructor) match {
+ case Nil => Nil
+ case t :: ts => t :: ts.filter(_.typeParams.size == t.typeParams.size)
+ }
+ }
+
def lub(ts: List[Type]): Type = ts match {
case List() => NothingClass.tpe
case List(t) => t
@@ -6688,8 +6405,20 @@ trait Types extends api.Types { self: SymbolTable =>
if (Statistics.canEnable) Statistics.incCounter(lubCount)
val start = if (Statistics.canEnable) Statistics.pushTimer(typeOpsStack, lubNanos) else null
try {
- lub(ts, lubDepth(ts))
- } finally {
+ val res = lub(ts, lubDepth(ts))
+ // If the number of unapplied type parameters in all incoming
+ // types is consistent, and the lub does not match that, return
+ // the type constructor of the calculated lub instead. This
+ // is because lubbing type constructors tends to result in types
+ // which have been applied to dummies or Nothing.
+ ts.map(_.typeParams.size).distinct match {
+ case x :: Nil if res.typeParams.size != x =>
+ logResult(s"Stripping type args from lub because $res is not consistent with $ts")(res.typeConstructor)
+ case _ =>
+ res
+ }
+ }
+ finally {
lubResults.clear()
glbResults.clear()
if (Statistics.canEnable) Statistics.popTimer(typeOpsStack, start)
@@ -6723,13 +6452,13 @@ trait Types extends api.Types { self: SymbolTable =>
}
}
def lub1(ts0: List[Type]): Type = {
- val (ts, tparams) = stripExistentialsAndTypeVars(ts0)
+ val (ts, tparams) = stripExistentialsAndTypeVars(ts0)
val lubBaseTypes: List[Type] = lubList(ts, depth)
- val lubParents = spanningTypes(lubBaseTypes)
- val lubOwner = commonOwner(ts)
- val lubBase = intersectionType(lubParents, lubOwner)
+ val lubParents = spanningTypes(lubBaseTypes)
+ val lubOwner = commonOwner(ts)
+ val lubBase = intersectionType(lubParents, lubOwner)
val lubType =
- if (phase.erasedTypes || depth == 0) lubBase
+ if (phase.erasedTypes || depth == 0 ) lubBase
else {
val lubRefined = refinedType(lubParents, lubOwner)
val lubThisType = lubRefined.typeSymbol.thisType
@@ -6746,6 +6475,7 @@ trait Types extends api.Types { self: SymbolTable =>
val syms = narrowts map (t =>
t.nonPrivateMember(proto.name).suchThat(sym =>
sym.tpe matches prototp.substThis(lubThisType.typeSymbol, t)))
+
if (syms contains NoSymbol) NoSymbol
else {
val symtypes =
@@ -6772,10 +6502,8 @@ trait Types extends api.Types { self: SymbolTable =>
// add a refinement symbol for all non-class members of lubBase
// which are refined by every type in ts.
for (sym <- lubBase.nonPrivateMembers ; if !excludeFromLub(sym)) {
- try {
- val lsym = lubsym(sym)
- if (lsym != NoSymbol) addMember(lubThisType, lubRefined, lsym, depth)
- } catch {
+ try lubsym(sym) andAlso (addMember(lubThisType, lubRefined, _, depth))
+ catch {
case ex: NoCommonType =>
}
}
@@ -6972,15 +6700,19 @@ trait Types extends api.Types { self: SymbolTable =>
}
tvs.reverse
}
- /** Make each type var in this type use its original type for comparisons instead
- * of collecting constraints.
- */
- def suspendTypeVarsInType(tp: Type): List[TypeVar] = {
- val tvs = typeVarsInType(tp)
- // !!! Is it somehow guaranteed that this will not break under nesting?
- // In general one has to save and restore the contents of the field...
+
+ // If this type contains type variables, put them to sleep for a while.
+ // Don't just wipe them out by replacing them by the corresponding type
+ // parameter, as that messes up (e.g.) type variables in type refinements.
+ // Without this, the matchesType call would lead to type variables on both
+ // sides of a subtyping/equality judgement, which can lead to recursive types
+ // being constructed. See pos/t0851 for a situation where this happens.
+ @inline final def suspendingTypeVars[T](tvs: List[TypeVar])(op: => T): T = {
+ val saved = tvs map (_.suspended)
tvs foreach (_.suspended = true)
- tvs
+
+ try op
+ finally foreach2(tvs, saved)(_.suspended = _)
}
/** Compute lub (if `variance == 1`) or glb (if `variance == -1`) of given list
@@ -7019,18 +6751,16 @@ trait Types extends api.Types { self: SymbolTable =>
debuglog("transposed irregular matrix!?" +(tps, argss))
None
case Some(argsst) =>
- val args = map2(sym.typeParams, argsst) { (tparam, as) =>
- if (depth == 0) {
- if (tparam.variance == variance) {
- // Take the intersection of the upper bounds of the type parameters
- // rather than falling all the way back to "Any", otherwise we end up not
- // conforming to bounds.
- val bounds0 = sym.typeParams map (_.info.bounds.hi) filterNot (_.typeSymbol == AnyClass)
- if (bounds0.isEmpty) AnyClass.tpe
- else intersectionType(bounds0 map (b => b.asSeenFrom(tps.head, sym)))
- }
- else if (tparam.variance == -variance) NothingClass.tpe
- else NoType
+ val args = map2(sym.typeParams, argsst) { (tparam, as0) =>
+ val as = as0.distinct
+ if (as.size == 1) as.head
+ else if (depth == 0) {
+ log("Giving up merging args: can't unify %s under %s".format(as.mkString(", "), tparam.fullLocationString))
+ // Don't return "Any" (or "Nothing") when we have to give up due to
+ // recursion depth. Return NoType, which prevents us from poisoning
+ // lublist's results. It can recognize the recursion and deal with it, but
+ // only if we aren't returning invalid types.
+ NoType
}
else {
if (tparam.variance == variance) lub(as, decr(depth))
@@ -7039,7 +6769,7 @@ trait Types extends api.Types { self: SymbolTable =>
val l = lub(as, decr(depth))
val g = glb(as, decr(depth))
if (l <:< g) l
- else { // Martin: I removed this, because incomplete. Not sure there is a good way to fix it. For the moment we
+ else { // Martin: I removed this, because incomplete. Not sure there is a good way to fix it. For the moment we
// just err on the conservative side, i.e. with a bound that is too high.
// if(!(tparam.info.bounds contains tparam)) //@M can't deal with f-bounds, see #2251
@@ -7087,6 +6817,14 @@ trait Types extends api.Types { self: SymbolTable =>
}
}
+ def isJavaVarargsAncestor(clazz: Symbol) = (
+ clazz.isClass
+ && clazz.isJavaDefined
+ && (clazz.info.nonPrivateDecls exists isJavaVarArgsMethod)
+ )
+ def inheritsJavaVarArgsMethod(clazz: Symbol) =
+ clazz.thisType.baseClasses exists isJavaVarargsAncestor
+
/** All types in list must be polytypes with type parameter lists of
* same length as tparams.
* Returns list of list of bounds infos, where corresponding type
@@ -7199,6 +6937,15 @@ trait Types extends api.Types { self: SymbolTable =>
else (ps :+ SerializableClass.tpe).toList
)
+ /** Members of the given class, other than those inherited
+ * from Any or AnyRef.
+ */
+ def nonTrivialMembers(clazz: Symbol): Scope = clazz.info.members filterNot isUniversalMember
+
+ /** Members which can be imported into other scopes.
+ */
+ def importableMembers(pre: Type): Scope = pre.members filter isImportable
+
def objToAny(tp: Type): Type =
if (!phase.erasedTypes && tp.typeSymbol == ObjectClass) AnyClass.tpe
else tp
@@ -7222,7 +6969,7 @@ trait Types extends api.Types { self: SymbolTable =>
protected def typeToString(tpe: Type): String =
if (tostringRecursions >= maxTostringRecursions) {
- debugwarn("Exceeded recursion depth attempting to print type.")
+ devWarning("Exceeded recursion depth attempting to print " + util.shortClassOfInstance(tpe))
if (settings.debug.value)
(new Throwable).printStackTrace
@@ -7292,7 +7039,6 @@ trait Types extends api.Types { self: SymbolTable =>
object TypesStats {
import BaseTypeSeqsStats._
val rawTypeCount = Statistics.newCounter ("#raw type creations")
- val asSeenFromCount = Statistics.newCounter ("#asSeenFrom ops")
val subtypeCount = Statistics.newCounter ("#subtype ops")
val sametypeCount = Statistics.newCounter ("#sametype ops")
val lubCount = Statistics.newCounter ("#toplevel lubs/glbs")
diff --git a/src/reflect/scala/reflect/internal/pickling/PickleBuffer.scala b/src/reflect/scala/reflect/internal/pickling/PickleBuffer.scala
index 6170fcbb90..34c6fe234c 100644
--- a/src/reflect/scala/reflect/internal/pickling/PickleBuffer.scala
+++ b/src/reflect/scala/reflect/internal/pickling/PickleBuffer.scala
@@ -62,11 +62,8 @@ class PickleBuffer(data: Array[Byte], from: Int, to: Int) {
writeByte((x & 0x7f).toInt)
}
- /** Write a natural number <code>x</code> at position <code>pos</code>.
+ /** Write a natural number `x` at position `pos`.
* If number is more than one byte, shift rest of array to make space.
- *
- * @param pos ...
- * @param x ...
*/
def patchNat(pos: Int, x: Int) {
def patchNatPrefix(x: Int) {
@@ -81,7 +78,7 @@ class PickleBuffer(data: Array[Byte], from: Int, to: Int) {
if (y != 0) patchNatPrefix(y)
}
- /** Write a long number <code>x</code> in signed big endian format, base 256.
+ /** Write a long number `x` in signed big endian format, base 256.
*
* @param x The long number to be written.
*/
@@ -94,9 +91,6 @@ class PickleBuffer(data: Array[Byte], from: Int, to: Int) {
// -- Basic input routines --------------------------------------------
- /** Peek at the current byte without moving the read index */
- def peekByte(): Int = bytes(readIndex)
-
/** Read a byte */
def readByte(): Int = {
val x = bytes(readIndex); readIndex += 1; x
@@ -151,18 +145,14 @@ class PickleBuffer(data: Array[Byte], from: Int, to: Int) {
result.toIndexedSeq
}
- /** Perform operation <code>op</code> until the condition
- * <code>readIndex == end</code> is satisfied.
+ /** Perform operation `op` until the condition
+ * `readIndex == end` is satisfied.
* Concatenate results into a list.
- *
- * @param end ...
- * @param op ...
- * @return ...
*/
def until[T](end: Int, op: () => T): List[T] =
if (readIndex == end) List() else op() :: until(end, op);
- /** Perform operation <code>op</code> the number of
+ /** Perform operation `op` the number of
* times specified. Concatenate the results into a list.
*/
def times[T](n: Int, op: ()=>T): List[T] =
diff --git a/src/reflect/scala/reflect/internal/pickling/PickleFormat.scala b/src/reflect/scala/reflect/internal/pickling/PickleFormat.scala
index 16747af08a..3722c77aa2 100644
--- a/src/reflect/scala/reflect/internal/pickling/PickleFormat.scala
+++ b/src/reflect/scala/reflect/internal/pickling/PickleFormat.scala
@@ -56,7 +56,7 @@ object PickleFormat {
* | 42 ANNOTATEDtpe len_Nat [sym_Ref /* no longer needed */] tpe_Ref {annotinfo_Ref}
* | 43 ANNOTINFO len_Nat AnnotInfoBody
* | 44 ANNOTARGARRAY len_Nat {constAnnotArg_Ref}
- * | 47 DEBRUIJNINDEXtpe len_Nat level_Nat index_Nat
+ * | 47 DEBRUIJNINDEXtpe len_Nat level_Nat index_Nat /* no longer needed */
* | 48 EXISTENTIALtpe len_Nat type_Ref {symbol_Ref}
* | 49 TREE len_Nat 1 EMPTYtree
* | 49 TREE len_Nat 2 PACKAGEtree type_Ref sym_Ref mods_Ref name_Ref {tree_Ref}
@@ -115,7 +115,6 @@ object PickleFormat {
*/
val MajorVersion = 5
val MinorVersion = 0
- def VersionString = "V" + MajorVersion + "." + MinorVersion
final val TERMname = 1
final val TYPEname = 2
@@ -161,7 +160,7 @@ object PickleFormat {
final val ANNOTARGARRAY = 44
final val SUPERtpe = 46
- final val DEBRUIJNINDEXtpe = 47
+ final val DEBRUIJNINDEXtpe = 47 // no longer generated
final val EXISTENTIALtpe = 48
final val TREE = 49 // prefix code that means a tree is coming
diff --git a/src/reflect/scala/reflect/internal/pickling/UnPickler.scala b/src/reflect/scala/reflect/internal/pickling/UnPickler.scala
index 603fff4f1c..5b01b5ffa5 100644
--- a/src/reflect/scala/reflect/internal/pickling/UnPickler.scala
+++ b/src/reflect/scala/reflect/internal/pickling/UnPickler.scala
@@ -159,9 +159,9 @@ abstract class UnPickler {
result
}
- /** If entry at <code>i</code> is undefined, define it by performing
- * operation <code>op</code> with <code>readIndex at start of i'th
- * entry. Restore <code>readIndex</code> afterwards.
+ /** If entry at `i` is undefined, define it by performing
+ * operation `op` with `readIndex at start of i'th
+ * entry. Restore `readIndex` afterwards.
*/
protected def at[T <: AnyRef](i: Int, op: () => T): T = {
var r = entries(i)
@@ -186,13 +186,12 @@ abstract class UnPickler {
case _ => errorBadSignature("bad name tag: " + tag)
}
}
- protected def readTermName(): TermName = readName().toTermName
- protected def readTypeName(): TypeName = readName().toTypeName
+ private def readEnd() = readNat() + readIndex
/** Read a symbol */
protected def readSymbol(): Symbol = {
val tag = readByte()
- val end = readNat() + readIndex
+ val end = readEnd()
def atEnd = readIndex == end
def readExtSymbol(): Symbol = {
@@ -325,7 +324,7 @@ abstract class UnPickler {
*/
protected def readType(forceProperType: Boolean = false): Type = {
val tag = readByte()
- val end = readNat() + readIndex
+ val end = readEnd()
(tag: @switch) match {
case NOtpe =>
NoType
@@ -344,7 +343,7 @@ abstract class UnPickler {
case TYPEREFtpe =>
val pre = readTypeRef()
val sym = readSymbolRef()
- var args = until(end, readTypeRef)
+ val args = until(end, readTypeRef)
TypeRef(pre, sym, args)
case TYPEBOUNDStpe =>
TypeBounds(readTypeRef(), readTypeRef())
@@ -431,7 +430,7 @@ abstract class UnPickler {
protected def readChildren() {
val tag = readByte()
assert(tag == CHILDREN)
- val end = readNat() + readIndex
+ val end = readEnd()
val target = readSymbolRef()
while (readIndex != end) target addChild readSymbolRef()
}
@@ -450,7 +449,7 @@ abstract class UnPickler {
*/
private def readArrayAnnot() = {
readByte() // skip the `annotargarray` tag
- val end = readNat() + readIndex
+ val end = readEnd()
until(end, () => readClassfileAnnotArg(readNat())).toArray(JavaArgumentTag)
}
protected def readClassfileAnnotArg(i: Int): ClassfileAnnotArg = bytes(index(i)) match {
@@ -486,7 +485,7 @@ abstract class UnPickler {
val tag = readByte()
if (tag != SYMANNOT)
errorBadSignature("symbol annotation expected ("+ tag +")")
- val end = readNat() + readIndex
+ val end = readEnd()
val target = readSymbolRef()
target.addAnnotation(readAnnotationInfo(end))
}
@@ -497,7 +496,7 @@ abstract class UnPickler {
val tag = readByte()
if (tag != ANNOTINFO)
errorBadSignature("annotation expected (" + tag + ")")
- val end = readNat() + readIndex
+ val end = readEnd()
readAnnotationInfo(end)
}
@@ -506,7 +505,7 @@ abstract class UnPickler {
val outerTag = readByte()
if (outerTag != TREE)
errorBadSignature("tree expected (" + outerTag + ")")
- val end = readNat() + readIndex
+ val end = readEnd()
val tag = readByte()
val tpe = if (tag == EMPTYtree) NoType else readTypeRef()
@@ -764,7 +763,8 @@ abstract class UnPickler {
val tag = readNat()
if (tag != MODIFIERS)
errorBadSignature("expected a modifiers tag (" + tag + ")")
- val end = readNat() + readIndex
+
+ readEnd()
val pflagsHi = readNat()
val pflagsLo = readNat()
val pflags = (pflagsHi.toLong << 32) + pflagsLo
@@ -796,7 +796,6 @@ abstract class UnPickler {
protected def readTreeRef(): Tree = at(readNat(), readTree)
protected def readTypeNameRef(): TypeName = readNameRef().toTypeName
- protected def readTermNameRef(): TermName = readNameRef().toTermName
protected def readTemplateRef(): Template =
readTreeRef() match {
@@ -843,7 +842,6 @@ abstract class UnPickler {
* error reporting, so we rely on the typechecker to report the error).
*/
def toTypeError(e: MissingRequirementError) = {
- // e.printStackTrace()
new TypeError(e.msg)
}
@@ -853,7 +851,7 @@ abstract class UnPickler {
private val p = phase
override def complete(sym: Symbol) : Unit = try {
val tp = at(i, () => readType(sym.isTerm)) // after NMT_TRANSITION, revert `() => readType(sym.isTerm)` to `readType`
- atPhase(p) (sym setInfo tp)
+ enteringPhase(p) (sym setInfo tp)
if (currentRunId != definedAtRunId)
sym.setInfo(adaptToNewRunMap(tp))
}
@@ -871,7 +869,7 @@ abstract class UnPickler {
super.complete(sym)
var alias = at(j, readSymbol)
if (alias.isOverloaded)
- alias = atPhase(picklerPhase)((alias suchThat (alt => sym.tpe =:= sym.owner.thisType.memberType(alt))))
+ alias = enteringPhase(picklerPhase)((alias suchThat (alt => sym.tpe =:= sym.owner.thisType.memberType(alt))))
sym.asInstanceOf[TermSymbol].setAlias(alias)
}
diff --git a/src/reflect/scala/reflect/internal/settings/MutableSettings.scala b/src/reflect/scala/reflect/internal/settings/MutableSettings.scala
index 81368df7a6..81ed63bfc6 100644
--- a/src/reflect/scala/reflect/internal/settings/MutableSettings.scala
+++ b/src/reflect/scala/reflect/internal/settings/MutableSettings.scala
@@ -47,4 +47,5 @@ abstract class MutableSettings extends AbsSettings {
def XoldPatmat: BooleanSetting
def XnoPatmatAnalysis: BooleanSetting
def XfullLubs: BooleanSetting
+ def breakCycles: BooleanSetting
}
diff --git a/src/reflect/scala/reflect/internal/transform/Erasure.scala b/src/reflect/scala/reflect/internal/transform/Erasure.scala
index 52d1657dc3..59bf51d638 100644
--- a/src/reflect/scala/reflect/internal/transform/Erasure.scala
+++ b/src/reflect/scala/reflect/internal/transform/Erasure.scala
@@ -69,7 +69,7 @@ trait Erasure {
//
// This requires that cls.isClass.
protected def rebindInnerClass(pre: Type, cls: Symbol): Type = {
- if (cls.owner.isClass) cls.owner.tpe else pre // why not cls.isNestedClass?
+ if (cls.owner.isClass) cls.owner.tpe_* else pre // why not cls.isNestedClass?
}
def unboxDerivedValueClassMethod(clazz: Symbol): Symbol =
@@ -233,7 +233,7 @@ trait Erasure {
// It seems there is a deeper problem here, which needs
// following up to. But we will not risk regressions
// in 2.10 because of it.
- log(s"!!! unexpected constructor erasure $tp for $clazz")
+ devWarning(s"unexpected constructor erasure $tp for $clazz")
specialScalaErasure(tp)
}
}
diff --git a/src/reflect/scala/reflect/internal/util/Collections.scala b/src/reflect/scala/reflect/internal/util/Collections.scala
index 2ba15e0776..0d644aa73e 100644
--- a/src/reflect/scala/reflect/internal/util/Collections.scala
+++ b/src/reflect/scala/reflect/internal/util/Collections.scala
@@ -40,8 +40,6 @@ trait Collections {
mforeach(xss)(x => if ((res eq null) && p(x)) res = Some(x))
if (res eq null) None else res
}
- final def mfilter[A](xss: List[List[A]])(p: A => Boolean) =
- for (xs <- xss; x <- xs; if p(x)) yield x
final def map2[A, B, C](xs1: List[A], xs2: List[B])(f: (A, B) => C): List[C] = {
val lb = new ListBuffer[C]
@@ -78,19 +76,6 @@ trait Collections {
lb.toList
}
- final def distinctBy[A, B](xs: List[A])(f: A => B): List[A] = {
- val buf = new ListBuffer[A]
- val seen = mutable.Set[B]()
- xs foreach { x =>
- val y = f(x)
- if (!seen(y)) {
- buf += x
- seen += y
- }
- }
- buf.toList
- }
-
@tailrec final def flattensToEmpty(xss: Seq[Seq[_]]): Boolean = {
xss.isEmpty || xss.head.isEmpty && flattensToEmpty(xss.tail)
}
@@ -189,18 +174,6 @@ trait Collections {
}
false
}
- final def forall2[A, B](xs1: List[A], xs2: List[B])(f: (A, B) => Boolean): Boolean = {
- var ys1 = xs1
- var ys2 = xs2
- while (!ys1.isEmpty && !ys2.isEmpty) {
- if (!f(ys1.head, ys2.head))
- return false
-
- ys1 = ys1.tail
- ys2 = ys2.tail
- }
- true
- }
final def forall3[A, B, C](xs1: List[A], xs2: List[B], xs3: List[C])(f: (A, B, C) => Boolean): Boolean = {
var ys1 = xs1
var ys2 = xs2
@@ -222,6 +195,3 @@ trait Collections {
case _: IllegalArgumentException => None
}
}
-
-object Collections extends Collections { }
-
diff --git a/src/reflect/scala/reflect/internal/util/HashSet.scala b/src/reflect/scala/reflect/internal/util/HashSet.scala
index 4135f3c469..74b6a54c6e 100644
--- a/src/reflect/scala/reflect/internal/util/HashSet.scala
+++ b/src/reflect/scala/reflect/internal/util/HashSet.scala
@@ -6,8 +6,6 @@
package scala.reflect.internal.util
object HashSet {
- def apply[T >: Null <: AnyRef](): HashSet[T] = this(16)
- def apply[T >: Null <: AnyRef](label: String): HashSet[T] = this(label, 16)
def apply[T >: Null <: AnyRef](initialCapacity: Int): HashSet[T] = this("No Label", initialCapacity)
def apply[T >: Null <: AnyRef](label: String, initialCapacity: Int): HashSet[T] =
new HashSet[T](label, initialCapacity)
diff --git a/src/reflect/scala/reflect/internal/util/Origins.scala b/src/reflect/scala/reflect/internal/util/Origins.scala
index 3259a12163..a2b9e24ebc 100644
--- a/src/reflect/scala/reflect/internal/util/Origins.scala
+++ b/src/reflect/scala/reflect/internal/util/Origins.scala
@@ -6,9 +6,7 @@
package scala.reflect
package internal.util
-import NameTransformer._
import scala.collection.{ mutable, immutable }
-import Origins._
/** A debugging class for logging from whence a method is being called.
* Say you wanted to discover who was calling phase_= in SymbolTable.
diff --git a/src/reflect/scala/reflect/internal/util/Position.scala b/src/reflect/scala/reflect/internal/util/Position.scala
index 3d10d4c9ce..1c29cabe24 100644
--- a/src/reflect/scala/reflect/internal/util/Position.scala
+++ b/src/reflect/scala/reflect/internal/util/Position.scala
@@ -129,7 +129,7 @@ abstract class Position extends scala.reflect.api.Position { self =>
def endOrPoint: Int = point
@deprecated("use point instead", "2.9.0")
- def offset: Option[Int] = if (isDefined) Some(point) else None
+ def offset: Option[Int] = if (isDefined) Some(point) else None // used by sbt
/** The same position with a different start value (if a range) */
def withStart(off: Int): Position = this
diff --git a/src/reflect/scala/reflect/internal/util/Set.scala b/src/reflect/scala/reflect/internal/util/Set.scala
index 36bdb8174a..57e5e0c0b9 100644
--- a/src/reflect/scala/reflect/internal/util/Set.scala
+++ b/src/reflect/scala/reflect/internal/util/Set.scala
@@ -18,8 +18,6 @@ abstract class Set[T <: AnyRef] {
def apply(x: T): Boolean = contains(x)
- @deprecated("use `iterator` instead", "2.9.0") def elements = iterator
-
def contains(x: T): Boolean =
findEntry(x) ne null
diff --git a/src/reflect/scala/reflect/internal/util/SourceFile.scala b/src/reflect/scala/reflect/internal/util/SourceFile.scala
index bc2d0ee4db..dd2a6e21f1 100644
--- a/src/reflect/scala/reflect/internal/util/SourceFile.scala
+++ b/src/reflect/scala/reflect/internal/util/SourceFile.scala
@@ -24,7 +24,6 @@ abstract class SourceFile {
assert(offset < length, file + ": " + offset + " >= " + length)
new OffsetPosition(this, offset)
}
- def position(line: Int, column: Int) : Position = new OffsetPosition(this, lineToOffset(line) + column)
def offsetToLine(offset: Int): Int
def lineToOffset(index : Int): Int
@@ -37,9 +36,6 @@ abstract class SourceFile {
def dbg(offset: Int) = (new OffsetPosition(this, offset)).dbgString
def path = file.path
- def beginsWith(offset: Int, text: String): Boolean =
- (content drop offset) startsWith text
-
def lineToString(index: Int): String =
content drop lineToOffset(index) takeWhile (c => !isLineBreakChar(c.toChar)) mkString ""
@@ -81,7 +77,6 @@ object ScriptSourceFile {
}
else 0
}
- def stripHeader(cs: Array[Char]): Array[Char] = cs drop headerLength(cs)
def apply(file: AbstractFile, content: Array[Char]) = {
val underlying = new BatchSourceFile(file, content)
@@ -91,7 +86,6 @@ object ScriptSourceFile {
stripped
}
}
-import ScriptSourceFile._
class ScriptSourceFile(underlying: BatchSourceFile, content: Array[Char], override val start: Int) extends BatchSourceFile(underlying.file, content) {
override def isSelfContained = false
diff --git a/src/reflect/scala/reflect/internal/util/Statistics.scala b/src/reflect/scala/reflect/internal/util/Statistics.scala
index 2c90d2d525..b078b7d4f9 100644
--- a/src/reflect/scala/reflect/internal/util/Statistics.scala
+++ b/src/reflect/scala/reflect/internal/util/Statistics.scala
@@ -257,7 +257,6 @@ quant)
def enabled = _enabled
def enabled_=(cond: Boolean) = {
if (cond && !_enabled) {
- val test = new Timer("", Nil)
val start = System.nanoTime()
var total = 0L
for (i <- 1 to 10000) {
diff --git a/src/reflect/scala/reflect/internal/util/StringOps.scala b/src/reflect/scala/reflect/internal/util/StringOps.scala
index 8f6c409e0b..93bbfdd273 100644
--- a/src/reflect/scala/reflect/internal/util/StringOps.scala
+++ b/src/reflect/scala/reflect/internal/util/StringOps.scala
@@ -6,7 +6,6 @@
** |/ **
\* */
-
package scala.reflect.internal.util
/** This object provides utility methods to extract elements
@@ -16,22 +15,14 @@ package scala.reflect.internal.util
* @version 1.0
*/
trait StringOps {
- def onull(s: String) = if (s == null) "" else s
- def oempty(xs: String*) = xs filterNot (x => x == null || x == "")
- def ojoin(xs: String*): String = oempty(xs: _*) mkString " "
- def ojoin(xs: Seq[String], sep: String): String = oempty(xs: _*) mkString sep
- def ojoinOr(xs: Seq[String], sep: String, orElse: String) = {
- val ys = oempty(xs: _*)
- if (ys.isEmpty) orElse else ys mkString sep
- }
- def trimTrailingSpace(s: String) = {
- if (s.length == 0 || !s.charAt(s.length - 1).isWhitespace) s
- else {
- var idx = s.length - 1
- while (idx >= 0 && s.charAt(idx).isWhitespace)
- idx -= 1
-
- s.substring(0, idx + 1)
+ def oempty(xs: String*) = xs filterNot (x => x == null || x == "")
+ def ojoin(xs: String*): String = oempty(xs: _*) mkString " "
+ def longestCommonPrefix(xs: List[String]): String = {
+ if (xs.isEmpty || xs.contains("")) ""
+ else xs.head.head match {
+ case ch =>
+ if (xs.tail forall (_.head == ch)) "" + ch + longestCommonPrefix(xs map (_.tail))
+ else ""
}
}
@@ -49,14 +40,6 @@ trait StringOps {
def words(str: String): List[String] = decompose(str, ' ')
- def stripPrefixOpt(str: String, prefix: String): Option[String] =
- if (str startsWith prefix) Some(str drop prefix.length)
- else None
-
- def stripSuffixOpt(str: String, suffix: String): Option[String] =
- if (str endsWith suffix) Some(str dropRight suffix.length)
- else None
-
def splitWhere(str: String, f: Char => Boolean, doDropIndex: Boolean = false): Option[(String, String)] =
splitAt(str, str indexWhere f, doDropIndex)
@@ -65,10 +48,6 @@ trait StringOps {
else Some((str take idx, str drop (if (doDropIndex) idx + 1 else idx)))
/** Returns a string meaning "n elements".
- *
- * @param n ...
- * @param elements ...
- * @return ...
*/
def countElementsAsString(n: Int, elements: String): String =
n match {
@@ -81,9 +60,6 @@ trait StringOps {
}
/** Turns a count into a friendly English description if n<=4.
- *
- * @param n ...
- * @return ...
*/
def countAsString(n: Int): String =
n match {
diff --git a/src/reflect/scala/reflect/internal/util/TableDef.scala b/src/reflect/scala/reflect/internal/util/TableDef.scala
index 8e2bcc2ff7..04ecfe8d76 100644
--- a/src/reflect/scala/reflect/internal/util/TableDef.scala
+++ b/src/reflect/scala/reflect/internal/util/TableDef.scala
@@ -67,12 +67,6 @@ class TableDef[T](_cols: Column[T]*) {
override def toString = allToSeq mkString "\n"
}
- def formatterFor(rows: Seq[T]): T => String = {
- val formatStr = new Table(rows).rowFormat
-
- x => formatStr.format(colApply(x) : _*)
- }
-
def table(rows: Seq[T]) = new Table(rows)
override def toString = cols.mkString("TableDef(", ", ", ")")
diff --git a/src/reflect/scala/reflect/internal/util/TraceSymbolActivity.scala b/src/reflect/scala/reflect/internal/util/TraceSymbolActivity.scala
index fa83f70f3a..632890d600 100644
--- a/src/reflect/scala/reflect/internal/util/TraceSymbolActivity.scala
+++ b/src/reflect/scala/reflect/internal/util/TraceSymbolActivity.scala
@@ -12,13 +12,9 @@ trait TraceSymbolActivity {
if (enabled && global.isCompilerUniverse)
scala.sys addShutdownHook showAllSymbols()
- private type Set[T] = scala.collection.immutable.Set[T]
- private val Set = scala.collection.immutable.Set
-
val allSymbols = mutable.Map[Int, Symbol]()
val allChildren = mutable.Map[Int, List[Int]]() withDefaultValue Nil
val prevOwners = mutable.Map[Int, List[(Int, Phase)]]() withDefaultValue Nil
- val symsCaused = mutable.Map[Int, Int]() withDefaultValue 0
val allTrees = mutable.Set[Tree]()
def recordSymbolsInTree(tree: Tree) {
@@ -44,38 +40,6 @@ trait TraceSymbolActivity {
}
}
- /** TODO.
- */
- private def reachableDirectlyFromSymbol(sym: Symbol): List[Symbol] = (
- List(sym.owner, sym.alias, sym.thisSym)
- ++ sym.children
- ++ sym.info.parents.map(_.typeSymbol)
- ++ sym.typeParams
- ++ sym.paramss.flatten
- )
- private def reachable[T](inputs: Traversable[T], mkSymbol: T => Symbol): Set[Symbol] = {
- def loop(seen: Set[Symbol], remaining: List[Symbol]): Set[Symbol] = {
- remaining match {
- case Nil => seen
- case head :: rest =>
- if ((head eq null) || (head eq NoSymbol) || seen(head)) loop(seen, rest)
- else loop(seen + head, rest ++ reachableDirectlyFromSymbol(head).filterNot(seen))
- }
- }
- loop(immutable.Set(), inputs.toList map mkSymbol filterNot (_ eq null) distinct)
- }
- private def treeList(t: Tree) = {
- val buf = mutable.ListBuffer[Tree]()
- t foreach (buf += _)
- buf.toList
- }
-
- private def reachableFromSymbol(root: Symbol): Set[Symbol] =
- reachable[Symbol](List(root, root.info.typeSymbol), x => x)
-
- private def reachableFromTree(tree: Tree): Set[Symbol] =
- reachable[Tree](treeList(tree), _.symbol)
-
private def signature(id: Int) = runBeforeErasure(allSymbols(id).defString)
private def dashes(s: Any): String = ("" + s) map (_ => '-')
@@ -119,7 +83,7 @@ trait TraceSymbolActivity {
}
println("\n")
}
- private def showFreq[T, U](xs: Traversable[T])(groupFn: T => U, showFn: U => String = (x: U) => "" + x) = {
+ private def showFreq[T, U](xs: Traversable[T])(groupFn: T => U, showFn: U => String) = {
showMapFreq(xs.toList groupBy groupFn)(showFn)
}
private lazy val findErasurePhase: Phase = {
@@ -129,7 +93,7 @@ trait TraceSymbolActivity {
}
ph
}
- private def runBeforeErasure[T](body: => T): T = atPhase(findErasurePhase)(body)
+ private def runBeforeErasure[T](body: => T): T = enteringPhase(findErasurePhase)(body)
def showAllSymbols() {
if (!enabled) return
diff --git a/src/reflect/scala/reflect/internal/util/WeakHashSet.scala b/src/reflect/scala/reflect/internal/util/WeakHashSet.scala
index 9882aad5e5..41e74f80e9 100644
--- a/src/reflect/scala/reflect/internal/util/WeakHashSet.scala
+++ b/src/reflect/scala/reflect/internal/util/WeakHashSet.scala
@@ -1,9 +1,6 @@
package scala.reflect.internal.util
import scala.collection.mutable
-import scala.collection.mutable.ArrayBuffer
-import scala.collection.mutable.Builder
-import scala.collection.mutable.SetBuilder
import scala.collection.generic.Clearable
import scala.runtime.AbstractFunction1
diff --git a/src/reflect/scala/reflect/internal/util/package.scala b/src/reflect/scala/reflect/internal/util/package.scala
index 6d77235db6..1ca57b81ed 100644
--- a/src/reflect/scala/reflect/internal/util/package.scala
+++ b/src/reflect/scala/reflect/internal/util/package.scala
@@ -1,7 +1,36 @@
-package scala.reflect
+package scala
+package reflect
package internal
package object util {
+ import StringOps.longestCommonPrefix
+
+ // Shorten a name like Symbols$FooSymbol to FooSymbol.
+ private def shortenName(name: String): String = {
+ if (name == "") return ""
+ val segments = (name split '$').toList
+ val last = segments.last
+
+ if (last.length == 0)
+ segments takeRight 2 mkString "$"
+ else
+ last
+ }
+
+ def shortClassOfInstance(x: AnyRef): String = shortClass(x.getClass)
+ def shortClass(clazz: Class[_]): String = {
+ val name: String = (clazz.getName split '.').last
+ def isModule = name endsWith "$" // object
+ def isAnon = (name split '$').last forall (_.isDigit) // anonymous class
+
+ if (isModule)
+ (name split '$' filterNot (_ == "")).last + "$"
+ else if (isAnon) {
+ val parents = clazz.getSuperclass :: clazz.getInterfaces.toList
+ parents map (c => shortClass(c)) mkString " with "
+ }
+ else shortenName(name)
+ }
/**
* Adds the `sm` String interpolator to a [[scala.StringContext]].
*/
diff --git a/src/reflect/scala/reflect/io/AbstractFile.scala b/src/reflect/scala/reflect/io/AbstractFile.scala
index 15befb67f1..1a8d1c4f5e 100644
--- a/src/reflect/scala/reflect/io/AbstractFile.scala
+++ b/src/reflect/scala/reflect/io/AbstractFile.scala
@@ -14,9 +14,9 @@ import scala.collection.mutable.ArrayBuffer
/**
* An abstraction over files for use in the reflection/compiler libraries.
- *
+ *
* ''Note: This library is considered experimental and should not be used unless you know what you are doing.''
- *
+ *
* @author Philippe Altherr
* @version 1.0, 23/03/2004
*/
@@ -27,7 +27,7 @@ object AbstractFile {
/**
* If the specified File exists and is a regular file, returns an
- * abstract regular file backed by it. Otherwise, returns <code>null</code>.
+ * abstract regular file backed by it. Otherwise, returns `null`.
*/
def getFile(file: File): AbstractFile =
if (file.isFile) new PlainFile(file) else null
@@ -38,10 +38,7 @@ object AbstractFile {
/**
* If the specified File exists and is either a directory or a
* readable zip or jar archive, returns an abstract directory
- * backed by it. Otherwise, returns <code>null</code>.
- *
- * @param file ...
- * @return ...
+ * backed by it. Otherwise, returns `null`.
*/
def getDirectory(file: File): AbstractFile =
if (file.isDirectory) new PlainFile(file)
@@ -51,10 +48,7 @@ object AbstractFile {
/**
* If the specified URL exists and is a readable zip or jar archive,
* returns an abstract directory backed by it. Otherwise, returns
- * <code>null</code>.
- *
- * @param file ...
- * @return ...
+ * `null`.
*/
def getURL(url: URL): AbstractFile = {
if (url == null || !Path.isExtensionJarOrZip(url.getPath)) null
@@ -80,12 +74,12 @@ object AbstractFile {
* </p>
* <p>
* The interface does <b>not</b> allow to access the content.
- * The class <code>symtab.classfile.AbstractFileReader</code> accesses
+ * The class `symtab.classfile.AbstractFileReader` accesses
* bytes, knowing that the character set of classfiles is UTF-8. For
- * all other cases, the class <code>SourceFile</code> is used, which honors
- * <code>global.settings.encoding.value</code>.
+ * all other cases, the class `SourceFile` is used, which honors
+ * `global.settings.encoding.value`.
* </p>
- *
+ *
* ''Note: This library is considered experimental and should not be used unless you know what you are doing.''
*/
abstract class AbstractFile extends Iterable[AbstractFile] {
@@ -148,7 +142,7 @@ abstract class AbstractFile extends Iterable[AbstractFile] {
def toURL: URL = if (file == null) null else file.toURI.toURL
/** Returns contents of file (if applicable) in a Char array.
- * warning: use <code>Global.getSourceFile()</code> to use the proper
+ * warning: use `Global.getSourceFile()` to use the proper
* encoding when converting to the char array.
*/
@throws(classOf[IOException])
@@ -175,8 +169,8 @@ abstract class AbstractFile extends Iterable[AbstractFile] {
def iterator: Iterator[AbstractFile]
/** Returns the abstract file in this abstract directory with the specified
- * name. If there is no such file, returns <code>null</code>. The argument
- * <code>directory</code> tells whether to look for a directory or
+ * name. If there is no such file, returns `null`. The argument
+ * `directory` tells whether to look for a directory or
* a regular file.
*/
def lookupName(name: String, directory: Boolean): AbstractFile
@@ -186,19 +180,6 @@ abstract class AbstractFile extends Iterable[AbstractFile] {
*/
def lookupNameUnchecked(name: String, directory: Boolean): AbstractFile
- /** Returns the abstract file in this abstract directory with the specified
- * path relative to it, If there is no such file, returns null. The argument
- * <code>directory</code> tells whether to look for a directory or a regular
- * file.
- *
- * @param path ...
- * @param directory ...
- * @return ...
- */
- def lookupPath(path: String, directory: Boolean): AbstractFile = {
- lookup((f, p, dir) => f.lookupName(p, dir), path, directory)
- }
-
/** Return an abstract file that does not check that `path` denotes
* an existing file.
*/
diff --git a/src/reflect/scala/reflect/io/Directory.scala b/src/reflect/scala/reflect/io/Directory.scala
index c040d1eac5..4bf9ed8a36 100644
--- a/src/reflect/scala/reflect/io/Directory.scala
+++ b/src/reflect/scala/reflect/io/Directory.scala
@@ -14,12 +14,10 @@ import java.io.{ File => JFile }
* ''Note: This library is considered experimental and should not be used unless you know what you are doing.''
*/
object Directory {
- import scala.util.Properties.{ tmpDir, userHome, userDir }
+ import scala.util.Properties.{ userHome, userDir }
private def normalizePath(s: String) = Some(apply(Path(s).normalize))
def Current: Option[Directory] = if (userDir == "") None else normalizePath(userDir)
- def Home: Option[Directory] = if (userHome == "") None else normalizePath(userHome)
- def TmpDir: Option[Directory] = if (tmpDir == "") None else normalizePath(tmpDir)
def apply(path: Path): Directory = path.toDirectory
@@ -30,20 +28,18 @@ object Directory {
path.createDirectory()
}
}
-import Path._
/** An abstraction for directories.
*
* @author Paul Phillips
* @since 2.8
- *
+ *
* ''Note: This is library is considered experimental and should not be used unless you know what you are doing.''
*/
class Directory(jfile: JFile) extends Path(jfile) {
override def toAbsolute: Directory = if (isAbsolute) this else super.toAbsolute.toDirectory
override def toDirectory: Directory = this
override def toFile: File = new File(jfile)
- override def isValid = jfile.isDirectory() || !jfile.exists()
override def normalize: Directory = super.normalize.toDirectory
/** An iterator over the contents of this directory.
@@ -60,7 +56,6 @@ class Directory(jfile: JFile) extends Path(jfile) {
override def walkFilter(cond: Path => Boolean): Iterator[Path] =
list filter cond flatMap (_ walkFilter cond)
- def deepDirs: Iterator[Directory] = Path.onlyDirs(deepList())
def deepFiles: Iterator[File] = Path.onlyFiles(deepList())
/** If optional depth argument is not given, will recurse
@@ -70,10 +65,4 @@ class Directory(jfile: JFile) extends Path(jfile) {
if (depth < 0) list ++ (dirs flatMap (_ deepList (depth)))
else if (depth == 0) Iterator.empty
else list ++ (dirs flatMap (_ deepList (depth - 1)))
-
- /** An iterator over the directories underneath this directory,
- * to the (optionally) given depth.
- */
- def subdirs(depth: Int = 1): Iterator[Directory] =
- deepList(depth) collect { case x: Directory => x }
}
diff --git a/src/reflect/scala/reflect/io/File.scala b/src/reflect/scala/reflect/io/File.scala
index 736ba5d51e..c74dc06501 100644
--- a/src/reflect/scala/reflect/io/File.scala
+++ b/src/reflect/scala/reflect/io/File.scala
@@ -22,8 +22,7 @@ import scala.language.{reflectiveCalls, implicitConversions}
*/
object File {
def pathSeparator = java.io.File.pathSeparator
- def separator = java.io.File.separator
-
+ def separator = java.io.File.separator
def apply(path: Path)(implicit codec: Codec) = new File(path.jfile)(codec)
// Create a temporary file, which will be deleted upon jvm exit.
@@ -32,41 +31,7 @@ object File {
jfile.deleteOnExit()
apply(jfile)
}
-
- type HasClose = { def close(): Unit }
-
- def closeQuietly(target: HasClose) {
- try target.close() catch { case e: IOException => }
- }
- def closeQuietly(target: JCloseable) {
- try target.close() catch { case e: IOException => }
- }
-
- // this is a workaround for http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6503430
- // we are using a static initializer to statically initialize a java class so we don't
- // trigger java.lang.InternalErrors later when using it concurrently. We ignore all
- // the exceptions so as not to cause spurious failures when no write access is available,
- // e.g. google app engine.
- //
- // XXX need to put this behind a setting.
- //
- // try {
- // import Streamable.closing
- // val tmp = java.io.File.createTempFile("bug6503430", null, null)
- // try closing(new FileInputStream(tmp)) { in =>
- // val inc = in.getChannel()
- // closing(new FileOutputStream(tmp, true)) { out =>
- // out.getChannel().transferFrom(inc, 0, 0)
- // }
- // }
- // finally tmp.delete()
- // }
- // catch {
- // case _: IllegalArgumentException | _: IllegalStateException | _: IOException | _: SecurityException => ()
- // }
}
-import File._
-import Path._
/** An abstraction for files. For character data, a Codec
* can be supplied at either creation time or when a method
@@ -76,19 +41,17 @@ import Path._
*
* @author Paul Phillips
* @since 2.8
- *
+ *
* ''Note: This is library is considered experimental and should not be used unless you know what you are doing.''
*/
class File(jfile: JFile)(implicit constructorCodec: Codec) extends Path(jfile) with Streamable.Chars {
override val creationCodec = constructorCodec
- def withCodec(codec: Codec): File = new File(jfile)(codec)
override def addExtension(ext: String): File = super.addExtension(ext).toFile
override def toAbsolute: File = if (isAbsolute) this else super.toAbsolute.toFile
override def toDirectory: Directory = new Directory(jfile)
override def toFile: File = this
override def normalize: File = super.normalize.toFile
- override def isValid = jfile.isFile() || !jfile.exists()
override def length = super[Path].length
override def walkFilter(cond: Path => Boolean): Iterator[Path] =
if (cond(this)) Iterator.single(this) else Iterator.empty
@@ -99,14 +62,11 @@ class File(jfile: JFile)(implicit constructorCodec: Codec) extends Path(jfile) w
/** Obtains a OutputStream. */
def outputStream(append: Boolean = false) = new FileOutputStream(jfile, append)
def bufferedOutput(append: Boolean = false) = new BufferedOutputStream(outputStream(append))
- def printStream(append: Boolean = false) = new PrintStream(outputStream(append), true)
/** Obtains an OutputStreamWriter wrapped around a FileOutputStream.
* This should behave like a less broken version of java.io.FileWriter,
* in that unlike the java version you can specify the encoding.
*/
- def writer(): OutputStreamWriter = writer(false)
- def writer(append: Boolean): OutputStreamWriter = writer(append, creationCodec)
def writer(append: Boolean, codec: Codec): OutputStreamWriter =
new OutputStreamWriter(outputStream(append), codec.charSet)
@@ -118,7 +78,6 @@ class File(jfile: JFile)(implicit constructorCodec: Codec) extends Path(jfile) w
new BufferedWriter(writer(append, codec))
def printWriter(): PrintWriter = new PrintWriter(bufferedWriter(), true)
- def printWriter(append: Boolean): PrintWriter = new PrintWriter(bufferedWriter(append), true)
/** Creates a new file and writes all the Strings to it. */
def writeAll(strings: String*): Unit = {
@@ -127,12 +86,6 @@ class File(jfile: JFile)(implicit constructorCodec: Codec) extends Path(jfile) w
finally out.close()
}
- def writeBytes(bytes: Array[Byte]): Unit = {
- val out = bufferedOutput()
- try out write bytes
- finally out.close()
- }
-
def appendAll(strings: String*): Unit = {
val out = bufferedWriter(append = true)
try strings foreach (out write _)
@@ -150,39 +103,6 @@ class File(jfile: JFile)(implicit constructorCodec: Codec) extends Path(jfile) w
try Some(slurp())
catch { case _: IOException => None }
- def copyTo(destPath: Path, preserveFileDate: Boolean = false): Boolean = {
- val CHUNK = 1024 * 1024 * 16 // 16 MB
- val dest = destPath.toFile
- if (!isValid) fail("Source %s is not a valid file." format name)
- if (this.normalize == dest.normalize) fail("Source and destination are the same.")
- if (!dest.parent.exists) fail("Destination cannot be created.")
- if (dest.exists && !dest.canWrite) fail("Destination exists but is not writable.")
- if (dest.isDirectory) fail("Destination exists but is a directory.")
-
- lazy val in_s = inputStream()
- lazy val out_s = dest.outputStream()
- lazy val in = in_s.getChannel()
- lazy val out = out_s.getChannel()
-
- try {
- val size = in.size()
- var pos, count = 0L
- while (pos < size) {
- count = (size - pos) min CHUNK
- pos += out.transferFrom(in, pos, count)
- }
- }
- finally List[HasClose](out, out_s, in, in_s) foreach closeQuietly
-
- if (this.length != dest.length)
- fail("Failed to completely copy %s to %s".format(name, dest.name))
-
- if (preserveFileDate)
- dest.lastModified = this.lastModified
-
- true
- }
-
/** Reflection since we're into the java 6+ API.
*/
def setExecutable(executable: Boolean, ownerOnly: Boolean = true): Boolean = {
diff --git a/src/reflect/scala/reflect/io/Path.scala b/src/reflect/scala/reflect/io/Path.scala
index 36fdc04db4..3b5d3079cd 100644
--- a/src/reflect/scala/reflect/io/Path.scala
+++ b/src/reflect/scala/reflect/io/Path.scala
@@ -27,7 +27,7 @@ import scala.language.implicitConversions
*
* @author Paul Phillips
* @since 2.8
- *
+ *
* ''Note: This library is considered experimental and should not be used unless you know what you are doing.''
*/
object Path {
@@ -49,27 +49,12 @@ object Path {
implicit def string2path(s: String): Path = apply(s)
implicit def jfile2path(jfile: JFile): Path = apply(jfile)
- // java 7 style, we don't use it yet
- // object AccessMode extends Enumeration {
- // val EXECUTE, READ, WRITE = Value
- // }
- // def checkAccess(modes: AccessMode*): Boolean = {
- // modes foreach {
- // case EXECUTE => throw new Exception("Unsupported") // can't check in java 5
- // case READ => if (!jfile.canRead()) return false
- // case WRITE => if (!jfile.canWrite()) return false
- // }
- // true
- // }
-
def onlyDirs(xs: Iterator[Path]): Iterator[Directory] = xs filter (_.isDirectory) map (_.toDirectory)
def onlyDirs(xs: List[Path]): List[Directory] = xs filter (_.isDirectory) map (_.toDirectory)
def onlyFiles(xs: Iterator[Path]): Iterator[File] = xs filter (_.isFile) map (_.toFile)
- def onlyFiles(xs: List[Path]): List[File] = xs filter (_.isFile) map (_.toFile)
def roots: List[Path] = java.io.File.listRoots().toList map Path.apply
- def apply(segments: Seq[String]): Path = apply(segments mkString java.io.File.separator)
def apply(path: String): Path = apply(new JFile(path))
def apply(jfile: JFile): Path =
if (jfile.isFile) new File(jfile)
@@ -84,19 +69,13 @@ import Path._
/** The Path constructor is private so we can enforce some
* semantics regarding how a Path might relate to the world.
- *
+ *
* ''Note: This library is considered experimental and should not be used unless you know what you are doing.''
*/
class Path private[io] (val jfile: JFile) {
val separator = java.io.File.separatorChar
val separatorStr = java.io.File.separator
- // Validation: this verifies that the type of this object and the
- // contents of the filesystem are in agreement. All objects are
- // valid except File objects whose path points to a directory and
- // Directory objects whose path points to a file.
- def isValid: Boolean = true
-
// conversions
def toFile: File = new File(jfile)
def toDirectory: Directory = new Directory(jfile)
@@ -104,6 +83,7 @@ class Path private[io] (val jfile: JFile) {
def toCanonical: Path = Path(jfile.getCanonicalPath())
def toURI: URI = jfile.toURI()
def toURL: URL = toURI.toURL()
+
/** If this path is absolute, returns it: otherwise, returns an absolute
* path made up of root / this.
*/
@@ -136,7 +116,6 @@ class Path private[io] (val jfile: JFile) {
def name: String = jfile.getName()
def path: String = jfile.getPath()
def normalize: Path = Path(jfile.getAbsolutePath())
- def isRootPath: Boolean = roots exists (_ isSame this)
def resolve(other: Path) = if (other.isAbsolute || isEmpty) other else /(other)
def relativize(other: Path) = {
@@ -152,9 +131,8 @@ class Path private[io] (val jfile: JFile) {
Path(createRelativePath(segments, other.segments))
}
- // derived from identity
- def root: Option[Path] = roots find (this startsWith _)
def segments: List[String] = (path split separator).toList filterNot (_.length == 0)
+
/**
* @return The path of the parent directory, or root if path is already root
*/
@@ -185,10 +163,6 @@ class Path private[io] (val jfile: JFile) {
if (i < 0) ""
else name.substring(i + 1)
}
- // def extension: String = (name lastIndexOf '.') match {
- // case -1 => ""
- // case idx => name drop (idx + 1)
- // }
// compares against extensions in a CASE INSENSITIVE way.
def hasExtension(ext: String, exts: String*) = {
val lower = extension.toLowerCase
@@ -213,22 +187,18 @@ class Path private[io] (val jfile: JFile) {
def canRead = jfile.canRead()
def canWrite = jfile.canWrite()
def exists = jfile.exists()
- def notExists = try !jfile.exists() catch { case ex: SecurityException => false }
def isFile = jfile.isFile()
def isDirectory = jfile.isDirectory()
def isAbsolute = jfile.isAbsolute()
- def isHidden = jfile.isHidden()
def isEmpty = path.length == 0
// Information
def lastModified = jfile.lastModified()
- def lastModified_=(time: Long) = jfile setLastModified time // should use setXXX function?
def length = jfile.length()
// Boolean path comparisons
def endsWith(other: Path) = segments endsWith other.segments
- def startsWith(other: Path) = segments startsWith other.segments
def isSame(other: Path) = toCanonical == other.toCanonical
def isFresher(other: Path) = lastModified > other.lastModified
@@ -248,7 +218,6 @@ class Path private[io] (val jfile: JFile) {
// deletions
def delete() = jfile.delete()
- def deleteIfExists() = if (jfile.exists()) delete() else false
/** Deletes the path recursively. Returns false on failure.
* Use with caution!
@@ -270,16 +239,6 @@ class Path private[io] (val jfile: JFile) {
length == 0
}
- def touch(modTime: Long = System.currentTimeMillis) = {
- createFile()
- if (isFile)
- lastModified = modTime
- }
-
- // todo
- // def copyTo(target: Path, options ...): Boolean
- // def moveTo(target: Path, options ...): Boolean
-
override def toString() = path
override def equals(other: Any) = other match {
case x: Path => path == x.path
diff --git a/src/reflect/scala/reflect/io/PlainFile.scala b/src/reflect/scala/reflect/io/PlainFile.scala
index 82b0568657..0d4d55bdec 100644
--- a/src/reflect/scala/reflect/io/PlainFile.scala
+++ b/src/reflect/scala/reflect/io/PlainFile.scala
@@ -3,23 +3,11 @@
* @author Martin Odersky
*/
-
package scala.reflect
package io
import java.io.{ FileInputStream, FileOutputStream, IOException }
-import PartialFunction._
-/** ''Note: This library is considered experimental and should not be used unless you know what you are doing.'' */
-object PlainFile {
- /**
- * If the specified File exists, returns an abstract file backed
- * by it. Otherwise, returns null.
- */
- def fromPath(file: Path): PlainFile =
- if (file.isDirectory) new PlainDirectory(file.toDirectory)
- else if (file.isFile) new PlainFile(file)
- else null
-}
+
/** ''Note: This library is considered experimental and should not be used unless you know what you are doing.'' */
class PlainDirectory(givenPath: Directory) extends PlainFile(givenPath) {
override def isDirectory = true
@@ -28,7 +16,7 @@ class PlainDirectory(givenPath: Directory) extends PlainFile(givenPath) {
}
/** This class implements an abstract file backed by a File.
- *
+ *
* ''Note: This library is considered experimental and should not be used unless you know what you are doing.''
*/
class PlainFile(val givenPath: Path) extends AbstractFile {
@@ -77,10 +65,6 @@ class PlainFile(val givenPath: Path) extends AbstractFile {
* specified name. If there is no such file, returns null. The
* argument "directory" tells whether to look for a directory or
* or a regular file.
- *
- * @param name ...
- * @param directory ...
- * @return ...
*/
def lookupName(name: String, directory: Boolean): AbstractFile = {
val child = givenPath / name
diff --git a/src/reflect/scala/reflect/io/Streamable.scala b/src/reflect/scala/reflect/io/Streamable.scala
index 61ec8a4c23..b45cffb150 100644
--- a/src/reflect/scala/reflect/io/Streamable.scala
+++ b/src/reflect/scala/reflect/io/Streamable.scala
@@ -17,14 +17,14 @@ import Path.fail
*
* @author Paul Phillips
* @since 2.8
- *
+ *
* ''Note: This library is considered experimental and should not be used unless you know what you are doing.''
*/
object Streamable {
/** Traits which can be viewed as a sequence of bytes. Source types
* which know their length should override def length: Long for more
* efficient method implementations.
- *
+ *
* ''Note: This library is considered experimental and should not be used unless you know what you are doing.''
*/
trait Bytes {
@@ -69,7 +69,7 @@ object Streamable {
}
/** For objects which can be viewed as Chars.
- *
+ *
* ''Note: This library is considered experimental and should not be used unless you know what you are doing.''
*/
trait Chars extends Bytes {
@@ -81,7 +81,6 @@ object Streamable {
*/
def creationCodec: Codec = implicitly[Codec]
- def chars(): BufferedSource = chars(creationCodec)
def chars(codec: Codec): BufferedSource = Source.fromInputStream(inputStream())(codec)
def lines(): Iterator[String] = lines(creationCodec)
@@ -89,7 +88,6 @@ object Streamable {
/** Obtains an InputStreamReader wrapped around a FileInputStream.
*/
- def reader(): InputStreamReader = reader(creationCodec)
def reader(codec: Codec): InputStreamReader = new InputStreamReader(inputStream, codec.charSet)
/** Wraps a BufferedReader around the result of reader().
diff --git a/src/reflect/scala/reflect/io/VirtualDirectory.scala b/src/reflect/scala/reflect/io/VirtualDirectory.scala
index 78713c2ae0..94cb52e9b5 100644
--- a/src/reflect/scala/reflect/io/VirtualDirectory.scala
+++ b/src/reflect/scala/reflect/io/VirtualDirectory.scala
@@ -11,7 +11,7 @@ import scala.collection.mutable
* An in-memory directory.
*
* @author Lex Spoon
- *
+ *
* ''Note: This library is considered experimental and should not be used unless you know what you are doing.''
*/
class VirtualDirectory(val name: String, maybeContainer: Option[VirtualDirectory])
@@ -26,7 +26,7 @@ extends AbstractFile {
def container = maybeContainer.get
def isDirectory = true
- var lastModified: Long = System.currentTimeMillis
+ val lastModified: Long = System.currentTimeMillis
override def file = null
override def input = sys.error("directories cannot be read")
diff --git a/src/reflect/scala/reflect/io/VirtualFile.scala b/src/reflect/scala/reflect/io/VirtualFile.scala
index 95f4429fad..09b977bd45 100644
--- a/src/reflect/scala/reflect/io/VirtualFile.scala
+++ b/src/reflect/scala/reflect/io/VirtualFile.scala
@@ -3,7 +3,6 @@
* @author Martin Odersky
*/
-
package scala.reflect
package io
@@ -14,7 +13,7 @@ import java.io.{ File => JFile }
*
* @author Philippe Altherr
* @version 1.0, 23/03/2004
- *
+ *
* ''Note: This library is considered experimental and should not be used unless you know what you are doing.''
*/
class VirtualFile(val name: String, override val path: String) extends AbstractFile {
@@ -33,12 +32,8 @@ class VirtualFile(val name: String, override val path: String) extends AbstractF
case _ => false
}
- //########################################################################
- // Private data
private var content = Array.emptyByteArray
- //########################################################################
- // Public Methods
def absolute = this
/** Returns null. */
@@ -65,7 +60,6 @@ class VirtualFile(val name: String, override val path: String) extends AbstractF
/** Returns the time that this abstract file was last modified. */
private var _lastModified: Long = 0
def lastModified: Long = _lastModified
- def lastModified_=(x: Long) = _lastModified = x
/** Returns all abstract subfiles of this abstract directory. */
def iterator: Iterator[AbstractFile] = {
@@ -84,10 +78,6 @@ class VirtualFile(val name: String, override val path: String) extends AbstractF
* specified name. If there is no such file, returns null. The
* argument "directory" tells whether to look for a directory or
* or a regular file.
- *
- * @param name ...
- * @param directory ...
- * @return ...
*/
def lookupName(name: String, directory: Boolean): AbstractFile = {
assert(isDirectory, "not a directory '" + this + "'")
@@ -98,6 +88,4 @@ class VirtualFile(val name: String, override val path: String) extends AbstractF
* check that it exists.
*/
def lookupNameUnchecked(name: String, directory: Boolean) = unsupported
-
- //########################################################################
}
diff --git a/src/reflect/scala/reflect/io/ZipArchive.scala b/src/reflect/scala/reflect/io/ZipArchive.scala
index 3b57721e89..097d3cb71c 100644
--- a/src/reflect/scala/reflect/io/ZipArchive.scala
+++ b/src/reflect/scala/reflect/io/ZipArchive.scala
@@ -20,13 +20,10 @@ import scala.annotation.tailrec
* @author Philippe Altherr (original version)
* @author Paul Phillips (this one)
* @version 2.0,
- *
+ *
* ''Note: This library is considered experimental and should not be used unless you know what you are doing.''
*/
object ZipArchive {
- def fromPath(path: String): FileZipArchive = fromFile(new JFile(path))
- def fromPath(path: Path): FileZipArchive = fromFile(path.toFile)
-
/**
* @param file a File
* @return A ZipArchive if `file` is a readable zip file, otherwise null.
@@ -41,7 +38,6 @@ object ZipArchive {
* @return A ZipArchive backed by the given url.
*/
def fromURL(url: URL): URLZipArchive = new URLZipArchive(url)
- def fromURL(url: String): URLZipArchive = fromURL(new URL(url))
private def dirName(path: String) = splitPath(path, true)
private def baseName(path: String) = splitPath(path, false)
@@ -79,7 +75,6 @@ abstract class ZipArchive(override val file: JFile) extends AbstractFile with Eq
else Iterator(f)
}
}
- def deepIterator = walkIterator(iterator)
/** ''Note: This library is considered experimental and should not be used unless you know what you are doing.'' */
sealed abstract class Entry(path: String) extends VirtualFile(baseName(path), path) {
// have to keep this name for compat with sbt's compiler-interface
diff --git a/src/reflect/scala/reflect/macros/TreeBuilder.scala b/src/reflect/scala/reflect/macros/TreeBuilder.scala
index 204dc40858..fbbbe13201 100644
--- a/src/reflect/scala/reflect/macros/TreeBuilder.scala
+++ b/src/reflect/scala/reflect/macros/TreeBuilder.scala
@@ -11,7 +11,6 @@ abstract class TreeBuilder {
val global: Universe
import global._
- import definitions._
/** Builds a reference to value whose type is given stable prefix.
* The type must be suitable for this. For example, it
diff --git a/src/reflect/scala/reflect/macros/Universe.scala b/src/reflect/scala/reflect/macros/Universe.scala
index 4e76f7c408..31f3192a85 100644
--- a/src/reflect/scala/reflect/macros/Universe.scala
+++ b/src/reflect/scala/reflect/macros/Universe.scala
@@ -114,7 +114,7 @@ abstract class Universe extends scala.reflect.api.Universe {
def setPos(newpos: Position): Tree
/** Sets the `tpe` of the tree. Returns `Unit`. */
- def tpe_=(t: Type): Unit
+ @deprecated("Use setType", "2.11.0") def tpe_=(t: Type): Unit
/** Sets the `tpe` of the tree. Returns the tree itself. */
def setType(tp: Type): Tree
@@ -238,4 +238,4 @@ abstract class Universe extends scala.reflect.api.Universe {
/** The AST that corresponds to this compilation unit. */
def body: Tree
}
-} \ No newline at end of file
+}
diff --git a/src/reflect/scala/reflect/runtime/JavaMirrors.scala b/src/reflect/scala/reflect/runtime/JavaMirrors.scala
index 01e0634902..57cfb8b515 100644
--- a/src/reflect/scala/reflect/runtime/JavaMirrors.scala
+++ b/src/reflect/scala/reflect/runtime/JavaMirrors.scala
@@ -17,12 +17,9 @@ import internal.ClassfileConstants._
import internal.pickling.UnPickler
import scala.collection.mutable.{ HashMap, ListBuffer }
import internal.Flags._
-//import scala.tools.nsc.util.ScalaClassLoader
-//import scala.tools.nsc.util.ScalaClassLoader._
import ReflectionUtils.{staticSingletonInstance, innerSingletonInstance}
import scala.language.existentials
import scala.runtime.{ScalaRunTime, BoxesRunTime}
-import scala.reflect.internal.util.Collections._
private[reflect] trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { thisUniverse: SymbolTable =>
@@ -378,7 +375,7 @@ private[reflect] trait JavaMirrors extends internal.SymbolTable with api.JavaUni
val varargMatch = args.length >= params.length - 1 && isVarArgsList(params)
if (!perfectMatch && !varargMatch) {
val n_arguments = if (isVarArgsList(params)) s"${params.length - 1} or more" else s"${params.length}"
- var s_arguments = if (params.length == 1 && !isVarArgsList(params)) "argument" else "arguments"
+ val s_arguments = if (params.length == 1 && !isVarArgsList(params)) "argument" else "arguments"
throw new ScalaReflectionException(s"${showMethodSig(symbol)} takes $n_arguments $s_arguments")
}
@@ -468,7 +465,7 @@ private[reflect] trait JavaMirrors extends internal.SymbolTable with api.JavaUni
staticSingletonInstance(classLoader, symbol.fullName)
else
if (outer == null) staticSingletonInstance(classToJava(symbol.moduleClass.asClass))
- else innerSingletonInstance(outer, symbol.name)
+ else innerSingletonInstance(outer, symbol.name.toString)
}
override def toString = s"module mirror for ${symbol.fullName} (bound to $outer)"
}
@@ -495,13 +492,10 @@ private[reflect] trait JavaMirrors extends internal.SymbolTable with api.JavaUni
Class.forName(path, true, classLoader)
/** Does `path` correspond to a Java class with that fully qualified name in the current class loader? */
- def tryJavaClass(path: String): Option[jClass[_]] =
- try {
- Some(javaClass(path))
- } catch {
- case (_: ClassNotFoundException) | (_: NoClassDefFoundError) | (_: IncompatibleClassChangeError) =>
- None
- }
+ def tryJavaClass(path: String): Option[jClass[_]] = (
+ try Some(javaClass(path))
+ catch { case ex @ (_: LinkageError | _: ClassNotFoundException) => None } // TODO - log
+ )
/** The mirror that corresponds to the classloader that original defined the given Java class */
def mirrorDefining(jclazz: jClass[_]): JavaMirror = {
@@ -838,20 +832,6 @@ private[reflect] trait JavaMirrors extends internal.SymbolTable with api.JavaUni
}
/**
- * The Scala field corresponding to given Java field.
- * @param jfield The Java field
- * @return A Scala field object that corresponds to `jfield`.
- * // ??? should we return the getter instead?
- */
- def fieldToScala(jfield: jField): TermSymbol =
- toScala(fieldCache, jfield)(_ fieldToScala1 _)
-
- private def fieldToScala1(jfield: jField): TermSymbol = {
- val owner = followStatic(classToScala(jfield.getDeclaringClass), jfield.getModifiers)
- (lookup(owner, jfield.getName) suchThat (!_.isMethod) orElse jfieldAsScala(jfield)).asTerm
- }
-
- /**
* The Scala package corresponding to given Java package
*/
def packageToScala(jpkg: jPackage): ModuleSymbol = packageCache.toScala(jpkg) {
@@ -1043,6 +1023,7 @@ private[reflect] trait JavaMirrors extends internal.SymbolTable with api.JavaUni
val owner = sOwner(jclazz)
val name = scalaSimpleName(jclazz)
val completer = (clazz: Symbol, module: Symbol) => new FromJavaClassCompleter(clazz, module, jclazz)
+
initAndEnterClassAndModule(owner, name, completer)._1
}
@@ -1106,7 +1087,7 @@ private[reflect] trait JavaMirrors extends internal.SymbolTable with api.JavaUni
constructorCache enter (jconstr, constr)
val tparams = jconstr.getTypeParameters.toList map createTypeParameter
val paramtpes = jconstr.getGenericParameterTypes.toList map typeToScala
- setMethType(constr, tparams, paramtpes, clazz.tpe)
+ setMethType(constr, tparams, paramtpes, clazz.tpe_*)
constr setInfo GenPolyType(tparams, MethodType(clazz.newSyntheticValueParams(paramtpes), clazz.tpe))
copyAnnotations(constr, jconstr)
constr
@@ -1114,13 +1095,6 @@ private[reflect] trait JavaMirrors extends internal.SymbolTable with api.JavaUni
// -------------------- Scala to Java -----------------------------------
- /** Optionally, the Java package corresponding to a given Scala package, or None if no such Java package exists.
- * @param pkg The Scala package
- */
- def packageToJavaOption(pkg: ModuleSymbol): Option[jPackage] = packageCache.toJavaOption(pkg) {
- Option(jPackage.getPackage(pkg.fullName.toString))
- }
-
/** The Java class corresponding to given Scala class.
* Note: This only works for
* - top-level classes
diff --git a/src/reflect/scala/reflect/runtime/JavaUniverse.scala b/src/reflect/scala/reflect/runtime/JavaUniverse.scala
index e18435d5b0..a12e7d43d4 100644
--- a/src/reflect/scala/reflect/runtime/JavaUniverse.scala
+++ b/src/reflect/scala/reflect/runtime/JavaUniverse.scala
@@ -1,8 +1,6 @@
package scala.reflect
package runtime
-import internal.{SomePhase, NoPhase, Phase, TreeGen}
-
/** An implementation of [[scala.reflect.api.Universe]] for runtime reflection using JVM classloaders.
*
* Should not be instantiated directly, use [[scala.reflect.runtime.universe]] instead.
@@ -11,13 +9,14 @@ import internal.{SomePhase, NoPhase, Phase, TreeGen}
*/
class JavaUniverse extends internal.SymbolTable with ReflectSetup with runtime.SymbolTable { self =>
- def picklerPhase = SomePhase
+ def picklerPhase = internal.SomePhase
- lazy val settings = new Settings
def forInteractive = false
def forScaladoc = false
+ lazy val settings = new Settings
+ private val isLogging = sys.props contains "scala.debug.reflect"
- def log(msg: => AnyRef): Unit = println(" [] "+msg)
+ def log(msg: => AnyRef): Unit = if (isLogging) Console.err.println("[reflect] " + msg)
type TreeCopier = InternalTreeCopierOps
def newStrictTreeCopier: TreeCopier = new StrictTreeCopier
@@ -25,4 +24,3 @@ class JavaUniverse extends internal.SymbolTable with ReflectSetup with runtime.S
init()
}
-
diff --git a/src/reflect/scala/reflect/runtime/Settings.scala b/src/reflect/scala/reflect/runtime/Settings.scala
index 0e0cf3fc40..7d04202455 100644
--- a/src/reflect/scala/reflect/runtime/Settings.scala
+++ b/src/reflect/scala/reflect/runtime/Settings.scala
@@ -43,6 +43,7 @@ private[reflect] class Settings extends MutableSettings {
val printtypes = new BooleanSetting(false)
val uniqid = new BooleanSetting(false)
val verbose = new BooleanSetting(false)
+ val breakCycles = new BooleanSetting(false)
val Yrecursion = new IntSetting(0)
val maxClassfileName = new IntSetting(255)
diff --git a/src/reflect/scala/reflect/runtime/SymbolLoaders.scala b/src/reflect/scala/reflect/runtime/SymbolLoaders.scala
index 311db64b91..ea14e8ad43 100644
--- a/src/reflect/scala/reflect/runtime/SymbolLoaders.scala
+++ b/src/reflect/scala/reflect/runtime/SymbolLoaders.scala
@@ -28,7 +28,7 @@ private[reflect] trait SymbolLoaders { self: SymbolTable =>
debugInfo("completing "+sym+"/"+clazz.fullName)
assert(sym == clazz || sym == module || sym == module.moduleClass)
// try {
- atPhaseNotLaterThan(picklerPhase) {
+ enteringPhaseNotLaterThan(picklerPhase) {
val loadingMirror = mirrorThatLoaded(sym)
val javaClass = loadingMirror.javaClass(clazz.javaClassName)
loadingMirror.unpickleClass(clazz, module, javaClass)
@@ -116,7 +116,7 @@ private[reflect] trait SymbolLoaders { self: SymbolTable =>
currentMirror.tryJavaClass(path) match {
case Some(cls) =>
val loadingMirror = currentMirror.mirrorDefining(cls)
- val (clazz, module) =
+ val (_, module) =
if (loadingMirror eq currentMirror) {
initAndEnterClassAndModule(pkgClass, name.toTypeName, new TopClassCompleter(_, _))
} else {
diff --git a/src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala b/src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala
index 00f6952dc1..1154927279 100644
--- a/src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala
+++ b/src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala
@@ -83,9 +83,6 @@ private[reflect] trait SynchronizedSymbols extends internal.Symbols { self: Symb
override protected def createPackageObjectClassSymbol(pos: Position, newFlags: Long): PackageObjectClassSymbol =
new PackageObjectClassSymbol(this, pos) with SynchronizedClassSymbol initFlags newFlags
- override protected def createTermSymbol(name: TermName, pos: Position, newFlags: Long): TermSymbol =
- new TermSymbol(this, pos, name) with SynchronizedTermSymbol initFlags newFlags
-
override protected def createMethodSymbol(name: TermName, pos: Position, newFlags: Long): MethodSymbol =
new MethodSymbol(this, pos, name) with SynchronizedMethodSymbol initFlags newFlags
@@ -118,7 +115,8 @@ private[reflect] trait SynchronizedSymbols extends internal.Symbols { self: Symb
override def name_=(x: Name) = synchronized { super.name_=(x) }
override def rawname = synchronized { super.rawname }
override def typeConstructor: Type = synchronized { super.typeConstructor }
- override def tpe: Type = synchronized { super.tpe }
+ override def tpe_* : Type = synchronized { super.tpe_* }
+ override def tpeHK : Type = synchronized { super.tpeHK }
}
trait SynchronizedClassSymbol extends ClassSymbol with SynchronizedTypeSymbol {
diff --git a/src/reflect/scala/reflect/runtime/package.scala b/src/reflect/scala/reflect/runtime/package.scala
index b97913daf0..eadbc0c52e 100644
--- a/src/reflect/scala/reflect/runtime/package.scala
+++ b/src/reflect/scala/reflect/runtime/package.scala
@@ -6,7 +6,7 @@ package scala.reflect
package object runtime {
/** The entry point into Scala runtime reflection.
- *
+ *
* To use Scala runtime reflection, simply use or import `scala.reflect.runtime.universe._`
*
* See [[scala.reflect.api.Universe]] or the
diff --git a/src/scalacheck/org/scalacheck/Commands.scala b/src/scalacheck/org/scalacheck/Commands.scala
index 88ef8ae2a1..2acc460b5e 100644
--- a/src/scalacheck/org/scalacheck/Commands.scala
+++ b/src/scalacheck/org/scalacheck/Commands.scala
@@ -87,11 +87,6 @@ trait Commands extends Prop {
private val bindings = new scala.collection.mutable.ListBuffer[(State,Any)]
- private def initState() = {
- bindings.clear()
- initialState()
- }
-
private def genCmds: Gen[Cmds] = {
def sizedCmds(s: State)(sz: Int): Gen[Cmds] =
if(sz <= 0) value(Cmds(Nil, Nil)) else for {
diff --git a/src/scalap/scala/tools/scalap/Arguments.scala b/src/scalap/scala/tools/scalap/Arguments.scala
index a151e3067e..9f139cb5ea 100644
--- a/src/scalap/scala/tools/scalap/Arguments.scala
+++ b/src/scalap/scala/tools/scalap/Arguments.scala
@@ -87,7 +87,7 @@ object Arguments {
i += 2
}
} else {
- var iter = prefixes.iterator
+ val iter = prefixes.iterator
val j = i
while ((i == j) && iter.hasNext) {
val prefix = iter.next
diff --git a/src/scalap/scala/tools/scalap/scalax/rules/Rule.scala b/src/scalap/scala/tools/scalap/scalax/rules/Rule.scala
index 1500b81050..489a05ecd0 100644
--- a/src/scalap/scala/tools/scalap/scalax/rules/Rule.scala
+++ b/src/scalap/scala/tools/scalap/scalax/rules/Rule.scala
@@ -50,7 +50,7 @@ trait Rule[-In, +Out, +A, +X] extends (In => Result[Out, A, X]) {
lazy val choices = Rule.this :: other :: Nil
}
- def orError[In2 <: In] = this orElse(error[In2])
+ def orError[In2 <: In] = this orElse error[Any]
def |[In2 <: In, Out2 >: Out, A2 >: A, X2 >: X](other : => Rule[In2, Out2, A2, X2]) = orElse(other)
diff --git a/src/scalap/scala/tools/scalap/scalax/rules/scalasig/ScalaSig.scala b/src/scalap/scala/tools/scalap/scalax/rules/scalasig/ScalaSig.scala
index aa5acbb06d..fd70e0de35 100644
--- a/src/scalap/scala/tools/scalap/scalax/rules/scalasig/ScalaSig.scala
+++ b/src/scalap/scala/tools/scalap/scalax/rules/scalasig/ScalaSig.scala
@@ -167,57 +167,10 @@ object ScalaSigEntryParsers extends RulesWithState with MemoisableRules {
val symbolInfo = nameRef ~ symbolRef ~ nat ~ (symbolRef?) ~ ref ~ get ^~~~~~^ SymbolInfo
- def symHeader(key: Int) = (key -~ none | (key + 64) -~ nat)
+ def symHeader(key: Int): EntryParser[Any] = (key -~ none | (key + 64) -~ nat)
def symbolEntry(key : Int) = symHeader(key) -~ symbolInfo
- /***************************************************
- * Symbol table attribute format:
- * Symtab = nentries_Nat {Entry}
- * Entry = 1 TERMNAME len_Nat NameInfo
- * | 2 TYPENAME len_Nat NameInfo
- * | 3 NONEsym len_Nat
- * | 4 TYPEsym len_Nat SymbolInfo
- * | 5 ALIASsym len_Nat SymbolInfo
- * | 6 CLASSsym len_Nat SymbolInfo [thistype_Ref]
- * | 7 MODULEsym len_Nat SymbolInfo
- * | 8 VALsym len_Nat [defaultGetter_Ref /* no longer needed*/] SymbolInfo [alias_Ref]
- * | 9 EXTref len_Nat name_Ref [owner_Ref]
- * | 10 EXTMODCLASSref len_Nat name_Ref [owner_Ref]
- * | 11 NOtpe len_Nat
- * | 12 NOPREFIXtpe len_Nat
- * | 13 THIStpe len_Nat sym_Ref
- * | 14 SINGLEtpe len_Nat type_Ref sym_Ref
- * | 15 CONSTANTtpe len_Nat constant_Ref
- * | 16 TYPEREFtpe len_Nat type_Ref sym_Ref {targ_Ref}
- * | 17 TYPEBOUNDStpe len_Nat tpe_Ref tpe_Ref
- * | 18 REFINEDtpe len_Nat classsym_Ref {tpe_Ref}
- * | 19 CLASSINFOtpe len_Nat classsym_Ref {tpe_Ref}
- * | 20 METHODtpe len_Nat tpe_Ref {sym_Ref}
- * | 21 POLYTtpe len_Nat tpe_Ref {sym_Ref}
- * | 22 IMPLICITMETHODtpe len_Nat tpe_Ref {sym_Ref} /* no longer needed */
- * | 52 SUPERtpe len_Nat tpe_Ref tpe_Ref
- * | 24 LITERALunit len_Nat
- * | 25 LITERALboolean len_Nat value_Long
- * | 26 LITERALbyte len_Nat value_Long
- * | 27 LITERALshort len_Nat value_Long
- * | 28 LITERALchar len_Nat value_Long
- * | 29 LITERALint len_Nat value_Long
- * | 30 LITERALlong len_Nat value_Long
- * | 31 LITERALfloat len_Nat value_Long
- * | 32 LITERALdouble len_Nat value_Long
- * | 33 LITERALstring len_Nat name_Ref
- * | 34 LITERALnull len_Nat
- * | 35 LITERALclass len_Nat tpe_Ref
- * | 36 LITERALenum len_Nat sym_Ref
- * | 40 SYMANNOT len_Nat sym_Ref AnnotInfoBody
- * | 41 CHILDREN len_Nat sym_Ref {sym_Ref}
- * | 42 ANNOTATEDtpe len_Nat [sym_Ref /* no longer needed */] tpe_Ref {annotinfo_Ref}
- * | 43 ANNOTINFO len_Nat AnnotInfoBody
- * | 44 ANNOTARGARRAY len_Nat {constAnnotArg_Ref}
- * | 47 DEBRUIJNINDEXtpe len_Nat level_Nat index_Nat
- * | 48 EXISTENTIALtpe len_Nat type_Ref {symbol_Ref}
- */
val noSymbol = 3 -^ NoSymbol
val typeSymbol = symbolEntry(4) ^^ TypeSymbol as "typeSymbol"
val aliasSymbol = symbolEntry(5) ^^ AliasSymbol as "alias"
@@ -260,10 +213,9 @@ object ScalaSigEntryParsers extends RulesWithState with MemoisableRules {
22 -~ typeRef ~ (symbolRef*) ^~^ MethodType,
42 -~ typeRef ~ (attribTreeRef*) ^~^ AnnotatedType,
51 -~ typeRef ~ symbolRef ~ (attribTreeRef*) ^~~^ AnnotatedWithSelfType,
- 47 -~ typeLevel ~ typeIndex ^~^ DeBruijnIndexType,
48 -~ typeRef ~ (symbolRef*) ^~^ ExistentialType) as "type"
- lazy val literal = oneOf(
+ lazy val literal: EntryParser[Any] = oneOf(
24 -^ (()),
25 -~ longValue ^^ (_ != 0L),
26 -~ longValue ^^ (_.toByte),
diff --git a/src/scalap/scala/tools/scalap/scalax/rules/scalasig/ScalaSigPrinter.scala b/src/scalap/scala/tools/scalap/scalax/rules/scalasig/ScalaSigPrinter.scala
index cfe615a6d5..e5a4ff649e 100644
--- a/src/scalap/scala/tools/scalap/scalax/rules/scalasig/ScalaSigPrinter.scala
+++ b/src/scalap/scala/tools/scalap/scalax/rules/scalasig/ScalaSigPrinter.scala
@@ -70,7 +70,7 @@ class ScalaSigPrinter(stream: PrintStream, printPrivates: Boolean) {
}
def isCaseClassObject(o: ObjectSymbol): Boolean = {
- val TypeRefType(prefix, classSymbol: ClassSymbol, typeArgs) = o.infoType
+ val TypeRefType(_, classSymbol: ClassSymbol, _) = o.infoType
o.isFinal && (classSymbol.children.find(x => x.isCase && x.isInstanceOf[MethodSymbol]) match {
case Some(_) => true
case None => false
@@ -167,7 +167,7 @@ class ScalaSigPrinter(stream: PrintStream, printPrivates: Boolean) {
print("object ")
val poName = o.symbolInfo.owner.name
print(processName(poName))
- val TypeRefType(prefix, classSymbol: ClassSymbol, typeArgs) = o.infoType
+ val TypeRefType(_, classSymbol: ClassSymbol, _) = o.infoType
printType(classSymbol)
print(" {\n")
printChildren(level, classSymbol)
@@ -179,7 +179,7 @@ class ScalaSigPrinter(stream: PrintStream, printPrivates: Boolean) {
printModifiers(o)
print("object ")
print(processName(o.name))
- val TypeRefType(prefix, classSymbol: ClassSymbol, typeArgs) = o.infoType
+ val TypeRefType(_, classSymbol: ClassSymbol, _) = o.infoType
printType(classSymbol)
print(" {\n")
printChildren(level, classSymbol)
@@ -191,7 +191,7 @@ class ScalaSigPrinter(stream: PrintStream, printPrivates: Boolean) {
val j = str.indexOf("[")
if (j > 0) str = str.substring(0, j)
str = StringUtil.trimStart(str, "=> ")
- var i = str.lastIndexOf(".")
+ val i = str.lastIndexOf(".")
val res = if (i > 0) str.substring(i + 1) else str
if (res.length > 1) StringUtil.decapitalize(res.substring(0, 1)) else res.toLowerCase
})
@@ -381,7 +381,6 @@ class ScalaSigPrinter(stream: PrintStream, printPrivates: Boolean) {
toString(typeRef, sep)
}
case AnnotatedWithSelfType(typeRef, symbol, attribTreeRefs) => toString(typeRef, sep)
- //case DeBruijnIndexType(typeLevel, typeIndex) =>
case ExistentialType(typeRef, symbols) => {
val refs = symbols.map(toString _).filter(!_.startsWith("_")).map("type " + _)
toString(typeRef, sep) + (if (refs.size > 0) refs.mkString(" forSome {", "; ", "}") else "")
diff --git a/src/scalap/scala/tools/scalap/scalax/rules/scalasig/Type.scala b/src/scalap/scala/tools/scalap/scalax/rules/scalasig/Type.scala
index 543ddbe186..0444e701f2 100644
--- a/src/scalap/scala/tools/scalap/scalax/rules/scalasig/Type.scala
+++ b/src/scalap/scala/tools/scalap/scalax/rules/scalasig/Type.scala
@@ -22,5 +22,4 @@ case class PolyType(typeRef : Type, symbols : Seq[TypeSymbol]) extends Type
case class PolyTypeWithCons(typeRef : Type, symbols : Seq[TypeSymbol], cons: String) extends Type
case class AnnotatedType(typeRef : Type, attribTreeRefs : List[Int]) extends Type
case class AnnotatedWithSelfType(typeRef : Type, symbol : Symbol, attribTreeRefs : List[Int]) extends Type
-case class DeBruijnIndexType(typeLevel : Int, typeIndex : Int) extends Type
case class ExistentialType(typeRef : Type, symbols : Seq[Symbol]) extends Type
diff --git a/src/swing/scala/swing/Button.scala b/src/swing/scala/swing/Button.scala
index f10d49d804..0170727e3b 100644
--- a/src/swing/scala/swing/Button.scala
+++ b/src/swing/scala/swing/Button.scala
@@ -6,11 +6,8 @@
** |/ **
\* */
-
-
package scala.swing
-import event._
import javax.swing._
object Button {
diff --git a/src/swing/scala/swing/ButtonGroup.scala b/src/swing/scala/swing/ButtonGroup.scala
index 2075df7c92..0b04d20837 100644
--- a/src/swing/scala/swing/ButtonGroup.scala
+++ b/src/swing/scala/swing/ButtonGroup.scala
@@ -8,9 +8,7 @@
package scala.swing
-import event._
-import javax.swing.{AbstractButton => JAbstractButton,Icon}
-import scala.collection.{ mutable, immutable }
+import scala.collection.mutable
/**
* A button mutex. At most one of its associated buttons is selected
diff --git a/src/swing/scala/swing/ComboBox.scala b/src/swing/scala/swing/ComboBox.scala
index 5b70f6fda9..ce2b3ba6fb 100644
--- a/src/swing/scala/swing/ComboBox.scala
+++ b/src/swing/scala/swing/ComboBox.scala
@@ -182,7 +182,7 @@ class ComboBox[A](items: Seq[A]) extends Component with Publisher {
* of the component to its own defaults _after_ the renderer has been
* configured. That's Swing's principle of most suprise.
*/
- def renderer: ListView.Renderer[A] = ListView.Renderer.wrap(peer.getRenderer)
+ def renderer: ListView.Renderer[A] = ListView.Renderer.wrap[A](peer.getRenderer)
def renderer_=(r: ListView.Renderer[A]) { peer.setRenderer(r.peer) }
/* XXX: currently not safe to expose:
diff --git a/src/swing/scala/swing/EditorPane.scala b/src/swing/scala/swing/EditorPane.scala
index b8c506daf0..9b1aab7874 100644
--- a/src/swing/scala/swing/EditorPane.scala
+++ b/src/swing/scala/swing/EditorPane.scala
@@ -6,13 +6,10 @@
** |/ **
\* */
-
package scala.swing
-import event._
import javax.swing._
import javax.swing.text._
-import java.awt.event._
/**
* A text component that allows multiline text input and display.
diff --git a/src/swing/scala/swing/Font.scala.disabled b/src/swing/scala/swing/Font.scala.disabled
deleted file mode 100644
index 9e21eb859c..0000000000
--- a/src/swing/scala/swing/Font.scala.disabled
+++ /dev/null
@@ -1,70 +0,0 @@
-package scala.swing
-
-/*object Font {
- def apply(fontFormat: Int, fontFile: java.io.File) = java.awt.Font.createFont(fontFormat, fontFile)
- def apply(fontFormat: Int, fontStream: java.io.InputStream) = java.awt.Font.createFont(fontFormat, fontStream)
- def decode(str: String) = java.awt.Font.decode(str)
-
- /* TODO: finish implementation
- /**
- * See [java.awt.Font.getFont].
- */
- def get(attributes: Map[_ <: java.text.AttributedCharacterIterator.Attribute, _]) =
- java.awt.Font.getFont(ImmutableMapWrapper(attributes))
-
- import java.{util => ju}
- private case class ImmutableMapWrapper[A, B](underlying : Map[A, B])(t : ClassTag[A]) extends ju.AbstractMap[A, B] {
- self =>
- override def size = underlying.size
-
- override def put(k : A, v : B) =
- throw new UnsupportedOperationException("This is a wrapper that does not support mutation")
- override def remove(k : AnyRef) =
- throw new UnsupportedOperationException("This is a wrapper that does not support mutation")
-
- override def entrySet : ju.Set[ju.Map.Entry[A, B]] = new ju.AbstractSet[ju.Map.Entry[A, B]] {
- def size = self.size
-
- def iterator = new ju.Iterator[ju.Map.Entry[A, B]] {
- val ui = underlying.iterator
- var prev : Option[A] = None
-
- def hasNext = ui.hasNext
-
- def next = {
- val (k, v) = ui.next
- prev = Some(k)
- new ju.Map.Entry[A, B] {
- def getKey = k
- def getValue = v
- def setValue(v1 : B) = self.put(k, v1)
- override def equals(other : Any) = other match {
- case e : ju.Map.Entry[_, _] => k == e.getKey && v == e.getValue
- case _ => false
- }
- }
- }
-
- def remove = prev match {
- case Some(k) => val v = self.remove(k.asInstanceOf[AnyRef]) ; prev = None ; v
- case _ => throw new IllegalStateException("next must be called at least once before remove")
- }
- }
- }
- }
- */
-
- /**
- * See [java.awt.Font.getFont].
- */
- def get(nm: String) = java.awt.Font.getFont(nm)
- /**
- * See [java.awt.Font.getFont].
- */
- def get(nm: String, font: Font) = java.awt.Font.getFont(nm, font)
-
- def Insets(x: Int, y: Int, width: Int, height: Int) = new Insets(x, y, width, height)
- def Rectangle(x: Int, y: Int, width: Int, height: Int) = new Insets(x, y, width, height)
- def Point(x: Int, y: Int) = new Point(x, y)
- def Dimension(x: Int, y: Int) = new Dimension(x, y)
-}*/ \ No newline at end of file
diff --git a/src/swing/scala/swing/FormattedTextField.scala b/src/swing/scala/swing/FormattedTextField.scala
index 311ff42d0a..b08075850c 100644
--- a/src/swing/scala/swing/FormattedTextField.scala
+++ b/src/swing/scala/swing/FormattedTextField.scala
@@ -6,13 +6,9 @@
** |/ **
\* */
-
-
package scala.swing
-import event._
import javax.swing._
-import java.awt.event._
object FormattedTextField {
/**
diff --git a/src/swing/scala/swing/ListView.scala b/src/swing/scala/swing/ListView.scala
index 40639aa9e2..d0c4e45190 100644
--- a/src/swing/scala/swing/ListView.scala
+++ b/src/swing/scala/swing/ListView.scala
@@ -216,7 +216,7 @@ class ListView[A] extends Component {
def adjusting = peer.getSelectionModel.getValueIsAdjusting
}
- def renderer: ListView.Renderer[A] = ListView.Renderer.wrap(peer.getCellRenderer)
+ def renderer: ListView.Renderer[A] = ListView.Renderer.wrap[A](peer.getCellRenderer)
def renderer_=(r: ListView.Renderer[A]) { peer.setCellRenderer(r.peer) }
def fixedCellWidth = peer.getFixedCellWidth
diff --git a/src/swing/scala/swing/MainFrame.scala b/src/swing/scala/swing/MainFrame.scala
index 85ce0755ac..1dfc155f9c 100644
--- a/src/swing/scala/swing/MainFrame.scala
+++ b/src/swing/scala/swing/MainFrame.scala
@@ -6,12 +6,8 @@
** |/ **
\* */
-
-
package scala.swing
-import event._
-
/**
* A frame that can be used for main application windows. Shuts down the
* framework and quits the application when closed.
diff --git a/src/swing/scala/swing/PasswordField.scala b/src/swing/scala/swing/PasswordField.scala
index d2fdd0d38a..fd0b586a0f 100644
--- a/src/swing/scala/swing/PasswordField.scala
+++ b/src/swing/scala/swing/PasswordField.scala
@@ -6,13 +6,9 @@
** |/ **
\* */
-
-
package scala.swing
-import event._
import javax.swing._
-import java.awt.event._
/**
* A password field, that displays a replacement character for each character in the password.
diff --git a/src/swing/scala/swing/ProgressBar.scala b/src/swing/scala/swing/ProgressBar.scala
index 33dd716524..81e2989c3e 100644
--- a/src/swing/scala/swing/ProgressBar.scala
+++ b/src/swing/scala/swing/ProgressBar.scala
@@ -6,12 +6,8 @@
** |/ **
\* */
-
-
package scala.swing
-import event._
-
/**
* A bar indicating progress of some action. Can be in indeterminate mode,
* in which it indicates that the action is in progress (usually by some
diff --git a/src/swing/scala/swing/Reactions.scala b/src/swing/scala/swing/Reactions.scala
index d8a62aa99d..c32212cf3a 100644
--- a/src/swing/scala/swing/Reactions.scala
+++ b/src/swing/scala/swing/Reactions.scala
@@ -14,8 +14,6 @@ import event.Event
import scala.collection.mutable.{Buffer, ListBuffer}
object Reactions {
- import scala.ref._
-
class Impl extends Reactions {
private val parts: Buffer[Reaction] = new ListBuffer[Reaction]
def isDefinedAt(e: Event) = parts.exists(_ isDefinedAt e)
diff --git a/src/swing/scala/swing/SplitPane.scala b/src/swing/scala/swing/SplitPane.scala
index dd4f2908d5..f61dfedbf4 100644
--- a/src/swing/scala/swing/SplitPane.scala
+++ b/src/swing/scala/swing/SplitPane.scala
@@ -6,11 +6,8 @@
** |/ **
\* */
-
-
package scala.swing
-import event._
import Swing._
/**
diff --git a/src/swing/scala/swing/SwingActor.scala b/src/swing/scala/swing/SwingActor.scala
index 6692180aac..c665fa4c00 100644
--- a/src/swing/scala/swing/SwingActor.scala
+++ b/src/swing/scala/swing/SwingActor.scala
@@ -6,12 +6,8 @@
** |/ **
\* */
-
-
package scala.swing
-import scala.actors._
-
// Dummy to keep ant from recompiling on every run.
trait SwingActor { }
diff --git a/src/swing/scala/swing/TabbedPane.scala b/src/swing/scala/swing/TabbedPane.scala
index 338050515a..6e46256f86 100644
--- a/src/swing/scala/swing/TabbedPane.scala
+++ b/src/swing/scala/swing/TabbedPane.scala
@@ -112,9 +112,6 @@ class TabbedPane extends Component with Publisher {
*/
def tabPlacement_=(b: Alignment.Value) { peer.setTabPlacement(b.id) }
- @deprecated("Use tabPlacement_=() instead.", "2.9.1")
- def tabPlacement(b: Alignment.Value) { peer.setTabPlacement(b.id) }
-
/**
* The current page selection
*/
diff --git a/src/swing/scala/swing/TextArea.scala b/src/swing/scala/swing/TextArea.scala
index 01bf115d28..2f6bdca119 100644
--- a/src/swing/scala/swing/TextArea.scala
+++ b/src/swing/scala/swing/TextArea.scala
@@ -6,13 +6,9 @@
** |/ **
\* */
-
-
package scala.swing
-import event._
import javax.swing._
-import java.awt.event._
/**
* A text component that allows multiline text input and display.
diff --git a/src/swing/scala/swing/TextComponent.scala b/src/swing/scala/swing/TextComponent.scala
index 48c03a5f54..4d23399737 100644
--- a/src/swing/scala/swing/TextComponent.scala
+++ b/src/swing/scala/swing/TextComponent.scala
@@ -6,12 +6,9 @@
** |/ **
\* */
-
-
package scala.swing
import event._
-import javax.swing._
import javax.swing.text._
import javax.swing.event._
diff --git a/src/swing/scala/swing/ToggleButton.scala b/src/swing/scala/swing/ToggleButton.scala
index 3d3d0b957f..8f210d00d8 100644
--- a/src/swing/scala/swing/ToggleButton.scala
+++ b/src/swing/scala/swing/ToggleButton.scala
@@ -6,11 +6,8 @@
** |/ **
\* */
-
-
package scala.swing
-import event._
import javax.swing._
/**
diff --git a/src/swing/scala/swing/Window.scala b/src/swing/scala/swing/Window.scala
index 5bdb50e959..a9f4ae7538 100644
--- a/src/swing/scala/swing/Window.scala
+++ b/src/swing/scala/swing/Window.scala
@@ -6,13 +6,10 @@
** |/ **
\* */
-
-
package scala.swing
import java.awt.{Window => AWTWindow}
import event._
-import javax.swing._
/**
* A window with decoration such as a title, border, and action buttons.
diff --git a/test/attic/files/cli/test1/Main.check.j9vm5 b/test/attic/files/cli/test1/Main.check.j9vm5
deleted file mode 100644
index de454ef478..0000000000
--- a/test/attic/files/cli/test1/Main.check.j9vm5
+++ /dev/null
@@ -1,4 +0,0 @@
-env: -cpp: No such file or directory
-env: test1.Main: No such file or directory
-env: -cp: No such file or directory
-1: test 3 passed
diff --git a/test/attic/files/cli/test1/Main.check.java b/test/attic/files/cli/test1/Main.check.java
deleted file mode 100644
index 64410de98f..0000000000
--- a/test/attic/files/cli/test1/Main.check.java
+++ /dev/null
@@ -1,6 +0,0 @@
-Unrecognized option: -cpp
-Could not create the Java virtual machine.
-1: test 1 passed (1)
-1: test 2 passed (1)
-1: test 3 passed (1)
-1: test 4 passed (2)
diff --git a/test/attic/files/cli/test1/Main.check.java5 b/test/attic/files/cli/test1/Main.check.java5
deleted file mode 100644
index 64410de98f..0000000000
--- a/test/attic/files/cli/test1/Main.check.java5
+++ /dev/null
@@ -1,6 +0,0 @@
-Unrecognized option: -cpp
-Could not create the Java virtual machine.
-1: test 1 passed (1)
-1: test 2 passed (1)
-1: test 3 passed (1)
-1: test 4 passed (2)
diff --git a/test/attic/files/cli/test1/Main.check.java5_api b/test/attic/files/cli/test1/Main.check.java5_api
deleted file mode 100644
index 8693a5d92f..0000000000
--- a/test/attic/files/cli/test1/Main.check.java5_api
+++ /dev/null
@@ -1,19 +0,0 @@
-|-- allclasses-frame.html
-|-- allclasses-noframe.html
-|-- constant-values.html
-|-- deprecated-list.html
-|-- help-doc.html
-|-- index-all.html
-|-- index.html
-|-- overview-tree.html
-|-- package-list
-|-- resources
-| `-- inherit.gif
-|-- stylesheet.css
-`-- test1
- |-- Main.html
- |-- package-frame.html
- |-- package-summary.html
- `-- package-tree.html
-
-2 directories, 15 files
diff --git a/test/attic/files/cli/test1/Main.check.java5_j9 b/test/attic/files/cli/test1/Main.check.java5_j9
deleted file mode 100644
index de454ef478..0000000000
--- a/test/attic/files/cli/test1/Main.check.java5_j9
+++ /dev/null
@@ -1,4 +0,0 @@
-env: -cpp: No such file or directory
-env: test1.Main: No such file or directory
-env: -cp: No such file or directory
-1: test 3 passed
diff --git a/test/attic/files/cli/test1/Main.check.javac b/test/attic/files/cli/test1/Main.check.javac
deleted file mode 100644
index ba25d9b6ca..0000000000
--- a/test/attic/files/cli/test1/Main.check.javac
+++ /dev/null
@@ -1,19 +0,0 @@
-javac: invalid flag: -dd
-Usage: javac <options> <source files>
-where possible options include:
- -g Generate all debugging info
- -g:none Generate no debugging info
- -g:{lines,vars,source} Generate only some debugging info
- -nowarn Generate no warnings
- -verbose Output messages about what the compiler is doing
- -deprecation Output source locations where deprecated APIs are used
- -classpath <path> Specify where to find user class files
- -sourcepath <path> Specify where to find input source files
- -bootclasspath <path> Override location of bootstrap class files
- -extdirs <dirs> Override location of installed extensions
- -d <directory> Specify where to place generated class files
- -encoding <encoding> Specify character encoding used by source files
- -source <release> Provide source compatibility with specified release
- -target <release> Generate class files for specific VM version
- -help Print a synopsis of standard options
-
diff --git a/test/attic/files/cli/test1/Main.check.javac5 b/test/attic/files/cli/test1/Main.check.javac5
deleted file mode 100644
index 0cb29d31ff..0000000000
--- a/test/attic/files/cli/test1/Main.check.javac5
+++ /dev/null
@@ -1,24 +0,0 @@
-javac: invalid flag: -dd
-Usage: javac <options> <source files>
-where possible options include:
- -g Generate all debugging info
- -g:none Generate no debugging info
- -g:{lines,vars,source} Generate only some debugging info
- -nowarn Generate no warnings
- -verbose Output messages about what the compiler is doing
- -deprecation Output source locations where deprecated APIs are used
- -classpath <path> Specify where to find user class files
- -cp <path> Specify where to find user class files
- -sourcepath <path> Specify where to find input source files
- -bootclasspath <path> Override location of bootstrap class files
- -extdirs <dirs> Override location of installed extensions
- -endorseddirs <dirs> Override location of endorsed standards path
- -d <directory> Specify where to place generated class files
- -encoding <encoding> Specify character encoding used by source files
- -source <release> Provide source compatibility with specified release
- -target <release> Generate class files for specific VM version
- -version Version information
- -help Print a synopsis of standard options
- -X Print a synopsis of nonstandard options
- -J<flag> Pass <flag> directly to the runtime system
-
diff --git a/test/attic/files/cli/test1/Main.check.javac6 b/test/attic/files/cli/test1/Main.check.javac6
deleted file mode 100644
index 8f37a05bcb..0000000000
--- a/test/attic/files/cli/test1/Main.check.javac6
+++ /dev/null
@@ -1,29 +0,0 @@
-javac: invalid flag: -dd
-Usage: javac <options> <source files>
-where possible options include:
- -g Generate all debugging info
- -g:none Generate no debugging info
- -g:{lines,vars,source} Generate only some debugging info
- -nowarn Generate no warnings
- -verbose Output messages about what the compiler is doing
- -deprecation Output source locations where deprecated APIs are used
- -classpath <path> Specify where to find user class files and annotation processors
- -cp <path> Specify where to find user class files and annotation processors
- -sourcepath <path> Specify where to find input source files
- -bootclasspath <path> Override location of bootstrap class files
- -extdirs <dirs> Override location of installed extensions
- -endorseddirs <dirs> Override location of endorsed standards path
- -proc:{none, only} Control whether annotation processing and/or compilation is done.
- -processor <class> Name of the annotation processor to run; bypasses default discovery process
- -processorpath <path> Specify where to find annotation processors
- -d <directory> Specify where to place generated class files
- -s <directory> Specify where to place generated source files
- -encoding <encoding> Specify character encoding used by source files
- -source <release> Provide source compatibility with specified release
- -target <release> Generate class files for specific VM version
- -version Version information
- -help Print a synopsis of standard options
- -A[key[=value]] Options to pass to annotation processors
- -X Print a synopsis of nonstandard options
- -J<flag> Pass <flag> directly to the runtime system
-
diff --git a/test/attic/files/cli/test1/Main.check.jikes b/test/attic/files/cli/test1/Main.check.jikes
deleted file mode 100644
index cd891689db..0000000000
--- a/test/attic/files/cli/test1/Main.check.jikes
+++ /dev/null
@@ -1,3 +0,0 @@
-Error: "-dd" is an invalid option.
-use: jikes [options] [@files] file.java...
-For more help, try -help or -version.
diff --git a/test/attic/files/cli/test1/Main.check.jikes5 b/test/attic/files/cli/test1/Main.check.jikes5
deleted file mode 100644
index cd891689db..0000000000
--- a/test/attic/files/cli/test1/Main.check.jikes5
+++ /dev/null
@@ -1,3 +0,0 @@
-Error: "-dd" is an invalid option.
-use: jikes [options] [@files] file.java...
-For more help, try -help or -version.
diff --git a/test/attic/files/cli/test1/Main.check.scala b/test/attic/files/cli/test1/Main.check.scala
deleted file mode 100644
index 43b200ae02..0000000000
--- a/test/attic/files/cli/test1/Main.check.scala
+++ /dev/null
@@ -1,24 +0,0 @@
-unknown option: '-cpp'
-scala [ <option> ]... [<torun> <arguments>]
-
-All options to scalac are allowed. See scalac -help.
-
-<torun>, if present, is an object or script file to run.
-If no <torun> is present, run an interactive interpreter.
-
-Option -howtorun allows explicitly specifying how to run <torun>:
- script: it is a script file
- object: it is an object name
- guess: (the default) try to guess
-
-Option -savecompiled requests that the compiled script be saved
-for future use.
-
-Option -nocompdaemon requests that the fsc offline compiler not be used.
-
-Option -Dproperty=value sets a Java system property.
-
-1: test 1 passed (1)
-1: test 2 passed (1)
-1: test 3 passed (1)
-1: test 4 passed (2)
diff --git a/test/attic/files/cli/test1/Main.check.scala_api b/test/attic/files/cli/test1/Main.check.scala_api
deleted file mode 100644
index 6fac39d3f0..0000000000
--- a/test/attic/files/cli/test1/Main.check.scala_api
+++ /dev/null
@@ -1,33 +0,0 @@
-|-- all-classes.html
-|-- index.html
-|-- modules.html
-|-- nav-classes.html
-|-- root-content.html
-|-- scala
-| |-- Any.html
-| |-- AnyRef.html
-| |-- AnyVal.html
-| |-- Boolean.html
-| |-- Byte.html
-| |-- Char.html
-| |-- Double.html
-| |-- Float.html
-| |-- Int.html
-| |-- Long.html
-| |-- Nothing.html
-| |-- Null.html
-| |-- Short.html
-| |-- Unit.html
-| `-- runtime
-| |-- BoxedFloat.html
-| |-- BoxedInt.html
-| |-- BoxedLong.html
-| `-- BoxedNumber.html
-|-- script.js
-|-- style.css
-|-- test1
-| `-- Main$object.html
-|-- test1$content.html
-`-- test1$package.html
-
-3 directories, 28 files
diff --git a/test/attic/files/cli/test1/Main.check.scala_j9 b/test/attic/files/cli/test1/Main.check.scala_j9
deleted file mode 100644
index 65d5ddaac4..0000000000
--- a/test/attic/files/cli/test1/Main.check.scala_j9
+++ /dev/null
@@ -1,15 +0,0 @@
-unknown option: '-cpp'
-scala [ <compiler-option> | -howtorun:how ]... [<torun> <arguments>]
-
-<compiler-option>'s are as for scalac; see scalac -help.
-<torun>, if present, is an object or script file to run.
-If no <torun> is present, run an interactive interpreter.
--howtorun allows explicitly specifying how to run <torun>:
- script: it is a script file
- object: it is an object name
- guess: (the default) try to guess
-
-1: test 1 passed (1)
-1: test 2 passed (1)
-1: test 3 passed (1)
-1: test 4 passed (2)
diff --git a/test/attic/files/cli/test1/Main.check.scalac b/test/attic/files/cli/test1/Main.check.scalac
deleted file mode 100644
index 8465810d0b..0000000000
--- a/test/attic/files/cli/test1/Main.check.scalac
+++ /dev/null
@@ -1,63 +0,0 @@
-scalac error: bad option: '-dd'
- scalac -help gives more information
-Usage: scalac <options | source files>
-where possible options include:
- -doc Generate documentation
- -g:<g> Generate debugging info (none,source,line,vars,notc)
- -nowarn Generate no warnings
- -noassert Generate no assertions and assumptions
- -verbose Output messages about what the compiler is doing
- -classpath <path> Specify where to find user class files
- -sourcepath <path> Specify where to find input source files
- -bootclasspath <path> Override location of bootstrap class files
- -extdirs <dirs> Override location of installed extensions
- -d <directory> Specify where to place generated class files
- -encoding <encoding> Specify character encoding used by source files
- -windowtitle <windowtitle> Specify window title of generated HTML documentation
- -documenttitle <documenttitle> Specify document title of generated HTML documentation
- -target:<target> Specify which backend to use (jvm-1.5,msil)
- -migrate Assist in migrating from Scala version 1.0
- -o <file> Name of the output assembly (only relevant with -target:msil)
- -r <path> List of assemblies referenced by the program (only relevant with -target:msil)
- -debug Output debugging messages
- -deprecation enable detailed deprecation warnings
- -unchecked enable detailed unchecked warnings
- -statistics Print compiler statistics
- -explaintypes Explain type errors in more detail
- -resident Compiler stays resident, files to compile are read from standard input
- -uniqid Print identifiers with unique names (debugging option)
- -printtypes Print tree types (debugging option)
- -prompt Display a prompt after each error (debugging option)
- -noimports Compile without any implicit imports
- -nopredefs Compile without any implicit predefined values
- -skip:<phase> Skip <phase>
- -check:<phase> Check the tree at start of <phase>
- -print:<phase> Print out program after <phase>
- -printer:<printer> Printer to use (text,html)
- -printfile <file> Specify file in which to print trees
- -graph:<phase> Graph the program after <phase>
- -browse:<phase> Browse the abstract syntax tree after <phase>
- -stop:<phase> Stop after phase <phase>
- -log:<phase> Log operations in <phase>
- -logall Log all operations
- -version Print product version and exit
- -help Print a synopsis of standard options
- -nouescape disables handling of \u unicode escapes
- -Xinline Perform inlining when possible
- -XO Optimize. implies -Xinline, -Xcloselim and -Xdce
- -Xcloselim Perform closure elimination
- -Xdce Perform dead code elimination
- -Xwarndeadcode Emit warnings for dead code
- -XbytecodeRead Enable bytecode reader.
- -Xdetach Perform detaching of remote closures
- -Xshowcls <class> Show class info
- -Xshowobj <object> Show object info
- -Xlinearizer:<Xlinearizer> Linearizer to use (normal,dfs,rpo,dump)
- -Xgenerics Use generic Java types
- -Xprintpos Print tree positions (as offsets)
- -Xscript compile script file
- -Xexperimental enable experimental extensions
- -Xplugtypes parse but ignore annotations in more locations
- -Xkilloption optimizes option types
-
-one error found
diff --git a/test/attic/files/cli/test1/Main.check.scalaint b/test/attic/files/cli/test1/Main.check.scalaint
deleted file mode 100644
index 88345d1874..0000000000
--- a/test/attic/files/cli/test1/Main.check.scalaint
+++ /dev/null
@@ -1,45 +0,0 @@
-unknown option: '-cpp'
-scala [ <option> ]... [<torun> <arguments>]
-
-All options to scalac are allowed. See scalac -help.
-
-<torun>, if present, is an object or script file to run.
-If no <torun> is present, run an interactive interpreter.
-
-Option -howtorun allows explicitly specifying how to run <torun>:
- script: it is a script file
- object: it is an object name
- guess: (the default) try to guess
-
-Option -savecompiled requests that the compiled script be saved
-for future use.
-
-Option -nocompdaemon requests that the fsc offline compiler not be used.
-
-Option -Dproperty=value sets a Java system property.
-
-
-This is an interpreter for Scala.
-Type in expressions to have them evaluated.
-Type :help for more information.
-
-scala> 1: test 1 passed (1)
-unnamed0: scala.Unit = ()
-
-scala>
-This is an interpreter for Scala.
-Type in expressions to have them evaluated.
-Type :help for more information.
-
-scala> 1: test 2 passed (1)
-unnamed0: scala.Unit = ()
-
-scala>
-This is an interpreter for Scala.
-Type in expressions to have them evaluated.
-Type :help for more information.
-
-scala> 1: test 3 passed (1)
-unnamed0: scala.Unit = ()
-
-scala>
diff --git a/test/attic/files/cli/test1/Main.java b/test/attic/files/cli/test1/Main.java
deleted file mode 100644
index 8850b87517..0000000000
--- a/test/attic/files/cli/test1/Main.java
+++ /dev/null
@@ -1,8 +0,0 @@
-// @info no dependency
-package test1;
-public class Main {
- public static void main(String args[]) {
- String arg = (args.length > 0) ? args[0] : "?";
- System.out.println("1: test " + arg + " passed (" + args.length + ")");
- }
-}
diff --git a/test/attic/files/cli/test1/Main.scala b/test/attic/files/cli/test1/Main.scala
deleted file mode 100644
index f7dd8a0a36..0000000000
--- a/test/attic/files/cli/test1/Main.scala
+++ /dev/null
@@ -1,8 +0,0 @@
-// @info no dependency
-package test1
-object Main {
- def main(args: Array[String]) = {
- val arg = if (args != null && args.length > 0) args(0) else "?"
- Console.println("1: test " + arg + " passed (" + args.length + ")")
- }
-}
diff --git a/test/attic/files/cli/test2/Main.check.j9vm5 b/test/attic/files/cli/test2/Main.check.j9vm5
deleted file mode 100644
index 8f4fdf8aa1..0000000000
--- a/test/attic/files/cli/test2/Main.check.j9vm5
+++ /dev/null
@@ -1,4 +0,0 @@
-env: -cpp: No such file or directory
-env: test2.Main: No such file or directory
-env: -cp: No such file or directory
-2: 1: test 3 passed
diff --git a/test/attic/files/cli/test2/Main.check.java b/test/attic/files/cli/test2/Main.check.java
deleted file mode 100644
index aca383de3e..0000000000
--- a/test/attic/files/cli/test2/Main.check.java
+++ /dev/null
@@ -1,6 +0,0 @@
-Unrecognized option: -cpp
-Could not create the Java virtual machine.
-2: 1: test 1 passed (1)
-2: 1: test 2 passed (1)
-2: 1: test 3 passed (1)
-2: 1: test 4 passed (2)
diff --git a/test/attic/files/cli/test2/Main.check.java5 b/test/attic/files/cli/test2/Main.check.java5
deleted file mode 100644
index aca383de3e..0000000000
--- a/test/attic/files/cli/test2/Main.check.java5
+++ /dev/null
@@ -1,6 +0,0 @@
-Unrecognized option: -cpp
-Could not create the Java virtual machine.
-2: 1: test 1 passed (1)
-2: 1: test 2 passed (1)
-2: 1: test 3 passed (1)
-2: 1: test 4 passed (2)
diff --git a/test/attic/files/cli/test2/Main.check.java5_api b/test/attic/files/cli/test2/Main.check.java5_api
deleted file mode 100644
index 4ff775c3da..0000000000
--- a/test/attic/files/cli/test2/Main.check.java5_api
+++ /dev/null
@@ -1,24 +0,0 @@
-|-- allclasses-frame.html
-|-- allclasses-noframe.html
-|-- constant-values.html
-|-- deprecated-list.html
-|-- help-doc.html
-|-- index-all.html
-|-- index.html
-|-- overview-tree.html
-|-- package-list
-|-- resources
-| `-- inherit.gif
-|-- stylesheet.css
-|-- test1
-| |-- Main.html
-| |-- package-frame.html
-| |-- package-summary.html
-| `-- package-tree.html
-`-- test2
- |-- Main.html
- |-- package-frame.html
- |-- package-summary.html
- `-- package-tree.html
-
-3 directories, 19 files
diff --git a/test/attic/files/cli/test2/Main.check.java5_j9 b/test/attic/files/cli/test2/Main.check.java5_j9
deleted file mode 100644
index 2dcb6e892a..0000000000
--- a/test/attic/files/cli/test2/Main.check.java5_j9
+++ /dev/null
@@ -1,36 +0,0 @@
-JVMJ9VM007E Command-line option unrecognised: -cpp
-Could not create the Java virtual machine.
-
-Usage: java [-options] class [args...]
- (to execute a class)
- or java [-jar] [-options] jarfile [args...]
- (to execute a jar file)
-
-where options include:
- -cp -classpath <directories and zip/jar files separated by :>
- set search path for application classes and resources
- -D<name>=<value>
- set a system property
- -verbose[:class|gc|jni]
- enable verbose output
- -version print product version
- -version:<value>
- require the specified version to run
- -showversion print product version and continue
- -jre-restrict-search | -no-jre-restrict-search
- include/exclude user private JREs in the version search
- -agentlib:<libname>[=<options>]
- load native agent library <libname>, e.g. -agentlib:hprof
- see also, -agentlib:jdwp=help and -agentlib:hprof=help
- -agentpath:<pathname>[=<options>]
- load native agent library by full pathname
- -javaagent:<jarpath>[=<options>]
- load Java programming language agent, see java.lang.instrument
- -? -help print this help message
- -X print help on non-standard options
- -assert print help on assert options
-
-The java class is not found: test2.Main
-The java class is not found: test2.Main
-The java class is not found: test2.Main
-The java class is not found: test2.Main
diff --git a/test/attic/files/cli/test2/Main.check.javac b/test/attic/files/cli/test2/Main.check.javac
deleted file mode 100644
index c40c0a7a89..0000000000
--- a/test/attic/files/cli/test2/Main.check.javac
+++ /dev/null
@@ -1,27 +0,0 @@
-javac: invalid flag: -dd
-Usage: javac <options> <source files>
-where possible options include:
- -g Generate all debugging info
- -g:none Generate no debugging info
- -g:{lines,vars,source} Generate only some debugging info
- -nowarn Generate no warnings
- -verbose Output messages about what the compiler is doing
- -deprecation Output source locations where deprecated APIs are used
- -classpath <path> Specify where to find user class files
- -sourcepath <path> Specify where to find input source files
- -bootclasspath <path> Override location of bootstrap class files
- -extdirs <dirs> Override location of installed extensions
- -d <directory> Specify where to place generated class files
- -encoding <encoding> Specify character encoding used by source files
- -source <release> Provide source compatibility with specified release
- -target <release> Generate class files for specific VM version
- -help Print a synopsis of standard options
-
-files/cli/test2/Main.java:6: package test1 does not exist
- test1.Main.main(args);
- ^
-1 error
-files/cli/test2/Main.java:6: package test1 does not exist
- test1.Main.main(args);
- ^
-1 error
diff --git a/test/attic/files/cli/test2/Main.check.javac5 b/test/attic/files/cli/test2/Main.check.javac5
deleted file mode 100644
index 0ac32b056e..0000000000
--- a/test/attic/files/cli/test2/Main.check.javac5
+++ /dev/null
@@ -1,28 +0,0 @@
-javac: invalid flag: -dd
-Usage: javac <options> <source files>
-where possible options include:
- -g Generate all debugging info
- -g:none Generate no debugging info
- -g:{lines,vars,source} Generate only some debugging info
- -nowarn Generate no warnings
- -verbose Output messages about what the compiler is doing
- -deprecation Output source locations where deprecated APIs are used
- -classpath <path> Specify where to find user class files
- -cp <path> Specify where to find user class files
- -sourcepath <path> Specify where to find input source files
- -bootclasspath <path> Override location of bootstrap class files
- -extdirs <dirs> Override location of installed extensions
- -endorseddirs <dirs> Override location of endorsed standards path
- -d <directory> Specify where to place generated class files
- -encoding <encoding> Specify character encoding used by source files
- -source <release> Provide source compatibility with specified release
- -target <release> Generate class files for specific VM version
- -version Version information
- -help Print a synopsis of standard options
- -X Print a synopsis of nonstandard options
- -J<flag> Pass <flag> directly to the runtime system
-
-files/cli/test2/Main.java:6: package test1 does not exist
- test1.Main.main(args);
- ^
-1 error
diff --git a/test/attic/files/cli/test2/Main.check.javac6 b/test/attic/files/cli/test2/Main.check.javac6
deleted file mode 100644
index 350d3253bc..0000000000
--- a/test/attic/files/cli/test2/Main.check.javac6
+++ /dev/null
@@ -1,33 +0,0 @@
-javac: invalid flag: -dd
-Usage: javac <options> <source files>
-where possible options include:
- -g Generate all debugging info
- -g:none Generate no debugging info
- -g:{lines,vars,source} Generate only some debugging info
- -nowarn Generate no warnings
- -verbose Output messages about what the compiler is doing
- -deprecation Output source locations where deprecated APIs are used
- -classpath <path> Specify where to find user class files and annotation processors
- -cp <path> Specify where to find user class files and annotation processors
- -sourcepath <path> Specify where to find input source files
- -bootclasspath <path> Override location of bootstrap class files
- -extdirs <dirs> Override location of installed extensions
- -endorseddirs <dirs> Override location of endorsed standards path
- -proc:{none, only} Control whether annotation processing and/or compilation is done.
- -processor <class> Name of the annotation processor to run; bypasses default discovery process
- -processorpath <path> Specify where to find annotation processors
- -d <directory> Specify where to place generated class files
- -s <directory> Specify where to place generated source files
- -encoding <encoding> Specify character encoding used by source files
- -source <release> Provide source compatibility with specified release
- -target <release> Generate class files for specific VM version
- -version Version information
- -help Print a synopsis of standard options
- -A[key[=value]] Options to pass to annotation processors
- -X Print a synopsis of nonstandard options
- -J<flag> Pass <flag> directly to the runtime system
-
-files/cli/test2/Main.java:5: package test1 does not exist
- test1.Main.main(args);
- ^
-1 error
diff --git a/test/attic/files/cli/test2/Main.check.jikes b/test/attic/files/cli/test2/Main.check.jikes
deleted file mode 100644
index 97943e8347..0000000000
--- a/test/attic/files/cli/test2/Main.check.jikes
+++ /dev/null
@@ -1,9 +0,0 @@
-Error: "-dd" is an invalid option.
-use: jikes [options] [@files] file.java...
-For more help, try -help or -version.
-
-Found 1 semantic error compiling "files/cli/test2/Main.java":
-
- 6. test1.Main.main(args);
- ^---^
-*** Semantic Error: No accessible field named "test1" was found in type "test2.Main".
diff --git a/test/attic/files/cli/test2/Main.check.jikes5 b/test/attic/files/cli/test2/Main.check.jikes5
deleted file mode 100644
index 97943e8347..0000000000
--- a/test/attic/files/cli/test2/Main.check.jikes5
+++ /dev/null
@@ -1,9 +0,0 @@
-Error: "-dd" is an invalid option.
-use: jikes [options] [@files] file.java...
-For more help, try -help or -version.
-
-Found 1 semantic error compiling "files/cli/test2/Main.java":
-
- 6. test1.Main.main(args);
- ^---^
-*** Semantic Error: No accessible field named "test1" was found in type "test2.Main".
diff --git a/test/attic/files/cli/test2/Main.check.scala b/test/attic/files/cli/test2/Main.check.scala
deleted file mode 100644
index 7e5f17625b..0000000000
--- a/test/attic/files/cli/test2/Main.check.scala
+++ /dev/null
@@ -1,24 +0,0 @@
-unknown option: '-cpp'
-scala [ <option> ]... [<torun> <arguments>]
-
-All options to scalac are allowed. See scalac -help.
-
-<torun>, if present, is an object or script file to run.
-If no <torun> is present, run an interactive interpreter.
-
-Option -howtorun allows explicitly specifying how to run <torun>:
- script: it is a script file
- object: it is an object name
- guess: (the default) try to guess
-
-Option -savecompiled requests that the compiled script be saved
-for future use.
-
-Option -nocompdaemon requests that the fsc offline compiler not be used.
-
-Option -Dproperty=value sets a Java system property.
-
-2: 1: test 1 passed (1)
-2: 1: test 2 passed (1)
-2: 1: test 3 passed (1)
-2: 1: test 4 passed (2)
diff --git a/test/attic/files/cli/test2/Main.check.scala_api b/test/attic/files/cli/test2/Main.check.scala_api
deleted file mode 100644
index bcb0f0c7fb..0000000000
--- a/test/attic/files/cli/test2/Main.check.scala_api
+++ /dev/null
@@ -1,37 +0,0 @@
-|-- all-classes.html
-|-- index.html
-|-- modules.html
-|-- nav-classes.html
-|-- root-content.html
-|-- scala
-| |-- Any.html
-| |-- AnyRef.html
-| |-- AnyVal.html
-| |-- Boolean.html
-| |-- Byte.html
-| |-- Char.html
-| |-- Double.html
-| |-- Float.html
-| |-- Int.html
-| |-- Long.html
-| |-- Nothing.html
-| |-- Null.html
-| |-- Short.html
-| |-- Unit.html
-| `-- runtime
-| |-- BoxedFloat.html
-| |-- BoxedInt.html
-| |-- BoxedLong.html
-| `-- BoxedNumber.html
-|-- script.js
-|-- style.css
-|-- test1
-| `-- Main$object.html
-|-- test1$content.html
-|-- test1$package.html
-|-- test2
-| `-- Main$object.html
-|-- test2$content.html
-`-- test2$package.html
-
-4 directories, 31 files
diff --git a/test/attic/files/cli/test2/Main.check.scala_j9 b/test/attic/files/cli/test2/Main.check.scala_j9
deleted file mode 100644
index 80cbb50fa9..0000000000
--- a/test/attic/files/cli/test2/Main.check.scala_j9
+++ /dev/null
@@ -1,15 +0,0 @@
-unknown option: '-cpp'
-scala [ <compiler-option> | -howtorun:how ]... [<torun> <arguments>]
-
-<compiler-option>'s are as for scalac; see scalac -help.
-<torun>, if present, is an object or script file to run.
-If no <torun> is present, run an interactive interpreter.
--howtorun allows explicitly specifying how to run <torun>:
- script: it is a script file
- object: it is an object name
- guess: (the default) try to guess
-
-2: 1: test 1 passed (1)
-2: 1: test 2 passed (1)
-2: 1: test 3 passed (1)
-2: 1: test 4 passed (2)
diff --git a/test/attic/files/cli/test2/Main.check.scalac b/test/attic/files/cli/test2/Main.check.scalac
deleted file mode 100644
index 8465810d0b..0000000000
--- a/test/attic/files/cli/test2/Main.check.scalac
+++ /dev/null
@@ -1,63 +0,0 @@
-scalac error: bad option: '-dd'
- scalac -help gives more information
-Usage: scalac <options | source files>
-where possible options include:
- -doc Generate documentation
- -g:<g> Generate debugging info (none,source,line,vars,notc)
- -nowarn Generate no warnings
- -noassert Generate no assertions and assumptions
- -verbose Output messages about what the compiler is doing
- -classpath <path> Specify where to find user class files
- -sourcepath <path> Specify where to find input source files
- -bootclasspath <path> Override location of bootstrap class files
- -extdirs <dirs> Override location of installed extensions
- -d <directory> Specify where to place generated class files
- -encoding <encoding> Specify character encoding used by source files
- -windowtitle <windowtitle> Specify window title of generated HTML documentation
- -documenttitle <documenttitle> Specify document title of generated HTML documentation
- -target:<target> Specify which backend to use (jvm-1.5,msil)
- -migrate Assist in migrating from Scala version 1.0
- -o <file> Name of the output assembly (only relevant with -target:msil)
- -r <path> List of assemblies referenced by the program (only relevant with -target:msil)
- -debug Output debugging messages
- -deprecation enable detailed deprecation warnings
- -unchecked enable detailed unchecked warnings
- -statistics Print compiler statistics
- -explaintypes Explain type errors in more detail
- -resident Compiler stays resident, files to compile are read from standard input
- -uniqid Print identifiers with unique names (debugging option)
- -printtypes Print tree types (debugging option)
- -prompt Display a prompt after each error (debugging option)
- -noimports Compile without any implicit imports
- -nopredefs Compile without any implicit predefined values
- -skip:<phase> Skip <phase>
- -check:<phase> Check the tree at start of <phase>
- -print:<phase> Print out program after <phase>
- -printer:<printer> Printer to use (text,html)
- -printfile <file> Specify file in which to print trees
- -graph:<phase> Graph the program after <phase>
- -browse:<phase> Browse the abstract syntax tree after <phase>
- -stop:<phase> Stop after phase <phase>
- -log:<phase> Log operations in <phase>
- -logall Log all operations
- -version Print product version and exit
- -help Print a synopsis of standard options
- -nouescape disables handling of \u unicode escapes
- -Xinline Perform inlining when possible
- -XO Optimize. implies -Xinline, -Xcloselim and -Xdce
- -Xcloselim Perform closure elimination
- -Xdce Perform dead code elimination
- -Xwarndeadcode Emit warnings for dead code
- -XbytecodeRead Enable bytecode reader.
- -Xdetach Perform detaching of remote closures
- -Xshowcls <class> Show class info
- -Xshowobj <object> Show object info
- -Xlinearizer:<Xlinearizer> Linearizer to use (normal,dfs,rpo,dump)
- -Xgenerics Use generic Java types
- -Xprintpos Print tree positions (as offsets)
- -Xscript compile script file
- -Xexperimental enable experimental extensions
- -Xplugtypes parse but ignore annotations in more locations
- -Xkilloption optimizes option types
-
-one error found
diff --git a/test/attic/files/cli/test2/Main.check.scalaint b/test/attic/files/cli/test2/Main.check.scalaint
deleted file mode 100644
index 89b6766bb5..0000000000
--- a/test/attic/files/cli/test2/Main.check.scalaint
+++ /dev/null
@@ -1,45 +0,0 @@
-unknown option: '-cpp'
-scala [ <option> ]... [<torun> <arguments>]
-
-All options to scalac are allowed. See scalac -help.
-
-<torun>, if present, is an object or script file to run.
-If no <torun> is present, run an interactive interpreter.
-
-Option -howtorun allows explicitly specifying how to run <torun>:
- script: it is a script file
- object: it is an object name
- guess: (the default) try to guess
-
-Option -savecompiled requests that the compiled script be saved
-for future use.
-
-Option -nocompdaemon requests that the fsc offline compiler not be used.
-
-Option -Dproperty=value sets a Java system property.
-
-
-This is an interpreter for Scala.
-Type in expressions to have them evaluated.
-Type :help for more information.
-
-scala> 2: 1: test 1 passed (1)
-unnamed0: scala.Unit = ()
-
-scala>
-This is an interpreter for Scala.
-Type in expressions to have them evaluated.
-Type :help for more information.
-
-scala> 2: 1: test 2 passed (1)
-unnamed0: scala.Unit = ()
-
-scala>
-This is an interpreter for Scala.
-Type in expressions to have them evaluated.
-Type :help for more information.
-
-scala> 2: 1: test 3 passed (1)
-unnamed0: scala.Unit = ()
-
-scala>
diff --git a/test/attic/files/cli/test2/Main.java b/test/attic/files/cli/test2/Main.java
deleted file mode 100644
index f6797632bf..0000000000
--- a/test/attic/files/cli/test2/Main.java
+++ /dev/null
@@ -1,8 +0,0 @@
-// @info 1 dependency
-package test2;
-public class Main {
- public static void main(String args[]) {
- System.out.print("2: ");
- test1.Main.main(args);
- }
-}
diff --git a/test/attic/files/cli/test2/Main.scala b/test/attic/files/cli/test2/Main.scala
deleted file mode 100644
index 11c878b9c0..0000000000
--- a/test/attic/files/cli/test2/Main.scala
+++ /dev/null
@@ -1,8 +0,0 @@
-// @info 1 dependency
-package test2
-object Main {
- def main(args: Array[String]) = {
- Console.print("2: ")
- test1.Main.main(args)
- }
-}
diff --git a/test/attic/files/cli/test3/Main.check.j9vm5 b/test/attic/files/cli/test3/Main.check.j9vm5
deleted file mode 100644
index a094dc8daf..0000000000
--- a/test/attic/files/cli/test3/Main.check.j9vm5
+++ /dev/null
@@ -1,5 +0,0 @@
-env: -cpp: No such file or directory
-env: test3.Main: No such file or directory
-env: -cp: No such file or directory
-3: 1: test 3 passed
-3: 2: 1: test 3 passed
diff --git a/test/attic/files/cli/test3/Main.check.java b/test/attic/files/cli/test3/Main.check.java
deleted file mode 100644
index de3eb7b136..0000000000
--- a/test/attic/files/cli/test3/Main.check.java
+++ /dev/null
@@ -1,10 +0,0 @@
-Unrecognized option: -cpp
-Could not create the Java virtual machine.
-3: 1: test 1 passed (1)
-3: 2: 1: test 1 passed (1)
-3: 1: test 2 passed (1)
-3: 2: 1: test 2 passed (1)
-3: 1: test 3 passed (1)
-3: 2: 1: test 3 passed (1)
-3: 1: test 4 passed (2)
-3: 2: 1: test 4 passed (2)
diff --git a/test/attic/files/cli/test3/Main.check.java5 b/test/attic/files/cli/test3/Main.check.java5
deleted file mode 100644
index de3eb7b136..0000000000
--- a/test/attic/files/cli/test3/Main.check.java5
+++ /dev/null
@@ -1,10 +0,0 @@
-Unrecognized option: -cpp
-Could not create the Java virtual machine.
-3: 1: test 1 passed (1)
-3: 2: 1: test 1 passed (1)
-3: 1: test 2 passed (1)
-3: 2: 1: test 2 passed (1)
-3: 1: test 3 passed (1)
-3: 2: 1: test 3 passed (1)
-3: 1: test 4 passed (2)
-3: 2: 1: test 4 passed (2)
diff --git a/test/attic/files/cli/test3/Main.check.java5_api b/test/attic/files/cli/test3/Main.check.java5_api
deleted file mode 100644
index f6112211f0..0000000000
--- a/test/attic/files/cli/test3/Main.check.java5_api
+++ /dev/null
@@ -1,29 +0,0 @@
-|-- allclasses-frame.html
-|-- allclasses-noframe.html
-|-- constant-values.html
-|-- deprecated-list.html
-|-- help-doc.html
-|-- index-all.html
-|-- index.html
-|-- overview-tree.html
-|-- package-list
-|-- resources
-| `-- inherit.gif
-|-- stylesheet.css
-|-- test1
-| |-- Main.html
-| |-- package-frame.html
-| |-- package-summary.html
-| `-- package-tree.html
-|-- test2
-| |-- Main.html
-| |-- package-frame.html
-| |-- package-summary.html
-| `-- package-tree.html
-`-- test3
- |-- Main.html
- |-- package-frame.html
- |-- package-summary.html
- `-- package-tree.html
-
-4 directories, 23 files
diff --git a/test/attic/files/cli/test3/Main.check.java5_j9 b/test/attic/files/cli/test3/Main.check.java5_j9
deleted file mode 100644
index 9e228d7649..0000000000
--- a/test/attic/files/cli/test3/Main.check.java5_j9
+++ /dev/null
@@ -1,36 +0,0 @@
-JVMJ9VM007E Command-line option unrecognised: -cpp
-Could not create the Java virtual machine.
-
-Usage: java [-options] class [args...]
- (to execute a class)
- or java [-jar] [-options] jarfile [args...]
- (to execute a jar file)
-
-where options include:
- -cp -classpath <directories and zip/jar files separated by :>
- set search path for application classes and resources
- -D<name>=<value>
- set a system property
- -verbose[:class|gc|jni]
- enable verbose output
- -version print product version
- -version:<value>
- require the specified version to run
- -showversion print product version and continue
- -jre-restrict-search | -no-jre-restrict-search
- include/exclude user private JREs in the version search
- -agentlib:<libname>[=<options>]
- load native agent library <libname>, e.g. -agentlib:hprof
- see also, -agentlib:jdwp=help and -agentlib:hprof=help
- -agentpath:<pathname>[=<options>]
- load native agent library by full pathname
- -javaagent:<jarpath>[=<options>]
- load Java programming language agent, see java.lang.instrument
- -? -help print this help message
- -X print help on non-standard options
- -assert print help on assert options
-
-The java class is not found: test3.Main
-The java class is not found: test3.Main
-The java class is not found: test3.Main
-The java class is not found: test3.Main
diff --git a/test/attic/files/cli/test3/Main.check.javac b/test/attic/files/cli/test3/Main.check.javac
deleted file mode 100644
index 8d235b647b..0000000000
--- a/test/attic/files/cli/test3/Main.check.javac
+++ /dev/null
@@ -1,33 +0,0 @@
-javac: invalid flag: -dd
-Usage: javac <options> <source files>
-where possible options include:
- -g Generate all debugging info
- -g:none Generate no debugging info
- -g:{lines,vars,source} Generate only some debugging info
- -nowarn Generate no warnings
- -verbose Output messages about what the compiler is doing
- -deprecation Output source locations where deprecated APIs are used
- -classpath <path> Specify where to find user class files
- -sourcepath <path> Specify where to find input source files
- -bootclasspath <path> Override location of bootstrap class files
- -extdirs <dirs> Override location of installed extensions
- -d <directory> Specify where to place generated class files
- -encoding <encoding> Specify character encoding used by source files
- -source <release> Provide source compatibility with specified release
- -target <release> Generate class files for specific VM version
- -help Print a synopsis of standard options
-
-files/cli/test3/Main.java:6: package test1 does not exist
- test1.Main.main(args);
- ^
-files/cli/test3/Main.java:8: package test2 does not exist
- test2.Main.main(args);
- ^
-2 errors
-files/cli/test3/Main.java:6: package test1 does not exist
- test1.Main.main(args);
- ^
-files/cli/test3/Main.java:8: package test2 does not exist
- test2.Main.main(args);
- ^
-2 errors
diff --git a/test/attic/files/cli/test3/Main.check.javac5 b/test/attic/files/cli/test3/Main.check.javac5
deleted file mode 100644
index 3a48fa000e..0000000000
--- a/test/attic/files/cli/test3/Main.check.javac5
+++ /dev/null
@@ -1,31 +0,0 @@
-javac: invalid flag: -dd
-Usage: javac <options> <source files>
-where possible options include:
- -g Generate all debugging info
- -g:none Generate no debugging info
- -g:{lines,vars,source} Generate only some debugging info
- -nowarn Generate no warnings
- -verbose Output messages about what the compiler is doing
- -deprecation Output source locations where deprecated APIs are used
- -classpath <path> Specify where to find user class files
- -cp <path> Specify where to find user class files
- -sourcepath <path> Specify where to find input source files
- -bootclasspath <path> Override location of bootstrap class files
- -extdirs <dirs> Override location of installed extensions
- -endorseddirs <dirs> Override location of endorsed standards path
- -d <directory> Specify where to place generated class files
- -encoding <encoding> Specify character encoding used by source files
- -source <release> Provide source compatibility with specified release
- -target <release> Generate class files for specific VM version
- -version Version information
- -help Print a synopsis of standard options
- -X Print a synopsis of nonstandard options
- -J<flag> Pass <flag> directly to the runtime system
-
-files/cli/test3/Main.java:6: package test1 does not exist
- test1.Main.main(args);
- ^
-files/cli/test3/Main.java:8: package test2 does not exist
- test2.Main.main(args);
- ^
-2 errors
diff --git a/test/attic/files/cli/test3/Main.check.javac6 b/test/attic/files/cli/test3/Main.check.javac6
deleted file mode 100644
index 677b950aed..0000000000
--- a/test/attic/files/cli/test3/Main.check.javac6
+++ /dev/null
@@ -1,36 +0,0 @@
-javac: invalid flag: -dd
-Usage: javac <options> <source files>
-where possible options include:
- -g Generate all debugging info
- -g:none Generate no debugging info
- -g:{lines,vars,source} Generate only some debugging info
- -nowarn Generate no warnings
- -verbose Output messages about what the compiler is doing
- -deprecation Output source locations where deprecated APIs are used
- -classpath <path> Specify where to find user class files and annotation processors
- -cp <path> Specify where to find user class files and annotation processors
- -sourcepath <path> Specify where to find input source files
- -bootclasspath <path> Override location of bootstrap class files
- -extdirs <dirs> Override location of installed extensions
- -endorseddirs <dirs> Override location of endorsed standards path
- -proc:{none, only} Control whether annotation processing and/or compilation is done.
- -processor <class> Name of the annotation processor to run; bypasses default discovery process
- -processorpath <path> Specify where to find annotation processors
- -d <directory> Specify where to place generated class files
- -s <directory> Specify where to place generated source files
- -encoding <encoding> Specify character encoding used by source files
- -source <release> Provide source compatibility with specified release
- -target <release> Generate class files for specific VM version
- -version Version information
- -help Print a synopsis of standard options
- -A[key[=value]] Options to pass to annotation processors
- -X Print a synopsis of nonstandard options
- -J<flag> Pass <flag> directly to the runtime system
-
-files/cli/test3/Main.java:5: package test1 does not exist
- test1.Main.main(args);
- ^
-files/cli/test3/Main.java:7: package test2 does not exist
- test2.Main.main(args);
- ^
-2 errors
diff --git a/test/attic/files/cli/test3/Main.check.jikes b/test/attic/files/cli/test3/Main.check.jikes
deleted file mode 100644
index 604333e81a..0000000000
--- a/test/attic/files/cli/test3/Main.check.jikes
+++ /dev/null
@@ -1,14 +0,0 @@
-Error: "-dd" is an invalid option.
-use: jikes [options] [@files] file.java...
-For more help, try -help or -version.
-
-Found 2 semantic errors compiling "files/cli/test3/Main.java":
-
- 6. test1.Main.main(args);
- ^---^
-*** Semantic Error: No accessible field named "test1" was found in type "test3.Main".
-
-
- 8. test2.Main.main(args);
- ^---^
-*** Semantic Error: No accessible field named "test2" was found in type "test3.Main".
diff --git a/test/attic/files/cli/test3/Main.check.jikes5 b/test/attic/files/cli/test3/Main.check.jikes5
deleted file mode 100644
index 604333e81a..0000000000
--- a/test/attic/files/cli/test3/Main.check.jikes5
+++ /dev/null
@@ -1,14 +0,0 @@
-Error: "-dd" is an invalid option.
-use: jikes [options] [@files] file.java...
-For more help, try -help or -version.
-
-Found 2 semantic errors compiling "files/cli/test3/Main.java":
-
- 6. test1.Main.main(args);
- ^---^
-*** Semantic Error: No accessible field named "test1" was found in type "test3.Main".
-
-
- 8. test2.Main.main(args);
- ^---^
-*** Semantic Error: No accessible field named "test2" was found in type "test3.Main".
diff --git a/test/attic/files/cli/test3/Main.check.scala b/test/attic/files/cli/test3/Main.check.scala
deleted file mode 100644
index f78729b9a2..0000000000
--- a/test/attic/files/cli/test3/Main.check.scala
+++ /dev/null
@@ -1,28 +0,0 @@
-unknown option: '-cpp'
-scala [ <option> ]... [<torun> <arguments>]
-
-All options to scalac are allowed. See scalac -help.
-
-<torun>, if present, is an object or script file to run.
-If no <torun> is present, run an interactive interpreter.
-
-Option -howtorun allows explicitly specifying how to run <torun>:
- script: it is a script file
- object: it is an object name
- guess: (the default) try to guess
-
-Option -savecompiled requests that the compiled script be saved
-for future use.
-
-Option -nocompdaemon requests that the fsc offline compiler not be used.
-
-Option -Dproperty=value sets a Java system property.
-
-3: 1: test 1 passed (1)
-3: 2: 1: test 1 passed (1)
-3: 1: test 2 passed (1)
-3: 2: 1: test 2 passed (1)
-3: 1: test 3 passed (1)
-3: 2: 1: test 3 passed (1)
-3: 1: test 4 passed (2)
-3: 2: 1: test 4 passed (2)
diff --git a/test/attic/files/cli/test3/Main.check.scala_api b/test/attic/files/cli/test3/Main.check.scala_api
deleted file mode 100644
index 4552819b5b..0000000000
--- a/test/attic/files/cli/test3/Main.check.scala_api
+++ /dev/null
@@ -1,41 +0,0 @@
-|-- all-classes.html
-|-- index.html
-|-- modules.html
-|-- nav-classes.html
-|-- root-content.html
-|-- scala
-| |-- Any.html
-| |-- AnyRef.html
-| |-- AnyVal.html
-| |-- Boolean.html
-| |-- Byte.html
-| |-- Char.html
-| |-- Double.html
-| |-- Float.html
-| |-- Int.html
-| |-- Long.html
-| |-- Nothing.html
-| |-- Null.html
-| |-- Short.html
-| |-- Unit.html
-| `-- runtime
-| |-- BoxedFloat.html
-| |-- BoxedInt.html
-| |-- BoxedLong.html
-| `-- BoxedNumber.html
-|-- script.js
-|-- style.css
-|-- test1
-| `-- Main$object.html
-|-- test1$content.html
-|-- test1$package.html
-|-- test2
-| `-- Main$object.html
-|-- test2$content.html
-|-- test2$package.html
-|-- test3
-| `-- Main$object.html
-|-- test3$content.html
-`-- test3$package.html
-
-5 directories, 34 files
diff --git a/test/attic/files/cli/test3/Main.check.scala_j9 b/test/attic/files/cli/test3/Main.check.scala_j9
deleted file mode 100644
index 3804c17636..0000000000
--- a/test/attic/files/cli/test3/Main.check.scala_j9
+++ /dev/null
@@ -1,19 +0,0 @@
-unknown option: '-cpp'
-scala [ <compiler-option> | -howtorun:how ]... [<torun> <arguments>]
-
-<compiler-option>'s are as for scalac; see scalac -help.
-<torun>, if present, is an object or script file to run.
-If no <torun> is present, run an interactive interpreter.
--howtorun allows explicitly specifying how to run <torun>:
- script: it is a script file
- object: it is an object name
- guess: (the default) try to guess
-
-3: 1: test 1 passed (1)
-3: 2: 1: test 1 passed (1)
-3: 1: test 2 passed (1)
-3: 2: 1: test 2 passed (1)
-3: 1: test 3 passed (1)
-3: 2: 1: test 3 passed (1)
-3: 1: test 4 passed (2)
-3: 2: 1: test 4 passed (2)
diff --git a/test/attic/files/cli/test3/Main.check.scalac b/test/attic/files/cli/test3/Main.check.scalac
deleted file mode 100644
index 8465810d0b..0000000000
--- a/test/attic/files/cli/test3/Main.check.scalac
+++ /dev/null
@@ -1,63 +0,0 @@
-scalac error: bad option: '-dd'
- scalac -help gives more information
-Usage: scalac <options | source files>
-where possible options include:
- -doc Generate documentation
- -g:<g> Generate debugging info (none,source,line,vars,notc)
- -nowarn Generate no warnings
- -noassert Generate no assertions and assumptions
- -verbose Output messages about what the compiler is doing
- -classpath <path> Specify where to find user class files
- -sourcepath <path> Specify where to find input source files
- -bootclasspath <path> Override location of bootstrap class files
- -extdirs <dirs> Override location of installed extensions
- -d <directory> Specify where to place generated class files
- -encoding <encoding> Specify character encoding used by source files
- -windowtitle <windowtitle> Specify window title of generated HTML documentation
- -documenttitle <documenttitle> Specify document title of generated HTML documentation
- -target:<target> Specify which backend to use (jvm-1.5,msil)
- -migrate Assist in migrating from Scala version 1.0
- -o <file> Name of the output assembly (only relevant with -target:msil)
- -r <path> List of assemblies referenced by the program (only relevant with -target:msil)
- -debug Output debugging messages
- -deprecation enable detailed deprecation warnings
- -unchecked enable detailed unchecked warnings
- -statistics Print compiler statistics
- -explaintypes Explain type errors in more detail
- -resident Compiler stays resident, files to compile are read from standard input
- -uniqid Print identifiers with unique names (debugging option)
- -printtypes Print tree types (debugging option)
- -prompt Display a prompt after each error (debugging option)
- -noimports Compile without any implicit imports
- -nopredefs Compile without any implicit predefined values
- -skip:<phase> Skip <phase>
- -check:<phase> Check the tree at start of <phase>
- -print:<phase> Print out program after <phase>
- -printer:<printer> Printer to use (text,html)
- -printfile <file> Specify file in which to print trees
- -graph:<phase> Graph the program after <phase>
- -browse:<phase> Browse the abstract syntax tree after <phase>
- -stop:<phase> Stop after phase <phase>
- -log:<phase> Log operations in <phase>
- -logall Log all operations
- -version Print product version and exit
- -help Print a synopsis of standard options
- -nouescape disables handling of \u unicode escapes
- -Xinline Perform inlining when possible
- -XO Optimize. implies -Xinline, -Xcloselim and -Xdce
- -Xcloselim Perform closure elimination
- -Xdce Perform dead code elimination
- -Xwarndeadcode Emit warnings for dead code
- -XbytecodeRead Enable bytecode reader.
- -Xdetach Perform detaching of remote closures
- -Xshowcls <class> Show class info
- -Xshowobj <object> Show object info
- -Xlinearizer:<Xlinearizer> Linearizer to use (normal,dfs,rpo,dump)
- -Xgenerics Use generic Java types
- -Xprintpos Print tree positions (as offsets)
- -Xscript compile script file
- -Xexperimental enable experimental extensions
- -Xplugtypes parse but ignore annotations in more locations
- -Xkilloption optimizes option types
-
-one error found
diff --git a/test/attic/files/cli/test3/Main.check.scalaint b/test/attic/files/cli/test3/Main.check.scalaint
deleted file mode 100644
index cffa02c5b6..0000000000
--- a/test/attic/files/cli/test3/Main.check.scalaint
+++ /dev/null
@@ -1,48 +0,0 @@
-unknown option: '-cpp'
-scala [ <option> ]... [<torun> <arguments>]
-
-All options to scalac are allowed. See scalac -help.
-
-<torun>, if present, is an object or script file to run.
-If no <torun> is present, run an interactive interpreter.
-
-Option -howtorun allows explicitly specifying how to run <torun>:
- script: it is a script file
- object: it is an object name
- guess: (the default) try to guess
-
-Option -savecompiled requests that the compiled script be saved
-for future use.
-
-Option -nocompdaemon requests that the fsc offline compiler not be used.
-
-Option -Dproperty=value sets a Java system property.
-
-
-This is an interpreter for Scala.
-Type in expressions to have them evaluated.
-Type :help for more information.
-
-scala> 3: 1: test 1 passed (1)
-3: 2: 1: test 1 passed (1)
-unnamed0: scala.Unit = ()
-
-scala>
-This is an interpreter for Scala.
-Type in expressions to have them evaluated.
-Type :help for more information.
-
-scala> 3: 1: test 2 passed (1)
-3: 2: 1: test 2 passed (1)
-unnamed0: scala.Unit = ()
-
-scala>
-This is an interpreter for Scala.
-Type in expressions to have them evaluated.
-Type :help for more information.
-
-scala> 3: 1: test 3 passed (1)
-3: 2: 1: test 3 passed (1)
-unnamed0: scala.Unit = ()
-
-scala>
diff --git a/test/attic/files/cli/test3/Main.java b/test/attic/files/cli/test3/Main.java
deleted file mode 100644
index 208863d012..0000000000
--- a/test/attic/files/cli/test3/Main.java
+++ /dev/null
@@ -1,10 +0,0 @@
-// @info 2 dependency
-package test3;
-public class Main {
- public static void main(String args[]) {
- System.out.print("3: ");
- test1.Main.main(args);
- System.out.print("3: ");
- test2.Main.main(args);
- }
-}
diff --git a/test/attic/files/cli/test3/Main.scala b/test/attic/files/cli/test3/Main.scala
deleted file mode 100644
index 63fc11b771..0000000000
--- a/test/attic/files/cli/test3/Main.scala
+++ /dev/null
@@ -1,10 +0,0 @@
-// @info 2 dependencies
-package test3
-object Main {
- def main(args: Array[String]) = {
- Console.print("3: ")
- test1.Main.main(args)
- Console.print("3: ")
- test2.Main.main(args)
- }
-}
diff --git a/test/files/disabled/A.scala b/test/disabled/buildmanager/overloaded_1/A.scala
index c070faf978..c070faf978 100644
--- a/test/files/disabled/A.scala
+++ b/test/disabled/buildmanager/overloaded_1/A.scala
diff --git a/test/files/disabled/overloaded_1.check b/test/disabled/buildmanager/overloaded_1/overloaded_1.check
index 4d643ce6b4..4d643ce6b4 100644
--- a/test/files/disabled/overloaded_1.check
+++ b/test/disabled/buildmanager/overloaded_1/overloaded_1.check
diff --git a/test/files/disabled/overloaded_1.test b/test/disabled/buildmanager/overloaded_1/overloaded_1.test
index 392e0d365f..392e0d365f 100644
--- a/test/files/disabled/overloaded_1.test
+++ b/test/disabled/buildmanager/overloaded_1/overloaded_1.test
diff --git a/test/files/disabled/t4245/A.scala b/test/disabled/buildmanager/t4245/A.scala
index 7c4efe1b4b..7c4efe1b4b 100644
--- a/test/files/disabled/t4245/A.scala
+++ b/test/disabled/buildmanager/t4245/A.scala
diff --git a/test/files/disabled/t4245/t4245.check b/test/disabled/buildmanager/t4245/t4245.check
index 3d3898c671..3d3898c671 100644
--- a/test/files/disabled/t4245/t4245.check
+++ b/test/disabled/buildmanager/t4245/t4245.check
diff --git a/test/files/disabled/t4245/t4245.test b/test/disabled/buildmanager/t4245/t4245.test
index 392e0d365f..392e0d365f 100644
--- a/test/files/disabled/t4245/t4245.test
+++ b/test/disabled/buildmanager/t4245/t4245.test
diff --git a/test/disabled/presentation/akka.flags b/test/disabled/presentation/akka.flags
index 56d026a62d..9bf2878f62 100644
--- a/test/disabled/presentation/akka.flags
+++ b/test/disabled/presentation/akka.flags
@@ -12,7 +12,7 @@
# running partest from. Run it from the root scala checkout for these files to resolve correctly
# (by default when running 'ant test', or 'test/partest'). Paths use Unix separators, the test
# framework translates them to the platform dependent representation.
-# -bootclasspath lib/scala-compiler.jar:lib/scala-library.jar:lib/fjbg.jar
+# -bootclasspath lib/scala-compiler.jar:lib/scala-library.jar
# the following line would test using the quick compiler
-# -bootclasspath build/quick/classes/compiler:build/quick/classes/library:lib/fjbg.jar
+# -bootclasspath build/quick/classes/compiler:build/quick/classes/library
diff --git a/test/disabled/presentation/simple-tests.opts b/test/disabled/presentation/simple-tests.opts
index 8529bbf1a0..d651316984 100644
--- a/test/disabled/presentation/simple-tests.opts
+++ b/test/disabled/presentation/simple-tests.opts
@@ -12,7 +12,7 @@
# running partest from. Run it from the root scala checkout for these files to resolve correctly
# (by default when running 'ant test', or 'test/partest'). Paths use Unix separators, the test
# framework translates them to the platform dependent representation.
--bootclasspath lib/scala-compiler.jar:lib/scala-library.jar:lib/fjbg.jar
+-bootclasspath lib/scala-compiler.jar:lib/scala-library.jar
# the following line would test using the quick compiler
-# -bootclasspath build/quick/classes/compiler:build/quick/classes/library:lib/fjbg.jar
+# -bootclasspath build/quick/classes/compiler:build/quick/classes/library
diff --git a/test/files/run/t4146.scala b/test/disabled/run/t4146.scala
index 93ce22b519..a17de50ee1 100644
--- a/test/files/run/t4146.scala
+++ b/test/disabled/run/t4146.scala
@@ -1,4 +1,4 @@
-object bob extends Application {
+object bob extends App {
var name = "Bob"
}
diff --git a/test/files/ant/imported.xml b/test/files/ant/imported.xml
index 5a4dfc319b..182c80aadf 100644
--- a/test/files/ant/imported.xml
+++ b/test/files/ant/imported.xml
@@ -56,7 +56,6 @@ INITIALISATION
<property name="scala.dir" value="${quick.dir}"/>
<property name="scala-library.lib" value="${scala.dir}/classes/library/"/>
<property name="scala-compiler.lib" value="${scala.dir}/classes/compiler/"/>
- <property name="fjbg.lib" value="${project.dir}/lib/fjbg.jar"/>
</target>
<target name="pack.init" if="pack.binary">
@@ -67,7 +66,6 @@ INITIALISATION
<property name="scala.dir" value="${pack.dir}"/>
<property name="scala-library.lib" value="${scala.dir}/lib/scala-library.jar"/>
<property name="scala-compiler.lib" value="${scala.dir}/lib/scala-compiler.jar"/>
- <property name="fjbg.lib" value=""/>
</target>
<target name="latest.init" if="latest.binary">
@@ -78,7 +76,6 @@ INITIALISATION
<property name="scala.dir" value="${latest.dir}"/>
<property name="scala-library.lib" value="${scala.dir}/lib/scala-library.jar"/>
<property name="scala-compiler.lib" value="${scala.dir}/lib/scala-compiler.jar"/>
- <property name="fjbg.lib" value=""/>
</target>
<target name="installed.init" if="installed.binary">
@@ -89,7 +86,6 @@ INITIALISATION
<property name="scala.dir" value="${installed.dir}"/>
<property name="scala-library.lib" value="${scala.dir}/lib/scala-library.jar"/>
<property name="scala-compiler.lib" value="${scala.dir}/lib/scala-compiler.jar"/>
- <property name="fjbg.lib" value=""/>
</target>
<target name="init" depends="quick.init, pack.init, latest.init, installed.init">
@@ -98,7 +94,6 @@ INITIALISATION
<path id="scala.classpath">
<pathelement location="${scala-library.lib}"/>
<pathelement location="${scala-compiler.lib}"/>
- <pathelement location="${fjbg.lib}"/> <!-- only present for 'quick' -->
</path>
<fail message="Scala library '${scala-library.lib}' or '${scala-compiler.lib}' is missing/broken">
diff --git a/test/files/bench/equality/eqeq.eqlog b/test/files/bench/equality/eqeq.eqlog
index d1e27aceed..55a5eb430a 100644
--- a/test/files/bench/equality/eqeq.eqlog
+++ b/test/files/bench/equality/eqeq.eqlog
@@ -1,42 +1,42 @@
-Banchmark results for testing equality operations:
-eq.scala: Base case, use eq equality only
-eqeq.scala: Test case, use == instead of eq.
-All tests run on Thinkpad T400, 1.6.0_12 client VM.
-Test command: java eq 5 5
- java eqeq 5 5
-eq.scala, no -optimise
-eq$ 109 78 79 63 63
-eq$ 94 63 63 78 78
-eq$ 94 62 62 62 78
-eq$ 94 78 78 78 78
-eq$ 94 78 78 78 78
-eq.scala, with -optimise
-eq$ 421 63 62 47 63
-eq$ 406 62 62 63 62
-eq$ 407 62 62 78 63
-eq$ 406 63 63 62 62
-eq$ 407 62 62 63 47
-eqeq.scala with version of BoxesRuntime as of Nov 13th, no -optimise
-eqeq$ 562 516 516 516 515
-eqeq$ 547 515 515 531 532
-eqeq$ 532 516 516 515 516
-eqeq$ 547 531 531 516 531
-eqeq$ 547 515 515 516 516
-eqeq.scala with version of BoxesRuntime as of Nov 13th, with -optimise
-eqeq$ 1031 390 391 391 391
-eqeq$ 1031 391 391 391 390
-eqeq$ 1031 390 390 391 391
-eqeq$ 1031 406 407 391 390
-eqeq$ 1031 390 390 391 391
-eqeq.scala with 1st optimized of Nov 14th, no -optimise
-eqeq$ 484 421 438 438 437
-eqeq$ 484 438 437 437 438
-eqeq$ 469 437 453 454 438
-eqeq$ 468 437 438 468 438
-eqeq$ 485 437 437 422 438
-eqeq.scala with 1st optimized of Nov 14th, with -optimise
-eqeq$ 1016 375 391 375 375
-eqeq$ 1016 375 391 390 375
-eqeq$ 1016 390 391 375 375
-eqeq$ 1015 375 391 390 375
-eqeq$ 1016 390 375 375 375
+Banchmark results for testing equality operations:
+eq.scala: Base case, use eq equality only
+eqeq.scala: Test case, use == instead of eq.
+All tests run on Thinkpad T400, 1.6.0_12 client VM.
+Test command: java eq 5 5
+ java eqeq 5 5
+eq.scala, no -optimise
+eq$ 109 78 79 63 63
+eq$ 94 63 63 78 78
+eq$ 94 62 62 62 78
+eq$ 94 78 78 78 78
+eq$ 94 78 78 78 78
+eq.scala, with -optimise
+eq$ 421 63 62 47 63
+eq$ 406 62 62 63 62
+eq$ 407 62 62 78 63
+eq$ 406 63 63 62 62
+eq$ 407 62 62 63 47
+eqeq.scala with version of BoxesRuntime as of Nov 13th, no -optimise
+eqeq$ 562 516 516 516 515
+eqeq$ 547 515 515 531 532
+eqeq$ 532 516 516 515 516
+eqeq$ 547 531 531 516 531
+eqeq$ 547 515 515 516 516
+eqeq.scala with version of BoxesRuntime as of Nov 13th, with -optimise
+eqeq$ 1031 390 391 391 391
+eqeq$ 1031 391 391 391 390
+eqeq$ 1031 390 390 391 391
+eqeq$ 1031 406 407 391 390
+eqeq$ 1031 390 390 391 391
+eqeq.scala with 1st optimized of Nov 14th, no -optimise
+eqeq$ 484 421 438 438 437
+eqeq$ 484 438 437 437 438
+eqeq$ 469 437 453 454 438
+eqeq$ 468 437 438 468 438
+eqeq$ 485 437 437 422 438
+eqeq.scala with 1st optimized of Nov 14th, with -optimise
+eqeq$ 1016 375 391 375 375
+eqeq$ 1016 375 391 390 375
+eqeq$ 1016 390 391 375 375
+eqeq$ 1015 375 391 390 375
+eqeq$ 1016 390 375 375 375
diff --git a/test/files/continuations-run/implicit-infer-annotations.check b/test/files/continuations-run/implicit-infer-annotations.check
new file mode 100644
index 0000000000..e8206c4319
--- /dev/null
+++ b/test/files/continuations-run/implicit-infer-annotations.check
@@ -0,0 +1,5 @@
+Range(5, 6, 7, 8, 9, 10)
+Range(5, 6, 7, 8, 9, 10)
+15
+List(10, 1, 2, 3)
+Range(5, 6, 7, 8, 9, 10)
diff --git a/test/files/continuations-run/implicit-infer-annotations.scala b/test/files/continuations-run/implicit-infer-annotations.scala
new file mode 100644
index 0000000000..3f0e959f60
--- /dev/null
+++ b/test/files/continuations-run/implicit-infer-annotations.scala
@@ -0,0 +1,59 @@
+import annotation._
+
+object A {
+ class foo[-B,+C] extends StaticAnnotation with TypeConstraint
+
+ def shift[A, B, C](fun: (A => B) => C): A @foo[B, C] = ???
+ def reset[A, C](ctx: => (A @foo[A, C])): C = ???
+
+ def m1 = reset { shift { f: (Int => Range) => f(5) }.to(10) }
+}
+
+object B {
+ import scala.util.continuations._
+
+ def m1 = reset { shift { f: (Int => Range) => f(5) }.to(10) }
+ def m2 = reset { val a = shift { f: (Int => Range) => f(5) } ; a.to(10) }
+
+ val x1 = reset{
+ shift{ cont: (Int => Range) =>
+ cont(5)
+ }.to(10)
+ }
+
+ val x2 = reset{
+ val a = shift{ cont: (Int => Range) =>
+ cont(5)
+ }
+ a.to(10)
+ } // x is now Range(5, 6, 7, 8, 9, 10)
+
+ val x3 = reset{
+ shift{ cont: (Int => Int) =>
+ cont(5)
+ } + 10
+ } // x is now 15
+
+ val x4 = reset{
+ 10 :: shift{ cont: (List[Int] => List[Int]) =>
+ cont(List(1, 2, 3))
+ }
+ } // x is List(10, 1, 2, 3)
+
+ val x5 = reset{
+ new scala.runtime.RichInt(shift{ cont: (Int => Range) =>
+ cont(5)
+ }) to 10
+ }
+}
+
+object Test {
+ def main(args: Array[String]): Unit = {
+ import B._
+ println(x1)
+ println(x2)
+ println(x3)
+ println(x4)
+ println(x5)
+ }
+}
diff --git a/test/files/detach-neg/det_bar.check b/test/files/detach-neg/det_bar.check
deleted file mode 100644
index 70b47581a5..0000000000
--- a/test/files/detach-neg/det_bar.check
+++ /dev/null
@@ -1,4 +0,0 @@
-det_bar.scala:7: error: detach inapplicable for method bar
- detach(bar)
- ^
-one error found
diff --git a/test/files/detach-neg/det_bar.scala b/test/files/detach-neg/det_bar.scala
deleted file mode 100644
index 862afb1d6e..0000000000
--- a/test/files/detach-neg/det_bar.scala
+++ /dev/null
@@ -1,13 +0,0 @@
-import scala.remoting._
-class A(y: Int) {
- var z = 2
- var bar = (x: Int) => x + y + z
- def foo(x: Int): Int = x + y + z
- bar = (x: Int) => x * y
- detach(bar)
-}
-
-object test extends App {
- val a = new A(1)
- println(a.bar(2))
-}
diff --git a/test/files/detach-run/actor-run.check b/test/files/detach-run/actor-run.check
deleted file mode 100644
index 9448ddd5fe..0000000000
--- a/test/files/detach-run/actor-run.check
+++ /dev/null
@@ -1,5 +0,0 @@
-Server.main 8889
-Client.main 127.0.0.1 8889
-yInstVal = 10
-zLocVal = 1000
-result received: 11111
diff --git a/test/files/detach-run/actor/Client.scala b/test/files/detach-run/actor/Client.scala
deleted file mode 100644
index 12573e24d3..0000000000
--- a/test/files/detach-run/actor/Client.scala
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * @author Stephane Micheloud
- */
-
-import scala.actors.Actor._, ClientHelper._
-import scala.actors.remote._, RemoteActor._
-import scala.remoting._, Debug._
-
-object Foo {
- def trace(msg: String) { info("[Foo.trace] "+msg)}
-}
-object Client {
- val yInstVal: Int = 10
- var yInstVar: Int = 99
- object Bar {
- def trace(msg: String) { info("[Bar.trace] "+msg) }
- }
- def main(args: Array[String]) {
- init(args)
- actor {
- val server = select(Node(host, port), 'Server)
- val zLocVal: Int = 1000
- var zLocVar: Int = 9998
- server ! detach(
- (x: Int) => {
- println("yInstVal = "+yInstVal)
- this.trace("yInstVar = "+yInstVar)
- Bar.trace("zLocVal = "+zLocVal)
- Foo.trace("zLocVar = "+zLocVar)
- zLocVar += 2
- System.out.println("zLocVal = "+zLocVal)
- Debug.info("zLocVar = "+zLocVar)
- x + yInstVal + yInstVar + zLocVal + zLocVar
- })
- react {
- case result: Int =>
- println("result received: " + result)
- Predef.exit(0)
- }
- }
- }
- private def trace(msg: String) { info("[Client.trace] "+msg) }
-}
-
-object ClientHelper {
- private var _host = "127.0.0.1"
- private var _port = 8888
- def host = _host
- def port = _port
- def init(args: Array[String]) {
- try { _host = args(0) } catch { case _ => }
- try { _port = args(1).toInt } catch { case _ => }
- }
-}
diff --git a/test/files/detach-run/actor/Server.scala b/test/files/detach-run/actor/Server.scala
deleted file mode 100644
index b56d22f744..0000000000
--- a/test/files/detach-run/actor/Server.scala
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * @author Stephane Micheloud
- */
-
-import scala.actors.Actor._
-import scala.actors.remote.RemoteActor._
-
-object Server extends ServerConsole {
- private def computation(f: Int => Int): Int = {
- //some time-consuming task
- f(2)
- }
- def main(args: Array[String]) {
- actor {
- classLoader = serverClassLoader
- alive(args(0).toInt)
- register('Server, self)
- loopWhile(isRunning) {
- react {
- case f: (Int => Int) =>
- val result = computation(f)
- sender ! result
- }
- }
- }
- }
-}
diff --git a/test/files/detach-run/actor/ServerConsole.scala b/test/files/detach-run/actor/ServerConsole.scala
deleted file mode 100644
index 8ebd9d4c2e..0000000000
--- a/test/files/detach-run/actor/ServerConsole.scala
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * @author Stephane Micheloud
- */
-
-import java.io.{BufferedReader, InputStreamReader}
-
-import scala.compat.Platform.currentTime
-import scala.remoting.Debug, Debug._
-
-trait ServerConsole extends Thread {
- private val startTime = currentTime
- actors.Debug.level = // e.g. 3 // info+warning+error
- try { System.getProperty("scala.actors.logLevel", "0").toInt }
- catch { case e => 0 }
-
- start()
-
- val serverClassLoader = {
- import java.rmi.server.RMIClassLoader
- val codebase = System.getProperty("java.rmi.server.codebase")
- info("[ServerConsole] codebase="+codebase)
- RMIClassLoader getClassLoader codebase
- }
-
- private var isTerminated = false
-
- def terminate() { isTerminated = false }
-
- def isRunning = !isTerminated
-
- override def run() {
- val in = new BufferedReader(new InputStreamReader(System.in))
- var quit = false
- while (!quit) {
- val args = getArgs(in)
- if (args contains "quit")
- quit = true
- if (args contains "cls") {
- println(ERASE_SCREEN)
- println(CURSOR_HOME)
- }
- if (args contains "warning")
- Debug.level = Level.WARNING
- if (args contains "info")
- Debug.level = Level.INFO
- if (args contains "silent")
- Debug.level = Level.SILENT
- }
- terminate()
- println("Server exited ("+mkTimeString(currentTime - startTime)+")")
- sys.exit(0)
- }
-
- protected def trace(msg: String) {
- Debug.info("[ServerConsole.trace] "+msg)
- }
-
- private def getArgs(in: BufferedReader): List[String] = {
- val input = try { in.readLine() } catch { case _ => null }
- if (input != null) (input.trim split "\\s+").toList else Nil
- }
-
- private def mkTimeString(time: Long): String = {
- def twoDigits(i: Long) = (if (i < 10) "0" else "")+i
- val sec = time / 1000
- val min = sec / 60
- val h = min / 60
- twoDigits(h) +":"+
- twoDigits(min - h * 60)+":"+
- twoDigits(sec - min * 60)
- }
-
- private val ERASE_SCREEN = "\033[2J"
- private val CURSOR_HOME = "\033[H"
-}
diff --git a/test/files/detach-run/actor/actor.flags b/test/files/detach-run/actor/actor.flags
deleted file mode 100644
index 55eed8bbcd..0000000000
--- a/test/files/detach-run/actor/actor.flags
+++ /dev/null
@@ -1 +0,0 @@
--Xpluginsdir ../../../../build/pack/misc/scala-devel/plugins -Xplugin-require:detach -P:detach:enable
diff --git a/test/files/detach-run/actor/actor.scala b/test/files/detach-run/actor/actor.scala
deleted file mode 100644
index 23a10d6982..0000000000
--- a/test/files/detach-run/actor/actor.scala
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * @author Stephane Micheloud
- */
-
-object Test {
-
- val name = "actor"
- val host = "127.0.0.1"
- val port = 8889
-
- def main(args: Array[String]) {
- setenv()
- println("Server.main "+port)
- Server.main(Array(port.toString))
- println("Client.main "+host+" "+port)
- Client.main(Array(host, port.toString))
- Server.terminate()
- }
-
- private def setenv() {
- import Env._
-
- // Java properties for server & client
- System.setProperty("scala.actors.logLevel", actors_logLevel)
- System.setProperty("scala.remoting.logLevel", logLevel)
- System.setProperty("java.security.manager", "")
- System.setProperty("java.security.policy", policyFile)
- // Java properties for server only
- System.setProperty("java.rmi.server.codebase", deployUrl)
- System.setProperty("java.rmi.server.hostname", host)
- System.setProperty("java.rmi.server.useCodebaseOnly", "true")
-
- // application-specific classes to be deployed and accessed via URL
- // (i.e. detached closure, proxy interfaces and proxy stubs)
- val classNames = List(
- "$anonfun$main$1$proxy",
- "$anonfun$main$1$proxyImpl_Stub",
- "Bar$proxy",
- "Bar$proxyImpl_Stub",
- "Client$$anonfun$main$1$$anonfun$apply$1$detach",
- "Client$proxy",
- "Client$proxyImpl_Stub",
- "Foo$proxy",
- "Foo$proxyImpl_Stub")
-
- val proxyImplNames =
- for (n <- classNames; i = n lastIndexOf "_Stub"; if i > 0)
- yield n.substring(0, i)
-
- generatePolicyFile()
- generateRmiStubs(proxyImplNames)
- generateJarFile(classNames)
- }
-}
-
-object Env {
- import java.io._, java.util.jar._
-
- val actors_logLevel = "0"
- // = "3" // info+warning+error
- val logLevel = "silent"
- // = "info" // debug user code only
- // = "info,lib" // debug user & library code
-
- // we assume an Apache server is running locally for deployment
- private val sep = File.separator
- val docPath = System.getProperty("user.home")+sep+"public_html"
- val docRoot = "http://127.0.0.1/~"+System.getProperty("user.name")
-
- private val policyTmpl =
- System.getProperty("partest.cwd")+sep+Test.name+sep+"java.policy"
- val outPath = System.getProperty("partest.output")
- val libPath = System.getProperty("partest.lib")
- val policyFile = outPath+sep+"java.policy"
- val codebaseDir = outPath+sep+"-"
-
- assert((new File(docPath)).isDirectory,
- "Root directory \""+docPath+"\" not found")
- val deployJar = docPath+sep+Test.name+"_deploy.jar"
- val deployUrl = docRoot+"/"+Test.name+"_deploy.jar"
-
- def generatePolicyFile() {
- val in = new BufferedReader(new FileReader(policyTmpl))
- val out = new PrintWriter(new BufferedWriter(new FileWriter(policyFile)))
- var line = in.readLine()
- while (line != null) {
- val line1 = line.replaceAll("@PROJECT_LIB_BASE@", codebaseDir)
- out.println(line1)
- line = in.readLine()
- }
- in.close()
- out.close()
- }
-
- def generateRmiStubs(classNames: List[String]) {
- val options = List(
- "-v1.2",
- "-classpath "+libPath+File.pathSeparator+outPath,
- "-d "+outPath)
- rmic(options, classNames)
- //ls(outPath)
- }
-
- def generateJarFile(classNames: List[String]) {
- val out = new JarOutputStream(new FileOutputStream(deployJar))
- classNames foreach (name => try {
- val classFile = name+".class"
- val in = new FileInputStream(outPath+sep+classFile)
- out putNextEntry new JarEntry(classFile)
- val buf = new Array[Byte](512)
- var len = in read buf
- while (len != -1) {
- out.write(buf, 0, len)
- len = in read buf
- }
- in.close()
- } catch {
- case e: FileNotFoundException => println(e)
- })
- out.close()
- }
-
- private def ls(path: String) { exec("ls -al "+path) }
-
- private def rmic(options: List[String], classNames: List[String]) {
- val javaHome = scala.util.Properties.javaHome
- val jdkHome =
- if (javaHome endsWith "jre") javaHome.substring(0, javaHome.length-4)
- else javaHome
- val rmicExt = if (scala.util.Properties.isWin) ".exe" else ""
- val rmicCmd = jdkHome+sep+"bin"+sep+"rmic"+rmicExt
- val cmdLine = rmicCmd+options.mkString(" ", " ", "")+
- classNames.mkString(" "," ","")
- // println(cmdLine)
- exec(cmdLine)
- }
-
- private def exec(command: String) {
- val proc = Runtime.getRuntime exec command
- proc.waitFor()
- val out = new BufferedReader(new InputStreamReader(proc.getInputStream))
- var line = out.readLine()
- while (line != null) {
- println(line)
- line = out.readLine()
- }
- out.close()
- val err = new BufferedReader(new InputStreamReader(proc.getErrorStream))
- line = err.readLine()
- while (line != null) {
- println(line)
- line = err.readLine()
- }
- err.close()
- }
-}
-
diff --git a/test/files/detach-run/actor/java.policy b/test/files/detach-run/actor/java.policy
deleted file mode 100644
index 4beb2ca26b..0000000000
--- a/test/files/detach-run/actor/java.policy
+++ /dev/null
@@ -1,25 +0,0 @@
-// See http://java.sun.com/javase/6/docs/technotes/guides/security/permissions.html
-// See http://mindprod.com/jgloss/policyfile.html
-// The policy expands ${/} to the correct path or folder delimiter on your host platform.
-
-// Actions available with SocketPermission: accept, connect, listen, resolve
-// 1) The "resolve" action is implied when any of the other actions are present.
-// 2) The "listen" action is only meaningful when used with "localhost".
-
-grant {
- permission java.net.SocketPermission "*:80", "connect,accept,listen";
- permission java.net.SocketPermission "*:1024-", "connect,accept,listen";
- permission java.util.PropertyPermission "scala.remoting.logLevel", "read";
- permission java.util.PropertyPermission "scala.remoting.port", "read";
-};
-
-grant codeBase "@PROJECT_LIB_BASE@" {
- permission java.lang.RuntimePermission "getClassLoader";
- permission java.util.PropertyPermission "java.rmi.server.codebase", "read";
- permission java.util.PropertyPermission "java.rmi.server.hostname", "read";
- permission java.util.PropertyPermission "sun.rmi.dgc.server.gcInterval", "read,write";
-};
-
-//grant {
-// permission java.security.AllPermission;
-//};
diff --git a/test/files/detach-run/basic-run.check b/test/files/detach-run/basic-run.check
deleted file mode 100644
index 6463d97497..0000000000
--- a/test/files/detach-run/basic-run.check
+++ /dev/null
@@ -1,5 +0,0 @@
-Server.main 8889
-> Client.main 127.0.0.1 8889
-yInstVal = 10
-zLocVal = 1000
-result received: 11111
diff --git a/test/files/detach-run/basic/Client.scala b/test/files/detach-run/basic/Client.scala
deleted file mode 100644
index f8eddb041d..0000000000
--- a/test/files/detach-run/basic/Client.scala
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * @author Stephane Micheloud
- */
-
-import java.net._, Thread._, ClientHelper._
-import scala.remoting._, Debug._
-
-object Foo {
- def trace(s: String) { info("[Foo.trace] "+s)}
-}
-object Client {
- val yInstVal: Int = 10
- var yInstVar: Int = 99
- object Bar {
- def trace(s: String) { info("[Bar.trace] "+s) }
- }
- def main(args: Array[String]) {
- init(args)
- val server = new Channel(host, port)
- val zLocVal: Int = 1000
- var zLocVar: Int = 9998
- server ! detach(
- (x: Int) => {
- println("yInstVal = "+yInstVal)
- this.trace("yInstVar = "+yInstVar)
- Bar.trace("zLocVal = "+zLocVal)
- Foo.trace("zLocVar = "+zLocVar)
- zLocVar += 2
- System.out.println("zLocVal = "+zLocVal)
- Debug.info("zLocVar = "+zLocVar)
- x + yInstVal + yInstVar + zLocVal + zLocVar
- })
- val result = server.receiveInt
- println("result received: " + result)
- }
- private def trace(s: String) { info("[Client.trace] "+s) }
-}
-
-object ClientHelper {
- private var _host = "127.0.0.1"
- private var _port = 8888
- def host = _host
- def port = _port
- def init(args: Array[String]) {
- try { _host = args(0) } catch { case _ => }
- try { _port = args(1).toInt } catch { case _ => }
- }
-}
diff --git a/test/files/detach-run/basic/Server.scala b/test/files/detach-run/basic/Server.scala
deleted file mode 100644
index f8aa02a4ba..0000000000
--- a/test/files/detach-run/basic/Server.scala
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * @author Stephane Micheloud
- */
-
-import scala.remoting.ServerChannel
-
-object Server extends ServerConsole {
- private def computation(f: Int => Int): Int = {
- //some time-consuming task
- f(2)
- }
- def main(args: Array[String]) {
- val server = new ServerChannel(args(0).toInt)
- loop {
- val client = server.accept
- val f = client.receive[Int => Int]
- val result = computation(f)
- client ! result
- }
- server.close()
- }
-}
diff --git a/test/files/detach-run/basic/ServerConsole.scala b/test/files/detach-run/basic/ServerConsole.scala
deleted file mode 100644
index 65b81c0ca1..0000000000
--- a/test/files/detach-run/basic/ServerConsole.scala
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * @author Stephane Micheloud
- */
-
-import java.io._
-
-import scala.compat.Platform.currentTime
-import scala.remoting.Debug, Debug._
-
-trait ServerConsole extends Thread {
- private val startTime = currentTime
-
- start()
-
- private var isTerminated = false
-
- def terminate() { isTerminated = true }
-
- protected def loop(block: => Unit) {
- while (!isTerminated) {
- try {
- block
- }
- catch {
- case e: ObjectStreamException =>
- trace("Object stream error ("+e.getMessage+")")
- case e: EOFException =>
- trace("Connection lost")
- case e: ClassNotFoundException =>
- trace("Class not found")
- case e =>
- trace("Server error: "+e)
- }
- }
- }
-
- override def run() {
- val in = new BufferedReader(new InputStreamReader(System.in))
- var quit = false
- while (!quit) {
- val args = getArgs(in)
- if (args contains "quit")
- quit = true
- if (args contains "cls") {
- println(ERASE_SCREEN)
- println(CURSOR_HOME)
- }
- if (args contains "warning")
- Debug.level = Level.WARNING
- if (args contains "info")
- Debug.level = Level.INFO
- if (args contains "silent")
- Debug.level = Level.SILENT
- }
- terminate()
- println("Server exited ("+mkTimeString(currentTime - startTime)+")")
- exit(0)
-
- }
-
- protected def trace(msg: String) {
- Debug.info("[ServerConsole.trace] "+msg)
- }
-
- private def getArgs(in: BufferedReader): List[String] = {
- print("> ")
- val input = try { in.readLine() } catch { case _ => null }
- if (input != null) (input.trim split "\\s+").toList else Nil
- }
-
- private def mkTimeString(time: Long): String = {
- def twoDigits(i: Long) = (if (i < 10) "0" else "")+i
- val sec = time / 1000
- val min = sec / 60
- val h = min / 60
- twoDigits(h) +":"+
- twoDigits(min - h * 60)+":"+
- twoDigits(sec - min * 60)
- }
-
- private val ERASE_SCREEN = "\033[2J"
- private val CURSOR_HOME = "\033[H"
-}
diff --git a/test/files/detach-run/basic/basic.flags b/test/files/detach-run/basic/basic.flags
deleted file mode 100644
index 55eed8bbcd..0000000000
--- a/test/files/detach-run/basic/basic.flags
+++ /dev/null
@@ -1 +0,0 @@
--Xpluginsdir ../../../../build/pack/misc/scala-devel/plugins -Xplugin-require:detach -P:detach:enable
diff --git a/test/files/detach-run/basic/basic.scala b/test/files/detach-run/basic/basic.scala
deleted file mode 100644
index 4d0fc2d933..0000000000
--- a/test/files/detach-run/basic/basic.scala
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- * @author Stephane Micheloud
- */
-
-object Test {
-
- val name = "basic"
- val host = "127.0.0.1"
- val port = 8889
-
- def main(args: Array[String]) {
- setenv()
- println("Server.main "+port)
- server.start()
- println("Client.main "+host+" "+port)
- client.start()
- server.terminate()
- }
-
- private var server = new ServerThread(port)
- private var client = new ClientThread(host, port)
-
- private class ServerThread(port: Int) extends Runnable {
- private var th = new Thread(this)
- def start() { th.start(); Thread.sleep(1000) }
- def run() { Server.main(Array(port.toString)) }
- def terminate() { Server.terminate(); sys.exit(0) }
- }
-
- private class ClientThread(host: String, port: Int) extends Runnable {
- private var th = new Thread(this)
- def start() { th.start(); th.join() }
- def run() { Client.main(Array(host, port.toString)) }
- }
-
- private def setenv() {
- import Env._
-
- // Java properties for server & client
- System.setProperty("scala.remoting.logLevel", logLevel)
- System.setProperty("java.security.manager", "")
- System.setProperty("java.security.policy", policyFile)
- // Java properties for server only
- System.setProperty("java.rmi.server.codebase", deployUrl)
- System.setProperty("java.rmi.server.hostname", host)
- System.setProperty("java.rmi.server.useCodebaseOnly", "true")
-
- // application-secific classes to be deployed and accessed via URL
- // (i.e. detached closure, proxy interfaces and proxy stubs)
- val classNames = List(
- "Bar$proxy",
- "Bar$proxyImpl_Stub",
- "Client$$anonfun$main$1$detach",
- "Client$proxy",
- "Client$proxyImpl_Stub",
- "Foo$proxy",
- "Foo$proxyImpl_Stub")
-
- val proxyImplNames =
- for (n <- classNames; i = n lastIndexOf "_Stub"; if i > 0)
- yield n.substring(0, i)
-
- generatePolicyFile()
- generateRmiStubs(proxyImplNames)
- generateJarFile(classNames)
- }
-}
-
-object Env {
- import java.io._, java.util.jar._
-
- val actors_logLevel = "0"
- // = "3" // info+warning+error
- val logLevel = "silent"
- // = "info" // debug user code only
- // = "info,lib" // debug user & library code
-
- // we assume an Apache server is running locally for deployment
- private val sep = File.separator
- val docPath = System.getProperty("user.home")+sep+"public_html"
- val docRoot = "http://127.0.0.1/~"+System.getProperty("user.name")
-
- private val policyTmpl =
- System.getProperty("partest.cwd")+sep+Test.name+sep+"java.policy"
- val outPath = System.getProperty("partest.output")
- val libPath = System.getProperty("partest.lib")
- val policyFile = outPath+sep+"java.policy"
- val codebaseDir = outPath+sep+"-"
-
- assert((new File(docPath)).isDirectory,
- "Root directory \""+docPath+"\" not found")
- val deployJar = docPath+sep+Test.name+"_deploy.jar"
- val deployUrl = docRoot+"/"+Test.name+"_deploy.jar"
-
- def generatePolicyFile() {
- val in = new BufferedReader(new FileReader(policyTmpl))
- val out = new PrintWriter(new BufferedWriter(new FileWriter(policyFile)))
- var line = in.readLine()
- while (line != null) {
- val line1 = line.replaceAll("@PROJECT_LIB_BASE@", codebaseDir)
- out.println(line1)
- line = in.readLine()
- }
- in.close()
- out.close()
- }
-
- def generateRmiStubs(classNames: List[String]) {
- val options = List(
- "-v1.2",
- "-classpath "+libPath+File.pathSeparator+outPath,
- "-d "+outPath)
- rmic(options, classNames)
- //ls(outPath)
- }
-
- def generateJarFile(classNames: List[String]) {
- val out = new JarOutputStream(new FileOutputStream(deployJar))
- classNames foreach (name => try {
- val classFile = name+".class"
- val in = new FileInputStream(outPath+sep+classFile)
- out putNextEntry new JarEntry(classFile)
- val buf = new Array[Byte](512)
- var len = in read buf
- while (len != -1) {
- out.write(buf, 0, len)
- len = in read buf
- }
- in.close()
- } catch {
- case e: FileNotFoundException => println(e)
- })
- out.close()
- }
-
- private def ls(path: String) { exec("ls -al "+path) }
-
- private def rmic(options: List[String], classNames: List[String]) {
- val javaHome = scala.util.Properties.javaHome
- val jdkHome =
- if (javaHome endsWith "jre") javaHome.substring(0, javaHome.length-4)
- else javaHome
- val rmicExt = if (scala.util.Properties.isWin) ".exe" else ""
- val rmicCmd = jdkHome+sep+"bin"+sep+"rmic"+rmicExt
- val cmdLine = rmicCmd+options.mkString(" ", " ", "")+
- classNames.mkString(" "," ","")
- // println(cmdLine)
- exec(cmdLine)
- }
-
- private def exec(command: String) {
- val proc = Runtime.getRuntime exec command
- proc.waitFor()
- val out = new BufferedReader(new InputStreamReader(proc.getInputStream))
- var line = out.readLine()
- while (line != null) {
- println(line)
- line = out.readLine()
- }
- out.close()
- val err = new BufferedReader(new InputStreamReader(proc.getErrorStream))
- line = err.readLine()
- while (line != null) {
- println(line)
- line = err.readLine()
- }
- err.close()
- }
-}
diff --git a/test/files/detach-run/basic/java.policy b/test/files/detach-run/basic/java.policy
deleted file mode 100644
index 92c1045c3d..0000000000
--- a/test/files/detach-run/basic/java.policy
+++ /dev/null
@@ -1,26 +0,0 @@
-// See http://java.sun.com/javase/6/docs/technotes/guides/security/permissions.html
-// See http://mindprod.com/jgloss/policyfile.html
-// The policy expands ${/} to the correct path or folder delimiter on your host platform.
-
-// Actions available with SocketPermission: accept, connect, listen, resolve
-// 1) The "resolve" action is implied when any of the other actions are present.
-// 2) The "listen" action is only meaningful when used with "localhost".
-
-grant {
- permission java.net.SocketPermission "*:80", "connect,accept,listen";
- permission java.net.SocketPermission "*:1024-", "connect,accept,listen";
- permission java.util.PropertyPermission "scala.remoting.logLevel", "read";
- permission java.util.PropertyPermission "scala.remoting.port", "read";
-};
-
-grant codeBase "@PROJECT_LIB_BASE@" {
- permission java.lang.RuntimePermission "getClassLoader";
- permission java.lang.RuntimePermission "createClassLoader";
- permission java.util.PropertyPermission "java.rmi.server.codebase", "read";
- permission java.util.PropertyPermission "java.rmi.server.hostname", "read";
- permission java.util.PropertyPermission "sun.rmi.dgc.server.gcInterval", "read,write";
-};
-
-//grant {
-// permission java.security.AllPermission;
-//};
diff --git a/test/files/instrumented/t6611.check b/test/files/instrumented/t6611.check
new file mode 100644
index 0000000000..5cd691e93a
--- /dev/null
+++ b/test/files/instrumented/t6611.check
@@ -0,0 +1 @@
+Method call statistics:
diff --git a/test/files/instrumented/t6611.scala b/test/files/instrumented/t6611.scala
new file mode 100644
index 0000000000..4c52f8a5ef
--- /dev/null
+++ b/test/files/instrumented/t6611.scala
@@ -0,0 +1,35 @@
+import scala.tools.partest.instrumented.Instrumentation._
+
+object Test {
+ def main(args: Array[String]) {
+ startProfiling()
+
+ // tests optimization in Cleanup for varargs reference arrays
+ Array("")
+
+
+ Array(true)
+ Array(true, false)
+ Array(1: Byte)
+ Array(1: Byte, 2: Byte)
+ Array(1: Short)
+ Array(1: Short, 2: Short)
+ Array(1)
+ Array(1, 2)
+ Array(1L)
+ Array(1L, 2L)
+ Array(1d)
+ Array(1d, 2d)
+ Array(1f)
+ Array(1f, 2f)
+
+ /* Not currently optimized:
+ Array[Int](1, 2) etc
+ Array(())
+ Array((), ())
+ */
+
+ stopProfiling()
+ printStatistics()
+ }
+}
diff --git a/test/files/jvm/t1143-2/t1143-2.scala b/test/files/jvm/t1143-2/t1143-2.scala
index 44b1febd8b..13ab13b48c 100644
--- a/test/files/jvm/t1143-2/t1143-2.scala
+++ b/test/files/jvm/t1143-2/t1143-2.scala
@@ -16,43 +16,39 @@ object Serialize {
}
}
-@serializable
@SerialVersionUID(1L)
-class VarModel[T]( getter: => T, setter: T => Unit )
-{
+class VarModel[T](getter: => T, setter: T => Unit) extends Serializable {
Serialize.write(getter)
Serialize.write(setter)
- def this( getter: => T ) = this( getter, null )
+ def this(getter: => T) = this(getter, null)
def getObject: AnyRef = getter.asInstanceOf[AnyRef]
- def setObject( v: AnyRef ) = {
- if( setter==null )
- throw new RuntimeException( "Tried to set readonly model!")
- setter( v.asInstanceOf[T] )
+ def setObject(v: AnyRef) = {
+ if(setter==null)
+ throw new RuntimeException("Tried to set readonly model!")
+ setter(v.asInstanceOf[T])
}
def detach = ()
}
-@serializable
@SerialVersionUID(1L)
-class Printer( p: VarModel[String] ) {
- def print = println( p.getObject );
+class Printer(p: VarModel[String]) extends Serializable {
+ def print = println(p.getObject)
}
class Component extends Marker { }
class Form extends Component { }
-@serializable
@SerialVersionUID(1L)
-class Main {
+class Main extends Serializable {
var pass = "pass"
- def main(args : Array[String]) : Unit = {
+ def main(args: Array[String]): Unit = {
val f = new Form {
- val p = new Printer( new VarModel( pass, s => pass = s ) );
+ val p = new Printer(new VarModel(pass, s => pass = s))
p.print
}
()
diff --git a/test/files/jvm/t1143.scala b/test/files/jvm/t1143.scala
index 7dd374f432..eb03c7224e 100644
--- a/test/files/jvm/t1143.scala
+++ b/test/files/jvm/t1143.scala
@@ -16,9 +16,8 @@ object Serialize {
}
}
-@serializable
@SerialVersionUID(1L)
-class VarModel[T](getter: => T, setter: T => Unit) {
+class VarModel[T](getter: => T, setter: T => Unit) extends Serializable {
Serialize.write(getter)
Serialize.write(setter)
@@ -35,23 +34,20 @@ class VarModel[T](getter: => T, setter: T => Unit) {
def detach = ()
}
-@serializable
@SerialVersionUID(1L)
-class Printer(p: VarModel[String]) {
+class Printer(p: VarModel[String]) extends Serializable {
def print = println(p.getObject)
}
-@serializable
@SerialVersionUID(1L)
-class Component {
+class Component extends Serializable {
}
class Form extends Component {
}
-@serializable
@SerialVersionUID(1L)
-class Main {
+class Main extends Serializable {
var pass = "pass"
def main(args: Array[String]) {
val f = new Form {
diff --git a/test/files/jvm/t1342/SI.scala b/test/files/jvm/t1342/SI.scala
index 8e3b753210..7c37d4bcd7 100644
--- a/test/files/jvm/t1342/SI.scala
+++ b/test/files/jvm/t1342/SI.scala
@@ -4,7 +4,7 @@ class SI extends JI {
}
}
-object Test extends Application {
+object Test extends App {
val x: JI = new SI
x.varArgsMethod("one", "two")
}
diff --git a/test/files/jvm/t1600.scala b/test/files/jvm/t1600.scala
index 7e23687425..69179c1ba4 100644
--- a/test/files/jvm/t1600.scala
+++ b/test/files/jvm/t1600.scala
@@ -69,8 +69,7 @@ object Test {
var hashCodeModifier = 0
}
- @serializable
- class Foo {
+ class Foo extends Serializable {
override def hashCode = System.identityHashCode(this) + Foo.hashCodeModifier
}
}
diff --git a/test/files/jvm/ticket2163/ticket2163.java b/test/files/jvm/t2163/t2163.java
index b6511d241c..83bd37d212 100644
--- a/test/files/jvm/ticket2163/ticket2163.java
+++ b/test/files/jvm/t2163/t2163.java
@@ -1,9 +1,9 @@
import java.util.*;
-public class ticket2163 {
+public class t2163 {
public void test() {
List<Integer> array = new ArrayList<Integer>();
- Ticket2163Scala<List> foo = new Ticket2163Scala<List>(array);
+ T2163Scala<List> foo = new T2163Scala<List>(array);
foo.bar(array);
}
}
diff --git a/test/files/jvm/t2163/t2163.scala b/test/files/jvm/t2163/t2163.scala
new file mode 100644
index 0000000000..f73b520cbe
--- /dev/null
+++ b/test/files/jvm/t2163/t2163.scala
@@ -0,0 +1,5 @@
+class T2163Scala[CC[X]](x: CC[Int]) {
+ def bar[DD[X]](meh: DD[Int]): CC[Int] = x
+}
+
+object Test extends App {}
diff --git a/test/files/jvm/t2470.cmds b/test/files/jvm/t2470.cmds
deleted file mode 100644
index b4ef0f4aeb..0000000000
--- a/test/files/jvm/t2470.cmds
+++ /dev/null
@@ -1,3 +0,0 @@
-javac Action.java Task.java
-scalac Test_1.scala
-scalac Read_Classfile_2.scala
diff --git a/test/files/jvm/t2570/Test.scala b/test/files/jvm/t2570/Test.scala
index 7944aedae6..f1cba53546 100644
--- a/test/files/jvm/t2570/Test.scala
+++ b/test/files/jvm/t2570/Test.scala
@@ -1,3 +1,3 @@
class Test2 extends Test1[Test3[Test4]]
class Test4
-object Test extends Application {} \ No newline at end of file
+object Test extends App {} \ No newline at end of file
diff --git a/test/files/jvm/t3003.cmds b/test/files/jvm/t3003.cmds
deleted file mode 100644
index c00396627c..0000000000
--- a/test/files/jvm/t3003.cmds
+++ /dev/null
@@ -1,2 +0,0 @@
-javac Annot.java
-scalac Test_1.scala
diff --git a/test/files/jvm/t3415/HelloWorld.scala b/test/files/jvm/t3415/HelloWorld.scala
index 53bf55e444..5ef012390e 100644
--- a/test/files/jvm/t3415/HelloWorld.scala
+++ b/test/files/jvm/t3415/HelloWorld.scala
@@ -1,4 +1,4 @@
-object Test extends Application {
+object Test extends App {
@Hello
def foo() { }
}
diff --git a/test/files/jvm/ticket4283/AbstractFoo.java b/test/files/jvm/t4283/AbstractFoo.java
index 74f3827fe3..74f3827fe3 100644
--- a/test/files/jvm/ticket4283/AbstractFoo.java
+++ b/test/files/jvm/t4283/AbstractFoo.java
diff --git a/test/files/jvm/ticket4283/ScalaBipp.scala b/test/files/jvm/t4283/ScalaBipp.scala
index 36dea9f4de..36dea9f4de 100644
--- a/test/files/jvm/ticket4283/ScalaBipp.scala
+++ b/test/files/jvm/t4283/ScalaBipp.scala
diff --git a/test/files/jvm/ticket4283/Test.scala b/test/files/jvm/t4283/Test.scala
index 9bbfaab928..9bbfaab928 100644
--- a/test/files/jvm/ticket4283/Test.scala
+++ b/test/files/jvm/t4283/Test.scala
diff --git a/test/files/jvm/ticket2163/ticket2163.scala b/test/files/jvm/ticket2163/ticket2163.scala
deleted file mode 100644
index d30bfe251b..0000000000
--- a/test/files/jvm/ticket2163/ticket2163.scala
+++ /dev/null
@@ -1,5 +0,0 @@
-class Ticket2163Scala[CC[X]](x: CC[Int]) {
- def bar[DD[X]](meh: DD[Int]): CC[Int] = x
-}
-
-object Test extends Application {}
diff --git a/test/files/jvm/typerep.scala b/test/files/jvm/typerep.scala
index 3befc7ff3f..47bd16a467 100644
--- a/test/files/jvm/typerep.scala
+++ b/test/files/jvm/typerep.scala
@@ -280,100 +280,74 @@ object TypeRep {
override def toString = "Nothing"
}
- @serializable
case class ClassRep[A](elemRep: TypeRep[A]) extends TypeRep[Class[A]] {
override def toString = "Class[" + elemRep + "]"
}
- @serializable
case class SomeRep[A](elemRep: TypeRep[A]) extends TypeRep[Some[A]] {
override def toString = "Some[" + elemRep + "]"
}
- @serializable
case class NoneRep[A](elemRep: TypeRep[A]) extends TypeRep[Option[A]] {
override def toString = "None[" + elemRep + "]"
}
-
- @serializable
case class ListRep[A](elemRep: TypeRep[A]) extends TypeRep[List[A]] {
override def toString = "List[" + elemRep + "]"
}
-
- @serializable
case class ArrayRep[A](elemRep: TypeRep[A]) extends TypeRep[Array[A]] {
override def toString = "Array[" + elemRep + "]"
}
-
- @serializable
case class Tuple2Rep[A1, A2](_1: TypeRep[A1], _2: TypeRep[A2]) extends TypeRep[(A1, A2)] {
override def toString = "Tuple2[" + _1 + ", " + _2 + "]"
}
- @serializable
case class Tuple3Rep[A1, A2, A3](_1: TypeRep[A1], _2: TypeRep[A2], _3: TypeRep[A3]) extends TypeRep[Tuple3[A1, A2, A3]] {
override def toString = "Tuple3[" + _1 + ", " + _2 + ", " + _3 + "]"
}
- @serializable
case class Tuple4Rep[A1, A2, A3, A4](_1: TypeRep[A1], _2: TypeRep[A2], _3: TypeRep[A3], _4: TypeRep[A4]) extends TypeRep[Tuple4[A1, A2, A3, A4]] {
override def toString = "Tuple4[" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + "]"
}
- @serializable
case class Tuple5Rep[A1, A2, A3, A4, A5](_1: TypeRep[A1], _2: TypeRep[A2], _3: TypeRep[A3], _4: TypeRep[A4], _5: TypeRep[A5]) extends TypeRep[Tuple5[A1, A2, A3, A4, A5]] {
override def toString = "Tuple5[" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ", " + _5 + "]"
}
- @serializable
case class Tuple6Rep[A1, A2, A3, A4, A5, A6](val _1: TypeRep[A1], val _2: TypeRep[A2], val _3: TypeRep[A3], val _4: TypeRep[A4], val _5: TypeRep[A5], val _6: TypeRep[A6]) extends TypeRep[Tuple6[A1, A2, A3, A4, A5, A6]] {
override def toString = "Tuple6[" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ", " + _5 + ", " + _6 + "]"
}
- @serializable
case class Tuple7Rep[A1, A2, A3, A4, A5, A6, A7](val _1: TypeRep[A1], val _2: TypeRep[A2], val _3: TypeRep[A3], val _4: TypeRep[A4], val _5: TypeRep[A5], val _6: TypeRep[A6], val _7: TypeRep[A7]) extends TypeRep[Tuple7[A1, A2, A3, A4, A5, A6, A7]] {
override def toString = "Tuple7[" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ", " + _5 + ", " + _6 + ", " + _7 + "]"
}
- @serializable
case class Tuple8Rep[A1, A2, A3, A4, A5, A6, A7, A8](val _1: TypeRep[A1], val _2: TypeRep[A2], val _3: TypeRep[A3], val _4: TypeRep[A4], val _5: TypeRep[A5], val _6: TypeRep[A6], val _7: TypeRep[A7], val _8: TypeRep[A8]) extends TypeRep[Tuple8[A1, A2, A3, A4, A5, A6, A7, A8]] {
override def toString = "Tuple8[" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ", " + _5 + ", " + _6 + ", " + _7 + ", " + _8 + "]"
}
- @serializable
case class Tuple9Rep[A1, A2, A3, A4, A5, A6, A7, A8, A9](val _1: TypeRep[A1], val _2: TypeRep[A2], val _3: TypeRep[A3], val _4: TypeRep[A4], val _5: TypeRep[A5], val _6: TypeRep[A6], val _7: TypeRep[A7], val _8: TypeRep[A8], val _9: TypeRep[A9]) extends TypeRep[Tuple9[A1, A2, A3, A4, A5, A6, A7, A8, A9]] {
override def toString = "Tuple9[" + _1 + ", " + _2 + ", " + _3 + ", " + _4 + ", " + _5 + ", " + _6 + ", " + _7 + ", " + _8 + ", " + _9 + "]"
}
- @serializable
case class Function1Rep[A1, B](a1: TypeRep[A1], b: TypeRep[B]) extends TypeRep[Function1[A1, B]] {
override def toString = "Function1[" + a1 + ", " + b + "]"
}
- @serializable
case class Function2Rep[A1, A2, B](a1: TypeRep[A1], a2: TypeRep[A2], b: TypeRep[B]) extends TypeRep[Function2[A1, A2, B]] {
override def toString = "Function2[" + a1 + ", " + a2 + ", " + b + "]"
}
- @serializable
case class Function3Rep[A1, A2, A3, B](a1: TypeRep[A1], a2: TypeRep[A2], a3: TypeRep[A3], b: TypeRep[B]) extends TypeRep[Function3[A1, A2, A3, B]] {
override def toString = "Function3[" + a1 + ", " + a2 + ", " + a3 + ", " + b + "]"
}
- @serializable
case class Function4Rep[A1, A2, A3, A4, B](a1: TypeRep[A1], a2: TypeRep[A2], a3: TypeRep[A3], a4: TypeRep[A4], b: TypeRep[B]) extends TypeRep[Function4[A1, A2, A3, A4, B]] {
override def toString = "Function4[" + a1 + ", " + a2 + ", " + a3 + ", " + a4 + ", " + b + "]"
}
- @serializable
case class Function5Rep[A1, A2, A3, A4, A5, B](a1: TypeRep[A1], a2: TypeRep[A2], a3: TypeRep[A3], a4: TypeRep[A4], a5: TypeRep[A5], b: TypeRep[B]) extends TypeRep[Function5[A1, A2, A3, A4, A5, B]] {
override def toString = "Function5[" + a1 + ", " + a2 + ", " + a3 + ", " + a4 + ", " + a5 + ", " + b + "]"
}
- @serializable
case class Function6Rep[A1, A2, A3, A4, A5, A6, B](a1: TypeRep[A1], a2: TypeRep[A2], a3: TypeRep[A3], a4: TypeRep[A4], a5: TypeRep[A5], a6: TypeRep[A6], b: TypeRep[B]) extends TypeRep[Function6[A1, A2, A3, A4, A5, A6, B]] {
override def toString = "Function6[" + a1 + ", " + a2 + ", " + a3 + ", " + a4 + ", " + a5 + ", " + a6 + ", " + b + "]"
}
- @serializable
case class Function7Rep[A1, A2, A3, A4, A5, A6, A7, B](a1: TypeRep[A1], a2: TypeRep[A2], a3: TypeRep[A3], a4: TypeRep[A4], a5: TypeRep[A5], a6: TypeRep[A6], a7: TypeRep[A7], b: TypeRep[B]) extends TypeRep[Function7[A1, A2, A3, A4, A5, A6, A7, B]] {
override def toString = "Function7[" + a1 + ", " + a2 + ", " + a3 + ", " + a4 + ", " + a5 + ", " + a6 + ", " + a7 + ", " + b + "]"
}
- @serializable
case class Function8Rep[A1, A2, A3, A4, A5, A6, A7, A8, B](a1: TypeRep[A1], a2: TypeRep[A2], a3: TypeRep[A3], a4: TypeRep[A4], a5: TypeRep[A5], a6: TypeRep[A6], a7: TypeRep[A7], a8: TypeRep[A8], b: TypeRep[B]) extends TypeRep[Function8[A1, A2, A3, A4, A5, A6, A7, A8, B]] {
override def toString = "Function8[" + a1 + ", " + a2 + ", " + a3 + ", " + a4 + ", " + a5 + ", " + a6 + ", " + a7 + ", " + a8 + b + "]"
}
- @serializable
case class Function9Rep[A1, A2, A3, A4, A5, A6, A7, A8, A9, B](a1: TypeRep[A1], a2: TypeRep[A2], a3: TypeRep[A3], a4: TypeRep[A4], a5: TypeRep[A5], a6: TypeRep[A6], a7: TypeRep[A7], a8: TypeRep[A8], a9: TypeRep[A9], b: TypeRep[B]) extends TypeRep[Function9[A1, A2, A3, A4, A5, A6, A7, A8, A9, B]] {
override def toString = "Function9[" + a1 + ", " + a2 + ", " + a3 + ", " + a4 + ", " + a5 + ", " + a6 + ", " + a7 + ", " + a8 + ", " + b + "]"
}
/*
- @serializable
case class ObjectRep[A](c: Class) extends TypeRep[A] {
override def toString = c.getName
}
diff --git a/test/files/jvm/xmlattr.scala b/test/files/jvm/xmlattr.scala
index d214642eb6..6423268ba7 100644
--- a/test/files/jvm/xmlattr.scala
+++ b/test/files/jvm/xmlattr.scala
@@ -6,6 +6,7 @@ object Test {
UnprefixedAttributeTest()
AttributeWithOptionTest()
AttributeOutputTest()
+ AttributeOperatorTest()
}
object UnprefixedAttributeTest {
@@ -60,4 +61,10 @@ object Test {
}
}
+ object AttributeOperatorTest {
+ def apply() {
+ val xml = <foo bar="apple" />
+ assert(xml \@ "bar" == "apple")
+ }
+ }
}
diff --git a/test/files/lib/jsoup-1.3.1.jar.desired.sha1 b/test/files/lib/jsoup-1.3.1.jar.desired.sha1
new file mode 100644
index 0000000000..46fa3dae9d
--- /dev/null
+++ b/test/files/lib/jsoup-1.3.1.jar.desired.sha1
@@ -0,0 +1 @@
+346d3dff4088839d6b4d163efa2892124039d216 ?jsoup-1.3.1.jar
diff --git a/test/files/neg/abstract-inaccessible.check b/test/files/neg/abstract-inaccessible.check
index 42b98ac026..d56f5691be 100644
--- a/test/files/neg/abstract-inaccessible.check
+++ b/test/files/neg/abstract-inaccessible.check
@@ -1,13 +1,15 @@
-abstract-inaccessible.scala:5: error: method implementMe in trait YourTrait references private[foo] trait Bippy.
+abstract-inaccessible.scala:5: warning: method implementMe in trait YourTrait references private[foo] trait Bippy.
Classes which cannot access Bippy may be unable to provide a concrete implementation of implementMe.
def implementMe(f: Int => (String, Bippy)): Unit
^
-abstract-inaccessible.scala:6: error: method overrideMe in trait YourTrait references private[foo] trait Bippy.
+abstract-inaccessible.scala:6: warning: method overrideMe in trait YourTrait references private[foo] trait Bippy.
Classes which cannot access Bippy may be unable to override overrideMe.
def overrideMe[T <: Bippy](x: T): T = x
^
-abstract-inaccessible.scala:7: error: method overrideMeAlso in trait YourTrait references private[foo] trait Bippy.
+abstract-inaccessible.scala:7: warning: method overrideMeAlso in trait YourTrait references private[foo] trait Bippy.
Classes which cannot access Bippy may be unable to override overrideMeAlso.
def overrideMeAlso(x: Map[Int, Set[Bippy]]) = 5
^
-three errors found
+error: No warnings can be incurred under -Xfatal-warnings.
+three warnings found
+one error found
diff --git a/test/files/neg/ambiguous-float-dots.check b/test/files/neg/ambiguous-float-dots.check
index 6c21056d7a..cdd2d6fa2a 100644
--- a/test/files/neg/ambiguous-float-dots.check
+++ b/test/files/neg/ambiguous-float-dots.check
@@ -1,16 +1,27 @@
-ambiguous-float-dots.scala:2: error: This lexical syntax is deprecated. From scala 2.11, a dot will only be considered part of a number if it is immediately followed by a digit.
+ambiguous-float-dots.scala:2: warning: This lexical syntax is deprecated. From scala 2.11, a dot will only be considered part of a number if it is immediately followed by a digit.
val x0 = 5.
^
-ambiguous-float-dots.scala:6: error: This lexical syntax is deprecated. From scala 2.11, a dot will only be considered part of a number if it is immediately followed by a digit.
+ambiguous-float-dots.scala:6: warning: This lexical syntax is deprecated. From scala 2.11, a dot will only be considered part of a number if it is immediately followed by a digit.
val x1 = 5.f
^
-ambiguous-float-dots.scala:7: error: Treating numbers with a leading zero as octal is deprecated.
+ambiguous-float-dots.scala:7: warning: Treating numbers with a leading zero as octal is deprecated.
val y0 = 055
^
-ambiguous-float-dots.scala:11: error: This lexical syntax is deprecated. From scala 2.11, a dot will only be considered part of a number if it is immediately followed by a digit.
+ambiguous-float-dots.scala:11: warning: This lexical syntax is deprecated. From scala 2.11, a dot will only be considered part of a number if it is immediately followed by a digit.
1.+(2)
^
-ambiguous-float-dots.scala:12: error: This lexical syntax is deprecated. From scala 2.11, a dot will only be considered part of a number if it is immediately followed by a digit.
+ambiguous-float-dots.scala:12: warning: This lexical syntax is deprecated. From scala 2.11, a dot will only be considered part of a number if it is immediately followed by a digit.
1. + 2
^
-5 errors found
+ambiguous-float-dots.scala:11: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses
+ 1.+(2)
+ ^
+ambiguous-float-dots.scala:12: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses
+ 1. + 2
+ ^
+ambiguous-float-dots.scala:13: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses
+ 1 + 2
+ ^
+error: No warnings can be incurred under -Xfatal-warnings.
+8 warnings found
+one error found
diff --git a/test/files/neg/array-not-seq.check b/test/files/neg/array-not-seq.check
deleted file mode 100644
index a3a639e772..0000000000
--- a/test/files/neg/array-not-seq.check
+++ /dev/null
@@ -1,13 +0,0 @@
-array-not-seq.scala:2: error: An Array will no longer match as Seq[_].
- def f1(x: Any) = x.isInstanceOf[Seq[_]]
- ^
-array-not-seq.scala:4: error: An Array will no longer match as Seq[_].
- case _: Seq[_] => true
- ^
-array-not-seq.scala:16: error: An Array will no longer match as Seq[_].
- case (Some(_: Seq[_]), Nil, _) => 1
- ^
-array-not-seq.scala:17: error: An Array will no longer match as Seq[_].
- case (None, List(_: List[_], _), _) => 2
- ^
-four errors found
diff --git a/test/files/neg/array-not-seq.flags b/test/files/neg/array-not-seq.flags
deleted file mode 100644
index 4e9f7e4a56..0000000000
--- a/test/files/neg/array-not-seq.flags
+++ /dev/null
@@ -1 +0,0 @@
--Xmigration -Xfatal-warnings \ No newline at end of file
diff --git a/test/files/neg/array-not-seq.scala b/test/files/neg/array-not-seq.scala
deleted file mode 100644
index 5f367bdd85..0000000000
--- a/test/files/neg/array-not-seq.scala
+++ /dev/null
@@ -1,26 +0,0 @@
-object Test {
- def f1(x: Any) = x.isInstanceOf[Seq[_]]
- def f2(x: Any) = x match {
- case _: Seq[_] => true
- case _ => false
- }
-
- def f3(x: Any) = x match {
- case _: Array[_] => true
- case _ => false
- }
-
- def f4(x: Any) = x.isInstanceOf[Traversable[_]]
-
- def f5(x1: Any, x2: Any, x3: AnyRef) = (x1, x2, x3) match {
- case (Some(_: Seq[_]), Nil, _) => 1
- case (None, List(_: List[_], _), _) => 2
- case _ => 3
- }
-
- def main(args: Array[String]): Unit = {
- // println(f1(Array(1)))
- // println(f2(Array(1)))
- // println(f3(Array(1))
- }
-}
diff --git a/test/files/neg/case-collision.check b/test/files/neg/case-collision.check
index 4edc6f1205..22cf105a4f 100644
--- a/test/files/neg/case-collision.check
+++ b/test/files/neg/case-collision.check
@@ -1,10 +1,12 @@
-case-collision.scala:5: error: Class foo.BIPPY differs only in case from foo.Bippy. Such classes will overwrite one another on case-insensitive filesystems.
+case-collision.scala:5: warning: Class foo.BIPPY differs only in case from foo.Bippy. Such classes will overwrite one another on case-insensitive filesystems.
class BIPPY
^
-case-collision.scala:11: error: Class foo.HyRaX$ differs only in case from foo.Hyrax$. Such classes will overwrite one another on case-insensitive filesystems.
+case-collision.scala:11: warning: Class foo.HyRaX$ differs only in case from foo.Hyrax$. Such classes will overwrite one another on case-insensitive filesystems.
object HyRaX
^
-case-collision.scala:8: error: Class foo.DINGO$ differs only in case from foo.Dingo$. Such classes will overwrite one another on case-insensitive filesystems.
+case-collision.scala:8: warning: Class foo.DINGO$ differs only in case from foo.Dingo$. Such classes will overwrite one another on case-insensitive filesystems.
object DINGO
^
-three errors found
+error: No warnings can be incurred under -Xfatal-warnings.
+three warnings found
+one error found
diff --git a/test/files/neg/catch-all.check b/test/files/neg/catch-all.check
index 62f895cc7e..2d58dd99a8 100644
--- a/test/files/neg/catch-all.check
+++ b/test/files/neg/catch-all.check
@@ -1,10 +1,15 @@
-catch-all.scala:2: error: This catches all Throwables. If this is really intended, use `case _ : Throwable` to clear this warning.
+catch-all.scala:2: warning: This catches all Throwables, which often has undesirable consequences.
+If intentional, use `case _ : Throwable` to clear this warning.
try { "warn" } catch { case _ => }
^
-catch-all.scala:4: error: This catches all Throwables. If this is really intended, use `case x : Throwable` to clear this warning.
+catch-all.scala:4: warning: This catches all Throwables, which often has undesirable consequences.
+If intentional, use `case x : Throwable` to clear this warning.
try { "warn" } catch { case x => }
^
-catch-all.scala:6: error: This catches all Throwables. If this is really intended, use `case x : Throwable` to clear this warning.
+catch-all.scala:6: warning: This catches all Throwables, which often has undesirable consequences.
+If intentional, use `case x : Throwable` to clear this warning.
try { "warn" } catch { case _: RuntimeException => ; case x => }
^
-three errors found
+error: No warnings can be incurred under -Xfatal-warnings.
+three warnings found
+one error found
diff --git a/test/files/neg/check-dead.check b/test/files/neg/check-dead.check
index 29601c1d4a..2150a942bf 100644
--- a/test/files/neg/check-dead.check
+++ b/test/files/neg/check-dead.check
@@ -1,13 +1,15 @@
-check-dead.scala:7: error: dead code following this construct
+check-dead.scala:7: warning: dead code following this construct
def z1 = y1(throw new Exception) // should warn
^
-check-dead.scala:10: error: dead code following this construct
+check-dead.scala:10: warning: dead code following this construct
def z2 = y2(throw new Exception) // should warn
^
-check-dead.scala:29: error: dead code following this construct
+check-dead.scala:29: warning: dead code following this construct
throw new Exception // should warn
^
-check-dead.scala:33: error: dead code following this construct
+check-dead.scala:33: warning: dead code following this construct
throw new Exception // should warn
^
-four errors found
+error: No warnings can be incurred under -Xfatal-warnings.
+four warnings found
+one error found
diff --git a/test/files/neg/checksensible.check b/test/files/neg/checksensible.check
index d785179a56..e5f1a38d96 100644
--- a/test/files/neg/checksensible.check
+++ b/test/files/neg/checksensible.check
@@ -1,100 +1,102 @@
-checksensible.scala:13: error: comparing a fresh object using `eq' will always yield false
+checksensible.scala:13: warning: comparing a fresh object using `eq' will always yield false
(new AnyRef) eq (new AnyRef)
^
-checksensible.scala:14: error: comparing a fresh object using `ne' will always yield true
+checksensible.scala:14: warning: comparing a fresh object using `ne' will always yield true
(new AnyRef) ne (new AnyRef)
^
-checksensible.scala:15: error: comparing a fresh object using `eq' will always yield false
+checksensible.scala:15: warning: comparing a fresh object using `eq' will always yield false
Shmoopie eq (new AnyRef)
^
-checksensible.scala:16: error: comparing a fresh object using `eq' will always yield false
+checksensible.scala:16: warning: comparing a fresh object using `eq' will always yield false
(Shmoopie: AnyRef) eq (new AnyRef)
^
-checksensible.scala:17: error: comparing a fresh object using `eq' will always yield false
+checksensible.scala:17: warning: comparing a fresh object using `eq' will always yield false
(new AnyRef) eq Shmoopie
^
-checksensible.scala:18: error: comparing a fresh object using `eq' will always yield false
+checksensible.scala:18: warning: comparing a fresh object using `eq' will always yield false
(new AnyRef) eq null
^
-checksensible.scala:19: error: comparing a fresh object using `eq' will always yield false
+checksensible.scala:19: warning: comparing a fresh object using `eq' will always yield false
null eq new AnyRef
^
-checksensible.scala:26: error: comparing values of types Unit and Int using `==' will always yield false
+checksensible.scala:26: warning: comparing values of types Unit and Int using `==' will always yield false
(c = 1) == 0
^
-checksensible.scala:27: error: comparing values of types Int and Unit using `==' will always yield false
+checksensible.scala:27: warning: comparing values of types Int and Unit using `==' will always yield false
0 == (c = 1)
^
-checksensible.scala:29: error: comparing values of types Int and String using `==' will always yield false
+checksensible.scala:29: warning: comparing values of types Int and String using `==' will always yield false
1 == "abc"
^
-checksensible.scala:33: error: comparing values of types Some[Int] and Int using `==' will always yield false
+checksensible.scala:33: warning: comparing values of types Some[Int] and Int using `==' will always yield false
Some(1) == 1 // as above
^
-checksensible.scala:38: error: comparing a fresh object using `==' will always yield false
+checksensible.scala:38: warning: comparing a fresh object using `==' will always yield false
new AnyRef == 1
^
-checksensible.scala:41: error: comparing values of types Int and Boolean using `==' will always yield false
+checksensible.scala:41: warning: comparing values of types Int and Boolean using `==' will always yield false
1 == (new java.lang.Boolean(true))
^
-checksensible.scala:43: error: comparing values of types Int and Boolean using `!=' will always yield true
+checksensible.scala:43: warning: comparing values of types Int and Boolean using `!=' will always yield true
1 != true
^
-checksensible.scala:44: error: comparing values of types Unit and Boolean using `==' will always yield false
+checksensible.scala:44: warning: comparing values of types Unit and Boolean using `==' will always yield false
() == true
^
-checksensible.scala:45: error: comparing values of types Unit and Unit using `==' will always yield true
+checksensible.scala:45: warning: comparing values of types Unit and Unit using `==' will always yield true
() == ()
^
-checksensible.scala:46: error: comparing values of types Unit and Unit using `==' will always yield true
+checksensible.scala:46: warning: comparing values of types Unit and Unit using `==' will always yield true
() == println
^
-checksensible.scala:47: error: comparing values of types Unit and scala.runtime.BoxedUnit using `==' will always yield true
+checksensible.scala:47: warning: comparing values of types Unit and scala.runtime.BoxedUnit using `==' will always yield true
() == scala.runtime.BoxedUnit.UNIT // these should warn for always being true/false
^
-checksensible.scala:48: error: comparing values of types scala.runtime.BoxedUnit and Unit using `!=' will always yield false
+checksensible.scala:48: warning: comparing values of types scala.runtime.BoxedUnit and Unit using `!=' will always yield false
scala.runtime.BoxedUnit.UNIT != ()
^
-checksensible.scala:51: error: comparing values of types Int and Unit using `!=' will always yield true
+checksensible.scala:51: warning: comparing values of types Int and Unit using `!=' will always yield true
(1 != println)
^
-checksensible.scala:52: error: comparing values of types Int and Symbol using `!=' will always yield true
+checksensible.scala:52: warning: comparing values of types Int and Symbol using `!=' will always yield true
(1 != 'sym)
^
-checksensible.scala:58: error: comparing a fresh object using `==' will always yield false
+checksensible.scala:58: warning: comparing a fresh object using `==' will always yield false
((x: Int) => x + 1) == null
^
-checksensible.scala:59: error: comparing a fresh object using `==' will always yield false
+checksensible.scala:59: warning: comparing a fresh object using `==' will always yield false
Bep == ((_: Int) + 1)
^
-checksensible.scala:61: error: comparing a fresh object using `==' will always yield false
+checksensible.scala:61: warning: comparing a fresh object using `==' will always yield false
new Object == new Object
^
-checksensible.scala:62: error: comparing a fresh object using `==' will always yield false
+checksensible.scala:62: warning: comparing a fresh object using `==' will always yield false
new Object == "abc"
^
-checksensible.scala:63: error: comparing a fresh object using `!=' will always yield true
+checksensible.scala:63: warning: comparing a fresh object using `!=' will always yield true
new Exception() != new Exception()
^
-checksensible.scala:66: error: comparing values of types Int and Null using `==' will always yield false
+checksensible.scala:66: warning: comparing values of types Int and Null using `==' will always yield false
if (foo.length == null) "plante" else "plante pas"
^
-checksensible.scala:71: error: comparing values of types Bip and Bop using `==' will always yield false
+checksensible.scala:71: warning: comparing values of types Bip and Bop using `==' will always yield false
(x1 == x2)
^
-checksensible.scala:81: error: comparing values of types EqEqRefTest.this.C3 and EqEqRefTest.this.Z1 using `==' will always yield false
+checksensible.scala:81: warning: comparing values of types EqEqRefTest.this.C3 and EqEqRefTest.this.Z1 using `==' will always yield false
c3 == z1
^
-checksensible.scala:82: error: comparing values of types EqEqRefTest.this.Z1 and EqEqRefTest.this.C3 using `==' will always yield false
+checksensible.scala:82: warning: comparing values of types EqEqRefTest.this.Z1 and EqEqRefTest.this.C3 using `==' will always yield false
z1 == c3
^
-checksensible.scala:83: error: comparing values of types EqEqRefTest.this.Z1 and EqEqRefTest.this.C3 using `!=' will always yield true
+checksensible.scala:83: warning: comparing values of types EqEqRefTest.this.Z1 and EqEqRefTest.this.C3 using `!=' will always yield true
z1 != c3
^
-checksensible.scala:84: error: comparing values of types EqEqRefTest.this.C3 and String using `!=' will always yield true
+checksensible.scala:84: warning: comparing values of types EqEqRefTest.this.C3 and String using `!=' will always yield true
c3 != "abc"
^
-checksensible.scala:95: error: comparing values of types Unit and Int using `!=' will always yield true
+checksensible.scala:95: warning: comparing values of types Unit and Int using `!=' will always yield true
while ((c = in.read) != -1)
^
-33 errors found
+error: No warnings can be incurred under -Xfatal-warnings.
+33 warnings found
+one error found
diff --git a/test/files/neg/classmanifests_new_deprecations.check b/test/files/neg/classmanifests_new_deprecations.check
index 12428c7626..fddd6bf5b4 100644
--- a/test/files/neg/classmanifests_new_deprecations.check
+++ b/test/files/neg/classmanifests_new_deprecations.check
@@ -1,31 +1,33 @@
-classmanifests_new_deprecations.scala:2: error: type ClassManifest in object Predef is deprecated: Use scala.reflect.ClassTag instead
+classmanifests_new_deprecations.scala:2: warning: type ClassManifest in object Predef is deprecated: Use scala.reflect.ClassTag instead
def cm1[T: ClassManifest] = ???
^
-classmanifests_new_deprecations.scala:3: error: type ClassManifest in object Predef is deprecated: Use scala.reflect.ClassTag instead
+classmanifests_new_deprecations.scala:3: warning: type ClassManifest in object Predef is deprecated: Use scala.reflect.ClassTag instead
def cm2[T](implicit evidence$1: ClassManifest[T]) = ???
^
-classmanifests_new_deprecations.scala:4: error: type ClassManifest in object Predef is deprecated: Use scala.reflect.ClassTag instead
+classmanifests_new_deprecations.scala:4: warning: type ClassManifest in object Predef is deprecated: Use scala.reflect.ClassTag instead
val cm3: ClassManifest[Int] = null
^
-classmanifests_new_deprecations.scala:4: error: type ClassManifest in object Predef is deprecated: Use scala.reflect.ClassTag instead
+classmanifests_new_deprecations.scala:4: warning: type ClassManifest in object Predef is deprecated: Use scala.reflect.ClassTag instead
val cm3: ClassManifest[Int] = null
^
-classmanifests_new_deprecations.scala:6: error: type ClassManifest in package reflect is deprecated: Use scala.reflect.ClassTag instead
+classmanifests_new_deprecations.scala:6: warning: type ClassManifest in package reflect is deprecated: Use scala.reflect.ClassTag instead
def rcm1[T: scala.reflect.ClassManifest] = ???
^
-classmanifests_new_deprecations.scala:7: error: type ClassManifest in package reflect is deprecated: Use scala.reflect.ClassTag instead
+classmanifests_new_deprecations.scala:7: warning: type ClassManifest in package reflect is deprecated: Use scala.reflect.ClassTag instead
def rcm2[T](implicit evidence$1: scala.reflect.ClassManifest[T]) = ???
^
-classmanifests_new_deprecations.scala:8: error: type ClassManifest in package reflect is deprecated: Use scala.reflect.ClassTag instead
+classmanifests_new_deprecations.scala:8: warning: type ClassManifest in package reflect is deprecated: Use scala.reflect.ClassTag instead
val rcm3: scala.reflect.ClassManifest[Int] = null
^
-classmanifests_new_deprecations.scala:8: error: type ClassManifest in package reflect is deprecated: Use scala.reflect.ClassTag instead
+classmanifests_new_deprecations.scala:8: warning: type ClassManifest in package reflect is deprecated: Use scala.reflect.ClassTag instead
val rcm3: scala.reflect.ClassManifest[Int] = null
^
-classmanifests_new_deprecations.scala:10: error: type ClassManifest in object Predef is deprecated: Use scala.reflect.ClassTag instead
+classmanifests_new_deprecations.scala:10: warning: type ClassManifest in object Predef is deprecated: Use scala.reflect.ClassTag instead
type CM[T] = ClassManifest[T]
^
-classmanifests_new_deprecations.scala:15: error: type ClassManifest in package reflect is deprecated: Use scala.reflect.ClassTag instead
+classmanifests_new_deprecations.scala:15: warning: type ClassManifest in package reflect is deprecated: Use scala.reflect.ClassTag instead
type RCM[T] = scala.reflect.ClassManifest[T]
^
-10 errors found
+error: No warnings can be incurred under -Xfatal-warnings.
+10 warnings found
+one error found
diff --git a/test/files/neg/cycle-bounds.check b/test/files/neg/cycle-bounds.check
new file mode 100644
index 0000000000..d924838aec
--- /dev/null
+++ b/test/files/neg/cycle-bounds.check
@@ -0,0 +1,4 @@
+cycle-bounds.scala:5: error: illegal cyclic reference involving type T
+class NotOk[T <: Comparable[_ <: T]]
+ ^
+one error found
diff --git a/test/files/neg/cycle-bounds.flags b/test/files/neg/cycle-bounds.flags
new file mode 100644
index 0000000000..ca20f55172
--- /dev/null
+++ b/test/files/neg/cycle-bounds.flags
@@ -0,0 +1 @@
+-Ybreak-cycles
diff --git a/test/files/neg/cycle-bounds.scala b/test/files/neg/cycle-bounds.scala
new file mode 100644
index 0000000000..0b43bc703e
--- /dev/null
+++ b/test/files/neg/cycle-bounds.scala
@@ -0,0 +1,5 @@
+// This should be allowed
+class Ok[T <: Comparable[_ >: T]]
+
+// This is (il)legitimately a cyclic reference
+class NotOk[T <: Comparable[_ <: T]]
diff --git a/test/files/neg/dbldef.check b/test/files/neg/dbldef.check
index 3ee63475e4..b896c4cdcf 100644
--- a/test/files/neg/dbldef.check
+++ b/test/files/neg/dbldef.check
@@ -6,9 +6,7 @@ dbldef.scala:1: error: type mismatch;
required: Int
case class test0(x: Int, x: Float)
^
-dbldef.scala:1: error: type mismatch;
- found : Float
- required: Int
+dbldef.scala:1: error: in class test0, multiple overloaded alternatives of x define default arguments
case class test0(x: Int, x: Float)
^
three errors found
diff --git a/test/files/neg/exhausting.check b/test/files/neg/exhausting.check
index 0f0d13cb33..c573eb3e15 100644
--- a/test/files/neg/exhausting.check
+++ b/test/files/neg/exhausting.check
@@ -1,25 +1,27 @@
-exhausting.scala:21: error: match may not be exhaustive.
+exhausting.scala:21: warning: match may not be exhaustive.
It would fail on the following input: List(_, _, _)
def fail1[T](xs: List[T]) = xs match {
^
-exhausting.scala:27: error: match may not be exhaustive.
+exhausting.scala:27: warning: match may not be exhaustive.
It would fail on the following input: Nil
def fail2[T](xs: List[T]) = xs match {
^
-exhausting.scala:32: error: match may not be exhaustive.
+exhausting.scala:32: warning: match may not be exhaustive.
It would fail on the following input: List((x: Int forSome x not in (1, 2)))
def fail3a(xs: List[Int]) = xs match {
^
-exhausting.scala:39: error: match may not be exhaustive.
+exhausting.scala:39: warning: match may not be exhaustive.
It would fail on the following input: Bar3
def fail3[T](x: Foo[T]) = x match {
^
-exhausting.scala:47: error: match may not be exhaustive.
+exhausting.scala:47: warning: match may not be exhaustive.
It would fail on the following inputs: (Bar1, Bar2), (Bar1, Bar3), (Bar2, Bar1), (Bar2, Bar2)
def fail4[T <: AnyRef](xx: (Foo[T], Foo[T])) = xx match {
^
-exhausting.scala:56: error: match may not be exhaustive.
+exhausting.scala:56: warning: match may not be exhaustive.
It would fail on the following inputs: (Bar1, Bar2), (Bar1, Bar3), (Bar2, Bar1), (Bar2, Bar2)
def fail5[T](xx: (Foo[T], Foo[T])) = xx match {
^
-6 errors found
+error: No warnings can be incurred under -Xfatal-warnings.
+6 warnings found
+one error found
diff --git a/test/files/neg/gadts1.check b/test/files/neg/gadts1.check
index a5e3e0de10..9b7ea5556a 100644
--- a/test/files/neg/gadts1.check
+++ b/test/files/neg/gadts1.check
@@ -1,8 +1,3 @@
-gadts1.scala:15: error: type mismatch;
- found : Test.Double
- required: a
- case NumTerm(n) => c.x = Double(1.0)
- ^
gadts1.scala:20: error: Test.Cell[a] does not take parameters
case Cell[a](x: Int) => c.x = 5
^
@@ -11,4 +6,4 @@ gadts1.scala:20: error: type mismatch;
required: a
case Cell[a](x: Int) => c.x = 5
^
-three errors found
+two errors found
diff --git a/test/files/neg/import-precedence.check b/test/files/neg/import-precedence.check
new file mode 100644
index 0000000000..5f99611052
--- /dev/null
+++ b/test/files/neg/import-precedence.check
@@ -0,0 +1,19 @@
+import-precedence.scala:18: error: reference to X is ambiguous;
+it is imported twice in the same scope by
+import uniq1.uniq2._
+and import uniq1.X
+ object Y { def f = X }
+ ^
+import-precedence.scala:61: error: reference to X is ambiguous;
+it is imported twice in the same scope by
+import uniq1.uniq2._
+and import uniq1._
+ object Y { def f = X }
+ ^
+import-precedence.scala:67: error: reference to X is ambiguous;
+it is imported twice in the same scope by
+import uniq1.uniq2.X
+and import uniq1.X
+ object Y { def f = X }
+ ^
+three errors found
diff --git a/test/files/neg/import-precedence.scala b/test/files/neg/import-precedence.scala
new file mode 100644
index 0000000000..0401635e32
--- /dev/null
+++ b/test/files/neg/import-precedence.scala
@@ -0,0 +1,68 @@
+package uniq1 {
+ object X
+ package uniq2 {
+ object X
+ package uniq3 {
+ object X
+ package uniq4 {
+ object X
+ }
+ }
+ }
+}
+
+package p1 {
+ import uniq1.X
+ package p2 {
+ import uniq1.uniq2._
+ object Y { def f = X }
+ }
+}
+
+package p2 {
+ import uniq1.uniq2._
+ package p2 {
+ import uniq1.X
+ object Y { def f = X }
+ }
+}
+
+package p3 {
+ import uniq1.X
+ import uniq1.uniq2._
+ object Y { def f = X }
+}
+
+package p4 {
+ import uniq1.uniq2._
+ import uniq1.X
+ object Y { def f = X }
+}
+
+package p5 {
+ import uniq1.X
+ package p6 {
+ import uniq1.uniq2.X
+ object Y { def f = X }
+ }
+}
+
+package p6 {
+ import uniq1._
+ package p5 {
+ import uniq1.uniq2._
+ object Y { def f = X }
+ }
+}
+
+package p7 {
+ import uniq1._
+ import uniq1.uniq2._
+ object Y { def f = X }
+}
+
+package p8 {
+ import uniq1.X
+ import uniq1.uniq2.X
+ object Y { def f = X }
+}
diff --git a/test/files/neg/lubs.check b/test/files/neg/lubs.check
index 77ab20102c..affbd4983c 100644
--- a/test/files/neg/lubs.check
+++ b/test/files/neg/lubs.check
@@ -1,5 +1,10 @@
+lubs.scala:10: error: type mismatch;
+ found : test1.A[test1.A[Object]]
+ required: test1.A[test1.A[test1.A[Any]]]
+ val x3: A[A[A[Any]]] = f
+ ^
lubs.scala:11: error: type mismatch;
- found : test1.A[test1.A[test1.A[Any]]]
+ found : test1.A[test1.A[Object]]
required: test1.A[test1.A[test1.A[test1.A[Any]]]]
val x4: A[A[A[A[Any]]]] = f
^
@@ -13,4 +18,4 @@ lubs.scala:25: error: type mismatch;
required: test2.A{type T >: Null <: test2.A{type T >: Null <: test2.A{type T >: Null <: test2.A}}}
val x4: A { type T >: Null <: A { type T >: Null <: A { type T >: Null <: A } } } = f
^
-three errors found
+four errors found
diff --git a/test/files/neg/macro-deprecate-idents.check b/test/files/neg/macro-deprecate-idents.check
index 22b667c390..c653eabaef 100644
--- a/test/files/neg/macro-deprecate-idents.check
+++ b/test/files/neg/macro-deprecate-idents.check
@@ -1,52 +1,54 @@
-macro-deprecate-idents.scala:2: error: macro is now a reserved word; usage as an identifier is deprecated
+macro-deprecate-idents.scala:2: warning: macro is now a reserved word; usage as an identifier is deprecated
val macro = ???
^
-macro-deprecate-idents.scala:6: error: macro is now a reserved word; usage as an identifier is deprecated
+macro-deprecate-idents.scala:6: warning: macro is now a reserved word; usage as an identifier is deprecated
var macro = ???
^
-macro-deprecate-idents.scala:10: error: macro is now a reserved word; usage as an identifier is deprecated
+macro-deprecate-idents.scala:10: warning: macro is now a reserved word; usage as an identifier is deprecated
type macro = Int
^
-macro-deprecate-idents.scala:14: error: macro is now a reserved word; usage as an identifier is deprecated
+macro-deprecate-idents.scala:14: warning: macro is now a reserved word; usage as an identifier is deprecated
class macro
^
-macro-deprecate-idents.scala:18: error: macro is now a reserved word; usage as an identifier is deprecated
+macro-deprecate-idents.scala:18: warning: macro is now a reserved word; usage as an identifier is deprecated
class macro
^
-macro-deprecate-idents.scala:22: error: macro is now a reserved word; usage as an identifier is deprecated
+macro-deprecate-idents.scala:22: warning: macro is now a reserved word; usage as an identifier is deprecated
object macro
^
-macro-deprecate-idents.scala:26: error: macro is now a reserved word; usage as an identifier is deprecated
+macro-deprecate-idents.scala:26: warning: macro is now a reserved word; usage as an identifier is deprecated
object macro
^
-macro-deprecate-idents.scala:30: error: macro is now a reserved word; usage as an identifier is deprecated
+macro-deprecate-idents.scala:30: warning: macro is now a reserved word; usage as an identifier is deprecated
trait macro
^
-macro-deprecate-idents.scala:34: error: macro is now a reserved word; usage as an identifier is deprecated
+macro-deprecate-idents.scala:34: warning: macro is now a reserved word; usage as an identifier is deprecated
trait macro
^
-macro-deprecate-idents.scala:37: error: macro is now a reserved word; usage as an identifier is deprecated
+macro-deprecate-idents.scala:37: warning: macro is now a reserved word; usage as an identifier is deprecated
package macro {
^
-macro-deprecate-idents.scala:38: error: macro is now a reserved word; usage as an identifier is deprecated
+macro-deprecate-idents.scala:38: warning: macro is now a reserved word; usage as an identifier is deprecated
package macro.bar {
^
-macro-deprecate-idents.scala:43: error: macro is now a reserved word; usage as an identifier is deprecated
+macro-deprecate-idents.scala:43: warning: macro is now a reserved word; usage as an identifier is deprecated
package macro.foo {
^
-macro-deprecate-idents.scala:48: error: macro is now a reserved word; usage as an identifier is deprecated
+macro-deprecate-idents.scala:48: warning: macro is now a reserved word; usage as an identifier is deprecated
val Some(macro) = Some(42)
^
-macro-deprecate-idents.scala:49: error: macro is now a reserved word; usage as an identifier is deprecated
+macro-deprecate-idents.scala:49: warning: macro is now a reserved word; usage as an identifier is deprecated
macro match {
^
-macro-deprecate-idents.scala:50: error: macro is now a reserved word; usage as an identifier is deprecated
+macro-deprecate-idents.scala:50: warning: macro is now a reserved word; usage as an identifier is deprecated
case macro => println(macro)
^
-macro-deprecate-idents.scala:50: error: macro is now a reserved word; usage as an identifier is deprecated
+macro-deprecate-idents.scala:50: warning: macro is now a reserved word; usage as an identifier is deprecated
case macro => println(macro)
^
-macro-deprecate-idents.scala:55: error: macro is now a reserved word; usage as an identifier is deprecated
+macro-deprecate-idents.scala:55: warning: macro is now a reserved word; usage as an identifier is deprecated
def macro = 2
^
-17 errors found
+error: No warnings can be incurred under -Xfatal-warnings.
+17 warnings found
+one error found
diff --git a/test/files/neg/main1.check b/test/files/neg/main1.check
index 1a7a13e1e9..b745105818 100644
--- a/test/files/neg/main1.check
+++ b/test/files/neg/main1.check
@@ -1,26 +1,28 @@
-main1.scala:3: error: Foo has a main method with parameter type Array[String], but foo1.Foo will not be a runnable program.
+main1.scala:3: warning: Foo has a main method with parameter type Array[String], but foo1.Foo will not be a runnable program.
Reason: companion is a trait, which means no static forwarder can be generated.
object Foo { // companion is trait
^
-main1.scala:10: error: Foo has a main method with parameter type Array[String], but foo2.Foo will not be a runnable program.
+main1.scala:10: warning: Foo has a main method with parameter type Array[String], but foo2.Foo will not be a runnable program.
Reason: companion contains its own main method, which means no static forwarder can be generated.
object Foo { // companion has its own main
^
-main1.scala:22: error: Foo has a main method with parameter type Array[String], but foo3.Foo will not be a runnable program.
+main1.scala:22: warning: Foo has a main method with parameter type Array[String], but foo3.Foo will not be a runnable program.
Reason: companion contains its own main method (implementation restriction: no main is allowed, regardless of signature), which means no static forwarder can be generated.
object Foo { // Companion contains main, but not an interfering main.
^
-main1.scala:31: error: Foo has a main method with parameter type Array[String], but foo4.Foo will not be a runnable program.
+main1.scala:31: warning: Foo has a main method with parameter type Array[String], but foo4.Foo will not be a runnable program.
Reason: companion contains its own main method, which means no static forwarder can be generated.
object Foo extends Foo { // Inherits main from the class
^
-main1.scala:39: error: Foo has a main method with parameter type Array[String], but foo5.Foo will not be a runnable program.
+main1.scala:39: warning: Foo has a main method with parameter type Array[String], but foo5.Foo will not be a runnable program.
Reason: companion contains its own main method, which means no static forwarder can be generated.
object Foo extends Foo { // Overrides main from the class
^
-5 errors found
+error: No warnings can be incurred under -Xfatal-warnings.
+5 warnings found
+one error found
diff --git a/test/files/neg/migration28.check b/test/files/neg/migration28.check
index d7dfacf3db..afb4db62e2 100644
--- a/test/files/neg/migration28.check
+++ b/test/files/neg/migration28.check
@@ -1,5 +1,7 @@
-migration28.scala:4: error: method scanRight in trait TraversableLike has changed semantics in version 2.9.0:
+migration28.scala:4: warning: method scanRight in trait TraversableLike has changed semantics in version 2.9.0:
The behavior of `scanRight` has changed. The previous behavior can be reproduced with scanRight.reverse.
List(1,2,3,4,5).scanRight(0)(_+_)
^
+error: No warnings can be incurred under -Xfatal-warnings.
+one warning found
one error found
diff --git a/test/files/neg/names-defaults-neg-warn.check b/test/files/neg/names-defaults-neg-warn.check
index e1085acf76..0f4edef84e 100644
--- a/test/files/neg/names-defaults-neg-warn.check
+++ b/test/files/neg/names-defaults-neg-warn.check
@@ -1,7 +1,9 @@
-names-defaults-neg-warn.scala:11: error: the parameter name s has been deprecated. Use x instead.
+names-defaults-neg-warn.scala:11: warning: the parameter name s has been deprecated. Use x instead.
deprNam2.f(s = "dlfkj")
^
-names-defaults-neg-warn.scala:12: error: the parameter name x has been deprecated. Use s instead.
+names-defaults-neg-warn.scala:12: warning: the parameter name x has been deprecated. Use s instead.
deprNam2.g(x = "dlkjf")
^
-two errors found
+error: No warnings can be incurred under -Xfatal-warnings.
+two warnings found
+one error found
diff --git a/test/files/neg/newpat_unreachable.check b/test/files/neg/newpat_unreachable.check
index 08453cac19..a928e3853a 100644
--- a/test/files/neg/newpat_unreachable.check
+++ b/test/files/neg/newpat_unreachable.check
@@ -1,27 +1,29 @@
-newpat_unreachable.scala:6: error: patterns after a variable pattern cannot match (SLS 8.1.1)
+newpat_unreachable.scala:6: warning: patterns after a variable pattern cannot match (SLS 8.1.1)
If you intended to match against parameter b of method contrivedExample, you must use backticks, like: case `b` =>
case b => println("matched b")
^
-newpat_unreachable.scala:7: error: unreachable code due to variable pattern 'b' on line 6
+newpat_unreachable.scala:7: warning: unreachable code due to variable pattern 'b' on line 6
If you intended to match against parameter c of method contrivedExample, you must use backticks, like: case `c` =>
case c => println("matched c")
^
-newpat_unreachable.scala:8: error: unreachable code due to variable pattern 'b' on line 6
+newpat_unreachable.scala:8: warning: unreachable code due to variable pattern 'b' on line 6
If you intended to match against value d in class A, you must use backticks, like: case `d` =>
case d => println("matched d")
^
-newpat_unreachable.scala:9: error: unreachable code due to variable pattern 'b' on line 6
+newpat_unreachable.scala:9: warning: unreachable code due to variable pattern 'b' on line 6
case _ => println("matched neither")
^
-newpat_unreachable.scala:22: error: patterns after a variable pattern cannot match (SLS 8.1.1)
+newpat_unreachable.scala:22: warning: patterns after a variable pattern cannot match (SLS 8.1.1)
If you intended to match against parameter b of method g, you must use backticks, like: case `b` =>
case b => 1
^
-newpat_unreachable.scala:23: error: unreachable code due to variable pattern 'b' on line 22
+newpat_unreachable.scala:23: warning: unreachable code due to variable pattern 'b' on line 22
If you intended to match against parameter c of method h, you must use backticks, like: case `c` =>
case c => 2
^
-newpat_unreachable.scala:24: error: unreachable code due to variable pattern 'b' on line 22
+newpat_unreachable.scala:24: warning: unreachable code due to variable pattern 'b' on line 22
case _ => 3
^
-7 errors found
+error: No warnings can be incurred under -Xfatal-warnings.
+7 warnings found
+one error found
diff --git a/test/files/neg/nonlocal-warning.check b/test/files/neg/nonlocal-warning.check
new file mode 100644
index 0000000000..67b3b10095
--- /dev/null
+++ b/test/files/neg/nonlocal-warning.check
@@ -0,0 +1,10 @@
+nonlocal-warning.scala:4: warning: This catches all Throwables, which often has undesirable consequences.
+If intentional, use `case x : Throwable` to clear this warning.
+ catch { case x => 11 }
+ ^
+nonlocal-warning.scala:2: warning: catch block may intercept non-local return from method foo
+ def foo(l: List[Int]): Int = {
+ ^
+error: No warnings can be incurred under -Xfatal-warnings.
+two warnings found
+one error found
diff --git a/test/pending/pos/t4649.flags b/test/files/neg/nonlocal-warning.flags
index e8fb65d50c..e8fb65d50c 100644
--- a/test/pending/pos/t4649.flags
+++ b/test/files/neg/nonlocal-warning.flags
diff --git a/test/files/neg/nonlocal-warning.scala b/test/files/neg/nonlocal-warning.scala
new file mode 100644
index 0000000000..f908a86302
--- /dev/null
+++ b/test/files/neg/nonlocal-warning.scala
@@ -0,0 +1,18 @@
+class Foo {
+ def foo(l: List[Int]): Int = {
+ try l foreach { _ => return 5 }
+ catch { case x => 11 }
+ 22
+ }
+
+ val pf: PartialFunction[Throwable, Unit] = {
+ case x if false => ()
+ }
+
+ def bar(l: List[Int]): Int = {
+ try l foreach { _ => return 5 }
+ catch pf
+ finally println()
+ 22
+ }
+}
diff --git a/test/files/neg/nullary-override.check b/test/files/neg/nullary-override.check
index 6b2ded2d4a..f032f4a6c2 100644
--- a/test/files/neg/nullary-override.check
+++ b/test/files/neg/nullary-override.check
@@ -1,4 +1,6 @@
-nullary-override.scala:2: error: non-nullary method overrides nullary method
+nullary-override.scala:2: warning: non-nullary method overrides nullary method
class B extends A { override def x(): Int = 4 }
^
+error: No warnings can be incurred under -Xfatal-warnings.
+one warning found
one error found
diff --git a/test/files/neg/overloaded-implicit.check b/test/files/neg/overloaded-implicit.check
index bdbe6a89d5..ca0870705d 100644
--- a/test/files/neg/overloaded-implicit.check
+++ b/test/files/neg/overloaded-implicit.check
@@ -1,7 +1,9 @@
-overloaded-implicit.scala:2: error: parameterized overloaded implicit methods are not visible as view bounds
+overloaded-implicit.scala:2: warning: parameterized overloaded implicit methods are not visible as view bounds
implicit def imp1[T](x: List[T]): Map[T, T] = Map()
^
-overloaded-implicit.scala:3: error: parameterized overloaded implicit methods are not visible as view bounds
+overloaded-implicit.scala:3: warning: parameterized overloaded implicit methods are not visible as view bounds
implicit def imp1[T](x: Set[T]): Map[T, T] = Map()
^
-two errors found
+error: No warnings can be incurred under -Xfatal-warnings.
+two warnings found
+one error found
diff --git a/test/files/neg/overloaded-implicit.flags b/test/files/neg/overloaded-implicit.flags
index 7949c2afa2..9c1e74e4ef 100644
--- a/test/files/neg/overloaded-implicit.flags
+++ b/test/files/neg/overloaded-implicit.flags
@@ -1 +1 @@
--Xlint -Xfatal-warnings
+-Xlint -Xfatal-warnings -Xdev
diff --git a/test/files/neg/package-ob-case.check b/test/files/neg/package-ob-case.check
index e6b2f858ef..063a120db1 100644
--- a/test/files/neg/package-ob-case.check
+++ b/test/files/neg/package-ob-case.check
@@ -1,5 +1,7 @@
-package-ob-case.scala:3: error: it is not recommended to define classes/objects inside of package objects.
+package-ob-case.scala:3: warning: it is not recommended to define classes/objects inside of package objects.
If possible, define class X in package foo instead.
case class X(z: Int) { }
^
+error: No warnings can be incurred under -Xfatal-warnings.
+one warning found
one error found
diff --git a/test/files/neg/patmat-type-check.check b/test/files/neg/patmat-type-check.check
index 721217c314..fedac3b746 100644
--- a/test/files/neg/patmat-type-check.check
+++ b/test/files/neg/patmat-type-check.check
@@ -1,12 +1,27 @@
patmat-type-check.scala:11: warning: fruitless type test: a value of type Test.Bop4[T] cannot also be a Seq[A]
def s3[T](x: Bop4[T]) = x match { case Seq('b', 'o', 'b') => true }
^
+patmat-type-check.scala:11: error: pattern type is incompatible with expected type;
+ found : Seq[A]
+ required: Test.Bop4[T]
+ def s3[T](x: Bop4[T]) = x match { case Seq('b', 'o', 'b') => true }
+ ^
patmat-type-check.scala:15: warning: fruitless type test: a value of type Test.Bop5[_$1,T1,T2] cannot also be a Seq[A]
def s4[T1, T2](x: Bop5[_, T1, T2]) = x match { case Seq('b', 'o', 'b') => true }
^
+patmat-type-check.scala:15: error: pattern type is incompatible with expected type;
+ found : Seq[A]
+ required: Test.Bop5[_$1,T1,T2] where type _$1
+ def s4[T1, T2](x: Bop5[_, T1, T2]) = x match { case Seq('b', 'o', 'b') => true }
+ ^
patmat-type-check.scala:19: warning: fruitless type test: a value of type Test.Bop3[T] cannot also be a Seq[A]
def f4[T](x: Bop3[T]) = x match { case Seq('b', 'o', 'b') => true }
^
+patmat-type-check.scala:19: error: pattern type is incompatible with expected type;
+ found : Seq[A]
+ required: Test.Bop3[T]
+ def f4[T](x: Bop3[T]) = x match { case Seq('b', 'o', 'b') => true }
+ ^
patmat-type-check.scala:22: error: scrutinee is incompatible with pattern type;
found : Seq[A]
required: String
@@ -28,4 +43,4 @@ patmat-type-check.scala:30: error: scrutinee is incompatible with pattern type;
def f4[T](x: Bop3[Char]) = x match { case Seq('b', 'o', 'b') => true } // fail
^
three warnings found
-four errors found
+7 errors found
diff --git a/test/files/neg/patmatexhaust.check b/test/files/neg/patmatexhaust.check
index 4556e6622f..6069dfdaab 100644
--- a/test/files/neg/patmatexhaust.check
+++ b/test/files/neg/patmatexhaust.check
@@ -1,40 +1,42 @@
-patmatexhaust.scala:7: error: match may not be exhaustive.
+patmatexhaust.scala:7: warning: match may not be exhaustive.
It would fail on the following input: Baz
def ma1(x:Foo) = x match {
^
-patmatexhaust.scala:11: error: match may not be exhaustive.
+patmatexhaust.scala:11: warning: match may not be exhaustive.
It would fail on the following input: Bar(_)
def ma2(x:Foo) = x match {
^
-patmatexhaust.scala:23: error: match may not be exhaustive.
+patmatexhaust.scala:23: warning: match may not be exhaustive.
It would fail on the following inputs: (Kult(_), Kult(_)), (Qult(), Qult())
def ma3(x:Mult) = (x,x) match { // not exhaustive
^
-patmatexhaust.scala:49: error: match may not be exhaustive.
+patmatexhaust.scala:49: warning: match may not be exhaustive.
It would fail on the following inputs: Gp(), Gu
def ma4(x:Deep) = x match { // missing cases: Gu, Gp
^
-patmatexhaust.scala:55: error: unreachable code
+patmatexhaust.scala:55: warning: unreachable code
case _ if 1 == 0 =>
^
-patmatexhaust.scala:53: error: match may not be exhaustive.
+patmatexhaust.scala:53: warning: match may not be exhaustive.
It would fail on the following input: Gp()
def ma5(x:Deep) = x match {
^
-patmatexhaust.scala:75: error: match may not be exhaustive.
+patmatexhaust.scala:75: warning: match may not be exhaustive.
It would fail on the following input: B()
def ma9(x: B) = x match {
^
-patmatexhaust.scala:100: error: match may not be exhaustive.
+patmatexhaust.scala:100: warning: match may not be exhaustive.
It would fail on the following input: C1()
def ma10(x: C) = x match { // not exhaustive: C1 is not sealed.
^
-patmatexhaust.scala:114: error: match may not be exhaustive.
+patmatexhaust.scala:114: warning: match may not be exhaustive.
It would fail on the following inputs: D1, D2()
def ma10(x: C) = x match { // not exhaustive: C1 has subclasses.
^
-patmatexhaust.scala:126: error: match may not be exhaustive.
+patmatexhaust.scala:126: warning: match may not be exhaustive.
It would fail on the following input: C1()
def ma10(x: C) = x match { // not exhaustive: C1 is not abstract.
^
-10 errors found
+error: No warnings can be incurred under -Xfatal-warnings.
+10 warnings found
+one error found
diff --git a/test/files/neg/permanent-blindness.check b/test/files/neg/permanent-blindness.check
index 18b4543707..cdde201ef6 100644
--- a/test/files/neg/permanent-blindness.check
+++ b/test/files/neg/permanent-blindness.check
@@ -1,10 +1,12 @@
-permanent-blindness.scala:10: error: imported `Bippy' is permanently hidden by definition of class Bippy in package bar
+permanent-blindness.scala:10: warning: imported `Bippy' is permanently hidden by definition of class Bippy in package bar
import foo.{ Bippy, Bop, Dingus }
^
-permanent-blindness.scala:10: error: imported `Bop' is permanently hidden by definition of object Bop in package bar
+permanent-blindness.scala:10: warning: imported `Bop' is permanently hidden by definition of object Bop in package bar
import foo.{ Bippy, Bop, Dingus }
^
-permanent-blindness.scala:10: error: imported `Dingus' is permanently hidden by definition of object Dingus in package bar
+permanent-blindness.scala:10: warning: imported `Dingus' is permanently hidden by definition of object Dingus in package bar
import foo.{ Bippy, Bop, Dingus }
^
-three errors found
+error: No warnings can be incurred under -Xfatal-warnings.
+three warnings found
+one error found
diff --git a/test/files/neg/sealed-final-neg.check b/test/files/neg/sealed-final-neg.check
new file mode 100644
index 0000000000..500d23f49a
--- /dev/null
+++ b/test/files/neg/sealed-final-neg.check
@@ -0,0 +1,4 @@
+sealed-final-neg.scala:41: error: expected class or object definition
+"Due to SI-6142 this emits no warnings, so we'll just break it until that's fixed."
+^
+one error found
diff --git a/test/files/neg/sealed-final-neg.flags b/test/files/neg/sealed-final-neg.flags
new file mode 100644
index 0000000000..cfabf7a5b4
--- /dev/null
+++ b/test/files/neg/sealed-final-neg.flags
@@ -0,0 +1 @@
+-Xfatal-warnings -Yinline-warnings -optimise \ No newline at end of file
diff --git a/test/files/neg/sealed-final-neg.scala b/test/files/neg/sealed-final-neg.scala
new file mode 100644
index 0000000000..bc25330e13
--- /dev/null
+++ b/test/files/neg/sealed-final-neg.scala
@@ -0,0 +1,41 @@
+package neg1 {
+ sealed abstract class Foo {
+ @inline def bar(x: Int) = x + 1
+ }
+ object Foo {
+ def mkFoo(): Foo = new Baz2
+ }
+
+ object Baz1 extends Foo
+ final class Baz2 extends Foo
+ final class Baz3 extends Foo {
+ override def bar(x: Int) = x - 1
+ }
+
+ object Test {
+ // bar can't be inlined - it is overridden in Baz3
+ def f = Foo.mkFoo() bar 10
+ }
+}
+
+package neg2 {
+ sealed abstract class Foo {
+ @inline def bar(x: Int) = x + 1
+ }
+ object Foo {
+ def mkFoo(): Foo = new Baz2
+ }
+
+ object Baz1 extends Foo
+ final class Baz2 extends Foo
+ class Baz3 extends Foo {
+ override def bar(x: Int) = x - 1
+ }
+
+ object Test {
+ // bar can't be inlined - Baz3 is not final
+ def f = Foo.mkFoo() bar 10
+ }
+}
+
+"Due to SI-6142 this emits no warnings, so we'll just break it until that's fixed."
diff --git a/test/files/neg/sealed-java-enums.check b/test/files/neg/sealed-java-enums.check
index 20d00c8e91..a3c39ec5cd 100644
--- a/test/files/neg/sealed-java-enums.check
+++ b/test/files/neg/sealed-java-enums.check
@@ -1,5 +1,7 @@
-sealed-java-enums.scala:5: error: match may not be exhaustive.
+sealed-java-enums.scala:5: warning: match may not be exhaustive.
It would fail on the following inputs: BLOCKED, TERMINATED, TIMED_WAITING
def f(state: State) = state match {
^
+error: No warnings can be incurred under -Xfatal-warnings.
+one warning found
one error found
diff --git a/test/files/neg/serialversionuid-not-const.check b/test/files/neg/serialversionuid-not-const.check
new file mode 100644
index 0000000000..9c383d97ad
--- /dev/null
+++ b/test/files/neg/serialversionuid-not-const.check
@@ -0,0 +1,10 @@
+serialversionuid-not-const.scala:1: error: annotation argument needs to be a constant; found: 13L.toLong
+@SerialVersionUID(13l.toLong) class C1 extends Serializable
+ ^
+serialversionuid-not-const.scala:3: error: annotation argument needs to be a constant; found: 13.asInstanceOf[Long]
+@SerialVersionUID(13.asInstanceOf[Long]) class C3 extends Serializable
+ ^
+serialversionuid-not-const.scala:4: error: annotation argument needs to be a constant; found: Test.bippy
+@SerialVersionUID(Test.bippy) class C4 extends Serializable
+ ^
+three errors found
diff --git a/test/files/neg/serialversionuid-not-const.scala b/test/files/neg/serialversionuid-not-const.scala
new file mode 100644
index 0000000000..f0e3ef4e7e
--- /dev/null
+++ b/test/files/neg/serialversionuid-not-const.scala
@@ -0,0 +1,16 @@
+@SerialVersionUID(13l.toLong) class C1 extends Serializable
+@SerialVersionUID(13l) class C2 extends Serializable
+@SerialVersionUID(13.asInstanceOf[Long]) class C3 extends Serializable
+@SerialVersionUID(Test.bippy) class C4 extends Serializable
+
+object Test {
+ val bippy = 13L
+
+ def show(c: Class[_]) = println(java.io.ObjectStreamClass.lookup(c).getSerialVersionUID)
+ def main(args: Array[String]): Unit = {
+ show(classOf[C1])
+ show(classOf[C2])
+ show(classOf[C3])
+ show(classOf[C4])
+ }
+}
diff --git a/test/files/neg/stmt-expr-discard.check b/test/files/neg/stmt-expr-discard.check
index 2d6420a61d..1207e6da50 100644
--- a/test/files/neg/stmt-expr-discard.check
+++ b/test/files/neg/stmt-expr-discard.check
@@ -1,7 +1,9 @@
-stmt-expr-discard.scala:3: error: a pure expression does nothing in statement position; you may be omitting necessary parentheses
+stmt-expr-discard.scala:3: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses
+ 2
^
-stmt-expr-discard.scala:4: error: a pure expression does nothing in statement position; you may be omitting necessary parentheses
+stmt-expr-discard.scala:4: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses
- 4
^
-two errors found
+error: No warnings can be incurred under -Xfatal-warnings.
+two warnings found
+one error found
diff --git a/test/files/neg/switch.check b/test/files/neg/switch.check
index e4730b6459..f968d3a448 100644
--- a/test/files/neg/switch.check
+++ b/test/files/neg/switch.check
@@ -1,7 +1,9 @@
-switch.scala:38: error: could not emit switch for @switch annotated match
+switch.scala:38: warning: could not emit switch for @switch annotated match
def fail2(c: Char) = (c: @switch @unchecked) match {
^
-switch.scala:45: error: could not emit switch for @switch annotated match
+switch.scala:45: warning: could not emit switch for @switch annotated match
def fail3(c: Char) = (c: @unchecked @switch) match {
^
-two errors found
+error: No warnings can be incurred under -Xfatal-warnings.
+two warnings found
+one error found
diff --git a/test/files/neg/t1224.check b/test/files/neg/t1224.check
index fb61275911..ab8a6f1130 100644
--- a/test/files/neg/t1224.check
+++ b/test/files/neg/t1224.check
@@ -1,4 +1,4 @@
-t1224.scala:4: error: illegal cyclic reference involving type T
+t1224.scala:4: error: lower bound C[A.this.T] does not conform to upper bound C[C[A.this.T]]
type T >: C[T] <: C[C[T]]
^
one error found
diff --git a/test/files/neg/t1224.flags b/test/files/neg/t1224.flags
new file mode 100644
index 0000000000..ca20f55172
--- /dev/null
+++ b/test/files/neg/t1224.flags
@@ -0,0 +1 @@
+-Ybreak-cycles
diff --git a/test/files/neg/t2442.check b/test/files/neg/t2442.check
index 714816fd62..9ff0b44661 100644
--- a/test/files/neg/t2442.check
+++ b/test/files/neg/t2442.check
@@ -1,9 +1,11 @@
-t2442.scala:4: error: match may not be exhaustive.
+t2442.scala:4: warning: match may not be exhaustive.
It would fail on the following input: THREE
def f(e: MyEnum) = e match {
^
-t2442.scala:11: error: match may not be exhaustive.
+t2442.scala:11: warning: match may not be exhaustive.
It would fail on the following input: BLUE
def g(e: MySecondEnum) = e match {
^
-two errors found
+error: No warnings can be incurred under -Xfatal-warnings.
+two warnings found
+one error found
diff --git a/test/files/neg/t2796.check b/test/files/neg/t2796.check
index aeb18497ed..4456a7fc19 100644
--- a/test/files/neg/t2796.check
+++ b/test/files/neg/t2796.check
@@ -1,4 +1,6 @@
-t2796.scala:7: error: Implementation restriction: early definitions in traits are not initialized before the super class is initialized.
+t2796.scala:7: warning: Implementation restriction: early definitions in traits are not initialized before the super class is initialized.
val abstractVal = "T1.abstractVal" // warn
^
+error: No warnings can be incurred under -Xfatal-warnings.
+one warning found
one error found
diff --git a/test/files/neg/t2968.check b/test/files/neg/t2968.check
new file mode 100644
index 0000000000..5d2387f98c
--- /dev/null
+++ b/test/files/neg/t2968.check
@@ -0,0 +1,10 @@
+t2968.scala:8: error: Missing closing brace `}' assumed here
+} // missing brace
+^
+t2968.scala:17: error: Missing closing brace `}' assumed here
+} // missing brace
+^
+t2968.scala:26: error: Missing closing brace `}' assumed here
+} // missing brace
+^
+three errors found
diff --git a/test/files/neg/t2968.scala b/test/files/neg/t2968.scala
new file mode 100644
index 0000000000..41c3a798a5
--- /dev/null
+++ b/test/files/neg/t2968.scala
@@ -0,0 +1,26 @@
+object t1 {
+ case object Const {
+ }
+
+ class Var
+ {
+
+} // missing brace
+
+object t2 {
+ case class Const() {
+ }
+
+ class Var
+ {
+
+} // missing brace
+
+object t3 {
+ final case class Const() {
+ }
+
+ class Var
+ {
+
+} // missing brace
diff --git a/test/files/neg/t2968b.check b/test/files/neg/t2968b.check
new file mode 100644
index 0000000000..36d25a2d12
--- /dev/null
+++ b/test/files/neg/t2968b.check
@@ -0,0 +1,4 @@
+t2968b.scala:7: error: '}' expected but eof found.
+// missing brace
+ ^
+one error found
diff --git a/test/files/neg/t2968b.scala b/test/files/neg/t2968b.scala
new file mode 100644
index 0000000000..422b618aba
--- /dev/null
+++ b/test/files/neg/t2968b.scala
@@ -0,0 +1,7 @@
+case class Const()
+{
+}
+
+class Var
+{
+// missing brace
diff --git a/test/files/neg/t3098.check b/test/files/neg/t3098.check
index 85829747b9..5343b128f0 100644
--- a/test/files/neg/t3098.check
+++ b/test/files/neg/t3098.check
@@ -1,5 +1,7 @@
-b.scala:3: error: match may not be exhaustive.
+b.scala:3: warning: match may not be exhaustive.
It would fail on the following input: (_ : C)
def f = (null: T) match {
^
+error: No warnings can be incurred under -Xfatal-warnings.
+one warning found
one error found
diff --git a/test/files/neg/t3160ambiguous.check b/test/files/neg/t3160ambiguous.check
new file mode 100644
index 0000000000..e80d9a5461
--- /dev/null
+++ b/test/files/neg/t3160ambiguous.check
@@ -0,0 +1,7 @@
+t3160ambiguous.scala:8: error: reference to Node is ambiguous;
+it is imported twice in the same scope by
+import scala.xml._
+and import Bippy._
+ def f(x: Node): String = ??? // ambiguous, because Bippy.Node is accessible
+ ^
+one error found
diff --git a/test/files/neg/t3160ambiguous.scala b/test/files/neg/t3160ambiguous.scala
new file mode 100644
index 0000000000..cb9759b79c
--- /dev/null
+++ b/test/files/neg/t3160ambiguous.scala
@@ -0,0 +1,15 @@
+object Bippy {
+ private class Node
+}
+class Bippy {
+ import Bippy._
+ import scala.xml._
+
+ def f(x: Node): String = ??? // ambiguous, because Bippy.Node is accessible
+}
+class Other {
+ import Bippy._
+ import scala.xml._
+
+ def f(x: Node): String = ??? // unambiguous, because Bippy.Node is inaccessible
+}
diff --git a/test/files/neg/t3224.check b/test/files/neg/t3224.check
index 29304c567a..69b02c8862 100644
--- a/test/files/neg/t3224.check
+++ b/test/files/neg/t3224.check
@@ -1,6 +1,26 @@
-t3224.scala:29: error: polymorphic expression cannot be instantiated to expected type;
+t3224.scala:30: error: polymorphic expression cannot be instantiated to expected type;
found : [T]Array[T]
required: List[?]
- println(Texts textL Array()); println(Texts textL Array(1)); println(Texts textL Array(1, 1))
- ^
-one error found
+ println(Texts textL Array())
+ ^
+t3224.scala:34: error: type mismatch;
+ found : List[Nothing]
+ required: Array[?]
+ println(Texts textA List())
+ ^
+t3224.scala:35: error: type mismatch;
+ found : List[Int]
+ required: Array[?]
+ println(Texts textA List(1))
+ ^
+t3224.scala:36: error: type mismatch;
+ found : List[Int]
+ required: Array[?]
+ println(Texts textA List(1, 1));
+ ^
+t3224.scala:48: error: polymorphic expression cannot be instantiated to expected type;
+ found : [T]Array[T]
+ required: List[?]
+ assert(size(Array()) == 0)
+ ^
+5 errors found
diff --git a/test/files/neg/t3224.scala b/test/files/neg/t3224.scala
index 774de3335a..b7af8a67b5 100755
--- a/test/files/neg/t3224.scala
+++ b/test/files/neg/t3224.scala
@@ -1,30 +1,50 @@
object Texts{
- def textL[T](list: List[T]) = {
- list match{
- case List() => "Empty"
- case List(_) => "One"
+ def textL[T](list: List[T]) = {
+ list match{
+ case List() => "Empty"
+ case List(_) => "One"
case List(_*) => "Many"
}
}
- def textA[T](array: Array[T]) = {
- array match{
- case Array() => "Empty"
- case Array(_) => "One"
+ def textA[T](array: Array[T]) = {
+ array match{
+ case Array() => "Empty"
+ case Array(_) => "One"
case Array(_*) => "Many"
}
}
}
object Test extends App {
+ {
+ implicit def array2list[T](array: Array[T]) = {
+ println(array.toList.size)
+ array.toList
+ }
+
+ println(Texts textL List())
+ println(Texts textL List(1))
+ println(Texts textL List(1, 1));
+
+ println(Texts textL Array())
+ println(Texts textL Array(1))
+ println(Texts textL Array(1, 1))
- implicit def array2list[T](array: Array[T]) = {
- println(array.toList.size)
- array.toList
+ println(Texts textA List())
+ println(Texts textA List(1))
+ println(Texts textA List(1, 1));
+
+ println(Texts textA Array())
+ println(Texts textA Array(1))
+ println(Texts textA Array(1, 1))
}
-
- println(Texts textL List()); println(Texts textL List(1)); println(Texts textL List(1, 1));
+ {
+ implicit def array2list[T](array: Array[T]) = array.toList
+ def size[T](list: List[T]) = list.size
- println(Texts textL Array()); println(Texts textL Array(1)); println(Texts textL Array(1, 1))
+ assert(size(array2list(Array())) == 0)
+ assert(size(Array()) == 0)
+ }
}
diff --git a/test/files/neg/t3234.check b/test/files/neg/t3234.check
index 477b021e5e..8f0d624ed9 100644
--- a/test/files/neg/t3234.check
+++ b/test/files/neg/t3234.check
@@ -1,2 +1,6 @@
-error: there were 1 inliner warnings; re-run with -Yinline-warnings for details
+t3234.scala:17: warning: At the end of the day, could not inline @inline-marked method foo3
+ println(foo(42) + foo2(11) + foo3(2))
+ ^
+error: No warnings can be incurred under -Xfatal-warnings.
+one warning found
one error found
diff --git a/test/files/neg/t3234.flags b/test/files/neg/t3234.flags
index c9cefdc4b9..cc3d9fb6f0 100644
--- a/test/files/neg/t3234.flags
+++ b/test/files/neg/t3234.flags
@@ -1 +1 @@
--Yinline -Xfatal-warnings \ No newline at end of file
+-Yinline -Yinline-warnings -Xfatal-warnings
diff --git a/test/files/neg/t3683a.check b/test/files/neg/t3683a.check
index 3de3ad784e..6386265ebc 100644
--- a/test/files/neg/t3683a.check
+++ b/test/files/neg/t3683a.check
@@ -1,5 +1,7 @@
-t3683a.scala:14: error: match may not be exhaustive.
+t3683a.scala:14: warning: match may not be exhaustive.
It would fail on the following input: XX()
w match {
^
+error: No warnings can be incurred under -Xfatal-warnings.
+one warning found
one error found
diff --git a/test/files/neg/t4302.check b/test/files/neg/t4302.check
index 450d28bbc5..ea48729276 100644
--- a/test/files/neg/t4302.check
+++ b/test/files/neg/t4302.check
@@ -1,4 +1,6 @@
-t4302.scala:2: error: abstract type T is unchecked since it is eliminated by erasure
+t4302.scala:2: warning: abstract type T is unchecked since it is eliminated by erasure
def hasMatch[T](x: AnyRef) = x.isInstanceOf[T]
^
+error: No warnings can be incurred under -Xfatal-warnings.
+one warning found
one error found
diff --git a/test/files/neg/t4440.check b/test/files/neg/t4440.check
index 2861dc3040..10e7188e32 100644
--- a/test/files/neg/t4440.check
+++ b/test/files/neg/t4440.check
@@ -1,13 +1,15 @@
-t4440.scala:12: error: The outer reference in this type test cannot be checked at run time.
+t4440.scala:12: warning: The outer reference in this type test cannot be checked at run time.
case _: b.Inner => println("b")
^
-t4440.scala:13: error: The outer reference in this type test cannot be checked at run time.
+t4440.scala:13: warning: The outer reference in this type test cannot be checked at run time.
case _: a.Inner => println("a") // this is the case we want
^
-t4440.scala:16: error: The outer reference in this type test cannot be checked at run time.
+t4440.scala:16: warning: The outer reference in this type test cannot be checked at run time.
case _: a.Inner => println("a")
^
-t4440.scala:17: error: The outer reference in this type test cannot be checked at run time.
+t4440.scala:17: warning: The outer reference in this type test cannot be checked at run time.
case _: b.Inner => println("b") // this is the case we want
^
-four errors found
+error: No warnings can be incurred under -Xfatal-warnings.
+four warnings found
+one error found
diff --git a/test/files/neg/t4537.check b/test/files/neg/t4537.check
deleted file mode 100644
index 931bcd0405..0000000000
--- a/test/files/neg/t4537.check
+++ /dev/null
@@ -1,4 +0,0 @@
-c.scala:7: error: object Settings in package a cannot be accessed in package a
- println(Settings.Y)
- ^
-one error found
diff --git a/test/files/neg/t4537/c.scala b/test/files/neg/t4537/c.scala
deleted file mode 100644
index 379599112d..0000000000
--- a/test/files/neg/t4537/c.scala
+++ /dev/null
@@ -1,8 +0,0 @@
-package b
-package c
-
-import a._
-
-object Test {
- println(Settings.Y)
-} \ No newline at end of file
diff --git a/test/files/neg/t4691_exhaust_extractor.check b/test/files/neg/t4691_exhaust_extractor.check
index cd12e56f86..6396944145 100644
--- a/test/files/neg/t4691_exhaust_extractor.check
+++ b/test/files/neg/t4691_exhaust_extractor.check
@@ -1,13 +1,15 @@
-t4691_exhaust_extractor.scala:17: error: match may not be exhaustive.
+t4691_exhaust_extractor.scala:17: warning: match may not be exhaustive.
It would fail on the following input: Bar3()
def f1(x: Foo) = x match {
^
-t4691_exhaust_extractor.scala:23: error: match may not be exhaustive.
+t4691_exhaust_extractor.scala:23: warning: match may not be exhaustive.
It would fail on the following input: Bar3()
def f2(x: Foo) = x match {
^
-t4691_exhaust_extractor.scala:29: error: match may not be exhaustive.
+t4691_exhaust_extractor.scala:29: warning: match may not be exhaustive.
It would fail on the following input: Bar3()
def f3(x: Foo) = x match {
^
-three errors found
+error: No warnings can be incurred under -Xfatal-warnings.
+three warnings found
+one error found
diff --git a/test/files/neg/t4749.check b/test/files/neg/t4749.check
index 93ad3935fa..34eed6e433 100644
--- a/test/files/neg/t4749.check
+++ b/test/files/neg/t4749.check
@@ -1,28 +1,30 @@
-t4749.scala:2: error: Fail1 has a main method with parameter type Array[String], but bippy.Fail1 will not be a runnable program.
+t4749.scala:2: warning: Fail1 has a main method with parameter type Array[String], but bippy.Fail1 will not be a runnable program.
Reason: main method must have exact signature (Array[String])Unit
object Fail1 {
^
-t4749.scala:6: error: Fail2 has a main method with parameter type Array[String], but bippy.Fail2 will not be a runnable program.
+t4749.scala:6: warning: Fail2 has a main method with parameter type Array[String], but bippy.Fail2 will not be a runnable program.
Reason: main methods cannot be generic.
object Fail2 {
^
-t4749.scala:13: error: Fail3 has a main method with parameter type Array[String], but bippy.Fail3 will not be a runnable program.
+t4749.scala:13: warning: Fail3 has a main method with parameter type Array[String], but bippy.Fail3 will not be a runnable program.
Reason: main methods cannot refer to type parameters or abstract types.
object Fail3 extends Bippy[Unit] { }
^
-t4749.scala:16: error: Fail4 has a main method with parameter type Array[String], but bippy.Fail4 will not be a runnable program.
+t4749.scala:16: warning: Fail4 has a main method with parameter type Array[String], but bippy.Fail4 will not be a runnable program.
Reason: companion is a trait, which means no static forwarder can be generated.
object Fail4 {
^
-t4749.scala:21: error: Fail5 has a main method with parameter type Array[String], but bippy.Fail5 will not be a runnable program.
+t4749.scala:21: warning: Fail5 has a main method with parameter type Array[String], but bippy.Fail5 will not be a runnable program.
Reason: companion contains its own main method, which means no static forwarder can be generated.
object Fail5 extends Fail5 { }
^
-t4749.scala:26: error: Fail6 has a main method with parameter type Array[String], but bippy.Fail6 will not be a runnable program.
+t4749.scala:26: warning: Fail6 has a main method with parameter type Array[String], but bippy.Fail6 will not be a runnable program.
Reason: companion contains its own main method (implementation restriction: no main is allowed, regardless of signature), which means no static forwarder can be generated.
object Fail6 {
^
-6 errors found
+error: No warnings can be incurred under -Xfatal-warnings.
+6 warnings found
+one error found
diff --git a/test/files/neg/t4762.check b/test/files/neg/t4762.check
index 5e67f2022a..a0525f6226 100644
--- a/test/files/neg/t4762.check
+++ b/test/files/neg/t4762.check
@@ -1,7 +1,9 @@
-t4762.scala:15: error: private[this] value x in class B shadows mutable x inherited from class A. Changes to x will not be visible within class B - you may want to give them distinct names.
+t4762.scala:15: warning: private[this] value x in class B shadows mutable x inherited from class A. Changes to x will not be visible within class B - you may want to give them distinct names.
/* (99,99) */ (this.x, this.y),
^
-t4762.scala:48: error: private[this] value x in class Derived shadows mutable x inherited from class Base. Changes to x will not be visible within class Derived - you may want to give them distinct names.
+t4762.scala:48: warning: private[this] value x in class Derived shadows mutable x inherited from class Base. Changes to x will not be visible within class Derived - you may want to give them distinct names.
class Derived( x : Int ) extends Base( x ) { override def toString = x.toString }
^
-two errors found
+error: No warnings can be incurred under -Xfatal-warnings.
+two warnings found
+one error found
diff --git a/test/files/neg/t4851.check b/test/files/neg/t4851.check
index 8011350f23..0fd66b9efe 100644
--- a/test/files/neg/t4851.check
+++ b/test/files/neg/t4851.check
@@ -1,43 +1,45 @@
-S.scala:2: error: Adapting argument list by inserting (): leaky (Object-receiving) target makes this especially dangerous.
+S.scala:2: warning: Adapting argument list by inserting (): leaky (Object-receiving) target makes this especially dangerous.
signature: J(x: Any): J
given arguments: <none>
after adaptation: new J((): Unit)
val x1 = new J
^
-S.scala:3: error: Adapting argument list by inserting (): leaky (Object-receiving) target makes this especially dangerous.
+S.scala:3: warning: Adapting argument list by inserting (): leaky (Object-receiving) target makes this especially dangerous.
signature: J(x: Any): J
given arguments: <none>
after adaptation: new J((): Unit)
val x2 = new J()
^
-S.scala:4: error: Adapting argument list by creating a 5-tuple: this may not be what you want.
+S.scala:4: warning: Adapting argument list by creating a 5-tuple: this may not be what you want.
signature: J(x: Any): J
given arguments: 1, 2, 3, 4, 5
after adaptation: new J((1, 2, 3, 4, 5): (Int, Int, Int, Int, Int))
val x3 = new J(1, 2, 3, 4, 5)
^
-S.scala:6: error: Adapting argument list by creating a 3-tuple: this may not be what you want.
+S.scala:6: warning: Adapting argument list by creating a 3-tuple: this may not be what you want.
signature: Some.apply[A](x: A): Some[A]
given arguments: 1, 2, 3
after adaptation: Some((1, 2, 3): (Int, Int, Int))
val y1 = Some(1, 2, 3)
^
-S.scala:7: error: Adapting argument list by creating a 3-tuple: this may not be what you want.
+S.scala:7: warning: Adapting argument list by creating a 3-tuple: this may not be what you want.
signature: Some(x: A): Some[A]
given arguments: 1, 2, 3
after adaptation: new Some((1, 2, 3): (Int, Int, Int))
val y2 = new Some(1, 2, 3)
^
-S.scala:9: error: Adapting argument list by inserting (): this is unlikely to be what you want.
+S.scala:9: warning: Adapting argument list by inserting (): this is unlikely to be what you want.
signature: J2[T](x: T): J2[T]
given arguments: <none>
after adaptation: new J2((): Unit)
val z1 = new J2
^
-S.scala:10: error: Adapting argument list by inserting (): this is unlikely to be what you want.
+S.scala:10: warning: Adapting argument list by inserting (): this is unlikely to be what you want.
signature: J2[T](x: T): J2[T]
given arguments: <none>
after adaptation: new J2((): Unit)
val z2 = new J2()
^
-7 errors found
+error: No warnings can be incurred under -Xfatal-warnings.
+7 warnings found
+one error found
diff --git a/test/files/neg/t5353.check b/test/files/neg/t5353.check
new file mode 100644
index 0000000000..75e2435600
--- /dev/null
+++ b/test/files/neg/t5353.check
@@ -0,0 +1,4 @@
+t5353.scala:2: error: this type parameter must be specified
+ def f(x: Boolean) = if (x) Array("abc") else Array()
+ ^
+one error found
diff --git a/test/files/neg/t5353.scala b/test/files/neg/t5353.scala
new file mode 100644
index 0000000000..1ee869aac1
--- /dev/null
+++ b/test/files/neg/t5353.scala
@@ -0,0 +1,3 @@
+class A {
+ def f(x: Boolean) = if (x) Array("abc") else Array()
+}
diff --git a/test/files/neg/t5426.check b/test/files/neg/t5426.check
index d9e192d3f0..98f3ddaaae 100644
--- a/test/files/neg/t5426.check
+++ b/test/files/neg/t5426.check
@@ -1,13 +1,15 @@
-t5426.scala:2: error: comparing values of types Some[Int] and Int using `==' will always yield false
+t5426.scala:2: warning: comparing values of types Some[Int] and Int using `==' will always yield false
def f1 = Some(5) == 5
^
-t5426.scala:3: error: comparing values of types Int and Some[Int] using `==' will always yield false
+t5426.scala:3: warning: comparing values of types Int and Some[Int] using `==' will always yield false
def f2 = 5 == Some(5)
^
-t5426.scala:8: error: comparing values of types Int and Some[Int] using `==' will always yield false
+t5426.scala:8: warning: comparing values of types Int and Some[Int] using `==' will always yield false
(x1 == x2)
^
-t5426.scala:9: error: comparing values of types Some[Int] and Int using `==' will always yield false
+t5426.scala:9: warning: comparing values of types Some[Int] and Int using `==' will always yield false
(x2 == x1)
^
-four errors found
+error: No warnings can be incurred under -Xfatal-warnings.
+four warnings found
+one error found
diff --git a/test/files/neg/t5663-badwarneq.check b/test/files/neg/t5663-badwarneq.check
index 00c2234e9d..12e93ff373 100644
--- a/test/files/neg/t5663-badwarneq.check
+++ b/test/files/neg/t5663-badwarneq.check
@@ -1,22 +1,24 @@
-t5663-badwarneq.scala:42: error: comparing case class values of types Some[Int] and None.type using `==' will always yield false
+t5663-badwarneq.scala:42: warning: comparing case class values of types Some[Int] and None.type using `==' will always yield false
println(new Some(1) == None) // Should complain on type, was: spuriously complains on fresh object
^
-t5663-badwarneq.scala:43: error: comparing case class values of types Some[Int] and Thing using `==' will always yield false
+t5663-badwarneq.scala:43: warning: comparing case class values of types Some[Int] and Thing using `==' will always yield false
println(Some(1) == new Thing(1)) // Should complain on type, was: spuriously complains on fresh object
^
-t5663-badwarneq.scala:51: error: ThingOne and Thingy are unrelated: they will most likely never compare equal
+t5663-badwarneq.scala:51: warning: ThingOne and Thingy are unrelated: they will most likely never compare equal
println(t1 == t2) // true, but apparently unrelated, a compromise warning
^
-t5663-badwarneq.scala:52: error: ThingThree and Thingy are unrelated: they will most likely never compare equal
+t5663-badwarneq.scala:52: warning: ThingThree and Thingy are unrelated: they will most likely never compare equal
println(t4 == t2) // true, complains because ThingThree is final and Thingy not a subclass, stronger claim than unrelated
^
-t5663-badwarneq.scala:55: error: comparing case class values of types ThingTwo and Some[Int] using `==' will always yield false
+t5663-badwarneq.scala:55: warning: comparing case class values of types ThingTwo and Some[Int] using `==' will always yield false
println(t3 == Some(1)) // false, warn on different cases
^
-t5663-badwarneq.scala:56: error: comparing values of types ThingOne and Cousin using `==' will always yield false
+t5663-badwarneq.scala:56: warning: comparing values of types ThingOne and Cousin using `==' will always yield false
println(t1 == c) // should warn
^
-t5663-badwarneq.scala:64: error: comparing case class values of types Simple and SimpleSibling.type using `==' will always yield false
+t5663-badwarneq.scala:64: warning: comparing case class values of types Simple and SimpleSibling.type using `==' will always yield false
println(new Simple() == SimpleSibling) // like Some(1) == None, but needn't be final case
^
-7 errors found
+error: No warnings can be incurred under -Xfatal-warnings.
+7 warnings found
+one error found
diff --git a/test/files/neg/t5692a.check b/test/files/neg/t5692a.check
index ded95a8820..7fbfb5dba7 100644
--- a/test/files/neg/t5692a.check
+++ b/test/files/neg/t5692a.check
@@ -1,4 +1,4 @@
-Test_2.scala:2: error: type parameter not specified
+Test_2.scala:2: error: this type parameter must be specified
def x = Macros.foo
^
one error found
diff --git a/test/files/neg/t5692b.check b/test/files/neg/t5692b.check
index e453870ec8..16796826b4 100644
--- a/test/files/neg/t5692b.check
+++ b/test/files/neg/t5692b.check
@@ -1,4 +1,4 @@
-Test_2.scala:2: error: type parameters not specified
+Test_2.scala:2: error: these type parameters must be specified
def x = Macros.foo
^
one error found
diff --git a/test/files/neg/t5762.check b/test/files/neg/t5762.check
index 10064032aa..2a2f12144a 100644
--- a/test/files/neg/t5762.check
+++ b/test/files/neg/t5762.check
@@ -1,13 +1,15 @@
-t5762.scala:6: error: non-variable type argument Int in type pattern D[Int] is unchecked since it is eliminated by erasure
+t5762.scala:6: warning: non-variable type argument Int in type pattern D[Int] is unchecked since it is eliminated by erasure
case _: D[Int] if bippy => 1
^
-t5762.scala:7: error: non-variable type argument String in type pattern D[String] is unchecked since it is eliminated by erasure
+t5762.scala:7: warning: non-variable type argument String in type pattern D[String] is unchecked since it is eliminated by erasure
case _: D[String] => 2
^
-t5762.scala:20: error: non-variable type argument D[Int] in type pattern D[D[Int]] is unchecked since it is eliminated by erasure
+t5762.scala:20: warning: non-variable type argument D[Int] in type pattern D[D[Int]] is unchecked since it is eliminated by erasure
case _: D[D[Int]] if bippy => 1
^
-t5762.scala:21: error: non-variable type argument D[String] in type pattern D[D[String]] is unchecked since it is eliminated by erasure
+t5762.scala:21: warning: non-variable type argument D[String] in type pattern D[D[String]] is unchecked since it is eliminated by erasure
case _: D[D[String]] => 2
^
-four errors found
+error: No warnings can be incurred under -Xfatal-warnings.
+four warnings found
+one error found
diff --git a/test/files/neg/t5830.check b/test/files/neg/t5830.check
index 726fac2a1e..58c3a1be38 100644
--- a/test/files/neg/t5830.check
+++ b/test/files/neg/t5830.check
@@ -1,7 +1,9 @@
-t5830.scala:6: error: unreachable code
+t5830.scala:6: warning: unreachable code
case 'a' => println("b") // unreachable
^
-t5830.scala:4: error: could not emit switch for @switch annotated match
+t5830.scala:4: warning: could not emit switch for @switch annotated match
def unreachable(ch: Char) = (ch: @switch) match {
^
-two errors found
+error: No warnings can be incurred under -Xfatal-warnings.
+two warnings found
+one error found
diff --git a/test/files/neg/t6011.check b/test/files/neg/t6011.check
index 5b5a861e5b..cb7f189031 100644
--- a/test/files/neg/t6011.check
+++ b/test/files/neg/t6011.check
@@ -1,10 +1,12 @@
-t6011.scala:4: error: unreachable code
+t6011.scala:4: warning: unreachable code
case 'a' | 'c' => 1 // unreachable
^
-t6011.scala:10: error: unreachable code
+t6011.scala:10: warning: unreachable code
case 'b' | 'a' => 1 // unreachable
^
-t6011.scala:8: error: could not emit switch for @switch annotated match
+t6011.scala:8: warning: could not emit switch for @switch annotated match
def f2(ch: Char): Any = (ch: @annotation.switch) match {
^
-three errors found
+error: No warnings can be incurred under -Xfatal-warnings.
+three warnings found
+one error found
diff --git a/test/files/neg/t6048.check b/test/files/neg/t6048.check
index 5bdf2eca88..5e11d24fde 100644
--- a/test/files/neg/t6048.check
+++ b/test/files/neg/t6048.check
@@ -1,13 +1,15 @@
-t6048.scala:3: error: unreachable code
+t6048.scala:3: warning: unreachable code
case _ if false => x // unreachable
^
-t6048.scala:8: error: unreachable code
+t6048.scala:8: warning: unreachable code
case _ if false => x // unreachable
^
-t6048.scala:13: error: patterns after a variable pattern cannot match (SLS 8.1.1)
+t6048.scala:13: warning: patterns after a variable pattern cannot match (SLS 8.1.1)
case _ => x
^
-t6048.scala:14: error: unreachable code due to variable pattern on line 13
+t6048.scala:14: warning: unreachable code due to variable pattern on line 13
case 5 if true => x // unreachable
^
-four errors found
+error: No warnings can be incurred under -Xfatal-warnings.
+four warnings found
+one error found
diff --git a/test/files/neg/t6162-inheritance.check b/test/files/neg/t6162-inheritance.check
index a7d3cc3238..e98fa79eb7 100644
--- a/test/files/neg/t6162-inheritance.check
+++ b/test/files/neg/t6162-inheritance.check
@@ -1,10 +1,18 @@
-t6162-inheritance.scala:6: error: inheritance from class Foo in package t6126 is deprecated: `Foo` will be made final in a future version.
+t6162-inheritance.scala:6: warning: inheritance from class Foo in package t6126 is deprecated: `Foo` will be made final in a future version.
class SubFoo extends Foo
^
-t6162-inheritance.scala:11: error: inheritance from trait T in package t6126 is deprecated
+t6162-inheritance.scala:11: warning: inheritance from trait T in package t6126 is deprecated
object SubT extends T
^
-t6162-inheritance.scala:17: error: inheritance from trait S in package t6126 is deprecated
+t6162-inheritance.scala:17: warning: inheritance from trait S in package t6126 is deprecated
new S {
^
-three errors found
+t6162-inheritance.scala:6: warning: inheritance from class Foo in package t6126 is deprecated: `Foo` will be made final in a future version.
+class SubFoo extends Foo
+ ^
+t6162-inheritance.scala:11: warning: inheritance from trait T in package t6126 is deprecated
+object SubT extends T
+ ^
+error: No warnings can be incurred under -Xfatal-warnings.
+5 warnings found
+one error found
diff --git a/test/files/neg/t6162-overriding.check b/test/files/neg/t6162-overriding.check
index e774888d36..6bff75d88d 100644
--- a/test/files/neg/t6162-overriding.check
+++ b/test/files/neg/t6162-overriding.check
@@ -1,7 +1,9 @@
-t6162-overriding.scala:14: error: overriding method bar in class Bar is deprecated: `bar` will be made private in a future version.
+t6162-overriding.scala:14: warning: overriding method bar in class Bar is deprecated: `bar` will be made private in a future version.
override def bar = 43
^
-t6162-overriding.scala:15: error: overriding method baz in class Bar is deprecated
+t6162-overriding.scala:15: warning: overriding method baz in class Bar is deprecated
override def baz = 43
^
-two errors found
+error: No warnings can be incurred under -Xfatal-warnings.
+two warnings found
+one error found
diff --git a/test/files/neg/t6264.check b/test/files/neg/t6264.check
index 438be4c39f..c0975a80b2 100644
--- a/test/files/neg/t6264.check
+++ b/test/files/neg/t6264.check
@@ -1,4 +1,6 @@
-t6264.scala:3: error: non-variable type argument Tuple1[_] in type Tuple2[_, Tuple1[_]] is unchecked since it is eliminated by erasure
+t6264.scala:3: warning: non-variable type argument Tuple1[_] in type Tuple2[_, Tuple1[_]] is unchecked since it is eliminated by erasure
x.isInstanceOf[Tuple2[_, Tuple1[_]]]
^
+error: No warnings can be incurred under -Xfatal-warnings.
+one warning found
one error found
diff --git a/test/files/neg/t6276.check b/test/files/neg/t6276.check
index 0b3dfa5531..f275de9d0a 100644
--- a/test/files/neg/t6276.check
+++ b/test/files/neg/t6276.check
@@ -1,19 +1,21 @@
-t6276.scala:4: error: method a in class C does nothing other than call itself recursively
+t6276.scala:4: warning: method a in class C does nothing other than call itself recursively
def a: Any = a // warn
^
-t6276.scala:5: error: value b in class C does nothing other than call itself recursively
+t6276.scala:5: warning: value b in class C does nothing other than call itself recursively
val b: Any = b // warn
^
-t6276.scala:7: error: method c in class C does nothing other than call itself recursively
+t6276.scala:7: warning: method c in class C does nothing other than call itself recursively
def c: Any = this.c // warn
^
-t6276.scala:8: error: method d in class C does nothing other than call itself recursively
+t6276.scala:8: warning: method d in class C does nothing other than call itself recursively
def d: Any = C.this.d // warn
^
-t6276.scala:13: error: method a does nothing other than call itself recursively
+t6276.scala:13: warning: method a does nothing other than call itself recursively
def a: Any = a // warn
^
-t6276.scala:22: error: method a does nothing other than call itself recursively
+t6276.scala:22: warning: method a does nothing other than call itself recursively
def a = a // warn
^
-6 errors found
+error: No warnings can be incurred under -Xfatal-warnings.
+6 warnings found
+one error found
diff --git a/test/files/neg/t6355.check b/test/files/neg/t6355.check
new file mode 100644
index 0000000000..c1fa147f52
--- /dev/null
+++ b/test/files/neg/t6355.check
@@ -0,0 +1,4 @@
+t6355.scala:12: error: implementation restriction: applyDynamic cannot be overloaded
+ def applyDynamic(name: String)(x: Int): Int = 2
+ ^
+one error found
diff --git a/test/files/neg/t6355.scala b/test/files/neg/t6355.scala
new file mode 100644
index 0000000000..3007dc49f6
--- /dev/null
+++ b/test/files/neg/t6355.scala
@@ -0,0 +1,13 @@
+package foo
+
+import scala.language.dynamics
+
+class DoesntExtendDynamic {
+ def applyDynamic(name: String)(s: String): Int = 1
+ def applyDynamic(name: String)(x: Int): Int = 2
+}
+
+class A extends Dynamic {
+ def applyDynamic(name: String)(s: String): Int = 1
+ def applyDynamic(name: String)(x: Int): Int = 2
+}
diff --git a/test/files/neg/t6406-regextract.check b/test/files/neg/t6406-regextract.check
new file mode 100644
index 0000000000..19425a68b0
--- /dev/null
+++ b/test/files/neg/t6406-regextract.check
@@ -0,0 +1,6 @@
+t6406-regextract.scala:4: warning: method unapplySeq in class Regex is deprecated: Extracting a match result from anything but a CharSequence or Match is deprecated
+ List(1) collect { case r(i) => i }
+ ^
+error: No warnings can be incurred under -Xfatal-warnings.
+one warning found
+one error found
diff --git a/test/files/neg/t6406-regextract.flags b/test/files/neg/t6406-regextract.flags
new file mode 100644
index 0000000000..85d8eb2ba2
--- /dev/null
+++ b/test/files/neg/t6406-regextract.flags
@@ -0,0 +1 @@
+-Xfatal-warnings
diff --git a/test/files/neg/t6406-regextract.scala b/test/files/neg/t6406-regextract.scala
new file mode 100644
index 0000000000..0f5dad908d
--- /dev/null
+++ b/test/files/neg/t6406-regextract.scala
@@ -0,0 +1,5 @@
+
+object Test extends App {
+ val r = "(\\d+)".r
+ List(1) collect { case r(i) => i }
+}
diff --git a/test/files/neg/t6426.check b/test/files/neg/t6426.check
new file mode 100644
index 0000000000..149f74c4de
--- /dev/null
+++ b/test/files/neg/t6426.check
@@ -0,0 +1,7 @@
+t6426.scala:4: error: wildcard invalid as backquoted identifier
+ println(`_`.Buffer(0))
+ ^
+t6426.scala:5: error: ')' expected but '}' found.
+}
+^
+two errors found
diff --git a/test/files/neg/t6426.scala b/test/files/neg/t6426.scala
new file mode 100644
index 0000000000..a27d18eb58
--- /dev/null
+++ b/test/files/neg/t6426.scala
@@ -0,0 +1,5 @@
+class A {
+ import collection.{mutable => _, _}
+
+ println(`_`.Buffer(0))
+}
diff --git a/test/files/neg/t6567.check b/test/files/neg/t6567.check
new file mode 100644
index 0000000000..a733d75354
--- /dev/null
+++ b/test/files/neg/t6567.check
@@ -0,0 +1,9 @@
+t6567.scala:8: warning: Suspicious application of an implicit view (Test.this.a2b) in the argument to Option.apply.
+ Option[B](a)
+ ^
+t6567.scala:10: warning: Suspicious application of an implicit view (Test.this.a2b) in the argument to Option.apply.
+ val b: Option[B] = Option(a)
+ ^
+error: No warnings can be incurred under -Xfatal-warnings.
+two warnings found
+one error found
diff --git a/test/files/neg/t6567.flags b/test/files/neg/t6567.flags
new file mode 100644
index 0000000000..e93641e931
--- /dev/null
+++ b/test/files/neg/t6567.flags
@@ -0,0 +1 @@
+-Xlint -Xfatal-warnings \ No newline at end of file
diff --git a/test/files/neg/t6567.scala b/test/files/neg/t6567.scala
new file mode 100644
index 0000000000..650e5e39ae
--- /dev/null
+++ b/test/files/neg/t6567.scala
@@ -0,0 +1,11 @@
+class A
+class B
+
+object Test {
+ val a: A = null
+ implicit def a2b(a: A) = new B
+
+ Option[B](a)
+
+ val b: Option[B] = Option(a)
+}
diff --git a/test/files/neg/unchecked-abstract.check b/test/files/neg/unchecked-abstract.check
index 6e811dc156..72019082ac 100644
--- a/test/files/neg/unchecked-abstract.check
+++ b/test/files/neg/unchecked-abstract.check
@@ -1,25 +1,27 @@
-unchecked-abstract.scala:16: error: abstract type H in type Contravariant[M.this.H] is unchecked since it is eliminated by erasure
+unchecked-abstract.scala:16: warning: abstract type H in type Contravariant[M.this.H] is unchecked since it is eliminated by erasure
/* warn */ println(x.isInstanceOf[Contravariant[H]])
^
-unchecked-abstract.scala:21: error: abstract type H in type Contravariant[M.this.H] is unchecked since it is eliminated by erasure
+unchecked-abstract.scala:21: warning: abstract type H in type Contravariant[M.this.H] is unchecked since it is eliminated by erasure
/* warn */ println(x.isInstanceOf[Contravariant[H]])
^
-unchecked-abstract.scala:27: error: abstract type T in type Invariant[M.this.T] is unchecked since it is eliminated by erasure
+unchecked-abstract.scala:27: warning: abstract type T in type Invariant[M.this.T] is unchecked since it is eliminated by erasure
/* warn */ println(x.isInstanceOf[Invariant[T]])
^
-unchecked-abstract.scala:28: error: abstract type L in type Invariant[M.this.L] is unchecked since it is eliminated by erasure
+unchecked-abstract.scala:28: warning: abstract type L in type Invariant[M.this.L] is unchecked since it is eliminated by erasure
/* warn */ println(x.isInstanceOf[Invariant[L]])
^
-unchecked-abstract.scala:31: error: abstract type H in type Invariant[M.this.H] is unchecked since it is eliminated by erasure
+unchecked-abstract.scala:31: warning: abstract type H in type Invariant[M.this.H] is unchecked since it is eliminated by erasure
/* warn */ println(x.isInstanceOf[Invariant[H]])
^
-unchecked-abstract.scala:33: error: abstract type L in type Invariant[M.this.L] is unchecked since it is eliminated by erasure
+unchecked-abstract.scala:33: warning: abstract type L in type Invariant[M.this.L] is unchecked since it is eliminated by erasure
/* warn */ println(x.isInstanceOf[Invariant[L]])
^
-unchecked-abstract.scala:36: error: abstract type H in type Invariant[M.this.H] is unchecked since it is eliminated by erasure
+unchecked-abstract.scala:36: warning: abstract type H in type Invariant[M.this.H] is unchecked since it is eliminated by erasure
/* warn */ println(x.isInstanceOf[Invariant[H]])
^
-unchecked-abstract.scala:37: error: abstract type T in type Invariant[M.this.T] is unchecked since it is eliminated by erasure
+unchecked-abstract.scala:37: warning: abstract type T in type Invariant[M.this.T] is unchecked since it is eliminated by erasure
/* warn */ println(x.isInstanceOf[Invariant[T]])
^
-8 errors found
+error: No warnings can be incurred under -Xfatal-warnings.
+8 warnings found
+one error found
diff --git a/test/files/neg/unchecked-impossible.check b/test/files/neg/unchecked-impossible.check
index 0ab371dbaa..d150a5a853 100644
--- a/test/files/neg/unchecked-impossible.check
+++ b/test/files/neg/unchecked-impossible.check
@@ -1,4 +1,10 @@
-unchecked-impossible.scala:5: error: fruitless type test: a value of type T2[Int,Int] cannot also be a Seq[A]
+unchecked-impossible.scala:5: warning: fruitless type test: a value of type T2[Int,Int] cannot also be a Seq[A]
case Seq(x) =>
^
+unchecked-impossible.scala:5: error: pattern type is incompatible with expected type;
+ found : Seq[A]
+ required: T2[Int,Int]
+ case Seq(x) =>
+ ^
+one warning found
one error found
diff --git a/test/files/neg/unchecked-knowable.check b/test/files/neg/unchecked-knowable.check
index d279427327..327a5f202d 100644
--- a/test/files/neg/unchecked-knowable.check
+++ b/test/files/neg/unchecked-knowable.check
@@ -1,7 +1,9 @@
-unchecked-knowable.scala:18: error: fruitless type test: a value of type Bippy cannot also be a A1
+unchecked-knowable.scala:18: warning: fruitless type test: a value of type Bippy cannot also be a A1
/* warn */ (new Bippy).isInstanceOf[A1]
^
-unchecked-knowable.scala:19: error: fruitless type test: a value of type Bippy cannot also be a B1
+unchecked-knowable.scala:19: warning: fruitless type test: a value of type Bippy cannot also be a B1
/* warn */ (new Bippy).isInstanceOf[B1]
^
-two errors found
+error: No warnings can be incurred under -Xfatal-warnings.
+two warnings found
+one error found
diff --git a/test/files/neg/unchecked-refinement.check b/test/files/neg/unchecked-refinement.check
index d81517464f..e85a51f44d 100644
--- a/test/files/neg/unchecked-refinement.check
+++ b/test/files/neg/unchecked-refinement.check
@@ -1,13 +1,15 @@
-unchecked-refinement.scala:17: error: abstract type U in type pattern Foo[U,U,V] is unchecked since it is eliminated by erasure
+unchecked-refinement.scala:17: warning: abstract type U in type pattern Foo[U,U,V] is unchecked since it is eliminated by erasure
/* warn */ case _: Foo[U, U, V] if b => ()
^
-unchecked-refinement.scala:19: error: non-variable type argument Any in type pattern Foo[Any,U,V] is unchecked since it is eliminated by erasure
+unchecked-refinement.scala:19: warning: non-variable type argument Any in type pattern Foo[Any,U,V] is unchecked since it is eliminated by erasure
/* warn */ case _: Foo[Any, U, V] if b => ()
^
-unchecked-refinement.scala:23: error: a pattern match on a refinement type is unchecked
+unchecked-refinement.scala:23: warning: a pattern match on a refinement type is unchecked
/* nowarn - todo */ case x: AnyRef { def bippy: Int } if b => x.bippy // this could/should do an instance check and not warn
^
-unchecked-refinement.scala:24: error: a pattern match on a refinement type is unchecked
+unchecked-refinement.scala:24: warning: a pattern match on a refinement type is unchecked
/* nowarn - todo */ case x: AnyRef { def size: Int } if b => x.size // this could/should do a static conformance test and not warn
^
-four errors found
+error: No warnings can be incurred under -Xfatal-warnings.
+four warnings found
+one error found
diff --git a/test/files/neg/unchecked-suppress.check b/test/files/neg/unchecked-suppress.check
index 2e23d21386..038105918e 100644
--- a/test/files/neg/unchecked-suppress.check
+++ b/test/files/neg/unchecked-suppress.check
@@ -1,10 +1,12 @@
-unchecked-suppress.scala:4: error: non-variable type argument Int in type pattern Set[Int] is unchecked since it is eliminated by erasure
+unchecked-suppress.scala:4: warning: non-variable type argument Int in type pattern Set[Int] is unchecked since it is eliminated by erasure
case xs: Set[Int] => xs.head // unchecked
^
-unchecked-suppress.scala:5: error: non-variable type argument String in type pattern Map[String @unchecked,String] is unchecked since it is eliminated by erasure
+unchecked-suppress.scala:5: warning: non-variable type argument String in type pattern Map[String @unchecked,String] is unchecked since it is eliminated by erasure
case xs: Map[String @unchecked, String] => xs.head // one unchecked, one okay
^
-unchecked-suppress.scala:7: error: non-variable type argument Int in type pattern (Int, Int) => Int is unchecked since it is eliminated by erasure
+unchecked-suppress.scala:7: warning: non-variable type argument Int in type pattern (Int, Int) => Int is unchecked since it is eliminated by erasure
case f: ((Int, Int) => Int) => // unchecked
^
-three errors found
+error: No warnings can be incurred under -Xfatal-warnings.
+three warnings found
+one error found
diff --git a/test/files/neg/unchecked.check b/test/files/neg/unchecked.check
index 2883b716c9..570f02f219 100644
--- a/test/files/neg/unchecked.check
+++ b/test/files/neg/unchecked.check
@@ -1,19 +1,21 @@
-unchecked.scala:18: error: non-variable type argument String in type pattern Iterable[String] is unchecked since it is eliminated by erasure
+unchecked.scala:18: warning: non-variable type argument String in type pattern Iterable[String] is unchecked since it is eliminated by erasure
case xs: Iterable[String] => xs.head // unchecked
^
-unchecked.scala:22: error: non-variable type argument Any in type pattern Set[Any] is unchecked since it is eliminated by erasure
+unchecked.scala:22: warning: non-variable type argument Any in type pattern Set[Any] is unchecked since it is eliminated by erasure
case xs: Set[Any] => xs.head // unchecked
^
-unchecked.scala:26: error: non-variable type argument Any in type pattern Map[Any,Any] is unchecked since it is eliminated by erasure
+unchecked.scala:26: warning: non-variable type argument Any in type pattern Map[Any,Any] is unchecked since it is eliminated by erasure
case xs: Map[Any, Any] => xs.head // unchecked
^
-unchecked.scala:35: error: non-variable type argument List[Nothing] in type pattern Test.Contra[List[Nothing]] is unchecked since it is eliminated by erasure
+unchecked.scala:35: warning: non-variable type argument List[Nothing] in type pattern Test.Contra[List[Nothing]] is unchecked since it is eliminated by erasure
case xs: Contra[List[Nothing]] => xs.head // unchecked
^
-unchecked.scala:50: error: non-variable type argument String in type pattern Test.Exp[String] is unchecked since it is eliminated by erasure
+unchecked.scala:50: warning: non-variable type argument String in type pattern Test.Exp[String] is unchecked since it is eliminated by erasure
case ArrayApply(x: Exp[Array[T]], _, j: Exp[String]) => x // unchecked
^
-unchecked.scala:55: error: non-variable type argument Array[T] in type pattern Test.Exp[Array[T]] is unchecked since it is eliminated by erasure
+unchecked.scala:55: warning: non-variable type argument Array[T] in type pattern Test.Exp[Array[T]] is unchecked since it is eliminated by erasure
case ArrayApply(x: Exp[Array[T]], _, _) => x // unchecked
^
-6 errors found
+error: No warnings can be incurred under -Xfatal-warnings.
+6 warnings found
+one error found
diff --git a/test/files/neg/unchecked2.check b/test/files/neg/unchecked2.check
index 68fdfa82ac..a7b8391856 100644
--- a/test/files/neg/unchecked2.check
+++ b/test/files/neg/unchecked2.check
@@ -1,43 +1,45 @@
-unchecked2.scala:4: error: fruitless type test: a value of type Some[List[Int]] cannot also be a Option[List[String]] (but still might match its erasure)
+unchecked2.scala:4: warning: fruitless type test: a value of type Some[List[Int]] cannot also be a Option[List[String]] (but still might match its erasure)
/* warn */ Some(List(1)).isInstanceOf[Option[List[String]]]
^
-unchecked2.scala:5: error: non-variable type argument Option[_] in type Option[Option[_]] is unchecked since it is eliminated by erasure
+unchecked2.scala:5: warning: non-variable type argument Option[_] in type Option[Option[_]] is unchecked since it is eliminated by erasure
/* warn */ Some(123).isInstanceOf[Option[Option[_]]]
^
-unchecked2.scala:6: error: fruitless type test: a value of type Some[Int] cannot also be a Option[String] (but still might match its erasure)
+unchecked2.scala:6: warning: fruitless type test: a value of type Some[Int] cannot also be a Option[String] (but still might match its erasure)
/* warn */ Some(123).isInstanceOf[Option[String]]
^
-unchecked2.scala:7: error: fruitless type test: a value of type Some[Int] cannot also be a Option[List[String]] (but still might match its erasure)
+unchecked2.scala:7: warning: fruitless type test: a value of type Some[Int] cannot also be a Option[List[String]] (but still might match its erasure)
/* warn */ Some(123).isInstanceOf[Option[List[String]]]
^
-unchecked2.scala:8: error: fruitless type test: a value of type Some[Int] cannot also be a Option[List[Int => String]] (but still might match its erasure)
+unchecked2.scala:8: warning: fruitless type test: a value of type Some[Int] cannot also be a Option[List[Int => String]] (but still might match its erasure)
/* warn */ Some(123).isInstanceOf[Option[List[Int => String]]]
^
-unchecked2.scala:9: error: fruitless type test: a value of type Some[Int] cannot also be a Option[(String, Double)] (but still might match its erasure)
+unchecked2.scala:9: warning: fruitless type test: a value of type Some[Int] cannot also be a Option[(String, Double)] (but still might match its erasure)
/* warn */ Some(123).isInstanceOf[Option[(String, Double)]]
^
-unchecked2.scala:10: error: fruitless type test: a value of type Some[Int] cannot also be a Option[String => Double] (but still might match its erasure)
+unchecked2.scala:10: warning: fruitless type test: a value of type Some[Int] cannot also be a Option[String => Double] (but still might match its erasure)
/* warn */ Some(123).isInstanceOf[Option[String => Double]]
^
-unchecked2.scala:14: error: non-variable type argument List[String] in type Option[List[String]] is unchecked since it is eliminated by erasure
+unchecked2.scala:14: warning: non-variable type argument List[String] in type Option[List[String]] is unchecked since it is eliminated by erasure
/* warn */ (Some(List(1)): Any).isInstanceOf[Option[List[String]]]
^
-unchecked2.scala:15: error: non-variable type argument Int in type Option[Int] is unchecked since it is eliminated by erasure
+unchecked2.scala:15: warning: non-variable type argument Int in type Option[Int] is unchecked since it is eliminated by erasure
/* warn */ (Some(123): Any).isInstanceOf[Option[Int]]
^
-unchecked2.scala:16: error: non-variable type argument String in type Option[String] is unchecked since it is eliminated by erasure
+unchecked2.scala:16: warning: non-variable type argument String in type Option[String] is unchecked since it is eliminated by erasure
/* warn */ (Some(123): Any).isInstanceOf[Option[String]]
^
-unchecked2.scala:17: error: non-variable type argument List[String] in type Option[List[String]] is unchecked since it is eliminated by erasure
+unchecked2.scala:17: warning: non-variable type argument List[String] in type Option[List[String]] is unchecked since it is eliminated by erasure
/* warn */ (Some(123): Any).isInstanceOf[Option[List[String]]]
^
-unchecked2.scala:18: error: non-variable type argument List[Int => String] in type Option[List[Int => String]] is unchecked since it is eliminated by erasure
+unchecked2.scala:18: warning: non-variable type argument List[Int => String] in type Option[List[Int => String]] is unchecked since it is eliminated by erasure
/* warn */ (Some(123): Any).isInstanceOf[Option[List[Int => String]]]
^
-unchecked2.scala:19: error: non-variable type argument (String, Double) in type Option[(String, Double)] is unchecked since it is eliminated by erasure
+unchecked2.scala:19: warning: non-variable type argument (String, Double) in type Option[(String, Double)] is unchecked since it is eliminated by erasure
/* warn */ (Some(123): Any).isInstanceOf[Option[(String, Double)]]
^
-unchecked2.scala:20: error: non-variable type argument String => Double in type Option[String => Double] is unchecked since it is eliminated by erasure
+unchecked2.scala:20: warning: non-variable type argument String => Double in type Option[String => Double] is unchecked since it is eliminated by erasure
/* warn */ (Some(123): Any).isInstanceOf[Option[String => Double]]
^
-14 errors found
+error: No warnings can be incurred under -Xfatal-warnings.
+14 warnings found
+one error found
diff --git a/test/files/neg/unchecked3.check b/test/files/neg/unchecked3.check
index f4f0c74257..a7582a8930 100644
--- a/test/files/neg/unchecked3.check
+++ b/test/files/neg/unchecked3.check
@@ -1,37 +1,42 @@
-unchecked3.scala:24: error: non-variable type argument Double in type pattern E1[Double] is unchecked since it is eliminated by erasure
+unchecked3.scala:24: warning: non-variable type argument Double in type pattern E1[Double] is unchecked since it is eliminated by erasure
/* warn */ def peerTypes2(x: B1[Int]) = x match { case _: E1[Double] => true }
^
-unchecked3.scala:25: error: non-variable type argument Double in type pattern F1[Double] is unchecked since it is eliminated by erasure
+unchecked3.scala:25: warning: non-variable type argument Double in type pattern F1[Double] is unchecked since it is eliminated by erasure
/* warn */ def peerTypes3(x: B1[_]) = x match { case _: F1[Double] => true }
^
-unchecked3.scala:28: error: non-variable type argument Int in type pattern A2[Int] is unchecked since it is eliminated by erasure
+unchecked3.scala:28: warning: non-variable type argument Int in type pattern A2[Int] is unchecked since it is eliminated by erasure
/* warn */ def twotypes1[T](x: B2[T, Int]) = x match { case _: A2[Int] => true }
^
-unchecked3.scala:32: error: non-variable type argument Int in type pattern B2[_,Int] is unchecked since it is eliminated by erasure
+unchecked3.scala:32: warning: non-variable type argument Int in type pattern B2[_,Int] is unchecked since it is eliminated by erasure
/* warn */ def twotypes5[T](x: A2[T]) = x match { case _: B2[_, Int] => true }
^
-unchecked3.scala:40: error: non-variable type argument String in type pattern Array[List[String]] is unchecked since it is eliminated by erasure
+unchecked3.scala:40: warning: non-variable type argument String in type pattern Array[List[String]] is unchecked since it is eliminated by erasure
/* warn */ case _: Array[List[String]] => ()
^
-unchecked3.scala:43: error: non-variable type argument String in type pattern Array[Array[List[String]]] is unchecked since it is eliminated by erasure
+unchecked3.scala:43: warning: non-variable type argument String in type pattern Array[Array[List[String]]] is unchecked since it is eliminated by erasure
/* warn */ case _: Array[Array[List[String]]] => ()
^
-unchecked3.scala:50: error: non-variable type argument String in type pattern Array[List[String]] is unchecked since it is eliminated by erasure
+unchecked3.scala:50: warning: non-variable type argument String in type pattern Array[List[String]] is unchecked since it is eliminated by erasure
/* warn */ case _: Array[List[String]] => ()
^
-unchecked3.scala:53: error: non-variable type argument String in type pattern Array[Array[List[String]]] is unchecked since it is eliminated by erasure
+unchecked3.scala:53: warning: non-variable type argument String in type pattern Array[Array[List[String]]] is unchecked since it is eliminated by erasure
/* warn */ case _: Array[Array[List[String]]] => ()
^
-unchecked3.scala:60: error: non-variable type argument String in type pattern Array[List[String]] is unchecked since it is eliminated by erasure
+unchecked3.scala:60: warning: non-variable type argument String in type pattern Array[List[String]] is unchecked since it is eliminated by erasure
/* warn */ case _: Array[List[String]] => ()
^
-unchecked3.scala:62: error: non-variable type argument Array[String] in type pattern Array[List[Array[String]]] is unchecked since it is eliminated by erasure
+unchecked3.scala:62: warning: non-variable type argument Array[String] in type pattern Array[List[Array[String]]] is unchecked since it is eliminated by erasure
/* warn */ case _: Array[List[Array[String]]] => ()
^
-unchecked3.scala:63: error: non-variable type argument String in type pattern Array[Array[List[String]]] is unchecked since it is eliminated by erasure
+unchecked3.scala:63: warning: non-variable type argument String in type pattern Array[Array[List[String]]] is unchecked since it is eliminated by erasure
/* warn */ case _: Array[Array[List[String]]] => ()
^
-unchecked3.scala:75: error: abstract type A in type pattern Set[Q.this.A] is unchecked since it is eliminated by erasure
+unchecked3.scala:75: warning: abstract type A in type pattern Set[Q.this.A] is unchecked since it is eliminated by erasure
/* warn */ case xs: Set[A] => xs.head
^
-12 errors found
+unchecked3.scala:62: warning: unreachable code
+ /* warn */ case _: Array[List[Array[String]]] => ()
+ ^
+error: No warnings can be incurred under -Xfatal-warnings.
+13 warnings found
+one error found
diff --git a/test/files/neg/unit-returns-value.check b/test/files/neg/unit-returns-value.check
index ab458a350b..f30a506ebe 100644
--- a/test/files/neg/unit-returns-value.check
+++ b/test/files/neg/unit-returns-value.check
@@ -1,7 +1,15 @@
-unit-returns-value.scala:4: error: a pure expression does nothing in statement position; you may be omitting necessary parentheses
+unit-returns-value.scala:4: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses
if (b) return 5
^
-unit-returns-value.scala:4: error: enclosing method f has result type Unit: return value discarded
+unit-returns-value.scala:4: warning: enclosing method f has result type Unit: return value discarded
if (b) return 5
^
-two errors found
+unit-returns-value.scala:22: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses
+ i1 // warn
+ ^
+unit-returns-value.scala:23: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses
+ i2 // warn
+ ^
+error: No warnings can be incurred under -Xfatal-warnings.
+four warnings found
+one error found
diff --git a/test/files/neg/unit-returns-value.scala b/test/files/neg/unit-returns-value.scala
index ecc981f217..fc5a37069f 100644
--- a/test/files/neg/unit-returns-value.scala
+++ b/test/files/neg/unit-returns-value.scala
@@ -3,9 +3,30 @@ object Test {
var b = false
if (b) return 5
}
-
+
// no warning
def g {
return println("hello")
}
}
+
+class UnusedValues {
+ var i1 = 2
+ val i2 = 2
+ lazy val i3 = 2
+ object i4 { }
+ def i5 = 2
+ final def i6 = 2
+
+ def x = {
+ i1 // warn
+ i2 // warn
+ i3 // no warn
+ i4 // no warn
+ i5 // no warn
+ i6 // could warn someday, if i6 returned 2.type instead of Int
+
+ 5
+ }
+}
+
diff --git a/test/files/neg/virtpatmat_reach_null.check b/test/files/neg/virtpatmat_reach_null.check
index 595c8ec889..e0c36c8c5b 100644
--- a/test/files/neg/virtpatmat_reach_null.check
+++ b/test/files/neg/virtpatmat_reach_null.check
@@ -1,4 +1,6 @@
-virtpatmat_reach_null.scala:13: error: unreachable code
+virtpatmat_reach_null.scala:13: warning: unreachable code
case _ => // unreachable
^
+error: No warnings can be incurred under -Xfatal-warnings.
+one warning found
one error found
diff --git a/test/files/neg/virtpatmat_reach_sealed_unsealed.check b/test/files/neg/virtpatmat_reach_sealed_unsealed.check
index 10638eff52..064a12bcaa 100644
--- a/test/files/neg/virtpatmat_reach_sealed_unsealed.check
+++ b/test/files/neg/virtpatmat_reach_sealed_unsealed.check
@@ -1,14 +1,16 @@
-virtpatmat_reach_sealed_unsealed.scala:16: error: match may not be exhaustive.
+virtpatmat_reach_sealed_unsealed.scala:16: warning: match may not be exhaustive.
It would fail on the following input: false
(true: Boolean) match { case true => } // not exhaustive, but reachable
^
-virtpatmat_reach_sealed_unsealed.scala:18: error: unreachable code
+virtpatmat_reach_sealed_unsealed.scala:18: warning: unreachable code
(true: Boolean) match { case true => case false => case _ => } // exhaustive, last case is unreachable
^
-virtpatmat_reach_sealed_unsealed.scala:19: error: unreachable code
+virtpatmat_reach_sealed_unsealed.scala:19: warning: unreachable code
(true: Boolean) match { case true => case false => case _: Boolean => } // exhaustive, last case is unreachable
^
-virtpatmat_reach_sealed_unsealed.scala:20: error: unreachable code
+virtpatmat_reach_sealed_unsealed.scala:20: warning: unreachable code
(true: Boolean) match { case true => case false => case _: Any => } // exhaustive, last case is unreachable
^
-four errors found
+error: No warnings can be incurred under -Xfatal-warnings.
+four warnings found
+one error found
diff --git a/test/files/neg/virtpatmat_unreach_select.check b/test/files/neg/virtpatmat_unreach_select.check
index 3771971020..4fc78cd412 100644
--- a/test/files/neg/virtpatmat_unreach_select.check
+++ b/test/files/neg/virtpatmat_unreach_select.check
@@ -1,4 +1,6 @@
-virtpatmat_unreach_select.scala:10: error: unreachable code
+virtpatmat_unreach_select.scala:10: warning: unreachable code
case WARNING.id => // unreachable
^
+error: No warnings can be incurred under -Xfatal-warnings.
+one warning found
one error found
diff --git a/test/files/neg/warn-inferred-any.check b/test/files/neg/warn-inferred-any.check
new file mode 100644
index 0000000000..4628033e55
--- /dev/null
+++ b/test/files/neg/warn-inferred-any.check
@@ -0,0 +1,12 @@
+warn-inferred-any.scala:8: warning: a type was inferred to be `Any`; this may indicate a programming error.
+ { List(1, 2, 3) contains "a" } // only this warns
+ ^
+warn-inferred-any.scala:16: warning: a type was inferred to be `AnyVal`; this may indicate a programming error.
+ { 1l to 5l contains 5 }
+ ^
+warn-inferred-any.scala:17: warning: a type was inferred to be `AnyVal`; this may indicate a programming error.
+ { 1l to 5l contains 5d }
+ ^
+error: No warnings can be incurred under -Xfatal-warnings.
+three warnings found
+one error found
diff --git a/test/files/neg/warn-inferred-any.flags b/test/files/neg/warn-inferred-any.flags
new file mode 100644
index 0000000000..a3127d392a
--- /dev/null
+++ b/test/files/neg/warn-inferred-any.flags
@@ -0,0 +1 @@
+-Xfatal-warnings -Ywarn-infer-any
diff --git a/test/files/neg/warn-inferred-any.scala b/test/files/neg/warn-inferred-any.scala
new file mode 100644
index 0000000000..b853e6e5a8
--- /dev/null
+++ b/test/files/neg/warn-inferred-any.scala
@@ -0,0 +1,19 @@
+trait Foo[-A <: AnyRef, +B <: AnyRef] {
+ def run[U](x: A)(action: B => U): Boolean = ???
+
+ { run(_: A)(_: B => String) }
+}
+
+trait Xs[+A] {
+ { List(1, 2, 3) contains "a" } // only this warns
+ { List(1, 2, 3) contains 1 }
+ { identity(List(1, 2, 3) contains 1) }
+ { List("a") foreach println }
+}
+
+trait Ys[+A] {
+ { 1 to 5 contains 5l }
+ { 1l to 5l contains 5 }
+ { 1l to 5l contains 5d }
+ { 1l to 5l contains 5l }
+}
diff --git a/test/files/neg/warn-unused-imports.check b/test/files/neg/warn-unused-imports.check
new file mode 100644
index 0000000000..e61ec267d3
--- /dev/null
+++ b/test/files/neg/warn-unused-imports.check
@@ -0,0 +1,44 @@
+warn-unused-imports.scala:7: warning: it is not recommended to define classes/objects inside of package objects.
+If possible, define class A in package p1 instead.
+ class A
+ ^
+warn-unused-imports.scala:13: warning: it is not recommended to define classes/objects inside of package objects.
+If possible, define class A in package p2 instead.
+ class A
+ ^
+warn-unused-imports.scala:99: warning: local trait Warn is never used
+ trait Warn { // warn about unused local trait for good measure
+ ^
+warn-unused-imports.scala:57: warning: Unused import
+ import p1.A // warn
+ ^
+warn-unused-imports.scala:62: warning: Unused import
+ import p1.{ A, B } // warn on A
+ ^
+warn-unused-imports.scala:67: warning: Unused import
+ import p1.{ A, B } // warn on both
+ ^
+warn-unused-imports.scala:67: warning: Unused import
+ import p1.{ A, B } // warn on both
+ ^
+warn-unused-imports.scala:73: warning: Unused import
+ import c._ // warn
+ ^
+warn-unused-imports.scala:78: warning: Unused import
+ import p1._ // warn
+ ^
+warn-unused-imports.scala:85: warning: Unused import
+ import c._ // warn
+ ^
+warn-unused-imports.scala:91: warning: Unused import
+ import p1.c._ // warn
+ ^
+warn-unused-imports.scala:98: warning: Unused import
+ import p1._ // warn
+ ^
+warn-unused-imports.scala:118: warning: Unused import
+ import p1.A // warn
+ ^
+error: No warnings can be incurred under -Xfatal-warnings.
+13 warnings found
+one error found
diff --git a/test/files/neg/warn-unused-imports.flags b/test/files/neg/warn-unused-imports.flags
new file mode 100644
index 0000000000..954eaba352
--- /dev/null
+++ b/test/files/neg/warn-unused-imports.flags
@@ -0,0 +1 @@
+-Xfatal-warnings -Xlint
diff --git a/test/files/neg/warn-unused-imports.scala b/test/files/neg/warn-unused-imports.scala
new file mode 100644
index 0000000000..b7a2f1c414
--- /dev/null
+++ b/test/files/neg/warn-unused-imports.scala
@@ -0,0 +1,125 @@
+class Bippo {
+ def length: Int = 123
+ class Tree
+}
+
+package object p1 {
+ class A
+ implicit class B(val s: String) { def bippy = s }
+ val c: Bippo = new Bippo
+ type D = String
+}
+package object p2 {
+ class A
+ implicit class B(val s: String) { def bippy = s }
+ val c: Bippo = new Bippo
+ type D = Int
+}
+
+trait NoWarn {
+ {
+ import p1._ // no warn
+ println("abc".bippy)
+ }
+
+ {
+ import p1._ // no warn
+ println(new A)
+ }
+
+ {
+ import p1.B // no warn
+ println("abc".bippy)
+ }
+
+ {
+ import p1._ // no warn
+ import c._ // no warn
+ println(length)
+ }
+
+ {
+ import p1._ // no warn
+ import c._ // no warn
+ val x: Tree = null
+ println(x)
+ }
+
+ {
+ import p1.D // no warn
+ val x: D = null
+ println(x)
+ }
+}
+
+trait Warn {
+ {
+ import p1.A // warn
+ println(123)
+ }
+
+ {
+ import p1.{ A, B } // warn on A
+ println("abc".bippy)
+ }
+
+ {
+ import p1.{ A, B } // warn on both
+ println(123)
+ }
+
+ {
+ import p1._ // no warn (technically this could warn, but not worth the effort to unroll unusedness transitively)
+ import c._ // warn
+ println(123)
+ }
+
+ {
+ import p1._ // warn
+ println(123)
+ }
+
+ {
+ class Tree
+ import p1._ // no warn
+ import c._ // warn
+ val x: Tree = null
+ println(x)
+ }
+
+ {
+ import p1.c._ // warn
+ println(123)
+ }
+}
+
+trait Nested {
+ {
+ import p1._ // warn
+ trait Warn { // warn about unused local trait for good measure
+ import p2._
+ println(new A)
+ println("abc".bippy)
+ }
+ println("")
+ }
+
+ {
+ import p1._ // no warn
+ trait NoWarn {
+ import p2.B // no warn
+ println("abc".bippy)
+ println(new A)
+ }
+ println(new NoWarn { })
+ }
+
+ {
+ import p1.A // warn
+ trait Warn {
+ import p2.A
+ println(new A)
+ }
+ println(new Warn { })
+ }
+}
diff --git a/test/files/neg/warn-unused-privates.check b/test/files/neg/warn-unused-privates.check
new file mode 100644
index 0000000000..9c41a33e8f
--- /dev/null
+++ b/test/files/neg/warn-unused-privates.check
@@ -0,0 +1,63 @@
+warn-unused-privates.scala:2: warning: private constructor in class Bippy is never used
+ private def this(c: Int) = this(c, c) // warn
+ ^
+warn-unused-privates.scala:4: warning: private method in class Bippy is never used
+ private def boop(x: Int) = x+a+b // warn
+ ^
+warn-unused-privates.scala:6: warning: private val in class Bippy is never used
+ final private val MILLIS2: Int = 1000 // warn
+ ^
+warn-unused-privates.scala:13: warning: private val in object Bippy is never used
+ private val HEY_INSTANCE: Int = 1000 // warn
+ ^
+warn-unused-privates.scala:35: warning: private val in class Boppy is never used
+ private val hummer = "def" // warn
+ ^
+warn-unused-privates.scala:42: warning: private var in trait Accessors is never used
+ private var v1: Int = 0 // warn
+ ^
+warn-unused-privates.scala:43: warning: private setter in trait Accessors is never used
+ private var v2: Int = 0 // warn, never set
+ ^
+warn-unused-privates.scala:44: warning: private var in trait Accessors is never used
+ private var v3: Int = 0 // warn, never got
+ ^
+warn-unused-privates.scala:56: warning: private default argument in trait DefaultArgs is never used
+ private def bippy(x1: Int, x2: Int = 10, x3: Int = 15): Int = x1 + x2 + x3
+ ^
+warn-unused-privates.scala:56: warning: private default argument in trait DefaultArgs is never used
+ private def bippy(x1: Int, x2: Int = 10, x3: Int = 15): Int = x1 + x2 + x3
+ ^
+warn-unused-privates.scala:67: warning: local var in method f0 is never used
+ var x = 1 // warn
+ ^
+warn-unused-privates.scala:74: warning: local val in method f1 is never used
+ val b = new Outer // warn
+ ^
+warn-unused-privates.scala:84: warning: private object in object Types is never used
+ private object Dongo { def f = this } // warn
+ ^
+warn-unused-privates.scala:94: warning: local object in method l1 is never used
+ object HiObject { def f = this } // warn
+ ^
+warn-unused-privates.scala:78: warning: local var x in method f2 is never set - it could be a val
+ var x = 100 // warn about it being a var
+ ^
+warn-unused-privates.scala:85: warning: private class Bar1 in object Types is never used
+ private class Bar1 // warn
+ ^
+warn-unused-privates.scala:87: warning: private type Alias1 in object Types is never used
+ private type Alias1 = String // warn
+ ^
+warn-unused-privates.scala:95: warning: local class Hi is never used
+ class Hi { // warn
+ ^
+warn-unused-privates.scala:99: warning: local class DingDongDoobie is never used
+ class DingDongDoobie // warn
+ ^
+warn-unused-privates.scala:102: warning: local type OtherThing is never used
+ type OtherThing = String // warn
+ ^
+error: No warnings can be incurred under -Xfatal-warnings.
+20 warnings found
+one error found
diff --git a/test/files/neg/warn-unused-privates.flags b/test/files/neg/warn-unused-privates.flags
new file mode 100644
index 0000000000..7949c2afa2
--- /dev/null
+++ b/test/files/neg/warn-unused-privates.flags
@@ -0,0 +1 @@
+-Xlint -Xfatal-warnings
diff --git a/test/files/neg/warn-unused-privates.scala b/test/files/neg/warn-unused-privates.scala
new file mode 100644
index 0000000000..cb6e946a34
--- /dev/null
+++ b/test/files/neg/warn-unused-privates.scala
@@ -0,0 +1,105 @@
+class Bippy(a: Int, b: Int) {
+ private def this(c: Int) = this(c, c) // warn
+ private def bippy(x: Int): Int = bippy(x) // TODO: could warn
+ private def boop(x: Int) = x+a+b // warn
+ final private val MILLIS1 = 2000 // no warn, might have been inlined
+ final private val MILLIS2: Int = 1000 // warn
+ final private val HI_COMPANION: Int = 500 // no warn, accessed from companion
+ def hi() = Bippy.HI_INSTANCE
+}
+object Bippy {
+ def hi(x: Bippy) = x.HI_COMPANION
+ private val HI_INSTANCE: Int = 500 // no warn, accessed from instance
+ private val HEY_INSTANCE: Int = 1000 // warn
+}
+
+class A(val msg: String)
+class B1(msg: String) extends A(msg)
+class B2(msg0: String) extends A(msg0)
+class B3(msg0: String) extends A("msg")
+
+/*** Early defs warnings disabled primarily due to SI-6595.
+ * The test case is here to assure we aren't issuing false positives;
+ * the ones labeled "warn" don't warn.
+ ***/
+class Boppy extends {
+ private val hmm: String = "abc" // no warn, used in early defs
+ private val hom: String = "def" // no warn, used in body
+ private final val him = "ghi" // no warn, might have been (was) inlined
+ final val him2 = "ghi" // no warn, same
+ final val himinline = him
+ private val hum: String = "jkl" // warn
+ final val ding = hmm.length
+} with Mutable {
+ val dinger = hom
+ private val hummer = "def" // warn
+
+ private final val bum = "ghi" // no warn, might have been (was) inlined
+ final val bum2 = "ghi" // no warn, same
+}
+
+trait Accessors {
+ private var v1: Int = 0 // warn
+ private var v2: Int = 0 // warn, never set
+ private var v3: Int = 0 // warn, never got
+ private var v4: Int = 0 // no warn
+
+ def bippy(): Int = {
+ v3 = 5
+ v4 = 6
+ v2 + v4
+ }
+}
+
+trait DefaultArgs {
+ // warn about default getters for x2 and x3
+ private def bippy(x1: Int, x2: Int = 10, x3: Int = 15): Int = x1 + x2 + x3
+
+ def boppy() = bippy(5, 100, 200)
+}
+
+class Outer {
+ class Inner
+}
+
+trait Locals {
+ def f0 = {
+ var x = 1 // warn
+ var y = 2
+ y = 3
+ y + y
+ }
+ def f1 = {
+ val a = new Outer // no warn
+ val b = new Outer // warn
+ new a.Inner
+ }
+ def f2 = {
+ var x = 100 // warn about it being a var
+ x
+ }
+}
+
+object Types {
+ private object Dongo { def f = this } // warn
+ private class Bar1 // warn
+ private class Bar2 // no warn
+ private type Alias1 = String // warn
+ private type Alias2 = String // no warn
+ def bippo = (new Bar2).toString
+
+ def f(x: Alias2) = x.length
+
+ def l1() = {
+ object HiObject { def f = this } // warn
+ class Hi { // warn
+ def f1: Hi = new Hi
+ def f2(x: Hi) = x
+ }
+ class DingDongDoobie // warn
+ class Bippy // no warn
+ type Something = Bippy // no warn
+ type OtherThing = String // warn
+ (new Bippy): Something
+ }
+}
diff --git a/test/files/pos/annotations.scala b/test/files/pos/annotations.scala
index 706a715bad..501e2a6bd3 100644
--- a/test/files/pos/annotations.scala
+++ b/test/files/pos/annotations.scala
@@ -2,7 +2,7 @@ class ann(i: Int) extends scala.annotation.Annotation
class cfann(x: String) extends annotation.ClassfileAnnotation
// annotations on abstract types
-abstract class C1[@serializable @cloneable +T, U, V[_]]
+abstract class C1[@cloneable +T, U, V[_]]
abstract class C2[@deprecated
@ann(1) T <: Number,
V]
diff --git a/test/files/pos/attributes.scala b/test/files/pos/attributes.scala
index ec735d0aae..60e00bff7d 100644
--- a/test/files/pos/attributes.scala
+++ b/test/files/pos/attributes.scala
@@ -1,3 +1,5 @@
+class serializable extends annotation.StaticAnnotation
+
@serializable class C1;
@serializable @volatile class C2;
@serializable @volatile class C3;
diff --git a/test/files/pos/chang/Test.scala b/test/files/pos/chang/Test.scala
index 9bb745e377..f74c6355b5 100644
--- a/test/files/pos/chang/Test.scala
+++ b/test/files/pos/chang/Test.scala
@@ -1,3 +1,3 @@
-object Test extends Application {
+object Test extends App {
new com.netgents.hello.Outer[String]
}
diff --git a/test/files/pos/cycle-jsoup.flags b/test/files/pos/cycle-jsoup.flags
new file mode 100644
index 0000000000..ca20f55172
--- /dev/null
+++ b/test/files/pos/cycle-jsoup.flags
@@ -0,0 +1 @@
+-Ybreak-cycles
diff --git a/test/files/pos/cycle-jsoup.scala b/test/files/pos/cycle-jsoup.scala
new file mode 100644
index 0000000000..879e693537
--- /dev/null
+++ b/test/files/pos/cycle-jsoup.scala
@@ -0,0 +1,5 @@
+object Test {
+ def main(args : Array[String]) {
+ org.jsoup.Jsoup.parse(null: java.net.URL, 3000)
+ }
+}
diff --git a/test/files/pos/cycle.flags b/test/files/pos/cycle.flags
new file mode 100644
index 0000000000..ca20f55172
--- /dev/null
+++ b/test/files/pos/cycle.flags
@@ -0,0 +1 @@
+-Ybreak-cycles
diff --git a/test/files/pos/cycle/J_1.java b/test/files/pos/cycle/J_1.java
new file mode 100644
index 0000000000..0cc218eebe
--- /dev/null
+++ b/test/files/pos/cycle/J_1.java
@@ -0,0 +1,16 @@
+package bar;
+
+public class J_1 {
+ public void f(C.D arg) {
+ }
+}
+
+class B extends J_1 {
+ public void g(C.D arg) {
+ }
+}
+
+class C extends B {
+ public class D {
+ }
+}
diff --git a/test/files/pos/cycle/X_2.scala b/test/files/pos/cycle/X_2.scala
new file mode 100644
index 0000000000..c1840f3b99
--- /dev/null
+++ b/test/files/pos/cycle/X_2.scala
@@ -0,0 +1,3 @@
+import bar.J_1._ //<--- illegal cyclic reference involving
+
+class X
diff --git a/test/pending/pos/exhaust_2.scala b/test/files/pos/exhaust_2.scala
index 4f4e47c43b..4f4e47c43b 100644
--- a/test/pending/pos/exhaust_2.scala
+++ b/test/files/pos/exhaust_2.scala
diff --git a/test/files/pos/liftcode_polymorphic.scala b/test/files/pos/liftcode_polymorphic.scala
index 8f537d278a..249f5a0569 100644
--- a/test/files/pos/liftcode_polymorphic.scala
+++ b/test/files/pos/liftcode_polymorphic.scala
@@ -1,6 +1,6 @@
import scala.reflect.runtime.universe._
-object Append extends Application {
+object Append extends App {
def append[A](l1: List[A], l2: List[A]):List[A] =
l1 match {
diff --git a/test/pending/pos/no-widen-locals.scala b/test/files/pos/no-widen-locals.scala
index 013e63f0a2..013e63f0a2 100644
--- a/test/pending/pos/no-widen-locals.scala
+++ b/test/files/pos/no-widen-locals.scala
diff --git a/test/files/pos/sealed-final.flags b/test/files/pos/sealed-final.flags
new file mode 100644
index 0000000000..cfabf7a5b4
--- /dev/null
+++ b/test/files/pos/sealed-final.flags
@@ -0,0 +1 @@
+-Xfatal-warnings -Yinline-warnings -optimise \ No newline at end of file
diff --git a/test/files/pos/sealed-final.scala b/test/files/pos/sealed-final.scala
new file mode 100644
index 0000000000..bdedb5c1f6
--- /dev/null
+++ b/test/files/pos/sealed-final.scala
@@ -0,0 +1,14 @@
+sealed abstract class Foo {
+ @inline def bar(x: Int) = x + 1
+}
+object Foo {
+ def mkFoo(): Foo = new Baz2
+}
+
+object Baz1 extends Foo
+final class Baz2 extends Foo
+
+object Test {
+ // bar should be inlined now
+ def f = Foo.mkFoo() bar 10
+}
diff --git a/test/files/pos/spec-annotations.scala b/test/files/pos/spec-annotations.scala
index 48281e5df5..6c1f737470 100644
--- a/test/files/pos/spec-annotations.scala
+++ b/test/files/pos/spec-annotations.scala
@@ -1,7 +1,7 @@
class ann(i: Int) extends scala.annotation.Annotation
// annotations on abstract types
-abstract class C1[@serializable @cloneable +T, U, V[_]]
+abstract class C1[@cloneable +T, U, V[_]]
abstract class C2[@deprecated
@ann(1) T <: Number,
V]
diff --git a/test/files/pos/super.cmds b/test/files/pos/super.cmds
deleted file mode 100644
index 8f3f8a4172..0000000000
--- a/test/files/pos/super.cmds
+++ /dev/null
@@ -1,2 +0,0 @@
-javac Super_1.java
-scalac Super_2.scala
diff --git a/test/files/pos/t0851.scala b/test/files/pos/t0851.scala
new file mode 100644
index 0000000000..fc7109dcd4
--- /dev/null
+++ b/test/files/pos/t0851.scala
@@ -0,0 +1,14 @@
+package test
+
+object test1 {
+ case class Foo[T,T2](f : (T,T2) => String) extends (((T,T2)) => String){
+ def apply(t : T) = (s:T2) => f(t,s)
+ def apply(p : (T,T2)) = f(p._1,p._2)
+ }
+ implicit def g[T](f : (T,String) => String) = Foo(f)
+ def main(args : Array[String]) : Unit = {
+ val f = (x:Int,s:String) => s + x
+ println(f(1))
+ ()
+ }
+}
diff --git a/test/files/pos/t0872.scala b/test/files/pos/t0872.scala
new file mode 100644
index 0000000000..8f4c1c4436
--- /dev/null
+++ b/test/files/pos/t0872.scala
@@ -0,0 +1,8 @@
+object Main {
+ def main(args : Array[String]) {
+ val fn = (a : Int, str : String) => "a: " + a + ", str: " + str
+ implicit def fx[T](f : (T,String) => String) = (x:T) => f(x,null)
+ println(fn(1))
+ ()
+ }
+}
diff --git a/test/files/pos/t1029.cmds b/test/files/pos/t1029.cmds
deleted file mode 100644
index 06b863dc03..0000000000
--- a/test/files/pos/t1029.cmds
+++ /dev/null
@@ -1,2 +0,0 @@
-scalac Test_1.scala
-scalac Test_2.scala
diff --git a/test/files/pos/t1107.scala b/test/files/pos/t1107a.scala
index 0bf40bb4cc..0bf40bb4cc 100644
--- a/test/files/pos/t1107.scala
+++ b/test/files/pos/t1107a.scala
diff --git a/test/files/pos/t1203.scala b/test/files/pos/t1203a.scala
index 062ef93fc6..062ef93fc6 100644
--- a/test/files/pos/t1203.scala
+++ b/test/files/pos/t1203a.scala
diff --git a/test/files/pos/t1230/S.scala b/test/files/pos/t1230/S.scala
index f8a691b6de..530dd4b853 100644
--- a/test/files/pos/t1230/S.scala
+++ b/test/files/pos/t1230/S.scala
@@ -1 +1 @@
-object S extends Application { (new J).foo = 5 }
+object S extends App { (new J).foo = 5 }
diff --git a/test/files/pos/t1231/S.scala b/test/files/pos/t1231/S.scala
index ee08866e04..f14aa2561b 100644
--- a/test/files/pos/t1231/S.scala
+++ b/test/files/pos/t1231/S.scala
@@ -1 +1 @@
-object S extends Application { println(J.j1) }
+object S extends App { println(J.j1) }
diff --git a/test/files/pos/t1385.scala b/test/files/pos/t1385.scala
index 59953bcc39..6fe7308281 100644
--- a/test/files/pos/t1385.scala
+++ b/test/files/pos/t1385.scala
@@ -1,3 +1,3 @@
-@serializable object Test {
- private def readResolve:AnyRef = this
+object Test extends Serializable {
+ private def readResolve: AnyRef = this
}
diff --git a/test/pending/pos/t1751/A1_2.scala b/test/files/pos/t1751/A1_2.scala
index 354d5eecd0..354d5eecd0 100644
--- a/test/pending/pos/t1751/A1_2.scala
+++ b/test/files/pos/t1751/A1_2.scala
diff --git a/test/pending/pos/t1751/A2_1.scala b/test/files/pos/t1751/A2_1.scala
index c768062e43..c768062e43 100644
--- a/test/pending/pos/t1751/A2_1.scala
+++ b/test/files/pos/t1751/A2_1.scala
diff --git a/test/pending/pos/t1751/SuiteClasses.java b/test/files/pos/t1751/SuiteClasses.java
index a415e4f572..a415e4f572 100644
--- a/test/pending/pos/t1751/SuiteClasses.java
+++ b/test/files/pos/t1751/SuiteClasses.java
diff --git a/test/pending/pos/t1782/Ann.java b/test/files/pos/t1782/Ann.java
index 0dcfbd2ed7..0dcfbd2ed7 100644
--- a/test/pending/pos/t1782/Ann.java
+++ b/test/files/pos/t1782/Ann.java
diff --git a/test/pending/pos/t1782/Days.java b/test/files/pos/t1782/Days.java
index 203a87b1c2..203a87b1c2 100644
--- a/test/pending/pos/t1782/Days.java
+++ b/test/files/pos/t1782/Days.java
diff --git a/test/pending/pos/t1782/ImplementedBy.java b/test/files/pos/t1782/ImplementedBy.java
index 6aa8b4fa9e..6aa8b4fa9e 100644
--- a/test/pending/pos/t1782/ImplementedBy.java
+++ b/test/files/pos/t1782/ImplementedBy.java
diff --git a/test/pending/pos/t1782/Test_1.scala b/test/files/pos/t1782/Test_1.scala
index 6467a74c29..6467a74c29 100644
--- a/test/pending/pos/t1782/Test_1.scala
+++ b/test/files/pos/t1782/Test_1.scala
diff --git a/test/files/pos/t1942.cmds b/test/files/pos/t1942.cmds
deleted file mode 100644
index c14311042a..0000000000
--- a/test/files/pos/t1942.cmds
+++ /dev/null
@@ -1,2 +0,0 @@
-scalac A_1.scala
-scalac Test_2.scala
diff --git a/test/files/pos/t2464.cmds b/test/files/pos/t2464.cmds
deleted file mode 100644
index ca733ef23d..0000000000
--- a/test/files/pos/t2464.cmds
+++ /dev/null
@@ -1,3 +0,0 @@
-javac JavaOne.java
-scalac ScalaOne_1.scala
-scalac t2464_2.scala
diff --git a/test/files/pos/t2726.cmds b/test/files/pos/t2726.cmds
deleted file mode 100644
index 5fcb18bfbb..0000000000
--- a/test/files/pos/t2726.cmds
+++ /dev/null
@@ -1,2 +0,0 @@
-scalac SQLBuilder_1.scala
-scalac test_2.scala
diff --git a/test/pending/pos/t294/Ann.java b/test/files/pos/t294/Ann.java
index 934ca46297..934ca46297 100644
--- a/test/pending/pos/t294/Ann.java
+++ b/test/files/pos/t294/Ann.java
diff --git a/test/pending/pos/t294/Ann2.java b/test/files/pos/t294/Ann2.java
index 025b79e794..025b79e794 100644
--- a/test/pending/pos/t294/Ann2.java
+++ b/test/files/pos/t294/Ann2.java
diff --git a/test/pending/pos/t294/Test_1.scala b/test/files/pos/t294/Test_1.scala
index ff1f34b10e..ff1f34b10e 100644
--- a/test/pending/pos/t294/Test_1.scala
+++ b/test/files/pos/t294/Test_1.scala
diff --git a/test/pending/pos/t294/Test_2.scala b/test/files/pos/t294/Test_2.scala
index 9fb1c6e175..9fb1c6e175 100644
--- a/test/pending/pos/t294/Test_2.scala
+++ b/test/files/pos/t294/Test_2.scala
diff --git a/test/files/pos/t3160.scala b/test/files/pos/t3160.scala
new file mode 100644
index 0000000000..3309ece160
--- /dev/null
+++ b/test/files/pos/t3160.scala
@@ -0,0 +1,6 @@
+import scala.collection.mutable._
+import scala.xml._
+
+class A {
+ def f(x: Node): Node = ???
+}
diff --git a/test/files/pos/t3577.scala b/test/files/pos/t3577.scala
new file mode 100644
index 0000000000..80a280f67a
--- /dev/null
+++ b/test/files/pos/t3577.scala
@@ -0,0 +1,29 @@
+case class Check[A](val value: A)
+
+case class C2(checks: Check[_]*);
+
+object C {
+ def m(x : C2): Any = (null: Any) match {
+ case C2(_, rest @ _*) => {
+ rest.map(_.value)
+ }
+ }
+}
+
+///////////////////
+
+object Container {
+ trait Exp[+T]
+ abstract class FuncExp[-S, +T]
+
+ sealed abstract class FoundNode[T, Repr] {
+ def optimize[TupleT, U, That](parentNode: FlatMap[T, Repr, U, That]): Any
+ def optimize2[TupleT, U, That](parentNode: Any): Any
+ }
+
+ class FlatMap[T, Repr, U, That]
+
+ val Seq(fn: FoundNode[t, repr]) = Seq[FoundNode[_, _]]()
+ fn.optimize(null) // was: scala.MatchError: ? (of class BoundedWildcardType) @ Variances#varianceInType
+ fn.optimize2(null) // was: fatal error: bad type: ?(class scala.reflect.internal.Types$BoundedWildcardType) @ Pickle.putType
+}
diff --git a/test/files/pos/t4649.flags b/test/files/pos/t4649.flags
new file mode 100644
index 0000000000..e8fb65d50c
--- /dev/null
+++ b/test/files/pos/t4649.flags
@@ -0,0 +1 @@
+-Xfatal-warnings \ No newline at end of file
diff --git a/test/pending/pos/t4649.scala b/test/files/pos/t4649.scala
index 0d6caa8d7a..0d6caa8d7a 100644
--- a/test/pending/pos/t4649.scala
+++ b/test/files/pos/t4649.scala
diff --git a/test/files/pos/t4744.flags b/test/files/pos/t4744.flags
new file mode 100644
index 0000000000..ca20f55172
--- /dev/null
+++ b/test/files/pos/t4744.flags
@@ -0,0 +1 @@
+-Ybreak-cycles
diff --git a/test/files/pos/t4744/Bar.scala b/test/files/pos/t4744/Bar.scala
new file mode 100644
index 0000000000..1fb6d78973
--- /dev/null
+++ b/test/files/pos/t4744/Bar.scala
@@ -0,0 +1 @@
+class Bar { val quux = new Foo[java.lang.Integer]() }
diff --git a/test/files/pos/t4744/Foo.java b/test/files/pos/t4744/Foo.java
new file mode 100644
index 0000000000..6c764d0470
--- /dev/null
+++ b/test/files/pos/t4744/Foo.java
@@ -0,0 +1 @@
+public class Foo<T extends Comparable<? super T>> {}
diff --git a/test/pending/pos/t4786.scala b/test/files/pos/t4786.scala
index f0579142b8..f0579142b8 100644
--- a/test/pending/pos/t4786.scala
+++ b/test/files/pos/t4786.scala
diff --git a/test/files/pos/t5130.scala b/test/files/pos/t5130.scala
new file mode 100644
index 0000000000..676d3c7050
--- /dev/null
+++ b/test/files/pos/t5130.scala
@@ -0,0 +1,46 @@
+import scala.language.reflectiveCalls
+
+class A {
+ this_a =>
+
+ def b = new B
+ class B { def a: this_a.type = this_a }
+}
+trait A2 { def c = () }
+
+object Test {
+ val v1 = new A { def c = () }
+ val v2 = new A with A2 { }
+ val v3: A { def c: Unit } = null
+ def d1 = new A { def c = () }
+ def d2 = new A with A2 { }
+ def d3: A { def c: Unit } = null
+ var x1 = new A { def c = () }
+ var x2 = new A with A2 { }
+ var x3: A { def c: Unit } = null
+
+ def main(args: Array[String]): Unit = {
+ val mv1 = new A { def c = () }
+ val mv2 = new A with A2 { }
+ val mv3: A { def c: Unit } = null
+ def md1 = new A { def c = () }
+ def md2 = new A with A2 { }
+ def md3: A { def c: Unit } = null
+
+ v1.b.a.c
+ v2.b.a.c
+ v3.b.a.c
+ d1.b.a.c
+ d2.b.a.c
+ d3.b.a.c
+ x1.b.a.c
+ x2.b.a.c
+ x3.b.a.c
+ mv1.b.a.c
+ mv2.b.a.c
+ mv3.b.a.c
+ md1.b.a.c
+ md2.b.a.c
+ md3.b.a.c
+ }
+}
diff --git a/test/pending/pos/t5399a.scala b/test/files/pos/t5399a.scala
index 4ebd85ad03..4ebd85ad03 100644
--- a/test/pending/pos/t5399a.scala
+++ b/test/files/pos/t5399a.scala
diff --git a/test/files/pos/t5604b/T_1.scala b/test/files/pos/t5604b/T_1.scala
new file mode 100644
index 0000000000..179dcb10c6
--- /dev/null
+++ b/test/files/pos/t5604b/T_1.scala
@@ -0,0 +1,6 @@
+// sandbox/t5604/T.scala
+package t6504
+
+trait T {
+ def foo: Boolean = false
+}
diff --git a/test/files/pos/t5604b/T_2.scala b/test/files/pos/t5604b/T_2.scala
new file mode 100644
index 0000000000..179dcb10c6
--- /dev/null
+++ b/test/files/pos/t5604b/T_2.scala
@@ -0,0 +1,6 @@
+// sandbox/t5604/T.scala
+package t6504
+
+trait T {
+ def foo: Boolean = false
+}
diff --git a/test/files/pos/t5604b/Test_1.scala b/test/files/pos/t5604b/Test_1.scala
new file mode 100644
index 0000000000..f7c58ebe83
--- /dev/null
+++ b/test/files/pos/t5604b/Test_1.scala
@@ -0,0 +1,7 @@
+// sandbox/t5604/Test.scala
+package t6504
+
+object Test {
+ def blerg1(a: Any): Any = if (foo) blerg1(0)
+ def blerg2(a: Any): Any = if (t6504.foo) blerg2(0)
+}
diff --git a/test/files/pos/t5604b/Test_2.scala b/test/files/pos/t5604b/Test_2.scala
new file mode 100644
index 0000000000..f7c58ebe83
--- /dev/null
+++ b/test/files/pos/t5604b/Test_2.scala
@@ -0,0 +1,7 @@
+// sandbox/t5604/Test.scala
+package t6504
+
+object Test {
+ def blerg1(a: Any): Any = if (foo) blerg1(0)
+ def blerg2(a: Any): Any = if (t6504.foo) blerg2(0)
+}
diff --git a/test/files/pos/t5604b/pack_1.scala b/test/files/pos/t5604b/pack_1.scala
new file mode 100644
index 0000000000..f50d568bfa
--- /dev/null
+++ b/test/files/pos/t5604b/pack_1.scala
@@ -0,0 +1,5 @@
+// sandbox/t5604/pack.scala
+package t6504
+
+object `package` extends T {
+}
diff --git a/test/pending/pos/t5606.scala b/test/files/pos/t5606.scala
index 2545271e32..2545271e32 100644
--- a/test/pending/pos/t5606.scala
+++ b/test/files/pos/t5606.scala
diff --git a/test/pending/pos/t5639/Bar.scala b/test/files/pos/t5639/Bar.scala
index f577500acd..f577500acd 100644
--- a/test/pending/pos/t5639/Bar.scala
+++ b/test/files/pos/t5639/Bar.scala
diff --git a/test/pending/pos/t5639/Foo.scala b/test/files/pos/t5639/Foo.scala
index 6602150661..6602150661 100644
--- a/test/pending/pos/t5639/Foo.scala
+++ b/test/files/pos/t5639/Foo.scala
diff --git a/test/files/pos/t5809.scala b/test/files/pos/t5809.scala
index 133e13c4ed..4bcd743faa 100644
--- a/test/files/pos/t5809.scala
+++ b/test/files/pos/t5809.scala
@@ -1,5 +1,6 @@
package object foo {
implicit class PimpedInt(foo: Int) {
def bar = ???
+ def bippy = foo
}
-} \ No newline at end of file
+}
diff --git a/test/files/pos/t5858.scala b/test/files/pos/t5858.scala
new file mode 100644
index 0000000000..f2b0f58d76
--- /dev/null
+++ b/test/files/pos/t5858.scala
@@ -0,0 +1,3 @@
+object Test {
+ new xml.Elem(null, null, xml.Null, xml.TopScope, Nil: _*) // was ambiguous
+}
diff --git a/test/files/pos/t5859.scala b/test/files/pos/t5859.scala
new file mode 100644
index 0000000000..2a31e68ee5
--- /dev/null
+++ b/test/files/pos/t5859.scala
@@ -0,0 +1,15 @@
+
+class A {
+ def f(xs: List[Int], ys: AnyRef*) = ()
+ def f(xs: AnyRef*) = ()
+
+ f()
+ f(List[AnyRef](): _*)
+ f(List(): _*)
+ f(Nil: _*)
+ f(Array(): _*)
+ f(Array[AnyRef](): _*)
+ f(List(1))
+ f(List(1), Nil: _*)
+ f(List(1), Array(): _*)
+}
diff --git a/test/files/pos/t6072.scala b/test/files/pos/t6072.scala
new file mode 100644
index 0000000000..e25ebbffc5
--- /dev/null
+++ b/test/files/pos/t6072.scala
@@ -0,0 +1,3 @@
+class A {
+ object B { def eq(lvl: Int) = ??? }
+}
diff --git a/test/files/pos/t6301.scala b/test/files/pos/t6301.scala
new file mode 100644
index 0000000000..fa81bbfa77
--- /dev/null
+++ b/test/files/pos/t6301.scala
@@ -0,0 +1,9 @@
+trait LoadedOver[@specialized(Int) A] {
+ def foo(x: Any): A
+ def foo(xs: String): A
+}
+
+object Test {
+ def loaded: AnyRef with LoadedOver[Int] = sys.error("")
+ loaded.foo("")
+}
diff --git a/test/files/pos/t640.scala b/test/files/pos/t640.scala
index 55f61df8af..45608bc3d4 100644
--- a/test/files/pos/t640.scala
+++ b/test/files/pos/t640.scala
@@ -1,2 +1,2 @@
-@serializable class A
-@serializable class B extends A
+class A extends Serializable
+class B extends A with Serializable
diff --git a/test/files/pos/t6447.scala b/test/files/pos/t6447.scala
new file mode 100644
index 0000000000..1c0c0f2a31
--- /dev/null
+++ b/test/files/pos/t6447.scala
@@ -0,0 +1,18 @@
+import scala.language.experimental.macros
+import scala.reflect.macros.Context
+
+class X { type T }
+
+object X {
+ // this works
+ def foo(x: X): x.T = macro fooImpl
+ def fooImpl(c: Context)(x: c.Expr[X]): c.Expr[x.value.T] = ???
+
+ // this doesn't
+ def bar(x: X, y: X): (x.T, y.T) = macro barImpl
+ def barImpl(c: Context)(x: c.Expr[X], y: c.Expr[X]): c.Expr[(x.value.T, y.value.T)] = ???
+
+ // neither does this
+ def baz(x: X)(xs: List[x.T]): Unit = macro bazImpl
+ def bazImpl(c: Context)(x: c.Expr[X])(xs: c.Expr[List[x.value.T]]): c.Expr[Unit] = ???
+}
diff --git a/test/files/pos/t6482.scala b/test/files/pos/t6482.scala
new file mode 100644
index 0000000000..24ea38e519
--- /dev/null
+++ b/test/files/pos/t6482.scala
@@ -0,0 +1,11 @@
+final class TraversableOnceOps[+A](val collection: TraversableOnce[A]) extends AnyVal {
+ def reduceLeftOption[B >: A](op: (B, A) => B): Option[B] =
+ if (collection.isEmpty) None else Some(collection.reduceLeft[B](op))
+}
+// error: type arguments [B] do not conform to method reduceLeft's type parameter bounds [B >: A]
+// if (collection.isEmpty) None else Some(collection.reduceLeft[B](op))
+// ^
+
+class Foo[+A <: AnyRef](val xs: List[A]) extends AnyVal {
+ def baz[B >: A](x: B): List[B] = x :: xs
+}
diff --git a/test/files/pos/t6595.flags b/test/files/pos/t6595.flags
new file mode 100644
index 0000000000..85d8eb2ba2
--- /dev/null
+++ b/test/files/pos/t6595.flags
@@ -0,0 +1 @@
+-Xfatal-warnings
diff --git a/test/files/pos/t6595.scala b/test/files/pos/t6595.scala
new file mode 100644
index 0000000000..437c0bcf05
--- /dev/null
+++ b/test/files/pos/t6595.scala
@@ -0,0 +1,18 @@
+import scala.annotation.switch
+
+class Foo extends {
+ final val b0 = 5
+} with AnyRef {
+ final val b1 = 10
+
+ // Using the @switch annotation as a means of testing that the
+ // type inferred for b0 is Int(5) and not Int. Only in the former
+ // case can a switch be generated.
+ def f(p: Int) = (p: @switch) match {
+ case `b0` => 1
+ case `b1` => 2
+ case 15 => 3
+ case 20 => 4
+ case _ => 5
+ }
+}
diff --git a/test/files/pos/t6664.scala b/test/files/pos/t6664.scala
new file mode 100644
index 0000000000..7eb85f619d
--- /dev/null
+++ b/test/files/pos/t6664.scala
@@ -0,0 +1,4 @@
+final case class A(i: Int, s: String) {
+ protected def copy(s2: String): A = A(i, s2)
+ protected def copy(i2: Int): A = A(i2, s)
+}
diff --git a/test/files/pos/t6664b.scala b/test/files/pos/t6664b.scala
new file mode 100644
index 0000000000..a622866838
--- /dev/null
+++ b/test/files/pos/t6664b.scala
@@ -0,0 +1,5 @@
+object T {
+ def A(s: String): A = new A(3, s)
+ def A(i: Int): A = A(i, "abc")
+ case class A(i: Int, s: String)
+}
diff --git a/test/files/pos/t715.cmds b/test/files/pos/t715.cmds
deleted file mode 100644
index 2836967fca..0000000000
--- a/test/files/pos/t715.cmds
+++ /dev/null
@@ -1,2 +0,0 @@
-scalac meredith_1.scala
-scalac runner_2.scala
diff --git a/test/files/pos/t715/meredith_1.scala b/test/files/pos/t715/meredith_1.scala
index 8261b9881a..c28afb4a9b 100644
--- a/test/files/pos/t715/meredith_1.scala
+++ b/test/files/pos/t715/meredith_1.scala
@@ -3,7 +3,7 @@ package com.sap.dspace.model.othello;
import scala.xml._
trait XMLRenderer {
- type T <: Any {def getClass() : java.lang.Class[_]}
+ type T <: Any {def getClass(): java.lang.Class[_]}
val valueTypes =
List(
classOf[java.lang.Boolean],
@@ -14,21 +14,21 @@ trait XMLRenderer {
)
def value2XML(
- value : Object,
- field : java.lang.reflect.Field,
- pojo : T
- ) : Node = {
+ value: Object,
+ field: java.lang.reflect.Field,
+ pojo: T
+ ): Node = {
value match {
- case null => Text( "null" )
+ case null => Text("null")
case vUnmatched =>
if (value.isInstanceOf[java.lang.Boolean])
- Text( value.asInstanceOf[java.lang.Boolean].toString )
+ Text(value.asInstanceOf[java.lang.Boolean].toString)
else if (value.isInstanceOf[java.lang.Integer])
- Text( value.asInstanceOf[java.lang.Integer].toString )
+ Text(value.asInstanceOf[java.lang.Integer].toString)
else if (value.isInstanceOf[java.lang.Float])
- Text( value.asInstanceOf[java.lang.Float].toString )
+ Text(value.asInstanceOf[java.lang.Float].toString)
// else if (value.isInstanceOf[T])
- // pojo2XML( value.asInstanceOf[T] )
+ // pojo2XML(value.asInstanceOf[T])
else
<unmatchedType>
<theType>
@@ -42,16 +42,16 @@ trait XMLRenderer {
}
def field2XML(
- field : java.lang.reflect.Field,
- pojo : T
- ) : Elem = {
+ field: java.lang.reflect.Field,
+ pojo: T
+ ): Elem = {
- val accessible = field.isAccessible;
- field.setAccessible( true );
+ val accessible = field.isAccessible
+ field.setAccessible(true)
// BUGBUG lgm need to disambiguate on type and possibly make
// recursive call to pojo2XML
- val fldValXML = value2XML( field.get( pojo ), field, pojo );
- field.setAccessible( accessible );
+ val fldValXML = value2XML(field.get( pojo ), field, pojo)
+ field.setAccessible( accessible )
Elem(
null,
@@ -62,37 +62,37 @@ trait XMLRenderer {
)
}
- def pojo2XML( pojo : T ) : Elem = {
+ def pojo2XML(pojo: T): Elem = {
val progeny =
for (field <- pojo.getClass.getDeclaredFields)
- yield field2XML( field, pojo );
+ yield field2XML(field, pojo)
Elem(
null,
pojo.getClass.getName,
null,
TopScope,
- progeny.asInstanceOf[Array[scala.xml.Node]] : _*
+ progeny.asInstanceOf[Array[scala.xml.Node]]: _*
)
}
}
-case class POJO2XMLRenderer( recurse : Boolean )
+case class POJO2XMLRenderer(recurse: Boolean)
extends XMLRenderer {
type T = java.io.Serializable
override def value2XML(
- value : Object,
- field : java.lang.reflect.Field,
- pojo : java.io.Serializable
- ) : Node = {
- if (recurse) super.value2XML( value, field, pojo )
- else Text( value + "" )
+ value: Object,
+ field: java.lang.reflect.Field,
+ pojo: java.io.Serializable
+ ): Node = {
+ if (recurse) super.value2XML(value, field, pojo)
+ else Text(value + "")
}
}
-object thePOJO2XMLRenderer extends POJO2XMLRenderer( true ) {
+object thePOJO2XMLRenderer extends POJO2XMLRenderer(true) {
}
-object Test extends Application {
+object Test extends App {
println(com.sap.dspace.model.othello.thePOJO2XMLRenderer)
}
diff --git a/test/files/pos/t715/runner_2.scala b/test/files/pos/t715/runner_2.scala
index 1e4f40d654..d54805629a 100644
--- a/test/files/pos/t715/runner_2.scala
+++ b/test/files/pos/t715/runner_2.scala
@@ -1,3 +1,3 @@
-object Test extends Application {
+object Test extends App {
println(com.sap.dspace.model.othello.thePOJO2XMLRenderer)
}
diff --git a/test/files/pos/ticket2251.scala b/test/files/pos/ticket2251.scala
index b3afee4ea9..c220e85350 100644
--- a/test/files/pos/ticket2251.scala
+++ b/test/files/pos/ticket2251.scala
@@ -22,4 +22,18 @@ lub of List(D, C) is B[_2] forSome { type _2 >: D with C{} <: B[_1] forSome { ty
// should be: B[X] forSome {type X <: B[X]} -- can this be done automatically? for now, just detect f-bounded polymorphism and fall back to more coarse approximation
val data: List[A] = List(new C, new D)
+
+ val data2 = List(new C, new D)
+
+ val data3: List[B[X] forSome { type X <: B[_ <: A] }] = List(new C, new D)
+
+ // Not yet --
+ // val data4: List[B[X] forSome { type X <: B[X] }] = List(new C, new D)
+ // <console>:7: error: type mismatch;
+ // found : List[B[_ >: D with C <: B[_ >: D with C <: A]]]
+ // required: List[B[X] forSome { type X <: B[X] }]
+ // val data4: List[B[X] forSome { type X <: B[X] }] = List(new C, new D)
+
+ // works
+ val data5 = List[B[X] forSome { type X <: B[X] }](new C, new D)
}
diff --git a/test/files/presentation/ide-bug-1000531.check b/test/files/presentation/ide-bug-1000531.check
index 4be98a6b21..6c3892d272 100644
--- a/test/files/presentation/ide-bug-1000531.check
+++ b/test/files/presentation/ide-bug-1000531.check
@@ -19,7 +19,7 @@ retrieved 126 members
[accessible: true] `method addString(b: StringBuilder)StringBuilder`
[accessible: true] `method addString(b: StringBuilder, sep: String)StringBuilder`
[accessible: true] `method addString(b: StringBuilder, start: String, sep: String, end: String)StringBuilder`
-[accessible: true] `method aggregate[B](z: B)(seqop: (B, B) => B, combop: (B, B) => B)B`
+[accessible: true] `method aggregate[B](z: => B)(seqop: (B, B) => B, combop: (B, B) => B)B`
[accessible: true] `method asInstanceOf[T0]=> T0`
[accessible: true] `method buffered=> scala.collection.BufferedIterator[B]`
[accessible: true] `method collectFirst[B](pf: PartialFunction[B,B])Option[B]`
diff --git a/test/files/run/collection-stacks.check b/test/files/run/collection-stacks.check
new file mode 100644
index 0000000000..aa25cd1fa6
--- /dev/null
+++ b/test/files/run/collection-stacks.check
@@ -0,0 +1,14 @@
+3-2-1: true
+3-2-1: true
+apply
+3: true
+3: true
+1: true
+1: true
+top
+3: true
+3: true
+pop
+2-1: true
+3: true
+2-1: true
diff --git a/test/files/run/collection-stacks.scala b/test/files/run/collection-stacks.scala
new file mode 100644
index 0000000000..be9fbbf1ae
--- /dev/null
+++ b/test/files/run/collection-stacks.scala
@@ -0,0 +1,38 @@
+import scala.collection.{ immutable, mutable }
+
+object Test extends App {
+ def mutableStack[T](xs: T*): mutable.Stack[T] = {
+ val s = new mutable.Stack[T]
+ s.pushAll(xs)
+ s
+ }
+
+ def immutableStack[T](xs: T*): immutable.Stack[T] = {
+ immutable.Stack.empty[T] pushAll xs
+ }
+
+ def check[T](expected: T, got: T) {
+ println(got + ": " + (expected == got))
+ }
+
+ // check #957
+ check("3-2-1", immutableStack(1, 2, 3).iterator.mkString("-"))
+ check("3-2-1", mutableStack(1, 2, 3).iterator.mkString("-"))
+
+ println("apply")
+ check(3, immutableStack(1, 2, 3).apply(0))
+ check(3, mutableStack(1, 2, 3).apply(0))
+ check(1, immutableStack(1, 2, 3).apply(2))
+ check(1, mutableStack(1, 2, 3).apply(2))
+
+ println("top")
+ check(3, immutableStack(1, 2, 3).top)
+ check(3, mutableStack(1, 2, 3).top)
+
+ println("pop")
+ check("2-1", immutableStack(1, 2, 3).pop.mkString("-"))
+ check(3, mutableStack(1, 2, 3).pop())
+ check("2-1", { val s = mutableStack(1, 2, 3); s.pop(); s.toList.mkString("-") })
+}
+
+// vim: set ts=2 sw=2 et:
diff --git a/test/files/run/compiler-asSeenFrom.scala b/test/files/run/compiler-asSeenFrom.scala
index 19feb45101..0d4b504d3c 100644
--- a/test/files/run/compiler-asSeenFrom.scala
+++ b/test/files/run/compiler-asSeenFrom.scala
@@ -47,10 +47,10 @@ package ll {
for (p <- typeRefPrefixes ; c <- classes filter (isPossibleEnclosure(p.typeSymbol, _)) ; a <- targs) yield
typeRef(p, c, List(a))
)
-
+
val wfmt = "%-" + 25 + "s"
def to_s(x: Any): String = wfmt.format(x.toString.replaceAll("""\bll\.""", ""))
-
+
def fmt(args: Any*): String = {
(args map to_s mkString " ").replaceAll("""\s+$""", "")
}
@@ -61,7 +61,7 @@ package ll {
}
def permuteAsSeenFrom(targs: List[Type]) = (
- for {
+ for {
tp <- typeRefs(targs filterNot (_ eq NoType))
prefix <- asSeenPrefixes
if tp.prefix != prefix
@@ -72,11 +72,11 @@ package ll {
}
yield ((site, tp, prefix, seen))
)
-
+
def block(label: Any)(lines: List[String]): List[String] = {
val first = "" + label + " {"
val last = "}"
-
+
first +: lines.map(" " + _) :+ last
}
@@ -84,7 +84,7 @@ package ll {
permuteAsSeenFrom(targs).groupBy(_._1).toList.sortBy(_._1.toString) flatMap {
case (site, xs) =>
block(fmt(site)) {
- fmt("type", "seen from prefix", "is") ::
+ fmt("type", "seen from prefix", "is") ::
fmt("----", "----------------", "--") :: {
xs.groupBy(_._2).toList.sortBy(_._1.toString) flatMap {
case (tp, ys) =>
@@ -95,7 +95,7 @@ package ll {
}
}
}
-
+
def pretty(xs: List[_]) = if (xs.isEmpty) "" else xs.mkString("\n ", "\n ", "\n")
def signaturesIn(info: Type): List[String] = (
@@ -103,11 +103,11 @@ package ll {
filterNot (s => s.isType || s.owner == ObjectClass || s.owner == AnyClass || s.isConstructor)
map (_.defString)
)
-
+
def check(source: String, unit: global.CompilationUnit) = {
import syms._
- afterTyper {
+ exitingTyper {
val typeArgs = List[Type](IntClass.tpe, ListClass[Int]) ++ tparams.map(_.tpe)
permute(typeArgs) foreach println
}
diff --git a/test/files/run/constant-type.check b/test/files/run/constant-type.check
index dfd8be5297..4eededb8ba 100644
--- a/test/files/run/constant-type.check
+++ b/test/files/run/constant-type.check
@@ -13,16 +13,16 @@ scala> :power
scala> val s = transformedType(StringClass.toType).asInstanceOf[Type]
s: $r.intp.global.Type = String
-scala> { println(afterPhase(currentRun.erasurePhase)(ConstantType(Constant(s)))) }
+scala> { println(exitingPhase(currentRun.erasurePhase)(ConstantType(Constant(s)))) }
Class[String](classOf[java.lang.String])
-scala> { afterPhase(currentRun.erasurePhase)(println(ConstantType(Constant(s)))) }
+scala> { exitingPhase(currentRun.erasurePhase)(println(ConstantType(Constant(s)))) }
Class(classOf[java.lang.String])
-scala> { ConstantType(Constant(s)); println(afterPhase(currentRun.erasurePhase)(ConstantType(Constant(s)))); }
+scala> { ConstantType(Constant(s)); println(exitingPhase(currentRun.erasurePhase)(ConstantType(Constant(s)))); }
Class[String](classOf[java.lang.String])
-scala> { ConstantType(Constant(s)); afterPhase(currentRun.erasurePhase)(println(ConstantType(Constant(s)))); }
+scala> { ConstantType(Constant(s)); exitingPhase(currentRun.erasurePhase)(println(ConstantType(Constant(s)))); }
Class(classOf[java.lang.String])
scala>
diff --git a/test/files/run/constant-type.scala b/test/files/run/constant-type.scala
index 84539e2895..373746af4a 100644
--- a/test/files/run/constant-type.scala
+++ b/test/files/run/constant-type.scala
@@ -9,9 +9,9 @@ object Test extends ReplTest {
def code = """
:power
val s = transformedType(StringClass.toType).asInstanceOf[Type]
-{ println(afterPhase(currentRun.erasurePhase)(ConstantType(Constant(s)))) }
-{ afterPhase(currentRun.erasurePhase)(println(ConstantType(Constant(s)))) }
-{ ConstantType(Constant(s)); println(afterPhase(currentRun.erasurePhase)(ConstantType(Constant(s)))); }
-{ ConstantType(Constant(s)); afterPhase(currentRun.erasurePhase)(println(ConstantType(Constant(s)))); }
+{ println(exitingPhase(currentRun.erasurePhase)(ConstantType(Constant(s)))) }
+{ exitingPhase(currentRun.erasurePhase)(println(ConstantType(Constant(s)))) }
+{ ConstantType(Constant(s)); println(exitingPhase(currentRun.erasurePhase)(ConstantType(Constant(s)))); }
+{ ConstantType(Constant(s)); exitingPhase(currentRun.erasurePhase)(println(ConstantType(Constant(s)))); }
"""
}
diff --git a/test/files/run/deeps.check b/test/files/run/deeps.check
new file mode 100644
index 0000000000..a68e474f62
--- /dev/null
+++ b/test/files/run/deeps.check
@@ -0,0 +1,87 @@
+testEquals1
+false
+false
+true
+
+testEquals2
+false
+false
+true
+
+testEquals3
+x=Array(1)
+y=Array(1)
+false
+false
+true
+
+x=Array(Array(1), Array(1))
+y=Array(Array(1), Array(1))
+false
+false
+true
+
+x=Array(Array(Array(1), Array(1)), Array(Array(1), Array(1)))
+y=Array(Array(Array(1), Array(1)), Array(Array(1), Array(1)))
+false
+false
+true
+
+testEquals4
+false
+false
+true
+false
+false
+true
+Array(true, false)
+Array(true, false)
+[true;false]
+true;false
+
+Array(Array(true, false), Array(true, false))
+Array(Array(true, false), Array(true, false))
+[Array(true, false);Array(true, false)]
+Array(true, false);Array(true, false)
+
+Array(Array(Array(true, false), Array(true, false)), Array(Array(true, false), Array(true, false)))
+Array(Array(Array(true, false), Array(true, false)), Array(Array(true, false), Array(true, false)))
+[Array(Array(true, false), Array(true, false));Array(Array(true, false), Array(true, false))]
+Array(Array(true, false), Array(true, false));Array(Array(true, false), Array(true, false))
+
+Array(1.0, 0.0)
+Array(1.0, 0.0)
+[1.0;0.0]
+1.0;0.0
+
+Array(Array(1.0, 0.0), Array(1.0, 0.0))
+Array(Array(1.0, 0.0), Array(1.0, 0.0))
+[Array(1.0, 0.0);Array(1.0, 0.0)]
+Array(1.0, 0.0);Array(1.0, 0.0)
+
+Array(Array(Array(1.0, 0.0), Array(1.0, 0.0)), Array(Array(1.0, 0.0), Array(1.0, 0.0)))
+Array(Array(Array(1.0, 0.0), Array(1.0, 0.0)), Array(Array(1.0, 0.0), Array(1.0, 0.0)))
+[Array(Array(1.0, 0.0), Array(1.0, 0.0));Array(Array(1.0, 0.0), Array(1.0, 0.0))]
+Array(Array(1.0, 0.0), Array(1.0, 0.0));Array(Array(1.0, 0.0), Array(1.0, 0.0))
+
+Array(a, b)
+Array(a, b)
+[a;b]
+a;b
+
+Array(Array(a, b), Array(a, b))
+Array(Array(a, b), Array(a, b))
+[Array(a, b);Array(a, b)]
+Array(a, b);Array(a, b)
+
+Array(Array(Array(a, b), Array(a, b)), Array(Array(a, b), Array(a, b)))
+Array(Array(Array(a, b), Array(a, b)), Array(Array(a, b), Array(a, b)))
+[Array(Array(a, b), Array(a, b));Array(Array(a, b), Array(a, b))]
+Array(Array(a, b), Array(a, b));Array(Array(a, b), Array(a, b))
+
+[Array(true, false); Array(false)]
+[Array(1, 2); Array(3)]
+[Array(1, 2); Array(3)]
+
+Array(boo, and, foo)
+Array(a)
diff --git a/test/files/run/deeps.scala b/test/files/run/deeps.scala
new file mode 100644
index 0000000000..6049cc6024
--- /dev/null
+++ b/test/files/run/deeps.scala
@@ -0,0 +1,114 @@
+//############################################################################
+// deepEquals / deep.toString
+//############################################################################
+
+//############################################################################
+// need to revisit array equqality
+object Test {
+
+ def testEquals1 {
+ println(Array(1) == Array(1))
+ println(Array(1) equals Array(1))
+ println(Array(1).deep == Array(1).deep)
+ println
+ }
+
+ def testEquals2 {
+ println(Array(Array(1), Array(2)) == Array(Array(1), Array(2)))
+ println(Array(Array(1), Array(2)) equals Array(Array(1), Array(2)))
+ println(Array(Array(1), Array(2)).deep equals Array(Array(1), Array(2)).deep)
+ println
+ }
+
+ def testEquals3 {
+ val a1 = Array(1)
+ val b1 = Array(1)
+ val a2 = Array(a1, b1)
+ val b2 = Array(a1, b1)
+ val a3 = Array(a2, b2)
+ val b3 = Array(a2, b2)
+ def test[T](x: Array[T], y: Array[T]) {
+ println("x=" + x.deep.toString)
+ println("y=" + y.deep.toString)
+ println(x == y)
+ println(x equals y)
+ println(x.deep == y.deep)
+ println
+ }
+ test(a1, b1)
+ test(a2, b2)
+ test(a3, b3)
+ }
+
+ def testEquals4 {
+ println("boo:and:foo".split(':') == "boo:and:foo".split(':'))
+ println("boo:and:foo".split(':') equals "boo:and:foo".split(':'))
+ println("boo:and:foo".split(':').deep == "boo:and:foo".split(':').deep)
+
+ val xs = new java.util.ArrayList[String](); xs.add("a")
+ val ys = new java.util.ArrayList[String](); ys.add("a")
+ println(xs.toArray == ys.toArray)
+ println(xs.toArray equals ys.toArray)
+ println(xs.toArray.deep == ys.toArray.deep)
+ }
+
+ def testToString1 {
+ def sweep(s: String) = (
+ s.replaceAll("D@[0-9a-fA-F]+", "D@0000000")
+ .replaceAll("Z@[0-9a-fA-F]+", "Z@0000000")
+ .replaceAll(";@[0-9a-fA-F]+", ";@0000000")
+ )
+ def test[T](a: Array[T]) {
+ println(sweep(a.deep.toString))
+ println(a.deep.toString)
+ println(a.deep.mkString("[", ";", "]"))
+ println(a.deep.mkString(";"))
+ println
+ }
+
+ val ba1 = Array(true, false)
+ val ba2 = Array(ba1, ba1)
+ val ba3 = Array(ba2, ba2)
+ test(ba1)
+ test(ba2)
+ test(ba3)
+
+ val da1 = Array(1.0d, 0.0d)
+ val da2 = Array(da1, da1)
+ val da3 = Array(da2, da2)
+ test(da1)
+ test(da2)
+ test(da3)
+
+ val sa1 = Array("a", "b")
+ val sa2 = Array(sa1, sa1)
+ val sa3 = Array(sa2, sa2)
+ test(sa1)
+ test(sa2)
+ test(sa3)
+ }
+
+ def testToString2 {
+ println(Array(Array(true, false), Array(false)).deep.mkString("[", "; ", "]"))
+ println(Array(Array('1', '2'), Array('3')).deep.mkString("[", "; ", "]"))
+ println(Array(Array(1, 2), Array(3)).deep.mkString("[", "; ", "]"))
+ println
+ }
+
+ def testToString3 {
+ println("boo:and:foo".split(':').deep.toString)
+
+ val xs = new java.util.ArrayList[String](); xs.add("a")
+ println(xs.toArray.deep.toString)
+ }
+
+ def main(args: Array[String]): Unit = {
+ println("testEquals1") ; testEquals1
+ println("testEquals2") ; testEquals2
+ println("testEquals3") ; testEquals3
+ println("testEquals4") ; testEquals4
+ testToString1
+ testToString2
+ testToString3
+ }
+}
diff --git a/test/files/run/existentials-in-compiler.scala b/test/files/run/existentials-in-compiler.scala
index c69d1217fd..14c25849cb 100644
--- a/test/files/run/existentials-in-compiler.scala
+++ b/test/files/run/existentials-in-compiler.scala
@@ -73,7 +73,7 @@ package extest {
def check(source: String, unit: global.CompilationUnit) = {
getRequiredPackage("extest").moduleClass.info.decls.toList.filter(_.isType).map(_.initialize).sortBy(_.name.toString) foreach { clazz =>
- afterTyper {
+ exitingTyper {
clazz.info
println(clazz.defString)
println(" " + classExistentialType(clazz) + "\n")
diff --git a/test/files/run/lub-visibility.check b/test/files/run/lub-visibility.check
index 3461d1bf6b..f3a6bef215 100644
--- a/test/files/run/lub-visibility.check
+++ b/test/files/run/lub-visibility.check
@@ -8,7 +8,7 @@ scala> // should infer List[scala.collection.immutable.Seq[Nothing]]
scala> // but reverted that for SI-5534.
scala> val x = List(List(), Vector())
-x: List[scala.collection.immutable.Seq[Nothing] with scala.collection.AbstractSeq[Nothing]{def companion: scala.collection.generic.GenericCompanion[scala.collection.immutable.Seq with scala.collection.AbstractSeq{def dropRight(n: Int): scala.collection.immutable.Seq[Any] with scala.collection.AbstractSeq[Any]; def takeRight(n: Int): scala.collection.immutable.Seq[Any] with scala.collection.AbstractSeq[Any]; def drop(n: Int): scala.collection.immutable.Seq[Any] with scala.collection.AbstractSeq[Any]; def take(n: Int): scala.collection.immutable.Seq[Any] with scala.collection.AbstractSeq[Any]; def slice(from: Int,until: Int): scala.collection.immutable.Seq[Any] with scala.collection.AbstractSeq[Any]}]; def dropRight(n: Int): scala.collection.immutable.Seq[Nothing] with scala.collection.Ab...
+x: List[scala.collection.immutable.Seq[Nothing] with scala.collection.AbstractSeq[Nothing]{def companion: scala.collection.generic.GenericCompanion[scala.collection.immutable.Seq with scala.collection.AbstractSeq]; def dropRight(n: Int): scala.collection.immutable.Seq[Nothing] with scala.collection.AbstractSeq[Nothing]{def companion: scala.collection.generic.GenericCompanion[scala.collection.immutable.Seq with scala.collection.AbstractSeq]; def dropRight(n: Int): scala.collection.immutable.Seq[Nothing] with scala.collection.AbstractSeq[Nothing]{def dropRight(n: Int): scala.collection.immutable.Seq[Nothing] with scala.collection.AbstractSeq[Nothing]; def takeRight(n: Int): scala.collection.immutable.Seq[Nothing] with scala.collection.AbstractSeq[Nothing]; def drop(n: Int): scala.collecti...
scala>
scala>
diff --git a/test/files/run/no-pickle-skolems.check b/test/files/run/no-pickle-skolems.check
new file mode 100644
index 0000000000..d64066171a
--- /dev/null
+++ b/test/files/run/no-pickle-skolems.check
@@ -0,0 +1 @@
+OK!
diff --git a/test/files/run/no-pickle-skolems/Source_1.scala b/test/files/run/no-pickle-skolems/Source_1.scala
new file mode 100644
index 0000000000..1b4cbfa788
--- /dev/null
+++ b/test/files/run/no-pickle-skolems/Source_1.scala
@@ -0,0 +1,5 @@
+package s
+
+trait Foo { def to[CC[X]](implicit cc: CC[Int]): Unit }
+
+class Bar extends Foo { def to[CC[X]](implicit cc: CC[Int]): Unit = ??? }
diff --git a/test/files/run/no-pickle-skolems/Test_2.scala b/test/files/run/no-pickle-skolems/Test_2.scala
new file mode 100644
index 0000000000..90bb4c4f88
--- /dev/null
+++ b/test/files/run/no-pickle-skolems/Test_2.scala
@@ -0,0 +1,37 @@
+import scala.reflect.runtime.universe._
+
+object Test {
+ /** Collects symbols by the given name, even if they're not
+ * named CC.
+ */
+ def collectSymbols[T: TypeTag](inMethod: TermName, name: String): List[String] = {
+ val m = typeOf[T] member inMethod typeSignatureIn typeOf[T]
+ var buf: List[Symbol] = Nil
+ var seen: Set[Symbol] = Set()
+ def id(s: Symbol): Int = s.asInstanceOf[{ def id: Int }].id
+
+ def check(s: Symbol) {
+ if (!seen(s)) {
+ seen += s
+ if (s.name.toString == name) buf ::= s
+ }
+ }
+ def loop(t: Type) {
+ t match {
+ case TypeRef(pre, sym, args) => loop(pre) ; check(sym) ; args foreach loop
+ case PolyType(tparams, restpe) => tparams foreach { tp => check(tp) ; check(tp.owner) ; loop(tp.typeSignature) } ; loop(restpe)
+ case MethodType(params, restpe) => params foreach { p => check(p) ; loop(p.typeSignature) } ; loop(restpe)
+ case _ =>
+ }
+ }
+ loop(m)
+
+ buf.reverse.distinct map (s => s.name + "#" + id(s))
+ }
+
+ def main(args: Array[String]): Unit = {
+ val syms = collectSymbols[s.Bar]("to", "CC")
+ assert(syms.size == 1, syms)
+ println("OK!")
+ }
+}
diff --git a/test/files/run/parserJavaIdent.check b/test/files/run/parserJavaIdent.check
new file mode 100644
index 0000000000..597ddbee47
--- /dev/null
+++ b/test/files/run/parserJavaIdent.check
@@ -0,0 +1,26 @@
+[1.7] parsed: simple
+[1.8] parsed: with123
+[1.6] parsed: with$
+[1.10] parsed: withøßöèæ
+[1.6] parsed: with_
+[1.6] parsed: _with
+[1.1] failure: java identifier expected
+
+3start
+^
+[1.1] failure: java identifier expected
+
+-start
+^
+[1.5] failure: java identifier expected
+
+with-s
+ ^
+[1.3] failure: java identifier expected
+
+we♥scala
+ ^
+[1.6] failure: java identifier expected
+
+with space
+ ^
diff --git a/test/files/run/parserJavaIdent.scala b/test/files/run/parserJavaIdent.scala
new file mode 100644
index 0000000000..c068075e4e
--- /dev/null
+++ b/test/files/run/parserJavaIdent.scala
@@ -0,0 +1,26 @@
+object Test extends scala.util.parsing.combinator.JavaTokenParsers {
+
+ def test[A](s: String) {
+ val res = parseAll(ident, s) match {
+ case Failure(_, in) => Failure("java identifier expected", in)
+ case o => o
+ }
+ println(res)
+ }
+
+ def main(args: Array[String]) {
+ // Happy tests
+ test("simple")
+ test("with123")
+ test("with$")
+ test("withøßöèæ")
+ test("with_")
+ test("_with")
+ // Sad tests
+ test("3start")
+ test("-start")
+ test("with-s")
+ test("we♥scala")
+ test("with space")
+ }
+}
diff --git a/test/pending/run/reify_implicits-new.check b/test/files/run/reify_implicits-new.check
index e3aeb20f6b..e3aeb20f6b 100644
--- a/test/pending/run/reify_implicits-new.check
+++ b/test/files/run/reify_implicits-new.check
diff --git a/test/pending/run/reify_implicits-new.scala b/test/files/run/reify_implicits-new.scala
index 42a1deef26..42a1deef26 100644
--- a/test/pending/run/reify_implicits-new.scala
+++ b/test/files/run/reify_implicits-new.scala
diff --git a/test/pending/run/reify_implicits-old.check b/test/files/run/reify_implicits-old.check
index e3aeb20f6b..e3aeb20f6b 100644
--- a/test/pending/run/reify_implicits-old.check
+++ b/test/files/run/reify_implicits-old.check
diff --git a/test/pending/run/reify_implicits-old.scala b/test/files/run/reify_implicits-old.scala
index 8ff256d2d4..8ff256d2d4 100644
--- a/test/pending/run/reify_implicits-old.scala
+++ b/test/files/run/reify_implicits-old.scala
diff --git a/test/files/run/reify_newimpl_11.check b/test/files/run/reify_newimpl_11.check
index 2f5cb581e6..c019c6db2d 100644
--- a/test/files/run/reify_newimpl_11.check
+++ b/test/files/run/reify_newimpl_11.check
@@ -1,2 +1,4 @@
-scala.tools.reflect.ToolBoxError: reflective toolbox has failed:
-unresolved free type variables (namely: T defined by C in reify_newimpl_11.scala:6:11). have you forgot to use TypeTag annotations for type parameters external to a reifee? if you have troubles tracking free type variables, consider using -Xlog-free-types
+scala.tools.reflect.ToolBoxError: reflective toolbox failed due to unresolved free type variables:
+ T defined by C in reify_newimpl_11.scala:6:11
+have you forgotten to use TypeTag annotations for type parameters external to a reifee?
+if you have troubles tracking free type variables, consider using -Xlog-free-types
diff --git a/test/files/run/reify_newimpl_13.check b/test/files/run/reify_newimpl_13.check
index d518cd7b84..13e3c9af1e 100644
--- a/test/files/run/reify_newimpl_13.check
+++ b/test/files/run/reify_newimpl_13.check
@@ -1,2 +1,4 @@
-scala.tools.reflect.ToolBoxError: reflective toolbox has failed:
-unresolved free type variables (namely: T defined by C in reify_newimpl_13.scala:7:13). have you forgot to use TypeTag annotations for type parameters external to a reifee? if you have troubles tracking free type variables, consider using -Xlog-free-types
+scala.tools.reflect.ToolBoxError: reflective toolbox failed due to unresolved free type variables:
+ T defined by C in reify_newimpl_13.scala:7:13
+have you forgotten to use TypeTag annotations for type parameters external to a reifee?
+if you have troubles tracking free type variables, consider using -Xlog-free-types
diff --git a/test/files/run/reify_newimpl_19.check b/test/files/run/reify_newimpl_19.check
index 8b8652f92c..c749d4f106 100644
--- a/test/files/run/reify_newimpl_19.check
+++ b/test/files/run/reify_newimpl_19.check
@@ -1,2 +1,4 @@
-scala.tools.reflect.ToolBoxError: reflective toolbox has failed:
-unresolved free type variables (namely: T defined by C in reify_newimpl_19.scala:7:10). have you forgot to use TypeTag annotations for type parameters external to a reifee? if you have troubles tracking free type variables, consider using -Xlog-free-types
+scala.tools.reflect.ToolBoxError: reflective toolbox failed due to unresolved free type variables:
+ T defined by C in reify_newimpl_19.scala:7:10
+have you forgotten to use TypeTag annotations for type parameters external to a reifee?
+if you have troubles tracking free type variables, consider using -Xlog-free-types
diff --git a/test/files/run/repl-colon-type.check b/test/files/run/repl-colon-type.check
index 35cd04ba87..7716221f54 100644
--- a/test/files/run/repl-colon-type.check
+++ b/test/files/run/repl-colon-type.check
@@ -14,7 +14,6 @@ scala> :type List[1, 2, 3]
List[1, 2, 3]
^
-
scala> :type List(1, 2, 3)
List[Int]
@@ -52,10 +51,9 @@ scala> :type protected lazy val f = 5
Access to protected value f not permitted because
enclosing object $eval in package $line19 is not a subclass of
object $iw where target is defined
- lazy val $result = `f`
+ lazy val $result = f
^
-
scala> :type def f = 5
=> Int
diff --git a/test/files/run/repl-out-dir.check b/test/files/run/repl-out-dir.check
new file mode 100644
index 0000000000..a96f9ba9d9
--- /dev/null
+++ b/test/files/run/repl-out-dir.check
@@ -0,0 +1,53 @@
+Type in expressions to have them evaluated.
+Type :help for more information.
+
+scala>
+
+scala> case class Bippy(x: Int)
+defined class Bippy
+
+scala> val x = Bippy(1)
+x: Bippy = Bippy(1)
+
+scala> $intp.showDirectory
+repl-out-dir-run.obj
+ $line1
+ $eval$.class
+ $eval.class
+ $line2
+ $eval$.class
+ $eval.class
+ $read$$iw$$iw$.class
+ $read$$iw$.class
+ $read$.class
+ $read.class
+ $line3
+ $eval$.class
+ $eval.class
+ $read$$iw$$iw$.class
+ $read$$iw$$iw$Bippy$.class
+ $read$$iw$$iw$Bippy.class
+ $read$$iw$.class
+ $read$.class
+ $read.class
+ $line4
+ $eval$.class
+ $eval.class
+ $read$$iw$$iw$.class
+ $read$$iw$.class
+ $read$.class
+ $read.class
+ $line5
+ $eval$.class
+ $eval.class
+ $read$$iw$$iw$.class
+ $read$$iw$.class
+ $read$.class
+ $read.class
+ $repl_$init.class
+ Test$.class
+ Test.class
+
+scala>
+
+scala>
diff --git a/test/files/run/repl-out-dir.scala b/test/files/run/repl-out-dir.scala
new file mode 100644
index 0000000000..33c823aa2d
--- /dev/null
+++ b/test/files/run/repl-out-dir.scala
@@ -0,0 +1,13 @@
+import scala.tools.partest.ReplTest
+import scala.tools.nsc.Settings
+
+object Test extends ReplTest {
+ override def extraSettings = s"-Yrepl-outdir ${testOutput.path}"
+
+ def code = s"""
+case class Bippy(x: Int)
+val x = Bippy(1)
+$$intp.showDirectory
+ """
+
+}
diff --git a/test/files/run/search.check b/test/files/run/search.check
new file mode 100644
index 0000000000..a885696509
--- /dev/null
+++ b/test/files/run/search.check
@@ -0,0 +1,6 @@
+Found(2)
+Found(4)
+InsertionPoint(9)
+Found(2)
+Found(4)
+InsertionPoint(9)
diff --git a/test/files/run/search.scala b/test/files/run/search.scala
new file mode 100644
index 0000000000..ed7fed54a7
--- /dev/null
+++ b/test/files/run/search.scala
@@ -0,0 +1,14 @@
+object Test extends App {
+ import scala.collection.{LinearSeq, IndexedSeq}
+ import scala.collection.Searching.search
+
+ val ls = LinearSeq(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 13)
+ println(ls.search(3))
+ println(ls.search(5, 3, 8))
+ println(ls.search(12))
+
+ val is = IndexedSeq(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 13)
+ println(is.search(3))
+ println(is.search(5, 3, 8))
+ println(is.search(12))
+}
diff --git a/test/files/run/settings-parse.check b/test/files/run/settings-parse.check
new file mode 100644
index 0000000000..18145c9100
--- /dev/null
+++ b/test/files/run/settings-parse.check
@@ -0,0 +1,566 @@
+0) List(-cp, ) ==> Settings {
+ -d = .
+ -classpath = ""
+}
+
+1) List(-cp, , ) ==> Settings {
+ -d = .
+ -classpath = ""
+}
+
+2) List(, -cp, ) ==> Settings {
+ -d = .
+ -classpath = ""
+}
+
+3) List(-cp, , -deprecation) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = ""
+}
+
+4) List(-cp, , , -deprecation) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = ""
+}
+
+5) List(-cp, , -deprecation, ) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = ""
+}
+
+6) List(, -cp, , -deprecation) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = ""
+}
+
+7) List(-cp, , -deprecation, foo.scala) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = ""
+}
+
+8) List(-cp, , , -deprecation, foo.scala) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = ""
+}
+
+9) List(-cp, , -deprecation, , foo.scala) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = ""
+}
+
+10) List(-cp, , -deprecation, foo.scala, ) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = ""
+}
+
+11) List(, -cp, , -deprecation, foo.scala) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = ""
+}
+
+12) List(-cp, , foo.scala) ==> Settings {
+ -d = .
+ -classpath = ""
+}
+
+13) List(-cp, , , foo.scala) ==> Settings {
+ -d = .
+ -classpath = ""
+}
+
+14) List(-cp, , foo.scala, ) ==> Settings {
+ -d = .
+ -classpath = ""
+}
+
+15) List(, -cp, , foo.scala) ==> Settings {
+ -d = .
+ -classpath = ""
+}
+
+16) List(-cp, , foo.scala, -deprecation) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = ""
+}
+
+17) List(-cp, , , foo.scala, -deprecation) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = ""
+}
+
+18) List(-cp, , foo.scala, , -deprecation) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = ""
+}
+
+19) List(-cp, , foo.scala, -deprecation, ) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = ""
+}
+
+20) List(, -cp, , foo.scala, -deprecation) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = ""
+}
+
+21) List(-deprecation, -cp, ) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = ""
+}
+
+22) List(, -deprecation, -cp, ) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = ""
+}
+
+23) List(-deprecation, -cp, , ) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = ""
+}
+
+24) List(-deprecation, , -cp, ) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = ""
+}
+
+25) List(-deprecation, -cp, , foo.scala) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = ""
+}
+
+26) List(, -deprecation, -cp, , foo.scala) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = ""
+}
+
+27) List(-deprecation, -cp, , , foo.scala) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = ""
+}
+
+28) List(-deprecation, -cp, , foo.scala, ) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = ""
+}
+
+29) List(-deprecation, , -cp, , foo.scala) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = ""
+}
+
+30) List(-deprecation, foo.scala, -cp, ) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = ""
+}
+
+31) List(, -deprecation, foo.scala, -cp, ) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = ""
+}
+
+32) List(-deprecation, , foo.scala, -cp, ) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = ""
+}
+
+33) List(-deprecation, foo.scala, -cp, , ) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = ""
+}
+
+34) List(-deprecation, foo.scala, , -cp, ) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = ""
+}
+
+35) List(foo.scala, -cp, ) ==> Settings {
+ -d = .
+ -classpath = ""
+}
+
+36) List(, foo.scala, -cp, ) ==> Settings {
+ -d = .
+ -classpath = ""
+}
+
+37) List(foo.scala, -cp, , ) ==> Settings {
+ -d = .
+ -classpath = ""
+}
+
+38) List(foo.scala, , -cp, ) ==> Settings {
+ -d = .
+ -classpath = ""
+}
+
+39) List(foo.scala, -cp, , -deprecation) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = ""
+}
+
+40) List(, foo.scala, -cp, , -deprecation) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = ""
+}
+
+41) List(foo.scala, -cp, , , -deprecation) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = ""
+}
+
+42) List(foo.scala, -cp, , -deprecation, ) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = ""
+}
+
+43) List(foo.scala, , -cp, , -deprecation) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = ""
+}
+
+44) List(foo.scala, -deprecation, -cp, ) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = ""
+}
+
+45) List(, foo.scala, -deprecation, -cp, ) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = ""
+}
+
+46) List(foo.scala, , -deprecation, -cp, ) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = ""
+}
+
+47) List(foo.scala, -deprecation, -cp, , ) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = ""
+}
+
+48) List(foo.scala, -deprecation, , -cp, ) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = ""
+}
+
+0) List(-cp, /tmp:/bippy) ==> Settings {
+ -d = .
+ -classpath = /tmp:/bippy
+}
+
+1) List(-cp, /tmp:/bippy, ) ==> Settings {
+ -d = .
+ -classpath = /tmp:/bippy
+}
+
+2) List(, -cp, /tmp:/bippy) ==> Settings {
+ -d = .
+ -classpath = /tmp:/bippy
+}
+
+3) List(-cp, /tmp:/bippy, -deprecation) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = /tmp:/bippy
+}
+
+4) List(-cp, /tmp:/bippy, , -deprecation) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = /tmp:/bippy
+}
+
+5) List(-cp, /tmp:/bippy, -deprecation, ) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = /tmp:/bippy
+}
+
+6) List(, -cp, /tmp:/bippy, -deprecation) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = /tmp:/bippy
+}
+
+7) List(-cp, /tmp:/bippy, -deprecation, foo.scala) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = /tmp:/bippy
+}
+
+8) List(-cp, /tmp:/bippy, , -deprecation, foo.scala) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = /tmp:/bippy
+}
+
+9) List(-cp, /tmp:/bippy, -deprecation, , foo.scala) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = /tmp:/bippy
+}
+
+10) List(-cp, /tmp:/bippy, -deprecation, foo.scala, ) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = /tmp:/bippy
+}
+
+11) List(, -cp, /tmp:/bippy, -deprecation, foo.scala) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = /tmp:/bippy
+}
+
+12) List(-cp, /tmp:/bippy, foo.scala) ==> Settings {
+ -d = .
+ -classpath = /tmp:/bippy
+}
+
+13) List(-cp, /tmp:/bippy, , foo.scala) ==> Settings {
+ -d = .
+ -classpath = /tmp:/bippy
+}
+
+14) List(-cp, /tmp:/bippy, foo.scala, ) ==> Settings {
+ -d = .
+ -classpath = /tmp:/bippy
+}
+
+15) List(, -cp, /tmp:/bippy, foo.scala) ==> Settings {
+ -d = .
+ -classpath = /tmp:/bippy
+}
+
+16) List(-cp, /tmp:/bippy, foo.scala, -deprecation) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = /tmp:/bippy
+}
+
+17) List(-cp, /tmp:/bippy, , foo.scala, -deprecation) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = /tmp:/bippy
+}
+
+18) List(-cp, /tmp:/bippy, foo.scala, , -deprecation) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = /tmp:/bippy
+}
+
+19) List(-cp, /tmp:/bippy, foo.scala, -deprecation, ) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = /tmp:/bippy
+}
+
+20) List(, -cp, /tmp:/bippy, foo.scala, -deprecation) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = /tmp:/bippy
+}
+
+21) List(-deprecation, -cp, /tmp:/bippy) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = /tmp:/bippy
+}
+
+22) List(, -deprecation, -cp, /tmp:/bippy) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = /tmp:/bippy
+}
+
+23) List(-deprecation, -cp, /tmp:/bippy, ) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = /tmp:/bippy
+}
+
+24) List(-deprecation, , -cp, /tmp:/bippy) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = /tmp:/bippy
+}
+
+25) List(-deprecation, -cp, /tmp:/bippy, foo.scala) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = /tmp:/bippy
+}
+
+26) List(, -deprecation, -cp, /tmp:/bippy, foo.scala) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = /tmp:/bippy
+}
+
+27) List(-deprecation, -cp, /tmp:/bippy, , foo.scala) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = /tmp:/bippy
+}
+
+28) List(-deprecation, -cp, /tmp:/bippy, foo.scala, ) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = /tmp:/bippy
+}
+
+29) List(-deprecation, , -cp, /tmp:/bippy, foo.scala) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = /tmp:/bippy
+}
+
+30) List(-deprecation, foo.scala, -cp, /tmp:/bippy) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = /tmp:/bippy
+}
+
+31) List(, -deprecation, foo.scala, -cp, /tmp:/bippy) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = /tmp:/bippy
+}
+
+32) List(-deprecation, , foo.scala, -cp, /tmp:/bippy) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = /tmp:/bippy
+}
+
+33) List(-deprecation, foo.scala, -cp, /tmp:/bippy, ) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = /tmp:/bippy
+}
+
+34) List(-deprecation, foo.scala, , -cp, /tmp:/bippy) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = /tmp:/bippy
+}
+
+35) List(foo.scala, -cp, /tmp:/bippy) ==> Settings {
+ -d = .
+ -classpath = /tmp:/bippy
+}
+
+36) List(, foo.scala, -cp, /tmp:/bippy) ==> Settings {
+ -d = .
+ -classpath = /tmp:/bippy
+}
+
+37) List(foo.scala, -cp, /tmp:/bippy, ) ==> Settings {
+ -d = .
+ -classpath = /tmp:/bippy
+}
+
+38) List(foo.scala, , -cp, /tmp:/bippy) ==> Settings {
+ -d = .
+ -classpath = /tmp:/bippy
+}
+
+39) List(foo.scala, -cp, /tmp:/bippy, -deprecation) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = /tmp:/bippy
+}
+
+40) List(, foo.scala, -cp, /tmp:/bippy, -deprecation) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = /tmp:/bippy
+}
+
+41) List(foo.scala, -cp, /tmp:/bippy, , -deprecation) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = /tmp:/bippy
+}
+
+42) List(foo.scala, -cp, /tmp:/bippy, -deprecation, ) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = /tmp:/bippy
+}
+
+43) List(foo.scala, , -cp, /tmp:/bippy, -deprecation) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = /tmp:/bippy
+}
+
+44) List(foo.scala, -deprecation, -cp, /tmp:/bippy) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = /tmp:/bippy
+}
+
+45) List(, foo.scala, -deprecation, -cp, /tmp:/bippy) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = /tmp:/bippy
+}
+
+46) List(foo.scala, , -deprecation, -cp, /tmp:/bippy) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = /tmp:/bippy
+}
+
+47) List(foo.scala, -deprecation, -cp, /tmp:/bippy, ) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = /tmp:/bippy
+}
+
+48) List(foo.scala, -deprecation, , -cp, /tmp:/bippy) ==> Settings {
+ -d = .
+ -deprecation = true
+ -classpath = /tmp:/bippy
+}
+
diff --git a/test/files/run/settings-parse.scala b/test/files/run/settings-parse.scala
new file mode 100644
index 0000000000..2b04f55b24
--- /dev/null
+++ b/test/files/run/settings-parse.scala
@@ -0,0 +1,27 @@
+import scala.tools.nsc._
+
+object Test {
+ val tokens = List("", "-deprecation", "foo.scala")
+ val subsets = tokens.toSet.subsets.toList
+ val permutations0 = subsets.flatMap(_.toList.permutations).distinct
+
+ def runWithCp(cp: String) = {
+ val permutations = permutations0 flatMap ("-cp CPTOKEN" :: _ permutations)
+
+ for ((p, i) <- permutations.distinct.sortBy(_ mkString "").zipWithIndex) {
+ val args = p flatMap (_ split "\\s+") map (x => if (x == "CPTOKEN") cp else x)
+ val s = new settings.MutableSettings(println)
+ val (ok, residual) = s.processArguments(args, processAll = true)
+
+ val expected = args filter (_ == "foo.scala")
+ assert(residual == expected, residual)
+ assert(ok, args)
+ println(s"$i) $args ==> $s")
+ }
+ }
+
+ def main(args0: Array[String]): Unit = {
+ runWithCp("")
+ runWithCp("/tmp:/bippy")
+ }
+}
diff --git a/test/files/run/shortClass.check b/test/files/run/shortClass.check
new file mode 100644
index 0000000000..fbdb725cca
--- /dev/null
+++ b/test/files/run/shortClass.check
@@ -0,0 +1,10 @@
+bippity.bop.Foo
+bippity.bop.Foo$Bar
+bippity.bop.Foo$Bar$
+Test$$anon$1
+Test$$anon$2
+Foo
+Bar
+Bar$
+Foo with DingDongBippy
+Bar with DingDongBippy
diff --git a/test/files/run/shortClass.scala b/test/files/run/shortClass.scala
new file mode 100644
index 0000000000..b7bb016896
--- /dev/null
+++ b/test/files/run/shortClass.scala
@@ -0,0 +1,24 @@
+import scala.reflect.internal.util._
+
+package bippity {
+ trait DingDongBippy
+
+ package bop {
+ class Foo {
+ class Bar
+ object Bar
+ }
+ }
+}
+
+object Test {
+ import bippity._
+ import bop._
+
+ def main(args: Array[String]): Unit = {
+ val f = new Foo
+ val instances = List(f, new f.Bar, f.Bar, new Foo with DingDongBippy, new f.Bar with DingDongBippy)
+ instances map (_.getClass.getName) foreach println
+ instances map shortClassOfInstance foreach println
+ }
+}
diff --git a/test/files/run/streams.check b/test/files/run/streams.check
index 7f894052d9..032057d4a1 100644
--- a/test/files/run/streams.check
+++ b/test/files/run/streams.check
@@ -23,3 +23,4 @@ Stream(100001, ?)
true
true
705082704
+6
diff --git a/test/files/run/streams.scala b/test/files/run/streams.scala
index 51b4e5d76c..dc5d0204ac 100644
--- a/test/files/run/streams.scala
+++ b/test/files/run/streams.scala
@@ -29,7 +29,7 @@ object Test extends App {
def powers(x: Int) = if ((x&(x-1)) == 0) Some(x) else None
println(s3.flatMap(powers).reverse.head)
- // large enough to generate StackOverflows (on most systems)
+ // large enough to generate StackOverflows (on most systems)
// unless the following methods are tail call optimized.
val size = 100000
@@ -43,4 +43,7 @@ object Test extends App {
println(Stream.from(1).take(size).foldLeft(0)(_ + _))
val arr = new Array[Int](size)
Stream.from(1).take(size).copyToArray(arr, 0)
+
+ // dropRight terminates
+ println(Stream from 1 dropRight 1000 take 3 sum)
}
diff --git a/test/files/run/t0091.check b/test/files/run/t0091.check
index 7ed6ff82de..fd3c81a4d7 100644
--- a/test/files/run/t0091.check
+++ b/test/files/run/t0091.check
@@ -1 +1,2 @@
5
+5
diff --git a/test/files/run/t0091.scala b/test/files/run/t0091.scala
index eaddde0dbf..45235eb77b 100644
--- a/test/files/run/t0091.scala
+++ b/test/files/run/t0091.scala
@@ -4,10 +4,13 @@ object C extends B {
object m extends A { def x = 5 }
}
object Test {
- // The type annotation here is necessary, otherwise
- // the compiler would reference C$m$ directly.
- def o : B = C
- def main(argv : Array[String]) : Unit = {
- println(o.m.x)
- }
+ // The type annotation here is necessary, otherwise
+ // the compiler would reference C$m$ directly.
+ def o1 : B = C
+ def o2 = C
+
+ def main(argv : Array[String]) : Unit = {
+ println(o1.m.x)
+ println(o2.m.x)
+ }
}
diff --git a/test/files/run/t1500.scala b/test/files/run/t1500.scala
index ab132b724f..6d2e7ee05f 100644
--- a/test/files/run/t1500.scala
+++ b/test/files/run/t1500.scala
@@ -21,7 +21,7 @@ object Test {
val settings = new Settings()
settings.classpath.value = System.getProperty("java.class.path")
val tool = new interpreter.IMain(settings)
- val global = tool.compiler
+ val global = tool.global
import global._
import definitions._
diff --git a/test/files/run/t1501.scala b/test/files/run/t1501.scala
index aba206bc7a..a2f7bb3a65 100644
--- a/test/files/run/t1501.scala
+++ b/test/files/run/t1501.scala
@@ -31,7 +31,7 @@ object Test {
val settings = new Settings()
settings.classpath.value = System.getProperty("java.class.path")
val tool = new interpreter.IMain(settings)
- val global = tool.compiler
+ val global = tool.global
import global._
import definitions._
diff --git a/test/files/run/t2251.check b/test/files/run/t2251.check
new file mode 100644
index 0000000000..55ad2a5857
--- /dev/null
+++ b/test/files/run/t2251.check
@@ -0,0 +1 @@
+Set(List(List(C), Stream(D, ?)))
diff --git a/test/files/run/t2251.scala b/test/files/run/t2251.scala
new file mode 100644
index 0000000000..00c5619b49
--- /dev/null
+++ b/test/files/run/t2251.scala
@@ -0,0 +1,19 @@
+class A
+trait B[T <: B[T]] extends A
+class C extends B[C] { override def toString = "C" }
+class D extends B[D] { override def toString = "D" }
+
+class E {
+ val ys = List(List(new C), Stream(new D))
+}
+
+object Test {
+ def trav = List(List(), Stream())
+
+ def main(args: Array[String]): Unit = {
+ val f = (new E).ys _
+ var xs: Set[List[_ <: Seq[B[_]]]] = Set()
+ xs += f()
+ println(xs)
+ }
+}
diff --git a/test/files/run/t2251b.check b/test/files/run/t2251b.check
new file mode 100644
index 0000000000..42b0be457a
--- /dev/null
+++ b/test/files/run/t2251b.check
@@ -0,0 +1,11 @@
+TypeTag[List[scala.collection.immutable.LinearSeq[B[_ >: D with C <: B[_ >: D with C <: A]]] with scala.collection.AbstractSeq[B[_ >: D with C <: B[_ >: D with C <: A]]]{def companion: scala.collection.generic.GenericCompanion[scala.collection.immutable.LinearSeq with scala.collection.AbstractSeq]; def reverse: scala.collection.immutable.LinearSeq[B[_ >: D with C <: A]] with scala.collection.AbstractSeq[B[_ >: D with C <: A]]{def companion: scala.collection.generic.GenericCompanion[scala.collection.immutable.LinearSeq with scala.collection.AbstractSeq]; def reverse: scala.collection.immutable.LinearSeq[A] with scala.collection.AbstractSeq[A]; def dropRight(n: Int): scala.collection.immutable.LinearSeq[A] with scala.collection.AbstractSeq[A]; def takeRight(n: Int): scala.collection.immutable.LinearSeq[A] with scala.collection.AbstractSeq[A]; def drop(n: Int): scala.collection.immutable.LinearSeq[A] with scala.collection.AbstractSeq[A]; def take(n: Int): scala.collection.immutable.LinearSeq[A] with scala.collection.AbstractSeq[A]; def slice(from: Int,until: Int): scala.collection.immutable.LinearSeq[A] with scala.collection.AbstractSeq[A]}; def dropRight(n: Int): scala.collection.immutable.LinearSeq[B[_ >: D with C <: A]] with scala.collection.AbstractSeq[B[_ >: D with C <: A]]{def companion: scala.collection.generic.GenericCompanion[scala.collection.immutable.LinearSeq with scala.collection.AbstractSeq]; def reverse: scala.collection.immutable.LinearSeq[A] with scala.collection.AbstractSeq[A]; def dropRight(n: Int): scala.collection.immutable.LinearSeq[A] with scala.collection.AbstractSeq[A]; def takeRight(n: Int): scala.collection.immutable.LinearSeq[A] with scala.collection.AbstractSeq[A]; def drop(n: Int): scala.collection.immutable.LinearSeq[A] with scala.collection.AbstractSeq[A]; def take(n: Int): scala.collection.immutable.LinearSeq[A] with scala.collection.AbstractSeq[A]; def slice(from: Int,until: Int): scala.collection.immutable.LinearSeq[A] with scala.collection.AbstractSeq[A]}; def takeRight(n: Int): scala.collection.immutable.LinearSeq[B[_ >: D with C <: A]] with scala.collection.AbstractSeq[B[_ >: D with C <: A]]{def companion: scala.collection.generic.GenericCompanion[scala.collection.immutable.LinearSeq with scala.collection.AbstractSeq]; def reverse: scala.collection.immutable.LinearSeq[A] with scala.collection.AbstractSeq[A]; def dropRight(n: Int): scala.collection.immutable.LinearSeq[A] with scala.collection.AbstractSeq[A]; def takeRight(n: Int): scala.collection.immutable.LinearSeq[A] with scala.collection.AbstractSeq[A]; def drop(n: Int): scala.collection.immutable.LinearSeq[A] with scala.collection.AbstractSeq[A]; def take(n: Int): scala.collection.immutable.LinearSeq[A] with scala.collection.AbstractSeq[A]; def slice(from: Int,until: Int): scala.collection.immutable.LinearSeq[A] with scala.collection.AbstractSeq[A]}; def drop(n: Int): scala.collection.immutable.LinearSeq[B[_ >: D with C <: A]] with scala.collection.AbstractSeq[B[_ >: D with C <: A]]{def companion: scala.collection.generic.GenericCompanion[scala.collection.immutable.LinearSeq with scala.collection.AbstractSeq]; def reverse: scala.collection.immutable.LinearSeq[A] with scala.collection.AbstractSeq[A]; def dropRight(n: Int): scala.collection.immutable.LinearSeq[A] with scala.collection.AbstractSeq[A]; def takeRight(n: Int): scala.collection.immutable.LinearSeq[A] with scala.collection.AbstractSeq[A]; def drop(n: Int): scala.collection.immutable.LinearSeq[A] with scala.collection.AbstractSeq[A]; def take(n: Int): scala.collection.immutable.LinearSeq[A] with scala.collection.AbstractSeq[A]; def slice(from: Int,until: Int): scala.collection.immutable.LinearSeq[A] with scala.collection.AbstractSeq[A]}; def take(n: Int): scala.collection.immutable.LinearSeq[B[_ >: D with C <: A]] with scala.collection.AbstractSeq[B[_ >: D with C <: A]]{def companion: scala.collection.generic.GenericCompanion[scala.collection.immutable.LinearSeq with scala.collection.AbstractSeq]; def reverse: scala.collection.immutable.LinearSeq[A] with scala.collection.AbstractSeq[A]; def dropRight(n: Int): scala.collection.immutable.LinearSeq[A] with scala.collection.AbstractSeq[A]; def takeRight(n: Int): scala.collection.immutable.LinearSeq[A] with scala.collection.AbstractSeq[A]; def drop(n: Int): scala.collection.immutable.LinearSeq[A] with scala.collection.AbstractSeq[A]; def take(n: Int): scala.collection.immutable.LinearSeq[A] with scala.collection.AbstractSeq[A]; def slice(from: Int,until: Int): scala.collection.immutable.LinearSeq[A] with scala.collection.AbstractSeq[A]}; def slice(from: Int,until: Int): scala.collection.immutable.LinearSeq[B[_ >: D with C <: A]] with scala.collection.AbstractSeq[B[_ >: D with C <: A]]{def companion: scala.collection.generic.GenericCompanion[scala.collection.immutable.LinearSeq with scala.collection.AbstractSeq]; def reverse: scala.collection.immutable.LinearSeq[A] with scala.collection.AbstractSeq[A]; def dropRight(n: Int): scala.collection.immutable.LinearSeq[A] with scala.collection.AbstractSeq[A]; def takeRight(n: Int): scala.collection.immutable.LinearSeq[A] with scala.collection.AbstractSeq[A]; def drop(n: Int): scala.collection.immutable.LinearSeq[A] with scala.collection.AbstractSeq[A]; def take(n: Int): scala.collection.immutable.LinearSeq[A] with scala.collection.AbstractSeq[A]; def slice(from: Int,until: Int): scala.collection.immutable.LinearSeq[A] with scala.collection.AbstractSeq[A]}; def splitAt(n: Int): (scala.collection.immutable.LinearSeq[A] with scala.collection.AbstractSeq[A], scala.collection.immutable.LinearSeq[A] with scala.collection.AbstractSeq[A])}]]
+TypeTag[List[scala.collection.immutable.Iterable[B[_ >: F with E with D with C <: B[_ >: F with E with D with C <: A]]] with F with Int => Any]]
+TypeTag[List[scala.collection.immutable.Seq[B[_ >: D with C <: B[_ >: D with C <: A]]] with scala.collection.AbstractSeq[B[_ >: D with C <: B[_ >: D with C <: A]]]{def companion: scala.collection.generic.GenericCompanion[scala.collection.immutable.Seq with scala.collection.AbstractSeq]; def dropRight(n: Int): scala.collection.immutable.Seq[B[_ >: D with C <: A]] with scala.collection.AbstractSeq[B[_ >: D with C <: A]]{def companion: scala.collection.generic.GenericCompanion[scala.collection.immutable.Seq with scala.collection.AbstractSeq]; def dropRight(n: Int): scala.collection.immutable.Seq[A] with scala.collection.AbstractSeq[A]; def takeRight(n: Int): scala.collection.immutable.Seq[A] with scala.collection.AbstractSeq[A]; def drop(n: Int): scala.collection.immutable.Seq[A] with scala.collection.AbstractSeq[A]; def take(n: Int): scala.collection.immutable.Seq[A] with scala.collection.AbstractSeq[A]; def slice(from: Int,until: Int): scala.collection.immutable.Seq[A] with scala.collection.AbstractSeq[A]; def init: scala.collection.immutable.Seq[A] with scala.collection.AbstractSeq[A]}; def takeRight(n: Int): scala.collection.immutable.Seq[B[_ >: D with C <: A]] with scala.collection.AbstractSeq[B[_ >: D with C <: A]]{def companion: scala.collection.generic.GenericCompanion[scala.collection.immutable.Seq with scala.collection.AbstractSeq]; def dropRight(n: Int): scala.collection.immutable.Seq[A] with scala.collection.AbstractSeq[A]; def takeRight(n: Int): scala.collection.immutable.Seq[A] with scala.collection.AbstractSeq[A]; def drop(n: Int): scala.collection.immutable.Seq[A] with scala.collection.AbstractSeq[A]; def take(n: Int): scala.collection.immutable.Seq[A] with scala.collection.AbstractSeq[A]; def slice(from: Int,until: Int): scala.collection.immutable.Seq[A] with scala.collection.AbstractSeq[A]; def init: scala.collection.immutable.Seq[A] with scala.collection.AbstractSeq[A]}; def drop(n: Int): scala.collection.immutable.Seq[B[_ >: D with C <: A]] with scala.collection.AbstractSeq[B[_ >: D with C <: A]]{def companion: scala.collection.generic.GenericCompanion[scala.collection.immutable.Seq with scala.collection.AbstractSeq]; def dropRight(n: Int): scala.collection.immutable.Seq[A] with scala.collection.AbstractSeq[A]; def takeRight(n: Int): scala.collection.immutable.Seq[A] with scala.collection.AbstractSeq[A]; def drop(n: Int): scala.collection.immutable.Seq[A] with scala.collection.AbstractSeq[A]; def take(n: Int): scala.collection.immutable.Seq[A] with scala.collection.AbstractSeq[A]; def slice(from: Int,until: Int): scala.collection.immutable.Seq[A] with scala.collection.AbstractSeq[A]; def init: scala.collection.immutable.Seq[A] with scala.collection.AbstractSeq[A]}; def take(n: Int): scala.collection.immutable.Seq[B[_ >: D with C <: A]] with scala.collection.AbstractSeq[B[_ >: D with C <: A]]{def companion: scala.collection.generic.GenericCompanion[scala.collection.immutable.Seq with scala.collection.AbstractSeq]; def dropRight(n: Int): scala.collection.immutable.Seq[A] with scala.collection.AbstractSeq[A]; def takeRight(n: Int): scala.collection.immutable.Seq[A] with scala.collection.AbstractSeq[A]; def drop(n: Int): scala.collection.immutable.Seq[A] with scala.collection.AbstractSeq[A]; def take(n: Int): scala.collection.immutable.Seq[A] with scala.collection.AbstractSeq[A]; def slice(from: Int,until: Int): scala.collection.immutable.Seq[A] with scala.collection.AbstractSeq[A]; def init: scala.collection.immutable.Seq[A] with scala.collection.AbstractSeq[A]}; def slice(from: Int,until: Int): scala.collection.immutable.Seq[B[_ >: D with C <: A]] with scala.collection.AbstractSeq[B[_ >: D with C <: A]]{def companion: scala.collection.generic.GenericCompanion[scala.collection.immutable.Seq with scala.collection.AbstractSeq]; def dropRight(n: Int): scala.collection.immutable.Seq[A] with scala.collection.AbstractSeq[A]; def takeRight(n: Int): scala.collection.immutable.Seq[A] with scala.collection.AbstractSeq[A]; def drop(n: Int): scala.collection.immutable.Seq[A] with scala.collection.AbstractSeq[A]; def take(n: Int): scala.collection.immutable.Seq[A] with scala.collection.AbstractSeq[A]; def slice(from: Int,until: Int): scala.collection.immutable.Seq[A] with scala.collection.AbstractSeq[A]; def init: scala.collection.immutable.Seq[A] with scala.collection.AbstractSeq[A]}; def splitAt(n: Int): (scala.collection.immutable.Seq[A] with scala.collection.AbstractSeq[A], scala.collection.immutable.Seq[A] with scala.collection.AbstractSeq[A]); def init: scala.collection.immutable.Seq[B[_ >: D with C <: A]] with scala.collection.AbstractSeq[B[_ >: D with C <: A]]{def companion: scala.collection.generic.GenericCompanion[scala.collection.immutable.Seq with scala.collection.AbstractSeq]; def dropRight(n: Int): scala.collection.immutable.Seq[A] with scala.collection.AbstractSeq[A]; def takeRight(n: Int): scala.collection.immutable.Seq[A] with scala.collection.AbstractSeq[A]; def drop(n: Int): scala.collection.immutable.Seq[A] with scala.collection.AbstractSeq[A]; def take(n: Int): scala.collection.immutable.Seq[A] with scala.collection.AbstractSeq[A]; def slice(from: Int,until: Int): scala.collection.immutable.Seq[A] with scala.collection.AbstractSeq[A]; def init: scala.collection.immutable.Seq[A] with scala.collection.AbstractSeq[A]}}]]
+TypeTag[List[scala.collection.Set[_ >: G with F <: B[_ >: G with F <: B[_ >: G with F <: A]]]]]
+TypeTag[List[scala.collection.Set[_ >: G with F <: B[_ >: G with F <: B[_ >: G with F <: A]]]]]
+TypeTag[List[scala.collection.Set[_ >: G with F <: B[_ >: G with F <: B[_ >: G with F <: A]]]]]
+TypeTag[List[Seq[B[_ >: G with F <: B[_ >: G with F <: A]]]]]
+TypeTag[List[scala.collection.Map[_ >: F with C <: B[_ >: F with C <: B[_ >: F with C <: A]], B[_ >: G with D <: B[_ >: G with D <: A]]]]]
+TypeTag[List[scala.collection.AbstractSeq[B[_ >: G with F <: B[_ >: G with F <: A]]] with scala.collection.LinearSeq[B[_ >: G with F <: B[_ >: G with F <: A]]]{def companion: scala.collection.generic.GenericCompanion[scala.collection.AbstractSeq with scala.collection.LinearSeq]; def dropRight(n: Int): scala.collection.AbstractSeq[B[_ >: G with F <: A]] with scala.collection.LinearSeq[B[_ >: G with F <: A]]{def companion: scala.collection.generic.GenericCompanion[scala.collection.AbstractSeq with scala.collection.LinearSeq]; def dropRight(n: Int): scala.collection.AbstractSeq[A] with scala.collection.LinearSeq[A]; def drop(n: Int): scala.collection.AbstractSeq[A] with scala.collection.LinearSeq[A]; def take(n: Int): scala.collection.AbstractSeq[A] with scala.collection.LinearSeq[A]; def slice(from: Int,until: Int): scala.collection.AbstractSeq[A] with scala.collection.LinearSeq[A]}; def drop(n: Int): scala.collection.AbstractSeq[B[_ >: G with F <: A]] with scala.collection.LinearSeq[B[_ >: G with F <: A]]{def companion: scala.collection.generic.GenericCompanion[scala.collection.AbstractSeq with scala.collection.LinearSeq]; def dropRight(n: Int): scala.collection.AbstractSeq[A] with scala.collection.LinearSeq[A]; def drop(n: Int): scala.collection.AbstractSeq[A] with scala.collection.LinearSeq[A]; def take(n: Int): scala.collection.AbstractSeq[A] with scala.collection.LinearSeq[A]; def slice(from: Int,until: Int): scala.collection.AbstractSeq[A] with scala.collection.LinearSeq[A]}; def take(n: Int): scala.collection.AbstractSeq[B[_ >: G with F <: A]] with scala.collection.LinearSeq[B[_ >: G with F <: A]]{def companion: scala.collection.generic.GenericCompanion[scala.collection.AbstractSeq with scala.collection.LinearSeq]; def dropRight(n: Int): scala.collection.AbstractSeq[A] with scala.collection.LinearSeq[A]; def drop(n: Int): scala.collection.AbstractSeq[A] with scala.collection.LinearSeq[A]; def take(n: Int): scala.collection.AbstractSeq[A] with scala.collection.LinearSeq[A]; def slice(from: Int,until: Int): scala.collection.AbstractSeq[A] with scala.collection.LinearSeq[A]}; def slice(from: Int,until: Int): scala.collection.AbstractSeq[B[_ >: G with F <: A]] with scala.collection.LinearSeq[B[_ >: G with F <: A]]{def companion: scala.collection.generic.GenericCompanion[scala.collection.AbstractSeq with scala.collection.LinearSeq]; def dropRight(n: Int): scala.collection.AbstractSeq[A] with scala.collection.LinearSeq[A]; def drop(n: Int): scala.collection.AbstractSeq[A] with scala.collection.LinearSeq[A]; def take(n: Int): scala.collection.AbstractSeq[A] with scala.collection.LinearSeq[A]; def slice(from: Int,until: Int): scala.collection.AbstractSeq[A] with scala.collection.LinearSeq[A]}}]]
+TypeTag[List[Seq[B[_ >: G with F <: B[_ >: G with F <: A]]]]]
+TypeTag[List[Seq[B[_ >: G with F <: B[_ >: G with F <: A]]]]]
diff --git a/test/files/run/t2251b.scala b/test/files/run/t2251b.scala
new file mode 100644
index 0000000000..b67b3aec1e
--- /dev/null
+++ b/test/files/run/t2251b.scala
@@ -0,0 +1,48 @@
+class A
+trait B[T <: B[T]] extends A
+class B1[T <: B1[T]] extends B[T]
+class C extends B[C] { override def toString = "C" }
+class D extends B[D] { override def toString = "D" }
+class E extends B[E] { override def toString = "E" }
+class F extends B[F] { override def toString = "F" }
+class G extends B1[G] { override def toString = "G" }
+
+object Test {
+ import scala.collection.{ mutable, immutable }
+ import scala.collection.immutable.{ Vector }
+ import scala.reflect.runtime.universe._
+ def what[T: TypeTag](x: T) = println(typeTag[T])
+
+ def main(args: Array[String]): Unit = {
+ what(List(List(new C), Stream(new D)))
+ what(List(List(new C), Stream(new D), Vector(new E), Set(new F)))
+ what(List(immutable.Vector(new C), Stream(new D)))
+ what(List(collection.Set(new F), mutable.Set(new G)))
+ what(List(collection.Set(new F), immutable.Set(new G)))
+ what(List(mutable.Set(new F), immutable.Set(new G)))
+ what(List(mutable.Seq(new F), immutable.Seq(new G)))
+ what(List(mutable.Map(new C -> new D), immutable.Map(new F -> new G)))
+ what(List(mutable.MutableList(new F), immutable.List(new G)))
+ what(List(mutable.Seq(new F), collection.Seq(new G)))
+ what(List(mutable.LinearSeq(new F), collection.IndexedSeq(new G)))
+ }
+}
+
+
+// class D extends B[D] { override def toString = "D" }
+
+
+// class E {
+// val ys = List(List(new C), Stream(new D))
+// }
+
+// object Test {
+// def trav = List(List(), Stream())
+
+// def main(args: Array[String]): Unit = {
+// val f = (new E).ys _
+// var xs: Set[List[_ <: Seq[B[_]]]] = Set()
+// xs += f()
+// println(xs)
+// }
+// }
diff --git a/test/pending/run/t2318.check b/test/files/run/t2318.check
index a486f1ac47..a486f1ac47 100644
--- a/test/pending/run/t2318.check
+++ b/test/files/run/t2318.check
diff --git a/test/pending/run/t2318.scala b/test/files/run/t2318.scala
index e42cbb9680..47d083eb9d 100644
--- a/test/pending/run/t2318.scala
+++ b/test/files/run/t2318.scala
@@ -7,7 +7,8 @@ object Test {
override def checkPermission(perm: Permission) = perm match {
case _: java.lang.RuntimePermission => ()
case _: java.io.FilePermission => ()
- case x: java.security.AccessControlException if x.getName contains ".networkaddress." => () // generality ftw
+ case x: java.security.SecurityPermission if x.getName contains ".networkaddress." => () // generality ftw
+ case x: java.util.PropertyPermission if x.getName == "sun.net.inetaddr.ttl" => ()
case _ => super.checkPermission(perm)
}
}
diff --git a/test/files/run/t2418.check b/test/files/run/t2418.check
new file mode 100644
index 0000000000..f599e28b8a
--- /dev/null
+++ b/test/files/run/t2418.check
@@ -0,0 +1 @@
+10
diff --git a/test/files/run/t2418.scala b/test/files/run/t2418.scala
new file mode 100644
index 0000000000..f330bef60a
--- /dev/null
+++ b/test/files/run/t2418.scala
@@ -0,0 +1,10 @@
+class Foo {
+ @volatile final var x=10
+ override def toString = "" + x
+}
+
+object Test {
+ def main(args: Array[String]): Unit = {
+ println((new Foo))
+ }
+}
diff --git a/test/files/run/t2886.check b/test/files/run/t2886.check
index ce31bc7408..cb0db8a6dc 100644
--- a/test/files/run/t2886.check
+++ b/test/files/run/t2886.check
@@ -1,5 +1,5 @@
((x: String) => {
- val x$1 = x;
- val x$2 = x;
+ <artifact> val x$1 = x;
+ <artifact> val x$2 = x;
Test.this.test(x$2, x$1)
})
diff --git a/test/files/run/t3038d.scala b/test/files/run/t3038d.scala
index 6cd2d83776..9550165235 100644
--- a/test/files/run/t3038d.scala
+++ b/test/files/run/t3038d.scala
@@ -16,9 +16,7 @@ trait Foo {
}
}
-
-@serializable
-class Bar extends Foo {
+class Bar extends Foo with Serializable {
@transient protected var first: Any = null
def size = a
@transient var second: Any = null
diff --git a/test/files/run/t3667.check b/test/files/run/t3667.check
index bbe5d1bc48..6375c88997 100644
--- a/test/files/run/t3667.check
+++ b/test/files/run/t3667.check
@@ -1,6 +1,3 @@
-1
-2
-3
4
2
3
diff --git a/test/files/run/t3667.scala b/test/files/run/t3667.scala
index f30d57ce3a..ada09d5886 100644
--- a/test/files/run/t3667.scala
+++ b/test/files/run/t3667.scala
@@ -1,27 +1,9 @@
object Test {
def main(args: Array[String]) {
- val o1 = new Outer1
- val o2 = new Outer2
- val o3 = new Outer3
val o4 = new Outer4
val o5 = new Outer5
val o6 = new Outer6
- println(1)
- ser(new o1.Inner(1))
- o1.Inner // make sure the Inner$module field of the Outer1 instance is initialized!
- ser(new o1.Inner(1))
-
- println(2)
- ser(new o2.Inner(1))
- o2.Inner
- ser(new o2.Inner(1))
-
- println(3)
- ser(new o3.Inner(1))
- o3.Inner
- ser(new o3.Inner(1))
-
println(4)
ser(new o4.Inner(1))
o4.Inner
@@ -54,23 +36,6 @@ object Test {
}
-@serializable
-class Outer1 {
- @serializable
- class Inner(x: Int = 1)
-}
-
-@serializable
-class Outer2 {
- case class Inner(x: Int = 1)
-}
-
-@serializable
-class Outer3 {
- case class Inner(x: Int)
-}
-
-
class Outer4 extends Serializable {
class Inner(x: Int = 1) extends Serializable
}
diff --git a/test/pending/run/t3897.check b/test/files/run/t3897.check
index 244b83716f..244b83716f 100644
--- a/test/pending/run/t3897.check
+++ b/test/files/run/t3897.check
diff --git a/test/pending/run/t3897/J_2.java b/test/files/run/t3897/J_2.java
index 178412dc92..178412dc92 100644
--- a/test/pending/run/t3897/J_2.java
+++ b/test/files/run/t3897/J_2.java
diff --git a/test/pending/run/t3897/a_1.scala b/test/files/run/t3897/a_1.scala
index 4da959e2ac..4da959e2ac 100644
--- a/test/pending/run/t3897/a_1.scala
+++ b/test/files/run/t3897/a_1.scala
diff --git a/test/pending/run/t3897/a_2.scala b/test/files/run/t3897/a_2.scala
index 4d9e59ef05..4d9e59ef05 100644
--- a/test/pending/run/t3897/a_2.scala
+++ b/test/files/run/t3897/a_2.scala
diff --git a/test/files/run/t4023.check b/test/files/run/t4023.check
new file mode 100644
index 0000000000..05f867c397
--- /dev/null
+++ b/test/files/run/t4023.check
@@ -0,0 +1,21 @@
+Try 1: (6 classes)
+class Test$C$B1
+class Test$C$B2
+class Test$C$B3$
+class Test$C$B4$
+class Test$C$B5$
+class Test$C$B6$
+Try 2: (6 classes)
+class Test$C$B1
+class Test$C$B2
+class Test$C$B3$
+class Test$C$B4$
+class Test$C$B5$
+class Test$C$B6$
+Try 3: (6 classes)
+class Test$C$B1
+class Test$C$B2
+class Test$C$B3$
+class Test$C$B4$
+class Test$C$B5$
+class Test$C$B6$
diff --git a/test/files/run/t4023.scala b/test/files/run/t4023.scala
new file mode 100644
index 0000000000..4846fa31b4
--- /dev/null
+++ b/test/files/run/t4023.scala
@@ -0,0 +1,23 @@
+object Test {
+ object C {
+ class B1
+ private class B2
+ object B3
+ private object B4
+ object B5 extends B1
+ private object B6 extends B2
+
+ val valuesTry1 = this.getClass.getDeclaredClasses
+ val valuesTry2 = C.getClass.getDeclaredClasses
+ val valuesTry3 = getClass.getDeclaredClasses
+ }
+
+ def main(args: Array[String]) {
+ println("Try 1: (" + C.valuesTry1.length + " classes)")
+ C.valuesTry1.foreach(println)
+ println("Try 2: (" + C.valuesTry2.length + " classes)")
+ C.valuesTry2.foreach(println)
+ println("Try 3: (" + C.valuesTry3.length + " classes)")
+ C.valuesTry3.foreach(println)
+ }
+} \ No newline at end of file
diff --git a/test/files/run/t4047.scala b/test/files/run/t4047.scala
index cd42a8b4df..08989bd278 100644
--- a/test/files/run/t4047.scala
+++ b/test/files/run/t4047.scala
@@ -18,7 +18,7 @@ class D extends Bar[Unit]{
def foo = println("Unit: called D.foo")
}
-object Test extends Application {
+object Test extends App {
val a: Foo[Unit] = new A
a.foo
a.foo
diff --git a/test/files/run/t4537.check b/test/files/run/t4537.check
new file mode 100644
index 0000000000..63739ca64a
--- /dev/null
+++ b/test/files/run/t4537.check
@@ -0,0 +1 @@
+b.Settings
diff --git a/test/files/neg/t4537/a.scala b/test/files/run/t4537/a.scala
index 65e183c5f8..125e223e13 100644
--- a/test/files/neg/t4537/a.scala
+++ b/test/files/run/t4537/a.scala
@@ -1,5 +1,5 @@
package a
private[a] object Settings {
- val X = 0
-} \ No newline at end of file
+ val X = "a.Settings"
+}
diff --git a/test/files/neg/t4537/b.scala b/test/files/run/t4537/b.scala
index bb9dd4e15a..c709d49b04 100644
--- a/test/files/neg/t4537/b.scala
+++ b/test/files/run/t4537/b.scala
@@ -1,5 +1,5 @@
package b
object Settings {
- val Y = 0
-} \ No newline at end of file
+ val Y = "b.Settings"
+}
diff --git a/test/files/run/t4537/c.scala b/test/files/run/t4537/c.scala
new file mode 100644
index 0000000000..ee05d4bbfb
--- /dev/null
+++ b/test/files/run/t4537/c.scala
@@ -0,0 +1,8 @@
+package b
+package c
+
+import a._
+
+object Unambiguous {
+ println(Settings.Y)
+}
diff --git a/test/files/run/t4537/d.scala b/test/files/run/t4537/d.scala
new file mode 100644
index 0000000000..dd1d2045ed
--- /dev/null
+++ b/test/files/run/t4537/d.scala
@@ -0,0 +1,6 @@
+import a._
+import b._
+
+object Test extends App {
+ println(Settings.Y)
+}
diff --git a/test/files/run/t4729.check b/test/files/run/t4729.check
new file mode 100644
index 0000000000..9a2aa56d99
--- /dev/null
+++ b/test/files/run/t4729.check
@@ -0,0 +1,4 @@
+WrappedArray(1, 2)
+WrappedArray(1, 2)
+WrappedArray(1, 2)
+WrappedArray(1, 2)
diff --git a/test/files/run/t4729/J_1.java b/test/files/run/t4729/J_1.java
new file mode 100644
index 0000000000..2ffb5a88d1
--- /dev/null
+++ b/test/files/run/t4729/J_1.java
@@ -0,0 +1,4 @@
+// Java Interface:
+public interface J_1 {
+ public void method(String... s);
+}
diff --git a/test/files/run/t4729/S_2.scala b/test/files/run/t4729/S_2.scala
new file mode 100644
index 0000000000..e34e3d34d4
--- /dev/null
+++ b/test/files/run/t4729/S_2.scala
@@ -0,0 +1,29 @@
+ // Scala class:
+class ScalaVarArgs extends J_1 {
+ // -- no problem on overriding it using ordinary class
+ def method(s: String*) { println(s) }
+}
+
+object Test {
+ def main(args: Array[String]) {
+ //[1] Ok - no problem using inferred type
+ val varArgs = new J_1 {
+ def method(s: String*) { println(s) }
+ }
+ varArgs.method("1", "2")
+
+ //[2] Ok -- no problem when explicit set its type after construction
+ val b: J_1 = varArgs
+ b.method("1", "2")
+
+ //[3] Ok -- no problem on calling its method
+ (new ScalaVarArgs).method("1", "2")
+ (new ScalaVarArgs: J_1).method("1", "2")
+
+ //[4] Not Ok -- error when assigning anonymous class to a explictly typed val
+ // Compiler error: object creation impossible, since method method in trait VarArgs of type (s: <repeated...>[java.lang.String])Unit is not defined
+ val tagged: J_1 = new J_1 {
+ def method(s: String*) { println(s) }
+ }
+ }
+}
diff --git a/test/files/run/t4935.flags b/test/files/run/t4935.flags
index ac14fe5dbd..49d036a887 100644
--- a/test/files/run/t4935.flags
+++ b/test/files/run/t4935.flags
@@ -1 +1 @@
--optimize
+-optimize
diff --git a/test/files/run/t4996.check b/test/files/run/t4996.check
new file mode 100644
index 0000000000..8d45b413c9
--- /dev/null
+++ b/test/files/run/t4996.check
@@ -0,0 +1,4 @@
+B.foo
+M.foo
+B.foo
+M.foo \ No newline at end of file
diff --git a/test/files/run/t4996.scala b/test/files/run/t4996.scala
new file mode 100644
index 0000000000..8e7636aaac
--- /dev/null
+++ b/test/files/run/t4996.scala
@@ -0,0 +1,47 @@
+
+
+
+
+
+
+trait A[@specialized(Int) T] {
+ def foo(t: T)
+}
+
+
+trait B extends A[Int] {
+ def foo(t: Int) {
+ println("B.foo")
+ }
+}
+
+
+trait M extends B {
+ abstract override def foo(t: Int) {
+ super.foo(t)
+ println("M.foo")
+ }
+}
+
+
+object C extends B with M
+
+
+object D extends B {
+ override def foo(t: Int) {
+ super.foo(t)
+ println("M.foo")
+ }
+}
+
+
+object Test {
+
+ def main(args: Array[String]) {
+ D.foo(42) // OK, prints B.foo M.foo
+ C.foo(42) // was StackOverflowError
+ }
+
+}
+
+
diff --git a/test/pending/run/t5293-map.scala b/test/files/run/t5293-map.scala
index 2707aed07e..2707aed07e 100644
--- a/test/pending/run/t5293-map.scala
+++ b/test/files/run/t5293-map.scala
diff --git a/test/pending/run/t5293.scala b/test/files/run/t5293.scala
index 01ead45d2a..01ead45d2a 100644
--- a/test/pending/run/t5293.scala
+++ b/test/files/run/t5293.scala
diff --git a/test/files/run/t5374.check b/test/files/run/t5374.check
index 6be88d77ec..c1cd843080 100644
--- a/test/files/run/t5374.check
+++ b/test/files/run/t5374.check
@@ -2,5 +2,4 @@ ListBuffer(1, 2, 3, 1)
ListBuffer(1, 2, 3, 1)
ListBuffer()
List(1, 2, 3, 4, 5)
-List(1, 2, 3)
-ok \ No newline at end of file
+ok
diff --git a/test/files/run/t5374.scala b/test/files/run/t5374.scala
index 9b1671e795..f6a913e35c 100644
--- a/test/files/run/t5374.scala
+++ b/test/files/run/t5374.scala
@@ -7,15 +7,15 @@ import java.io._
object Test {
-
+
def main(args: Array[String]) {
ticketExample()
emptyListBuffer()
list()
- legacyList()
+ // legacyList()
objectWithMultipleLists()
}
-
+
def inAndOut[T <: AnyRef](obj: T): T = {
val baos = new ByteArrayOutputStream
val oos = new ObjectOutputStream(baos)
@@ -24,53 +24,53 @@ object Test {
val ois = new ObjectInputStream(bais)
ois.readObject.asInstanceOf[T]
}
-
+
def ticketExample() {
val lb = inAndOut(ListBuffer(1, 2, 3))
val lb2 = ListBuffer[Int]() ++= lb
-
+
lb2 ++= List(1)
lb ++= List(1)
println(lb)
println(lb2)
}
-
+
def emptyListBuffer() {
val lb = inAndOut(ListBuffer[Int]())
-
+
println(lb)
}
-
+
def list() {
val l = inAndOut(List(1, 2, 3, 4, 5))
-
+
println(l)
}
-
+
// this byte array corresponds to what List(1, 2, 3) used to be serialized to prior to this fix
val listBytes = Array[Byte](-84, -19, 0, 5, 115, 114, 0, 39, 115, 99, 97, 108, 97, 46, 99, 111, 108, 108, 101, 99, 116, 105, 111, 110, 46, 105, 109, 109, 117, 116, 97, 98, 108, 101, 46, 36, 99, 111, 108, 111, 110, 36, 99, 111, 108, 111, 110, -118, 92, 99, 91, -10, -40, -7, 109, 3, 0, 2, 76, 0, 43, 115, 99, 97, 108, 97, 36, 99, 111, 108, 108, 101, 99, 116, 105, 111, 110, 36, 105, 109, 109, 117, 116, 97, 98, 108, 101, 36, 36, 99, 111, 108, 111, 110, 36, 99, 111, 108, 111, 110, 36, 36, 104, 100, 116, 0, 18, 76, 106, 97, 118, 97, 47, 108, 97, 110, 103, 47, 79, 98, 106, 101, 99, 116, 59, 76, 0, 2, 116, 108, 116, 0, 33, 76, 115, 99, 97, 108, 97, 47, 99, 111, 108, 108, 101, 99, 116, 105, 111, 110, 47, 105, 109, 109, 117, 116, 97, 98, 108, 101, 47, 76, 105, 115, 116, 59, 120, 112, 115, 114, 0, 17, 106, 97, 118, 97, 46, 108, 97, 110, 103, 46, 73, 110, 116, 101, 103, 101, 114, 18, -30, -96, -92, -9, -127, -121, 56, 2, 0, 1, 73, 0, 5, 118, 97, 108, 117, 101, 120, 114, 0, 16, 106, 97, 118, 97, 46, 108, 97, 110, 103, 46, 78, 117, 109, 98, 101, 114, -122, -84, -107, 29, 11, -108, -32, -117, 2, 0, 0, 120, 112, 0, 0, 0, 1, 115, 113, 0, 126, 0, 4, 0, 0, 0, 2, 115, 113, 0, 126, 0, 4, 0, 0, 0, 3, 115, 114, 0, 44, 115, 99, 97, 108, 97, 46, 99, 111, 108, 108, 101, 99, 116, 105, 111, 110, 46, 105, 109, 109, 117, 116, 97, 98, 108, 101, 46, 76, 105, 115, 116, 83, 101, 114, 105, 97, 108, 105, 122, 101, 69, 110, 100, 36, -118, 92, 99, 91, -9, 83, 11, 109, 2, 0, 0, 120, 112, 120)
-
- def legacyList() {
- val bais = new ByteArrayInputStream(listBytes)
- val ois = new ObjectInputStream(bais)
- val l = ois.readObject()
-
- println(l)
- }
-
+
+ // def legacyList() {
+ // val bais = new ByteArrayInputStream(listBytes)
+ // val ois = new ObjectInputStream(bais)
+ // val l = ois.readObject()
+
+ // println(l)
+ // }
+
class Foo extends Serializable {
val head = List(1, 2, 3)
val last = head.tail.tail
def structuralSharing: Boolean = head.tail.tail eq last
-
+
assert(structuralSharing)
}
-
+
def objectWithMultipleLists() {
val foo = inAndOut(new Foo)
-
+
if (foo.structuralSharing) println("ok")
else println("no structural sharing")
}
-
+
}
diff --git a/test/pending/run/t5418.check b/test/files/run/t5418.check
index e69de29bb2..e69de29bb2 100644
--- a/test/pending/run/t5418.check
+++ b/test/files/run/t5418.check
diff --git a/test/pending/run/t5418.scala b/test/files/run/t5418.scala
index e3cb20cf82..e3cb20cf82 100644
--- a/test/pending/run/t5418.scala
+++ b/test/files/run/t5418.scala
diff --git a/test/files/run/t5604.check b/test/files/run/t5604.check
new file mode 100644
index 0000000000..53a2fc8894
--- /dev/null
+++ b/test/files/run/t5604.check
@@ -0,0 +1,8 @@
+long
+double
+long
+double
+long
+double
+long
+double
diff --git a/test/files/run/t5604.scala b/test/files/run/t5604.scala
new file mode 100644
index 0000000000..a06c8aab3e
--- /dev/null
+++ b/test/files/run/t5604.scala
@@ -0,0 +1,50 @@
+// a.scala
+// Fri Jan 13 11:31:47 PST 2012
+
+package foo {
+ object regular extends Duh {
+ def buh(n: Long) = println("long")
+ def buh(n: Double) = println("double")
+ }
+ class regular {
+ import regular._
+
+ duh(33L)
+ duh(3.0d)
+ foo.regular.duh(33L)
+ foo.regular.duh(3.0d)
+ buh(66L)
+ buh(6.0d)
+ foo.regular.buh(66L)
+ foo.regular.buh(6.0d)
+ }
+
+ trait Duh {
+ def duh(n: Long) = println("long")
+ def duh(n: Double) = println("double")
+ }
+ package object bar extends Duh {
+ def buh(n: Long) = println("long")
+ def buh(n: Double) = println("double")
+ }
+ package bar {
+ object Main {
+ def main(args:Array[String]) {
+ duh(33L)
+ duh(3.0d)
+ foo.bar.duh(33L)
+ foo.bar.duh(3.0d)
+ buh(66L)
+ buh(6.0d)
+ foo.bar.buh(66L)
+ foo.bar.buh(6.0d)
+ }
+ }
+ }
+}
+
+object Test {
+ def main(args: Array[String]): Unit = {
+ foo.bar.Main.main(null)
+ }
+}
diff --git a/test/pending/run/t5610a.check b/test/files/run/t5610a.check
index 2aa46b3b91..2aa46b3b91 100644
--- a/test/pending/run/t5610a.check
+++ b/test/files/run/t5610a.check
diff --git a/test/pending/run/t5610a.scala b/test/files/run/t5610a.scala
index f20b295762..f20b295762 100644
--- a/test/pending/run/t5610a.scala
+++ b/test/files/run/t5610a.scala
diff --git a/test/files/run/t6028.check b/test/files/run/t6028.check
index 34f4b22134..42921ae2f5 100644
--- a/test/files/run/t6028.check
+++ b/test/files/run/t6028.check
@@ -31,14 +31,14 @@ package <empty> {
};
final def apply(): Int = $anonfun$foo$1.this.apply$mcI$sp();
<specialized> def apply$mcI$sp(): Int = $anonfun$foo$1.this.$outer.T$$classParam.+($anonfun$foo$1.this.$outer.field()).+($anonfun$foo$1.this.methodParam$1).+($anonfun$foo$1.this.methodLocal$1);
- <synthetic> <paramaccessor> private[this] val $outer: T = _;
- <synthetic> <stable> def T$$anonfun$$$outer(): T = $anonfun$foo$1.this.$outer;
- final <bridge> def apply(): Object = scala.Int.box($anonfun$foo$1.this.apply());
+ <synthetic> <paramaccessor> <artifact> private[this] val $outer: T = _;
+ <synthetic> <stable> <artifact> def T$$anonfun$$$outer(): T = $anonfun$foo$1.this.$outer;
+ final <bridge> <artifact> def apply(): Object = scala.Int.box($anonfun$foo$1.this.apply());
<synthetic> <paramaccessor> private[this] val methodParam$1: Int = _;
<synthetic> <paramaccessor> private[this] val methodLocal$1: Int = _
};
abstract trait MethodLocalTrait$1 extends Object {
- <synthetic> <stable> def T$MethodLocalTrait$$$outer(): T
+ <synthetic> <stable> <artifact> def T$MethodLocalTrait$$$outer(): T
};
object MethodLocalObject$2 extends Object with T#MethodLocalTrait$1 {
def <init>($outer: T, barParam$1: Int): T#MethodLocalObject$2.type = {
@@ -46,9 +46,9 @@ package <empty> {
MethodLocalObject$2.this.$asInstanceOf[T#MethodLocalTrait$1$class]()./*MethodLocalTrait$1$class*/$init$(barParam$1);
()
};
- <synthetic> <paramaccessor> private[this] val $outer: T = _;
- <synthetic> <stable> def T$MethodLocalObject$$$outer(): T = MethodLocalObject$2.this.$outer;
- <synthetic> <stable> def T$MethodLocalTrait$$$outer(): T = MethodLocalObject$2.this.$outer
+ <synthetic> <paramaccessor> <artifact> private[this] val $outer: T = _;
+ <synthetic> <stable> <artifact> def T$MethodLocalObject$$$outer(): T = MethodLocalObject$2.this.$outer;
+ <synthetic> <stable> <artifact> def T$MethodLocalTrait$$$outer(): T = MethodLocalObject$2.this.$outer
};
final <stable> private[this] def MethodLocalObject$1(barParam$1: Int, MethodLocalObject$module$1: runtime.VolatileObjectRef): T#MethodLocalObject$2.type = {
MethodLocalObject$module$1.elem = new T#MethodLocalObject$2.type(T.this, barParam$1);
@@ -69,9 +69,9 @@ package <empty> {
<specialized> def apply$mcV$sp(): Unit = try {
$anonfun$tryy$1.this.tryyLocal$1.elem = $anonfun$tryy$1.this.tryyParam$1
} finally ();
- <synthetic> <paramaccessor> private[this] val $outer: T = _;
- <synthetic> <stable> def T$$anonfun$$$outer(): T = $anonfun$tryy$1.this.$outer;
- final <bridge> def apply(): Object = {
+ <synthetic> <paramaccessor> <artifact> private[this] val $outer: T = _;
+ <synthetic> <stable> <artifact> def T$$anonfun$$$outer(): T = $anonfun$tryy$1.this.$outer;
+ final <bridge> <artifact> def apply(): Object = {
$anonfun$tryy$1.this.apply();
scala.runtime.BoxedUnit.UNIT
};
diff --git a/test/files/run/t6064.scala b/test/files/run/t6064.scala
new file mode 100644
index 0000000000..fc184dd92d
--- /dev/null
+++ b/test/files/run/t6064.scala
@@ -0,0 +1,9 @@
+object Test extends App {
+ assert(Option(42) contains 42)
+ assert(Some(42) contains 42)
+ assert(Option(BigInt(42)) contains 42)
+ assert(Option(42) contains BigInt(42))
+ assert(!(None contains 42))
+ assert(Some(null) contains null)
+ assert(!(Option(null) contains null))
+} \ No newline at end of file
diff --git a/test/files/run/t6150.scala b/test/files/run/t6150.scala
index bd8af5d460..f3e83e1549 100644
--- a/test/files/run/t6150.scala
+++ b/test/files/run/t6150.scala
@@ -1,7 +1,3 @@
-
-
-
-
object Test {
import collection.{ immutable, mutable, generic }
def TheOneTrueCBF = collection.IndexedSeq.ReusableCBF
@@ -38,7 +34,3 @@ object Test {
check(iv.:+(4)(cbf3))
}
}
-
-
-
-
diff --git a/test/files/run/t6154.check b/test/files/run/t6154.check
new file mode 100644
index 0000000000..9766475a41
--- /dev/null
+++ b/test/files/run/t6154.check
@@ -0,0 +1 @@
+ok
diff --git a/test/files/run/t6154.scala b/test/files/run/t6154.scala
new file mode 100644
index 0000000000..02ef62905f
--- /dev/null
+++ b/test/files/run/t6154.scala
@@ -0,0 +1,10 @@
+object Test {
+ def foo(a: Int) {
+ var bar: Int = 0
+ bar = try { 0 } catch { case ex: Throwable => 0 }
+ new { foo(bar) }
+ }
+
+ def main(args: Array[String]): Unit =
+ try foo(0) catch { case _: java.lang.StackOverflowError => println("ok") }
+}
diff --git a/test/files/run/t6206.check b/test/files/run/t6206.check
new file mode 100644
index 0000000000..8064573667
--- /dev/null
+++ b/test/files/run/t6206.check
@@ -0,0 +1,4 @@
+outer
+outer
+inner
+inner
diff --git a/test/files/run/t6206.scala b/test/files/run/t6206.scala
new file mode 100644
index 0000000000..07ff246d02
--- /dev/null
+++ b/test/files/run/t6206.scala
@@ -0,0 +1,37 @@
+class Outer {
+ def apply( position : Inner ) {}
+ class Inner
+
+ this.apply(new Inner)
+ this (new Inner) // error,
+}
+
+
+class Outer1 {
+
+ self =>
+
+ def apply( position : Inner ) : String = "outer"
+
+ class Inner( ) {
+
+ def apply(arg: Inner): String = "inner"
+
+ def testMe = {
+ List(
+ self.apply( this ), // a) this works
+ self( this ), // b) this does not work!
+ this apply this,
+ this(this)
+ ) foreach println
+ }
+ }
+}
+
+object Test {
+ def main(args: Array[String]): Unit = {
+ val o = new Outer1
+ val i = new o.Inner
+ i.testMe
+ }
+}
diff --git a/test/files/run/t6223.check b/test/files/run/t6223.check
index 90ec019407..4a09d1930f 100644
--- a/test/files/run/t6223.check
+++ b/test/files/run/t6223.check
@@ -1,4 +1,4 @@
bar
-bar$mcI$sp
bar$mIc$sp
bar$mIcI$sp
+bar$mcI$sp
diff --git a/test/files/run/t6223.scala b/test/files/run/t6223.scala
index 4ab7c832e6..fb176e32e6 100644
--- a/test/files/run/t6223.scala
+++ b/test/files/run/t6223.scala
@@ -5,7 +5,7 @@ class Foo[@specialized(Int) A](a:A) {
object Test {
def main(args:Array[String]) {
val f = new Foo(333)
- val ms = f.getClass().getDeclaredMethods()
+ val ms = f.getClass().getDeclaredMethods().sortBy(_.getName)
ms.foreach(m => println(m.getName))
}
}
diff --git a/test/files/run/t6288.check b/test/files/run/t6288.check
index af6bd5d269..0a8ff0b92d 100644
--- a/test/files/run/t6288.check
+++ b/test/files/run/t6288.check
@@ -66,7 +66,7 @@
[273]case5()[293]{
[293]<synthetic> val o7: [293]Option[List[Int]] = [293][293]Case4.unapplySeq([293]x1);
[293]if ([293]o7.isEmpty.unary_!)
- [293]if ([293][293][293][293]o7.get.!=([293]null).&&([293][293][293][293]o7.get.lengthCompare([293]0).==([195]0)))
+ [293]if ([293][293][293][293]o7.get.!=([293]null).&&([293][293][293][293]o7.get.lengthCompare([293]0).==([293]0)))
[304][304]matchEnd4([304]())
else
[293][293]case6()
diff --git a/test/files/run/t6381.check b/test/files/run/t6381.check
new file mode 100644
index 0000000000..b51cfd0398
--- /dev/null
+++ b/test/files/run/t6381.check
@@ -0,0 +1,17 @@
+Type in expressions to have them evaluated.
+Type :help for more information.
+
+scala> import language.experimental.macros
+import language.experimental.macros
+
+scala> def pos_impl(c: reflect.macros.Context): c.Expr[String] =
+ c.literal(c.enclosingPosition.getClass.toString)
+pos_impl: (c: scala.reflect.macros.Context)c.Expr[String]
+
+scala> def pos = macro pos_impl
+pos: String
+
+scala> pos
+res0: String = class scala.reflect.internal.util.RangePosition
+
+scala>
diff --git a/test/files/run/t6381.scala b/test/files/run/t6381.scala
new file mode 100644
index 0000000000..859ec3cb30
--- /dev/null
+++ b/test/files/run/t6381.scala
@@ -0,0 +1,13 @@
+import scala.tools.partest.ReplTest
+
+object Test extends ReplTest {
+ def code = """
+ |import language.experimental.macros
+ |def pos_impl(c: reflect.macros.Context): c.Expr[String] =
+ | c.literal(c.enclosingPosition.getClass.toString)
+ |def pos = macro pos_impl
+ |pos
+ |""".stripMargin.trim
+
+ override def extraSettings: String = "-Yrangepos"
+}
diff --git a/test/files/run/t6406-regextract.check b/test/files/run/t6406-regextract.check
new file mode 100644
index 0000000000..88c5a52eb3
--- /dev/null
+++ b/test/files/run/t6406-regextract.check
@@ -0,0 +1,4 @@
+List(1, 3)
+List(1, 3)
+List(1, 3)
+Some(2011) Some(2011)
diff --git a/test/files/run/t6406-regextract.scala b/test/files/run/t6406-regextract.scala
new file mode 100644
index 0000000000..83679a5167
--- /dev/null
+++ b/test/files/run/t6406-regextract.scala
@@ -0,0 +1,30 @@
+
+object Test extends App {
+ import util.matching._
+ import Regex._
+
+ val r = "(\\d+)".r
+ val q = """(\d)""".r
+ val ns = List("1,2","x","3,4")
+ val u = r.unanchored
+
+ val is = ns collect { case u(x) => x } map { case r(x) => x }
+ println(is)
+ // Match from same pattern
+ val js = (ns map { u findFirstMatchIn _ }).flatten map { case r(x) => x }
+ println(js)
+ // Match not from same pattern
+ val ks = (ns map { q findFirstMatchIn _ }).flatten map { case r(x) => x }
+ println(ks)
+
+ val t = "Last modified 2011-07-15"
+ val p1 = """(\d\d\d\d)-(\d\d)-(\d\d)""".r
+ val y1: Option[String] = for {
+ p1(year, month, day) <- p1 findFirstIn t
+ } yield year
+ val y2: Option[String] = for {
+ p1(year, month, day) <- p1 findFirstMatchIn t
+ } yield year
+ println(s"$y1 $y2")
+
+}
diff --git a/test/files/run/t6448.check b/test/files/run/t6448.check
new file mode 100644
index 0000000000..9401568319
--- /dev/null
+++ b/test/files/run/t6448.check
@@ -0,0 +1,32 @@
+
+=List.collect=
+f(1)
+f(2)
+List(1)
+
+=List.collectFirst=
+f(1)
+Some(1)
+
+=Option.collect=
+f(1)
+Some(1)
+
+=Option.collect=
+f(2)
+None
+
+=Stream.collect=
+f(1)
+f(2)
+List(1)
+
+=Stream.collectFirst=
+f(1)
+Some(1)
+
+=ParVector.collect=
+(ParVector(1),2)
+
+=ParArray.collect=
+(ParArray(1),2)
diff --git a/test/files/run/t6448.scala b/test/files/run/t6448.scala
new file mode 100644
index 0000000000..4d1528e500
--- /dev/null
+++ b/test/files/run/t6448.scala
@@ -0,0 +1,61 @@
+// Tests to show that various `collect` functions avoid calling
+// both `PartialFunction#isDefinedAt` and `PartialFunction#apply`.
+//
+object Test {
+ def f(i: Int) = { println("f(" + i + ")"); true }
+ class Counter {
+ var count = 0
+ def apply(i: Int) = synchronized {count += 1; true}
+ }
+
+ def testing(label: String)(body: => Any) {
+ println(s"\n=$label=")
+ println(body)
+ }
+
+ def main(args: Array[String]) {
+ testing("List.collect")(List(1, 2) collect { case x if f(x) && x < 2 => x})
+ testing("List.collectFirst")(List(1, 2) collectFirst { case x if f(x) && x < 2 => x})
+ testing("Option.collect")(Some(1) collect { case x if f(x) && x < 2 => x})
+ testing("Option.collect")(Some(2) collect { case x if f(x) && x < 2 => x})
+ testing("Stream.collect")((Stream(1, 2).collect { case x if f(x) && x < 2 => x}).toList)
+ testing("Stream.collectFirst")(Stream.continually(1) collectFirst { case x if f(x) && x < 2 => x})
+
+ import collection.parallel.ParIterable
+ import collection.parallel.immutable.ParVector
+ import collection.parallel.mutable.ParArray
+ testing("ParVector.collect") {
+ val counter = new Counter()
+ (ParVector(1, 2) collect { case x if counter(x) && x < 2 => x}, counter.synchronized(counter.count))
+ }
+
+ testing("ParArray.collect") {
+ val counter = new Counter()
+ (ParArray(1, 2) collect { case x if counter(x) && x < 2 => x}, counter.synchronized(counter.count))
+ }
+
+ object PendingTests {
+ testing("Iterator.collect")((Iterator(1, 2) collect { case x if f(x) && x < 2 => x}).toList)
+
+ testing("List.view.collect")((List(1, 2).view collect { case x if f(x) && x < 2 => x}).force)
+
+ // This would do the trick in Future.collect, but I haven't added this yet as there is a tradeoff
+ // with extra allocations to consider.
+ //
+ // pf.lift(v) match {
+ // case Some(x) => p success x
+ // case None => fail(v)
+ // }
+ testing("Future.collect") {
+ import concurrent.ExecutionContext.Implicits.global
+ import concurrent.Await
+ import concurrent.duration.Duration
+ val result = concurrent.future(1) collect { case x if f(x) => x}
+ Await.result(result, Duration.Inf)
+ }
+
+ // TODO Future.{onSuccess, onFailure, recoverWith, andThen}
+ }
+
+ }
+}
diff --git a/test/files/run/t6467.scala b/test/files/run/t6467.scala
new file mode 100644
index 0000000000..dc93b69fdc
--- /dev/null
+++ b/test/files/run/t6467.scala
@@ -0,0 +1,20 @@
+
+
+
+
+import collection._
+
+
+
+object Test extends App {
+
+ def compare(s1: String, s2: String) {
+ assert(s1 == s2, s1 + "\nvs.\n" + s2)
+ }
+
+ compare(List(1, 2, 3, 4).aggregate(new java.lang.StringBuffer)(_ append _, _ append _).toString, "1234")
+ compare(List(1, 2, 3, 4).par.aggregate(new java.lang.StringBuffer)(_ append _, _ append _).toString, "1234")
+ compare(Seq(0 until 100: _*).aggregate(new java.lang.StringBuffer)(_ append _, _ append _).toString, (0 until 100).mkString)
+ compare(Seq(0 until 100: _*).par.aggregate(new java.lang.StringBuffer)(_ append _, _ append _).toString, (0 until 100).mkString)
+
+} \ No newline at end of file
diff --git a/test/files/run/t6584.check b/test/files/run/t6584.check
new file mode 100644
index 0000000000..35c8688751
--- /dev/null
+++ b/test/files/run/t6584.check
@@ -0,0 +1,8 @@
+Array: 102400
+Vector: 102400
+List: 102400
+Stream: 102400
+Array: 102400
+Vector: 102400
+List: 102400
+Stream: 102400
diff --git a/test/files/run/t6584.scala b/test/files/run/t6584.scala
new file mode 100644
index 0000000000..24c236ef35
--- /dev/null
+++ b/test/files/run/t6584.scala
@@ -0,0 +1,16 @@
+object Test {
+ def main(args: Array[String]): Unit = {
+ val size = 100 * 1024
+ val doubled = (1 to size) ++ (1 to size)
+
+ println("Array: " + Array.tabulate(size)(x => x).distinct.size)
+ println("Vector: " + Vector.tabulate(size)(x => x).distinct.size)
+ println("List: " + List.tabulate(size)(x => x).distinct.size)
+ println("Stream: " + Stream.tabulate(size)(x => x).distinct.size)
+
+ println("Array: " + doubled.toArray.distinct.size)
+ println("Vector: " + doubled.toVector.distinct.size)
+ println("List: " + doubled.toList.distinct.size)
+ println("Stream: " + doubled.toStream.distinct.size)
+ }
+}
diff --git a/test/files/run/t6611.scala b/test/files/run/t6611.scala
new file mode 100644
index 0000000000..c295368aea
--- /dev/null
+++ b/test/files/run/t6611.scala
@@ -0,0 +1,61 @@
+object Test extends App {
+ locally {
+ val a = Array("1")
+ val a2 = Array(a: _*)
+ assert(a ne a2)
+ }
+
+ locally {
+ val a = Array("1": Object)
+ val a2 = Array(a: _*)
+ assert(a ne a2)
+ }
+
+ locally {
+ val a = Array(true)
+ val a2 = Array(a: _*)
+ assert(a ne a2)
+ }
+
+ locally {
+ val a = Array(1: Short)
+ val a2 = Array(a: _*)
+ assert(a ne a2)
+ }
+
+ locally {
+ val a = Array(1: Byte)
+ val a2 = Array(a: _*)
+ assert(a ne a2)
+ }
+
+ locally {
+ val a = Array(1)
+ val a2 = Array(a: _*)
+ assert(a ne a2)
+ }
+
+ locally {
+ val a = Array(1L)
+ val a2 = Array(a: _*)
+ assert(a ne a2)
+ }
+
+ locally {
+ val a = Array(1f)
+ val a2 = Array(a: _*)
+ assert(a ne a2)
+ }
+
+ locally {
+ val a = Array(1d)
+ val a2 = Array(a: _*)
+ assert(a ne a2)
+ }
+
+ locally {
+ val a = Array(())
+ val a2 = Array(a: _*)
+ assert(a ne a2)
+ }
+}
diff --git a/test/files/run/t6637.check b/test/files/run/t6637.check
new file mode 100644
index 0000000000..9766475a41
--- /dev/null
+++ b/test/files/run/t6637.check
@@ -0,0 +1 @@
+ok
diff --git a/test/files/run/t6637.scala b/test/files/run/t6637.scala
new file mode 100644
index 0000000000..d3c380370b
--- /dev/null
+++ b/test/files/run/t6637.scala
@@ -0,0 +1,8 @@
+
+object Test extends App {
+ try {
+ class A ; class B ; List().head.isInstanceOf[A with B]
+ } catch {
+ case _ :java.util.NoSuchElementException => println("ok")
+ }
+}
diff --git a/test/files/run/t6745-2.scala b/test/files/run/t6745-2.scala
new file mode 100644
index 0000000000..31ecd42bd1
--- /dev/null
+++ b/test/files/run/t6745-2.scala
@@ -0,0 +1,22 @@
+import scala.tools.nsc._
+import scala.tools.partest.CompilerTest
+import scala.collection.{ mutable, immutable, generic }
+
+object Test extends CompilerTest {
+ import global._
+ import rootMirror._
+ import definitions._
+ import global.analyzer.{Context, ImportInfo}
+
+ override def code = """
+package context {
+}
+ """
+
+ def check(source: String, unit: global.CompilationUnit) = {
+ val context: Context = global.analyzer.rootContext(unit)
+ val importInfo: ImportInfo = context.imports.head // Predef._
+ val importedSym = importInfo.importedSymbol(nme.CONSTRUCTOR)
+ assert(importedSym == NoSymbol, importedSym) // was "constructor Predef"
+ }
+}
diff --git a/test/flaky/pos/t2868.cmds b/test/flaky/pos/t2868.cmds
deleted file mode 100644
index ed8124a9e0..0000000000
--- a/test/flaky/pos/t2868.cmds
+++ /dev/null
@@ -1,3 +0,0 @@
-javac Jann.java Nest.java
-scalac pick_1.scala
-scalac test_2.scala
diff --git a/test/partest b/test/partest
index 8352f8a946..ae60c49929 100755
--- a/test/partest
+++ b/test/partest
@@ -70,6 +70,12 @@ if $cygwin; then
else
format=windows
fi
+ if [ -n "${JAVA_HOME}" ] ; then
+ JAVA_HOME=`cygpath --$format "$JAVA_HOME"`
+ fi
+ if [ -n "${JAVACMD}" ] ; then
+ JAVACMD=`cygpath --$format "$JAVACMD"`
+ fi
SCALA_HOME=`cygpath --$format "$SCALA_HOME"`
EXT_CLASSPATH=`cygpath --path --$format "$EXT_CLASSPATH"`
fi
@@ -84,7 +90,7 @@ if [ ! -z "${PARTEST_DEBUG}" ] ; then
partestDebugStr="-Dpartest.debug=${PARTEST_DEBUG}"
fi
-${JAVACMD:=java} \
+"${JAVACMD:=java}" \
$JAVA_OPTS -cp "$EXT_CLASSPATH" \
${partestDebugStr} \
-Dscala.home="${SCALA_HOME}" \
diff --git a/test/pending/jvm/cf-attributes.scala b/test/pending/jvm/cf-attributes.scala
index 9e0e9d95de..f4964b63b1 100644
--- a/test/pending/jvm/cf-attributes.scala
+++ b/test/pending/jvm/cf-attributes.scala
@@ -52,14 +52,14 @@ object anonymousFunctions {
}
object anonymousClasses {
- //InnerClass:
+ //InnerClass:
// public abstract #_= #_ of #_; //Foo=class anonymousClasses$Foo of class anonymousClasses$
// public abstract #_= #_ of #_; //Foo$class=class anonymousClasses$Foo$class of class anonymousClasses$
trait Foo {
def foo() { println("foo"); }
override def toString = getClass.getName
}
- //InnerClass:
+ //InnerClass:
// public final #_; //class anonymousClasses$$anon$1 of class anonymousClasses$
val x = new Foo() {
override def foo() { println("foo (overriden)"); }
@@ -88,16 +88,16 @@ trait Test1 {
trait Test2 {
@throws(classOf[Exception])
- def printInnerClasses(cls: Class[_]) {
- import java.io._, ch.epfl.lamp.fjbg._
- val fjbgContext = new FJBGContext(49, 0)
- val outDir = System.getProperty("partest.output", "cf-attributes.obj")
- val fileName = outDir+File.separator+cls.getName+".class"
- val in = new DataInputStream(new FileInputStream(fileName))
- val jclass = fjbgContext.JClass(in)
- println(jclass.getInnerClasses)
- in.close()
- }
+ // def printInnerClasses(cls: Class[_]) {
+ // import java.io._, ch.epfl.lamp.fjbg._
+ // val fjbgContext = new FJBGContext(49, 0)
+ // val outDir = System.getProperty("partest.output", "cf-attributes.obj")
+ // val fileName = outDir+File.separator+cls.getName+".class"
+ // val in = new DataInputStream(new FileInputStream(fileName))
+ // val jclass = fjbgContext.JClass(in)
+ // println(jclass.getInnerClasses)
+ // in.close()
+ // }
def printClass(name: String) {
try { printClass(Class.forName(name)) }
catch { case e: Exception => println(e) }
@@ -105,7 +105,7 @@ trait Test2 {
def printClass(cls: Class[_]) {
println("\n[[ "+cls.getName+" ]]");
try { printInnerClasses(cls) }
- catch { case e: Exception => println(e) }
+ catch { case e: Exception => println(e) }
}
}
diff --git a/test/pending/pos/overloading-boundaries.scala b/test/pending/pos/overloading-boundaries.scala
new file mode 100644
index 0000000000..d2e9fdbb12
--- /dev/null
+++ b/test/pending/pos/overloading-boundaries.scala
@@ -0,0 +1,37 @@
+package bar {
+ object bippy extends (Double => String) {
+ def apply(x: Double): String = "Double"
+ }
+}
+
+package object bar {
+ def bippy(x: Int, y: Int, z: Int) = "(Int, Int, Int)"
+}
+
+object Test {
+ def main(args: Array[String]): Unit = {
+ println(bar.bippy(5.5d))
+ println(bar.bippy(1, 2, 3))
+ }
+}
+
+/****
+
+% scalac3 a.scala
+a.scala:13: error: not enough arguments for method bippy: (x: Int, y: Int, z: Int)String.
+Unspecified value parameters y, z.
+ println(bar.bippy(5.5d))
+ ^
+one error found
+
+# Comment out the call to bar.bippy(5.5d) - compiles
+% scalac3 a.scala
+
+# Compiles only from pure source though - if classes are present, fails.
+% scalac3 a.scala
+a.scala:2: error: bippy is already defined as method bippy in package object bar
+ object bippy extends (Double => String) {
+ ^
+one error found
+
+****/
diff --git a/test/pending/pos/t1751.cmds b/test/pending/pos/t1751.cmds
deleted file mode 100644
index d4a4898ffd..0000000000
--- a/test/pending/pos/t1751.cmds
+++ /dev/null
@@ -1,3 +0,0 @@
-javac SuiteClasses.java
-scalac A2_1.scala
-scalac A1_2.scala
diff --git a/test/pending/pos/t1782.cmds b/test/pending/pos/t1782.cmds
deleted file mode 100644
index 61f3d3788e..0000000000
--- a/test/pending/pos/t1782.cmds
+++ /dev/null
@@ -1,2 +0,0 @@
-javac Ann.java Days.java ImplementedBy.java
-scalac Test_1.scala
diff --git a/test/pending/pos/t1832.scala b/test/pending/pos/t1832.scala
deleted file mode 100644
index bca863f4bd..0000000000
--- a/test/pending/pos/t1832.scala
+++ /dev/null
@@ -1,10 +0,0 @@
-// Edit by paulp: reduced.
-trait Cloning {
- trait Foo
- def fn(g: Int => Unit): Foo
-
- implicit def mkStar(i: Int) = new { def *(a: Foo): Foo = null }
-
- val pool1 = 4 * fn { case i => i * 2 }
- val pool2 = 4 * fn { case i: Int => i * 2 }
-}
diff --git a/test/pending/pos/t294.cmds b/test/pending/pos/t294.cmds
deleted file mode 100644
index 62c9a5a068..0000000000
--- a/test/pending/pos/t294.cmds
+++ /dev/null
@@ -1,3 +0,0 @@
-javac Ann.java Ann2.java
-scalac Test_1.scala
-scalac Test_2.scala
diff --git a/test/pending/pos/t4612.scala b/test/pending/pos/t4612.scala
new file mode 100644
index 0000000000..a93c12ef01
--- /dev/null
+++ b/test/pending/pos/t4612.scala
@@ -0,0 +1,15 @@
+class CyclicReferenceCompilerBug {
+ trait Trait[A] {
+ def foo: A
+ }
+
+ class Class extends Trait[Class] {
+ def foo = new Class
+
+ trait OtherTrait extends Trait[OtherTrait] {
+ self: Class =>
+
+ def foo = new Class
+ }
+ }
+}
diff --git a/test/pending/pos/t4695/T_1.scala b/test/pending/pos/t4695/T_1.scala
new file mode 100644
index 0000000000..70fb1a7f21
--- /dev/null
+++ b/test/pending/pos/t4695/T_1.scala
@@ -0,0 +1,4 @@
+package foo
+
+class Bar { }
+package object Bar { }
diff --git a/test/pending/pos/t4695/T_2.scala b/test/pending/pos/t4695/T_2.scala
new file mode 100644
index 0000000000..70fb1a7f21
--- /dev/null
+++ b/test/pending/pos/t4695/T_2.scala
@@ -0,0 +1,4 @@
+package foo
+
+class Bar { }
+package object Bar { }
diff --git a/test/pending/pos/t4717.scala b/test/pending/pos/t4717.scala
deleted file mode 100644
index 7eaa3dd487..0000000000
--- a/test/pending/pos/t4717.scala
+++ /dev/null
@@ -1,7 +0,0 @@
-trait Bounds[@specialized A] {
- // okay without `>: A`
- def x[B >: A]: Unit = new Bounds[B] {
- lazy val it = ??? // def or val okay
- it
- }
-} \ No newline at end of file
diff --git a/test/pending/pos/t5082.scala b/test/pending/pos/t5082.scala
new file mode 100644
index 0000000000..20a6cfc55f
--- /dev/null
+++ b/test/pending/pos/t5082.scala
@@ -0,0 +1,8 @@
+object Test {
+ sealed trait A
+ case object A1 extends A
+}
+
+trait Something[T]
+
+case class Test() extends Something[Test.A]
diff --git a/test/pending/pos/t5259.scala b/test/pending/pos/t5259.scala
deleted file mode 100644
index 317e28a9dc..0000000000
--- a/test/pending/pos/t5259.scala
+++ /dev/null
@@ -1,14 +0,0 @@
-object DefaultArgBogusTypeMismatch {
-
- class A[T]
- class B {
- type T = this.type
- def m(implicit a : A[T] = new A[T]) = a
- }
-
- def newB = new B
- val a1 = newB.m // Bogus type mismatch
-
- val stableB = new B
- val a2 = stableB.m // OK
-}
diff --git a/test/pending/pos/t5399.scala b/test/pending/pos/t5399.scala
deleted file mode 100644
index 89caba39c1..0000000000
--- a/test/pending/pos/t5399.scala
+++ /dev/null
@@ -1,8 +0,0 @@
-class Test {
- class A[T]
- class B[T](val a: A[T])
-
- case class CaseClass[T](x: T)
-
- def break(existB: B[_]) = CaseClass(existB.a) match { case CaseClass(_) => }
-}
diff --git a/test/pending/pos/t5626.scala b/test/pending/pos/t5626.scala
deleted file mode 100644
index 7ab3881827..0000000000
--- a/test/pending/pos/t5626.scala
+++ /dev/null
@@ -1,12 +0,0 @@
-object Test {
- val blob0 = new {
- case class Foo(i : Int)
- }
- val foo0 = blob0.Foo(22)
-
- val blob1 = new {
- class Foo(i: Int)
- object Foo { def apply(i: Int): Foo = new Foo(i) }
- }
- val foo1 = blob1.Foo(22)
-}
diff --git a/test/pending/pos/t5654.scala b/test/pending/pos/t5654.scala
deleted file mode 100644
index eb711a5f37..0000000000
--- a/test/pending/pos/t5654.scala
+++ /dev/null
@@ -1,4 +0,0 @@
-case class Bomb(a: Array[_])
-case class Bomb2(a: Array[T] forSome { type T })
-class Okay1(a: Array[_])
-case class Okay2(s: Seq[_]) \ No newline at end of file
diff --git a/test/pending/pos/t5877.scala b/test/pending/pos/t5877.scala
new file mode 100644
index 0000000000..b77605f7f2
--- /dev/null
+++ b/test/pending/pos/t5877.scala
@@ -0,0 +1,5 @@
+package foo { }
+
+package object foo {
+ implicit class Foo(val s: String) { }
+}
diff --git a/test/pending/pos/t5954/T_1.scala b/test/pending/pos/t5954/T_1.scala
new file mode 100644
index 0000000000..0064c596b6
--- /dev/null
+++ b/test/pending/pos/t5954/T_1.scala
@@ -0,0 +1,8 @@
+package p {
+ package base {
+ class X
+ }
+ package object base {
+ case class B()
+ }
+}
diff --git a/test/pending/pos/t5954/T_2.scala b/test/pending/pos/t5954/T_2.scala
new file mode 100644
index 0000000000..0064c596b6
--- /dev/null
+++ b/test/pending/pos/t5954/T_2.scala
@@ -0,0 +1,8 @@
+package p {
+ package base {
+ class X
+ }
+ package object base {
+ case class B()
+ }
+}
diff --git a/test/pending/pos/t5954/T_3.scala b/test/pending/pos/t5954/T_3.scala
new file mode 100644
index 0000000000..0064c596b6
--- /dev/null
+++ b/test/pending/pos/t5954/T_3.scala
@@ -0,0 +1,8 @@
+package p {
+ package base {
+ class X
+ }
+ package object base {
+ case class B()
+ }
+}
diff --git a/test/pending/pos/t6225.scala b/test/pending/pos/t6225.scala
new file mode 100644
index 0000000000..d7dff3c419
--- /dev/null
+++ b/test/pending/pos/t6225.scala
@@ -0,0 +1,11 @@
+package library.x {
+ class X {
+ class Foo
+ implicit val foo = new Foo
+ }
+}
+package library { package object x extends X }
+package app {
+ import library.x._
+ object App { implicitly[Foo] }
+}
diff --git a/test/pending/pos/z1720.scala b/test/pending/pos/z1720.scala
deleted file mode 100644
index 6050f3ff88..0000000000
--- a/test/pending/pos/z1720.scala
+++ /dev/null
@@ -1,16 +0,0 @@
-package test
-
-class Thing {
- def info: Info[this.type] = InfoRepository.getInfo(this)
- def info2: Info[this.type] = {
- def self: this.type = this
- InfoRepository.getInfo(self)
- }
-}
-
-trait Info[T]
-case class InfoImpl[T](thing: T) extends Info[T]
-
-object InfoRepository {
- def getInfo(t: Thing): Info[t.type] = InfoImpl(t)
-} \ No newline at end of file
diff --git a/test/postreview.py b/test/postreview.py
deleted file mode 100644
index 2e2518f7ee..0000000000
--- a/test/postreview.py
+++ /dev/null
@@ -1,2540 +0,0 @@
-#!/usr/bin/env python
-import cookielib
-import difflib
-import getpass
-import marshal
-import mimetools
-import ntpath
-import os
-import re
-import socket
-import stat
-import subprocess
-import sys
-import tempfile
-import urllib
-import urllib2
-from optparse import OptionParser
-from tempfile import mkstemp
-from urlparse import urljoin, urlparse
-
-try:
- from hashlib import md5
-except ImportError:
- # Support Python versions before 2.5.
- from md5 import md5
-
-try:
- import json
-except ImportError:
- import simplejson as json
-
-# This specific import is necessary to handle the paths for
-# cygwin enabled machines.
-if (sys.platform.startswith('win')
- or sys.platform.startswith('cygwin')):
- import ntpath as cpath
-else:
- import posixpath as cpath
-
-###
-# Default configuration -- user-settable variables follow.
-###
-
-# The following settings usually aren't needed, but if your Review
-# Board crew has specific preferences and doesn't want to express
-# them with command line switches, set them here and you're done.
-# In particular, setting the REVIEWBOARD_URL variable will allow
-# you to make it easy for people to submit reviews regardless of
-# their SCM setup.
-#
-# Note that in order for this script to work with a reviewboard site
-# that uses local paths to access a repository, the 'Mirror path'
-# in the repository setup page must be set to the remote URL of the
-# repository.
-
-#
-# Reviewboard URL.
-#
-# Set this if you wish to hard-code a default server to always use.
-# It's generally recommended to set this using your SCM repository
-# (for those that support it -- currently only SVN, Git, and Perforce).
-#
-# For example, on SVN:
-# $ svn propset reviewboard:url http://reviewboard.example.com .
-#
-# Or with Git:
-# $ git config reviewboard.url http://reviewboard.example.com
-#
-# On Perforce servers version 2008.1 and above:
-# $ p4 counter reviewboard.url http://reviewboard.example.com
-#
-# Older Perforce servers only allow numerical counters, so embedding
-# the url in the counter name is also supported:
-# $ p4 counter reviewboard.url.http:\|\|reviewboard.example.com 1
-#
-# Note that slashes are not allowed in Perforce counter names, so replace them
-# with pipe characters (they are a safe substitute as they are not used
-# unencoded in URLs). You may need to escape them when issuing the p4 counter
-# command as above.
-#
-# If this is not possible or desired, setting the value here will let
-# you get started quickly.
-#
-# For all other repositories, a .reviewboardrc file present at the top of
-# the checkout will also work. For example:
-#
-# $ cat .reviewboardrc
-# REVIEWBOARD_URL = "http://reviewboard.example.com"
-#
-REVIEWBOARD_URL = None
-
-# Default submission arguments. These are all optional; run this
-# script with --help for descriptions of each argument.
-TARGET_GROUPS = None
-TARGET_PEOPLE = None
-SUBMIT_AS = None
-PUBLISH = False
-OPEN_BROWSER = False
-
-# Debugging. For development...
-DEBUG = False
-
-###
-# End user-settable variables.
-###
-
-
-VERSION = "0.8"
-
-user_config = None
-tempfiles = []
-options = None
-
-
-class APIError(Exception):
- pass
-
-
-class RepositoryInfo:
- """
- A representation of a source code repository.
- """
- def __init__(self, path=None, base_path=None, supports_changesets=False,
- supports_parent_diffs=False):
- self.path = path
- self.base_path = base_path
- self.supports_changesets = supports_changesets
- self.supports_parent_diffs = supports_parent_diffs
- debug("repository info: %s" % self)
-
- def __str__(self):
- return "Path: %s, Base path: %s, Supports changesets: %s" % \
- (self.path, self.base_path, self.supports_changesets)
-
- def set_base_path(self, base_path):
- if not base_path.startswith('/'):
- base_path = '/' + base_path
- debug("changing repository info base_path from %s to %s" % \
- (self.base_path, base_path))
- self.base_path = base_path
-
- def find_server_repository_info(self, server):
- """
- Try to find the repository from the list of repositories on the server.
- For Subversion, this could be a repository with a different URL. For
- all other clients, this is a noop.
- """
- return self
-
-
-class SvnRepositoryInfo(RepositoryInfo):
- """
- A representation of a SVN source code repository. This version knows how to
- find a matching repository on the server even if the URLs differ.
- """
- def __init__(self, path, base_path, uuid, supports_parent_diffs=False):
- RepositoryInfo.__init__(self, path, base_path,
- supports_parent_diffs=supports_parent_diffs)
- self.uuid = uuid
-
- def find_server_repository_info(self, server):
- """
- The point of this function is to find a repository on the server that
- matches self, even if the paths aren't the same. (For example, if self
- uses an 'http' path, but the server uses a 'file' path for the same
- repository.) It does this by comparing repository UUIDs. If the
- repositories use the same path, you'll get back self, otherwise you'll
- get a different SvnRepositoryInfo object (with a different path).
- """
- repositories = server.get_repositories()
-
- for repository in repositories:
- if repository['tool'] != 'Subversion':
- continue
-
- info = self._get_repository_info(server, repository)
-
- if not info or self.uuid != info['uuid']:
- continue
-
- repos_base_path = info['url'][len(info['root_url']):]
- relpath = self._get_relative_path(self.base_path, repos_base_path)
- if relpath:
- return SvnRepositoryInfo(info['url'], relpath, self.uuid)
-
- # We didn't find a matching repository on the server. We'll just return
- # self and hope for the best.
- return self
-
- def _get_repository_info(self, server, repository):
- try:
- return server.get_repository_info(repository['id'])
- except APIError, e:
- # If the server couldn't fetch the repository info, it will return
- # code 210. Ignore those.
- # Other more serious errors should still be raised, though.
- rsp = e.args[0]
- if rsp['err']['code'] == 210:
- return None
-
- raise e
-
- def _get_relative_path(self, path, root):
- pathdirs = self._split_on_slash(path)
- rootdirs = self._split_on_slash(root)
-
- # root is empty, so anything relative to that is itself
- if len(rootdirs) == 0:
- return path
-
- # If one of the directories doesn't match, then path is not relative
- # to root.
- if rootdirs != pathdirs:
- return None
-
- # All the directories matched, so the relative path is whatever
- # directories are left over. The base_path can't be empty, though, so
- # if the paths are the same, return '/'
- if len(pathdirs) == len(rootdirs):
- return '/'
- else:
- return '/'.join(pathdirs[len(rootdirs):])
-
- def _split_on_slash(self, path):
- # Split on slashes, but ignore multiple slashes and throw away any
- # trailing slashes.
- split = re.split('/*', path)
- if split[-1] == '':
- split = split[0:-1]
- return split
-
-
-class ReviewBoardHTTPPasswordMgr(urllib2.HTTPPasswordMgr):
- """
- Adds HTTP authentication support for URLs.
-
- Python 2.4's password manager has a bug in http authentication when the
- target server uses a non-standard port. This works around that bug on
- Python 2.4 installs. This also allows post-review to prompt for passwords
- in a consistent way.
-
- See: http://bugs.python.org/issue974757
- """
- def __init__(self, reviewboard_url):
- self.passwd = {}
- self.rb_url = reviewboard_url
- self.rb_user = None
- self.rb_pass = None
-
- def find_user_password(self, realm, uri):
- if uri.startswith(self.rb_url):
- if self.rb_user is None or self.rb_pass is None:
- print "==> HTTP Authentication Required"
- print 'Enter username and password for "%s" at %s' % \
- (realm, urlparse(uri)[1])
- self.rb_user = raw_input('Username: ')
- self.rb_pass = getpass.getpass('Password: ')
-
- return self.rb_user, self.rb_pass
- else:
- # If this is an auth request for some other domain (since HTTP
- # handlers are global), fall back to standard password management.
- return urllib2.HTTPPasswordMgr.find_user_password(self, realm, uri)
-
-
-class ReviewBoardServer(object):
- """
- An instance of a Review Board server.
- """
- def __init__(self, url, info, cookie_file):
- self.url = url
- if self.url[-1] != '/':
- self.url += '/'
- self._info = info
- self._server_info = None
- self.cookie_file = cookie_file
- self.cookie_jar = cookielib.MozillaCookieJar(self.cookie_file)
-
- # Set up the HTTP libraries to support all of the features we need.
- cookie_handler = urllib2.HTTPCookieProcessor(self.cookie_jar)
- password_mgr = ReviewBoardHTTPPasswordMgr(self.url)
- auth_handler = urllib2.HTTPBasicAuthHandler(password_mgr)
-
- opener = urllib2.build_opener(cookie_handler, auth_handler)
- opener.addheaders = [('User-agent', 'post-review/' + VERSION)]
- urllib2.install_opener(opener)
-
- def login(self, force=False):
- """
- Logs in to a Review Board server, prompting the user for login
- information if needed.
- """
- if not force and self.has_valid_cookie():
- return
-
- print "==> Review Board Login Required"
- print "Enter username and password for Review Board at %s" % self.url
- if options.username:
- username = options.username
- elif options.submit_as:
- username = options.submit_as
- else:
- username = raw_input('Username: ')
-
- if not options.password:
- password = getpass.getpass('Password: ')
- else:
- password = options.password
-
- debug('Logging in with username "%s"' % username)
- try:
- self.api_post('api/json/accounts/login/', {
- 'username': username,
- 'password': password,
- })
- except APIError, e:
- rsp, = e.args
-
- die("Unable to log in: %s (%s)" % (rsp["err"]["msg"],
- rsp["err"]["code"]))
-
- debug("Logged in.")
-
- def has_valid_cookie(self):
- """
- Load the user's cookie file and see if they have a valid
- 'rbsessionid' cookie for the current Review Board server. Returns
- true if so and false otherwise.
- """
- try:
- parsed_url = urlparse(self.url)
- host = parsed_url[1]
- path = parsed_url[2] or '/'
-
- # Cookie files don't store port numbers, unfortunately, so
- # get rid of the port number if it's present.
- host = host.split(":")[0]
-
- debug("Looking for '%s %s' cookie in %s" % \
- (host, path, self.cookie_file))
- self.cookie_jar.load(self.cookie_file, ignore_expires=True)
-
- try:
- cookie = self.cookie_jar._cookies[host][path]['rbsessionid']
-
- if not cookie.is_expired():
- debug("Loaded valid cookie -- no login required")
- return True
-
- debug("Cookie file loaded, but cookie has expired")
- except KeyError:
- debug("Cookie file loaded, but no cookie for this server")
- except IOError, error:
- debug("Couldn't load cookie file: %s" % error)
-
- return False
-
- def new_review_request(self, changenum, submit_as=None):
- """
- Creates a review request on a Review Board server, updating an
- existing one if the changeset number already exists.
-
- If submit_as is provided, the specified user name will be recorded as
- the submitter of the review request (given that the logged in user has
- the appropriate permissions).
- """
- try:
- debug("Attempting to create review request for %s" % changenum)
- data = { 'repository_path': self.info.path }
-
- if changenum:
- data['changenum'] = changenum
-
- if submit_as:
- debug("Submitting the review request as %s" % submit_as)
- data['submit_as'] = submit_as
-
- rsp = self.api_post('api/json/reviewrequests/new/', data)
- except APIError, e:
- rsp, = e.args
-
- if not options.diff_only:
- if rsp['err']['code'] == 204: # Change number in use
- debug("Review request already exists. Updating it...")
- rsp = self.api_post(
- 'api/json/reviewrequests/%s/update_from_changenum/' %
- rsp['review_request']['id'])
- else:
- raise e
-
- debug("Review request created")
- return rsp['review_request']
-
- def set_review_request_field(self, review_request, field, value):
- """
- Sets a field in a review request to the specified value.
- """
- rid = review_request['id']
-
- debug("Attempting to set field '%s' to '%s' for review request '%s'" %
- (field, value, rid))
-
- self.api_post('api/json/reviewrequests/%s/draft/set/' % rid, {
- field: value,
- })
-
- def get_review_request(self, rid):
- """
- Returns the review request with the specified ID.
- """
- rsp = self.api_get('api/json/reviewrequests/%s/' % rid)
- return rsp['review_request']
-
- def get_repositories(self):
- """
- Returns the list of repositories on this server.
- """
- rsp = self.api_get('/api/json/repositories/')
- return rsp['repositories']
-
- def get_repository_info(self, rid):
- """
- Returns detailed information about a specific repository.
- """
- rsp = self.api_get('/api/json/repositories/%s/info/' % rid)
- return rsp['info']
-
- def save_draft(self, review_request):
- """
- Saves a draft of a review request.
- """
- self.api_post("api/json/reviewrequests/%s/draft/save/" %
- review_request['id'])
- debug("Review request draft saved")
-
- def upload_diff(self, review_request, diff_content, parent_diff_content):
- """
- Uploads a diff to a Review Board server.
- """
- debug("Uploading diff, size: %d" % len(diff_content))
-
- if parent_diff_content:
- debug("Uploading parent diff, size: %d" % len(parent_diff_content))
-
- fields = {}
- files = {}
-
- if self.info.base_path:
- fields['basedir'] = self.info.base_path
-
- files['path'] = {
- 'filename': 'diff',
- 'content': diff_content
- }
-
- if parent_diff_content:
- files['parent_diff_path'] = {
- 'filename': 'parent_diff',
- 'content': parent_diff_content
- }
-
- self.api_post('api/json/reviewrequests/%s/diff/new/' %
- review_request['id'], fields, files)
-
- def publish(self, review_request):
- """
- Publishes a review request.
- """
- debug("Publishing")
- self.api_post('api/json/reviewrequests/%s/publish/' %
- review_request['id'])
-
- def _get_server_info(self):
- if not self._server_info:
- self._server_info = self._info.find_server_repository_info(self)
-
- return self._server_info
-
- info = property(_get_server_info)
-
- def process_json(self, data):
- """
- Loads in a JSON file and returns the data if successful. On failure,
- APIError is raised.
- """
- rsp = json.loads(data)
-
- if rsp['stat'] == 'fail':
- raise APIError, rsp
-
- return rsp
-
- def http_get(self, path):
- """
- Performs an HTTP GET on the specified path, storing any cookies that
- were set.
- """
- debug('HTTP GETting %s' % path)
-
- url = self._make_url(path)
-
- try:
- rsp = urllib2.urlopen(url).read()
- self.cookie_jar.save(self.cookie_file)
- return rsp
- except urllib2.HTTPError, e:
- print "Unable to access %s (%s). The host path may be invalid" % \
- (url, e.code)
- try:
- debug(e.read())
- except AttributeError:
- pass
- die()
-
- def _make_url(self, path):
- """Given a path on the server returns a full http:// style url"""
- app = urlparse(self.url)[2]
- if path[0] == '/':
- url = urljoin(self.url, app[:-1] + path)
- else:
- url = urljoin(self.url, app + path)
-
- if not url.startswith('http'):
- url = 'http://%s' % url
- return url
-
- def api_get(self, path):
- """
- Performs an API call using HTTP GET at the specified path.
- """
- return self.process_json(self.http_get(path))
-
- def http_post(self, path, fields, files=None):
- """
- Performs an HTTP POST on the specified path, storing any cookies that
- were set.
- """
- if fields:
- debug_fields = fields.copy()
- else:
- debug_fields = {}
-
- if 'password' in debug_fields:
- debug_fields["password"] = "**************"
- url = self._make_url(path)
- debug('HTTP POSTing to %s: %s' % (url, debug_fields))
-
- content_type, body = self._encode_multipart_formdata(fields, files)
- headers = {
- 'Content-Type': content_type,
- 'Content-Length': str(len(body))
- }
-
- try:
- r = urllib2.Request(url, body, headers)
- data = urllib2.urlopen(r).read()
- self.cookie_jar.save(self.cookie_file)
- return data
- except urllib2.URLError, e:
- try:
- debug(e.read())
- except AttributeError:
- pass
-
- die("Unable to access %s. The host path may be invalid\n%s" % \
- (url, e))
- except urllib2.HTTPError, e:
- die("Unable to access %s (%s). The host path may be invalid\n%s" % \
- (url, e.code, e.read()))
-
- def api_post(self, path, fields=None, files=None):
- """
- Performs an API call using HTTP POST at the specified path.
- """
- return self.process_json(self.http_post(path, fields, files))
-
- def _encode_multipart_formdata(self, fields, files):
- """
- Encodes data for use in an HTTP POST.
- """
- BOUNDARY = mimetools.choose_boundary()
- content = ""
-
- fields = fields or {}
- files = files or {}
-
- for key in fields:
- content += "--" + BOUNDARY + "\r\n"
- content += "Content-Disposition: form-data; name=\"%s\"\r\n" % key
- content += "\r\n"
- content += fields[key] + "\r\n"
-
- for key in files:
- filename = files[key]['filename']
- value = files[key]['content']
- content += "--" + BOUNDARY + "\r\n"
- content += "Content-Disposition: form-data; name=\"%s\"; " % key
- content += "filename=\"%s\"\r\n" % filename
- content += "\r\n"
- content += value + "\r\n"
-
- content += "--" + BOUNDARY + "--\r\n"
- content += "\r\n"
-
- content_type = "multipart/form-data; boundary=%s" % BOUNDARY
-
- return content_type, content
-
-
-class SCMClient(object):
- """
- A base representation of an SCM tool for fetching repository information
- and generating diffs.
- """
- def get_repository_info(self):
- return None
-
- def scan_for_server(self, repository_info):
- """
- Scans the current directory on up to find a .reviewboard file
- containing the server path.
- """
- server_url = self._get_server_from_config(user_config, repository_info)
- if server_url:
- return server_url
-
- for path in walk_parents(os.getcwd()):
- filename = os.path.join(path, ".reviewboardrc")
- if os.path.exists(filename):
- config = load_config_file(filename)
- server_url = self._get_server_from_config(config,
- repository_info)
- if server_url:
- return server_url
-
- return None
-
- def diff(self, args):
- """
- Returns the generated diff and optional parent diff for this
- repository.
-
- The returned tuple is (diff_string, parent_diff_string)
- """
- return (None, None)
-
- def diff_between_revisions(self, revision_range, args, repository_info):
- """
- Returns the generated diff between revisions in the repository.
- """
- return None
-
- def _get_server_from_config(self, config, repository_info):
- if 'REVIEWBOARD_URL' in config:
- return config['REVIEWBOARD_URL']
- elif 'TREES' in config:
- trees = config['TREES']
- if not isinstance(trees, dict):
- die("Warning: 'TREES' in config file is not a dict!")
-
- if repository_info.path in trees and \
- 'REVIEWBOARD_URL' in trees[repository_info.path]:
- return trees[repository_info.path]['REVIEWBOARD_URL']
-
- return None
-
-
-class CVSClient(SCMClient):
- """
- A wrapper around the cvs tool that fetches repository
- information and generates compatible diffs.
- """
- def get_repository_info(self):
- if not check_install("cvs"):
- return None
-
- cvsroot_path = os.path.join("CVS", "Root")
-
- if not os.path.exists(cvsroot_path):
- return None
-
- fp = open(cvsroot_path, "r")
- repository_path = fp.read().strip()
- fp.close()
-
- i = repository_path.find("@")
- if i != -1:
- repository_path = repository_path[i + 1:]
-
- i = repository_path.find(":")
- if i != -1:
- host = repository_path[:i]
- try:
- canon = socket.getfqdn(host)
- repository_path = repository_path.replace('%s:' % host,
- '%s:' % canon)
- except socket.error, msg:
- debug("failed to get fqdn for %s, msg=%s" % (host, msg))
-
- return RepositoryInfo(path=repository_path)
-
- def diff(self, files):
- """
- Performs a diff across all modified files in a CVS repository.
-
- CVS repositories do not support branches of branches in a way that
- makes parent diffs possible, so we never return a parent diff
- (the second value in the tuple).
- """
- return (self.do_diff(files), None)
-
- def diff_between_revisions(self, revision_range, args, repository_info):
- """
- Performs a diff between 2 revisions of a CVS repository.
- """
- revs = []
-
- for rev in revision_range.split(":"):
- revs += ["-r", rev]
-
- return self.do_diff(revs)
-
- def do_diff(self, params):
- """
- Performs the actual diff operation through cvs diff, handling
- fake errors generated by CVS.
- """
- # Diff returns "1" if differences were found.
- return execute(["cvs", "diff", "-uN"] + params,
- extra_ignore_errors=(1,))
-
-
-class ClearCaseClient(SCMClient):
- """
- A wrapper around the clearcase tool that fetches repository
- information and generates compatible diffs.
- This client assumes that cygwin is installed on windows.
- """
- ccroot_path = "/view/reviewboard.diffview/vobs/"
- viewinfo = ""
- viewtype = "snapshot"
-
- def get_filename_hash(self, fname):
- # Hash the filename string so its easy to find the file later on.
- return md5(fname).hexdigest()
-
- def get_repository_info(self):
- if not check_install('cleartool help'):
- return None
-
- # We must be running this from inside a view.
- # Otherwise it doesn't make sense.
- self.viewinfo = execute(["cleartool", "pwv", "-short"])
- if self.viewinfo.startswith('\*\* NONE'):
- return None
-
- # Returning the hardcoded clearcase root path to match the server
- # respository path.
- # There is no reason to have a dynamic path unless you have
- # multiple clearcase repositories. This should be implemented.
- return RepositoryInfo(path=self.ccroot_path,
- base_path=self.ccroot_path,
- supports_parent_diffs=False)
-
- def get_previous_version(self, files):
- file = []
- curdir = os.getcwd()
-
- # Cygwin case must transform a linux-like path to windows like path
- # including drive letter.
- if 'cygdrive' in curdir:
- where = curdir.index('cygdrive') + 9
- drive_letter = curdir[where:where+1]
- curdir = drive_letter + ":\\" + curdir[where+2:len(curdir)]
-
- for key in files:
- # Sometimes there is a quote in the filename. It must be removed.
- key = key.replace('\'', '')
- elem_path = cpath.normpath(os.path.join(curdir, key))
-
- # Removing anything before the last /vobs
- # because it may be repeated.
- elem_path_idx = elem_path.rfind("/vobs")
- if elem_path_idx != -1:
- elem_path = elem_path[elem_path_idx:len(elem_path)].strip("\"")
-
- # Call cleartool to get this version and the previous version
- # of the element.
- curr_version, pre_version = execute(
- ["cleartool", "desc", "-pre", elem_path])
- curr_version = cpath.normpath(curr_version)
- pre_version = pre_version.split(':')[1].strip()
-
- # If a specific version was given, remove it from the path
- # to avoid version duplication
- if "@@" in elem_path:
- elem_path = elem_path[:elem_path.rfind("@@")]
- file.append(elem_path + "@@" + pre_version)
- file.append(curr_version)
-
- # Determnine if the view type is snapshot or dynamic.
- if os.path.exists(file[0]):
- self.viewtype = "dynamic"
-
- return file
-
- def get_extended_namespace(self, files):
- """
- Parses the file path to get the extended namespace
- """
- versions = self.get_previous_version(files)
-
- evfiles = []
- hlist = []
-
- for vkey in versions:
- # Verify if it is a checkedout file.
- if "CHECKEDOUT" in vkey:
- # For checkedout files just add it to the file list
- # since it cannot be accessed outside the view.
- splversions = vkey[:vkey.rfind("@@")]
- evfiles.append(splversions)
- else:
- # For checkedin files.
- ext_path = []
- ver = []
- fname = "" # fname holds the file name without the version.
- (bpath, fpath) = cpath.splitdrive(vkey)
- if bpath :
- # Windows.
- # The version (if specified like file.c@@/main/1)
- # should be kept as a single string
- # so split the path and concat the file name
- # and version in the last position of the list.
- ver = fpath.split("@@")
- splversions = fpath[:vkey.rfind("@@")].split("\\")
- fname = splversions.pop()
- splversions.append(fname + ver[1])
- else :
- # Linux.
- bpath = vkey[:vkey.rfind("vobs")+4]
- fpath = vkey[vkey.rfind("vobs")+5:]
- ver = fpath.split("@@")
- splversions = ver[0][:vkey.rfind("@@")].split("/")
- fname = splversions.pop()
- splversions.append(fname + ver[1])
-
- filename = splversions.pop()
- bpath = cpath.normpath(bpath + "/")
- elem_path = bpath
-
- for key in splversions:
- # For each element (directory) in the path,
- # get its version from clearcase.
- elem_path = cpath.join(elem_path, key)
-
- # This is the version to be appended to the extended
- # path list.
- this_version = execute(
- ["cleartool", "desc", "-fmt", "%Vn",
- cpath.normpath(elem_path)])
- if this_version:
- ext_path.append(key + "/@@" + this_version + "/")
- else:
- ext_path.append(key + "/")
-
- # This must be done in case we haven't specified
- # the version on the command line.
- ext_path.append(cpath.normpath(fname + "/@@" +
- vkey[vkey.rfind("@@")+2:len(vkey)]))
- epstr = cpath.join(bpath, cpath.normpath(''.join(ext_path)))
- evfiles.append(epstr)
-
- """
- In windows, there is a problem with long names(> 254).
- In this case, we hash the string and copy the unextended
- filename to a temp file whose name is the hash.
- This way we can get the file later on for diff.
- The same problem applies to snapshot views where the
- extended name isn't available.
- The previous file must be copied from the CC server
- to a local dir.
- """
- if cpath.exists(epstr) :
- pass
- else:
- if len(epstr) > 254 or self.viewtype == "snapshot":
- name = self.get_filename_hash(epstr)
- # Check if this hash is already in the list
- try:
- i = hlist.index(name)
- die("ERROR: duplicate value %s : %s" %
- (name, epstr))
- except ValueError:
- hlist.append(name)
-
- normkey = cpath.normpath(vkey)
- td = tempfile.gettempdir()
- # Cygwin case must transform a linux-like path to
- # windows like path including drive letter
- if 'cygdrive' in td:
- where = td.index('cygdrive') + 9
- drive_letter = td[where:where+1] + ":"
- td = cpath.join(drive_letter, td[where+1:])
- tf = cpath.normpath(cpath.join(td, name))
- if cpath.exists(tf):
- debug("WARNING: FILE EXISTS")
- os.unlink(tf)
- execute(["cleartool", "get", "-to", tf, normkey])
- else:
- die("ERROR: FILE NOT FOUND : %s" % epstr)
-
- return evfiles
-
- def get_files_from_label(self, label):
- voblist=[]
- # Get the list of vobs for the current view
- allvoblist = execute(["cleartool", "lsvob", "-short"]).split()
- # For each vob, find if the label is present
- for vob in allvoblist:
- try:
- execute(["cleartool", "describe", "-local",
- "lbtype:%s@%s" % (label, vob)]).split()
- voblist.append(vob)
- except:
- pass
-
- filelist=[]
- # For each vob containing the label, get the file list
- for vob in voblist:
- try:
- res = execute(["cleartool", "find", vob, "-all", "-version",
- "lbtype(%s)" % label, "-print"])
- filelist.extend(res.split())
- except :
- pass
-
- # Return only the unique itens
- return set(filelist)
-
- def diff(self, files):
- """
- Performs a diff of the specified file and its previous version.
- """
- # We must be running this from inside a view.
- # Otherwise it doesn't make sense.
- return self.do_diff(self.get_extended_namespace(files))
-
- def diff_label(self, label):
- """
- Get the files that are attached to a label and diff them
- TODO
- """
- return self.diff(self.get_files_from_label(label))
-
- def diff_between_revisions(self, revision_range, args, repository_info):
- """
- Performs a diff between 2 revisions of a CC repository.
- """
- rev_str = ''
-
- for rev in revision_range.split(":"):
- rev_str += "-r %s " % rev
-
- return self.do_diff(rev_str)
-
- def do_diff(self, params):
- # Diff returns "1" if differences were found.
- # Add the view name and view type to the description
- if options.description:
- options.description = ("VIEW: " + self.viewinfo +
- "VIEWTYPE: " + self.viewtype + "\n" + options.description)
- else:
- options.description = (self.viewinfo +
- "VIEWTYPE: " + self.viewtype + "\n")
-
- o = []
- Feol = False
- while len(params) > 0:
- # Read both original and modified files.
- onam = params.pop(0)
- mnam = params.pop(0)
- file_data = []
- do_rem = False
- # If the filename length is greater than 254 char for windows,
- # we copied the file to a temp file
- # because the open will not work for path greater than 254.
- # This is valid for the original and
- # modified files if the name size is > 254.
- for filenam in (onam, mnam) :
- if cpath.exists(filenam) and self.viewtype == "dynamic":
- do_rem = False
- fn = filenam
- elif len(filenam) > 254 or self.viewtype == "snapshot":
- fn = self.get_filename_hash(filenam)
- fn = cpath.join(tempfile.gettempdir(), fn)
- do_rem = True
- fd = open(cpath.normpath(fn))
- fdata = fd.readlines()
- fd.close()
- file_data.append(fdata)
- # If the file was temp, it should be removed.
- if do_rem:
- os.remove(filenam)
-
- modi = file_data.pop()
- orig = file_data.pop()
-
- # For snapshot views, the local directories must be removed because
- # they will break the diff on the server. Just replacing
- # everything before the view name (including the view name) for
- # vobs do the work.
- if (self.viewtype == "snapshot"
- and (sys.platform.startswith('win')
- or sys.platform.startswith('cygwin'))):
- vinfo = self.viewinfo.rstrip("\r\n")
- mnam = "c:\\\\vobs" + mnam[mnam.rfind(vinfo) + len(vinfo):]
- onam = "c:\\\\vobs" + onam[onam.rfind(vinfo) + len(vinfo):]
- # Call the diff lib to generate a diff.
- # The dates are bogus, since they don't natter anyway.
- # The only thing is that two spaces are needed to the server
- # so it can identify the heades correctly.
- diff = difflib.unified_diff(orig, modi, onam, mnam,
- ' 2002-02-21 23:30:39.942229878 -0800',
- ' 2002-02-21 23:30:50.442260588 -0800', lineterm=' \n')
- # Transform the generator output into a string output
- # Use a comprehension instead of a generator,
- # so 2.3.x doesn't fail to interpret.
- diffstr = ''.join([str(l) for l in diff])
- # Workaround for the difflib no new line at end of file
- # problem.
- if not diffstr.endswith('\n'):
- diffstr = diffstr + ("\n\\ No newline at end of file\n")
- o.append(diffstr)
-
- ostr = ''.join(o)
- return (ostr, None) # diff, parent_diff (not supported)
-
-
-class SVNClient(SCMClient):
- """
- A wrapper around the svn Subversion tool that fetches repository
- information and generates compatible diffs.
- """
- def get_repository_info(self):
- if not check_install('svn help'):
- return None
-
- # Get the SVN repository path (either via a working copy or
- # a supplied URI)
- svn_info_params = ["svn", "info"]
- if options.repository_url:
- svn_info_params.append(options.repository_url)
- data = execute(svn_info_params,
- ignore_errors=True)
- m = re.search(r'^Repository Root: (.+)$', data, re.M)
- if not m:
- return None
-
- path = m.group(1)
-
- m = re.search(r'^URL: (.+)$', data, re.M)
- if not m:
- return None
-
- base_path = m.group(1)[len(path):] or "/"
-
- m = re.search(r'^Repository UUID: (.+)$', data, re.M)
- if not m:
- return None
-
- return SvnRepositoryInfo(path, base_path, m.group(1))
-
- def scan_for_server(self, repository_info):
- # Scan first for dot files, since it's faster and will cover the
- # user's $HOME/.reviewboardrc
- server_url = super(SVNClient, self).scan_for_server(repository_info)
- if server_url:
- return server_url
-
- return self.scan_for_server_property(repository_info)
-
- def scan_for_server_property(self, repository_info):
- def get_url_prop(path):
- url = execute(["svn", "propget", "reviewboard:url", path]).strip()
- return url or None
-
- for path in walk_parents(os.getcwd()):
- if not os.path.exists(os.path.join(path, ".svn")):
- break
-
- prop = get_url_prop(path)
- if prop:
- return prop
-
- return get_url_prop(repository_info.path)
-
- def diff(self, files):
- """
- Performs a diff across all modified files in a Subversion repository.
-
- SVN repositories do not support branches of branches in a way that
- makes parent diffs possible, so we never return a parent diff
- (the second value in the tuple).
- """
- return (self.do_diff(["svn", "diff", "--diff-cmd=diff"] + files),
- None)
-
- def diff_between_revisions(self, revision_range, args, repository_info):
- """
- Performs a diff between 2 revisions of a Subversion repository.
- """
- if options.repository_url:
- revisions = revision_range.split(':')
- if len(revisions) < 1:
- return None
- elif len(revisions) == 1:
- revisions.append('HEAD')
-
- # if a new path was supplied at the command line, set it
- if len(args):
- repository_info.set_base_path(args[0])
-
- url = repository_info.path + repository_info.base_path
-
- old_url = url + '@' + revisions[0]
- new_url = url + '@' + revisions[1]
-
- return self.do_diff(["svn", "diff", "--diff-cmd=diff", old_url,
- new_url],
- repository_info)
- # Otherwise, perform the revision range diff using a working copy
- else:
- return self.do_diff(["svn", "diff", "--diff-cmd=diff", "-r",
- revision_range],
- repository_info)
-
- def do_diff(self, cmd, repository_info=None):
- """
- Performs the actual diff operation, handling renames and converting
- paths to absolute.
- """
- diff = execute(cmd, split_lines=True)
- diff = self.handle_renames(diff)
- diff = self.convert_to_absolute_paths(diff, repository_info)
-
- return ''.join(diff)
-
- def handle_renames(self, diff_content):
- """
- The output of svn diff is incorrect when the file in question came
- into being via svn mv/cp. Although the patch for these files are
- relative to its parent, the diff header doesn't reflect this.
- This function fixes the relevant section headers of the patch to
- portray this relationship.
- """
-
- # svn diff against a repository URL on two revisions appears to
- # handle moved files properly, so only adjust the diff file names
- # if they were created using a working copy.
- if options.repository_url:
- return diff_content
-
- result = []
-
- from_line = ""
- for line in diff_content:
- if line.startswith('--- '):
- from_line = line
- continue
-
- # This is where we decide how mangle the previous '--- '
- if line.startswith('+++ '):
- to_file, _ = self.parse_filename_header(line[4:])
- info = self.svn_info(to_file)
- if info.has_key("Copied From URL"):
- url = info["Copied From URL"]
- root = info["Repository Root"]
- from_file = urllib.unquote(url[len(root):])
- result.append(from_line.replace(to_file, from_file))
- else:
- result.append(from_line) #as is, no copy performed
-
- # We only mangle '---' lines. All others get added straight to
- # the output.
- result.append(line)
-
- return result
-
-
- def convert_to_absolute_paths(self, diff_content, repository_info):
- """
- Converts relative paths in a diff output to absolute paths.
- This handles paths that have been svn switched to other parts of the
- repository.
- """
-
- result = []
-
- for line in diff_content:
- front = None
- if line.startswith('+++ ') or line.startswith('--- ') or line.startswith('Index: '):
- front, line = line.split(" ", 1)
-
- if front:
- if line.startswith('/'): #already absolute
- line = front + " " + line
- else:
- # filename and rest of line (usually the revision
- # component)
- file, rest = self.parse_filename_header(line)
-
- # If working with a diff generated outside of a working
- # copy, then file paths are already absolute, so just
- # add initial slash.
- if options.repository_url:
- path = urllib.unquote(
- "%s/%s" % (repository_info.base_path, file))
- else:
- info = self.svn_info(file)
- url = info["URL"]
- root = info["Repository Root"]
- path = urllib.unquote(url[len(root):])
-
- line = front + " " + path + rest
-
- result.append(line)
-
- return result
-
- def svn_info(self, path):
- """Return a dict which is the result of 'svn info' at a given path."""
- svninfo = {}
- for info in execute(["svn", "info", path],
- split_lines=True):
- parts = info.strip().split(": ", 1)
- if len(parts) == 2:
- key, value = parts
- svninfo[key] = value
-
- return svninfo
-
- # Adapted from server code parser.py
- def parse_filename_header(self, s):
- parts = None
- if "\t" in s:
- # There's a \t separating the filename and info. This is the
- # best case scenario, since it allows for filenames with spaces
- # without much work.
- parts = s.split("\t")
-
- # There's spaces being used to separate the filename and info.
- # This is technically wrong, so all we can do is assume that
- # 1) the filename won't have multiple consecutive spaces, and
- # 2) there's at least 2 spaces separating the filename and info.
- if " " in s:
- parts = re.split(r" +", s)
-
- if parts:
- parts[1] = '\t' + parts[1]
- return parts
-
- # strip off ending newline, and return it as the second component
- return [s.split('\n')[0], '\n']
-
-
-class PerforceClient(SCMClient):
- """
- A wrapper around the p4 Perforce tool that fetches repository information
- and generates compatible diffs.
- """
- def get_repository_info(self):
- if not check_install('p4 help'):
- return None
-
- data = execute(["p4", "info"], ignore_errors=True)
-
- m = re.search(r'^Server address: (.+)$', data, re.M)
- if not m:
- return None
-
- repository_path = m.group(1).strip()
-
- try:
- hostname, port = repository_path.split(":")
- info = socket.gethostbyaddr(hostname)
- repository_path = "%s:%s" % (info[0], port)
- except (socket.gaierror, socket.herror):
- pass
-
- return RepositoryInfo(path=repository_path, supports_changesets=True)
-
- def scan_for_server(self, repository_info):
- # Scan first for dot files, since it's faster and will cover the
- # user's $HOME/.reviewboardrc
- server_url = \
- super(PerforceClient, self).scan_for_server(repository_info)
-
- if server_url:
- return server_url
-
- return self.scan_for_server_counter(repository_info)
-
- def scan_for_server_counter(self, repository_info):
- """
- Checks the Perforce counters to see if the Review Board server's url
- is specified. Since Perforce only started supporting non-numeric
- counter values in server version 2008.1, we support both a normal
- counter 'reviewboard.url' with a string value and embedding the url in
- a counter name like 'reviewboard.url.http:||reviewboard.example.com'.
- Note that forward slashes aren't allowed in counter names, so
- pipe ('|') characters should be used. These should be safe because they
- should not be used unencoded in urls.
- """
-
- counters_text = execute(["p4", "counters"])
-
- # Try for a "reviewboard.url" counter first.
- m = re.search(r'^reviewboard.url = (\S+)', counters_text, re.M)
-
- if m:
- return m.group(1)
-
- # Next try for a counter of the form:
- # reviewboard_url.http:||reviewboard.example.com
- m2 = re.search(r'^reviewboard.url\.(\S+)', counters_text, re.M)
-
- if m2:
- return m2.group(1).replace('|', '/')
-
- return None
-
- def get_changenum(self, args):
- if len(args) == 1:
- try:
- return str(int(args[0]))
- except ValueError:
- pass
- return None
-
- def diff(self, args):
- """
- Goes through the hard work of generating a diff on Perforce in order
- to take into account adds/deletes and to provide the necessary
- revision information.
- """
- # set the P4 enviroment:
- if options.p4_client:
- os.environ['P4CLIENT'] = options.p4_client
-
- if options.p4_port:
- os.environ['P4PORT'] = options.p4_port
-
- changenum = self.get_changenum(args)
- if changenum is None:
- return self._path_diff(args)
- else:
- return self._changenum_diff(changenum)
-
-
- def _path_diff(self, args):
- """
- Process a path-style diff. See _changenum_diff for the alternate
- version that handles specific change numbers.
-
- Multiple paths may be specified in `args`. The path styles supported
- are:
-
- //path/to/file
- Upload file as a "new" file.
-
- //path/to/dir/...
- Upload all files as "new" files.
-
- //path/to/file[@#]rev
- Upload file from that rev as a "new" file.
-
- //path/to/file[@#]rev,[@#]rev
- Upload a diff between revs.
-
- //path/to/dir/...[@#]rev,[@#]rev
- Upload a diff of all files between revs in that directory.
- """
- r_revision_range = re.compile(r'^(?P<path>//[^@#]+)' +
- r'(?P<revision1>[#@][^,]+)?' +
- r'(?P<revision2>,[#@][^,]+)?$')
-
- empty_filename = make_tempfile()
- tmp_diff_from_filename = make_tempfile()
- tmp_diff_to_filename = make_tempfile()
-
- diff_lines = []
-
- for path in args:
- m = r_revision_range.match(path)
-
- if not m:
- die('Path %r does not match a valid Perforce path.' % (path,))
- revision1 = m.group('revision1')
- revision2 = m.group('revision2')
- first_rev_path = m.group('path')
-
- if revision1:
- first_rev_path += revision1
- records = self._run_p4(['files', first_rev_path])
-
- # Make a map for convenience.
- files = {}
-
- # Records are:
- # 'rev': '1'
- # 'func': '...'
- # 'time': '1214418871'
- # 'action': 'edit'
- # 'type': 'ktext'
- # 'depotFile': '...'
- # 'change': '123456'
- for record in records:
- if record['action'] != 'delete':
- if revision2:
- files[record['depotFile']] = [record, None]
- else:
- files[record['depotFile']] = [None, record]
-
- if revision2:
- # [1:] to skip the comma.
- second_rev_path = m.group('path') + revision2[1:]
- records = self._run_p4(['files', second_rev_path])
- for record in records:
- if record['action'] != 'delete':
- try:
- m = files[record['depotFile']]
- m[1] = record
- except KeyError:
- files[record['depotFile']] = [None, record]
-
- old_file = new_file = empty_filename
- changetype_short = None
-
- for depot_path, (first_record, second_record) in files.items():
- old_file = new_file = empty_filename
- if first_record is None:
- self._write_file(depot_path + '#' + second_record['rev'],
- tmp_diff_to_filename)
- new_file = tmp_diff_to_filename
- changetype_short = 'A'
- base_revision = 0
- elif second_record is None:
- self._write_file(depot_path + '#' + first_record['rev'],
- tmp_diff_from_filename)
- old_file = tmp_diff_from_filename
- changetype_short = 'D'
- base_revision = int(first_record['rev'])
- else:
- self._write_file(depot_path + '#' + first_record['rev'],
- tmp_diff_from_filename)
- self._write_file(depot_path + '#' + second_record['rev'],
- tmp_diff_to_filename)
- new_file = tmp_diff_to_filename
- old_file = tmp_diff_from_filename
- changetype_short = 'M'
- base_revision = int(first_record['rev'])
-
- dl = self._do_diff(old_file, new_file, depot_path,
- base_revision, changetype_short,
- ignore_unmodified=True)
- diff_lines += dl
-
- os.unlink(empty_filename)
- os.unlink(tmp_diff_from_filename)
- os.unlink(tmp_diff_to_filename)
- return (''.join(diff_lines), None)
-
- def _run_p4(self, command):
- """Execute a perforce command using the python marshal API.
-
- - command: A list of strings of the command to execute.
-
- The return type depends on the command being run.
- """
- command = ['p4', '-G'] + command
- p = subprocess.Popen(command, stdout=subprocess.PIPE)
- result = []
- has_error = False
-
- while 1:
- try:
- data = marshal.load(p.stdout)
- except EOFError:
- break
- else:
- result.append(data)
- if data.get('code', None) == 'error':
- has_error = True
-
- rc = p.wait()
-
- if rc or has_error:
- for record in result:
- if 'data' in record:
- print record['data']
- die('Failed to execute command: %s\n' % (command,))
-
- return result
-
- def _changenum_diff(self, changenum):
- """
- Process a diff for a particular change number. This handles both
- pending and submitted changelists.
-
- See _path_diff for the alternate version that does diffs of depot
- paths.
- """
- # TODO: It might be a good idea to enhance PerforceDiffParser to
- # understand that newFile could include a revision tag for post-submit
- # reviewing.
- cl_is_pending = False
-
- debug("Generating diff for changenum %s" % changenum)
-
- description = execute(["p4", "describe", "-s", changenum],
- split_lines=True)
-
- if '*pending*' in description[0]:
- cl_is_pending = True
-
- # Get the file list
- for line_num, line in enumerate(description):
- if 'Affected files ...' in line:
- break
- else:
- # Got to the end of all the description lines and didn't find
- # what we were looking for.
- die("Couldn't find any affected files for this change.")
-
- description = description[line_num+2:]
-
- diff_lines = []
-
- empty_filename = make_tempfile()
- tmp_diff_from_filename = make_tempfile()
- tmp_diff_to_filename = make_tempfile()
-
- for line in description:
- line = line.strip()
- if not line:
- continue
-
- m = re.search(r'\.\.\. ([^#]+)#(\d+) (add|edit|delete|integrate|branch)', line)
- if not m:
- die("Unsupported line from p4 opened: %s" % line)
-
- depot_path = m.group(1)
- base_revision = int(m.group(2))
- if not cl_is_pending:
- # If the changelist is pending our base revision is the one that's
- # currently in the depot. If we're not pending the base revision is
- # actually the revision prior to this one
- base_revision -= 1
-
- changetype = m.group(3)
-
- debug('Processing %s of %s' % (changetype, depot_path))
-
- old_file = new_file = empty_filename
- old_depot_path = new_depot_path = None
- changetype_short = None
-
- if changetype == 'edit' or changetype == 'integrate':
- # A big assumption
- new_revision = base_revision + 1
-
- # We have an old file, get p4 to take this old version from the
- # depot and put it into a plain old temp file for us
- old_depot_path = "%s#%s" % (depot_path, base_revision)
- self._write_file(old_depot_path, tmp_diff_from_filename)
- old_file = tmp_diff_from_filename
-
- # Also print out the new file into a tmpfile
- if cl_is_pending:
- new_file = self._depot_to_local(depot_path)
- else:
- new_depot_path = "%s#%s" %(depot_path, new_revision)
- self._write_file(new_depot_path, tmp_diff_to_filename)
- new_file = tmp_diff_to_filename
-
- changetype_short = "M"
-
- elif changetype == 'add' or changetype == 'branch':
- # We have a new file, get p4 to put this new file into a pretty
- # temp file for us. No old file to worry about here.
- if cl_is_pending:
- new_file = self._depot_to_local(depot_path)
- else:
- self._write_file(depot_path, tmp_diff_to_filename)
- new_file = tmp_diff_to_filename
- changetype_short = "A"
-
- elif changetype == 'delete':
- # We've deleted a file, get p4 to put the deleted file into a temp
- # file for us. The new file remains the empty file.
- old_depot_path = "%s#%s" % (depot_path, base_revision)
- self._write_file(old_depot_path, tmp_diff_from_filename)
- old_file = tmp_diff_from_filename
- changetype_short = "D"
- else:
- die("Unknown change type '%s' for %s" % (changetype, depot_path))
-
- dl = self._do_diff(old_file, new_file, depot_path, base_revision, changetype_short)
- diff_lines += dl
-
- os.unlink(empty_filename)
- os.unlink(tmp_diff_from_filename)
- os.unlink(tmp_diff_to_filename)
- return (''.join(diff_lines), None)
-
- def _do_diff(self, old_file, new_file, depot_path, base_revision,
- changetype_short, ignore_unmodified=False):
- """
- Do the work of producing a diff for Perforce.
-
- old_file - The absolute path to the "old" file.
- new_file - The absolute path to the "new" file.
- depot_path - The depot path in Perforce for this file.
- base_revision - The base perforce revision number of the old file as
- an integer.
- changetype_short - The change type as a single character string.
- ignore_unmodified - If True, will return an empty list if the file
- is not changed.
-
- Returns a list of strings of diff lines.
- """
- if hasattr(os, 'uname') and os.uname()[0] == 'SunOS':
- diff_cmd = ["gdiff", "-urNp", old_file, new_file]
- else:
- diff_cmd = ["diff", "-urNp", old_file, new_file]
- # Diff returns "1" if differences were found.
- dl = execute(diff_cmd, extra_ignore_errors=(1,2),
- translate_newlines=False)
-
- # If the input file has ^M characters at end of line, lets ignore them.
- dl = dl.replace('\r\r\n', '\r\n')
- dl = dl.splitlines(True)
-
- cwd = os.getcwd()
- if depot_path.startswith(cwd):
- local_path = depot_path[len(cwd) + 1:]
- else:
- local_path = depot_path
-
- # Special handling for the output of the diff tool on binary files:
- # diff outputs "Files a and b differ"
- # and the code below expects the output to start with
- # "Binary files "
- if len(dl) == 1 and \
- dl[0] == ('Files %s and %s differ'% (old_file, new_file)):
- dl = ['Binary files %s and %s differ'% (old_file, new_file)]
-
- if dl == [] or dl[0].startswith("Binary files "):
- if dl == []:
- if ignore_unmodified:
- return []
- else:
- print "Warning: %s in your changeset is unmodified" % \
- local_path
-
- dl.insert(0, "==== %s#%s ==%s== %s ====\n" % \
- (depot_path, base_revision, changetype_short, local_path))
- dl.append('\n')
- else:
- m = re.search(r'(\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d)', dl[1])
- if m:
- timestamp = m.group(1)
- else:
- # Thu Sep 3 11:24:48 2007
- m = re.search(r'(\w+)\s+(\w+)\s+(\d+)\s+(\d\d:\d\d:\d\d)\s+(\d\d\d\d)', dl[1])
- if not m:
- die("Unable to parse diff header: %s" % dl[1])
-
- month_map = {
- "Jan": "01",
- "Feb": "02",
- "Mar": "03",
- "Apr": "04",
- "May": "05",
- "Jun": "06",
- "Jul": "07",
- "Aug": "08",
- "Sep": "09",
- "Oct": "10",
- "Nov": "11",
- "Dec": "12",
- }
- month = month_map[m.group(2)]
- day = m.group(3)
- timestamp = m.group(4)
- year = m.group(5)
-
- timestamp = "%s-%s-%s %s" % (year, month, day, timestamp)
-
- dl[0] = "--- %s\t%s#%s\n" % (local_path, depot_path, base_revision)
- dl[1] = "+++ %s\t%s\n" % (local_path, timestamp)
-
- return dl
-
- def _write_file(self, depot_path, tmpfile):
- """
- Grabs a file from Perforce and writes it to a temp file. p4 print sets
- the file readonly and that causes a later call to unlink fail. So we
- make the file read/write.
- """
- debug('Writing "%s" to "%s"' % (depot_path, tmpfile))
- execute(["p4", "print", "-o", tmpfile, "-q", depot_path])
- os.chmod(tmpfile, stat.S_IREAD | stat.S_IWRITE)
-
- def _depot_to_local(self, depot_path):
- """
- Given a path in the depot return the path on the local filesystem to
- the same file. If there are multiple results, take only the last
- result from the where command.
- """
- where_output = self._run_p4(['where', depot_path])
- return where_output[-1]['path']
-
-
-class MercurialClient(SCMClient):
- """
- A wrapper around the hg Mercurial tool that fetches repository
- information and generates compatible diffs.
- """
- def get_repository_info(self):
- if not check_install('hg --help'):
- return None
-
- data = execute(["hg", "root"], ignore_errors=True)
- if data.startswith('abort:'):
- # hg aborted => no mercurial repository here.
- return None
-
- # Elsewhere, hg root output give us the repository path.
-
- # We save data here to use it as a fallback. See below
- local_data = data.strip()
-
- svn = execute(["hg", "svn", "info", ], ignore_errors=True)
-
- if (not svn.startswith('abort:') and
- not svn.startswith("hg: unknown command")):
- self.type = 'svn'
- m = re.search(r'^Repository Root: (.+)$', svn, re.M)
-
- if not m:
- return None
-
- path = m.group(1)
- m2 = re.match(r'^(svn\+ssh|http|https)://([-a-zA-Z0-9.]*@)(.*)$',
- path)
- if m2:
- path = '%s://%s' % (m2.group(1), m2.group(3))
-
- m = re.search(r'^URL: (.+)$', svn, re.M)
-
- if not m:
- return None
-
- base_path = m.group(1)[len(path):] or "/"
- return RepositoryInfo(path=path,
- base_path=base_path,
- supports_parent_diffs=True)
-
- self.type = 'hg'
-
- # We are going to search .hg/hgrc for the default path.
- file_name = os.path.join(local_data,'.hg', 'hgrc')
-
- if not os.path.exists(file_name):
- return RepositoryInfo(path=local_data, base_path='/',
- supports_parent_diffs=True)
-
- f = open(file_name)
- data = f.read()
- f.close()
-
- m = re.search(r'^default\s+=\s+(.+)$', data, re.M)
-
- if not m:
- # Return the local path, if no default value is found.
- return RepositoryInfo(path=local_data, base_path='/',
- supports_parent_diffs=True)
-
- path = m.group(1).strip()
-
- return RepositoryInfo(path=path, base_path='',
- supports_parent_diffs=True)
-
- def diff(self, files):
- """
- Performs a diff across all modified files in a Mercurial repository.
- """
- # We don't support parent diffs with Mercurial yet, so we always
- # return None for the parent diff.
- if self.type == 'svn':
- parent = execute(['hg', 'parent', '--svn', '--template',
- '{node}\n']).strip()
-
- if options.parent_branch:
- parent = options.parent_branch
-
- if options.guess_summary and not options.summary:
- options.summary = execute(['hg', 'log', '-r.', '--template',
- r'{desc|firstline}\n'])
-
- if options.guess_description and not options.description:
- numrevs = len(execute(['hg', 'log', '-r.:%s' % parent,
- '--follow', '--template',
- r'{rev}\n']).strip().split('\n'))
- options.description = execute(['hg', 'log', '-r.:%s' % parent,
- '--follow', '--template',
- r'{desc}\n\n', '--limit',
- str(numrevs-1)]).strip()
-
- return (execute(["hg", "diff", "--svn", '-r%s:.' % parent]), None)
-
- return (execute(["hg", "diff"] + files), None)
-
- def diff_between_revisions(self, revision_range, args, repository_info):
- """
- Performs a diff between 2 revisions of a Mercurial repository.
- """
- if self.type != 'hg':
- raise NotImplementedError
-
- r1, r2 = revision_range.split(':')
- return execute(["hg", "diff", "-r", r1, "-r", r2])
-
-
-class GitClient(SCMClient):
- """
- A wrapper around git that fetches repository information and generates
- compatible diffs. This will attempt to generate a diff suitable for the
- remote repository, whether git, SVN or Perforce.
- """
- def get_repository_info(self):
- if not check_install('git --help'):
- return None
-
- git_dir = execute(["git", "rev-parse", "--git-dir"],
- ignore_errors=True).strip()
-
- if git_dir.startswith("fatal:") or not os.path.isdir(git_dir):
- return None
-
- # post-review in directories other than the top level of
- # of a work-tree would result in broken diffs on the server
- os.chdir(os.path.dirname(os.path.abspath(git_dir)))
-
- # We know we have something we can work with. Let's find out
- # what it is. We'll try SVN first.
- data = execute(["git", "svn", "info"], ignore_errors=True)
-
- m = re.search(r'^Repository Root: (.+)$', data, re.M)
- if m:
- path = m.group(1)
- m = re.search(r'^URL: (.+)$', data, re.M)
-
- if m:
- base_path = m.group(1)[len(path):] or "/"
- m = re.search(r'^Repository UUID: (.+)$', data, re.M)
-
- if m:
- uuid = m.group(1)
- self.type = "svn"
-
- return SvnRepositoryInfo(path=path, base_path=base_path,
- uuid=uuid,
- supports_parent_diffs=True)
- else:
- # Versions of git-svn before 1.5.4 don't (appear to) support
- # 'git svn info'. If we fail because of an older git install,
- # here, figure out what version of git is installed and give
- # the user a hint about what to do next.
- version = execute(["git", "svn", "--version"], ignore_errors=True)
- version_parts = re.search('version (\d+)\.(\d+)\.(\d+)',
- version)
- svn_remote = execute(["git", "config", "--get",
- "svn-remote.svn.url"], ignore_errors=True)
-
- if (version_parts and
- not self.is_valid_version((int(version_parts.group(1)),
- int(version_parts.group(2)),
- int(version_parts.group(3))),
- (1, 5, 4)) and
- svn_remote):
- die("Your installation of git-svn must be upgraded to " + \
- "version 1.5.4 or later")
-
- # Okay, maybe Perforce.
- # TODO
-
- # Nope, it's git then.
- origin = execute(["git", "remote", "show", "origin"])
- m = re.search(r'URL: (.+)', origin)
- if m:
- url = m.group(1).rstrip('/')
- if url:
- self.type = "git"
- return RepositoryInfo(path=url, base_path='',
- supports_parent_diffs=True)
-
- return None
-
- def is_valid_version(self, actual, expected):
- """
- Takes two tuples, both in the form:
- (major_version, minor_version, micro_version)
- Returns true if the actual version is greater than or equal to
- the expected version, and false otherwise.
- """
- return (actual[0] > expected[0]) or \
- (actual[0] == expected[0] and actual[1] > expected[1]) or \
- (actual[0] == expected[0] and actual[1] == expected[1] and \
- actual[2] >= expected[2])
-
- def scan_for_server(self, repository_info):
- # Scan first for dot files, since it's faster and will cover the
- # user's $HOME/.reviewboardrc
- server_url = super(GitClient, self).scan_for_server(repository_info)
-
- if server_url:
- return server_url
-
- # TODO: Maybe support a server per remote later? Is that useful?
- url = execute(["git", "config", "--get", "reviewboard.url"],
- ignore_errors=True).strip()
- if url:
- return url
-
- if self.type == "svn":
- # Try using the reviewboard:url property on the SVN repo, if it
- # exists.
- prop = SVNClient().scan_for_server_property(repository_info)
-
- if prop:
- return prop
-
- return None
-
- def diff(self, args):
- """
- Performs a diff across all modified files in the branch, taking into
- account a parent branch.
- """
- parent_branch = options.parent_branch or "master"
-
- diff_lines = self.make_diff(parent_branch)
-
- if parent_branch != "master":
- parent_diff_lines = self.make_diff("master", parent_branch)
- else:
- parent_diff_lines = None
-
- if options.guess_summary and not options.summary:
- options.summary = execute(["git", "log", "--pretty=format:%s",
- "HEAD^.."], ignore_errors=True).strip()
-
- if options.guess_description and not options.description:
- options.description = execute(
- ["git", "log", "--pretty=format:%s%n%n%b", parent_branch + ".."],
- ignore_errors=True).strip()
-
- return (diff_lines, parent_diff_lines)
-
- def make_diff(self, parent_branch, source_branch=""):
- """
- Performs a diff on a particular branch range.
- """
- if self.type == "svn":
- diff_lines = execute(["git", "diff", "--no-color", "--no-prefix",
- "-r", "-u", "%s..%s" % (parent_branch,
- source_branch)],
- split_lines=True)
- return self.make_svn_diff(parent_branch, diff_lines)
- elif self.type == "git":
- return execute(["git", "diff", "--no-color", "--full-index",
- parent_branch])
-
- return None
-
- def make_svn_diff(self, parent_branch, diff_lines):
- """
- Formats the output of git diff such that it's in a form that
- svn diff would generate. This is needed so the SVNTool in Review
- Board can properly parse this diff.
- """
- rev = execute(["git", "svn", "find-rev", "master"]).strip()
-
- if not rev:
- return None
-
- diff_data = ""
- filename = ""
- revision = ""
- newfile = False
-
- for line in diff_lines:
- if line.startswith("diff "):
- # Grab the filename and then filter this out.
- # This will be in the format of:
- #
- # diff --git a/path/to/file b/path/to/file
- info = line.split(" ")
- diff_data += "Index: %s\n" % info[2]
- diff_data += "=" * 67
- diff_data += "\n"
- elif line.startswith("index "):
- # Filter this out.
- pass
- elif line.strip() == "--- /dev/null":
- # New file
- newfile = True
- elif line.startswith("--- "):
- newfile = False
- diff_data += "--- %s\t(revision %s)\n" % \
- (line[4:].strip(), rev)
- elif line.startswith("+++ "):
- filename = line[4:].strip()
- if newfile:
- diff_data += "--- %s\t(revision 0)\n" % filename
- diff_data += "+++ %s\t(revision 0)\n" % filename
- else:
- # We already printed the "--- " line.
- diff_data += "+++ %s\t(working copy)\n" % filename
- else:
- diff_data += line
-
- return diff_data
-
- def diff_between_revisions(self, revision_range, args, repository_info):
- pass
-
-
-SCMCLIENTS = (
- SVNClient(),
- CVSClient(),
- GitClient(),
- MercurialClient(),
- PerforceClient(),
- ClearCaseClient(),
-)
-
-def debug(s):
- """
- Prints debugging information if post-review was run with --debug
- """
- if DEBUG or options and options.debug:
- print ">>> %s" % s
-
-
-def make_tempfile():
- """
- Creates a temporary file and returns the path. The path is stored
- in an array for later cleanup.
- """
- fd, tmpfile = mkstemp()
- os.close(fd)
- tempfiles.append(tmpfile)
- return tmpfile
-
-
-def check_install(command):
- """
- Try executing an external command and return a boolean indicating whether
- that command is installed or not. The 'command' argument should be
- something that executes quickly, without hitting the network (for
- instance, 'svn help' or 'git --version').
- """
- try:
- p = subprocess.Popen(command.split(' '),
- stdin=subprocess.PIPE,
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE)
- return True
- except OSError:
- return False
-
-
-def execute(command, env=None, split_lines=False, ignore_errors=False,
- extra_ignore_errors=(), translate_newlines=True):
- """
- Utility function to execute a command and return the output.
- """
- if isinstance(command, list):
- debug(subprocess.list2cmdline(command))
- else:
- debug(command)
-
- if env:
- env.update(os.environ)
- else:
- env = os.environ.copy()
-
- env['LC_ALL'] = 'en_US.UTF-8'
- env['LANGUAGE'] = 'en_US.UTF-8'
-
- if sys.platform.startswith('win'):
- p = subprocess.Popen(command,
- stdin=subprocess.PIPE,
- stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT,
- shell=False,
- universal_newlines=translate_newlines,
- env=env)
- else:
- p = subprocess.Popen(command,
- stdin=subprocess.PIPE,
- stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT,
- shell=False,
- close_fds=True,
- universal_newlines=translate_newlines,
- env=env)
- if split_lines:
- data = p.stdout.readlines()
- else:
- data = p.stdout.read()
- rc = p.wait()
- if rc and not ignore_errors and rc not in extra_ignore_errors:
- die('Failed to execute command: %s\n%s' % (command, data))
-
- return data
-
-
-def die(msg=None):
- """
- Cleanly exits the program with an error message. Erases all remaining
- temporary files.
- """
- for tmpfile in tempfiles:
- try:
- os.unlink(tmpfile)
- except:
- pass
-
- if msg:
- print msg
-
- sys.exit(1)
-
-
-def walk_parents(path):
- """
- Walks up the tree to the root directory.
- """
- while os.path.splitdrive(path)[1] != os.sep:
- yield path
- path = os.path.dirname(path)
-
-
-def load_config_file(filename):
- """
- Loads data from a config file.
- """
- config = {
- 'TREES': {},
- }
-
- if os.path.exists(filename):
- try:
- execfile(filename, config)
- except:
- pass
-
- return config
-
-
-def tempt_fate(server, tool, changenum, diff_content=None,
- parent_diff_content=None, submit_as=None, retries=3):
- """
- Attempts to create a review request on a Review Board server and upload
- a diff. On success, the review request path is displayed.
- """
- try:
- save_draft = False
-
- if options.rid:
- review_request = server.get_review_request(options.rid)
- else:
- review_request = server.new_review_request(changenum, submit_as)
-
- if options.target_groups:
- server.set_review_request_field(review_request, 'target_groups',
- options.target_groups)
- save_draft = True
-
- if options.target_people:
- server.set_review_request_field(review_request, 'target_people',
- options.target_people)
- save_draft = True
-
- if options.summary:
- server.set_review_request_field(review_request, 'summary',
- options.summary)
- save_draft = True
-
- if options.branch:
- server.set_review_request_field(review_request, 'branch',
- options.branch)
- save_draft = True
-
- if options.bugs_closed:
- server.set_review_request_field(review_request, 'bugs_closed',
- options.bugs_closed)
- save_draft = True
-
- if options.description:
- server.set_review_request_field(review_request, 'description',
- options.description)
- save_draft = True
-
- if options.testing_done:
- server.set_review_request_field(review_request, 'testing_done',
- options.testing_done)
- save_draft = True
-
- if save_draft:
- server.save_draft(review_request)
- except APIError, e:
- rsp, = e.args
- if rsp['err']['code'] == 103: # Not logged in
- retries = retries - 1
-
- # We had an odd issue where the server ended up a couple of
- # years in the future. Login succeeds but the cookie date was
- # "odd" so use of the cookie appeared to fail and eventually
- # ended up at max recursion depth :-(. Check for a maximum
- # number of retries.
- if retries >= 0:
- server.login(force=True)
- tempt_fate(server, tool, changenum, diff_content,
- parent_diff_content, submit_as, retries=retries)
- return
-
- if options.rid:
- die("Error getting review request %s: %s (code %s)" % \
- (options.rid, rsp['err']['msg'], rsp['err']['code']))
- else:
- die("Error creating review request: %s (code %s)" % \
- (rsp['err']['msg'], rsp['err']['code']))
-
-
- if not server.info.supports_changesets or not options.change_only:
- try:
- server.upload_diff(review_request, diff_content,
- parent_diff_content)
- except APIError, e:
- rsp, = e.args
- print "Error uploading diff: %s (%s)" % (rsp['err']['msg'],
- rsp['err']['code'])
- debug(rsp)
- die("Your review request still exists, but the diff is not " +
- "attached.")
-
- if options.publish:
- server.publish(review_request)
-
- request_url = 'r/' + str(review_request['id'])
- review_url = urljoin(server.url, request_url)
-
- if not review_url.startswith('http'):
- review_url = 'http://%s' % review_url
-
- print "Review request #%s posted." % (review_request['id'],)
- print
- print review_url
-
- return review_url
-
-
-def parse_options(args):
- parser = OptionParser(usage="%prog [-pond] [-r review_id] [changenum]",
- version="%prog " + VERSION)
-
- parser.add_option("-p", "--publish",
- dest="publish", action="store_true", default=PUBLISH,
- help="publish the review request immediately after "
- "submitting")
- parser.add_option("-r", "--review-request-id",
- dest="rid", metavar="ID", default=None,
- help="existing review request ID to update")
- parser.add_option("-o", "--open",
- dest="open_browser", action="store_true",
- default=OPEN_BROWSER,
- help="open a web browser to the review request page")
- parser.add_option("-n", "--output-diff",
- dest="output_diff_only", action="store_true",
- default=False,
- help="outputs a diff to the console and exits. "
- "Does not post")
- parser.add_option("--server",
- dest="server", default=REVIEWBOARD_URL,
- metavar="SERVER",
- help="specify a different Review Board server "
- "to use")
- parser.add_option("--diff-only",
- dest="diff_only", action="store_true", default=False,
- help="uploads a new diff, but does not update "
- "info from changelist")
- parser.add_option("--target-groups",
- dest="target_groups", default=TARGET_GROUPS,
- help="names of the groups who will perform "
- "the review")
- parser.add_option("--target-people",
- dest="target_people", default=TARGET_PEOPLE,
- help="names of the people who will perform "
- "the review")
- parser.add_option("--summary",
- dest="summary", default=None,
- help="summary of the review ")
- parser.add_option("--description",
- dest="description", default=None,
- help="description of the review ")
- parser.add_option("--description-file",
- dest="description_file", default=None,
- help="text file containing a description of the review")
- parser.add_option("--guess-summary",
- dest="guess_summary", action="store_true",
- default=False,
- help="guess summary from the latest commit (git/"
- "hgsubversion only)")
- parser.add_option("--guess-description",
- dest="guess_description", action="store_true",
- default=False,
- help="guess description based on commits on this branch "
- "(git/hgsubversion only)")
- parser.add_option("--testing-done",
- dest="testing_done", default=None,
- help="details of testing done ")
- parser.add_option("--testing-done-file",
- dest="testing_file", default=None,
- help="text file containing details of testing done ")
- parser.add_option("--branch",
- dest="branch", default=None,
- help="affected branch ")
- parser.add_option("--bugs-closed",
- dest="bugs_closed", default=None,
- help="list of bugs closed ")
- parser.add_option("--revision-range",
- dest="revision_range", default=None,
- help="generate the diff for review based on given "
- "revision range")
- parser.add_option("--label",
- dest="label", default=None,
- help="label (ClearCase Only) ")
- parser.add_option("--submit-as",
- dest="submit_as", default=SUBMIT_AS, metavar="USERNAME",
- help="user name to be recorded as the author of the "
- "review request, instead of the logged in user")
- parser.add_option("--username",
- dest="username", default=None, metavar="USERNAME",
- help="user name to be supplied to the reviewboard server")
- parser.add_option("--password",
- dest="password", default=None, metavar="PASSWORD",
- help="password to be supplied to the reviewboard server")
- parser.add_option("--change-only",
- dest="change_only", action="store_true",
- default=False,
- help="updates info from changelist, but does "
- "not upload a new diff (only available if your "
- "repository supports changesets)")
- parser.add_option("--parent",
- dest="parent_branch", default=None,
- metavar="PARENT_BRANCH",
- help="the parent branch this diff should be against "
- "(only available if your repository supports "
- "parent diffs)")
- parser.add_option("--p4-client",
- dest="p4_client", default=None,
- help="the Perforce client name that the review is in")
- parser.add_option("--p4-port",
- dest="p4_port", default=None,
- help="the Perforce servers IP address that the review is on")
- parser.add_option("--repository-url",
- dest="repository_url", default=None,
- help="the url for a repository for creating a diff "
- "outside of a working copy (currently only supported "
- "by Subversion). Requires --revision-range")
- parser.add_option("-d", "--debug",
- action="store_true", dest="debug", default=DEBUG,
- help="display debug output")
-
- (globals()["options"], args) = parser.parse_args(args)
-
- if options.description and options.description_file:
- sys.stderr.write("The --description and --description-file options "
- "are mutually exclusive.\n")
- sys.exit(1)
-
- if options.description_file:
- if os.path.exists(options.description_file):
- fp = open(options.description_file, "r")
- options.description = fp.read()
- fp.close()
- else:
- sys.stderr.write("The description file %s does not exist.\n" %
- options.description_file)
- sys.exit(1)
-
- if options.testing_done and options.testing_file:
- sys.stderr.write("The --testing-done and --testing-done-file options "
- "are mutually exclusive.\n")
- sys.exit(1)
-
- if options.testing_file:
- if os.path.exists(options.testing_file):
- fp = open(options.testing_file, "r")
- options.testing_done = fp.read()
- fp.close()
- else:
- sys.stderr.write("The testing file %s does not exist.\n" %
- options.testing_file)
- sys.exit(1)
-
- if options.repository_url and not options.revision_range:
- sys.stderr.write("The --repository-url option requires the "
- "--revision-range option.\n")
- sys.exit(1)
-
- return args
-
-def determine_client():
-
- repository_info = None
- tool = None
-
- # Try to find the SCM Client we're going to be working with.
- for tool in SCMCLIENTS:
- repository_info = tool.get_repository_info()
-
- if repository_info:
- break
-
- if not repository_info:
- if options.repository_url:
- print "No supported repository could be access at the supplied url."
- else:
- print "The current directory does not contain a checkout from a"
- print "supported source code repository."
- sys.exit(1)
-
- # Verify that options specific to an SCM Client have not been mis-used.
- if options.change_only and not repository_info.supports_changesets:
- sys.stderr.write("The --change-only option is not valid for the "
- "current SCM client.\n")
- sys.exit(1)
-
- if options.parent_branch and not repository_info.supports_parent_diffs:
- sys.stderr.write("The --parent option is not valid for the "
- "current SCM client.\n")
- sys.exit(1)
-
- if ((options.p4_client or options.p4_port) and \
- not isinstance(tool, PerforceClient)):
- sys.stderr.write("The --p4-client and --p4-port options are not valid "
- "for the current SCM client.\n")
- sys.exit(1)
-
- return (repository_info, tool)
-
-def main():
- if 'USERPROFILE' in os.environ:
- homepath = os.path.join(os.environ["USERPROFILE"], "Local Settings",
- "Application Data")
- elif 'HOME' in os.environ:
- homepath = os.environ["HOME"]
- else:
- homepath = ''
-
- # Load the config and cookie files
- globals()['user_config'] = \
- load_config_file(os.path.join(homepath, ".reviewboardrc"))
- cookie_file = os.path.join(homepath, ".post-review-cookies.txt")
-
- args = parse_options(sys.argv[1:])
-
- repository_info, tool = determine_client()
-
- # Try to find a valid Review Board server to use.
- if options.server:
- server_url = options.server
- else:
- server_url = tool.scan_for_server(repository_info)
-
- if not server_url:
- print "Unable to find a Review Board server for this source code tree."
- sys.exit(1)
-
- server = ReviewBoardServer(server_url, repository_info, cookie_file)
-
- if repository_info.supports_changesets:
- changenum = tool.get_changenum(args)
- else:
- changenum = None
-
- if options.revision_range:
- diff = tool.diff_between_revisions(options.revision_range, args,
- repository_info)
- parent_diff = None
- elif options.label and isinstance(tool, ClearCaseClient):
- diff, parent_diff = tool.diff_label(options.label)
- else:
- diff, parent_diff = tool.diff(args)
-
- if options.output_diff_only:
- print diff
- sys.exit(0)
-
- # Let's begin.
- server.login()
-
- review_url = tempt_fate(server, tool, changenum, diff_content=diff,
- parent_diff_content=parent_diff,
- submit_as=options.submit_as)
-
- # Load the review up in the browser if requested to:
- if options.open_browser:
- try:
- import webbrowser
- if 'open_new_tab' in dir(webbrowser):
- # open_new_tab is only in python 2.5+
- webbrowser.open_new_tab(review_url)
- elif 'open_new' in dir(webbrowser):
- webbrowser.open_new(review_url)
- else:
- os.system( 'start %s' % review_url )
- except:
- print 'Error opening review URL: %s' % review_url
-
-
-if __name__ == "__main__":
- main()
diff --git a/test/review b/test/review
deleted file mode 100755
index e1ccb9c0af..0000000000
--- a/test/review
+++ /dev/null
@@ -1,44 +0,0 @@
-#!/bin/sh
-
-if [ -z $1 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ] || [ "$1" = "-help" ] || [ "$1" = "-?" ]; then
- echo "Usage: `basename $0` [rev] [args]\n"
- echo " [rev] : either the revision number without leading 'r' (post-commit),"
- echo " or '-loc' to create a review from current local changes (pre-commit)\n"
- echo " [args] : optional arguments:"
- echo " -r ID existing review request ID to update\n"
- exit 1
-fi
-
-POSTREVIEW=`dirname $0`/postreview.py
-
-if [ "$1" = "-loc" ]; then
- echo "creating review request from local changes..."
- REVARG=""
- LOG=""
- SUMMARY="local changes"
- REPO=""
-else
- REV=$1
- PREV=`expr $REV - 1`
- if [ $? -ne 0 ]; then
- echo "argument revision not a number: $REV"
- exit 1
- fi
-
- echo "creating review request for changeset $REV..."
-
- LOG="`svn log http://lampsvn.epfl.ch/svn-repos/scala -c $REV`"
- if [ $? -ne 0 ]; then
- echo "could not get svn log for revision $REV"
- exit 1
- fi
-
- REVARG="--revision-range=$PREV:$REV"
- SUMMARY="r$REV"
- REPO="--repository-url=http://lampsvn.epfl.ch/svn-repos/scala"
-fi
-
-
-shift # remove parameter $1 (revision)
-
-python $POSTREVIEW --server="https://chara2.epfl.ch" $REVARG --summary="$SUMMARY" --description="$LOG" $REPO -o $@
diff --git a/test/scaladoc/resources/links.scala b/test/scaladoc/resources/links.scala
index bd69665357..ecac9c63cf 100644
--- a/test/scaladoc/resources/links.scala
+++ b/test/scaladoc/resources/links.scala
@@ -25,6 +25,7 @@ package scala.test.scaladoc.links {
object Target {
type T = Int => Int
type S = Int
+ type ::[X] = scala.collection.immutable.::[X]
class C
def foo(i: Int) = 2
def foo(z: String) = 3
@@ -46,6 +47,7 @@ package scala.test.scaladoc.links {
* - [[[[Target!.foo[A[_[_]]]* trait Target -> def foo with 3 nested tparams]]]] (should exercise nested parens)
* - [[Target$.T object Target -> type T]]
* - [[Target$.S object Target -> type S]]
+ * - [[Target$.:: object Target -> type ::]]
* - [[Target$.foo(z:Str* object Target -> def foo]]
* - [[Target$.bar object Target -> def bar]]
* - [[[[Target$.foo[A[_[_]]]* trait Target -> def foo with 3 nested tparams]]]] (should exercise nested parens)
diff --git a/test/scaladoc/run/links.scala b/test/scaladoc/run/links.scala
index fde24edb2a..64441c2d95 100644
--- a/test/scaladoc/run/links.scala
+++ b/test/scaladoc/run/links.scala
@@ -26,7 +26,7 @@ object Test extends ScaladocModelTest {
val memberLinks = countLinks(TEST.comment.get, _.link.isInstanceOf[LinkToMember[_, _]])
val templateLinks = countLinks(TEST.comment.get, _.link.isInstanceOf[LinkToTpl[_]])
- assert(memberLinks == 17, memberLinks + " == 17 (the member links in object TEST)")
+ assert(memberLinks == 18, memberLinks + " == 18 (the member links in object TEST)")
assert(templateLinks == 6, templateLinks + " == 6 (the template links in object TEST)")
}
}
diff --git a/test/scaladoc/scalacheck/HtmlFactoryTest.scala b/test/scaladoc/scalacheck/HtmlFactoryTest.scala
index 13eacf79a5..d7b5e48288 100644
--- a/test/scaladoc/scalacheck/HtmlFactoryTest.scala
+++ b/test/scaladoc/scalacheck/HtmlFactoryTest.scala
@@ -680,7 +680,7 @@ object Test extends Properties("HtmlFactory") {
property("package object") = files("com/example/p1/package.html") match {
case node: scala.xml.Node =>
- node.toString contains "com.example.p1.package#packageObjectMethod"
+ node.toString contains "com.example.p1#packageObjectMethod"
case _ => false
}
diff --git a/tools/binary-repo-lib.sh b/tools/binary-repo-lib.sh
index 4fe6dd67a0..704bf4944d 100755
--- a/tools/binary-repo-lib.sh
+++ b/tools/binary-repo-lib.sh
@@ -208,7 +208,7 @@ pullJarFile() {
local sha1=$(cat ${jar}${desired_ext})
local jar_dir=$(dirname $jar)
local jar_name=${jar#$jar_dir/}
- local version=${sha1% ?$jar_name}
+ local version=${sha1%% *}
local remote_uri=${version}/${jar#$basedir/}
echo "Resolving [${remote_uri}]"
pullJarFileToCache $remote_uri $version
diff --git a/tools/buildcp b/tools/buildcp
index 766ab81f90..3ae70e10a3 100755
--- a/tools/buildcp
+++ b/tools/buildcp
@@ -8,4 +8,4 @@ lib=$($dir/abspath $dir/../lib)
build=$($dir/abspath $dir/../build)
cp=$($dir/cpof $build/$1/classes):$build/asm/classes
-echo $cp:$lib/fjbg.jar:$lib/msil.jar:$lib/forkjoin.jar:$lib/jline.jar:$lib/extra/'*'
+echo $cp:$lib/forkjoin.jar:$lib/jline.jar:$lib/extra/'*'
diff --git a/tools/make-release-notes b/tools/make-release-notes
deleted file mode 100755
index dcd206f7fc..0000000000
--- a/tools/make-release-notes
+++ /dev/null
@@ -1,49 +0,0 @@
-#!/usr/bin/env bash
-
-# This tool is used to build a *scaffold* of a release note that you can fill in details with before posting to the list.
-# It aims to provide *all* the information you need, and probably need to prune it before releasing.
-# Author: jsuereth
-
-fixMessages() {
- local tag1="$1"
- local tag2="$2"
- git log $tag1..$tag2 "--format=format: * %h - %s" --no-merges --grep "SI-"
-}
-
-allcommitMessages() {
- local tag1="$1"
- local tag2="$2"
- git log $tag1..$tag2 "--format=format: * %h - %s" --no-merges
-}
-
-authors() {
- local tag1="$1"
- local tag2="$2"
- git log $tag1..$tag2 --format=format:%an --no-merges | sort | uniq -c | sort -rh
-}
-
-
-message() {
- local tag1="$1"
- local tag2="$2"
-
- echo "A new release of Scala is available! Please point your build tools at ${tag2#v}"
- echo
- echo "Here's a list of the issues that have been fixed since ${tag1#v}: "
- fixMessages "$tag1" "$tag2"
- echo
- echo
- echo "Special thanks to all the contributions!"
- echo "------- --------------------------------"
- authors "$tag1" "$tag2"
- echo "------- --------------------------------"
- echo
- echo
- echo "Here's a complete list of changes:"
- allcommitMessages "$tag1" "$tag2"
-}
-
-
-message "$1" "$2"
-
-
diff --git a/tools/make-release-notes.scala b/tools/make-release-notes.scala
new file mode 100644
index 0000000000..3e5b60d223
--- /dev/null
+++ b/tools/make-release-notes.scala
@@ -0,0 +1,129 @@
+#!/bin/sh
+exec scala -feature $0 $@
+!#
+
+import sys.process._
+
+val tag1 = "v2.10.0-M4"
+val tag2 = "v2.10.0-M5"
+
+// Git commit parsing magikz
+
+case class Commit(sha: String, author: String, header: String, body: String) {
+ override def toString = " * " + sha + " (" + author + ") " + header + " - " + body.take(5) + " ..."
+}
+
+val gitFormat = "--format=format:*-*%h``%aN``%s``%b"
+
+def processGitCommits(input: String): IndexedSeq[Commit] =
+ ((input split "[\\r\\n]*\\*\\-\\*").view map (_ split "``") collect {
+ case Array(sha, author, hdr, msg) => Commit(sha, author, hdr, msg)
+ }).toVector
+
+val commits =
+ processGitCommits(Process(Seq("git", "log", tag1+".."+tag2,"--format=format:*-*%h``%aN``%s``%b","--no-merges")).!!)
+
+val authors: Seq[(String, Int)] = {
+ val grouped: Vector[(String,Int)] = (commits groupBy (_.author)).map { case (a,c) => a -> c.length }{collection.breakOut}
+ (grouped sortBy (_._2)).reverse
+}
+
+def hasFixins(msg: String): Boolean = (
+ (msg contains "SI-") /*&& ((msg.toLowerCase contains "fix") || (msg.toLowerCase contains "close"))*/
+)
+
+val fixCommits =
+ for {
+ commit <- commits
+ searchString = commit.body + commit.header
+ if hasFixins(searchString)
+ } yield commit
+
+
+val siPattern = java.util.regex.Pattern.compile("(SI-[0-9]+)")
+
+def fixLinks(commit: Commit): String = {
+ val searchString = commit.body + commit.header
+ val m = siPattern matcher searchString
+ val issues = new collection.mutable.ArrayBuffer[String]
+ while(m.find()) {
+ issues += (m group 1)
+ }
+ issues map (si => """<a href="https://issues.scala-lang.org/browse/%s">%s</a>""" format (si, si)) mkString ", "
+}
+
+
+// HTML Generation for Toni
+
+def commitShaLink(sha: String) =
+ """<a href="https://github.com/scala/scala/commit/%s">%s</a>""" format (sha,sha)
+
+def printBlankLine(): Unit = println("<p>&nbsp</p>")
+def printHeader4(msg: String): Unit = println("<h4>%s</h4>" format (msg))
+
+def printCommiterList(): Unit = {
+ printBlankLine()
+ printHeader4("Special thanks to all the contribtuors!")
+ println("""<table border="0" cellspacing="0" cellpadding="1">
+ <thead><tr><th>#</th><th align="left">Author</th></tr></thead>
+ <tbody>""")
+ for((author, count) <- authors)
+ println("""<tr><td align="right">%d &nbsp;</td><td>%s</td></tr>""" format (count, author))
+ println("""</tbody>
+</table>""")
+}
+
+def printCommitList(): Unit = {
+ printBlankLine()
+ printHeader4("Complete commit list!")
+ println("""<table border="0" cellspacing="0" cellpadding="1">
+ <thead><tr><th>sha</th><th align="left">Title</th></tr></thead>
+ <tbody>""")
+ for(commit <- commits) {
+ println("<tr>")
+ println("""<td align="right">%s&nbsp;</td><td>%s</td>""" format (commitShaLink(commit.sha), commit.header))
+ /*print("<td>")
+ (commit.body split "[\\r\\n]") foreach { line =>
+ print(line)
+ print("<br/>")
+ }
+ print("</td>")*/
+ println("""</tr>""")
+ }
+ println("""</tbody>
+</table>""")
+}
+
+def issueFixPrinter(): Unit = {
+ printBlankLine()
+ printHeader4("Here's a list of isssues that have been fixed since %s" format (tag1))
+ println("""<table border="0" cellspacing="0" cellpading="1">
+ <thead><tr><th>Issue(s)</th><th>Commit</th><th>Message</th></tr></thead>
+ <tbody>""")
+ for(commit <- fixCommits) {
+ println("""<tr><td>%s&nbsp;</td><td>%s&nbsp;</td><td>%s</td></tr>""" format(fixLinks(commit), commitShaLink(commit.sha), commit.header))
+ }
+ println("""</tbody>
+</table>""")
+ printBlankLine()
+}
+
+def printHTML(): Unit = {
+ println("""<html>
+ <head>
+ <title>%s - Release notes</title>
+ </head>
+ <body>
+ <h3>A new release of Scala is available! Please point your build tools at %s</h3>
+ <p>:: INSERT HAND GENERATED NOTES HERE ::</p>
+""" format(tag2, tag2 drop 1))
+ issueFixPrinter()
+ printCommiterList()
+ printCommitList()
+ println("""</body></html>""")
+}
+
+printHTML()
+
+
+
diff --git a/tools/partest-ack b/tools/partest-ack
new file mode 100755
index 0000000000..0c8244257b
--- /dev/null
+++ b/tools/partest-ack
@@ -0,0 +1,71 @@
+#!/usr/bin/env bash
+#
+# wrapper around partest for fine-grained test selection via ack
+
+args="$@"
+
+pathMatches () {
+ ack --noenv --text --files-with-matches "$@" test/files
+
+ for p in $(find test/files/* -print); do
+ [[ $p =~ $1 ]] && echo "$p"
+ done
+}
+
+testIds () {
+ pathMatches "$@" | \
+ perl -pe 's#^(test/files/[^/]+/[^/.]+).*$#$1#' | \
+ sort -u
+}
+testPaths () {
+ for id in "$@"; do
+ if [[ -d $id ]]; then
+ echo $id
+ elif [[ -f ${id}.scala ]]; then
+ echo "${id}.scala"
+ else
+ echo >&2 "No test corresponds to $id"
+ fi
+ done
+}
+
+[[ $# -gt 0 ]] || {
+ cat <<EOM
+Usage: $0 <regex> [ack options]
+
+Given a regular expression (and optionally, any arguments accepted by ack)
+runs all the tests for which any associated file matches the regex. Associated
+files include .check and .flags files. Tests in directories will match if any
+file matches. A file can match the regex by its contents or by its name.
+
+You must have ack installed: http://betterthangrep.com/ack-standalone
+
+Examples:
+
+ % tools/partest-ack monad
+ Found 4 tests matching 'ack monad'
+
+ Testing individual files
+ testing: [...]/files/pos/tcpoly_boundedmonad.scala [ OK ]
+ testing: [...]/files/pos/tcpoly_ticket2096.scala [ OK ]
+ testing: [...]/files/run/tcpoly_monads.scala [ OK ]
+ testing: [...]/files/presentation/callcc-interpreter [ OK ]
+
+ % tools/partest-ack monad -i # -i == ignore case
+ Found 12 tests matching 'ack monad -i'
+
+ Testing individual files
+ [etc]
+EOM
+
+ exit 0
+}
+
+paths=$(testPaths $(testIds "$@"))
+if [[ -z $paths ]]; then
+ echo >&2 "No matching tests."
+else
+ count=$(echo $(echo "$paths" | wc -w))
+ echo "Found $count tests matching 'ack $@'"
+ test/partest $paths
+fi
diff --git a/tools/strapcp b/tools/strapcp
index 6a46b4e1c8..6a4044ae24 100755
--- a/tools/strapcp
+++ b/tools/strapcp
@@ -6,7 +6,6 @@ strap="$dir/../build/strap/classes"
[[ -d $strap ]] || { echo "Error: no directory at $strap"; exit 1; }
cp=$($dir/cpof $strap)
-fjbg=$($dir/abspath $dir/../lib/fjbg.jar)
asm=$($dir/abspath $dir/../build/asm/classes)
-echo $cp:$fjbg:$asm
+echo $cp:$asm