View | Details | Raw Unified | Return to bug 354244
Collapse All | Expand All

(-)compiler/org/eclipse/objectteams/otdt/internal/core/compiler/mappings/CallinImplementor.java (-31 / +40 lines)
Lines 497-504 Link Here
497
497
498
		// ------------- support for reflective function isExecutingCallin():
498
		// ------------- support for reflective function isExecutingCallin():
499
		// boolean oldIsExecutingCallin = _OT$setExecutingCallin();
499
		// boolean oldIsExecutingCallin = _OT$setExecutingCallin();
500
        // try { ... main dispatching statements ... }
501
        // finally { resetFlag }
500
		MessageSend resetFlag = setExecutingCallin(roleModel, statements);
502
		MessageSend resetFlag = setExecutingCallin(roleModel, statements);
501
503
504
		// from here on all statements go into the try block - with "finally { resetFlag(); }"
505
        ArrayList<Statement> tryStatements = new ArrayList<Statement>();
506
507
		
502
		// -------------- call receiver & arguments --------------
508
		// -------------- call receiver & arguments --------------
503
		//_OT$role.myRoleMethod(_OT$param0, ...);
509
		//_OT$role.myRoleMethod(_OT$param0, ...);
504
		// or:
510
		// or:
Lines 517-523 Link Here
517
        	return false;
523
        	return false;
518
        }
524
        }
519
        // pack unmapped arguments (positions are set by above makeWrapperCallArguments):
525
        // pack unmapped arguments (positions are set by above makeWrapperCallArguments):
520
        packUnmappedArgs(baseMethodSpec, callinBindingDeclaration, callinWrapperDecl, statements, gen);
526
        packUnmappedArgs(baseMethodSpec, callinBindingDeclaration, callinWrapperDecl, tryStatements, gen);
521
527
522
		// for role-side predicate
528
		// for role-side predicate
523
        Expression[] predicateArgs = null;
529
        Expression[] predicateArgs = null;
Lines 557-563 Link Here
557
	
563
	
558
			//MyRole _OT$role = _OT$liftToMyRole(_OT$base_arg);
564
			//MyRole _OT$role = _OT$liftToMyRole(_OT$base_arg);
559
			if (needRoleVar)
565
			if (needRoleVar)
560
				statements.add(createLiftedRoleVar(callinBindingDeclaration, roleModel, baseTypeBinding, otBaseArg, gen));
566
				tryStatements.add(createLiftedRoleVar(callinBindingDeclaration, roleModel, baseTypeBinding, otBaseArg, gen));
561
567
562
			// store mapped arguments in local variables to use for predicate check
568
			// store mapped arguments in local variables to use for predicate check
563
			// and wrapper call.
569
			// and wrapper call.
Lines 566-572 Link Here
566
			Expression[] newArgs = new Expression[plainLen];
572
			Expression[] newArgs = new Expression[plainLen];
567
			for (int i = offset; i < messageSendArguments.length; i++) {
573
			for (int i = offset; i < messageSendArguments.length; i++) {
568
 				char[] localName = (OT_LOCAL+i).toCharArray();
574
 				char[] localName = (OT_LOCAL+i).toCharArray();
569
				statements.add(gen.localVariable(
575
 				tryStatements.add(gen.localVariable(
570
 						localName,
576
 						localName,
571
						roleParameters[i-offset],
577
						roleParameters[i-offset],
572
 						new PotentialRoleReceiverExpression(messageSendArguments[i], ROLE_VAR_NAME, gen.typeReference(roleModel.getClassPartBinding()))));
578
 						new PotentialRoleReceiverExpression(messageSendArguments[i], ROLE_VAR_NAME, gen.typeReference(roleModel.getClassPartBinding()))));
Lines 595-601 Link Here
595
				gen);
601
				gen);
596
		if (predicateCheck != null)
602
		if (predicateCheck != null)
597
        	// predicateCheck(_OT$role)
603
        	// predicateCheck(_OT$role)
