summaryrefslogtreecommitdiff
path: root/include/flang/Sema/Sema.h
blob: 7b5cb742c61ab2dfbefc2652d4d036eef1907dcb (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
//===--- Sema.h - Semantic Analysis & AST Building --------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines the Sema class, which performs semantic analysis and builds
// ASTs.
//
//===----------------------------------------------------------------------===//

#ifndef FLANG_SEMA_SEMA_H__
#define FLANG_SEMA_SEMA_H__

#include "flang/Basic/Token.h"
#include "flang/AST/FormatSpec.h"
#include "flang/AST/Stmt.h"
#include "flang/AST/Type.h"
#include "flang/AST/Expr.h"
#include "flang/AST/IOSpec.h"
#include "flang/Sema/Ownership.h"
#include "flang/Sema/Scope.h"
#include "flang/Sema/DeclSpec.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/SourceMgr.h"
#include "flang/Basic/LLVM.h"
#include <vector>

namespace flang {

class ASTContext;
class DeclContext;
class DeclSpec;
class DeclarationNameInfo;
class DiagnosticsEngine;
class Expr;
class FormatSpec;
class IdentifierInfo;
class Token;
class VarDecl;

/// Sema - This implements semantic analysis and AST building for Fortran.
class Sema {
  Sema(const Sema&);           // DO NOT IMPLEMENT
  void operator=(const Sema&); // DO NOT IMPLEMENT


  /// \brief A statement label scope for the current program unit.
  StmtLabelScope *CurStmtLabelScope;

  /// \brief A named constructs scope for the current program unit.
  ConstructNameScope *CurNamedConstructs;

  /// \brief A class which supports the executable statements in
  /// the current scope.
  BlockStmtBuilder *CurExecutableStmts;

  /// \brief The implicit scope for the current program unit.
  ImplicitTypingScope *CurImplicitTypingScope;

  /// \brief The equivalence scope for the current program unit.
  EquivalenceScope *CurEquivalenceScope;

  /// \brief The common block scope for the current program unit.
  CommonBlockScope *CurCommonBlockScope;

  /// \brief The specification scope for the current program unit.
  SpecificationScope *CurSpecScope;

  /// \brief Represents the do loop variable currently being used.
  SmallVector<const VarExpr*, 8> CurLoopVars;

  /// \brief Marks the variable as used by a loop.
  void AddLoopVar(const VarExpr *Var) {
    CurLoopVars.push_back(Var);
  }

  /// \brief Clears the variable of a used by a loop mark.
  void RemoveLoopVar(const VarExpr *Var) {
    for(auto I = CurLoopVars.begin();I!=CurLoopVars.end();++I) {
      if(*I == Var) {
        CurLoopVars.erase(I);
        return;
      }
    }
  }

  /// \brief The mapping
  intrinsic::FunctionMapping IntrinsicFunctionMapping;

public:
  typedef Expr ExprTy;

  ASTContext &Context;
  DiagnosticsEngine &Diags;

  /// CurContext - This is the current declaration context of parsing.
  DeclContext *CurContext;

  Sema(ASTContext &ctxt, DiagnosticsEngine &Diags);
  ~Sema();

  ASTContext &getContext() { return Context; }

  LangOptions getLangOpts() const {
    return Context.getLangOpts();
  }

  DeclContext *getContainingDC(DeclContext *DC);

  StmtLabelScope *getCurrentStmtLabelScope() const {
    return CurStmtLabelScope;
  }

  ConstructNameScope *getCurrentConstructNameScope() const {
    return CurNamedConstructs;
  }

  ImplicitTypingScope *getCurrentImplicitTypingScope() const {
    return CurImplicitTypingScope;
  }

  EquivalenceScope *getCurrentEquivalenceScope() const {
    return CurEquivalenceScope;
  }

  CommonBlockScope *getCurrentCommonBlockScope() const {
    return CurCommonBlockScope;
  }

  BlockStmtBuilder *getCurrentBody() const {
    return CurExecutableStmts;
  }

  SourceRange getTokenRange(SourceLocation Loc);

  inline ExprResult ExprError() const { return ExprResult(true); }
  inline StmtResult StmtError() const { return StmtResult(true); }

  /// Set the current declaration context until it gets popped.
  void PushDeclContext(DeclContext *DC);
  void PopDeclContext();

  bool IsInsideFunctionOrSubroutine() const;
  FunctionDecl *CurrentContextAsFunction() const;

  void PushExecutableProgramUnit(ExecutableProgramUnitScope &Scope);
  void PopExecutableProgramUnit(SourceLocation Loc);

  void PushProgramUnitScope(ExecutableProgramUnitScope &Scope);
  void PopExecutableProgramUnitScope(SourceLocation Loc);

  void DeclareStatementLabel(Expr *StmtLabel, Stmt *S);
  void CheckStatementLabelEndDo(Expr *StmtLabel, Stmt *S);

  void DeclareConstructName(ConstructName Name, NamedConstructStmt *S);

  /// translation unit actions
  void ActOnTranslationUnit(TranslationUnitScope &Scope);
  void ActOnEndTranslationUnit();

  /// program unit actions
  MainProgramDecl *ActOnMainProgram(ASTContext &C, MainProgramScope &Scope,
                                    const IdentifierInfo *IDInfo, SourceLocation NameLoc);

  void ActOnEndMainProgram(SourceLocation Loc);

  FunctionDecl *ActOnSubProgram(ASTContext &C, SubProgramScope &Scope,
                                bool IsSubRoutine, SourceLocation IDLoc,
                                const IdentifierInfo *IDInfo, DeclSpec &ReturnTypeDecl,
                                int Attr);
  void ActOnRESULT(ASTContext &C, SourceLocation IDLoc,
                   const IdentifierInfo *IDInfo);
  VarDecl *ActOnSubProgramArgument(ASTContext &C, SourceLocation IDLoc,
                                   const IdentifierInfo *IDInfo);
  void ActOnSubProgramStarArgument(ASTContext &C, SourceLocation Loc);
  void ActOnSubProgramArgumentList(ASTContext &C, ArrayRef<VarDecl*> Arguments);
  void ActOnEndSubProgram(ASTContext &C, SourceLocation Loc);

  FunctionDecl *ActOnStatementFunction(ASTContext &C,
                                       SourceLocation IDLoc,
                                       const IdentifierInfo *IDInfo);
  VarDecl *ActOnStatementFunctionArgument(ASTContext &C, SourceLocation IDLoc,
                                          const IdentifierInfo *IDInfo);
  void ActOnStatementFunctionBody(SourceLocation Loc, ExprResult Body);
  void ActOnEndStatementFunction(ASTContext &C);

  void ActOnSpecificationPart();

  void ActOnFunctionSpecificationPart();

  VarDecl *GetVariableForSpecification(SourceLocation StmtLoc, const IdentifierInfo *IDInfo,
                                       SourceLocation IDLoc,
                                       bool CanBeArgument = true);

  bool ApplyDimensionSpecification(SourceLocation Loc, SourceLocation IDLoc,
                                   const IdentifierInfo *IDInfo,
                                   ArrayRef<ArraySpec*> Dims);

  bool ApplySaveSpecification(SourceLocation Loc, SourceLocation IDLoc,
                              const IdentifierInfo *IDInfo);

  bool ApplySaveSpecification(SourceLocation Loc, SourceLocation IDLoc, VarDecl *VD);

  bool ApplySaveSpecification(SourceLocation Loc, SourceLocation IDLoc,
                              CommonBlockDecl *Block);

  bool ApplyCommonSpecification(SourceLocation Loc, SourceLocation IDLoc,
                                const IdentifierInfo *IDInfo,
                                CommonBlockDecl *Block,
                                CommonBlockSetBuilder &Builder);

  QualType ActOnTypeName(ASTContext &C, DeclSpec &DS);
  VarDecl *ActOnKindSelector(ASTContext &C, SourceLocation IDLoc,
                             const IdentifierInfo *IDInfo);

  /// ActOnAttrSpec - Helper function that assigns the attribute specification to
  /// the list, but reports an error if that attribute was all ready assigned.
  /// Returns true if the attribute specification wasn't applied.
  bool ActOnAttrSpec(SourceLocation Loc, DeclSpec &DS, DeclSpec::AS Val);

  /// ActOnDimensionAttrSpec - returns true if the DIMENSION attribute
  /// specification wasn't applied.
  bool ActOnDimensionAttrSpec(ASTContext &C, SourceLocation Loc,
                              DeclSpec &DS,
                              ArrayRef<ArraySpec*> Dimensions);

  /// ActOnAccessSpec - Helper function that assigns the access specification to
  /// the DeclSpec, but reports an error if that access spec was all ready
  /// assigned.
  bool ActOnAccessSpec(SourceLocation Loc, DeclSpec &DS, DeclSpec::AC Val);

  /// ActOnIntentSpec - Helper function that assigns the intent specification to
  /// the DeclSpec, but reports an error if that intent spec was all ready
  /// assigned.
  bool ActOnIntentSpec(SourceLocation Loc, DeclSpec &DS, DeclSpec::IS Val);

  /// ActOnObjectArraySpec - returns true if the array specification wasn't
  /// applied.
  bool ActOnObjectArraySpec(ASTContext &C, SourceLocation Loc, DeclSpec &DS,
                            ArrayRef<ArraySpec*> Dimensions);

  /// AtOnTypeDeclSpec - returns true if the derived type specification wasn't
  /// applied.
  void ActOnTypeDeclSpec(ASTContext &C, SourceLocation Loc,
                         const IdentifierInfo *IDInfo, DeclSpec &DS);

  VarDecl *CreateImplicitEntityDecl(ASTContext &C, SourceLocation IDLoc,
                                    const IdentifierInfo *IDInfo);

  Decl *ActOnExternalEntityDecl(ASTContext &C, QualType T,
                                SourceLocation IDLoc, const IdentifierInfo *IDInfo);

  Decl *ActOnIntrinsicEntityDecl(ASTContext &C, QualType T,
                                 SourceLocation IDLoc, const IdentifierInfo *IDInfo);

  Decl *ActOnParameterEntityDecl(ASTContext &C, QualType T,
                                 SourceLocation IDLoc, const IdentifierInfo *IDInfo,
                                 SourceLocation EqualLoc, ExprResult Value);

  Decl *ActOnEntityDecl(ASTContext &C, const QualType &T,
                        SourceLocation IDLoc, const IdentifierInfo *IDInfo);

  Decl *ActOnEntityDecl(ASTContext &C, DeclSpec &DS,
                        SourceLocation IDLoc, const IdentifierInfo *IDInfo);

  QualType ResolveImplicitType(const IdentifierInfo *IDInfo);

  Decl *ActOnImplicitEntityDecl(ASTContext &C, SourceLocation IDLoc,
                                const IdentifierInfo *IDInfo);

  Decl *ActOnImplicitFunctionDecl(ASTContext &C, SourceLocation IDLoc,
                                  const IdentifierInfo *IDInfo);

  Decl *ActOnPossibleImplicitFunctionDecl(ASTContext &C, SourceLocation IDLoc,
                                          const IdentifierInfo *IDInfo,
                                          Decl *PrevDecl);

  bool ApplyImplicitRulesToArgument(VarDecl *Arg,
                                    SourceRange Range = SourceRange());

  /// Returns a declaration which matches the identifier in this context
  Decl *LookupIdentifier(const IdentifierInfo *IDInfo);

  Decl *ResolveIdentifier(const IdentifierInfo *IDInfo);

  /// \brief Returns a variable declaration if the given identifier resolves
  /// to a variable, or null otherwise. If the identifier isn't resolved
  /// an implicit variable declaration will be created whenever possible.
  VarDecl *ExpectVarRefOrDeclImplicitVar(SourceLocation IDLoc,
                                         const IdentifierInfo *IDInfo);

  /// \brief Returns a variable declaration if the given identifier resolves to
  /// a variable, or null otherwise.
  VarDecl *ExpectVarRef(SourceLocation IDLoc,
                        const IdentifierInfo *IDInfo);

  VarExpr *ConstructRecoveryVariable(ASTContext &C, SourceLocation Loc,
                                     QualType T);

  /// \brief Returns true if the given identifier can be used as the function name
  /// in a statement function declaration. This function resolves the ambiguity
  /// of statement function declarations and array subscript assignments.
  bool IsValidStatementFunctionIdentifier(const IdentifierInfo *IDInfo);

  RecordDecl *ActOnDerivedTypeDecl(ASTContext &C, SourceLocation Loc,
                                   SourceLocation IDLoc, const IdentifierInfo* IDInfo);

  void ActOnDerivedTypeSequenceStmt(ASTContext &C, SourceLocation Loc);

  FieldDecl *ActOnDerivedTypeFieldDecl(ASTContext &C, DeclSpec &DS, SourceLocation IDLoc,
                                       const IdentifierInfo *IDInfo,
                                       ExprResult Init = ExprResult());

  void ActOnENDTYPE(ASTContext &C, SourceLocation Loc,
                    SourceLocation IDLoc, const IdentifierInfo* IDInfo);

  void ActOnEndDerivedTypeDecl(ASTContext &C);

  StmtResult ActOnCompoundStmt(ASTContext &C, SourceLocation Loc,
                               ArrayRef<Stmt*> Body, Expr *StmtLabel);

  // PROGRAM statement:
  StmtResult ActOnPROGRAM(ASTContext &C, const IdentifierInfo *ProgName,
                          SourceLocation Loc, SourceLocation NameLoc, Expr *StmtLabel);

  // END PROGRAM / SUBROUTINE / FUNCTION statement:
  StmtResult ActOnEND(ASTContext &C, SourceLocation Loc,
                      ConstructPartStmt::ConstructStmtClass Kind,
                      SourceLocation IDLoc, const IdentifierInfo *IDInfo,
                      Expr *StmtLabel);

  // USE statement:
  StmtResult ActOnUSE(ASTContext &C, UseStmt::ModuleNature MN,
                      const IdentifierInfo *ModName, Expr *StmtLabel);
  StmtResult ActOnUSE(ASTContext &C, UseStmt::ModuleNature MN,
                      const IdentifierInfo *ModName, bool OnlyList,
                      ArrayRef<UseStmt::RenamePair> RenameNames,
                      Expr *StmtLabel);

  // IMPORT statement:
  StmtResult ActOnIMPORT(ASTContext &C, SourceLocation Loc,
                         ArrayRef<const IdentifierInfo*> ImportNamesList,
                         Expr *StmtLabel);

  // IMPLICIT statement:
  StmtResult ActOnIMPLICIT(ASTContext &C, SourceLocation Loc, DeclSpec &DS,
                           ImplicitStmt::LetterSpecTy LetterSpec, Expr *StmtLabel);

  StmtResult ActOnIMPLICIT(ASTContext &C, SourceLocation Loc, Expr *StmtLabel);

  // DIMENSION statement
  // The source code statement is split into multiple ones in the parsing stage.
  StmtResult ActOnDIMENSION(ASTContext &C, SourceLocation Loc, SourceLocation IDLoc,
                            const IdentifierInfo *IDInfo,
                            ArrayRef<ArraySpec*> Dims,
                            Expr *StmtLabel);

  // PARAMETER statement:
  StmtResult ActOnPARAMETER(ASTContext &C, SourceLocation Loc,
                            SourceLocation EqualLoc,
                            SourceLocation IDLoc,
                            const IdentifierInfo *IDInfo,
                            ExprResult Value,
                            Expr *StmtLabel);

  // ASYNCHRONOUS statement:
  StmtResult ActOnASYNCHRONOUS(ASTContext &C, SourceLocation Loc,
                               ArrayRef<const IdentifierInfo*> ObjNames,
                               Expr *StmtLabel);

  // EXTERNAL statement:
  StmtResult ActOnEXTERNAL(ASTContext &C, SourceLocation Loc,
                           SourceLocation IDLoc,
                           const IdentifierInfo *IDInfo,
                           Expr *StmtLabel);

  // INTRINSIC statement:
  StmtResult ActOnINTRINSIC(ASTContext &C, SourceLocation Loc,
                            SourceLocation IDLoc,
                            const IdentifierInfo *IDInfo,
                            Expr *StmtLabel);

  // SAVE statement
  StmtResult ActOnSAVE(ASTContext &C, SourceLocation Loc, Expr *StmtLabel);

  StmtResult ActOnSAVE(ASTContext &C, SourceLocation Loc,
                       SourceLocation IDLoc,
                       const IdentifierInfo *IDInfo,
                       Expr *StmtLabel);

  StmtResult ActOnSAVECommonBlock(ASTContext &C, SourceLocation Loc,
                                  SourceLocation IDLoc,
                                  const IdentifierInfo *IDInfo);

  // EQUIVALENCE statement
  StmtResult ActOnEQUIVALENCE(ASTContext &C, SourceLocation Loc,
                              SourceLocation PartLoc,
                              ArrayRef<Expr*> ObjectList,
                              Expr *StmtLabel);

  bool CheckEquivalenceObject(SourceLocation Loc, Expr *E, VarDecl *&Object);

  bool CheckEquivalenceType(QualType ExpectedType, const Expr *E);

  void ActOnCOMMON(ASTContext &C, SourceLocation Loc, SourceLocation BlockLoc,
                   SourceLocation IDLoc, const IdentifierInfo *BlockID,
                   const IdentifierInfo *IDInfo, ArrayRef<ArraySpec *> Dimensions);

  // DATA statement:
  StmtResult ActOnDATA(ASTContext &C, SourceLocation Loc,
                       ArrayRef<Expr*> LHS, ArrayRef<Expr*> Values,
                       Expr *StmtLabel);

  ExprResult ActOnDATAConstantExpr(ASTContext &C, SourceLocation RepeatLoc,
                                   ExprResult RepeatCount,
                                   ExprResult Value);

  ExprResult ActOnDATAOuterImpliedDoExpr(ASTContext &C,
                                         ExprResult Expression);

  ExprResult ActOnDATAImpliedDoExpr(ASTContext &C, SourceLocation Loc,
                                    SourceLocation IDLoc,
                                    const IdentifierInfo *IDInfo,
                                    ArrayRef<ExprResult> Body,
                                    ExprResult E1, ExprResult E2,
                                    ExprResult E3);

  StmtResult ActOnAssignmentStmt(ASTContext &C, SourceLocation Loc,
                                 ExprResult LHS,
                                 ExprResult RHS, Expr *StmtLabel);

  QualType ActOnArraySpec(ASTContext &C, QualType ElemTy,
                          ArrayRef<ArraySpec *> Dims);

  StarFormatSpec *ActOnStarFormatSpec(ASTContext &C, SourceLocation Loc);
  LabelFormatSpec *ActOnLabelFormatSpec(ASTContext &C, SourceLocation Loc,
                                        ExprResult Label);
  FormatSpec *ActOnExpressionFormatSpec(ASTContext &C, SourceLocation Loc,
                                             Expr *E);

  ExternalStarUnitSpec *ActOnStarUnitSpec(ASTContext &C, SourceLocation Loc,
                                          bool IsLabeled);
  UnitSpec *ActOnUnitSpec(ASTContext &C, ExprResult Value, SourceLocation Loc,
                          bool IsLabeled);

  StmtResult ActOnAssignStmt(ASTContext &C, SourceLocation Loc,
                             ExprResult Value, VarExpr* VarRef,
                             Expr *StmtLabel);

  StmtResult ActOnAssignedGotoStmt(ASTContext &C, SourceLocation Loc,
                                   VarExpr* VarRef, ArrayRef<Expr *> AllowedValues,
                                   Expr *StmtLabel);

  StmtResult ActOnGotoStmt(ASTContext &C, SourceLocation Loc,
                           ExprResult Destination, Expr *StmtLabel);

  StmtResult ActOnComputedGotoStmt(ASTContext &C, SourceLocation Loc,
                                   ArrayRef<Expr*> Targets,
                                   ExprResult Operand, Expr *StmtLabel);

  StmtResult ActOnIfStmt(ASTContext &C, SourceLocation Loc,
                         ExprResult Condition, ConstructName Name,
                         Expr *StmtLabel);
  StmtResult ActOnElseIfStmt(ASTContext &C, SourceLocation Loc,
                             ExprResult Condition, ConstructName Name, Expr *StmtLabel);
  StmtResult ActOnElseStmt(ASTContext &C, SourceLocation Loc,
                           ConstructName Name, Expr *StmtLabel);
  StmtResult ActOnEndIfStmt(ASTContext &C, SourceLocation Loc,
                            ConstructName Name, Expr *StmtLabel);

  StmtResult ActOnDoStmt(ASTContext &C, SourceLocation Loc, SourceLocation EqualLoc,
                         ExprResult TerminatingStmt,
                         VarExpr *DoVar, ExprResult E1, ExprResult E2,
                         ExprResult E3, ConstructName Name,
                         Expr *StmtLabel);

  StmtResult ActOnDoWhileStmt(ASTContext &C, SourceLocation Loc, ExprResult Condition,
                              ConstructName Name, Expr *StmtLabel);

  StmtResult ActOnEndDoStmt(ASTContext &C, SourceLocation Loc,
                            ConstructName Name, Expr *StmtLabel);

  StmtResult ActOnCycleStmt(ASTContext &C, SourceLocation Loc,
                            ConstructName LoopName, Expr *StmtLabel);

  StmtResult ActOnExitStmt(ASTContext &C, SourceLocation Loc,
                           ConstructName LoopName, Expr *StmtLabel);

  StmtResult ActOnSelectCaseStmt(ASTContext &C, SourceLocation Loc,
                                 ExprResult Operand,
                                 ConstructName Name, Expr *StmtLabel);

  StmtResult ActOnCaseDefaultStmt(ASTContext &C, SourceLocation Loc,
                                  ConstructName Name, Expr *StmtLabel);

  StmtResult ActOnCaseStmt(ASTContext &C, SourceLocation Loc,
                           llvm::MutableArrayRef<Expr*> Values,
                           ConstructName Name, Expr *StmtLabel);

  StmtResult ActOnEndSelectStmt(ASTContext &C, SourceLocation Loc,
                                ConstructName Name, Expr *StmtLabel);

  StmtResult ActOnWhereStmt(ASTContext &C, SourceLocation Loc,
                            ExprResult Mask, Expr *StmtLabel);

  StmtResult ActOnWhereStmt(ASTContext &C, SourceLocation Loc,
                            ExprResult Mask, StmtResult Body, Expr *StmtLabel);

  StmtResult ActOnElseWhereStmt(ASTContext &C, SourceLocation Loc, Expr *StmtLabel);

  StmtResult ActOnEndWhereStmt(ASTContext &C, SourceLocation Loc, Expr *StmtLabel);

  StmtResult ActOnContinueStmt(ASTContext &C, SourceLocation Loc, Expr *StmtLabel);

  StmtResult ActOnStopStmt(ASTContext &C, SourceLocation Loc, ExprResult StopCode, Expr *StmtLabel);

  StmtResult ActOnReturnStmt(ASTContext &C, SourceLocation Loc, ExprResult E, Expr *StmtLabel);

  StmtResult ActOnCallStmt(ASTContext &C, SourceLocation Loc, SourceLocation RParenLoc,
                           SourceLocation IDLoc,
                           const IdentifierInfo *IDInfo,
                           llvm::MutableArrayRef<Expr *> Arguments, Expr *StmtLabel);

  StmtResult ActOnPrintStmt(ASTContext &C, SourceLocation Loc, FormatSpec *FS,
                            ArrayRef<ExprResult> OutputItemList,
                            Expr *StmtLabel);

  StmtResult ActOnWriteStmt(ASTContext &C, SourceLocation Loc,
                            UnitSpec *US, FormatSpec *FS,
                            ArrayRef<ExprResult> OutputItemList,
                            Expr *StmtLabel);

  // FIXME: TODO:

  QualType ActOnBuiltinType(ASTContext *Ctx,
                            BuiltinType::TypeSpec TS,
                            Expr *Kind) { return QualType(); }
  QualType ActOnCharacterBuiltinType(ASTContext *Ctx,
                                     Expr *Len,
                                     Expr *Kind) { return QualType(); }

  ExprResult ActOnDataReference(llvm::ArrayRef<ExprResult> Exprs) {
    return ExprResult();
  }

  ExprResult ActOnComplexConstantExpr(ASTContext &C, SourceLocation Loc,
                                      SourceLocation MaxLoc,
                                      ExprResult RealPart, ExprResult ImPart);

  /// Returns true if a type is a double precision real type.
  bool IsTypeDoublePrecisionReal(QualType T) const;

  /// Returns true if a type is a double precision complex type.
  bool IsTypeDoublePrecisionComplex(QualType T) const;

  /// Returns true if a type is a byte type.
  bool IsTypeByte(QualType T) const;

  /// GetUnaryReturnType - Returns the type T with the
  /// required qualifiers and array type from the given expression.
  QualType GetUnaryReturnType(const Expr *E, QualType T);

  ExprResult ActOnUnaryExpr(ASTContext &C, SourceLocation Loc,
                            UnaryExpr::Operator Op, ExprResult E);

  /// GetBinaryReturnType - Returns the type T with the
  /// required qualifiers and array type from the given expression.
  QualType GetBinaryReturnType(const Expr *LHS, const Expr *RHS,
                               QualType T);

  ExprResult ActOnBinaryExpr(ASTContext &C, SourceLocation Loc,
                             BinaryExpr::Operator Op,
                             ExprResult LHS,ExprResult RHS);

  ExprResult ActOnSubstringExpr(ASTContext &C, SourceLocation Loc,
                                Expr *Target,
                                Expr *StartingPoint, Expr *EndPoint);

  ExprResult ActOnSubscriptExpr(ASTContext &C, SourceLocation Loc, SourceLocation RParenLoc,
                                Expr* Target, llvm::ArrayRef<Expr*> Subscripts);

  ExprResult ActOnCallExpr(ASTContext &C, SourceLocation Loc, SourceLocation RParenLoc,
                           SourceLocation IDLoc,
                           FunctionDecl *Function, llvm::MutableArrayRef<Expr *> Arguments);

  ExprResult ActOnIntrinsicFunctionCallExpr(ASTContext &C, SourceLocation Loc,
                                            const IntrinsicFunctionDecl *FunctionDecl,
                                            ArrayRef<Expr*> Arguments);

  ExprResult ActOnArrayConstructorExpr(ASTContext &C, SourceLocation Loc,
                                       SourceLocation RParenLoc, ArrayRef<Expr*> Elements);

  ExprResult ActOnTypeConstructorExpr(ASTContext &C, SourceLocation Loc, SourceLocation LParenLoc,
                                      SourceLocation RParenLoc, RecordDecl *Record,
                                      ArrayRef<Expr*> Arguments);


  ExprResult ActOnStructureComponentExpr(ASTContext &C, SourceLocation Loc,
                                         SourceLocation IDLoc,
                                         const IdentifierInfo *IDInfo, Expr *Target);

  /// AssignmentAction - This is used by all the assignment diagnostic functions
  /// to represent what is actually causing the operation
  class AssignmentAction {
  public:
    enum Type {
      Assigning,
      Passing,
      Returning,
      Converting,
      Initializing
    };
  private:
    Type ActTy;
    const Decl *D;
  public:

    AssignmentAction(Type Ty)
      : ActTy(Ty), D(nullptr) {}
    AssignmentAction(Type Ty, const Decl *d)
      : ActTy(Ty), D(d) {}

    Type getType() const  {
      return ActTy;
    }
    const Decl *getDecl() const {
      return D;
    }
  };

  /// AssignConvertType - All of the 'assignment' semantic checks return this
  /// enum to indicate whether the assignment was allowed. These checks are
  /// done for simple assignments, as well as initialization, return from
  /// function, argument passing, etc. The query is phrased in terms of a
  /// source and destination type.
  enum AssignConvertType {
    /// Compatible - the types are compatible according to the standard.
    Compatible,

    /// Incompatible - We reject this conversion outright, it is invalid to
    /// represent it in the AST.
    Incompatible,

    /// IncompatibleDimensions - We reject this conversion outright because
    /// of array dimension incompability, it is invalid to
    /// represent it in the AST.
    IncompatibleDimensions
  };

  /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the
  /// assignment conversion type specified by ConvTy. This returns true if the
  /// conversion was invalid or false if the conversion was accepted.
  bool DiagnoseAssignmentResult(AssignConvertType ConvTy,
                                SourceLocation Loc,
                                QualType DstType, QualType SrcType,
                                const Expr *SrcExpr, AssignmentAction Action,
                                const Expr *DstExpr = nullptr);

  ExprResult
  CheckAndApplyAssignmentConstraints(SourceLocation Loc, QualType LHSType,
                                     Expr *RHS,
                                     AssignmentAction AAction,
                                     const Expr *LHS = nullptr);


  // Format
  StmtResult ActOnFORMAT(ASTContext &C, SourceLocation Loc,
                         FormatItemResult Items,
                         FormatItemResult UnlimitedItems,
                         Expr *StmtLabel, bool IsInline = false);

  FormatItemResult ActOnFORMATIntegerDataEditDesc(ASTContext &C, SourceLocation Loc,
                                                  tok::TokenKind Kind,
                                                  IntegerConstantExpr *RepeatCount,
                                                  IntegerConstantExpr *W,
                                                  IntegerConstantExpr *M);

  FormatItemResult ActOnFORMATRealDataEditDesc(ASTContext &C, SourceLocation Loc,
                                               tok::TokenKind Kind,
                                               IntegerConstantExpr *RepeatCount,
                                               IntegerConstantExpr *W,
                                               IntegerConstantExpr *D,
                                               IntegerConstantExpr *E);

  FormatItemResult ActOnFORMATLogicalDataEditDesc(ASTContext &C, SourceLocation Loc,
                                                  tok::TokenKind Kind,
                                                  IntegerConstantExpr *RepeatCount,
                                                  IntegerConstantExpr *W);

  FormatItemResult ActOnFORMATCharacterDataEditDesc(ASTContext &C, SourceLocation Loc,
                                                    tok::TokenKind Kind,
                                                    IntegerConstantExpr *RepeatCount,
                                                    IntegerConstantExpr *W);

  FormatItemResult ActOnFORMATPositionEditDesc(ASTContext &C, SourceLocation Loc,
                                               tok::TokenKind Kind,
                                               IntegerConstantExpr *N);

  FormatItemResult ActOnFORMATControlEditDesc(ASTContext &C, SourceLocation Loc,
                                              tok::TokenKind Kind);

  FormatItemResult ActOnFORMATCharacterStringDesc(ASTContext &C, SourceLocation Loc,
                                                  ExprResult E);

  FormatItemResult ActOnFORMATFormatItemList(ASTContext &C, SourceLocation Loc,
                                             IntegerConstantExpr *RepeatCount,
                                             ArrayRef<FormatItem*> Items);

  /// Returns true if the declaration with the given name is valid.
  bool CheckDeclaration(const IdentifierInfo *IDInfo, SourceLocation IDLoc);

  void DiagnoseRedefinition(SourceLocation Loc, const IdentifierInfo *IDInfo,
                            Decl *Prev);

  /// Returns evaluated integer,
  /// or an ErrorValue if the expression couldn't
  /// be evaluated.
  int64_t EvalAndCheckIntExpr(const Expr *E,
                              int64_t ErrorValue);

  /// Checks if an evaluated integer greater than 0.
  /// Returns EvalResult if EvalResult > 0, or the error
  /// value if EvalResult <= 0
  int64_t CheckIntGT0(const Expr *E, int64_t EvalResult, int64_t ErrorValue = 1);

  /// Returns evaluated kind specification for the builtin types.
  BuiltinType::TypeKind EvalAndCheckTypeKind(QualType T,
                                             const Expr *E);

  QualType ApplyTypeKind(QualType T, const Expr *E);

  /// Returns evaluated length specification
  /// fot the character type.
  uint64_t EvalAndCheckCharacterLength(const Expr *E);

  /// Returns true if an expression is constant(i.e. evaluatable)
  bool CheckConstantExpression(const Expr *E);

  /// Returns true if an expression is a real or integer constant expression.
  bool CheckIntegerOrRealConstantExpression(const Expr *E);

  /// Returns true if an expression is dependent on a
  /// function argument. Does integer typechecking and
  /// reports argument type errors.
  bool CheckArgumentDependentEvaluatableIntegerExpression(Expr *E);

  /// Returns true if an expression is constant
  bool StatementRequiresConstantExpression(SourceLocation Loc, const Expr *E);

  /// Returns true if an expression is an integer expression
  bool CheckIntegerExpression(const Expr *E);

  /// Returns true if an expression is an integer expression
  bool StmtRequiresIntegerExpression(SourceLocation Loc, const Expr *E);

  /// Returns true if an expression is a scalar numeric expression
  bool CheckScalarNumericExpression(const Expr *E);

  /// Returns true if a variable reference points to an integer
  /// variable
  bool StmtRequiresIntegerVar(SourceLocation Loc, const VarExpr *E);

  /// Returns true if a variable reference points to an integer
  /// or a real variable
  bool StmtRequiresScalarNumericVar(SourceLocation Loc, const VarExpr *E, unsigned DiagId);

  /// Returns true if an expression is a logical expression
  bool CheckLogicalExpression(const Expr *E);

  /// Returns true if an expression is a logical expression
  bool StmtRequiresLogicalExpression(SourceLocation Loc, const Expr *E);

  /// Returns true if an expression is a logical array expression
  bool StmtRequiresLogicalArrayExpression(SourceLocation Loc, const Expr *E);

  /// Returns true if an expression is an integer, logical or a character expression.
  bool StmtRequiresIntegerOrLogicalOrCharacterExpression(SourceLocation Loc, const Expr *E);

  /// Returns true if an expression is a character expression
  bool CheckCharacterExpression(const Expr *E);

  /// Returns true if two types have the same type class
  /// and kind.
  bool AreTypesOfSameKind(QualType A, QualType B) const;

  /// Returns true if two types have the same type class
  /// and kind.
  bool CheckTypesOfSameKind(QualType A, QualType B,
                            const Expr *E) const;

  /// Returns true if the given Type is a scalar(integer,
  /// real, complex) or character
  bool CheckTypeScalarOrCharacter(const Expr *E, QualType T,
                                  bool IsConstant = false);

  /// Typechecks the expression - the following rules are correct:
  /// if the expected type is integer and expression is integer(any kind)
  /// if the expected type is logical and expression is logical(any kind)
  /// if the expected type is character and expression is character(same kind)
  Expr *TypecheckExprIntegerOrLogicalOrSameCharacter(Expr *E,
                                                     QualType ExpectedType);

  /// Returns true if the type is of default kind,
  /// or is a double precision type
  bool IsDefaultBuiltinOrDoublePrecisionType(QualType T);

  /// Returns true if the expession's type is of default kind,
  /// or is a double precision type
  bool CheckDefaultBuiltinOrDoublePrecisionExpression(const Expr *E);

  /// Checks that all of the expressions have the same type
  /// class and kind.
  void CheckExpressionListSameTypeKind(ArrayRef<Expr*> Expressions, bool AllowArrays = false);

  /// Returns true if the argument count doesn't match to the function
  /// count
  bool CheckIntrinsicCallArgumentCount(intrinsic::FunctionKind Function,
                                       ArrayRef<Expr*> Args, SourceLocation Loc);

  /// Returns false if the call to a function from a conversion group
  /// is valid.
  bool CheckIntrinsicConversionFunc(intrinsic::FunctionKind Function,
                                    ArrayRef<Expr*> Args,
                                    QualType &ReturnType);

  /// Returns false if the call to a function from the truncation group
  /// is valid.
  bool CheckIntrinsicTruncationFunc(intrinsic::FunctionKind Function,
                                    ArrayRef<Expr*> Args,
                                    QualType &ReturnType);

  /// Returns false if the call to a function from the complex group
  /// is valid.
  bool CheckIntrinsicComplexFunc(intrinsic::FunctionKind Function,
                                 ArrayRef<Expr*> Args,
                                 QualType &ReturnType);

  /// Returns false if the call to a function from the maths group
  /// is valid.
  bool CheckIntrinsicMathsFunc(intrinsic::FunctionKind Function,
                               ArrayRef<Expr*> Args,
                               QualType &ReturnType);

  /// Returns false if the call to a function from the character group
  /// is valid.
  bool CheckIntrinsicCharacterFunc(intrinsic::FunctionKind Function,
                                   ArrayRef<Expr*> Args,
                                   QualType &ReturnType);

  /// Returns false if the call to a function from the array group
  /// is valid.
  bool CheckIntrinsicArrayFunc(intrinsic::FunctionKind Function,
                               ArrayRef<Expr*> Args,
                               QualType &ReturnType);

  /// Returns false if the call to a function from the numeric inquiry group
  /// is valid.
  bool CheckIntrinsicNumericInquiryFunc(intrinsic::FunctionKind Function,
                                        ArrayRef<Expr*> Args,
                                        QualType &ReturnType);

  /// Returns false if the call to a function from the system group
  /// is valid.
  bool CheckIntrinsicSystemFunc(intrinsic::FunctionKind Function,
                                ArrayRef<Expr*> Args,
                                QualType &ReturnType);

  /// Returns false if the call to a function from the inquiry group
  /// is valid.
  bool CheckIntrinsicInquiryFunc(intrinsic::FunctionKind Function,
                                 ArrayRef<Expr*> Args,
                                 QualType &ReturnType);

  /// Returns false if the call to a function from the
  /// bit operations group is valid.
  bool CheckIntrinsicBitFunc(intrinsic::FunctionKind Function,
                             ArrayRef<Expr*> Args,
                             QualType &ReturnType);

  /// Reports an incompatible argument error and returns true.
  bool DiagnoseIncompatiblePassing(const Expr *E, QualType T,
                                   bool AllowArrays,
                                   StringRef ArgName = StringRef());
  bool DiagnoseIncompatiblePassing(const Expr *E, StringRef T,
                                   bool AllowArrays,
                                   StringRef ArgName = StringRef());

  bool CheckArgumentsTypeCompability(const Expr *E1, const Expr *E2,
                                     StringRef ArgName1, StringRef ArgName2,
                                     bool AllowArrays = false);

  /// Returns false if the argument's type is built in.
  bool CheckBuiltinTypeArgument(const Expr *E, bool AllowArrays = false);

  /// Returns false if the argument's type is integer.
  bool CheckIntegerArgument(const Expr *E, bool AllowArrays = false,
                            StringRef ArgName = StringRef());

  /// Returns false if the argument's type is real.
  bool CheckRealArgument(const Expr *E, bool AllowArrays = false);

  /// Returns false if the argument's type is complex.
  bool CheckComplexArgument(const Expr *E, bool AllowArrays = false);

  /// Returns false if the argument's type is real but isn't double precision.
  bool CheckStrictlyRealArgument(const Expr *E, bool AllowArrays = false);

  /// Returns false if the argument's type is real array.
  bool CheckStrictlyRealArrayArgument(const Expr *E, StringRef ArgName);

  /// Returns false if the argument's type is real and is double precision.
  bool CheckDoublePrecisionRealArgument(const Expr *E, bool AllowArrays = false);

  /// Returns false if the argument's type is complex and is double complex.
  bool CheckDoubleComplexArgument(const Expr *E, bool AllowArrays = false);

  /// Returns false if the argument's type is character.
  bool CheckCharacterArgument(const Expr *E);

  /// Returns false if the argument has an integer or a real type.
  bool CheckIntegerOrRealArgument(const Expr *E, bool AllowArrays = false);

  /// Returns false if the argument has an integer or a real array type.
  bool CheckIntegerOrRealArrayArgument(const Expr *E, StringRef ArgName);

  /// Returns false if the argument has an integer or a real or
  /// a complex argument.
  bool CheckIntegerOrRealOrComplexArgument(const Expr *E, bool AllowArrays = false);

  /// Returns false if the argument has a real or
  /// a complex argument.
  bool CheckRealOrComplexArgument(const Expr *E, bool AllowArrays = false);

  /// Returns true if the given expression is a logical array.
  bool IsLogicalArray(const Expr *E);

  /// Returns false if the argument has a logical array type.
  bool CheckLogicalArrayArgument(const Expr *E, StringRef ArgName);

  /// Returns false if the argument is an integer or a logical array.
  bool CheckIntegerArgumentOrLogicalArrayArgument(const Expr *E, StringRef ArgName1,
                                                  StringRef ArgName2);

  /// Returns false if the array argument is compatible with a given array type.
  bool CheckArrayArgumentDimensionCompability(const Expr *E, const ArrayType *AT,
                                              StringRef ArgName);

  /// Returns false if the two array arguments are compatible with each other
  bool CheckArrayArgumentsDimensionCompability(const Expr *E1, const Expr *E2,
                                               StringRef ArgName1, StringRef ArgName2);

  bool IsValidFunctionType(QualType Type);

  /// Sets a type for a function
  void SetFunctionType(FunctionDecl *Function, QualType Type,
                       SourceLocation DiagLoc, SourceRange DiagRange);

  /// Returns true if the call expression has the correct arguments.
  bool CheckCallArguments(FunctionDecl *Function, llvm::MutableArrayRef<Expr *> Arguments,
                          SourceLocation Loc, SourceLocation IDLoc);

  /// Returns an array that is passed to a function, with optional implcit operations.
  Expr *ActOnArrayArgument(VarDecl *Arg, Expr *E);

  /// Returns true if an array expression needs a temporary storage array.
  bool ArrayExprNeedsTemp(const Expr *E);

  /// Returns true if the array shape bound is valid
  bool CheckArrayBoundValue(Expr *E);

  /// Returns true if the given array type can be applied to a declaration.
  bool CheckArrayTypeDeclarationCompability(const ArrayType *T, VarDecl *VD);

  /// Returns true if the given character length can be applied to a declaration.
  bool CheckCharacterLengthDeclarationCompability(QualType T, VarDecl *VD);

  /// Returns true if the subscript expression has the
  /// right amount of dimensions.
  bool CheckSubscriptExprDimensionCount(SourceLocation Loc, SourceLocation RParenLoc,
                                        Expr *Target,
                                        ArrayRef<Expr *> Arguments);

  /// Returns true if the items in the array constructor
  /// satisfy all the constraints.
  /// As a bonus it also returns the Element type in ObtainedElementType.
  bool CheckArrayConstructorItems(ArrayRef<Expr*> Items,
                                  QualType &ResultingArrayType);


  /// Returns true if an array doesn't
  /// have an implied shape dimension specifier.
  bool CheckArrayNoImpliedDimension(const ArrayType *T,
                                    SourceRange Range);

  /// Returns true if an array expression is usable for a unary expression.
  bool CheckArrayExpr(const Expr *E);

  /// Returns true if the two array types are compatible with
  /// one another, i.e. they have the same dimension count
  /// and the shapes of the dimensions are identical
  bool CheckArrayDimensionsCompability(const ArrayType *LHS,
                                       const ArrayType *RHS, SourceLocation Loc,
                                       SourceRange LHSRange, SourceRange RHSRange);

  /// Returns true if the variable can be assigned to (mutated)
  bool CheckVarIsAssignable(const VarExpr *E);

  /// Returns true if a statement is a valid do terminator
  bool IsValidDoTerminatingStatement(const Stmt *S);

  /// Reports an unterminated construct such as do, if, etc.
  void ReportUnterminatedStmt(const BlockStmtBuilder::Entry &S,
                              SourceLocation Loc,
                              bool ReportUnterminatedLabeledDo = true);

  /// Leaves the last block construct, and performs any clean up
  /// that might be needed.
  void LeaveLastBlock();

  /// Leaves the block constructs until the given construct is reached.
  void LeaveUnterminatedBlocksUntil(SourceLocation Loc, Stmt *S);

  /// Leaves block constructs until a do construct is reached.
  /// NB: the do statements with a termination label such as DO 100 I = ..
  /// are popped.
  Stmt *LeaveBlocksUntilDo(SourceLocation Loc);

  /// Returns true if the current statement is inside a do construct which
  /// is terminated by the given statement label.
  bool IsInLabeledDo(const Expr *StmtLabel);

  /// Leaves block constructs until a label termination do construct is reached.
  DoStmt *LeaveBlocksUntilLabeledDo(SourceLocation Loc, const Expr *StmtLabel);

  /// Leaves block constructs until an if construct is reached.
  IfStmt *LeaveBlocksUntilIf(SourceLocation Loc);

  /// Leaves block constructs until a select case construct is reached.
  SelectCaseStmt *LeaveBlocksUntilSelectCase(SourceLocation Loc);

  /// Leaves block constructs until a where construct is reached.
  WhereStmt *LeaveBlocksUntilWhere(SourceLocation Loc);

  /// Returns the amount of where constructs that were entered.
  int CountWhereConstructs();

  /// Checks to see if the part of the constructs has a valid construct name.
  void CheckConstructNameMatch(Stmt *Part, ConstructName Name, Stmt *S);

  /// Checks to see if a statement is inside an outer loop or a loop
  /// associated with a given name, and returns this loop. Null
  /// is returned when an error occurs.
  Stmt *CheckWithinLoopRange(const char *StmtString, SourceLocation Loc, ConstructName Name);

  /// Returns true if we are inside a where construct.
  bool InsideWhereConstruct(Stmt *S);

  /// Returns true if the given statement can be part of a where construct.
  bool CheckValidWhereStmtPart(Stmt *S);

  /// Returns true if the current function/subroutine is recursive.
  bool CheckRecursiveFunction(SourceLocation Loc);

  /// Returns a vector of elements with a given size.
  QualType GetSingleDimArrayType(QualType ElTy, int Size);

};

} // end flang namespace

#endif