public override object VisitTypeOfExpression([NotNull] DoshikParser.TypeOfExpressionContext context)
        {
            SetWholeExpression(context);
            VisitChildren(context);
            _compilationContext.SetParsingAntlrContext(context);

            var node = new TypeOfExpressionNode(context);

            var foundType = GetTypeNameVisitor.Apply(_compilationContext, context.typeOf().typeType());

            foundType.ThrowIfNotFound(_compilationContext);
            node.Type = foundType.DataType;

            Sequence.Sequence.Add(node);

            return(null);
        }
Beispiel #2
0
        private IExpression HandleTypeOfExpressionNode(TypeOfExpressionNode node)
        {
            if (!node.Type.ExternalType.DeclaredAsTypeNode)
            {
                throw _compilationContext.ThrowCompilationError("specified type cannot be used in typeof() operator");
            }

            var result = new ConstantValueExpression();

            var constant = Constant.CreateAsDotnetTypeString(node.Type.ExternalType.DotnetTypeString, _compilationContext.TypeLibrary);

            result.ValueType        = constant.Type;
            result.DotnetTypeString = constant.DotnetTypeString;

            _compilationContext.CompilationUnit.AddConstant(constant);

            result.ReturnOutputSlot = new ExpressionSlot(result.ValueType, result);

            return(result);
        }