| Thread overview | ||||||
|---|---|---|---|---|---|---|
|
January 13, 2018 how to instrument dmd compiler to dump all references to a given symbol? | ||||
|---|---|---|---|---|
| ||||
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
}
```
| ||||
January 14, 2018 Re: how to instrument dmd compiler to dump all references to a given symbol? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Timothee Cour | 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.
| |||
January 14, 2018 Re: how to instrument dmd compiler to dump all references to a given symbol? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | 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);
| |||
January 14, 2018 Re: how to instrument dmd compiler to dump all references to a given symbol? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Timothee Cour | 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 | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply