| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
 | import java.util.Map;
import java.util.HashMap;
import java.util.Set;
import java.io.FileNotFoundException;
import java.io.IOException;
public class Models
{
   public static Map<String, String> IS_IN_FILE;
   public static Map<String, String> IS_IN_ARCHITECTURE;
   public static Map<String, String> IS_IN_ENTITY;
   static
   {
      IS_IN_FILE = new HashMap<String, String>();
      IS_IN_ARCHITECTURE = new HashMap<String, String>();
      IS_IN_ENTITY = new HashMap<String, String>();
   }
   public static boolean load_file (final String filename)
   throws FileNotFoundException
   {
      final QuickParser qp;
      String[] input;
      qp = new QuickParser(filename);
      for (;;)
      {
         try
         {
            input = qp.parse_line();
            if (input == null)
            {
               qp.finalize();
               return false;
            }
            else if (input.length == 0)
            {
               qp.finalize();
               break;
            }
         }
         catch (final IOException e)
         {
            System.err.println
            (
               "[E] IO error while parsing file \""
               + filename
               + "\":"
               /* FIXME: can be null */
               + e.getMessage()
            );
            return false;
         }
         if (input[0].equals("set_function"))
         {
            handle_set_function(input);
         }
         else if (input[0].equals("is_waveform_of"))
         {
            handle_is_waveform_of(input);
         }
         else
         {
            handle_parent_predicate(input);
         }
      }
      return true;
   }
   private static void handle_is_waveform_of
   (
      final String[] input
   )
   {
      if (input.length != 3)
      {
         return;
      }
      SolutionItem.handle_is_waveform_of
      (
         input[1],
         input[2]
      );
   }
   private static void handle_set_function
   (
      final String[] input
   )
   {
      if (input.length != 4)
      {
         return;
      }
      SolutionItem.handle_unary_set_function
      (
         input[1],
         input[2],
         input[3]
      );
   }
   private static void handle_parent_predicate
   (
      final String[] input
   )
   {
      if (input.length != 3)
      {
         return;
      }
      if (input[0].equals("is_in_file"))
      {
         IS_IN_FILE.put(input[1], input[2]);
      }
      else if (input[0].equals("belongs_to_architecture"))
      {
         IS_IN_ARCHITECTURE.put(input[1], input[2]);
      }
      else if
      (
         input[0].equals("is_port_of")
         || input[0].equals("is_generic_of")
      )
      {
         IS_IN_ENTITY.put(input[1], input[2]);
      }
   }
   public static boolean propagate_filenames ()
   {
      for (final Map.Entry<String, String> file_ref: IS_IN_FILE.entrySet())
      {
         final SolutionItem file_si;
         file_si =
            SolutionItem.get_item_from_id
            (
               file_ref.getValue()
            );
         if (file_si == null)
         {
            System.err.println
            (
               "[E] Can't find any file with id \""
               + file_ref.getValue()
               + "\", yet the item with id \""
               + file_ref.getKey()
               + "\" is supposed to be in it."
            );
            return false;
         }
         SolutionItem.handle_unary_set_function
         (
            "file",
            file_ref.getKey(),
            file_si.get_function_value("filename")
         );
      }
      for
      (
         final Map.Entry<String, String> arch_ref: IS_IN_ARCHITECTURE.entrySet()
      )
      {
         final SolutionItem arch_si;
         arch_si =
            SolutionItem.get_item_from_id
            (
               arch_ref.getValue()
            );
         if (arch_si == null)
         {
            System.err.println
            (
               "[E] Can't find any architecture with id \""
               + arch_ref.getValue()
               + "\", yet the item with id \""
               + arch_ref.getKey()
               + "\" is supposed to be in it."
            );
            return false;
         }
         SolutionItem.handle_unary_set_function
         (
            "file",
            arch_ref.getKey(),
            arch_si.get_function_value("file")
         );
      }
      for
      (
         final Map.Entry<String, String> entity_ref: IS_IN_ENTITY.entrySet()
      )
      {
         final SolutionItem entity_si;
         entity_si =
            SolutionItem.get_item_from_id
            (
               entity_ref.getValue()
            );
         if (entity_si == null)
         {
            System.err.println
            (
               "[E] Can't find any entity with id \""
               + entity_ref.getValue()
               + "\", yet the item with id \""
               + entity_ref.getKey()
               + "\" is supposed to be in it."
            );
            return false;
         }
         SolutionItem.handle_unary_set_function
         (
            "file",
            entity_ref.getKey(),
            entity_si.get_function_value("file")
         );
      }
      return true;
   }
}
 |