Specman: how to retrieve values of var which is stored in another var - specman

I have stored var name in another var and I want to retrieve values from original var.
for ex:
var var_A: list of uint = {1,3,2};
var var_A_str:string = "var_A";
//Now i want to print var_A list of values using var_A_str. How can i do that?
print $var_A_str;

This is called introspection or reflection. You have to use Specman's rf_manager. Search for it in the docs. However, the docs don't show you all the methods that this unit has. If you really want to see all the methods, run this snippet of code:
extend sys {
run() is also {
var rf_man : rf_struct = rf_manager.get_exact_subtype_of_instance(rf_manager);
out(" RF Manager:");
for each (meth) in rf_man.get_declared_methods() {
print meth;
};
};
};
I'm not sure how to iterate through the list elements, but you can use this snippet to look at the methods on a reference to an object's instance members ( not a subroutine's variable).
extend sys {
A : list of uint;
keep A == {1;3;2};
run() is also {
var variable_name := "A";
var rf_obj: rf_struct = rf_manager.get_exact_subtype_of_instance(sys);
var rf_i : rf_field = rf_obj.get_field(variable_name);
print rf_i;
var rf_rf_i := rf_manager.get_exact_subtype_of_instance(rf_i);
out ( "#\n# RF_RFI\n#");
for each (meth) in rf_rf_i.get_declared_methods() {
print meth;
};
};
};
In my version ( 8.2 ) this prints:
Starting the test ...
Running the test ...
rf_i = rf_field 'A', line 7 in #rf_test4
#
# RF_RFI
#
meth = rf_method 'get_type', Specman's private modules
meth = rf_method 'is_physical', Specman's private modules
meth = rf_method 'get_svtp_pack', Specman's private modules
meth = rf_method 'set_svtp_pack', Specman's private modules
meth = rf_method 'is_ungenerated', Specman's private modules
meth = rf_method 'is_const', Specman's private modules
meth = rf_method 'is_unit_instance', Specman's private modules
meth = rf_method 'is_port_instance', Specman's private modules
meth = rf_method 'is_reference', Specman's private modules
meth = rf_method 'get_constrained_types', Specman's private modules
meth = rf_method 'get_deep_copy_attr', Specman's private modules
meth = rf_method 'get_value', Specman's private modules
meth = rf_method 'set_value', Specman's private modules
meth = rf_method 'get_value_unsafe', Specman's private modules
meth = rf_method 'get_all_when_value_unsafe', Specman's private modules
meth = rf_method 'set_value_unsafe', Specman's private modules
meth = rf_method 'set_value_const_reassign_unsafe', Specman's private modules
meth = rf_method 'get_interface_port_prefix', Specman's private modules
meth = rf_method 'get_interface_port_suffix', Specman's private modules
meth = rf_method 'is_gen_intelligen', Specman's private modules
meth = rf_method 'get_long_name', Specman's private modules
meth = rf_method 'get_implicit_constraints', Specman's private modules
meth = rf_method 'make_path', Specman's private modules
meth = rf_method 'make_element', Specman's private modules
meth = rf_method 'make_list_size_path', Specman's private modules
meth = rf_method 'is_unit_reference', Specman's private modules
meth = rf_method 'get_id_name_for_port_type', Specman's private modules
meth = rf_method 'get_list_upper_bound', Specman's private modules
meth = rf_method 'get_sv_typename', Specman's private modules
meth = rf_method 'get_sv_name_under_when', Specman's private modules
meth = rf_method 'get_sv_size', Specman's private modules
meth = rf_method 'sv_add_encode_lines', Specman's private modules
meth = rf_method 'sv_get_decode_function_local_var_name', Specman's private modules
meth = rf_method 'sv_get_decode_function_local_var_decl', Specman's private modules
meth = rf_method 'sv_add_decode_lines', Specman's private modules
meth = rf_method 'get_sv_field_name', Specman's private modules
meth = rf_method 'get_sv_field', Specman's private modules
meth = rf_method 'sv_must_be_protected_field', Specman's private modules
meth = rf_method 'sv_add_get_set_field_functions', Specman's private modules
meth = rf_method 'sv_add_get_set_field_function_decs', Specman's private modules
meth = rf_method 'is_sv_exported_field', Specman's private modules
meth = rf_method 'is_sv_determinant_field', Specman's private modules
meth = rf_method 'field_configured_to_svtp_pack', Specman's private modules
meth = rf_method 'get_ovm_field_macro', Specman's private modules
meth = rf_method 'is_internal', Specman's private modules
meth = rf_method 'get', Specman's private modules
meth = rf_method 'eanalyze_lnt', Specman's private modules
No actual running requested.
Checking the test ...
Checking is complete - 0 DUT errors, 0 DUT warnings.
I'm sure there's a way to do what you want, but it can be very difficult to use Specman's reflection interface.
Merry hacking!

Related

Sbt nested dependsOn

I have a root project that depends on a subproject1. And subproject1 depends on subproject2.
Does that imply that I Can use subproject2's source code directly in root?
lazy val root =
Project(id = "root", base = file(".")).dependsOn(sub1)
lazy val sub1 =
Project(id = "sub1").dependsOn(sub2)
lazy val sub2 =
Project(id = "sub2")
Yes.
This can easily be checked.
build.sbt
name := "sbtdemo"
version := "0.1"
ThisBuild / scalaVersion := "2.13.4"
lazy val root =
Project(id = "root", base = file(".")).dependsOn(sub1)
lazy val sub1 =
Project(id = "sub1", base = file("sub1")).dependsOn(sub2)
lazy val sub2 =
Project(id = "sub2", base = file("sub2"))
sub2/src/main/scala/App.scala
object App {
def foo() = println("foo")
}
src/main/scala/Main.scala
object Main {
def main(args: Array[String]): Unit = {
App.foo() // foo
}
}
Yes. From Classpath dependencies by sbt:
lazy val core = project.dependsOn(util)
Now code in core can use classes from util. This also creates an ordering between the projects when compiling them; util must be updated and compiled before core can be compiled.

Scala 2.12 interop with java 1.8 doesn't compile for twitter finagle code

I've Java polyglot application which mainly has Java code and uses few Scala libraries as well.
The Scala below code compiles fine.
import com.twitter.finagle.{Http, Service}
import com.twitter.finagle.http.{Request, Response}
import com.twitter.finagle.stats.StatsReceiver
import com.twitter.finagle.tracing.Tracer
import com.twitter.util.Duration
private val loggerFinagle = java.util.logging.Logger.getLogger("FinagleLogger")
val statsReceiver: StatsReceiver = ???
val tracer: Tracer = ???
val requestTimeout: Duration = ???
val connectTimeout: Duration = ???
val client: Service[Request, Response] = Http.client
.withLabel("clientname")
.withStatsReceiver(statsReceiver)
.withTracer(tracer)
.withRequestTimeout(requestTimeout)
.withTransport.connectTimeout(???)
.withSessionQualifier.noFailureAccrual
.withSessionQualifier.noFailFast
.withSession.acquisitionTimeout(connectTimeout)
.withSessionPool.maxSize(1)
.newService("localhost:10000,localhost:10001")
I write the same code in java as below
import com.twitter.finagle.Http;
import com.twitter.finagle.stats.StatsReceiver;
import com.twitter.finagle.tracing.Tracer;
import com.twitter.util.Duration;
public class JavaMain {
public static void main(String[] args) {
StatsReceiver statsReceiver = null;
Tracer tracer = null;
Duration requestTimeout =null;
Duration connectTimeout = null;
Http.client()
.withLabel("clientname")
.withStatsReceiver(statsReceiver)
.withTracer(tracer)
.withRequestTimeout(requestTimeout)
.withTransport.connectTimeout(connectTimeout)
.withSessionQualifier.noFailureAccrual()
.withSessionQualifier.noFailFast()
.withSession.acquisitionTimeout(connectTimeout)
.withSessionPool.maxSize(1)
.newService("localhost:10000,localhost:10001");
}
}
When I compile the above java code, I get below errors -
[info] Done updating.
[error] /Users/rajkumar.natarajan/eclipse-workspace/FinagleDemo/chapter1/src/main/java/JavaMain.java:19:1: withTransport has private access in com.twitter.finagle.Http.Client
[error] .withTransport.connectTimeout(connectTimeout)
[error] /Users/rajkumar.natarajan/eclipse-workspace/FinagleDemo/chapter1/src/main/java/JavaMain.java:20:1: withSessionQualifier has private access in com.twitter.finagle.Http.Client
[error] .withSessionQualifier.noFailureAccrual()
[error] /Users/rajkumar.natarajan/eclipse-workspace/FinagleDemo/chapter1/src/main/java/JavaMain.java:21:1: withSessionQualifier has private access in com.twitter.finagle.Http.Client
[error] .withSessionQualifier.noFailFast()
[error] /Users/rajkumar.natarajan/eclipse-workspace/FinagleDemo/chapter1/src/main/java/JavaMain.java:22:1: withSession has private access in com.twitter.finagle.Http.Client
[error] .withSession.acquisitionTimeout(connectTimeout)
[error] /Users/rajkumar.natarajan/eclipse-workspace/FinagleDemo/chapter1/src/main/java/JavaMain.java:23:1: withSessionPool has private access in com.twitter.finagle.Http.Client
[error] .withSessionPool.maxSize(1)
[error] (chapter1 / Compile / compileIncremental) javac returned non-zero exit code
The project in github is here.
Below are dependency details of my project -
Scala Version - 2.12.6
Java Version - 1.8.0_151
finagle version - 7.1.0
Any idea how can I make the java code work?
You forgot that in Java methods are called with brackets (). Without them you actually tried to call not methods (getters) but fields themselves and they have private access.
Correct Java translation is
Http.client()
.withLabel("clientname")
.withStatsReceiver(statsReceiver)
.withTracer(tracer)
.withRequestTimeout(requestTimeout)
.withTransport().connectTimeout(connectTimeout)
.withSessionQualifier().noFailureAccrual()
.withSessionQualifier().noFailFast()
.withSession().acquisitionTimeout(connectTimeout)
.withSessionPool().maxSize(1)
.newService("localhost:10000,localhost:10001");

Intellj doesn't see changes in multi project sbt

I have a multi module sbt project. When I change some source code in a module, other modules don't see the changes in IntelliJ .
When I try to navigate, it goes to declaration, instead of navigating to the source it navigates to compiled jar file.
It works fine when I remove the jar from library dependencies in project settings. I think because it recompiles so works fine till next change. And sbt compiles works fine but I guess problem because of Build.scala settings, project dependencies can have order issues. Here is the dependencies;
lazy val root = Project(id = "xx-main", base = file("."), settings = commonSettings)
.aggregate(utils, models, commons, dao, te)
.dependsOn(utils, models, commons, dao)
lazy val utils = Project(id = "xx-utils", base = file("xx-utils"))
.settings(commonSettings: _*)
lazy val commons = Project(id = "xx-commons", base = file("xx-commons"))
.settings(commonSettings: _*)
.dependsOn(utils, models)
lazy val models =
Project(id = "xx-models", base = file("xx-models"), settings = commonSettings)
.dependsOn(utils)
lazy val dao = Project(id = "xx-dao", base = file("xx-dao"))
.settings(commonSettings: _*)
.dependsOn(utils, models)
lazy val te = Project(id = "xx-te", base = file("xx-te"))
.settings(commonSettings: _*)
.dependsOn(utils, models, dao, commons)

Deep nesting of project folder in a SBT multi-project project

I have an SBT project that aggregates over multiple projects like this:
object ClientCore extends Build {
/**
* This is the root project
*/
lazy val rootProj = Project(id = "clientcore", base = file(".")) aggregate(
utilsProj,
commonUiProj,
spatialMathProj,
sessionManagerProj,
lobbyProj,
)
/**
* This is a utils library
*/
lazy val utilsProj = Project(id = "utils", base = file("Utils"))
/**
* A shared library for UI elements
*/
lazy val commonUiProj = Project(id = "commonui", base = file("CommonUI"))
/**
* This is a spatial math library
*/
lazy val spatialMathProj = Project(id = "spatialmath", base = file("SpatialMath"))
lazy val sessionManagerProj = Project(id = "sessionmanager", base = file("sessionManager"),
settings = buildSettings ++ assemblySettings) settings(
outputPath in assembly := new File(s"$outDir\\SessionManagerClient.jar"),
jarName in assembly := "SessionManagerClient.jar",
test in assembly := {}
) dependsOn(utilsProj)
lazy val lobbyProj = Project(id = "lobby", base = file("Lobby"),
settings = buildSettings ++ assemblySettings) settings(
outputPath in assembly := new File(s"$outDir\\Lobby.jar"),
jarName in assembly := "Lobby.jar",
test in assembly := {}
) dependsOn(utilsProj)
}
For some reason some of the projects end up with a deep nesting of 'project' folders. For example Utils might look like: 'Util/project/project/project/project/...
I'm using Intellij's SBT plugin to sync the presentation but managing the project with SBT. I'm not certain whether this is an SBT issue or an Intellij one.
Thanks for any help you can provide.
Kurt
This is an IntelliJ issue (among many others related to the SBT plugin...)
I think you may have refreshed your config somewhere before defining a module and adding that module to the root project aggregates, which has a tendency to make a mess in IntelliJ.
This can be fixed in IntelliJ:
detach your project from IntelliJ
restart IntelliJ
reimport your project

How to enable sbt plugins of root project for all subprojects?

I have a project/build.scala file that defines a root project and a bunch of sub projects:
lazy val root = Project(
id="root",
base=file(".")).aggregate(subA, subB).enablePlugins(MyPlugin)
lazy val subA = Project(
id="subA",
base=file("a"))
lazy val subB = Project(
id="subB",
base=file("b"))
How do I make MyPlugin available in subA and subB without specifying it on each of them? I just want them to inherit the plugins from the root project.
Someone in IRC suggested overriding projects in my build object in build.scala:
override def projects = super.projects map { _.enablePlugins(...) }