Skip to content

Commit 953d32f

Browse files
ryuukkWebFreak001
authored andcommitted
run a lightweight version of second phase to make sure no symbols are left out
1 parent 33fd0db commit 953d32f

File tree

3 files changed

+129
-93
lines changed

3 files changed

+129
-93
lines changed

dsymbol/src/dsymbol/conversion/package.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ ScopeSymbolPair generateAutocompleteTrees(const(Token)[] tokens,
5151

5252
secondPass(first.rootSymbol, first.moduleScope, cache);
5353

54-
thirdPass(first.moduleScope, cache, cursorPosition);
54+
thirdPass(first.rootSymbol, first.moduleScope, cache, cursorPosition);
5555

5656
auto ufcsSymbols = getUFCSSymbolsForCursor(first.moduleScope, tokens, cursorPosition);
5757

dsymbol/src/dsymbol/conversion/second.d

Lines changed: 91 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,97 @@ do
311311
}
312312
}
313313

314+
void resolveTypeFromInitializer(DSymbol* symbol, TypeLookup* lookup,
315+
Scope* moduleScope, ref ModuleCache cache)
316+
{
317+
if (lookup.breadcrumbs.length == 0)
318+
return;
319+
DSymbol* currentSymbol = null;
320+
size_t i = 0;
321+
322+
auto crumbs = lookup.breadcrumbs[];
323+
foreach (crumb; crumbs)
324+
{
325+
if (i == 0)
326+
{
327+
currentSymbol = moduleScope.getFirstSymbolByNameAndCursor(
328+
symbolNameToTypeName(crumb), symbol.location);
329+
330+
if (currentSymbol is null)
331+
return;
332+
}
333+
else if (crumb == ARRAY_LITERAL_SYMBOL_NAME)
334+
{
335+
auto arr = GCAllocator.instance.make!(DSymbol)(ARRAY_LITERAL_SYMBOL_NAME, CompletionKind.dummy, currentSymbol);
336+
arr.qualifier = SymbolQualifier.array;
337+
currentSymbol = arr;
338+
}
339+
else if (crumb == ARRAY_SYMBOL_NAME)
340+
{
341+
typeSwap(currentSymbol);
342+
if (currentSymbol is null)
343+
return;
344+
345+
// Index expressions can be on a pointer, an array or an AA
346+
if (currentSymbol.qualifier == SymbolQualifier.array
347+
|| currentSymbol.qualifier == SymbolQualifier.assocArray
348+
|| currentSymbol.qualifier == SymbolQualifier.pointer
349+
|| currentSymbol.kind == CompletionKind.aliasName)
350+
{
351+
if (currentSymbol.type !is null)
352+
currentSymbol = currentSymbol.type;
353+
else
354+
return;
355+
}
356+
else
357+
{
358+
auto opIndex = currentSymbol.getFirstPartNamed(internString("opIndex"));
359+
if (opIndex !is null)
360+
currentSymbol = opIndex.type;
361+
else
362+
return;
363+
}
364+
}
365+
else if (crumb == "foreach")
366+
{
367+
typeSwap(currentSymbol);
368+
if (currentSymbol is null)
369+
return;
370+
if (currentSymbol.qualifier == SymbolQualifier.array
371+
|| currentSymbol.qualifier == SymbolQualifier.assocArray)
372+
{
373+
currentSymbol = currentSymbol.type;
374+
break;
375+
}
376+
auto front = currentSymbol.getFirstPartNamed(internString("front"));
377+
if (front !is null)
378+
{
379+
currentSymbol = front.type;
380+
break;
381+
}
382+
auto opApply = currentSymbol.getFirstPartNamed(internString("opApply"));
383+
if (opApply !is null)
384+
{
385+
currentSymbol = opApply.type;
386+
break;
387+
}
388+
}
389+
else
390+
{
391+
typeSwap(currentSymbol);
392+
if (currentSymbol is null)
393+
return;
394+
currentSymbol = currentSymbol.getFirstPartNamed(crumb);
395+
}
396+
++i;
397+
if (currentSymbol is null)
398+
return;
399+
}
400+
typeSwap(currentSymbol);
401+
symbol.type = currentSymbol;
402+
symbol.ownType = false;
403+
}
404+
314405
private:
315406

316407
void resolveInheritance(DSymbol* symbol, ref TypeLookups typeLookups,
@@ -425,97 +516,6 @@ void resolveType(DSymbol* symbol, ref TypeLookups typeLookups,
425516
}
426517
}
427518

