本文整理汇总了C#中SymbolTable.GetVariable方法的典型用法代码示例。如果您正苦于以下问题:C# SymbolTable.GetVariable方法的具体用法?C# SymbolTable.GetVariable怎么用?C# SymbolTable.GetVariable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SymbolTable
的用法示例。
在下文中一共展示了SymbolTable.GetVariable方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Check
private void Check(CodeElement e, SymbolTable table, FunctionCall call, FunctionDeclaration definition)
{
var parameters = definition.Profile.Parameters;
if (call.InputParameters.Count > parameters.Count) {
var m = System.String.Format("Function {0} only takes {1} parameters", definition.Name, parameters.Count);
DiagnosticUtils.AddError(e, m);
}
for (int c = 0; c < parameters.Count; c++) {
var expected = parameters[c];
if (c < call.InputParameters.Count) {
var actual = call.InputParameters[c];
if (actual.IsLiteral) continue;
var found = table.GetVariable(new URI(actual.Value));
if (found.Count < 1) DiagnosticUtils.AddError(e, "Parameter "+actual.Value+" is not referenced");
if (found.Count > 1) DiagnosticUtils.AddError(e, "Ambiguous reference to parameter "+actual.Value);
if (found.Count!= 1) continue;
var type = found[0] as Typed;
// type check. please note:
// 1- if only one of [actual|expected] types is null, overriden DataType.!= operator will detect it
// 2- if both are null, we WANT it to break: in TypeCobol EVERYTHING should be typed,
// and things we cannot know their type as typed as DataType.Unknown (which is a non-null valid type).
if (type == null || type.DataType != expected.DataType) {
var m = System.String.Format("Function {0} expected parameter {1} of type {2} (actual: {3})", definition.Name, c+1, expected.DataType, type.DataType);
DiagnosticUtils.AddError(e, m);
}
if (type != null && type.Length > expected.Length) {
var m = System.String.Format("Function {0} expected parameter {1} of max length {2} (actual: {3})", definition.Name, c+1, expected.Length, type.Length);
DiagnosticUtils.AddError(e, m);
}
} else {
var m = System.String.Format("Function {0} is missing parameter {1} of type {2}", definition.Name, c+1, expected.DataType);
DiagnosticUtils.AddError(e, m);
}
}
}