官术网_书友最值得收藏!

Creating a syntax node analyzer to report issues about language syntax

A syntax node analyzer registers action callbacks to analyze one or more kinds of syntax nodes, such as operators, identifiers, expressions, declarations, and so on, and reports semantic issues about syntax. These analyzers generally need to fetch semantic information about different syntax nodes being analyzed and use the compiler semantic model APIs to get this information.

In this section, we will create a syntax analyzer that analyzes VariableDeclarationSyntax nodes for local declarations and reports a diagnostic recommending use of the explicit type instead of an implicitly typed declaration, that is, variables defined with the keyword var, such as var i = new X();. Analyzer will not report diagnostics if there is a compiler syntax error (implicitly typed declarations cannot define more than one variable), or the right side of the assignment has an error type or special System type such as int, char, string, and so on. For example, the analyzer will not flag locals local1, local2, and local3 here, but will flag local4.

int local1 = 0;
Class1 local2 = new Class1();
var local3 = 0;
var local4 = new Class1();
主站蜘蛛池模板: 子洲县| 双鸭山市| 阿合奇县| 读书| 寿光市| 仁化县| 汾西县| 宁河县| 庆安县| 新昌县| 阿克陶县| 南陵县| 大同市| 泸州市| 黄冈市| 奉化市| 报价| 江北区| 利川市| 山西省| 灵寿县| 长宁县| 五原县| 金川县| 新沂市| 清水县| 新源县| 临高县| 陇南市| 宿松县| 渑池县| 盖州市| 宜良县| 讷河市| 上思县| 特克斯县| 乌兰浩特市| 凭祥市| 大新县| 麻江县| 昭苏县|