Skip to content

Commit f519665

Browse files
committed
Refactor instanciateSymbol.
1 parent 82e801a commit f519665

File tree

1 file changed

+22
-37
lines changed

1 file changed

+22
-37
lines changed

src/d/semantic/identifier.d

Lines changed: 22 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -292,46 +292,31 @@ private:
292292
}
293293
})(a)).array();
294294

295-
CompileError ce;
296-
Symbol instantiated;
297-
298-
TemplateInstance instanciateSymbol(S : Symbol)(S s) {
299-
// If we are within a pattern, we are not looking to instantiate.
300-
// XXX: Arguably, we'd like the TemplateInstancier to figure out if
301-
// this is a pattern instead of using this hack.
302-
if (inPattern) {
303-
instantiated = s;
304-
return null;
305-
}
306-
307-
import d.semantic.dtemplate;
308-
return TemplateInstancier(pass.pass, iloc, args, fargs).visit(s);
309-
}
310-
311295
auto iloc = i.location;
312-
auto instance = finalize(i.identifier.location, visit(i.identifier))
313-
.apply!(delegate TemplateInstance(identified) {
314-
static if (is(typeof(identified) : Symbol)) {
315-
return instanciateSymbol(identified);
316-
} else {
317-
import std.format;
318-
ce = getError(identified, iloc,
319-
format!"Unexpected %s."(typeid(identified)));
320-
321-
return null;
296+
return finalize(
297+
i.identifier.location,
298+
visit(i.identifier)
299+
).apply!(delegate Identifiable(identified) {
300+
static if (is(typeof(identified) : Symbol)) {
301+
// If we are within a pattern, we are not looking to instantiate.
302+
// XXX: Arguably, we'd like the TemplateInstancier to figure out
303+
// if this is a pattern instead of using this hack.
304+
if (inPattern) {
305+
return Identifiable(Pattern(identified, args).getType());
322306
}
323-
})();
324-
325-
if (inPattern && instantiated) {
326-
return Identifiable(Pattern(instantiated, args).getType());
327-
}
328307

329-
if (instance is null) {
330-
assert(ce, "No error reported :(");
331-
return Identifiable(ce.symbol);
332-
}
333-
334-
return Identifiable(instance);
308+
import d.semantic.dtemplate;
309+
auto ti = TemplateInstancier(pass.pass, iloc, args, fargs)
310+
.visit(identified);
311+
return Identifiable(ti);
312+
} else {
313+
import std.format;
314+
return Identifiable(
315+
getError(identified, iloc,
316+
format!"Unexpected %s."(typeid(identified))).symbol
317+
);
318+
}
319+
})();
335320
}
336321

337322
Identifiable resolveBracket(I)(Location location, Identifier base,

0 commit comments

Comments
 (0)