Skip to content

Commit 9719966

Browse files
committed
Load can't be moved to compiler.cpp
Since meta.load-css is fully dynamic! Maybe marry compiler and eval even?
1 parent 5f65664 commit 9719966

File tree

11 files changed

+43
-61
lines changed

11 files changed

+43
-61
lines changed

src/ast_values.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ namespace Sass {
697697
return l.value() > r.value();
698698
}
699699
// Throw error, unit are incompatible
700-
logger.addFinalStackTrace(pstate);//XXX
700+
callStackFrame csf(logger, pstate);
701701
throw Exception::UnitMismatch(
702702
logger, this, rhs);
703703
}
@@ -726,7 +726,7 @@ namespace Sass {
726726
return l.value() >= r.value();
727727
}
728728
// Throw error, unit are incompatible
729-
logger.addFinalStackTrace(pstate);//XXX
729+
callStackFrame csf(logger, pstate);
730730
throw Exception::UnitMismatch(
731731
logger, this, rhs);
732732
}
@@ -755,7 +755,7 @@ namespace Sass {
755755
return l.value() < r.value();
756756
}
757757
// Throw error, unit are incompatible
758-
logger.addFinalStackTrace(pstate);//XXX
758+
callStackFrame csf(logger, pstate);
759759
throw Exception::UnitMismatch(
760760
logger, this, rhs);
761761
}

src/backtrace.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ namespace Sass {
5151
return name;
5252
}
5353

54+
bool operator==(const StackTrace& other) const {
55+
return pstate == other.pstate &&
56+
name == other.name && fn == other.fn;
57+
}
58+
5459
bool isFn() const override final {
5560
return fn;
5661
}

src/compiler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include "fn_colors.hpp"
2626
#include "fn_selectors.hpp"
2727

28+
#include "preloader.hpp"
29+
2830
#include <cstring>
2931
#include <csignal>
3032
#ifdef _MSC_VER
@@ -239,6 +241,9 @@ struct SassValue* fn_##fn(struct SassValue* s_args, Sass_Function_Entry cb, stru
239241

240242
Eval eval(*this, *this, plainCss);
241243

244+
// Preloader preloader(*this, root);
245+
// preloader.process();
246+
242247
CssRootObj compiled = eval.acceptRoot(root); // 50%
243248
// debug_ast(compiled);
244249

