Commit 8d13612a authored by Bill Wendling's avatar Bill Wendling
Browse files

Merging r195092:

------------------------------------------------------------------------
r195092 | ributzka | 2013-11-18 19:08:35 -0800 (Mon, 18 Nov 2013) | 5 lines

[weak vtables] Place class definitions into anonymous namespaces to prevent weak vtables.

This patch places class definitions in implementation files into anonymous
namespaces to prevent weak vtables. This eliminates the need of providing an
out-of-line definition to pin the vtable explicitly to the file.
------------------------------------------------------------------------

llvm-svn: 195111
parent 413a2d26
Loading
Loading
Loading
Loading
+3 −5
Original line number Diff line number Diff line
@@ -1562,7 +1562,7 @@ llvm::Function *createUnwindExceptionTest(llvm::Module &module,
  return(outerCatchFunct);
}


namespace {
/// Represents our foreign exceptions
class OurCppRunException : public std::runtime_error {
public:
@@ -1577,11 +1577,9 @@ public:
                                 std::runtime_error::operator=(toCopy)));
  }

  ~OurCppRunException (void) throw ();
  virtual ~OurCppRunException (void) throw () {}
};

// Provide out-of-line definition to prevent weak vtable.
OurCppRunException::~OurCppRunException() throw () {}
} // end anonymous namespace

/// Throws foreign C++ exception.
/// @param ignoreIt unused parameter that allows function to match implied
+3 −14
Original line number Diff line number Diff line
@@ -75,18 +75,17 @@ static int gettok() {
//===----------------------------------------------------------------------===//
// Abstract Syntax Tree (aka Parse Tree)
//===----------------------------------------------------------------------===//

namespace {
/// ExprAST - Base class for all expression nodes.
class ExprAST {
public:
  virtual ~ExprAST();
  virtual ~ExprAST() {}
};

/// NumberExprAST - Expression class for numeric literals like "1.0".
class NumberExprAST : public ExprAST {
public:
  NumberExprAST(double val) {}
  virtual ~NumberExprAST();
};

/// VariableExprAST - Expression class for referencing a variable, like "a".
@@ -94,14 +93,12 @@ class VariableExprAST : public ExprAST {
  std::string Name;
public:
  VariableExprAST(const std::string &name) : Name(name) {}
  virtual ~VariableExprAST();
};

/// BinaryExprAST - Expression class for a binary operator.
class BinaryExprAST : public ExprAST {
public:
  BinaryExprAST(char op, ExprAST *lhs, ExprAST *rhs) {}
  virtual ~BinaryExprAST();
};

/// CallExprAST - Expression class for function calls.
@@ -111,16 +108,8 @@ class CallExprAST : public ExprAST {
public:
  CallExprAST(const std::string &callee, std::vector<ExprAST*> &args)
    : Callee(callee), Args(args) {}
  virtual ~CallExprAST();
};

// Provide out-of-line definitions to prevent weak vtables.
ExprAST::~ExprAST() {}
NumberExprAST::~NumberExprAST() {}
VariableExprAST::~VariableExprAST() {}
BinaryExprAST::~BinaryExprAST() {}
CallExprAST::~CallExprAST() {}

/// PrototypeAST - This class represents the "prototype" for a function,
/// which captures its name, and its argument names (thus implicitly the number
/// of arguments the function takes).
@@ -138,6 +127,7 @@ class FunctionAST {
public:
  FunctionAST(PrototypeAST *proto, ExprAST *body) {}
};
} // end anonymous namespace

//===----------------------------------------------------------------------===//
// Parser
@@ -169,7 +159,6 @@ static int GetTokPrecedence() {
/// Error* - These are little helper functions for error handling.
ExprAST *Error(const char *Str) { fprintf(stderr, "Error: %s\n", Str);return 0;}
PrototypeAST *ErrorP(const char *Str) { Error(Str); return 0; }
FunctionAST *ErrorF(const char *Str) { Error(Str); return 0; }

static ExprAST *ParseExpression();

+3 −5
Original line number Diff line number Diff line
@@ -80,17 +80,14 @@ static int gettok() {
//===----------------------------------------------------------------------===//
// Abstract Syntax Tree (aka Parse Tree)
//===----------------------------------------------------------------------===//

namespace {
/// ExprAST - Base class for all expression nodes.
class ExprAST {
public:
  virtual ~ExprAST();
  virtual ~ExprAST() {}
  virtual Value *Codegen() = 0;
};

// Provide out-of-line definition to prevent weak vtable.
ExprAST::~ExprAST() {}

/// NumberExprAST - Expression class for numeric literals like "1.0".
class NumberExprAST : public ExprAST {
  double Val;
@@ -150,6 +147,7 @@ public:
  
  Function *Codegen();
};
} // end anonymous namespace

//===----------------------------------------------------------------------===//
// Parser
+3 −5
Original line number Diff line number Diff line
@@ -87,17 +87,14 @@ static int gettok() {
//===----------------------------------------------------------------------===//
// Abstract Syntax Tree (aka Parse Tree)
//===----------------------------------------------------------------------===//

namespace {
/// ExprAST - Base class for all expression nodes.
class ExprAST {
public:
  virtual ~ExprAST();
  virtual ~ExprAST() {}
  virtual Value *Codegen() = 0;
};

// Provide out-of-line definition to prevent weak vtable.
ExprAST::~ExprAST() {}

/// NumberExprAST - Expression class for numeric literals like "1.0".
class NumberExprAST : public ExprAST {
  double Val;
@@ -157,6 +154,7 @@ public:
  
  Function *Codegen();
};
} // end anonymous namespace

//===----------------------------------------------------------------------===//
// Parser
+3 −5
Original line number Diff line number Diff line
@@ -96,17 +96,14 @@ static int gettok() {
//===----------------------------------------------------------------------===//
// Abstract Syntax Tree (aka Parse Tree)
//===----------------------------------------------------------------------===//

namespace {
/// ExprAST - Base class for all expression nodes.
class ExprAST {
public:
  virtual ~ExprAST();
  virtual ~ExprAST() {}
  virtual Value *Codegen() = 0;
};

// Provide out-of-line definition to prevent weak vtable.
ExprAST::~ExprAST() {}

/// NumberExprAST - Expression class for numeric literals like "1.0".
class NumberExprAST : public ExprAST {
  double Val;
@@ -186,6 +183,7 @@ public:
  
  Function *Codegen();
};
} // end anonymous namespace

//===----------------------------------------------------------------------===//
// Parser
Loading