update tests

This commit is contained in:
ryuukk 2023-02-14 16:51:21 +01:00
parent 16a83a398a
commit 2a3c235b31
18 changed files with 390 additions and 195 deletions

View File

@ -32,6 +32,7 @@ import dsymbol.semantic;
import dsymbol.string_interning; import dsymbol.string_interning;
import dsymbol.symbol; import dsymbol.symbol;
import dsymbol.type_lookup; import dsymbol.type_lookup;
import dsymbol.coloredlogger;
import std.algorithm.iteration : map; import std.algorithm.iteration : map;
import std.experimental.allocator; import std.experimental.allocator;
import std.experimental.allocator.gc_allocator : GCAllocator; import std.experimental.allocator.gc_allocator : GCAllocator;
@ -258,20 +259,11 @@ final class FirstPass : ASTVisitor
} }
} }
void processTemplateInstance(SemanticSymbol* symbol, TypeLookup* lookup, VariableContext* ctx, VariableContext.TypeInstance* current, TemplateInstance ti) void processTemplateArguments(SemanticSymbol* symbol, TypeLookup* lookup, VariableContext* ctx, VariableContext.TypeInstance* current, TemplateArguments targs)
{ {
if (ti.identifier != tok!"") if (targs.templateArgumentList)
{ {
current.chain ~= ti.identifier.text; foreach(i, targ; targs.templateArgumentList.items)
warning("type: ", ti.identifier.text);
}
else assert(0, "templateinstance type missing");
if (ti.templateArguments)
{
if (ti.templateArguments.templateArgumentList)
{
foreach(i, targ; ti.templateArguments.templateArgumentList.items)
{ {
if (targ.type is null) continue; if (targ.type is null) continue;
if (targ.type.type2 is null) continue; if (targ.type.type2 is null) continue;
@ -293,17 +285,12 @@ final class FirstPass : ASTVisitor
{ {
processIdentifierOrTemplate(symbol, lookup, ctx, newArg, part.typeIdentifierPart.identifierOrTemplateInstance); processIdentifierOrTemplate(symbol, lookup, ctx, newArg, part.typeIdentifierPart.identifierOrTemplateInstance);
} }
}
if (part.typeIdentifierPart) }
}
else if (targs.templateSingleArgument)
{ {
error("i should probably handle this"); auto singleArg = targs.templateSingleArgument;
}
}
}
}
else if (ti.templateArguments.templateSingleArgument)
{
auto singleArg = ti.templateArguments.templateSingleArgument;
auto arg = GCAllocator.instance.make!(VariableContext.TypeInstance)(); auto arg = GCAllocator.instance.make!(VariableContext.TypeInstance)();
arg.parent = current; arg.parent = current;
arg.name = singleArg.token.text; arg.name = singleArg.token.text;
@ -311,6 +298,20 @@ final class FirstPass : ASTVisitor
current.args ~= arg; current.args ~= arg;
} }
} }
void processTemplateInstance(SemanticSymbol* symbol, TypeLookup* lookup, VariableContext* ctx, VariableContext.TypeInstance* current, TemplateInstance ti)
{
if (ti.identifier != tok!"")
{
current.chain ~= ti.identifier.text;
warning("type: ", ti.identifier.text);
}
else assert(0, "templateinstance type missing");
if (ti.templateArguments)
{
processTemplateArguments(symbol, lookup, ctx, current, ti.templateArguments);
}
} }
void buildChain(SemanticSymbol* symbol, TypeLookup* lookup, VariableContext* ctx, TypeIdentifierPart tip) void buildChain(SemanticSymbol* symbol, TypeLookup* lookup, VariableContext* ctx, TypeIdentifierPart tip)
@ -477,9 +478,9 @@ final class FirstPass : ASTVisitor
currentSymbol.addChild(symbol, true); currentSymbol.addChild(symbol, true);
currentScope.addSymbol(symbol.acSymbol, false); currentScope.addSymbol(symbol.acSymbol, false);
warning(" part: ", symbol.acSymbol.name); warning("part: ", symbol.acSymbol.name);
scope(exit) warning("crumbs: ", symbol.typeLookups.front.breadcrumbs[]); scope(exit) warning("crumbs: ".red, symbol.typeLookups.front.breadcrumbs[]);
if (currentSymbol.acSymbol.kind == CompletionKind.structName if (currentSymbol.acSymbol.kind == CompletionKind.structName
@ -490,18 +491,26 @@ final class FirstPass : ASTVisitor
structFieldTypes.insert(null); structFieldTypes.insert(null);
} }
auto lookup = symbol.typeLookups.front;
scope(exit) if (lookup.ctx.root) foreach(arg; lookup.ctx.root.args) warning("args: ".red, arg.chain);
auto initializer = part.initializer.nonVoidInitializer; auto initializer = part.initializer.nonVoidInitializer;
UnaryExpression unary;
if (initializer && initializer.assignExpression) if (initializer && initializer.assignExpression)
{ {
unary = cast(UnaryExpression) initializer.assignExpression; UnaryExpression unary = cast(UnaryExpression) initializer.assignExpression;
if (unary && (unary.newExpression || unary.indexExpression))
{
continue;
}
lookup.breadcrumbs.clear();
if (unary) if (unary)
{ {
if (CastExpression castExpression = unary.castExpression) if (CastExpression castExpression = unary.castExpression)
{ {
warning("cast expression"); warning("cast expression");
auto lookup = symbol.typeLookups.front;
lookup.breadcrumbs.clear();
if (castExpression.type && castExpression.type.type2) if (castExpression.type && castExpression.type.type2)
{ {
Type2 t2 = castExpression.type.type2; Type2 t2 = castExpression.type.type2;
@ -518,20 +527,14 @@ final class FirstPass : ASTVisitor
//if (fc.unaryExpression) //if (fc.unaryExpression)
// traverseUnaryExpression(symbol, lookup, &lookup.ctx, unary); // traverseUnaryExpression(symbol, lookup, &lookup.ctx, unary);
unary = fc.unaryExpression; unary = fc.unaryExpression;
}
}
if (unary if (fc.templateArguments)
&& !unary.indexExpression
&& !unary.throwExpression
&& !unary.assertExpression
&& !unary.argumentList
&& !unary.deleteExpression
&& !unary.newExpression
)
{ {
auto lookup = symbol.typeLookups.front; warning("fc template arguments!");
lookup.breadcrumbs.clear(); // lookup.ctx.root = GCAllocator.instance.make!(VariableContext.TypeInstance)();
// processTemplateArguments(symbol, lookup, &lookup.ctx, lookup.ctx.root, fc.templateArguments);
}
}
// build chain // build chain
traverseUnaryExpression(symbol, lookup, &lookup.ctx, unary); traverseUnaryExpression(symbol, lookup, &lookup.ctx, unary);
// needs to be reversed because it got added in order (right->left) // needs to be reversed because it got added in order (right->left)
@ -550,33 +553,59 @@ final class FirstPass : ASTVisitor
// check template // check template
if (IdentifierOrTemplateInstance iot = unary.identifierOrTemplateInstance) if (IdentifierOrTemplateInstance iot = unary.identifierOrTemplateInstance)
{ {
auto crumb = iot.identifier; auto crumb = iot.identifier;
warning("it's iot ", crumb);
if (crumb != tok!"") if (crumb != tok!"")
{ {
//lookup.breadcrumbs.insert(istring(crumb.text)); //lookup.breadcrumbs.insert(istring(crumb.text));
} }
else if (iot.templateInstance) else if (iot.templateInstance)
{ {
warning("iot template instance");
//auto tic = iot.templateInstance.identifier; //auto tic = iot.templateInstance.identifier;
//warning("template! ", tic.text); //warning("template! ", tic.text);
//if (tic != tok!"") //if (tic != tok!"")
// lookup.breadcrumbs.insert(istring(tic.text)); // lookup.breadcrumbs.insert(istring(tic.text));
lookup.ctx.root = GCAllocator.instance.make!(VariableContext.TypeInstance)(); lookup.ctx.root = GCAllocator.instance.make!(VariableContext.TypeInstance)();
processTemplateInstance(symbol, lookup, &lookup.ctx, lookup.ctx.root, iot.templateInstance); processTemplateInstance(symbol, lookup, &lookup.ctx, lookup.ctx.root, iot.templateInstance);
} }
} }
else if (PrimaryExpression pe = unary.primaryExpression)
{
if (pe.identifierOrTemplateInstance)
{
if (pe.identifierOrTemplateInstance.templateInstance)
{
warning("iot template instance");
//auto tic = iot.templateInstance.identifier;
//warning("template! ", tic.text);
//if (tic != tok!"")
// lookup.breadcrumbs.insert(istring(tic.text));
lookup.ctx.root = GCAllocator.instance.make!(VariableContext.TypeInstance)();
processTemplateInstance(symbol, lookup, &lookup.ctx, lookup.ctx.root, pe.identifierOrTemplateInstance.templateInstance);
} }
} }
}
}
else
{
warning("no unary".red);
}
if (unary)
{
}
}
import std.string: indexOf; import std.string: indexOf;
if (symbol.acSymbol.name.indexOf("from_auto_two") != -1) if (symbol.acSymbol.name.indexOf("b") != -1)
{ {
import core.stdc.stdlib: exit; import core.stdc.stdlib: exit;
auto lookup = symbol.typeLookups.front;
warning("crumb: ", lookup.breadcrumbs[]); warning("crumb: ", lookup.breadcrumbs[]);
if (lookup.ctx.root) if (lookup.ctx.root)
{ {
@ -584,15 +613,19 @@ final class FirstPass : ASTVisitor
foreach(arg; lookup.ctx.root.args) foreach(arg; lookup.ctx.root.args)
warning(" arg: ", arg.chain); warning(" arg: ", arg.chain);
} }
UnaryExpression unary = cast(UnaryExpression) initializer.assignExpression;
if (unary) if (unary)
{ {
warning(" primaryExpression: ", unary.primaryExpression); warning(" unaryExpression: ", unary.unaryExpression);
warning(" indexExpression: ", unary.indexExpression);
warning(" throwExpression: ", unary.throwExpression);
warning(" assertExpression: ", unary.assertExpression);
warning(" argumentList: ", unary.argumentList);
warning(" deleteExpression: ", unary.deleteExpression);
warning(" newExpression: ", unary.newExpression); warning(" newExpression: ", unary.newExpression);
warning(" deleteExpression: ", unary.deleteExpression);
warning(" castExpression: ", unary.castExpression);
warning(" functionCallExpression: ", unary.functionCallExpression);
warning(" argumentList: ", unary.argumentList);
warning(" identifierOrTemplateInstance: ", unary.identifierOrTemplateInstance);
warning(" assertExpression: ", unary.assertExpression);
warning(" throwExpression: ", unary.throwExpression);
warning(" indexExpression: ", unary.indexExpression);
} }
//exit(0); //exit(0);
} }

View File

@ -1,5 +1,5 @@
set -e set -e
set -u set -u
../../bin/dcd-client $1 file.d -c66 > actual1.txt ../../bin/dcd-client $1 file.d --extended -c66 > actual1.txt
diff actual1.txt expected1.txt --strip-trailing-cr diff actual1.txt expected1.txt --strip-trailing-cr

View File

@ -0,0 +1,95 @@
struct Data
{
int inside_data;
Inner inner;
}
struct Inner
{
int inside_inner;
}
struct AganeOne(T)
{
int inside_aganeone;
T yo;
}
struct AganeTwo(T, U)
{
int inside_aganetwo;
T yo_T;
U yo_U;
}
struct Other(T)
{
int inside_other;
T what;
AganeOne!(T) agane_T;
AganeOne!(Inner) agane_inner;
}
struct One(T){ T inside_one; }
struct Outter {
struct Two(T, U){ int inside_two; T agane_one; U agane_two; One!(T) one_agane_one; T get_T(T)(){return T.init;} U get_U(){return U.init;} }
}
struct A{ int inside_a;}
struct B{ int inside_b;}
struct C{ int inside_c;}
struct What
{
int inside_what;
const(V) get_it(T, U, V)() { return T.init; }
}
void main()
{
auto from_auto = Outter.Two!(
AganeOne!(Other!(Data)),
AganeTwo!(A, B)
)();
Outter.Two!(
AganeOne!(Other!(Data)),
AganeTwo!(A, Other!(B))
) from_normal;
auto u = from_auto.get_U();
auto uuu = from_normal.agane_two;
auto v = from_normal.get_U();
What what;
auto it = what.get_it!(A, B, C)();
{
from_auto.agane_one.
}
{
from_auto.agane_two.
}
{
from_normal.agane_two.
}
{
from_normal.agane_two.
}
{
u.
}
{
uuu.
}
{
uuu.
}
{
it.
}
}

View File

@ -0,0 +1,9 @@
identifiers
alignof k
init k
mangleof k
one_t v One one_t stdin 103
sizeof k
stringof k
tupleof k
value_t v A value_t stdin 0

View File

@ -0,0 +1,9 @@
identifiers
alignof k
init k
mangleof k
sizeof k
stringof k
tupleof k
value_t v A value_t stdin 0
value_u v B value_u stdin 0

View File

@ -0,0 +1,9 @@
identifiers
alignof k
init k
mangleof k
one_t v One one_t stdin 103
sizeof k
stringof k
tupleof k
value_t v A value_t stdin 0

View File

@ -0,0 +1,9 @@
identifiers
alignof k
init k
mangleof k
sizeof k
stringof k
tupleof k
value_t v A value_t stdin 0
value_u v B value_u stdin 0

View File

@ -0,0 +1,9 @@
identifiers
alignof k
init k
inside_aganeone v int inside_aganeone stdin 137
mangleof k
sizeof k
stringof k
tupleof k
yo v Other yo stdin 0

View File

@ -0,0 +1,10 @@
identifiers
alignof k
init k
inside_aganetwo v int inside_aganetwo stdin 205
mangleof k
sizeof k
stringof k
tupleof k
yo_T v A yo_T stdin 0
yo_U v B yo_U stdin 0

View File

@ -0,0 +1,10 @@
identifiers
alignof k
init k
inside_aganetwo v int inside_aganetwo stdin 205
mangleof k
sizeof k
stringof k
tupleof k
yo_T v A yo_T stdin 0
yo_U v Other yo_U stdin 0

View File

@ -0,0 +1,10 @@
identifiers
alignof k
init k
inside_aganetwo v int inside_aganetwo stdin 205
mangleof k
sizeof k
stringof k
tupleof k
yo_T v A yo_T stdin 0
yo_U v Other yo_U stdin 0

View File

@ -0,0 +1,10 @@
identifiers
alignof k
init k
inside_aganetwo v int inside_aganetwo stdin 205
mangleof k
sizeof k
stringof k
tupleof k
yo_T v A yo_T stdin 0
yo_U v B yo_U stdin 0

View File

@ -0,0 +1,10 @@
identifiers
alignof k
init k
inside_aganetwo v int inside_aganetwo stdin 205
mangleof k
sizeof k
stringof k
tupleof k
yo_T v A yo_T stdin 0
yo_U v Other yo_U stdin 0

View File

@ -0,0 +1,10 @@
identifiers
alignof k
init k
inside_aganetwo v int inside_aganetwo stdin 205
mangleof k
sizeof k
stringof k
tupleof k
yo_T v A yo_T stdin 0
yo_U v Other yo_U stdin 0

View File

@ -0,0 +1,8 @@
identifiers
alignof k
init k
inside_c v int inside_c stdin 645
mangleof k
sizeof k
stringof k
tupleof k

View File

@ -1,96 +1,31 @@
struct Data struct A
{ {
int inside_data; int inside_a;
Inner inner;
} }
struct B
struct Inner
{ {
int inside_inner; int inside_b;
} }
struct One(T)
struct AganeOne(T)
{ {
int inside_aganeone; T value_t;
T yo; One!T one_t;
} }
struct AganeTwo(T, U) struct Two(T, U)
{ {
int inside_aganetwo; T value_t;
T yo_T; U value_u;
U yo_U;
} }
struct Other(T)
{
int inside_other;
T what;
AganeOne!(T) agane_T;
AganeOne!(Inner) agane_inner;
}
struct One(T){ T inside_one; }
struct Outter {
struct Two(T, U){ int inside_two; T agane_one; U agane_two; One!(T) one_agane_one; T get_T(T)(){return T.init;} U get_U(){return U.init;} }
}
struct A{ int inside_a;}
struct B{ int inside_b;}
void main() void main()
{ {
auto from_auto = Outter.Two!( auto from_auto_one = One!A();
AganeOne!(Other!(Data)), auto from_auto_two = Two!(A, B)();
AganeTwo!(A, B) {
)(); from_auto_one.
}
{
auto check = from_auto; from_auto_two.
}
import std;
// should be of type Inner, completion: inside_inner
writeln(typeid(from_auto.agane_one)); //file1.AganeOne!(file1.Other!(file1.Data).Other).AganeOne
writeln(typeid(from_auto.agane_one.yo)); // file1.Other!(file1.Data).Other
writeln(typeid(from_auto.agane_one.yo.agane_inner)); // file1.AganeOne!(file1.Inner).AganeOne
writeln(typeid(from_auto.agane_one.yo.agane_inner.yo)); // file1.Inner
} }
// struct S { int x; int y; }
// S doStuff(int x) { return S(); }
// void main(string[] args)
// {
// auto alpha = 10;
// auto bravo = S(1, 2);
// int charlie = 4;
// auto delta = doStuff();
// {
// alpha
// }
// {
// bravo.
// }
// {
// charlie.
// }
// {
// delta.
// }
// }

View File

@ -1,47 +1,31 @@
struct Data struct A
{ {
float inside_data; int inside_a;
Inner inner;
} }
struct B
struct Inner
{ {
float inside_inner; int inside_b;
} }
struct One(T)
struct AganeOne(T)
{ {
T yo; T value_t;
One!T one_t;
} }
struct AganeTwo(T, U) struct Two(T, U)
{ {
T yo_T; T value_t;
U yo_U; U value_u;
} }
struct Other(T)
{
T what;
AganeOne!(T) agane_T;
AganeOne!(Inner) agane_inner;
}
struct One(T){ T inside_one; }
struct Outter {
struct Two(T, U){ T agane_one; U agane_two; One!(T) one_agane_one; }
}
struct A{ int inside_a;}
struct B{ int inside_b;}
void main() void main()
{ {
auto from_auto = Outter.Two!( One!A from_normal_one;
AganeOne!(Other!Data), Two!(A, B) from_normal_two;
AganeTwo!(A, B) {
); from_normal_one.
from_auto.agane_two.yo }
{
from_normal_two.
}
} }

View File

@ -1,14 +1,49 @@
#!/bin/bash
set -e set -e
set -u set -u
../../bin/dcd-client $1 file1.d --extended -c 831 MODE=$1
# ../../bin/dcd-client $1 file1.d --extended -c 270
function check () {
echo "$1 $2"
../../bin/dcd-client $MODE $1.d --extended -c $2 > $3.txt
diff $3.txt $4.txt --strip-trailing-cr
}
#echo "test1" #echo "test1"
#../../bin/dcd-client $1 file1.d --extended -c 751 > actual_1.txt ../../bin/dcd-client $1 file1.d --extended -c 280 > actual_1_1.txt
#diff actual_1.txt expected_1.txt --strip-trailing-cr diff actual_1_1.txt expected_1_1.txt --strip-trailing-cr
#echo "test2" #echo "test2"
#../../bin/dcd-client $1 file2.d --extended -c 674 > actual_2.txt ../../bin/dcd-client $1 file1.d --extended -c 315 > actual_1_2.txt
#diff actual_2.txt expected_2.txt --strip-trailing-cr diff actual_1_2.txt expected_1_2.txt --strip-trailing-cr
#echo "test3"
../../bin/dcd-client $1 file2.d --extended -c 268 > actual_2_1.txt
diff actual_2_1.txt expected_2_1.txt --strip-trailing-cr
#echo "test4"
../../bin/dcd-client $1 file2.d --extended -c 305 > actual_2_2.txt
diff actual_2_2.txt expected_2_2.txt --strip-trailing-cr
#echo "test c omplex"
check complex 1192 actual_complex_1 expected_complex_1
check complex 1236 actual_complex_2 expected_complex_2
check complex 1282 actual_complex_3 expected_complex_3
check complex 1328 actual_complex_4 expected_complex_4
check complex 1354 actual_complex_5 expected_complex_5
check complex 1382 actual_complex_6 expected_complex_6
check complex 1410 actual_complex_7 expected_complex_7
check complex 1437 actual_complex_8 expected_complex_8