Commit graph

22 commits

Author SHA1 Message Date
Tim Keith
3e8c62b48b [flang] Track current statement location in SemanticsVisitor
Change `SemanticsVisitor` to track the location of the current
statement, if any, so that it's available through
`SemanticsContext::location()`

Add overloading of `SemanticsContext::Say()` that reports the
message at the location of the current statement if a `CharBlock`
is not provided.

Original-commit: flang-compiler/f18@5185c721ee
Reviewed-on: https://github.com/flang-compiler/f18/pull/357
2019-03-26 12:40:13 -07:00
Steve Scalpone
3d892d56e9 [flang] Remove the IF specific context classes; in these cases they
added no value. Change several error messages to better say
what is expected.  Adjust tests for new messages.  Reformat
with llvm7 clang-format.

Original-commit: flang-compiler/f18@706b506e26
Reviewed-on: https://github.com/flang-compiler/f18/pull/356
Tree-same-pre-rewrite: false
2019-03-26 18:03:33 -07:00
Tim Keith
3ec5e102e2 [flang] Name resolution for defined operators
Instead of tracking just genericName_ while in a generic interface
block or generic statement, now we immediately create a symbol for it.
A parser::Name isn't good enough because a defined-operator or
defined-io-generic-spec doesn't have a name.

Change the parse tree to add a source field to GenericSpec. Use these
as names for symbols for defined-operator and defined-io-generic-spec
(e.g. "operator(+)" or "read(formatted)").

Change the source for defined-op-name to include the dots so that they
can be distinguished from normal symbols with the same name (e.g. you
can have both ".foo." and "foo"). These symbols have names in the symbol
table like ".foo.", not "operator(.foo.)", because references to them
have that form.

Add GenericKind enum to GenericDetails and GenericBindingDetails.
This allows us to know a symbol is "assignment(=)", for example,
without having to do a string comparison.

Add GenericSpecInfo to handle analyzing the various kinds of
generic-spec and generating symbol names and GenericKind for them.

Add reference to LanguageFeatureControl to SemanticsContext so that
they can be checked during semantics. For this change, if
LogicalAbbreviations is enabled, report an error if the user tries
to define an operator named ".T." or ".F.".

Add resolve-name-utils.cc to hold utility functions and classes that
don't have to be in the ResolveNamesVisitor class hierarchy. The goal
is to reduce the size of resolve-names.cc where possible.

Original-commit: flang-compiler/f18@3081f694e2
Reviewed-on: https://github.com/flang-compiler/f18/pull/338
2019-03-18 11:48:02 -07:00
Tim Keith
f85ac283c5 [flang] Move ExprChecker into separate pass
DoConcurrentChecker depends on expressions being fully resolved so it
can't be in the same pass as ExprChecker. The same will probably
apply to AssignmentChecker when its finished.

Checks that don't depend on expressions can go in the first pass
with ExprChecker.

Original-commit: flang-compiler/f18@c0785ec06f
Reviewed-on: https://github.com/flang-compiler/f18/pull/315
2019-03-06 14:15:13 -08:00
Tim Keith
813e48dc21 [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@3a222c3673
Reviewed-on: https://github.com/flang-compiler/f18/pull/315
Tree-same-pre-rewrite: false
2019-03-05 16:52:50 -08:00
peter klausler
8a57433273 [flang] C1594 constraint checking on pointer components in struct constructors
Original-commit: flang-compiler/f18@386cd8a9b4
Reviewed-on: https://github.com/flang-compiler/f18/pull/311
Tree-same-pre-rewrite: false
2019-03-04 16:30:24 -08:00
peter klausler
4417443be9 [flang] Fix CHECK() on wa22 by implementing PGI language extension
Original-commit: flang-compiler/f18@03fcb58977
Reviewed-on: https://github.com/flang-compiler/f18/pull/287
Tree-same-pre-rewrite: false
2019-02-15 12:29:10 -08:00
peter klausler
0ae3d43d76 [flang] Run expression semantic analysis with rest of semantics.
checkpoint array constructor semantics work

checkpoint

array constructors of lengthless intrinsic types

checkpoint

Correct ambiguous substring refs misparsed as array elements

Original-commit: flang-compiler/f18@2232549efe
Reviewed-on: https://github.com/flang-compiler/f18/pull/271
Tree-same-pre-rewrite: false
2019-01-31 09:59:28 -08:00
peter klausler
f9d6c0a338 [flang] Move default intrinsic type kinds from lib/semantics to lib/common
Original-commit: flang-compiler/f18@887e72dd61
Reviewed-on: https://github.com/flang-compiler/f18/pull/265
Tree-same-pre-rewrite: false
2019-01-22 16:31:18 -08:00
Tim Keith
ee28b70827 [flang] Resolve names in ASSOCIATE and SELECT TYPE
Create `AssocEntityDetails` for symbols that represent entities
identified by the associate-name in ASSOCIATE and SELECT TYPE
constructs.

For ASSOCIATE, create a new scope for the associated entity.
For SELECT TYPE, create a new scope for each of type guard blocks.
Each one contains an associated entity with the appropriate type.

For SELECT TYPE, also create a place-holder symbol for the
associate-name in the SELECT TYPE statement. The real symbols
are in the new scopes and none of them is uniquely identified
with the associate-name.

Handling of `Selector` is common between these, with
`associate-name => expr | variable` recorded in
`ConstructVisitor::association_`.

When the selector is an expression, derive the type of the associated
entity from the type of the expression. This required some refactoring
of how `DeclTypeSpec`s are created. The `DerivedTypeSpec` that comes
from and expression is const so we can only create const `DeclTypeSpec`s
from it. But there were times during name resolution when we needed to
set type parameters in the current `DeclTypeSpec`. Now the non-const
`DerivedTypeSpec` is saved separately from the const `DeclTypeSpec`
while we are processing a declaration type spec. This makes it
unnecessary to save the derived type name.

Add a type alias for `common::Indirection` to reduce verbosity.

Original-commit: flang-compiler/f18@b7668cebe4
Reviewed-on: https://github.com/flang-compiler/f18/pull/261
Tree-same-pre-rewrite: false
2019-01-15 16:59:20 -08:00
Tim Keith
b8b53ba2f4 [flang] Refactoring: improve some names
IntrinsicTypeSpec was used for all intrinsics except for character.
Change it to be a common base class for NumericTypeSpec,
LogicalTypeSpec, and CharacterTypeSpec.

Change DeclTypeSpec to categorize the intrinsics as Numeric, Logical,
and Character. Add some utility methods: AsIntrinsic() and IsNumeric().

In scope.h, give the functions that create DeclTypeSpecs better names.

In semantics.h, replace MakeIntrinsicTypeSpec() with MakeNumericType()
and MakeLogicalType() as it does not apply to character types.

Original-commit: flang-compiler/f18@8ad92d069c
Reviewed-on: https://github.com/flang-compiler/f18/pull/247
Tree-same-pre-rewrite: false
2018-12-17 12:41:43 -08:00
Tim Keith
396b3fde60 [flang] Rework how DeclTypeSpecs are stored
Now DeclTypeSpecs are stored in the scope so that they remain available
as long as the scope exists. DeclTypeSpecs for intrinsic types are
stored in the global scope; those for derived types are in the current
scope. They can contains type parameter values so they can't be reused.

Add `Semantics::MakeIntrinsicTypeSpec` to simplify creating
DeclTypeSpecs for intrinsic types.

Replace `std::optional<DeclTypeSpec>` with `DeclTypeSpec *` as they do
not need to be copied around.

Also fix a small bug with writing `class(t(...))` to the module file --
the type parameters were missing.

Original-commit: flang-compiler/f18@e4744418fc
Reviewed-on: https://github.com/flang-compiler/f18/pull/247
Tree-same-pre-rewrite: false
2018-12-14 07:17:12 -08:00
peter klausler
659c32947c [flang] checkpoint during refactor
Original-commit: flang-compiler/f18@01fe82b95b
Reviewed-on: https://github.com/flang-compiler/f18/pull/234
Tree-same-pre-rewrite: false
2018-11-30 14:03:05 -08:00
Tim Keith
cef802b1b4 [flang] Add mapping of source location to Scope
Each Scope now tracks the source locations that it and its nested scopes
span. This is achieved by extending the source range of a scope for each
statement encountered while it is the current scope.

Semantics::FindScope maps a source location (from the cooked character
stream) to the narrowest scope that contains it.

Original-commit: flang-compiler/f18@7b4d2bb113
Reviewed-on: https://github.com/flang-compiler/f18/pull/230
Tree-same-pre-rewrite: false
2018-11-28 15:55:55 -08:00
Jean Perier
f7e7cb349b [flang] Changed .clang-format so that it will not add a comment after the closing brace of each namespace. Removed all such previous comments from all .cc and .h files
Original-commit: flang-compiler/f18@aa7f55e15f
Reviewed-on: https://github.com/flang-compiler/f18/pull/217
2018-10-25 05:55:23 -07:00
Tim Keith
30dd289247 [flang] Add FoldingContext to SemanticsContext
FoldingContext is now part of SemanticsContext. It is created at the
beginning with a default-constructed CharBlock as the location in its
ContextualMessages.

Add PushLocation() to ContextualMessages to remember the previous source
location and set a new one. The old one is restored when the returned
object goes out of scope.

SemanticsContext is now the only state passed in to class ExprAnalyzer,
class Mutator, AnalyzeExpr(), AnalyzeExpressions().

Add Say() convenience functions for reporting errors to ExprAnalyzer.

Original-commit: flang-compiler/f18@70c499ffc4
Reviewed-on: https://github.com/flang-compiler/f18/pull/215
Tree-same-pre-rewrite: false
2018-10-22 16:41:26 -07:00
Tim Keith
16980c718a [flang] Refactoring: add SemanticsContext class
The new SemanticsContext holds the state of semantics whose lifetime
spans all of the compilations. It contains the scope tree (and so all
symbols), the intrinsics table, messages, and the state of options that
affect semantics (default kinds, search directories, etc.)

Original-commit: flang-compiler/f18@f04ceab81f
Reviewed-on: https://github.com/flang-compiler/f18/pull/215
Tree-same-pre-rewrite: false
2018-10-22 07:37:38 -07:00
peter klausler
7c402d9c50 [flang] Add -i8, -r8, &c. options to f18 development driver
Original-commit: flang-compiler/f18@ff7f338126
Reviewed-on: https://github.com/flang-compiler/f18/pull/213
2018-10-16 14:42:22 -07:00
peter klausler
d2f36b9d76 [flang] Eliminating old default type declarations
Original-commit: flang-compiler/f18@10e4a3385a
Reviewed-on: https://github.com/flang-compiler/f18/pull/213
Tree-same-pre-rewrite: false
2018-10-15 17:11:24 -07:00
peter klausler
7b141b62df [flang] Resolve g++ 7.2 build problem
Original-commit: flang-compiler/f18@09859b2e9c
Reviewed-on: https://github.com/flang-compiler/f18/pull/197
2018-10-01 14:36:31 -07:00
Tim Keith
64ed507b36 [flang] Initialize directories_ directly rather than with setter.
Original-commit: flang-compiler/f18@a9a6fc688b
Reviewed-on: https://github.com/flang-compiler/f18/pull/186
Tree-same-pre-rewrite: false
2018-09-14 16:21:37 -07:00
Tim Keith
7edb7ec69b [flang] Add top-level Semantics class
Refactor to create the Semantics class that is responsible for holding
state during semantics (the scope tree and messages) and managing the
logic of the various phases of semantic processing. Eliminate static
Scope::globalScope.

The messages generated during semantic processing are accumulated in a
Messages data member of Semantics so that individual phases don't need
to emit them to std::cerr. This is now done by the driver so that it has
control over where they go and eliminates other includes of iostream.
To do this, the messages object is passed in to the various semantics
operations.

Move DumpSymbols into semantics.cc: it doesn't belong in resolve-names.cc
and it depends on the global scope, so it's as good a place as any.
The call to RewriteParseTree is also moved to Semantics.

Original-commit: flang-compiler/f18@771d0e1293
Reviewed-on: https://github.com/flang-compiler/f18/pull/186
Tree-same-pre-rewrite: false
2018-09-14 15:04:50 -07:00