From a8dda38d9703bbc3f94cc0c4c3cc730ef8f79b6a Mon Sep 17 00:00:00 2001
From: Mick Jordan <mick.jordan@oracle.com>
Date: Fri, 22 May 2015 07:44:22 -0700
Subject: [PATCH] make RConnection RAttributable

---
 .../truffle/r/runtime/conn/ConnectionSupport.java |  9 ++-------
 .../truffle/r/runtime/conn/RConnection.java       | 15 ++++++++++++++-
 .../truffle/r/runtime/data/RAttributes.java       |  2 +-
 3 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/ConnectionSupport.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/ConnectionSupport.java
index 8113cfb9a4..b0bf7e55f8 100644
--- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/ConnectionSupport.java
+++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/ConnectionSupport.java
@@ -249,11 +249,6 @@ public class ConnectionSupport implements RContext.StateFactory {
          */
         private OpenMode openMode;
 
-        /**
-         * The classes of the connection, which always includes "connection".
-         */
-        private final RStringVector classHr;
-
         /**
          * The actual connection, if delegated.
          */
@@ -295,7 +290,7 @@ public class ConnectionSupport implements RContext.StateFactory {
             String[] classes = new String[2];
             classes[0] = conClass.printName;
             classes[1] = "connection";
-            this.classHr = RDataFactory.createStringVector(classes, RDataFactory.COMPLETE_VECTOR);
+            getAttributes().put(RRuntime.CLASS_ATTR_KEY, RDataFactory.createStringVector(classes, RDataFactory.COMPLETE_VECTOR));
         }
 
         protected void openNonLazyConnection() throws IOException {
@@ -549,7 +544,7 @@ public class ConnectionSupport implements RContext.StateFactory {
         }
 
         public RStringVector getClassHr() {
-            return classHr;
+            return (RStringVector) getAttributes().get(RRuntime.CLASS_ATTR_KEY);
         }
 
         public boolean isClosed() {
diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/RConnection.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/RConnection.java
index f23093c1c3..c14f081ec3 100644
--- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/RConnection.java
+++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/RConnection.java
@@ -36,10 +36,23 @@ import com.oracle.truffle.r.runtime.data.model.*;
  *
  * TODO Refactor the pushBack code into ConnectionsSupport
  */
-public abstract class RConnection implements RClassHierarchy, RTypedValue, AutoCloseable {
+public abstract class RConnection implements RClassHierarchy, RAttributable, RTypedValue, AutoCloseable {
 
     private LinkedList<String> pushBack;
 
+    /**
+     * Connections always have at least a class attribute.
+     */
+    private RAttributes attributes = RAttributes.create();
+
+    public RAttributes initAttributes() {
+        return attributes;
+    }
+
+    public RAttributes getAttributes() {
+        return attributes;
+    }
+
     public abstract String[] readLinesInternal(int n) throws IOException;
 
     public RType getRType() {
diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RAttributes.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RAttributes.java
index e8e749d85b..63b9278bed 100644
--- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RAttributes.java
+++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RAttributes.java
@@ -69,7 +69,7 @@ public final class RAttributes implements Iterable<RAttributes.RAttribute> {
 
     private static final ConditionProfile statsProfile = ConditionProfile.createBinaryProfile();
 
-    static RAttributes create() {
+    public static RAttributes create() {
         return new RAttributes();
     }
 
-- 
GitLab