public boolean identicalTo(Type other) { boolean result = false; if (other instanceof MethodType) { final MethodType temp = (MethodType) other; if (_resultType.identicalTo(temp._resultType)) { final int len = argsCount(); result = len == temp.argsCount(); for (int i = 0; i < len && result; i++) { final Type arg1 = (Type)_argsType.elementAt(i); final Type arg2 = (Type)temp._argsType.elementAt(i); result = arg1.identicalTo(arg2); } } } return result; }
public Type typeCheck(SymbolTable stable) throws TypeCheckError { final Vector contents = getContents(); final int n = contents.size(); for (int i = 0; i < n; i++) { final Expression exp = (Expression)contents.elementAt(i); if (!exp.typeCheck(stable).identicalTo(Type.String)) { contents.setElementAt(new CastExpr(exp, Type.String), i); } } return _type = Type.String; }
public Type typeCheck(SymbolTable stable) throws TypeCheckError { Type type = _select.typeCheck(stable); // Prefer to handle the value as a node; fall back to String, otherwise if (type != null && !type.identicalTo(Type.Node)) { /*** *** %HZ% Would like to treat result-tree fragments in the same *** %HZ% way as node sets for value-of, but that's running into *** %HZ% some snags. Instead, they'll be converted to String if (type.identicalTo(Type.ResultTree)) { _select = new CastExpr(new CastExpr(_select, Type.NodeSet), Type.Node); } else ***/ if (type.identicalTo(Type.NodeSet)) { _select = new CastExpr(_select, Type.Node); } else { _isString = true; if (!type.identicalTo(Type.String)) { _select = new CastExpr(_select, Type.String); } _isString = true; } } return Type.Void; }
public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final Type ltype = _left.getType(); _left.translate(classGen, methodGen); if (_type.identicalTo(ltype) == false) { _left.startIterator(classGen, methodGen); ltype.translateTo(classGen, methodGen, _type); } } }
public void translate(ClassGenerator classGen, MethodGenerator methodGen) { _arg.translate(classGen, methodGen); final Type targ = _arg.getType(); if (!targ.identicalTo(Type.Boolean)) { _arg.startIterator(classGen, methodGen); targ.translateTo(classGen, methodGen, Type.Boolean); } } }
public Type typeCheck(SymbolTable stable) throws TypeCheckError { final Type tleft = _left.typeCheck(stable); final Type tright = _right.typeCheck(stable); final MethodType ptype = lookupPrimop(stable, Ops[_op], new MethodType(Type.Void, tleft, tright)); if (ptype != null) { final Type arg1 = (Type) ptype.argsType().elementAt(0); if (!arg1.identicalTo(tleft)) { _left = new CastExpr(_left, arg1); } final Type arg2 = (Type) ptype.argsType().elementAt(1); if (!arg2.identicalTo(tright)) { _right = new CastExpr(_right, arg1); } return _type = ptype.resultType(); } throw new TypeCheckError(this); }
public Type typeCheck(SymbolTable stable) throws TypeCheckError { for (int i = 0; i < argumentCount(); i++) { final Expression exp = argument(i); if (!exp.typeCheck(stable).identicalTo(Type.String)) { setArgument(i, new CastExpr(exp, Type.String)); } } return _type = Type.String; }
/** * Type-check this expression, and possibly child expressions. */ public Type typeCheck(SymbolTable stable) throws TypeCheckError { // Get the left and right operand types Type tleft = _left.typeCheck(stable); Type tright = _right.typeCheck(stable); // Check if the operator supports the two operand types MethodType wantType = new MethodType(Type.Void, tleft, tright); MethodType haveType = lookupPrimop(stable, Ops[_op], wantType); // Yes, the operation is supported if (haveType != null) { // Check if left-hand side operand must be type casted Type arg1 = (Type)haveType.argsType().elementAt(0); if (!arg1.identicalTo(tleft)) _left = new CastExpr(_left, arg1); // Check if right-hand side operand must be type casted Type arg2 = (Type) haveType.argsType().elementAt(1); if (!arg2.identicalTo(tright)) _right = new CastExpr(_right, arg1); // Return the result type for the operator we will use return _type = haveType.resultType(); } throw new TypeCheckError(this); }
public Type typeCheck(SymbolTable stable) throws TypeCheckError { final Type tleft = _left.typeCheck(stable); final MethodType ptype = lookupPrimop(stable, "u-", new MethodType(Type.Void, tleft)); if (ptype != null) { final Type arg1 = (Type) ptype.argsType().elementAt(0); if (!arg1.identicalTo(tleft)) { _left = new CastExpr(_left, arg1); } return _type = ptype.resultType(); } throw new TypeCheckError(this); }
/** * Type check a call to a standard function. Insert CastExprs when needed. * If as a result of the insertion of a CastExpr a type check error is * thrown, then catch it and re-throw it with a new "this". */ public Type typeCheckStandard(SymbolTable stable) throws TypeCheckError { _fname.clearNamespace(); // HACK!!! final int n = _arguments.size(); final Vector argsType = typeCheckArgs(stable); final MethodType args = new MethodType(Type.Void, argsType); final MethodType ptype = lookupPrimop(stable, _fname.getLocalPart(), args); if (ptype != null) { for (int i = 0; i < n; i++) { final Type argType = (Type) ptype.argsType().elementAt(i); final Expression exp = (Expression)_arguments.elementAt(i); if (!argType.identicalTo(exp.getType())) { try { _arguments.setElementAt(new CastExpr(exp, argType), i); } catch (TypeCheckError e) { throw new TypeCheckError(this); // invalid conversion } } } _chosenMethodType = ptype; return _type = ptype.resultType(); } throw new TypeCheckError(this); }
public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final InstructionList il = methodGen.getInstructionList(); Type targ; if (argumentCount() == 0) { il.append(methodGen.loadContextNode()); targ = Type.Node; } else { final Expression arg = argument(); arg.translate(classGen, methodGen); arg.startIterator(classGen, methodGen); targ = arg.getType(); } if (!targ.identicalTo(Type.String)) { targ.translateTo(classGen, methodGen, Type.String); } } }
public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final InstructionList il = methodGen.getInstructionList(); Type targ; if (argumentCount() == 0) { il.append(methodGen.loadContextNode()); targ = Type.Node; } else { final Expression arg = argument(); arg.translate(classGen, methodGen); arg.startIterator(classGen, methodGen); targ = arg.getType(); } if (!targ.identicalTo(Type.Real)) { targ.translateTo(classGen, methodGen, Type.Real); } } }
if (arg2Type.identicalTo(Type.Node)) { _arg2 = new CastExpr(_arg2, Type.NodeSet); } else if (arg2Type.identicalTo(Type.NodeSet)) {
if (!arg1.identicalTo(tleft)) { _left = new CastExpr(_left, arg1); if (!arg2.identicalTo(tright)) { _right = new CastExpr(_right, arg1);
public Type typeCheck(SymbolTable stable) throws TypeCheckError { final Vector contents = getContents(); final int n = contents.size(); for (int i = 0; i < n; i++) { final Expression exp = (Expression)contents.elementAt(i); if (!exp.typeCheck(stable).identicalTo(Type.String)) { contents.setElementAt(new CastExpr(exp, Type.String), i); } } return _type = Type.String; }
public void translate(ClassGenerator classGen, MethodGenerator methodGen) { final Type ltype = _left.getType(); _left.translate(classGen, methodGen); if (_type.identicalTo(ltype) == false) { _left.startIterator(classGen, methodGen); ltype.translateTo(classGen, methodGen, _type); } } }
public void translate(ClassGenerator classGen, MethodGenerator methodGen) { _arg.translate(classGen, methodGen); final Type targ = _arg.getType(); if (!targ.identicalTo(Type.Boolean)) { _arg.startIterator(classGen, methodGen); targ.translateTo(classGen, methodGen, Type.Boolean); } } }
public void translate(ClassGenerator classGen, MethodGenerator methodGen) { _arg.translate(classGen, methodGen); final Type targ = _arg.getType(); if (!targ.identicalTo(Type.Boolean)) { _arg.startIterator(classGen, methodGen); targ.translateTo(classGen, methodGen, Type.Boolean); } } }
public Type typeCheck(SymbolTable stable) throws TypeCheckError { for (int i = 0; i < argumentCount(); i++) { final Expression exp = argument(i); if (!exp.typeCheck(stable).identicalTo(Type.String)) { setArgument(i, new CastExpr(exp, Type.String)); } } return _type = Type.String; }
public Type typeCheck(SymbolTable stable) throws TypeCheckError { for (int i = 0; i < argumentCount(); i++) { final Expression exp = argument(i); if (!exp.typeCheck(stable).identicalTo(Type.String)) { setArgument(i, new CastExpr(exp, Type.String)); } } return _type = Type.String; }