Commit graph

19 commits

Author SHA1 Message Date
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
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
Tim Keith
0c575ed548 [flang] Implement writing of .mod files.
Module file writing is implemented in mod-file.cc. They need to be
written after all semantic checking. Until then, for testing, write
them out whenever names are resolved.

There is a header comment in the .mod files but it is mostly a
placeholder until we can read them in and do something with it.

Rename `Symbol::details<D>` to `Symbol::get<D>`. This asserts that the
details of the symbol match D and returns that type. But we need a way
to access the details as a variant as well (not just one of its types).
`details()` is the best name for that, especially as we already have
`set_details()`. Renaming the old `details` to `get` also better matches
`has` which is used to check which variant is present.

Original-commit: flang-compiler/f18@8d14be1a16
Reviewed-on: https://github.com/flang-compiler/f18/pull/126
Tree-same-pre-rewrite: false
2018-07-16 16:23:18 -07:00
Tim Keith
be886c18ac [flang] Sort enumerators in enum class Attr.
Original-commit: flang-compiler/f18@ce43e4e556
Reviewed-on: https://github.com/flang-compiler/f18/pull/120
2018-07-12 10:14:58 -07:00
Tim Keith
d42bb955a6 [flang] Support intent-stmt and resolve subprogram prefixes and suffixes.
Recognize `IntentStmt` and use `HandleAttributeStmt()` to implement it
as is done with other attribute statements. Add `Attr::INTENT_INOUT` as
a separate attribute for `INTENT(INOUT)`.

Collect attributes from the prefix and suffix of `FunctionStmt` and
`SubroutineStmt` (including `BIND(C)`) and set them on the subprogram
symbol.

Create a test for this using `test_symbol.sh`. It compiles with
`-funparse-with-symbols` and compares the output with the symbols in
comments in the input.

Change `test_errors.sh` to be similar to `test_symbol.sh`: check usage
and allow `F18` environment variable to override the path to the
compiler.

Original-commit: flang-compiler/f18@384828a22f
Reviewed-on: https://github.com/flang-compiler/f18/pull/120
Tree-same-pre-rewrite: false
2018-07-11 17:45:13 -07:00
peter klausler
b23701f7d0 [flang] Rearrange some facilities into a new lib/common.
Original-commit: flang-compiler/f18@279af1e817
Reviewed-on: https://github.com/flang-compiler/f18/pull/106
2018-06-18 11:05:17 -07:00
peter klausler
57f4186ca2 [flang] Address review comments
Original-commit: flang-compiler/f18@d96917c701
Reviewed-on: https://github.com/flang-compiler/f18/pull/101
Tree-same-pre-rewrite: false
2018-06-14 13:53:09 -07:00
Tim Keith
b8ec1fd041 [flang] Run clang-format on all .h and .cc files.
Original-commit: flang-compiler/f18@b7f02808a2
Reviewed-on: https://github.com/flang-compiler/f18/pull/77
2018-05-02 14:06:02 -07:00
Tim Keith
7f66c0ae72 [flang] Normalize namespace definitions.
Replace `namespace Fortran { namespace parser { ... } }` with
`namespace Fortran::parser { ... }` and similarly for semantics.

Original-commit: flang-compiler/f18@838c9539b2
Reviewed-on: https://github.com/flang-compiler/f18/pull/77
Tree-same-pre-rewrite: false
2018-05-02 13:52:36 -07:00
Tim Keith
4008e3e5d7 [flang] Make include guards consistent.
The include guard symbol is `FORTRAN_$dir_$file_H_` where $dir is the
subdirectory of `lib` and $file is the basename of the header file.
Those names are mapped to uppercase and hyphens are replaced by
underscores.

Original-commit: flang-compiler/f18@ac9c0e7106
Reviewed-on: https://github.com/flang-compiler/f18/pull/75
2018-05-01 14:07:52 -07:00
Tim Keith
18cee3e8e6 [flang] Add copyright notices.
For source files (C++, Fortran, CMake) add copyright and license.
For documentation files add just copyright.

Original-commit: flang-compiler/f18@38381aed83
Reviewed-on: https://github.com/flang-compiler/f18/pull/74
2018-05-01 12:50:34 -07:00
Tim Keith
6c772ac40b [flang] Improve include file sorting.
Includes like "../dir/file.h" should sort after local includes.
This change fixes that and applies the new formatting.

