tgjones / HlslTools

A Visual Studio extension that provides enhanced support for editing High Level Shading Language (HLSL) files
http://timjones.io/blog/archive/2016/04/25/hlsl-tools-for-visual-studio-v1.0-released
Other
562 stars 97 forks source link

Generate HLSL syntax nodes #132

Closed Jjagg closed 5 years ago

Jjagg commented 5 years ago

This PR will use the SyntaxGenerator project to generate HLSL syntax nodes from a config file, the same way Roslyn does it. Generated code will implement the following:

I'm currently throwing out some Roslyn code that's related to how they expose their syntax trees that's not relevant to this project. Roslyn uses what they call green and red trees. The red tree is an internal, mutable tree, used for performance while the green tree is the exposed layer on top that cannot be mutated by consumers directly. It's pretty neat, but also very complex.

@tgjones Putting this WIP PR up so progress can be tracked and commented.

Jjagg commented 5 years ago

@tgjones All SyntaxNodes are done!

I'm not sure how to best reference the SyntaxGenerator project to ensure it's built before the generator .targets file is run. I'm inexperienced with msbuild. I looked around a bit, and it seems there's an issue with build-time dependencies in the case where target frameworks are not compatible (Microsoft/msbuild#2661). 632673f might just do the trick though.

Some inconsistencies I came across and changed:

Visit method renames (breaking change for visitors)

VisitPrefixCastExpression => VisitCastExpression VisitFieldAccess => VisitFieldAccessExpression VisitNumericConstructorInvocation => VisitNumericConstructorInvocationExpression VisitSkippedTokensSyntaxTrivia => VisitSkippedTokensTrivia

Incorrect SyntaxKinds

MacroArgumentListSyntax had SyntaxKind VariableDeclarator ParameterListSyntax had SyntaxKind ArgumentList (SyntaxKind.ParameterList did not exist) VariableDeclaratorSyntax had SyntaxKind ArgumentList

tgjones commented 5 years ago

This is amazing work, thank you! PRs that have the effect of removing ~1000 LOC are the best kind :)

Jjagg commented 5 years ago

Yay! :) I'll see if I can find some time to move along with the SyntaxRewriter next.