1 //
2 // Copyright (c) 2010-2018 Antmicro
3 //
4 // This file is licensed under the MIT License.
5 // Full license text is available in 'licenses/MIT.txt'.
6 //
7 
8 using System;
9 using System.Collections.Generic;
10 using System.Linq;
11 using Antmicro.Renode.PlatformDescription.Syntax;
12 using Sprache;
13 
14 namespace Antmicro.Renode.PlatformDescription
15 {
16     public sealed class Variable
17     {
Variable(Type variableType, DeclarationPlace declarationPlace)18         public Variable(Type variableType, DeclarationPlace declarationPlace)
19         {
20             associatedEntries = new List<Entry>();
21             VariableType = variableType;
22             DeclarationPlace = declarationPlace;
23         }
24 
AddEntry(Entry entry)25         public void AddEntry(Entry entry)
26         {
27             associatedEntries.Add(entry);
28         }
29 
GetMergedEntry()30         public Entry GetMergedEntry()
31         {
32             if(associatedEntries.Count == 0)
33             {
34                 return null;
35             }
36             var entriesToMerge = associatedEntries.ToList();
37             Entry result = entriesToMerge[0];
38             result = entriesToMerge.Skip(1).Aggregate(entriesToMerge[0], (x, y) => x.MergeWith(y));
39             result.Variable = this;
40             return result;
41         }
42 
43         public Type VariableType { get; set; }
44         public DeclarationPlace DeclarationPlace { get; set; }
45         public object Value { get; set; }
46 
47         private readonly List<Entry> associatedEntries;
48     }
49 
50 }
51