/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* WARNING: The contents of this source file are not part of any
* supported API. Code that depends on them does so at its own risk:
* they are subject to change or removal without notice.
*/
public
/**
* Constructor
*/
}
// /**
// * Constructor for try (init) {body}
// */
// public FinallyStatement(long where, Statement init, Statement body, int junk) {
// this(where, body, null);
// this.init = init;
// }
/**
* Check statement
*/
// Handle the proposed 'try (init) { stmts } finally { stmts }' syntax.
// This feature has not been adopted, and support is presently disabled.
/*-----------------------------------------------------------*
if (init != null) {
ClassDefinition sourceClass = ctx.field.getClassDefinition();
Expression tryExpr = null;
DeclarationStatement tryDecl = null;
long where = init.getWhere();
// find out whether init is a simple expression or a declaration
if (init.getOp() == EXPRESSION) {
tryExpr = ((ExpressionStatement)init).expr;
init = null; // restore it below
vset = tryExpr.checkValue(env, ctx, vset, exp);
} else if (init.getOp() == DECLARATION) {
tryDecl = (DeclarationStatement) init;
init = null; // restore it below
vset = tryDecl.checkBlockStatement(env, ctx, vset, exp);
if (tryDecl.args.length != 1) {
env.error(where, "invalid.decl");
} else {
LocalMember field =
((VarDeclarationStatement) tryDecl.args[0]).field;
tryExpr = new IdentifierExpression(where, field);
tryExpr.type = field.getType();
}
} else {
env.error(where, "invalid.expr");
vset = init.check(env, ctx, vset, exp);
}
Type type = (tryExpr == null) ? Type.tError : tryExpr.getType();
MemberDefinition tryEnter = null;
MemberDefinition tryExit = null;
if (!type.isType(TC_CLASS)) {
if (!type.isType(TC_ERROR)) {
env.error(where, "invalid.method.invoke", type);
}
} else {
Identifier idTryEnter = Identifier.lookup("tryEnter");
Identifier idTryExit = Identifier.lookup("tryExit");
Type tTryMethod = Type.tMethod(Type.tVoid);
try {
ClassDefinition tryClass = env.getClassDefinition(type);
tryEnter = tryClass.matchMethod(env, sourceClass, idTryEnter);
tryExit = tryClass.matchMethod(env, sourceClass, idTryExit);
if (tryEnter != null && !tryEnter.getType().equals(tTryMethod)) {
tryEnter = null;
}
if (tryExit != null && !tryExit.getType().equals(tTryMethod)) {
tryExit = null;
}
} catch (ClassNotFound ee) {
env.error(where, "class.not.found", ee.name, ctx.field);
} catch (AmbiguousMember ee) {
Identifier id = ee.field1.getName();
env.error(where, "ambig.field", id, ee.field1, ee.field2);
}
}
if (tryEnter == null || tryExit == null) {
// Make a better (more didactic) error here!
env.error(where, "invalid.method.invoke", type);
} else {
tryTemp = new LocalMember(where, sourceClass, 0,
type, Identifier.lookup("<try_object>"));
ctx = new Context(ctx, this);
ctx.declare(env, tryTemp);
Expression e;
e = new IdentifierExpression(where, tryTemp);
e = new AssignExpression(where, e, tryExpr);
e = new MethodExpression(where, e, tryEnter, new Expression[0]);
e.type = Type.tVoid;
Statement enterCall = new ExpressionStatement(where, e);
// store it on the init, for code generation
if (tryDecl != null) {
Statement args2[] = { tryDecl.args[0], enterCall };
tryDecl.args = args2;
init = tryDecl;
} else {
init = enterCall;
}
e = new IdentifierExpression(where, tryTemp);
e = new MethodExpression(where, e, tryExit, new Expression[0]);
e.type = Type.tVoid;
Statement exitCall = new ExpressionStatement(where, e);
finalbody = exitCall;
}
}
*-----------------------------------------------------------*/
// Check the try part. We reach the end of the try part either by
// NOTE: I don't think newctx1.vsBreak is ever used -- see TryStatement.
// Check the finally part.
// Should never access this field. The null indicates the finally part.
// If !finallyCanFinish, then the only possible exceptions that can
// the ones generated by the finally. Anything in the try is
// irrelevant. Otherwise, we have to merge in all the exceptions
// generated by the body into exp.
if (finallyCanFinish) {
// Add newexp's back into exp; cf. ThrowStatement.check().
}
}
}
/**
* Inline
*/
}
}
}
}
}
}
return this;
}
/**
* Create a copy of the statement for method inlining
*/
}
}
}
}
return s;
}
/**
* Compute cost of inlining this statement
*/
int cost = 4;
}
}
}
return cost;
}
/**
* Code
*/
}
}
if (finallyCanFinish) {
if (needReturnSlot) {
}
// allocate space for the exception and return address
}
// Main body
// Cleanup afer body
if (finallyCanFinish) {
} else {
// just goto the cleanup code. It will never return.
}
// Catch code
if (finallyCanFinish) {
} else {
// pop exception off stack. Fall through to finally code
}
// The finally part, which is marked by the contLabel. Update
// breakLabel: since break's in the finally are different
// contLabel: to null to indicate no longer in the protected code.
if (finallyCanFinish) {
} else {
}
}
/**
* Print
*/
} else {
}
} else {
}
}
}