Loading src/main/java/ca/mcscert/jtet/expression/Variable.java +51 −5 Original line number Diff line number Diff line Loading @@ -5,39 +5,73 @@ package ca.mcscert.jtet.expression; /** * Variable stores the information about a single variable, making it available inside an expression. * <p> * This class holds all the relevant information about a variable, including the necessary logic to handle outputting the * variable. The base name is used by parsers to recognize the variable inside expression, and the output name is used * at generation time to allow efficient renaming. The type is used as usual by generation logic to ensure an expression * is well formed. * * @author matthew * @author Matthew Dawson */ public class Variable implements Expression, ExpressionValue { /** * This constructs a variable with the given name and type. Both cannot be modified later to avoid invalidating an * expression. * <p> * The output name, as used in generators, can be modified later as it doesn't effect the semantics. * @param name The name of the variable, as found in expressions handed to a parser. * @param type The type of the variable, used to ensure expressions are well formed. */ public Variable(String name, VariableType type) { m_outputName = m_name = name; m_type = type; } /** * Returns the name of the variable. * @return Name of the variable. */ public String name() { return m_name; } /** * Returns the type of the variable. * @return Type of the variable. */ public VariableType type() { return m_type; } /** * Returns the current output name of the variable. If the output name of the variable is unset, this returns the * same as {@link name()}. * @return The output name of the variable. */ public String outputName() { return m_outputName; } /* This changes the variable as outputed by a CheckerGenerator. * /** * This changes the variable as outputed by a CheckerGenerator. * <p> * There are times when a user wants to rename a variable used in an Expression. However, it would be weird to change * the actual name, as then the VariableCollection would be weird. Instead, use a special output name, that is used * when generating code but is otherwise the same. * the actual name, as expressions would not be able to find this variable anymore. Instead, use a special output * name, that is used only when generating expressions. * @param outputName The new name to be used during generation. */ public void setOutputName(String outputName) { this.m_outputName = outputName; } /** * {@inheritDoc} * <p> * This only allows for types that match the type of the variable, and doesn't do casting. */ @Override public VariableType actualOutputTypeForRequestedOutput(VariableTypeMarker requestedType) { if (requestedType.isMarkerFor(m_type)) { Loading @@ -50,6 +84,12 @@ public class Variable implements Expression, ExpressionValue { private String m_outputName; final private VariableType m_type; /** * {@inheritDoc} * <p> * This just uses the output name for use in expressions, and doesn't currently go through {@link ca.mcscert.jtet.expression.CheckerGenerator}. * It also only allows use of the variable type. */ @Override public String getCheckerOutput(CheckerGenerator generator, VariableType requestedType) { if (!type().equals(requestedType)) { Loading @@ -58,6 +98,12 @@ public class Variable implements Expression, ExpressionValue { return m_outputName; } /** * Returns the regular name of the variable. * <p> * As this is used only for debugging, return the regular name of the variable, to make it easy to identify. * @return The name of the variable. */ @Override public String toString() { return m_name; Loading Loading
src/main/java/ca/mcscert/jtet/expression/Variable.java +51 −5 Original line number Diff line number Diff line Loading @@ -5,39 +5,73 @@ package ca.mcscert.jtet.expression; /** * Variable stores the information about a single variable, making it available inside an expression. * <p> * This class holds all the relevant information about a variable, including the necessary logic to handle outputting the * variable. The base name is used by parsers to recognize the variable inside expression, and the output name is used * at generation time to allow efficient renaming. The type is used as usual by generation logic to ensure an expression * is well formed. * * @author matthew * @author Matthew Dawson */ public class Variable implements Expression, ExpressionValue { /** * This constructs a variable with the given name and type. Both cannot be modified later to avoid invalidating an * expression. * <p> * The output name, as used in generators, can be modified later as it doesn't effect the semantics. * @param name The name of the variable, as found in expressions handed to a parser. * @param type The type of the variable, used to ensure expressions are well formed. */ public Variable(String name, VariableType type) { m_outputName = m_name = name; m_type = type; } /** * Returns the name of the variable. * @return Name of the variable. */ public String name() { return m_name; } /** * Returns the type of the variable. * @return Type of the variable. */ public VariableType type() { return m_type; } /** * Returns the current output name of the variable. If the output name of the variable is unset, this returns the * same as {@link name()}. * @return The output name of the variable. */ public String outputName() { return m_outputName; } /* This changes the variable as outputed by a CheckerGenerator. * /** * This changes the variable as outputed by a CheckerGenerator. * <p> * There are times when a user wants to rename a variable used in an Expression. However, it would be weird to change * the actual name, as then the VariableCollection would be weird. Instead, use a special output name, that is used * when generating code but is otherwise the same. * the actual name, as expressions would not be able to find this variable anymore. Instead, use a special output * name, that is used only when generating expressions. * @param outputName The new name to be used during generation. */ public void setOutputName(String outputName) { this.m_outputName = outputName; } /** * {@inheritDoc} * <p> * This only allows for types that match the type of the variable, and doesn't do casting. */ @Override public VariableType actualOutputTypeForRequestedOutput(VariableTypeMarker requestedType) { if (requestedType.isMarkerFor(m_type)) { Loading @@ -50,6 +84,12 @@ public class Variable implements Expression, ExpressionValue { private String m_outputName; final private VariableType m_type; /** * {@inheritDoc} * <p> * This just uses the output name for use in expressions, and doesn't currently go through {@link ca.mcscert.jtet.expression.CheckerGenerator}. * It also only allows use of the variable type. */ @Override public String getCheckerOutput(CheckerGenerator generator, VariableType requestedType) { if (!type().equals(requestedType)) { Loading @@ -58,6 +98,12 @@ public class Variable implements Expression, ExpressionValue { return m_outputName; } /** * Returns the regular name of the variable. * <p> * As this is used only for debugging, return the regular name of the variable, to make it easy to identify. * @return The name of the variable. */ @Override public String toString() { return m_name; Loading