[flang] Create framework for checking statement semantics
authorTim Keith <tkeith@nvidia.com>
Wed, 6 Mar 2019 00:52:50 +0000 (16:52 -0800)
committerTim Keith <tkeith@nvidia.com>
Wed, 6 Mar 2019 00:52:50 +0000 (16:52 -0800)
commit813e48dc2165f11d3e1f4e1b39b44fa687496092
treede7abb8178c75cdd38970dab6fa83f99afa518b1
parent18329e25243063e620ee32ba97605f335e0fec61
[flang] Create framework for checking statement semantics

Add `SemanticsVisitor` as the visitor class to perform statement
semantics checks. Its template parameters are "checker" classes
that perform the checks. They have `Enter` and `Leave` functions
that are called for the corresponding parse tree nodes (`Enter`
before the children, `Leave` after). Unlike `Pre` and `Post` in
visitors they cannot prevent the parse tree walker from visiting
child nodes.

Existing checks have been incorporated into this framework:
- `ExprChecker` replaces `AnalyzeExpressions()`
- `AssignmentChecker` replaces `AnalyzeAssignments()`
- `DoConcurrentChecker` replaces `CheckDoConcurrentConstraints()`

Adding a new checker requires:
- defining the checker class:
  - with BaseChecker as virtual base class
  - constructible from `SemanticsContext`
  - with Enter/Leave functions for nodes of interest
- add the checker class to the template parameters of `StatementSemantics`

Because these checkers and also `ResolveNamesVisitor` require tracking
the current statement source location, that has been moved into
`SemanticsContext`. `ResolveNamesVisitor` and `SemanticsVisitor`
update the location when `Statement` nodes are encountered, making it
available for error messages.

`AnalyzeKindSelector()` now has access to the current statement through
the context and so no longer needs to have it passed in.

Test `assign01.f90` was added to verify that `AssignmentChecker` is
actually doing something.

Original-commit: flang-compiler/f18@3a222c36731029fabf026e5301dc60f0587595be
Reviewed-on: https://github.com/flang-compiler/f18/pull/315
Tree-same-pre-rewrite: false
flang/lib/semantics/assignment.cc
flang/lib/semantics/assignment.h
flang/lib/semantics/check-do-concurrent.cc
flang/lib/semantics/check-do-concurrent.h
flang/lib/semantics/expression.cc
flang/lib/semantics/expression.h
flang/lib/semantics/resolve-names.cc
flang/lib/semantics/semantics.cc
flang/lib/semantics/semantics.h