598
        	statements.add(predicateCheck);
604
			tryStatements.add(predicateCheck);
599
605
600
		// ------------- the role message send:
606
		// ------------- the role message send:
601
		MessageSend roleMessageSend = gen.messageSend(receiver, roleMethodName, messageSendArguments);
607
		MessageSend roleMessageSend = gen.messageSend(receiver, roleMethodName, messageSendArguments);
Lines 642-653 Link Here
642
			callinBindingDeclaration.resultVar = gen.localVariable(
648
			callinBindingDeclaration.resultVar = gen.localVariable(
643
											IOTConstants.OT_RESULT, wrapperReturnType, null);
649
											IOTConstants.OT_RESULT, wrapperReturnType, null);
644
			callinBindingDeclaration.resultVar.type.setBaseclassDecapsulation(DecapsulationState.REPORTED);
650
			callinBindingDeclaration.resultVar.type.setBaseclassDecapsulation(DecapsulationState.REPORTED);
645
			statements.add(callinBindingDeclaration.resultVar);
651
			tryStatements.add(callinBindingDeclaration.resultVar);
646
			Statement roleMessageSendStatement = gen.assignment(
652
			tryStatements.add(gen.assignment(
647
											gen.singleNameReference(IOTConstants.OT_RESULT),
653
									gen.singleNameReference(IOTConstants.OT_RESULT),
648
											roleMessageSendExpression);
654
									roleMessageSendExpression));
655
			
656
			// ResultNotProvidedException?
657
			if (isReturnBoxed && !callinBindingDeclaration.isResultMapped)
658
			{
659
				tryStatements.add(genResultNotProvidedCheck(
660
						this._role.getTeamModel().getBinding().sourceName(),
661
						roleTypeName, roleMethodBinding, baseTypeBinding, baseMethodSpec, gen));
662
			}
663
			// ------------- possibly convert using result mapping
664
			if (   callinBindingDeclaration.mappings != null
665
					&& callinBindingDeclaration.isResultMapped)
666
			{
667
				tryStatements.add(
668
						stepOverGen.returnStatement(
669
								new PotentialRoleReceiverExpression(
670
										callinBindingDeclaration.getResultExpression(baseMethodSpec, isReturnBoxed, stepOverGen),
671
										ROLE_VAR_NAME,
672
										gen.typeReference(roleModel.getClassPartBinding()))));
673
			} else {
674
				tryStatements.add(
675
						stepOverGen.returnStatement(stepOverGen.singleNameReference(IOTConstants.OT_RESULT)));
676
			}
677
			
649
			TryStatement tryFinally = gen.tryFinally(
678
			TryStatement tryFinally = gen.tryFinally(
650
								new Statement[] {roleMessageSendStatement},
679
								tryStatements.toArray(new Statement[tryStatements.size()]),
651
								new Statement[] {resetFlag});
680
								new Statement[] {resetFlag});
652
// for debugging:
681
// for debugging:
653
//			tryFinally.catchArguments = new Argument[] {
682
//			tryFinally.catchArguments = new Argument[] {
Lines 672-706 Link Here
672
//			};
701
//			};
673
			statements.add(tryFinally);
702
			statements.add(tryFinally);
674
703
675
			// ResultNotProvidedException?
676
			if (isReturnBoxed && !callinBindingDeclaration.isResultMapped)
677
			{
678
				statements.add(genResultNotProvidedCheck(
679
						this._role.getTeamModel().getBinding().sourceName(),
680
						roleTypeName, roleMethodBinding, baseTypeBinding, baseMethodSpec, gen));
681
			}
682
			// ------------- possibly convert using result mapping
683
			if (   callinBindingDeclaration.mappings != null
684
				&& callinBindingDeclaration.isResultMapped)
