@SuppressWarnings("unchecked") private static void addPrivateFieldOrMethodAccess(Expression source, ClassNode cn, StaticTypesMarker type, ASTNode accessedMember) { Set<ASTNode> set = (Set<ASTNode>) cn.getNodeMetaData(type); if (set == null) { set = new LinkedHashSet<ASTNode>(); cn.putNodeMetaData(type, set); } set.add(accessedMember); source.putNodeMetaData(type, accessedMember); }
@Override public void call(SourceUnit source, GeneratorContext context, ClassNode classNode) throws CompilationFailedException { Object callback = classNode.getNodeMetaData(StaticCompilationMetadataKeys.DYNAMIC_OUTER_NODE_CALLBACK); if (callback instanceof PrimaryClassNodeOperation) { ((PrimaryClassNodeOperation) callback).call(source, context, classNode); classNode.removeNodeMetaData(StaticCompilationMetadataKeys.DYNAMIC_OUTER_NODE_CALLBACK); } } }, Phases.INSTRUCTION_SELECTION);
public void createMopMethods() { ClassNode classNode = controller.getClassNode(); LinkedList<MethodNode> requiredMopMethods = classNode.getNodeMetaData(StaticTypesMarker.SUPER_MOP_METHOD_REQUIRED); if (requiredMopMethods!=null) { generateMopCalls(requiredMopMethods, false); } }
public static void setNodeMeta(TypeChooser chooser, ClassNode classNode) { if (classNode.getNodeMetaData(ClassNodeSkip.class)!=null) return; new OptVisitor(chooser).visitClass(classNode); }
private void addDynamicOuterClassAccessorsCallback(final ClassNode outer) { if (outer != null && !isStaticallyCompiled(outer) && outer.getNodeMetaData(StaticCompilationMetadataKeys.DYNAMIC_OUTER_NODE_CALLBACK) == null) { outer.putNodeMetaData(StaticCompilationMetadataKeys.DYNAMIC_OUTER_NODE_CALLBACK, new CompilationUnit.PrimaryClassNodeOperation() { @Override public void call(SourceUnit source, GeneratorContext context, ClassNode classNode) throws CompilationFailedException { if (classNode == outer) { addPrivateBridgeMethods(classNode); addPrivateFieldsAccessors(classNode); } } }); } }
private static void addFastPathHelperFieldsAndHelperMethod(ClassNode node, final String classInternalName, boolean knownSpecialCase) { if (node.getNodeMetaData(ClassNodeSkip.class) != null) return; FieldNode stMCB = checkFieldDoesNotExist(node, STATIC_METACLASS_BOOL); if (stMCB == null) { stMCB = node.addField( STATIC_METACLASS_BOOL, ACC_PUBLIC | ACC_STATIC | ACC_SYNTHETIC | ACC_TRANSIENT, ClassHelper.boolean_TYPE, null); stMCB.setSynthetic(true); } }
/** * If we are in a constructor, that is static compiled, but in a class, that * is not, it may happen that init code from object initializers, fields * or properties is added into the constructor code. The backend assumes * a purely static constructor, so it may fail if it encounters dynamic * code here. Thus we make this kind of code fail */ private void checkForConstructorWithCSButClassWithout(MethodNode node) { if (!(node instanceof ConstructorNode)) return; Object meta = node.getNodeMetaData(STATIC_COMPILE_NODE); if (!Boolean.TRUE.equals(meta)) return; ClassNode clz = typeCheckingContext.getEnclosingClassNode(); meta = clz.getNodeMetaData(STATIC_COMPILE_NODE); if (Boolean.TRUE.equals(meta)) return; if ( clz.getObjectInitializerStatements().isEmpty() && clz.getFields().isEmpty() && clz.getProperties().isEmpty()) { return; } addStaticTypeError("Cannot statically compile constructor implicitly including non static elements from object initializers, properties or fields.",node); }
private void resolveHelperClassIfNecessary(final ClassNode helperClassNode) { if (helperClassNode == null) { return; } for (ClassNode cNode : unit.getAST().getClasses()) { ClassNode unresolvedHelperNode = cNode.getNodeMetaData(UNRESOLVED_HELPER_CLASS); if (unresolvedHelperNode != null && unresolvedHelperNode.getName().equals(helperClassNode.getName())) { unresolvedHelperNode.setRedirect(helperClassNode); } } }
private static List<AnnotationNode> getMeta(ClassNode cn) { List<AnnotationNode> meta = cn.getNodeMetaData(AnnotationCollector.class); if (meta == null) { if (cn.isPrimaryClassNode()) { meta = getTargetListFromAnnotations(cn); } else { meta = getTargetListFromClass(cn); } cn.setNodeMetaData(AnnotationCollector.class, meta); } return meta; }
private void checkSuperCallFromClosure(Expression call, MethodNode directCallTarget) { if (call instanceof MethodCallExpression && typeCheckingContext.getEnclosingClosure() != null) { Expression objectExpression = ((MethodCallExpression) call).getObjectExpression(); if (objectExpression instanceof VariableExpression) { VariableExpression var = (VariableExpression) objectExpression; if (var.isSuperExpression()) { ClassNode current = typeCheckingContext.getEnclosingClassNode(); LinkedList<MethodNode> list = current.getNodeMetaData(StaticTypesMarker.SUPER_MOP_METHOD_REQUIRED); if (list == null) { list = new LinkedList<MethodNode>(); current.putNodeMetaData(StaticTypesMarker.SUPER_MOP_METHOD_REQUIRED, list); } list.add(directCallTarget); call.putNodeMetaData(StaticTypesMarker.SUPER_MOP_METHOD_REQUIRED, current); } } } }
private void updateStaticCompileFlag(final MethodNode mn) { ClassNode classNode = getClassNode(); AnnotatedNode node = mn; if (classNode.implementsInterface(ClassHelper.GENERATED_CLOSURE_Type)) { node = classNode.getOuterClass(); } isInStaticallyCheckedMethod = mn != null && ( StaticCompilationVisitor.isStaticallyCompiled(node) || classNode.implementsInterface(ClassHelper.GENERATED_CLOSURE_Type)&&classNode.getNodeMetaData(StaticCompilationMetadataKeys.STATIC_COMPILE_NODE)!=null); }
private boolean tryPrivateMethod(final MethodNode target, final boolean implicitThis, final Expression receiver, final TupleExpression args, final ClassNode classNode) { ClassNode declaringClass = target.getDeclaringClass(); if ((isPrivateBridgeMethodsCallAllowed(declaringClass, classNode) || isPrivateBridgeMethodsCallAllowed(classNode, declaringClass)) && declaringClass.getNodeMetaData(PRIVATE_BRIDGE_METHODS) != null && !declaringClass.equals(classNode)) { if (tryBridgeMethod(target, receiver, implicitThis, args, classNode)) { return true; } else { checkAndAddCannotCallPrivateMethodError(target, receiver, classNode, declaringClass); } } checkAndAddCannotCallPrivateMethodError(target, receiver, classNode, declaringClass); return false; }
Set<ASTNode> accessedFields = (Set<ASTNode>) node.getNodeMetaData(StaticTypesMarker.PV_FIELDS_ACCESS); Set<ASTNode> mutatedFields = (Set<ASTNode>) node.getNodeMetaData(StaticTypesMarker.PV_FIELDS_MUTATION); if (accessedFields == null && mutatedFields == null) return; Map<String, MethodNode> privateFieldAccessors = (Map<String, MethodNode>) node.getNodeMetaData(PRIVATE_FIELDS_ACCESSORS); Map<String, MethodNode> privateFieldMutators = (Map<String, MethodNode>) node.getNodeMetaData(PRIVATE_FIELDS_MUTATORS); if (privateFieldAccessors != null || privateFieldMutators != null) {
return; Object type = node.getNodeMetaData(StaticTypesMarker.INFERRED_TYPE); if (type != null) {
@Override public void visitClass(final ClassNode node) { boolean skip = shouldSkipClassNode(node); if (!skip && !anyMethodSkip(node)) { node.putNodeMetaData(MopWriter.Factory.class, StaticCompilationMopWriter.FACTORY); } ClassNode oldCN = classNode; classNode = node; Iterator<InnerClassNode> innerClasses = classNode.getInnerClasses(); while (innerClasses.hasNext()) { InnerClassNode innerClassNode = innerClasses.next(); boolean innerStaticCompile = !(skip || isSkippedInnerClass(innerClassNode)); innerClassNode.putNodeMetaData(STATIC_COMPILE_NODE, innerStaticCompile); innerClassNode.putNodeMetaData(WriterControllerFactory.class, node.getNodeMetaData(WriterControllerFactory.class)); if (innerStaticCompile && !anyMethodSkip(innerClassNode)) { innerClassNode.putNodeMetaData(MopWriter.Factory.class, StaticCompilationMopWriter.FACTORY); } } super.visitClass(node); addPrivateFieldAndMethodAccessors(node); if (isStaticallyCompiled(node)) addDynamicOuterClassAccessorsCallback(node.getOuterClass()); classNode = oldCN; }
addInitialization(node, dummy); node.visitContents(this); if (classNode.getNodeMetaData(ClassNodeSkip.class) == null) { classNode.setNodeMetaData(ClassNodeSkip.class, true);
addTypeCheckingExtensions(visitor, extensions); methodNode.putNodeMetaData(STATIC_COMPILE_NODE, !visitor.isSkipMode(node)); if (declaringClass.getNodeMetaData(WriterControllerFactory.class) == null) { declaringClass.putNodeMetaData(WriterControllerFactory.class, factory);
lookupClassNode = target.getDeclaringClass().redirect(); Map<MethodNode, MethodNode> bridges = lookupClassNode.getNodeMetaData(PRIVATE_BRIDGE_METHODS); MethodNode bridge = bridges==null?null:bridges.get(target); if (bridge != null) {
&& (StaticInvocationWriter.isPrivateBridgeMethodsCallAllowed(receiverType, classNode) || StaticInvocationWriter.isPrivateBridgeMethodsCallAllowed(classNode,receiverType)) && !receiverType.equals(classNode)) { Map<String, MethodNode> accessors = receiverType.redirect().getNodeMetaData(StaticCompilationMetadataKeys.PRIVATE_FIELDS_ACCESSORS); if (accessors!=null) { MethodNode methodNode = accessors.get(fieldName);
&& (StaticInvocationWriter.isPrivateBridgeMethodsCallAllowed(receiverType, classNode) || StaticInvocationWriter.isPrivateBridgeMethodsCallAllowed(classNode,receiverType)) && !receiverType.equals(classNode)) { Map<String, MethodNode> mutators = receiverType.redirect().getNodeMetaData(StaticCompilationMetadataKeys.PRIVATE_FIELDS_MUTATORS); if (mutators != null) { MethodNode methodNode = mutators.get(fieldName);