Skip to content

Commit 69eb4a6

Browse files
committed
[WIP] [DNM] Backport dart sass parser 5
1 parent 3886992 commit 69eb4a6

20 files changed

+201
-211
lines changed

include/sass/base.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define SASS_BASE_H
33

44
// #define DEBUG
5-
// #define DEBUG_SHARED_PTR
5+
#define DEBUG_SHARED_PTR
66

77
#ifdef _MSC_VER
88
#pragma warning(disable : 4503)

src/ast_values.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ namespace Sass {
936936
// debugger << "plain with more than one?\n";
937937
return "";
938938
}
939-
if (StringLiteral * str = Cast<StringLiteral>(first())) {
939+
if (StringLiteral* str = Cast<StringLiteral>(first())) {
940940
return str->text();
941941
}
942942
else {
@@ -1000,7 +1000,7 @@ namespace Sass {
10001000

10011001
InterpolationObj StringExpression2::getAsInterpolation(bool escape, uint8_t quote)
10021002
{
1003-
Interpolation* itpl = SASS_MEMORY_NEW(Interpolation, "[pstate]");
1003+
InterpolationObj itpl = SASS_MEMORY_NEW(Interpolation, "[pstate]");
10041004

10051005
if (!hasQuotes()) return text_;
10061006
// debugger << "do asInterpolation magic1\n";

src/context.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,7 @@ namespace Sass {
275275
}
276276

277277
std::string text(contents);
278-
const char* cstr = text.c_str();
279-
278+
280279
Block_Obj root;
281280

282281
if (Util::ascii_str_ends_with_insensitive(inc.abs_path, ".css")) {
@@ -300,7 +299,7 @@ namespace Sass {
300299
sass_import_take_srcmap(import);
301300
// then parse the root block
302301
root = SASS_MEMORY_NEW(Block, "[blk]", p2.parse(), true);
303-
302+
// debug_ast(root);
304303
}
305304

306305
// delete memory of current stack frame

src/debugger.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,9 @@ inline std::string pstate_source_position(AST_Node* node)
317317
<< "-[" << end.line << ":" << end.column << "]";
318318
#ifdef DEBUG_SHARED_PTR
319319
str << "x" << node->getRefCount() << ""
320-
<< " " << node->getDbgFile()
321-
<< "@" << node->getDbgLine();
320+
<< " {#" << node->objId << "}"
321+
<< " " << node->getDbgFile()
322+
<< "@" << node->getDbgLine();
322323
#endif
323324
return str.str();
324325
}
@@ -933,9 +934,9 @@ inline void debug_ast(AST_Node* node, std::string ind, Env* env)
933934
} else if (Cast<StringExpression2>(node)) {
934935
StringExpression2* expression = Cast<StringExpression2>(node);
935936
// std::cerr << ind << "StringExpression " << expression;
936-
// std::cerr << " (" << pstate_source_position(node) << ")";
937937
// std::cerr << " [" << prettyprint(expression->text()) << "]";
938938
std::cerr << ind << "StringExpression";
939+
std::cerr << " (" << pstate_source_position(node) << ")";
939940
if (expression->hasQuotes()) std::cerr << " {quoted}";
940941
std::cerr << std::endl;
941942
debug_ast(expression->text(), ind + " ");
@@ -968,9 +969,9 @@ inline void debug_ast(AST_Node* node, std::string ind, Env* env)
968969
} else if (Cast<Interpolation>(node)) {
969970
Interpolation* expression = Cast<Interpolation>(node);
970971
std::cerr << ind << "Interpolation";
972+
std::cerr << " (" << pstate_source_position(expression) << ")";
971973

972974
// std::cerr << ind << "Interpolation " << expression;
973-
// std::cerr << " (" << pstate_source_position(expression) << ")";
974975
// std::cerr << " " << expression->concrete_type();
975976
// std::cerr << " (" << pstate_source_position(node) << ")";
976977
std::cerr << std::endl;

src/devlog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Sass {
55
std::ostringstream stdnull;
66

77
void STDERR::writeln(const std::string& msg) {
8-
debugger << msg << "\n";
8+
// debugger << msg << "\n";
99
}
1010

1111
}

src/eval.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,7 +1384,7 @@ namespace Sass {
13841384

13851385
Expression* expression = value;
13861386
// debug_ast(expression, "perform now: ");
1387-
Expression* result = expression->perform(this);
1387+
ExpressionObj result = expression->perform(this);
13881388

13891389
if (String_Quoted * result = Cast<String_Quoted>(value)) {
13901390
// std::cerr << "have a quoted string\n";
@@ -1470,7 +1470,7 @@ namespace Sass {
14701470
// }
14711471
else {
14721472
// std::cerr << "perform item\n";
1473-
Expression* result = item->perform(this);
1473+
ExpressionObj result = item->perform(this);
14741474
// std::cerr << "performed item\n";
14751475
if (StringLiteral * lit = Cast<StringLiteral>(result)) {
14761476
// std::cerr << "APPEND STRING [" << lit->text() << "]\n";

src/expand.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ namespace Sass {
528528
auto back = block_stack.back();
529529
// block_stack.pop_back();
530530
for ( size_t i = 0, S = imp->incs().size(); i < S; ++i) {
531-
auto asd = SASS_MEMORY_NEW(Import_Stub, "[pstate]", imp->incs()[i]);
531+
Import_StubObj asd = SASS_MEMORY_NEW(Import_Stub, "[pstate]", imp->incs()[i]);
532532

533533
asd->perform(this);
534534
}
@@ -631,7 +631,7 @@ namespace Sass {
631631
if (!c->is_important()) return NULL;
632632
}
633633
eval.is_in_comment = true;
634-
Comment* rv = nullptr;
634+
CommentObj rv;
635635
if (Interpolation * itpl = Cast<Interpolation>(c->text())) {
636636
std::string text = performInterpolation(itpl);
637637
rv = SASS_MEMORY_NEW(Comment, c->pstate(), SASS_MEMORY_NEW(StringLiteral, "[pstate]", text), c->is_important());
@@ -642,7 +642,7 @@ namespace Sass {
642642
}
643643
eval.is_in_comment = false;
644644
// TODO: eval the text, once we're parsing/storing it as a String_Schema
645-
return rv;
645+
return rv.detach();
646646
}
647647

648648
Statement* Expand::operator()(If* i)
@@ -872,7 +872,7 @@ namespace Sass {
872872

873873
Expression* expression = value;
874874

875-
Expression* result = expression->perform(&eval);
875+
ExpressionObj result = expression->perform(&eval);
876876

877877
if (Cast<Null>(result)) continue;
878878
if (result == nullptr) continue;

src/fn_lists.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ namespace Sass {
203203
if (m) {
204204
l = m->to_list(pstate);
205205
}
206-
List* result = SASS_MEMORY_COPY(l);
206+
ListObj result = SASS_MEMORY_COPY(l);
207207
std::string sep_str(unquote(sep->value()));
208208
if (sep_str != "auto") { // check default first
209209
if (sep_str == "space") result->separator(SASS_SPACE);
@@ -221,7 +221,7 @@ namespace Sass {
221221
} else {
222222
result->append(v);
223223
}
224-
return result;
224+
return result.detach();
225225
}
226226

227227
Signature zip_sig = "zip($lists...)";

src/fn_utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Sass {
1313
{
1414
ScssParser p2(ctx, sig, 0, 0);
1515
std::string name(Util::normalize_underscores(p2.identifier()));
16-
Parameters_Obj params = p2.parseArgumentDeclaration();
16+
ParametersObj params = p2.parseArgumentDeclaration();
1717
return SASS_MEMORY_NEW(Definition,
1818
ParserState("[built-in function]"),
1919
sig, name, params, func, false);

src/interpolation.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace Sass {
2525

2626
Interpolation* InterpolationBuffer::getInterpolation()
2727
{
28-
auto itpl = SASS_MEMORY_NEW(Interpolation, "[pstate]");
28+
Interpolation* itpl = SASS_MEMORY_NEW(Interpolation, "[pstate]");
2929
for (PreValueObj item : contents) {
3030
// Appends an Expression
3131
itpl->append(item);
@@ -39,7 +39,7 @@ namespace Sass {
3939

4040
Interpolation* InterpolationBuffer::getInterpolation(ParserState pstate)
4141
{
42-
auto itpl = SASS_MEMORY_NEW(Interpolation, pstate);
42+
InterpolationObj itpl = SASS_MEMORY_NEW(Interpolation, pstate);
4343
for (PreValueObj item : contents) {
4444
// Appends an Expression
4545
itpl->append(item);
@@ -48,7 +48,9 @@ namespace Sass {
4848
// Appends a StringLiteral from the remaining text in the string buffer
4949
itpl->append(SASS_MEMORY_NEW(StringLiteral, pstate, text.toString()));
5050
}
51-
return itpl;
51+
size_t objId = itpl->objId;
52+
// debugger << itpl->objId << "\n";
53+
return itpl.detach();
5254
}
5355

5456
// Flushes [text] to [contents] if necessary.
@@ -105,11 +107,11 @@ namespace Sass {
105107

106108
}
107109

108-
void InterpolationBuffer::addInterpolation(const Interpolation* schema)
110+
void InterpolationBuffer::addInterpolation(const InterpolationObj schema)
109111
{
110112
if (schema->empty()) return;
111113
// debug_ast(schema);
112-
debugger << "addInterpolation [" << schema->to_string() << "]\n";
114+
// debugger << "addInterpolation [" << schema->to_string() << "]\n";
113115

114116
auto& elements = schema->elements();
115117
auto addStart = elements.begin();

0 commit comments

Comments
 (0)