Exemple #1
0
        private void InitRunner(Options options)
        {
            graphCompiler = GraphToDSCompiler.GraphCompiler.CreateInstance();
            graphCompiler.SetCore(GraphUtilities.GetCore());
            runner = new ProtoScriptTestRunner();

            executionOptions = options;
            InitOptions();
            InitCore();


            taskQueue = new Queue <Task>();

            workerThread = new Thread(new ThreadStart(TaskExecMethod));
            workerThread.IsBackground = true;
            workerThread.Start();

            staticContext = new ProtoCore.CompileTime.Context();
        }
Exemple #2
0
        private void ImportProcedure(string library, ProcedureNode proc)
        {
            string procName = proc.name;

            if (proc.isAutoGeneratedThisProc ||
                CoreUtils.IsSetter(procName) ||
                CoreUtils.IsDisposeMethod(procName) ||
                CoreUtils.StartsWithDoubleUnderscores(procName))
            {
                return;
            }

            int              classScope      = proc.classScope;
            string           className       = string.Empty;
            MethodAttributes methodAttribute = proc.MethodAttribute;
            ClassAttributes  classAttribute  = null;

            if (classScope != ProtoCore.DSASM.Constants.kGlobalScope)
            {
                var classNode = GraphUtilities.GetCore().ClassTable.ClassNodes[classScope];

                classAttribute = classNode.ClassAttributes;
                className      = classNode.name;
            }

            // MethodAttribute's HiddenInLibrary has higher priority than
            // ClassAttribute's HiddenInLibrary
            bool isVisible = true;

            if (methodAttribute != null)
            {
                isVisible = !methodAttribute.HiddenInLibrary;
            }
            else
            {
                if (classAttribute != null)
                {
                    isVisible = !classAttribute.HiddenInLibrary;
                }
            }

            FunctionType type;

            if (classScope == ProtoCore.DSASM.Constants.kGlobalScope)
            {
                type = FunctionType.GenericFunction;
            }
            else
            {
                if (CoreUtils.IsGetter(procName))
                {
                    type = proc.isStatic
                        ? FunctionType.StaticProperty
                        : FunctionType.InstanceProperty;

                    string property;
                    if (CoreUtils.TryGetPropertyName(procName, out property))
                    {
                        procName = property;
                    }
                }
                else
                {
                    if (proc.isConstructor)
                    {
                        type = FunctionType.Constructor;
                    }
                    else if (proc.isStatic)
                    {
                        type = FunctionType.StaticMethod;
                    }
                    else
                    {
                        type = FunctionType.InstanceMethod;
                    }
                }
            }

            IEnumerable <TypedParameter> arguments = proc.argInfoList.Zip(
                proc.argTypeList,
                (arg, argType) =>
            {
                object defaultValue = null;
                if (arg.IsDefault)
                {
                    var binaryExpr = arg.DefaultExpression as BinaryExpressionNode;
                    if (binaryExpr != null)
                    {
                        AssociativeNode vnode = binaryExpr.RightNode;
                        if (vnode is IntNode)
                        {
                            defaultValue = (vnode as IntNode).Value;
                        }
                        else if (vnode is DoubleNode)
                        {
                            defaultValue = (vnode as DoubleNode).Value;
                        }
                        else if (vnode is BooleanNode)
                        {
                            defaultValue = (vnode as BooleanNode).Value;
                        }
                        else if (vnode is StringNode)
                        {
                            defaultValue = (vnode as StringNode).value;
                        }
                    }
                }

                return(new TypedParameter(arg.Name, argType.ToString(), defaultValue));
            });

            IEnumerable <string> returnKeys = null;

            if (proc.MethodAttribute != null && proc.MethodAttribute.ReturnKeys != null)
            {
                returnKeys = proc.MethodAttribute.ReturnKeys;
            }

            var function = new FunctionDescriptor(
                library,
                className,
                procName,
                arguments,
                proc.returntype.ToString(),
                type,
                isVisible,
                returnKeys,
                proc.isVarArg);

            AddImportedFunctions(library, new[] { function });
        }