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

Jacob Carlborg doob at me.com
Fri Nov 27 20:47:37 UTC 2020


On 2020-11-26 20:04, Mihaela Chirea wrote:

> The main problem here is that there are quite a lot of node types using 
> stc this way so both of these options would require significant changes. 
> I'll check the locations of the rest of the nodes as well to see if any 
> of them include the storage classes.

I did some tests with the parser. For code like this: `const a = 3;`, 
the parser creates a `VarDeclaration` node, with the storage class set 
in `storage_class`. If the code looks like this: `const int a = 3;`, it 
creates the exact same node, but it also wraps that in a 
`StorageClassDeclaration` node. If the parse is already doing that, the 
semantic analyzer need to be able to handle both cases.

So you should be able to modify the first case so that it wraps the 
`VarDeclaration` inside a `StorageClassDeclaration`. Pass the same 
storage class to `StorageClassDeclaration` as the existing code passes 
to `VarDeclaration`. It only requires to add couple of lines here [1].

I've tested this. It works to parse and run the semantic analyzer on 
both of the above code snippets with the change to the parser applied. 
But I haven't run the full test suite.

[1] 
https://github.com/dlang/dmd/blob/860d0b2d2f24f3d0ef5cc12e4f43f12aa0e406c8/src/dmd/parse.d#L1270

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list