aspect ITDMangledNames { //refined from IntertypeDeclarations refine IntertypeFieldCodegeneration eq IntertypeFieldDeclaration.introducedName() { ModuleCompilationUnit mcu = hostAspect().compilationUnit().getModuleCompilationUnit(); String modulePrefix = ""; if (mcu != null) { modulePrefix = mcu.modulePrefix() + "_"; } else { modulePrefix = ""; } if(isPrivate()) { return "abc$interField$" + modulePrefix + hostAspect().topLevelType().abcMangledName() + "$" + name(); } else if(isPublic()) { return name(); } else { return "abc$interField$" + modulePrefix + hostAspect().packageName().replace('.', '_') + "$" + name(); } } //refined from IntertypeDeclarations refine IntertypeMethodCodegeneration eq IntertypeMethodDecl.delegateName() { ModuleCompilationUnit mcu = hostAspect().compilationUnit().getModuleCompilationUnit(); String modulePrefix = ""; if (mcu != null) { modulePrefix = mcu.modulePrefix() + "_"; } else { modulePrefix = ""; } if(isPrivate()) { return "abc$interMethod$" + modulePrefix + hostAspect().topLevelType().abcMangledName() + "$" + name(); } else if(isPublic()) { return name(); } else { return "abc$interMethod$" + modulePrefix + hostAspect().packageName().replace('.', '_') + "$" + name(); } } //rewrites public String AspectDecl.modulePrefix() { String modulePrefix = ""; ModuleCompilationUnit mcu = compilationUnit().getModuleCompilationUnit(); if (mcu != null) { modulePrefix = mcu.modulePrefix() + "_"; } else { modulePrefix = ""; } return modulePrefix; } refine Rewrites eq AspectDecl.duringCounter() { String modulePrefix = modulePrefix(); if(duringCounter != null) return duringCounter; TypeDecl typeDecl = astNode(); for(int i = 0; i < typeDecl.getNumBodyDecl(); i++) { //TODO: Check if modulePrefix is needed here if(typeDecl.getBodyDecl(i) instanceof FieldDeclaration && ((FieldDeclaration)typeDecl.getBodyDecl(i)).name().equals("during" + modulePrefix + name())) { return duringCounter = (FieldDeclaration)typeDecl.getBodyDecl(i); } } FieldDeclaration field = new FieldDeclaration( new Modifiers(new List().add(new Modifier("public")).add(new Modifier("static")).add(new Modifier("synthetic"))), new TypeAccess("int"), "during" + modulePrefix + name(), new IntegerLiteral(0) ); return duringCounter = typeDecl.addMemberField(field); } refine Rewrites eq AspectDecl.duringMethod() { String modulePrefix = modulePrefix(); if(duringMethod != null) return duringMethod; FieldDeclaration field = duringCounter(); MethodDecl method = new IntertypeMethodDecl( new Modifiers(new List().add(new Modifier("public")).add(new Modifier("static")).add(new Modifier("synthetic"))), new PrimitiveTypeAccess("boolean"), "during" + modulePrefix + name(), new List(), new List(), new Opt( new Block( new List().add( new IfStmt( new EQExpr( field.createBoundFieldAccess(), new IntegerLiteral(0) ), new ReturnStmt(new BooleanLiteral(false)), new Block( new List().add( new ExprStmt( new VarAccess("state").qualifiesAccess( new MethodAccess( "pop", new List() ) ) ) ).add( new ExprStmt( new VarAccess("state").qualifiesAccess( new MethodAccess( "push", new List().add( astNodeState().createQualifiedAccess().qualifiesAccess( new VarAccess("REWRITE_INTERRUPT") ) ) ) ) ) ).add( new ReturnStmt(new BooleanLiteral(true)) ) ) ) ) ) ), astNode().createQualifiedAccess() ); return duringMethod = addMemberMethod(method); } }