0

Here's the output from the console,

Debug print..
exprNode(
  assign(
    var(name(name("alpha")))[
      @at=|file:///Users/apil/Dropbox/Scripts/Class_Based_Analysis/SimpleClass_CopyObject.php|(56,6,<9,0>,<9,0>),
      @scope="scope"("","","",""),
      @decl=|php+variable:///alpha|,
      @phpdoc="",
      @lab=lab(3)
    ],
    new(
      name(name("MyClass")[
          @at=|file:///Users/apil/Dropbox/Scripts/Class_Based_Analysis/SimpleClass_CopyObject.php|(67,7,<9,0>,<9,0>),
          @scope="scope"("","","",""),
          @phpdoc=""
        ]),
      [])[
      @at=|file:///Users/apil/Dropbox/Scripts/Class_Based_Analysis/SimpleClass_CopyObject.php|(63,13,<9,0>,<9,0>),
      @scope="scope"("","","",""),
      @phpdoc="",
      @lab=lab(4)
    ])[
    @at=|file:///Users/apil/Dropbox/Scripts/Class_Based_Analysis/SimpleClass_CopyObject.php|(56,20,<9,0>,<9,0>),
    @scope="scope"("","","",""),
    @phpdoc="",
    @lab=lab(5)
  ],
  lab(5))[
  @lab=lab(5)
]
var(name(name("alpha")))[
  @at=|file:///Users/apil/Dropbox/Scripts/Class_Based_Analysis/SimpleClass_CopyObject.php|(56,6,<9,0>,<9,0>),
  @scope="scope"("","","",""),
  @decl=|php+variable:///alpha|,
  @phpdoc="",
  @lab=lab(3)
]
|rascal://soft::typing::php::elements::Identifier|(1678,6,<54,10>,<54,16>): get-annotation not supported on value at |rascal://soft::typing::php::elements::Identifier|(1678,6,<54,10>,<54,16>)
☞ Advice

and here's the script responsible for generating the content:

LabelToIdentifierMap mapp=( );
println("Debug print..");
iprintln(cfgNode);
result=[e | /assign(e,_):=cfgNode];

if(isEmpty(result))
    return mapp;

result=getElementFromSingletonList(result);
iprintln(result);
if(var(name(name(str x))):=result)
    mapp +=(result@lab:var(x));
else if(propertyFetch(var(name(name(str x))),name(name(str y))):=result)
    mapp +=(result@lab:propertySet(var(x),var(y)));
else
    throw "Unsupported expression encountered at left hand side of an assignment node.\n"+
    "Got: <result>. Error loc: 510142847";   
return mapp;

My concern is that the output of variable "result": var(name(name("alpha")))[ @at=... ] shows that there is an annotation @lab in the attached with the variable. Why am I unable to retrieve it? Also, how may I retrieve it if that's possible at all!

apil.tamang
  • 2,545
  • 7
  • 29
  • 40

1 Answers1

0

The reason can be several things.

  • At least the language must know the type of the value you want to address the annotation on. Currently that type is value, which is not specific enough. I don't know why this is happening in your example because not all details are given. It could very well be that getElementFromSingletonList returns a value? I'd use result[0] or write a type parameterized function which returns the type of the element: &T get([&T elem]) = elem;
  • Annotations must be declared before they can be used, as in anno int MyExpressionType@lab; or anno int node@label;. This can only be done for the node type or defined data types.

So when the receiver of @ is typed well and the label of the annotation is declared, then it will work as expected:

 data MyExp = bla();
 anno int MyExp@label;
 MyExp example = bla()[@label=1];
 println(example@label); // prints 1
Jurgen Vinju
  • 6,393
  • 1
  • 15
  • 26
  • Thanks.. it makes sense. However, I do use a parameterized function to return the element from "getElementFromSingletonList(..)". This function ensures that the passed argument is a list with only a single element and throws an exception otherwise. I think this may fix the problem.. result=[e | /assign(Expr e,_):=cfgNode], as now the pattern is explicitly matched to an Expr type, for which the annotations are rightfully declared. Any thoughts?? – apil.tamang Jan 29 '15 at 21:40
  • 1
    It would help to see the function signature, but if it's something like `value getElementFromSingletonList(list[value] l)` it would be better to have `&T getElementFromSingletonList(list[&T] l)` so it would maintain the type of the element. – Mark Hills Jan 30 '15 at 12:24