diff --git a/flang/lib/semantics/GetValue.def b/flang/lib/semantics/GetValue.def deleted file mode 100644 index 9e2b3b95569e..000000000000 --- a/flang/lib/semantics/GetValue.def +++ /dev/null @@ -1,148 +0,0 @@ - -// ============ Forward declarations ============== - -template inline const auto & GET_VALUE( const T &x) ; -template inline auto & GET_VALUE( T &x) ; -template inline bool HAS_VALUE( const T &x) ; -template inline bool HAS_VALUE( T &x) ; - -#ifndef IGNORE_Scalar -template inline const auto & GET_VALUE( const Fortran::parser::Scalar &x) ; -template inline auto & GET_VALUE( Fortran::parser::Scalar &x) ; -template inline bool HAS_VALUE( const Fortran::parser::Scalar &x) ; -template inline bool HAS_VALUE( Fortran::parser::Scalar &x) ; -#endif - -#ifndef IGNORE_Constant -template inline const auto & GET_VALUE( const Fortran::parser::Constant &x) ; -template inline auto & GET_VALUE( Fortran::parser::Constant &x) ; -template inline bool HAS_VALUE( const Fortran::parser::Constant &x) ; -template inline bool HAS_VALUE( Fortran::parser::Constant &x) ; -#endif - -#ifndef IGNORE_Integer -template inline const auto & GET_VALUE( const Fortran::parser::Integer &x) ; -template inline auto & GET_VALUE( Fortran::parser::Integer &x) ; -template inline bool HAS_VALUE( const Fortran::parser::Integer &x) ; -template inline bool HAS_VALUE( Fortran::parser::Integer &x) ; -#endif - -#ifndef IGNORE_Logical -template inline const auto & GET_VALUE( const Fortran::parser::Logical &x) ; -template inline auto & GET_VALUE( Fortran::parser::Logical &x) ; -template inline bool HAS_VALUE( const Fortran::parser::Logical &x) ; -template inline bool HAS_VALUE( Fortran::parser::Logical &x) ; -#endif - -#ifndef IGNORE_DefaultChar -template inline const auto & GET_VALUE( const Fortran::parser::DefaultChar &x) ; -template inline auto & GET_VALUE( Fortran::parser::DefaultChar &x) ; -template inline bool HAS_VALUE( const Fortran::parser::DefaultChar &x) ; -template inline bool HAS_VALUE( Fortran::parser::DefaultChar &x) ; -#endif - -#ifndef IGNORE_Indirection -template inline const auto & GET_VALUE( const Fortran::parser::Indirection &x) ; -template inline auto & GET_VALUE( Fortran::parser::Indirection &x) ; -template inline bool HAS_VALUE( const Fortran::parser::Indirection &x) ; -template inline bool HAS_VALUE( Fortran::parser::Indirection &x) ; -#endif - -#ifndef IGNORE_Statement -template inline const auto & GET_VALUE( const Fortran::parser::Statement &x) ; -template inline auto & GET_VALUE( Fortran::parser::Statement &x) ; -template inline bool HAS_VALUE( const Fortran::parser::Statement &x) ; -template inline bool HAS_VALUE( Fortran::parser::Statement &x) ; -#endif - -#ifndef IGNORE_optional -template inline const auto & GET_VALUE( const std::optional &x) ; -template inline auto & GET_VALUE( std::optional &x) ; -template inline bool HAS_VALUE( const std::optional &x) ; -template inline bool HAS_VALUE( std::optional &x) ; -#endif - - -// =========== Actual implementation of GET_VALUE() and HAS_VALUE() ============================== - - -template inline const auto & GET_VALUE( const T &x) { return x ;} -template inline auto & GET_VALUE( T &x) { return x ;} -template inline bool HAS_VALUE( const T &x) { return true; } -template inline bool HAS_VALUE( T &x) { return true; } - -#ifndef IGNORE_Scalar -template inline const auto & GET_VALUE( const Fortran::parser::Scalar &x) { return GET_VALUE(x.thing) ;} -template inline auto & GET_VALUE( Fortran::parser::Scalar &x) { return GET_VALUE(x.thing) ;} -template inline bool HAS_VALUE( const Fortran::parser::Scalar &x) { return HAS_VALUE(x.thing) ;} -template inline bool HAS_VALUE( Fortran::parser::Scalar &x) { return HAS_VALUE(x.thing) ;} -#endif - -#ifndef IGNORE_Constant -template inline const auto & GET_VALUE( const Fortran::parser::Constant &x) { return GET_VALUE(x.thing) ;} -template inline auto & GET_VALUE( Fortran::parser::Constant &x) { return GET_VALUE(x.thing) ;} -template inline bool HAS_VALUE( const Fortran::parser::Constant &x) { return HAS_VALUE(x.thing) ;} -template inline bool HAS_VALUE( Fortran::parser::Constant &x) { return HAS_VALUE(x.thing) ;} -#endif - -#ifndef IGNORE_Integer -template inline const auto & GET_VALUE( const Fortran::parser::Integer &x) { return GET_VALUE(x.thing) ;} -template inline auto & GET_VALUE( Fortran::parser::Integer &x) { return GET_VALUE(x.thing) ;} -template inline bool HAS_VALUE( const Fortran::parser::Integer &x) { return HAS_VALUE(x.thing) ;} -template inline bool HAS_VALUE( Fortran::parser::Integer &x) { return HAS_VALUE(x.thing) ;} -#endif - -#ifndef IGNORE_Logical -template inline const auto & GET_VALUE( const Fortran::parser::Logical &x) { return GET_VALUE(x.thing) ;} -template inline auto & GET_VALUE( Fortran::parser::Logical &x) { return GET_VALUE(x.thing) ;} -template inline bool HAS_VALUE( const Fortran::parser::Logical &x) { return HAS_VALUE(x.thing) ;} -template inline bool HAS_VALUE( Fortran::parser::Logical &x) { return HAS_VALUE(x.thing) ;} -#endif - -#ifndef IGNORE_DefaultChar -template inline const auto & GET_VALUE( const Fortran::parser::DefaultChar &x) { return GET_VALUE(x.thing) ;} -template inline auto & GET_VALUE( Fortran::parser::DefaultChar &x) { return GET_VALUE(x.thing) ;} -template inline bool HAS_VALUE( const Fortran::parser::DefaultChar &x) { return HAS_VALUE(x.thing) ;} -template inline bool HAS_VALUE( Fortran::parser::DefaultChar &x) { return HAS_VALUE(x.thing) ;} -#endif - -#ifndef IGNORE_Indirection -template inline const auto & GET_VALUE( const Fortran::parser::Indirection &x) { return GET_VALUE(*x) ;} -template inline auto & GET_VALUE( Fortran::parser::Indirection &x) { return GET_VALUE(*x) ;} -template inline bool HAS_VALUE( const Fortran::parser::Indirection &x) { return GET_VALUE(*x) ;} -template inline bool HAS_VALUE( Fortran::parser::Indirection &x) { return GET_VALUE(*x) ;} -#endif - -#ifndef IGNORE_Statement -template inline const auto & GET_VALUE( const Fortran::parser::Statement &x) { return GET_VALUE(x.statement) ;} -template inline auto & GET_VALUE( Fortran::parser::Statement &x) { return GET_VALUE(x.statement) ;} -template inline bool HAS_VALUE( const Fortran::parser::Statement &x) { return HAS_VALUE(x.statement) ;} -template inline bool HAS_VALUE( Fortran::parser::Statement &x) { return HAS_VALUE(x.statement) ;} -#endif - -#ifndef IGNORE_optional -template inline const auto & GET_VALUE( const std::optional &x) { return GET_VALUE(x.value()) ; } -template inline auto & GET_VALUE( std::optional &x) { return GET_VALUE(x.value()) ; } -template inline bool HAS_VALUE( const std::optional &x) { return x.has_value() && HAS_VALUE(*x); } -template inline bool HAS_VALUE( std::optional &x) { return x.has_value() && HAS_VALUE(*x); } -#endif - -template inline auto GET_OPT_VALUE(const T &x) { - if ( HAS_VALUE(x) ) { - return & GET_VALUE(x) ; - } else { - return decltype(&GET_VALUE(x)){0} ; - } -} - -template inline auto GET_OPT_VALUE(T &x) { - if ( HAS_VALUE(x) ) { - return & GET_VALUE(x) ; - } else { - return decltype(&GET_VALUE(x)){0} ; - } -} - -#undef GET_VALUE -#undef HAS_VALUE -#undef GET_OPT_VALUE diff --git a/flang/lib/semantics/GetValue.h b/flang/lib/semantics/GetValue.h deleted file mode 100644 index 2d86e7227f26..000000000000 --- a/flang/lib/semantics/GetValue.h +++ /dev/null @@ -1,134 +0,0 @@ -// Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef FORTRAN_SEMANTICS_GETVALUE_H_ -#define FORTRAN_SEMANTICS_GETVALUE_H_ - -#undef IGNORE_optional -#undef IGNORE_Statement -#undef IGNORE_Scalar -#undef IGNORE_Constant -#undef IGNORE_Indirection -#undef IGNORE_Logical -#undef IGNORE_DefaultChar - -// Each include of "GetValue.def" provides a set of helper functions -// whose names are specified by the macros GET_VALUE, HAS_VALUE and -// GET_OPT_VALUE. -// -// The purpose of those function is to provide easier access to the -// parse-tree by ignoring some wrapper classes/ -// -// -// GET_VALUE(x) provides a reference to the value that x is holding. -// -// The following wrapper classes are ignored unless the corresponding -// IGNORES_xxx macro is defined. -// -// Scalar -// Constant -// Integer -// Logical -// DefaultChar -// Indirection -// Statement -// std::optional -// -// -// HAS_VALUE(x) return true if it is legal to call GET_VALUE(x) in case x -// contains some std::optional -// -// Example: -// Constant>>> &x = ... ; -// if ( HasValue(x) ) { -// const int &v = getValue(x) ; -// ... -// } -// -// GET_OPT_VALUE(T &x) is equivalent to -// -// HAS_VALUE(x) ? &GET_VALUE(x) : (Type*) nullptr -// -// here Type is the type of GET_VALUE(x) -// -// Example: -// -// const Scalar>> & z = ... -// const Expr *ptr_z = GET_OPT_VALUE(z) ; -// if ( ptr_z ) { -// ... do something with *ptr_z % -// } -// - -// This is the default version that handles all wrapper - -#define GET_VALUE GetValue -#define HAS_VALUE HasValue -#define GET_OPT_VALUE GetOptValue -#include "GetValue.def" - -// HAS_VALUE and GET_OPT_VALUE are only interesting when -// std::optional is not ignored. -// We need to give a name to the function but they are pretty much useless -#define IGNORE_optional -#define GET_VALUE GetOptionalValue -#define HAS_VALUE HasOptionalValue__ -#define GET_OPT_VALUE GetOptValue__ -#include "GetValue.def" -#undef IGNORE_optional - -#define IGNORE_Statement -#define GET_VALUE GetStatementValue -#define HAS_VALUE HasStatementValue -#define GET_OPT_VALUE GetOptStatementValue -#include "GetValue.def" -#undef IGNORE_Statement - -#define IGNORE_Scalar -#define GET_VALUE GetScalarValue -#define HAS_VALUE HasScalarValue -#define GET_OPT_VALUE GetOptScalarValue -#include "GetValue.def" -#undef IGNORE_Scalar - -#define IGNORE_Constant -#define GET_VALUE GetConstantValue -#define HAS_VALUE HasConstantValue -#define GET_OPT_VALUE GetOptConstantValue -#include "GetValue.def" -#undef IGNORE_Constant - -#define IGNORE_Indirection -#define GET_VALUE GetIndirectionValue -#define HAS_VALUE HasIndirectionValue -#define GET_OPT_VALUE GetOptIndirectionValue -#include "GetValue.def" -#undef IGNORE_Indirection - - -#define IGNORE_Logical -#define GET_VALUE GetLogicalValue -#define HAS_VALUE HasLogicalValue -#define GET_OPT_VALUE GetOptLogicalValue -#include "GetValue.def" -#undef IGNORE_Logical - -#define IGNORE_DefaultChar -#define GET_VALUE GetDefaultCharValue -#define HAS_VALUE HasDefaultCharValue -#define GET_OPT_VALUE GetOptDefaultCharValue -#include "GetValue.def" -#undef IGNORE_DefaultChar - -#endif // FORTRAN_SEMANTICS_GETVALUE_H_ diff --git a/flang/lib/semantics/LabelTable.h b/flang/lib/semantics/LabelTable.h deleted file mode 100644 index 1cbe2764da87..000000000000 --- a/flang/lib/semantics/LabelTable.h +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef FORTRAN_SEMANTICS_LABELTABLE_H_ -#define FORTRAN_SEMANTICS_LABELTABLE_H_ - -#include -#include - -namespace Fortran::semantics { - -// Each statement label is in one of those groups -enum class LabelGroup -{ - BranchTarget, ///< A label a possible branch target - Format, ///< A label on a FORMAT statement - Other ///< A label on another statement -}; - - -// -// Hold all the labels of a Program Unit -// -// This is going to a integrated into the Scope/SymbolTable -// once we have it implemented. For now, I am just simulating -// scopes with LabelTable and LabelTableStack -// -class LabelTable -{ -private: - - struct Entry { - // TODO: what to put here - Fortran::parser::Provenance loc; - }; - - std::map entries_ ; - -public: - - void add( int label , Fortran::parser::Provenance loc ) - { - if (label<1 || label>99999) return ; // Hoops! - auto &entry = entries_[label] ; - entry.loc = loc ; - } - - bool find(int label, Fortran::parser::Provenance &loc) - { - - auto it = entries_.find(label); - if( it != entries_.end()) { - Entry & entry{it->second}; - loc = entry.loc; - return true; - } - return false; - } - - -}; // of class LabelTable - - -class LabelTableStack { -private: - std::stack stack ; -public: - LabelTable *PushLabelTable( LabelTable *table ) - { - assert(table!=NULL); - stack.push(table); - return table; - } - - void PopLabelTable( LabelTable *table ) - { - assert( !stack.empty() ) ; - assert( stack.top() == table ) ; - stack.pop(); - } - - LabelTable & GetLabelTable() { - assert( !stack.empty() ) ; - return *stack.top() ; - } - - bool NoLabelTable() { - return stack.empty() ; - } - -}; // of class LabelTableStack - -} // of namespace Fortran::semantics - -#endif // FORTRAN_SEMANTICS_LABELTABLE_H_ diff --git a/flang/lib/semantics/SemanticData.h b/flang/lib/semantics/SemanticData.h deleted file mode 100644 index dfa90ed0ab31..000000000000 --- a/flang/lib/semantics/SemanticData.h +++ /dev/null @@ -1,608 +0,0 @@ -// Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef FORTRAN_SEMANTICS_SEMANTICDATA_H_ -#define FORTRAN_SEMANTICS_SEMANTICDATA_H_ - -#include - -// -// -// Declare here the members of the Semantic that will -// be attached to each parse-tree class T. The default is -// an empty struct. All members added here shall be -// copiable and should be provided with a default value. -// -// Here are a few common fields -// -// Scope *scope_provider = the scope provided by a construct or statement -// int stmt_index = the index used in the StatementMap -// -// Remark: Weither we want to annotate parse-tree nodes with -// semantic information is still debatable. -// - -namespace Fortran::semantics { - -// Initialize the semantic information attached to a parser-tree node -// -// Ideally, the function should be called once at the begining of the corresponding Pre() -// member in Pass1. However, for the few cases where the semantic data need to be -// initialize earlier the strict argument can be set to false. -// -template Semantic & InitSema(const T &node, bool strict=true) { - - // Do not use the default implementation! - // If the following assert fails, then a DECLARE_SEMANTIC_DATA is - // missing below - assert(Semantic::IS_DECLARED); - - if (node.s) { - if (strict) { - // TODO: emit proper message - std::cerr << "Duplicate call of " << __PRETTY_FUNCTION__ << "\n" ; - exit(1); - } else { - return *(node.s); - } - } - auto s = new Semantic( const_cast(&node) ) ; - const_cast(node).s = s; - return *s ; -} - - -// Retreive the semantic information attached to a parser-tree node -template Semantic & GetSema(const T &node) { - // Do not use the default implementation! - // If the following assert fails, then a DECLARE_SEMANTIC is missing above - assert(Semantic::IS_DECLARED); - assert(node.s) ; - return *(node.s) ; -} - - -#define DEFINE_SEMANTIC_DATA(Class) \ - template <> struct Semantic { \ - Semantic(Fortran::parser::Class *node) {} \ - enum {IS_DECLARED=1}; - -#define END_SEMANTIC_DATA \ - } - -// Some fields that need to be defined for all statements -#define SEMANTIC_STMT_FIELDS \ - int stmt_index=0 - -DEFINE_SEMANTIC_DATA(ProgramUnit) - StatementMap *statement_map=0 ; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(MainProgram) - Scope *scope_provider=0 ; - LabelTable *label_table=0 ; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(SubroutineSubprogram) - Scope *scope_provider=0 ; - LabelTable *label_table=0 ; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(FunctionSubprogram) - Scope *scope_provider=0 ; - LabelTable *label_table=0 ; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(Module) - Scope *scope_provider=0 ; - LabelTable *label_table=0 ; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(DerivedTypeDef) - // WARNING: there is also a sm::DerivedTypeDef defined in types.h - Scope *scope_provider=0 ; -END_SEMANTIC_DATA; - - -DEFINE_SEMANTIC_DATA(AssignmentStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(DataStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(FunctionStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(SubroutineStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(ModuleStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(EndModuleStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(StmtFunctionStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(EndFunctionStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(EndSubroutineStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(TypeDeclarationStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(DerivedTypeStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(EndTypeStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(PrintStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(UseStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(ProgramStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(EndProgramStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(ImplicitStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(AccessStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(AllocatableStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(AsynchronousStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(BindStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(CodimensionStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(ContiguousStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(ContainsStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(DimensionStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(ExternalStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(IntentStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(IntrinsicStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(NamelistStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(OptionalStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(PointerStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(ProtectedStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(SaveStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(TargetStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(ValueStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(VolatileStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(CommonStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(EquivalenceStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(BasedPointerStmt) // extension - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(GenericStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(ParameterStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(EnumDef) -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(EnumDefStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(EndEnumStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(InterfaceStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(EndInterfaceStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(IfThenStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(ElseIfStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(ElseStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(EndIfStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(IfStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(SelectCaseStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(CaseStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(EndSelectStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(SelectRankStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(SelectRankCaseStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(SelectTypeStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(ProcedureDeclarationStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(StructureStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(StructureDef::EndStructureStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(FormatStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(EntryStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(ImportStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(AllocateStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(BackspaceStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(CallStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(CloseStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(ContinueStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(DeallocateStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(EndfileStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(EventPostStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(EventWaitStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(CycleStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(ExitStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(FailImageStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(FlushStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(FormTeamStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(GotoStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(InquireStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(LockStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(NullifyStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(OpenStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(PointerAssignmentStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(ReadStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(ReturnStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(RewindStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(StopStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(SyncAllStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(SyncImagesStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(SyncMemoryStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(SyncTeamStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(UnlockStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(WaitStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(WhereStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(WriteStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(ComputedGotoStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(ForallStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(ForallConstructStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(EndForallStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(ArithmeticIfStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(AssignStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(AssignedGotoStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(PauseStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(PrivateStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(TypeBoundProcedureStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(TypeBoundGenericStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(FinalProcedureStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(ComponentDefStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(EnumeratorDefStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(TypeGuardStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(NonLabelDoStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(LabelDoStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(EndDoStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(BlockStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(EndBlockStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(AssociateStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(EndAssociateStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(ChangeTeamStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(EndChangeTeamStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(CriticalStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - -DEFINE_SEMANTIC_DATA(EndCriticalStmt) - SEMANTIC_STMT_FIELDS; -END_SEMANTIC_DATA; - - -#undef DEFINE_SEMANTIC_DATA -#undef END_SEMANTIC_DATA_SEMANTIC -#undef SEMANTIC_STMT_FIELDS - -} // of namespace Fortran::semantics - -#endif // FORTRAN_SEMANTICS_SEMANTICDATA_H_ diff --git a/flang/lib/semantics/StatementMap.cc b/flang/lib/semantics/StatementMap.cc deleted file mode 100644 index 07b77dc7120e..000000000000 --- a/flang/lib/semantics/StatementMap.cc +++ /dev/null @@ -1,622 +0,0 @@ -// Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - - -#include "StatementMap.h" - -#include -#include -#include -#include - -#define FAIL(msg) \ - do { \ - std::cerr << "FATAL " << __FILE__ << ":" << __LINE__ << ":\n " << msg \ - << "\n"; \ - exit(1); \ - } while (0) -#define INTERNAL_ERROR FAIL("Internal Error") - -namespace Fortran::semantics { - -StatementMap::Entry &StatementMap::at(Index index) { - if (!(( First() <= index) && (index <= Last()))) { - FAIL("Illegal Stmt index " << index << " (expect " - << First() << " .." << Last() << ")"); - exit(1); - } - return entries_[index - 1]; -} - -const StatementMap::Entry &StatementMap::at(Index index) const { - if (!((First() <= index) && (index <= Last()))) { - FAIL("Illegal Stmt index " << index << " (expect " - << First() << ".." << Last() << ")"); - exit(1); - } - return entries_[index - 1]; -} - -StatementMap::Index StatementMap::Add(StmtClass sclass, int label) { - Entry self; - self.sclass = sclass; - self.group = StmtClassToGroup(sclass); - self.label = label; - - self.parent = None; - self.prev_in_body = None; - self.next_in_body = None; - self.prev_in_construct = None; - self.next_in_construct = None; - - Index self_index = Last() + 1; - - if (Size() == 0) { - // Special case of the first entry. - entries_.push_back(self); - return self_index; - } - - Index prev_index = self_index - 1; - auto prev_group = at(prev_index).group; - if (prev_group == StmtGroup::End) { - // When inserting after a closed construct, do as if - // that was after a single statement - prev_index = StartOfConstruct(prev_index); - prev_group = StmtGroup::Single; - } - - Entry &prev = at(prev_index); - - if (self.group == StmtGroup::Single || self.group == StmtGroup::Start) { - if (prev_group == StmtGroup::Start || prev_group == StmtGroup::Part) { - // Insert 'self' as first statement in body of 'prev; - self.parent = prev_index; - } else if (prev_group == StmtGroup::Single) { - // Insert 'self' after 'prev' (in the same body) - prev.next_in_body = self_index; - self.prev_in_body = prev_index; - self.parent = prev.parent; - } else { - INTERNAL_ERROR; - } - } else if (self.group == StmtGroup::Part || self.group == StmtGroup::End) { - if (prev_group == StmtGroup::Start || prev_group == StmtGroup::Part) { - // Close the empty body of 'prev' - assert(prev.next_in_construct == None); - prev.next_in_construct = self_index; - self.prev_in_construct = prev_index; - } else if (prev_group == StmtGroup::Single) { - // Close a non-empty body ending with 'prev' - assert(prev.next_in_body == None); - if (prev.parent == None) { - DumpFlat(std::cerr); - } - assert(prev.parent != None); - at(prev.parent).next_in_construct = self_index; - self.prev_in_construct = prev.parent; - } else { - INTERNAL_ERROR; - } - } - - // TODO: Beware of the reallocation cost of calling push_back() for each - // statement. - // const int chunksize = 128; - // entries_.reserve( (entries_.size()/chunksize+1)*chunksize ); - - entries_.push_back(self); - - - if ( self.group == StmtGroup::Part || self.group == StmtGroup::End ) { - assert( self.prev_in_construct != None) ; - assert( NextInConstruct(self.prev_in_construct) == self_index) ; - assert( PrevInConstruct(self_index) == self.prev_in_construct) ; - AssertNextInConstruct(self.prev_in_construct); - } - - return self_index; -} - -// -// 'prev_index' shall be a Start or Part statement. -// -// Assert that the next statement in the construct is of an expected class. -// -// -void StatementMap::AssertNextInConstruct(Index prev_index) const { - - if (prev_index == None) return; - auto &prev = at(prev_index); - if (prev.next_in_construct == None) return; - auto &next = at(prev.next_in_construct); - - -#define ORDER(A, B) (prev.sclass == StmtClass::A && next.sclass == StmtClass::B) - - if ( // If THEN ... [ELSEIF]* ... [ELSE] ... Endif - ORDER(IfThen, ElseIf) || ORDER(IfThen, Else) || ORDER(IfThen, EndIf) || - ORDER(ElseIf, ElseIf) || ORDER(ElseIf, Else) || ORDER(ElseIf, EndIf) || - ORDER(Else, EndIf) || - // PROGRAM ... [CONTAINS] ... END - ORDER(Program, Contains) || ORDER(Program, EndProgram) || - ORDER(Contains, EndProgram) || - // MODULE - ORDER(Module, Contains) || ORDER(Module, EndModule) || - ORDER(Contains, EndModule) || - // SUBROUTINE - ORDER(Subroutine, Contains) || ORDER(Subroutine, EndSubroutine) || - ORDER(Contains, EndSubroutine) || - // FUNCTION - ORDER(Function, Contains) || ORDER(Function, EndFunction) || - ORDER(Contains, EndFunction) || - // IF .. - ORDER(If, DummyEndIf) || - // FORALL .. - ORDER(Forall, DummyEndForall) || ORDER(ForallConstruct, EndForall) || - // WHERE .. - ORDER(Where, DummyEndWhere) || ORDER(WhereConstruct, MaskedElsewhere) || - ORDER(WhereConstruct, EndWhere) || ORDER(ElseWhere, EndWhere) || - ORDER(MaskedElsewhere, EndWhere) || - ORDER(MaskedElsewhere, MaskedElsewhere) || - // ASSOCIATE - ORDER(Associate, EndAssociate) || - // BLOCK - ORDER(Block, EndBlock) || - // CHANGE TEAM - ORDER(ChangeTeam, EndChangeTeam) || - // CRITICAL - ORDER(Critical, EndCritical) || - // TYPE - ORDER(DerivedType, EndType) || - // ENUM - ORDER(EnumDef, EndEnum) || - // INTERFACE - ORDER(Interface, EndInterface) || - // DO var=... - ORDER(NonLabelDo, EndDo) || - // DO WHILE ... - ORDER(NonLabelDoWhile, EndDo) || - // DO CONCURRENT - ORDER(NonLabelDoConcurrent, EndDo) || - // DO