Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
Remove _Ptr(_Const) typedefs (#2847)
Browse files Browse the repository at this point in the history
Removes these typedefs because pointers should be handled with care.
Having them visually stand out in the code helps us avoid common pitfalls,
such as accidentally using `Ptr` instead of `Obj`.

This change has been automatically generated using the following command:

```bash
find src \( -name '*.cpp' -o -name '*.hpp' \) -exec sed -i \
'/typedef.*_Ptr[_;]/d;'\
's/\([A-Za-z_]*\)_Ptr_Const/const \1*/g;'\
's/\([A-Za-z_]*\)_Ptr/\1*/g;'\
's/\([a-z]\)##\*/\1*/g' '{}' \+
```

Fixes #2785
  • Loading branch information
glebm authored and xzyfer committed Mar 20, 2019
1 parent 20b91ef commit c55821a
Show file tree
Hide file tree
Showing 69 changed files with 1,439 additions and 1,595 deletions.
10 changes: 5 additions & 5 deletions src/ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ namespace Sass {
Inspect i(emitter);
i.in_declaration = true;
// ToDo: inspect should be const
const_cast<AST_Node_Ptr>(this)->perform(&i);
const_cast<AST_Node*>(this)->perform(&i);
return i.get_buffer();
}

Expand Down Expand Up @@ -173,7 +173,7 @@ namespace Sass {
{ statement_type(RULESET); }

bool Ruleset::is_invisible() const {
if (Selector_List_Ptr sl = Cast<Selector_List>(selector())) {
if (Selector_List* sl = Cast<Selector_List>(selector())) {
for (size_t i = 0, L = sl->length(); i < L; ++i)
if (!(*sl)[i]->has_placeholder()) return false;
}
Expand Down Expand Up @@ -594,7 +594,7 @@ namespace Sass {
{
try
{
Unary_Expression_Ptr_Const m = Cast<Unary_Expression>(&rhs);
const Unary_Expression* m = Cast<Unary_Expression>(&rhs);
if (m == 0) return false;
return type() == m->type() &&
*operand() == *m->operand();
Expand Down Expand Up @@ -647,7 +647,7 @@ namespace Sass {
{
try
{
Argument_Ptr_Const m = Cast<Argument>(&rhs);
const Argument* m = Cast<Argument>(&rhs);
if (!(m && name() == m->name())) return false;
return *value() == *m->value();
}
Expand Down Expand Up @@ -794,7 +794,7 @@ namespace Sass {
bool At_Root_Query::exclude(std::string str)
{
bool with = feature() && unquote(feature()->to_string()).compare("with") == 0;
List_Ptr l = static_cast<List_Ptr>(value().ptr());
List* l = static_cast<List*>(value().ptr());
std::string v;

if (with)
Expand Down
26 changes: 13 additions & 13 deletions src/ast2c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@

namespace Sass {

union Sass_Value* AST2C::operator()(Boolean_Ptr b)
union Sass_Value* AST2C::operator()(Boolean* b)
{ return sass_make_boolean(b->value()); }

union Sass_Value* AST2C::operator()(Number_Ptr n)
union Sass_Value* AST2C::operator()(Number* n)
{ return sass_make_number(n->value(), n->unit().c_str()); }

union Sass_Value* AST2C::operator()(Custom_Warning_Ptr w)
union Sass_Value* AST2C::operator()(Custom_Warning* w)
{ return sass_make_warning(w->message().c_str()); }

union Sass_Value* AST2C::operator()(Custom_Error_Ptr e)
union Sass_Value* AST2C::operator()(Custom_Error* e)
{ return sass_make_error(e->message().c_str()); }

union Sass_Value* AST2C::operator()(Color_RGBA_Ptr c)
union Sass_Value* AST2C::operator()(Color_RGBA* c)
{ return sass_make_color(c->r(), c->g(), c->b(), c->a()); }

union Sass_Value* AST2C::operator()(Color_HSLA_Ptr c)
union Sass_Value* AST2C::operator()(Color_HSLA* c)
{
Color_RGBA_Obj rgba = c->copyAsRGBA();
return operator()(rgba.ptr());
}

union Sass_Value* AST2C::operator()(String_Constant_Ptr s)
union Sass_Value* AST2C::operator()(String_Constant* s)
{
if (s->quote_mark()) {
return sass_make_qstring(s->value().c_str());
Expand All @@ -37,10 +37,10 @@ namespace Sass {
}
}

union Sass_Value* AST2C::operator()(String_Quoted_Ptr s)
union Sass_Value* AST2C::operator()(String_Quoted* s)
{ return sass_make_qstring(s->value().c_str()); }

union Sass_Value* AST2C::operator()(List_Ptr l)
union Sass_Value* AST2C::operator()(List* l)
{
union Sass_Value* v = sass_make_list(l->length(), l->separator(), l->is_bracketed());
for (size_t i = 0, L = l->length(); i < L; ++i) {
Expand All @@ -49,7 +49,7 @@ namespace Sass {
return v;
}

union Sass_Value* AST2C::operator()(Map_Ptr m)
union Sass_Value* AST2C::operator()(Map* m)
{
union Sass_Value* v = sass_make_map(m->length());
int i = 0;
Expand All @@ -61,7 +61,7 @@ namespace Sass {
return v;
}

union Sass_Value* AST2C::operator()(Arguments_Ptr a)
union Sass_Value* AST2C::operator()(Arguments* a)
{
union Sass_Value* v = sass_make_list(a->length(), SASS_COMMA, false);
for (size_t i = 0, L = a->length(); i < L; ++i) {
Expand All @@ -70,11 +70,11 @@ namespace Sass {
return v;
}

union Sass_Value* AST2C::operator()(Argument_Ptr a)
union Sass_Value* AST2C::operator()(Argument* a)
{ return a->value()->perform(this); }

// not strictly necessary because of the fallback
union Sass_Value* AST2C::operator()(Null_Ptr n)
union Sass_Value* AST2C::operator()(Null* n)
{ return sass_make_null(); }

};
28 changes: 14 additions & 14 deletions src/ast2c.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ namespace Sass {
AST2C() { }
~AST2C() { }

union Sass_Value* operator()(Boolean_Ptr);
union Sass_Value* operator()(Number_Ptr);
union Sass_Value* operator()(Color_RGBA_Ptr);
union Sass_Value* operator()(Color_HSLA_Ptr);
union Sass_Value* operator()(String_Constant_Ptr);
union Sass_Value* operator()(String_Quoted_Ptr);
union Sass_Value* operator()(Custom_Warning_Ptr);
union Sass_Value* operator()(Custom_Error_Ptr);
union Sass_Value* operator()(List_Ptr);
union Sass_Value* operator()(Map_Ptr);
union Sass_Value* operator()(Null_Ptr);
union Sass_Value* operator()(Arguments_Ptr);
union Sass_Value* operator()(Argument_Ptr);
union Sass_Value* operator()(Boolean*);
union Sass_Value* operator()(Number*);
union Sass_Value* operator()(Color_RGBA*);
union Sass_Value* operator()(Color_HSLA*);
union Sass_Value* operator()(String_Constant*);
union Sass_Value* operator()(String_Quoted*);
union Sass_Value* operator()(Custom_Warning*);
union Sass_Value* operator()(Custom_Error*);
union Sass_Value* operator()(List*);
union Sass_Value* operator()(Map*);
union Sass_Value* operator()(Null*);
union Sass_Value* operator()(Arguments*);
union Sass_Value* operator()(Argument*);

// return sass error if type is not supported
union Sass_Value* fallback(AST_Node_Ptr x)
union Sass_Value* fallback(AST_Node* x)
{ return sass_make_error("unknown type for C-API"); }

};
Expand Down
38 changes: 19 additions & 19 deletions src/ast_def_macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,59 +70,59 @@ public: \
#ifdef DEBUG_SHARED_PTR

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

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

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

#else

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

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

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

#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); \
klass* klass::copy(std::string file, size_t line) const { \
klass* 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); \
klass* klass::clone(std::string file, size_t line) const { \
klass* cpy = copy(file, line); \
cpy->cloneChildren(); \
return cpy; \
} \

#else

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

0 comments on commit c55821a

Please sign in to comment.