Skip to content

Commit

Permalink
Wrap llvm::SourceMgr in swift::SourceManager so that we can add new m…
Browse files Browse the repository at this point in the history
…embers

to the source manager.


Swift SVN r6815
  • Loading branch information
gribozavr committed Aug 1, 2013
1 parent 37ca2c3 commit e1c4ae3
Show file tree
Hide file tree
Showing 40 changed files with 181 additions and 163 deletions.
8 changes: 4 additions & 4 deletions include/swift/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@

namespace llvm {
class BumpPtrAllocator;
class SourceMgr;
}

namespace clang {
Expand Down Expand Up @@ -65,6 +64,7 @@ namespace swift {
class UnionElementDecl;
class ProtocolDecl;
class SubstitutableType;
class SourceManager;
class ValueDecl;
class DiagnosticEngine;
class Substitution;
Expand Down Expand Up @@ -142,15 +142,15 @@ class ASTContext {

friend class ConstraintCheckerArenaRAII;
public:
ASTContext(LangOptions &langOpts, llvm::SourceMgr &SourceMgr,
ASTContext(LangOptions &langOpts, SourceManager &SourceMgr,
DiagnosticEngine &Diags);
~ASTContext();

/// \brief The language options used for translation.
LangOptions &LangOpts;

/// SourceMgr - The source manager object.
llvm::SourceMgr &SourceMgr;
/// \brief The source manager object.
SourceManager &SourceMgr;

/// Diags - The diagnostics engine.
DiagnosticEngine &Diags;
Expand Down
11 changes: 3 additions & 8 deletions include/swift/AST/DiagnosticEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,10 @@
#include <string>
#include <utility>

namespace llvm {
class SourceMgr;
}

namespace swift {
using llvm::ArrayRef;
using llvm::StringRef;
class Decl;
class DiagnosticEngine;
class SourceManager;

enum class PatternKind : uint8_t;

Expand Down Expand Up @@ -302,7 +297,7 @@ namespace swift {
class DiagnosticEngine {
/// \brief The source manager used to interpret source locations and
/// display diagnostics.
llvm::SourceMgr &SourceMgr;
SourceManager &SourceMgr;

/// \brief The diagnostic consumer(s) that will be responsible for actually
/// emitting diagnostics.
Expand All @@ -329,7 +324,7 @@ namespace swift {
friend class InFlightDiagnostic;

public:
explicit DiagnosticEngine(llvm::SourceMgr &SourceMgr)
explicit DiagnosticEngine(SourceManager &SourceMgr)
: SourceMgr(SourceMgr), HadAnyError(false), ActiveDiagnostic() {
}

Expand Down
9 changes: 3 additions & 6 deletions include/swift/Basic/DiagnosticConsumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@
#include "llvm/ADT/StringRef.h"
#include <string>

namespace llvm {
class SourceMgr;
}

namespace swift {
class SourceManager;

/// \brief Describes the kind of diagnostic.
///
Expand Down Expand Up @@ -101,15 +98,15 @@ class DiagnosticConsumer {
/// \param Text The diagnostic text.
///
/// \param Info Extra information associated with the diagnostic.
virtual void handleDiagnostic(llvm::SourceMgr &SM, SourceLoc Loc,
virtual void handleDiagnostic(SourceManager &SM, SourceLoc Loc,
DiagnosticKind Kind, llvm::StringRef Text,
const DiagnosticInfo &Info) = 0;
};

/// \brief DiagnosticConsumer that discards all diagnostics.
class NullDiagnosticConsumer : public DiagnosticConsumer {
public:
void handleDiagnostic(llvm::SourceMgr &SM, SourceLoc Loc,
void handleDiagnostic(SourceManager &SM, SourceLoc Loc,
DiagnosticKind Kind, llvm::StringRef Text,
const DiagnosticInfo &Info) override;
};
Expand Down
18 changes: 9 additions & 9 deletions include/swift/Basic/SourceLoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@
#include "swift/Basic/LLVM.h"
#include "llvm/Support/SMLoc.h"

namespace llvm {
class SourceMgr;
}
namespace swift {
class SourceManager;

/// SourceLoc in swift is just an SMLoc. We define it as a different type
/// (instead of as a typedef) just to remove the "getFromPointer" methods and
Expand Down Expand Up @@ -53,14 +51,15 @@ class SourceLoc {
/// as specified by LastBuffer, then we don't print the filename. If not, we
/// do print the filename, and then update LastBuffer with the BufferID
/// printed.
void print(raw_ostream &OS, const llvm::SourceMgr &SM,
void print(raw_ostream &OS, const SourceManager &SM,
int &LastBuffer) const;

void print(raw_ostream &OS, const llvm::SourceMgr &SM) const {
void print(raw_ostream &OS, const SourceManager &SM) const {
int Tmp = -1;
print(OS, SM, Tmp);
}
void dump(const llvm::SourceMgr &SM) const;

void dump(const SourceManager &SM) const;
};

/// SourceRange in swift is a pair of locations. However, note that the end
Expand All @@ -85,14 +84,15 @@ class SourceRange {
/// as specified by LastBuffer, then we don't print the filename. If not, we
/// do print the filename, and then update LastBuffer with the BufferID
/// printed.
void print(raw_ostream &OS, const llvm::SourceMgr &SM,
void print(raw_ostream &OS, const SourceManager &SM,
int &LastBuffer) const;

void print(raw_ostream &OS, const llvm::SourceMgr &SM) const {
void print(raw_ostream &OS, const SourceManager &SM) const {
int Tmp = -1;
print(OS, SM, Tmp);
}
void dump(const llvm::SourceMgr &SM) const;

void dump(const SourceManager &SM) const;
};

} // end namespace swift
Expand Down
39 changes: 39 additions & 0 deletions include/swift/Basic/SourceManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//===--- SourceManager.h - Manager for Source Buffers -----------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//


#ifndef SWIFT_SOURCEMANAGER_H
#define SWIFT_SOURCEMANAGER_H

#include "llvm/Support/SourceMgr.h"

namespace swift {

/// \brief This class manages and owns source buffers.
class SourceManager {
llvm::SourceMgr LLVMSourceMgr;

public:
SourceManager() {}

llvm::SourceMgr *operator->() { return &LLVMSourceMgr; }
const llvm::SourceMgr *operator->() const { return &LLVMSourceMgr; }

const llvm::SourceMgr &getLLVMSourceMgr() const {
return LLVMSourceMgr;
}
};

} // namespace swift

#endif // LLVM_SWIFT_SOURCEMANAGER_H

6 changes: 3 additions & 3 deletions include/swift/Frontend/Frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "swift/Basic/DiagnosticConsumer.h"
#include "swift/Basic/LangOptions.h"
#include "swift/Basic/SourceManager.h"
#include "swift/AST/DiagnosticEngine.h"
#include "swift/AST/Module.h"
#include "swift/Parse/CodeCompletionCallbacks.h"
Expand All @@ -25,7 +26,6 @@
#include "swift/Sema/SourceLoader.h"
#include "swift/SIL/SILModule.h"
#include "llvm/ADT/IntrusiveRefCntPtr.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/Host.h"

#include <memory>
Expand Down Expand Up @@ -199,7 +199,7 @@ class CompilerInvocation {

class CompilerInstance {
CompilerInvocation Invocation;
llvm::SourceMgr SourceMgr;
SourceManager SourceMgr;
std::vector<unsigned> BufferIDs;
unsigned CodeCompletionBufferID = ~0U;
DiagnosticEngine Diagnostics;
Expand All @@ -216,7 +216,7 @@ class CompilerInstance {
CompilerInstance() : Diagnostics(SourceMgr), TU(nullptr) {
}

llvm::SourceMgr &getSourceMgr() { return SourceMgr; }
SourceManager &getSourceMgr() { return SourceMgr; }

DiagnosticEngine &getDiags() { return Diagnostics; }

Expand Down
4 changes: 2 additions & 2 deletions include/swift/Frontend/PrintingDiagnosticConsumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ namespace swift {
/// \brief Diagnostic consumer that displays diagnostics to standard error.
class PrintingDiagnosticConsumer : public DiagnosticConsumer {
public:
virtual void handleDiagnostic(llvm::SourceMgr &SM, SourceLoc Loc,
virtual void handleDiagnostic(SourceManager &SM, SourceLoc Loc,
DiagnosticKind Kind, llvm::StringRef Text,
const DiagnosticInfo &Info);
const DiagnosticInfo &Info) override;
};

}
Expand Down
15 changes: 6 additions & 9 deletions include/swift/Parse/Lexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,17 @@
#include "llvm/ADT/SmallVector.h"
#include "swift/Basic/SourceLoc.h"

namespace llvm {
class SourceMgr;
}

namespace swift {
class DiagnosticEngine;
class Identifier;
class InFlightDiagnostic;
class ASTContext;
class SourceManager;

template<typename ...T> struct Diag;

class Lexer {
llvm::SourceMgr &SourceMgr;
SourceManager &SourceMgr;
DiagnosticEngine *Diags;

/// Pointer to the first character of the buffer.
Expand Down Expand Up @@ -75,14 +72,14 @@ class Lexer {
Lexer(const Lexer&) = delete;
void operator=(const Lexer&) = delete;

Lexer(llvm::SourceMgr &SourceMgr, llvm::StringRef Buffer,
Lexer(SourceManager &SourceMgr, llvm::StringRef Buffer,
DiagnosticEngine *Diags, const char *CurrentPosition,
bool InSILMode, bool KeepComments, bool AllowHashbang, bool Prime);

void primeLexer();

public:
Lexer(llvm::StringRef Buffer, llvm::SourceMgr &SourceMgr,
Lexer(llvm::StringRef Buffer, SourceManager &SourceMgr,
DiagnosticEngine *Diags, bool InSILMode, bool KeepComments = false,
bool AllowHashbang = false)
: Lexer(SourceMgr, Buffer, Diags, Buffer.begin(), InSILMode,
Expand Down Expand Up @@ -110,7 +107,7 @@ class Lexer {
/// \param BeginState start of the subrange
/// \param EndState end of the subrange
Lexer(Lexer &Parent, State BeginState, State EndState,
llvm::SourceMgr &SourceMgr, DiagnosticEngine *Diags, bool InSILMode)
SourceManager &SourceMgr, DiagnosticEngine *Diags, bool InSILMode)
: Lexer(SourceMgr,
StringRef(BeginState.CurPtr, Parent.BufferEnd - BeginState.CurPtr),
Diags, BeginState.CurPtr, InSILMode, Parent.isKeepingComments(),
Expand Down Expand Up @@ -203,7 +200,7 @@ class Lexer {
/// resides.
///
/// \param Loc The source location of the beginning of a token.
static SourceLoc getLocForEndOfToken(llvm::SourceMgr &SM, SourceLoc Loc);
static SourceLoc getLocForEndOfToken(SourceManager &SM, SourceLoc Loc);

/// \brief Determines if the given string is a valid non-operator
/// identifier.
Expand Down
4 changes: 2 additions & 2 deletions include/swift/Parse/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include "llvm/ADT/SetVector.h"

namespace llvm {
class SourceMgr;
template <typename PT1, typename PT2, typename PT3> class PointerUnion3;
}

Expand All @@ -37,6 +36,7 @@ namespace swift {
struct TypeLoc;
class TupleType;
class SILParserState;
class SourceManager;
class PersistentParserState;
class CodeCompletionCallbacks;
class DelayedParsingCallbacks;
Expand Down Expand Up @@ -65,7 +65,7 @@ class Parser {
public:
typedef llvm::PointerUnion3<Expr*, Stmt*, Decl*> ExprStmtOrDecl;

llvm::SourceMgr &SourceMgr;
SourceManager &SourceMgr;
DiagnosticEngine &Diags;
TranslationUnit *TU;
Lexer *L;
Expand Down
4 changes: 2 additions & 2 deletions include/swift/Subsystems.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <memory>

namespace llvm {
class SourceMgr;
class MemoryBuffer;
class Module;
class FunctionPass;
Expand All @@ -41,6 +40,7 @@ namespace swift {
class CodeCompletionCallbacksFactory;
class PersistentParserState;
class DelayedParsingCallbacks;
class SourceManager;

namespace irgen {
class Options;
Expand Down Expand Up @@ -92,7 +92,7 @@ namespace swift {
unsigned CodeCompletionOffset);

/// \brief Lex and return a vector of tokens for the given buffer.
std::vector<Token> tokenize(llvm::SourceMgr &SM, unsigned BufferID,
std::vector<Token> tokenize(SourceManager &SM, unsigned BufferID,
unsigned Offset = 0, unsigned EndOffset = 0,
bool KeepComments = true);

Expand Down
6 changes: 3 additions & 3 deletions lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#include "swift/AST/ExprHandle.h"
#include "swift/AST/ModuleLoader.h"
#include "swift/AST/ModuleLoadListener.h"
#include "swift/Basic/SourceManager.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/StringMap.h"
#include <memory>
Expand Down Expand Up @@ -148,11 +148,11 @@ ConstraintCheckerArenaRAII::~ConstraintCheckerArenaRAII() {
(ASTContext::Implementation::ConstraintSolverArena *)Data);
}

ASTContext::ASTContext(LangOptions &langOpts, llvm::SourceMgr &sourcemgr,
ASTContext::ASTContext(LangOptions &langOpts, SourceManager &SourceMgr,
DiagnosticEngine &Diags)
: Impl(*new Implementation()),
LangOpts(langOpts),
SourceMgr(sourcemgr),
SourceMgr(SourceMgr),
Diags(Diags),
TheBuiltinModule(new (*this) BuiltinModule(getIdentifier("Builtin"), *this)),
TheErrorType(new (*this, AllocationArena::Permanent) ErrorType(*this)),
Expand Down
4 changes: 2 additions & 2 deletions lib/AST/DiagnosticEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#include "swift/AST/Pattern.h"
#include "swift/AST/PrintOptions.h"
#include "swift/AST/TypeRepr.h"
#include "swift/Basic/SourceManager.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/raw_ostream.h"
Expand Down Expand Up @@ -322,7 +322,7 @@ void DiagnosticEngine::flushActiveDiagnostic() {
// Build a buffer with the pretty-printed declaration.
auto memBuffer = llvm::MemoryBuffer::getMemBufferCopy(buffer,
bufferName);
SourceMgr.AddNewSourceBuffer(memBuffer, llvm::SMLoc());
SourceMgr->AddNewSourceBuffer(memBuffer, llvm::SMLoc());

// Go through all of the pretty-printed entries and record their
// locations.
Expand Down
Loading

0 comments on commit e1c4ae3

Please sign in to comment.