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

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();
主站蜘蛛池模板: 嘉鱼县| 疏附县| 海林市| 阿巴嘎旗| 余江县| 全州县| 育儿| 循化| 太和县| 大方县| 贵州省| 香格里拉县| 三江| 饶阳县| 安康市| 易门县| 娄底市| 宿迁市| 阳泉市| 石嘴山市| 临桂县| 阿拉善左旗| 廊坊市| 林芝县| 顺昌县| 南宫市| 岳阳县| 长乐市| 新和县| 澄江县| 磐安县| 正宁县| 青浦区| 永仁县| 社会| 肥西县| 江油市| 克山县| 西安市| 澜沧| 泗阳县|