diff options
author | Alexey Bataev <a.bataev@hotmail.com> | 2016-06-15 11:19:39 +0000 |
---|---|---|
committer | Alexey Bataev <a.bataev@hotmail.com> | 2016-06-15 11:19:39 +0000 |
commit | 86e786bd17603b3839a8654ddae7710a63f8008d (patch) | |
tree | 59fcc841d26f22c91dc71a747bc069b81db258d2 /clang/lib/AST/StmtCXX.cpp | |
parent | d58dc298ef9c124bf875a7f7ee56ec9048cc6d74 (diff) |
[MSVC] Late parsing of in-class defined member functions in template
classes.
MSVC actively uses unqualified lookup in dependent bases, lookup at the
instantiation point (non-dependent names may be resolved on things
declared later) etc. and all this stuff is the main cause of
incompatibility between clang and MSVC.
Clang tries to emulate MSVC behavior but it may fail in many cases.
clang could store lexed tokens for member functions definitions within
ClassTemplateDecl for later parsing during template instantiation.
It will allow resolving many possible issues with lookup in dependent
base classes and removing many already existing MSVC-specific
hacks/workarounds from the clang code.
llvm-svn: 272774
Diffstat (limited to 'clang/lib/AST/StmtCXX.cpp')
-rw-r--r-- | clang/lib/AST/StmtCXX.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/clang/lib/AST/StmtCXX.cpp b/clang/lib/AST/StmtCXX.cpp index 4692db84b505..08cdd2045820 100644 --- a/clang/lib/AST/StmtCXX.cpp +++ b/clang/lib/AST/StmtCXX.cpp @@ -86,3 +86,38 @@ VarDecl *CXXForRangeStmt::getLoopVariable() { const VarDecl *CXXForRangeStmt::getLoopVariable() const { return const_cast<CXXForRangeStmt *>(this)->getLoopVariable(); } + +MSLateParsedCompoundStmt * +MSLateParsedCompoundStmt::Create(ASTContext &C, SourceLocation LB, + SourceLocation RB, ArrayRef<Token> Tokens, + StringRef Rep) { + // Allocate space for private variables and initializer expressions. + void *Mem = C.Allocate(totalSizeToAlloc<Token>(Tokens.size()), + llvm::alignOf<MSLateParsedCompoundStmt>()); + auto *S = new (Mem) MSLateParsedCompoundStmt(); + S->init(C, LB, RB, Tokens, Rep); + return S; +} + +MSLateParsedCompoundStmt * +MSLateParsedCompoundStmt::CreateEmpty(ASTContext &C, unsigned NumTokens) { + // Allocate space for private variables and initializer expressions. + void *Mem = C.Allocate(totalSizeToAlloc<Token>(NumTokens), + llvm::alignOf<MSLateParsedCompoundStmt>()); + return new (Mem) MSLateParsedCompoundStmt(); +} + +void MSLateParsedCompoundStmt::init(ASTContext &C, SourceLocation LB, + SourceLocation RB, ArrayRef<Token> Tokens, + StringRef Rep) { + LBraceLoc = LB; + RBraceLoc = RB; + std::copy(Tokens.begin(), Tokens.end(), getTrailingObjects<Token>()); + StringRep = Rep.copy(C); + NumToks = Tokens.size(); +} + +ArrayRef<Token> MSLateParsedCompoundStmt::tokens() const { + return llvm::makeArrayRef(getTrailingObjects<Token>(), NumToks); +} + |