Ejemplo n.º 1
0
        public IValue GetFunctionCallReturnValue(IValue target, BasicClepsType targetType, string targetFunctionName, FunctionClepsType clepsType, List <IValue> parameters)
        {
            string code;

            if (CompilerConstants.SystemSupportedTypes.Contains(targetType) && target != null)
            {
                string fullFunctionName = String.Format("{0}.{1}.prototype.{2}", JavaScriptCodeParameters.TOPLEVELNAMESPACE, targetType.GetClepsTypeString(), JavaScriptCodeParameters.GetMangledFunctionName(targetFunctionName, clepsType));
                string functionTarget   = target != null ? (target as JavaScriptValue).Expression : String.Format("{0}.{1}", JavaScriptCodeParameters.TOPLEVELNAMESPACE, targetType.GetClepsTypeString());
                string parameterString  = String.Join("", parameters.Select(v => ", " + (v as JavaScriptValue).Expression).ToList());

                code = String.Format("{0}.call({1}{2})", fullFunctionName, functionTarget, parameterString);
            }
            else
            {
                string functionTarget   = target != null ? (target as JavaScriptValue).Expression : String.Format("{0}.{1}", JavaScriptCodeParameters.TOPLEVELNAMESPACE, targetType.GetClepsTypeString());
                string fullFunctionName = String.Format("{0}.{1}", functionTarget, JavaScriptCodeParameters.GetMangledFunctionName(targetFunctionName, clepsType));

                string parameterString = String.Join(", ", parameters.Select(v => (v as JavaScriptValue).Expression).ToList());
                code = String.Format("{0}({1})", fullFunctionName, parameterString);
            }

            JavaScriptValue ret = new JavaScriptValue(code, clepsType.ReturnType);

            return(ret);
        }
Ejemplo n.º 2
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()
                                );
        }
Ejemplo n.º 3
0
        private void GenerateClass(StringBuilder output, ClepsClass clepsClass)
        {
            FunctionClepsType voidFuncType = new FunctionClepsType(new List <ClepsType>(), VoidClepsType.GetVoidType());

            EnsureNamespaceExists(output, clepsClass);
            output.AppendLine(JavaScriptCodeParameters.TOPLEVELNAMESPACE + "." + clepsClass.FullyQualifiedName + " = function() {");
            {
                clepsClass.MemberVariables.ToList().ForEach(kvp => output.AppendFormat("\tthis.{0} = undefined;\n", kvp.Key));

                output.AppendFormat("\tthis.{0}();\n", JavaScriptCodeParameters.GetMangledFunctionName("classInitializer", voidFuncType));
                output.AppendFormat("\t{0}.{1}.{2}();\n", JavaScriptCodeParameters.TOPLEVELNAMESPACE, clepsClass.FullyQualifiedName, JavaScriptCodeParameters.GetMangledFunctionName("classStaticInitializer", voidFuncType));
            }
            output.AppendLine("};");

            GenerateMethodWithBody(output, clepsClass.FullyQualifiedName, "classInitializer", voidFuncType, false, ClassInitializers[clepsClass.FullyQualifiedName]);
            GenerateMethodWithBody(output, clepsClass.FullyQualifiedName, "classStaticInitializer", voidFuncType, true, ClassStaticInitializers[clepsClass.FullyQualifiedName]);
        }
Ejemplo n.º 4
0
        public IValueRegister GetConstantMemberFieldRegisterForWrite(string className, string memberName, ClepsType memberType)
        {
            JavaScriptRegister ret;

            if (memberType.IsFunctionType)
            {
                ret = new JavaScriptRegister(String.Format("{0}.{1}.prototype.{2}", JavaScriptCodeParameters.TOPLEVELNAMESPACE, className, JavaScriptCodeParameters.GetMangledFunctionName(memberName, memberType as FunctionClepsType)), memberType);
            }
            else
            {
                ret = new JavaScriptRegister(String.Format("{0}.{1}.prototype.{2}", JavaScriptCodeParameters.TOPLEVELNAMESPACE, className, memberName), memberType);
            }
            return(ret);
        }
Ejemplo n.º 5
0
        public void Output(string directoryName, string fileNameWithoutExtension, CompileStatus status)
        {
            StringBuilder output = new StringBuilder();

            InitializeOutput(output);

            foreach (var nativeCodeSnippet in GlobalNativeCodeSnippets)
            {
                output.AppendLine(nativeCodeSnippet);
            }

            foreach (var clepsClass in ClassesLoaded)
            {
                GenerateClass(output, clepsClass.Value);
            }

            output.AppendLine(GlobalInitializer.GetMethodBodyWithoutDeclaration());

            FunctionClepsType voidFuncType = new FunctionClepsType(new List <ClepsType>(), VoidClepsType.GetVoidType());

            foreach (var clepsType in CompilerConstants.SystemSupportedTypes)
            {
                output.AppendFormat("{0}.{1}.{2}();\n", JavaScriptCodeParameters.TOPLEVELNAMESPACE, clepsType.GetClepsTypeString(), JavaScriptCodeParameters.GetMangledFunctionName("classStaticInitializer", voidFuncType));
            }

            if (!String.IsNullOrWhiteSpace(EntryPointClass) && !String.IsNullOrWhiteSpace(EntryPointFunctionName))
            {
                output.AppendFormat("{0}.{1}.{2}();\n", JavaScriptCodeParameters.TOPLEVELNAMESPACE, EntryPointClass, JavaScriptCodeParameters.GetMangledFunctionName("classStaticInitializer", voidFuncType));
                output.AppendFormat("{0}.{1}.{2}();\n", JavaScriptCodeParameters.TOPLEVELNAMESPACE, EntryPointClass, JavaScriptCodeParameters.GetMangledFunctionName(EntryPointFunctionName, voidFuncType));
            }

            var outputFileName = Path.Combine(directoryName, fileNameWithoutExtension + ".js");

            File.WriteAllText(outputFileName, output.ToString());
        }