Files
swift-mirror/include/swift/Parse/DelayedParsingCallbacks.h
Jordan Rose fa3dd42c54 Don't parse function bodies in imported TUs.
...unless the functions are declared [transparent], or if we're in an
immediate mode (in which case we won't get a separate chance to link
against the imported TUs).

This is an optimization that will matter more when we start dealing with
Xcode projects with many cross-file dependencies, especially if we have
some kind of implicit import of the other source files in the project.

In the future, we may want to parse more function bodies for the purpose
of inlining, not just the transparent ones, but we weren't taking
advantage of that now, so it's not a regression. (We're still not taking
advantage of it even for [transparent] functions.)

Swift SVN r7698
2013-08-28 22:53:28 +00:00

69 lines
2.4 KiB
C++

//===- DelayedParsingCallbacks.h - Callbacks for Parser's delayed parsing -===//
//
// 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_PARSE_DELAYED_PARSING_CALLBACKS_H
#define SWIFT_PARSE_DELAYED_PARSING_CALLBACKS_H
#include "swift/Basic/SourceLoc.h"
#include "swift/Basic/SourceManager.h"
#include "swift/Parse/Parser.h"
namespace swift {
class DeclAttributes;
class FuncExpr;
/// \brief Callbacks for Parser's delayed parsing.
class DelayedParsingCallbacks {
virtual void anchor();
public:
virtual ~DelayedParsingCallbacks() = default;
/// Checks if a function body should be delayed or skipped altogether.
virtual bool shouldDelayFunctionBodyParsing(Parser &TheParser,
FuncExpr *FE,
const DeclAttributes &Attrs,
SourceRange BodyRange) = 0;
};
class AlwaysDelayedCallbacks : public DelayedParsingCallbacks {
bool shouldDelayFunctionBodyParsing(Parser &TheParser,
FuncExpr *FE,
const DeclAttributes &Attrs,
SourceRange BodyRange) override {
return true;
}
};
/// \brief Implementation of callbacks that guide the parser in delayed
/// parsing for code completion.
class CodeCompleteDelayedCallbacks : public DelayedParsingCallbacks {
SourceLoc CodeCompleteLoc;
public:
explicit CodeCompleteDelayedCallbacks(SourceLoc CodeCompleteLoc)
: CodeCompleteLoc(CodeCompleteLoc) {
}
bool shouldDelayFunctionBodyParsing(Parser &TheParser,
FuncExpr *FE,
const DeclAttributes &Attrs,
SourceRange BodyRange) override {
// Delay parsing if the code completion point is in the function body.
return TheParser.SourceMgr
.rangeContainsTokenLoc(BodyRange, CodeCompleteLoc);
}
};
} // namespace swift
#endif