Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/builtins/SLAssertTrueBuiltin.java @ 20843:a74c785068e0
converted @MethodSubstitutions for jString.equals to MethodSubstitutionPlugins
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Wed, 08 Apr 2015 11:24:16 +0200 |
parents | 158c9ba66e45 |
children |
rev | line source |
---|---|
17003
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1 /* |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
4 * |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
8 * |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
13 * accompanied this code). |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
14 * |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
18 * |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
21 * questions. |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
22 */ |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
23 package com.oracle.truffle.sl.builtins; |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
24 |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
25 import com.oracle.truffle.api.*; |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
26 import com.oracle.truffle.api.dsl.*; |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
27 import com.oracle.truffle.api.nodes.*; |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
28 import com.oracle.truffle.api.source.*; |
17004
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
17003
diff
changeset
|
29 import com.oracle.truffle.sl.*; |
17003
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
30 import com.oracle.truffle.sl.runtime.*; |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
31 |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
32 /** |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
33 * Asserts a given value to be <code>true</code> and throws an {@link AssertionError} if the value |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
34 * was <code>false</code>. |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
35 */ |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
36 @NodeInfo(shortName = "assertTrue") |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
37 public abstract class SLAssertTrueBuiltin extends SLBuiltinNode { |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
38 |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
39 public SLAssertTrueBuiltin() { |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
40 super(new NullSourceSection("SL builtin", "assertTrue")); |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
41 } |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
42 |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
43 @Specialization |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
44 public boolean doAssert(boolean value, String message) { |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
45 if (!value) { |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
46 CompilerDirectives.transferToInterpreter(); |
17004
158c9ba66e45
SL: added support for guest language stack traces to SLException; added SLAssertionError.
Christian Humer <christian.humer@gmail.com>
parents:
17003
diff
changeset
|
47 throw new SLAssertionError(message == null ? "" : message); |
17003
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
48 } |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
49 return value; |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
50 } |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
51 |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
52 @Specialization |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
53 public boolean doAssertNull(boolean value, @SuppressWarnings("unused") SLNull message) { |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
54 return doAssert(value, null); |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
55 } |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
56 |
8fd42ea95f64
SL: added assertTrue and assertFalse builtins to SL.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
57 } |