[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
This commit is contained in:
Tim Keith 2018-05-02 14:06:02 -07:00
parent 7f66c0ae72
commit b8ec1fd041
9 changed files with 157 additions and 213 deletions

View File

@ -34,14 +34,11 @@ ENUM_CLASS(Attr, ABSTRACT, ALLOCATABLE, ASYNCHRONOUS, BIND_C, CONTIGUOUS,
class Attrs : public EnumSet<Attr, Attr_enumSize> { class Attrs : public EnumSet<Attr, Attr_enumSize> {
private: private:
using enumSetType = EnumSet<Attr, Attr_enumSize>; using enumSetType = EnumSet<Attr, Attr_enumSize>;
public: public:
using enumSetType::enumSetType; using enumSetType::enumSetType;
constexpr bool HasAny(const Attrs &x) const { constexpr bool HasAny(const Attrs &x) const { return !(*this & x).none(); }
return !(*this & x).none(); constexpr bool HasAll(const Attrs &x) const { return (~*this & x).none(); }
}
constexpr bool HasAll(const Attrs &x) const {
return (~*this & x).none();
}
// Internal error if any of these attributes are not in allowed. // Internal error if any of these attributes are not in allowed.
void CheckValid(const Attrs &allowed) const; void CheckValid(const Attrs &allowed) const;

View File

@ -14,54 +14,52 @@
#include "dump-parse-tree.h" #include "dump-parse-tree.h"
#include <string>
#include <cstring> #include <cstring>
#include <iostream>
#include <iomanip> #include <iomanip>
#include <iostream>
#include <string>
#ifdef __GNUG__ #ifdef __GNUG__
#include <cstdlib> #include <cstdlib>
#include <memory>
#include <cxxabi.h> #include <cxxabi.h>
#include <memory>
namespace Fortran::semantics { namespace Fortran::semantics {
std::string DemangleCxxName(const char* name) { std::string DemangleCxxName(const char *name) {
std::string result; std::string result;
int status = -4; // some arbitrary value to eliminate the compiler warning int status = -4; // some arbitrary value to eliminate the compiler warning
char * output = abi::__cxa_demangle(name, NULL, NULL, &status); char *output = abi::__cxa_demangle(name, NULL, NULL, &status);
if ( status==0 ) { if (status == 0) {
std::string result(output); std::string result(output);
free(output) ; free(output);
return result ; return result;
} else { } else {
return name ; return name;
} }
} }
} // of namespace Fortran::semantics } // namespace Fortran::semantics
#else #else
// Nothing if not G++ // Nothing if not G++
namespace Fortran::semantics { namespace Fortran::semantics {
std::string DemangleCxxName(const char* name) { std::string DemangleCxxName(const char *name) { return name; }
return name; } // namespace Fortran::semantics
}
}
#endif #endif
namespace Fortran::parser { namespace Fortran::parser {
bool ParseTreeDumper::startwith( const std::string str, const char *prefix) { bool ParseTreeDumper::startwith(const std::string str, const char *prefix) {
size_t len = strlen(prefix) ; size_t len = strlen(prefix);
return (str.compare(0,len,prefix)==0) ; return (str.compare(0, len, prefix) == 0);
} }
std::string ParseTreeDumper::cleanup(const std::string &name) { std::string ParseTreeDumper::cleanup(const std::string &name) {
if ( startwith(name,"Fortran::parser::") ) if (startwith(name, "Fortran::parser::"))
return name.substr(strlen("Fortran::parser::")) ; return name.substr(strlen("Fortran::parser::"));
else else
return name; return name;
} }
@ -69,7 +67,4 @@ std::string ParseTreeDumper::cleanup(const std::string &name) {
// Perform all required instantiations // Perform all required instantiations
FLANG_PARSE_TREE_DUMPER_INSTANTIATE_ALL() FLANG_PARSE_TREE_DUMPER_INSTANTIATE_ALL()
} // of namespace } // namespace Fortran::parser

View File

@ -28,42 +28,36 @@
namespace Fortran::semantics { namespace Fortran::semantics {
std::string DemangleCxxName(const char *name);
std::string DemangleCxxName(const char* name) ; template<typename T> std::string GetTypeName_base() {
return DemangleCxxName(typeid(T).name());
template <typename T> std::string GetTypeName_base() {
return DemangleCxxName( typeid(T).name() ) ;
} }
template <typename T> std::string GetTypeName() { template<typename T> std::string GetTypeName() {
return GetTypeName_base< return GetTypeName_base<
typename std::remove_cv< typename std::remove_cv<typename std::remove_reference<T>::type>::type>();
typename std::remove_reference<
T
>::type
>::type
> ();
} }
// Make it usable on // Make it usable on
template <typename T> std::string GetTypeName(const T &x) { template<typename T> std::string GetTypeName(const T &x) {
return GetTypeName<decltype(x)>() ; return GetTypeName<decltype(x)>();
} }
// Simplify the name of some types // Simplify the name of some types
#define FLANG_PARSER_RENAME_TYPE( TYPE, NAME ) \ #define FLANG_PARSER_RENAME_TYPE(TYPE, NAME) \
template <> inline std::string GetTypeName_base<TYPE>() { return NAME; } template<> inline std::string GetTypeName_base<TYPE>() { return NAME; }
FLANG_PARSER_RENAME_TYPE( Fortran::parser::LoopBounds<Fortran::parser::ScalarIntConstantExpr> , FLANG_PARSER_RENAME_TYPE(
"LoopBounds<Expr>") Fortran::parser::LoopBounds<Fortran::parser::ScalarIntConstantExpr>,
"LoopBounds<Expr>")
FLANG_PARSER_RENAME_TYPE( Fortran::parser::LoopBounds<Fortran::parser::ScalarIntExpr> , FLANG_PARSER_RENAME_TYPE(
"LoopBounds<Expr>") Fortran::parser::LoopBounds<Fortran::parser::ScalarIntExpr>,
"LoopBounds<Expr>")
} // end of namespace
} // namespace Fortran::semantics
namespace Fortran::parser { namespace Fortran::parser {
@ -76,49 +70,46 @@ namespace Fortran::parser {
class ParseTreeDumper { class ParseTreeDumper {
private: private:
int indent; int indent;
std::ostream &out ; std::ostream &out;
bool emptyline; bool emptyline;
public:
ParseTreeDumper(std::ostream &out_ = std::cerr) : indent(0) , out(out_) , emptyline(false) { } public:
ParseTreeDumper(std::ostream &out_ = std::cerr)
: indent(0), out(out_), emptyline(false) {}
private: private:
static bool startwith(const std::string str, const char *prefix);
static bool startwith( const std::string str, const char *prefix) ; static std::string cleanup(const std::string &name);
static std::string cleanup(const std::string &name) ;
public: public:
void out_indent() { void out_indent() {
for (int i=0;i<indent;i++) { for (int i = 0; i < indent; i++) {
out << "| " ; out << "| ";
} }
} }
template<typename T> bool Pre(const T &x) {
template <typename T> bool Pre(const T &x) { if (emptyline) {
if (emptyline ) {
out_indent(); out_indent();
emptyline = false ; emptyline = false;
} }
if ( UnionTrait<T> || WrapperTrait<T> ) { if (UnionTrait<T> || WrapperTrait<T>) {
out << cleanup(Fortran::semantics::GetTypeName<decltype(x)>()) << " -> " ; out << cleanup(Fortran::semantics::GetTypeName<decltype(x)>()) << " -> ";
emptyline = false ; emptyline = false;
} else { } else {
out << cleanup(Fortran::semantics::GetTypeName<decltype(x)>()) ; out << cleanup(Fortran::semantics::GetTypeName<decltype(x)>());
out << "\n" ; out << "\n";
indent++ ; indent++;
emptyline = true ; emptyline = true;
} }
return true ; return true;
} }
template <typename T> void Post(const T &x) { template<typename T> void Post(const T &x) {
if ( UnionTrait<T> || WrapperTrait<T> ) { if (UnionTrait<T> || WrapperTrait<T>) {
if (!emptyline) { if (!emptyline) {
out << "\n" ; out << "\n";
emptyline = true ; emptyline = true;
} }
} else { } else {
indent--; indent--;
@ -141,115 +132,83 @@ public:
return true; return true;
} }
bool Pre(const parser::Name &x) { bool Pre(const parser::Name &x) { return PutName(x.ToString(), x.symbol); }
return PutName(x.ToString(), x.symbol);
}
void Post(const parser::Name &) { void Post(const parser::Name &) { indent--; }
indent--;
}
bool Pre(const std::string &x) { bool Pre(const std::string &x) { return PutName(x, nullptr); }
return PutName(x, nullptr);
}
void Post(const std::string &x) { void Post(const std::string &x) { indent--; }
indent--;
}
bool Pre(const std::int64_t &x) { bool Pre(const std::int64_t &x) {
if (emptyline ) { if (emptyline) {
out_indent(); out_indent();
emptyline = false ; emptyline = false;
} }
out << "int = '" << x << "'\n"; out << "int = '" << x << "'\n";
indent++ ; indent++;
emptyline = true ; emptyline = true;
return true ; return true;
} }
void Post(const std::int64_t &x) { void Post(const std::int64_t &x) { indent--; }
indent--;
}
bool Pre(const std::uint64_t &x) { bool Pre(const std::uint64_t &x) {
if (emptyline ) { if (emptyline) {
out_indent(); out_indent();
emptyline = false ; emptyline = false;
} }
out << "int = '" << x << "'\n"; out << "int = '" << x << "'\n";
indent++ ; indent++;
emptyline = true ; emptyline = true;
return true ; return true;
} }
void Post(const std::uint64_t &x) { void Post(const std::uint64_t &x) { indent--; }
indent--;
}
// A few types we want to ignore // A few types we want to ignore
template<typename T> bool Pre(const Fortran::parser::Statement<T> &) {
template <typename T> bool Pre(const Fortran::parser::Statement<T> &) {
return true; return true;
} }
template <typename T> void Post(const Fortran::parser::Statement<T> &) { template<typename T> void Post(const Fortran::parser::Statement<T> &) {}
}
template <typename T> bool Pre(const Fortran::parser::Indirection<T> &) { template<typename T> bool Pre(const Fortran::parser::Indirection<T> &) {
return true; return true;
} }
template <typename T> void Post(const Fortran::parser::Indirection<T> &) { template<typename T> void Post(const Fortran::parser::Indirection<T> &) {}
}
template <typename T> bool Pre(const Fortran::parser::Integer<T> &) { template<typename T> bool Pre(const Fortran::parser::Integer<T> &) {
return true; return true;
} }
template <typename T> void Post(const Fortran::parser::Integer<T> &) { template<typename T> void Post(const Fortran::parser::Integer<T> &) {}
}
template<typename T> bool Pre(const Fortran::parser::Scalar<T> &) {
template <typename T> bool Pre(const Fortran::parser::Scalar<T> &) {
return true; return true;
} }
template <typename T> void Post(const Fortran::parser::Scalar<T> &) { template<typename T> void Post(const Fortran::parser::Scalar<T> &) {}
}
template <typename... A> bool Pre(const std::tuple<A...> &) { template<typename... A> bool Pre(const std::tuple<A...> &) { return true; }
return true;
}
template <typename... A> void Post(const std::tuple<A...> &) { template<typename... A> void Post(const std::tuple<A...> &) {}
}
template <typename... A> bool Pre(const std::variant<A...> &) { template<typename... A> bool Pre(const std::variant<A...> &) { return true; }
return true;
}
template <typename... A> void Post(const std::variant<A...> &) {
}
template<typename... A> void Post(const std::variant<A...> &) {}
public: public:
}; };
template<typename T> void DumpTree(const T &x, std::ostream &out = std::cout) {
template <typename T>
void DumpTree(const T &x, std::ostream &out=std::cout )
{
ParseTreeDumper dumper(out); ParseTreeDumper dumper(out);
Fortran::parser::Walk(x,dumper); Fortran::parser::Walk(x, dumper);
} }
} // namespace Fortran::parser
} // of namespace
namespace Fortran::parser { namespace Fortran::parser {
@ -259,30 +218,26 @@ namespace Fortran::parser {
// the instanciation of thousands of types. // the instanciation of thousands of types.
// //
#define FLANG_PARSE_TREE_DUMPER_INSTANTIATE(MODE, TYPE) \
#define FLANG_PARSE_TREE_DUMPER_INSTANTIATE(MODE,TYPE) \ MODE template void Walk(const TYPE &, Fortran::parser::ParseTreeDumper &);
MODE template void Walk(const TYPE&, Fortran::parser::ParseTreeDumper &);
#define FLANG_PARSE_TREE_DUMPER_INSTANTIATE_ALL(MODE) \ #define FLANG_PARSE_TREE_DUMPER_INSTANTIATE_ALL(MODE) \
FLANG_PARSE_TREE_DUMPER_INSTANTIATE(MODE,ProgramUnit) \ FLANG_PARSE_TREE_DUMPER_INSTANTIATE(MODE, ProgramUnit) \
FLANG_PARSE_TREE_DUMPER_INSTANTIATE(MODE,SubroutineStmt) \ FLANG_PARSE_TREE_DUMPER_INSTANTIATE(MODE, SubroutineStmt) \
FLANG_PARSE_TREE_DUMPER_INSTANTIATE(MODE,ProgramStmt) \ FLANG_PARSE_TREE_DUMPER_INSTANTIATE(MODE, ProgramStmt) \
FLANG_PARSE_TREE_DUMPER_INSTANTIATE(MODE,FunctionStmt) \ FLANG_PARSE_TREE_DUMPER_INSTANTIATE(MODE, FunctionStmt) \
FLANG_PARSE_TREE_DUMPER_INSTANTIATE(MODE,ModuleStmt) \ FLANG_PARSE_TREE_DUMPER_INSTANTIATE(MODE, ModuleStmt) \
FLANG_PARSE_TREE_DUMPER_INSTANTIATE(MODE,Expr) \ FLANG_PARSE_TREE_DUMPER_INSTANTIATE(MODE, Expr) \
FLANG_PARSE_TREE_DUMPER_INSTANTIATE(MODE,ActionStmt) \ FLANG_PARSE_TREE_DUMPER_INSTANTIATE(MODE, ActionStmt) \
FLANG_PARSE_TREE_DUMPER_INSTANTIATE(MODE,ExecutableConstruct) \ FLANG_PARSE_TREE_DUMPER_INSTANTIATE(MODE, ExecutableConstruct) \
FLANG_PARSE_TREE_DUMPER_INSTANTIATE(MODE,Block)\ FLANG_PARSE_TREE_DUMPER_INSTANTIATE(MODE, Block) \
FLANG_PARSE_TREE_DUMPER_INSTANTIATE(MODE,DeclarationConstruct)\ FLANG_PARSE_TREE_DUMPER_INSTANTIATE(MODE, DeclarationConstruct) \
FLANG_PARSE_TREE_DUMPER_INSTANTIATE(MODE,SpecificationPart)\ FLANG_PARSE_TREE_DUMPER_INSTANTIATE(MODE, SpecificationPart) \
FLANG_PARSE_TREE_DUMPER_INSTANTIATE(MODE,OtherSpecificationStmt)\ FLANG_PARSE_TREE_DUMPER_INSTANTIATE(MODE, OtherSpecificationStmt) \
FLANG_PARSE_TREE_DUMPER_INSTANTIATE(MODE,SpecificationConstruct)\ FLANG_PARSE_TREE_DUMPER_INSTANTIATE(MODE, SpecificationConstruct)
FLANG_PARSE_TREE_DUMPER_INSTANTIATE_ALL(extern) FLANG_PARSE_TREE_DUMPER_INSTANTIATE_ALL(extern)
} // of namespace
} // of namespace
#endif // FORTRAN_SEMANTICS_PARSETREEDUMP_H_ #endif // FORTRAN_SEMANTICS_PARSETREEDUMP_H_

View File

@ -26,6 +26,7 @@ namespace Fortran::semantics {
template<typename ENUM, std::size_t BITS> class EnumSet { template<typename ENUM, std::size_t BITS> class EnumSet {
static_assert(BITS > 0); static_assert(BITS > 0);
public: public:
using bitsetType = std::bitset<BITS>; using bitsetType = std::bitset<BITS>;
using enumerationType = ENUM; using enumerationType = ENUM;
@ -176,7 +177,8 @@ private:
template<typename ENUM, std::size_t values> template<typename ENUM, std::size_t values>
struct std::hash<Fortran::semantics::EnumSet<ENUM, values>> { struct std::hash<Fortran::semantics::EnumSet<ENUM, values>> {
std::size_t operator()(const Fortran::semantics::EnumSet<ENUM, values> &x) const { std::size_t operator()(
const Fortran::semantics::EnumSet<ENUM, values> &x) const {
return std::hash(x.bitset()); return std::hash(x.bitset());
} }
}; };

View File

@ -13,17 +13,17 @@
// limitations under the License. // limitations under the License.
#include "resolve-names.h" #include "resolve-names.h"
#include "rewrite-parse-tree.h"
#include "attr.h" #include "attr.h"
#include "rewrite-parse-tree.h"
#include "scope.h" #include "scope.h"
#include "symbol.h" #include "symbol.h"
#include "type.h" #include "type.h"
#include "../parser/indirection.h" #include "../parser/indirection.h"
#include "../parser/parse-tree-visitor.h" #include "../parser/parse-tree-visitor.h"
#include "../parser/parse-tree.h" #include "../parser/parse-tree.h"
#include <ostream>
#include <list> #include <list>
#include <memory> #include <memory>
#include <ostream>
#include <stack> #include <stack>
namespace Fortran::semantics { namespace Fortran::semantics {
@ -1262,8 +1262,6 @@ static void DumpSymbols(std::ostream &os, const Scope &scope, int indent = 0) {
--indent; --indent;
} }
void DumpSymbols(std::ostream &os) { void DumpSymbols(std::ostream &os) { DumpSymbols(os, Scope::globalScope); }
DumpSymbols(os, Scope::globalScope);
}
} // namespace Fortran::semantics } // namespace Fortran::semantics

View File

@ -76,13 +76,9 @@ public:
return true; return true;
} }
void Post(parser::Variable &x) { void Post(parser::Variable &x) { ConvertFunctionRef(x); }
ConvertFunctionRef(x);
}
void Post(parser::Expr &x) { void Post(parser::Expr &x) { ConvertFunctionRef(x); }
ConvertFunctionRef(x);
}
private: private:
const symbolMap &symbols_; const symbolMap &symbols_;
@ -91,7 +87,7 @@ private:
// For T = Variable or Expr, if x has a function reference that really // For T = Variable or Expr, if x has a function reference that really
// should be an array element reference (i.e. the name occurs in an // should be an array element reference (i.e. the name occurs in an
// entity declaration, convert it. // entity declaration, convert it.
template<typename T> void ConvertFunctionRef(T & x) { template<typename T> void ConvertFunctionRef(T &x) {
auto *funcRef = auto *funcRef =
std::get_if<parser::Indirection<parser::FunctionReference>>(&x.u); std::get_if<parser::Indirection<parser::FunctionReference>>(&x.u);
if (!funcRef) { if (!funcRef) {

View File

@ -18,7 +18,8 @@
namespace Fortran::semantics { namespace Fortran::semantics {
const Scope Scope::systemScope{Scope::systemScope, Scope::Kind::System, nullptr}; const Scope Scope::systemScope{
Scope::systemScope, Scope::Kind::System, nullptr};
Scope Scope::globalScope{Scope::systemScope, Scope::Kind::Global, nullptr}; Scope Scope::globalScope{Scope::systemScope, Scope::Kind::Global, nullptr};
Scope &Scope::MakeScope(Kind kind, const Symbol *symbol) { Scope &Scope::MakeScope(Kind kind, const Symbol *symbol) {
@ -27,8 +28,8 @@ Scope &Scope::MakeScope(Kind kind, const Symbol *symbol) {
} }
std::ostream &operator<<(std::ostream &os, const Scope &scope) { std::ostream &operator<<(std::ostream &os, const Scope &scope) {
os << Scope::EnumToString(scope.kind()) << " scope: " << scope.children_.size() os << Scope::EnumToString(scope.kind())
<< " children\n"; << " scope: " << scope.children_.size() << " children\n";
for (const auto &sym : scope.symbols_) { for (const auto &sym : scope.symbols_) {
os << " " << sym.second << "\n"; os << " " << sym.second << "\n";
} }

View File

@ -49,7 +49,10 @@ public:
: dummyArgs_{that.dummyArgs_}, result_{that.result_} {} : dummyArgs_{that.dummyArgs_}, result_{that.result_} {}
bool isFunction() const { return result_.has_value(); } bool isFunction() const { return result_.has_value(); }
const Symbol &result() const { CHECK(isFunction()); return **result_; } const Symbol &result() const {
CHECK(isFunction());
return **result_;
}
void set_result(Symbol &result) { void set_result(Symbol &result) {
CHECK(!result_.has_value()); CHECK(!result_.has_value());
result_ = &result; result_ = &result;
@ -91,8 +94,8 @@ public:
Symbol(const Scope &owner, const SourceName &name, const Attrs &attrs, Symbol(const Scope &owner, const SourceName &name, const Attrs &attrs,
Details &&details) Details &&details)
: owner_{owner}, attrs_{attrs}, details_{std::move(details)} { : owner_{owner}, attrs_{attrs}, details_{std::move(details)} {
add_occurrence(name); add_occurrence(name);
} }
const Scope &owner() const { return owner_; } const Scope &owner() const { return owner_; }
const SourceName &name() const { return occurrences_.front(); } const SourceName &name() const { return occurrences_.front(); }
Attrs &attrs() { return attrs_; } Attrs &attrs() { return attrs_; }
@ -129,12 +132,8 @@ public:
details_.swap(details); details_.swap(details);
} }
const std::list<SourceName> &occurrences() const { const std::list<SourceName> &occurrences() const { return occurrences_; }
return occurrences_; void add_occurrence(const SourceName &name) { occurrences_.push_back(name); }
}
void add_occurrence(const SourceName &name) {
occurrences_.push_back(name);
}
private: private:
const Scope &owner_; const Scope &owner_;

View File

@ -233,9 +233,10 @@ DeclTypeSpec &DeclTypeSpec::operator=(const DeclTypeSpec &that) {
return *this; return *this;
} }
DeclTypeSpec::DeclTypeSpec(Category category, std::unique_ptr<DerivedTypeSpec> &&typeSpec) DeclTypeSpec::DeclTypeSpec(
: category_{category}, intrinsicTypeSpec_{nullptr}, Category category, std::unique_ptr<DerivedTypeSpec> &&typeSpec)
derivedTypeSpec_{std::move(typeSpec)} { : category_{category}, intrinsicTypeSpec_{nullptr}, derivedTypeSpec_{
std::move(typeSpec)} {
CHECK(category == TypeDerived || category == ClassDerived); CHECK(category == TypeDerived || category == ClassDerived);
} }