本文整理汇总了C#中Scope.AddError方法的典型用法代码示例。如果您正苦于以下问题:C# Scope.AddError方法的具体用法?C# Scope.AddError怎么用?C# Scope.AddError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Scope
的用法示例。
在下文中一共展示了Scope.AddError方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessContract
private static SyntaxNode ProcessContract(SyntaxNode node, Scope scope, SyntacticalExtension<SyntaxNode> extension)
{
if (extension.Kind == ExtensionKind.Code)
{
var block = extension.Body as BlockSyntax;
Debug.Assert(block != null);
List<StatementSyntax> checks = new List<StatementSyntax>();
foreach (var st in block.Statements)
{
var stExpression = st as ExpressionStatementSyntax;
if (stExpression == null)
{
scope.AddError("contract01", "contracts only support boolean expressions", st);
continue;
}
var contractCheck = ContractCheck
.ReplaceNodes(ContractCheck
.DescendantNodes()
.OfType<ExpressionSyntax>()
.Where(expr => expr.ToString() == "__condition"),
(oldNode, newNode) =>
stExpression.Expression);
checks.Add(contractCheck);
}
return CSharp.Block(checks);
}
scope.AddError("contract02", "contract cannot return a value", node);
return node;
}
示例2: ProcessSynch
private static SyntaxNode ProcessSynch(SyntaxNode node, Scope scope, SyntacticalExtension<SyntaxNode> extension)
{
if (extension.Kind == ExtensionKind.Code)
{
//td: verify it's inside an asynch
return SynchTemplate
.ReplaceNodes(SynchTemplate
.DescendantNodes()
.OfType<BlockSyntax>(),
(oldNode, newNode) => extension.Body);
}
scope.AddError("synch01", "synch does not return a value", node);
return node;
}
示例3: ProcessAsynch
private static SyntaxNode ProcessAsynch(SyntaxNode node, Scope scope, SyntacticalExtension<SyntaxNode> extension)
{
if (extension.Kind == ExtensionKind.Code)
{
var result = AsynchTemplate
.ReplaceNodes(AsynchTemplate
.DescendantNodes()
.OfType<BlockSyntax>(),
(oldNode, newNode) => extension.Body);
var document = scope.GetDocument<SyntaxToken, SyntaxNode, SemanticModel>();
document.change(node.Parent, RoslynCompiler.AddStatement(ContextVariable, before: node));
return result;
}
scope.AddError("asynch01", "asynch does not return a value", node);
return node;
}
示例4: Typedef
private static SyntaxNode Typedef(SyntaxNode node, Scope scope)
{
var field = node
.AncestorsAndSelf()
.OfType<FieldDeclarationSyntax>()
.FirstOrDefault();
if (field == null)
{
scope.AddError("xs01", "malformed typedef", node);
//td: error, malformed typedef
return node;
}
if (field.Declaration.Variables.Count != 1)
{
scope.AddError("xs01", "malformed typedef", node);
return node;
}
var variable = field
.Declaration
.Variables[0];
Debug.Assert(variable.Initializer == null || variable.Initializer.IsMissing);
var type = RoslynCompiler.UnMark(field.Declaration.Type);
var identifier = variable.Identifier;
var parentScope = scope.CreateScope<SyntaxToken, SyntaxNode, SemanticModel>(field.Parent);
Debug.Assert(parentScope != null);
parentScope.set("__tdef" + identifier.ToString(), type);
//schedule deletion
var document = scope.GetDocument<SyntaxToken, SyntaxNode, SemanticModel>();
document.change(field.Parent, RoslynCompiler.RemoveMember(field));
//return intact
return node;
}
示例5: TransformFoo
private static SyntaxNode TransformFoo(string id, object value, IEnumerable<InstanceConnection<SyntaxNode>> connections, Scope scope)
{
var decl = instanceCreation.Get(id, "RuntimeFoo");
scope.AddInstanceDeclaration(decl
.ReplaceNodes(decl
.DescendantNodes()
.OfType<ParameterListSyntax>(),
(on, nn) =>
{
var values = (value as InstanceFoo).Values;
return nn
.WithParameters(CSharp.SeparatedList(
values.Select(val => CSharp.Parameter(CSharp.Literal(val)))));
}));
foreach (var connection in connections)
{
if (connection.Input == null)
{
scope.AddError("test01", "unregistered connection", connection.OutputModelNode);
continue;
}
if (connection.Output == null)
{
scope.AddError("test01", "unregistered connection", connection.InputModelNode);
continue;
}
if (connection.Source == id)
connection.OutputNode = CSharp.ParseExpression(id + "." + connection.Output.Id);
else
{
Assert.IsTrue(connection.Target == id);
connection.InputNode = CSharp.ParseExpression(id + "." + connection.Input.Id);
}
}
return null;
}
示例6: ProcessMatch
private static SyntaxNode ProcessMatch(SyntaxNode node, Scope scope)
{
var switchExpr = node as SwitchStatementSyntax;
if (switchExpr == null)
{
scope.AddError("match01", "malformed match", node);
return node;
}
//store items to simplify
var cases = new List<ExpressionSyntax>();
var statements = new List<StatementSyntax>();
var defaultStatement = null as StatementSyntax;
foreach (var section in switchExpr.Sections)
{
bool isDefault;
var expr = caseExpression(section.Labels, switchExpr.Expression, out isDefault);
StatementSyntax statement = caseStatement(section.Statements);
if (isDefault && section.Labels.Count == 1)
{
defaultStatement = statement;
}
else
{
cases.Add(expr);
statements.Add(statement);
if (isDefault)
defaultStatement = statement;
}
}
//convert cases to ifs
Debug.Assert(cases.Count == statements.Count);
var last = cases.Count - 1;
IfStatementSyntax result = CSharp.IfStatement(cases[last], statements[last]);
if (defaultStatement != null)
result = result.WithElse(CSharp.ElseClause(defaultStatement));
for (int i = last - 1; i >= 0; i--)
{
result = CSharp.IfStatement(cases[i], statements[i])
.WithElse(CSharp.ElseClause(result));
}
return result;
}
示例7: Transform
private static SyntaxNode Transform(SyntaxNode oldNode, SyntaxNode newNode, Scope scope, LexicalExtension<SyntaxToken> extension)
{
Debug.Assert(newNode is BlockSyntax);
var isAssignment = oldNode is LocalDeclarationStatementSyntax;
if (!isAssignment && oldNode is BinaryExpressionSyntax)
{
var expr = oldNode as BinaryExpressionSyntax;
isAssignment = expr.Kind() == SyntaxKind.SimpleAssignmentExpression;
}
if (isAssignment)
{
scope.AddError("r01", "R does not return", oldNode);
return newNode;
}
var document = scope.GetDocument<SyntaxToken, SyntaxNode, SemanticModel>();
document.change(oldNode.Parent, RoslynCompiler.ExplodeBlock(newNode));
return newNode;
}