Mihaela Chirea - SAOC 2020 Milestone 2 Update 2 - Improving DMD as a Library

Mihaela Chirea chireamihaela99 at gmail.com
Mon Nov 9 18:32:38 UTC 2020


> The start position needs to point to the first byte of the AST 
> node. If you want to get the location of some specific part of 
> a node, you should access the smallest sub node and then re-lex 
> the source range the sub node occupies (when source ranges are 
> available). Then you can get the location of the specific token 
> you're interested in, like the identifier. At this point you 
> already know the semantic meanings of the tokens, so it 
> shouldn't be any problem.

That makes sense. Thanks for explaining!

>> - StaticForeachDeclaration: this one contains a StaticForeach 
>> which already starts at `static` so I'm not sure if adding it 
>> here as well would be necessary
>
> All AST nodes should have a location. Otherwise more special 
> casing in the code is required when operating on the nodes. Do 
> you know why there are two nodes? Do they have the same meaning?

StaticForeach[1] is not an AST node. It's just an object used to 
keep the common parts of the StaticForeachDeclaration[2] and 
StaticForeachStatement[3] nodes.

[1] https://github.com/dlang/dmd/blob/master/src/dmd/cond.d#L95
[2] 
https://github.com/dlang/dmd/blob/master/src/dmd/attrib.d#L1114
[3] 
https://github.com/dlang/dmd/blob/master/src/dmd/statement.d#L1532


More information about the Digitalmars-d mailing list