コード例 #1
0
        public IMethodRegister CreateMethod(string className, bool isStatic, ClepsType functionType, string functionName)
        {
            if (!classesLoaded.ContainsKey(className))
            {
                throw new ArgumentException(String.Format("Class {0} not loaded", className));
            }

            if (!functionType.IsFunctionType)
            {
                throw new ArgumentException("Expected function type. Got " + functionType.GetClepsTypeString());
            }

            var classNameToUse = isStatic ? className + ".static" : className;
            var functionNameAndType = new FunctionNameAndType(classNameToUse, functionName, functionType);
            var methodList = isStatic ? staticMethods[classNameToUse] : memberMethods[classNameToUse];

            if (methodList.Contains(functionNameAndType))
            {
                throw new ArgumentException(String.Format("Function {0} {1} {2} for class {3} already exists", isStatic ? "static" : "", functionType, functionName, className));
            }

            methodList.Add(functionNameAndType);
            var methodRegister = new JavaScriptMethod(functionType as FunctionClepsType);
            methodBodies.Add(functionNameAndType, methodRegister);

            return methodRegister;
        }
コード例 #2
0
        public IMethodRegister CreateMethod(string className, bool isStatic, ClepsType functionType, string functionName)
        {
            if (!classesLoaded.ContainsKey(className))
            {
                throw new ArgumentException(String.Format("Class {0} not loaded", className));
            }

            if (!functionType.IsFunctionType)
            {
                throw new ArgumentException("Expected function type. Got " + functionType.GetClepsTypeString());
            }

            var classNameToUse      = isStatic ? className + ".static" : className;
            var functionNameAndType = new FunctionNameAndType(classNameToUse, functionName, functionType);
            var methodList          = isStatic ? staticMethods[classNameToUse] : memberMethods[classNameToUse];

            if (methodList.Contains(functionNameAndType))
            {
                throw new ArgumentException(String.Format("Function {0} {1} {2} for class {3} already exists", isStatic ? "static" : "", functionType, functionName, className));
            }

            methodList.Add(functionNameAndType);
            var methodRegister = new JavaScriptMethod(functionType as FunctionClepsType);

            methodBodies.Add(functionNameAndType, methodRegister);

            return(methodRegister);
        }
コード例 #3
0
        public void CreateClass(string className)
        {
            ClassesLoaded.Add(className, null);
            ClassInitializers[className] = new JavaScriptMethod(new FunctionClepsType(new List<ClepsType>(), VoidClepsType.GetVoidType()));
            ClassStaticInitializers[className] = new JavaScriptMethod(new FunctionClepsType(new List<ClepsType>(), VoidClepsType.GetVoidType()));

            //static initializing should occur only once
            ClassStaticInitializers[className].CreateIfStatementBlock(new JavaScriptValue("![" + JavaScriptCodeParameters.TOPLEVELNAMESPACE + "." + className + ".classStaticInitialized]", CompilerConstants.ClepsBoolType));
            ClassStaticInitializers[className].CreateAssignment(new JavaScriptRegister(JavaScriptCodeParameters.TOPLEVELNAMESPACE + "." + className + ".classStaticInitialized", CompilerConstants.ClepsBoolType), new JavaScriptValue("[true]", CompilerConstants.ClepsBoolType));
        }
コード例 #4
0
        public void CreateClass(string className)
        {
            ClassesLoaded.Add(className, null);
            ClassInitializers[className]       = new JavaScriptMethod(new FunctionClepsType(new List <ClepsType>(), VoidClepsType.GetVoidType()));
            ClassStaticInitializers[className] = new JavaScriptMethod(new FunctionClepsType(new List <ClepsType>(), VoidClepsType.GetVoidType()));

            //static initializing should occur only once
            ClassStaticInitializers[className].CreateIfStatementBlock(new JavaScriptValue("![" + JavaScriptCodeParameters.TOPLEVELNAMESPACE + "." + className + ".classStaticInitialized]", CompilerConstants.ClepsBoolType));
            ClassStaticInitializers[className].CreateAssignment(new JavaScriptRegister(JavaScriptCodeParameters.TOPLEVELNAMESPACE + "." + className + ".classStaticInitialized", CompilerConstants.ClepsBoolType), new JavaScriptValue("[true]", CompilerConstants.ClepsBoolType));
        }
