### Debugging Parser
Last, a string literal `"..."_debug` denotes a parser that emits the string to
-`std::cerr` and succeeds. It is useful for tracing while debugging a parser but should
+`llvm::errs` and succeeds. It is useful for tracing while debugging a parser but should
obviously not be committed for production code.
#include "constexpr-bitset.h"
#include "idioms.h"
+#include "llvm/Support/raw_ostream.h"
#include <bitset>
#include <cstddef>
#include <initializer_list>
#include <optional>
-#include <ostream>
#include <string>
#include <type_traits>
}
}
- std::ostream &Dump(
- std::ostream &o, std::string EnumToString(enumerationType)) const {
+ llvm::raw_ostream &Dump(
+ llvm::raw_ostream &o, std::string EnumToString(enumerationType)) const {
char sep{'{'};
IterateOverMembers([&](auto e) {
o << sep << EnumToString(e);
#include "flang/Parser/char-block.h"
#include "flang/Semantics/attr.h"
#include <optional>
-#include <ostream>
#include <vector>
+namespace llvm {
+class raw_ostream;
+}
+
namespace Fortran::semantics {
class Symbol;
}
bool operator==(const AssumedType &that) const {
return &*symbol_ == &*that.symbol_;
}
- std::ostream &AsFortran(std::ostream &) const;
+ llvm::raw_ostream &AsFortran(llvm::raw_ostream &) const;
private:
SymbolRef symbol_;
std::optional<DynamicType> GetType() const;
int Rank() const;
bool operator==(const ActualArgument &) const;
- std::ostream &AsFortran(std::ostream &) const;
+ llvm::raw_ostream &AsFortran(llvm::raw_ostream &) const;
std::optional<parser::CharBlock> keyword() const { return keyword_; }
void set_keyword(parser::CharBlock x) { keyword_ = x; }
DECLARE_CONSTRUCTORS_AND_ASSIGNMENTS(SpecificIntrinsic)
~SpecificIntrinsic();
bool operator==(const SpecificIntrinsic &) const;
- std::ostream &AsFortran(std::ostream &) const;
+ llvm::raw_ostream &AsFortran(llvm::raw_ostream &) const;
IntrinsicProcedure name;
bool isRestrictedSpecific{false}; // if true, can only call it, not pass it
int Rank() const;
bool IsElemental() const;
std::optional<Expr<SubscriptInteger>> LEN() const;
- std::ostream &AsFortran(std::ostream &) const;
+ llvm::raw_ostream &AsFortran(llvm::raw_ostream &) const;
std::variant<SpecificIntrinsic, SymbolRef,
common::CopyableIndirection<Component>>
int Rank() const;
bool IsElemental() const { return proc_.IsElemental(); }
bool operator==(const ProcedureRef &) const;
- std::ostream &AsFortran(std::ostream &) const;
+ llvm::raw_ostream &AsFortran(llvm::raw_ostream &) const;
protected:
ProcedureDesignator proc_;
#include "flang/Parser/char-block.h"
#include "flang/Semantics/symbol.h"
#include <optional>
-#include <ostream>
#include <string>
#include <variant>
#include <vector>
+namespace llvm {
+class raw_ostream;
+}
+
namespace Fortran::evaluate {
class IntrinsicProcTable;
}
const char *thisIs = "POINTER", const char *thatIs = "TARGET",
bool isElemental = false) const;
- std::ostream &Dump(std::ostream &) const;
+ llvm::raw_ostream &Dump(llvm::raw_ostream &) const;
private:
void AcquireShape(const semantics::ObjectEntityDetails &);
}
static std::optional<DummyDataObject> Characterize(const semantics::Symbol &);
bool CanBePassedViaImplicitInterface() const;
- std::ostream &Dump(std::ostream &) const;
+ llvm::raw_ostream &Dump(llvm::raw_ostream &) const;
TypeAndShape type;
std::vector<Expr<SubscriptInteger>> coshape;
common::Intent intent{common::Intent::Default};
bool operator!=(const DummyProcedure &that) const { return !(*this == that); }
static std::optional<DummyProcedure> Characterize(
const semantics::Symbol &, const IntrinsicProcTable &);
- std::ostream &Dump(std::ostream &) const;
+ llvm::raw_ostream &Dump(llvm::raw_ostream &) const;
CopyableIndirection<Procedure> procedure;
common::Intent intent{common::Intent::Default};
Attrs attrs;
struct AlternateReturn {
bool operator==(const AlternateReturn &) const { return true; }
bool operator!=(const AlternateReturn &) const { return false; }
- std::ostream &Dump(std::ostream &) const;
+ llvm::raw_ostream &Dump(llvm::raw_ostream &) const;
};
// 15.3.2.1
bool IsOptional() const;
void SetOptional(bool = true);
bool CanBePassedViaImplicitInterface() const;
- std::ostream &Dump(std::ostream &) const;
+ llvm::raw_ostream &Dump(llvm::raw_ostream &) const;
// name and pass are not characteristics and so does not participate in
// operator== but are needed to determine if procedures are distinguishable
std::string name;
void SetType(DynamicType t) { std::get<TypeAndShape>(u).set_type(t); }
bool CanBeReturnedViaImplicitInterface() const;
- std::ostream &Dump(std::ostream &) const;
+ llvm::raw_ostream &Dump(llvm::raw_ostream &) const;
Attrs attrs;
std::variant<TypeAndShape, CopyableIndirection<Procedure>> u;
int FindPassIndex(std::optional<parser::CharBlock>) const;
bool CanBeCalledViaImplicitInterface() const;
bool CanOverride(const Procedure &, std::optional<int> passIndex) const;
- std::ostream &Dump(std::ostream &) const;
+ llvm::raw_ostream &Dump(llvm::raw_ostream &) const;
std::optional<FunctionResult> functionResult;
DummyArguments dummyArguments;
#include "real.h"
#include <string>
+namespace llvm {
+class raw_ostream;
+}
+
namespace Fortran::evaluate::value {
template<typename REAL_TYPE> class Complex {
}
std::string DumpHexadecimal() const;
- std::ostream &AsFortran(std::ostream &, int kind) const;
+ llvm::raw_ostream &AsFortran(llvm::raw_ostream &, int kind) const;
// TODO: (C)ABS once Real::HYPOT is done
// TODO: unit testing
#include "flang/Common/default-kinds.h"
#include "flang/Common/reference.h"
#include <map>
-#include <ostream>
#include <vector>
+namespace llvm {
+class raw_ostream;
+}
+
namespace Fortran::semantics {
class Symbol;
}
constexpr Result result() const { return result_; }
constexpr DynamicType GetType() const { return result_.GetType(); }
- std::ostream &AsFortran(std::ostream &) const;
+ llvm::raw_ostream &AsFortran(llvm::raw_ostream &) const;
protected:
std::vector<Element> Reshape(const ConstantSubscripts &) const;
Scalar<Result> At(const ConstantSubscripts &) const;
Constant Reshape(ConstantSubscripts &&) const;
- std::ostream &AsFortran(std::ostream &) const;
+ llvm::raw_ostream &AsFortran(llvm::raw_ostream &) const;
static constexpr DynamicType GetType() {
return {TypeCategory::Character, KIND};
}
#include "flang/Parser/char-block.h"
#include <algorithm>
#include <list>
-#include <ostream>
#include <tuple>
#include <type_traits>
#include <variant>
+namespace llvm {
+class raw_ostream;
+}
+
namespace Fortran::evaluate {
using common::LogicalOperator;
std::optional<DynamicType> GetType() const;
int Rank() const;
std::string AsFortran() const;
- std::ostream &AsFortran(std::ostream &) const;
+ llvm::raw_ostream &AsFortran(llvm::raw_ostream &) const;
static Derived Rewrite(FoldingContext &, Derived &&);
};
return operand_ == that.operand_;
}
- std::ostream &AsFortran(std::ostream &) const;
+ llvm::raw_ostream &AsFortran(llvm::raw_ostream &) const;
private:
Container operand_;
using Operand = SomeKind<FROMCAT>;
using Base = Operation<Convert, Result, Operand>;
using Base::Base;
- std::ostream &AsFortran(std::ostream &) const;
+ llvm::raw_ostream &AsFortran(llvm::raw_ostream &) const;
};
template<typename A>
template<typename T> explicit ArrayConstructor(const Expr<T> &) {}
static constexpr Result result() { return Result{}; }
static constexpr DynamicType GetType() { return Result::GetType(); }
- std::ostream &AsFortran(std::ostream &) const;
+ llvm::raw_ostream &AsFortran(llvm::raw_ostream &) const;
};
template<int KIND>
bool operator==(const ArrayConstructor &) const;
static constexpr Result result() { return Result{}; }
static constexpr DynamicType GetType() { return Result::GetType(); }
- std::ostream &AsFortran(std::ostream &) const;
+ llvm::raw_ostream &AsFortran(llvm::raw_ostream &) const;
const Expr<SubscriptInteger> &LEN() const { return length_.value(); }
private:
bool operator==(const ArrayConstructor &) const;
constexpr Result result() const { return result_; }
constexpr DynamicType GetType() const { return result_.GetType(); }
- std::ostream &AsFortran(std::ostream &) const;
+ llvm::raw_ostream &AsFortran(llvm::raw_ostream &) const;
private:
Result result_;
int Rank() const {
return std::visit([](const auto &x) { return x.Rank(); }, u);
}
- std::ostream &AsFortran(std::ostream &o) const;
+ llvm::raw_ostream &AsFortran(llvm::raw_ostream &o) const;
common::MapTemplate<Relational, DirectlyComparableTypes> u;
};
StructureConstructor &Add(const semantics::Symbol &, Expr<SomeType> &&);
int Rank() const { return 0; }
DynamicType GetType() const;
- std::ostream &AsFortran(std::ostream &) const;
+ llvm::raw_ostream &AsFortran(llvm::raw_ostream &) const;
private:
Result result_;
using BoundsSpec = std::vector<Expr<SubscriptInteger>>;
using BoundsRemapping =
std::vector<std::pair<Expr<SubscriptInteger>, Expr<SubscriptInteger>>>;
- std::ostream &AsFortran(std::ostream &) const;
+ llvm::raw_ostream &AsFortran(llvm::raw_ostream &) const;
Expr<SomeType> lhs;
Expr<SomeType> rhs;
#ifndef FORTRAN_EVALUATE_FORMATTING_H_
#define FORTRAN_EVALUATE_FORMATTING_H_
-// It is inconvenient in C++ to have std::ostream::operator<<() as a direct
+// It is inconvenient in C++ to have llvm::raw_ostream::operator<<() as a direct
// friend function of a class template with many instantiations, so the
// various representational class templates in lib/Evaluate format themselves
-// via AsFortran(std::ostream &) member functions, which the operator<<()
+// via AsFortran(llvm::raw_ostream &) member functions, which the operator<<()
// overload below will call. Others have AsFortran() member functions that
// return strings.
//
// representational class templates that need it, not by external clients.
#include "flang/Common/indirection.h"
+#include "llvm/Support/raw_ostream.h"
#include <optional>
-#include <ostream>
#include <type_traits>
namespace Fortran::evaluate {
template<typename A>
-auto operator<<(std::ostream &o, const A &x) -> decltype(x.AsFortran(o)) {
+auto operator<<(llvm::raw_ostream &o, const A &x) -> decltype(x.AsFortran(o)) {
return x.AsFortran(o);
}
template<typename A>
-auto operator<<(std::ostream &o, const A &x) -> decltype(o << x.AsFortran()) {
+auto operator<<(llvm::raw_ostream &o, const A &x) -> decltype(o << x.AsFortran()) {
return o << x.AsFortran();
}
template<typename A, bool COPYABLE>
auto operator<<(
- std::ostream &o, const Fortran::common::Indirection<A, COPYABLE> &x)
+ llvm::raw_ostream &o, const Fortran::common::Indirection<A, COPYABLE> &x)
-> decltype(o << x.value()) {
return o << x.value();
}
template<typename A>
-auto operator<<(std::ostream &o, const std::optional<A> &x)
+auto operator<<(llvm::raw_ostream &o, const std::optional<A> &x)
-> decltype(o << *x) {
if (x) {
o << *x;
#include "flang/Parser/char-block.h"
#include "flang/Parser/message.h"
#include <optional>
-#include <ostream>
#include <string>
+namespace llvm {
+class raw_ostream;
+}
+
namespace Fortran::evaluate {
class FoldingContext;
std::optional<SpecificIntrinsicFunctionInterface> IsSpecificIntrinsicFunction(
const std::string &) const;
- std::ostream &Dump(std::ostream &) const;
+ llvm::raw_ostream &Dump(llvm::raw_ostream &) const;
private:
Implementation *impl_{nullptr}; // owning pointer
#include "flang/Evaluate/common.h"
#include <cinttypes>
#include <limits>
-#include <ostream>
#include <string>
// Some environments, viz. clang on Darwin, allow the macro HUGE
// to leak out of <math.h> even when it is never directly included.
#undef HUGE
+namespace llvm {
+class raw_ostream;
+}
namespace Fortran::evaluate::value {
// LOG10(2.)*1E12
// Emits a character representation for an equivalent Fortran constant
// or parenthesized constant expression that produces this value.
- std::ostream &AsFortran(std::ostream &, int kind, bool minimal = false) const;
+ llvm::raw_ostream &AsFortran(llvm::raw_ostream &, int kind, bool minimal = false) const;
private:
using Significand = Integer<significandBits>; // no implicit bit
#include <cinttypes>
#include <memory>
#include <optional>
-#include <ostream>
#include <string>
#include <vector>
+namespace llvm {
+class raw_ostream;
+}
+
namespace Fortran::evaluate {
class StaticDataObject {
std::optional<std::string> AsString() const;
std::optional<std::u16string> AsU16String() const;
std::optional<std::u32string> AsU32String() const;
- std::ostream &AsFortran(std::ostream &) const;
+ llvm::raw_ostream &AsFortran(llvm::raw_ostream &) const;
static bool bigEndian;
#include "flang/Common/template.h"
#include "flang/Parser/char-block.h"
#include <optional>
-#include <ostream>
#include <variant>
#include <vector>
+namespace llvm {
+class raw_ostream;
+}
+
namespace Fortran::semantics {
class Symbol;
}
EVALUATE_UNION_CLASS_BOILERPLATE(BaseObject)
int Rank() const;
std::optional<Expr<SubscriptInteger>> LEN() const;
- std::ostream &AsFortran(std::ostream &) const;
+ llvm::raw_ostream &AsFortran(llvm::raw_ostream &) const;
const Symbol *symbol() const {
if (const auto *result{std::get_if<SymbolRef>(&u)}) {
return &result->get();
const Symbol &GetLastSymbol() const { return symbol_; }
std::optional<Expr<SubscriptInteger>> LEN() const;
bool operator==(const Component &) const;
- std::ostream &AsFortran(std::ostream &) const;
+ llvm::raw_ostream &AsFortran(llvm::raw_ostream &) const;
private:
common::CopyableIndirection<DataRef> base_;
int Rank() const;
std::optional<Expr<SubscriptInteger>> LEN() const;
bool operator==(const NamedEntity &) const;
- std::ostream &AsFortran(std::ostream &) const;
+ llvm::raw_ostream &AsFortran(llvm::raw_ostream &) const;
private:
std::variant<SymbolRef, Component> u_;
static constexpr int Rank() { return 0; } // always scalar
bool operator==(const TypeParamInquiry &) const;
- std::ostream &AsFortran(std::ostream &) const;
+ llvm::raw_ostream &AsFortran(llvm::raw_ostream &) const;
private:
std::optional<NamedEntity> base_;
bool operator==(const Triplet &) const;
bool IsStrideOne() const;
- std::ostream &AsFortran(std::ostream &) const;
+ llvm::raw_ostream &AsFortran(llvm::raw_ostream &) const;
private:
std::optional<IndirectSubscriptIntegerExpr> lower_, upper_;
explicit Subscript(Expr<SubscriptInteger> &&s)
: u{IndirectSubscriptIntegerExpr::Make(std::move(s))} {}
int Rank() const;
- std::ostream &AsFortran(std::ostream &) const;
+ llvm::raw_ostream &AsFortran(llvm::raw_ostream &) const;
std::variant<IndirectSubscriptIntegerExpr, Triplet> u;
};
const Symbol &GetLastSymbol() const;
std::optional<Expr<SubscriptInteger>> LEN() const;
bool operator==(const ArrayRef &) const;
- std::ostream &AsFortran(std::ostream &) const;
+ llvm::raw_ostream &AsFortran(llvm::raw_ostream &) const;
private:
NamedEntity base_;
NamedEntity GetBase() const;
std::optional<Expr<SubscriptInteger>> LEN() const;
bool operator==(const CoarrayRef &) const;
- std::ostream &AsFortran(std::ostream &) const;
+ llvm::raw_ostream &AsFortran(llvm::raw_ostream &) const;
private:
SymbolVector base_;
const Symbol &GetFirstSymbol() const;
const Symbol &GetLastSymbol() const;
std::optional<Expr<SubscriptInteger>> LEN() const;
- std::ostream &AsFortran(std::ostream &) const;
+ llvm::raw_ostream &AsFortran(llvm::raw_ostream &) const;
std::variant<SymbolRef, Component, ArrayRef, CoarrayRef> u;
};
const Symbol *GetLastSymbol() const;
std::optional<Expr<SubscriptInteger>> LEN() const;
bool operator==(const Substring &) const;
- std::ostream &AsFortran(std::ostream &) const;
+ llvm::raw_ostream &AsFortran(llvm::raw_ostream &) const;
std::optional<Expr<SomeCharacter>> Fold(FoldingContext &);
const Symbol &GetFirstSymbol() const { return complex_.GetFirstSymbol(); }
const Symbol &GetLastSymbol() const { return complex_.GetLastSymbol(); }
bool operator==(const ComplexPart &) const;
- std::ostream &AsFortran(std::ostream &) const;
+ llvm::raw_ostream &AsFortran(llvm::raw_ostream &) const;
private:
DataRef complex_;
BaseObject GetBaseObject() const;
const Symbol *GetLastSymbol() const;
std::optional<Expr<SubscriptInteger>> LEN() const;
- std::ostream &AsFortran(std::ostream &o) const;
+ llvm::raw_ostream &AsFortran(llvm::raw_ostream &o) const;
Variant u;
};
int Rank() const {
return std::visit([](const auto &x) { return x.Rank(); }, u);
}
- std::ostream &AsFortran(std::ostream &o) const {
+ llvm::raw_ostream &AsFortran(llvm::raw_ostream &o) const {
std::visit([&](const auto &x) { x.AsFortran(o); }, u);
return o;
}
static constexpr int Rank() { return 0; } // always scalar
bool operator==(const DescriptorInquiry &) const;
- std::ostream &AsFortran(std::ostream &) const;
+ llvm::raw_ostream &AsFortran(llvm::raw_ostream &) const;
private:
NamedEntity base_;
#include "flang/Common/template.h"
#include "flang/Parser/parse-tree.h"
-#include "llvm/Support/raw_ostream.h"
#include <memory>
/// Build a light-weight tree over the parse-tree to help with lowering to FIR.
/// are either statements or constructs, where a construct contains a list of
/// evaluations. The resulting PFT structure can then be used to create FIR.
+namespace llvm {
+class raw_ostream;
+}
+
namespace Fortran::lower {
namespace pft {
#include <string>
#include <utility>
+namespace llvm {
+class raw_ostream;
+}
+
namespace Fortran::parser {
class CharBlock {
return right < left;
}
-std::ostream &operator<<(std::ostream &os, const CharBlock &x);
+llvm::raw_ostream &operator<<(llvm::raw_ostream &os, const CharBlock &x);
}
#include "unparse.h"
#include "flang/Common/idioms.h"
#include "flang/Common/indirection.h"
-#include <ostream>
-#include <sstream>
+#include "llvm/Support/raw_ostream.h"
#include <string>
#include <type_traits>
class ParseTreeDumper {
public:
explicit ParseTreeDumper(
- std::ostream &out, const AnalyzedObjectsAsFortran *asFortran = nullptr)
+ llvm::raw_ostream &out, const AnalyzedObjectsAsFortran *asFortran = nullptr)
: out_(out), asFortran_{asFortran} {}
static constexpr const char *GetNodeName(const char *) { return "char *"; }
protected:
// Return a Fortran representation of this node to include in the dump
template<typename T> std::string AsFortran(const T &x) {
- std::ostringstream ss;
+ std::string buf;
+ llvm::raw_string_ostream ss{buf};
if constexpr (std::is_same_v<T, Expr>) {
if (asFortran_ && x.typedExpr) {
asFortran_->expr(ss, *x.typedExpr);
std::is_same_v<T, std::int64_t> || std::is_same_v<T, std::uint64_t>) {
ss << x;
}
- if (ss.tellp()) {
+ if (ss.tell()) {
return ss.str();
}
if constexpr (std::is_same_v<T, Name> || HasSource<T>::value) {
private:
int indent_{0};
- std::ostream &out_;
+ llvm::raw_ostream &out_;
const AnalyzedObjectsAsFortran *const asFortran_;
bool emptyline_{false};
};
template<typename T>
-void DumpTree(std::ostream &out, const T &x,
+void DumpTree(llvm::raw_ostream &out, const T &x,
const AnalyzedObjectsAsFortran *asFortran = nullptr) {
ParseTreeDumper dumper{out, asFortran};
Walk(x, dumper);
#include "flang/Parser/provenance.h"
#include <cstddef>
#include <map>
-#include <ostream>
+
+namespace llvm {
+class raw_ostream;
+}
namespace Fortran::parser {
bool Fails(const char *at, const MessageFixedText &tag, ParseState &);
void Note(const char *at, const MessageFixedText &tag, bool pass,
const ParseState &);
- void Dump(std::ostream &, const CookedSource &) const;
+ void Dump(llvm::raw_ostream &, const CookedSource &) const;
private:
struct LogForPosition {
#include <cstring>
#include <forward_list>
#include <optional>
-#include <ostream>
#include <string>
#include <utility>
#include <variant>
std::string ToString() const;
std::optional<ProvenanceRange> GetProvenanceRange(const CookedSource &) const;
void Emit(
- std::ostream &, const CookedSource &, bool echoSourceLine = true) const;
+ llvm::raw_ostream &, const CookedSource &, bool echoSourceLine = true) const;
// If this Message or any of its attachments locates itself via a CharBlock
// within a particular CookedSource, replace its location with the
void Merge(Messages &&);
void Copy(const Messages &);
void ResolveProvenances(const CookedSource &);
- void Emit(std::ostream &, const CookedSource &cooked,
+ void Emit(llvm::raw_ostream &, const CookedSource &cooked,
bool echoSourceLines = true) const;
void AttachTo(Message &);
bool AnyFatalError() const;
#include "parse-tree.h"
#include "provenance.h"
#include "flang/Common/Fortran-features.h"
+#include "llvm/Support/raw_ostream.h"
#include <optional>
-#include <ostream>
#include <string>
#include <utility>
#include <vector>
std::optional<Program> &parseTree() { return parseTree_; }
const SourceFile *Prescan(const std::string &path, Options);
- void DumpCookedChars(std::ostream &) const;
- void DumpProvenance(std::ostream &) const;
- void DumpParsingLog(std::ostream &) const;
- void Parse(std::ostream *debugOutput = nullptr);
+ void DumpCookedChars(llvm::raw_ostream &) const;
+ void DumpProvenance(llvm::raw_ostream &) const;
+ void DumpParsingLog(llvm::raw_ostream &) const;
+ void Parse(llvm::raw_ostream &debugOutput);
void ClearLog();
- void EmitMessage(std::ostream &o, const char *at, const std::string &message,
+ void EmitMessage(llvm::raw_ostream &o, const char *at, const std::string &message,
bool echoSourceLine = false) const {
cooked_.allSources().EmitMessage(
o, cooked_.GetProvenanceRange(CharBlock(at)), message, echoSourceLine);
}
- bool ForTesting(std::string path, std::ostream &);
+ bool ForTesting(std::string path, llvm::raw_ostream &);
private:
Options options_;
#include "source.h"
#include "flang/Common/idioms.h"
#include "flang/Common/interval.h"
+#include "llvm/Support/raw_ostream.h"
#include <cstddef>
#include <map>
#include <memory>
#include <optional>
-#include <ostream>
-#include <sstream>
#include <string>
#include <utility>
#include <variant>
bool empty() const { return map_.empty(); }
void Put(ProvenanceRange, std::size_t offset);
std::optional<std::size_t> Map(ProvenanceRange) const;
- std::ostream &Dump(std::ostream &) const;
+ llvm::raw_ostream &Dump(llvm::raw_ostream &) const;
private:
// A comparison function object for use in std::multimap<Compare=>.
ProvenanceRange Map(std::size_t at) const;
void RemoveLastBytes(std::size_t);
ProvenanceRangeToOffsetMappings Invert(const AllSources &) const;
- std::ostream &Dump(std::ostream &) const;
+ llvm::raw_ostream &Dump(llvm::raw_ostream &) const;
private:
struct ContiguousProvenanceMapping {
void PushSearchPathDirectory(std::string);
std::string PopSearchPathDirectory();
- const SourceFile *Open(std::string path, std::stringstream *error);
- const SourceFile *ReadStandardInput(std::stringstream *error);
+ const SourceFile *Open(std::string path, llvm::raw_ostream &error);
+ const SourceFile *ReadStandardInput(llvm::raw_ostream &error);
ProvenanceRange AddIncludedFile(
const SourceFile &, ProvenanceRange, bool isModule = false);
bool IsValid(ProvenanceRange range) const {
return range.size() > 0 && range_.Contains(range);
}
- void EmitMessage(std::ostream &, const std::optional<ProvenanceRange> &,
+ void EmitMessage(llvm::raw_ostream &, const std::optional<ProvenanceRange> &,
const std::string &message, bool echoSourceLine = false) const;
const SourceFile *GetSourceFile(
Provenance, std::size_t *offset = nullptr) const;
Provenance CompilerInsertionProvenance(char ch);
Provenance CompilerInsertionProvenance(const char *, std::size_t);
ProvenanceRange IntersectionWithSourceFiles(ProvenanceRange) const;
- std::ostream &Dump(std::ostream &) const;
+ llvm::raw_ostream &Dump(llvm::raw_ostream &) const;
private:
struct Inclusion {
void Marshal(); // marshals text into one contiguous block
void CompileProvenanceRangeToOffsetMappings();
std::string AcquireData() { return std::move(data_); }
- std::ostream &Dump(std::ostream &) const;
+ llvm::raw_ostream &Dump(llvm::raw_ostream &) const;
private:
AllSources &allSources_;
#include "characters.h"
#include <cstddef>
-#include <sstream>
#include <string>
#include <utility>
#include <vector>
+namespace llvm {
+class raw_ostream;
+}
+
namespace Fortran::parser {
std::string DirectoryName(std::string path);
std::size_t lines() const { return lineStart_.size(); }
Encoding encoding() const { return encoding_; }
- bool Open(std::string path, std::stringstream *error);
- bool ReadStandardInput(std::stringstream *error);
+ bool Open(std::string path, llvm::raw_ostream &error);
+ bool ReadStandardInput(llvm::raw_ostream &error);
void Close();
SourcePosition FindOffsetLineAndColumn(std::size_t) const;
std::size_t GetLineStartOffset(int lineNumber) const {
}
private:
- bool ReadFile(std::string errorPath, std::stringstream *error);
+ bool ReadFile(std::string errorPath, llvm::raw_ostream &error);
void IdentifyPayload();
void RecordLineStarts();
#include <functional>
#include <iosfwd>
+namespace llvm {
+class raw_ostream;
+}
+
namespace Fortran::evaluate {
struct GenericExprWrapper;
struct GenericAssignmentWrapper;
// A function called before each Statement is unparsed.
using preStatementType =
- std::function<void(const CharBlock &, std::ostream &, int)>;
+ std::function<void(const CharBlock &, llvm::raw_ostream &, int)>;
// Functions to handle unparsing of analyzed expressions and related
// objects rather than their original parse trees.
struct AnalyzedObjectsAsFortran {
- std::function<void(std::ostream &, const evaluate::GenericExprWrapper &)>
+ std::function<void(llvm::raw_ostream &, const evaluate::GenericExprWrapper &)>
expr;
std::function<void(
- std::ostream &, const evaluate::GenericAssignmentWrapper &)>
+ llvm::raw_ostream &, const evaluate::GenericAssignmentWrapper &)>
assignment;
- std::function<void(std::ostream &, const evaluate::ProcedureRef &)> call;
+ std::function<void(llvm::raw_ostream &, const evaluate::ProcedureRef &)> call;
};
// Converts parsed program to out as Fortran.
-void Unparse(std::ostream &out, const Program &program,
+void Unparse(llvm::raw_ostream &out, const Program &program,
Encoding encoding = Encoding::UTF_8, bool capitalizeKeywords = true,
bool backslashEscapes = true, preStatementType *preStatement = nullptr,
AnalyzedObjectsAsFortran * = nullptr);
#include "flang/Common/idioms.h"
#include "flang/Parser/char-block.h"
#include "flang/Parser/parse-tree.h"
+#include "llvm/Support/raw_ostream.h"
#include <cinttypes>
#include <optional>
-#include <ostream>
#include <set>
#include <unordered_map>
const CookedSource &cooked() const { return cooked_; }
const common::LanguageFeatureControl &features() const { return features_; }
- std::ostream *debugOutput() const { return debugOutput_; }
- UserState &set_debugOutput(std::ostream *out) {
- debugOutput_ = out;
+ llvm::raw_ostream *debugOutput() const { return debugOutput_; }
+ UserState &set_debugOutput(llvm::raw_ostream &out) {
+ debugOutput_ = &out;
return *this;
}
private:
const CookedSource &cooked_;
- std::ostream *debugOutput_{nullptr};
+ llvm::raw_ostream *debugOutput_{nullptr};
ParsingLog *log_{nullptr};
bool instrumentedParse_{false};
#include <cinttypes>
#include <string>
+namespace llvm {
+class raw_ostream;
+}
+
namespace Fortran::semantics {
// All available attributes.
void CheckValid(const Attrs &allowed) const;
private:
- friend std::ostream &operator<<(std::ostream &, const Attrs &);
+ friend llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Attrs &);
};
// Return string representation of attr that matches Fortran source.
std::string AttrToString(Attr attr);
-std::ostream &operator<<(std::ostream &o, Attr attr);
-std::ostream &operator<<(std::ostream &o, const Attrs &attrs);
+llvm::raw_ostream &operator<<(llvm::raw_ostream &o, Attr attr);
+llvm::raw_ostream &operator<<(llvm::raw_ostream &o, const Attrs &attrs);
}
#endif // FORTRAN_SEMANTICS_ATTR_H_
#include <set>
#include <string>
+namespace llvm {
+class raw_ostream;
+}
+
namespace Fortran::semantics {
using namespace parser::literals;
bool CanImport(const SourceName &) const;
const DeclTypeSpec &MakeLengthlessType(DeclTypeSpec &&);
- friend std::ostream &operator<<(std::ostream &, const Scope &);
+ friend llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Scope &);
};
}
#endif // FORTRAN_SEMANTICS_SCOPE_H_
#include <string>
#include <vector>
+namespace llvm {
+class raw_ostream;
+}
+
namespace Fortran::common {
class IntrinsicTypeDefaultKinds;
}
return context_.FindScope(where);
}
bool AnyFatalError() const { return context_.AnyFatalError(); }
- void EmitMessages(std::ostream &) const;
- void DumpSymbols(std::ostream &);
- void DumpSymbolsSources(std::ostream &) const;
+ void EmitMessages(llvm::raw_ostream &) const;
+ void DumpSymbols(llvm::raw_ostream &);
+ void DumpSymbolsSources(llvm::raw_ostream &) const;
private:
SemanticsContext &context_;
#include <set>
#include <vector>
+namespace llvm {
+class raw_ostream;
+}
+
namespace Fortran::semantics {
/// A Symbol consists of common information (name, owner, and attributes)
std::vector<Symbol *> dummyArgs_; // nullptr -> alternate return indicator
Symbol *result_{nullptr};
MaybeExpr stmtFunction_;
- friend std::ostream &operator<<(std::ostream &, const SubprogramDetails &);
+ friend llvm::raw_ostream &operator<<(llvm::raw_ostream &, const SubprogramDetails &);
};
// For SubprogramNameDetails, the kind indicates whether it is the name
bool isFuncResult_{false};
const DeclTypeSpec *type_{nullptr};
MaybeExpr bindName_;
- friend std::ostream &operator<<(std::ostream &, const EntityDetails &);
+ friend llvm::raw_ostream &operator<<(llvm::raw_ostream &, const EntityDetails &);
};
// Symbol is associated with a name or expression in a SELECT TYPE or ASSOCIATE.
ArraySpec shape_;
ArraySpec coshape_;
const Symbol *commonBlock_{nullptr}; // common block this object is in
- friend std::ostream &operator<<(std::ostream &, const ObjectEntityDetails &);
+ friend llvm::raw_ostream &operator<<(llvm::raw_ostream &, const ObjectEntityDetails &);
};
// Mixin for details with passed-object dummy argument.
private:
ProcInterface interface_;
std::optional<const Symbol *> init_;
- friend std::ostream &operator<<(std::ostream &, const ProcEntityDetails &);
+ friend llvm::raw_ostream &operator<<(llvm::raw_ostream &, const ProcEntityDetails &);
};
// These derived type details represent the characteristics of a derived
std::list<SourceName> componentNames_;
bool sequence_{false};
bool isForwardReferenced_{false};
- friend std::ostream &operator<<(std::ostream &, const DerivedTypeDetails &);
+ friend llvm::raw_ostream &operator<<(llvm::raw_ostream &, const DerivedTypeDetails &);
};
class ProcBindingDetails : public WithPassArg {
DerivedTypeDetails, UseDetails, UseErrorDetails, HostAssocDetails,
GenericDetails, ProcBindingDetails, NamelistDetails, CommonBlockDetails,
FinalProcDetails, TypeParamDetails, MiscDetails>;
-std::ostream &operator<<(std::ostream &, const Details &);
+llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Details &);
std::string DetailsToString(const Details &);
class Symbol {
Symbol() {} // only created in class Symbols
const std::string GetDetailsName() const;
- friend std::ostream &operator<<(std::ostream &, const Symbol &);
- friend std::ostream &DumpForUnparse(std::ostream &, const Symbol &, bool);
+ friend llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Symbol &);
+ friend llvm::raw_ostream &DumpForUnparse(llvm::raw_ostream &, const Symbol &, bool);
// If a derived type's symbol refers to an extended derived type,
// return the parent component's symbol. The scope of the derived type
template<class, std::size_t> friend struct std::array;
};
-std::ostream &operator<<(std::ostream &, Symbol::Flag);
+llvm::raw_ostream &operator<<(llvm::raw_ostream &, Symbol::Flag);
// Manage memory for all symbols. BLOCK_SIZE symbols at a time are allocated.
// Make() returns a reference to the next available one. They are never
#include <variant>
#include <vector>
+namespace llvm {
+class raw_ostream;
+}
+
namespace Fortran::parser {
struct Keyword;
}
: category_{category}, expr_{std::move(expr)} {}
Category category_{Category::Explicit};
MaybeSubscriptIntExpr expr_;
- friend std::ostream &operator<<(std::ostream &, const Bound &);
+ friend llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Bound &);
};
// A type parameter value: integer expression or assumed or deferred.
Category category_{Category::Explicit};
common::TypeParamAttr attr_{common::TypeParamAttr::Kind};
MaybeIntExpr expr_;
- friend std::ostream &operator<<(std::ostream &, const ParamValue &);
+ friend llvm::raw_ostream &operator<<(llvm::raw_ostream &, const ParamValue &);
};
class IntrinsicTypeSpec {
private:
TypeCategory category_;
KindExpr kind_;
- friend std::ostream &operator<<(std::ostream &os, const IntrinsicTypeSpec &x);
+ friend llvm::raw_ostream &operator<<(llvm::raw_ostream &os, const IntrinsicTypeSpec &x);
};
class NumericTypeSpec : public IntrinsicTypeSpec {
private:
ParamValue length_;
- friend std::ostream &operator<<(std::ostream &os, const CharacterTypeSpec &x);
+ friend llvm::raw_ostream &operator<<(llvm::raw_ostream &os, const CharacterTypeSpec &x);
};
class ShapeSpec {
ShapeSpec(Bound &&lb, Bound &&ub) : lb_{std::move(lb)}, ub_{std::move(ub)} {}
Bound lb_;
Bound ub_;
- friend std::ostream &operator<<(std::ostream &, const ShapeSpec &);
+ friend llvm::raw_ostream &operator<<(llvm::raw_ostream &, const ShapeSpec &);
};
struct ArraySpec : public std::vector<ShapeSpec> {
return !empty() && std::all_of(begin(), end(), predicate);
}
};
-std::ostream &operator<<(std::ostream &, const ArraySpec &);
+llvm::raw_ostream &operator<<(llvm::raw_ostream &, const ArraySpec &);
// Each DerivedTypeSpec has a typeSymbol that has DerivedTypeDetails.
// The name may not match the symbol's name in case of a USE rename.
bool instantiated_{false};
RawParameters rawParameters_;
ParameterMapType parameters_;
- friend std::ostream &operator<<(std::ostream &, const DerivedTypeSpec &);
+ friend llvm::raw_ostream &operator<<(llvm::raw_ostream &, const DerivedTypeSpec &);
};
class DeclTypeSpec {
CharacterTypeSpec, DerivedTypeSpec>
typeSpec_;
};
-std::ostream &operator<<(std::ostream &, const DeclTypeSpec &);
+llvm::raw_ostream &operator<<(llvm::raw_ostream &, const DeclTypeSpec &);
// This represents a proc-interface in the declaration of a procedure or
// procedure component. It comprises a symbol that represents the specific
#include "flang/Parser/characters.h"
#include <iosfwd>
+namespace llvm {
+class raw_ostream;
+}
+
namespace Fortran::parser {
struct Program;
}
namespace Fortran::semantics {
-void UnparseWithSymbols(std::ostream &, const parser::Program &,
+void UnparseWithSymbols(llvm::raw_ostream &, const parser::Program &,
parser::Encoding encoding = parser::Encoding::UTF_8);
}
#include "flang/Parser/message.h"
#include "flang/Semantics/scope.h"
#include "flang/Semantics/symbol.h"
+#include "llvm/Support/raw_ostream.h"
#include <initializer_list>
-#include <ostream>
using namespace Fortran::parser::literals;
}
}
-std::ostream &TypeAndShape::Dump(std::ostream &o) const {
+llvm::raw_ostream &TypeAndShape::Dump(llvm::raw_ostream &o) const {
o << type_.AsFortran(LEN_ ? LEN_->AsFortran() : "");
attrs_.Dump(o, EnumToString);
if (!shape_.empty()) {
}
}
-std::ostream &DummyDataObject::Dump(std::ostream &o) const {
+llvm::raw_ostream &DummyDataObject::Dump(llvm::raw_ostream &o) const {
attrs.Dump(o, EnumToString);
if (intent != common::Intent::Default) {
o << "INTENT(" << common::EnumToString(intent) << ')';
}
}
-std::ostream &DummyProcedure::Dump(std::ostream &o) const {
+llvm::raw_ostream &DummyProcedure::Dump(llvm::raw_ostream &o) const {
attrs.Dump(o, EnumToString);
if (intent != common::Intent::Default) {
o << "INTENT(" << common::EnumToString(intent) << ')';
return o;
}
-std::ostream &AlternateReturn::Dump(std::ostream &o) const { return o << '*'; }
+llvm::raw_ostream &AlternateReturn::Dump(llvm::raw_ostream &o) const {
+ return o << '*';
+}
DummyArgument::~DummyArgument() {}
}
}
-std::ostream &DummyArgument::Dump(std::ostream &o) const {
+llvm::raw_ostream &DummyArgument::Dump(llvm::raw_ostream &o) const {
if (!name.empty()) {
o << name << '=';
}
}
}
-std::ostream &FunctionResult::Dump(std::ostream &o) const {
+llvm::raw_ostream &FunctionResult::Dump(llvm::raw_ostream &o) const {
attrs.Dump(o, EnumToString);
std::visit(
common::visitors{
}
}
-std::ostream &Procedure::Dump(std::ostream &o) const {
+llvm::raw_ostream &Procedure::Dump(llvm::raw_ostream &o) const {
attrs.Dump(o, EnumToString);
if (functionResult) {
functionResult->Dump(o << "TYPE(") << ") FUNCTION";
//===----------------------------------------------------------------------===//
#include "flang/Evaluate/complex.h"
+#include "llvm/Support/raw_ostream.h"
namespace Fortran::evaluate::value {
}
template<typename R>
-std::ostream &Complex<R>::AsFortran(std::ostream &o, int kind) const {
+llvm::raw_ostream &Complex<R>::AsFortran(llvm::raw_ostream &o, int kind) const {
re_.AsFortran(o << '(', kind);
im_.AsFortran(o << ',', kind);
return o << ')';
#include "flang/Evaluate/tools.h"
#include "flang/Evaluate/variable.h"
#include "flang/Parser/message.h"
+#include "llvm/Support/raw_ostream.h"
#include <string>
#include <type_traits>
#include "flang/Evaluate/tools.h"
#include "flang/Parser/characters.h"
#include "flang/Semantics/symbol.h"
-#include <sstream>
+#include "llvm/Support/raw_ostream.h"
namespace Fortran::evaluate {
-static void ShapeAsFortran(std::ostream &o, const ConstantSubscripts &shape) {
+static void ShapeAsFortran(
+ llvm::raw_ostream &o, const ConstantSubscripts &shape) {
if (GetRank(shape) > 1) {
o << ",shape=";
char ch{'['};
}
template<typename RESULT, typename VALUE>
-std::ostream &ConstantBase<RESULT, VALUE>::AsFortran(std::ostream &o) const {
+llvm::raw_ostream &ConstantBase<RESULT, VALUE>::AsFortran(
+ llvm::raw_ostream &o) const {
if (Rank() > 1) {
o << "reshape(";
}
}
template<int KIND>
-std::ostream &Constant<Type<TypeCategory::Character, KIND>>::AsFortran(
- std::ostream &o) const {
+llvm::raw_ostream &Constant<Type<TypeCategory::Character, KIND>>::AsFortran(
+ llvm::raw_ostream &o) const {
if (Rank() > 1) {
o << "reshape(";
}
return o;
}
-std::ostream &ActualArgument::AssumedType::AsFortran(std::ostream &o) const {
+llvm::raw_ostream &ActualArgument::AssumedType::AsFortran(
+ llvm::raw_ostream &o) const {
return o << symbol_->name().ToString();
}
-std::ostream &ActualArgument::AsFortran(std::ostream &o) const {
+llvm::raw_ostream &ActualArgument::AsFortran(llvm::raw_ostream &o) const {
if (keyword_) {
o << keyword_->ToString() << '=';
}
}
}
-std::ostream &SpecificIntrinsic::AsFortran(std::ostream &o) const {
+llvm::raw_ostream &SpecificIntrinsic::AsFortran(llvm::raw_ostream &o) const {
return o << name;
}
-std::ostream &ProcedureRef::AsFortran(std::ostream &o) const {
+llvm::raw_ostream &ProcedureRef::AsFortran(llvm::raw_ostream &o) const {
for (const auto &arg : arguments_) {
if (arg && arg->isPassedObject()) {
arg->AsFortran(o) << '%';
}
template<typename D, typename R, typename... O>
-std::ostream &Operation<D, R, O...>::AsFortran(std::ostream &o) const {
+llvm::raw_ostream &Operation<D, R, O...>::AsFortran(
+ llvm::raw_ostream &o) const {
Precedence lhsPrec{ToPrecedence(left())};
OperatorSpelling spelling{SpellOperator(derived())};
o << spelling.prefix;
}
template<typename TO, TypeCategory FROMCAT>
-std::ostream &Convert<TO, FROMCAT>::AsFortran(std::ostream &o) const {
+llvm::raw_ostream &Convert<TO, FROMCAT>::AsFortran(llvm::raw_ostream &o) const {
static_assert(TO::category == TypeCategory::Integer ||
TO::category == TypeCategory::Real ||
TO::category == TypeCategory::Character ||
return o << ",kind=" << TO::kind << ')';
}
-std::ostream &Relational<SomeType>::AsFortran(std::ostream &o) const {
+llvm::raw_ostream &Relational<SomeType>::AsFortran(llvm::raw_ostream &o) const {
std::visit([&](const auto &rel) { rel.AsFortran(o); }, u);
return o;
}
template<typename T>
-std::ostream &EmitArray(std::ostream &o, const Expr<T> &expr) {
+llvm::raw_ostream &EmitArray(llvm::raw_ostream &o, const Expr<T> &expr) {
return expr.AsFortran(o);
}
template<typename T>
-std::ostream &EmitArray(std::ostream &, const ArrayConstructorValues<T> &);
+llvm::raw_ostream &EmitArray(
+ llvm::raw_ostream &, const ArrayConstructorValues<T> &);
template<typename T>
-std::ostream &EmitArray(std::ostream &o, const ImpliedDo<T> &implDo) {
+llvm::raw_ostream &EmitArray(llvm::raw_ostream &o, const ImpliedDo<T> &implDo) {
o << '(';
EmitArray(o, implDo.values());
o << ',' << ImpliedDoIndex::Result::AsFortran()
}
template<typename T>
-std::ostream &EmitArray(
- std::ostream &o, const ArrayConstructorValues<T> &values) {
+llvm::raw_ostream &EmitArray(
+ llvm::raw_ostream &o, const ArrayConstructorValues<T> &values) {
const char *sep{""};
for (const auto &value : values) {
o << sep;
}
template<typename T>
-std::ostream &ArrayConstructor<T>::AsFortran(std::ostream &o) const {
+llvm::raw_ostream &ArrayConstructor<T>::AsFortran(llvm::raw_ostream &o) const {
o << '[' << GetType().AsFortran() << "::";
EmitArray(o, *this);
return o << ']';
}
template<int KIND>
-std::ostream &ArrayConstructor<Type<TypeCategory::Character, KIND>>::AsFortran(
- std::ostream &o) const {
+llvm::raw_ostream &
+ArrayConstructor<Type<TypeCategory::Character, KIND>>::AsFortran(
+ llvm::raw_ostream &o) const {
o << '[' << GetType().AsFortran(LEN().AsFortran()) << "::";
EmitArray(o, *this);
return o << ']';
}
-std::ostream &ArrayConstructor<SomeDerived>::AsFortran(std::ostream &o) const {
+llvm::raw_ostream &ArrayConstructor<SomeDerived>::AsFortran(
+ llvm::raw_ostream &o) const {
o << '[' << GetType().AsFortran() << "::";
EmitArray(o, *this);
return o << ']';
template<typename RESULT>
std::string ExpressionBase<RESULT>::AsFortran() const {
- std::ostringstream ss;
+ std::string buf;
+ llvm::raw_string_ostream ss{buf};
AsFortran(ss);
return ss.str();
}
template<typename RESULT>
-std::ostream &ExpressionBase<RESULT>::AsFortran(std::ostream &o) const {
+llvm::raw_ostream &ExpressionBase<RESULT>::AsFortran(
+ llvm::raw_ostream &o) const {
std::visit(
common::visitors{
[&](const BOZLiteralConstant &x) {
return o;
}
-std::ostream &StructureConstructor::AsFortran(std::ostream &o) const {
+llvm::raw_ostream &StructureConstructor::AsFortran(llvm::raw_ostream &o) const {
o << DerivedTypeSpecAsFortran(result_.derivedTypeSpec());
if (values_.empty()) {
o << '(';
}
std::string DerivedTypeSpecAsFortran(const semantics::DerivedTypeSpec &spec) {
- std::stringstream ss;
+ std::string buf;
+ llvm::raw_string_ostream ss{buf};
ss << spec.name().ToString();
char ch{'('};
for (const auto &[name, value] : spec.parameters()) {
return ss.str();
}
-std::ostream &EmitVar(std::ostream &o, const Symbol &symbol) {
+llvm::raw_ostream &EmitVar(llvm::raw_ostream &o, const Symbol &symbol) {
return o << symbol.name().ToString();
}
-std::ostream &EmitVar(std::ostream &o, const std::string &lit) {
+llvm::raw_ostream &EmitVar(llvm::raw_ostream &o, const std::string &lit) {
return o << parser::QuoteCharacterLiteral(lit);
}
-std::ostream &EmitVar(std::ostream &o, const std::u16string &lit) {
+llvm::raw_ostream &EmitVar(llvm::raw_ostream &o, const std::u16string &lit) {
return o << parser::QuoteCharacterLiteral(lit);
}
-std::ostream &EmitVar(std::ostream &o, const std::u32string &lit) {
+llvm::raw_ostream &EmitVar(llvm::raw_ostream &o, const std::u32string &lit) {
return o << parser::QuoteCharacterLiteral(lit);
}
-template<typename A> std::ostream &EmitVar(std::ostream &o, const A &x) {
+template<typename A>
+llvm::raw_ostream &EmitVar(llvm::raw_ostream &o, const A &x) {
return x.AsFortran(o);
}
template<typename A>
-std::ostream &EmitVar(std::ostream &o, common::Reference<A> x) {
+llvm::raw_ostream &EmitVar(llvm::raw_ostream &o, common::Reference<A> x) {
return EmitVar(o, *x);
}
template<typename A>
-std::ostream &EmitVar(std::ostream &o, const A *p, const char *kw = nullptr) {
+llvm::raw_ostream &EmitVar(
+ llvm::raw_ostream &o, const A *p, const char *kw = nullptr) {
if (p) {
if (kw) {
o << kw;
}
template<typename A>
-std::ostream &EmitVar(
- std::ostream &o, const std::optional<A> &x, const char *kw = nullptr) {
+llvm::raw_ostream &EmitVar(
+ llvm::raw_ostream &o, const std::optional<A> &x, const char *kw = nullptr) {
if (x) {
if (kw) {
o << kw;
}
template<typename A, bool COPY>
-std::ostream &EmitVar(std::ostream &o, const common::Indirection<A, COPY> &p,
- const char *kw = nullptr) {
+llvm::raw_ostream &EmitVar(llvm::raw_ostream &o,
+ const common::Indirection<A, COPY> &p, const char *kw = nullptr) {
if (kw) {
o << kw;
}
}
template<typename A>
-std::ostream &EmitVar(std::ostream &o, const std::shared_ptr<A> &p) {
+llvm::raw_ostream &EmitVar(llvm::raw_ostream &o, const std::shared_ptr<A> &p) {
CHECK(p);
return EmitVar(o, *p);
}
template<typename... A>
-std::ostream &EmitVar(std::ostream &o, const std::variant<A...> &u) {
+llvm::raw_ostream &EmitVar(llvm::raw_ostream &o, const std::variant<A...> &u) {
std::visit([&](const auto &x) { EmitVar(o, x); }, u);
return o;
}
-std::ostream &BaseObject::AsFortran(std::ostream &o) const {
+llvm::raw_ostream &BaseObject::AsFortran(llvm::raw_ostream &o) const {
return EmitVar(o, u);
}
template<int KIND>
-std::ostream &TypeParamInquiry<KIND>::AsFortran(std::ostream &o) const {
+llvm::raw_ostream &TypeParamInquiry<KIND>::AsFortran(
+ llvm::raw_ostream &o) const {
if (base_) {
return base_->AsFortran(o) << '%';
}
return EmitVar(o, parameter_);
}
-std::ostream &Component::AsFortran(std::ostream &o) const {
+llvm::raw_ostream &Component::AsFortran(llvm::raw_ostream &o) const {
base_.value().AsFortran(o);
return EmitVar(o << '%', symbol_);
}
-std::ostream &NamedEntity::AsFortran(std::ostream &o) const {
+llvm::raw_ostream &NamedEntity::AsFortran(llvm::raw_ostream &o) const {
std::visit(
common::visitors{
[&](SymbolRef s) { EmitVar(o, s); },
return o;
}
-std::ostream &Triplet::AsFortran(std::ostream &o) const {
+llvm::raw_ostream &Triplet::AsFortran(llvm::raw_ostream &o) const {
EmitVar(o, lower_) << ':';
EmitVar(o, upper_);
EmitVar(o << ':', stride_.value());
return o;
}
-std::ostream &Subscript::AsFortran(std::ostream &o) const {
+llvm::raw_ostream &Subscript::AsFortran(llvm::raw_ostream &o) const {
return EmitVar(o, u);
}
-std::ostream &ArrayRef::AsFortran(std::ostream &o) const {
+llvm::raw_ostream &ArrayRef::AsFortran(llvm::raw_ostream &o) const {
base_.AsFortran(o);
char separator{'('};
for (const Subscript &ss : subscript_) {
return o << ')';
}
-std::ostream &CoarrayRef::AsFortran(std::ostream &o) const {
+llvm::raw_ostream &CoarrayRef::AsFortran(llvm::raw_ostream &o) const {
bool first{true};
for (const Symbol &part : base_) {
if (first) {
return o << ']';
}
-std::ostream &DataRef::AsFortran(std::ostream &o) const {
+llvm::raw_ostream &DataRef::AsFortran(llvm::raw_ostream &o) const {
return EmitVar(o, u);
}
-std::ostream &Substring::AsFortran(std::ostream &o) const {
+llvm::raw_ostream &Substring::AsFortran(llvm::raw_ostream &o) const {
EmitVar(o, parent_) << '(';
EmitVar(o, lower_) << ':';
return EmitVar(o, upper_) << ')';
}
-std::ostream &ComplexPart::AsFortran(std::ostream &o) const {
+llvm::raw_ostream &ComplexPart::AsFortran(llvm::raw_ostream &o) const {
return complex_.AsFortran(o) << '%' << EnumToString(part_);
}
-std::ostream &ProcedureDesignator::AsFortran(std::ostream &o) const {
+llvm::raw_ostream &ProcedureDesignator::AsFortran(llvm::raw_ostream &o) const {
return EmitVar(o, u);
}
template<typename T>
-std::ostream &Designator<T>::AsFortran(std::ostream &o) const {
+llvm::raw_ostream &Designator<T>::AsFortran(llvm::raw_ostream &o) const {
std::visit(
common::visitors{
[&](SymbolRef symbol) { EmitVar(o, symbol); },
return o;
}
-std::ostream &DescriptorInquiry::AsFortran(std::ostream &o) const {
+llvm::raw_ostream &DescriptorInquiry::AsFortran(llvm::raw_ostream &o) const {
switch (field_) {
case Field::LowerBound: o << "lbound("; break;
case Field::Extent: o << "size("; break;
}
}
-std::ostream &Assignment::AsFortran(std::ostream &o) const {
+llvm::raw_ostream &Assignment::AsFortran(llvm::raw_ostream &o) const {
std::visit(
common::visitors{
[&](const Assignment::Intrinsic &) {
#include "host.h"
#include "flang/Common/idioms.h"
-#include <cerrno>
+#include "llvm/Support/Errno.h"
#include <cfenv>
namespace Fortran::evaluate::host {
errno = 0;
if (feholdexcept(&originalFenv_) != 0) {
common::die("Folding with host runtime: feholdexcept() failed: %s",
- std::strerror(errno));
+ llvm::sys::StrError(errno).c_str());
return;
}
if (fegetenv(¤tFenv_) != 0) {
common::die("Folding with host runtime: fegetenv() failed: %s",
- std::strerror(errno));
+ llvm::sys::StrError(errno).c_str());
return;
}
#if __x86_64__
errno = 0;
if (fesetenv(¤tFenv_) != 0) {
common::die("Folding with host runtime: fesetenv() failed: %s",
- std::strerror(errno));
+ llvm::sys::StrError(errno).c_str());
return;
}
switch (context.rounding().mode) {
}
errno = 0;
if (fesetenv(&originalFenv_) != 0) {
- std::fprintf(stderr, "fesetenv() failed: %s\n", std::strerror(errno));
+ std::fprintf(
+ stderr, "fesetenv() failed: %s\n", llvm::sys::StrError(errno).c_str());
common::die(
"Folding with host runtime: fesetenv() failed while restoring fenv: %s",
- std::strerror(errno));
+ llvm::sys::StrError(errno).c_str());
}
errno = 0;
}
#include "flang/Evaluate/shape.h"
#include "flang/Evaluate/tools.h"
#include "flang/Evaluate/type.h"
+#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <map>
-#include <ostream>
-#include <sstream>
#include <string>
#include <utility>
struct TypePattern {
CategorySet categorySet;
KindCode kindCode{KindCode::none};
- std::ostream &Dump(std::ostream &) const;
+ llvm::raw_ostream &Dump(llvm::raw_ostream &) const;
};
// Abbreviations for argument and result patterns in the intrinsic prototypes:
TypePattern typePattern;
Rank rank{Rank::elemental};
Optionality optionality{Optionality::required};
- std::ostream &Dump(std::ostream &) const;
+ llvm::raw_ostream &Dump(llvm::raw_ostream &) const;
};
// constexpr abbreviations for popular arguments:
const common::IntrinsicTypeDefaultKinds &, ActualArguments &,
FoldingContext &context) const;
int CountArguments() const;
- std::ostream &Dump(std::ostream &) const;
+ llvm::raw_ostream &Dump(llvm::raw_ostream &) const;
};
int IntrinsicInterface::CountArguments() const {
std::optional<SpecificIntrinsicFunctionInterface> IsSpecificIntrinsicFunction(
const std::string &) const;
- std::ostream &Dump(std::ostream &) const;
+ llvm::raw_ostream &Dump(llvm::raw_ostream &) const;
private:
DynamicType GetSpecificType(const TypePattern &) const;
return DEREF(impl_).IsSpecificIntrinsicFunction(name);
}
-std::ostream &TypePattern::Dump(std::ostream &o) const {
+llvm::raw_ostream &TypePattern::Dump(llvm::raw_ostream &o) const {
if (categorySet == AnyType) {
o << "any type";
} else {
return o;
}
-std::ostream &IntrinsicDummyArgument::Dump(std::ostream &o) const {
+llvm::raw_ostream &IntrinsicDummyArgument::Dump(llvm::raw_ostream &o) const {
if (keyword) {
o << keyword << '=';
}
<< ' ' << EnumToString(rank) << ' ' << EnumToString(optionality);
}
-std::ostream &IntrinsicInterface::Dump(std::ostream &o) const {
+llvm::raw_ostream &IntrinsicInterface::Dump(llvm::raw_ostream &o) const {
o << name;
char sep{'('};
for (const auto &d : dummy) {
return result.Dump(o << " -> ") << ' ' << EnumToString(rank);
}
-std::ostream &IntrinsicProcTable::Implementation::Dump(std::ostream &o) const {
+llvm::raw_ostream &IntrinsicProcTable::Implementation::Dump(
+ llvm::raw_ostream &o) const {
o << "generic intrinsic functions:\n";
for (const auto &iter : genericFuncs_) {
iter.second->Dump(o << iter.first << ": ") << '\n';
return o;
}
-std::ostream &IntrinsicProcTable::Dump(std::ostream &o) const {
+llvm::raw_ostream &IntrinsicProcTable::Dump(llvm::raw_ostream &o) const {
return impl_->Dump(o);
}
}
#include "flang/Common/idioms.h"
#include "flang/Decimal/decimal.h"
#include "flang/Parser/characters.h"
+#include "llvm/Support/raw_ostream.h"
#include <limits>
namespace Fortran::evaluate::value {
}
template<typename W, int P>
-std::ostream &Real<W, P>::AsFortran(
- std::ostream &o, int kind, bool minimal) const {
+llvm::raw_ostream &Real<W, P>::AsFortran(
+ llvm::raw_ostream &o, int kind, bool minimal) const {
if (IsNotANumber()) {
o << "(0._" << kind << "/0.)";
} else if (IsInfinite()) {
bool StaticDataObject::bigEndian{false};
-std::ostream &StaticDataObject::AsFortran(std::ostream &o) const {
+llvm::raw_ostream &StaticDataObject::AsFortran(llvm::raw_ostream &o) const {
if (auto string{AsString()}) {
o << parser::QuoteCharacterLiteral(*string);
} else if (auto string{AsU16String()}) {
#include "flang/Semantics/type.h"
#include <algorithm>
#include <optional>
-#include <sstream>
#include <string>
// IsDescriptor() predicate
#include "flang/Parser/characters.h"
#include "flang/Parser/message.h"
#include "flang/Semantics/symbol.h"
-#include <ostream>
#include <type_traits>
using namespace Fortran::parser::literals;
target_link_libraries(FortranParser
FortranCommon
+ LLVMSupport
)
install (TARGETS FortranParser
//----------------------------------------------------------------------------//
#include "flang/Parser/char-block.h"
-#include <ostream>
+#include "llvm/Support/raw_ostream.h"
namespace Fortran::parser {
-std::ostream &operator<<(std::ostream &os, const CharBlock &x) {
+llvm::raw_ostream &operator<<(llvm::raw_ostream &os, const CharBlock &x) {
return os << x.ToString();
}
#include "debug-parser.h"
#include "flang/Parser/user-state.h"
-#include <ostream>
#include <string>
namespace Fortran::parser {
#include "flang/Parser/instrumented-parser.h"
#include "flang/Parser/message.h"
#include "flang/Parser/provenance.h"
+#include "llvm/Support/raw_ostream.h"
#include <map>
-#include <ostream>
namespace Fortran::parser {
}
}
-void ParsingLog::Dump(std::ostream &o, const CookedSource &cooked) const {
+void ParsingLog::Dump(llvm::raw_ostream &o, const CookedSource &cooked) const {
for (const auto &posLog : perPos_) {
const char *at{reinterpret_cast<const char *>(posLog.first)};
for (const auto &tagLog : posLog.second.perTag) {
#include "flang/Parser/message.h"
#include "flang/Common/idioms.h"
#include "flang/Parser/char-set.h"
+#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cstdarg>
#include <cstddef>
namespace Fortran::parser {
-std::ostream &operator<<(std::ostream &o, const MessageFixedText &t) {
+llvm::raw_ostream &operator<<(llvm::raw_ostream &o, const MessageFixedText &t) {
std::size_t n{t.text().size()};
for (std::size_t j{0}; j < n; ++j) {
o << t.text()[j];
location_);
}
-void Message::Emit(
- std::ostream &o, const CookedSource &cooked, bool echoSourceLine) const {
+void Message::Emit(llvm::raw_ostream &o, const CookedSource &cooked,
+ bool echoSourceLine) const {
std::optional<ProvenanceRange> provenanceRange{GetProvenanceRange(cooked)};
std::string text;
if (IsFatal()) {
}
}
-void Messages::Emit(
- std::ostream &o, const CookedSource &cooked, bool echoSourceLines) const {
+void Messages::Emit(llvm::raw_ostream &o, const CookedSource &cooked,
+ bool echoSourceLines) const {
std::vector<const Message *> sorted;
for (const auto &msg : messages_) {
sorted.push_back(&msg);
#include "flang/Common/indirection.h"
#include "flang/Parser/tools.h"
#include "flang/Parser/user-state.h"
+#include "llvm/Support/raw_ostream.h"
#include <algorithm>
// So "delete Expr;" calls an external destructor for its typedExpr.
u);
}
-std::ostream &operator<<(std::ostream &os, const Name &x) {
+llvm::raw_ostream &operator<<(llvm::raw_ostream &os, const Name &x) {
return os << x.ToString();
}
#include "flang/Parser/message.h"
#include "flang/Parser/provenance.h"
#include "flang/Parser/source.h"
-#include <sstream>
+#include "llvm/Support/raw_ostream.h"
namespace Fortran::parser {
}
}
- std::stringstream fileError;
+ std::string buf;
+ llvm::raw_string_ostream fileError{buf};
const SourceFile *sourceFile;
if (path == "-") {
- sourceFile = allSources.ReadStandardInput(&fileError);
+ sourceFile = allSources.ReadStandardInput(fileError);
} else {
- sourceFile = allSources.Open(path, &fileError);
+ sourceFile = allSources.Open(path, fileError);
}
if (!fileError.str().empty()) {
ProvenanceRange range{allSources.AddCompilerInsertion(path)};
return sourceFile;
}
-void Parsing::DumpCookedChars(std::ostream &out) const {
+void Parsing::DumpCookedChars(llvm::raw_ostream &out) const {
UserState userState{cooked_, common::LanguageFeatureControl{}};
ParseState parseState{cooked_};
parseState.set_inFixedForm(options_.isFixedForm).set_userState(&userState);
}
}
-void Parsing::DumpProvenance(std::ostream &out) const { cooked_.Dump(out); }
+void Parsing::DumpProvenance(llvm::raw_ostream &out) const {
+ cooked_.Dump(out);
+}
-void Parsing::DumpParsingLog(std::ostream &out) const {
+void Parsing::DumpParsingLog(llvm::raw_ostream &out) const {
log_.Dump(out, cooked_);
}
-void Parsing::Parse(std::ostream *out) {
+void Parsing::Parse(llvm::raw_ostream &out) {
UserState userState{cooked_, options_.features};
userState.set_debugOutput(out)
.set_instrumentedParse(options_.instrumentedParse)
void Parsing::ClearLog() { log_.clear(); }
-bool Parsing::ForTesting(std::string path, std::ostream &err) {
+bool Parsing::ForTesting(std::string path, llvm::raw_ostream &err) {
+ llvm::raw_null_ostream NullStream;
Prescan(path, Options{});
if (messages_.AnyFatalError()) {
messages_.Emit(err, cooked_);
err << "could not scan " << path << '\n';
return false;
}
- Parse();
+ Parse(NullStream);
messages_.Emit(err, cooked_);
if (!consumedWholeFile_) {
EmitMessage(err, finalRestingPlace_, "parser FAIL; final position");
#include "flang/Common/idioms.h"
#include "flang/Parser/characters.h"
#include "flang/Parser/message.h"
+#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cinttypes>
#include <cstddef>
#include <memory>
#include <optional>
#include <set>
-#include <sstream>
#include <utility>
namespace Fortran::parser {
repl = "\""s +
allSources_.GetPath(prescanner.GetCurrentProvenance()) + '"';
} else if (name == "__LINE__") {
- std::stringstream ss;
+ std::string buf;
+ llvm::raw_string_ostream ss{buf};
ss << allSources_.GetLineNumber(prescanner.GetCurrentProvenance());
repl = ss.str();
}
"#include: empty include file name"_err_en_US);
return;
}
- std::stringstream error;
- const SourceFile *included{allSources_.Open(include, &error)};
+ std::string buf;
+ llvm::raw_string_ostream error{buf};
+ const SourceFile *included{allSources_.Open(include, error)};
if (!included) {
prescanner->Say(dir.GetTokenProvenanceRange(dirOffset),
"#include: %s"_err_en_US, error.str());
#include "flang/Parser/characters.h"
#include "flang/Parser/message.h"
#include "flang/Parser/source.h"
+#include "llvm/Support/raw_ostream.h"
#include <cstddef>
#include <cstring>
-#include <sstream>
#include <utility>
#include <vector>
Say(GetProvenanceRange(garbage, p),
"excess characters after path name"_en_US);
}
- std::stringstream error;
+ std::string buf;
+ llvm::raw_string_ostream error{buf};
Provenance provenance{GetProvenance(nextLine_)};
AllSources &allSources{cooked_.allSources()};
const SourceFile *currentFile{allSources.GetSourceFile(provenance)};
if (currentFile) {
allSources.PushSearchPathDirectory(DirectoryName(currentFile->path()));
}
- const SourceFile *included{allSources.Open(path, &error)};
+ const SourceFile *included{allSources.Open(path, error)};
if (currentFile) {
allSources.PopSearchPathDirectory();
}
#include "flang/Parser/provenance.h"
#include "flang/Common/idioms.h"
+#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <utility>
return directory;
}
-const SourceFile *AllSources::Open(std::string path, std::stringstream *error) {
+const SourceFile *AllSources::Open(std::string path, llvm::raw_ostream &error) {
std::unique_ptr<SourceFile> source{std::make_unique<SourceFile>(encoding_)};
if (source->Open(LocateSourceFile(path, searchPath_), error)) {
return ownedSourceFiles_.emplace_back(std::move(source)).get();
}
}
-const SourceFile *AllSources::ReadStandardInput(std::stringstream *error) {
+const SourceFile *AllSources::ReadStandardInput(llvm::raw_ostream &error) {
std::unique_ptr<SourceFile> source{std::make_unique<SourceFile>(encoding_)};
if (source->ReadStandardInput(error)) {
return ownedSourceFiles_.emplace_back(std::move(source)).get();
return covers;
}
-void AllSources::EmitMessage(std::ostream &o,
+void AllSources::EmitMessage(llvm::raw_ostream &o,
const std::optional<ProvenanceRange> &range, const std::string &message,
bool echoSourceLine) const {
if (!range) {
}
}
-static void DumpRange(std::ostream &o, const ProvenanceRange &r) {
+static void DumpRange(llvm::raw_ostream &o, const ProvenanceRange &r) {
o << "[" << r.start().offset() << ".." << r.Last().offset() << "] ("
<< r.size() << " bytes)";
}
-std::ostream &ProvenanceRangeToOffsetMappings::Dump(std::ostream &o) const {
+llvm::raw_ostream &ProvenanceRangeToOffsetMappings::Dump(
+ llvm::raw_ostream &o) const {
for (const auto &m : map_) {
o << "provenances ";
DumpRange(o, m.first);
return o;
}
-std::ostream &OffsetToProvenanceMappings::Dump(std::ostream &o) const {
+llvm::raw_ostream &OffsetToProvenanceMappings::Dump(
+ llvm::raw_ostream &o) const {
for (const ContiguousProvenanceMapping &m : provenanceMap_) {
std::size_t n{m.range.size()};
o << "offsets [" << m.start << ".." << (m.start + n - 1)
return o;
}
-std::ostream &AllSources::Dump(std::ostream &o) const {
+llvm::raw_ostream &AllSources::Dump(llvm::raw_ostream &o) const {
o << "AllSources range_ ";
DumpRange(o, range_);
o << '\n';
o << "compiler '" << ins.text << '\'';
if (ins.text.length() == 1) {
int ch = ins.text[0];
- o << " (0x" << std::hex << (ch & 0xff) << std::dec << ")";
+ o << "(0x";
+ o.write_hex(ch & 0xff) << ")";
}
},
},
return o;
}
-std::ostream &CookedSource::Dump(std::ostream &o) const {
+llvm::raw_ostream &CookedSource::Dump(llvm::raw_ostream &o) const {
o << "CookedSource:\n";
allSources_.Dump(o);
o << "CookedSource::provenanceMap_:\n";
#include "flang/Parser/source.h"
#include "flang/Common/idioms.h"
#include "flang/Parser/char-buffer.h"
+#include "llvm/Support/Errno.h"
+#include "llvm/Support/raw_ostream.h"
#include <algorithm>
-#include <cerrno>
#include <cstddef>
#include <cstring>
#include <fcntl.h>
return wrote;
}
-bool SourceFile::Open(std::string path, std::stringstream *error) {
+bool SourceFile::Open(std::string path, llvm::raw_ostream &error) {
Close();
path_ = path;
std::string errorPath{"'"s + path + "'"};
errno = 0;
fileDescriptor_ = open(path.c_str(), O_RDONLY);
if (fileDescriptor_ < 0) {
- *error << "Could not open " << errorPath << ": " << std::strerror(errno);
+ error << "Could not open " << errorPath << ": "
+ << llvm::sys::StrError(errno);
return false;
}
++openFileDescriptors;
return ReadFile(errorPath, error);
}
-bool SourceFile::ReadStandardInput(std::stringstream *error) {
+bool SourceFile::ReadStandardInput(llvm::raw_ostream &error) {
Close();
path_ = "standard input";
fileDescriptor_ = 0;
return ReadFile(path_, error);
}
-bool SourceFile::ReadFile(std::string errorPath, std::stringstream *error) {
+bool SourceFile::ReadFile(std::string errorPath, llvm::raw_ostream &error) {
struct stat statbuf;
if (fstat(fileDescriptor_, &statbuf) != 0) {
- *error << "fstat failed on " << errorPath << ": " << std::strerror(errno);
+ error << "fstat failed on " << errorPath << ": "
+ << llvm::sys::StrError(errno);
Close();
return false;
}
if (S_ISDIR(statbuf.st_mode)) {
- *error << errorPath << " is a directory";
+ error << errorPath << " is a directory";
Close();
return false;
}
char *to{buffer.FreeSpace(count)};
ssize_t got{read(fileDescriptor_, to, count)};
if (got < 0) {
- *error << "could not read " << errorPath << ": " << std::strerror(errno);
+ error << "could not read " << errorPath << ": "
+ << llvm::sys::StrError(errno);
Close();
return false;
}
#include "token-sequence.h"
#include "flang/Parser/characters.h"
+#include "llvm/Support/raw_ostream.h"
namespace Fortran::parser {
Put(s.data(), s.size(), provenance);
}
-void TokenSequence::Put(const std::stringstream &ss, Provenance provenance) {
+void TokenSequence::Put(llvm::raw_string_ostream &ss, Provenance provenance) {
Put(ss.str(), provenance);
}
cooked.PutProvenanceMappings(provenances_);
}
-void TokenSequence::Dump(std::ostream &o) const {
+void TokenSequence::Dump(llvm::raw_ostream &o) const {
o << "TokenSequence has " << char_.size() << " chars; nextStart_ "
<< nextStart_ << '\n';
for (std::size_t j{0}; j < start_.size(); ++j) {
#include "flang/Parser/provenance.h"
#include <cstddef>
#include <cstring>
-#include <ostream>
#include <string>
#include <utility>
#include <vector>
+namespace llvm {
+class raw_ostream;
+}
+
namespace Fortran::parser {
// Buffers a contiguous sequence of characters that has been partitioned into
void Put(const char *, std::size_t, Provenance);
void Put(const CharBlock &, Provenance);
void Put(const std::string &, Provenance);
- void Put(const std::stringstream &, Provenance);
+ void Put(llvm::raw_string_ostream &, Provenance);
Provenance GetTokenProvenance(
std::size_t token, std::size_t offset = 0) const;
TokenSequence &RemoveRedundantBlanks(std::size_t firstChar = 0);
TokenSequence &ClipComment(bool skipFirst = false);
void Emit(CookedSource &) const;
- void Dump(std::ostream &) const;
+ void Dump(llvm::raw_ostream &) const;
private:
std::size_t TokenBytes(std::size_t token) const {
#include "flang/Parser/characters.h"
#include "flang/Parser/parse-tree-visitor.h"
#include "flang/Parser/parse-tree.h"
+#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cinttypes>
#include <cstddef>
class UnparseVisitor {
public:
- UnparseVisitor(std::ostream &out, int indentationAmount, Encoding encoding,
- bool capitalize, bool backslashEscapes, preStatementType *preStatement,
- AnalyzedObjectsAsFortran *asFortran)
+ UnparseVisitor(llvm::raw_ostream &out, int indentationAmount,
+ Encoding encoding, bool capitalize, bool backslashEscapes,
+ preStatementType *preStatement, AnalyzedObjectsAsFortran *asFortran)
: out_{out}, indentationAmount_{indentationAmount}, encoding_{encoding},
capitalizeKeywords_{capitalize}, backslashEscapes_{backslashEscapes},
preStatement_{preStatement}, asFortran_{asFortran} {}
structureComponents_.clear();
}
- std::ostream &out_;
+ llvm::raw_ostream &out_;
int indent_{0};
const int indentationAmount_{1};
int column_{1};
void UnparseVisitor::Word(const std::string &str) { Word(str.c_str()); }
-void Unparse(std::ostream &out, const Program &program, Encoding encoding,
+void Unparse(llvm::raw_ostream &out, const Program &program, Encoding encoding,
bool capitalizeKeywords, bool backslashEscapes,
preStatementType *preStatement, AnalyzedObjectsAsFortran *asFortran) {
UnparseVisitor visitor{out, 1, encoding, capitalizeKeywords, backslashEscapes,
#include "flang/Semantics/attr.h"
#include "flang/Common/idioms.h"
-#include <ostream>
+#include "llvm/Support/raw_ostream.h"
#include <stddef.h>
namespace Fortran::semantics {
}
}
-std::ostream &operator<<(std::ostream &o, Attr attr) {
+llvm::raw_ostream &operator<<(llvm::raw_ostream &o, Attr attr) {
return o << AttrToString(attr);
}
-std::ostream &operator<<(std::ostream &o, const Attrs &attrs) {
+llvm::raw_ostream &operator<<(llvm::raw_ostream &o, const Attrs &attrs) {
std::size_t n{attrs.count()};
std::size_t seen{0};
for (std::size_t j{0}; seen < n; ++j) {
#include "flang/Semantics/semantics.h"
#include "flang/Semantics/symbol.h"
#include "flang/Semantics/tools.h"
+#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <functional>
#include <optional>
#include <set>
-#include <sstream>
// Typedef for optional generic expressions (ubiquitous in this file)
using MaybeExpr =
// Find and return a user-defined assignment
std::optional<ProcedureRef> TryDefinedAssignment();
std::optional<ProcedureRef> GetDefinedAssignmentProc();
- void Dump(std::ostream &);
+ void Dump(llvm::raw_ostream &);
private:
MaybeExpr TryDefinedOp(
x.typedExpr.reset(new GenericExprWrapper{std::move(result)});
if (!x.typedExpr->v) {
if (!context_.AnyFatalError()) {
- std::stringstream dump;
+ std::string buf;
+ llvm::raw_string_ostream dump{buf};
parser::DumpTree(dump, x);
Say("Internal error: Expression analysis failed on: %s"_err_en_US,
dump.str());
const MaybeExpr &result, TypeCategory category, bool defaultKind) {
if (result) {
if (auto type{result->GetType()}) {
- if (type->category() != category) { // C885
+ if (type->category() != category) { // C885
Say(at, "Must have %s type, but is %s"_err_en_US,
ToUpperCase(EnumToString(category)),
ToUpperCase(type->AsFortran()));
}
}
-void ArgumentAnalyzer::Dump(std::ostream &os) {
+void ArgumentAnalyzer::Dump(llvm::raw_ostream &os) {
os << "source_: " << source_.ToString() << " fatalErrors_ = " << fatalErrors_
<< '\n';
for (const auto &actual : actuals_) {
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <fstream>
-#include <ostream>
#include <set>
#include <string_view>
#include <vector>
static std::optional<SourceName> GetSubmoduleParent(const parser::Program &);
static SymbolVector CollectSymbols(const Scope &);
-static void PutEntity(std::ostream &, const Symbol &);
-static void PutObjectEntity(std::ostream &, const Symbol &);
-static void PutProcEntity(std::ostream &, const Symbol &);
-static void PutPassName(std::ostream &, const std::optional<SourceName> &);
-static void PutTypeParam(std::ostream &, const Symbol &);
+static void PutEntity(llvm::raw_ostream &, const Symbol &);
+static void PutObjectEntity(llvm::raw_ostream &, const Symbol &);
+static void PutProcEntity(llvm::raw_ostream &, const Symbol &);
+static void PutPassName(llvm::raw_ostream &, const std::optional<SourceName> &);
+static void PutTypeParam(llvm::raw_ostream &, const Symbol &);
static void PutEntity(
- std::ostream &, const Symbol &, std::function<void()>, Attrs);
-static void PutInit(std::ostream &, const Symbol &, const MaybeExpr &);
-static void PutInit(std::ostream &, const MaybeIntExpr &);
-static void PutBound(std::ostream &, const Bound &);
-static std::ostream &PutAttrs(std::ostream &, Attrs,
+ llvm::raw_ostream &, const Symbol &, std::function<void()>, Attrs);
+static void PutInit(llvm::raw_ostream &, const Symbol &, const MaybeExpr &);
+static void PutInit(llvm::raw_ostream &, const MaybeIntExpr &);
+static void PutBound(llvm::raw_ostream &, const Bound &);
+static llvm::raw_ostream &PutAttrs(llvm::raw_ostream &, Attrs,
const MaybeExpr & = std::nullopt, std::string before = ","s,
std::string after = ""s);
-static std::ostream &PutAttr(std::ostream &, Attr);
-static std::ostream &PutType(std::ostream &, const DeclTypeSpec &);
-static std::ostream &PutLower(std::ostream &, const std::string &);
+
+static llvm::raw_ostream &PutAttr(llvm::raw_ostream &, Attr);
+static llvm::raw_ostream &PutType(llvm::raw_ostream &, const DeclTypeSpec &);
+static llvm::raw_ostream &PutLower(llvm::raw_ostream &, const std::string &);
static std::error_code WriteFile(
const std::string &, const std::string &, bool = true);
static bool FileContentsMatch(
// Return the entire body of the module file
// and clear saved uses, decls, and contains.
std::string ModFileWriter::GetAsString(const Symbol &symbol) {
- std::stringstream all;
+ std::string buf;
+ llvm::raw_string_ostream all{buf};
auto &details{symbol.get<ModuleDetails>()};
if (!details.isSubmodule()) {
all << "module " << symbol.name();
all << ") " << symbol.name();
}
all << '\n' << uses_.str();
- uses_.str(""s);
+ uses_.str().clear();
all << useExtraAttrs_.str();
- useExtraAttrs_.str(""s);
+ useExtraAttrs_.str().clear();
all << decls_.str();
- decls_.str(""s);
+ decls_.str().clear();
auto str{contains_.str()};
- contains_.str(""s);
+ contains_.str().clear();
if (!str.empty()) {
all << "contains\n" << str;
}
// Put out the visible symbols from scope.
void ModFileWriter::PutSymbols(const Scope &scope) {
- std::stringstream typeBindings; // stuff after CONTAINS in derived type
+ std::string buf;
+ llvm::raw_string_ostream typeBindings{
+ buf}; // stuff after CONTAINS in derived type
for (const Symbol &symbol : CollectSymbols(scope)) {
PutSymbol(typeBindings, symbol);
}
// Emit a symbol to decls_, except for bindings in a derived type (type-bound
// procedures, type-bound generics, final procedures) which go to typeBindings.
void ModFileWriter::PutSymbol(
- std::stringstream &typeBindings, const Symbol &symbol) {
+ llvm::raw_ostream &typeBindings, const Symbol &symbol) {
std::visit(
common::visitors{
[&](const ModuleDetails &) { /* should be current module */ },
Attrs prefixAttrs{subprogramPrefixAttrs & attrs};
// emit any non-prefix attributes in an attribute statement
attrs &= ~subprogramPrefixAttrs;
- std::stringstream ss;
+ std::string ssBuf;
+ llvm::raw_string_ostream ss{ssBuf};
PutAttrs(ss, attrs);
if (!ss.str().empty()) {
decls_ << ss.str().substr(1) << "::" << symbol.name() << '\n';
}
bool isInterface{details.isInterface()};
- std::ostream &os{isInterface ? decls_ : contains_};
+ llvm::raw_ostream &os{isInterface ? decls_ : contains_};
if (isInterface) {
os << "interface\n";
}
// walk symbols, collect ones needed
ModFileWriter writer{context_};
- std::stringstream typeBindings;
+ std::string typeBindingsBuf;
+ llvm::raw_string_ostream typeBindings{typeBindingsBuf};
SubprogramSymbolCollector collector{symbol};
collector.Collect();
for (const Symbol &need : collector.symbols()) {
}
}
-static std::ostream &PutGenericName(std::ostream &os, const Symbol &symbol) {
+static llvm::raw_ostream &PutGenericName(
+ llvm::raw_ostream &os, const Symbol &symbol) {
if (IsGenericDefinedOp(symbol)) {
return os << "operator(" << symbol.name() << ')';
} else {
return sorted;
}
-void PutEntity(std::ostream &os, const Symbol &symbol) {
+void PutEntity(llvm::raw_ostream &os, const Symbol &symbol) {
std::visit(
common::visitors{
[&](const ObjectEntityDetails &) { PutObjectEntity(os, symbol); },
symbol.details());
}
-void PutShapeSpec(std::ostream &os, const ShapeSpec &x) {
+void PutShapeSpec(llvm::raw_ostream &os, const ShapeSpec &x) {
if (x.lbound().isAssumed()) {
CHECK(x.ubound().isAssumed());
os << "..";
}
}
}
-void PutShape(std::ostream &os, const ArraySpec &shape, char open, char close) {
+void PutShape(
+ llvm::raw_ostream &os, const ArraySpec &shape, char open, char close) {
if (!shape.empty()) {
os << open;
bool first{true};
}
}
-void PutObjectEntity(std::ostream &os, const Symbol &symbol) {
+void PutObjectEntity(llvm::raw_ostream &os, const Symbol &symbol) {
auto &details{symbol.get<ObjectEntityDetails>()};
PutEntity(os, symbol, [&]() { PutType(os, DEREF(symbol.GetType())); },
symbol.attrs());
os << '\n';
}
-void PutProcEntity(std::ostream &os, const Symbol &symbol) {
+void PutProcEntity(llvm::raw_ostream &os, const Symbol &symbol) {
if (symbol.attrs().test(Attr::INTRINSIC)) {
os << "intrinsic::" << symbol.name() << '\n';
return;
os << '\n';
}
-void PutPassName(std::ostream &os, const std::optional<SourceName> &passName) {
+void PutPassName(
+ llvm::raw_ostream &os, const std::optional<SourceName> &passName) {
if (passName) {
os << ",pass(" << *passName << ')';
}
}
-
-void PutTypeParam(std::ostream &os, const Symbol &symbol) {
+void PutTypeParam(llvm::raw_ostream &os, const Symbol &symbol) {
auto &details{symbol.get<TypeParamDetails>()};
PutEntity(os, symbol,
[&]() {
os << '\n';
}
-void PutInit(std::ostream &os, const Symbol &symbol, const MaybeExpr &init) {
+void PutInit(
+ llvm::raw_ostream &os, const Symbol &symbol, const MaybeExpr &init) {
if (init) {
if (symbol.attrs().test(Attr::PARAMETER) ||
symbol.owner().IsDerivedType()) {
}
}
-void PutInit(std::ostream &os, const MaybeIntExpr &init) {
+void PutInit(llvm::raw_ostream &os, const MaybeIntExpr &init) {
if (init) {
init->AsFortran(os << '=');
}
}
-void PutBound(std::ostream &os, const Bound &x) {
+void PutBound(llvm::raw_ostream &os, const Bound &x) {
if (x.isAssumed()) {
os << '*';
} else if (x.isDeferred()) {
// Write an entity (object or procedure) declaration.
// writeType is called to write out the type.
-void PutEntity(std::ostream &os, const Symbol &symbol,
+void PutEntity(llvm::raw_ostream &os, const Symbol &symbol,
std::function<void()> writeType, Attrs attrs) {
writeType();
MaybeExpr bindName;
// Put out each attribute to os, surrounded by `before` and `after` and
// mapped to lower case.
-std::ostream &PutAttrs(std::ostream &os, Attrs attrs, const MaybeExpr &bindName,
- std::string before, std::string after) {
+llvm::raw_ostream &PutAttrs(llvm::raw_ostream &os, Attrs attrs,
+ const MaybeExpr &bindName, std::string before, std::string after) {
attrs.set(Attr::PUBLIC, false); // no need to write PUBLIC
attrs.set(Attr::EXTERNAL, false); // no need to write EXTERNAL
if (bindName) {
return os;
}
-std::ostream &PutAttr(std::ostream &os, Attr attr) {
+llvm::raw_ostream &PutAttr(llvm::raw_ostream &os, Attr attr) {
return PutLower(os, AttrToString(attr));
}
-std::ostream &PutType(std::ostream &os, const DeclTypeSpec &type) {
+llvm::raw_ostream &PutType(llvm::raw_ostream &os, const DeclTypeSpec &type) {
return PutLower(os, type.AsFortran());
}
-std::ostream &PutLower(std::ostream &os, const std::string &str) {
+llvm::raw_ostream &PutLower(llvm::raw_ostream &os, const std::string &str) {
for (char c : str) {
os << parser::ToLowerCaseLetter(c);
}
sourceFile->path());
return nullptr;
}
-
- parsing.Parse(nullptr);
+ llvm::raw_null_ostream NullStream;
+ parsing.Parse(NullStream);
auto &parseTree{parsing.parseTree()};
if (!parsing.messages().empty() || !parsing.consumedWholeFile() ||
!parseTree) {
#define FORTRAN_SEMANTICS_MOD_FILE_H_
#include "flang/Semantics/attr.h"
-#include <sstream>
#include <string>
namespace Fortran::parser {
class MessageFixedText;
}
+namespace llvm {
+class raw_ostream;
+}
+
namespace Fortran::semantics {
using SourceName = parser::CharBlock;
private:
SemanticsContext &context_;
- std::stringstream uses_;
- std::stringstream useExtraAttrs_; // attrs added to used entity
- std::stringstream decls_;
- std::stringstream contains_;
+ // Buffer to use with raw_string_ostream
+ std::string usesBuf_;
+ std::string useExtraAttrsBuf_;
+ std::string declsBuf_;
+ std::string containsBuf_;
+
+ llvm::raw_string_ostream uses_{usesBuf_};
+ llvm::raw_string_ostream useExtraAttrs_{useExtraAttrsBuf_}; // attrs added to used entity
+ llvm::raw_string_ostream decls_{declsBuf_};
+ llvm::raw_string_ostream contains_{containsBuf_};
void WriteAll(const Scope &);
void WriteOne(const Scope &);
void Write(const Symbol &);
std::string GetAsString(const Symbol &);
void PutSymbols(const Scope &);
- void PutSymbol(std::stringstream &, const Symbol &);
+ void PutSymbol(llvm::raw_ostream &, const Symbol &);
void PutDerivedType(const Symbol &);
void PutSubprogram(const Symbol &);
void PutGeneric(const Symbol &);
#include "flang/Semantics/expression.h"
#include "flang/Semantics/symbol.h"
#include "flang/Semantics/tools.h"
+#include "llvm/Support/raw_ostream.h"
#include <optional>
#include <set>
#include <string>
if (msg) {
auto restorer{common::ScopedSet(lhs_, last)};
if (auto *m{std::get_if<MessageFixedText>(&*msg)}) {
- std::ostringstream ss;
+ std::string buf;
+ llvm::raw_string_ostream ss{buf};
d.AsFortran(ss);
Say(*m, description_, ss.str());
} else {
#include "flang/Semantics/semantics.h"
#include "flang/Semantics/tools.h"
#include <initializer_list>
-#include <ostream>
#include <variant>
namespace Fortran::semantics {
#include "flang/Semantics/symbol.h"
#include "flang/Semantics/tools.h"
#include "flang/Semantics/type.h"
+#include "llvm/Support/raw_ostream.h"
#include <list>
#include <map>
-#include <ostream>
#include <set>
#include <stack>
// the default Fortran mappings nor the mapping defined in parents.
std::map<char, common::Reference<const DeclTypeSpec>> map_;
- friend std::ostream &operator<<(std::ostream &, const ImplicitRules &);
- friend void ShowImplicitRule(std::ostream &, const ImplicitRules &, char);
+ friend llvm::raw_ostream &operator<<(
+ llvm::raw_ostream &, const ImplicitRules &);
+ friend void ShowImplicitRule(
+ llvm::raw_ostream &, const ImplicitRules &, char);
};
// scope -> implicit rules for that scope
}
}
-std::ostream &operator<<(std::ostream &o, const ImplicitRules &implicitRules) {
+llvm::raw_ostream &operator<<(
+ llvm::raw_ostream &o, const ImplicitRules &implicitRules) {
o << "ImplicitRules:\n";
for (char ch = 'a'; ch; ch = ImplicitRules::Incr(ch)) {
ShowImplicitRule(o, implicitRules, ch);
return o;
}
void ShowImplicitRule(
- std::ostream &o, const ImplicitRules &implicitRules, char ch) {
+ llvm::raw_ostream &o, const ImplicitRules &implicitRules, char ch) {
auto it{implicitRules.map_.find(ch)};
if (it != implicitRules.map_.end()) {
o << " " << ch << ": " << *it->second << '\n';
#include <string>
#include <vector>
+namespace llvm {
+class raw_ostream;
+}
+
namespace Fortran::parser {
struct Program;
}
bool ResolveNames(SemanticsContext &, const parser::Program &);
void ResolveSpecificationParts(SemanticsContext &, const Symbol &);
-void DumpSymbols(std::ostream &);
+void DumpSymbols(llvm::raw_ostream &);
}
#include "flang/Parser/characters.h"
#include "flang/Semantics/symbol.h"
#include "flang/Semantics/type.h"
+#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <memory>
-#include <sstream>
namespace Fortran::semantics {
}
std::string EquivalenceObject::AsFortran() const {
- std::stringstream ss;
+ std::string buf;
+ llvm::raw_string_ostream ss{buf};
ss << symbol.name().ToString();
if (!subscripts.empty()) {
char sep{'('};
}
}
-std::ostream &operator<<(std::ostream &os, const Scope &scope) {
+llvm::raw_ostream &operator<<(llvm::raw_ostream &os, const Scope &scope) {
os << Scope::EnumToString(scope.kind()) << " scope: ";
if (auto *symbol{scope.symbol()}) {
os << *symbol << ' ';
#include "flang/Semantics/expression.h"
#include "flang/Semantics/scope.h"
#include "flang/Semantics/symbol.h"
+#include "llvm/Support/raw_ostream.h"
namespace Fortran::semantics {
using NameToSymbolMap = std::map<const char *, SymbolRef>;
-static void DoDumpSymbols(std::ostream &, const Scope &, int indent = 0);
-static void PutIndent(std::ostream &, int indent);
+static void DoDumpSymbols(llvm::raw_ostream &, const Scope &, int indent = 0);
+static void PutIndent(llvm::raw_ostream &, int indent);
static void GetSymbolNames(const Scope &scope, NameToSymbolMap &symbols) {
// Finds all symbol names in the scope without collecting duplicates.
ModFileWriter{context_}.WriteAll();
}
-void Semantics::EmitMessages(std::ostream &os) const {
+void Semantics::EmitMessages(llvm::raw_ostream &os) const {
context_.messages().Emit(os, cooked_);
}
-void Semantics::DumpSymbols(std::ostream &os) {
+void Semantics::DumpSymbols(llvm::raw_ostream &os) {
DoDumpSymbols(os, context_.globalScope());
}
-void Semantics::DumpSymbolsSources(std::ostream &os) const {
+void Semantics::DumpSymbolsSources(llvm::raw_ostream &os) const {
NameToSymbolMap symbols;
GetSymbolNames(context_.globalScope(), symbols);
for (const auto &pair : symbols) {
}
}
-void DoDumpSymbols(std::ostream &os, const Scope &scope, int indent) {
+void DoDumpSymbols(llvm::raw_ostream &os, const Scope &scope, int indent) {
PutIndent(os, indent);
os << Scope::EnumToString(scope.kind()) << " scope:";
if (const auto *symbol{scope.symbol()}) {
--indent;
}
-static void PutIndent(std::ostream &os, int indent) {
+static void PutIndent(llvm::raw_ostream &os, int indent) {
for (int i = 0; i < indent; ++i) {
os << " ";
}
#include "flang/Semantics/scope.h"
#include "flang/Semantics/semantics.h"
#include "flang/Semantics/tools.h"
-#include <ostream>
+#include "llvm/Support/raw_ostream.h"
#include <string>
namespace Fortran::semantics {
template<typename T>
-static void DumpOptional(std::ostream &os, const char *label, const T &x) {
+static void DumpOptional(llvm::raw_ostream &os, const char *label, const T &x) {
if (x) {
os << ' ' << label << ':' << *x;
}
}
template<typename T>
-static void DumpExpr(std::ostream &os, const char *label,
+static void DumpExpr(llvm::raw_ostream &os, const char *label,
const std::optional<evaluate::Expr<T>> &x) {
if (x) {
x->AsFortran(os << ' ' << label << ':');
}
}
-static void DumpBool(std::ostream &os, const char *label, bool x) {
+static void DumpBool(llvm::raw_ostream &os, const char *label, bool x) {
if (x) {
os << ' ' << label;
}
}
-static void DumpSymbolVector(std::ostream &os, const SymbolVector &list) {
+static void DumpSymbolVector(llvm::raw_ostream &os, const SymbolVector &list) {
char sep{' '};
for (const Symbol &elem : list) {
os << sep << elem.name();
}
}
-static void DumpType(std::ostream &os, const Symbol &symbol) {
+static void DumpType(llvm::raw_ostream &os, const Symbol &symbol) {
if (const auto *type{symbol.GetType()}) {
os << *type << ' ';
}
}
-static void DumpType(std::ostream &os, const DeclTypeSpec *type) {
+static void DumpType(llvm::raw_ostream &os, const DeclTypeSpec *type) {
if (type) {
os << ' ' << *type;
}
}
template<typename T>
-static void DumpList(std::ostream &os, const char *label, const T &list) {
+static void DumpList(llvm::raw_ostream &os, const char *label, const T &list) {
if (!list.empty()) {
os << ' ' << label << ':';
char sep{' '};
scope_ = scope;
}
-std::ostream &operator<<(std::ostream &os, const SubprogramDetails &x) {
+llvm::raw_ostream &operator<<(
+ llvm::raw_ostream &os, const SubprogramDetails &x) {
DumpBool(os, "isInterface", x.isInterface_);
DumpExpr(os, "bindName", x.bindName_);
if (x.result_) {
ObjectEntityDetails::ObjectEntityDetails(EntityDetails &&d)
: EntityDetails(d) {}
-std::ostream &operator<<(std::ostream &os, const EntityDetails &x) {
+llvm::raw_ostream &operator<<(llvm::raw_ostream &os, const EntityDetails &x) {
DumpBool(os, "dummy", x.isDummy());
DumpBool(os, "funcResult", x.isFuncResult());
if (x.type()) {
return os;
}
-std::ostream &operator<<(std::ostream &os, const ObjectEntityDetails &x) {
+llvm::raw_ostream &operator<<(
+ llvm::raw_ostream &os, const ObjectEntityDetails &x) {
os << *static_cast<const EntityDetails *>(&x);
DumpList(os, "shape", x.shape());
DumpList(os, "coshape", x.coshape());
return os;
}
-std::ostream &operator<<(std::ostream &os, const AssocEntityDetails &x) {
+llvm::raw_ostream &operator<<(
+ llvm::raw_ostream &os, const AssocEntityDetails &x) {
os << *static_cast<const EntityDetails *>(&x);
DumpExpr(os, "expr", x.expr());
return os;
}
-std::ostream &operator<<(std::ostream &os, const ProcEntityDetails &x) {
+llvm::raw_ostream &operator<<(
+ llvm::raw_ostream &os, const ProcEntityDetails &x) {
if (auto *symbol{x.interface_.symbol()}) {
os << ' ' << symbol->name();
} else {
return os;
}
-std::ostream &operator<<(std::ostream &os, const DerivedTypeDetails &x) {
+llvm::raw_ostream &operator<<(
+ llvm::raw_ostream &os, const DerivedTypeDetails &x) {
DumpBool(os, "sequence", x.sequence_);
DumpList(os, "components", x.componentNames_);
return os;
}
-std::ostream &operator<<(std::ostream &os, const Details &details) {
+llvm::raw_ostream &operator<<(llvm::raw_ostream &os, const Details &details) {
os << DetailsToString(details);
std::visit(
common::visitors{
return os;
}
-std::ostream &operator<<(std::ostream &o, Symbol::Flag flag) {
+llvm::raw_ostream &operator<<(llvm::raw_ostream &o, Symbol::Flag flag) {
return o << Symbol::EnumToString(flag);
}
-std::ostream &operator<<(std::ostream &o, const Symbol::Flags &flags) {
+llvm::raw_ostream &operator<<(
+ llvm::raw_ostream &o, const Symbol::Flags &flags) {
std::size_t n{flags.count()};
std::size_t seen{0};
for (std::size_t j{0}; seen < n; ++j) {
return o;
}
-std::ostream &operator<<(std::ostream &os, const Symbol &symbol) {
+llvm::raw_ostream &operator<<(llvm::raw_ostream &os, const Symbol &symbol) {
os << symbol.name();
if (!symbol.attrs().empty()) {
os << ", " << symbol.attrs();
// Output a unique name for a scope by qualifying it with the names of
// parent scopes. For scopes without corresponding symbols, use the kind
// with an index (e.g. Block1, Block2, etc.).
-static void DumpUniqueName(std::ostream &os, const Scope &scope) {
+static void DumpUniqueName(llvm::raw_ostream &os, const Scope &scope) {
if (!scope.IsGlobal()) {
DumpUniqueName(os, scope.parent());
os << '/';
// Dump a symbol for UnparseWithSymbols. This will be used for tests so the
// format should be reasonably stable.
-std::ostream &DumpForUnparse(
- std::ostream &os, const Symbol &symbol, bool isDef) {
+llvm::raw_ostream &DumpForUnparse(
+ llvm::raw_ostream &os, const Symbol &symbol, bool isDef) {
DumpUniqueName(os, symbol.owner());
os << '/' << symbol.name();
if (isDef) {
#include "flang/Semantics/symbol.h"
#include "flang/Semantics/tools.h"
#include "flang/Semantics/type.h"
+#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <set>
-#include <sstream>
#include <variant>
namespace Fortran::semantics {
// If an analyzed expr or assignment is missing, dump the node and die.
template<typename T> static void CheckMissingAnalysis(bool absent, const T &x) {
if (absent) {
- std::ostringstream ss;
+ std::string buf;
+ llvm::raw_string_ostream ss{buf};
ss << "node has not been analyzed:\n";
parser::DumpTree(ss, x);
common::die(ss.str().c_str());
#include "flang/Semantics/scope.h"
#include "flang/Semantics/symbol.h"
#include "flang/Semantics/tools.h"
-#include <ostream>
-#include <sstream>
+#include "llvm/Support/raw_ostream.h"
namespace Fortran::semantics {
}
std::string DerivedTypeSpec::AsFortran() const {
- std::stringstream ss;
+ std::string buf;
+ llvm::raw_string_ostream ss{buf};
ss << name_;
if (!rawParameters_.empty()) {
CHECK(parameters_.empty());
return ss.str();
}
-std::ostream &operator<<(std::ostream &o, const DerivedTypeSpec &x) {
+llvm::raw_ostream &operator<<(llvm::raw_ostream &o, const DerivedTypeSpec &x) {
return o << x.AsFortran();
}
Bound::Bound(int bound) : expr_{bound} {}
-std::ostream &operator<<(std::ostream &o, const Bound &x) {
+llvm::raw_ostream &operator<<(llvm::raw_ostream &o, const Bound &x) {
if (x.isAssumed()) {
o << '*';
} else if (x.isDeferred()) {
return o;
}
-std::ostream &operator<<(std::ostream &o, const ShapeSpec &x) {
+llvm::raw_ostream &operator<<(llvm::raw_ostream &o, const ShapeSpec &x) {
if (x.lb_.isAssumed()) {
CHECK(x.ub_.isAssumed());
o << "..";
return Rank() == 1 && front().lbound().isAssumed();
}
-std::ostream &operator<<(std::ostream &os, const ArraySpec &arraySpec) {
+llvm::raw_ostream &operator<<(
+ llvm::raw_ostream &os, const ArraySpec &arraySpec) {
char sep{'('};
for (auto &shape : arraySpec) {
os << sep << shape;
case Category::Deferred: return ":";
case Category::Explicit:
if (expr_) {
- std::stringstream ss;
+ std::string buf;
+ llvm::raw_string_ostream ss{buf};
expr_->AsFortran(ss);
return ss.str();
} else {
}
}
-std::ostream &operator<<(std::ostream &o, const ParamValue &x) {
+llvm::raw_ostream &operator<<(llvm::raw_ostream &o, const ParamValue &x) {
return o << x.AsFortran();
}
}
static std::string KindAsFortran(const KindExpr &kind) {
- std::stringstream ss;
+ std::string buf;
+ llvm::raw_string_ostream ss{buf};
if (auto k{evaluate::ToInt64(kind)}) {
ss << *k; // emit unsuffixed kind code
} else {
KindAsFortran(kind_) + ')';
}
-std::ostream &operator<<(std::ostream &os, const IntrinsicTypeSpec &x) {
+llvm::raw_ostream &operator<<(
+ llvm::raw_ostream &os, const IntrinsicTypeSpec &x) {
return os << x.AsFortran();
}
return "CHARACTER(" + length_.AsFortran() + ',' + KindAsFortran(kind()) + ')';
}
-std::ostream &operator<<(std::ostream &os, const CharacterTypeSpec &x) {
+llvm::raw_ostream &operator<<(
+ llvm::raw_ostream &os, const CharacterTypeSpec &x) {
return os << x.AsFortran();
}
}
}
-std::ostream &operator<<(std::ostream &o, const DeclTypeSpec &x) {
+llvm::raw_ostream &operator<<(llvm::raw_ostream &o, const DeclTypeSpec &x) {
return o << x.AsFortran();
}
#include "flang/Parser/parse-tree.h"
#include "flang/Parser/unparse.h"
#include "flang/Semantics/symbol.h"
+#include "llvm/Support/raw_ostream.h"
#include <map>
-#include <ostream>
#include <set>
namespace Fortran::semantics {
class SymbolDumpVisitor {
public:
// Write out symbols referenced at this statement.
- void PrintSymbols(const parser::CharBlock &, std::ostream &, int);
+ void PrintSymbols(const parser::CharBlock &, llvm::raw_ostream &, int);
template<typename T> bool Pre(const T &) { return true; }
template<typename T> void Post(const T &) {}
std::optional<SourceName> currStmt_; // current statement we are processing
std::multimap<const char *, const Symbol *> symbols_; // location to symbol
std::set<const Symbol *> symbolsDefined_; // symbols that have been processed
- void Indent(std::ostream &, int) const;
+ void Indent(llvm::raw_ostream &, int) const;
};
void SymbolDumpVisitor::PrintSymbols(
- const parser::CharBlock &location, std::ostream &out, int indent) {
+ const parser::CharBlock &location, llvm::raw_ostream &out, int indent) {
std::set<const Symbol *> done; // prevent duplicates on this line
auto range{symbols_.equal_range(location.begin())};
for (auto it{range.first}; it != range.second; ++it) {
}
}
-void SymbolDumpVisitor::Indent(std::ostream &out, int indent) const {
+void SymbolDumpVisitor::Indent(llvm::raw_ostream &out, int indent) const {
for (int i{0}; i < indent; ++i) {
out << ' ';
}
}
}
-void UnparseWithSymbols(std::ostream &out, const parser::Program &program,
+void UnparseWithSymbols(llvm::raw_ostream &out, const parser::Program &program,
parser::Encoding encoding) {
SymbolDumpVisitor visitor;
parser::Walk(program, visitor);
parser::preStatementType preStatement{
- [&](const parser::CharBlock &location, std::ostream &out, int indent) {
- visitor.PrintSymbols(location, out, indent);
- }};
+ [&](const parser::CharBlock &location, llvm::raw_ostream &out,
+ int indent) { visitor.PrintSymbols(location, out, indent); }};
parser::Unparse(out, program, encoding, false, true, &preStatement);
}
}
// This file defines Dump routines available for calling from the debugger.
// Each is based on operator<< for that type. There are overloadings for
-// reference and pointer, and for dumping to a provided ostream or cerr.
+// reference and pointer, and for dumping to a provided raw_ostream or errs().
#ifdef DEBUGF18
-#include <iostream>
+#include "llvm/Support/raw_ostream.h"
#define DEFINE_DUMP(ns, name) \
namespace ns { \
class name; \
- std::ostream &operator<<(std::ostream &, const name &); \
+ llvm::raw_ostream &operator<<(llvm::raw_ostream &, const name &); \
} \
- void Dump(std::ostream &os, const ns::name &x) { os << x << '\n'; } \
- void Dump(std::ostream &os, const ns::name *x) { \
+ void Dump(llvm::raw_ostream &os, const ns::name &x) { os << x << '\n'; } \
+ void Dump(llvm::raw_ostream &os, const ns::name *x) { \
if (x == nullptr) \
os << "null\n"; \
else \
Dump(os, *x); \
} \
- void Dump(const ns::name &x) { Dump(std::cerr, x); } \
- void Dump(const ns::name *x) { Dump(std::cerr, *x); }
+ void Dump(const ns::name &x) { Dump(llvm::errs(), x); } \
+ void Dump(const ns::name *x) { Dump(llvm::errs(), *x); }
namespace Fortran {
DEFINE_DUMP(parser, Name)
#include "flang/Parser/parsing.h"
#include "flang/Parser/provenance.h"
#include "flang/Parser/unparse.h"
-#include <cerrno>
+#include "llvm/Support/Errno.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/raw_ostream.h"
#include <cstdio>
#include <cstring>
#include <fstream>
-#include <iostream>
#include <list>
#include <memory>
#include <optional>
void Exec(std::vector<char *> &argv, bool verbose = false) {
if (verbose) {
for (size_t j{0}; j < argv.size(); ++j) {
- std::cerr << (j > 0 ? " " : "") << argv[j];
+ llvm::errs() << (j > 0 ? " " : "") << argv[j];
}
- std::cerr << '\n';
+ llvm::errs() << '\n';
}
argv.push_back(nullptr);
execvp(argv[0], &argv[0]);
- std::cerr << "execvp(" << argv[0] << ") failed: " << std::strerror(errno)
- << '\n';
+ llvm::errs() << "execvp(" << argv[0]
+ << ") failed: " << llvm::sys::StrError(errno) << '\n';
exit(EXIT_FAILURE);
}
parsing.Prescan(path, options);
if (!parsing.messages().empty() &&
(driver.warningsAreErrors || parsing.messages().AnyFatalError())) {
- std::cerr << driver.prefix << "could not scan " << path << '\n';
- parsing.messages().Emit(std::cerr, parsing.cooked());
+ llvm::errs() << driver.prefix << "could not scan " << path << '\n';
+ parsing.messages().Emit(llvm::errs(), parsing.cooked());
exitStatus = EXIT_FAILURE;
return {};
}
if (driver.dumpProvenance) {
- parsing.DumpProvenance(std::cout);
+ parsing.DumpProvenance(llvm::outs());
return {};
}
if (driver.dumpCookedChars) {
- parsing.DumpCookedChars(std::cout);
+ parsing.DumpCookedChars(llvm::outs());
return {};
}
- parsing.Parse(&std::cout);
+ parsing.Parse(llvm::outs());
auto stop{CPUseconds()};
if (driver.timeParse) {
if (canTime) {
- std::cout << "parse time for " << path << ": " << (stop - start)
- << " CPU seconds\n";
+ llvm::outs() << "parse time for " << path << ": " << (stop - start)
+ << " CPU seconds\n";
} else {
- std::cout << "no timing information due to lack of clock_gettime()\n";
+ llvm::outs() << "no timing information due to lack of clock_gettime()\n";
}
}
parsing.ClearLog();
- parsing.messages().Emit(std::cerr, parsing.cooked());
+ parsing.messages().Emit(llvm::errs(), parsing.cooked());
if (!parsing.consumedWholeFile()) {
- parsing.EmitMessage(
- std::cerr, parsing.finalRestingPlace(), "parser FAIL (final position)");
+ parsing.EmitMessage(llvm::errs(), parsing.finalRestingPlace(),
+ "parser FAIL (final position)");
exitStatus = EXIT_FAILURE;
return {};
}
if ((!parsing.messages().empty() &&
(driver.warningsAreErrors || parsing.messages().AnyFatalError())) ||
!parsing.parseTree()) {
- std::cerr << driver.prefix << "could not parse " << path << '\n';
+ llvm::errs() << driver.prefix << "could not parse " << path << '\n';
exitStatus = EXIT_FAILURE;
return {};
}
auto &parseTree{*parsing.parseTree()};
if (driver.dumpParseTree) {
- Fortran::parser::DumpTree(std::cout, parseTree);
+ Fortran::parser::DumpTree(llvm::outs(), parseTree);
return {};
}
if (driver.dumpUnparse) {
- Unparse(std::cout, parseTree, driver.encoding, true /*capitalize*/,
+ Unparse(llvm::outs(), parseTree, driver.encoding, true /*capitalize*/,
options.features.IsEnabled(
Fortran::common::LanguageFeature::BackslashEscapes));
return {};
std::snprintf(tmpSourcePath, sizeof tmpSourcePath, "/tmp/f18-%lx.f90",
static_cast<unsigned long>(getpid()));
{
- std::ofstream tmpSource;
- tmpSource.open(tmpSourcePath);
+ std::error_code EC;
+ llvm::raw_fd_ostream tmpSource(tmpSourcePath, EC, llvm::sys::fs::F_None);
+ if (EC) {
+ llvm::errs() << EC.message();
+ std::exit(EXIT_FAILURE);
+ }
Unparse(tmpSource, parseTree, driver.encoding, true /*capitalize*/,
options.features.IsEnabled(
Fortran::common::LanguageFeature::BackslashEscapes));
} else if (arg == "-i8" || arg == "-fdefault-integer-8") {
defaultKinds.set_defaultIntegerKind(8);
} else if (arg == "-help" || arg == "--help" || arg == "-?") {
- std::cerr
+ llvm::errs()
<< "f18-parse-demo options:\n"
<< " -Mfixed | -Mfree force the source form\n"
<< " -Mextend 132-column fixed form\n"
<< "Other options are passed through to the $F18_FC compiler.\n";
return exitStatus;
} else if (arg == "-V") {
- std::cerr << "\nf18-parse-demo\n";
+ llvm::errs() << "\nf18-parse-demo\n";
return exitStatus;
} else {
driver.fcArgs.push_back(arg);
#include "flang/Semantics/expression.h"
#include "flang/Semantics/semantics.h"
#include "flang/Semantics/unparse-with-symbols.h"
+#include "llvm/Support/Errno.h"
+#include "llvm/Support/FileSystem.h"
#include "llvm/Support/raw_ostream.h"
-#include <cerrno>
#include <cstdio>
#include <cstring>
#include <fstream>
-#include <iostream>
#include <list>
#include <memory>
#include <optional>
void MeasureParseTree(const Fortran::parser::Program &program) {
MeasurementVisitor visitor;
Fortran::parser::Walk(program, visitor);
- std::cout << "Parse tree comprises " << visitor.objects
- << " objects and occupies " << visitor.bytes << " total bytes.\n";
+ llvm::outs() << "Parse tree comprises " << visitor.objects
+ << " objects and occupies " << visitor.bytes
+ << " total bytes.\n";
}
std::vector<std::string> filesToDelete;
void Exec(std::vector<char *> &argv, bool verbose = false) {
if (verbose) {
for (size_t j{0}; j < argv.size(); ++j) {
- std::cerr << (j > 0 ? " " : "") << argv[j];
+ llvm::errs() << (j > 0 ? " " : "") << argv[j];
}
- std::cerr << '\n';
+ llvm::errs() << '\n';
}
argv.push_back(nullptr);
execvp(argv[0], &argv[0]);
- std::cerr << "execvp(" << argv[0] << ") failed: " << std::strerror(errno)
- << '\n';
+ llvm::errs() << "execvp(" << argv[0]
+ << ") failed: " << llvm::sys::StrError(errno) << '\n';
exit(EXIT_FAILURE);
}
int exitStatus{EXIT_SUCCESS};
static Fortran::parser::AnalyzedObjectsAsFortran asFortran{
- [](std::ostream &o, const Fortran::evaluate::GenericExprWrapper &x) {
+ [](llvm::raw_ostream &o, const Fortran::evaluate::GenericExprWrapper &x) {
if (x.v) {
x.v->AsFortran(o);
} else {
o << "(bad expression)";
}
},
- [](std::ostream &o, const Fortran::evaluate::GenericAssignmentWrapper &x) {
+ [](llvm::raw_ostream &o,
+ const Fortran::evaluate::GenericAssignmentWrapper &x) {
if (x.v) {
x.v->AsFortran(o);
} else {
o << "(bad assignment)";
}
},
- [](std::ostream &o, const Fortran::evaluate::ProcedureRef &x) {
+ [](llvm::raw_ostream &o, const Fortran::evaluate::ProcedureRef &x) {
x.AsFortran(o << "CALL ");
},
};
parsing.Prescan(path, options);
if (!parsing.messages().empty() &&
(driver.warningsAreErrors || parsing.messages().AnyFatalError())) {
- std::cerr << driver.prefix << "could not scan " << path << '\n';
- parsing.messages().Emit(std::cerr, parsing.cooked());
+ llvm::errs() << driver.prefix << "could not scan " << path << '\n';
+ parsing.messages().Emit(llvm::errs(), parsing.cooked());
exitStatus = EXIT_FAILURE;
return {};
}
if (driver.dumpProvenance) {
- parsing.DumpProvenance(std::cout);
+ parsing.DumpProvenance(llvm::outs());
return {};
}
if (driver.dumpCookedChars) {
- parsing.messages().Emit(std::cerr, parsing.cooked());
- parsing.DumpCookedChars(std::cout);
+ parsing.messages().Emit(llvm::errs(), parsing.cooked());
+ parsing.DumpCookedChars(llvm::outs());
return {};
}
- parsing.Parse(&std::cout);
+ parsing.Parse(llvm::outs());
if (options.instrumentedParse) {
- parsing.DumpParsingLog(std::cout);
+ parsing.DumpParsingLog(llvm::outs());
return {};
}
parsing.ClearLog();
- parsing.messages().Emit(std::cerr, parsing.cooked());
+ parsing.messages().Emit(llvm::errs(), parsing.cooked());
if (!parsing.consumedWholeFile()) {
- parsing.EmitMessage(
- std::cerr, parsing.finalRestingPlace(), "parser FAIL (final position)");
+ parsing.EmitMessage(llvm::errs(), parsing.finalRestingPlace(),
+ "parser FAIL (final position)");
exitStatus = EXIT_FAILURE;
return {};
}
if ((!parsing.messages().empty() &&
(driver.warningsAreErrors || parsing.messages().AnyFatalError())) ||
!parsing.parseTree()) {
- std::cerr << driver.prefix << "could not parse " << path << '\n';
+ llvm::errs() << driver.prefix << "could not parse " << path << '\n';
exitStatus = EXIT_FAILURE;
return {};
}
Fortran::semantics::Semantics semantics{semanticsContext, parseTree,
parsing.cooked(), driver.debugModuleWriter};
semantics.Perform();
- semantics.EmitMessages(std::cerr);
+ semantics.EmitMessages(llvm::errs());
if (driver.dumpSymbols) {
- semantics.DumpSymbols(std::cout);
+ semantics.DumpSymbols(llvm::outs());
}
if (semantics.AnyFatalError()) {
- std::cerr << driver.prefix << "semantic errors in " << path << '\n';
+ llvm::errs() << driver.prefix << "semantic errors in " << path << '\n';
exitStatus = EXIT_FAILURE;
if (driver.dumpParseTree) {
- Fortran::parser::DumpTree(std::cout, parseTree, &asFortran);
+ Fortran::parser::DumpTree(llvm::outs(), parseTree, &asFortran);
}
return {};
}
if (driver.dumpUnparseWithSymbols) {
Fortran::semantics::UnparseWithSymbols(
- std::cout, parseTree, driver.encoding);
+ llvm::outs(), parseTree, driver.encoding);
return {};
}
if (driver.getSymbolsSources) {
- semantics.DumpSymbolsSources(std::cout);
+ semantics.DumpSymbolsSources(llvm::outs());
return {};
}
if (driver.getDefinition) {
driver.getDefinitionArgs.line,
driver.getDefinitionArgs.startColumn,
driver.getDefinitionArgs.endColumn)}) {
- std::cerr << "String range: >" << cb->ToString() << "<\n";
+ llvm::errs() << "String range: >" << cb->ToString() << "<\n";
if (auto symbol{semanticsContext.FindScope(*cb).FindSymbol(*cb)}) {
- std::cerr << "Found symbol name: " << symbol->name().ToString()
- << "\n";
+ llvm::errs() << "Found symbol name: " << symbol->name().ToString()
+ << "\n";
if (auto sourceInfo{
parsing.cooked().GetSourcePositionRange(symbol->name())}) {
- std::cout << symbol->name().ToString() << ": "
- << sourceInfo->first.file.path() << ", "
- << sourceInfo->first.line << ", "
- << sourceInfo->first.column << "-"
- << sourceInfo->second.column << "\n";
+ llvm::outs() << symbol->name().ToString() << ": "
+ << sourceInfo->first.file.path() << ", "
+ << sourceInfo->first.line << ", "
+ << sourceInfo->first.column << "-"
+ << sourceInfo->second.column << "\n";
exitStatus = EXIT_SUCCESS;
return {};
}
}
}
- std::cerr << "Symbol not found.\n";
+ llvm::errs() << "Symbol not found.\n";
exitStatus = EXIT_FAILURE;
return {};
}
}
if (driver.dumpParseTree) {
- Fortran::parser::DumpTree(std::cout, parseTree, &asFortran);
+ Fortran::parser::DumpTree(llvm::outs(), parseTree, &asFortran);
}
if (driver.dumpUnparse) {
- Unparse(std::cout, parseTree, driver.encoding, true /*capitalize*/,
+ Unparse(llvm::outs(), parseTree, driver.encoding, true /*capitalize*/,
options.features.IsEnabled(
Fortran::common::LanguageFeature::BackslashEscapes),
nullptr /* action before each statement */, &asFortran);
Fortran::lower::annotateControl(*ast);
Fortran::lower::dumpPFT(llvm::outs(), *ast);
} else {
- std::cerr << "Pre FIR Tree is NULL.\n";
+ llvm::errs() << "Pre FIR Tree is NULL.\n";
exitStatus = EXIT_FAILURE;
}
}
std::snprintf(tmpSourcePath, sizeof tmpSourcePath, "/tmp/f18-%lx.f90",
static_cast<unsigned long>(getpid()));
{
- std::ofstream tmpSource;
- tmpSource.open(tmpSourcePath);
+ std::error_code EC;
+ llvm::raw_fd_ostream tmpSource(tmpSourcePath, EC, llvm::sys::fs::F_None);
+ if (EC) {
+ llvm::errs() << EC.message() << "\n";
+ std::exit(EXIT_FAILURE);
+ }
Unparse(tmpSource, parseTree, driver.encoding, true /*capitalize*/,
options.features.IsEnabled(
Fortran::common::LanguageFeature::BackslashEscapes),
int arguments[3];
for (int i = 0; i < 3; i++) {
if (args.empty()) {
- std::cerr << "Must provide 3 arguments for -fget-definitions.\n";
+ llvm::errs() << "Must provide 3 arguments for -fget-definitions.\n";
return EXIT_FAILURE;
}
arguments[i] = std::strtol(args.front().c_str(), &endptr, 10);
if (*endptr != '\0') {
- std::cerr << "Invalid argument to -fget-definitions: " << args.front()
- << '\n';
+ llvm::errs() << "Invalid argument to -fget-definitions: "
+ << args.front() << '\n';
return EXIT_FAILURE;
}
args.pop_front();
} else if (arg == "-fget-symbols-sources") {
driver.getSymbolsSources = true;
} else if (arg == "-help" || arg == "--help" || arg == "-?") {
- std::cerr
+ llvm::errs()
<< "f18 options:\n"
<< " -Mfixed | -Mfree force the source form\n"
<< " -Mextend 132-column fixed form\n"
<< "Other options are passed through to the compiler.\n";
return exitStatus;
} else if (arg == "-V") {
- std::cerr << "\nf18 compiler (under development)\n";
+ llvm::errs() << "\nf18 compiler (under development)\n";
return exitStatus;
} else {
driver.pgf90Args.push_back(arg);
target_link_libraries(quick-sanity-test
FortranDecimal
+ LLVMSupport
)
add_executable(thorough-test
target_link_libraries(thorough-test
FortranDecimal
+ LLVMSupport
)
add_test(Sanity quick-sanity-test)
#include "flang/Decimal/decimal.h"
+#include "llvm/Support/raw_ostream.h"
#include <cinttypes>
#include <cstdio>
#include <cstring>
-#include <iostream>
using namespace Fortran::decimal;
std::uint32_t u;
};
-std::ostream &failed(float x) {
+llvm::raw_ostream &failed(float x) {
++fails;
union u u;
u.x = x;
- return std::cout << "FAIL: 0x" << std::hex << u.u << std::dec;
+ llvm::outs() << "FAIL: 0x";
+ return llvm::outs().write_hex(u.u);
}
void testDirect(float x, const char *expect, int expectExpo, int flags = 0) {
if (!(x == x)) {
if (y == y || *p != '\0' || (rflags & Invalid)) {
u.x = y;
- failed(x) << " (NaN) " << flags << ": -> '" << result.str << "' -> 0x"
- << std::hex << u.u << std::dec << " '" << p << "' " << rflags
- << '\n';
+ failed(x) << " (NaN) " << flags << ": -> '" << result.str << "' -> 0x";
+ failed(x).write_hex(u.u) << " '" << p << "' " << rflags << '\n';
}
} else if (x != y || *p != '\0' || (rflags & Invalid)) {
u.x = y;
- failed(x) << ' ' << flags << ": -> '" << result.str << "' -> 0x"
- << std::hex << u.u << std::dec << " '" << p << "' " << rflags
- << '\n';
+ failed(x) << ' ' << flags << ": -> '" << result.str << "' -> 0x";
+ failed(x).write_hex(u.u) << " '" << p << "' " << rflags << '\n';
}
}
}
testReadback(u.x, Minimize);
testReadback(-u.x, Minimize);
}
- std::cout << tests << " tests run, " << fails << " tests failed\n";
+ llvm::outs() << tests << " tests run, " << fails << " tests failed\n";
return fails > 0;
}
#include "flang/Decimal/decimal.h"
+#include "llvm/Support/raw_ostream.h"
#include <cinttypes>
#include <cstdio>
#include <cstring>
-#include <iostream>
static constexpr int incr{1}; // steps through all values
static constexpr bool doNegative{true};
std::uint32_t u;
};
-std::ostream &failed(float x) {
+llvm::raw_ostream &failed(float x) {
++fails;
union u u;
u.x = x;
- return std::cout << "FAIL: 0x" << std::hex << u.u << std::dec;
+ llvm::outs() << "FAIL: 0x";
+ return llvm::outs().write_hex(u.u);
}
void testReadback(float x, int flags) {
union u u;
u.x = x;
if (!(tests & 0x3fffff)) {
- std::cerr << "\n0x" << std::hex << u.u << std::dec << ' ';
+ llvm::errs() << "\n0x";
+ llvm::errs().write_hex(u.u) << ' ';
} else if (!(tests & 0xffff)) {
- std::cerr << '.';
+ llvm::errs() << '.';
}
++tests;
auto result{ConvertFloatToDecimal(buffer, sizeof buffer,
if (!(x == x)) {
if (y == y || *p != '\0' || (rflags & Invalid)) {
u.x = y;
- failed(x) << " (NaN) " << flags << ": -> '" << result.str << "' -> 0x"
- << std::hex << u.u << std::dec << " '" << p << "' " << rflags
- << '\n';
+ failed(x) << " (NaN) " << flags << ": -> '" << result.str << "' -> 0x";
+ failed(x).write_hex(u.u) << " '" << p << "' " << rflags << '\n';
}
} else if (x != y || *p != '\0' || (rflags & Invalid)) {
u.x = y;
- failed(x) << ' ' << flags << ": -> '" << result.str << "' -> 0x"
- << std::hex << u.u << std::dec << " '" << p << "' " << rflags
- << '\n';
+ failed(x) << ' ' << flags << ": -> '" << result.str << "' -> 0x";
+ failed(x).write_hex(u.u) << " '" << p << "' " << rflags << '\n';
}
}
}
}
}
}
- std::cout << '\n' << tests << " tests run, " << fails << " tests failed\n";
+ llvm::outs() << '\n' << tests << " tests run, " << fails << " tests failed\n";
return fails > 0;
}
target_link_libraries(leading-zero-bit-count-test
FortranEvaluateTesting
+ LLVMSupport
)
add_executable(bit-population-count-test
target_link_libraries(bit-population-count-test
FortranEvaluateTesting
+ LLVMSupport
)
add_executable(uint128-test
target_link_libraries(uint128-test
FortranEvaluateTesting
+ LLVMSupport
)
# These routines live in lib/Common but we test them here.
FortranEvaluate
FortranSemantics
FortranParser
+ LLVMSupport
)
add_executable(integer-test
FortranEvaluateTesting
FortranEvaluate
FortranSemantics
+ LLVMSupport
)
add_executable(intrinsics-test
FortranSemantics
FortranParser
FortranRuntime
+ LLVMSupport
)
add_executable(logical-test
FortranEvaluateTesting
FortranEvaluate
FortranSemantics
+ LLVMSupport
)
# GCC -fno-exceptions breaks the fenv.h interfaces needed to capture
FortranEvaluate
FortranDecimal
FortranSemantics
+ LLVMSupport
)
add_executable(reshape-test
FortranSemantics
FortranEvaluate
FortranRuntime
+ LLVMSupport
)
add_executable(ISO-Fortran-binding-test
FortranEvaluate
FortranSemantics
FortranRuntime
+ LLVMSupport
)
add_executable(folding-test
FortranEvaluateTesting
FortranEvaluate
FortranSemantics
+ LLVMSupport
)
add_test(Expression expression-test)
#include "testing.h"
#include "../../include/flang/ISO_Fortran_binding.h"
#include "../../runtime/descriptor.h"
+#include "llvm/Support/raw_ostream.h"
#include <type_traits>
-#ifdef VERBOSE
-#include <iostream>
-#endif
using namespace Fortran::runtime;
using namespace Fortran::ISO;
static void DumpTestWorld(const void *bAddr, CFI_attribute_t attr,
CFI_type_t ty, std::size_t eLen, CFI_rank_t rank,
const CFI_index_t *eAddr) {
- std::cout << " base_addr: " << std::hex
- << reinterpret_cast<std::intptr_t>(bAddr)
- << " attribute: " << static_cast<int>(attr) << std::dec
- << " type: " << static_cast<int>(ty) << " elem_len: " << eLen
- << " rank: " << static_cast<int>(rank) << " extent: " << std::hex
- << reinterpret_cast<std::intptr_t>(eAddr) << std::endl
- << std::dec;
+ llvm::outs() << " base_addr: ";
+ llvm::outs().write_hex(reinterpret_cast<std::intptr_t>(bAddr))
+ << " attribute: " << static_cast<int>(attr)
+ << " type: " << static_cast<int>(ty) << " elem_len: " << eLen
+ << " rank: " << static_cast<int>(rank) << " extent: ";
+ llvm::outs().write_hex(reinterpret_cast<std::intptr_t>(eAddr)) << '\n';
+ llvm::outs().flush();
}
#endif
#include "fp-testing.h"
+#include "llvm/Support/Errno.h"
#include <cstdio>
#include <cstdlib>
#include <cstring>
) {
errno = 0;
if (feholdexcept(&originalFenv_) != 0) {
- std::fprintf(stderr, "feholdexcept() failed: %s\n", std::strerror(errno));
+ std::fprintf(stderr, "feholdexcept() failed: %s\n",
+ llvm::sys::StrError(errno).c_str());
std::abort();
}
if (fegetenv(¤tFenv_) != 0) {
- std::fprintf(stderr, "fegetenv() failed: %s\n", std::strerror(errno));
+ std::fprintf(
+ stderr, "fegetenv() failed: %s\n", llvm::sys::StrError(errno).c_str());
std::abort();
}
#if __x86_64__
#endif
errno = 0;
if (fesetenv(¤tFenv_) != 0) {
- std::fprintf(stderr, "fesetenv() failed: %s\n", std::strerror(errno));
+ std::fprintf(
+ stderr, "fesetenv() failed: %s\n", llvm::sys::StrError(errno).c_str());
std::abort();
}
}
ScopedHostFloatingPointEnvironment::~ScopedHostFloatingPointEnvironment() {
errno = 0;
if (fesetenv(&originalFenv_) != 0) {
- std::fprintf(stderr, "fesetenv() failed: %s\n", std::strerror(errno));
+ std::fprintf(
+ stderr, "fesetenv() failed: %s\n", llvm::sys::StrError(errno).c_str());
std::abort();
}
}
#include "flang/Evaluate/expression.h"
#include "flang/Evaluate/tools.h"
#include "flang/Parser/provenance.h"
+#include "llvm/Support/raw_ostream.h"
#include <initializer_list>
-#include <iostream>
#include <map>
#include <string>
parser::ContextualMessages Messages(parser::Messages &buffer) {
return parser::ContextualMessages{cooked_.data(), &buffer};
}
- void Emit(std::ostream &o, const parser::Messages &messages) {
+ void Emit(llvm::raw_ostream &o, const parser::Messages &messages) {
messages.Emit(o, cooked_);
}
int rank = 0, bool isElemental = false) {
Marshal();
parser::CharBlock fName{strings(name)};
- std::cout << "function: " << fName.ToString();
+ llvm::outs() << "function: " << fName.ToString();
char sep{'('};
for (const auto &a : args) {
- std::cout << sep;
+ llvm::outs() << sep;
sep = ',';
- a->AsFortran(std::cout);
+ a->AsFortran(llvm::outs());
}
if (sep == '(') {
- std::cout << '(';
+ llvm::outs() << '(';
}
- std::cout << ')' << std::endl;
+ llvm::outs() << ')' << '\n';
+ llvm::outs().flush();
CallCharacteristics call{fName.ToString()};
auto messages{strings.Messages(buffer)};
FoldingContext context{messages, defaults, table};
TEST((messages.messages() && messages.messages()->AnyFatalError()) ||
name == "bad");
}
- strings.Emit(std::cout, buffer);
+ strings.Emit(llvm::outs(), buffer);
}
const common::IntrinsicTypeDefaultKinds &defaults;
MATCH(4, defaults.GetDefaultKind(TypeCategory::Integer));
MATCH(4, defaults.GetDefaultKind(TypeCategory::Real));
IntrinsicProcTable table{IntrinsicProcTable::Configure(defaults)};
- table.Dump(std::cout);
+ table.Dump(llvm::outs());
using Int1 = Type<TypeCategory::Integer, 1>;
using Int4 = Type<TypeCategory::Integer, 4>;
#include "fp-testing.h"
#include "testing.h"
#include "flang/Evaluate/type.h"
+#include "llvm/Support/raw_ostream.h"
#include <cmath>
#include <cstdio>
#include <cstdlib>
-#include <sstream>
#include <type_traits>
using namespace Fortran::evaluate;
TEST(ivf.flags.empty())(ldesc);
MATCH(x, ivf.value.ToUInt64())(ldesc);
if (rounding.mode == RoundingMode::TiesToEven) { // to match stold()
- std::stringstream ss;
+ std::string buf;
+ llvm::raw_string_ostream ss{buf};
vr.value.AsFortran(ss, kind, false /*exact*/);
std::string decimal{ss.str()};
const char *p{decimal.data()};
("%d IsInfinite(0x%jx)", pass, static_cast<std::intmax_t>(rj));
static constexpr int kind{REAL::bits / 8};
- std::stringstream ss, css;
+ std::string ssBuf, cssBuf;
+ llvm::raw_string_ostream ss{ssBuf};
+ llvm::raw_string_ostream css{cssBuf};
x.AsFortran(ss, kind, false /*exact*/);
std::string s{ss.str()};
if (IsNaN(rj)) {
#include "testing.h"
+#include "llvm/Support/raw_ostream.h"
#include <cstdarg>
#include <cstdio>
#include <cstdlib>
-#include <iostream>
namespace testing {
int Complete() {
if (failures == 0) {
if (passes == 1) {
- std::cout << "single test PASSES\n";
+ llvm::outs() << "single test PASSES\n";
} else {
- std::cout << "all " << std::dec << passes << " tests PASS\n";
+ llvm::outs() << "all " << passes << " tests PASS\n";
}
passes = 0;
return EXIT_SUCCESS;
} else {
if (passes == 1) {
- std::cerr << "1 test passes, ";
+ llvm::errs() << "1 test passes, ";
} else {
- std::cerr << std::dec << passes << " tests pass, ";
+ llvm::errs() << passes << " tests pass, ";
}
if (failures == 1) {
- std::cerr << "1 test FAILS\n";
+ llvm::errs() << "1 test FAILS\n";
} else {
- std::cerr << std::dec << failures << " tests FAIL\n";
+ llvm::errs() << failures << " tests FAIL\n";
}
passes = failures = 0;
return EXIT_FAILURE;
#define AVOID_NATIVE_UINT128_T 1
#include "flang/Common/uint128.h"
#include "testing.h"
+#include "llvm/Support/raw_ostream.h"
#include <cinttypes>
-#include <iostream>
#if (defined __GNUC__ || defined __clang__) && defined __SIZEOF_INT128__
#define HAS_NATIVE_UINT128_T 1
}
}
#if HAS_NATIVE_UINT128_T
- std::cout << "Environment has native __uint128_t\n";
+ llvm::outs() << "Environment has native __uint128_t\n";
TestVsNative();
#else
- std::cout << "Environment lacks native __uint128_t\n";
+ llvm::outs() << "Environment lacks native __uint128_t\n";
#endif
return testing::Complete();
}
target_link_libraries(format-test
FortranRuntime
RuntimeTesting
+ LLVMSupport
)
add_test(Format format-test)
target_link_libraries(hello-world
FortranRuntime
RuntimeTesting
+ LLVMSupport
)
add_test(HelloWorld hello-world)
target_link_libraries(external-hello-world
FortranRuntime
+ LLVMSupport
)
add_executable(list-input-test
target_link_libraries(list-input-test
FortranRuntime
RuntimeTesting
+ LLVMSupport
)
add_test(ListInput list-input-test)
#include "testing.h"
#include "../runtime/format-implementation.h"
#include "../runtime/io-error.h"
+#include "llvm/Support/raw_ostream.h"
#include <cstdarg>
#include <cstring>
-#include <iostream>
#include <string>
#include <vector>
if (expect != results) {
Fail() << "expected:";
for (const std::string &s : expect) {
- std::cerr << ' ' << s;
+ llvm::errs() << ' ' << s;
}
- std::cerr << "\ngot:";
+ llvm::errs() << "\ngot:";
for (const std::string &s : results) {
- std::cerr << ' ' << s;
+ llvm::errs() << ' ' << s;
}
- std::cerr << '\n';
+ llvm::errs() << '\n';
}
expect.clear();
results.clear();
#include "testing.h"
#include "../../runtime/descriptor.h"
#include "../../runtime/io-api.h"
+#include "llvm/Support/raw_ostream.h"
#include <cstring>
-#include <iostream>
using namespace Fortran::runtime;
using namespace Fortran::runtime::io;
Fail() << '\'' << format << "' failed reading '" << data << "', status "
<< static_cast<int>(status) << " iomsg '" << iomsg << "'\n";
} else if (u.raw != want) {
- Fail() << '\'' << format << "' failed reading '" << data << "', want 0x"
- << std::hex << want << ", got 0x" << u.raw << std::dec << '\n';
+ Fail() << '\'' << format << "' failed reading '" << data << "', want 0x";
+ Fail().write_hex(want) << ", got 0x" << u.raw << '\n';
}
}
#include "../../runtime/descriptor.h"
#include "../../runtime/io-api.h"
#include "../../runtime/io-error.h"
+#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cstring>
-#include <iostream>
using namespace Fortran::runtime;
using namespace Fortran::runtime::io;
#include "testing.h"
#include "../../runtime/terminator.h"
+#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cstdarg>
#include <cstdio>
#include <cstring>
-#include <iostream>
#include <string>
static int failures{0};
Fortran::runtime::Terminator::RegisterCrashHandler(CatchCrash);
}
-std::ostream &Fail() {
+llvm::raw_ostream &Fail() {
++failures;
- return std::cerr;
+ return llvm::errs();
}
int EndTests() {
if (failures == 0) {
- std::cout << "PASS\n";
+ llvm::outs() << "PASS\n";
} else {
- std::cout << "FAIL " << failures << " tests\n";
+ llvm::outs() << "FAIL " << failures << " tests\n";
}
return failures != 0;
}
#include <cstddef>
#include <iosfwd>
+namespace llvm {
+ class raw_ostream;
+}
+
void StartTests();
-std::ostream &Fail();
+llvm::raw_ostream &Fail();
int EndTests();
void SetCharacter(char *, std::size_t, const char *);