Skip to content
Permalink
Browse files

Move AST memory macros to macro header

  • Loading branch information...
mgreter committed Mar 17, 2018
1 parent efc0331 commit 064d6dec7be3637e566a696b68e83e73ed88bfd9
Showing with 50 additions and 68 deletions.
  1. +0 −32 src/ast.cpp
  2. +0 −36 src/ast.hpp
  3. +50 −0 src/ast_def_macros.hpp
@@ -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);
@@ -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"
@@ -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.
You can’t perform that action at this time.