コード例 #5
0
        public void Initiate()
        {
            FunctionClepsType voidFuncType = new FunctionClepsType(new List<ClepsType>(), VoidClepsType.GetVoidType());

            ClassesLoaded = new Dictionary<string, ClepsClass>();
            ClassInitializers = new Dictionary<string, JavaScriptMethod>();
            ClassStaticInitializers = new Dictionary<string, JavaScriptMethod>();
            GlobalInitializer = new JavaScriptMethod(voidFuncType);
            EntryPointClass = null;
            EntryPointFunctionName = null;
            GlobalNativeCodeSnippets = new List<string>();
        }
コード例 #6
0
        public void Initiate()
        {
            FunctionClepsType voidFuncType = new FunctionClepsType(new List <ClepsType>(), VoidClepsType.GetVoidType());

            ClassesLoaded            = new Dictionary <string, ClepsClass>();
            ClassInitializers        = new Dictionary <string, JavaScriptMethod>();
            ClassStaticInitializers  = new Dictionary <string, JavaScriptMethod>();
            GlobalInitializer        = new JavaScriptMethod(voidFuncType);
            EntryPointClass          = null;
            EntryPointFunctionName   = null;
            GlobalNativeCodeSnippets = new List <string>();
        }
コード例 #7
0
        public JavaScriptCodeOutputter(Dictionary<string, ClepsClass> classesLoaded, 
            Dictionary<string, JavaScriptMethod> classInitializers,
            Dictionary<string, JavaScriptMethod> classStaticInitializers,
            JavaScriptMethod globalInitializer,
            string entryPointClass, 
            string entryPointFunctionName,
            List<string> globalNativeCodeSnippets
        )
        {
            ClassesLoaded = classesLoaded;
            ClassInitializers = classInitializers;
            ClassStaticInitializers = classStaticInitializers;
            GlobalInitializer = globalInitializer;
            EntryPointClass = entryPointClass;
            EntryPointFunctionName = entryPointFunctionName;
            GlobalNativeCodeSnippets = globalNativeCodeSnippets;

            NamespacesCreated = new List<string>();
        }
コード例 #8
0
        public JavaScriptCodeOutputter(Dictionary <string, ClepsClass> classesLoaded,
                                       Dictionary <string, JavaScriptMethod> classInitializers,
                                       Dictionary <string, JavaScriptMethod> classStaticInitializers,
                                       JavaScriptMethod globalInitializer,
                                       string entryPointClass,
                                       string entryPointFunctionName,
                                       List <string> globalNativeCodeSnippets
                                       )
        {
            ClassesLoaded            = classesLoaded;
            ClassInitializers        = classInitializers;
            ClassStaticInitializers  = classStaticInitializers;
            GlobalInitializer        = globalInitializer;
            EntryPointClass          = entryPointClass;
            EntryPointFunctionName   = entryPointFunctionName;
            GlobalNativeCodeSnippets = globalNativeCodeSnippets;

            NamespacesCreated = new List <string>();
        }
コード例 #9
0
 public IMethodValue CreateNewMethod(FunctionClepsType functionType)
 {
     var methodRegister = new JavaScriptMethod(functionType);
     return methodRegister;
 }
コード例 #10
0
        private void GenerateMethodWithBody(StringBuilder output, string fullyQualifiedClassName, string methodName, FunctionClepsType methodType, bool isStatic, JavaScriptMethod method)
        {
            string fullFunctionName = String.Format("{0}.{1}.{2}{3}",
                JavaScriptCodeParameters.TOPLEVELNAMESPACE,
                fullyQualifiedClassName,
                isStatic ? "" : "prototype.",
                JavaScriptCodeParameters.GetMangledFunctionName(methodName, methodType)
            );

            output.AppendFormat("{0} = {1};\n",
                fullFunctionName,
                method.GetMethodText()
            );
        }
コード例 #11
0
        public IMethodValue CreateNewMethod(FunctionClepsType functionType)
        {
            var methodRegister = new JavaScriptMethod(functionType);

            return(methodRegister);
        }
コード例 #12
0
        private void GenerateMethodWithBody(StringBuilder output, string fullyQualifiedClassName, string methodName, FunctionClepsType methodType, bool isStatic, JavaScriptMethod method)
        {
            string fullFunctionName = String.Format("{0}.{1}.{2}{3}",
                                                    JavaScriptCodeParameters.TOPLEVELNAMESPACE,
                                                    fullyQualifiedClassName,
                                                    isStatic ? "" : "prototype.",
                                                    JavaScriptCodeParameters.GetMangledFunctionName(methodName, methodType)
                                                    );

            output.AppendFormat("{0} = {1};\n",
                                fullFunctionName,
                                method.GetMethodText()
                                );
        }