compiler/PPCBenchmarkResources.st
changeset 414 0eaf09920532
parent 413 5389e6fbb3bc
--- a/compiler/PPCBenchmarkResources.st	Wed Nov 05 21:40:01 2014 +0000
+++ b/compiler/PPCBenchmarkResources.st	Wed Nov 05 23:05:19 2014 +0000
@@ -2,13 +2,29 @@
 
 Object subclass:#PPCBenchmarkResources
 	instanceVariableNames:''
-	classVariableNames:''
+	classVariableNames:'javaCache'
 	poolDictionaries:''
 	category:'PetitCompiler-Benchmarks'
 !
 
 !PPCBenchmarkResources methodsFor:'as yet unclassified'!
 
+changesSized: size
+	| string changes |
+	changes := PharoFilesOpener default changesFileOrNil contents.
+	string :=  changes copyFrom: 1 to: size.
+	^ string
+	
+!
+
+javaInDirectory: directory
+	| files |
+	files := self readDirectory: directory.
+	files := self files: files withExtension: 'java'.
+	
+	^ files collect: [ :f | (FileStream fileNamed: f) contents ]
+!
+
 javaLangClass
 !
 
@@ -1236,6 +1252,10 @@
 '
 !
 
+javaSourcesBig
+	^ self workingJavaInDirectory: '../java-src/java/util'
+!
+
 petitParserPackage
 ^ '
 Object subclass: #PPCharSetPredicate
@@ -5163,5 +5183,34 @@
 	^ ((Smalltalk allClasses copyFrom: 1 to: 30) collect: [ :c |
 			c allMethods collect: [ :m | m sourceCode ]
 	  ]) gather: [:each | each ].
+!
+
+workingJavaInDirectory: directory
+	| sources parser |
+	"return only such a files, that can be parsed by PPJavaSyntax"
+
+	javaCache ifNil: [ javaCache := Dictionary new ].
+	
+	^ javaCache at: directory ifAbsentPut: [ 
+		sources := self javaInDirectory: directory.
+		parser := PPJavaSyntax new.
+	
+		sources select: [ :source | ([parser parse: source ] on: Error do: [ PPFailure new ]) isPetitFailure not ]	
+	]
 ! !
 
+!PPCBenchmarkResources methodsFor:'private utilities'!
+
+files: files withExtension: extension
+	^ files select: [ :f | f extension = extension ] 
+!
+
+readDirectory: directory
+	| file |
+	file := directory asFileReference.
+	file exists ifTrue: [ 
+		^ file allFiles
+	].
+	^ #()
+! !
+