[Nice-commit] Nice/src/bossa/syntax Constructor.java,1.8,1.9
Brought to you by:
bonniot
From: <bo...@us...> - 2003-11-27 21:02:16
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1:/tmp/cvs-serv16784/src/bossa/syntax Modified Files: Constructor.java Log Message: Allow 'this' to be captured in initializers. Index: Constructor.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/Constructor.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Constructor.java 26 Nov 2003 16:25:55 -0000 1.8 --- Constructor.java 27 Nov 2003 21:02:13 -0000 1.9 *************** *** 86,90 **** { ClassType thisType = (ClassType) javaReturnType(); ! Expression thisExp = new ThisExp(thisType); MonoSymbol[] fullArgs = parameters.getMonoSymbols(); --- 86,92 ---- { ClassType thisType = (ClassType) javaReturnType(); ! Declaration thisDecl = new Declaration("this"); ! thisDecl.setType(thisType); ! Expression thisExp = new ThisExp(thisDecl); MonoSymbol[] fullArgs = parameters.getMonoSymbols(); *************** *** 129,161 **** ConstructorExp lambda = Gen.createConstructor ! (thisType, argTypesArray, argsArray); ! ! Expression[] body = ! new Expression[1 + fields.length + classe.nbInitializers()]; ! ! body[0] = callSuper(thisExp, fullArgs, omitDefaults); ! ! final int superArgs = fullArgs.length - fields.length; ! ! for (int i = 0; i < fields.length; i++) ! { ! bossa.syntax.Expression value = fields[i].value; ! ! Expression fieldValue; ! if (!omitDefaults || value == null) ! // Use the provided parameter. ! fieldValue = fullArgs[superArgs + i].compile(); ! else ! // Use the default value. ! fieldValue = value.compile(); ! ! body[1 + i] = fields[i].method.compileAssign(thisExp, fieldValue); ! } ! ! classe.setThisExp(thisExp); ! for (int i = 0; i < classe.nbInitializers(); i++) ! body[1 + fields.length + i] = classe.compileInitializer(i); ! Gen.setMethodBody(lambda, new BeginExp(body)); classe.getClassExp().addMethod(lambda); --- 131,138 ---- ConstructorExp lambda = Gen.createConstructor ! (thisDecl, argTypesArray, argsArray); ! lambda.setSuperCall(callSuper(thisExp, fullArgs, omitDefaults)); ! Gen.setMethodBody(lambda, body(thisExp, fullArgs, omitDefaults)); classe.getClassExp().addMethod(lambda); *************** *** 186,189 **** --- 163,200 ---- return new ApplyExp(superExp, (Expression[]) superArgs.toArray(new Expression[superArgs.size()])); + } + + private Expression body(Expression thisExp, + MonoSymbol[] fullArgs, boolean omitDefaults) + { + int len = fields.length + classe.nbInitializers(); + + if (len == 0) + return QuoteExp.voidExp; + + Expression[] body = new Expression[len]; + + final int superArgs = fullArgs.length - fields.length; + + for (int i = 0; i < fields.length; i++) + { + bossa.syntax.Expression value = fields[i].value; + + Expression fieldValue; + if (!omitDefaults || value == null) + // Use the provided parameter. + fieldValue = fullArgs[superArgs + i].compile(); + else + // Use the default value. + fieldValue = value.compile(); + + body[i] = fields[i].method.compileAssign(thisExp, fieldValue); + } + + classe.setThisExp(thisExp); + for (int i = 0; i < classe.nbInitializers(); i++) + body[fields.length + i] = classe.compileInitializer(i); + + return new BeginExp(body); } |