Loading src/main/java/ca/mcscert/jtet/expression/Expression.java +53 −7 Original line number Diff line number Diff line /* * To change this template, choose Tools | Templates * and open the template in the editor. * Copyright (C) 2014 Matthew Dawson <matthew@mjdsystems.ca> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the distribution * * Neither the name of the McMaster Centre for Software Certification nor the names * of its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ package ca.mcscert.jtet.expression; /** * Base interface to build an abstract syntax tree in jTET. * <p> * Expression provides the base class from which any abstract syntax tree is built in jTET. How exactly any given * part of the AST generates is left up to an implementation of this interface. Expression simply provides a way to * generate a string representing the expression while being appropriately typed. * * @author matthew * @author Matthew Dawson */ public interface Expression { /* This methods returns an actual variable type for the requested input type. If due to the setup of the system, * this is not possible, then this function should return null. /** * Attempts to resolve the type the expression will output, limited to the class of types given by the type marker. * * This function finds if the requested class of types can represent the output from this expression, and what that * output type would be. This is mostly used internally to make sure call to getCheckerOutput can succeed. * * @param requestedType The class of type requested. * @return The concrete type that will be used, or null if none can be found. */ VariableType actualOutputTypeForRequestedOutput(VariableTypeMarker requestedType); /** * Returns a string representing this expression generated from the given generator. * <p> * This function should make appropriate calls into the generator to generate an expression in its language that * outputs requested type. If it is impossible to satisfy this request, it should throw an appropriate exception. * <p> * Note that the AST should not modify the string returned from the generator, as its format is left unspecified. * * @param generator The expression generator that is used to generate the string output. * @param requestedType The type the expression output. * @return A string from the generator representing the expression. */ String getCheckerOutput(ExpressionGenerator generator, VariableType requestedType); } Loading
src/main/java/ca/mcscert/jtet/expression/Expression.java +53 −7 Original line number Diff line number Diff line /* * To change this template, choose Tools | Templates * and open the template in the editor. * Copyright (C) 2014 Matthew Dawson <matthew@mjdsystems.ca> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the distribution * * Neither the name of the McMaster Centre for Software Certification nor the names * of its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ package ca.mcscert.jtet.expression; /** * Base interface to build an abstract syntax tree in jTET. * <p> * Expression provides the base class from which any abstract syntax tree is built in jTET. How exactly any given * part of the AST generates is left up to an implementation of this interface. Expression simply provides a way to * generate a string representing the expression while being appropriately typed. * * @author matthew * @author Matthew Dawson */ public interface Expression { /* This methods returns an actual variable type for the requested input type. If due to the setup of the system, * this is not possible, then this function should return null. /** * Attempts to resolve the type the expression will output, limited to the class of types given by the type marker. * * This function finds if the requested class of types can represent the output from this expression, and what that * output type would be. This is mostly used internally to make sure call to getCheckerOutput can succeed. * * @param requestedType The class of type requested. * @return The concrete type that will be used, or null if none can be found. */ VariableType actualOutputTypeForRequestedOutput(VariableTypeMarker requestedType); /** * Returns a string representing this expression generated from the given generator. * <p> * This function should make appropriate calls into the generator to generate an expression in its language that * outputs requested type. If it is impossible to satisfy this request, it should throw an appropriate exception. * <p> * Note that the AST should not modify the string returned from the generator, as its format is left unspecified. * * @param generator The expression generator that is used to generate the string output. * @param requestedType The type the expression output. * @return A string from the generator representing the expression. */ String getCheckerOutput(ExpressionGenerator generator, VariableType requestedType); }