[ClavaWeaver] Reverts $jp.data code to original behavior
@@ -51,7 +51,6 @@ import pt.up.fe.specs.clava.weaver.abstracts.joinpoints.AType;
import pt.up.fe.specs.clava.weaver.importable.AstFactory;
import pt.up.fe.specs.clava.weaver.importable.LowLevelApi;
import pt.up.fe.specs.clava.weaver.joinpoints.CxxProgram;
-import pt.up.fe.specs.jsengine.JsFileType;
import pt.up.fe.specs.util.SpecsCheck;
import pt.up.fe.specs.util.SpecsLogs;
import pt.up.fe.specs.util.SpecsStrings;
@@ -1112,23 +1111,23 @@ public abstract class ACxxWeaverJoinPoint extends AJoinPoint {
var jsDataPragma = dataPragma != null ? dataPragma : jsEngine.getUndefined();
// Check if data object already exists
- var hasClavaDataJs = jsEngine.eval(
- "import { _hasClavaData } from 'node_modules/clavaapi/dist/clava/js/DataHandler.js'; _hasClavaData;",
- JsFileType.MODULE,
- "[Java] ACxxWeaverJoinPoint.getDataImpl() [" + (jsNameCounter++) + "]");
+ var hasClavaDataJs = jsEngine.eval("var _data = _hasClavaData; _data;");
var hasClavaData = jsEngine.asBoolean(jsEngine.call(hasClavaDataJs, getNode()));
- // Create proxy function
- var proxyBuilder = jsEngine.eval(
- "import { _getClavaData } from 'node_modules/clavaapi/dist/clava/js/DataHandler.js'; _getClavaData;",
- JsFileType.MODULE,
- "[Java] ACxxWeaverJoinPoint.getDataImpl() [" + (jsNameCounter++) + "]");
+ if (hasClavaData) {
+ // Return data object from managed cache
+ var dataCache = jsEngine.eval("var _data = _getClavaData; _data;");
+
+ // Create proxy object
+ return jsEngine.call(dataCache, getNode());
+ }
// TODO: Refactor, so that decoding of pragma is done separately
// TODO: life-cycle management of data objects according to node id
// Pragma exists and data has not been created yet
- if (!hasClavaData && dataPragma != null) {
+ // if (!hasClavaData && dataPragma != null) {
+ if (dataPragma != null) {
var node = getNode();
var tu = node instanceof TranslationUnit ? (TranslationUnit) node
: node.getAncestorTry(TranslationUnit.class).orElse(null);
@@ -1147,8 +1146,10 @@ public abstract class ACxxWeaverJoinPoint extends AJoinPoint {
try {
// Create object
- var newDataObject = jsEngine.eval("var _data = " + jsonString + "; _data;", JsFileType.MODULE,
- "[Java] ACxxWeaverJoinPoint.getDataImpl() [" + (jsNameCounter++) + "]");
+ var newDataObject = jsEngine.eval("var _data = " + jsonString + "; _data;");
+
+ // Create proxy function
+ var proxyBuilder = jsEngine.eval("var _data = _getClavaData; _data;");
// Create proxy object
return jsEngine.call(proxyBuilder, getNode(), newDataObject, jsDataPragma);
@@ -1161,9 +1162,10 @@ public abstract class ACxxWeaverJoinPoint extends AJoinPoint {
}
// Return data object from managed cache
- // Create proxy object
- return jsEngine.call(proxyBuilder, getNode());
+ var dataCache = jsEngine.eval("var _data = _getClavaData; _data;");
+ // Create proxy object
+ return jsEngine.call(dataCache, getNode());
}
@Override
