diff --git a/src/main/java/complexityparser/types/Operator.java b/src/main/java/complexityparser/types/FOTierList.java similarity index 66% rename from src/main/java/complexityparser/types/Operator.java rename to src/main/java/complexityparser/types/FOTierList.java index 17ce37599c2db49f6d8eedfffa7ba835c8852a8f..f48a72720f2c7bdc6f2fbaa97fe9993e3c0733b8 100644 --- a/src/main/java/complexityparser/types/Operator.java +++ b/src/main/java/complexityparser/types/FOTierList.java @@ -25,19 +25,20 @@ import complexityparser.types.env.TypingEnv; /** - * Represents the admissible first order tiers of an operator, constructor, or method. + * Represents the list of admissible first order tiers (FOTier) of an operator, constructor, or method. + * The boolean #primitiveReturnType is true if the return type is a primitive type and false if it is a reference type. */ -public class Operator { +public class FOTierList { private ArrayList<FOTier> results; private int arity; private boolean primitiveReturnType; /** - * Creates a new admissible tier types for an operator. + * Creates a new FOTierList. * Empty by default. - * The arity being fixed to -1 indicating that the operator admissible tier types has not been set. + * The arity being fixed to -1 indicating that the FOTierList has not been set yet. */ - public Operator(boolean primitiveReturnType) { + public FOTierList(boolean primitiveReturnType) { results = new ArrayList<>(); arity = -1; this.primitiveReturnType = primitiveReturnType; @@ -45,16 +46,17 @@ public class Operator { /** * - * @return true if this operator returns a primitive type, false otherwise. + * @return true if the return type is a primitive type, false otherwise. */ public boolean isPrimitiveReturnType() { return primitiveReturnType; } /** - * Adds an input to the current operator and sets the arity (or checks for corresponding arity) - * @param res - the output tier - * @param p - the input tiers + * Adds a FOTier to the current FOTierList and sets the arity (or checks for a coherent arity). + * @param out - the output tier . + * @param env - the environment tier. + * @param in - the input tiers. * @throws IOException */ public void add(Tier out, Tier env, Tier... in) throws IOException { @@ -62,23 +64,23 @@ public class Operator { arity = in.length; } if(arity != in.length) { - //If the cardinality of the input tiers given as paramater is distinct from the operator arity - //then an exception is thrown. - throw new IOException("Operator::addObserver input of wrong size expected " + arity + " got " + in.length); + //If the cardinality of the input tiers given as paramater is distinct + //from the FOTierList arity then an exception is thrown. + throw new IOException("FOTierList::addObserver input of wrong size expected " + arity + " got " + in.length); } results.add(new FOTier(out,env,in)); } /** - * Removes the input tier at index i. - * @param i - the index to remove. + * Removes the FOTier at index i. + * @param i - the index of the FOTier to remove. */ public void remove(int i) { results.remove(i); } /** - * @return the number of input tiers of the operator. + * @return the number of FOTiers in the FOTierList. */ public int size() { return results.size(); @@ -86,8 +88,8 @@ public class Operator { /** * - * @param i - the index to get. - * @return the first order tier of index i. + * @param i - the index of the FOTier to get. + * @return the FOTier of index i. */ public FOTier get(int i) { return results.get(i); @@ -96,7 +98,7 @@ public class Operator { /** * * @param in - input tiers. - * @return the output tier matching the given input tiers in and (NONE, NONE), if no match is found. + * @return the (first) FOTier matching the given input tiers #in and (NONE, NONE), if no match is found. */ public FOTier findRes(Tier... in) { for(FOTier i : results) { @@ -111,14 +113,14 @@ public class Operator { * * @param m - a mask. * @param in - input tiers. - * @return a compatible output marching the input tiers in and the mask m, (NONE, NONE) if no match is found. + * @return a compatible FOTier marching the input tiers #in and the mask #m, (NONE, NONE) if no match is found. */ public FOTier findCompatibleRes(Mask m, Tier... in) { for(FOTier i : results) { if(i.isCompatibleWith(m, in)) { - //the array is deep copied to avoid any unwanted side effect - //and to provide another possible returned value (the current input tiers instead of the parameter input tiers, - //both being compatible) + //The array is deep copied to avoid any unwanted side effect + //and to provide another possible returned value + //(the current input tiers instead of the parameter input tiers, both being compatible). System.arraycopy(i.getIn(), 0, in, 0, in.length); return i; } @@ -130,7 +132,7 @@ public class Operator { * * @param m - a mask. * @param in - input tiers. - * @return all the compatible inputs of the operator. + * @return an array of FOTiers of the FOTierList compatible with the input parameter. */ public FOTier[] findAllCompatibles(Mask m, Tier... in) { ArrayList<FOTier> res = new ArrayList<>(results.size()); diff --git a/src/main/java/complexityparser/types/Tier.java b/src/main/java/complexityparser/types/Tier.java index 5f4aa230f711fb7d2779256d3f72ab2cac3e6e07..2e2ba03ab8c273bd96bd36691beb71d5ba37bcf3 100644 --- a/src/main/java/complexityparser/types/Tier.java +++ b/src/main/java/complexityparser/types/Tier.java @@ -43,7 +43,7 @@ public enum Tier { /** * - * @param t : several tiers. + * @param t - several tiers. * @return the minimum of the tiers under the precedence NONE<T0<T1. */ public static Tier min(Tier... t) { @@ -117,7 +117,7 @@ public enum Tier { /** * * @param value - a string. - * @return a tier built from the string in paramater. + * @return a tier built from the string parameter. */ public static Tier fromString(String value) { Tier res = Tier.None; diff --git a/src/main/java/complexityparser/types/env/OperatorTypingEnvBuilder.java b/src/main/java/complexityparser/types/env/OperatorTypingEnvBuilder.java index 8d539402ec48d76b1f80413c3548b1035171d462..40e36fbe987aa79433c612160459f84a3b006ed4 100644 --- a/src/main/java/complexityparser/types/env/OperatorTypingEnvBuilder.java +++ b/src/main/java/complexityparser/types/env/OperatorTypingEnvBuilder.java @@ -21,24 +21,24 @@ import java.io.IOException; import java.util.List; import complexityparser.types.Tier; import complexityparser.types.FOTier; -import complexityparser.types.Operator; +import complexityparser.types.FOTierList; /** - * This class is only used to load the configuration file operators.config containing a description of - * the operators admissible first order tiers. + * This class is only used to load the configuration file operators.config containing a description (FOTierList) of + * the operators admissible FOTiers. */ public class OperatorTypingEnvBuilder extends OperatorsBaseListener { private TypingEnv te = new TypingEnv(); - private Operator latest; + private FOTierList latest; public TypingEnv getOp() { return te; } /** - * Creates a new operator, updates the attribute latest, and - * adds the new object with the operators string representation to the Operators op (HashMap). + * Creates a new FOTierList, updates the attribute latest, and + * adds the new object with the operator (or method) name to the TypingEnv #te. * @param ctx - an operator context. */ @Override @@ -47,7 +47,7 @@ public class OperatorTypingEnvBuilder extends OperatorsBaseListener { return; } super.enterOperator(ctx); - latest = new Operator(true); + latest = new FOTierList(true); String opString = ctx.STRING_LITERAL().getText(); opString = opString.substring(1, opString.length() - 1); te.add(opString, latest); diff --git a/src/main/java/complexityparser/types/env/TypingEnv.java b/src/main/java/complexityparser/types/env/TypingEnv.java index e88116bb443a813d1d74cf76ef966767b3a26520..4b502db5b8c9d045900f0acae5618e4a391742b4 100644 --- a/src/main/java/complexityparser/types/env/TypingEnv.java +++ b/src/main/java/complexityparser/types/env/TypingEnv.java @@ -18,7 +18,7 @@ package complexityparser.types.env; import complexityparser.types.Tier; import complexityparser.types.FOTier; -import complexityparser.types.Operator; +import complexityparser.types.FOTierList; import complexityparser.tos.TOS; import lib.Mask; import org.antlr.v4.runtime.CharStream; @@ -35,12 +35,12 @@ import java.util.HashMap; import java.util.Map; /** * A singleton class encoding typing environments. -* A hashmap relating an operation (operator, method, ...) name to the corresponding operator. -* (An operator has an attribute results of type ArrayList<FOTier> containing an arraylist of admissible FOTier). +* A hashmap relating an operation (operator, method, ...) namespace to the corresponding operator. +* (An operator has an attribute #results of type ArrayList<FOTier> containing an arraylist of admissible FOTier). */ public class TypingEnv { private static TypingEnv instance = null; - private HashMap<String, Operator> env; + private HashMap<String, FOTierList> env; protected TypingEnv() { env = new HashMap<>(); @@ -63,7 +63,7 @@ public class TypingEnv { */ public void clear() { ArrayList<String> keys = new ArrayList<>(); - for(Map.Entry<String, Operator> entry : env.entrySet()) { + for(Map.Entry<String, FOTierList> entry : env.entrySet()) { if(entry.getKey().contains("<root>")) { keys.add(entry.getKey()); } @@ -82,82 +82,82 @@ public class TypingEnv { } /** - * Adds an operator and a name to the typing environment. + * Adds a FOTierList and a name to the typing environment. * @param k - a name. * @param o - an operator. */ - public void add(String k, Operator o) { + public void add(String k, FOTierList o) { env.put(k, o); } /** * - * @param r - a name. + * @param name - a namespace. * @param in - input tiers. - * @return an output tier matching an given operator namespace and input tiers given as parameters. - * A default output tier (None) if no match is found. + * @return a FOTier matching a namespace and input tiers given as parameters. + * A default FOTier if no match is found. */ - public FOTier findRes(String r, Tier... in) { - if(env.containsKey(r)) { - return env.get(r).findRes(in); + public FOTier findRes(String name, Tier... in) { + if(env.containsKey(name)) { + return env.get(name).findRes(in); } return new FOTier(Tier.None, Tier.None, new Tier[0]); } /** * - * @param r - a name. + * @param name - a name. * @param m - a mask. * @param in - input tiers. - * @return a compatible FOTier matching a namespace, a mask, and input tiers. + * @return a FOTier matching a namespace, a mask, and input tiers. * A default FOTier if no match is found. */ - public FOTier findCompatibleIn(String r, Mask m, Tier... in) { - if(env.containsKey(r)) { - return env.get(r).findCompatibleRes(m, in); + public FOTier findCompatibleIn(String name, Mask m, Tier... in) { + if(env.containsKey(name)) { + return env.get(name).findCompatibleRes(m, in); } return new FOTier(Tier.None, Tier.None,new Tier[0]); } /** - * The behaviour is different from #findRes(String r, Tier... in): + * The behaviour is different from #findRes(String name, Tier... in): * Additional checks are performed on overriden methods. - * @param r - a name. + * @param name - a namespace. * @param in - input tiers. * @return the FOTier matching a method namespace and input tiers. */ - public FOTier findMethod(String r, Tier... in) { + public FOTier findMethod(String name, Tier... in) { FOTier res = null; TOS tos = TOS.getInstance(); - while (!r.contains("<root>::Object::") && !env.containsKey(r)) { - r = tos.getParentNamespace(r); + while (!name.contains("<root>::Object::") && !env.containsKey(name)) { + name = tos.getParentNamespace(name); } - //If the namespace is of the form <root>::Object:: then the method has not been found in the class hierarchy. - if(!r.contains("<root>::Object::") && env.containsKey(r)) { - res = env.get(r).findRes(in); - res = checkOverrideMethod(r, res, in); + //If the namespace is of the form "<root>::Object::..." then the method has not been found in the class hierarchy. + if(!name.contains("<root>::Object::") && env.containsKey(name)) { + res = env.get(name).findRes(in); + res = checkOverrideMethod(name, res, in); } return res; } /** - * The behaviour is different from #findCompatibleIn(String r, Mask m, Tier... in): + * The behaviour is different from #findCompatibleIn(String name, Mask m, Tier... in): * Additional checks are performed on overriden methods. - * @param r - a name. + * @param name - a name. * @param m - a mask. * @param in - input tiers. * @return a compatible FOTier matching a method namespace, mask, and input tiers. */ - public FOTier findCompatibleMethod(String r, Mask m, Tier... in) { + public FOTier findCompatibleMethod(String name, Mask m, Tier... in) { TOS tos = TOS.getInstance(); - while (!r.contains("<root>::Object::") && !env.containsKey(r)) { - r = tos.getParentNamespace(r); + while (!name.contains("<root>::Object::") && !env.containsKey(name)) { + name = tos.getParentNamespace(name); } - if(!r.contains("<root>::Object") && env.containsKey(r)) { - FOTier[] res = env.get(r).findAllCompatibles(m, in); + if(!name.contains("<root>::Object") && env.containsKey(name)) { + FOTier[] res = env.get(name).findAllCompatibles(m, in); for(FOTier i : res) { - FOTier tmp = checkOverrideMethod(r, i, i.getIn()); - if( ! tmp.equals(new FOTier(Tier.None, Tier.None,in))) { + FOTier tmp = checkOverrideMethod(name, i, i.getIn()); + if( ! tmp.equals(new FOTier(Tier.None, Tier.None,new Tier[0]))) { return tmp; } } @@ -169,29 +169,29 @@ public class TypingEnv { * Methods returning a primitive type do not need to return exactly the same tier. * Methods returning reference type need to preserve exactly the tier. * The check will be performed on every subclass to handle method overrides. - * @param r - a name. + * @param name - a namespace. * @param out - a FOTier. * @param in - input tiers. - * @return a FOTier matching the inputs. A default output tier if there is no match. + * @return a FOTier matching the input parameters. A default FOTier if there is no match. */ - public FOTier checkOverrideMethod(String r, FOTier out, Tier... in) { + public FOTier checkOverrideMethod(String name, FOTier out, Tier... in) { TOS tos = TOS.getInstance(); - //Only the children need to be verified since no superclass can be used in case of polymorphism. - return checkOverrideMethod_aux(r, out, in); + //Only the children needs to be verified since no superclass can be used in case of polymorphism. + return checkOverrideMethod_aux(name, out, in); } /** * A recursive algorithm to check the if the method of namespace, input tiers, and FOTier are compatible with * the class hierarchy. - * @param r - a namespace. + * @param name - a namespace. * @param out - a FOTier. * @param in - input tiers. * @return a FOTier matching the inputs. A default FOTier if there is no match. */ - private FOTier checkOverrideMethod_aux(String r, FOTier out, Tier... in) { + private FOTier checkOverrideMethod_aux(String name, FOTier out, Tier... in) { FOTier res = new FOTier(out.getOut(),out.getEnv(),in); - if(env.containsKey(r)) { - FOTier tmp = env.get(r).findRes(in); + if(env.containsKey(name)) { + FOTier tmp = env.get(name).findRes(in); /* The method return type has to be typed by considering possible method overrides: --if the return type is a primitive type: the output tier is the minimum of input tiers; @@ -199,7 +199,7 @@ public class TypingEnv { The environment tier is the maximum of the input tiers. */ res.setEnv(Tier.max(tmp.getEnv(), out.getEnv())); - if(env.get(r).isPrimitiveReturnType()) { + if(env.get(name).isPrimitiveReturnType()) { res.setOut(Tier.min(tmp.getOut(), out.getOut())); } else { @@ -209,12 +209,12 @@ public class TypingEnv { } } TOS tos = TOS.getInstance(); - String[] children = tos.getChildrenNamespaces(r); + String[] children = tos.getChildrenNamespaces(name); if(children != null) { for (int i = 0; i < children.length; i++) { FOTier tmp = checkOverrideMethod_aux(children[i], res, in); res.setEnv(Tier.max(tmp.getEnv(), out.getEnv())); - if(env.get(r).isPrimitiveReturnType()) { + if(env.get(name).isPrimitiveReturnType()) { res.setOut(Tier.min(tmp.getOut(), out.getOut())); } else { @@ -259,14 +259,14 @@ public class TypingEnv { * @param namespace - a namespace. * @return the operator associated with the given namespace. */ - public Operator get(String namespace) { + public FOTierList get(String namespace) { return env.get(namespace); } @Override public String toString() { StringBuilder str = new StringBuilder(); - for(Map.Entry<String, Operator> e : env.entrySet()) { + for(Map.Entry<String, FOTierList> e : env.entrySet()) { str.append("\""); str.append(e.getKey()); str.append("\" {\n"); diff --git a/src/main/java/complexityparser/typingVisitors/FinalPass.java b/src/main/java/complexityparser/typingVisitors/FinalPass.java index 39f54e4626dcc4f2a84725bd271350f373cbc697..603feb4552a05c865cf3ebec622ac539bbf2459a 100644 --- a/src/main/java/complexityparser/typingVisitors/FinalPass.java +++ b/src/main/java/complexityparser/typingVisitors/FinalPass.java @@ -20,15 +20,15 @@ package complexityparser.typingVisitors; import complexityparser.analyse.antlr.JavaParser; import complexityparser.listeners.TOSBuilder; import complexityparser.listeners.TypingListener; -import complexityparser.types.Operator; +import complexityparser.types.FOTierList; import complexityparser.types.FOTier; import complexityparser.types.Tier; import complexityparser.typingVisitors.base.ObjectVisitor; import org.antlr.v4.runtime.CommonTokenStream; /** - * Performs a final pass on the tree, checks the constructors and generates a string outpout for the method declarations - * (the first and second passes do not generate any string output) + * Performs a final pass on the tree, checks the constructors and generates a string output for the method declarations + * (the first and second passes do not generate any string output). */ public class FinalPass extends ObjectVisitor { @@ -82,7 +82,7 @@ public class FinalPass extends ObjectVisitor { if(ctx.formalParameters().formalParameterList() != null) { nbParam = ctx.formalParameters().formalParameterList().formalParameter().size(); } - Operator op = te.get(namespace); + FOTierList op = te.get(namespace); if(op.size() == 0) { putTierType(ctx, Tier.None, Tier.None); } @@ -92,4 +92,4 @@ public class FinalPass extends ObjectVisitor { } return null; } -} +} \ No newline at end of file diff --git a/src/main/java/complexityparser/typingVisitors/FirstPass.java b/src/main/java/complexityparser/typingVisitors/FirstPass.java index 51cfa9257f52d891fe3b6d32c6353c975bb9ee7a..1e6673f414fde77af4157af4c725868f05dba175 100644 --- a/src/main/java/complexityparser/typingVisitors/FirstPass.java +++ b/src/main/java/complexityparser/typingVisitors/FirstPass.java @@ -20,7 +20,7 @@ import complexityparser.analyse.antlr.JavaParser; import complexityparser.listeners.TOSBuilder; import complexityparser.listeners.TypingListener; import complexityparser.types.Tier; -import complexityparser.types.Operator; +import complexityparser.types.FOTierList; import complexityparser.types.FOTier; import complexityparser.types.TierArray; import complexityparser.typingVisitors.base.ObjectVisitor; @@ -30,9 +30,10 @@ import java.io.IOException; import java.util.HashSet; /** - * The first pass of type inference. In the first pass, all valid types are built and entered in the operators table (visitMethodDeclaration). - * The incorrect types will be removed during the second pass. - * The constructors are only checked at the final pass (there is no need to check them earlier especially if they + * The first pass of type inference. During this pass, all valid FOtiers are built and entered in the typing environment + * (using the method #visitMethodDeclaration). + * The incorrect FOtiers will be removed during the second pass. + * The constructors FOtiers are only checked at the final pass (there is no need to check them earlier especially if they * contain method calls that are valid now but may not be valid after the second pass). */ public class FirstPass extends ObjectVisitor { @@ -59,14 +60,14 @@ public class FirstPass extends ObjectVisitor { String type = getType(ctx.methodBody().block().expression()); isPrimitiveReturnType = type.equals("int") || type.equals("boolean"); } - Operator op = new Operator(isPrimitiveReturnType); + FOTierList op = new FOTierList(isPrimitiveReturnType); setOverrideResult(false); TierArray paramTiers = new TierArray(nbParam + 1); int noBloc = getBlockNumber(ctx.methodBody().block()); /* - Builds every possible tier types that can given to the method parameters and checks if they are valid. - If they are valid, they will be added to the operators table. - Recursive methods can be assigned to incorrect types in the first pass. + Builds every possible FOTier types that be can given to the method parameters and checks if they are valid. + If they are valid, they will be added to the typing environment. + Recursive methods can be assigned to incorrect FOtiers in the first pass. This is the reason why a second pass has to be realized (that will loop until a fixpoint has been reached). */ for(int i = 0; i < (1 << paramTiers.size()); i++) { diff --git a/src/main/java/complexityparser/typingVisitors/SecondPass.java b/src/main/java/complexityparser/typingVisitors/SecondPass.java index 6c9080fb55486d3915b1e59c384cc744e3a0f48a..f1a0c17949df3b9057c9e3a16360eb86151e6d04 100644 --- a/src/main/java/complexityparser/typingVisitors/SecondPass.java +++ b/src/main/java/complexityparser/typingVisitors/SecondPass.java @@ -18,7 +18,7 @@ package complexityparser.typingVisitors; import complexityparser.types.Tier; import complexityparser.types.FOTier; -import complexityparser.types.Operator; +import complexityparser.types.FOTierList; import complexityparser.analyse.antlr.JavaParser; import complexityparser.listeners.TOSBuilder; import complexityparser.listeners.TypingListener; @@ -39,9 +39,9 @@ public class SecondPass extends ObjectVisitor { } /** - * As long as the isOperatorModified returns true, it means that methods types have been modified. - * Consequenlty, all the methods that depend on the previous one may not be valid anymore and thus - * they must be analysed again. The second pass continues until a fixpoint has been reached. + * As long as the isOperatorModified returns true, it means that methods FOTiers have been modified. + * Consequenlty, all the methods that (functionnaly) depend on the previous one may not be valid anymore and thus + * they must be analysed again. The second pass is iterated until a fixpoint has been reached. * The worst case will be (NONE, NONE) if no other possibility can be found. */ public void visit() { @@ -53,9 +53,9 @@ public class SecondPass extends ObjectVisitor { } /** - * Handles method declarations by taking the types contained in the operators hashmap and verifying that - * those types are correct and compatible. Removes every type from the operator that is not compatible. - * If none are compatible the method type is set to (NONE, NONE). + * Handles method declarations by taking the FOTiers contained in the typing environment hashmap and verifying that + * those FOTiers are correct and compatible. Removes every FOTier that is not compatible. + * If none are compatible, the FOTier is set to (NONE, NONE). * @param ctx - a method declaration context. * @return the tier of the method body. */ @@ -68,7 +68,7 @@ public class SecondPass extends ObjectVisitor { if(ctx.formalParameters().formalParameterList() != null) { nbParam = ctx.formalParameters().formalParameterList().formalParameter().size(); } - Operator op = te.get(namespace); + FOTierList op = te.get(namespace); setOverrideResult(false); int noBloc = getBlockNumber(ctx.methodBody().block()); int i = 0; diff --git a/src/main/java/complexityparser/typingVisitors/base/BaseBlockStatementVisitor.java b/src/main/java/complexityparser/typingVisitors/base/BaseBlockStatementVisitor.java index 9924619c69c7a6b5d44755192f165367f8558854..60c6d0db403897725184de738e24bc988d863cde 100644 --- a/src/main/java/complexityparser/typingVisitors/base/BaseBlockStatementVisitor.java +++ b/src/main/java/complexityparser/typingVisitors/base/BaseBlockStatementVisitor.java @@ -16,7 +16,6 @@ limitations under the License. package complexityparser.typingVisitors.base; - import complexityparser.analyse.antlr.JavaParser; import complexityparser.listeners.TOSBuilder; import complexityparser.listeners.TypingListener; diff --git a/src/main/java/complexityparser/typingVisitors/base/BaseExpressionVisitor.java b/src/main/java/complexityparser/typingVisitors/base/BaseExpressionVisitor.java index d000e780038aae557966bb813d7c6d939c5b5ae4..9d6df5e66b37b3a4ce6e17d8c2c09e5679786cab 100644 --- a/src/main/java/complexityparser/typingVisitors/base/BaseExpressionVisitor.java +++ b/src/main/java/complexityparser/typingVisitors/base/BaseExpressionVisitor.java @@ -16,7 +16,6 @@ limitations under the License. package complexityparser.typingVisitors.base; - import complexityparser.analyse.antlr.JavaParser; import complexityparser.listeners.TOSBuilder; import complexityparser.listeners.TypingListener; @@ -124,7 +123,7 @@ public abstract class BaseExpressionVisitor extends BaseVisitor { Tier env = Tier.T0; Tier res = Tier.T0; /* - On a constructor call every parameter needs to be either of type 0 or 0 compatible. + On a constructor call every parameter needs to be either of tier 0 or 0 compatible. Only primitive types are compatible. */ if(ctx.creator().classCreatorRest().arguments().expressionList() != null) { @@ -146,7 +145,7 @@ public abstract class BaseExpressionVisitor extends BaseVisitor { /** * Handles the typing for operations on expressions and sets the environment tier to the max of the operand environment tiers. * @param ctx - an operation context. - * @return the operation output tier. + * @return the output tier. */ @Override public Object visitExpression_operation(JavaParser.Expression_operationContext ctx) { @@ -220,9 +219,9 @@ public abstract class BaseExpressionVisitor extends BaseVisitor { } /** - * Handles unary operators + * Handles unary operators and methods. * @param ctx - a unary expression context. - * @return the operator output tier. + * @return the output tier. */ @Override public Object visitExpression_unary(JavaParser.Expression_unaryContext ctx) { diff --git a/src/main/java/complexityparser/typingVisitors/base/BaseStatementVisitor.java b/src/main/java/complexityparser/typingVisitors/base/BaseStatementVisitor.java index b829089f4a0d4b1461f2fc1a4d61d61188f91fc3..e76756260ddbd4e00c00880e370fd40014f1afc5 100644 --- a/src/main/java/complexityparser/typingVisitors/base/BaseStatementVisitor.java +++ b/src/main/java/complexityparser/typingVisitors/base/BaseStatementVisitor.java @@ -27,7 +27,7 @@ import java.util.HashSet; import java.util.List; /** - * Base visitor extending BaseExpressionVisitor to handle statements + * Base visitor extending BaseExpressionVisitor to handle statements. */ public abstract class BaseStatementVisitor extends BaseExpressionVisitor { @@ -283,7 +283,7 @@ public abstract class BaseStatementVisitor extends BaseExpressionVisitor { } /** - * Verifies throw statements + * Verifies throw statements. * @param ctx - a throw statement context. * @return the tier of the block. */ diff --git a/src/main/java/complexityparser/typingVisitors/base/BaseVisitor.java b/src/main/java/complexityparser/typingVisitors/base/BaseVisitor.java index 19f9904e44614a0ee45ad172611d2c731d9ca6ea..e4252618a8e20f370f4060ccf47e65c1081fbf49 100644 --- a/src/main/java/complexityparser/typingVisitors/base/BaseVisitor.java +++ b/src/main/java/complexityparser/typingVisitors/base/BaseVisitor.java @@ -47,7 +47,7 @@ public abstract class BaseVisitor extends JavaParserBaseVisitor { private int whileCount; //The number of while statements encountered in the current block. private ParseTreeProperty<Integer> blockNumbers; //The block index associated to the each node of the parse tree. protected TOS tos; //The table of symbols. - protected TypingEnv te; //The typing environment (HashMap<String, Operator>). + protected TypingEnv te; //The typing environment (HashMap<String, FOTierList>). private CommonTokenStream commonTokenStream; //ANTLR token stream to show line numbers. private boolean overrideResult = true; //A flag to set if the final result should be overridden and if a string output should be generated. private boolean inInitBlock; //A flag to indicate if the visitor is currently located inside an init block or not. diff --git a/src/main/java/complexityparser/typingVisitors/base/ObjectVisitor.java b/src/main/java/complexityparser/typingVisitors/base/ObjectVisitor.java index 17dc7f53b97563a795f99c3c8402e38445d95f60..8801b846ec1175b0a530cfb0a6983d228574bf76 100644 --- a/src/main/java/complexityparser/typingVisitors/base/ObjectVisitor.java +++ b/src/main/java/complexityparser/typingVisitors/base/ObjectVisitor.java @@ -19,7 +19,7 @@ package complexityparser.typingVisitors.base; import complexityparser.types.Tier; import complexityparser.types.tieredtypes.TieredType; import complexityparser.types.FOTier; -import complexityparser.types.Operator; +import complexityparser.types.FOTierList; import complexityparser.analyse.antlr.JavaParser; import complexityparser.listeners.TOSBuilder; import complexityparser.listeners.TypingListener; @@ -40,7 +40,7 @@ import java.util.List; public abstract class ObjectVisitor extends BaseBlockStatementVisitor { private boolean isRecursive; //True if the current method is recursive. - private boolean operatorModified; //A flag which is true if an entry in the operators list has been modified during the pass. + private boolean operatorModified; //A flag which is true if an entry in the operators/methods list has been modified during the pass. private ArrayList<ArrayList<Node>> components; //The strongly connected components in the call graph. public ObjectVisitor(Graph g, TOSBuilder tosBuilder, TypingListener typingListener, CommonTokenStream stream) { @@ -75,14 +75,14 @@ public abstract class ObjectVisitor extends BaseBlockStatementVisitor { /** * - * @return true if an operator input/output array (in the Operators singleton) has been modified/reduced during the current pass. + * @return true if an operator or method FOTier of the TypingEnv has been modified/reduced. */ public boolean isOperatorModified() { return operatorModified; } /** - * Sets the operatorModified attribute to the given value. + * Sets the #operatorModified attribute to the given value. * @param operatorModified - a boolean. */ public void setOperatorModified(boolean operatorModified) { @@ -243,8 +243,8 @@ public abstract class ObjectVisitor extends BaseBlockStatementVisitor { } } } - //Finds the namespace in the operator table - //and returns a compatible output with the input found in the parameters and the receiver type. + //Finds the namespace in the typing environment #te and returns + //a compatible FOTier with the input tiers provided in the parameters. FOTier output = te.findMethod(namespace, paramTiers.getArray()); if(output == null || output.getOut() == Tier.None) { output = te.findCompatibleMethod(namespace, mask, paramTiers.getArray());