faisalv created this revision.
faisalv added a project: clang.
Herald added a subscriber: eraman.

I'd like to harden my patch here: https://reviews.llvm.org/rL316292 by adding 
some assertions.

But since the assertions in Decl,.h (FunctionDecl) require knowledge from 
DeclCXX.h (CXXDeductionGuideDecl),-  my question is: In order to keep the 
member functions inline I factored them out into a separate header file that I 
included in certain areas.

Is this an acceptable pattern?

Or does anyone have any other preferred engineering suggestions?

Thanks!


Repository:
  rL LLVM

https://reviews.llvm.org/D39166

Files:
  include/clang/AST/Decl.h
  include/clang/AST/InlineDeclMembers.h
  include/clang/Sema/Sema.h
  lib/AST/Decl.cpp
  lib/AST/DeclCXX.cpp
  lib/Parse/ParseCXXInlineMethods.cpp

Index: lib/Parse/ParseCXXInlineMethods.cpp
===================================================================
--- lib/Parse/ParseCXXInlineMethods.cpp
+++ lib/Parse/ParseCXXInlineMethods.cpp
@@ -13,6 +13,7 @@
 
 #include "clang/Parse/Parser.h"
 #include "clang/AST/DeclTemplate.h"
+#include "clang/AST/InlineDeclMembers.h"
 #include "clang/Parse/ParseDiagnostic.h"
 #include "clang/Parse/RAIIObjectsForParser.h"
 #include "clang/Sema/DeclSpec.h"
Index: lib/AST/DeclCXX.cpp
===================================================================
--- lib/AST/DeclCXX.cpp
+++ lib/AST/DeclCXX.cpp
@@ -18,6 +18,7 @@
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
+#include "clang/AST/InlineDeclMembers.h"
 #include "clang/AST/ODRHash.h"
 #include "clang/AST/TypeLoc.h"
 #include "clang/Basic/IdentifierTable.h"
Index: lib/AST/Decl.cpp
===================================================================
--- lib/AST/Decl.cpp
+++ lib/AST/Decl.cpp
@@ -23,6 +23,7 @@
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
+#include "clang/AST/InlineDeclMembers.h"
 #include "clang/AST/PrettyPrinter.h"
 #include "clang/AST/Stmt.h"
 #include "clang/AST/TypeLoc.h"
Index: include/clang/Sema/Sema.h
===================================================================
--- include/clang/Sema/Sema.h
+++ include/clang/Sema/Sema.h
@@ -22,6 +22,7 @@
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprObjC.h"
 #include "clang/AST/ExternalASTSource.h"
+#include "clang/AST/InlineDeclMembers.h"
 #include "clang/AST/LocInfoType.h"
 #include "clang/AST/MangleNumberingContext.h"
 #include "clang/AST/NSAPI.h"
Index: include/clang/AST/InlineDeclMembers.h
===================================================================
--- include/clang/AST/InlineDeclMembers.h
+++ include/clang/AST/InlineDeclMembers.h
@@ -0,0 +1,37 @@
+//===- InlineDeclMembers.h - Decl.h Members that must be inlined -*- 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 the Decl subclasses.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_AST_INLINEDECLMEMBERS_H
+#define LLVM_CLANG_AST_INLINEDECLMEMBERS_H
+
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
+
+
+inline bool clang::FunctionDecl::willHaveBody() const {
+  assert(!isa<CXXDeductionGuideDecl>(this) &&
+    "must not be called on a deduction guide since we share this data "
+    "member while giving it different semantics");
+  return WillHaveBody;
+}
+inline void clang::FunctionDecl::setWillHaveBody(bool V) {
+  assert(!isa<CXXDeductionGuideDecl>(this) &&
+    "must not be called on a deduction guide since we share this data "
+    "member while giving it different semantics");
+  WillHaveBody = V;
+}
+
+
+#endif  //LLVM_CLANG_AST_INLINEDECLMEMBERS_H
+
+
Index: include/clang/AST/Decl.h
===================================================================
--- include/clang/AST/Decl.h
+++ include/clang/AST/Decl.h
@@ -1680,7 +1680,9 @@
 
 protected:
   // Since a Deduction Guide [C++17] will never have a body, we can share the
-  // storage, and use a different name.
+  // storage, and use a different name.  Since WillHaveBody is not serialized we
+  // don't need to worry about collisions there.
+
   union {
     /// Indicates if the function declaration will have a body, once we're done
     /// parsing it.
@@ -2074,8 +2076,8 @@
   void setHasSkippedBody(bool Skipped = true) { HasSkippedBody = Skipped; }
 
   /// True if this function will eventually have a body, once it's fully parsed.
-  bool willHaveBody() const { return WillHaveBody; }
-  void setWillHaveBody(bool V = true) { WillHaveBody = V; }
+  bool willHaveBody() const;
+  void setWillHaveBody(bool V = true);
 
   void setPreviousDeclaration(FunctionDecl * PrevDecl);
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to