Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IOperation Analyzers and Fields #18915

Closed
Hosch250 opened this issue Apr 22, 2017 · 10 comments
Closed

IOperation Analyzers and Fields #18915

Hosch250 opened this issue Apr 22, 2017 · 10 comments
Labels
Area-Analyzers Concept-API This issue involves adding, removing, clarification, or modification of an API. Feature - IOperation IOperation

Comments

@Hosch250
Copy link
Contributor

Version Used: Latest Release

Steps to Reproduce:

  1. Create an analyzer that runs off of IOperation.
  2. Try to fire it on fields: OperationKind has field-related items FieldInitializerInCreation, FieldInitializerAtDeclaration, and FieldInitializerInCreation.

Expected Behavior: None of these fire on bool _foo;, which is expected given the names. I'd expect there to be a FieldDeclaration that fires on any FieldDeclarationSyntax node.

Actual Behavior: There is no OperationKind that makes the analyzer run on any field regardless of how it is written.

@CyrusNajmabadi: @jmarolf told me to make an issue for this and ping you.

@sharwell
Copy link
Member

sharwell commented Apr 23, 2017

@Hosch250 It sounds like what you want is a symbol analyzer, not an operation analyzer. These are easy to write for your described scenario.

@sharwell sharwell added the Feature - IOperation IOperation label Apr 23, 2017
@Hosch250
Copy link
Contributor Author

Hosch250 commented Apr 23, 2017

Oh sure, I know how to write those. I'm a bit confused on what all is what--better break out the search engine again. It's somewhat confusing, though, because there is OperationKind.VariableDeclaration, but no OperationKind.FieldDeclaration. A variable doesn't need to be assigned when it is declared, just like a field...

@CyrusNajmabadi
Copy link
Member

@Hosch250 IOperation is currently only a prototype. We're working on actually producing a full, real supported API for it. We'll keep your use case in mind as we go through our list of work items. Tagging @jinujoseph for visibility.

Note that I think is simply 'by design'. your "bool _foo;" is simply a field. A field initializer would be something like "bool _foo = code;" IOperation attempts to give you a rich semantic tree to represent the code that actually executes, not really the symbols that may be initialized from the code that executes.

@Hosch250
Copy link
Contributor Author

OK, thanks for the explanation. So, I should typically not write an analyzer off a syntax node, but should work with ISymbol and IOperation for analyzing symbols and operations?

@CyrusNajmabadi
Copy link
Member

@Hosch250 It really depends on what you're doing. :)

Lots of analyzers are suited to be written as syntax-analyzers. However, the benefit of IOperation over them is twofold:

  1. You get all the semantics in the operations, meaning you don't have to go back to the semantic model all the time with the nodes you're analyzing.
  2. You get VB+C# support generally for free.

The downside is that you are working on an abstraction. So if there was something particular to a specific language's syntax, then you wouldn't see that directly in the IOperation tree (though you could use teh SyntaxNode each operation exposes to track back to those pieces of syntax).

@Hosch250
Copy link
Contributor Author

OK, I'll write a few analyzers with it to see how it works better.

@CyrusNajmabadi
Copy link
Member

Take a look at https://github.com/dotnet/roslyn/blob/master/src/Features/Core/Portable/PopulateSwitch/PopulateSwitchDiagnosticAnalyzer.cs

It's an example of an analyzer that works for VB and C# without having any VB/C# specific code in it.

@Hosch250
Copy link
Contributor Author

Yup, I wrote that one originally, and then you rewrote it. That's where I first learned about IOperation, but school and other projects have kind of interfered with my learning it properly.

@CyrusNajmabadi
Copy link
Member

d'oh! I forgot about that :)

Note: learning about IOperation is definitely something you can do. But do take into account it's very much in flux. What is checked in now is simply a very rough prototype. And the work to actually produce a real API is going on as we speak.

@jinujoseph jinujoseph added the Concept-API This issue involves adding, removing, clarification, or modification of an API. label Apr 26, 2017
@jinujoseph
Copy link
Contributor

We're going to close this out currently as being unactionable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Analyzers Concept-API This issue involves adding, removing, clarification, or modification of an API. Feature - IOperation IOperation
Projects
None yet
Development

No branches or pull requests

5 participants