public static CodegenExpression Codegen(
            ExprInstanceofNodeForge forge,
            CodegenMethodScope codegenMethodScope,
            ExprForgeCodegenSymbol exprSymbol,
            CodegenClassScope codegenClassScope)
        {
            CodegenExpression cache = codegenClassScope.AddDefaultFieldUnshared<CopyOnWriteList<Pair<Type, bool>>>(
                true,
                NewInstance(typeof(CopyOnWriteList<Pair<Type, bool>>)));
            var methodNode = codegenMethodScope.MakeChild(
                typeof(bool),
                typeof(ExprInstanceofNodeForgeEval),
                codegenClassScope);

            var block = methodNode.Block
                .DeclareVar<object>(
                    "result",
                    forge.ForgeRenderableInstanceOf.ChildNodes[0]
                        .Forge.EvaluateCodegen(
                            typeof(object),
                            methodNode,
                            exprSymbol,
                            codegenClassScope))
                .IfRefNullReturnFalse("result");
            block.MethodReturn(
                StaticMethod(
                    typeof(ExprInstanceofNodeForgeEval),
                    "InstanceofCacheCheckOrAdd",
                    Constant(forge.Classes),
                    cache,
                    Ref("result")));
            return LocalMethod(methodNode);
        }
 public ExprInstanceofNodeForgeEval(
     ExprInstanceofNodeForge forge,
     ExprEvaluator evaluator)
 {
     this.forge = forge;
     this.evaluator = evaluator;
 }
Beispiel #3
0
        public override ExprNode Validate(ExprValidationContext validationContext)
        {
            if (this.ChildNodes.Length != 1) {
                throw new ExprValidationException(
                    "Instanceof node must have 1 child expression node supplying the expression to test");
            }

            if ((classIdentifiers == null) || (classIdentifiers.Length == 0)) {
                throw new ExprValidationException(
                    "Instanceof node must have 1 or more class identifiers to verify type against");
            }

            ISet<Type> classList = GetClassSet(classIdentifiers, validationContext.ImportService);
            Type[] classes;
            lock (this) {
                classes = classList.ToArray();
            }

            forge = new ExprInstanceofNodeForge(this, classes);
            return null;
        }