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.symbol;
import dsymbol.type_lookup;
import dsymbol.coloredlogger;
import std.algorithm.iteration : map;
import std.experimental.allocator;
import std.experimental.allocator.gc_allocator : GCAllocator;
@ -258,6 +259,46 @@ final class FirstPass : ASTVisitor
}
}
void processTemplateArguments(SemanticSymbol* symbol, TypeLookup* lookup, VariableContext* ctx, VariableContext.TypeInstance* current, TemplateArguments targs)
{
if (targs.templateArgumentList)
{
foreach(i, targ; targs.templateArgumentList.items)
{
if (targ.type is null) continue;
if (targ.type.type2 is null) continue;
auto part = targ.type.type2.typeIdentifierPart;
if (part is null) continue;
auto newArg = GCAllocator.instance.make!(VariableContext.TypeInstance)();
newArg.parent = current;
current.args ~= newArg;
if (part.identifierOrTemplateInstance)
{
processIdentifierOrTemplate(symbol, lookup, ctx, newArg, part.identifierOrTemplateInstance);
}
if (part.typeIdentifierPart)
{
if (part.typeIdentifierPart.identifierOrTemplateInstance)
{
processIdentifierOrTemplate(symbol, lookup, ctx, newArg, part.typeIdentifierPart.identifierOrTemplateInstance);
}
}
}
}
else if (targs.templateSingleArgument)
{
auto singleArg = targs.templateSingleArgument;
auto arg = GCAllocator.instance.make!(VariableContext.TypeInstance)();
arg.parent = current;
arg.name = singleArg.token.text;
arg.chain ~= arg.name;
current.args ~= arg;
}
}
void processTemplateInstance(SemanticSymbol* symbol, TypeLookup* lookup, VariableContext* ctx, VariableContext.TypeInstance* current, TemplateInstance ti)
{
if (ti.identifier != tok!"")
@ -269,47 +310,7 @@ final class FirstPass : ASTVisitor
if (ti.templateArguments)
{
if (ti.templateArguments.templateArgumentList)
{
foreach(i, targ; ti.templateArguments.templateArgumentList.items)
{
if (targ.type is null) continue;
if (targ.type.type2 is null) continue;
auto part = targ.type.type2.typeIdentifierPart;
if (part is null) continue;
auto newArg = GCAllocator.instance.make!(VariableContext.TypeInstance)();
newArg.parent = current;
current.args ~= newArg;
if (part.identifierOrTemplateInstance)
{
processIdentifierOrTemplate(symbol, lookup, ctx, newArg, part.identifierOrTemplateInstance);
}
if (part.typeIdentifierPart)
{
if (part.typeIdentifierPart.identifierOrTemplateInstance)
{
processIdentifierOrTemplate(symbol, lookup, ctx, newArg, part.typeIdentifierPart.identifierOrTemplateInstance);
}
if (part.typeIdentifierPart)
{
error("i should probably handle this");
}
}
}
}
else if (ti.templateArguments.templateSingleArgument)
{
auto singleArg = ti.templateArguments.templateSingleArgument;
auto arg = GCAllocator.instance.make!(VariableContext.TypeInstance)();
arg.parent = current;
arg.name = singleArg.token.text;
arg.chain ~= arg.name;
current.args ~= arg;
}
processTemplateArguments(symbol, lookup, ctx, current, ti.templateArguments);
}
}
@ -477,9 +478,9 @@ final class FirstPass : ASTVisitor
currentSymbol.addChild(symbol, true);
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
@ -490,18 +491,26 @@ final class FirstPass : ASTVisitor
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;
UnaryExpression unary;
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 (CastExpression castExpression = unary.castExpression)
{
warning("cast expression");
auto lookup = symbol.typeLookups.front;
lookup.breadcrumbs.clear();
if (castExpression.type && castExpression.type.type2)
{
Type2 t2 = castExpression.type.type2;
@ -518,20 +527,14 @@ final class FirstPass : ASTVisitor
//if (fc.unaryExpression)
// traverseUnaryExpression(symbol, lookup, &lookup.ctx, unary);
unary = fc.unaryExpression;
}
}
if (unary
&& !unary.indexExpression
&& !unary.throwExpression
&& !unary.assertExpression
&& !unary.argumentList
&& !unary.deleteExpression
&& !unary.newExpression
)
{
auto lookup = symbol.typeLookups.front;
lookup.breadcrumbs.clear();
if (fc.templateArguments)
{
warning("fc template arguments!");
// lookup.ctx.root = GCAllocator.instance.make!(VariableContext.TypeInstance)();
// processTemplateArguments(symbol, lookup, &lookup.ctx, lookup.ctx.root, fc.templateArguments);
}
}
// build chain
traverseUnaryExpression(symbol, lookup, &lookup.ctx, unary);
// needs to be reversed because it got added in order (right->left)
@ -550,49 +553,79 @@ final class FirstPass : ASTVisitor
// check template
if (IdentifierOrTemplateInstance iot = unary.identifierOrTemplateInstance)
{
auto crumb = iot.identifier;
warning("it's iot ", crumb);
if (crumb != tok!"")
{
//lookup.breadcrumbs.insert(istring(crumb.text));
}
else if (iot.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, 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;
if (symbol.acSymbol.name.indexOf("from_auto_two") != -1)
if (symbol.acSymbol.name.indexOf("b") != -1)
{
import core.stdc.stdlib: exit;
auto lookup = symbol.typeLookups.front;
warning("crumb: ", lookup.breadcrumbs[]);
warning("crumb: ", lookup.breadcrumbs[]);
if (lookup.ctx.root)
{
warning("root: ", lookup.ctx.root.chain);
foreach(arg; lookup.ctx.root.args)
warning(" arg: ", arg.chain);
}
UnaryExpression unary = cast(UnaryExpression) initializer.assignExpression;
if (unary)
{
warning(" primaryExpression: ", unary.primaryExpression);
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(" unaryExpression: ", unary.unaryExpression);
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);
}

View File

@ -1,5 +1,5 @@
set -e
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

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;
Inner inner;
int inside_a;
}
struct Inner
struct B
{
int inside_inner;
int inside_b;
}
struct AganeOne(T)
struct One(T)
{
int inside_aganeone;
T yo;
T value_t;
One!T one_t;
}
struct AganeTwo(T, U)
struct Two(T, U)
{
int inside_aganetwo;
T yo_T;
U yo_U;
T value_t;
U value_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()
{
auto from_auto = Outter.Two!(
AganeOne!(Other!(Data)),
AganeTwo!(A, B)
)();
auto check = from_auto;
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
auto from_auto_one = One!A();
auto from_auto_two = Two!(A, B)();
{
from_auto_one.
}
{
from_auto_two.
}
}
// 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;
Inner inner;
int inside_a;
}
struct Inner
struct B
{
float inside_inner;
int inside_b;
}
struct AganeOne(T)
struct One(T)
{
T yo;
T value_t;
One!T one_t;
}
struct AganeTwo(T, U)
struct Two(T, U)
{
T yo_T;
U yo_U;
T value_t;
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()
{
auto from_auto = Outter.Two!(
AganeOne!(Other!Data),
AganeTwo!(A, B)
);
from_auto.agane_two.yo
One!A from_normal_one;
Two!(A, B) from_normal_two;
{
from_normal_one.
}
{
from_normal_two.
}
}

View File

@ -1,14 +1,49 @@
#!/bin/bash
set -e
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"
#../../bin/dcd-client $1 file1.d --extended -c 751 > actual_1.txt
#diff actual_1.txt expected_1.txt --strip-trailing-cr
../../bin/dcd-client $1 file1.d --extended -c 280 > actual_1_1.txt
diff actual_1_1.txt expected_1_1.txt --strip-trailing-cr
#echo "test2"
#../../bin/dcd-client $1 file2.d --extended -c 674 > actual_2.txt
#diff actual_2.txt expected_2.txt --strip-trailing-cr
../../bin/dcd-client $1 file1.d --extended -c 315 > actual_1_2.txt
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