forked from llvm-mirror/clang
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement __builtin_LINE() et. al. to support source location capture.
Summary: This patch implements the source location builtins `__builtin_LINE(), `__builtin_FUNCTION()`, `__builtin_FILE()` and `__builtin_COLUMN()`. These builtins are needed to implement [`std::experimental::source_location`](https://rawgit.com/cplusplus/fundamentals-ts/v2/main.html#reflection.src_loc.creation). With the exception of `__builtin_COLUMN`, GCC also implements these builtins, and Clangs behavior is intended to match as closely as possible. Reviewers: rsmith, joerg, aaron.ballman, bogner, majnemer, shafik, martong Reviewed By: rsmith Subscribers: rnkovacs, loskutov, riccibruno, mgorny, kunitoki, alexr, majnemer, hfinkel, cfe-commits Differential Revision: https://reviews.llvm.org/D37035 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@360937 91177308-0d34-0410-b5e6-96231b3b80d8
- Loading branch information
Showing
44 changed files
with
1,702 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
//===--- CurrentSourceLocExprScope.h ----------------------------*- C++ -*-===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file defines types used to track the current context needed to evaluate | ||
// a SourceLocExpr. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_CLANG_AST_CURRENT_SOURCE_LOC_EXPR_SCOPE_H | ||
#define LLVM_CLANG_AST_CURRENT_SOURCE_LOC_EXPR_SCOPE_H | ||
|
||
#include <cassert> | ||
|
||
namespace clang { | ||
class Expr; | ||
|
||
/// Represents the current source location and context used to determine the | ||
/// value of the source location builtins (ex. __builtin_LINE), including the | ||
/// context of default argument and default initializer expressions. | ||
class CurrentSourceLocExprScope { | ||
/// The CXXDefaultArgExpr or CXXDefaultInitExpr we're currently evaluating. | ||
const Expr *DefaultExpr = nullptr; | ||
|
||
public: | ||
/// A RAII style scope guard used for tracking the current source | ||
/// location and context as used by the source location builtins | ||
/// (ex. __builtin_LINE). | ||
class SourceLocExprScopeGuard; | ||
|
||
const Expr *getDefaultExpr() const { return DefaultExpr; } | ||
|
||
explicit CurrentSourceLocExprScope() = default; | ||
|
||
private: | ||
explicit CurrentSourceLocExprScope(const Expr *DefaultExpr) | ||
: DefaultExpr(DefaultExpr) {} | ||
|
||
CurrentSourceLocExprScope(CurrentSourceLocExprScope const &) = default; | ||
CurrentSourceLocExprScope & | ||
operator=(CurrentSourceLocExprScope const &) = default; | ||
}; | ||
|
||
class CurrentSourceLocExprScope::SourceLocExprScopeGuard { | ||
public: | ||
SourceLocExprScopeGuard(const Expr *DefaultExpr, | ||
CurrentSourceLocExprScope &Current) | ||
: Current(Current), OldVal(Current), Enable(false) { | ||
assert(DefaultExpr && "the new scope should not be empty"); | ||
if ((Enable = (Current.getDefaultExpr() == nullptr))) | ||
Current = CurrentSourceLocExprScope(DefaultExpr); | ||
} | ||
|
||
~SourceLocExprScopeGuard() { | ||
if (Enable) | ||
Current = OldVal; | ||
} | ||
|
||
private: | ||
SourceLocExprScopeGuard(SourceLocExprScopeGuard const &) = delete; | ||
SourceLocExprScopeGuard &operator=(SourceLocExprScopeGuard const &) = delete; | ||
|
||
CurrentSourceLocExprScope &Current; | ||
CurrentSourceLocExprScope OldVal; | ||
bool Enable; | ||
}; | ||
|
||
} // end namespace clang | ||
|
||
#endif // LLVM_CLANG_AST_CURRENT_SOURCE_LOC_EXPR_SCOPE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.