示例#1
0
        public void IsExpressionAlias()
        {
            var ctxt = ResolutionTests.CreateCtxt("A", @"module A;
static if(is(const(int)* U == const(U)*))
U var;

U derp;
");

            IExpression  x;
            AbstractType t;
            DSymbol      ds;

            x = DParser.ParseExpression("var");
            (x as IdentifierExpression).Location = new CodeLocation(2, 3);
            t  = ExpressionTypeEvaluation.EvaluateType(x, ctxt);
            ds = t as DSymbol;

            Assert.That(t, Is.TypeOf(typeof(MemberSymbol)));
            Assert.That(ds.Base, Is.TypeOf(typeof(TemplateParameterSymbol)));
            ds = ds.Base as DSymbol;
            Assert.That(ds.Base, Is.TypeOf(typeof(PrimitiveType)));
            Assert.That((ds.Base as PrimitiveType).Modifier, Is.EqualTo(0));

            ctxt.CurrentContext.DeducedTemplateParameters.Clear();

            var dv = ctxt.ParseCache[0]["A"]["derp"].First() as DVariable;

            t = TypeDeclarationResolver.HandleNodeMatch(dv, ctxt);
            Assert.That(t, Is.TypeOf(typeof(MemberSymbol)));
            Assert.That((t as MemberSymbol).Base, Is.Null);
        }
示例#2
0
        public void BasicResolution()
        {
            var          ctxt = ResolutionTests.CreateCtxt("modA", @"module modA;
void writeln(T...)(T t) {}
int[] foo(string a) {}
int foo(int a) {}

string globStr;
int globI;
");
            IExpression  x;
            AbstractType t;

            x = DParser.ParseExpression("globStr.foo()");
            t = ExpressionTypeEvaluation.EvaluateType(x, ctxt);
            Assert.That(t, Is.TypeOf(typeof(ArrayType)));

            x = DParser.ParseExpression("globI.foo()");
            t = ExpressionTypeEvaluation.EvaluateType(x, ctxt);
            Assert.That(t, Is.TypeOf(typeof(PrimitiveType)));

            x = DParser.ParseExpression("globStr.writeln()");
            t = ExpressionTypeEvaluation.EvaluateType(x, ctxt);
            Assert.That(t, Is.TypeOf(typeof(PrimitiveType)));
            Assert.That((t as PrimitiveType).TypeToken, Is.EqualTo(DTokens.Void));
        }
示例#3
0
        public void IsExpressionAlias_InMethod()
        {
            var          ctxt = ResolutionTests.CreateCtxt("A", @"module A;
void main(){
pre;

static if(is(const(int)* U == const(U)*))
{
U var;
}

post;
}
");
            IExpression  x;
            AbstractType t;
            DSymbol      ds;

            var main = ctxt.ParseCache[0]["A"]["main"].First() as DMethod;

            ctxt.PushNewScope(main, main.Body.SubStatements.First());
            t = TypeDeclarationResolver.ResolveSingle(new IdentifierDeclaration("U")
            {
                Location = main.Body.SubStatements.First().Location
            }, ctxt);

            Assert.That(t, Is.Null);

            ctxt.Pop();
            ctxt.PushNewScope(main, main.Body.SubStatements.ElementAt(2));
            t = TypeDeclarationResolver.ResolveSingle(new IdentifierDeclaration("U")
            {
                Location = main.Body.SubStatements.ElementAt(2).Location
            }, ctxt);

            Assert.That(t, Is.Null);
            ctxt.Pop();

            x = DParser.ParseExpression("var");

            IStatement stmt;

            DResolver.SearchBlockAt(main, (x as IdentifierExpression).Location = new CodeLocation(3, 7), out stmt);

            ctxt.PushNewScope(main, stmt);
            t  = ExpressionTypeEvaluation.EvaluateType(x, ctxt);
            ds = t as DSymbol;

            Assert.That(t, Is.TypeOf(typeof(MemberSymbol)));
            Assert.That(ds.Base, Is.TypeOf(typeof(TemplateParameterSymbol)));
            ds = ds.Base as DSymbol;
            Assert.That(ds.Base, Is.TypeOf(typeof(PrimitiveType)));
            Assert.That((ds.Base as PrimitiveType).Modifier, Is.EqualTo(0));
        }
示例#4
0
        public void TestCastExpression1()
        {
            var ctxt = ResolutionTests.CreateCtxt("A", @"module A;");
            var vp   = new StandardValueProvider(ctxt);

            IExpression  x;
            ISymbolValue v;

            x = DParser.ParseExpression("cast(ubyte)20");
            v = Evaluation.EvaluateValue(x, vp);

            Assert.That(v, Is.TypeOf(typeof(PrimitiveValue)));
            Assert.That((v as PrimitiveValue).BaseTypeToken, Is.EqualTo(DTokens.Ubyte));
            Assert.That((v as PrimitiveValue).Value, Is.EqualTo(20M));
        }
示例#5
0
        public void ReturnStmt()
        {
            var ctxt = ResolutionTests.CreateCtxt("A", @"module A;
int foo() { return 123; }
string foo(string s) { return s ~ ""gh""; }

string inty(A)() { return ""int y;""; }
");

            IExpression    x;
            ISymbolValue   v;
            ArrayValue     av;
            PrimitiveValue pv;

            x = DParser.ParseExpression("inty!(\"asdf\")");
            v = Evaluation.EvaluateValue(x, ctxt);

            Assert.That(v, Is.TypeOf(typeof(ArrayValue)));
            av = v as ArrayValue;
            Assert.That(av.IsString, Is.True);
            Assert.That(av.StringValue, Is.EqualTo("int y;"));

            x = DParser.ParseExpression("foo");
            v = Evaluation.EvaluateValue(x, ctxt);

            Assert.That(v, Is.TypeOf(typeof(PrimitiveValue)));
            pv = v as PrimitiveValue;
            Assert.That(pv.BaseTypeToken, Is.EqualTo(DTokens.Int));
            Assert.That(pv.Value, Is.EqualTo(123M));

            x = DParser.ParseExpression("foo(\"asdf\")");
            v = Evaluation.EvaluateValue(x, ctxt);

            Assert.That(v, Is.TypeOf(typeof(ArrayValue)));
            av = v as ArrayValue;
            Assert.That(av.IsString, Is.True);
            Assert.That(av.StringValue, Is.EqualTo("asdfgh"));
        }