Skip to content

Commit 7194b71

Browse files
committed
Fixed scala code generation for test cases.
Confirmed able to generate both Scala and Java expression problem code, validating compilation and test cases.
1 parent e1d89f0 commit 7194b71

8 files changed

Lines changed: 20 additions & 24 deletions

File tree

approach/src/main/scala/org/combinators/ep/approach/oo/ExtensibleVisitor.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ trait ExtensibleVisitor extends SharedOO with OperationAsClass {
9999
_ <- addTypeParameter(visitTyParam, Command.skip)
100100

101101
// this returns mangled visitTypeParameter name and gets list of all type parameters, for which there is only one, so we get head
102-
args <- getTypeArguments()
102+
args <- getTypeArguments
103103
_ <- setReturnType(args.head)
104104

105105
// identify Visitor<R>
@@ -428,7 +428,7 @@ trait ExtensibleVisitor extends SharedOO with OperationAsClass {
428428
vType = visitorInterfaceName(model) // convert Name to a class
429429

430430
visitorClassType <- findClass(vType *)
431-
tpeParam <- getTypeArguments()
431+
tpeParam <- getTypeArguments
432432
instVisitClassType <- applyType(visitorClassType, tpeParam)
433433
castV <- castObject(instVisitClassType, v)
434434
// invoke visit method on 'v' with 'this' as argument

approach/src/main/scala/org/combinators/ep/approach/oo/RuntimeDispatch.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ trait RuntimeDispatch extends SharedOO with OperationAsClass {
125125
*/
126126
def makeDispatchingOperation(model: GenericModel, op: Operation): Generator[ClassContext, Unit] = {
127127
def ifStmt(): Generator[MethodBodyContext, Option[Expression]] = {
128-
import exceptions.exceptisonCapabilities._
128+
import exceptions.exceptionsCapabilities._
129129
import impParadigm.imperativeCapabilities._
130130
import ooParadigm.methodBodyCapabilities._
131131
import paradigm.methodBodyCapabilities._

approach/src/main/scala/org/combinators/ep/approach/oo/Visitor.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ trait Visitor extends SharedOO with OperationAsClass { self =>
238238
_ <- addTypeParameter(visitTyParam, Command.skip)
239239

240240
// this returns mangled visitTypeParameter name and gets list of all type parameters, for which there is only one, so we get head
241-
args <- getTypeArguments()
241+
args <- getTypeArguments
242242
_ <- setReturnType(args.head)
243243

244244
// identify Visitor<R>

builder/src/main/scala/org/combinators/ep/builder/java/Main.scala

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -577,8 +577,6 @@ object GenerateAllForOneApproach extends IOApp {
577577

578578

579579
object QuickValidation extends Subselection {
580-
581-
582580
// note that visitorSideEffect and dispatch are omitted from this validation. VISITORSIDEEFFECT has a problem
583581
// with the test cases in that the methods become too long for the JavaVM and attempts to subdivide them fail
584582
// because visitorSideEffect needs to create visitor objects, and arbitrarily splitting test cases means that
@@ -595,12 +593,9 @@ object QuickValidation extends Subselection {
595593

596594
// latest in all system families
597595
val evolutions = Seq("M9", "J8", "A3", "O1OA", "OD3", "OO3", "V1", "D3", "I2M3I1N1", "O2")
598-
599596
}
600597

601598
object GenerateAllMain extends Subselection {
602-
603-
604599
def approaches(args: List[String]): Seq[String] = if (args.isEmpty) {
605600
Seq("oo", "visitor", "extensibleVisitor", "interpreter", "coco", "trivially", "algebra")
606601
} else {
@@ -613,12 +608,9 @@ object GenerateAllMain extends Subselection {
613608
}
614609
val evolutions = Seq("M0", "M1", "M2", "M3", "M4", "M5", "M6", "M7", "M7I2", "M8", "M9", "I1", "A1", "A1M3", "A1M3I2", "A3", "I2",
615610
"O1", "O2", "OA", "O1OA", "OD1", "OD2", "OD3", "OO1", "OO2", "OO3")
616-
617611
}
618612

619613
object GenerateAllJ extends Subselection {
620-
621-
622614
def approaches(args: List[String]): Seq[String] = if (args.isEmpty) {
623615
Seq("oo", "visitor", "extensibleVisitor", "interpreter", "coco", "trivially", "algebra")
624616
} else {
@@ -630,11 +622,9 @@ object GenerateAllJ extends Subselection {
630622
args.head
631623
}
632624
val evolutions = Seq("M0", "J1", "J2", "J3", "K1", "K2", "J4", "J5", "J6", "K2J6", "J7", "J8")
633-
634625
}
635626

636627
object GenerateAllD1D2 extends Subselection {
637-
638628
def approaches(args: List[String]): Seq[String] = if (args.isEmpty) {
639629
Seq("oo", "visitor", "extensibleVisitor", "interpreter", "coco", "trivially", "algebra")
640630
} else {
@@ -649,7 +639,6 @@ object GenerateAllD1D2 extends Subselection {
649639
}
650640

651641
object GenerateAllMerging extends Subselection {
652-
653642
def approaches(args: List[String]): Seq[String] = if (args.isEmpty) {
654643
Seq("oo", "visitor", "extensibleVisitor", "interpreter", "coco", "trivially", "algebra")
655644
} else {
@@ -664,8 +653,6 @@ object GenerateAllMerging extends Subselection {
664653
}
665654

666655
object GenerateAllExtended extends Subselection {
667-
668-
669656
def approaches(args: List[String]): Seq[String] = if (args.isEmpty) {
670657
Seq("oo", "visitor", "extensibleVisitor", "interpreter", "coco", "trivially", "algebra")
671658
} else {
@@ -680,8 +667,6 @@ object GenerateAllExtended extends Subselection {
680667
}
681668

682669
object GenerateAllThirdAlternate extends Subselection {
683-
684-
685670
def approaches(args: List[String]): Seq[String] = if (args.isEmpty) {
686671
Seq("oo", "visitor", "extensibleVisitor", "interpreter", "coco", "trivially", "algebra")
687672
} else {
@@ -696,8 +681,6 @@ object GenerateAllThirdAlternate extends Subselection {
696681
}
697682

698683
object GenerateShapes extends Subselection {
699-
700-
701684
def approaches(args: List[String]): Seq[String] = if (args.isEmpty) {
702685
Seq("oo", "visitor", "extensibleVisitor", "interpreter", "coco", "trivially", "algebra")
703686
} else {

builder/src/main/scala/org/combinators/ep/builder/scala/Main.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,14 @@ class Main(choice:String, select:String) {
6969
val ast: FullAST & TreesAST = new FinalBaseAST
7070
with FinalNameProviderAST
7171
with FinalArithmeticAST
72+
with FinalArraysAST
7273
with FinalAssertionsAST
7374
with FinalBooleanAST
75+
with FinalConsoleAST
7476
with FinalEqualsAST
77+
with FinalExceptionsAST
7578
with FinalListsAST
79+
with FinalMapsAST
7680
with FinalOperatorExpressionsAST
7781
with FinalRealArithmeticOpsAST
7882
with FinalStringAST

language/inbetween/src/main/scala/org/combinators/ep/language/inbetween/any/AnyParadigm.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,14 @@ trait AnyParadigm[A, S](val ast: AnyAST & A, val syntax: AbstractSyntax.Abstract
149149
// underlying methods to exceed their maximum size.
150150
val groups = result.sliding(25,25)
151151

152+
var lastFresh:Name = command.name
152153
val blocks = groups.map(g => {
153154
val emptyMethod = factory.method(
154155
name = sample.getFreshName(command.name),
155156
typeLookupMap = context.methodTypeLookupMap
156157
)
157-
sample.addTestExpressions(g)
158+
lastFresh = sample.getFreshName(lastFresh) // prepare for next time
159+
emptyMethod.addTestExpressions(g)
158160
})
159161
(context.copy(tests = context.tests ++ blocks), ())
160162
}

language/newScala/src/main/scala/org/combinators/ep/language/scala/ast/BaseAST.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,15 +287,16 @@ trait BaseAST extends OOAST with FunctionalAST with GenericsAST with FunctionalC
287287
underlyingClass.addParent(classReferenceType(
288288
Seq("org", "scalatest", "funsuite", "AnyFunSuite").map(n => nameProvider.mangle(n)) *
289289
))
290-
val methodsAsTests = withFunSuiteExtension.methods.zip(this.testMarkers).filter { case (m, isTest) => isTest }.map { case (m, _) => {
290+
291+
val methodsAsTests = withFunSuiteExtension.methods.zip(this.testMarkers).filter { case (m, isTest) => isTest }.map { case (m, _) =>
291292
liftExpression(applyExpression(
292293
applyExpression(
293294
memberAccessExpression(selfReferenceExpression, nameProvider.mangle("test")),
294295
Seq(reifiedScalaValue(TypeRep.String, m.name.component))
295296
),
296297
Seq(blockExpression(m.statements))
297298
))
298-
}
299+
299300
}
300301
val withPrimaryClsConstructor = if (underlyingClass.constructors.isEmpty) {
301302
withFunSuiteExtension.addConstructor(constructor(statements = methodsAsTests))

scripts/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ For simplicity, all instructions using the 'sbt' command line.
2929
* ep-java-third-alternate (GenerateAllThirdAlternate)
3030
* Approaches: oo visitor visitorSideEffect extensibleVisitor interpreter coco trivially dispatch algebra
3131
* Evolutions: M0 X1 X2 X3 X2X3 X4
32+
33+
* ep-java-quick (QuickValidation) -- Note that you cannot validate this generation (so skip step 2 below)
34+
* Approaches: trivially oo visitor extensibleVisitor interpreter coco algebra
35+
* Evolutions: A3 D3 I2M3I1N1 J8 M9 O1OA O2 OD3 OO3 V1
3236

3337
For Scala-generated code, the above are replaced with `ep-scala-XXX` and approaches and
3438
evolutions remain the same.
@@ -128,6 +132,8 @@ or
128132
source code, executing the test cases and code coverage statistics. This script also detects
129133
errors in these three phases.
130134

135+
Make sure `scipy` is installed
136+
131137
In the respective ep-java-XXX directories, execute the following Python script:
132138

133139
```c:\Python37\python.exe ..\..\scripts\process.py > STATISTICS```

0 commit comments

Comments
 (0)