From 8fe9ee5b386af0cc4f2ff310179efb3d1d8ee2e1 Mon Sep 17 00:00:00 2001
From: Lukas Stadler <lukas.stadler@oracle.com>
Date: Thu, 2 Oct 2014 10:38:47 +0200
Subject: [PATCH] consistently "throw" RError.error messages

---
 .../r/nodes/builtin/base/FrameFunctions.java  |  6 +--
 .../r/nodes/builtin/base/LaFunctions.java     | 38 +++++++++----------
 .../access/array/read/AccessArrayNode.java    |  2 +-
 .../truffle/r/nodes/binary/ColonNode.java     |  2 +-
 4 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/FrameFunctions.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/FrameFunctions.java
index abff6826d3..e7f60e273c 100644
--- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/FrameFunctions.java
+++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/FrameFunctions.java
@@ -60,7 +60,7 @@ public class FrameFunctions {
             if (n > 0) {
                 int d = Utils.stackDepth();
                 if (n > d) {
-                    RError.error(RError.Message.NOT_THAT_MANY_FRAMES);
+                    throw RError.error(RError.Message.NOT_THAT_MANY_FRAMES);
                 }
                 n = d - n + 1; // add one to skip internal evaluation frame
             } else {
@@ -68,7 +68,7 @@ public class FrameFunctions {
             }
             Frame callerFrame = Utils.getStackFrame(frameAccess(), n);
             if (callerFrame == null) {
-                RError.error(RError.Message.NOT_THAT_MANY_FRAMES);
+                throw RError.error(RError.Message.NOT_THAT_MANY_FRAMES);
             }
             return callerFrame;
         }
@@ -286,7 +286,7 @@ public class FrameFunctions {
             controlVisibility();
             int n = (int) nd;
             if (n == 0) {
-                RError.error(RError.Message.INVALID_ARGUMENT, RRuntime.toString(n));
+                throw RError.error(RError.Message.INVALID_ARGUMENT, RRuntime.toString(n));
             }
             Frame callerFrame = Utils.getStackFrame(FrameAccess.MATERIALIZE, n + 1);
             if (callerFrame == null) {
diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/LaFunctions.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/LaFunctions.java
index 48eb528f16..fd36791e13 100644
--- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/LaFunctions.java
+++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/LaFunctions.java
@@ -52,11 +52,11 @@ public class LaFunctions {
         protected Object doRg(RDoubleVector matrix, byte onlyValues) {
             controlVisibility();
             if (!matrix.isMatrix()) {
-                RError.error(getEncapsulatingSourceSection(), RError.Message.MUST_BE_SQUARE_NUMERIC, "x");
+                throw RError.error(getEncapsulatingSourceSection(), RError.Message.MUST_BE_SQUARE_NUMERIC, "x");
             }
             int[] dims = matrix.getDimensions();
             if (onlyValues == RRuntime.LOGICAL_NA) {
-                RError.error(getEncapsulatingSourceSection(), RError.Message.INVALID_ARGUMENT, "only.values");
+                throw RError.error(getEncapsulatingSourceSection(), RError.Message.INVALID_ARGUMENT, "only.values");
             }
             // copy array component of matrix as Lapack destroys it
             int n = dims[0];
@@ -80,14 +80,14 @@ public class LaFunctions {
             // ask for optimal size of work array
             int info = RFFIFactory.getRFFI().getLapackRFFI().dgeev(jobVL, jobVR, n, a, n, wr, wi, left, n, right, n, work, -1);
             if (info != 0) {
-                RError.error(getEncapsulatingSourceSection(), RError.Message.LAPACK_ERROR, info, "dgeev");
+                throw RError.error(getEncapsulatingSourceSection(), RError.Message.LAPACK_ERROR, info, "dgeev");
             }
             // now allocate work array and make the actual call
             int lwork = (int) work[0];
             work = new double[lwork];
             info = RFFIFactory.getRFFI().getLapackRFFI().dgeev(jobVL, jobVR, n, a, n, wr, wi, left, n, right, n, work, lwork);
             if (info != 0) {
-                RError.error(getEncapsulatingSourceSection(), RError.Message.LAPACK_ERROR, info, "dgeev");
+                throw RError.error(getEncapsulatingSourceSection(), RError.Message.LAPACK_ERROR, info, "dgeev");
             }
             // result is a list containing "values" and "vectors" (unless only.values is TRUE)
             boolean complexValues = false;
@@ -130,7 +130,7 @@ public class LaFunctions {
         protected RList doQr(RAbstractVector aIn) {
             // This implementation is sufficient for B25 matcal-5.
             if (!aIn.isMatrix()) {
-                RError.error(getEncapsulatingSourceSection(), RError.Message.MUST_BE_NUMERIC_MATRIX, "a");
+                throw RError.error(getEncapsulatingSourceSection(), RError.Message.MUST_BE_NUMERIC_MATRIX, "a");
             }
             if (!(aIn instanceof RDoubleVector)) {
                 RError.nyi(getEncapsulatingSourceSection(), "non-real vectors not supported (yet)");
@@ -147,13 +147,13 @@ public class LaFunctions {
             // ask for optimal size of work array
             int info = RFFIFactory.getRFFI().getLapackRFFI().dgeqp3(m, n, a, m, jpvt, tau, work, -1);
             if (info < 0) {
-                RError.error(getEncapsulatingSourceSection(), RError.Message.LAPACK_ERROR, info, "dgeqp3");
+                throw RError.error(getEncapsulatingSourceSection(), RError.Message.LAPACK_ERROR, info, "dgeqp3");
             }
             int lwork = (int) work[0];
             work = new double[lwork];
             info = RFFIFactory.getRFFI().getLapackRFFI().dgeqp3(m, n, a, m, jpvt, tau, work, lwork);
             if (info < 0) {
-                RError.error(getEncapsulatingSourceSection(), RError.Message.LAPACK_ERROR, info, "dgeqp3");
+                throw RError.error(getEncapsulatingSourceSection(), RError.Message.LAPACK_ERROR, info, "dgeqp3");
             }
             Object[] data = new Object[4];
             // TODO check complete
@@ -183,7 +183,7 @@ public class LaFunctions {
         @Specialization
         protected RDoubleVector doQrCoefReal(RList qIn, RDoubleVector bIn) {
             if (!bIn.isMatrix()) {
-                RError.error(getEncapsulatingSourceSection(), RError.Message.MUST_BE_NUMERIC_MATRIX, "b");
+                throw RError.error(getEncapsulatingSourceSection(), RError.Message.MUST_BE_NUMERIC_MATRIX, "b");
             }
             // If bIn was coerced this extra copy is unnecessary
             RDoubleVector b = (RDoubleVector) bIn.copy();
@@ -197,7 +197,7 @@ public class LaFunctions {
             int[] qrDims = qr.getDimensions();
             int n = qrDims[0];
             if (bDims[0] != n) {
-                RError.error(getEncapsulatingSourceSection(), RError.Message.RHS_SHOULD_HAVE_ROWS, n, bDims[0]);
+                throw RError.error(getEncapsulatingSourceSection(), RError.Message.RHS_SHOULD_HAVE_ROWS, n, bDims[0]);
             }
             int nrhs = bDims[1];
             double[] work = new double[1];
@@ -209,17 +209,17 @@ public class LaFunctions {
             // ask for optimal size of work array
             int info = RFFIFactory.getRFFI().getLapackRFFI().dormqr(SIDE, TRANS, n, nrhs, k, qrData, n, tauData, bData, n, work, -1);
             if (info < 0) {
-                RError.error(getEncapsulatingSourceSection(), RError.Message.LAPACK_ERROR, info, "dormqr");
+                throw RError.error(getEncapsulatingSourceSection(), RError.Message.LAPACK_ERROR, info, "dormqr");
             }
             int lwork = (int) work[0];
             work = new double[lwork];
             info = RFFIFactory.getRFFI().getLapackRFFI().dormqr(SIDE, TRANS, n, nrhs, k, qrData, n, tauData, bData, n, work, lwork);
             if (info < 0) {
-                RError.error(getEncapsulatingSourceSection(), RError.Message.LAPACK_ERROR, info, "dormqr");
+                throw RError.error(getEncapsulatingSourceSection(), RError.Message.LAPACK_ERROR, info, "dormqr");
             }
             info = RFFIFactory.getRFFI().getLapackRFFI().dtrtrs('U', 'N', 'N', k, nrhs, qrData, n, bData, n);
             if (info < 0) {
-                RError.error(getEncapsulatingSourceSection(), RError.Message.LAPACK_ERROR, info, "dtrtrs");
+                throw RError.error(getEncapsulatingSourceSection(), RError.Message.LAPACK_ERROR, info, "dtrtrs");
             }
             // TODO check complete
             return b;
@@ -236,13 +236,13 @@ public class LaFunctions {
         @Specialization
         protected RList doDetGeReal(RDoubleVector aIn, byte useLogIn) {
             if (!aIn.isMatrix()) {
-                RError.error(getEncapsulatingSourceSection(), RError.Message.MUST_BE_NUMERIC_MATRIX, "a");
+                throw RError.error(getEncapsulatingSourceSection(), RError.Message.MUST_BE_NUMERIC_MATRIX, "a");
             }
             RDoubleVector a = (RDoubleVector) aIn.copy();
             int[] aDims = aIn.getDimensions();
             int n = aDims[0];
             if (n != aDims[1]) {
-                RError.error(getEncapsulatingSourceSection(), RError.Message.MUST_BE_SQUARE, "a");
+                throw RError.error(getEncapsulatingSourceSection(), RError.Message.MUST_BE_SQUARE, "a");
             }
             int[] ipiv = new int[n];
             double modulus = 0;
@@ -251,7 +251,7 @@ public class LaFunctions {
             int info = RFFIFactory.getRFFI().getLapackRFFI().dgetrf(n, n, aData, n, ipiv);
             int sign = 1;
             if (info < 0) {
-                RError.error(getEncapsulatingSourceSection(), RError.Message.LAPACK_ERROR, info, "dgetrf");
+                throw RError.error(getEncapsulatingSourceSection(), RError.Message.LAPACK_ERROR, info, "dgetrf");
             } else if (info > 0) {
                 modulus = useLog ? Double.NEGATIVE_INFINITY : 0;
             } else {
@@ -299,10 +299,10 @@ public class LaFunctions {
             int n = aDims[0];
             int m = aDims[1];
             if (n != m) {
-                RError.error(getEncapsulatingSourceSection(), RError.Message.MUST_BE_SQUARE, "a");
+                throw RError.error(getEncapsulatingSourceSection(), RError.Message.MUST_BE_SQUARE, "a");
             }
             if (m <= 0) {
-                RError.error(getEncapsulatingSourceSection(), RError.Message.DIMS_GT_ZERO, "a");
+                throw RError.error(getEncapsulatingSourceSection(), RError.Message.DIMS_GT_ZERO, "a");
             }
             double[] aData = a.getDataWithoutCopying();
             /* zero the lower triangle */
@@ -317,7 +317,7 @@ public class LaFunctions {
                 info = RFFIFactory.getRFFI().getLapackRFFI().dpotrf('U', m, aData, m);
                 if (info != 0) {
                     // TODO informative error message (aka GnuR)
-                    RError.error(getEncapsulatingSourceSection(), RError.Message.LAPACK_ERROR, info, "dpotrf");
+                    throw RError.error(getEncapsulatingSourceSection(), RError.Message.LAPACK_ERROR, info, "dpotrf");
                 }
             } else {
                 int[] ipiv = new int[m];
@@ -326,7 +326,7 @@ public class LaFunctions {
                 info = RFFIFactory.getRFFI().getLapackRFFI().dpstrf('U', n, aData, n, ipiv, rank, tol, work);
                 if (info != 0) {
                     // TODO informative error message (aka GnuR)
-                    RError.error(getEncapsulatingSourceSection(), RError.Message.LAPACK_ERROR, info, "dpotrf");
+                    throw RError.error(getEncapsulatingSourceSection(), RError.Message.LAPACK_ERROR, info, "dpotrf");
                 }
                 a.setAttr("pivot", pivot);
                 a.setAttr("rank", rank[0]);
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/array/read/AccessArrayNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/array/read/AccessArrayNode.java
index ded721b88f..52287f26c6 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/array/read/AccessArrayNode.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/array/read/AccessArrayNode.java
@@ -1204,7 +1204,7 @@ public abstract class AccessArrayNode extends RNode {
     @Specialization(guards = "isPositionZero")
     protected RRawVector accessPosZero(RRawVector vector, int recLevel, int position, RAbstractLogicalVector dropDim) {
         if (!isSubset) {
-            RError.error(getEncapsulatingSourceSection(), RError.Message.SELECT_LESS_1);
+            throw RError.error(getEncapsulatingSourceSection(), RError.Message.SELECT_LESS_1);
         }
         if (vector.getNames() == RNull.instance) {
             return RDataFactory.createEmptyRawVector();
diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/binary/ColonNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/binary/ColonNode.java
index eee5b9afde..6bfc6edcfd 100644
--- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/binary/ColonNode.java
+++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/binary/ColonNode.java
@@ -42,7 +42,7 @@ public abstract class ColonNode extends RNode implements VisibilityController {
 
     private void naCheck(boolean na) {
         if (na) {
-            RError.error(getSourceSection(), RError.Message.NA_OR_NAN);
+            throw RError.error(getSourceSection(), RError.Message.NA_OR_NAN);
         }
     }
 
-- 
GitLab