Skip to content

Commit 205dc65

Browse files
committed
Remove Function_Call_Schema class
- handle in Function_Call directly
1 parent 0599b2e commit 205dc65

File tree

12 files changed

+88
-89
lines changed

12 files changed

+88
-89
lines changed

src/ast.cpp

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2108,6 +2108,44 @@ namespace Sass {
21082108
}
21092109
}
21102110

2111+
Function_Call::Function_Call(ParserState pstate, std::string n, Arguments_Obj args, void* cookie)
2112+
: PreValue(pstate), sname_(SASS_MEMORY_NEW(String_Constant, pstate, n)), arguments_(args), func_(0), via_call_(false), cookie_(cookie), hash_(0)
2113+
{ concrete_type(FUNCTION); }
2114+
Function_Call::Function_Call(ParserState pstate, std::string n, Arguments_Obj args, Function_Obj func)
2115+
: PreValue(pstate), sname_(SASS_MEMORY_NEW(String_Constant, pstate, n)), arguments_(args), func_(func), via_call_(false), cookie_(0), hash_(0)
2116+
{ concrete_type(FUNCTION); }
2117+
Function_Call::Function_Call(ParserState pstate, std::string n, Arguments_Obj args)
2118+
: PreValue(pstate), sname_(SASS_MEMORY_NEW(String_Constant, pstate, n)), arguments_(args), via_call_(false), cookie_(0), hash_(0)
2119+
{ concrete_type(FUNCTION); }
2120+
2121+
bool Function_Call::operator==(const Expression& rhs) const
2122+
{
2123+
try
2124+
{
2125+
Function_Call_Ptr_Const m = Cast<Function_Call>(&rhs);
2126+
if (!(m && *sname() == *m->sname())) return false;
2127+
if (!(m && arguments()->length() == m->arguments()->length())) return false;
2128+
for (size_t i =0, L = arguments()->length(); i < L; ++i)
2129+
if (!(*(*arguments())[i] == *(*m->arguments())[i])) return false;
2130+
return true;
2131+
}
2132+
catch (std::bad_cast&)
2133+
{
2134+
return false;
2135+
}
2136+
catch (...) { throw; }
2137+
}
2138+
2139+
size_t Function_Call::hash()
2140+
{
2141+
if (hash_ == 0) {
2142+
hash_ = std::hash<std::string>()(name());
2143+
for (auto argument : arguments()->elements())
2144+
hash_combine(hash_, argument->hash());
2145+
}
2146+
return hash_;
2147+
}
2148+
21112149
//////////////////////////////////////////////////////////////////////////////////////////
21122150
// Convert map to (key, value) list.
21132151
//////////////////////////////////////////////////////////////////////////////////////////
@@ -2181,7 +2219,6 @@ namespace Sass {
21812219
IMPLEMENT_AST_OPERATORS(Arguments);
21822220
IMPLEMENT_AST_OPERATORS(Argument);
21832221
IMPLEMENT_AST_OPERATORS(Unary_Expression);
2184-
IMPLEMENT_AST_OPERATORS(Function_Call_Schema);
21852222
IMPLEMENT_AST_OPERATORS(Block);
21862223
IMPLEMENT_AST_OPERATORS(Content);
21872224
IMPLEMENT_AST_OPERATORS(Trace);

src/ast.hpp

Lines changed: 26 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ namespace Sass {
8181
: pstate_(ptr->pstate_)
8282
{ }
8383

84+
// allow implicit conversion to string
85+
// needed for by SharedPtr implementation
86+
operator std::string() {
87+
return to_string();
88+
}
89+
8490
// AST_Node(AST_Node& ptr) = delete;
8591

8692
virtual ~AST_Node() = 0;
@@ -1429,25 +1435,34 @@ namespace Sass {
14291435
// Function calls.
14301436
//////////////////
14311437
class Function_Call : public PreValue {
1432-
HASH_CONSTREF(std::string, name)
1438+
HASH_CONSTREF(String_Obj, sname)
14331439
HASH_PROPERTY(Arguments_Obj, arguments)
14341440
HASH_PROPERTY(Function_Obj, func)
14351441
ADD_PROPERTY(bool, via_call)
14361442
ADD_PROPERTY(void*, cookie)
14371443
size_t hash_;
14381444
public:
1439-
Function_Call(ParserState pstate, std::string n, Arguments_Obj args, void* cookie)
1440-
: PreValue(pstate), name_(n), arguments_(args), func_(0), via_call_(false), cookie_(cookie), hash_(0)
1445+
Function_Call(ParserState pstate, std::string n, Arguments_Obj args, void* cookie);
1446+
Function_Call(ParserState pstate, std::string n, Arguments_Obj args, Function_Obj func);
1447+
Function_Call(ParserState pstate, std::string n, Arguments_Obj args);
1448+
1449+
Function_Call(ParserState pstate, String_Obj n, Arguments_Obj args, void* cookie)
1450+
: PreValue(pstate), sname_(n), arguments_(args), func_(0), via_call_(false), cookie_(cookie), hash_(0)
14411451
{ concrete_type(FUNCTION); }
1442-
Function_Call(ParserState pstate, std::string n, Arguments_Obj args, Function_Obj func)
1443-
: PreValue(pstate), name_(n), arguments_(args), func_(func), via_call_(false), cookie_(0), hash_(0)
1452+
Function_Call(ParserState pstate, String_Obj n, Arguments_Obj args, Function_Obj func)
1453+
: PreValue(pstate), sname_(n), arguments_(args), func_(func), via_call_(false), cookie_(0), hash_(0)
14441454
{ concrete_type(FUNCTION); }
1445-
Function_Call(ParserState pstate, std::string n, Arguments_Obj args)
1446-
: PreValue(pstate), name_(n), arguments_(args), via_call_(false), cookie_(0), hash_(0)
1455+
Function_Call(ParserState pstate, String_Obj n, Arguments_Obj args)
1456+
: PreValue(pstate), sname_(n), arguments_(args), via_call_(false), cookie_(0), hash_(0)
14471457
{ concrete_type(FUNCTION); }
1458+
1459+
std::string name() {
1460+
return sname();
1461+
}
1462+
14481463
Function_Call(const Function_Call* ptr)
14491464
: PreValue(ptr),
1450-
name_(ptr->name_),
1465+
sname_(ptr->sname_),
14511466
arguments_(ptr->arguments_),
14521467
func_(ptr->func_),
14531468
via_call_(ptr->via_call_),
@@ -1460,53 +1475,11 @@ namespace Sass {
14601475
return false;
14611476
}
14621477

1463-
virtual bool operator==(const Expression& rhs) const
1464-
{
1465-
try
1466-
{
1467-
Function_Call_Ptr_Const m = Cast<Function_Call>(&rhs);
1468-
if (!(m && name() == m->name())) return false;
1469-
if (!(m && arguments()->length() == m->arguments()->length())) return false;
1470-
for (size_t i =0, L = arguments()->length(); i < L; ++i)
1471-
if (!(*(*arguments())[i] == *(*m->arguments())[i])) return false;
1472-
return true;
1473-
}
1474-
catch (std::bad_cast&)
1475-
{
1476-
return false;
1477-
}
1478-
catch (...) { throw; }
1479-
}
1478+
virtual bool operator==(const Expression& rhs) const;
14801479

1481-
virtual size_t hash()
1482-
{
1483-
if (hash_ == 0) {
1484-
hash_ = std::hash<std::string>()(name());
1485-
for (auto argument : arguments()->elements())
1486-
hash_combine(hash_, argument->hash());
1487-
}
1488-
return hash_;
1489-
}
1490-
ATTACH_AST_OPERATIONS(Function_Call)
1491-
ATTACH_CRTP_PERFORM_METHODS()
1492-
};
1480+
virtual size_t hash();
14931481

1494-
/////////////////////////
1495-
// Function call schemas.
1496-
/////////////////////////
1497-
class Function_Call_Schema : public Expression {
1498-
ADD_PROPERTY(String_Obj, name)
1499-
ADD_PROPERTY(Arguments_Obj, arguments)
1500-
public:
1501-
Function_Call_Schema(ParserState pstate, String_Obj n, Arguments_Obj args)
1502-
: Expression(pstate), name_(n), arguments_(args)
1503-
{ concrete_type(STRING); }
1504-
Function_Call_Schema(const Function_Call_Schema* ptr)
1505-
: Expression(ptr),
1506-
name_(ptr->name_),
1507-
arguments_(ptr->arguments_)
1508-
{ concrete_type(STRING); }
1509-
ATTACH_AST_OPERATIONS(Function_Call_Schema)
1482+
ATTACH_AST_OPERATIONS(Function_Call)
15101483
ATTACH_CRTP_PERFORM_METHODS()
15111484
};
15121485

src/ast_fwd_decl.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,6 @@ namespace Sass {
149149
class Function_Call;
150150
typedef Function_Call* Function_Call_Ptr;
151151
typedef Function_Call const* Function_Call_Ptr_Const;
152-
class Function_Call_Schema;
153-
typedef Function_Call_Schema* Function_Call_Schema_Ptr;
154-
typedef Function_Call_Schema const* Function_Call_Schema_Ptr_Const;
155152
class Custom_Warning;
156153
typedef Custom_Warning* Custom_Warning_Ptr;
157154
typedef Custom_Warning const* Custom_Warning_Ptr_Const;
@@ -319,7 +316,6 @@ namespace Sass {
319316
IMPL_MEM_OBJ(Binary_Expression);
320317
IMPL_MEM_OBJ(Unary_Expression);
321318
IMPL_MEM_OBJ(Function_Call);
322-
IMPL_MEM_OBJ(Function_Call_Schema);
323319
IMPL_MEM_OBJ(Custom_Warning);
324320
IMPL_MEM_OBJ(Custom_Error);
325321
IMPL_MEM_OBJ(Variable);

src/debugger.hpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -497,14 +497,6 @@ inline void debug_ast(AST_Node_Ptr node, std::string ind, Env* env)
497497
std::cerr << " [" << expression->name() << "]" << std::endl;
498498
std::string name(expression->name());
499499
if (env && env->has(name)) debug_ast(Cast<Expression>((*env)[name]), ind + " -> ", env);
500-
} else if (Cast<Function_Call_Schema>(node)) {
501-
Function_Call_Schema_Ptr expression = Cast<Function_Call_Schema>(node);
502-
std::cerr << ind << "Function_Call_Schema " << expression;
503-
std::cerr << " [interpolant: " << expression->is_interpolant() << "] ";
504-
std::cerr << " (" << pstate_source_position(node) << ")";
505-
std::cerr << "" << std::endl;
506-
debug_ast(expression->name(), ind + "name: ", env);
507-
debug_ast(expression->arguments(), ind + " args: ", env);
508500
} else if (Cast<Function_Call>(node)) {
509501
Function_Call_Ptr expression = Cast<Function_Call>(node);
510502
std::cerr << ind << "Function_Call " << expression;

src/eval.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -931,8 +931,18 @@ namespace Sass {
931931
stm << "Stack depth exceeded max of " << Constants::MaxCallStack;
932932
error(stm.str(), c->pstate(), traces);
933933
}
934+
935+
if (Cast<String_Schema>(c->sname())) {
936+
Expression_Ptr evaluated_name = c->sname()->perform(this);
937+
Expression_Ptr evaluated_args = c->arguments()->perform(this);
938+
std::string str(evaluated_name->to_string());
939+
str += evaluated_args->to_string();
940+
return SASS_MEMORY_NEW(String_Constant, c->pstate(), str);
941+
}
942+
934943
std::string name(Util::normalize_underscores(c->name()));
935944
std::string full_name(name + "[f]");
945+
936946
// we make a clone here, need to implement that further
937947
Arguments_Obj args = c->arguments();
938948

@@ -1090,16 +1100,6 @@ namespace Sass {
10901100
return result.detach();
10911101
}
10921102

1093-
Expression_Ptr Eval::operator()(Function_Call_Schema_Ptr s)
1094-
{
1095-
Expression_Ptr evaluated_name = s->name()->perform(this);
1096-
Expression_Ptr evaluated_args = s->arguments()->perform(this);
1097-
String_Schema_Obj ss = SASS_MEMORY_NEW(String_Schema, s->pstate(), 2);
1098-
ss->append(evaluated_name);
1099-
ss->append(evaluated_args);
1100-
return ss->perform(this);
1101-
}
1102-
11031103
Expression_Ptr Eval::operator()(Variable_Ptr v)
11041104
{
11051105
Expression_Obj value = 0;

src/eval.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ namespace Sass {
4848
Expression_Ptr operator()(Binary_Expression_Ptr);
4949
Expression_Ptr operator()(Unary_Expression_Ptr);
5050
Expression_Ptr operator()(Function_Call_Ptr);
51-
Expression_Ptr operator()(Function_Call_Schema_Ptr);
5251
Expression_Ptr operator()(Variable_Ptr);
5352
Expression_Ptr operator()(Number_Ptr);
5453
Expression_Ptr operator()(Color_Ptr);

src/inspect.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -513,12 +513,6 @@ namespace Sass {
513513
call->arguments()->perform(this);
514514
}
515515

516-
void Inspect::operator()(Function_Call_Schema_Ptr call)
517-
{
518-
call->name()->perform(this);
519-
call->arguments()->perform(this);
520-
}
521-
522516
void Inspect::operator()(Variable_Ptr var)
523517
{
524518
append_token(var->name(), var);

src/inspect.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ namespace Sass {
5151
virtual void operator()(Binary_Expression_Ptr);
5252
virtual void operator()(Unary_Expression_Ptr);
5353
virtual void operator()(Function_Call_Ptr);
54-
virtual void operator()(Function_Call_Schema_Ptr);
5554
// virtual void operator()(Custom_Warning_Ptr);
5655
// virtual void operator()(Custom_Error_Ptr);
5756
virtual void operator()(Variable_Ptr);

src/memory/SharedPtr.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ namespace Sass {
7878
static void setTaint(bool val) {
7979
taint = val;
8080
}
81+
82+
virtual const std::string to_string() const = 0;
83+
8184
virtual ~SharedObj();
8285
long getRefCount() {
8386
return refcounter;
@@ -169,6 +172,14 @@ namespace Sass {
169172
}
170173
return *this;
171174
}
175+
176+
// allow implicit conversion to string
177+
// relies on base class implementation
178+
operator const std::string() const {
179+
if (node) return node->to_string();
180+
else return std::string("[NULLPTR]");
181+
}
182+
172183
~SharedImpl() {};
173184
public:
174185
operator T*() const {

src/operation.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ namespace Sass {
6363
virtual T operator()(Binary_Expression_Ptr x) = 0;
6464
virtual T operator()(Unary_Expression_Ptr x) = 0;
6565
virtual T operator()(Function_Call_Ptr x) = 0;
66-
virtual T operator()(Function_Call_Schema_Ptr x) = 0;
6766
virtual T operator()(Custom_Warning_Ptr x) = 0;
6867
virtual T operator()(Custom_Error_Ptr x) = 0;
6968
virtual T operator()(Variable_Ptr x) = 0;
@@ -144,7 +143,6 @@ namespace Sass {
144143
T operator()(Binary_Expression_Ptr x) { return static_cast<D*>(this)->fallback(x); }
145144
T operator()(Unary_Expression_Ptr x) { return static_cast<D*>(this)->fallback(x); }
146145
T operator()(Function_Call_Ptr x) { return static_cast<D*>(this)->fallback(x); }
147-
T operator()(Function_Call_Schema_Ptr x) { return static_cast<D*>(this)->fallback(x); }
148146
T operator()(Custom_Warning_Ptr x) { return static_cast<D*>(this)->fallback(x); }
149147
T operator()(Custom_Error_Ptr x) { return static_cast<D*>(this)->fallback(x); }
150148
T operator()(Variable_Ptr x) { return static_cast<D*>(this)->fallback(x); }

0 commit comments

Comments
 (0)