aboutsummaryrefslogtreecommitdiffstats
path: root/googlemock/scripts/upload.py
blob: 95239dc2cbed11b17ff7ccc00eefa722d722cb19 (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
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
#!/usr/bin/env python
#
# Copyright 2007 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Tool for uploading diffs from a version control system to the codereview app.

Usage summary: upload.py [options] [-- diff_options]

Diff options are passed to the diff command of the underlying system.

Supported version control systems:
  Git
  Mercurial
  Subversion

It is important for Git/Mercurial users to specify a tree/node/branch to diff
against by using the '--rev' option.
"""
# This code is derived from appcfg.py in the App Engine SDK (open source),
# and from ASPN recipe #146306.

import cookielib
import getpass
import logging
import md5
import mimetypes
import optparse
import os
import re
import socket
import subprocess
import sys
import urllib
import urllib2
import urlparse

try:
  import readline
except ImportError:
  pass

# The logging verbosity:
#  0: Errors only.
#  1: Status messages.
#  2: Info logs.
#  3: Debug logs.
verbosity = 1

# Max size of patch or base file.
MAX_UPLOAD_SIZE = 900 * 1024


def GetEmail(prompt):
  """Prompts the user for their email address and returns it.

  The last used email address is saved to a file and offered up as a suggestion
  to the user. If the user presses enter without typing in anything the last
  used email address is used. If the user enters a new address, it is saved
  for next time we prompt.

  """
  last_email_file_name = os.path.expanduser("~/.last_codereview_email_address")
  last_email = ""
  if os.path.exists(last_email_file_name):
    try:
      last_email_file = open(last_email_file_name, "r")
      last_email = last_email_file.readline().strip("\n")
      last_email_file.close()
      prompt += " [%s]" % last_email
    except IOError, e:
      pass
  email = raw_input(prompt + ": ").strip()
  if email:
    try:
      last_email_file = open(last_email_file_name, "w")
      last_email_file.write(email)
      last_email_file.close()
    except IOError, e:
      pass
  else:
    email = last_email
  return email


def StatusUpdate(msg):
  """Print a status message to stdout.

  If 'verbosity' is greater than 0, print the message.

  Args:
    msg: The string to print.
  """
  if verbosity > 0:
    print msg


def ErrorExit(msg):
  """Print an error message to stderr and exit."""
  print >>sys.stderr, msg
  sys.exit(1)


class ClientLoginError(urllib2.HTTPError):
  """Raised to indicate there was an error authenticating with ClientLogin."""

  def __init__(self, url, code, msg, headers, args):
    urllib2.HTTPError.__init__(self, url, code, msg, headers, None)
    self.args = args
    self.reason = args["Error"]


class AbstractRpcServer(object):
  """Provides a common interface for a simple RPC server."""

  def __init__(self, host, auth_function, host_override=None, extra_headers={},
               save_cookies=False):
    """Creates a new HttpRpcServer.

    Args:
      host: The host to send requests to.
      auth_function: A function that takes no arguments and returns an
        (email, password) tuple when called. Will be called if authentication
        is required.
      host_override: The host header to send to the server (defaults to host).
      extra_headers: A dict of extra headers to append to every request.
      save_cookies: If True, save the authentication cookies to local disk.
        If False, use an in-memory cookiejar instead.  Subclasses must
        implement this functionality.  Defaults to False.
    """
    self.host = host
    self.host_override = host_override
    self.auth_function = auth_function
    self.authenticated = False
    self.extra_headers = extra_headers
    self.save_cookies = save_cookies
    self.opener = self._GetOpener()
    if self.host_override:
      logging.info("Server: %s; Host: %s", self.host, self.host_override)
    else:
      logging.info("Server: %s", self.host)

  def _GetOpener(self):
    """Returns an OpenerDirector for making HTTP requests.

    Returns:
      A urllib2.OpenerDirector object.
    """
    raise NotImplementedError()

  def _CreateRequest(self, url, data=None):
    """Creates a new urllib request."""
    logging.debug("Creating request for: '%s' with payload:\n%s", url, data)
    req = urllib2.Request(url, data=data)
    if self.host_override:
      req.add_header("Host", self.host_override)
    for key, value in self.extra_headers.iteritems():
      req.add_header(key, value)
    return req

  def _GetAuthToken(self, email, password):
    """Uses ClientLogin to authenticate the user, returning an auth token.

    Args:
      email:    The user's email address
      password: The user's password

    Raises:
      ClientLoginError: If there was an error authenticating with ClientLogin.
      HTTPError: If there was some other form of HTTP error.

    Returns:
      The authentication token returned by ClientLogin.
    """
    account_type = "GOOGLE"
    if self.host.endswith(".google.com"):
      # Needed for use inside Google.
      account_type = "HOSTED"
    req = self._CreateRequest(
        url="https://www.google.com/accounts/ClientLogin",
        data=urllib.urlencode({
            "Email": email,
            "Passwd": password,
            "service": "ah",
            "source": "rietveld-codereview-upload",
            "accountType": account_type,
        }),
    )
    try:
      response = self.opener.open(req)
      response_body = response.read()
      response_dict = dict(x.split("=")
                           for x in response_body.split("\n") if x)
      return response_dict["Auth"]
    except urllib2.HTTPError, e:
      if e.code == 403:
        body = e.read()
        response_dict = dict(x.split("=", 1) for x in body.split("\n") if x)
        raise ClientLoginError(req.get_full_url(), e.code, e.msg,
                               e.headers, response_dict)
      else:
        raise

  def _GetAuthCookie(self, auth_token):
    """Fetches authentication cookies for an authentication token.

    Args:
      auth_token: The authentication token returned by ClientLogin.

    Raises:
      HTTPError: If there was an error fetching the authentication cookies.
    """
    # This is a dummy value to allow us to identify when we're successful.
    continue_location = "http://localhost/"
    args = {"continue": continue_location, "auth": auth_token}
    req = self._CreateRequest("http://%s/_ah/login?%s" %
                              (self.host, urllib.urlencode(args)))
    try:
      response = self.opener.open(req)
    except urllib2.HTTPError, e:
      response = e
    if (response.code != 302 or
        response.info()["location"] != continue_location):
      raise urllib2.HTTPError(req.get_full_url(), response.code, response.msg,
                              response.headers, response.fp)
    self.authenticated = True

  def _Authenticate(self):
    """Authenticates the user.

    The authentication process works as follows:
     1) We get a username and password from the user
     2) We use ClientLogin to obtain an AUTH token for the user
        (see https://developers.google.com/identity/protocols/AuthForInstalledApps).
     3) We pass the auth token to /_ah/login on the server to obtain an
        authentication cookie. If login was successful, it tries to redirect
        us to the URL we provided.

    If we attempt to access the upload API without first obtaining an
    authentication cookie, it returns a 401 response and directs us to
    authenticate ourselves with ClientLogin.
    """
    for i in range(3):
      credentials = self.auth_function()
      try:
        auth_token = self._GetAuthToken(credentials[0], credentials[1])
      except ClientLoginError, e:
        if e.reason == "BadAuthentication":
          print >>sys.stderr, "Invalid username or password."
          continue
        if e.reason == "CaptchaRequired":
          print >>sys.stderr, (
              "Please go to\n"
              "https://www.google.com/accounts/DisplayUnlockCaptcha\n"
              "and verify you are a human.  Then try again.")
          break
        if e.reason == "NotVerified":
          print >>sys.stderr, "Account not verified."
          break
        if e.reason == "TermsNotAgreed":
          print >>sys.stderr, "User has not agreed to TOS."
          break
        if e.reason == "AccountDeleted":
          print >>sys.stderr, "The user account has been deleted."
          break
        if e.reason == "AccountDisabled":
          print >>sys.stderr, "The user account has been disabled."
          break
        if e.reason == "ServiceDisabled":
          print >>sys.stderr, ("The user's access to the service has been "
                               "disabled.")
          break
        if e.reason == "ServiceUnavailable":
          print >>sys.stderr, "The service is not available; try again later."
          break
        raise
      self._GetAuthCookie(auth_token)
      return

  def Send(self, request_path, payload=None,
           content_type="application/octet-stream",
           timeout=None,
           **kwargs):
    """Sends an RPC and returns the response.

    Args:
      request_path: The path to send the request to, eg /api/appversion/create.
      payload: The body of the request, or None to send an empty request.
      content_type: The Content-Type header to use.
      timeout: timeout in seconds; default None i.e. no timeout.
        (Note: for large requests on OS X, the timeout doesn't work right.)
      kwargs: Any keyword arguments are converted into query string parameters.

    Returns:
      The response body, as a string.
    """
    # TODO: Don't require authentication.  Let the server say
    # whether it is necessary.
    if not self.authenticated:
      self._Authenticate()

    old_timeout = socket.getdefaulttimeout()
    socket.setdefaulttimeout(timeout)
    try:
      tries = 0
      while True:
        tries += 1
        args = dict(kwargs)
        url = "http://%s%s" % (self.host, request_path)
        if args:
          url += "?" + urllib.urlencode(args)
        req = self._CreateRequest(url=url, data=payload)
        req.add_header("Content-Type", content_type)
        try:
          f = self.opener.open(req)
          response = f.read()
          f.close()
          return response
        except urllib2.HTTPError, e:
          if tries > 3:
            raise
          elif e.code == 401:
            self._Authenticate()
##           elif e.code >= 500 and e.code < 600:
##             # Server Error - try again.
##             continue
          else:
            raise
    finally:
      socket.setdefaulttimeout(old_timeout)


class HttpRpcServer(AbstractRpcServer):
  """Provides a simplified RPC-style interface for HTTP requests."""

  def _Authenticate(self):
    """Save the cookie jar after authentication."""
    super(HttpRpcServer, self)._Authenticate()
    if self.save_cookies:
      StatusUpdate("Saving authentication cookies to %s" % self.cookie_file)
      self.cookie_jar.save()

  def _GetOpener(self):
    """Returns an OpenerDirector that supports cookies and ignores redirects.

    Returns:
      A urllib2.OpenerDirector object.
    """
    opener = urllib2.OpenerDirector()
    opener.add_handler(urllib2.ProxyHandler())
    opener.add_handler(urllib2.UnknownHandler())
    opener.add_handler(urllib2.HTTPHandler())
    opener.add_handler(urllib2.HTTPDefaultErrorHandler())
    opener.add_handler(urllib2.HTTPSHandler())
    opener.add_handler(urllib2.HTTPErrorProcessor())
    if self.save_cookies:
      self.cookie_file = os.path.expanduser("~/.codereview_upload_cookies")
      self.cookie_jar = cookielib.MozillaCookieJar(self.cookie_file)
      if os.path.exists(self.cookie_file):
        try:
          self.cookie_jar.load()
          self.authenticated = True
          StatusUpdate("Loaded authentication cookies from %s" %
                       self.cookie_file)
        except (cookielib.LoadError, IOError):
          # Failed to load cookies - just ignore them.
          pass
      else:
        # Create an empty cookie file with mode 600
        fd = os.open(self.cookie_file, os.O_CREAT, 0600)
        os.close(fd)
      # Always chmod the cookie file
      os.chmod(self.cookie_file, 0600)
    else:
      # Don't save cookies across runs of update.py.
      self.cookie_jar = cookielib.CookieJar()
    opener.add_handler(urllib2.HTTPCookieProcessor(self.cookie_jar))
    return opener


parser = optparse.OptionParser(usage="%prog [options] [-- diff_options]")
parser.add_option("-y", "--assume_yes", action="store_true",
                  dest="assume_yes", default=False,
                  help="Assume that the answer to yes/no questions is 'yes'.")
# Logging
group = parser.add_option_group("Logging options")
group.add_option("-q", "--quiet", action="store_const", const=0,
                 dest="verbose", help="Print errors only.")
group.add_option("-v", "--verbose", action="store_const", const=2,
                 dest="verbose", default=1,
                 help="Print info level logs (default).")
group.add_option("--noisy", action="store_const", const=3,
                 dest="verbose", help="Print all logs.")
# Review server
group = parser.add_option_group("Review server options")
group.add_option("-s", "--server", action="store", dest="server",
                 default="codereview.appspot.com",
                 metavar="SERVER",
                 help=("The server to upload to. The format is host[:port]. "
                       "Defaults to 'codereview.appspot.com'."))
group.add_option("-e", "--email", action="store", dest="email",
                 metavar="EMAIL", default=None,
                 help="The username to use. Will prompt if omitted.")
group.add_option("-H", "--host", action="store", dest="host",
                 metavar="HOST", default=None,
                 help="Overrides the Host header sent with all RPCs.")
group.add_option("--no_cookies", action="store_false",
                 dest="save_cookies", default=True,
                 help="Do not save authentication cookies to local disk.")
# Issue
group = parser.add_option_group("Issue options")
group.add_option("-d", "--description", action="store", dest="description",
                 metavar="DESCRIPTION", default=None,
                 help="Optional description when creating an issue.")
group.add_option("-f", "--description_file", action="store",
                 dest="description_file", metavar="DESCRIPTION_FILE",
                 default=None,
                 help="Optional path of a file that contains "
                      "the description when creating an issue.")
group.add_option("-r", "--reviewers", action="store", dest="reviewers",
                 metavar="REVIEWERS", default=None,
                 help="Add reviewers (comma separated email addresses).")
group.add_option("--cc", action="store", dest="cc",
                 metavar="CC", default=None,
                 help="Add CC (comma separated email addresses).")
# Upload options
group = parser.add_option_group("Patch options")
group.add_option("-m", "--message", action="store", dest="message",
                 metavar="MESSAGE", default=None,
                 help="A message to identify the patch. "
                      "Will prompt if omitted.")
group.add_option("-i", "--issue", type="int", action="store",
                 metavar="ISSUE", default=None,
                 help="Issue number to which to add. Defaults to new issue.")
group.add_option("--download_base", action="store_true",
                 dest="download_base", default=False,
                 help="Base files will be downloaded by the server "
                 "(side-by-side diffs may not work on files with CRs).")
group.add_option("--rev", action="store", dest="revision",
                 metavar="REV", default=None,
                 help="Branch/tree/revision to diff against (used by DVCS).")
group.add_option("--send_mail", action="store_true",
                 dest="send_mail", default=False,
                 help="Send notification email to reviewers.")


def GetRpcServer(options):
  """Returns an instance of an AbstractRpcServer.

  Returns:
    A new AbstractRpcServer, on which RPC calls can be made.
  """

  rpc_server_class = HttpRpcServer

  def GetUserCredentials():
    """Prompts the user for a username and password."""
    email = options.email
    if email is None:
      email = GetEmail("Email (login for uploading to %s)" % options.server)
    password = getpass.getpass("Password for %s: " % email)
    return (email, password)

  # If this is the dev_appserver, use fake authentication.
  host = (options.host or options.server).lower()
  if host == "localhost" or host.startswith("localhost:"):
    email = options.email
    if email is None:
      email = "test@example.com"
      logging.info("Using debug user %s.  Override with --email" % email)
    server = rpc_server_class(
        options.server,
        lambda: (email, "password"),
        host_override=options.host,
        extra_headers={"Cookie":
                       'dev_appserver_login="%s:False"' % email},
        save_cookies=options.save_cookies)
    # Don't try to talk to ClientLogin.
    server.authenticated = True
    return server

  return rpc_server_class(options.server, GetUserCredentials,
                          host_override=options.host,
                          save_cookies=options.save_cookies)


def EncodeMultipartFormData(fields, files):
  """Encode form fields for multipart/form-data.

  Args:
    fields: A sequence of (name, value) elements for regular form fields.
    files: A sequence of (name, filename, value) elements for data to be
           uploaded as files.
  Returns:
    (content_type, body) ready for httplib.HTTP instance.

  Source:
    https://web.archive.org/web/20160116052001/code.activestate.com/recipes/146306
  """
  BOUNDARY = '-M-A-G-I-C---B-O-U-N-D-A-R-Y-'
  CRLF = '\r\n'
  lines = []
  for (key, value) in fields:
    lines.append('--' + BOUNDARY)
    lines.append('Content-Disposition: form-data; name="%s"' % key)
    lines.append('')
    lines.append(value)
  for (key, filename, value) in files:
    lines.append('--' + BOUNDARY)
    lines.append('Content-Disposition: form-data; name="%s"; filename="%s"' %
             (key, filename))
    lines.append('Content-Type: %s' % GetContentType(filename))
    lines.append('')
    lines.append(value)
  lines.append('--' + BOUNDARY + '--')
  lines.append('')
  body = CRLF.join(lines)
  content_type = 'multipart/form-data; boundary=%s' % BOUNDARY
  return content_type, body


def GetContentType(filename):
  """Helper to guess the content-type from the filename."""
  return mimetypes.guess_type(filename)[0] or 'application/octet-stream'


# Use a shell for subcommands on Windows to get a PATH search.
use_shell = sys.platform.startswith("win")

def RunShellWithReturnCode(command, print_output=False,
                           universal_newlines=True):
  """Executes a command and returns the output from stdout and the return code.

  Args:
    command: Command to execute.
    print_output: If True, the output is printed to stdout.
                  If False, both stdout and stderr are ignored.
    universal_newlines: Use universal_newlines flag (default: True).

  Returns:
    Tuple (output, return code)
  """
  logging.info("Running %s", command)
  p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
                       shell=use_shell, universal_newlines=universal_newlines)
  if print_output:
    output_array = []
    while True:
      line = p.stdout.readline()
      if not line:
        break
      print line.strip("\n")
      output_array.append(line)
    output = "".join(output_array)
  else:
    output = p.stdout.read()
  p.wait()
  errout = p.stderr.read()
  if print_output and errout:
    print >>sys.stderr, errout
  p.stdout.close()
  p.stderr.close()
  return output, p.returncode


def RunShell(command, silent_ok=False, universal_newlines=True,
             print_output=False):
  data, retcode = RunShellWithReturnCode(command, print_output,
                                         universal_newlines)
  if retcode:
    ErrorExit("Got error status from %s:\n%s" % (command, data))
  if not silent_ok and not data:
    ErrorExit("No output from %s" % command)
  return data


class VersionControlSystem(object):
  """Abstract base class providing an interface to the VCS."""

  def __init__(self, options):
    """Constructor.

    Args:
      options: Command line options.
    """
    self.options = options

  def GenerateDiff(self, args):
    """Return the current diff as a string.

    Args:
      args: Extra arguments to pass to the diff command.
    """
    raise NotImplementedError(
        "abstract method -- subclass %s must override" % self.__class__)

  def GetUnknownFiles(self):
    """Return a list of files unknown to the VCS."""
    raise NotImplementedError(
        "abstract method -- subclass %s must override" % self.__class__)

  def CheckForUnknownFiles(self):
    """Show an "are you sure?" prompt if there are unknown files."""
    unknown_files = self.GetUnknownFiles()
    if unknown_files:
      print "The following files are not added to version control:"
      for line in unknown_files:
        print line
      prompt = "Are you sure to continue?(y/N) "
      answer = raw_input(prompt).strip()
      if answer != "y":
        ErrorExit("User aborted")

  def GetBaseFile(self, filename):
    """Get the content of the upstream version of a file.

    Returns:
      A tuple (base_content, new_content, is_binary, status)
        base_content: The contents of the base file.
        new_content: For text files, this is empty.  For binary files, this is
          the contents of the new file, since the diff output won't contain
          information to reconstruct the current file.
        is_binary: True iff the file is binary.
        status: The status of the file.
    """

    raise NotImplementedError(
        "abstract method -- subclass %s must override" % self.__class__)


  def GetBaseFiles(self, diff):
    """Helper that calls GetBase file for each file in the patch.

    Returns:
      A dictionary that maps from filename to GetBaseFile's tuple.  Filenames
      are retrieved based on lines that start with "Index:" or
      "Property changes on:".
    """
    files = {}
    for line in diff.splitlines(True):
      if line.startswith('Index:') or line.startswith('Property changes on:'):
        unused, filename = line.split(':', 1)
        # On Windows if a file has property changes its filename uses '\'
        # instead of '/'.
        filename = filename.strip().replace('\\', '/')
        files[filename] = self.GetBaseFile(filename)
    return files


  def UploadBaseFiles(self, issue, rpc_server, patch_list, patchset, options,
                      files):
    """Uploads the base files (and if necessary, the current ones as well)."""

    def UploadFile(filename, file_id, content, is_binary, status, is_base):
      """Uploads a file to the server."""
      file_too_large = False
      if is_base:
        type = "base"
      else:
        type = "current"
      if len(content) > MAX_UPLOAD_SIZE:
        print ("Not uploading the %s file for %s because it's too large." %
               (type, filename))
        file_too_large = True
        content = ""
      checksum = md5.new(content).hexdigest()
      if options.verbose > 0 and not file_too_large:
        print "Uploading %s file for %s" % (type, filename)
      url = "/%d/upload_content/%d/%d" % (int(issue), int(patchset), file_id)
      form_fields = [("filename", filename),
                     ("status", status),
                     ("checksum", checksum),
                     ("is_binary", str(is_binary)),
                     ("is_current", str(not is_base)),
                    ]
      if file_too_large:
        form_fields.append(("file_too_large", "1"))
      if options.email:
        form_fields.append(("user", options.email))
      ctype, body = EncodeMultipartFormData(form_fields,
                                            [("data", filename, content)])
      response_body = rpc_server.Send(url, body,
                                      content_type=ctype)
      if not response_body.startswith("OK"):
        StatusUpdate("  --> %s" % response_body)
        sys.exit(1)

    patches = dict()
    [patches.setdefault(v, k) for k, v in patch_list]
    for filename in patches.keys():
      base_content, new_content, is_binary, status = files[filename]
      file_id_str = patches.get(filename)
      if file_id_str.find("nobase") != -1:
        base_content = None
        file_id_str = file_id_str[file_id_str.rfind("_") + 1:]
      file_id = int(file_id_str)
      if base_content != None:
        UploadFile(filename, file_id, base_content, is_binary, status, True)
      if new_content != None:
        UploadFile(filename, file_id, new_content, is_binary, status, False)

  def IsImage(self, filename):
    """Returns true if the filename has an image extension."""
    mimetype =  mimetypes.guess_type(filename)[0]
    if not mimetype:
      return False
    return mimetype.startswith("image/")


class SubversionVCS(VersionControlSystem):
  """Implementation of the VersionControlSystem interface for Subversion."""

  def __init__(self, options):
    super(SubversionVCS, self).__init__(options)
    if self.options.revision:
      match = re.match(r"(\d+)(:(\d+))?", self.options.revision)
      if not match:
        ErrorExit("Invalid Subversion revision %s." % self.options.revision)
      self.rev_start = match.group(1)
      self.rev_end = match.group(3)
    else:
      self.rev_start = self.rev_end = None
    # Cache output from "svn list -r REVNO dirname".
    # Keys: dirname, Values: 2-tuple (ouput for start rev and end rev).
    self.svnls_cache = {}
    # SVN base URL is required to fetch files deleted in an older revision.
    # Result is cached to not guess it over and over again in GetBaseFile().
    required = self.options.download_base or self.options.revision is not None
    self.svn_base = self._GuessBase(required)

  def GuessBase(self, required):
    """Wrapper for _GuessBase."""
    return self.svn_base

  def _GuessBase(self, required):
    """Returns the SVN base URL.

    Args:
      required: If true, exits if the url can't be guessed, otherwise None is
        returned.
    """
    info = RunShell(["svn", "info"])
    for line in info.splitlines():
      words = line.split()
      if len(words) == 2 and words[0] == "URL:":
        url = words[1]
        scheme, netloc, path, params, query, fragment = urlparse.urlparse(url)
        username, netloc = urllib.splituser(netloc)
        if username:
          logging.info("Removed username from base URL")
        if netloc.endswith("svn.python.org"):
          if netloc == "svn.python.org":
            if path.startswith("/projects/"):
              path = path[9:]
          elif netloc != "pythondev@svn.python.org":
            ErrorExit("Unrecognized Python URL: %s" % url)
          base = "http://svn.python.org/view/*checkout*%s/" % path
          logging.info("Guessed Python base = %s", base)
        elif netloc.endswith("svn.collab.net"):
          if path.startswith("/repos/"):
            path = path[6:]
          base = "http://svn.collab.net/viewvc/*checkout*%s/" % path
          logging.info("Guessed CollabNet base = %s", base)
        elif netloc.endswith(".googlecode.com"):
          path = path + "/"
          base = urlparse.urlunparse(("http", netloc, path, params,
                                      query, fragment))
          logging.info("Guessed Google Code base = %s", base)
        else:
          path = path + "/"
          base = urlparse.urlunparse((scheme, netloc, path, params,
                                      query, fragment))
          logging.info("Guessed base = %s", base)
        return base
    if required:
      ErrorExit("Can't find URL in output from svn info")
    return None

  def GenerateDiff(self, args):
    cmd = ["svn", "diff"]
    if self.options.revision:
      cmd += ["-r", self.options.revision]
    cmd.extend(args)
    data = RunShell(cmd)
    count = 0
    for line in data.splitlines():
      if line.startswith("Index:") or line.startswith("Property changes on:"):
        count += 1
        logging.info(line)
    if not count:
      ErrorExit("No valid patches found in output from svn diff")
    return data

  def _CollapseKeywords(self, content, keyword_str):
    """Collapses SVN keywords."""
    # svn cat translates keywords but svn diff doesn't. As a result of this
    # behavior patching.PatchChunks() fails with a chunk mismatch error.
    # This part was originally written by the Review Board development team
    # who had the same problem (https://reviews.reviewboard.org/r/276/).
    # Mapping of keywords to known aliases
    svn_keywords = {
      # Standard keywords
      'Date':                ['Date', 'LastChangedDate'],
      'Revision':            ['Revision', 'LastChangedRevision', 'Rev'],
      'Author':              ['Author', 'LastChangedBy'],
      'HeadURL':             ['HeadURL', 'URL'],
      'Id':                  ['Id'],

      # Aliases
      'LastChangedDate':     ['LastChangedDate', 'Date'],
      'LastChangedRevision': ['LastChangedRevision', 'Rev', 'Revision'],
      'LastChangedBy':       ['LastChangedBy', 'Author'],
      'URL':                 ['URL', 'HeadURL'],
    }

    def repl(m):
       if m.group(2):
         return "$%s::%s$" % (m.group(1), " " * len(m.group(3)))
       return "$%s$" % m.group(1)
    keywords = [keyword
                for name in keyword_str.split(" ")
                for keyword in svn_keywords.get(name, [])]
    return re.sub(r"\$(%s):(:?)([^\$]+)\$" % '|'.join(keywords), repl, content)

  def GetUnknownFiles(self):
    status = RunShell(["svn", "status", "--ignore-externals"], silent_ok=True)
    unknown_files = []
    for line in status.split("\n"):
      if line and line[0] == "?":
        unknown_files.append(line)
    return unknown_files

  def ReadFile(self, filename):
    """Returns the contents of a file."""
    file = open(filename, 'rb')
    result = ""
    try:
      result = file.read()
    finally:
      file.close()
    return result

  def GetStatus(self, filename):
    """Returns the status of a file."""
    if not self.options.revision:
      status = RunShell(["svn", "status", "--ignore-externals", filename])
      if not status:
        ErrorExit("svn status returned no output for %s" % filename)
      status_lines = status.splitlines()
      # If file is in a cl, the output will begin with
      # "\n--- Changelist 'cl_name':\n".  See
      # https://web.archive.org/web/20090918234815/svn.collab.net/repos/svn/trunk/notes/changelist-design.txt
      if (len(status_lines) == 3 and
          not status_lines[0] and
          status_lines[1].startswith("--- Changelist")):
        status = status_lines[2]
      else:
        status = status_lines[0]
    # If we have a revision to diff against we need to run "svn list"
    # for the old and the new revision and compare the results to get
    # the correct status for a file.
    else:
      dirname, relfilename = os.path.split(filename)
      if dirname not in self.svnls_cache:
        cmd = ["svn", "list", "-r", self.rev_start, dirname or "."]
        out, returncode = RunShellWithReturnCode(cmd)
        if returncode:
          ErrorExit("Failed to get status for %s." % filename)
        old_files = out.splitlines()
        args = ["svn", "list"]
        if self.rev_end:
          args += ["-r", self.rev_end]
        cmd = args + [dirname or "."]
        out, returncode = RunShellWithReturnCode(cmd)
        if returncode:
          ErrorExit("Failed to run command %s" % cmd)
        self.svnls_cache[dirname] = (old_files, out.splitlines())
      old_files, new_files = self.svnls_cache[dirname]
      if relfilename in old_files and relfilename not in new_files:
        status = "D   "
      elif relfilename in old_files and relfilename in new_files:
        status = "M   "
      else:
        status = "A   "
    return status

  def GetBaseFile(self, filename):
    status = self.GetStatus(filename)
    base_content = None
    new_content = None

    # If a file is copied its status will be "A  +", which signifies
    # "addition-with-history".  See "svn st" for more information.  We need to
    # upload the original file or else diff parsing will fail if the file was
    # edited.
    if status[0] == "A" and status[3] != "+":
      # We'll need to upload the new content if we're adding a binary file
      # since diff's output won't contain it.
      mimetype = RunShell(["svn", "propget", "svn:mime-type", filename],
                          silent_ok=True)
      base_content = ""
      is_binary = mimetype and not mimetype.startswith("text/")
      if is_binary and self.IsImage(filename):
        new_content = self.ReadFile(filename)
    elif (status[0] in ("M", "D", "R") or
          (status[0] == "A" and status[3] == "+") or  # Copied file.
          (status[0] == " " and status[1] == "M")):  # Property change.
      args = []
      if self.options.revision:
        url = "%s/%s@%s" % (self.svn_base, filename, self.rev_start)
      else:
        # Don't change filename, it's needed later.
        url = filename
        args += ["-r", "BASE"]
      cmd = ["svn"] + args + ["propget", "svn:mime-type", url]
      mimetype, returncode = RunShellWithReturnCode(cmd)
      if returncode:
        # File does not exist in the requested revision.
        # Reset mimetype, it contains an error message.
        mimetype = ""
      get_base = False
      is_binary = mimetype and not mimetype.startswith("text/")
      if status[0] == " ":
        # Empty base content just to force an upload.
        base_content = ""
      elif is_binary:
        if self.IsImage(filename):
          get_base = True
          if status[0] == "M":
            if not self.rev_end:
              new_content = self.ReadFile(filename)
            else:
              url = "%s/%s@%s" % (self.svn_base, filename, self.rev_end)
              new_content = RunShell(["svn", "cat", url],
                                     universal_newlines=True, silent_ok=True)
        else:
          base_content = ""
      else:
        get_base = True

      if get_base:
        if is_binary:
          universal_newlines = False
        else:
          universal_newlines = True
        if self.rev_start:
          # "svn cat -r REV delete_file.txt" doesn't work. cat requires
          # the full URL with "@REV" appended instead of using "-r" option.
          url = "%s/%s@%s" % (self.svn_base, filename, self.rev_start)
          base_content = RunShell(["svn", "cat", url],
                                  universal_newlines=universal_newlines,
                                  silent_ok=True)
        else:
          base_content = RunShell(["svn", "cat", filename],
                                  universal_newlines=universal_newlines,
                                  silent_ok=True)
        if not is_binary:
          args = []
          if self.rev_start:
            url = "%s/%s@%s" % (self.svn_base, filename, self.rev_start)
          else:
            url = filename
            args += ["-r", "BASE"]
          cmd = ["svn"] + args + ["propget", "svn:keywords", url]
          keywords, returncode = RunShellWithReturnCode(cmd)
          if keywords and not returncode:
            base_content = self._CollapseKeywords(base_content, keywords)
    else:
      StatusUpdate("svn status returned unexpected output: %s" % status)
      sys.exit(1)
    return base_content, new_content, is_binary, status[0:5]


class GitVCS(VersionControlSystem):
  """Implementation of the VersionControlSystem interface for Git."""

  def __init__(self, options):
    super(GitVCS, self).__init__(options)
    # Map of filename -> hash of base file.
    self.base_hashes = {}

  def GenerateDiff(self, extra_args):
    # This is more complicated than svn's GenerateDiff because we must convert
    # the diff output to include an svn-style "Index:" line as well as record
    # the hashes of the base files, so we can upload them along with our diff.
    if self.options.revision:
      extra_args = [self.options.revision] + extra_args
    gitdiff = RunShell(["git", "diff", "--full-index"] + extra_args)
    svndiff = []
    filecount = 0
    filename = None
    for line in gitdiff.splitlines():
      match = re.match(r"diff --git a/(.*) b/.*$", line)
      if match:
        filecount += 1
        filename = match.group(1)
        svndiff.append("Index: %s\n" % filename)
      else:
        # The "index" line in a git diff looks like this (long hashes elided):
        #   index 82c0d44..b2cee3f 100755
        # We want to save the left hash, as that identifies the base file.
        match = re.match(r"index (\w+)\.\.", line)
        if match:
          self.base_hashes[filename] = match.group(1)
      svndiff.append(line + "\n")
    if not filecount:
      ErrorExit("No valid patches found in output from git diff")
    return "".join(svndiff)

  def GetUnknownFiles(self):
    status = RunShell(["git", "ls-files", "--exclude-standard", "--others"],
                      silent_ok=True)
    return status.splitlines()

  def GetBaseFile(self, filename):
    hash = self.base_hashes[filename]
    base_content = None
    new_content = None
    is_binary = False
    if hash == "0" * 40:  # All-zero hash indicates no base file.
      status = "A"
      base_content = ""
    else:
      status = "M"
      base_content, returncode = RunShellWithReturnCode(["git", "show", hash])
      if returncode:
        ErrorExit("Got error status from 'git show %s'" % hash)
    return (base_content, new_content, is_binary, status)


class MercurialVCS(VersionControlSystem):
  """Implementation of the VersionControlSystem interface for Mercurial."""

  def __init__(self, options, repo_dir):
    super(MercurialVCS, self).__init__(options)
    # Absolute path to repository (we can be in a subdir)
    self.repo_dir = os.path.normpath(repo_dir)
    # Compute the subdir
    cwd = os.path.normpath(os.getcwd())
    assert cwd.startswith(self.repo_dir)
    self.subdir = cwd[len(self.repo_dir):].lstrip(r"\/")
    if self.options.revision:
      self.base_rev = self.options.revision
    else:
      self.base_rev = RunShell(["hg", "parent", "-q"]).split(':')[1].strip()

  def _GetRelPath(self, filename):
    """Get relative path of a file according to the current directory,
    given its logical path in the repo."""
    assert filename.startswith(self.subdir), filename
    return filename[len(self.subdir):].lstrip(r"\/")

  def GenerateDiff(self, extra_args):
    # If no file specified, restrict to the current subdir
    extra_args = extra_args or ["."]
    cmd = ["hg", "diff", "--git", "-r", self.base_rev] + extra_args
    data = RunShell(cmd, silent_ok=True)
    svndiff = []
    filecount = 0
    for line in data.splitlines():
      m = re.match("diff --git a/(\S+) b/(\S+)", line)
      if m:
        # Modify line to make it look like as it comes from svn diff.
        # With this modification no changes on the server side are required
        # to make upload.py work with Mercurial repos.
        # NOTE: for proper handling of moved/copied files, we have to use
        # the second filename.
        filename = m.group(2)
        svndiff.append("Index: %s" % filename)
        svndiff.append("=" * 67)
        filecount += 1
        logging.info(line)
      else:
        svndiff.append(line)
    if not filecount:
      ErrorExit("No valid patches found in output from hg diff")
    return "\n".join(svndiff) + "\n"

  def GetUnknownFiles(self):
    """Return a list of files unknown to the VCS."""
    args = []
    status = RunShell(["hg", "status", "--rev", self.base_rev, "-u", "."],
        silent_ok=True)
    unknown_files = []
    for line in status.splitlines():
      st, fn = line.split(" ", 1)
      if st == "?":
        unknown_files.append(fn)
    return unknown_files

  def GetBaseFile(self, filename):
    # "hg status" and "hg cat" both take a path relative to the current subdir
    # rather than to the repo root, but "hg diff" has given us the full path
    # to the repo root.
    base_content = ""
    new_content = None
    is_binary = False
    oldrelpath = relpath = self._GetRelPath(filename)
    # "hg status -C" returns two lines for moved/copied files, one otherwise
    out = RunShell(["hg", "status", "-C", "--rev", self.base_rev, relpath])
    out = out.splitlines()
    # HACK: strip error message about missing file/directory if it isn't in
    # the working copy
    if out[0].startswith('%s: ' % relpath):
      out = out[1:]
    if len(out) > 1:
      # Moved/copied => considered as modified, use old filename to
      # retrieve base contents
      oldrelpath = out[1].strip()
      status = "M"
    else:
      status, _ = out[0].split(' ', 1)
    if status != "A":
      base_content = RunShell(["hg", "cat", "-r", self.base_rev, oldrelpath],
        silent_ok=True)
      is_binary = "\0" in base_content  # Mercurial's heuristic
    if status != "R":
      new_content = open(relpath, "rb").read()
      is_binary = is_binary or "\0" in new_content
    if is_binary and base_content:
      # Fetch again without converting newlines
      base_content = RunShell(["hg", "cat", "-r", self.base_rev, oldrelpath],
        silent_ok=True, universal_newlines=False)
    if not is_binary or not self.IsImage(relpath):
      new_content = None
    return base_content, new_content, is_binary, status


# NOTE: The SplitPatch function is duplicated in engine.py, keep them in sync.
def SplitPatch(data):
  """Splits a patch into separate pieces for each file.

  Args:
    data: A string containing the output of svn diff.

  Returns:
    A list of 2-tuple (filename, text) where text is the svn diff output
      pertaining to filename.
  """
  patches = []
  filename = None
  diff = []
  for line in data.splitlines(True):
    new_filename = None
    if line.startswith('Index:'):
      unused, new_filename = line.split(':', 1)
      new_filename = new_filename.strip()
    elif line.startswith('Property changes on:'):
      unused, temp_filename = line.split(':', 1)
      # When a file is modified, paths use '/' between directories, however
      # when a property is modified '\' is used on Windows.  Make them the same
      # otherwise the file shows up twice.
      temp_filename = temp_filename.strip().replace('\\', '/')
      if temp_filename != filename:
        # File has property changes but no modifications, create a new diff.
        new_filename = temp_filename
    if new_filename:
      if filename and diff:
        patches.append((filename, ''.join(diff)))
      filename = new_filename
      diff = [line]
      continue
    if diff is not None:
      diff.append(line)
  if filename and diff:
    patches.append((filename, ''.join(diff)))
  return patches


def UploadSeparatePatches(issue, rpc_server, patchset, data, options):
  """Uploads a separate patch for each file in the diff output.

  Returns a list of [patch_key, filename] for each file.
  """
  patches = SplitPatch(data)
  rv = []
  for patch in patches:
    if len(patch[1]) > MAX_UPLOAD_SIZE:
      print ("Not uploading the patch for " + patch[0] +
             " because the file is too large.")
      continue
    form_fields = [("filename", patch[0])]
    if not options.download_base:
      form_fields.append(("content_upload", "1"))
    files = [("data", "data.diff", patch[1])]
    ctype, body = EncodeMultipartFormData(form_fields, files)
    url = "/%d/upload_patch/%d" % (int(issue), int(patchset))
    print "Uploading patch for " + patch[0]
    response_body = rpc_server.Send(url, body, content_type=ctype)
    lines = response_body.splitlines()
    if not lines or lines[0] != "OK":
      StatusUpdate("  --> %s" % response_body)
      sys.exit(1)
    rv.append([lines[1], patch[0]])
  return rv


def GuessVCS(options):
  """Helper to guess the version control system.

  This examines the current directory, guesses which VersionControlSystem
  we're using, and returns an instance of the appropriate class.  Exit with an
  error if we can't figure it out.

  Returns:
    A VersionControlSystem instance. Exits if the VCS can't be guessed.
  """
  # Mercurial has a command to get the base directory of a repository
  # Try running it, but don't die if we don't have hg installed.
  # NOTE: we try Mercurial first as it can sit on top of an SVN working copy.
  try:
    out, returncode = RunShellWithReturnCode(["hg", "root"])
    if returncode == 0:
      return MercurialVCS(options, out.strip())
  except OSError, (errno, message):
    if errno != 2:  # ENOENT -- they don't have hg installed.
      raise

  # Subversion has a .svn in all working directories.
  if os.path.isdir('.svn'):
    logging.info("Guessed VCS = Subversion")
    return SubversionVCS(options)

  # Git has a command to test if you're in a git tree.
  # Try running it, but don't die if we don't have git installed.
  try:
    out, returncode = RunShellWithReturnCode(["git", "rev-parse",
                                              "--is-inside-work-tree"])
    if returncode == 0:
      return GitVCS(options)
  except OSError, (errno, message):
    if errno != 2:  # ENOENT -- they don't have git installed.
      raise

  ErrorExit(("Could not guess version control system. "
             "Are you in a working copy directory?"))


def RealMain(argv, data=None):
  """The real main function.

  Args:
    argv: Command line arguments.
    data: Diff contents. If None (default) the diff is generated by
      the VersionControlSystem implementation returned by GuessVCS().

  Returns:
    A 2-tuple (issue id, patchset id).
    The patchset id is None if the base files are not uploaded by this
    script (applies only to SVN checkouts).
  """
  logging.basicConfig(format=("%(asctime).19s %(levelname)s %(filename)s:"
                              "%(lineno)s %(message)s "))
  os.environ['LC_ALL'] = 'C'
  options, args = parser.parse_args(argv[1:])
  global verbosity
  verbosity = options.verbose
  if verbosity >= 3:
    logging.getLogger().setLevel(logging.DEBUG)
  elif verbosity >= 2:
    logging.getLogger().setLevel(logging.INFO)
  vcs = GuessVCS(options)
  if isinstance(vcs, SubversionVCS):
    # base field is only allowed for Subversion.
    # Note: Fetching base files may become deprecated in future releases.
    base = vcs.GuessBase(options.download_base)
  else:
    base = None
  if not base and options.download_base:
    options.download_base = True
    logging.info("Enabled upload of base file")
  if not options.assume_yes:
    vcs.CheckForUnknownFiles()
  if data is None:
    data = vcs.GenerateDiff(args)
  files = vcs.GetBaseFiles(data)
  if verbosity >= 1:
    print "Upload server:", options.server, "(change with -s/--server)"
  if options.issue:
    prompt = "Message describing this patch set: "
  else:
    prompt = "New issue subject: "
  message = options.message or raw_input(prompt).strip()
  if not message:
    ErrorExit("A non-empty message is required")
  rpc_server = GetRpcServer(options)
  form_fields = [("subject", message)]
  if base:
    form_fields.append(("base", base))
  if options.issue:
    form_fields.append(("issue", str(options.issue)))
  if options.email:
    form_fields.append(("user", options.email))
  if options.reviewers:
    for reviewer in options.reviewers.split(','):
      if "@" in reviewer and not reviewer.split("@")[1].count(".") == 1:
        ErrorExit("Invalid email address: %s" % reviewer)
    form_fields.append(("reviewers", options.reviewers))
  if options.cc:
    for cc in options.cc.split(','):
      if "@" in cc and not cc.split("@")[1].count(".") == 1:
        ErrorExit("Invalid email address: %s" % cc)
    form_fields.append(("cc", options.cc))
  description = options.description
  if options.description_file:
    if options.description:
      ErrorExit("Can't specify description and description_file")
    file = open(options.description_file, 'r')
    description = file.read()
    file.close()
  if description:
    form_fields.append(("description", description))
  # Send a hash of all the base file so the server can determine if a copy
  # already exists in an earlier patchset.
  base_hashes = ""
  for file, info in files.iteritems():
    if not info[0] is None:
      checksum = md5.new(info[0]).hexdigest()
      if base_hashes:
        base_hashes += "|"
      base_hashes += checksum + ":" + file
  form_fields.append(("base_hashes", base_hashes))
  # If we're uploading base files, don't send the email before the uploads, so
  # that it contains the file status.
  if options.send_mail and options.download_base:
    form_fields.append(("send_mail", "1"))
  if not options.download_base:
    form_fields.append(("content_upload", "1"))
  if len(data) > MAX_UPLOAD_SIZE:
    print "Patch is large, so uploading file patches separately."
    uploaded_diff_file = []
    form_fields.append(("separate_patches", "1"))
  else:
    uploaded_diff_file = [("data", "data.diff", data)]
  ctype, body = EncodeMultipartFormData(form_fields, uploaded_diff_file)
  response_body = rpc_server.Send("/upload", body, content_type=ctype)
  patchset = None
  if not options.download_base or not uploaded_diff_file:
    lines = response_body.splitlines()
    if len(lines) >= 2:
      msg = lines[0]
      patchset = lines[1].strip()
      patches = [x.split(" ", 1) for x in lines[2:]]
    else:
      msg = response_body
  else:
    msg = response_body
  StatusUpdate(msg)
  if not response_body.startswith("Issue created.") and \
  not response_body.startswith("Issue updated."):
    sys.exit(0)
  issue = msg[msg.rfind("/")+1:]

  if not uploaded_diff_file:
    result = UploadSeparatePatches(issue, rpc_server, patchset, data, options)
    if not options.download_base:
      patches = result

  if not options.download_base:
    vcs.UploadBaseFiles(issue, rpc_server, patches, patchset, options, files)
    if options.send_mail:
      rpc_server.Send("/" + issue + "/mail", payload="")
  return issue, patchset


def main():
  try:
    RealMain(sys.argv)
  except KeyboardInterrupt:
    print
    StatusUpdate("Interrupted.")
    sys.exit(1)


if __name__ == "__main__":
  main()
a> 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365 7366 7367 7368 7369 7370 7371 7372 7373 7374 7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 7385 7386 7387 7388 7389 7390 7391 7392 7393 7394 7395 7396 7397 7398 7399 7400 7401 7402 7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 7435 7436 7437 7438 7439 7440 7441 7442 7443 7444 7445 7446 7447 7448 7449 7450 7451 7452 7453 7454 7455 7456 7457 7458 7459 7460 7461
--  Tree node definitions.
--  Copyright (C) 2002, 2003, 2004, 2005 Tristan Gingold
--
--  This program is free software: you can redistribute it and/or modify
--  it under the terms of the GNU General Public License as published by
--  the Free Software Foundation, either version 2 of the License, or
--  (at your option) any later version.
--
--  This program is distributed in the hope that it will be useful,
--  but WITHOUT ANY WARRANTY; without even the implied warranty of
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
--  GNU General Public License for more details.
--
--  You should have received a copy of the GNU General Public License
--  along with this program.  If not, see <gnu.org/licenses>.

with Ada.Unchecked_Conversion;
with Tables;
with Logging; use Logging;
with Vhdl.Lists; use Vhdl.Lists;
with Vhdl.Nodes_Meta; use Vhdl.Nodes_Meta;
with Vhdl.Nodes_Priv; use Vhdl.Nodes_Priv;

package body Vhdl.Nodes is
   --  A simple type that needs only 2 bits.
   type Bit2_Type is range 0 .. 2 ** 2 - 1;

   type Kind_Type is range 0 .. 2 ** 9 - 1;

   --  Format of a node.
   type Format_Type is
     (
      Format_Short,
      Format_Medium
     );

   -- Common fields are:
   --   Flag1 : Boolean
   --   Flag2 : Boolean
   --   Flag3 : Boolean
   --   Flag4 : Boolean
   --   Flag5 : Boolean
   --   Flag6 : Boolean
   --   Flag7 : Boolean
   --   Flag8 : Boolean
   --   Flag9 : Boolean
   --   Flag10 : Boolean
   --   Flag11 : Boolean
   --   Flag12 : Boolean
   --   Flag13 : Boolean
   --   Flag14 : Boolean
   --   Flag15 : Boolean
   --   Nkind : Kind_Type
   --   State1 : Bit2_Type
   --   State2 : Bit2_Type
   --   Location : Location_Type
   --   Field0 : Iir
   --   Field1 : Iir
   --   Field2 : Iir
   --   Field3 : Iir
   --   Field4 : Iir
   --   Field5 : Iir

   -- Fields of Format_Short:

   -- Fields of Format_Medium:
   --   State3 : Bit2_Type
   --   State4 : Bit2_Type
   --   Field6 : Iir (location)
   --   Field7 : Iir (field0)
   --   Field8 : Iir (field1)
   --   Field9 : Iir (field2)
   --   Field10 : Iir (field3)
   --   Field11 : Iir (field4)
   --   Field12 : Iir (field5)

   function Create_Node (Format : Format_Type) return Node_Type;
   procedure Free_Node (N : Node_Type);

   function Get_Nkind (N : Node_Type) return Kind_Type;
   pragma Inline (Get_Nkind);
   procedure Set_Nkind (N : Node_Type; Kind : Kind_Type);
   pragma Inline (Set_Nkind);

   function Get_Field0 (N : Node_Type) return Node_Type;
   pragma Inline (Get_Field0);
   procedure Set_Field0 (N : Node_Type; V : Node_Type);
   pragma Inline (Set_Field0);

   function Get_Field1 (N : Node_Type) return Node_Type;
   pragma Inline (Get_Field1);
   procedure Set_Field1 (N : Node_Type; V : Node_Type);
   pragma Inline (Set_Field1);

   function Get_Field2 (N : Node_Type) return Node_Type;
   pragma Inline (Get_Field2);
   procedure Set_Field2 (N : Node_Type; V : Node_Type);
   pragma Inline (Set_Field2);

   function Get_Field3 (N : Node_Type) return Node_Type;
   pragma Inline (Get_Field3);
   procedure Set_Field3 (N : Node_Type; V : Node_Type);
   pragma Inline (Set_Field3);

   function Get_Field4 (N : Node_Type) return Node_Type;
   pragma Inline (Get_Field4);
   procedure Set_Field4 (N : Node_Type; V : Node_Type);
   pragma Inline (Set_Field4);


   function Get_Field5 (N : Node_Type) return Node_Type;
   pragma Inline (Get_Field5);
   procedure Set_Field5 (N : Node_Type; V : Node_Type);
   pragma Inline (Set_Field5);

   function Get_Field6 (N: Node_Type) return Node_Type;
   pragma Inline (Get_Field6);
   procedure Set_Field6 (N: Node_Type; Val: Node_Type);
   pragma Inline (Set_Field6);

   function Get_Field7 (N: Node_Type) return Node_Type;
   pragma Inline (Get_Field7);
   procedure Set_Field7 (N: Node_Type; Val: Node_Type);
   pragma Inline (Set_Field7);

   function Get_Field8 (N: Node_Type) return Node_Type;
   pragma Inline (Get_Field8);
   procedure Set_Field8 (N: Node_Type; Val: Node_Type);
   pragma Inline (Set_Field8);

   function Get_Field9 (N: Node_Type) return Node_Type;
   pragma Inline (Get_Field9);
   procedure Set_Field9 (N: Node_Type; Val: Node_Type);
   pragma Inline (Set_Field9);

   function Get_Field10 (N: Node_Type) return Node_Type;
   pragma Inline (Get_Field10);
   procedure Set_Field10 (N: Node_Type; Val: Node_Type);
   pragma Inline (Set_Field10);

   function Get_Field11 (N: Node_Type) return Node_Type;
   pragma Inline (Get_Field11);
   procedure Set_Field11 (N: Node_Type; Val: Node_Type);
   pragma Inline (Set_Field11);

   function Get_Field12 (N: Node_Type) return Node_Type;
   pragma Inline (Get_Field12);
   procedure Set_Field12 (N: Node_Type; Val: Node_Type);
   pragma Inline (Set_Field12);


   function Get_Flag1 (N : Node_Type) return Boolean;
   pragma Inline (Get_Flag1);
   procedure Set_Flag1 (N : Node_Type; V : Boolean);
   pragma Inline (Set_Flag1);

   function Get_Flag2 (N : Node_Type) return Boolean;
   pragma Inline (Get_Flag2);
   procedure Set_Flag2 (N : Node_Type; V : Boolean);
   pragma Inline (Set_Flag2);

   function Get_Flag3 (N : Node_Type) return Boolean;
   pragma Inline (Get_Flag3);
   procedure Set_Flag3 (N : Node_Type; V : Boolean);
   pragma Inline (Set_Flag3);

   function Get_Flag4 (N : Node_Type) return Boolean;
   pragma Inline (Get_Flag4);
   procedure Set_Flag4 (N : Node_Type; V : Boolean);
   pragma Inline (Set_Flag4);

   function Get_Flag5 (N : Node_Type) return Boolean;
   pragma Inline (Get_Flag5);
   procedure Set_Flag5 (N : Node_Type; V : Boolean);
   pragma Inline (Set_Flag5);

   function Get_Flag6 (N : Node_Type) return Boolean;
   pragma Inline (Get_Flag6);
   procedure Set_Flag6 (N : Node_Type; V : Boolean);
   pragma Inline (Set_Flag6);

   function Get_Flag7 (N : Node_Type) return Boolean;
   pragma Inline (Get_Flag7);
   procedure Set_Flag7 (N : Node_Type; V : Boolean);
   pragma Inline (Set_Flag7);

   function Get_Flag8 (N : Node_Type) return Boolean;
   pragma Inline (Get_Flag8);
   procedure Set_Flag8 (N : Node_Type; V : Boolean);
   pragma Inline (Set_Flag8);

   function Get_Flag9 (N : Node_Type) return Boolean;
   pragma Inline (Get_Flag9);
   procedure Set_Flag9 (N : Node_Type; V : Boolean);
   pragma Inline (Set_Flag9);

   function Get_Flag10 (N : Node_Type) return Boolean;
   pragma Inline (Get_Flag10);
   procedure Set_Flag10 (N : Node_Type; V : Boolean);
   pragma Inline (Set_Flag10);

   function Get_Flag11 (N : Node_Type) return Boolean;
   pragma Inline (Get_Flag11);
   procedure Set_Flag11 (N : Node_Type; V : Boolean);
   pragma Inline (Set_Flag11);

   function Get_Flag12 (N : Node_Type) return Boolean;
   pragma Inline (Get_Flag12);
   procedure Set_Flag12 (N : Node_Type; V : Boolean);
   pragma Inline (Set_Flag12);

   function Get_Flag13 (N : Node_Type) return Boolean;
   pragma Inline (Get_Flag13);
   procedure Set_Flag13 (N : Node_Type; V : Boolean);
   pragma Inline (Set_Flag13);

   function Get_Flag14 (N : Node_Type) return Boolean;
   pragma Inline (Get_Flag14);
   procedure Set_Flag14 (N : Node_Type; V : Boolean);
   pragma Inline (Set_Flag14);

   function Get_Flag15 (N : Node_Type) return Boolean;
   pragma Inline (Get_Flag15);
   procedure Set_Flag15 (N : Node_Type; V : Boolean);
   pragma Inline (Set_Flag15);


   function Get_State1 (N : Node_Type) return Bit2_Type;
   pragma Inline (Get_State1);
   procedure Set_State1 (N : Node_Type; V : Bit2_Type);
   pragma Inline (Set_State1);

   function Get_State2 (N : Node_Type) return Bit2_Type;
   pragma Inline (Get_State2);
   procedure Set_State2 (N : Node_Type; V : Bit2_Type);
   pragma Inline (Set_State2);

   function Get_State3 (N : Node_Type) return Bit2_Type;
   pragma Inline (Get_State3);
   procedure Set_State3 (N : Node_Type; V : Bit2_Type);
   pragma Inline (Set_State3);

   type Node_Record is record
      --  First byte:
      Format : Format_Type;
      Flag1 : Boolean;
      Flag2 : Boolean;
      Flag3 : Boolean;
      Flag4 : Boolean;
      Flag5 : Boolean;
      Flag6 : Boolean;
      Flag7 : Boolean;

      --  Second byte:
      Flag8 : Boolean;
      Flag9 : Boolean;
      Flag10 : Boolean;
      Flag11 : Boolean;
      Flag12 : Boolean;
      Flag13 : Boolean;
      Flag14 : Boolean;
      Flag15 : Boolean;

      --  Third byte:
      Flag16 : Boolean;
      Flag17 : Boolean;
      Flag18 : Boolean;

      --  2*2 = 4 bits
      State1 : Bit2_Type;
      State2 : Bit2_Type;

      --  9 bits
      Kind : Kind_Type;

      -- Location.
      Location: Location_Type;

      Field0 : Node_Type;
      Field1 : Node_Type;
      Field2 : Node_Type;
      Field3 : Node_Type;
      Field4 : Node_Type;
      Field5 : Node_Type;
   end record;
   pragma Pack (Node_Record);
   for Node_Record'Size use 8*32;
   for Node_Record'Alignment use 4;
   pragma Suppress_Initialization (Node_Record);

   Init_Node : constant Node_Record := Node_Record'
     (Format => Format_Short,
      Kind => 0,
      State1 | State2 => 0,
      Location => Location_Nil,
      Field0 | Field1 | Field2 | Field3 | Field4 | Field5 => Null_Node,
      others => False);

      --  Suppress the access check of the table base.  This is really safe to
   --  suppress this check because the table base cannot be null.
   pragma Suppress (Access_Check);

   --  Suppress the index check on the table.
   --  Could be done during non-debug, since this may catch errors (reading
   --  Null_Node or Error_Node).
   --pragma Suppress (Index_Check);

   package Nodet is new Tables
     (Table_Component_Type => Node_Record,
      Table_Index_Type => Node_Type,
      Table_Low_Bound => 2,
      Table_Initial => 1024);

   function Get_Last_Node return Iir is
   begin
      return Nodet.Last;
   end Get_Last_Node;

   Free_Chain : Node_Type := Null_Node;

   function Create_Node (Format : Format_Type) return Node_Type
   is
      Res : Node_Type;
   begin
      case Format is
         when Format_Medium =>
            --  Allocate a first node.
            Nodet.Increment_Last;
            Res := Nodet.Last;
            --  Check alignment.
            if Res mod 2 = 1 then
               Set_Field1 (Res, Free_Chain);
               Free_Chain := Res;
               Nodet.Increment_Last;
               Res := Nodet.Last;
            end if;
            --  Allocate the second node.
            Nodet.Increment_Last;
            Nodet.Table (Res) := Init_Node;
            Nodet.Table (Res).Format := Format_Medium;
            Nodet.Table (Res + 1) := Init_Node;
         when Format_Short =>
            --  Check from free pool
            if Free_Chain = Null_Node then
               Nodet.Increment_Last;
               Res := Nodet.Last;
            else
               Res := Free_Chain;
               Free_Chain := Get_Field1 (Res);
            end if;
            Nodet.Table (Res) := Init_Node;
      end case;
      return Res;
   end Create_Node;

   type Free_Node_Hook_Array is
     array (Natural range 1 .. 8) of Free_Iir_Hook;
   Nbr_Free_Hooks : Natural := 0;

   Free_Hooks : Free_Node_Hook_Array;

   procedure Register_Free_Hook (Hook : Free_Iir_Hook) is
   begin
      if Nbr_Free_Hooks >= Free_Hooks'Last then
         --  Not enough room in Free_Hooks.
         raise Internal_Error;
      end if;
      Nbr_Free_Hooks := Nbr_Free_Hooks + 1;
      Free_Hooks (Nbr_Free_Hooks) := Hook;
   end Register_Free_Hook;

   procedure Free_Node (N : Node_Type) is
   begin
      if N = Null_Node then
         return;
      end if;

      --  Call hooks.
      for I in Free_Hooks'First .. Nbr_Free_Hooks loop
         Free_Hooks (I).all (N);
      end loop;

      --  Really free the node.
      Set_Nkind (N, 0);
      Set_Field1 (N, Free_Chain);
      Free_Chain := N;
      if Nodet.Table (N).Format = Format_Medium then
         Set_Field1 (N + 1, Free_Chain);
         Free_Chain := N + 1;
      end if;
   end Free_Node;

   procedure Free_Iir (Target : Iir) renames Free_Node;

   function Next_Node (N : Node_Type) return Node_Type is
   begin
      case Nodet.Table (N).Format is
         when Format_Medium =>
            return N + 2;
         when Format_Short =>
            return N + 1;
      end case;
   end Next_Node;

   function Get_Nkind (N : Node_Type) return Kind_Type is
   begin
      return Nodet.Table (N).Kind;
   end Get_Nkind;

   procedure Set_Nkind (N : Node_Type; Kind : Kind_Type) is
   begin
      Nodet.Table (N).Kind := Kind;
   end Set_Nkind;


   procedure Set_Location (N : Iir; Location: Location_Type) is
   begin
      Nodet.Table (N).Location := Location;
   end Set_Location;

   function Get_Location (N: Iir) return Location_Type is
   begin
      return Nodet.Table (N).Location;
   end Get_Location;


   procedure Set_Field0 (N : Node_Type; V : Node_Type) is
   begin
      Nodet.Table (N).Field0 := V;
   end Set_Field0;

   function Get_Field0 (N : Node_Type) return Node_Type is
   begin
      return Nodet.Table (N).Field0;
   end Get_Field0;


   function Get_Field1 (N : Node_Type) return Node_Type is
   begin
      return Nodet.Table (N).Field1;
   end Get_Field1;

   procedure Set_Field1 (N : Node_Type; V : Node_Type) is
   begin
      Nodet.Table (N).Field1 := V;
   end Set_Field1;

   function Get_Field2 (N : Node_Type) return Node_Type is
   begin
      return Nodet.Table (N).Field2;
   end Get_Field2;

   procedure Set_Field2 (N : Node_Type; V : Node_Type) is
   begin
      Nodet.Table (N).Field2 := V;
   end Set_Field2;

   function Get_Field3 (N : Node_Type) return Node_Type is
   begin
      return Nodet.Table (N).Field3;
   end Get_Field3;

   procedure Set_Field3 (N : Node_Type; V : Node_Type) is
   begin
      Nodet.Table (N).Field3 := V;
   end Set_Field3;

   function Get_Field4 (N : Node_Type) return Node_Type is
   begin
      return Nodet.Table (N).Field4;
   end Get_Field4;

   procedure Set_Field4 (N : Node_Type; V : Node_Type) is
   begin
      Nodet.Table (N).Field4 := V;
   end Set_Field4;

   function Get_Field5 (N : Node_Type) return Node_Type is
   begin
      return Nodet.Table (N).Field5;
   end Get_Field5;

   procedure Set_Field5 (N : Node_Type; V : Node_Type) is
   begin
      Nodet.Table (N).Field5 := V;
   end Set_Field5;

   function Get_Field6 (N: Node_Type) return Node_Type is
   begin
      return Node_Type (Nodet.Table (N + 1).Location);
   end Get_Field6;

   procedure Set_Field6 (N: Node_Type; Val: Node_Type) is
   begin
      Nodet.Table (N + 1).Location := Location_Type (Val);
   end Set_Field6;

   function Get_Field7 (N: Node_Type) return Node_Type is
   begin
      return Nodet.Table (N + 1).Field0;
   end Get_Field7;

   procedure Set_Field7 (N: Node_Type; Val: Node_Type) is
   begin
      Nodet.Table (N + 1).Field0 := Val;
   end Set_Field7;

   function Get_Field8 (N: Node_Type) return Node_Type is
   begin
      return Nodet.Table (N + 1).Field1;
   end Get_Field8;

   procedure Set_Field8 (N: Node_Type; Val: Node_Type) is
   begin
      Nodet.Table (N + 1).Field1 := Val;
   end Set_Field8;

   function Get_Field9 (N: Node_Type) return Node_Type is
   begin
      return Nodet.Table (N + 1).Field2;
   end Get_Field9;

   procedure Set_Field9 (N: Node_Type; Val: Node_Type) is
   begin
      Nodet.Table (N + 1).Field2 := Val;
   end Set_Field9;

   function Get_Field10 (N: Node_Type) return Node_Type is
   begin
      return Nodet.Table (N + 1).Field3;
   end Get_Field10;

   procedure Set_Field10 (N: Node_Type; Val: Node_Type) is
   begin
      Nodet.Table (N + 1).Field3 := Val;
   end Set_Field10;

   function Get_Field11 (N: Node_Type) return Node_Type is
   begin
      return Nodet.Table (N + 1).Field4;
   end Get_Field11;

   procedure Set_Field11 (N: Node_Type; Val: Node_Type) is
   begin
      Nodet.Table (N + 1).Field4 := Val;
   end Set_Field11;

   function Get_Field12 (N: Node_Type) return Node_Type is
   begin
      return Nodet.Table (N + 1).Field5;
   end Get_Field12;

   procedure Set_Field12 (N: Node_Type; Val: Node_Type) is
   begin
      Nodet.Table (N + 1).Field5 := Val;
   end Set_Field12;


   function Get_Flag1 (N : Node_Type) return Boolean is
   begin
      return Nodet.Table (N).Flag1;
   end Get_Flag1;

   procedure Set_Flag1 (N : Node_Type; V : Boolean) is
   begin
      Nodet.Table (N).Flag1 := V;
   end Set_Flag1;

   function Get_Flag2 (N : Node_Type) return Boolean is
   begin
      return Nodet.Table (N).Flag2;
   end Get_Flag2;

   procedure Set_Flag2 (N : Node_Type; V : Boolean) is
   begin
      Nodet.Table (N).Flag2 := V;
   end Set_Flag2;

   function Get_Flag3 (N : Node_Type) return Boolean is
   begin
      return Nodet.Table (N).Flag3;
   end Get_Flag3;

   procedure Set_Flag3 (N : Node_Type; V : Boolean) is
   begin
      Nodet.Table (N).Flag3 := V;
   end Set_Flag3;

   function Get_Flag4 (N : Node_Type) return Boolean is
   begin
      return Nodet.Table (N).Flag4;
   end Get_Flag4;

   procedure Set_Flag4 (N : Node_Type; V : Boolean) is
   begin
      Nodet.Table (N).Flag4 := V;
   end Set_Flag4;

   function Get_Flag5 (N : Node_Type) return Boolean is
   begin
      return Nodet.Table (N).Flag5;
   end Get_Flag5;

   procedure Set_Flag5 (N : Node_Type; V : Boolean) is
   begin
      Nodet.Table (N).Flag5 := V;
   end Set_Flag5;

   function Get_Flag6 (N : Node_Type) return Boolean is
   begin
      return Nodet.Table (N).Flag6;
   end Get_Flag6;

   procedure Set_Flag6 (N : Node_Type; V : Boolean) is
   begin
      Nodet.Table (N).Flag6 := V;
   end Set_Flag6;

   function Get_Flag7 (N : Node_Type) return Boolean is
   begin
      return Nodet.Table (N).Flag7;
   end Get_Flag7;

   procedure Set_Flag7 (N : Node_Type; V : Boolean) is
   begin
      Nodet.Table (N).Flag7 := V;
   end Set_Flag7;

   function Get_Flag8 (N : Node_Type) return Boolean is
   begin
      return Nodet.Table (N).Flag8;
   end Get_Flag8;

   procedure Set_Flag8 (N : Node_Type; V : Boolean) is
   begin
      Nodet.Table (N).Flag8 := V;
   end Set_Flag8;

   function Get_Flag9 (N : Node_Type) return Boolean is
   begin
      return Nodet.Table (N).Flag9;
   end Get_Flag9;

   procedure Set_Flag9 (N : Node_Type; V : Boolean) is
   begin
      Nodet.Table (N).Flag9 := V;
   end Set_Flag9;

   function Get_Flag10 (N : Node_Type) return Boolean is
   begin
      return Nodet.Table (N).Flag10;
   end Get_Flag10;

   procedure Set_Flag10 (N : Node_Type; V : Boolean) is
   begin
      Nodet.Table (N).Flag10 := V;
   end Set_Flag10;

   function Get_Flag11 (N : Node_Type) return Boolean is
   begin
      return Nodet.Table (N).Flag11;
   end Get_Flag11;

   procedure Set_Flag11 (N : Node_Type; V : Boolean) is
   begin
      Nodet.Table (N).Flag11 := V;
   end Set_Flag11;

   function Get_Flag12 (N : Node_Type) return Boolean is
   begin
      return Nodet.Table (N).Flag12;
   end Get_Flag12;

   procedure Set_Flag12 (N : Node_Type; V : Boolean) is
   begin
      Nodet.Table (N).Flag12 := V;
   end Set_Flag12;

   function Get_Flag13 (N : Node_Type) return Boolean is
   begin
      return Nodet.Table (N).Flag13;
   end Get_Flag13;

   procedure Set_Flag13 (N : Node_Type; V : Boolean) is
   begin
      Nodet.Table (N).Flag13 := V;
   end Set_Flag13;

   function Get_Flag14 (N : Node_Type) return Boolean is
   begin
      return Nodet.Table (N).Flag14;
   end Get_Flag14;

   procedure Set_Flag14 (N : Node_Type; V : Boolean) is
   begin
      Nodet.Table (N).Flag14 := V;
   end Set_Flag14;

   function Get_Flag15 (N : Node_Type) return Boolean is
   begin
      return Nodet.Table (N).Flag15;
   end Get_Flag15;

   procedure Set_Flag15 (N : Node_Type; V : Boolean) is
   begin
      Nodet.Table (N).Flag15 := V;
   end Set_Flag15;


   function Get_State1 (N : Node_Type) return Bit2_Type is
   begin
      return Nodet.Table (N).State1;
   end Get_State1;

   procedure Set_State1 (N : Node_Type; V : Bit2_Type) is
   begin
      Nodet.Table (N).State1 := V;
   end Set_State1;

   function Get_State2 (N : Node_Type) return Bit2_Type is
   begin
      return Nodet.Table (N).State2;
   end Get_State2;

   procedure Set_State2 (N : Node_Type; V : Bit2_Type) is
   begin
      Nodet.Table (N).State2 := V;
   end Set_State2;

   function Get_State3 (N : Node_Type) return Bit2_Type is
   begin
      return Nodet.Table (N + 1).State1;
   end Get_State3;

   procedure Set_State3 (N : Node_Type; V : Bit2_Type) is
   begin
      Nodet.Table (N + 1).State1 := V;
   end Set_State3;

   procedure Initialize is
   begin
      Free_Chain := Null_Node;
      Nodet.Init;
   end Initialize;

   procedure Finalize is
   begin
      Nodet.Free;
   end Finalize;

   function Is_Null (Node : Iir) return Boolean is
   begin
      return Node = Null_Iir;
   end Is_Null;

   function Is_Null_List (Node : Iir_List) return Boolean is
   begin
      return Node = Null_Iir_List;
   end Is_Null_List;

   function Is_Valid (Node : Iir) return Boolean is
   begin
      return Node /= Null_Iir;
   end Is_Valid;

   ---------------------------------------------------
   -- General subprograms that operate on every iir --
   ---------------------------------------------------

   function Get_Format (Kind : Iir_Kind) return Format_Type;

   function Create_Iir (Kind : Iir_Kind) return Iir
   is
      Res : Iir;
      Format : Format_Type;
   begin
      Format := Get_Format (Kind);
      Res := Create_Node (Format);
      Set_Nkind (Res, Iir_Kind'Pos (Kind));
      return Res;
   end Create_Iir;

   --  Statistics.
   procedure Disp_Stats
   is
      type Num_Array is array (Iir_Kind) of Natural;
      Num : Num_Array := (others => 0);
      type Format_Array is array (Format_Type) of Natural;
      Formats : Format_Array := (others => 0);
      Kind : Iir_Kind;
      I : Iir;
      Last_I : Iir;
      Format : Format_Type;
   begin
      I := Error_Node + 1;
      Last_I := Get_Last_Node;
      while I < Last_I loop
         Kind := Get_Kind (I);
         Num (Kind) := Num (Kind) + 1;
         Format := Get_Format (Kind);
         Formats (Format) := Formats (Format) + 1;
         I := Next_Node (I);
      end loop;

      Log_Line ("Stats per iir_kind:");
      for J in Iir_Kind loop
         if Num (J) /= 0 then
            Log_Line (' ' & Iir_Kind'Image (J) & ':'
                        & Natural'Image (Num (J)));
         end if;
      end loop;
      Log_Line ("Stats per formats:");
      for J in Format_Type loop
         Log_Line (' ' & Format_Type'Image (J) & ':'
                     & Natural'Image (Formats (J)));
      end loop;
   end Disp_Stats;

   function Kind_In (K : Iir_Kind; K1, K2 : Iir_Kind) return Boolean is
   begin
      return K = K1 or K = K2;
   end Kind_In;

   function Iir_Predefined_Shortcut_P (Func : Iir_Predefined_Functions)
     return Boolean is
   begin
      case Func is
         when Iir_Predefined_Bit_And
           | Iir_Predefined_Bit_Or
           | Iir_Predefined_Bit_Nand
           | Iir_Predefined_Bit_Nor
           | Iir_Predefined_Boolean_And
           | Iir_Predefined_Boolean_Or
           | Iir_Predefined_Boolean_Nand
           | Iir_Predefined_Boolean_Nor =>
            return True;
         when others =>
            return False;
      end case;
   end Iir_Predefined_Shortcut_P;

   function Create_Iir_Error return Iir
   is
      Res : Iir;
   begin
      Res := Create_Node (Format_Short);
      Set_Nkind (Res, Iir_Kind'Pos (Iir_Kind_Error));
      return Res;
   end Create_Iir_Error;

   procedure Location_Copy (Target : Iir; Src : Iir) is
   begin
      Set_Location (Target, Get_Location (Src));
   end Location_Copy;

   -- Get kind
   function Get_Kind (N : Iir) return Iir_Kind
   is
      --  Speed up: avoid to check that nkind is in the bounds of Iir_Kind.
      pragma Suppress (Range_Check);
   begin
      pragma Assert (N /= Null_Iir);
      return Iir_Kind'Val (Get_Nkind (N));
   end Get_Kind;

   function Time_Stamp_Id_To_Iir is new Ada.Unchecked_Conversion
     (Source => Time_Stamp_Id, Target => Iir);

   function Iir_To_Time_Stamp_Id is new Ada.Unchecked_Conversion
     (Source => Iir, Target => Time_Stamp_Id);

   function File_Checksum_Id_To_Iir is new Ada.Unchecked_Conversion
     (Source => File_Checksum_Id, Target => Iir);

   function Iir_To_File_Checksum_Id is new Ada.Unchecked_Conversion
     (Source => Iir, Target => File_Checksum_Id);

   function Iir_To_Iir_List is new Ada.Unchecked_Conversion
     (Source => Iir, Target => Iir_List);
   function Iir_List_To_Iir is new Ada.Unchecked_Conversion
     (Source => Iir_List, Target => Iir);

   function Iir_To_Iir_Flist is new Ada.Unchecked_Conversion
     (Source => Iir, Target => Iir_Flist);
   function Iir_Flist_To_Iir is new Ada.Unchecked_Conversion
     (Source => Iir_Flist, Target => Iir);

   function Iir_To_Token_Type (N : Iir) return Token_Type is
   begin
      return Token_Type'Val (N);
   end Iir_To_Token_Type;

   function Token_Type_To_Iir (T : Token_Type) return Iir is
   begin
      return Token_Type'Pos (T);
   end Token_Type_To_Iir;

--     function Iir_To_Iir_Index32 (N : Iir) return Iir_Index32 is
--     begin
--        return Iir_Index32 (N);
--     end Iir_To_Iir_Index32;

--     function Iir_Index32_To_Iir (V : Iir_Index32) return Iir is
--     begin
--        return Iir_Index32'Pos (V);
--     end Iir_Index32_To_Iir;

   function Iir_To_Name_Id (N : Iir) return Name_Id is
   begin
      return Iir'Pos (N);
   end Iir_To_Name_Id;
   pragma Inline (Iir_To_Name_Id);

   function Name_Id_To_Iir (V : Name_Id) return Iir is
   begin
      return Name_Id'Pos (V);
   end Name_Id_To_Iir;

   function Iir_To_Iir_Int32 is new Ada.Unchecked_Conversion
     (Source => Iir, Target => Iir_Int32);

   function Iir_Int32_To_Iir is new Ada.Unchecked_Conversion
     (Source => Iir_Int32, Target => Iir);

   function Iir_To_Source_Ptr (N : Iir) return Source_Ptr is
   begin
      return Source_Ptr (N);
   end Iir_To_Source_Ptr;

   function Source_Ptr_To_Iir (P : Source_Ptr) return Iir is
   begin
      return Iir (P);
   end Source_Ptr_To_Iir;

   function Iir_To_Source_File_Entry is new Ada.Unchecked_Conversion
     (Source => Iir, Target => Source_File_Entry);
   function Source_File_Entry_To_Iir is new Ada.Unchecked_Conversion
     (Source => Source_File_Entry, Target => Iir);

   function Boolean_To_Iir_Delay_Mechanism is new Ada.Unchecked_Conversion
     (Source => Boolean, Target => Iir_Delay_Mechanism);
   function Iir_Delay_Mechanism_To_Boolean is new Ada.Unchecked_Conversion
     (Source => Iir_Delay_Mechanism, Target => Boolean);

   function Boolean_To_Iir_Force_Mode is new Ada.Unchecked_Conversion
     (Source => Boolean, Target => Iir_Force_Mode);
   function Iir_Force_Mode_To_Boolean is new Ada.Unchecked_Conversion
     (Source => Iir_Force_Mode, Target => Boolean);

   function Boolean_To_Iir_Signal_Kind is new Ada.Unchecked_Conversion
     (Source => Boolean, Target => Iir_Signal_Kind);
   function Iir_Signal_Kind_To_Boolean is new Ada.Unchecked_Conversion
     (Source => Iir_Signal_Kind, Target => Boolean);

   function Boolean_To_Direction_Type is new Ada.Unchecked_Conversion
     (Source => Boolean, Target => Direction_Type);
   function Direction_Type_To_Boolean is new Ada.Unchecked_Conversion
     (Source => Direction_Type, Target => Boolean);

   function Iir_To_String8_Id is new Ada.Unchecked_Conversion
     (Source => Iir, Target => String8_Id);
   function String8_Id_To_Iir is new Ada.Unchecked_Conversion
     (Source => String8_Id, Target => Iir);

   function Iir_To_Int32 is new Ada.Unchecked_Conversion
     (Source => Iir, Target => Int32);
   function Int32_To_Iir is new Ada.Unchecked_Conversion
     (Source => Int32, Target => Iir);

   function Iir_To_PSL_Node is new Ada.Unchecked_Conversion
     (Source => Iir, Target => PSL_Node);

   function PSL_Node_To_Iir is new Ada.Unchecked_Conversion
     (Source => PSL_Node, Target => Iir);

   function Iir_To_PSL_NFA is new Ada.Unchecked_Conversion
     (Source => Iir, Target => PSL_NFA);

   function PSL_NFA_To_Iir is new Ada.Unchecked_Conversion
     (Source => PSL_NFA, Target => Iir);

   --  Subprograms
   function Get_Format (Kind : Iir_Kind) return Format_Type is
   begin
      case Kind is
         when Iir_Kind_Unused
           | Iir_Kind_Error
           | Iir_Kind_Library_Clause
           | Iir_Kind_Use_Clause
           | Iir_Kind_Context_Reference
           | Iir_Kind_PSL_Inherit_Spec
           | Iir_Kind_Integer_Literal
           | Iir_Kind_Floating_Point_Literal
           | Iir_Kind_Null_Literal
           | Iir_Kind_String_Literal8
           | Iir_Kind_Physical_Int_Literal
           | Iir_Kind_Physical_Fp_Literal
           | Iir_Kind_Simple_Aggregate
           | Iir_Kind_Overflow_Literal
           | Iir_Kind_Unaffected_Waveform
           | Iir_Kind_Waveform_Element
           | Iir_Kind_Conditional_Waveform
           | Iir_Kind_Conditional_Expression
           | Iir_Kind_Association_Element_By_Expression
           | Iir_Kind_Association_Element_By_Name
           | Iir_Kind_Association_Element_By_Individual
           | Iir_Kind_Association_Element_Open
           | Iir_Kind_Association_Element_Package
           | Iir_Kind_Association_Element_Type
           | Iir_Kind_Association_Element_Subprogram
           | Iir_Kind_Association_Element_Terminal
           | Iir_Kind_Choice_By_Range
           | Iir_Kind_Choice_By_Expression
           | Iir_Kind_Choice_By_Others
           | Iir_Kind_Choice_By_None
           | Iir_Kind_Choice_By_Name
           | Iir_Kind_Entity_Aspect_Entity
           | Iir_Kind_Entity_Aspect_Configuration
           | Iir_Kind_Entity_Aspect_Open
           | Iir_Kind_Psl_Hierarchical_Name
           | Iir_Kind_Block_Configuration
           | Iir_Kind_Component_Configuration
           | Iir_Kind_Entity_Class
           | Iir_Kind_Attribute_Value
           | Iir_Kind_Aggregate_Info
           | Iir_Kind_Procedure_Call
           | Iir_Kind_Record_Element_Constraint
           | Iir_Kind_Array_Element_Resolution
           | Iir_Kind_Record_Resolution
           | Iir_Kind_Record_Element_Resolution
           | Iir_Kind_Break_Element
           | Iir_Kind_Disconnection_Specification
           | Iir_Kind_Step_Limit_Specification
           | Iir_Kind_Configuration_Specification
           | Iir_Kind_Access_Type_Definition
           | Iir_Kind_Incomplete_Type_Definition
           | Iir_Kind_Interface_Type_Definition
           | Iir_Kind_File_Type_Definition
           | Iir_Kind_Protected_Type_Declaration
           | Iir_Kind_Record_Type_Definition
           | Iir_Kind_Access_Subtype_Definition
           | Iir_Kind_Physical_Subtype_Definition
           | Iir_Kind_Integer_Subtype_Definition
           | Iir_Kind_Enumeration_Subtype_Definition
           | Iir_Kind_Enumeration_Type_Definition
           | Iir_Kind_Integer_Type_Definition
           | Iir_Kind_Floating_Type_Definition
           | Iir_Kind_Physical_Type_Definition
           | Iir_Kind_Range_Expression
           | Iir_Kind_Protected_Type_Body
           | Iir_Kind_Wildcard_Type_Definition
           | Iir_Kind_Overload_List
           | Iir_Kind_Configuration_Declaration
           | Iir_Kind_Context_Declaration
           | Iir_Kind_Package_Body
           | Iir_Kind_Type_Declaration
           | Iir_Kind_Anonymous_Type_Declaration
           | Iir_Kind_Subtype_Declaration
           | Iir_Kind_Nature_Declaration
           | Iir_Kind_Subnature_Declaration
           | Iir_Kind_Unit_Declaration
           | Iir_Kind_Library_Declaration
           | Iir_Kind_Attribute_Declaration
           | Iir_Kind_Group_Template_Declaration
           | Iir_Kind_Group_Declaration
           | Iir_Kind_Element_Declaration
           | Iir_Kind_Nature_Element_Declaration
           | Iir_Kind_Non_Object_Alias_Declaration
           | Iir_Kind_Enumeration_Literal
           | Iir_Kind_Terminal_Declaration
           | Iir_Kind_Object_Alias_Declaration
           | Iir_Kind_Free_Quantity_Declaration
           | Iir_Kind_Noise_Quantity_Declaration
           | Iir_Kind_Guard_Signal_Declaration
           | Iir_Kind_Signal_Declaration
           | Iir_Kind_Variable_Declaration
           | Iir_Kind_Iterator_Declaration
           | Iir_Kind_Interface_Constant_Declaration
           | Iir_Kind_Interface_Variable_Declaration
           | Iir_Kind_Interface_Signal_Declaration
           | Iir_Kind_Interface_File_Declaration
           | Iir_Kind_Interface_Quantity_Declaration
           | Iir_Kind_Interface_Terminal_Declaration
           | Iir_Kind_Interface_Type_Declaration
           | Iir_Kind_Signal_Attribute_Declaration
           | Iir_Kind_Suspend_State_Declaration
           | Iir_Kind_Identity_Operator
           | Iir_Kind_Negation_Operator
           | Iir_Kind_Absolute_Operator
           | Iir_Kind_Not_Operator
           | Iir_Kind_Implicit_Condition_Operator
           | Iir_Kind_Condition_Operator
           | Iir_Kind_Reduction_And_Operator
           | Iir_Kind_Reduction_Or_Operator
           | Iir_Kind_Reduction_Nand_Operator
           | Iir_Kind_Reduction_Nor_Operator
           | Iir_Kind_Reduction_Xor_Operator
           | Iir_Kind_Reduction_Xnor_Operator
           | Iir_Kind_And_Operator
           | Iir_Kind_Or_Operator
           | Iir_Kind_Nand_Operator
           | Iir_Kind_Nor_Operator
           | Iir_Kind_Xor_Operator
           | Iir_Kind_Xnor_Operator
           | Iir_Kind_Equality_Operator
           | Iir_Kind_Inequality_Operator
           | Iir_Kind_Less_Than_Operator
           | Iir_Kind_Less_Than_Or_Equal_Operator
           | Iir_Kind_Greater_Than_Operator
           | Iir_Kind_Greater_Than_Or_Equal_Operator
           | Iir_Kind_Match_Equality_Operator
           | Iir_Kind_Match_Inequality_Operator
           | Iir_Kind_Match_Less_Than_Operator
           | Iir_Kind_Match_Less_Than_Or_Equal_Operator
           | Iir_Kind_Match_Greater_Than_Operator
           | Iir_Kind_Match_Greater_Than_Or_Equal_Operator
           | Iir_Kind_Sll_Operator
           | Iir_Kind_Sla_Operator
           | Iir_Kind_Srl_Operator
           | Iir_Kind_Sra_Operator
           | Iir_Kind_Rol_Operator
           | Iir_Kind_Ror_Operator
           | Iir_Kind_Addition_Operator
           | Iir_Kind_Substraction_Operator
           | Iir_Kind_Concatenation_Operator
           | Iir_Kind_Multiplication_Operator
           | Iir_Kind_Division_Operator
           | Iir_Kind_Modulus_Operator
           | Iir_Kind_Remainder_Operator
           | Iir_Kind_Exponentiation_Operator
           | Iir_Kind_Function_Call
           | Iir_Kind_Aggregate
           | Iir_Kind_Parenthesis_Expression
           | Iir_Kind_Qualified_Expression
           | Iir_Kind_Type_Conversion
           | Iir_Kind_Allocator_By_Expression
           | Iir_Kind_Allocator_By_Subtype
           | Iir_Kind_Selected_Element
           | Iir_Kind_Dereference
           | Iir_Kind_Implicit_Dereference
           | Iir_Kind_Slice_Name
           | Iir_Kind_Indexed_Name
           | Iir_Kind_Psl_Prev
           | Iir_Kind_Psl_Stable
           | Iir_Kind_Psl_Rose
           | Iir_Kind_Psl_Fell
           | Iir_Kind_Psl_Onehot
           | Iir_Kind_Psl_Onehot0
           | Iir_Kind_Psl_Expression
           | Iir_Kind_Concurrent_Assertion_Statement
           | Iir_Kind_Concurrent_Procedure_Call_Statement
           | Iir_Kind_If_Generate_Statement
           | Iir_Kind_Case_Generate_Statement
           | Iir_Kind_For_Generate_Statement
           | Iir_Kind_Psl_Default_Clock
           | Iir_Kind_Generate_Statement_Body
           | Iir_Kind_If_Generate_Else_Clause
           | Iir_Kind_Simultaneous_Null_Statement
           | Iir_Kind_Simultaneous_Procedural_Statement
           | Iir_Kind_Simultaneous_Case_Statement
           | Iir_Kind_Simultaneous_If_Statement
           | Iir_Kind_Simultaneous_Elsif
           | Iir_Kind_Simple_Signal_Assignment_Statement
           | Iir_Kind_Conditional_Signal_Assignment_Statement
           | Iir_Kind_Signal_Force_Assignment_Statement
           | Iir_Kind_Signal_Release_Assignment_Statement
           | Iir_Kind_Null_Statement
           | Iir_Kind_Assertion_Statement
           | Iir_Kind_Report_Statement
           | Iir_Kind_Variable_Assignment_Statement
           | Iir_Kind_Conditional_Variable_Assignment_Statement
           | Iir_Kind_Return_Statement
           | Iir_Kind_For_Loop_Statement
           | Iir_Kind_While_Loop_Statement
           | Iir_Kind_Next_Statement
           | Iir_Kind_Exit_Statement
           | Iir_Kind_Case_Statement
           | Iir_Kind_Procedure_Call_Statement
           | Iir_Kind_Break_Statement
           | Iir_Kind_If_Statement
           | Iir_Kind_Suspend_State_Statement
           | Iir_Kind_Elsif
           | Iir_Kind_Character_Literal
           | Iir_Kind_Simple_Name
           | Iir_Kind_Selected_Name
           | Iir_Kind_Operator_Symbol
           | Iir_Kind_Reference_Name
           | Iir_Kind_External_Constant_Name
           | Iir_Kind_External_Signal_Name
           | Iir_Kind_External_Variable_Name
           | Iir_Kind_Selected_By_All_Name
           | Iir_Kind_Parenthesis_Name
           | Iir_Kind_Package_Pathname
           | Iir_Kind_Absolute_Pathname
           | Iir_Kind_Relative_Pathname
           | Iir_Kind_Pathname_Element
           | Iir_Kind_Base_Attribute
           | Iir_Kind_Subtype_Attribute
           | Iir_Kind_Element_Attribute
           | Iir_Kind_Across_Attribute
           | Iir_Kind_Through_Attribute
           | Iir_Kind_Nature_Reference_Attribute
           | Iir_Kind_Left_Type_Attribute
           | Iir_Kind_Right_Type_Attribute
           | Iir_Kind_High_Type_Attribute
           | Iir_Kind_Low_Type_Attribute
           | Iir_Kind_Ascending_Type_Attribute
           | Iir_Kind_Image_Attribute
           | Iir_Kind_Value_Attribute
           | Iir_Kind_Pos_Attribute
           | Iir_Kind_Val_Attribute
           | Iir_Kind_Succ_Attribute
           | Iir_Kind_Pred_Attribute
           | Iir_Kind_Leftof_Attribute
           | Iir_Kind_Rightof_Attribute
           | Iir_Kind_Dot_Attribute
           | Iir_Kind_Integ_Attribute
           | Iir_Kind_Quantity_Delayed_Attribute
           | Iir_Kind_Above_Attribute
           | Iir_Kind_Delayed_Attribute
           | Iir_Kind_Stable_Attribute
           | Iir_Kind_Quiet_Attribute
           | Iir_Kind_Transaction_Attribute
           | Iir_Kind_Event_Attribute
           | Iir_Kind_Active_Attribute
           | Iir_Kind_Last_Event_Attribute
           | Iir_Kind_Last_Active_Attribute
           | Iir_Kind_Last_Value_Attribute
           | Iir_Kind_Driving_Attribute
           | Iir_Kind_Driving_Value_Attribute
           | Iir_Kind_Behavior_Attribute
           | Iir_Kind_Structure_Attribute
           | Iir_Kind_Simple_Name_Attribute
           | Iir_Kind_Instance_Name_Attribute
           | Iir_Kind_Path_Name_Attribute
           | Iir_Kind_Left_Array_Attribute
           | Iir_Kind_Right_Array_Attribute
           | Iir_Kind_High_Array_Attribute
           | Iir_Kind_Low_Array_Attribute
           | Iir_Kind_Length_Array_Attribute
           | Iir_Kind_Ascending_Array_Attribute
           | Iir_Kind_Range_Array_Attribute
           | Iir_Kind_Reverse_Range_Array_Attribute
           | Iir_Kind_Attribute_Name =>
            return Format_Short;
         when Iir_Kind_Design_File
           | Iir_Kind_Design_Unit
           | Iir_Kind_Block_Header
           | Iir_Kind_Binding_Indication
           | Iir_Kind_Signature
           | Iir_Kind_Attribute_Specification
           | Iir_Kind_Array_Type_Definition
           | Iir_Kind_Array_Subtype_Definition
           | Iir_Kind_Record_Subtype_Definition
           | Iir_Kind_Floating_Subtype_Definition
           | Iir_Kind_Foreign_Vector_Type_Definition
           | Iir_Kind_Subtype_Definition
           | Iir_Kind_Scalar_Nature_Definition
           | Iir_Kind_Record_Nature_Definition
           | Iir_Kind_Array_Nature_Definition
           | Iir_Kind_Array_Subnature_Definition
           | Iir_Kind_Foreign_Module
           | Iir_Kind_Entity_Declaration
           | Iir_Kind_Package_Declaration
           | Iir_Kind_Package_Instantiation_Declaration
           | Iir_Kind_Vmode_Declaration
           | Iir_Kind_Vprop_Declaration
           | Iir_Kind_Vunit_Declaration
           | Iir_Kind_Architecture_Body
           | Iir_Kind_Package_Header
           | Iir_Kind_Component_Declaration
           | Iir_Kind_Psl_Declaration
           | Iir_Kind_Psl_Endpoint_Declaration
           | Iir_Kind_Function_Declaration
           | Iir_Kind_Procedure_Declaration
           | Iir_Kind_Function_Body
           | Iir_Kind_Procedure_Body
           | Iir_Kind_Function_Instantiation_Declaration
           | Iir_Kind_Procedure_Instantiation_Declaration
           | Iir_Kind_Spectrum_Quantity_Declaration
           | Iir_Kind_Across_Quantity_Declaration
           | Iir_Kind_Through_Quantity_Declaration
           | Iir_Kind_File_Declaration
           | Iir_Kind_Constant_Declaration
           | Iir_Kind_Interface_Package_Declaration
           | Iir_Kind_Interface_Function_Declaration
           | Iir_Kind_Interface_Procedure_Declaration
           | Iir_Kind_Sensitized_Process_Statement
           | Iir_Kind_Process_Statement
           | Iir_Kind_Concurrent_Simple_Signal_Assignment
           | Iir_Kind_Concurrent_Conditional_Signal_Assignment
           | Iir_Kind_Concurrent_Selected_Signal_Assignment
           | Iir_Kind_Concurrent_Break_Statement
           | Iir_Kind_Psl_Assert_Directive
           | Iir_Kind_Psl_Assume_Directive
           | Iir_Kind_Psl_Cover_Directive
           | Iir_Kind_Psl_Restrict_Directive
           | Iir_Kind_Block_Statement
           | Iir_Kind_Component_Instantiation_Statement
           | Iir_Kind_Simple_Simultaneous_Statement
           | Iir_Kind_Selected_Waveform_Assignment_Statement
           | Iir_Kind_Wait_Statement
           | Iir_Kind_Signal_Slew_Attribute
           | Iir_Kind_Quantity_Slew_Attribute
           | Iir_Kind_Ramp_Attribute
           | Iir_Kind_Zoh_Attribute
           | Iir_Kind_Ltf_Attribute
           | Iir_Kind_Ztf_Attribute =>
            return Format_Medium;
      end case;
   end Get_Format;

   function Get_First_Design_Unit (Design : Iir) return Iir is
   begin
      pragma Assert (Design /= Null_Iir);
      pragma Assert (Has_First_Design_Unit (Get_Kind (Design)),
                     "no field First_Design_Unit");
      return Get_Field5 (Design);
   end Get_First_Design_Unit;

   procedure Set_First_Design_Unit (Design : Iir; Chain : Iir) is
   begin
      pragma Assert (Design /= Null_Iir);
      pragma Assert (Has_First_Design_Unit (Get_Kind (Design)),
                     "no field First_Design_Unit");
      Set_Field5 (Design, Chain);
   end Set_First_Design_Unit;

   function Get_Last_Design_Unit (Design : Iir) return Iir is
   begin
      pragma Assert (Design /= Null_Iir);
      pragma Assert (Has_Last_Design_Unit (Get_Kind (Design)),
                     "no field Last_Design_Unit");
      return Get_Field6 (Design);
   end Get_Last_Design_Unit;

   procedure Set_Last_Design_Unit (Design : Iir; Chain : Iir) is
   begin
      pragma Assert (Design /= Null_Iir);
      pragma Assert (Has_Last_Design_Unit (Get_Kind (Design)),
                     "no field Last_Design_Unit");
      Set_Field6 (Design, Chain);
   end Set_Last_Design_Unit;

   function Get_Library_Declaration (Design : Iir) return Iir is
   begin
      pragma Assert (Design /= Null_Iir);
      pragma Assert (Has_Library_Declaration (Get_Kind (Design)),
                     "no field Library_Declaration");
      return Get_Field1 (Design);
   end Get_Library_Declaration;

   procedure Set_Library_Declaration (Design : Iir; Library : Iir) is
   begin
      pragma Assert (Design /= Null_Iir);
      pragma Assert (Has_Library_Declaration (Get_Kind (Design)),
                     "no field Library_Declaration");
      Set_Field1 (Design, Library);
   end Set_Library_Declaration;

   function Get_File_Checksum (Design : Iir) return File_Checksum_Id is
   begin
      pragma Assert (Design /= Null_Iir);
      pragma Assert (Has_File_Checksum (Get_Kind (Design)),
                     "no field File_Checksum");
      return Iir_To_File_Checksum_Id (Get_Field4 (Design));
   end Get_File_Checksum;

   procedure Set_File_Checksum (Design : Iir; Checksum : File_Checksum_Id) is
   begin
      pragma Assert (Design /= Null_Iir);
      pragma Assert (Has_File_Checksum (Get_Kind (Design)),
                     "no field File_Checksum");
      Set_Field4 (Design, File_Checksum_Id_To_Iir (Checksum));
   end Set_File_Checksum;

   function Get_Analysis_Time_Stamp (Design : Iir) return Time_Stamp_Id is
   begin
      pragma Assert (Design /= Null_Iir);
      pragma Assert (Has_Analysis_Time_Stamp (Get_Kind (Design)),
                     "no field Analysis_Time_Stamp");
      return Iir_To_Time_Stamp_Id (Get_Field3 (Design));
   end Get_Analysis_Time_Stamp;

   procedure Set_Analysis_Time_Stamp (Design : Iir; Stamp : Time_Stamp_Id) is
   begin
      pragma Assert (Design /= Null_Iir);
      pragma Assert (Has_Analysis_Time_Stamp (Get_Kind (Design)),
                     "no field Analysis_Time_Stamp");
      Set_Field3 (Design, Time_Stamp_Id_To_Iir (Stamp));
   end Set_Analysis_Time_Stamp;

   function Get_Design_File_Source (Design : Iir) return Source_File_Entry is
   begin
      pragma Assert (Design /= Null_Iir);
      pragma Assert (Has_Design_File_Source (Get_Kind (Design)),
                     "no field Design_File_Source");
      return Iir_To_Source_File_Entry (Get_Field7 (Design));
   end Get_Design_File_Source;

   procedure Set_Design_File_Source (Design : Iir; Sfe : Source_File_Entry) is
   begin
      pragma Assert (Design /= Null_Iir);
      pragma Assert (Has_Design_File_Source (Get_Kind (Design)),
                     "no field Design_File_Source");
      Set_Field7 (Design, Source_File_Entry_To_Iir (Sfe));
   end Set_Design_File_Source;

   function Get_Library (File : Iir_Design_File) return Iir is
   begin
      pragma Assert (File /= Null_Iir);
      pragma Assert (Has_Library (Get_Kind (File)),
                     "no field Library");
      return Get_Field0 (File);
   end Get_Library;

   procedure Set_Library (File : Iir_Design_File; Lib : Iir) is
   begin
      pragma Assert (File /= Null_Iir);
      pragma Assert (Has_Library (Get_Kind (File)),
                     "no field Library");
      Set_Field0 (File, Lib);
   end Set_Library;

   function Get_File_Dependence_List (File : Iir_Design_File) return Iir_List
   is
   begin
      pragma Assert (File /= Null_Iir);
      pragma Assert (Has_File_Dependence_List (Get_Kind (File)),
                     "no field File_Dependence_List");
      return Iir_To_Iir_List (Get_Field1 (File));
   end Get_File_Dependence_List;

   procedure Set_File_Dependence_List (File : Iir_Design_File; Lst : Iir_List)
   is
   begin
      pragma Assert (File /= Null_Iir);
      pragma Assert (Has_File_Dependence_List (Get_Kind (File)),
                     "no field File_Dependence_List");
      Set_Field1 (File, Iir_List_To_Iir (Lst));
   end Set_File_Dependence_List;

   function Get_Design_File_Filename (File : Iir_Design_File) return Name_Id
   is
   begin
      pragma Assert (File /= Null_Iir);
      pragma Assert (Has_Design_File_Filename (Get_Kind (File)),
                     "no field Design_File_Filename");
      return Name_Id'Val (Get_Field12 (File));
   end Get_Design_File_Filename;

   procedure Set_Design_File_Filename (File : Iir_Design_File; Name : Name_Id)
   is
   begin
      pragma Assert (File /= Null_Iir);
      pragma Assert (Has_Design_File_Filename (Get_Kind (File)),
                     "no field Design_File_Filename");
      Set_Field12 (File, Name_Id'Pos (Name));
   end Set_Design_File_Filename;

   function Get_Design_File_Directory (File : Iir_Design_File) return Name_Id
   is
   begin
      pragma Assert (File /= Null_Iir);
      pragma Assert (Has_Design_File_Directory (Get_Kind (File)),
                     "no field Design_File_Directory");
      return Name_Id'Val (Get_Field11 (File));
   end Get_Design_File_Directory;

   procedure Set_Design_File_Directory (File : Iir_Design_File; Dir : Name_Id)
   is
   begin
      pragma Assert (File /= Null_Iir);
      pragma Assert (Has_Design_File_Directory (Get_Kind (File)),
                     "no field Design_File_Directory");
      Set_Field11 (File, Name_Id'Pos (Dir));
   end Set_Design_File_Directory;

   function Get_Design_File (Unit : Iir_Design_Unit) return Iir is
   begin
      pragma Assert (Unit /= Null_Iir);
      pragma Assert (Has_Design_File (Get_Kind (Unit)),
                     "no field Design_File");
      return Get_Field0 (Unit);
   end Get_Design_File;

   procedure Set_Design_File (Unit : Iir_Design_Unit; File : Iir) is
   begin
      pragma Assert (Unit /= Null_Iir);
      pragma Assert (Has_Design_File (Get_Kind (Unit)),
                     "no field Design_File");
      Set_Field0 (Unit, File);
   end Set_Design_File;

   function Get_Design_File_Chain (Library : Iir) return Iir is
   begin
      pragma Assert (Library /= Null_Iir);
      pragma Assert (Has_Design_File_Chain (Get_Kind (Library)),
                     "no field Design_File_Chain");
      return Get_Field1 (Library);
   end Get_Design_File_Chain;

   procedure Set_Design_File_Chain (Library : Iir; Chain : Iir) is
   begin
      pragma Assert (Library /= Null_Iir);
      pragma Assert (Has_Design_File_Chain (Get_Kind (Library)),
                     "no field Design_File_Chain");
      Set_Field1 (Library, Chain);
   end Set_Design_File_Chain;

   function Get_Library_Directory (Library : Iir) return Name_Id is
   begin
      pragma Assert (Library /= Null_Iir);
      pragma Assert (Has_Library_Directory (Get_Kind (Library)),
                     "no field Library_Directory");
      return Name_Id'Val (Get_Field5 (Library));
   end Get_Library_Directory;

   procedure Set_Library_Directory (Library : Iir; Dir : Name_Id) is
   begin
      pragma Assert (Library /= Null_Iir);
      pragma Assert (Has_Library_Directory (Get_Kind (Library)),
                     "no field Library_Directory");
      Set_Field5 (Library, Name_Id'Pos (Dir));
   end Set_Library_Directory;

   function Get_Date (Target : Iir) return Date_Type is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Date (Get_Kind (Target)),
                     "no field Date");
      return Date_Type'Val (Get_Field4 (Target));
   end Get_Date;

   procedure Set_Date (Target : Iir; Date : Date_Type) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Date (Get_Kind (Target)),
                     "no field Date");
      Set_Field4 (Target, Date_Type'Pos (Date));
   end Set_Date;

   function Get_Context_Items (Design_Unit : Iir) return Iir is
   begin
      pragma Assert (Design_Unit /= Null_Iir);
      pragma Assert (Has_Context_Items (Get_Kind (Design_Unit)),
                     "no field Context_Items");
      return Get_Field1 (Design_Unit);
   end Get_Context_Items;

   procedure Set_Context_Items (Design_Unit : Iir; Items_Chain : Iir) is
   begin
      pragma Assert (Design_Unit /= Null_Iir);
      pragma Assert (Has_Context_Items (Get_Kind (Design_Unit)),
                     "no field Context_Items");
      Set_Field1 (Design_Unit, Items_Chain);
   end Set_Context_Items;

   function Get_Dependence_List (Unit : Iir) return Iir_List is
   begin
      pragma Assert (Unit /= Null_Iir);
      pragma Assert (Has_Dependence_List (Get_Kind (Unit)),
                     "no field Dependence_List");
      return Iir_To_Iir_List (Get_Field8 (Unit));
   end Get_Dependence_List;

   procedure Set_Dependence_List (Unit : Iir; List : Iir_List) is
   begin
      pragma Assert (Unit /= Null_Iir);
      pragma Assert (Has_Dependence_List (Get_Kind (Unit)),
                     "no field Dependence_List");
      Set_Field8 (Unit, Iir_List_To_Iir (List));
   end Set_Dependence_List;

   function Get_Analysis_Checks_List (Unit : Iir) return Iir_List is
   begin
      pragma Assert (Unit /= Null_Iir);
      pragma Assert (Has_Analysis_Checks_List (Get_Kind (Unit)),
                     "no field Analysis_Checks_List");
      return Iir_To_Iir_List (Get_Field9 (Unit));
   end Get_Analysis_Checks_List;

   procedure Set_Analysis_Checks_List (Unit : Iir; List : Iir_List) is
   begin
      pragma Assert (Unit /= Null_Iir);
      pragma Assert (Has_Analysis_Checks_List (Get_Kind (Unit)),
                     "no field Analysis_Checks_List");
      Set_Field9 (Unit, Iir_List_To_Iir (List));
   end Set_Analysis_Checks_List;

   function Get_Date_State (Unit : Iir_Design_Unit) return Date_State_Type is
   begin
      pragma Assert (Unit /= Null_Iir);
      pragma Assert (Has_Date_State (Get_Kind (Unit)),
                     "no field Date_State");
      return Date_State_Type'Val (Get_State1 (Unit));
   end Get_Date_State;

   procedure Set_Date_State (Unit : Iir_Design_Unit; State : Date_State_Type)
   is
   begin
      pragma Assert (Unit /= Null_Iir);
      pragma Assert (Has_Date_State (Get_Kind (Unit)),
                     "no field Date_State");
      Set_State1 (Unit, Date_State_Type'Pos (State));
   end Set_Date_State;

   function Get_Guarded_Target_State (Stmt : Iir) return Tri_State_Type is
   begin
      pragma Assert (Stmt /= Null_Iir);
      pragma Assert (Has_Guarded_Target_State (Get_Kind (Stmt)),
                     "no field Guarded_Target_State");
      return Tri_State_Type'Val (Get_State1 (Stmt));
   end Get_Guarded_Target_State;

   procedure Set_Guarded_Target_State (Stmt : Iir; State : Tri_State_Type) is
   begin
      pragma Assert (Stmt /= Null_Iir);
      pragma Assert (Has_Guarded_Target_State (Get_Kind (Stmt)),
                     "no field Guarded_Target_State");
      Set_State1 (Stmt, Tri_State_Type'Pos (State));
   end Set_Guarded_Target_State;

   function Get_Library_Unit (Design_Unit : Iir_Design_Unit) return Iir is
   begin
      pragma Assert (Design_Unit /= Null_Iir);
      pragma Assert (Has_Library_Unit (Get_Kind (Design_Unit)),
                     "no field Library_Unit");
      return Get_Field7 (Design_Unit);
   end Get_Library_Unit;

   procedure Set_Library_Unit (Design_Unit : Iir_Design_Unit; Lib_Unit : Iir)
   is
   begin
      pragma Assert (Design_Unit /= Null_Iir);
      pragma Assert (Has_Library_Unit (Get_Kind (Design_Unit)),
                     "no field Library_Unit");
      Set_Field7 (Design_Unit, Lib_Unit);
   end Set_Library_Unit;

   function Get_Hash_Chain (Design_Unit : Iir_Design_Unit) return Iir is
   begin
      pragma Assert (Design_Unit /= Null_Iir);
      pragma Assert (Has_Hash_Chain (Get_Kind (Design_Unit)),
                     "no field Hash_Chain");
      return Get_Field5 (Design_Unit);
   end Get_Hash_Chain;

   procedure Set_Hash_Chain (Design_Unit : Iir_Design_Unit; Chain : Iir) is
   begin
      pragma Assert (Design_Unit /= Null_Iir);
      pragma Assert (Has_Hash_Chain (Get_Kind (Design_Unit)),
                     "no field Hash_Chain");
      Set_Field5 (Design_Unit, Chain);
   end Set_Hash_Chain;

   function Get_Design_Unit_Source_Pos (Design_Unit : Iir) return Source_Ptr
   is
   begin
      pragma Assert (Design_Unit /= Null_Iir);
      pragma Assert (Has_Design_Unit_Source_Pos (Get_Kind (Design_Unit)),
                     "no field Design_Unit_Source_Pos");
      return Iir_To_Source_Ptr (Get_Field10 (Design_Unit));
   end Get_Design_Unit_Source_Pos;

   procedure Set_Design_Unit_Source_Pos (Design_Unit : Iir; Pos : Source_Ptr)
   is
   begin
      pragma Assert (Design_Unit /= Null_Iir);
      pragma Assert (Has_Design_Unit_Source_Pos (Get_Kind (Design_Unit)),
                     "no field Design_Unit_Source_Pos");
      Set_Field10 (Design_Unit, Source_Ptr_To_Iir (Pos));
   end Set_Design_Unit_Source_Pos;

   function Get_Design_Unit_Source_Line (Design_Unit : Iir) return Int32 is
   begin
      pragma Assert (Design_Unit /= Null_Iir);
      pragma Assert (Has_Design_Unit_Source_Line (Get_Kind (Design_Unit)),
                     "no field Design_Unit_Source_Line");
      return Iir_To_Int32 (Get_Field11 (Design_Unit));
   end Get_Design_Unit_Source_Line;

   procedure Set_Design_Unit_Source_Line (Design_Unit : Iir; Line : Int32) is
   begin
      pragma Assert (Design_Unit /= Null_Iir);
      pragma Assert (Has_Design_Unit_Source_Line (Get_Kind (Design_Unit)),
                     "no field Design_Unit_Source_Line");
      Set_Field11 (Design_Unit, Int32_To_Iir (Line));
   end Set_Design_Unit_Source_Line;

   function Get_Design_Unit_Source_Col (Design_Unit : Iir) return Int32 is
   begin
      pragma Assert (Design_Unit /= Null_Iir);
      pragma Assert (Has_Design_Unit_Source_Col (Get_Kind (Design_Unit)),
                     "no field Design_Unit_Source_Col");
      return Iir_To_Int32 (Get_Field12 (Design_Unit));
   end Get_Design_Unit_Source_Col;

   procedure Set_Design_Unit_Source_Col (Design_Unit : Iir; Line : Int32) is
   begin
      pragma Assert (Design_Unit /= Null_Iir);
      pragma Assert (Has_Design_Unit_Source_Col (Get_Kind (Design_Unit)),
                     "no field Design_Unit_Source_Col");
      Set_Field12 (Design_Unit, Int32_To_Iir (Line));
   end Set_Design_Unit_Source_Col;

   type Int64_Conv is record
      Field4: Iir;
      Field5: Iir;
   end record;
   pragma Pack (Int64_Conv);
   pragma Assert (Int64_Conv'Size = Int64'Size);

   function Get_Value (Lit : Iir) return Int64
   is
      function To_Int64 is new Ada.Unchecked_Conversion
         (Int64_Conv, Int64);
      Conv : Int64_Conv;
   begin
      pragma Assert (Lit /= Null_Iir);
      pragma Assert (Has_Value (Get_Kind (Lit)),
                     "no field Value");
      Conv.Field4 := Get_Field4 (Lit);
      Conv.Field5 := Get_Field5 (Lit);
      return To_Int64 (Conv);
   end Get_Value;

   procedure Set_Value (Lit : Iir; Val : Int64)
   is
      function To_Int64_Conv is new Ada.Unchecked_Conversion
         (Int64, Int64_Conv);
      Conv : Int64_Conv;
   begin
      pragma Assert (Lit /= Null_Iir);
      pragma Assert (Has_Value (Get_Kind (Lit)),
                     "no field Value");
      Conv := To_Int64_Conv (Val);
      Set_Field4 (Lit, Conv.Field4);
      Set_Field5 (Lit, Conv.Field5);
   end Set_Value;

   function Get_Enum_Pos (Lit : Iir) return Iir_Int32 is
   begin
      pragma Assert (Lit /= Null_Iir);
      pragma Assert (Has_Enum_Pos (Get_Kind (Lit)),
                     "no field Enum_Pos");
      return Iir_Int32'Val (Get_Field5 (Lit));
   end Get_Enum_Pos;

   procedure Set_Enum_Pos (Lit : Iir; Val : Iir_Int32) is
   begin
      pragma Assert (Lit /= Null_Iir);
      pragma Assert (Has_Enum_Pos (Get_Kind (Lit)),
                     "no field Enum_Pos");
      Set_Field5 (Lit, Iir_Int32'Pos (Val));
   end Set_Enum_Pos;

   function Get_Physical_Literal (Unit : Iir) return Iir is
   begin
      pragma Assert (Unit /= Null_Iir);
      pragma Assert (Has_Physical_Literal (Get_Kind (Unit)),
                     "no field Physical_Literal");
      return Get_Field4 (Unit);
   end Get_Physical_Literal;

   procedure Set_Physical_Literal (Unit : Iir; Lit : Iir) is
   begin
      pragma Assert (Unit /= Null_Iir);
      pragma Assert (Has_Physical_Literal (Get_Kind (Unit)),
                     "no field Physical_Literal");
      Set_Field4 (Unit, Lit);
   end Set_Physical_Literal;

   type Fp64_Conv is record
      Field4: Iir;
      Field5: Iir;
   end record;
   pragma Pack (Fp64_Conv);
   pragma Assert (Fp64_Conv'Size = Fp64'Size);

   function Get_Fp_Value (Lit : Iir) return Fp64
   is
      function To_Fp64 is new Ada.Unchecked_Conversion
         (Fp64_Conv, Fp64);
      Conv : Fp64_Conv;
   begin
      pragma Assert (Lit /= Null_Iir);
      pragma Assert (Has_Fp_Value (Get_Kind (Lit)),
                     "no field Fp_Value");
      Conv.Field4 := Get_Field4 (Lit);
      Conv.Field5 := Get_Field5 (Lit);
      return To_Fp64 (Conv);
   end Get_Fp_Value;

   procedure Set_Fp_Value (Lit : Iir; Val : Fp64)
   is
      function To_Fp64_Conv is new Ada.Unchecked_Conversion
         (Fp64, Fp64_Conv);
      Conv : Fp64_Conv;
   begin
      pragma Assert (Lit /= Null_Iir);
      pragma Assert (Has_Fp_Value (Get_Kind (Lit)),
                     "no field Fp_Value");
      Conv := To_Fp64_Conv (Val);
      Set_Field4 (Lit, Conv.Field4);
      Set_Field5 (Lit, Conv.Field5);
   end Set_Fp_Value;

   function Get_Simple_Aggregate_List (Target : Iir) return Iir_Flist is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Simple_Aggregate_List (Get_Kind (Target)),
                     "no field Simple_Aggregate_List");
      return Iir_To_Iir_Flist (Get_Field4 (Target));
   end Get_Simple_Aggregate_List;

   procedure Set_Simple_Aggregate_List (Target : Iir; List : Iir_Flist) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Simple_Aggregate_List (Get_Kind (Target)),
                     "no field Simple_Aggregate_List");
      Set_Field4 (Target, Iir_Flist_To_Iir (List));
   end Set_Simple_Aggregate_List;

   function Get_String8_Id (Lit : Iir) return String8_Id is
   begin
      pragma Assert (Lit /= Null_Iir);
      pragma Assert (Has_String8_Id (Get_Kind (Lit)),
                     "no field String8_Id");
      return Iir_To_String8_Id (Get_Field5 (Lit));
   end Get_String8_Id;

   procedure Set_String8_Id (Lit : Iir; Id : String8_Id) is
   begin
      pragma Assert (Lit /= Null_Iir);
      pragma Assert (Has_String8_Id (Get_Kind (Lit)),
                     "no field String8_Id");
      Set_Field5 (Lit, String8_Id_To_Iir (Id));
   end Set_String8_Id;

   function Get_String_Length (Lit : Iir) return Int32 is
   begin
      pragma Assert (Lit /= Null_Iir);
      pragma Assert (Has_String_Length (Get_Kind (Lit)),
                     "no field String_Length");
      return Iir_To_Int32 (Get_Field4 (Lit));
   end Get_String_Length;

   procedure Set_String_Length (Lit : Iir; Len : Int32) is
   begin
      pragma Assert (Lit /= Null_Iir);
      pragma Assert (Has_String_Length (Get_Kind (Lit)),
                     "no field String_Length");
      Set_Field4 (Lit, Int32_To_Iir (Len));
   end Set_String_Length;

   type Number_Base_Type_Conv is record
      Flag12: Boolean;
      Flag13: Boolean;
      Flag14: Boolean;
   end record;
   pragma Pack (Number_Base_Type_Conv);
   pragma Assert (Number_Base_Type_Conv'Size = Number_Base_Type'Size);

   function Get_Bit_String_Base (Lit : Iir) return Number_Base_Type
   is
      function To_Number_Base_Type is new Ada.Unchecked_Conversion
         (Number_Base_Type_Conv, Number_Base_Type);
      Conv : Number_Base_Type_Conv;
   begin
      pragma Assert (Lit /= Null_Iir);
      pragma Assert (Has_Bit_String_Base (Get_Kind (Lit)),
                     "no field Bit_String_Base");
      Conv.Flag12 := Get_Flag12 (Lit);
      Conv.Flag13 := Get_Flag13 (Lit);
      Conv.Flag14 := Get_Flag14 (Lit);
      return To_Number_Base_Type (Conv);
   end Get_Bit_String_Base;

   procedure Set_Bit_String_Base (Lit : Iir; Base : Number_Base_Type)
   is
      function To_Number_Base_Type_Conv is new Ada.Unchecked_Conversion
         (Number_Base_Type, Number_Base_Type_Conv);
      Conv : Number_Base_Type_Conv;
   begin
      pragma Assert (Lit /= Null_Iir);
      pragma Assert (Has_Bit_String_Base (Get_Kind (Lit)),
                     "no field Bit_String_Base");
      Conv := To_Number_Base_Type_Conv (Base);
      Set_Flag12 (Lit, Conv.Flag12);
      Set_Flag13 (Lit, Conv.Flag13);
      Set_Flag14 (Lit, Conv.Flag14);
   end Set_Bit_String_Base;

   function Get_Has_Signed (Lit : Iir) return Boolean is
   begin
      pragma Assert (Lit /= Null_Iir);
      pragma Assert (Has_Has_Signed (Get_Kind (Lit)),
                     "no field Has_Signed");
      return Get_Flag1 (Lit);
   end Get_Has_Signed;

   procedure Set_Has_Signed (Lit : Iir; Flag : Boolean) is
   begin
      pragma Assert (Lit /= Null_Iir);
      pragma Assert (Has_Has_Signed (Get_Kind (Lit)),
                     "no field Has_Signed");
      Set_Flag1 (Lit, Flag);
   end Set_Has_Signed;

   function Get_Has_Sign (Lit : Iir) return Boolean is
   begin
      pragma Assert (Lit /= Null_Iir);
      pragma Assert (Has_Has_Sign (Get_Kind (Lit)),
                     "no field Has_Sign");
      return Get_Flag2 (Lit);
   end Get_Has_Sign;

   procedure Set_Has_Sign (Lit : Iir; Flag : Boolean) is
   begin
      pragma Assert (Lit /= Null_Iir);
      pragma Assert (Has_Has_Sign (Get_Kind (Lit)),
                     "no field Has_Sign");
      Set_Flag2 (Lit, Flag);
   end Set_Has_Sign;

   function Get_Has_Length (Lit : Iir) return Boolean is
   begin
      pragma Assert (Lit /= Null_Iir);
      pragma Assert (Has_Has_Length (Get_Kind (Lit)),
                     "no field Has_Length");
      return Get_Flag3 (Lit);
   end Get_Has_Length;

   procedure Set_Has_Length (Lit : Iir; Flag : Boolean) is
   begin
      pragma Assert (Lit /= Null_Iir);
      pragma Assert (Has_Has_Length (Get_Kind (Lit)),
                     "no field Has_Length");
      Set_Flag3 (Lit, Flag);
   end Set_Has_Length;

   function Get_Literal_Length (Lit : Iir) return Int32 is
   begin
      pragma Assert (Lit /= Null_Iir);
      pragma Assert (Has_Literal_Length (Get_Kind (Lit)),
                     "no field Literal_Length");
      return Iir_To_Int32 (Get_Field0 (Lit));
   end Get_Literal_Length;

   procedure Set_Literal_Length (Lit : Iir; Len : Int32) is
   begin
      pragma Assert (Lit /= Null_Iir);
      pragma Assert (Has_Literal_Length (Get_Kind (Lit)),
                     "no field Literal_Length");
      Set_Field0 (Lit, Int32_To_Iir (Len));
   end Set_Literal_Length;

   function Get_Literal_Origin (Lit : Iir) return Iir is
   begin
      pragma Assert (Lit /= Null_Iir);
      pragma Assert (Has_Literal_Origin (Get_Kind (Lit)),
                     "no field Literal_Origin");
      return Get_Field2 (Lit);
   end Get_Literal_Origin;

   procedure Set_Literal_Origin (Lit : Iir; Orig : Iir) is
   begin
      pragma Assert (Lit /= Null_Iir);
      pragma Assert (Has_Literal_Origin (Get_Kind (Lit)),
                     "no field Literal_Origin");
      Set_Field2 (Lit, Orig);
   end Set_Literal_Origin;

   function Get_Range_Origin (Lit : Iir) return Iir is
   begin
      pragma Assert (Lit /= Null_Iir);
      pragma Assert (Has_Range_Origin (Get_Kind (Lit)),
                     "no field Range_Origin");
      return Get_Field0 (Lit);
   end Get_Range_Origin;

   procedure Set_Range_Origin (Lit : Iir; Orig : Iir) is
   begin
      pragma Assert (Lit /= Null_Iir);
      pragma Assert (Has_Range_Origin (Get_Kind (Lit)),
                     "no field Range_Origin");
      Set_Field0 (Lit, Orig);
   end Set_Range_Origin;

   function Get_Literal_Subtype (Lit : Iir) return Iir is
   begin
      pragma Assert (Lit /= Null_Iir);
      pragma Assert (Has_Literal_Subtype (Get_Kind (Lit)),
                     "no field Literal_Subtype");
      return Get_Field3 (Lit);
   end Get_Literal_Subtype;

   procedure Set_Literal_Subtype (Lit : Iir; Atype : Iir) is
   begin
      pragma Assert (Lit /= Null_Iir);
      pragma Assert (Has_Literal_Subtype (Get_Kind (Lit)),
                     "no field Literal_Subtype");
      Set_Field3 (Lit, Atype);
   end Set_Literal_Subtype;

   function Get_Allocator_Subtype (Lit : Iir) return Iir is
   begin
      pragma Assert (Lit /= Null_Iir);
      pragma Assert (Has_Allocator_Subtype (Get_Kind (Lit)),
                     "no field Allocator_Subtype");
      return Get_Field3 (Lit);
   end Get_Allocator_Subtype;

   procedure Set_Allocator_Subtype (Lit : Iir; Atype : Iir) is
   begin
      pragma Assert (Lit /= Null_Iir);
      pragma Assert (Has_Allocator_Subtype (Get_Kind (Lit)),
                     "no field Allocator_Subtype");
      Set_Field3 (Lit, Atype);
   end Set_Allocator_Subtype;

   function Get_Entity_Class (Target : Iir) return Token_Type is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Entity_Class (Get_Kind (Target)),
                     "no field Entity_Class");
      return Iir_To_Token_Type (Get_Field3 (Target));
   end Get_Entity_Class;

   procedure Set_Entity_Class (Target : Iir; Kind : Token_Type) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Entity_Class (Get_Kind (Target)),
                     "no field Entity_Class");
      Set_Field3 (Target, Token_Type_To_Iir (Kind));
   end Set_Entity_Class;

   function Get_Entity_Name_List (Target : Iir) return Iir_Flist is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Entity_Name_List (Get_Kind (Target)),
                     "no field Entity_Name_List");
      return Iir_To_Iir_Flist (Get_Field8 (Target));
   end Get_Entity_Name_List;

   procedure Set_Entity_Name_List (Target : Iir; Names : Iir_Flist) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Entity_Name_List (Get_Kind (Target)),
                     "no field Entity_Name_List");
      Set_Field8 (Target, Iir_Flist_To_Iir (Names));
   end Set_Entity_Name_List;

   function Get_Attribute_Designator (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Attribute_Designator (Get_Kind (Target)),
                     "no field Attribute_Designator");
      return Get_Field6 (Target);
   end Get_Attribute_Designator;

   procedure Set_Attribute_Designator (Target : Iir; Designator : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Attribute_Designator (Get_Kind (Target)),
                     "no field Attribute_Designator");
      Set_Field6 (Target, Designator);
   end Set_Attribute_Designator;

   function Get_Attribute_Specification_Chain (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Attribute_Specification_Chain (Get_Kind (Target)),
                     "no field Attribute_Specification_Chain");
      return Get_Field7 (Target);
   end Get_Attribute_Specification_Chain;

   procedure Set_Attribute_Specification_Chain (Target : Iir; Chain : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Attribute_Specification_Chain (Get_Kind (Target)),
                     "no field Attribute_Specification_Chain");
      Set_Field7 (Target, Chain);
   end Set_Attribute_Specification_Chain;

   function Get_Attribute_Specification (Val : Iir) return Iir is
   begin
      pragma Assert (Val /= Null_Iir);
      pragma Assert (Has_Attribute_Specification (Get_Kind (Val)),
                     "no field Attribute_Specification");
      return Get_Field4 (Val);
   end Get_Attribute_Specification;

   procedure Set_Attribute_Specification (Val : Iir; Attr : Iir) is
   begin
      pragma Assert (Val /= Null_Iir);
      pragma Assert (Has_Attribute_Specification (Get_Kind (Val)),
                     "no field Attribute_Specification");
      Set_Field4 (Val, Attr);
   end Set_Attribute_Specification;

   function Get_Static_Attribute_Flag (Attr : Iir) return Boolean is
   begin
      pragma Assert (Attr /= Null_Iir);
      pragma Assert (Has_Static_Attribute_Flag (Get_Kind (Attr)),
                     "no field Static_Attribute_Flag");
      return Get_Flag2 (Attr);
   end Get_Static_Attribute_Flag;

   procedure Set_Static_Attribute_Flag (Attr : Iir; Flag : Boolean) is
   begin
      pragma Assert (Attr /= Null_Iir);
      pragma Assert (Has_Static_Attribute_Flag (Get_Kind (Attr)),
                     "no field Static_Attribute_Flag");
      Set_Flag2 (Attr, Flag);
   end Set_Static_Attribute_Flag;

   function Get_Signal_List (Target : Iir) return Iir_Flist is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Signal_List (Get_Kind (Target)),
                     "no field Signal_List");
      return Iir_To_Iir_Flist (Get_Field3 (Target));
   end Get_Signal_List;

   procedure Set_Signal_List (Target : Iir; List : Iir_Flist) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Signal_List (Get_Kind (Target)),
                     "no field Signal_List");
      Set_Field3 (Target, Iir_Flist_To_Iir (List));
   end Set_Signal_List;

   function Get_Quantity_List (Target : Iir) return Iir_Flist is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Quantity_List (Get_Kind (Target)),
                     "no field Quantity_List");
      return Iir_To_Iir_Flist (Get_Field3 (Target));
   end Get_Quantity_List;

   procedure Set_Quantity_List (Target : Iir; List : Iir_Flist) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Quantity_List (Get_Kind (Target)),
                     "no field Quantity_List");
      Set_Field3 (Target, Iir_Flist_To_Iir (List));
   end Set_Quantity_List;

   function Get_Designated_Entity (Val : Iir_Attribute_Value) return Iir is
   begin
      pragma Assert (Val /= Null_Iir);
      pragma Assert (Has_Designated_Entity (Get_Kind (Val)),
                     "no field Designated_Entity");
      return Get_Field3 (Val);
   end Get_Designated_Entity;

   procedure Set_Designated_Entity (Val : Iir_Attribute_Value; Entity : Iir)
   is
   begin
      pragma Assert (Val /= Null_Iir);
      pragma Assert (Has_Designated_Entity (Get_Kind (Val)),
                     "no field Designated_Entity");
      Set_Field3 (Val, Entity);
   end Set_Designated_Entity;

   function Get_Formal (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Formal (Get_Kind (Target)),
                     "no field Formal");
      return Get_Field1 (Target);
   end Get_Formal;

   procedure Set_Formal (Target : Iir; Formal : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Formal (Get_Kind (Target)),
                     "no field Formal");
      Set_Field1 (Target, Formal);
   end Set_Formal;

   function Get_Actual (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Actual (Get_Kind (Target)),
                     "no field Actual");
      return Get_Field3 (Target);
   end Get_Actual;

   procedure Set_Actual (Target : Iir; Actual : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Actual (Get_Kind (Target)),
                     "no field Actual");
      Set_Field3 (Target, Actual);
   end Set_Actual;

   function Get_Actual_Conversion (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Actual_Conversion (Get_Kind (Target)),
                     "no field Actual_Conversion");
      return Get_Field4 (Target);
   end Get_Actual_Conversion;

   procedure Set_Actual_Conversion (Target : Iir; Conv : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Actual_Conversion (Get_Kind (Target)),
                     "no field Actual_Conversion");
      Set_Field4 (Target, Conv);
   end Set_Actual_Conversion;

   function Get_Formal_Conversion (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Formal_Conversion (Get_Kind (Target)),
                     "no field Formal_Conversion");
      return Get_Field5 (Target);
   end Get_Formal_Conversion;

   procedure Set_Formal_Conversion (Target : Iir; Conv : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Formal_Conversion (Get_Kind (Target)),
                     "no field Formal_Conversion");
      Set_Field5 (Target, Conv);
   end Set_Formal_Conversion;

   function Get_Whole_Association_Flag (Target : Iir) return Boolean is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Whole_Association_Flag (Get_Kind (Target)),
                     "no field Whole_Association_Flag");
      return Get_Flag1 (Target);
   end Get_Whole_Association_Flag;

   procedure Set_Whole_Association_Flag (Target : Iir; Flag : Boolean) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Whole_Association_Flag (Get_Kind (Target)),
                     "no field Whole_Association_Flag");
      Set_Flag1 (Target, Flag);
   end Set_Whole_Association_Flag;

   function Get_Collapse_Signal_Flag (Target : Iir) return Boolean is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Collapse_Signal_Flag (Get_Kind (Target)),
                     "no field Collapse_Signal_Flag");
      return Get_Flag2 (Target);
   end Get_Collapse_Signal_Flag;

   procedure Set_Collapse_Signal_Flag (Target : Iir; Flag : Boolean) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Collapse_Signal_Flag (Get_Kind (Target)),
                     "no field Collapse_Signal_Flag");
      Set_Flag2 (Target, Flag);
   end Set_Collapse_Signal_Flag;

   function Get_Artificial_Flag (Target : Iir) return Boolean is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Artificial_Flag (Get_Kind (Target)),
                     "no field Artificial_Flag");
      return Get_Flag3 (Target);
   end Get_Artificial_Flag;

   procedure Set_Artificial_Flag (Target : Iir; Flag : Boolean) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Artificial_Flag (Get_Kind (Target)),
                     "no field Artificial_Flag");
      Set_Flag3 (Target, Flag);
   end Set_Artificial_Flag;

   function Get_Open_Flag (Target : Iir) return Boolean is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Open_Flag (Get_Kind (Target)),
                     "no field Open_Flag");
      return Get_Flag7 (Target);
   end Get_Open_Flag;

   procedure Set_Open_Flag (Target : Iir; Flag : Boolean) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Open_Flag (Get_Kind (Target)),
                     "no field Open_Flag");
      Set_Flag7 (Target, Flag);
   end Set_Open_Flag;

   function Get_After_Drivers_Flag (Target : Iir) return Boolean is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_After_Drivers_Flag (Get_Kind (Target)),
                     "no field After_Drivers_Flag");
      return Get_Flag5 (Target);
   end Get_After_Drivers_Flag;

   procedure Set_After_Drivers_Flag (Target : Iir; Flag : Boolean) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_After_Drivers_Flag (Get_Kind (Target)),
                     "no field After_Drivers_Flag");
      Set_Flag5 (Target, Flag);
   end Set_After_Drivers_Flag;

   function Get_We_Value (We : Iir_Waveform_Element) return Iir is
   begin
      pragma Assert (We /= Null_Iir);
      pragma Assert (Has_We_Value (Get_Kind (We)),
                     "no field We_Value");
      return Get_Field1 (We);
   end Get_We_Value;

   procedure Set_We_Value (We : Iir_Waveform_Element; An_Iir : Iir) is
   begin
      pragma Assert (We /= Null_Iir);
      pragma Assert (Has_We_Value (Get_Kind (We)),
                     "no field We_Value");
      Set_Field1 (We, An_Iir);
   end Set_We_Value;

   function Get_Time (We : Iir_Waveform_Element) return Iir is
   begin
      pragma Assert (We /= Null_Iir);
      pragma Assert (Has_Time (Get_Kind (We)),
                     "no field Time");
      return Get_Field3 (We);
   end Get_Time;

   procedure Set_Time (We : Iir_Waveform_Element; An_Iir : Iir) is
   begin
      pragma Assert (We /= Null_Iir);
      pragma Assert (Has_Time (Get_Kind (We)),
                     "no field Time");
      Set_Field3 (We, An_Iir);
   end Set_Time;

   function Get_Associated_Expr (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Associated_Expr (Get_Kind (Target)),
                     "no field Associated_Expr");
      return Get_Field3 (Target);
   end Get_Associated_Expr;

   procedure Set_Associated_Expr (Target : Iir; Associated : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Associated_Expr (Get_Kind (Target)),
                     "no field Associated_Expr");
      Set_Field3 (Target, Associated);
   end Set_Associated_Expr;

   function Get_Associated_Block (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Associated_Block (Get_Kind (Target)),
                     "no field Associated_Block");
      return Get_Field3 (Target);
   end Get_Associated_Block;

   procedure Set_Associated_Block (Target : Iir; Associated : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Associated_Block (Get_Kind (Target)),
                     "no field Associated_Block");
      Set_Field3 (Target, Associated);
   end Set_Associated_Block;

   function Get_Associated_Chain (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Associated_Chain (Get_Kind (Target)),
                     "no field Associated_Chain");
      return Get_Field4 (Target);
   end Get_Associated_Chain;

   procedure Set_Associated_Chain (Target : Iir; Associated : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Associated_Chain (Get_Kind (Target)),
                     "no field Associated_Chain");
      Set_Field4 (Target, Associated);
   end Set_Associated_Chain;

   function Get_Choice_Name (Choice : Iir) return Iir is
   begin
      pragma Assert (Choice /= Null_Iir);
      pragma Assert (Has_Choice_Name (Get_Kind (Choice)),
                     "no field Choice_Name");
      return Get_Field5 (Choice);
   end Get_Choice_Name;

   procedure Set_Choice_Name (Choice : Iir; Name : Iir) is
   begin
      pragma Assert (Choice /= Null_Iir);
      pragma Assert (Has_Choice_Name (Get_Kind (Choice)),
                     "no field Choice_Name");
      Set_Field5 (Choice, Name);
   end Set_Choice_Name;

   function Get_Choice_Expression (Choice : Iir) return Iir is
   begin
      pragma Assert (Choice /= Null_Iir);
      pragma Assert (Has_Choice_Expression (Get_Kind (Choice)),
                     "no field Choice_Expression");
      return Get_Field5 (Choice);
   end Get_Choice_Expression;

   procedure Set_Choice_Expression (Choice : Iir; Name : Iir) is
   begin
      pragma Assert (Choice /= Null_Iir);
      pragma Assert (Has_Choice_Expression (Get_Kind (Choice)),
                     "no field Choice_Expression");
      Set_Field5 (Choice, Name);
   end Set_Choice_Expression;

   function Get_Choice_Range (Choice : Iir) return Iir is
   begin
      pragma Assert (Choice /= Null_Iir);
      pragma Assert (Has_Choice_Range (Get_Kind (Choice)),
                     "no field Choice_Range");
      return Get_Field5 (Choice);
   end Get_Choice_Range;

   procedure Set_Choice_Range (Choice : Iir; Name : Iir) is
   begin
      pragma Assert (Choice /= Null_Iir);
      pragma Assert (Has_Choice_Range (Get_Kind (Choice)),
                     "no field Choice_Range");
      Set_Field5 (Choice, Name);
   end Set_Choice_Range;

   function Get_Same_Alternative_Flag (Target : Iir) return Boolean is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Same_Alternative_Flag (Get_Kind (Target)),
                     "no field Same_Alternative_Flag");
      return Get_Flag1 (Target);
   end Get_Same_Alternative_Flag;

   procedure Set_Same_Alternative_Flag (Target : Iir; Val : Boolean) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Same_Alternative_Flag (Get_Kind (Target)),
                     "no field Same_Alternative_Flag");
      Set_Flag1 (Target, Val);
   end Set_Same_Alternative_Flag;

   function Get_Element_Type_Flag (Target : Iir) return Boolean is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Element_Type_Flag (Get_Kind (Target)),
                     "no field Element_Type_Flag");
      return Get_Flag2 (Target);
   end Get_Element_Type_Flag;

   procedure Set_Element_Type_Flag (Target : Iir; Val : Boolean) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Element_Type_Flag (Get_Kind (Target)),
                     "no field Element_Type_Flag");
      Set_Flag2 (Target, Val);
   end Set_Element_Type_Flag;

   function Get_Architecture (Target : Iir_Entity_Aspect_Entity) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Architecture (Get_Kind (Target)),
                     "no field Architecture");
      return Get_Field3 (Target);
   end Get_Architecture;

   procedure Set_Architecture (Target : Iir_Entity_Aspect_Entity; Arch : Iir)
   is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Architecture (Get_Kind (Target)),
                     "no field Architecture");
      Set_Field3 (Target, Arch);
   end Set_Architecture;

   function Get_Block_Specification (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Block_Specification (Get_Kind (Target)),
                     "no field Block_Specification");
      return Get_Field5 (Target);
   end Get_Block_Specification;

   procedure Set_Block_Specification (Target : Iir; Block : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Block_Specification (Get_Kind (Target)),
                     "no field Block_Specification");
      Set_Field5 (Target, Block);
   end Set_Block_Specification;

   function Get_Prev_Block_Configuration (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Prev_Block_Configuration (Get_Kind (Target)),
                     "no field Prev_Block_Configuration");
      return Get_Field4 (Target);
   end Get_Prev_Block_Configuration;

   procedure Set_Prev_Block_Configuration (Target : Iir; Block : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Prev_Block_Configuration (Get_Kind (Target)),
                     "no field Prev_Block_Configuration");
      Set_Field4 (Target, Block);
   end Set_Prev_Block_Configuration;

   function Get_Configuration_Item_Chain (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Configuration_Item_Chain (Get_Kind (Target)),
                     "no field Configuration_Item_Chain");
      return Get_Field3 (Target);
   end Get_Configuration_Item_Chain;

   procedure Set_Configuration_Item_Chain (Target : Iir; Chain : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Configuration_Item_Chain (Get_Kind (Target)),
                     "no field Configuration_Item_Chain");
      Set_Field3 (Target, Chain);
   end Set_Configuration_Item_Chain;

   function Get_Attribute_Value_Chain (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Attribute_Value_Chain (Get_Kind (Target)),
                     "no field Attribute_Value_Chain");
      return Get_Field5 (Target);
   end Get_Attribute_Value_Chain;

   procedure Set_Attribute_Value_Chain (Target : Iir; Chain : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Attribute_Value_Chain (Get_Kind (Target)),
                     "no field Attribute_Value_Chain");
      Set_Field5 (Target, Chain);
   end Set_Attribute_Value_Chain;

   function Get_Spec_Chain (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Spec_Chain (Get_Kind (Target)),
                     "no field Spec_Chain");
      return Get_Field2 (Target);
   end Get_Spec_Chain;

   procedure Set_Spec_Chain (Target : Iir; Chain : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Spec_Chain (Get_Kind (Target)),
                     "no field Spec_Chain");
      Set_Field2 (Target, Chain);
   end Set_Spec_Chain;

   function Get_Value_Chain (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Value_Chain (Get_Kind (Target)),
                     "no field Value_Chain");
      return Get_Field0 (Target);
   end Get_Value_Chain;

   procedure Set_Value_Chain (Target : Iir; Chain : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Value_Chain (Get_Kind (Target)),
                     "no field Value_Chain");
      Set_Field0 (Target, Chain);
   end Set_Value_Chain;

   function Get_Attribute_Value_Spec_Chain (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Attribute_Value_Spec_Chain (Get_Kind (Target)),
                     "no field Attribute_Value_Spec_Chain");
      return Get_Field4 (Target);
   end Get_Attribute_Value_Spec_Chain;

   procedure Set_Attribute_Value_Spec_Chain (Target : Iir; Chain : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Attribute_Value_Spec_Chain (Get_Kind (Target)),
                     "no field Attribute_Value_Spec_Chain");
      Set_Field4 (Target, Chain);
   end Set_Attribute_Value_Spec_Chain;

   function Get_Entity_Name (Arch : Iir) return Iir is
   begin
      pragma Assert (Arch /= Null_Iir);
      pragma Assert (Has_Entity_Name (Get_Kind (Arch)),
                     "no field Entity_Name");
      return Get_Field2 (Arch);
   end Get_Entity_Name;

   procedure Set_Entity_Name (Arch : Iir; Entity : Iir) is
   begin
      pragma Assert (Arch /= Null_Iir);
      pragma Assert (Has_Entity_Name (Get_Kind (Arch)),
                     "no field Entity_Name");
      Set_Field2 (Arch, Entity);
   end Set_Entity_Name;

   function Get_Package (Package_Body : Iir) return Iir is
   begin
      pragma Assert (Package_Body /= Null_Iir);
      pragma Assert (Has_Package (Get_Kind (Package_Body)),
                     "no field Package");
      return Get_Field4 (Package_Body);
   end Get_Package;

   procedure Set_Package (Package_Body : Iir; Decl : Iir) is
   begin
      pragma Assert (Package_Body /= Null_Iir);
      pragma Assert (Has_Package (Get_Kind (Package_Body)),
                     "no field Package");
      Set_Field4 (Package_Body, Decl);
   end Set_Package;

   function Get_Package_Body (Pkg : Iir) return Iir is
   begin
      pragma Assert (Pkg /= Null_Iir);
      pragma Assert (Has_Package_Body (Get_Kind (Pkg)),
                     "no field Package_Body");
      return Get_Field4 (Pkg);
   end Get_Package_Body;

   procedure Set_Package_Body (Pkg : Iir; Decl : Iir) is
   begin
      pragma Assert (Pkg /= Null_Iir);
      pragma Assert (Has_Package_Body (Get_Kind (Pkg)),
                     "no field Package_Body");
      Set_Field4 (Pkg, Decl);
   end Set_Package_Body;

   function Get_Instance_Package_Body (Pkg : Iir) return Iir is
   begin
      pragma Assert (Pkg /= Null_Iir);
      pragma Assert (Has_Instance_Package_Body (Get_Kind (Pkg)),
                     "no field Instance_Package_Body");
      return Get_Field4 (Pkg);
   end Get_Instance_Package_Body;

   procedure Set_Instance_Package_Body (Pkg : Iir; Decl : Iir) is
   begin
      pragma Assert (Pkg /= Null_Iir);
      pragma Assert (Has_Instance_Package_Body (Get_Kind (Pkg)),
                     "no field Instance_Package_Body");
      Set_Field4 (Pkg, Decl);
   end Set_Instance_Package_Body;

   function Get_Need_Body (Decl : Iir_Package_Declaration) return Boolean is
   begin
      pragma Assert (Decl /= Null_Iir);
      pragma Assert (Has_Need_Body (Get_Kind (Decl)),
                     "no field Need_Body");
      return Get_Flag1 (Decl);
   end Get_Need_Body;

   procedure Set_Need_Body (Decl : Iir_Package_Declaration; Flag : Boolean) is
   begin
      pragma Assert (Decl /= Null_Iir);
      pragma Assert (Has_Need_Body (Get_Kind (Decl)),
                     "no field Need_Body");
      Set_Flag1 (Decl, Flag);
   end Set_Need_Body;

   function Get_Macro_Expanded_Flag (Decl : Iir) return Boolean is
   begin
      pragma Assert (Decl /= Null_Iir);
      pragma Assert (Has_Macro_Expanded_Flag (Get_Kind (Decl)),
                     "no field Macro_Expanded_Flag");
      return Get_Flag2 (Decl);
   end Get_Macro_Expanded_Flag;

   procedure Set_Macro_Expanded_Flag (Decl : Iir; Flag : Boolean) is
   begin
      pragma Assert (Decl /= Null_Iir);
      pragma Assert (Has_Macro_Expanded_Flag (Get_Kind (Decl)),
                     "no field Macro_Expanded_Flag");
      Set_Flag2 (Decl, Flag);
   end Set_Macro_Expanded_Flag;

   function Get_Need_Instance_Bodies (Decl : Iir) return Boolean is
   begin
      pragma Assert (Decl /= Null_Iir);
      pragma Assert (Has_Need_Instance_Bodies (Get_Kind (Decl)),
                     "no field Need_Instance_Bodies");
      return Get_Flag3 (Decl);
   end Get_Need_Instance_Bodies;

   procedure Set_Need_Instance_Bodies (Decl : Iir; Flag : Boolean) is
   begin
      pragma Assert (Decl /= Null_Iir);
      pragma Assert (Has_Need_Instance_Bodies (Get_Kind (Decl)),
                     "no field Need_Instance_Bodies");
      Set_Flag3 (Decl, Flag);
   end Set_Need_Instance_Bodies;

   function Get_Hierarchical_Name (Vunit : Iir) return Iir is
   begin
      pragma Assert (Vunit /= Null_Iir);
      pragma Assert (Has_Hierarchical_Name (Get_Kind (Vunit)),
                     "no field Hierarchical_Name");
      return Get_Field1 (Vunit);
   end Get_Hierarchical_Name;

   procedure Set_Hierarchical_Name (Vunit : Iir; Name : Iir) is
   begin
      pragma Assert (Vunit /= Null_Iir);
      pragma Assert (Has_Hierarchical_Name (Get_Kind (Vunit)),
                     "no field Hierarchical_Name");
      Set_Field1 (Vunit, Name);
   end Set_Hierarchical_Name;

   function Get_Vunit_Item_Chain (Vunit : Iir) return Iir is
   begin
      pragma Assert (Vunit /= Null_Iir);
      pragma Assert (Has_Vunit_Item_Chain (Get_Kind (Vunit)),
                     "no field Vunit_Item_Chain");
      return Get_Field6 (Vunit);
   end Get_Vunit_Item_Chain;

   procedure Set_Vunit_Item_Chain (Vunit : Iir; Chain : Iir) is
   begin
      pragma Assert (Vunit /= Null_Iir);
      pragma Assert (Has_Vunit_Item_Chain (Get_Kind (Vunit)),
                     "no field Vunit_Item_Chain");
      Set_Field6 (Vunit, Chain);
   end Set_Vunit_Item_Chain;

   function Get_Bound_Vunit_Chain (Unit : Iir) return Iir is
   begin
      pragma Assert (Unit /= Null_Iir);
      pragma Assert (Has_Bound_Vunit_Chain (Get_Kind (Unit)),
                     "no field Bound_Vunit_Chain");
      return Get_Field8 (Unit);
   end Get_Bound_Vunit_Chain;

   procedure Set_Bound_Vunit_Chain (Unit : Iir; Vunit : Iir) is
   begin
      pragma Assert (Unit /= Null_Iir);
      pragma Assert (Has_Bound_Vunit_Chain (Get_Kind (Unit)),
                     "no field Bound_Vunit_Chain");
      Set_Field8 (Unit, Vunit);
   end Set_Bound_Vunit_Chain;

   function Get_Verification_Block_Configuration (Vunit : Iir) return Iir is
   begin
      pragma Assert (Vunit /= Null_Iir);
      pragma Assert (Has_Verification_Block_Configuration (Get_Kind (Vunit)),
                     "no field Verification_Block_Configuration");
      return Get_Field4 (Vunit);
   end Get_Verification_Block_Configuration;

   procedure Set_Verification_Block_Configuration (Vunit : Iir; Conf : Iir) is
   begin
      pragma Assert (Vunit /= Null_Iir);
      pragma Assert (Has_Verification_Block_Configuration (Get_Kind (Vunit)),
                     "no field Verification_Block_Configuration");
      Set_Field4 (Vunit, Conf);
   end Set_Verification_Block_Configuration;

   function Get_Block_Configuration (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Block_Configuration (Get_Kind (Target)),
                     "no field Block_Configuration");
      return Get_Field4 (Target);
   end Get_Block_Configuration;

   procedure Set_Block_Configuration (Target : Iir; Block : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Block_Configuration (Get_Kind (Target)),
                     "no field Block_Configuration");
      Set_Field4 (Target, Block);
   end Set_Block_Configuration;

   function Get_Concurrent_Statement_Chain (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Concurrent_Statement_Chain (Get_Kind (Target)),
                     "no field Concurrent_Statement_Chain");
      return Get_Field4 (Target);
   end Get_Concurrent_Statement_Chain;

   procedure Set_Concurrent_Statement_Chain (Target : Iir; First : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Concurrent_Statement_Chain (Get_Kind (Target)),
                     "no field Concurrent_Statement_Chain");
      Set_Field4 (Target, First);
   end Set_Concurrent_Statement_Chain;

   function Get_Chain (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Chain (Get_Kind (Target)),
                     "no field Chain");
      return Get_Field2 (Target);
   end Get_Chain;

   procedure Set_Chain (Target : Iir; Chain : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Chain (Get_Kind (Target)),
                     "no field Chain");
      Set_Field2 (Target, Chain);
   end Set_Chain;

   function Get_Port_Chain (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Port_Chain (Get_Kind (Target)),
                     "no field Port_Chain");
      return Get_Field7 (Target);
   end Get_Port_Chain;

   procedure Set_Port_Chain (Target : Iir; Chain : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Port_Chain (Get_Kind (Target)),
                     "no field Port_Chain");
      Set_Field7 (Target, Chain);
   end Set_Port_Chain;

   function Get_Generic_Chain (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Generic_Chain (Get_Kind (Target)),
                     "no field Generic_Chain");
      return Get_Field6 (Target);
   end Get_Generic_Chain;

   procedure Set_Generic_Chain (Target : Iir; Generics : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Generic_Chain (Get_Kind (Target)),
                     "no field Generic_Chain");
      Set_Field6 (Target, Generics);
   end Set_Generic_Chain;

   function Get_Type (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Type (Get_Kind (Target)),
                     "no field Type");
      return Get_Field1 (Target);
   end Get_Type;

   procedure Set_Type (Target : Iir; Atype : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Type (Get_Kind (Target)),
                     "no field Type");
      Set_Field1 (Target, Atype);
   end Set_Type;

   function Get_Subtype_Indication (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Subtype_Indication (Get_Kind (Target)),
                     "no field Subtype_Indication");
      return Get_Field5 (Target);
   end Get_Subtype_Indication;

   procedure Set_Subtype_Indication (Target : Iir; Atype : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Subtype_Indication (Get_Kind (Target)),
                     "no field Subtype_Indication");
      Set_Field5 (Target, Atype);
   end Set_Subtype_Indication;

   function Get_Discrete_Range (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Discrete_Range (Get_Kind (Target)),
                     "no field Discrete_Range");
      return Get_Field4 (Target);
   end Get_Discrete_Range;

   procedure Set_Discrete_Range (Target : Iir; Rng : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Discrete_Range (Get_Kind (Target)),
                     "no field Discrete_Range");
      Set_Field4 (Target, Rng);
   end Set_Discrete_Range;

   function Get_Type_Definition (Decl : Iir) return Iir is
   begin
      pragma Assert (Decl /= Null_Iir);
      pragma Assert (Has_Type_Definition (Get_Kind (Decl)),
                     "no field Type_Definition");
      return Get_Field1 (Decl);
   end Get_Type_Definition;

   procedure Set_Type_Definition (Decl : Iir; Atype : Iir) is
   begin
      pragma Assert (Decl /= Null_Iir);
      pragma Assert (Has_Type_Definition (Get_Kind (Decl)),
                     "no field Type_Definition");
      Set_Field1 (Decl, Atype);
   end Set_Type_Definition;

   function Get_Subtype_Definition (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Subtype_Definition (Get_Kind (Target)),
                     "no field Subtype_Definition");
      return Get_Field4 (Target);
   end Get_Subtype_Definition;

   procedure Set_Subtype_Definition (Target : Iir; Def : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Subtype_Definition (Get_Kind (Target)),
                     "no field Subtype_Definition");
      Set_Field4 (Target, Def);
   end Set_Subtype_Definition;

   function Get_Incomplete_Type_Declaration (N : Iir) return Iir is
   begin
      pragma Assert (N /= Null_Iir);
      pragma Assert (Has_Incomplete_Type_Declaration (Get_Kind (N)),
                     "no field Incomplete_Type_Declaration");
      return Get_Field5 (N);
   end Get_Incomplete_Type_Declaration;

   procedure Set_Incomplete_Type_Declaration (N : Iir; Decl : Iir) is
   begin
      pragma Assert (N /= Null_Iir);
      pragma Assert (Has_Incomplete_Type_Declaration (Get_Kind (N)),
                     "no field Incomplete_Type_Declaration");
      Set_Field5 (N, Decl);
   end Set_Incomplete_Type_Declaration;

   function Get_Interface_Type_Subprograms (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Interface_Type_Subprograms (Get_Kind (Target)),
                     "no field Interface_Type_Subprograms");
      return Get_Field4 (Target);
   end Get_Interface_Type_Subprograms;

   procedure Set_Interface_Type_Subprograms (Target : Iir; Subprg : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Interface_Type_Subprograms (Get_Kind (Target)),
                     "no field Interface_Type_Subprograms");
      Set_Field4 (Target, Subprg);
   end Set_Interface_Type_Subprograms;

   function Get_Nature_Definition (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Nature_Definition (Get_Kind (Target)),
                     "no field Nature_Definition");
      return Get_Field1 (Target);
   end Get_Nature_Definition;

   procedure Set_Nature_Definition (Target : Iir; Def : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Nature_Definition (Get_Kind (Target)),
                     "no field Nature_Definition");
      Set_Field1 (Target, Def);
   end Set_Nature_Definition;

   function Get_Nature (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Nature (Get_Kind (Target)),
                     "no field Nature");
      return Get_Field1 (Target);
   end Get_Nature;

   procedure Set_Nature (Target : Iir; Nature : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Nature (Get_Kind (Target)),
                     "no field Nature");
      Set_Field1 (Target, Nature);
   end Set_Nature;

   function Get_Subnature_Indication (Decl : Iir) return Iir is
   begin
      pragma Assert (Decl /= Null_Iir);
      pragma Assert (Has_Subnature_Indication (Get_Kind (Decl)),
                     "no field Subnature_Indication");
      return Get_Field5 (Decl);
   end Get_Subnature_Indication;

   procedure Set_Subnature_Indication (Decl : Iir; Sub_Nature : Iir) is
   begin
      pragma Assert (Decl /= Null_Iir);
      pragma Assert (Has_Subnature_Indication (Get_Kind (Decl)),
                     "no field Subnature_Indication");
      Set_Field5 (Decl, Sub_Nature);
   end Set_Subnature_Indication;

   type Iir_Mode_Conv is record
      Flag13: Boolean;
      Flag14: Boolean;
      Flag15: Boolean;
   end record;
   pragma Pack (Iir_Mode_Conv);
   pragma Assert (Iir_Mode_Conv'Size = Iir_Mode'Size);

   function Get_Mode (Target : Iir) return Iir_Mode
   is
      function To_Iir_Mode is new Ada.Unchecked_Conversion
         (Iir_Mode_Conv, Iir_Mode);
      Conv : Iir_Mode_Conv;
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Mode (Get_Kind (Target)),
                     "no field Mode");
      Conv.Flag13 := Get_Flag13 (Target);
      Conv.Flag14 := Get_Flag14 (Target);
      Conv.Flag15 := Get_Flag15 (Target);
      return To_Iir_Mode (Conv);
   end Get_Mode;

   procedure Set_Mode (Target : Iir; Mode : Iir_Mode)
   is
      function To_Iir_Mode_Conv is new Ada.Unchecked_Conversion
         (Iir_Mode, Iir_Mode_Conv);
      Conv : Iir_Mode_Conv;
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Mode (Get_Kind (Target)),
                     "no field Mode");
      Conv := To_Iir_Mode_Conv (Mode);
      Set_Flag13 (Target, Conv.Flag13);
      Set_Flag14 (Target, Conv.Flag14);
      Set_Flag15 (Target, Conv.Flag15);
   end Set_Mode;

   function Get_Guarded_Signal_Flag (Target : Iir) return Boolean is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Guarded_Signal_Flag (Get_Kind (Target)),
                     "no field Guarded_Signal_Flag");
      return Get_Flag8 (Target);
   end Get_Guarded_Signal_Flag;

   procedure Set_Guarded_Signal_Flag (Target : Iir; Guarded : Boolean) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Guarded_Signal_Flag (Get_Kind (Target)),
                     "no field Guarded_Signal_Flag");
      Set_Flag8 (Target, Guarded);
   end Set_Guarded_Signal_Flag;

   function Get_Signal_Kind (Target : Iir) return Iir_Signal_Kind is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Signal_Kind (Get_Kind (Target)),
                     "no field Signal_Kind");
      return Boolean_To_Iir_Signal_Kind (Get_Flag9 (Target));
   end Get_Signal_Kind;

   procedure Set_Signal_Kind (Target : Iir; Signal_Kind : Iir_Signal_Kind) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Signal_Kind (Get_Kind (Target)),
                     "no field Signal_Kind");
      Set_Flag9 (Target, Iir_Signal_Kind_To_Boolean (Signal_Kind));
   end Set_Signal_Kind;

   function Get_Base_Name (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Base_Name (Get_Kind (Target)),
                     "no field Base_Name");
      return Get_Field5 (Target);
   end Get_Base_Name;

   procedure Set_Base_Name (Target : Iir; Name : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Base_Name (Get_Kind (Target)),
                     "no field Base_Name");
      Set_Field5 (Target, Name);
   end Set_Base_Name;

   function Get_Interface_Declaration_Chain (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Interface_Declaration_Chain (Get_Kind (Target)),
                     "no field Interface_Declaration_Chain");
      return Get_Field5 (Target);
   end Get_Interface_Declaration_Chain;

   procedure Set_Interface_Declaration_Chain (Target : Iir; Chain : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Interface_Declaration_Chain (Get_Kind (Target)),
                     "no field Interface_Declaration_Chain");
      Set_Field5 (Target, Chain);
   end Set_Interface_Declaration_Chain;

   function Get_Subprogram_Specification (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Subprogram_Specification (Get_Kind (Target)),
                     "no field Subprogram_Specification");
      return Get_Field6 (Target);
   end Get_Subprogram_Specification;

   procedure Set_Subprogram_Specification (Target : Iir; Spec : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Subprogram_Specification (Get_Kind (Target)),
                     "no field Subprogram_Specification");
      Set_Field6 (Target, Spec);
   end Set_Subprogram_Specification;

   function Get_Sequential_Statement_Chain (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Sequential_Statement_Chain (Get_Kind (Target)),
                     "no field Sequential_Statement_Chain");
      return Get_Field4 (Target);
   end Get_Sequential_Statement_Chain;

   procedure Set_Sequential_Statement_Chain (Target : Iir; Chain : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Sequential_Statement_Chain (Get_Kind (Target)),
                     "no field Sequential_Statement_Chain");
      Set_Field4 (Target, Chain);
   end Set_Sequential_Statement_Chain;

   function Get_Simultaneous_Statement_Chain (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Simultaneous_Statement_Chain (Get_Kind (Target)),
                     "no field Simultaneous_Statement_Chain");
      return Get_Field4 (Target);
   end Get_Simultaneous_Statement_Chain;

   procedure Set_Simultaneous_Statement_Chain (Target : Iir; Chain : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Simultaneous_Statement_Chain (Get_Kind (Target)),
                     "no field Simultaneous_Statement_Chain");
      Set_Field4 (Target, Chain);
   end Set_Simultaneous_Statement_Chain;

   function Get_Subprogram_Body (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Subprogram_Body (Get_Kind (Target)),
                     "no field Subprogram_Body");
      return Get_Field9 (Target);
   end Get_Subprogram_Body;

   procedure Set_Subprogram_Body (Target : Iir; A_Body : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Subprogram_Body (Get_Kind (Target)),
                     "no field Subprogram_Body");
      Set_Field9 (Target, A_Body);
   end Set_Subprogram_Body;

   function Get_Overload_Number (Target : Iir) return Iir_Int32 is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Overload_Number (Get_Kind (Target)),
                     "no field Overload_Number");
      return Iir_Int32'Val (Get_Field12 (Target));
   end Get_Overload_Number;

   procedure Set_Overload_Number (Target : Iir; Val : Iir_Int32) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Overload_Number (Get_Kind (Target)),
                     "no field Overload_Number");
      Set_Field12 (Target, Iir_Int32'Pos (Val));
   end Set_Overload_Number;

   function Get_Subprogram_Depth (Target : Iir) return Iir_Int32 is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Subprogram_Depth (Get_Kind (Target)),
                     "no field Subprogram_Depth");
      return Iir_Int32'Val (Get_Field10 (Target));
   end Get_Subprogram_Depth;

   procedure Set_Subprogram_Depth (Target : Iir; Depth : Iir_Int32) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Subprogram_Depth (Get_Kind (Target)),
                     "no field Subprogram_Depth");
      Set_Field10 (Target, Iir_Int32'Pos (Depth));
   end Set_Subprogram_Depth;

   function Get_Subprogram_Hash (Target : Iir) return Iir_Int32 is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Subprogram_Hash (Get_Kind (Target)),
                     "no field Subprogram_Hash");
      return Iir_Int32'Val (Get_Field4 (Target));
   end Get_Subprogram_Hash;

   procedure Set_Subprogram_Hash (Target : Iir; Val : Iir_Int32) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Subprogram_Hash (Get_Kind (Target)),
                     "no field Subprogram_Hash");
      Set_Field4 (Target, Iir_Int32'Pos (Val));
   end Set_Subprogram_Hash;

   function Get_Impure_Depth (Target : Iir) return Iir_Int32 is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Impure_Depth (Get_Kind (Target)),
                     "no field Impure_Depth");
      return Iir_To_Iir_Int32 (Get_Field3 (Target));
   end Get_Impure_Depth;

   procedure Set_Impure_Depth (Target : Iir; Depth : Iir_Int32) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Impure_Depth (Get_Kind (Target)),
                     "no field Impure_Depth");
      Set_Field3 (Target, Iir_Int32_To_Iir (Depth));
   end Set_Impure_Depth;

   function Get_Return_Type (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Return_Type (Get_Kind (Target)),
                     "no field Return_Type");
      return Get_Field1 (Target);
   end Get_Return_Type;

   procedure Set_Return_Type (Target : Iir; Decl : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Return_Type (Get_Kind (Target)),
                     "no field Return_Type");
      Set_Field1 (Target, Decl);
   end Set_Return_Type;

   function Get_Implicit_Definition (D : Iir) return Iir_Predefined_Functions
   is
   begin
      pragma Assert (D /= Null_Iir);
      pragma Assert (Has_Implicit_Definition (Get_Kind (D)),
                     "no field Implicit_Definition");
      return Iir_Predefined_Functions'Val (Get_Field7 (D));
   end Get_Implicit_Definition;

   procedure Set_Implicit_Definition (D : Iir; Def : Iir_Predefined_Functions)
   is
   begin
      pragma Assert (D /= Null_Iir);
      pragma Assert (Has_Implicit_Definition (Get_Kind (D)),
                     "no field Implicit_Definition");
      Set_Field7 (D, Iir_Predefined_Functions'Pos (Def));
   end Set_Implicit_Definition;

   function Get_Uninstantiated_Subprogram_Name (N : Iir) return Iir is
   begin
      pragma Assert (N /= Null_Iir);
      pragma Assert (Has_Uninstantiated_Subprogram_Name (Get_Kind (N)),
                     "no field Uninstantiated_Subprogram_Name");
      return Get_Field7 (N);
   end Get_Uninstantiated_Subprogram_Name;

   procedure Set_Uninstantiated_Subprogram_Name (N : Iir; Name : Iir) is
   begin
      pragma Assert (N /= Null_Iir);
      pragma Assert (Has_Uninstantiated_Subprogram_Name (Get_Kind (N)),
                     "no field Uninstantiated_Subprogram_Name");
      Set_Field7 (N, Name);
   end Set_Uninstantiated_Subprogram_Name;

   function Get_Default_Value (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Default_Value (Get_Kind (Target)),
                     "no field Default_Value");
      return Get_Field4 (Target);
   end Get_Default_Value;

   procedure Set_Default_Value (Target : Iir; Value : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Default_Value (Get_Kind (Target)),
                     "no field Default_Value");
      Set_Field4 (Target, Value);
   end Set_Default_Value;

   function Get_Deferred_Declaration (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Deferred_Declaration (Get_Kind (Target)),
                     "no field Deferred_Declaration");
      return Get_Field6 (Target);
   end Get_Deferred_Declaration;

   procedure Set_Deferred_Declaration (Target : Iir; Decl : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Deferred_Declaration (Get_Kind (Target)),
                     "no field Deferred_Declaration");
      Set_Field6 (Target, Decl);
   end Set_Deferred_Declaration;

   function Get_Deferred_Declaration_Flag (Target : Iir) return Boolean is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Deferred_Declaration_Flag (Get_Kind (Target)),
                     "no field Deferred_Declaration_Flag");
      return Get_Flag1 (Target);
   end Get_Deferred_Declaration_Flag;

   procedure Set_Deferred_Declaration_Flag (Target : Iir; Flag : Boolean) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Deferred_Declaration_Flag (Get_Kind (Target)),
                     "no field Deferred_Declaration_Flag");
      Set_Flag1 (Target, Flag);
   end Set_Deferred_Declaration_Flag;

   function Get_Shared_Flag (Target : Iir) return Boolean is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Shared_Flag (Get_Kind (Target)),
                     "no field Shared_Flag");
      return Get_Flag2 (Target);
   end Get_Shared_Flag;

   procedure Set_Shared_Flag (Target : Iir; Shared : Boolean) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Shared_Flag (Get_Kind (Target)),
                     "no field Shared_Flag");
      Set_Flag2 (Target, Shared);
   end Set_Shared_Flag;

   function Get_Design_Unit (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Design_Unit (Get_Kind (Target)),
                     "no field Design_Unit");
      return Get_Field0 (Target);
   end Get_Design_Unit;

   procedure Set_Design_Unit (Target : Iir; Unit : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Design_Unit (Get_Kind (Target)),
                     "no field Design_Unit");
      Set_Field0 (Target, Unit);
   end Set_Design_Unit;

   function Get_Block_Statement (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Block_Statement (Get_Kind (Target)),
                     "no field Block_Statement");
      return Get_Field5 (Target);
   end Get_Block_Statement;

   procedure Set_Block_Statement (Target : Iir; Block : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Block_Statement (Get_Kind (Target)),
                     "no field Block_Statement");
      Set_Field5 (Target, Block);
   end Set_Block_Statement;

   function Get_Signal_Driver (Target : Iir_Signal_Declaration) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Signal_Driver (Get_Kind (Target)),
                     "no field Signal_Driver");
      return Get_Field7 (Target);
   end Get_Signal_Driver;

   procedure Set_Signal_Driver (Target : Iir_Signal_Declaration; Driver : Iir)
   is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Signal_Driver (Get_Kind (Target)),
                     "no field Signal_Driver");
      Set_Field7 (Target, Driver);
   end Set_Signal_Driver;

   function Get_Declaration_Chain (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Declaration_Chain (Get_Kind (Target)),
                     "no field Declaration_Chain");
      return Get_Field1 (Target);
   end Get_Declaration_Chain;

   procedure Set_Declaration_Chain (Target : Iir; Decls : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Declaration_Chain (Get_Kind (Target)),
                     "no field Declaration_Chain");
      Set_Field1 (Target, Decls);
   end Set_Declaration_Chain;

   function Get_File_Logical_Name (Target : Iir_File_Declaration) return Iir
   is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_File_Logical_Name (Get_Kind (Target)),
                     "no field File_Logical_Name");
      return Get_Field6 (Target);
   end Get_File_Logical_Name;

   procedure Set_File_Logical_Name (Target : Iir_File_Declaration; Name : Iir)
   is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_File_Logical_Name (Get_Kind (Target)),
                     "no field File_Logical_Name");
      Set_Field6 (Target, Name);
   end Set_File_Logical_Name;

   function Get_File_Open_Kind (Target : Iir_File_Declaration) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_File_Open_Kind (Get_Kind (Target)),
                     "no field File_Open_Kind");
      return Get_Field7 (Target);
   end Get_File_Open_Kind;

   procedure Set_File_Open_Kind (Target : Iir_File_Declaration; Kind : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_File_Open_Kind (Get_Kind (Target)),
                     "no field File_Open_Kind");
      Set_Field7 (Target, Kind);
   end Set_File_Open_Kind;

   function Get_Element_Position (Target : Iir) return Iir_Index32 is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Element_Position (Get_Kind (Target)),
                     "no field Element_Position");
      return Iir_Index32'Val (Get_Field4 (Target));
   end Get_Element_Position;

   procedure Set_Element_Position (Target : Iir; Pos : Iir_Index32) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Element_Position (Get_Kind (Target)),
                     "no field Element_Position");
      Set_Field4 (Target, Iir_Index32'Pos (Pos));
   end Set_Element_Position;

   function Get_Use_Clause_Chain (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Use_Clause_Chain (Get_Kind (Target)),
                     "no field Use_Clause_Chain");
      return Get_Field3 (Target);
   end Get_Use_Clause_Chain;

   procedure Set_Use_Clause_Chain (Target : Iir; Chain : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Use_Clause_Chain (Get_Kind (Target)),
                     "no field Use_Clause_Chain");
      Set_Field3 (Target, Chain);
   end Set_Use_Clause_Chain;

   function Get_Context_Reference_Chain (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Context_Reference_Chain (Get_Kind (Target)),
                     "no field Context_Reference_Chain");
      return Get_Field3 (Target);
   end Get_Context_Reference_Chain;

   procedure Set_Context_Reference_Chain (Target : Iir; Chain : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Context_Reference_Chain (Get_Kind (Target)),
                     "no field Context_Reference_Chain");
      Set_Field3 (Target, Chain);
   end Set_Context_Reference_Chain;

   function Get_Inherit_Spec_Chain (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Inherit_Spec_Chain (Get_Kind (Target)),
                     "no field Inherit_Spec_Chain");
      return Get_Field3 (Target);
   end Get_Inherit_Spec_Chain;

   procedure Set_Inherit_Spec_Chain (Target : Iir; Chain : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Inherit_Spec_Chain (Get_Kind (Target)),
                     "no field Inherit_Spec_Chain");
      Set_Field3 (Target, Chain);
   end Set_Inherit_Spec_Chain;

   function Get_Selected_Name (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Selected_Name (Get_Kind (Target)),
                     "no field Selected_Name");
      return Get_Field1 (Target);
   end Get_Selected_Name;

   procedure Set_Selected_Name (Target : Iir; Name : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Selected_Name (Get_Kind (Target)),
                     "no field Selected_Name");
      Set_Field1 (Target, Name);
   end Set_Selected_Name;

   function Get_Type_Declarator (Def : Iir) return Iir is
   begin
      pragma Assert (Def /= Null_Iir);
      pragma Assert (Has_Type_Declarator (Get_Kind (Def)),
                     "no field Type_Declarator");
      return Get_Field3 (Def);
   end Get_Type_Declarator;

   procedure Set_Type_Declarator (Def : Iir; Decl : Iir) is
   begin
      pragma Assert (Def /= Null_Iir);
      pragma Assert (Has_Type_Declarator (Get_Kind (Def)),
                     "no field Type_Declarator");
      Set_Field3 (Def, Decl);
   end Set_Type_Declarator;

   function Get_Complete_Type_Definition (N : Iir) return Iir is
   begin
      pragma Assert (N /= Null_Iir);
      pragma Assert (Has_Complete_Type_Definition (Get_Kind (N)),
                     "no field Complete_Type_Definition");
      return Get_Field5 (N);
   end Get_Complete_Type_Definition;

   procedure Set_Complete_Type_Definition (N : Iir; Def : Iir) is
   begin
      pragma Assert (N /= Null_Iir);
      pragma Assert (Has_Complete_Type_Definition (Get_Kind (N)),
                     "no field Complete_Type_Definition");
      Set_Field5 (N, Def);
   end Set_Complete_Type_Definition;

   function Get_Incomplete_Type_Ref_Chain (N : Iir) return Iir is
   begin
      pragma Assert (N /= Null_Iir);
      pragma Assert (Has_Incomplete_Type_Ref_Chain (Get_Kind (N)),
                     "no field Incomplete_Type_Ref_Chain");
      return Get_Field0 (N);
   end Get_Incomplete_Type_Ref_Chain;

   procedure Set_Incomplete_Type_Ref_Chain (N : Iir; Def : Iir) is
   begin
      pragma Assert (N /= Null_Iir);
      pragma Assert (Has_Incomplete_Type_Ref_Chain (Get_Kind (N)),
                     "no field Incomplete_Type_Ref_Chain");
      Set_Field0 (N, Def);
   end Set_Incomplete_Type_Ref_Chain;

   function Get_Associated_Type (Def : Iir) return Iir is
   begin
      pragma Assert (Def /= Null_Iir);
      pragma Assert (Has_Associated_Type (Get_Kind (Def)),
                     "no field Associated_Type");
      return Get_Field5 (Def);
   end Get_Associated_Type;

   procedure Set_Associated_Type (Def : Iir; Atype : Iir) is
   begin
      pragma Assert (Def /= Null_Iir);
      pragma Assert (Has_Associated_Type (Get_Kind (Def)),
                     "no field Associated_Type");
      Set_Field5 (Def, Atype);
   end Set_Associated_Type;

   function Get_Enumeration_Literal_List (Target : Iir) return Iir_Flist is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Enumeration_Literal_List (Get_Kind (Target)),
                     "no field Enumeration_Literal_List");
      return Iir_To_Iir_Flist (Get_Field2 (Target));
   end Get_Enumeration_Literal_List;

   procedure Set_Enumeration_Literal_List (Target : Iir; List : Iir_Flist) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Enumeration_Literal_List (Get_Kind (Target)),
                     "no field Enumeration_Literal_List");
      Set_Field2 (Target, Iir_Flist_To_Iir (List));
   end Set_Enumeration_Literal_List;

   function Get_Entity_Class_Entry_Chain (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Entity_Class_Entry_Chain (Get_Kind (Target)),
                     "no field Entity_Class_Entry_Chain");
      return Get_Field1 (Target);
   end Get_Entity_Class_Entry_Chain;

   procedure Set_Entity_Class_Entry_Chain (Target : Iir; Chain : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Entity_Class_Entry_Chain (Get_Kind (Target)),
                     "no field Entity_Class_Entry_Chain");
      Set_Field1 (Target, Chain);
   end Set_Entity_Class_Entry_Chain;

   function Get_Group_Constituent_List (Group : Iir) return Iir_Flist is
   begin
      pragma Assert (Group /= Null_Iir);
      pragma Assert (Has_Group_Constituent_List (Get_Kind (Group)),
                     "no field Group_Constituent_List");
      return Iir_To_Iir_Flist (Get_Field1 (Group));
   end Get_Group_Constituent_List;

   procedure Set_Group_Constituent_List (Group : Iir; List : Iir_Flist) is
   begin
      pragma Assert (Group /= Null_Iir);
      pragma Assert (Has_Group_Constituent_List (Get_Kind (Group)),
                     "no field Group_Constituent_List");
      Set_Field1 (Group, Iir_Flist_To_Iir (List));
   end Set_Group_Constituent_List;

   function Get_Unit_Chain (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Unit_Chain (Get_Kind (Target)),
                     "no field Unit_Chain");
      return Get_Field2 (Target);
   end Get_Unit_Chain;

   procedure Set_Unit_Chain (Target : Iir; Chain : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Unit_Chain (Get_Kind (Target)),
                     "no field Unit_Chain");
      Set_Field2 (Target, Chain);
   end Set_Unit_Chain;

   function Get_Primary_Unit (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Primary_Unit (Get_Kind (Target)),
                     "no field Primary_Unit");
      return Get_Field2 (Target);
   end Get_Primary_Unit;

   procedure Set_Primary_Unit (Target : Iir; Unit : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Primary_Unit (Get_Kind (Target)),
                     "no field Primary_Unit");
      Set_Field2 (Target, Unit);
   end Set_Primary_Unit;

   function Get_Identifier (Target : Iir) return Name_Id is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Identifier (Get_Kind (Target)),
                     "no field Identifier");
      return Iir_To_Name_Id (Get_Field3 (Target));
   end Get_Identifier;

   procedure Set_Identifier (Target : Iir; Identifier : Name_Id) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Identifier (Get_Kind (Target)),
                     "no field Identifier");
      Set_Field3 (Target, Name_Id_To_Iir (Identifier));
   end Set_Identifier;

   function Get_Label (Target : Iir) return Name_Id is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Label (Get_Kind (Target)),
                     "no field Label");
      return Iir_To_Name_Id (Get_Field3 (Target));
   end Get_Label;

   procedure Set_Label (Target : Iir; Label : Name_Id) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Label (Get_Kind (Target)),
                     "no field Label");
      Set_Field3 (Target, Name_Id_To_Iir (Label));
   end Set_Label;

   function Get_Return_Identifier (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Return_Identifier (Get_Kind (Target)),
                     "no field Return_Identifier");
      return Get_Field11 (Target);
   end Get_Return_Identifier;

   procedure Set_Return_Identifier (Target : Iir; Decl : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Return_Identifier (Get_Kind (Target)),
                     "no field Return_Identifier");
      Set_Field11 (Target, Decl);
   end Set_Return_Identifier;

   function Get_Visible_Flag (Target : Iir) return Boolean is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Visible_Flag (Get_Kind (Target)),
                     "no field Visible_Flag");
      return Get_Flag4 (Target);
   end Get_Visible_Flag;

   procedure Set_Visible_Flag (Target : Iir; Flag : Boolean) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Visible_Flag (Get_Kind (Target)),
                     "no field Visible_Flag");
      Set_Flag4 (Target, Flag);
   end Set_Visible_Flag;

   function Get_Range_Constraint (Target : Iir) return Iir is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Range_Constraint (Get_Kind (Target)),
                     "no field Range_Constraint");
      return Get_Field1 (Target);
   end Get_Range_Constraint;

   procedure Set_Range_Constraint (Target : Iir; Constraint : Iir) is
   begin
      pragma Assert (Target /= Null_Iir);
      pragma Assert (Has_Range_Constraint (Get_Kind (Target)),
                     "no field Range_Constraint");
      Set_Field1 (Target, Constraint);
   end Set_Range_Constraint;

   function Get_Direction (Decl : Iir) return Direction_Type is
   begin
      pragma Assert (Decl /= Null_Iir);
      pragma Assert (Has_Direction (Get_Kind (Decl)),
                     "no field Direction");
      return Boolean_To_Direction_Type (Get_Flag1 (Decl));
   end Get_Direction;

   procedure Set_Direction (Decl : Iir; Dir : Direction_Type) is
   begin
      pragma Assert (Decl /= Null_Iir);
      pragma Assert (Has_Direction (Get_Kind (Decl)),
                     "no field Direction");
      Set_Flag1 (Decl, Direction_Type_To_Boolean (Dir));
   end Set_Direction;

   function Get_Left_Limit (Decl : Iir_Range_Expression) return Iir is
   begin
      pragma Assert (Decl /= Null_Iir);
      pragma Assert (Has_Left_Limit (Get_Kind (Decl)),
                     "no field Left_Limit");
      return Get_Field4 (Decl);
   end Get_Left_Limit;

   procedure Set_Left_Limit (Decl : Iir_Range_Expression; Limit : Iir) is
   begin
      pragma Assert (Decl /= Null_Iir);
      pragma Assert (Has_Left_Limit (Get_Kind (Decl)),
                     "no field Left_Limit");
      Set_Field4 (Decl, Limit);
   end Set_Left_Limit;

   function Get_Right_Limit (Decl : Iir_Range_Expression) return Iir is
   begin
      pragma Assert (Decl /= Null_Iir);
      pragma Assert (Has_Right_Limit (Get_Kind (Decl)),
                     "no field Right_Limit");
      return Get_Field5 (Decl);
   end Get_Right_Limit;

   procedure Set_Right_Limit (Decl : Iir_Range_Expression; Limit : Iir) is
   begin
      pragma Assert (Decl /= Null_Iir);
      pragma Assert (Has_Right_Limit (Get_Kind (Decl)),
                     "no field Right_Limit");
      Set_Field5 (Decl, Limit);
   end Set_Right_Limit;

   function Get_Left_Limit_Expr (Decl : Iir_Range_Expression) return Iir is
   begin
      pragma Assert (Decl /= Null_Iir);
      pragma Assert (Has_Left_Limit_Expr (Get_Kind (Decl)),
                     "no field Left_Limit_Expr");
      return Get_Field2 (Decl);
   end Get_Left_Limit_Expr;

   procedure Set_Left_Limit_Expr (Decl : Iir_Range_Expression; Limit : Iir) is
   begin
      pragma Assert (Decl /= Null_Iir);
      pragma Assert (Has_Left_Limit_Expr (Get_Kind (Decl)),
                     "no field Left_Limit_Expr");
      Set_Field2 (Decl, Limit);
   end Set_Left_Limit_Expr;

   function Get_Right_Limit_Expr (Decl : Iir_Range_Expression) return Iir is
   begin
      pragma Assert (Decl /= Null_Iir);
      pragma Assert (Has_Right_Limit_Expr (Get_Kind (Decl)),
                     "no field Right_Limit_Expr");
      return Get_Field3 (Decl);
   end Get_Right_Limit_Expr;

   procedure Set_Right_Limit_Expr (Decl : Iir_Range_Expression; Limit : Iir)
   is
   begin
      pragma Assert (Decl /= Null_Iir);
      pragma Assert (Has_Right_Limit_Expr (Get_Kind (Decl)),
                     "no field Right_Limit_Expr");
      Set_Field3 (Decl, Limit);
   end Set_Right_Limit_Expr;

   function Get_Parent_Type (Decl : Iir) return Iir is
   begin
      pragma Assert (Decl /= Null_Iir);
      pragma Assert (Has_Parent_Type (Get_Kind (Decl)),
                     "no field Parent_Type");
      return Get_Field4 (Decl);
   end Get_Parent_Type;

   procedure Set_Parent_Type (Decl : Iir; Base_Type : Iir) is
   begin
      pragma Assert (Decl /= Null_Iir);
      pragma Assert (Has_Parent_Type (Get_Kind (Decl)),
                     "no field Parent_Type");
      Set_Field4 (Decl, Base_Type);
   end Set_Parent_Type;

   function Get_Simple_Nature (Def : Iir) return Iir is
   begin
      pragma Assert (Def /= Null_Iir);
      pragma Assert (Has_Simple_Nature (Get_Kind (Def)),
                     "no field Simple_Nature");
      return Get_Field7 (Def);
   end Get_Simple_Nature;

   procedure Set_Simple_Nature (Def : Iir; Nature : Iir) is
   begin
      pragma Assert (Def /= Null_Iir);
      pragma Assert (Has_Simple_Nature (Get_Kind (Def)),
                     "no field Simple_Nature");
      Set_Field7 (Def, Nature);
   end Set_Simple_Nature;

   function Get_Base_Nature (Decl : Iir) return Iir is
   begin
      pragma Assert (Decl /= Null_Iir);
      pragma Assert (Has_Base_Nature (Get_Kind (Decl)),
                     "no field Base_Nature");
      return Get_Field4 (Decl);
   end Get_Base_Nature;

   procedure Set_Base_Nature (Decl : Iir; Base_Nature : Iir) is
   begin
      pragma Assert (Decl /= Null_Iir);
      pragma Assert (Has_Base_Nature (Get_Kind (Decl)),
                     "no field Base_Nature");
      Set_Field4 (Decl, Base_Nature);
   end Set_Base_Nature;

   function Get_Resolution_Indication (Decl : Iir) return Iir is
   begin
      pragma Assert (Decl /= Null_Iir);
      pragma Assert (Has_Resolution_Indication (Get_Kind (Decl)),
                     "no field Resolution_Indication");
      return Get_Field5 (Decl);
   end Get_Resolution_Indication;

   procedure Set_Resolution_Indication (Decl : Iir; Ind : Iir) is
   begin
      pragma Assert (Decl /= Null_Iir);
      pragma Assert (Has_Resolution_Indication (Get_Kind (Decl)),
                     "no field Resolution_Indication");
      Set_Field5 (Decl, Ind);
   end Set_Resolution_Indication;

   function Get_Record_Element_Resolution_Chain (Res : Iir) return Iir is
   begin
      pragma Assert (Res /= Null_Iir);
      pragma Assert (Has_Record_Element_Resolution_Chain (Get_Kind (Res)),
                     "no field Record_Element_Resolution_Chain");
      return Get_Field1 (Res);
   end Get_Record_Element_Resolution_Chain;

   procedure Set_Record_Element_Resolution_Chain (Res : Iir; Chain : Iir) is
   begin
      pragma Assert (Res /= Null_Iir);
      pragma Assert (Has_Record_Element_Resolution_Chain (Get_Kind (Res)),
                     "no field Record_Element_Resolution_Chain");
      Set_Field1 (Res, Chain);
   end Set_Record_Element_Resolution_Chain;

   function Get_Tolerance (Def : Iir) return Iir is
   begin
      pragma Assert (Def /= Null_Iir);
      pragma Assert (Has_Tolerance (Get_Kind (Def)),
                     "no field Tolerance");
      return Get_Field7 (Def);
   end Get_Tolerance;

   procedure Set_Tolerance (Def : Iir; Tol : Iir) is
   begin
      pragma Assert (Def /= Null_Iir);
      pragma Assert (Has_Tolerance (Get_Kind (Def)),
                     "no field Tolerance");
      Set_Field7 (Def, Tol);
   end Set_Tolerance;

   function Get_Plus_Terminal_Name (Def : Iir) return Iir is
   begin
      pragma Assert (Def /= Null_Iir);
      pragma Assert (Has_Plus_Terminal_Name (Get_Kind (Def)),
                     "no field Plus_Terminal_Name");
      return Get_Field8 (Def);
   end Get_Plus_Terminal_Name;

   procedure Set_Plus_Terminal_Name (Def : Iir; Name : Iir) is
   begin
      pragma Assert (Def /= Null_Iir);
      pragma Assert (Has_Plus_Terminal_Name (Get_Kind (Def)),
                     "no field Plus_Terminal_Name");
      Set_Field8 (Def, Name);
   end Set_Plus_Terminal_Name;

   function Get_Minus_Terminal_Name (Def : Iir) return Iir is
   begin
      pragma Assert (Def /= Null_Iir);
      pragma Assert (Has_Minus_Terminal_Name (Get_Kind (Def)),
                     "no field Minus_Terminal_Name");
      return Get_Field9 (Def);
   end Get_Minus_Terminal_Name;

   procedure Set_Minus_Terminal_Name (Def : Iir; Name : Iir) is
   begin
      pragma Assert (Def /= Null_Iir);
      pragma Assert (Has_Minus_Terminal_Name (Get_Kind (Def)),
                     "no field Minus_Terminal_Name");
      Set_Field9 (Def, Name);
   end Set_Minus_Terminal_Name;

   function Get_Plus_Terminal (Def : Iir) return Iir is
   begin
      pragma Assert (Def /= Null_Iir);
      pragma Assert (Has_Plus_Terminal (Get_Kind (Def)),
                     "no field Plus_Terminal");
      return Get_Field10 (Def);
   end Get_Plus_Terminal;

   procedure Set_Plus_Terminal (Def : Iir; Terminal : Iir) is
   begin
      pragma Assert (Def /= Null_Iir);
      pragma Assert (Has_Plus_Terminal (Get_Kind (Def)),
                     "no field Plus_Terminal");
      Set_Field10 (Def, Terminal);
   end Set_Plus_Terminal;

   function Get_Minus_Terminal (Def : Iir) return Iir is
   begin
      pragma Assert (Def /= Null_Iir);
      pragma Assert (Has_Minus_Terminal (Get_Kind (Def)),
                     "no field Minus_Terminal");
      return Get_Field11 (Def);
   end Get_Minus_Terminal;

   procedure Set_Minus_Terminal (Def : Iir; Terminal : Iir) is
   begin
      pragma Assert (Def /= Null_Iir);
      pragma Assert (Has_Minus_Terminal (Get_Kind (Def)),
                     "no field Minus_Terminal");
      Set_Field11 (Def, Terminal);
   end Set_Minus_Terminal;

   function Get_Magnitude_Expression (Decl : Iir) return Iir is
   begin
      pragma Assert (Decl /= Null_Iir);
      pragma Assert (Has_Magnitude_Expression (Get_Kind (Decl)),
                     "no field Magnitude_Expression");
      return Get_Field6 (Decl);
   end Get_Magnitude_Expression;

   procedure Set_Magnitude_Expression (Decl : Iir; Expr : Iir) is
   begin
      pragma Assert (Decl /= Null_Iir);
      pragma Assert (Has_Magnitude_Expression (Get_Kind (Decl)),
                     "no field Magnitude_Expression");
      Set_Field6 (Decl, Expr);
   end Set_Magnitude_Expression;

   function Get_Phase_Expression (Decl : Iir) return Iir is
   begin
      pragma Assert (Decl /= Null_Iir);
      pragma Assert (Has_Phase_Expression (Get_Kind (Decl)),
                     "no field Phase_Expression");
      return Get_Field7 (Decl);
   end Get_Phase_Expression;

   procedure Set_Phase_Expression (Decl : Iir; Expr : Iir) is
   begin
      pragma Assert (Decl /= Null_Iir);
      pragma Assert (Has_Phase_Expression (Get_Kind (Decl)),
                     "no field Phase_Expression");
      Set_Field7 (Decl, Expr);
   end Set_Phase_Expression;

   function Get_Power_Expression (Decl : Iir) return Iir is
   begin
      pragma Assert (Decl /= Null_Iir);
      pragma Assert (Has_Power_Expression (Get_Kind (Decl)),
                     "no field Power_Expression");
      return Get_Field4 (Decl);
   end Get_Power_Expression;

   procedure Set_Power_Expression (Decl : Iir; Expr : Iir) is
   begin
      pragma Assert (Decl /= Null_Iir);
      pragma Assert (Has_Power_Expression (Get_Kind (Decl)),
                     "no field Power_Expression");
      Set_Field4 (Decl, Expr);
   end Set_Power_Expression;

   function Get_Simultaneous_Left (Def : Iir) return Iir is
   begin
      pragma Assert (Def /= Null_Iir);
      pragma Assert (Has_Simultaneous_Left (Get_Kind (Def)),
                     "no field Simultaneous_Left");
      return Get_Field5 (Def);
   end Get_Simultaneous_Left;

   procedure Set_Simultaneous_Left (Def : Iir; Expr : Iir) is
   begin
      pragma Assert (Def /= Null_Iir);
      pragma Assert (Has_Simultaneous_Left (Get_Kind (Def)),
                     "no field Simultaneous_Left");
      Set_Field5 (Def, Expr);
   end Set_Simultaneous_Left;

   function Get_Simultaneous_Right (Def : Iir) return Iir is
   begin
      pragma Assert (Def /= Null_Iir);
      pragma Assert (Has_Simultaneous_Right (Get_Kind (Def)),
                     "no field Simultaneous_Right");
      return Get_Field6 (Def);
   end Get_Simultaneous_Right;

   procedure Set_Simultaneous_Right (Def : Iir; Expr : Iir) is
   begin
      pragma Assert (Def /= Null_Iir);
      pragma Assert (Has_Simultaneous_Right (Get_Kind (Def)),
                     "no field Simultaneous_Right");
      Set_Field6 (Def, Expr);
   end Set_Simultaneous_Right;

   function Get_Text_File_Flag (Atype : Iir) return Boolean is
   begin
      pragma Assert (Atype /= Null_Iir);
      pragma Assert (Has_Text_File_Flag (Get_Kind (Atype)),
                     "no field Text_File_Flag");
      return Get_Flag4 (Atype);
   end Get_Text_File_Flag;

   procedure Set_Text_File_Flag (Atype : Iir; Flag : Boolean) is
   begin
      pragma Assert (Atype /= Null_Iir);
      pragma Assert (Has_Text_File_Flag (Get_Kind (Atype)),
                     "no field Text_File_Flag");
      Set_Flag4 (Atype, Flag);
   end Set_Text_File_Flag;

   function Get_Only_Characters_Flag (Atype : Iir) return Boolean is
   begin
      pragma Assert (Atype /= Null_Iir);
      pragma Assert (Has_Only_Characters_Flag (Get_Kind (Atype)),
                     "no field Only_Characters_Flag");
      return Get_Flag4 (Atype);
   end Get_Only_Characters_Flag;

   procedure Set_Only_Characters_Flag (Atype : Iir; Flag : Boolean) is
   begin
      pragma Assert (Atype /= Null_Iir);
      pragma Assert (Has_Only_Characters_Flag (Get_Kind (Atype)),
                     "no field Only_Characters_Flag");
      Set_Flag4 (Atype, Flag);
   end Set_Only_Characters_Flag;

   function Get_Is_Character_Type (Atype : Iir) return Boolean is
   begin
      pragma Assert (Atype /= Null_Iir);
      pragma Assert (Has_Is_Character_Type (Get_Kind (Atype)),
                     "no field Is_Character_Type");
      return Get_Flag5 (Atype);
   end Get_Is_Character_Type;

   procedure Set_Is_Character_Type (Atype : Iir; Flag : Boolean) is
   begin
      pragma Assert (Atype /= Null_Iir);
      pragma Assert (Has_Is_Character_Type (Get_Kind (Atype)),
                     "no field Is_Character_Type");
      Set_Flag5 (Atype, Flag);
   end Set_Is_Character_Type;

   function Get_Nature_Staticness (Anat : Iir) return Iir_Staticness is
   begin
      pragma Assert (Anat /= Null_Iir);
      pragma Assert (Has_Nature_Staticness (Get_Kind (Anat)),
                     "no field Nature_Staticness");
      return Iir_Staticness'Val (Get_State1 (Anat));
   end Get_Nature_Staticness;

   procedure Set_Nature_Staticness (Anat : Iir; Static : Iir_Staticness) is
   begin
      pragma Assert (Anat /= Null_Iir);
      pragma Assert (Has_Nature_Staticness (Get_Kind (Anat)),
                     "no field Nature_Staticness");
      Set_State1 (Anat, Iir_Staticness'Pos (Static));
   end Set_Nature_Staticness;

   function Get_Type_Staticness (Atype : Iir) return Iir_Staticness is
   begin
      pragma Assert (Atype /= Null_Iir);
      pragma Assert (Has_Type_Staticness (Get_Kind (Atype)),
                     "no field Type_Staticness");
      return Iir_Staticness'Val (Get_State1 (Atype));
   end Get_Type_Staticness;

   procedure Set_Type_Staticness (Atype : Iir; Static : Iir_Staticness) is
   begin
      pragma Assert (Atype /= Null_Iir);
      pragma Assert (Has_Type_Staticness (Get_Kind (Atype)),
                     "no field Type_Staticness");
      Set_State1 (Atype, Iir_Staticness'Pos (Static));
   end Set_Type_Staticness;

   function Get_Constraint_State (Atype : Iir) return Iir_Constraint is
   begin
      pragma Assert (Atype /= Null_Iir);
      pragma Assert (Has_Constraint_State (Get_Kind (Atype)),
                     "no field Constraint_State");
      return Iir_Constraint'Val (Get_State2 (Atype));
   end Get_Constraint_State;

   procedure Set_Constraint_State (Atype : Iir; State : Iir_Constraint) is
   begin
      pragma Assert (Atype /= Null_Iir);
      pragma Assert (Has_Constraint_State (Get_Kind (Atype)),
                     "no field Constraint_State");
      Set_State2 (Atype, Iir_Constraint'Pos (State));
   end Set_Constraint_State;

   function Get_Index_Subtype_List (Decl : Iir) return Iir_Flist is
   begin
      pragma Assert (Decl /= Null_Iir);
      pragma Assert (Has_Index_Subtype_List (Get_Kind (Decl)),
                     "no field Index_Subtype_List");
      return Iir_To_Iir_Flist (Get_Field9 (Decl));
   end Get_Index_Subtype_List;

   procedure Set_Index_Subtype_List (Decl : Iir; List : Iir_Flist) is
   begin
      pragma Assert (Decl /= Null_Iir);
      pragma Assert (Has_Index_Subtype_List (Get_Kind (Decl)),
                     "no field Index_Subtype_List");
      Set_Field9 (Decl, Iir_Flist_To_Iir (List));
   end Set_Index_Subtype_List;

   function Get_Index_Subtype_Definition_List (Def : Iir) return Iir_Flist is
   begin
      pragma Assert (Def /= Null_Iir);
      pragma Assert (Has_Index_Subtype_Definition_List (Get_Kind (Def)),
                     "no field Index_Subtype_Definition_List");
      return Iir_To_Iir_Flist (Get_Field6 (Def));
   end Get_Index_Subtype_Definition_List;

   procedure Set_Index_Subtype_Definition_List (Def : Iir; Idx : Iir_Flist) is
   begin
      pragma Assert (Def /= Null_Iir);
      pragma Assert (Has_Index_Subtype_Definition_List (Get_Kind (Def)),
                     "no field Index_Subtype_Definition_List");
      Set_Field6 (Def, Iir_Flist_To_Iir (Idx));
   end Set_Index_Subtype_Definition_List;

   function Get_Element_Subtype_Indication (Decl : Iir) return Iir is
   begin
      pragma Assert (Decl /= Null_Iir);
      pragma Assert (Has_Element_Subtype_Indication (Get_Kind (Decl)),
                     "no field Element_Subtype_Indication");
      return Get_Field2 (Decl);
   end Get_Element_Subtype_Indication;

   procedure Set_Element_Subtype_Indication (Decl : Iir; Sub_Type : Iir) is
   begin
      pragma Assert (Decl /= Null_Iir);
      pragma Assert (Has_Element_Subtype_Indication (Get_Kind (Decl)),
                     "no field Element_Subtype_Indication");
      Set_Field2 (Decl, Sub_Type);
   end Set_Element_Subtype_Indication;

   function Get_Element_Subtype (Decl : Iir) return Iir is
   begin
      pragma Assert (Decl /= Null_Iir);
      pragma Assert (Has_Element_Subtype (Get_Kind (Decl)),
                     "no field Element_Subtype");
      return Get_Field1 (Decl);
   end Get_Element_Subtype;

   procedure Set_Element_Subtype (Decl : Iir; Sub_Type : Iir) is
   begin
      pragma Assert (Decl /= Null_Iir);
      pragma Assert (Has_Element_Subtype (Get_Kind (Decl)),
                     "no field Element_Subtype");
      Set_Field1 (Decl, Sub_Type);
   end Set_Element_Subtype;

   function Get_Element_Subnature_Indication (Decl : Iir) return Iir is
   begin
      pragma Assert (Decl /= Null_Iir);
      pragma Assert (Has_Element_Subnature_Indication (Get_Kind (Decl)),
                     "no field Element_Subnature_Indication");
      return Get_Field2 (Decl);
   end Get_Element_Subnature_Indication;

   procedure Set_Element_Subnature_Indication (Decl : Iir; Sub_Nature : Iir)
   is
   begin
      pragma Assert (Decl /= Null_Iir);
      pragma Assert (Has_Element_Subnature_Indication (Get_Kind (Decl)),
                     "no field Element_Subnature_Indication");
      Set_Field2 (Decl, Sub_Nature);