NTP Analyzer  0.8.2
Analyze the operation of time servers
HostGraphPageSyntaxNode.cs
Go to the documentation of this file.
1 //
2 // Copyright (c) 2013-2017 Carsten Sonne Larsen <cs@innolan.net>
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a copy
5 // of this software and associated documentation files (the "Software"), to deal
6 // in the Software without restriction, including without limitation the rights
7 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 // copies of the Software, and to permit persons to whom the Software is
9 // furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 // THE SOFTWARE.
21 
22 using System;
23 using System.Collections.Generic;
24 using System.Linq;
27 using Ntp.Analyzer.Config.Table;
28 
29 namespace Ntp.Analyzer.Config.Syntax
30 {
31  public sealed class HostGraphPageSyntaxNode : SyntaxNode<HostGraphPageConfiguration>
32  {
33  public HostGraphPageSyntaxNode(string name, int line)
34  : base(Symbol.KeywordHostGraphPage, name, line, true)
35  {
36  }
37 
38  private Uri location;
40 
42  {
43  var frequency = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordFrequency) as IntegerSettingNode;
44  var initialRun = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordInitialRun) as BooleanSettingNode;
45  var fixedRun = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordFixedRun) as BooleanSettingNode;
46  var linkIndex = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordLinkIndex) as IntegerSettingNode;
47  var dest = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordDestinations) as DirDestinationSyntaxNode;
48 
49  return new HostGraphPageConfiguration(
50  Name,
51  frequency?.Value,
52  initialRun?.Value,
53  fixedRun?.Value,
54  linkIndex?.Value,
55  pageNode.Compile(),
56  dest?.Compile(),
57  location
58  );
59  }
60 
61  protected override void InternalResolve(SymbolTable table)
62  {
63  var name = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordGraphPage) as StringSettingNode;
64  if (name != null)
65  pageNode = table.Lookup(name.Value) as HostPageSyntaxNode;
66  }
67 
68  protected override void ValidateMandatories()
69  {
70  CheckIsUnique(new List<Symbol>
71  {
72  Symbol.KeywordFrequency,
73  Symbol.KeywordInitialRun,
74  Symbol.KeywordFixedRun,
75  Symbol.KeywordLinkIndex,
76  Symbol.KeywordGraphPage,
77  Symbol.KeywordLink,
78  Symbol.KeywordDestinations
79  });
80 
81  CheckAllIsPresent(new List<Symbol>
82  {
83  Symbol.KeywordGraphPage,
84  Symbol.KeywordDestinations
85  });
86  }
87 
88  protected override void ValidateReferences(SymbolTable table)
89  {
90  var pageName = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordGraphPage) as StringSettingNode;
91  if (pageName != null)
92  {
93  string keyword = Keyword.Find(Symbol.KeywordGraphPage).Name;
94 
95  var reference = table.Lookup(pageName.Value);
96  if (reference == null)
97  {
98  AddReferenceNameError(pageName, keyword, pageName.Value);
99  }
100  else if (!(reference is HostPageSyntaxNode))
101  {
102  string hostPageKeyword = Keyword.Find(Symbol.KeywordHostPage).Name;
103  AddReferenceTypeError(pageName, keyword, hostPageKeyword, pageName.Value);
104  }
105  }
106 
107  var link = Nodes.SingleOrDefault(n => n.Symbol == Symbol.KeywordLink) as StringSettingNode;
108  if (link == null)
109  return;
110 
111  var linkKeyword = Keyword.Find(Symbol.KeywordLink).Name;
112  location = CheckLink(link.Value, linkKeyword);
113  }
114 
115  protected override void ValidateTypes()
116  {
117  CheckTypeIs<IntegerSettingNode>(Symbol.KeywordFrequency);
118  CheckTypeIs<BooleanSettingNode>(Symbol.KeywordInitialRun);
119  CheckTypeIs<BooleanSettingNode>(Symbol.KeywordFixedRun);
120  CheckTypeIs<IntegerSettingNode>(Symbol.KeywordLinkIndex);
121  CheckTypeIs<StringSettingNode>(Symbol.KeywordGraphPage);
122  CheckTypeIs<StringSettingNode>(Symbol.KeywordLink);
123  }
124  }
125 }
override void ValidateMandatories()
Override to validates the mandatory types in this syntax node.
override HostGraphPageConfiguration InternalCompile()
static Keyword Find(Symbol symbol)
Definition: Keyword.cs:216
ISyntaxNode Lookup(string name)
Definition: SymbolTable.cs:41
override void ValidateTypes()
Override to validates the types in this syntax node.