Skip to content

Commit

Permalink
Move AST memory macros to macro header
Browse files Browse the repository at this point in the history
  • Loading branch information
mgreter committed Mar 17, 2018
1 parent efc0331 commit 064d6de
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 68 deletions.
32 changes: 0 additions & 32 deletions src/ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2124,38 +2124,6 @@ namespace Sass {
return ret;
}

//////////////////////////////////////////////////////////////////////////////////////////
// Copy implementations
//////////////////////////////////////////////////////////////////////////////////////////

#ifdef DEBUG_SHARED_PTR

#define IMPLEMENT_AST_OPERATORS(klass) \
klass##_Ptr klass::copy(std::string file, size_t line) const { \
klass##_Ptr cpy = new klass(this); \
cpy->trace(file, line); \
return cpy; \
} \
klass##_Ptr klass::clone(std::string file, size_t line) const { \
klass##_Ptr cpy = copy(file, line); \
cpy->cloneChildren(); \
return cpy; \
} \

#else

#define IMPLEMENT_AST_OPERATORS(klass) \
klass##_Ptr klass::copy() const { \
return new klass(this); \
} \
klass##_Ptr klass::clone() const { \
klass##_Ptr cpy = copy(); \
cpy->cloneChildren(); \
return cpy; \
} \

#endif

IMPLEMENT_AST_OPERATORS(Supports_Operator);
IMPLEMENT_AST_OPERATORS(Supports_Negation);
IMPLEMENT_AST_OPERATORS(Compound_Selector);
Expand Down
36 changes: 0 additions & 36 deletions src/ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,6 @@
#include "sass/base.h"
#include "ast_fwd_decl.hpp"

#ifdef DEBUG_SHARED_PTR

#define ATTACH_VIRTUAL_AST_OPERATIONS(klass) \
virtual klass##_Ptr copy(std::string, size_t) const = 0; \
virtual klass##_Ptr clone(std::string, size_t) const = 0; \

#define ATTACH_AST_OPERATIONS(klass) \
virtual klass##_Ptr copy(std::string, size_t) const; \
virtual klass##_Ptr clone(std::string, size_t) const; \

#else

#define ATTACH_VIRTUAL_AST_OPERATIONS(klass) \
virtual klass##_Ptr copy() const = 0; \
virtual klass##_Ptr clone() const = 0; \

#define ATTACH_AST_OPERATIONS(klass) \
virtual klass##_Ptr copy() const; \
virtual klass##_Ptr clone() const; \

#endif

#ifdef __clang__

/*
* There are some overloads used here that trigger the clang overload
* hiding warning. Specifically:
*
* Type type() which hides string type() from Expression
*
*/
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Woverloaded-virtual"

#endif

#include "util.hpp"
#include "units.hpp"
#include "context.hpp"
Expand Down
50 changes: 50 additions & 0 deletions src/ast_def_macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,54 @@ public: \
void name(type name##__) { hash_ = 0; name##_ = name##__; } \
private:

#ifdef DEBUG_SHARED_PTR

#define ATTACH_VIRTUAL_AST_OPERATIONS(klass) \
virtual klass##_Ptr copy(std::string, size_t) const = 0; \
virtual klass##_Ptr clone(std::string, size_t) const = 0; \

#define ATTACH_AST_OPERATIONS(klass) \
virtual klass##_Ptr copy(std::string, size_t) const; \
virtual klass##_Ptr clone(std::string, size_t) const; \

#else

#define ATTACH_VIRTUAL_AST_OPERATIONS(klass) \
virtual klass##_Ptr copy() const = 0; \
virtual klass##_Ptr clone() const = 0; \

#define ATTACH_AST_OPERATIONS(klass) \
virtual klass##_Ptr copy() const; \
virtual klass##_Ptr clone() const; \

#endif

#ifdef DEBUG_SHARED_PTR

#define IMPLEMENT_AST_OPERATORS(klass) \
klass##_Ptr klass::copy(std::string file, size_t line) const { \
klass##_Ptr cpy = new klass(this); \
cpy->trace(file, line); \
return cpy; \
} \
klass##_Ptr klass::clone(std::string file, size_t line) const { \
klass##_Ptr cpy = copy(file, line); \
cpy->cloneChildren(); \
return cpy; \
} \

#else

#define IMPLEMENT_AST_OPERATORS(klass) \
klass##_Ptr klass::copy() const { \
return new klass(this); \
} \
klass##_Ptr klass::clone() const { \
klass##_Ptr cpy = copy(); \
cpy->cloneChildren(); \
return cpy; \
} \

#endif

#endif

0 comments on commit 064d6de

Please sign in to comment.