Now the order (in reverse) is:
- system includes
- includes from llvm or clang (this is from the default IncludeCategories)
- includes of ../something
- everything else

Original-commit: flang-compiler/f18@324643d63a
Reviewed-on: https://github.com/flang-compiler/f18/pull/52
2018-04-12 12:23:20 -07:00
peter klausler
216999318b [flang] Address review comments.
Original-commit: flang-compiler/f18@66ecc10722
Reviewed-on: https://github.com/flang-compiler/f18/pull/42
2018-04-06 10:34:59 -07:00
peter klausler
91b324ee71 [flang] Generalize semantics/attr.h into enum-set.h, implementing it atop std::bitset.
Original-commit: flang-compiler/f18@d827c8bcc3
Reviewed-on: https://github.com/flang-compiler/f18/pull/42
Tree-same-pre-rewrite: false
2018-04-05 16:49:48 -07:00
Tim Keith
9f755666fb [flang] Add ENUM_CLASS to define enum class with ToString function.
This replaces DEFINE_NESTED_ENUM_CLASS in parse-tree.h but works
similarly. "ENUM_CLASS(Foo, A, B, C)" defined enum class Foo with
enumerators A, B, C. It also defines an overloading of EnumToString
that converts enumerators to their string representation.

Change unparse.cc to adapt to this change.

Make use of ENUM_CLASS in attr.h and attr.cc.

Original-commit: flang-compiler/f18@c45b8f172a
Reviewed-on: https://github.com/flang-compiler/f18/pull/31
2018-03-23 14:41:48 -07:00
Tim Keith
a3de9d789c [flang] Partial implementation of Symbols and Scopes.
A Symbol consists of a common part (in class Symbol) containing name,
owner, attributes. Information for a specific kind of symbol is in a
variant containing one of the *Details classes. So the kind of symbol is
determined by the type of details class stored in the details_ variant.

For scopes there is a single Scope class with an enum indicating the
kind. So far there isn't a need for extra kind-specific details as with
Symbols but that could change. Symbols defined in a Scope are stored
there in a simple map.

resolve-names.cc is a partial implementation of a parse-tree walker that
resolves names to Symbols. Currently is only handles functions (which
introduce a new Scope) and entity-decls. The test-type executable was
reused as a driver for this to avoid the need for a new one.

Sample output is below. When each "end function" is encountered the
scope is dumped, which shows the symbols defined in it.

$ cat a.f90
pure integer(8) function foo(arg1, arg2) result(res)
  integer :: arg1
  real :: arg2
contains
  function bar(arg1)
    real :: bar
    real :: arg1
  end function
end function

$ Debug/tools/f18/test-type a.f90
Subprogram scope: 0 children
  arg1:  Entity type: REAL
  bar:  Entity type: REAL
Subprogram scope: 1 children
  arg1:  Entity type: INTEGER
  arg2:  Entity type: REAL
  bar:  Subprogram (arg1)
  foo:  Subprogram (arg1, arg2) result(res)
  res:  Entity type: INTEGER(8)

Original-commit: flang-compiler/f18@1cd2fbc04d
Reviewed-on: https://github.com/flang-compiler/f18/pull/30
Tree-same-pre-rewrite: false
2018-03-22 17:25:34 -07:00
Tim Keith
4a735b61c6 [flang] Rename methods with uppercase names.
Original-commit: flang-compiler/f18@00fec54e5a
Reviewed-on: https://github.com/flang-compiler/f18/pull/8
2018-02-15 08:27:19 -08:00
Tim Keith
6c168650b7 [flang] Add Attrs class to represent set of Attr
Original-commit: flang-compiler/f18@8bb1f0eb9b
Reviewed-on: https://github.com/flang-compiler/f18/pull/8
Tree-same-pre-rewrite: false
2018-02-14 15:07:59 -08:00
Tim Keith
e065e5b510 [flang] Move type.{h,cc} and attr.{h,cc}
The are now in new namespace and directory, "semantics", similar to
"parser".

Original-commit: flang-compiler/f18@115a1341e2
Reviewed-on: https://github.com/flang-compiler/f18/pull/5
2018-02-07 15:54:07 -08:00
Renamed from flang/attr.h (Browse further)