summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorJuergen Ributzka <juergen@apple.com>2013-11-19 03:08:35 +0000
committerJuergen Ributzka <juergen@apple.com>2013-11-19 03:08:35 +0000
commitba0f991a78706068cc2e6a1c4ef4b0d8f7ce748b (patch)
tree92f96f6c5615bd64c6f734f1534a7aa29a47c67a /examples
parent36c7806f4eacd676932ba630246f88e0e37b1cd4 (diff)
downloadllvm-ba0f991a78706068cc2e6a1c4ef4b0d8f7ce748b.tar.gz
llvm-ba0f991a78706068cc2e6a1c4ef4b0d8f7ce748b.tar.bz2
llvm-ba0f991a78706068cc2e6a1c4ef4b0d8f7ce748b.tar.xz
[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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@195092 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'examples')
-rw-r--r--examples/ExceptionDemo/ExceptionDemo.cpp8
-rw-r--r--examples/Kaleidoscope/Chapter2/toy.cpp17
-rw-r--r--examples/Kaleidoscope/Chapter3/toy.cpp8
-rw-r--r--examples/Kaleidoscope/Chapter4/toy.cpp8
-rw-r--r--examples/Kaleidoscope/Chapter5/toy.cpp8
-rw-r--r--examples/Kaleidoscope/Chapter6/toy.cpp8
-rw-r--r--examples/Kaleidoscope/Chapter7/toy.cpp8
7 files changed, 21 insertions, 44 deletions
diff --git a/examples/ExceptionDemo/ExceptionDemo.cpp b/examples/ExceptionDemo/ExceptionDemo.cpp
index 6a0d0d027f..d6954e83be 100644
--- a/examples/ExceptionDemo/ExceptionDemo.cpp
+++ b/examples/ExceptionDemo/ExceptionDemo.cpp
@@ -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
diff --git a/examples/Kaleidoscope/Chapter2/toy.cpp b/examples/Kaleidoscope/Chapter2/toy.cpp
index 99ec90e9b0..cd901394a5 100644
--- a/examples/Kaleidoscope/Chapter2/toy.cpp
+++ b/examples/Kaleidoscope/Chapter2/toy.cpp
@@ -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();
diff --git a/examples/Kaleidoscope/Chapter3/toy.cpp b/examples/Kaleidoscope/Chapter3/toy.cpp
index 2494345c3f..a7b60ba322 100644
--- a/examples/Kaleidoscope/Chapter3/toy.cpp
+++ b/examples/Kaleidoscope/Chapter3/toy.cpp
@@ -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
diff --git a/examples/Kaleidoscope/Chapter4/toy.cpp b/examples/Kaleidoscope/Chapter4/toy.cpp
index 4d56c0f2df..27c3f4f22d 100644
--- a/examples/Kaleidoscope/Chapter4/toy.cpp
+++ b/examples/Kaleidoscope/Chapter4/toy.cpp
@@ -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
diff --git a/examples/Kaleidoscope/Chapter5/toy.cpp b/examples/Kaleidoscope/Chapter5/toy.cpp
index 113016a326..fe4cdfe757 100644
--- a/examples/Kaleidoscope/Chapter5/toy.cpp
+++ b/examples/Kaleidoscope/Chapter5/toy.cpp
@@ -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
diff --git a/examples/Kaleidoscope/Chapter6/toy.cpp b/examples/Kaleidoscope/Chapter6/toy.cpp
index 70f233bf48..b7b347db0d 100644
--- a/examples/Kaleidoscope/Chapter6/toy.cpp
+++ b/examples/Kaleidoscope/Chapter6/toy.cpp
@@ -101,17 +101,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;
@@ -214,6 +211,7 @@ public:
Function *Codegen();
};
+} // end anonymous namespace
//===----------------------------------------------------------------------===//
// Parser
diff --git a/examples/Kaleidoscope/Chapter7/toy.cpp b/examples/Kaleidoscope/Chapter7/toy.cpp
index a05d134a1a..5c66f5c837 100644
--- a/examples/Kaleidoscope/Chapter7/toy.cpp
+++ b/examples/Kaleidoscope/Chapter7/toy.cpp
@@ -105,17 +105,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;
@@ -232,6 +229,7 @@ public:
Function *Codegen();
};
+} // end anonymous namespace
//===----------------------------------------------------------------------===//
// Parser