685
			{
686
				statements.add(
687
					stepOverGen.returnStatement(
688
							new PotentialRoleReceiverExpression(
689
									callinBindingDeclaration.getResultExpression(baseMethodSpec, isReturnBoxed, stepOverGen),
690
									ROLE_VAR_NAME,
691
									gen.typeReference(roleModel.getClassPartBinding()))));
692
			} else {
693
				statements.add(
694
					stepOverGen.returnStatement(stepOverGen.singleNameReference(IOTConstants.OT_RESULT)));
695
			}
696
		} else {
704
		} else {
697
			// try {
705
			// try {
698
			//    _OT$role.myRoleMethod(_OT$param0);
706
			//    _OT$role.myRoleMethod(_OT$param0);
699
			// finally {
707
			// finally {
700
			//     _OT$setExecutingCallin(oldIsExecutingCallin);
708
			//     _OT$setExecutingCallin(oldIsExecutingCallin);
701
			// }
709
			// }
710
			tryStatements.add(roleMessageSend);
702
			statements.add(gen.tryFinally(
711
			statements.add(gen.tryFinally(
703
					new Statement[] {roleMessageSend},
712
					tryStatements.toArray(new Statement[tryStatements.size()]),
704
					new Statement[] {resetFlag}));
713
					new Statement[] {resetFlag}));
705
			statements.add(stepOverGen.returnStatement(null)); // empty return to ensure step-over in the end
714
			statements.add(stepOverGen.returnStatement(null)); // empty return to ensure step-over in the end
706
		}
715
		}
(-)otjld/org/eclipse/objectteams/otdt/tests/otjld/teamactivation/Predicates.java (+44 lines)
Lines 2652-2658 Link Here
2652
    		"----------\n");
2652
    		"----------\n");
2653
    }
2653
    }
2654
2654
2655
    // Bug 354244 - Role-side callin guard predicate interferes with Team.isExecutingCallin()
2656
    public void test914_bindingPredicate22() {
2655
2657
2658
        runConformTest(
2659
             new String[] {
2660
 		"T914bp22Main.java",
2661
 			    "\n" +
2662
 			    "public class T914bp22Main {\n" +
2663
 			    "	public static void main(String[] args) {\n" +
2664
 			    "		Team914bp22 t = new Team914bp22();\n" +
2665
 			    "		T914bp22 o = new T914bp22();\n" +
2666
 			    "		t.activate();\n" +
2667
 			    "		o.test(1);\n" +
2668
 			    "       if (t.isExecutingCallin())\n" +
2669
 			    "           throw new Error(\"Flag not reset\");\n" +
2670
 			    "	}\n" +
2671
 			    "}\n" +
2672
 			    "	\n",
2673
 		"T914bp22.java",
2674
 			    "\n" +
2675
 			    "public class T914bp22 {\n" +
2676
 			    "        public void test(int value) {\n" +
2677
 			    "            System.out.print(\"OK\");\n" +
2678
 			    "        }\n" +
2679
 			    "}    \n" +
2680
 			    "    \n",
2681
 		"Team914bp22.java",
2682
 			    "\n" +
2683
 			    "public team class Team914bp22 {\n" +
2684
 			    "	public int code = 0;\n" +
2685
 			    "	protected class Role1 playedBy T914bp22 \n" +
2686
 			    "	{\n" +
2687
 			    "		void print(int value) {\n" +
2688
 			    "			System.out.print(\"NOT\");\n" +
2689
 			    "		}\n" +
2690
 			    "		void print(int value) <- before void test(int value)\n" +
2691
 			    "		    when (Team914bp22.this.code == value);\n" +
2692
 			    "	}\n" +
2693
 			    "}	\n" +
2694
 			    "	\n"
2695
             },
2696
             "OK");
2697
    }
2698
2699
2656
    // a role method has a guard predicate
2700
    // a role method has a guard predicate
2657
    // 9.1.5-otjld-method-predicate-1
2701
    // 9.1.5-otjld-method-predicate-1
2658
    public void test915_methodPredicate1() {
2702
    public void test915_methodPredicate1() {

Return to bug 354244