summaryrefslogtreecommitdiff
blob: 8e7182c67ea6bd78043a3c27169c5458ff8ba1f0 (plain)
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
import kodkod.ast.Relation;

import java.util.Map;
import java.util.HashMap;

public class StringManager
{
   private final Map<String, String> TO_ID;
   private final VHDLType string_type;

   private static String cleanup_string (final String str)
   {
      return str.replaceAll("\\s","").toLowerCase();
   }

   public StringManager ()
   {
      TO_ID = new HashMap<String, String>();
      string_type = Main.get_model().get_string_type();
   }


   public Relation get_string_as_relation
   (
      final String str
   )
   {
      final String id;

      id = TO_ID.get(cleanup_string(str));

      if (id == null)
      {
         System.err.println
         (
            "[F] There is no mapping associated with the string \""
            + str
            + "\", and anonymous strings are not yet supported."
         );

         System.exit(-1);
      }
      else
      {
         System.out.println
         (
            "[D] Using string \""
            + str
            + "\" (id: "
            + id
            + ")"
         );
      }

      return string_type.get_member_as_relation(id);
   }

   private void add_mapping (String str, final String id)
   {
      str = cleanup_string(str);

      if (!TO_ID.containsKey(str))
      {
         TO_ID.put(str, id);
         string_type.add_member(id);
      }
   }

   public boolean handle_mapping_instruction (final String... instr)
   {
      if (instr.length < 3)
      {
         return false;
      }

      if (!instr[0].equals("string->instr"))
      {
         return false;
      }

      add_mapping(instr[1], instr[2]);

      return true;
   }
}