www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - how to instrument dmd compiler to dump all references to a given

reply Timothee Cour <thelastmammoth gmail.com> writes:
eg:

how to instrument dmd compiler to dump all references to a given symbol?
eg: for `A.a` it should output the locations marked with HERE
any help/starting points would be appreciated!

```
Struct A{
int a;
 void fun(){
  a++; // HERE
  alias b=a;
 b++; // HERE
 }
}

void fun(){
 int a; // NOT HERE
 A b;
 b.a ++ ; // HERE
}
```
Jan 13 2018
next sibling parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Sunday, 14 January 2018 at 02:36:02 UTC, Timothee Cour wrote:
 how to instrument dmd compiler to dump all references to a 
 given symbol?
you can actually do it with your own code. behold: struct A{ //int a; // comment this line int _a; // make the actual var renamed... // then add a ref property with template file/line params property ref int a(string file = __FILE__, size_t line = __LINE__)() { pragma(msg, file); // and print those out pragma(msg, line); return _a; } void fun(){ a++; // HERE alias b=a; b++; // HERE } } void fun(){ int a; // NOT HERE A b; b.a ++ ; // HERE } Can be a bit trickier in other cases but there's a compile time list of uses.
Jan 13 2018
parent Shachar Shemesh <shachar weka.io> writes:
On 14/01/18 04:42, Adam D. Ruppe wrote:
 On Sunday, 14 January 2018 at 02:36:02 UTC, Timothee Cour wrote:
 how to instrument dmd compiler to dump all references to a given symbol?
you can actually do it with your own code. behold: struct A{ //int a; // comment this line int _a; // make the actual var renamed...
It wouldn't catch this use: auto hiddenUser(T)(T t) { static if( __traits(hasMember, T, "a") ) { return T.a; } else { return 17; } } ... A var; hiddenUser(var);
Jan 13 2018
prev sibling parent Seb <seb wilzba.ch> writes:
On Sunday, 14 January 2018 at 02:36:02 UTC, Timothee Cour wrote:
 eg:

 how to instrument dmd compiler to dump all references to a 
 given symbol?
 eg: for `A.a` it should output the locations marked with HERE
 any help/starting points would be appreciated!

 ```
 Struct A{
 int a;
  void fun(){
   a++; // HERE
   alias b=a;
  b++; // HERE
  }
 }

 void fun(){
  int a; // NOT HERE
  A b;
  b.a ++ ; // HERE
 }
 ```
I don't know what you are trying to achieve, but `deprecated` could work for you. At least it's an easy way to get all locations using a symbol: https://run.dlang.io/is/ICv9lH
Jan 13 2018