@Override public CAstType getType() { return base.getType(); }
@Override public CAstType getType() { return base.getType(); }
@Override protected boolean defineType(CAstEntity type, WalkContext wc) { CAstEntity parentType = getEnclosingType(type); // ((JavaSourceLoaderImpl)loader).defineType(type, // composeEntityName(wc,type), parentType); if (exclusions != null && exclusions.contains(type.getType().getName().substring(1))) { return false; } else { return ((JavaSourceLoaderImpl) loader).defineType(type, type.getType().getName(), parentType) != null; } }
@Override protected boolean defineType(CAstEntity type, WalkContext wc) { CAstEntity parentType = getEnclosingType(type); // ((JavaSourceLoaderImpl)loader).defineType(type, // composeEntityName(wc,type), parentType); if (exclusions != null && exclusions.contains(type.getType().getName().substring(1))) { return false; } else { return ((JavaSourceLoaderImpl) loader).defineType(type, type.getType().getName(), parentType) != null; } }
@Override protected Position[] getParameterPositions(CAstEntity n) { int offset = 0; Position[] parameterPositions = new Position[ n.getArgumentCount() ]; if ((n.getType() instanceof CAstType.Method) && !((CAstType.Method)n.getType()).isStatic()) { offset = 1; } for(int i = 0; i < n.getArgumentCount() - offset; i++) { parameterPositions[i+offset] = n.getPosition(i); } return parameterPositions; } }
@Override protected Position[] getParameterPositions(CAstEntity n) { int offset = 0; Position[] parameterPositions = new Position[ n.getArgumentCount() ]; if ((n.getType() instanceof CAstType.Method) && !((CAstType.Method)n.getType()).isStatic()) { offset = 1; } for(int i = 0; i < n.getArgumentCount() - offset; i++) { parameterPositions[i+offset] = n.getPosition(i); } return parameterPositions; } }
protected TypeReference[] computeExceptionTypes(CAstEntity methodEntity) { CAstType.Function fType = (Function) methodEntity.getType(); Collection<CAstType> exceptionTypes = fType.getExceptionTypes(); TypeReference[] result = new TypeReference[exceptionTypes.size()]; int i = 0; for (CAstType type : exceptionTypes) { result[i] = TypeReference.findOrCreate(JavaSourceLoaderImpl.this.getReference(), type.getName()); ++i; } return result; }
protected TypeReference[] computeExceptionTypes(CAstEntity methodEntity) { CAstType.Function fType = (Function) methodEntity.getType(); Collection<CAstType> exceptionTypes = fType.getExceptionTypes(); TypeReference[] result = new TypeReference[exceptionTypes.size()]; int i = 0; for (CAstType type : exceptionTypes) { result[i] = TypeReference.findOrCreate(JavaSourceLoaderImpl.this.getReference(), type.getName()); ++i; } return result; }
@Override protected void leaveGlobalEntity(CAstEntity n, WalkContext context, CAstVisitor<WalkContext> visitor) { // Define a new field in the enclosing type, if the language we're // processing allows such. context.getGlobalScope().declare(new CAstSymbolImpl(n.getName(), n.getType())); }
public IClass defineType(CAstEntity type, String typeName, CAstEntity owner) { Collection<TypeName> superTypeNames = new ArrayList<>(); for (CAstType superType : type.getType().getSupertypes()) { superTypeNames.add(toWALATypeName(superType)); } JavaClass javaClass = new JavaClass(typeName, superTypeNames, type.getPosition(), type.getQualifiers(), this, (owner != null) ? (JavaClass) fTypeMap.get(owner) : (JavaClass) null, getAnnotations(type)); if (getParent().lookupClass(javaClass.getName()) != null) { return null; } fTypeMap.put(type, javaClass); loadedClasses.put(javaClass.getName(), javaClass); return javaClass; }
public IClass defineType(CAstEntity type, String typeName, CAstEntity owner) { Collection<TypeName> superTypeNames = new ArrayList<>(); for (CAstType superType : type.getType().getSupertypes()) { superTypeNames.add(toWALATypeName(superType)); } JavaClass javaClass = new JavaClass(typeName, superTypeNames, type.getPosition(), type.getQualifiers(), this, (owner != null) ? (JavaClass) fTypeMap.get(owner) : (JavaClass) null, getAnnotations(type)); if (getParent().lookupClass(javaClass.getName()) != null) { return null; } fTypeMap.put(type, javaClass); loadedClasses.put(javaClass.getName(), javaClass); return javaClass; }
@Override protected void leaveGlobalEntity(CAstEntity n, WalkContext context, CAstVisitor<WalkContext> visitor) { // Define a new field in the enclosing type, if the language we're // processing allows such. context.getGlobalScope().declare(new CAstSymbolImpl(n.getName(), n.getType())); }
@Override protected void declareFunction(CAstEntity N, WalkContext definingContext) { CAstType.Method methodType = (Method) N.getType(); CAstType owningType = methodType.getDeclaringType(); IClass owner = loader.lookupClass(makeType(owningType).getName()); assert owner != null || exclusions.contains(owningType.getName()) : makeType(owningType).getName().toString() + " not found in " + loader; if (owner != null && N.getQualifiers().contains(CAstQualifier.ABSTRACT)) { ((JavaSourceLoaderImpl) loader).defineAbstractFunction(N, owner); } }
@Override protected void declareFunction(CAstEntity N, WalkContext definingContext) { CAstType.Method methodType = (Method) N.getType(); CAstType owningType = methodType.getDeclaringType(); IClass owner = loader.lookupClass(makeType(owningType).getName()); assert owner != null || exclusions.contains(owningType.getName()) : makeType(owningType).getName().toString() + " not found in " + loader; if (owner != null && N.getQualifiers().contains(CAstQualifier.ABSTRACT)) { ((JavaSourceLoaderImpl) loader).defineAbstractFunction(N, owner); } }
@Override protected void defineField(CAstEntity topEntity, WalkContext definingContext, CAstEntity n) { assert topEntity.getKind() == CAstEntity.TYPE_ENTITY; assert n.getKind() == CAstEntity.FIELD_ENTITY; // N.B.: base class may actually ask to create a synthetic type to wrap // code bodies, so we may see other things than TYPE_ENTITY here. TypeName ownerName = makeType(topEntity.getType()).getName(); IClass owner = loader.lookupClass(ownerName); assert owner != null || exclusions.contains(ownerName.toString()) : ownerName + " not found in " + loader; if (owner != null) { ((JavaSourceLoaderImpl) loader).defineField(n, owner); } }
@Override protected void defineField(CAstEntity topEntity, WalkContext definingContext, CAstEntity n) { assert topEntity.getKind() == CAstEntity.TYPE_ENTITY; assert n.getKind() == CAstEntity.FIELD_ENTITY; // N.B.: base class may actually ask to create a synthetic type to wrap // code bodies, so we may see other things than TYPE_ENTITY here. TypeName ownerName = makeType(topEntity.getType()).getName(); IClass owner = loader.lookupClass(ownerName); assert owner != null || exclusions.contains(ownerName.toString()) : ownerName + " not found in " + loader; if (owner != null) { ((JavaSourceLoaderImpl) loader).defineField(n, owner); } }
protected JavaField(CAstEntity fieldEntity, IClassLoader loader, IClass declaringClass, Collection<Annotation> annotations) { super(FieldReference.findOrCreate(declaringClass.getReference(), Atom.findOrCreateUnicodeAtom(fieldEntity.getName()), TypeReference.findOrCreate(loader.getReference(), TypeName.string2TypeName(fieldEntity.getType().getName()))), fieldEntity.getQualifiers(), declaringClass, declaringClass.getClassHierarchy(), annotations); } }
protected JavaField(CAstEntity fieldEntity, IClassLoader loader, IClass declaringClass, Collection<Annotation> annotations) { super(FieldReference.findOrCreate(declaringClass.getReference(), Atom.findOrCreateUnicodeAtom(fieldEntity.getName()), TypeReference.findOrCreate(loader.getReference(), TypeName.string2TypeName(fieldEntity.getType().getName()))), fieldEntity.getQualifiers(), declaringClass, declaringClass.getClassHierarchy(), annotations); } }
@Override protected void leaveFunctionStmt(CAstNode n, WalkContext context, CAstVisitor<WalkContext> visitor) { int result = processFunctionExpr(n, context); CAstEntity fn = (CAstEntity) n.getChild(0).getValue(); // FIXME: handle redefinitions of functions Scope cs = context.currentScope(); if (cs.contains(fn.getName()) && !cs.isLexicallyScoped(cs.lookup(fn.getName())) && !cs.isGlobal(cs.lookup(fn.getName()))) { // if we already have a local with the function's name, write the function // value to that local assignValue(n, context, cs.lookup(fn.getName()), fn.getName(), result); } else if (topLevelFunctionsInGlobalScope() && context.top().getKind() == CAstEntity.SCRIPT_ENTITY) { context.getGlobalScope().declare(new FinalCAstSymbol(fn.getName(), fn.getType())); assignValue(n, context, cs.lookup(fn.getName()), fn.getName(), result); } else { context.currentScope().declare(new FinalCAstSymbol(fn.getName(), fn.getType()), result); } }
@Override protected void leaveFunctionStmt(CAstNode n, WalkContext context, CAstVisitor<WalkContext> visitor) { int result = processFunctionExpr(n, context); CAstEntity fn = (CAstEntity) n.getChild(0).getValue(); // FIXME: handle redefinitions of functions Scope cs = context.currentScope(); if (cs.contains(fn.getName()) && !cs.isLexicallyScoped(cs.lookup(fn.getName())) && !cs.isGlobal(cs.lookup(fn.getName()))) { // if we already have a local with the function's name, write the function // value to that local assignValue(n, context, cs.lookup(fn.getName()), fn.getName(), result); } else if (topLevelFunctionsInGlobalScope() && context.top().getKind() == CAstEntity.SCRIPT_ENTITY) { context.getGlobalScope().declare(new FinalCAstSymbol(fn.getName(), fn.getType())); assignValue(n, context, cs.lookup(fn.getName()), fn.getName(), result); } else { context.currentScope().declare(new FinalCAstSymbol(fn.getName(), fn.getType()), result); } }