428-
void resolveTypeFromInitializer(DSymbol* symbol, TypeLookup* lookup,
429-
Scope* moduleScope, ref ModuleCache cache)
430-
{
431-
if (lookup.breadcrumbs.length == 0)
432-
return;
433-
DSymbol* currentSymbol = null;
434-
size_t i = 0;
435-
436-
auto crumbs = lookup.breadcrumbs[];
437-
foreach (crumb; crumbs)
438-
{
439-
if (i == 0)
440-
{
441-
currentSymbol = moduleScope.getFirstSymbolByNameAndCursor(
442-
symbolNameToTypeName(crumb), symbol.location);
443-
444-
if (currentSymbol is null)
445-
return;
446-
}
447-
else if (crumb == ARRAY_LITERAL_SYMBOL_NAME)
448-
{
449-
auto arr = GCAllocator.instance.make!(DSymbol)(ARRAY_LITERAL_SYMBOL_NAME, CompletionKind.dummy, currentSymbol);
450-
arr.qualifier = SymbolQualifier.array;
451-
currentSymbol = arr;
452-
}
453-
else if (crumb == ARRAY_SYMBOL_NAME)
454-
{
455-
typeSwap(currentSymbol);
456-
if (currentSymbol is null)
457-
return;
458-
459-
// Index expressions can be on a pointer, an array or an AA
460-
if (currentSymbol.qualifier == SymbolQualifier.array
461-
|| currentSymbol.qualifier == SymbolQualifier.assocArray
462-
|| currentSymbol.qualifier == SymbolQualifier.pointer
463-
|| currentSymbol.kind == CompletionKind.aliasName)
464-
{
465-
if (currentSymbol.type !is null)
466-
currentSymbol = currentSymbol.type;
467-
else
468-
return;
469-
}
470-
else
471-
{
472-
auto opIndex = currentSymbol.getFirstPartNamed(internString("opIndex"));
473-
if (opIndex !is null)
474-
currentSymbol = opIndex.type;
475-
else
476-
return;
477-
}
478-
}
479-
else if (crumb == "foreach")
480-
{
481-
typeSwap(currentSymbol);
482-
if (currentSymbol is null)
483-
return;
484-
if (currentSymbol.qualifier == SymbolQualifier.array
485-
|| currentSymbol.qualifier == SymbolQualifier.assocArray)
486-
{
487-
currentSymbol = currentSymbol.type;
488-
break;
489-
}
490-
auto front = currentSymbol.getFirstPartNamed(internString("front"));
491-
if (front !is null)
492-
{
493-
currentSymbol = front.type;
494-
break;
495-
}
496-
auto opApply = currentSymbol.getFirstPartNamed(internString("opApply"));
497-
if (opApply !is null)
498-
{
499-
currentSymbol = opApply.type;
500-
break;
501-
}
502-
}
503-
else
504-
{
505-
typeSwap(currentSymbol);
506-
if (currentSymbol is null)
507-
return;
508-
currentSymbol = currentSymbol.getFirstPartNamed(crumb);
509-
}
510-
++i;
511-
if (currentSymbol is null)
512-
return;
513-
}
514-
typeSwap(currentSymbol);
515-
symbol.type = currentSymbol;
516-
symbol.ownType = false;
517-
}
518-
519519
void typeSwap(ref DSymbol* currentSymbol)
520520
{
521521
while (currentSymbol !is null && currentSymbol.type !is currentSymbol

dsymbol/src/dsymbol/conversion/third.d

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,46 @@ import containers.hashset;
3434
* If it is, then it'll set its type
3535
* If the symbol is not found, then it'll do nothing
3636
*/
37-
void thirdPass(Scope* mscope, ref ModuleCache cache, size_t cursorPosition)
37+
void thirdPass(SemanticSymbol* root, Scope* mscope, ref ModuleCache cache, size_t cursorPosition)
3838
{
3939
auto desired = mscope.getScopeByCursor(cursorPosition);
4040
tryResolve(desired, cache);
41+
42+
// Check if there are any left out symbols
43+
// Check issue 717 and test tc717
44+
checkMissingTypes(root, mscope, cache);
45+
}
46+
47+
void checkMissingTypes(SemanticSymbol* currentSymbol, Scope* moduleScope, ref ModuleCache cache)
48+
{
49+
import dsymbol.conversion.second;
50+
import dsymbol.type_lookup;
51+
52+
with (CompletionKind) switch (currentSymbol.acSymbol.kind)
53+
{
54+
case withSymbol:
55+
case variableName:
56+
case memberVariableName:
57+
case functionName:
58+
case ufcsName:
59+
case aliasName:
60+
if (currentSymbol.acSymbol.type is null)
61+
{
62+
if (currentSymbol.typeLookups.length == 0)
63+
break;
64+
auto lookup = currentSymbol.typeLookups.front;
65+
if (lookup.kind == TypeLookupKind.varOrFunType)
66+
resolveTypeFromType(currentSymbol.acSymbol, lookup, moduleScope, cache, null);
67+
else if (lookup.kind == TypeLookupKind.initializer)
68+
resolveTypeFromInitializer(currentSymbol.acSymbol, lookup, moduleScope, cache);
69+
}
70+
break;
71+
default:
72+
break;
73+
}
74+
75+
foreach (child; currentSymbol.children)
76+
checkMissingTypes(child, moduleScope, cache);
4177
}
4278

4379
/**

0 commit comments

Comments
 (0)