From 509436cab1e809af6297bd15469e5077a17c379b Mon Sep 17 00:00:00 2001 From: peter klausler Date: Mon, 4 Feb 2019 12:24:25 -0800 Subject: [PATCH] [flang] begin work on structure constructors Original-commit: flang-compiler/f18@7131a2f91d8bfeed4d675be1db53b52e99acc83f Reviewed-on: https://github.com/flang-compiler/f18/pull/287 Tree-same-pre-rewrite: false --- flang/lib/semantics/resolve-names.cc | 22 +++++++++++++++++++++- flang/lib/semantics/symbol.cc | 6 +++--- flang/lib/semantics/symbol.h | 20 +++++++++++++------- flang/lib/semantics/type.cc | 3 ++- 4 files changed, 39 insertions(+), 12 deletions(-) diff --git a/flang/lib/semantics/resolve-names.cc b/flang/lib/semantics/resolve-names.cc index 685aac5..3f2ec42 100644 --- a/flang/lib/semantics/resolve-names.cc +++ b/flang/lib/semantics/resolve-names.cc @@ -3057,9 +3057,29 @@ bool DeclarationVisitor::Pre(const parser::StructureConstructor &x) { auto savedState{SetDeclTypeSpecState({})}; BeginDeclTypeSpec(); Walk(std::get(x.t)); - Walk(std::get>(x.t)); + const DeclTypeSpec *type{GetDeclTypeSpec()}; EndDeclTypeSpec(); SetDeclTypeSpecState(savedState); + bool anyKeyword{false}; + for (const auto &component : + std::get>(x.t)) { + Walk(component); + Symbol *symbol{nullptr}; + const parser::Expr &value{ + *std::get(component.t).v}; + if (const auto &kw{std::get>(component.t)}) { + symbol = kw->v.symbol; + anyKeyword = true; + } else if (anyKeyword) { + Say(value.source, + "Component value lacks a required component name"_err_en_US); + } else { + // TODO: keyword = next component in component order + } + MaybeExpr expr{EvaluateExpr(value)}; + if (type != nullptr && symbol != nullptr && expr.has_value()) { + } + } return false; } diff --git a/flang/lib/semantics/symbol.cc b/flang/lib/semantics/symbol.cc index 5f7ded7a..a38c039 100644 --- a/flang/lib/semantics/symbol.cc +++ b/flang/lib/semantics/symbol.cc @@ -616,15 +616,15 @@ std::list DerivedTypeDetails::OrderParameterNames( return result; } -std::list DerivedTypeDetails::OrderParameterDeclarations( +std::list DerivedTypeDetails::OrderParameterDeclarations( const Symbol &type) const { - std::list result; + std::list result; if (const DerivedTypeSpec * spec{type.GetParentTypeSpec()}) { const DerivedTypeDetails &details{ spec->typeSymbol().get()}; result = details.OrderParameterDeclarations(spec->typeSymbol()); } - for (Symbol *symbol : paramDecls_) { + for (const Symbol *symbol : paramDecls_) { result.push_back(symbol); } return result; diff --git a/flang/lib/semantics/symbol.h b/flang/lib/semantics/symbol.h index c94a83d..0623134 100644 --- a/flang/lib/semantics/symbol.h +++ b/flang/lib/semantics/symbol.h @@ -194,11 +194,13 @@ private: class DerivedTypeDetails { public: const std::list ¶mNames() const { return paramNames_; } - const std::list ¶mDecls() const { return paramDecls_; } + const std::list ¶mDecls() const { return paramDecls_; } SourceName extends() const { return extends_; } bool sequence() const { return sequence_; } void add_paramName(const SourceName &name) { paramNames_.emplace_back(name); } - void add_paramDecl(Symbol &symbol) { paramDecls_.emplace_back(&symbol); } + void add_paramDecl(const Symbol &symbol) { + paramDecls_.emplace_back(&symbol); + } void set_extends(const SourceName &name) { extends_ = name; } void set_sequence(bool x = true) { sequence_ = x; } @@ -209,14 +211,18 @@ public: // Returns the complete list of derived type parameter symbols in // the order in which their declarations appear in the derived type // definitions (parents first). - std::list OrderParameterDeclarations(const Symbol &) const; + std::list OrderParameterDeclarations(const Symbol &) const; private: - // These are the names of the derived type parameters in (1) the order - // in which they appear on the type definition statement, and (2) the - // order in which their declarations appear in the derived type definition. + // These are (1) the names of the derived type parameters in the order + // in which they appear on the type definition statement(s), and (2) the + // symbols that correspond to those names in the order in which their + // declarations appear in the derived type definition(s). std::list paramNames_; - std::list paramDecls_; + std::list paramDecls_; + // These are the declarations of the derived type's components in component + // order. A parent component, if any, appears first in this list. + std::list components_; SourceName extends_; bool sequence_{false}; }; diff --git a/flang/lib/semantics/type.cc b/flang/lib/semantics/type.cc index 4ddf6ee..1bcbe9d 100644 --- a/flang/lib/semantics/type.cc +++ b/flang/lib/semantics/type.cc @@ -84,7 +84,8 @@ void DerivedTypeSpec::Instantiate( evaluate::FoldingContext &foldingContext{semanticsContext.foldingContext()}; auto restorer{foldingContext.WithPDTInstance(*this)}; - for (Symbol *symbol : typeDetails.OrderParameterDeclarations(typeSymbol_)) { + for (const Symbol *symbol : + typeDetails.OrderParameterDeclarations(typeSymbol_)) { const SourceName &name{symbol->name()}; const TypeParamDetails &details{symbol->get()}; MaybeIntExpr expr; -- 2.7.4