src/context.hpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,6 @@ namespace Sass {
5252
// Same order needed for function stack
5353
std::vector<CallableObj> fnList;
5454

55-
// Lookup functions by function name
56-
// Due to EnvKayMap case insensitive.
57-
EnvKeyMap<CallableObj> fnLookup;
58-
59-
6055
public:
6156

6257
// sass::vector<WithConfigVar>* withConfig = nullptr;

src/environment.cpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -526,24 +526,17 @@ namespace Sass {
526526
ImportObj loaded = compiler.loadImport(resolved[0]);
527527
ImportStackFrame iframe(compiler, loaded);
528528

529-
Root* sheet = nullptr;
530529
sass::string abspath(loaded->getAbsPath());
531530
auto cached = compiler.sheets.find(abspath);
532531
if (cached != compiler.sheets.end()) {
533-
sheet = cached->second;
532+
return cached->second;
534533
}
535-
else {
536-
// Permeable seems to have minor negative impact!?
537-
EnvFrame local(compiler, false, true, isImport); // correct
538-
sheet = compiler.registerImport(loaded);
539-
sheet->idxs = local.idxs;
540-
sheet->import = loaded;
541-
}
542-
543-
// rule->module(sheet);
544-
// rule->sheet(sheet);
545534

546-
// wconfig.finalize();
535+
// Permeable seems to have minor negative impact!?
536+
EnvFrame local(compiler, false, true, isImport); // correct
537+
Root* sheet = compiler.registerImport(loaded);
538+
sheet->idxs = local.idxs;
539+
sheet->import = loaded;
547540
return sheet;
548541
}
549542

@@ -796,7 +789,6 @@ namespace Sass {
796789
rule->wasExported(true);
797790
}
798791
else if (frame->module->moduse.count(rule->ns())) {
799-
compiler.addFinalStackTrace(rule->pstate());//XXX
800792
throw Exception::ModuleAlreadyKnown(compiler, rule->ns());
801793
}
802794
else {

src/fn_colors.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,8 +1060,7 @@ namespace Sass {
10601060
// Support the proprietary Microsoft alpha() function.
10611061
return getFunctionString(Strings::alpha, pstate, arguments);
10621062
}
1063-
compiler.addFinalStackTrace(arguments[0]->pstate());//XXX
1064-
// callStackFrame csf(compiler, arguments[0]->pstate());
1063+
callStackFrame csf(compiler, arguments[0]->pstate());
10651064
throw Exception::TooManyArguments(compiler, size, 1);
10661065
}
10671066

src/fn_selectors.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ namespace Sass {
5151
// Iterate over the rest argument list
5252
for (Value* arg : arguments[0]->iterator()) {
5353
if (arg->isNull()) {
54-
// compiler.addFinalStackTrace(arg->pstate());
5554
callStackFrame csf(compiler, arg->pstate());
5655
throw Exception::RuntimeException(compiler, // "$selectors: "
5756
"null is not a valid selector: it must be a string,\n"

src/logger.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ namespace Sass {
596596

597597
i_beg = traces.size() - 1;
598598
i_end = sass::string::npos;
599+
const StackTrace* prev = nullptr;
599600
for (size_t i = i_beg; i != i_end; i--) {
600601

601602
const StackTrace& trace = traces[i];
@@ -607,8 +608,10 @@ namespace Sass {
607608
// if (trace.caller.substr(0, 6) == ", in f") continue;
608609

609610
if (amount == sass::string::npos || amount > 0) {
611+
if (prev && *prev == trace) continue;
610612
printSourceSpan(trace.pstate, os, style);
611613
if (amount > 0) --amount;
614+
prev = &trace;
612615
}
613616

614617
if (showPos) {

src/logger.hpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,6 @@ namespace Sass {
3434
// Flag for unicode and/or color
3535
enum SassLoggerStyle style;
3636

37-
// Append the pstate if not already there
38-
// Only call this right before throwing errors
39-
// DONT USE, CAN LEAD TO SEGFAULTS IF THE ERROR
40-
// WE THROW RIGHT AFTER IS CAUGHT AND BACKTRACKED
41-
void addFinalStackTrace(const SourceSpan& pstate)
42-
{
43-
if (callStack.empty()) {
44-
callStack.push_back(pstate);
45-
}
46-
else {
47-
BackTrace& trace(callStack.back());
48-
if (!(trace.pstate == pstate)) {
49-
callStack.push_back(pstate);
50-
}
51-
}
52-
}
53-
// EO addFinalStackTrace
54-
5537
private:
5638

5739
// Split the line to three parts for error reporting.

src/preloader.cpp

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace Sass {
1414
Preloader::Preloader(Eval& eval, Root* root) :
1515
eval(eval),
1616
root(root),
17+
compiler(eval.compiler),
1718
chroot77(eval.chroot77),
1819
wconfig(eval.wconfig),
1920
idxs(root->idxs)
@@ -32,41 +33,41 @@ namespace Sass {
3233
if (sheet && !sheet->empty()) {
3334
LOCAL_PTR(Root, chroot77, sheet);
3435
LOCAL_PTR(EnvRefs, idxs, sheet->idxs);
35-
ImportStackFrame isf(eval.compiler, sheet->import);
36-
eval.compiler.varRoot.stack.push_back(sheet->idxs);
36+
ImportStackFrame isf(compiler, sheet->import);
37+
compiler.varRoot.stack.push_back(sheet->idxs);
3738
for (auto& it : sheet->elements()) it->accept(this);
38-
eval.compiler.varRoot.stack.pop_back();
39+
compiler.varRoot.stack.pop_back();
3940
}
4041
}
4142

4243
void Preloader::visitParentStatement(ParentStatement* rule)
4344
{
4445
if (rule->empty()) return;
4546
LOCAL_PTR(EnvRefs, idxs, rule->idxs);
46-
eval.compiler.varRoot.stack.push_back(rule->idxs);
47+
compiler.varRoot.stack.push_back(rule->idxs);
4748
for (auto& it : rule->elements()) it->accept(this);
48-
eval.compiler.varRoot.stack.pop_back();
49+
compiler.varRoot.stack.pop_back();
4950
}
5051

5152
void Preloader::visitUseRule(UseRule* rule)
5253
{
53-
callStackFrame frame(eval.compiler, {
54+
callStackFrame frame(compiler, {
5455
rule->pstate(), Strings::useRule });
5556
acceptRoot(eval.loadModRule(rule));
5657
eval.exposeUseRule(rule);
5758
}
5859

5960
void Preloader::visitForwardRule(ForwardRule* rule)
6061
{
61-
callStackFrame frame(eval.compiler, {
62+
callStackFrame frame(compiler, {
6263
rule->pstate(), Strings::forwardRule });
6364
acceptRoot(eval.loadModRule(rule));
6465
eval.exposeFwdRule(rule);
6566
}
6667

6768
void Preloader::visitIncludeImport(IncludeImport* rule)
6869
{
69-
callStackFrame frame(eval.compiler, {
70+
callStackFrame frame(compiler, {
7071
rule->pstate(), Strings::importRule });
7172
acceptRoot(eval.resolveIncludeImport(rule));
7273
eval.exposeImpRule(rule);
@@ -81,18 +82,18 @@ namespace Sass {
8182
{
8283
// const EnvKey& fname(rule->name());
8384
LOCAL_PTR(EnvRefs, idxs, rule->idxs);
84-
eval.compiler.varRoot.stack.push_back(rule->idxs);
85+
compiler.varRoot.stack.push_back(rule->idxs);
8586
for (auto& it : rule->elements()) it->accept(this);
86-
eval.compiler.varRoot.stack.pop_back();
87+
compiler.varRoot.stack.pop_back();
8788
}
8889

8990
void Preloader::visitMixinRule(MixinRule* rule)
9091
{
9192
// const EnvKey& mname(rule->name());
9293
LOCAL_PTR(EnvRefs, idxs, rule->idxs);
93-
eval.compiler.varRoot.stack.push_back(rule->idxs);
94+
compiler.varRoot.stack.push_back(rule->idxs);
9495
for (auto& it : rule->elements()) it->accept(this);
95-
eval.compiler.varRoot.stack.pop_back();
96+
compiler.varRoot.stack.pop_back();
9697
}
9798

9899
void Preloader::visitImportRule(ImportRule* rule)
@@ -153,9 +154,9 @@ namespace Sass {
153154
{
154155
if (ContentBlock* content = rule->content()) {
155156
LOCAL_PTR(EnvRefs, idxs, content->idxs);
156-
eval.compiler.varRoot.stack.push_back(content->idxs);
157+
compiler.varRoot.stack.push_back(content->idxs);
157158
for (auto& it : content->elements()) it->accept(this);
158-
eval.compiler.varRoot.stack.pop_back();
159+
compiler.varRoot.stack.pop_back();
159160
}
160161
}
161162

@@ -175,18 +176,18 @@ namespace Sass {
175176
for (size_t i = 0; i < vars.size(); i += 1) {
176177
idxs->varIdxs.insert({ vars[i], (uint32_t)i });
177178
}
178-
eval.compiler.varRoot.stack.push_back(rule->idxs);
179+
compiler.varRoot.stack.push_back(rule->idxs);
179180
for (auto& it : rule->elements()) it->accept(this);
180-
eval.compiler.varRoot.stack.pop_back();
181+
compiler.varRoot.stack.pop_back();
181182
}
182183

183184
void Preloader::visitForRule(ForRule* rule)
184185
{
185186
LOCAL_PTR(EnvRefs, idxs, rule->idxs);
186187
idxs->varIdxs.insert({ rule->varname(), 0 });
187-
eval.compiler.varRoot.stack.push_back(rule->idxs);
188+
compiler.varRoot.stack.push_back(rule->idxs);
188189
for (auto& it : rule->elements()) it->accept(this);
189-
eval.compiler.varRoot.stack.pop_back();
190+
compiler.varRoot.stack.pop_back();
190191
}
191192

192193
void Preloader::visitReturnRule(ReturnRule* rule)

0 commit comments

Comments
 (0)