extract Inferer as IBindingResolver interface
This commit is contained in:
parent
3768f51d89
commit
18a7c2b851
|
@ -68,7 +68,7 @@ height="2.8465277777777778in"}
|
|||
ImportStrategy是一个策略类,命名为*Lang*ImportLookupStrategy,它继承ImportLookupStrategy接口。其的职责是负责建立起不同编译单元之间的关系。具体来说,是如何查找到位于其他编译单元的特定名字。
|
||||
|
||||
ImportStrategy的核心方法是lookupImportedType(String name, FileEntity
|
||||
fileEntity, EntityRepo repo, Inferer inferer)。其说明如下:
|
||||
fileEntity, EntityRepo repo, Inferer IBindingResolver)。其说明如下:
|
||||
|
||||
How to find the corresponding entity out of current scope
|
||||
|
||||
|
@ -80,7 +80,7 @@ How to find the corresponding entity out of current scope
|
|||
>
|
||||
> **repo** - the whole entity repo, which could be used when necessary
|
||||
>
|
||||
> **inferer** - the inferer object, which could be used when necessary
|
||||
> **IBindingResolver** - the IBindingResolver object, which could be used when necessary
|
||||
|
||||
**Returns:**
|
||||
|
||||
|
@ -122,7 +122,7 @@ Relation更简单,仅仅包含依赖关系的类型以及指向的Entity。Rel
|
|||
Entity提供了几个重要的方法。包括addRelation和inferEntities。
|
||||
addRelation的职责很容易理解。
|
||||
inferEntities是一个重要的方法,它负责完成自本实体开始的所有的类型的binding
|
||||
resolve和type inferer。
|
||||
resolve和type IBindingResolver。
|
||||
|
||||
### 表达式Expression
|
||||
|
||||
|
@ -354,7 +354,7 @@ height="2.8465277777777778in"}
|
|||
ImportStrategy是一个策略类,命名为*Lang*ImportLookupStrategy,它继承ImportLookupStrategy接口。其的职责是负责建立起不同编译单元之间的关系。具体来说,是如何查找到位于其他编译单元的特定名字。
|
||||
|
||||
ImportStrategy的核心方法是lookupImportedType(String name, FileEntity
|
||||
fileEntity, EntityRepo repo, Inferer inferer)。其说明如下:
|
||||
fileEntity, EntityRepo repo, Inferer IBindingResolver)。其说明如下:
|
||||
|
||||
How to find the corresponding entity out of current scope
|
||||
|
||||
|
@ -366,7 +366,7 @@ How to find the corresponding entity out of current scope
|
|||
>
|
||||
> **repo** - the whole entity repo, which could be used when necessary
|
||||
>
|
||||
> **inferer** - the inferer object, which could be used when necessary
|
||||
> **IBindingResolver** - the IBindingResolver object, which could be used when necessary
|
||||
|
||||
**Returns:**
|
||||
|
||||
|
@ -408,7 +408,7 @@ Relation更简单,仅仅包含依赖关系的类型以及指向的Entity。Rel
|
|||
Entity提供了几个重要的方法。包括addRelation和inferEntities。
|
||||
addRelation的职责很容易理解。
|
||||
inferEntities是一个重要的方法,它负责完成自本实体开始的所有的类型的binding
|
||||
resolve和type inferer。
|
||||
resolve和type IBindingResolver。
|
||||
|
||||
### 表达式Expression {#表达式expression}
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@ For example, the implementation of FileParser is as follows:
|
|||
CommonTokenStream tokens = new CommonTokenStream(lexer);
|
||||
Python3Parser parser = new Python3Parser(tokens);
|
||||
Python3CodeListener bridge = new Python3CodeListener(fileFullPath,
|
||||
entityRepo,inferer);
|
||||
entityRepo,IBindingResolver);
|
||||
ParseTreeWalker walker = new ParseTreeWalker();
|
||||
walker.walk(bridge, parser.file_input());
|
||||
}
|
||||
|
@ -99,8 +99,8 @@ Create a Lexer, create a Parse, create a Listener, and start traversing each of
|
|||
First, create a context for the file:
|
||||
|
||||
public Python3CodeListener(String fileFullPath, EntityRepo entityRepo,
|
||||
Inferer inferer) {
|
||||
this.context = new PythonHandlerContext(entityRepo,inferer);
|
||||
Inferer IBindingResolver) {
|
||||
this.context = new PythonHandlerContext(entityRepo,IBindingResolver);
|
||||
this.expressionUsage = new ExpressionUsage();
|
||||
context.startFile(fileFullPath);
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ We already succefully make the depends knows that a function entity is created.
|
|||
ImportStrategy is a strategy class named *Lang*ImportLookupStrategy that inherits the ImportLookupStrategy interface. Its role is to establish the relationship between different compilation units. Specifically, how to find a specific name in another compilation unit.
|
||||
|
||||
The core method of ImportStrategy is lookupImportedType(String name, FileEntity
|
||||
fileEntity, EntityRepo repo, Inferer inferer). Its description is as follows:
|
||||
fileEntity, EntityRepo repo, Inferer IBindingResolver). Its description is as follows:
|
||||
|
||||
How to find the corresponding entity out of current scope
|
||||
|
||||
|
@ -132,7 +132,7 @@ How to find the corresponding entity out of current scope
|
|||
>
|
||||
> **repo** - the whole entity repo, which could be used when necessary
|
||||
>
|
||||
> **inferer** - the inferer object, which could be used when necessary
|
||||
> **IBindingResolver** - the IBindingResolver object, which could be used when necessary
|
||||
|
||||
**Returns:**
|
||||
|
||||
|
@ -174,7 +174,7 @@ Relation is simpler, just contains the type of the dependency and the Entity poi
|
|||
Entity provides several important methods. Includes addRelation and inferEntities.
|
||||
The responsibilities of addRelation are easy to understand.
|
||||
inferEntities is an important method that is responsible for completing all types of bindings starting from this entity.
|
||||
Resolve and type inferer.
|
||||
Resolve and type IBindingResolver.
|
||||
|
||||
### Expression Expression
|
||||
|
||||
|
|
|
@ -37,7 +37,8 @@ import depends.generator.FunctionDependencyGenerator;
|
|||
import depends.generator.StructureDependencyGenerator;
|
||||
import depends.matrix.core.DependencyMatrix;
|
||||
import depends.matrix.transform.MatrixLevelReducer;
|
||||
import depends.relations.Inferer;
|
||||
import depends.relations.BindingResolver;
|
||||
import depends.relations.IBindingResolver;
|
||||
import depends.relations.RelationCounter;
|
||||
import edu.emory.mathcs.backport.java.util.Arrays;
|
||||
import multilang.depends.util.file.FileUtil;
|
||||
|
@ -104,14 +105,14 @@ public class Main {
|
|||
System.err.println("Not support this language: " + lang);
|
||||
return;
|
||||
}
|
||||
Inferer inferer = new Inferer(langProcessor.getEntityRepo(), langProcessor.getImportLookupStrategy(), langProcessor.getBuiltInType()
|
||||
IBindingResolver bindingResolver = new BindingResolver(langProcessor.getEntityRepo(), langProcessor.getImportLookupStrategy(), langProcessor.getBuiltInType()
|
||||
, app.isOutputExternalDependencies(), app.isDuckTypingDeduce());
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
//step1: build data
|
||||
EntityRepo entityRepo = langProcessor.buildDependencies(inputDir, includeDir, inferer);
|
||||
EntityRepo entityRepo = langProcessor.buildDependencies(inputDir, includeDir, bindingResolver);
|
||||
|
||||
new RelationCounter(entityRepo,supportImplLink,langProcessor,inferer).computeRelations();
|
||||
new RelationCounter(entityRepo,supportImplLink,langProcessor, bindingResolver).computeRelations();
|
||||
System.out.println("Dependency done....");
|
||||
|
||||
//step2: generate dependencies matrix
|
||||
|
|
|
@ -24,13 +24,9 @@ SOFTWARE.
|
|||
|
||||
package depends.entity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import depends.relations.IBindingResolver;
|
||||
|
||||
import depends.relations.Inferer;
|
||||
import java.util.*;
|
||||
|
||||
public class AliasEntity extends Entity {
|
||||
private Entity referToEntity = new EmptyTypeEntity();
|
||||
|
@ -45,9 +41,9 @@ public class AliasEntity extends Entity {
|
|||
this.originName = originTypeName;
|
||||
}
|
||||
|
||||
public void inferLocalLevelEntities(Inferer inferer) {
|
||||
public void inferLocalLevelEntities(IBindingResolver bindingResolver) {
|
||||
if (!(referToEntity instanceof EmptyTypeEntity)) return;
|
||||
Entity entity = inferer.resolveName(this, originName, true);
|
||||
Entity entity = bindingResolver.resolveName(this, originName, true);
|
||||
while(entity instanceof AliasEntity) {
|
||||
AliasEntity aliasEntity = (AliasEntity)entity;
|
||||
if (this.referPath.contains(aliasEntity)) {
|
||||
|
@ -55,7 +51,7 @@ public class AliasEntity extends Entity {
|
|||
break;
|
||||
}
|
||||
this.referPath.add(aliasEntity);
|
||||
entity = inferer.resolveName(aliasEntity, aliasEntity.originName,true);
|
||||
entity = bindingResolver.resolveName(aliasEntity, aliasEntity.originName,true);
|
||||
if (entity==null) break;
|
||||
if (entity.equals(this)) {
|
||||
entity = null;
|
||||
|
|
|
@ -24,15 +24,11 @@ SOFTWARE.
|
|||
|
||||
package depends.entity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import depends.relations.Inferer;
|
||||
import depends.relations.IBindingResolver;
|
||||
import depends.relations.Relation;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class CandidateTypes extends TypeEntity {
|
||||
private List<TypeEntity> candidateTypes;
|
||||
|
||||
|
@ -119,9 +115,9 @@ public class CandidateTypes extends TypeEntity {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void inferLocalLevelEntities(Inferer inferer) {
|
||||
public void inferLocalLevelEntities(IBindingResolver bindingResolver) {
|
||||
System.err.println("error: inferLocalLevelEntities should not been invoked");
|
||||
super.inferLocalLevelEntities(inferer);
|
||||
super.inferLocalLevelEntities(bindingResolver);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -166,10 +162,9 @@ public class CandidateTypes extends TypeEntity {
|
|||
super.addExpression(key, expression);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolveExpressions(Inferer inferer) {
|
||||
public void resolveExpressions(IBindingResolver bindingResolver) {
|
||||
System.err.println("error: resolveExpressions should not been invoked");
|
||||
super.resolveExpressions(inferer);
|
||||
super.resolveExpressions(bindingResolver);
|
||||
}
|
||||
|
||||
|
||||
|
@ -211,9 +206,9 @@ public class CandidateTypes extends TypeEntity {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Collection<Entity> identiferToEntities(Inferer inferer, Collection<GenericName> identifiers) {
|
||||
protected Collection<Entity> identiferToEntities(IBindingResolver bindingResolver, Collection<GenericName> identifiers) {
|
||||
System.err.println("error: identiferToTypes should not been invoked");
|
||||
return super.identiferToEntities(inferer, identifiers);
|
||||
return super.identiferToEntities(bindingResolver, identifiers);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -289,9 +284,9 @@ public class CandidateTypes extends TypeEntity {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void inferEntities(Inferer inferer) {
|
||||
public void inferEntities(IBindingResolver bindingResolver) {
|
||||
System.err.println("error: inferEntities should not been invoked");
|
||||
super.inferEntities(inferer);
|
||||
super.inferEntities(bindingResolver);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -25,7 +25,7 @@ SOFTWARE.
|
|||
package depends.entity;
|
||||
|
||||
import depends.entity.repo.EntityRepo;
|
||||
import depends.relations.Inferer;
|
||||
import depends.relations.IBindingResolver;
|
||||
import depends.relations.Relation;
|
||||
import multilang.depends.util.file.TemporaryFile;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -119,24 +119,24 @@ public abstract class ContainerEntity extends DecoratedEntity {
|
|||
* For all data in the class, infer their types. Should be override in
|
||||
* sub-classes
|
||||
*/
|
||||
public void inferLocalLevelEntities(Inferer inferer) {
|
||||
super.inferLocalLevelEntities(inferer);
|
||||
public void inferLocalLevelEntities(IBindingResolver bindingResolver) {
|
||||
super.inferLocalLevelEntities(bindingResolver);
|
||||
for (VarEntity var : this.vars()) {
|
||||
if (var.getParent()!=this) {
|
||||
var.inferLocalLevelEntities(inferer);
|
||||
var.inferLocalLevelEntities(bindingResolver);
|
||||
}
|
||||
}
|
||||
for (FunctionEntity func : this.getFunctions()) {
|
||||
if (func.getParent()!=this) {
|
||||
func.inferLocalLevelEntities(inferer);
|
||||
func.inferLocalLevelEntities(bindingResolver);
|
||||
}
|
||||
}
|
||||
if (inferer.isEagerExpressionResolve()) {
|
||||
reloadExpression(inferer.getRepo());
|
||||
resolveExpressions(inferer);
|
||||
if (bindingResolver.isEagerExpressionResolve()) {
|
||||
reloadExpression(bindingResolver.getRepo());
|
||||
resolveExpressions(bindingResolver);
|
||||
cacheExpressions();
|
||||
}
|
||||
resolvedMixins = identiferToContainerEntity(inferer, getMixins());
|
||||
resolvedMixins = identiferToContainerEntity(bindingResolver, getMixins());
|
||||
}
|
||||
|
||||
private Collection<GenericName> getMixins() {
|
||||
|
@ -145,11 +145,11 @@ public abstract class ContainerEntity extends DecoratedEntity {
|
|||
return mixins;
|
||||
}
|
||||
|
||||
private Collection<ContainerEntity> identiferToContainerEntity(Inferer inferer, Collection<GenericName> identifiers) {
|
||||
private Collection<ContainerEntity> identiferToContainerEntity(IBindingResolver bindingResolver, Collection<GenericName> identifiers) {
|
||||
if (identifiers.size()==0) return null;
|
||||
ArrayList<ContainerEntity> r = new ArrayList<>();
|
||||
for (GenericName identifier : identifiers) {
|
||||
Entity entity = inferer.resolveName(this, identifier, true);
|
||||
Entity entity = bindingResolver.resolveName(this, identifier, true);
|
||||
if (entity == null) {
|
||||
continue;
|
||||
}
|
||||
|
@ -162,10 +162,9 @@ public abstract class ContainerEntity extends DecoratedEntity {
|
|||
/**
|
||||
* Resolve all expression's type
|
||||
*
|
||||
* @param inferer
|
||||
* @param bindingResolver
|
||||
*/
|
||||
public void resolveExpressions(Inferer inferer) {
|
||||
|
||||
public void resolveExpressions(IBindingResolver bindingResolver) {
|
||||
if (this instanceof FunctionEntity) {
|
||||
((FunctionEntity)this).linkReturnToLastExpression();
|
||||
}
|
||||
|
@ -187,20 +186,13 @@ public abstract class ContainerEntity extends DecoratedEntity {
|
|||
// 2. if expression's rawType existed, directly infer type by rawType
|
||||
// if expression's rawType does not existed, infer type based on identifiers
|
||||
if (expression.getRawType() != null) {
|
||||
expression.setType(inferer.inferTypeFromName(this, expression.getRawType()), null, inferer);
|
||||
expression.setType(bindingResolver.inferTypeFromName(this, expression.getRawType()), null, bindingResolver);
|
||||
if (expression.getType() != null) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (expression.getIdentifier() != null) {
|
||||
|
||||
// if (this.getAncestorOfType(FileEntity.class).getRawName().contains("/examples/usersession/server.py") &&
|
||||
// expression.getIdentifier().contains("config")) {
|
||||
// System.out.print("dd");
|
||||
// }
|
||||
|
||||
|
||||
Entity entity = inferer.resolveName(this, expression.getIdentifier(), true);
|
||||
Entity entity = bindingResolver.resolveName(this, expression.getIdentifier(), true);
|
||||
String composedName = expression.getIdentifier().toString();
|
||||
Expression theExpr = expression;
|
||||
if (entity==null) {
|
||||
|
@ -208,27 +200,27 @@ public abstract class ContainerEntity extends DecoratedEntity {
|
|||
theExpr = theExpr.getParent();
|
||||
if (theExpr.getIdentifier()==null) break;
|
||||
composedName = composedName + "." + theExpr.getIdentifier().toString();
|
||||
entity = inferer.resolveName(this, GenericName.build(composedName), true);
|
||||
entity = bindingResolver.resolveName(this, GenericName.build(composedName), true);
|
||||
if (entity!=null)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (entity != null) {
|
||||
expression.setType(entity.getType(), entity, inferer);
|
||||
expression.setType(entity.getType(), entity, bindingResolver);
|
||||
continue;
|
||||
}
|
||||
if (expression.isCall()) {
|
||||
List<Entity> funcs = this.lookupFunctionInVisibleScope(expression.getIdentifier());
|
||||
if (funcs != null) {
|
||||
for (Entity func:funcs) {
|
||||
expression.setType(func.getType(), func, inferer);
|
||||
expression.setType(func.getType(), func, bindingResolver);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
Entity varEntity = this.lookupVarInVisibleScope(expression.getIdentifier());
|
||||
if (varEntity != null) {
|
||||
expression.setType(varEntity.getType(), varEntity, inferer);
|
||||
expression.setType(varEntity.getType(), varEntity, bindingResolver);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ SOFTWARE.
|
|||
|
||||
package depends.entity;
|
||||
|
||||
import depends.relations.Inferer;
|
||||
import depends.relations.IBindingResolver;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
@ -67,33 +67,33 @@ public abstract class DecoratedEntity extends Entity{
|
|||
* For all data in the class, infer their types.
|
||||
* Should be override in sub-classes
|
||||
*/
|
||||
public void inferLocalLevelEntities(Inferer inferer) {
|
||||
Collection<Entity> typeParameterEntities = typeParametersToEntities(inferer);
|
||||
public void inferLocalLevelEntities(IBindingResolver bindingResolver) {
|
||||
Collection<Entity> typeParameterEntities = typeParametersToEntities(bindingResolver);
|
||||
appendTypeParameters(typeParameterEntities);
|
||||
// if (this.getAncestorOfType(FileEntity.class).getRawName().contains("/examples/usersession/server.py")
|
||||
// ) {
|
||||
// System.out.print("dd");
|
||||
// }
|
||||
resolvedAnnotations = identiferToEntities(inferer, annotations);
|
||||
resolvedAnnotations = identiferToEntities(bindingResolver, annotations);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private Collection<Entity> typeParametersToEntities(Inferer inferer) {
|
||||
private Collection<Entity> typeParametersToEntities(IBindingResolver bindingResolver) {
|
||||
ArrayList<Entity> r = new ArrayList<>();
|
||||
for (GenericName typeParameter:this.getRawName().getArguments()) {
|
||||
toEntityList(inferer, r,typeParameter);
|
||||
toEntityList(bindingResolver, r,typeParameter);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
protected void toEntityList(Inferer inferer, ArrayList<Entity> r, GenericName typeParameter) {
|
||||
Entity entity = resolveEntity(inferer, typeParameter);
|
||||
protected void toEntityList(IBindingResolver bindingResolver, ArrayList<Entity> r, GenericName typeParameter) {
|
||||
Entity entity = resolveEntity(bindingResolver, typeParameter);
|
||||
if (entity != null)
|
||||
r.add(entity);
|
||||
for (GenericName arg: typeParameter.getArguments()) {
|
||||
toEntityList(inferer,r,arg);
|
||||
toEntityList(bindingResolver,r,arg);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -120,24 +120,24 @@ public abstract class DecoratedEntity extends Entity{
|
|||
/**
|
||||
* A common utility function used to transfer the identifiers
|
||||
* to types.
|
||||
* @param inferer - the inferer object
|
||||
* @param bindingResolver - the inferer object
|
||||
* @param identifiers - the identifiers will be translated
|
||||
* @return The translated Types
|
||||
*/
|
||||
protected Collection<Entity> identiferToEntities(Inferer inferer, Collection<GenericName> identifiers) {
|
||||
protected Collection<Entity> identiferToEntities(IBindingResolver bindingResolver, Collection<GenericName> identifiers) {
|
||||
if (identifiers==null) return null;
|
||||
if (identifiers.size()==0) return null;
|
||||
ArrayList<Entity> r = new ArrayList<>();
|
||||
for (GenericName name : identifiers) {
|
||||
Entity entity = resolveEntity(inferer, name);
|
||||
Entity entity = resolveEntity(bindingResolver, name);
|
||||
if (entity != null)
|
||||
r.add(entity);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
private Entity resolveEntity(Inferer inferer, GenericName name) {
|
||||
Entity entity = inferer.resolveName(this, name, true);
|
||||
private Entity resolveEntity(IBindingResolver bindingResolver, GenericName name) {
|
||||
Entity entity = bindingResolver.resolveName(this, name, true);
|
||||
if (entity==null) {
|
||||
if (((ContainerEntity)getParent()).isGenericTypeParameter(name)) {
|
||||
entity = TypeEntity.genericParameterType;
|
||||
|
|
|
@ -24,7 +24,7 @@ SOFTWARE.
|
|||
|
||||
package depends.entity;
|
||||
|
||||
import depends.relations.Inferer;
|
||||
import depends.relations.IBindingResolver;
|
||||
import depends.relations.Relation;
|
||||
|
||||
import java.util.*;
|
||||
|
@ -177,13 +177,13 @@ public abstract class Entity {
|
|||
/**
|
||||
* Invoke inferer to resolve the entity type etc.
|
||||
* */
|
||||
public void inferEntities(Inferer inferer) {
|
||||
inferLocalLevelEntities(inferer);
|
||||
public void inferEntities(IBindingResolver bindingResolver) {
|
||||
inferLocalLevelEntities(bindingResolver);
|
||||
for (Entity child:this.getChildren()) {
|
||||
child.inferEntities(inferer);
|
||||
child.inferEntities(bindingResolver);
|
||||
}
|
||||
}
|
||||
public abstract void inferLocalLevelEntities(Inferer inferer);
|
||||
public abstract void inferLocalLevelEntities(IBindingResolver bindingResolver);
|
||||
|
||||
public TypeEntity getType() {
|
||||
return null;
|
||||
|
|
|
@ -25,7 +25,7 @@ SOFTWARE.
|
|||
package depends.entity;
|
||||
|
||||
import depends.entity.repo.EntityRepo;
|
||||
import depends.relations.Inferer;
|
||||
import depends.relations.IBindingResolver;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
@ -121,9 +121,9 @@ public class Expression implements Serializable{
|
|||
* Set type of the expression
|
||||
* @param type
|
||||
* @param referredEntity
|
||||
* @param inferer
|
||||
* @param bindingResolver
|
||||
*/
|
||||
public void setType(TypeEntity type, Entity referredEntity, Inferer inferer) {
|
||||
public void setType(TypeEntity type, Entity referredEntity, IBindingResolver bindingResolver) {
|
||||
if (this.getReferredEntity()==null && referredEntity!=null) {
|
||||
this.setReferredEntity(referredEntity);
|
||||
}
|
||||
|
@ -147,16 +147,15 @@ public class Expression implements Serializable{
|
|||
this.setReferredEntity(this.type);
|
||||
|
||||
if (changedType)
|
||||
deduceTheParentType(inferer);
|
||||
deduceTheParentType(bindingResolver);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* deduce type of parent based on child's type
|
||||
* @param expressionList
|
||||
* @param inferer
|
||||
* @param bindingResolver
|
||||
*/
|
||||
private void deduceTheParentType(Inferer inferer) {
|
||||
private void deduceTheParentType(IBindingResolver bindingResolver) {
|
||||
if (this.type==null) return;
|
||||
if (this.parent==null) return;
|
||||
Expression parent = this.parent;
|
||||
|
@ -167,13 +166,13 @@ public class Expression implements Serializable{
|
|||
|
||||
//if child is a built-in/external type, then parent must also a built-in/external type
|
||||
if (this.type.equals(TypeEntity.buildInType)) {
|
||||
parent.setType(TypeEntity.buildInType,TypeEntity.buildInType,inferer);
|
||||
parent.setType(TypeEntity.buildInType,TypeEntity.buildInType, bindingResolver);
|
||||
return;
|
||||
}
|
||||
|
||||
/* if it is a logic expression, the return type/type is boolean. */
|
||||
if (parent.isLogic) {
|
||||
parent.setType(TypeEntity.buildInType,null,inferer);
|
||||
parent.setType(TypeEntity.buildInType,null, bindingResolver);
|
||||
}
|
||||
/* if it is a.b, and we already get a's type, b's type could be identified easily */
|
||||
else if (parent.isDot) {
|
||||
|
@ -184,15 +183,15 @@ public class Expression implements Serializable{
|
|||
if (funcs.size()>0) {
|
||||
Entity func = funcs.get(0);
|
||||
if (funcs.size()>1) {
|
||||
MultiDeclareEntities m = new MultiDeclareEntities(func, inferer.getRepo().generateId());
|
||||
inferer.getRepo().add(m);
|
||||
MultiDeclareEntities m = new MultiDeclareEntities(func, bindingResolver.getRepo().generateId());
|
||||
bindingResolver.getRepo().add(m);
|
||||
for (int i=1;i<funcs.size();i++) {
|
||||
m.add(funcs.get(i));
|
||||
}
|
||||
parent.setType(func.getType(), m,inferer);
|
||||
parent.setType(func.getType(), m, bindingResolver);
|
||||
parent.setReferredEntity(m);
|
||||
}else {
|
||||
parent.setType(func.getType(), func,inferer);
|
||||
parent.setType(func.getType(), func, bindingResolver);
|
||||
parent.setReferredEntity(func);
|
||||
}
|
||||
}
|
||||
|
@ -200,35 +199,35 @@ public class Expression implements Serializable{
|
|||
}else {
|
||||
Entity var = this.getType().lookupVarInVisibleScope(parent.identifier);
|
||||
if (var!=null) {
|
||||
parent.setType(var.getType(),var, inferer);
|
||||
parent.setType(var.getType(),var, bindingResolver);
|
||||
parent.setReferredEntity(var);
|
||||
}else {
|
||||
List<Entity> funcs = this.getType().lookupFunctionInVisibleScope(parent.identifier);
|
||||
if (funcs!=null) {
|
||||
Entity func = funcs.get(0);
|
||||
if (funcs.size()>1) {
|
||||
MultiDeclareEntities m = new MultiDeclareEntities(func, inferer.getRepo().generateId());
|
||||
inferer.getRepo().add(m);
|
||||
MultiDeclareEntities m = new MultiDeclareEntities(func, bindingResolver.getRepo().generateId());
|
||||
bindingResolver.getRepo().add(m);
|
||||
|
||||
for (int i=1;i<funcs.size();i++) {
|
||||
m.add(funcs.get(i));
|
||||
}
|
||||
parent.setType(func.getType(), m,inferer);
|
||||
parent.setType(func.getType(), m, bindingResolver);
|
||||
parent.setReferredEntity(m);
|
||||
}else {
|
||||
parent.setType(func.getType(), func,inferer);
|
||||
parent.setType(func.getType(), func, bindingResolver);
|
||||
parent.setReferredEntity(func);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (parent.getType()==null) {
|
||||
parent.setType(inferer.inferTypeFromName(this.getType(), parent.identifier),null,inferer);
|
||||
parent.setType(bindingResolver.inferTypeFromName(this.getType(), parent.identifier),null, bindingResolver);
|
||||
}
|
||||
}
|
||||
/* if other situation, simple make the parent and child type same */
|
||||
else {
|
||||
parent.setType(type, null, inferer);
|
||||
parent.setType(type, null, bindingResolver);
|
||||
}
|
||||
if (parent.getReferredEntity()==null)
|
||||
parent.setReferredEntity(parent.type);
|
||||
|
|
|
@ -24,14 +24,10 @@ SOFTWARE.
|
|||
|
||||
package depends.entity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import depends.importtypes.Import;
|
||||
import depends.relations.Inferer;
|
||||
import depends.relations.IBindingResolver;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class FileEntity extends TypeEntity {
|
||||
private List<Import> importedNames = new ArrayList<>();
|
||||
|
@ -95,12 +91,12 @@ public class FileEntity extends TypeEntity {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void inferLocalLevelEntities(Inferer inferer) {
|
||||
this.importedRelationEntities = inferer.getImportedRelationEntities(importedNames);
|
||||
this.importedTypes = inferer.getImportedTypes(importedNames,this);
|
||||
this.importedFiles = inferer.getImportedFiles(importedNames);
|
||||
public void inferLocalLevelEntities(IBindingResolver bindingResolver) {
|
||||
this.importedRelationEntities = bindingResolver.getImportedRelationEntities(importedNames);
|
||||
this.importedTypes = bindingResolver.getImportedTypes(importedNames,this);
|
||||
this.importedFiles = bindingResolver.getImportedFiles(importedNames);
|
||||
|
||||
super.inferLocalLevelEntities(inferer);
|
||||
super.inferLocalLevelEntities(bindingResolver);
|
||||
}
|
||||
|
||||
public boolean isInProjectScope() {
|
||||
|
|
|
@ -24,12 +24,12 @@ SOFTWARE.
|
|||
|
||||
package depends.entity;
|
||||
|
||||
import depends.relations.IBindingResolver;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import depends.relations.Inferer;
|
||||
|
||||
public class FunctionEntity extends ContainerEntity{
|
||||
private List<GenericName> returnTypeIdentifiers = new ArrayList<>();
|
||||
Collection<VarEntity> parameters;
|
||||
|
@ -79,28 +79,28 @@ public class FunctionEntity extends ContainerEntity{
|
|||
}
|
||||
|
||||
@Override
|
||||
public void inferLocalLevelEntities(Inferer inferer) {
|
||||
public void inferLocalLevelEntities(IBindingResolver bindingResolver) {
|
||||
for (VarEntity param:parameters) {
|
||||
param.fillCandidateTypes(inferer);
|
||||
param.inferLocalLevelEntities(inferer);
|
||||
param.fillCandidateTypes(bindingResolver);
|
||||
param.inferLocalLevelEntities(bindingResolver);
|
||||
}
|
||||
if (returnTypes.size()<returnTypeIdentifiers.size()) {
|
||||
returnTypes = identiferToEntities(inferer,this.returnTypeIdentifiers);
|
||||
returnTypes = identiferToEntities(bindingResolver,this.returnTypeIdentifiers);
|
||||
for ( GenericName returnTypeName: returnTypeIdentifiers) {
|
||||
Collection<Entity> typeEntities = typeParametersToEntities(inferer, returnTypeName);
|
||||
Collection<Entity> typeEntities = typeParametersToEntities(bindingResolver, returnTypeName);
|
||||
this.appendTypeParameters(typeEntities);
|
||||
}
|
||||
}
|
||||
if (throwTypes.size()<throwTypesIdentifiers.size())
|
||||
throwTypes = identiferToEntities(inferer,this.throwTypesIdentifiers);
|
||||
super.inferLocalLevelEntities(inferer);
|
||||
throwTypes = identiferToEntities(bindingResolver,this.throwTypesIdentifiers);
|
||||
super.inferLocalLevelEntities(bindingResolver);
|
||||
}
|
||||
|
||||
|
||||
private Collection<Entity> typeParametersToEntities(Inferer inferer,GenericName name) {
|
||||
private Collection<Entity> typeParametersToEntities(IBindingResolver bindingResolver, GenericName name) {
|
||||
ArrayList<Entity> r = new ArrayList<>();
|
||||
for (GenericName typeParameter:name.getArguments()) {
|
||||
toEntityList(inferer, r,typeParameter);
|
||||
toEntityList(bindingResolver, r,typeParameter);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package depends.entity;
|
||||
|
||||
import depends.relations.Inferer;
|
||||
import depends.relations.IBindingResolver;
|
||||
|
||||
public class FunctionEntityImpl extends FunctionEntity {
|
||||
Entity implementedFunction = null;
|
||||
|
@ -11,9 +11,9 @@ public class FunctionEntityImpl extends FunctionEntity {
|
|||
super(simpleName,parent,id,returnType);
|
||||
}
|
||||
@Override
|
||||
public void inferLocalLevelEntities(Inferer inferer) {
|
||||
super.inferLocalLevelEntities(inferer);
|
||||
implementedFunction = inferer.lookupTypeInImported((FileEntity)(getAncestorOfType(FileEntity.class)),this.getQualifiedName());
|
||||
public void inferLocalLevelEntities(IBindingResolver bindingResolver) {
|
||||
super.inferLocalLevelEntities(bindingResolver);
|
||||
implementedFunction = bindingResolver.lookupTypeInImported((FileEntity)(getAncestorOfType(FileEntity.class)),this.getQualifiedName());
|
||||
}
|
||||
public Entity getImplemented() {
|
||||
return implementedFunction;
|
||||
|
|
|
@ -29,7 +29,7 @@ import java.util.Collection;
|
|||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import depends.relations.Inferer;
|
||||
import depends.relations.IBindingResolver;
|
||||
|
||||
/**
|
||||
* MultiDeclareEntity is a special container, which is used as a wrapper
|
||||
|
@ -47,9 +47,9 @@ public class MultiDeclareEntities extends ContainerEntity {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void inferLocalLevelEntities(Inferer inferer) {
|
||||
public void inferLocalLevelEntities(IBindingResolver bindingResolver) {
|
||||
for (Entity entity:entities) {
|
||||
entity.inferLocalLevelEntities(inferer);
|
||||
entity.inferLocalLevelEntities(bindingResolver);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ SOFTWARE.
|
|||
|
||||
package depends.entity;
|
||||
|
||||
import depends.relations.Inferer;
|
||||
import depends.relations.IBindingResolver;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
@ -46,9 +46,9 @@ public class TypeEntity extends ContainerEntity {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void inferLocalLevelEntities(Inferer inferer) {
|
||||
public void inferLocalLevelEntities(IBindingResolver bindingResolver) {
|
||||
inheritedTypes = new ArrayList<>();
|
||||
Collection<Entity> r = identiferToEntities(inferer, this.inhertedTypeIdentifiers);
|
||||
Collection<Entity> r = identiferToEntities(bindingResolver, this.inhertedTypeIdentifiers);
|
||||
if (r!=null) {
|
||||
r.forEach(item -> {
|
||||
Entity typeItem = getTypeEntity(item);
|
||||
|
@ -62,7 +62,7 @@ public class TypeEntity extends ContainerEntity {
|
|||
inheritedTypes.remove(this);
|
||||
|
||||
implementedTypes = new ArrayList<>();
|
||||
r = identiferToEntities(inferer, this.implementedIdentifiers);
|
||||
r = identiferToEntities(bindingResolver, this.implementedIdentifiers);
|
||||
if (r!=null) {
|
||||
r.forEach(item -> {
|
||||
Entity typeItem = getTypeEntity(item);
|
||||
|
@ -76,7 +76,7 @@ public class TypeEntity extends ContainerEntity {
|
|||
implementedTypes.remove(this);
|
||||
if (inheritedTypes.size() > 0)
|
||||
inheritedType = inheritedTypes.iterator().next();
|
||||
super.inferLocalLevelEntities(inferer);
|
||||
super.inferLocalLevelEntities(bindingResolver);
|
||||
}
|
||||
|
||||
private Entity getTypeEntity(Entity item) {
|
||||
|
|
|
@ -24,11 +24,11 @@ SOFTWARE.
|
|||
|
||||
package depends.entity;
|
||||
|
||||
import depends.relations.IBindingResolver;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import depends.relations.Inferer;
|
||||
|
||||
public class VarEntity extends ContainerEntity {
|
||||
private GenericName rawType;
|
||||
private TypeEntity type;
|
||||
|
@ -59,9 +59,9 @@ public class VarEntity extends ContainerEntity {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void inferLocalLevelEntities(Inferer inferer) {
|
||||
super.inferLocalLevelEntities(inferer);
|
||||
Entity entity = inferer.resolveName(this, rawType, true);
|
||||
public void inferLocalLevelEntities(IBindingResolver bindingResolver) {
|
||||
super.inferLocalLevelEntities(bindingResolver);
|
||||
Entity entity = bindingResolver.resolveName(this, rawType, true);
|
||||
if (entity!=null) {
|
||||
this.setActualReferTo(entity);
|
||||
type = entity.getType();
|
||||
|
@ -72,7 +72,7 @@ public class VarEntity extends ContainerEntity {
|
|||
}
|
||||
}
|
||||
if (type==null) {
|
||||
fillCandidateTypes(inferer);
|
||||
fillCandidateTypes(bindingResolver);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,16 +90,16 @@ public class VarEntity extends ContainerEntity {
|
|||
this.functionCalls.add(new FunctionCall(fname));
|
||||
}
|
||||
|
||||
public void fillCandidateTypes(Inferer inferer) {
|
||||
if (!inferer.isEagerExpressionResolve()) return;
|
||||
public void fillCandidateTypes(IBindingResolver bindingResolver) {
|
||||
if (!bindingResolver.isEagerExpressionResolve()) return;
|
||||
if (type!=null && !(type instanceof CandidateTypes)) return ; //it is a strong type lang, do not need deduce candidate types
|
||||
if (functionCalls==null) return;
|
||||
if (functionCalls.size()==0) return; //no information avaliable for type deduction
|
||||
if (this.rawType==null) {
|
||||
List<TypeEntity> candidateTypes = inferer.calculateCandidateTypes(this,this.functionCalls);
|
||||
List<TypeEntity> candidateTypes = bindingResolver.calculateCandidateTypes(this,this.functionCalls);
|
||||
if (candidateTypes.size()>0) {
|
||||
this.type = new CandidateTypes(candidateTypes,inferer.getRepo().generateId());
|
||||
inferer.getRepo().add(this.type);
|
||||
this.type = new CandidateTypes(candidateTypes, bindingResolver.getRepo().generateId());
|
||||
bindingResolver.getRepo().add(this.type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ import depends.entity.repo.BuiltInType;
|
|||
import depends.entity.repo.EntityRepo;
|
||||
import depends.entity.repo.InMemoryEntityRepo;
|
||||
import depends.relations.ImportLookupStrategy;
|
||||
import depends.relations.Inferer;
|
||||
import depends.relations.IBindingResolver;
|
||||
import multilang.depends.util.file.FileTraversal;
|
||||
import multilang.depends.util.file.FileUtil;
|
||||
import org.codehaus.plexus.util.FileUtils;
|
||||
|
@ -83,7 +83,7 @@ abstract public class AbstractLangProcessor {
|
|||
*/
|
||||
public abstract FileParser createFileParser(String fileFullPath);
|
||||
|
||||
public Inferer inferer;
|
||||
public IBindingResolver bindingResolver;
|
||||
protected EntityRepo entityRepo;
|
||||
protected String inputSrcPath;
|
||||
public String[] includeDirs;
|
||||
|
@ -102,13 +102,13 @@ abstract public class AbstractLangProcessor {
|
|||
*
|
||||
* @param inputDir
|
||||
* @param includeDir
|
||||
* @param inferer
|
||||
* @param bindingResolver
|
||||
* @return
|
||||
*/
|
||||
public EntityRepo buildDependencies(String inputDir, String[] includeDir, Inferer inferer) {
|
||||
public EntityRepo buildDependencies(String inputDir, String[] includeDir, IBindingResolver bindingResolver) {
|
||||
this.inputSrcPath = inputDir;
|
||||
this.includeDirs = includeDir;
|
||||
this.inferer = inferer;
|
||||
this.bindingResolver = bindingResolver;
|
||||
logger.info("Start parsing files...");
|
||||
parseAllFiles();
|
||||
markAllEntitiesScope();
|
||||
|
@ -144,7 +144,7 @@ abstract public class AbstractLangProcessor {
|
|||
*/
|
||||
public void resolveBindings() {
|
||||
System.out.println("Resolve types and bindings of variables, methods and expressions....");
|
||||
this.potentialExternalDependencies = inferer.resolveAllBindings(this);
|
||||
this.potentialExternalDependencies = bindingResolver.resolveAllBindings(this.isEagerExpressionResolve());
|
||||
if (getExternalDependencies().size() > 0) {
|
||||
System.out.println("There are " + getExternalDependencies().size() + " items are potential external dependencies.");
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ import depends.entity.*;
|
|||
import depends.entity.repo.EntityRepo;
|
||||
import depends.entity.repo.IdGenerator;
|
||||
import depends.importtypes.Import;
|
||||
import depends.relations.Inferer;
|
||||
import depends.relations.IBindingResolver;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -40,14 +40,14 @@ public abstract class HandlerContext {
|
|||
protected IdGenerator idGenerator;
|
||||
|
||||
protected FileEntity currentFileEntity;
|
||||
protected Inferer inferer;
|
||||
protected IBindingResolver bindingResolver;
|
||||
|
||||
|
||||
public HandlerContext(EntityRepo entityRepo, Inferer inferer) {
|
||||
public HandlerContext(EntityRepo entityRepo, IBindingResolver bindingResolver) {
|
||||
this.entityRepo = entityRepo;
|
||||
this.idGenerator = entityRepo;
|
||||
entityStack = new Stack<Entity>();
|
||||
this.inferer = inferer;
|
||||
this.bindingResolver = bindingResolver;
|
||||
}
|
||||
|
||||
public FileEntity startFile(String fileName) {
|
||||
|
@ -312,7 +312,7 @@ public abstract class HandlerContext {
|
|||
}
|
||||
|
||||
private VarEntity getVarInLocalFile(ContainerEntity container, GenericName varName) {
|
||||
Entity entity = inferer.resolveName(container, varName, false);
|
||||
Entity entity = bindingResolver.resolveName(container, varName, false);
|
||||
if (entity ==null ) return null;
|
||||
if (!entity.getAncestorOfType(FileEntity.class).equals(currentFileEntity)) return null;
|
||||
if (entity instanceof VarEntity) return (VarEntity)entity;
|
||||
|
@ -320,7 +320,7 @@ public abstract class HandlerContext {
|
|||
}
|
||||
|
||||
public Entity foundEntityWithName(GenericName rawName) {
|
||||
return inferer.resolveName(lastContainer(), rawName, true);
|
||||
return bindingResolver.resolveName(lastContainer(), rawName, true);
|
||||
}
|
||||
|
||||
public void addToRepo(Entity entity) {
|
||||
|
|
|
@ -25,12 +25,11 @@ SOFTWARE.
|
|||
package depends.extractor.cpp;
|
||||
|
||||
import depends.entity.repo.EntityRepo;
|
||||
import depends.relations.Inferer;
|
||||
|
||||
public abstract class CppFileParser implements depends.extractor.FileParser {
|
||||
protected String fileFullPath;
|
||||
protected EntityRepo entityRepo;
|
||||
public CppFileParser(String fileFullPath, EntityRepo entityRepo, Inferer inferer) {
|
||||
public CppFileParser(String fileFullPath, EntityRepo entityRepo) {
|
||||
this.fileFullPath = fileFullPath;
|
||||
this.entityRepo = entityRepo;
|
||||
}
|
||||
|
|
|
@ -27,12 +27,12 @@ package depends.extractor.cpp;
|
|||
import depends.entity.*;
|
||||
import depends.entity.repo.EntityRepo;
|
||||
import depends.extractor.HandlerContext;
|
||||
import depends.relations.Inferer;
|
||||
import depends.relations.IBindingResolver;
|
||||
|
||||
public class CppHandlerContext extends HandlerContext {
|
||||
|
||||
public CppHandlerContext(EntityRepo entityRepo,Inferer inferer) {
|
||||
super(entityRepo,inferer);
|
||||
public CppHandlerContext(EntityRepo entityRepo, IBindingResolver IBindingResolver) {
|
||||
super(entityRepo, IBindingResolver);
|
||||
}
|
||||
|
||||
public Entity foundNamespace(String nampespaceName, int startingLineNumber) {
|
||||
|
|
|
@ -56,12 +56,12 @@ public class CppImportLookupStrategy extends ImportLookupStrategy {
|
|||
if (importedItem instanceof FileEntity) {
|
||||
FileEntity importedFile = (FileEntity) repo.getEntity(file);
|
||||
if (importedFile==null) continue;
|
||||
Entity entity = inferer.resolveName(importedFile,GenericName.build(name), false);
|
||||
Entity entity = bindingResolver.resolveName(importedFile,GenericName.build(name), false);
|
||||
if (entity!=null) return entity;
|
||||
Collection<Entity> namespaces = fileEntity.getImportedTypes();
|
||||
for (Entity ns:namespaces) {
|
||||
String nameWithPrefix = ns.getQualifiedName() + "." + name;
|
||||
entity = inferer.resolveName(importedFile,GenericName.build(nameWithPrefix), false);
|
||||
entity = bindingResolver.resolveName(importedFile,GenericName.build(nameWithPrefix), false);
|
||||
if (entity!=null) return entity;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ public class CppProcessor extends AbstractLangProcessor {
|
|||
if (preprocessorHandler==null) {
|
||||
preprocessorHandler = new PreprocessorHandler(super.inputSrcPath,super.includePaths());
|
||||
}
|
||||
return new CdtCppFileParser(fileFullPath, entityRepo, preprocessorHandler, inferer, macroRepo);
|
||||
return new CdtCppFileParser(fileFullPath, entityRepo, preprocessorHandler, bindingResolver, macroRepo);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -29,7 +29,7 @@ import depends.entity.FileEntity;
|
|||
import depends.entity.repo.EntityRepo;
|
||||
import depends.extractor.cpp.CppFileParser;
|
||||
import depends.extractor.cpp.MacroRepo;
|
||||
import depends.relations.Inferer;
|
||||
import depends.relations.IBindingResolver;
|
||||
import multilang.depends.util.file.FileUtil;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
|
||||
|
@ -40,14 +40,14 @@ import java.util.Map;
|
|||
public class CdtCppFileParser extends CppFileParser {
|
||||
|
||||
private PreprocessorHandler preprocessorHandler ;
|
||||
private Inferer inferer;
|
||||
private IBindingResolver bindingResolver;
|
||||
private MacroRepo macroRepo;
|
||||
|
||||
public CdtCppFileParser(String fileFullPath, EntityRepo entityRepo,PreprocessorHandler preprocessorHandler, Inferer inferer, MacroRepo macroRepo) {
|
||||
super(fileFullPath, entityRepo,inferer);
|
||||
public CdtCppFileParser(String fileFullPath, EntityRepo entityRepo, PreprocessorHandler preprocessorHandler, IBindingResolver bindingResolver, MacroRepo macroRepo) {
|
||||
super(fileFullPath, entityRepo);
|
||||
this.preprocessorHandler = preprocessorHandler;
|
||||
this.fileFullPath = FileUtil.uniqFilePath(fileFullPath);
|
||||
this.inferer = inferer;
|
||||
this.bindingResolver = bindingResolver;
|
||||
this.macroRepo= macroRepo;
|
||||
}
|
||||
@Override
|
||||
|
@ -73,11 +73,11 @@ public class CdtCppFileParser extends CppFileParser {
|
|||
if (fileFullPath.contains("regex.h")){
|
||||
System.out.println("stop");
|
||||
}
|
||||
CppVisitor bridge = new CppVisitor(fileFullPath, entityRepo, preprocessorHandler,inferer);
|
||||
CppVisitor bridge = new CppVisitor(fileFullPath, entityRepo, preprocessorHandler, bindingResolver);
|
||||
IASTTranslationUnit tu = (new CDTParser(preprocessorHandler.getIncludePaths())).parse(fileFullPath,macroMap);
|
||||
boolean containsIncludes = false;
|
||||
for (String incl:preprocessorHandler.getDirectIncludedFiles(tu.getAllPreprocessorStatements(),fileFullPath)) {
|
||||
CdtCppFileParser importedParser = new CdtCppFileParser(incl, entityRepo, preprocessorHandler,inferer,macroRepo);
|
||||
CdtCppFileParser importedParser = new CdtCppFileParser(incl, entityRepo, preprocessorHandler, bindingResolver,macroRepo);
|
||||
importedParser.parse(false,macroMap);
|
||||
Map<String, String> macros = macroRepo.get(incl);
|
||||
if (macros!=null)
|
||||
|
|
|
@ -31,7 +31,7 @@ import depends.extractor.cpp.CppHandlerContext;
|
|||
import depends.importtypes.ExactMatchImport;
|
||||
import depends.importtypes.FileImport;
|
||||
import depends.importtypes.PackageWildCardImport;
|
||||
import depends.relations.Inferer;
|
||||
import depends.relations.IBindingResolver;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
import org.eclipse.cdt.core.dom.ast.*;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTEnumerationSpecifier.IASTEnumerator;
|
||||
|
@ -50,17 +50,17 @@ public class CppVisitor extends ASTVisitor {
|
|||
private CppHandlerContext context;
|
||||
private IdGenerator idGenerator;
|
||||
private PreprocessorHandler preprocessorHandler;
|
||||
Inferer inferer;
|
||||
IBindingResolver bindingResolver;
|
||||
private ExpressionUsage expressionUsage;
|
||||
HashSet<String> file;
|
||||
public CppVisitor(String fileFullPath, EntityRepo entityRepo, PreprocessorHandler preprocessorHandler,Inferer inferer) {
|
||||
public CppVisitor(String fileFullPath, EntityRepo entityRepo, PreprocessorHandler preprocessorHandler, IBindingResolver bindingResolver) {
|
||||
super(true);
|
||||
this.shouldVisitAmbiguousNodes = true;
|
||||
this.shouldVisitImplicitNames = true;
|
||||
this.includeInactiveNodes = true;
|
||||
this.context = new CppHandlerContext(entityRepo,inferer);
|
||||
this.context = new CppHandlerContext(entityRepo, bindingResolver);
|
||||
idGenerator = entityRepo;
|
||||
this.inferer = inferer;
|
||||
this.bindingResolver = bindingResolver;
|
||||
this.preprocessorHandler = preprocessorHandler;
|
||||
expressionUsage = new ExpressionUsage(context,entityRepo);
|
||||
file = new HashSet<>();
|
||||
|
|
|
@ -27,7 +27,7 @@ package depends.extractor.golang;
|
|||
import depends.entity.Entity;
|
||||
import depends.entity.FileEntity;
|
||||
import depends.entity.repo.EntityRepo;
|
||||
import depends.relations.Inferer;
|
||||
import depends.relations.IBindingResolver;
|
||||
import org.antlr.v4.runtime.CharStream;
|
||||
import org.antlr.v4.runtime.CharStreams;
|
||||
import org.antlr.v4.runtime.CommonTokenStream;
|
||||
|
@ -43,11 +43,11 @@ import java.io.IOException;
|
|||
public class GoFileParser implements depends.extractor.FileParser{
|
||||
private String fileFullPath;
|
||||
private EntityRepo entityRepo;
|
||||
private Inferer inferer;
|
||||
public GoFileParser(String fileFullPath, EntityRepo entityRepo, Inferer inferer) {
|
||||
private IBindingResolver bindingResolver;
|
||||
public GoFileParser(String fileFullPath, EntityRepo entityRepo, IBindingResolver bindingResolver) {
|
||||
this.fileFullPath = fileFullPath;
|
||||
this.entityRepo = entityRepo;
|
||||
this.inferer = inferer;
|
||||
this.bindingResolver = bindingResolver;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -59,7 +59,7 @@ public class GoFileParser implements depends.extractor.FileParser{
|
|||
GoParser parser = new GoParser(tokens);
|
||||
ParserATNSimulator interpreter = new ParserATNSimulator(parser, parser.getATN(), parser.getInterpreter().decisionToDFA, new PredictionContextCache());
|
||||
parser.setInterpreter(interpreter);
|
||||
GoListener bridge = new GoListener(fileFullPath, entityRepo,inferer);
|
||||
GoListener bridge = new GoListener(fileFullPath, entityRepo, bindingResolver);
|
||||
ParseTreeWalker walker = new ParseTreeWalker();
|
||||
try {
|
||||
walker.walk(bridge, parser.sourceFile());
|
||||
|
|
|
@ -28,12 +28,12 @@ import depends.entity.Entity;
|
|||
import depends.entity.PackageEntity;
|
||||
import depends.entity.repo.EntityRepo;
|
||||
import depends.extractor.HandlerContext;
|
||||
import depends.relations.Inferer;
|
||||
import depends.relations.IBindingResolver;
|
||||
|
||||
public class GoHandlerContext extends HandlerContext {
|
||||
|
||||
public GoHandlerContext(EntityRepo entityRepo, Inferer inferer) {
|
||||
super(entityRepo,inferer);
|
||||
public GoHandlerContext(EntityRepo entityRepo, IBindingResolver bindingResolver) {
|
||||
super(entityRepo, bindingResolver);
|
||||
}
|
||||
|
||||
public Entity foundPackageDeclaration(String packageName){
|
||||
|
|
|
@ -4,7 +4,7 @@ import depends.entity.FunctionEntity;
|
|||
import depends.entity.GenericName;
|
||||
import depends.entity.VarEntity;
|
||||
import depends.entity.repo.EntityRepo;
|
||||
import depends.relations.Inferer;
|
||||
import depends.relations.IBindingResolver;
|
||||
import org.antlr.v4.runtime.tree.TerminalNode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -17,8 +17,8 @@ public class GoListener extends GoParserBaseListener {
|
|||
super.enterSourceFile(ctx);
|
||||
}
|
||||
|
||||
public GoListener(String fileFullPath, EntityRepo entityRepo, Inferer inferer) {
|
||||
context = new GoHandlerContext(entityRepo,inferer);
|
||||
public GoListener(String fileFullPath, EntityRepo entityRepo, IBindingResolver bindingResolver) {
|
||||
context = new GoHandlerContext(entityRepo, bindingResolver);
|
||||
context.startFile(fileFullPath);
|
||||
this.entityRepo = entityRepo;
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ public class GoProcessor extends AbstractLangProcessor {
|
|||
|
||||
@Override
|
||||
public FileParser createFileParser(String fileFullPath) {
|
||||
return new GoFileParser(fileFullPath, entityRepo, inferer);
|
||||
return new GoFileParser(fileFullPath, entityRepo, bindingResolver);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -24,8 +24,10 @@ SOFTWARE.
|
|||
|
||||
package depends.extractor.java;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import depends.entity.Entity;
|
||||
import depends.entity.FileEntity;
|
||||
import depends.entity.repo.EntityRepo;
|
||||
import depends.relations.IBindingResolver;
|
||||
import org.antlr.v4.runtime.CharStream;
|
||||
import org.antlr.v4.runtime.CharStreams;
|
||||
import org.antlr.v4.runtime.CommonTokenStream;
|
||||
|
@ -35,22 +37,17 @@ import org.antlr.v4.runtime.atn.ParserATNSimulator;
|
|||
import org.antlr.v4.runtime.atn.PredictionContextCache;
|
||||
import org.antlr.v4.runtime.tree.ParseTreeWalker;
|
||||
|
||||
import depends.entity.Entity;
|
||||
import depends.entity.FileEntity;
|
||||
import depends.entity.repo.EntityRepo;
|
||||
import depends.extractor.java.JavaLexer;
|
||||
import depends.extractor.java.JavaParser;
|
||||
import depends.relations.Inferer;
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
public class JavaFileParser implements depends.extractor.FileParser{
|
||||
private String fileFullPath;
|
||||
private EntityRepo entityRepo;
|
||||
private Inferer inferer;
|
||||
public JavaFileParser(String fileFullPath,EntityRepo entityRepo, Inferer inferer) {
|
||||
private IBindingResolver bindingResolver;
|
||||
public JavaFileParser(String fileFullPath,EntityRepo entityRepo, IBindingResolver bindingResolver) {
|
||||
this.fileFullPath = fileFullPath;
|
||||
this.entityRepo = entityRepo;
|
||||
this.inferer = inferer;
|
||||
this.bindingResolver = bindingResolver;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -62,7 +59,7 @@ public class JavaFileParser implements depends.extractor.FileParser{
|
|||
JavaParser parser = new JavaParser(tokens);
|
||||
ParserATNSimulator interpreter = new ParserATNSimulator(parser, parser.getATN(), parser.getInterpreter().decisionToDFA, new PredictionContextCache());
|
||||
parser.setInterpreter(interpreter);
|
||||
JavaListener bridge = new JavaListener(fileFullPath, entityRepo,inferer);
|
||||
JavaListener bridge = new JavaListener(fileFullPath, entityRepo, bindingResolver);
|
||||
ParseTreeWalker walker = new ParseTreeWalker();
|
||||
try {
|
||||
walker.walk(bridge, parser.compilationUnit());
|
||||
|
|
|
@ -28,12 +28,12 @@ import depends.entity.Entity;
|
|||
import depends.entity.PackageEntity;
|
||||
import depends.entity.repo.EntityRepo;
|
||||
import depends.extractor.HandlerContext;
|
||||
import depends.relations.Inferer;
|
||||
import depends.relations.IBindingResolver;
|
||||
|
||||
public class JavaHandlerContext extends HandlerContext {
|
||||
|
||||
public JavaHandlerContext(EntityRepo entityRepo,Inferer inferer) {
|
||||
super(entityRepo,inferer);
|
||||
public JavaHandlerContext(EntityRepo entityRepo, IBindingResolver bindingResolver) {
|
||||
super(entityRepo, bindingResolver);
|
||||
}
|
||||
|
||||
public Entity foundNewPackage(String packageName) {
|
||||
|
|
|
@ -29,7 +29,7 @@ import depends.entity.repo.EntityRepo;
|
|||
import depends.extractor.java.JavaParser.*;
|
||||
import depends.extractor.java.context.*;
|
||||
import depends.importtypes.ExactMatchImport;
|
||||
import depends.relations.Inferer;
|
||||
import depends.relations.IBindingResolver;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -40,8 +40,8 @@ public class JavaListener extends JavaParserBaseListener {
|
|||
private final ExpressionUsage expressionUsage;
|
||||
private final EntityRepo entityRepo;
|
||||
|
||||
public JavaListener(String fileFullPath, EntityRepo entityRepo,Inferer inferer) {
|
||||
this.context = new JavaHandlerContext(entityRepo,inferer);
|
||||
public JavaListener(String fileFullPath, EntityRepo entityRepo, IBindingResolver bindingResolver) {
|
||||
this.context = new JavaHandlerContext(entityRepo, bindingResolver);
|
||||
this.entityRepo = entityRepo;
|
||||
annotationProcessor = new AnnotationProcessor();
|
||||
expressionUsage = new ExpressionUsage(context,entityRepo);
|
||||
|
|
|
@ -52,7 +52,7 @@ public class JavaProcessor extends AbstractLangProcessor {
|
|||
|
||||
@Override
|
||||
public FileParser createFileParser(String fileFullPath) {
|
||||
return new JavaFileParser(fileFullPath,entityRepo, inferer);
|
||||
return new JavaFileParser(fileFullPath,entityRepo, bindingResolver);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
package depends.extractor.kotlin;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import depends.entity.repo.EntityRepo;
|
||||
import depends.extractor.FileParser;
|
||||
import depends.relations.IBindingResolver;
|
||||
import org.antlr.v4.runtime.CharStream;
|
||||
import org.antlr.v4.runtime.CharStreams;
|
||||
import org.antlr.v4.runtime.CommonTokenStream;
|
||||
import org.antlr.v4.runtime.Lexer;
|
||||
import org.antlr.v4.runtime.tree.ParseTreeWalker;
|
||||
|
||||
import depends.entity.repo.EntityRepo;
|
||||
import depends.extractor.FileParser;
|
||||
import depends.relations.Inferer;
|
||||
import java.io.IOException;
|
||||
|
||||
public class KotlinFileParser implements FileParser {
|
||||
|
||||
|
@ -20,18 +19,18 @@ public class KotlinFileParser implements FileParser {
|
|||
Lexer lexer = new KotlinLexer(input);
|
||||
CommonTokenStream tokens = new CommonTokenStream(lexer);
|
||||
KotlinParser parser = new KotlinParser(tokens);
|
||||
KotlinListener bridge = new KotlinListener(fileFullPath, entityRepo,inferer);
|
||||
KotlinListener bridge = new KotlinListener(fileFullPath, entityRepo, bindingResolver);
|
||||
ParseTreeWalker walker = new ParseTreeWalker();
|
||||
walker.walk(bridge, parser.kotlinFile());
|
||||
}
|
||||
|
||||
private String fileFullPath;
|
||||
private EntityRepo entityRepo;
|
||||
private Inferer inferer;
|
||||
public KotlinFileParser(String fileFullPath,EntityRepo entityRepo, Inferer inferer) {
|
||||
private IBindingResolver bindingResolver;
|
||||
public KotlinFileParser(String fileFullPath,EntityRepo entityRepo, IBindingResolver bindingResolver) {
|
||||
this.fileFullPath = fileFullPath;
|
||||
this.entityRepo = entityRepo;
|
||||
this.inferer = inferer;
|
||||
this.bindingResolver = bindingResolver;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -2,12 +2,12 @@ package depends.extractor.kotlin;
|
|||
|
||||
import depends.entity.repo.EntityRepo;
|
||||
import depends.extractor.java.JavaHandlerContext;
|
||||
import depends.relations.Inferer;
|
||||
import depends.relations.IBindingResolver;
|
||||
|
||||
public class KotlinHandlerContext extends JavaHandlerContext {
|
||||
|
||||
public KotlinHandlerContext(EntityRepo entityRepo, Inferer inferer) {
|
||||
super(entityRepo,inferer);
|
||||
public KotlinHandlerContext(EntityRepo entityRepo, IBindingResolver bindingResolver) {
|
||||
super(entityRepo, bindingResolver);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,14 +4,14 @@ import depends.entity.repo.EntityRepo;
|
|||
import depends.extractor.kotlin.KotlinParser.ImportHeaderContext;
|
||||
import depends.extractor.kotlin.KotlinParser.PackageHeaderContext;
|
||||
import depends.importtypes.ExactMatchImport;
|
||||
import depends.relations.Inferer;
|
||||
import depends.relations.IBindingResolver;
|
||||
|
||||
public class KotlinListener extends KotlinParserBaseListener {
|
||||
|
||||
private KotlinHandlerContext context;
|
||||
|
||||
public KotlinListener(String fileFullPath, EntityRepo entityRepo, Inferer inferer) {
|
||||
this.context = new KotlinHandlerContext(entityRepo,inferer);
|
||||
public KotlinListener(String fileFullPath, EntityRepo entityRepo, IBindingResolver bindingResolver) {
|
||||
this.context = new KotlinHandlerContext(entityRepo, bindingResolver);
|
||||
context.startFile(fileFullPath);
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ public class KotlinProcessor extends AbstractLangProcessor {
|
|||
|
||||
@Override
|
||||
public FileParser createFileParser(String fileFullPath) {
|
||||
return new KotlinFileParser(fileFullPath,entityRepo, inferer);
|
||||
return new KotlinFileParser(fileFullPath,entityRepo, bindingResolver);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -33,7 +33,6 @@ import depends.entity.Entity;
|
|||
import depends.entity.FileEntity;
|
||||
import depends.entity.GenericName;
|
||||
import depends.entity.TypeEntity;
|
||||
import depends.relations.Inferer;
|
||||
|
||||
public class PomArtifactEntity extends TypeEntity {
|
||||
HashMap<String,String> properties;
|
||||
|
|
|
@ -24,23 +24,22 @@ SOFTWARE.
|
|||
|
||||
package depends.extractor.pom;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.antlr.v4.runtime.CharStream;
|
||||
import org.antlr.v4.runtime.CharStreams;
|
||||
import org.antlr.v4.runtime.CommonTokenStream;
|
||||
import org.antlr.v4.runtime.Lexer;
|
||||
import org.antlr.v4.runtime.tree.ParseTreeWalker;
|
||||
|
||||
import depends.entity.Entity;
|
||||
import depends.entity.FileEntity;
|
||||
import depends.entity.repo.EntityRepo;
|
||||
import depends.extractor.FileParser;
|
||||
import depends.extractor.xml.XMLLexer;
|
||||
import depends.extractor.xml.XMLParser;
|
||||
import depends.relations.Inferer;
|
||||
import depends.relations.IBindingResolver;
|
||||
import multilang.depends.util.file.FileUtil;
|
||||
import org.antlr.v4.runtime.CharStream;
|
||||
import org.antlr.v4.runtime.CharStreams;
|
||||
import org.antlr.v4.runtime.CommonTokenStream;
|
||||
import org.antlr.v4.runtime.Lexer;
|
||||
import org.antlr.v4.runtime.tree.ParseTreeWalker;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class PomFileParser implements FileParser {
|
||||
|
||||
|
@ -48,14 +47,14 @@ public class PomFileParser implements FileParser {
|
|||
private EntityRepo entityRepo;
|
||||
private PomProcessor parseCreator;
|
||||
private List<String> includePaths;
|
||||
private Inferer inferer;
|
||||
private IBindingResolver bindingResolver;
|
||||
|
||||
public PomFileParser(String fileFullPath, EntityRepo entityRepo, List<String> includePaths, PomProcessor pomProcessor,Inferer inferer) {
|
||||
public PomFileParser(String fileFullPath, EntityRepo entityRepo, List<String> includePaths, PomProcessor pomProcessor, IBindingResolver bindingResolver) {
|
||||
this.fileFullPath = FileUtil.uniqFilePath(fileFullPath);
|
||||
this.entityRepo = entityRepo;
|
||||
this.parseCreator = pomProcessor;
|
||||
this.includePaths = includePaths;
|
||||
this.inferer = inferer;
|
||||
this.bindingResolver = bindingResolver;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -70,7 +69,7 @@ public class PomFileParser implements FileParser {
|
|||
Lexer lexer = new XMLLexer(input);
|
||||
CommonTokenStream tokens = new CommonTokenStream(lexer);
|
||||
XMLParser parser = new XMLParser(tokens);
|
||||
PomListener bridge = new PomListener(fileFullPath, entityRepo, includePaths,parseCreator,inferer);
|
||||
PomListener bridge = new PomListener(fileFullPath, entityRepo, includePaths,parseCreator, bindingResolver);
|
||||
ParseTreeWalker walker = new ParseTreeWalker();
|
||||
walker.walk(bridge, parser.document());
|
||||
fileEntity = entityRepo.getEntity(fileFullPath);
|
||||
|
|
|
@ -31,7 +31,7 @@ import depends.entity.repo.EntityRepo;
|
|||
import depends.extractor.FileParser;
|
||||
import depends.extractor.xml.XMLParser.ElementContext;
|
||||
import depends.extractor.xml.XMLParserBaseListener;
|
||||
import depends.relations.Inferer;
|
||||
import depends.relations.IBindingResolver;
|
||||
import org.antlr.v4.runtime.ParserRuleContext;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -46,16 +46,16 @@ public class PomListener extends XMLParserBaseListener {
|
|||
private PomParent pomParent;
|
||||
private PomProcessor parseCreator;
|
||||
private List<String> includePaths;
|
||||
private Inferer inferer;
|
||||
private IBindingResolver IBindingResolver;
|
||||
private Stack<PomCoords> pomCoords= new Stack<>();
|
||||
|
||||
public PomListener(String fileFullPath, EntityRepo entityRepo, List<String> includePaths, PomProcessor parseCreator,
|
||||
Inferer inferer) {
|
||||
IBindingResolver bindingResolver) {
|
||||
this.context = new PomHandlerContext(entityRepo);
|
||||
this.entityRepo = entityRepo;
|
||||
this.parseCreator = parseCreator;
|
||||
this.includePaths = includePaths;
|
||||
this.inferer = inferer;
|
||||
this.IBindingResolver = bindingResolver;
|
||||
context.startFile(fileFullPath);
|
||||
}
|
||||
|
||||
|
@ -144,7 +144,7 @@ public class PomListener extends XMLParserBaseListener {
|
|||
}
|
||||
}
|
||||
pomCoords.pop();
|
||||
context.currentFile().inferLocalLevelEntities(inferer);
|
||||
context.currentFile().inferLocalLevelEntities(IBindingResolver);
|
||||
}
|
||||
super.exitElement(ctx);
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ public class PomProcessor extends AbstractLangProcessor {
|
|||
|
||||
@Override
|
||||
public FileParser createFileParser(String fileFullPath) {
|
||||
return new PomFileParser(fileFullPath,entityRepo,includePaths(),this,inferer);
|
||||
return new PomFileParser(fileFullPath,entityRepo,includePaths(),this, bindingResolver);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
package depends.extractor.python;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import depends.entity.FileEntity;
|
||||
import depends.entity.FunctionCall;
|
||||
import depends.entity.FunctionEntity;
|
||||
import depends.entity.GenericName;
|
||||
|
|
|
@ -6,12 +6,12 @@ import depends.entity.GenericName;
|
|||
import depends.entity.PackageEntity;
|
||||
import depends.entity.repo.EntityRepo;
|
||||
import depends.extractor.HandlerContext;
|
||||
import depends.relations.Inferer;
|
||||
import depends.relations.IBindingResolver;
|
||||
|
||||
public class PythonHandlerContext extends HandlerContext {
|
||||
|
||||
public PythonHandlerContext(EntityRepo entityRepo, Inferer inferer) {
|
||||
super(entityRepo, inferer);
|
||||
public PythonHandlerContext(EntityRepo entityRepo, IBindingResolver bindingResolver) {
|
||||
super(entityRepo, bindingResolver);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -6,7 +6,7 @@ import depends.extractor.HandlerContext;
|
|||
import depends.extractor.python.PythonHandlerContext;
|
||||
import depends.extractor.python.PythonParser.*;
|
||||
import depends.extractor.python.PythonParserBaseVisitor;
|
||||
import depends.relations.Inferer;
|
||||
import depends.relations.IBindingResolver;
|
||||
import org.antlr.v4.runtime.ParserRuleContext;
|
||||
import org.antlr.v4.runtime.RuleContext;
|
||||
|
||||
|
@ -18,11 +18,11 @@ public class ExpressionUsage {
|
|||
HandlerContext context;
|
||||
IdGenerator idGenerator;
|
||||
private boolean exprStarted=false;
|
||||
private Inferer inferer;
|
||||
public ExpressionUsage(PythonHandlerContext context, IdGenerator idGenerator, Inferer inferer) {
|
||||
private IBindingResolver bindingResolver;
|
||||
public ExpressionUsage(PythonHandlerContext context, IdGenerator idGenerator, IBindingResolver bindingResolver) {
|
||||
this.context = context;
|
||||
this.idGenerator = idGenerator;
|
||||
this.inferer = inferer;
|
||||
this.bindingResolver = bindingResolver;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -207,7 +207,7 @@ public class ExpressionUsage {
|
|||
Entity typeEntity = context.foundEntityWithName(funcName);
|
||||
if (typeEntity instanceof TypeEntity && typeEntity.getId() > 0) {
|
||||
theExpression.setCreate(true);
|
||||
theExpression.setType(typeEntity.getType(), typeEntity, inferer);
|
||||
theExpression.setType(typeEntity.getType(), typeEntity, bindingResolver);
|
||||
theExpression.setRawType(typeEntity.getRawName());
|
||||
return;
|
||||
}
|
||||
|
@ -221,7 +221,7 @@ public class ExpressionUsage {
|
|||
Entity typeEntity = context.foundEntityWithName(funcName);
|
||||
if (typeEntity instanceof TypeEntity && typeEntity.getId() > 0) {
|
||||
theExpression.getParent().setCreate(true);
|
||||
theExpression.setType(typeEntity.getType(), typeEntity, inferer);
|
||||
theExpression.setType(typeEntity.getType(), typeEntity, bindingResolver);
|
||||
theExpression.getParent().setRawType(typeEntity.getRawName());
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import depends.extractor.python.PythonParser.*;
|
|||
import depends.extractor.python.PythonParserBaseListener;
|
||||
import depends.extractor.ruby.IncludedFileLocator;
|
||||
import depends.importtypes.FileImport;
|
||||
import depends.relations.Inferer;
|
||||
import depends.relations.IBindingResolver;
|
||||
import multilang.depends.util.file.FileUtil;
|
||||
import org.antlr.v4.runtime.ParserRuleContext;
|
||||
|
||||
|
@ -23,15 +23,15 @@ public class PythonCodeListener extends PythonParserBaseListener{
|
|||
private final EntityRepo entityRepo;
|
||||
private final IncludedFileLocator includeFileLocator;
|
||||
private final PythonProcessor pythonProcessor;
|
||||
private final Inferer inferer;
|
||||
public PythonCodeListener(String fileFullPath, EntityRepo entityRepo, Inferer inferer,
|
||||
private final IBindingResolver bindingResolver;
|
||||
public PythonCodeListener(String fileFullPath, EntityRepo entityRepo, IBindingResolver bindingResolver,
|
||||
IncludedFileLocator includeFileLocator, PythonProcessor pythonProcessor) {
|
||||
this.context = new PythonHandlerContext(entityRepo, inferer);
|
||||
this.expressionUsage = new ExpressionUsage(context, entityRepo, inferer);
|
||||
this.context = new PythonHandlerContext(entityRepo, bindingResolver);
|
||||
this.expressionUsage = new ExpressionUsage(context, entityRepo, bindingResolver);
|
||||
FileEntity fileEntity = context.startFile(fileFullPath);
|
||||
this.entityRepo = entityRepo;
|
||||
this.includeFileLocator = includeFileLocator;
|
||||
this.inferer = inferer;
|
||||
this.bindingResolver = bindingResolver;
|
||||
this.pythonProcessor = pythonProcessor;
|
||||
|
||||
String dir = FileUtil.uniqFilePath(FileUtil.getLocatedDir(fileFullPath));
|
||||
|
@ -117,7 +117,7 @@ public class PythonCodeListener extends PythonParserBaseListener{
|
|||
if (FileUtil.existFile(fullName) && !(FileUtil.isDirectory(fullName))) {
|
||||
context.foundNewImport(new FileImport(fullName));
|
||||
}
|
||||
Entity itemEntity = inferer.resolveName(entityRepo.getEntity(fullName), GenericName.build(name), true);
|
||||
Entity itemEntity = bindingResolver.resolveName(entityRepo.getEntity(fullName), GenericName.build(name), true);
|
||||
if (itemEntity != null) {
|
||||
context.foundNewAlias(GenericName.build(alias), itemEntity);
|
||||
context.foundNewImport(new NameAliasImport(itemEntity.getQualifiedName(), itemEntity, alias));
|
||||
|
@ -183,7 +183,7 @@ public class PythonCodeListener extends PythonParserBaseListener{
|
|||
}
|
||||
|
||||
private void visitIncludedFile(String fullName) {
|
||||
PythonFileParser importedParser = new PythonFileParser(fullName, entityRepo, includeFileLocator, inferer,
|
||||
PythonFileParser importedParser = new PythonFileParser(fullName, entityRepo, includeFileLocator, bindingResolver,
|
||||
pythonProcessor);
|
||||
try {
|
||||
importedParser.parse();
|
||||
|
|
|
@ -1,13 +1,5 @@
|
|||
package depends.extractor.python.union;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.antlr.v4.runtime.CharStream;
|
||||
import org.antlr.v4.runtime.CharStreams;
|
||||
import org.antlr.v4.runtime.CommonTokenStream;
|
||||
import org.antlr.v4.runtime.Lexer;
|
||||
import org.antlr.v4.runtime.tree.ParseTreeWalker;
|
||||
|
||||
import depends.entity.Entity;
|
||||
import depends.entity.FileEntity;
|
||||
import depends.entity.repo.EntityRepo;
|
||||
|
@ -15,21 +7,28 @@ import depends.extractor.FileParser;
|
|||
import depends.extractor.python.PythonLexer;
|
||||
import depends.extractor.python.PythonParser;
|
||||
import depends.extractor.ruby.IncludedFileLocator;
|
||||
import depends.relations.Inferer;
|
||||
import depends.relations.IBindingResolver;
|
||||
import org.antlr.v4.runtime.CharStream;
|
||||
import org.antlr.v4.runtime.CharStreams;
|
||||
import org.antlr.v4.runtime.CommonTokenStream;
|
||||
import org.antlr.v4.runtime.Lexer;
|
||||
import org.antlr.v4.runtime.tree.ParseTreeWalker;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class PythonFileParser implements FileParser {
|
||||
|
||||
private String fileFullPath;
|
||||
private EntityRepo entityRepo;
|
||||
private Inferer inferer;
|
||||
private IBindingResolver bindingResolver;
|
||||
private IncludedFileLocator includeFileLocator;
|
||||
private PythonProcessor processor;
|
||||
|
||||
public PythonFileParser(String fileFullPath, EntityRepo entityRepo, IncludedFileLocator includeFileLocator,
|
||||
Inferer inferer, PythonProcessor pythonProcessor) {
|
||||
IBindingResolver bindingResolver, PythonProcessor pythonProcessor) {
|
||||
this.fileFullPath = fileFullPath;
|
||||
this.entityRepo = entityRepo;
|
||||
this.inferer = inferer;
|
||||
this.bindingResolver = bindingResolver;
|
||||
this.includeFileLocator = includeFileLocator;
|
||||
this.processor = pythonProcessor;
|
||||
}
|
||||
|
@ -47,7 +46,7 @@ public class PythonFileParser implements FileParser {
|
|||
|
||||
|
||||
PythonParser parser = new PythonParser(tokens);
|
||||
PythonCodeListener bridge = new PythonCodeListener(fileFullPath, entityRepo,inferer, includeFileLocator, processor);
|
||||
PythonCodeListener bridge = new PythonCodeListener(fileFullPath, entityRepo, bindingResolver, includeFileLocator, processor);
|
||||
ParseTreeWalker walker = new ParseTreeWalker();
|
||||
walker.walk(bridge, parser.file_input());
|
||||
fileEntity = entityRepo.getEntity(fileFullPath);
|
||||
|
|
|
@ -20,7 +20,7 @@ public class PythonProcessor extends BasePythonProcessor {
|
|||
@Override
|
||||
public FileParser createFileParser(String fileFullPath) {
|
||||
IncludedFileLocator includeFileLocator = new IncludedFileLocator(super.includePaths());
|
||||
return new PythonFileParser(fileFullPath,entityRepo,includeFileLocator,inferer,this);
|
||||
return new PythonFileParser(fileFullPath,entityRepo,includeFileLocator, bindingResolver,this);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ import depends.extractor.FileParser;
|
|||
import depends.extractor.HandlerContext;
|
||||
import depends.extractor.ParserCreator;
|
||||
import depends.importtypes.FileImport;
|
||||
import depends.relations.Inferer;
|
||||
import depends.relations.IBindingResolver;
|
||||
import multilang.depends.util.file.FileUtil;
|
||||
|
||||
import java.util.Collection;
|
||||
|
@ -41,11 +41,11 @@ public class RubyHandlerContext extends HandlerContext {
|
|||
|
||||
private IncludedFileLocator includedFileLocator;
|
||||
private ParserCreator parserCreator;
|
||||
public RubyHandlerContext(EntityRepo entityRepo,
|
||||
IncludedFileLocator includedFileLocator,
|
||||
ExecutorService executorService,
|
||||
Inferer inferer, ParserCreator parserCreator) {
|
||||
super(entityRepo,inferer);
|
||||
public RubyHandlerContext(EntityRepo entityRepo,
|
||||
IncludedFileLocator includedFileLocator,
|
||||
ExecutorService executorService,
|
||||
IBindingResolver bindingResolver, ParserCreator parserCreator) {
|
||||
super(entityRepo, bindingResolver);
|
||||
this.includedFileLocator = includedFileLocator;
|
||||
this.parserCreator = parserCreator;
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ public class RubyProcessor extends AbstractLangProcessor implements ParserCreato
|
|||
@Override
|
||||
public FileParser createFileParser(String fileFullPath) {
|
||||
executor = Executors.newSingleThreadExecutor();
|
||||
return new JRubyFileParser(fileFullPath,entityRepo,executor,new IncludedFileLocator(super.includePaths()),inferer,this);
|
||||
return new JRubyFileParser(fileFullPath,entityRepo,executor,new IncludedFileLocator(super.includePaths()), bindingResolver,this);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ package depends.extractor.ruby.jruby;
|
|||
import depends.entity.*;
|
||||
import depends.entity.repo.IdGenerator;
|
||||
import depends.extractor.ruby.RubyHandlerContext;
|
||||
import depends.relations.Inferer;
|
||||
import depends.relations.IBindingResolver;
|
||||
import org.jrubyparser.ast.*;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -35,14 +35,14 @@ import java.util.List;
|
|||
public class ExpressionUsage {
|
||||
RubyHandlerContext context;
|
||||
IdGenerator idGenerator;
|
||||
Inferer inferer;
|
||||
IBindingResolver bindingResolver;
|
||||
private RubyParserHelper helper;
|
||||
|
||||
public ExpressionUsage(RubyHandlerContext context, IdGenerator idGenerator, RubyParserHelper helper,
|
||||
Inferer inferer) {
|
||||
IBindingResolver bindingResolver) {
|
||||
this.context = context;
|
||||
this.idGenerator = idGenerator;
|
||||
this.inferer = inferer;
|
||||
this.bindingResolver = bindingResolver;
|
||||
this.helper = helper;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,10 +24,14 @@ SOFTWARE.
|
|||
|
||||
package depends.extractor.ruby.jruby;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
import depends.entity.Entity;
|
||||
import depends.entity.FileEntity;
|
||||
import depends.entity.repo.EntityRepo;
|
||||
import depends.extractor.FileParser;
|
||||
import depends.extractor.ParserCreator;
|
||||
import depends.extractor.ruby.IncludedFileLocator;
|
||||
import depends.relations.IBindingResolver;
|
||||
import multilang.depends.util.file.FileUtil;
|
||||
import org.antlr.v4.runtime.CharStream;
|
||||
import org.antlr.v4.runtime.CharStreams;
|
||||
import org.jrubyparser.CompatVersion;
|
||||
|
@ -35,31 +39,26 @@ import org.jrubyparser.Parser;
|
|||
import org.jrubyparser.ast.Node;
|
||||
import org.jrubyparser.parser.ParserConfiguration;
|
||||
|
||||
import depends.entity.Entity;
|
||||
import depends.entity.FileEntity;
|
||||
import depends.entity.repo.EntityRepo;
|
||||
import depends.extractor.FileParser;
|
||||
import depends.extractor.ParserCreator;
|
||||
import depends.extractor.ruby.IncludedFileLocator;
|
||||
import depends.relations.Inferer;
|
||||
import multilang.depends.util.file.FileUtil;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
public class JRubyFileParser implements FileParser {
|
||||
private String fileFullPath;
|
||||
private EntityRepo entityRepo;
|
||||
private ExecutorService executor;
|
||||
private IncludedFileLocator includesFileLocator;
|
||||
private Inferer inferer;
|
||||
private IBindingResolver bindingResolver;
|
||||
private ParserCreator parserCreator;
|
||||
|
||||
public JRubyFileParser(String fileFullPath, EntityRepo entityRepo,
|
||||
ExecutorService executorService,
|
||||
IncludedFileLocator includesFileLocator,
|
||||
Inferer inferer, ParserCreator parserCreator) {
|
||||
public JRubyFileParser(String fileFullPath, EntityRepo entityRepo,
|
||||
ExecutorService executorService,
|
||||
IncludedFileLocator includesFileLocator,
|
||||
IBindingResolver bindingResolver, ParserCreator parserCreator) {
|
||||
this.fileFullPath = FileUtil.uniqFilePath(fileFullPath);
|
||||
this.entityRepo = entityRepo;
|
||||
this.executor = executorService;
|
||||
this.includesFileLocator = includesFileLocator;
|
||||
this.inferer = inferer;
|
||||
this.bindingResolver = bindingResolver;
|
||||
this.parserCreator = parserCreator;
|
||||
}
|
||||
|
||||
|
@ -79,7 +78,7 @@ public class JRubyFileParser implements FileParser {
|
|||
ParserConfiguration config = new ParserConfiguration(0, version);
|
||||
try {
|
||||
Node node = rubyParser.parse("<code>", in, config);
|
||||
JRubyVisitor parser = new JRubyVisitor(fileFullPath, entityRepo, includesFileLocator,executor,inferer,parserCreator);
|
||||
JRubyVisitor parser = new JRubyVisitor(fileFullPath, entityRepo, includesFileLocator,executor, bindingResolver,parserCreator);
|
||||
node.accept(parser);
|
||||
fileEntity = entityRepo.getEntity(fileFullPath);
|
||||
((FileEntity)fileEntity).cacheAllExpressions();
|
||||
|
|
|
@ -29,7 +29,7 @@ import depends.entity.repo.EntityRepo;
|
|||
import depends.extractor.ParserCreator;
|
||||
import depends.extractor.ruby.IncludedFileLocator;
|
||||
import depends.extractor.ruby.RubyHandlerContext;
|
||||
import depends.relations.Inferer;
|
||||
import depends.relations.IBindingResolver;
|
||||
import org.jrubyparser.ast.*;
|
||||
import org.jrubyparser.util.NoopVisitor;
|
||||
|
||||
|
@ -44,9 +44,9 @@ public class JRubyVisitor extends NoopVisitor {
|
|||
private ExpressionUsage expressionUsage;
|
||||
|
||||
public JRubyVisitor(String fileFullPath, EntityRepo entityRepo, IncludedFileLocator includedFileLocator,
|
||||
ExecutorService executorService, Inferer inferer, ParserCreator parserCreator) {
|
||||
this.context = new RubyHandlerContext(entityRepo, includedFileLocator, executorService, inferer, parserCreator);
|
||||
expressionUsage = new ExpressionUsage(context, entityRepo, helper, inferer);
|
||||
ExecutorService executorService, IBindingResolver bindingResolver, ParserCreator parserCreator) {
|
||||
this.context = new RubyHandlerContext(entityRepo, includedFileLocator, executorService, bindingResolver, parserCreator);
|
||||
expressionUsage = new ExpressionUsage(context, entityRepo, helper, bindingResolver);
|
||||
context.startFile(fileFullPath);
|
||||
|
||||
}
|
||||
|
|
|
@ -23,12 +23,10 @@ SOFTWARE.
|
|||
*/
|
||||
|
||||
package depends.relations;
|
||||
|
||||
import depends.entity.*;
|
||||
import depends.entity.repo.BuiltInType;
|
||||
import depends.entity.repo.EntityRepo;
|
||||
import depends.entity.repo.NullBuiltInType;
|
||||
import depends.extractor.AbstractLangProcessor;
|
||||
import depends.extractor.UnsolvedBindings;
|
||||
import depends.importtypes.Import;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -37,7 +35,7 @@ import org.slf4j.LoggerFactory;
|
|||
import java.lang.management.ManagementFactory;
|
||||
import java.util.*;
|
||||
|
||||
public class Inferer {
|
||||
public class BindingResolver implements IBindingResolver{
|
||||
|
||||
private BuiltInType buildInTypeManager = new NullBuiltInType();
|
||||
private ImportLookupStrategy importLookupStrategy;
|
||||
|
@ -47,31 +45,26 @@ public class Inferer {
|
|||
private boolean eagerExpressionResolve = false;
|
||||
private boolean isCollectUnsolvedBindings = false;
|
||||
private boolean isDuckTypingDeduce = true;
|
||||
private static Logger logger = LoggerFactory.getLogger(Inferer.class);
|
||||
private static Logger logger = LoggerFactory.getLogger(IBindingResolver.class);
|
||||
|
||||
public Inferer(EntityRepo repo, ImportLookupStrategy importLookupStrategy, BuiltInType buildInTypeManager,
|
||||
boolean isCollectUnsolvedBindings, boolean isDuckTypingDeduce) {
|
||||
public BindingResolver(EntityRepo repo, ImportLookupStrategy importLookupStrategy, BuiltInType buildInTypeManager,
|
||||
boolean isCollectUnsolvedBindings, boolean isDuckTypingDeduce) {
|
||||
this.repo = repo;
|
||||
this.importLookupStrategy = importLookupStrategy;
|
||||
this.buildInTypeManager = buildInTypeManager;
|
||||
this.isCollectUnsolvedBindings = isCollectUnsolvedBindings;
|
||||
this.isDuckTypingDeduce = isDuckTypingDeduce;
|
||||
unsolvedSymbols= new HashSet<>();
|
||||
importLookupStrategy.setInferer(this);
|
||||
importLookupStrategy.setBindingResolver(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve all bindings
|
||||
* - Firstly, we resolve all types from there names.
|
||||
* - Secondly, we resolve all expressions (expression will use type infomation of previous step
|
||||
* @param langProcessor
|
||||
*/
|
||||
public Set<UnsolvedBindings> resolveAllBindings(AbstractLangProcessor langProcessor) {
|
||||
@Override
|
||||
public Set<UnsolvedBindings> resolveAllBindings(boolean isEagerExpressionResolve) {
|
||||
System.out.println("Resolve type bindings....");
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Resolve type bindings...");
|
||||
}
|
||||
resolveTypes(langProcessor.isEagerExpressionResolve());
|
||||
resolveTypes(isEagerExpressionResolve);
|
||||
System.out.println("Dependency analaysing....");
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Dependency analaysing...");
|
||||
|
@ -90,26 +83,13 @@ public class Inferer {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* For types start with the prefix, it will be treated as built-in type
|
||||
* For example, java.io.* in Java, or __ in C/C++
|
||||
* @param prefix
|
||||
* @return
|
||||
*/
|
||||
public boolean isBuiltInTypePrefix(String prefix) {
|
||||
return buildInTypeManager.isBuiltInTypePrefix(prefix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Different languages have different strategy on how to compute the imported types
|
||||
* and the imported files.
|
||||
* For example, in C/C++, both imported types (using namespace, using <type>) and imported files exists.
|
||||
* while in java, only 'import class/function, or import wildcard class.* package.* exists.
|
||||
*/
|
||||
|
||||
@Override
|
||||
public Collection<Entity> getImportedRelationEntities(List<Import> importedNames) {
|
||||
return importLookupStrategy.getImportedRelationEntities(importedNames);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Entity> getImportedTypes(List<Import> importedNames, FileEntity fileEntity) {
|
||||
HashSet<UnsolvedBindings> unsolved = new HashSet<UnsolvedBindings>();
|
||||
Collection<Entity> result = importLookupStrategy.getImportedTypes(importedNames,unsolved);
|
||||
|
@ -124,22 +104,13 @@ public class Inferer {
|
|||
if (!isCollectUnsolvedBindings) return;
|
||||
this.unsolvedSymbols.add(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Entity> getImportedFiles(List<Import> importedNames) {
|
||||
return importLookupStrategy.getImportedFiles(importedNames);
|
||||
}
|
||||
|
||||
/**
|
||||
* By given raw name, to infer the type of the name
|
||||
* for example
|
||||
* (It is just a wrapper of resolve name)
|
||||
* if it is a class, the class is the type
|
||||
* if it is a function, the return type is the type
|
||||
* if it is a variable, type of variable is the type
|
||||
* @param fromEntity
|
||||
* @param rawName
|
||||
* @return
|
||||
*/
|
||||
|
||||
@Override
|
||||
public TypeEntity inferTypeFromName(Entity fromEntity, GenericName rawName) {
|
||||
Entity data = resolveName(fromEntity, rawName, true);
|
||||
if (data == null)
|
||||
|
@ -147,13 +118,8 @@ public class Inferer {
|
|||
return data.getType();
|
||||
}
|
||||
|
||||
/**
|
||||
* By given raw name, to infer the entity of the name
|
||||
* @param fromEntity
|
||||
* @param rawName
|
||||
* @param searchImport
|
||||
* @return
|
||||
*/
|
||||
|
||||
@Override
|
||||
public Entity resolveName(Entity fromEntity, GenericName rawName, boolean searchImport) {
|
||||
if (rawName==null) return null;
|
||||
Entity entity = resolveNameInternal(fromEntity,rawName,searchImport);
|
||||
|
@ -262,6 +228,7 @@ public class Inferer {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity lookupTypeInImported(FileEntity fileEntity, String name) {
|
||||
if (fileEntity == null)
|
||||
return null;
|
||||
|
@ -290,13 +257,8 @@ public class Inferer {
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deduce type based on function calls
|
||||
* If the function call is a subset of a type, then the type could be a candidate of the var's type
|
||||
* @param fromEntity
|
||||
* @param functionCalls
|
||||
* @return
|
||||
*/
|
||||
|
||||
@Override
|
||||
public List<TypeEntity> calculateCandidateTypes(VarEntity fromEntity, List<FunctionCall> functionCalls) {
|
||||
if (buildInTypeManager.isBuildInTypeMethods(functionCalls)) {
|
||||
return new ArrayList<>();
|
||||
|
@ -323,16 +285,14 @@ public class Inferer {
|
|||
return types;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEagerExpressionResolve() {
|
||||
return eagerExpressionResolve;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public EntityRepo getRepo() {
|
||||
return repo;
|
||||
}
|
||||
|
||||
public void setCollectUnsolvedBindings(boolean isCollectUnsolvedBindings) {
|
||||
this.isCollectUnsolvedBindings = isCollectUnsolvedBindings;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
package depends.relations;
|
||||
|
||||
import depends.entity.*;
|
||||
import depends.entity.repo.EntityRepo;
|
||||
import depends.extractor.UnsolvedBindings;
|
||||
import depends.importtypes.Import;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public interface IBindingResolver {
|
||||
/**
|
||||
* Resolve all bindings
|
||||
* - Firstly, we resolve all types from there names.
|
||||
* - Secondly, we resolve all expressions (expression will use type infomation of previous step
|
||||
*/
|
||||
Set<UnsolvedBindings> resolveAllBindings(boolean isEagerExpressionResolve);
|
||||
|
||||
/**
|
||||
* Different languages have different strategy on how to compute the imported types
|
||||
* and the imported files.
|
||||
* For example, in C/C++, both imported types (using namespace, using <type>) and imported files exists.
|
||||
* while in java, only 'import class/function, or import wildcard class.* package.* exists.
|
||||
*/
|
||||
Collection<Entity> getImportedRelationEntities(List<Import> importedNames);
|
||||
|
||||
Collection<Entity> getImportedTypes(List<Import> importedNames, FileEntity fileEntity);
|
||||
|
||||
Collection<Entity> getImportedFiles(List<Import> importedNames);
|
||||
|
||||
/**
|
||||
* By given raw name, to infer the type of the name
|
||||
* for example
|
||||
* (It is just a wrapper of resolve name)
|
||||
* if it is a class, the class is the type
|
||||
* if it is a function, the return type is the type
|
||||
* if it is a variable, type of variable is the type
|
||||
* @param fromEntity
|
||||
* @param rawName
|
||||
* @return
|
||||
*/
|
||||
TypeEntity inferTypeFromName(Entity fromEntity, GenericName rawName);
|
||||
|
||||
/**
|
||||
* By given raw name, to infer the entity of the name
|
||||
* @param fromEntity
|
||||
* @param rawName
|
||||
* @param searchImport
|
||||
* @return
|
||||
*/
|
||||
Entity resolveName(Entity fromEntity, GenericName rawName, boolean searchImport);
|
||||
|
||||
Entity lookupTypeInImported(FileEntity fileEntity, String name);
|
||||
|
||||
/**
|
||||
* Deduce type based on function calls
|
||||
* If the function call is a subset of a type, then the type could be a candidate of the var's type
|
||||
* @param fromEntity
|
||||
* @param functionCalls
|
||||
* @return
|
||||
*/
|
||||
List<TypeEntity> calculateCandidateTypes(VarEntity fromEntity, List<FunctionCall> functionCalls);
|
||||
|
||||
boolean isEagerExpressionResolve();
|
||||
|
||||
EntityRepo getRepo();
|
||||
}
|
|
@ -40,8 +40,6 @@ public abstract class ImportLookupStrategy {
|
|||
*
|
||||
* @param name - the entity name
|
||||
* @param fileEntity - the current file
|
||||
* @param repo - the whole entity repo, which could be used when necessary
|
||||
* @param inferer - the inferer object, which could be used when necessary
|
||||
* @return the founded entity, or null if not found.
|
||||
*/
|
||||
public abstract Entity lookupImportedType(String name, FileEntity fileEntity);
|
||||
|
@ -51,7 +49,6 @@ public abstract class ImportLookupStrategy {
|
|||
* In C/CPP, it is calculated by the file name
|
||||
* In Java, it is calculated by the imported types
|
||||
* @param importedNames - the original name of the import relation
|
||||
* @param repo - entity repo
|
||||
* @return the corresponding entities related with importedNames
|
||||
*/
|
||||
public abstract Collection<Entity> getImportedRelationEntities(List<Import> importedNames);
|
||||
|
@ -59,7 +56,6 @@ public abstract class ImportLookupStrategy {
|
|||
/**
|
||||
* The types been imported
|
||||
* @param importedNames
|
||||
* @param repo
|
||||
* @return
|
||||
*/
|
||||
public abstract Collection<Entity> getImportedTypes(List<Import> importedNames,Set<UnsolvedBindings> unsolvedSymbols);
|
||||
|
@ -67,7 +63,6 @@ public abstract class ImportLookupStrategy {
|
|||
/**
|
||||
* The files been imported
|
||||
* @param importedNames
|
||||
* @param repo
|
||||
* @return
|
||||
*/
|
||||
public abstract Collection<Entity> getImportedFiles(List<Import> importedNames);
|
||||
|
@ -78,12 +73,12 @@ public abstract class ImportLookupStrategy {
|
|||
*/
|
||||
public abstract boolean supportGlobalNameLookup();
|
||||
|
||||
public void setInferer(Inferer inferer){
|
||||
this.inferer = inferer;
|
||||
public void setBindingResolver(IBindingResolver bindingResolver){
|
||||
this.bindingResolver = bindingResolver;
|
||||
}
|
||||
public ImportLookupStrategy(EntityRepo repo){
|
||||
this.repo = repo;
|
||||
}
|
||||
protected EntityRepo repo;
|
||||
protected Inferer inferer;
|
||||
protected IBindingResolver bindingResolver;
|
||||
}
|
||||
|
|
|
@ -36,14 +36,14 @@ import java.util.stream.Collectors;
|
|||
public class RelationCounter {
|
||||
|
||||
private Collection<Entity> entities;
|
||||
private Inferer inferer;
|
||||
private IBindingResolver bindingResolver;
|
||||
private EntityRepo repo;
|
||||
private boolean callAsImpl;
|
||||
private AbstractLangProcessor langProcessor;
|
||||
|
||||
public RelationCounter( EntityRepo repo, boolean callAsImpl, AbstractLangProcessor langProcessor,Inferer inferer) {
|
||||
public RelationCounter(EntityRepo repo, boolean callAsImpl, AbstractLangProcessor langProcessor, IBindingResolver bindingResolver) {
|
||||
this.entities = repo.getFileEntities();
|
||||
this.inferer = inferer;
|
||||
this.bindingResolver = bindingResolver;
|
||||
this.repo = repo;
|
||||
this.callAsImpl = callAsImpl;
|
||||
this.langProcessor = langProcessor;
|
||||
|
@ -93,9 +93,9 @@ public class RelationCounter {
|
|||
}
|
||||
|
||||
entity.reloadExpression(repo);
|
||||
if (!inferer.isEagerExpressionResolve())
|
||||
if (!bindingResolver.isEagerExpressionResolve())
|
||||
{
|
||||
entity.resolveExpressions(inferer);
|
||||
entity.resolveExpressions(bindingResolver);
|
||||
}
|
||||
for (Expression expression:entity.expressionList()){
|
||||
if (expression.isStatement()) {
|
||||
|
|
|
@ -5,7 +5,8 @@ import depends.entity.Entity;
|
|||
import depends.entity.FunctionEntity;
|
||||
import depends.entity.VarEntity;
|
||||
import depends.entity.repo.EntityRepo;
|
||||
import depends.relations.Inferer;
|
||||
import depends.relations.BindingResolver;
|
||||
import depends.relations.IBindingResolver;
|
||||
import depends.relations.Relation;
|
||||
import depends.relations.RelationCounter;
|
||||
import multilang.depends.util.file.TemporaryFile;
|
||||
|
@ -18,32 +19,32 @@ import static org.junit.Assert.fail;
|
|||
|
||||
public abstract class ParserTest {
|
||||
protected EntityRepo entityRepo ;
|
||||
protected Inferer inferer ;
|
||||
protected IBindingResolver bindingResolver;
|
||||
protected AbstractLangProcessor langProcessor;
|
||||
|
||||
protected void init(){
|
||||
entityRepo = langProcessor.getEntityRepo();
|
||||
inferer = new Inferer(langProcessor.getEntityRepo(),langProcessor.getImportLookupStrategy(),langProcessor.getBuiltInType(),false,false);
|
||||
langProcessor.inferer = inferer;
|
||||
bindingResolver = new BindingResolver(langProcessor.getEntityRepo(),langProcessor.getImportLookupStrategy(),langProcessor.getBuiltInType(),true,false);
|
||||
langProcessor.bindingResolver = bindingResolver;
|
||||
TemporaryFile.reset();
|
||||
}
|
||||
|
||||
protected void init(boolean duckTypingDeduce){
|
||||
entityRepo = langProcessor.getEntityRepo();
|
||||
inferer = new Inferer(langProcessor.getEntityRepo(),langProcessor.getImportLookupStrategy(),langProcessor.getBuiltInType(),false,duckTypingDeduce);
|
||||
langProcessor.inferer = inferer;
|
||||
bindingResolver = new BindingResolver(langProcessor.getEntityRepo(),langProcessor.getImportLookupStrategy(),langProcessor.getBuiltInType(),false,duckTypingDeduce);
|
||||
langProcessor.bindingResolver = bindingResolver;
|
||||
TemporaryFile.reset();
|
||||
}
|
||||
|
||||
public Set<UnsolvedBindings> resolveAllBindings() {
|
||||
Set<UnsolvedBindings> result = inferer.resolveAllBindings(langProcessor);
|
||||
new RelationCounter(entityRepo,false,langProcessor,inferer).computeRelations();
|
||||
Set<UnsolvedBindings> result = bindingResolver.resolveAllBindings(langProcessor.isEagerExpressionResolve());
|
||||
new RelationCounter(entityRepo,false,langProcessor, bindingResolver).computeRelations();
|
||||
return result;
|
||||
}
|
||||
|
||||
protected Set<UnsolvedBindings> resolveAllBindings(boolean callAsImpl) {
|
||||
Set<UnsolvedBindings> result = inferer.resolveAllBindings(langProcessor);
|
||||
new RelationCounter(entityRepo,callAsImpl,langProcessor,inferer).computeRelations();
|
||||
Set<UnsolvedBindings> result = bindingResolver.resolveAllBindings(langProcessor.isEagerExpressionResolve());
|
||||
new RelationCounter(entityRepo,callAsImpl,langProcessor, bindingResolver).computeRelations();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,6 @@ public abstract class CppParserTest extends ParserTest{
|
|||
}
|
||||
|
||||
public CppFileParser createParser(String src) {
|
||||
return new CdtCppFileParser(src, entityRepo, preprocessorHandler,inferer,macroRepo );
|
||||
return new CdtCppFileParser(src, entityRepo, preprocessorHandler, bindingResolver,macroRepo );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ public abstract class GolangParserTest extends ParserTest{
|
|||
}
|
||||
|
||||
public GoFileParser createParser(String src) {
|
||||
return new GoFileParser(src,entityRepo, inferer);
|
||||
return new GoFileParser(src,entityRepo, bindingResolver);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,6 +9,6 @@ public abstract class JavaParserTest extends ParserTest{
|
|||
}
|
||||
|
||||
public JavaFileParser createParser(String src) {
|
||||
return new JavaFileParser(src,entityRepo, inferer);
|
||||
return new JavaFileParser(src,entityRepo, bindingResolver);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ public class UnsolvedSymbolsTest extends JavaParserTest {
|
|||
String src = "./src/test/resources/java-code-examples/UnsolvedSymbols/MissingImport.java";
|
||||
JavaFileParser parser = createParser(src);
|
||||
parser.parse();
|
||||
inferer.setCollectUnsolvedBindings(true);
|
||||
Set<UnsolvedBindings> missing = resolveAllBindings();
|
||||
assertEquals(1,missing.size());
|
||||
assertEquals("a.b",missing.iterator().next().getRawName());
|
||||
|
|
|
@ -11,7 +11,6 @@ import depends.entity.FunctionEntity;
|
|||
import depends.entity.TypeEntity;
|
||||
import depends.entity.VarEntity;
|
||||
import depends.extractor.FileParser;
|
||||
import depends.relations.Inferer;
|
||||
|
||||
public class RubyAssignedVariableTypeDedudceTest extends RubyParserTest {
|
||||
@Before
|
||||
|
|
|
@ -9,7 +9,7 @@ import depends.deptypes.DependencyType;
|
|||
import depends.entity.FunctionEntity;
|
||||
import depends.extractor.FileParser;
|
||||
|
||||
public class RubyNameInfererTest extends RubyParserTest {
|
||||
public class RubyNameIBindingResolverTest extends RubyParserTest {
|
||||
@Before
|
||||
public void setUp() {
|
||||
super.init();
|
|
@ -17,7 +17,7 @@ public abstract class RubyParserTest extends ParserTest implements ParserCreator
|
|||
|
||||
public FileParser createFileParser(String src) {
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
return new JRubyFileParser(src,entityRepo, executor,new IncludedFileLocator(includePaths()), inferer, this);
|
||||
return new JRubyFileParser(src,entityRepo, executor,new IncludedFileLocator(includePaths()), bindingResolver, this);
|
||||
}
|
||||
|
||||
private List<String> includePaths() {
|
||||
|
|
Loading…
Reference in New Issue