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.Collections.Generic;
9 using System.Linq;
10 using Sprache;
11 
12 namespace Antmicro.Renode.PlatformDescription.Syntax
13 {
14     public sealed class InitAttribute : Attribute
15     {
InitAttribute(IEnumerable<string> lines, bool isAdd)16         public InitAttribute(IEnumerable<string> lines, bool isAdd)
17         {
18             Lines = lines.ToArray();
19             IsAdd = isAdd;
20         }
21 
22         public bool IsAdd { get; private set; }
23         public IEnumerable<string> Lines { get; private set; }
24 
Merge(InitAttribute other)25         public InitAttribute Merge(InitAttribute other)
26         {
27             if(other.IsAdd)
28             {
29                 // the result is a modified init attribute, which has the same position information as the original init attribute
30                 // this can be a problem if validation depends on specific stamements of init, not on the existence of init per se
31                 // in such case an init statement should be changed to be a separate grammar unit which is .Positioned
32                 Lines = Lines.Concat(other.Lines);
33                 return this;
34             }
35             return other;
36         }
37     }
38 
39     // the class is there because we are not able to have position aware IEnumerable
40 }
41