public void SetClassBodyAndCreateConstructor(ClepsClass clepsClass)
        {
            if(!classesLoaded.ContainsKey(clepsClass.FullyQualifiedName))
            {
                throw new ArgumentException(String.Format("Class {0} not loaded", clepsClass.FullyQualifiedName));
            }

            if(classesLoaded[clepsClass.FullyQualifiedName] != null)
            {
                throw new ArgumentException(String.Format("Body for class {0} already set", clepsClass.FullyQualifiedName));
            }

            classesLoaded[clepsClass.FullyQualifiedName] = clepsClass;
        }
示例#2
0
        public override bool Equals(object obj)
        {
            if (obj.GetType() != typeof(ClepsClass) || Object.ReferenceEquals(null, obj))
            {
                return(false);
            }

            ClepsClass objToCompare = obj as ClepsClass;

            return(FullyQualifiedName == objToCompare.FullyQualifiedName &&
                   AreDictionariesEqual(MemberVariables, objToCompare.MemberVariables) &&
                   AreDictionariesEqual(MemberMethods, objToCompare.MemberMethods) &&
                   AreDictionariesEqual(StaticMemberVariables, objToCompare.StaticMemberVariables) &&
                   AreDictionariesEqual(StaticMemberMethods, objToCompare.StaticMemberMethods));
        }
        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]);
        }
 public void SetClassBodyAndCreateConstructor(ClepsClass clepsClass)
 {
     ClassesLoaded[clepsClass.FullyQualifiedName] = clepsClass;
 }
示例#5
0
 public void SetClassBodyAndCreateConstructor(ClepsClass clepsClass)
 {
     var memberTypes = clepsClass.MemberVariables.Values.Select(c => GetLLVMType(c)).ToArray();
     LLVM.StructSetBody(ClassSkeletons[clepsClass.FullyQualifiedName], memberTypes, false /* packed */);
 }
示例#6
0
 public void SetClassDefinition(ClepsClass clepsClass)
 {
     LoadedClasses.Add(clepsClass.FullyQualifiedName, clepsClass);
 }
        private void EnsureNamespaceExists(StringBuilder output, ClepsClass clepsClass)
        {
            string currNamespace = clepsClass.GetPrefixNamespaceAndClass();
            var pieces = currNamespace.Split('.').ToList();

            for (int i = 1; i <= pieces.Count; i++)
            {
                var currNesting = String.Join(".", pieces.Take(i));
                if (!NamespacesCreated.Contains(currNesting))
                {
                    output.AppendFormat("{0}.{1} = {0}.{1} || {{}};\n", JavaScriptCodeParameters.TOPLEVELNAMESPACE, currNesting);
                    NamespacesCreated.Add(currNesting);
                }
            }
        }
示例#8
0
 public void SetClassDefinition(ClepsClass clepsClass)
 {
     LoadedClasses.Add(clepsClass.FullyQualifiedName, clepsClass);
 }
 private void GenerateClass(StringBuilder output, ClepsClass clepsClass)
 {
     EnsureNamespaceExists(output, clepsClass);
     //output.AppendLine(TOPLEVELNAMESPACE + "." + clepsClass.FullyQualifiedName + " = function() {");
     //{
     //    output.AppendLine("\tfunction newInst(curr) {");
     //    {
     //        clepsClass.MemberVariables.ToList().ForEach(kvp => output.AppendFormat("\t\tcurr.{0} = {1};\n", kvp.Key, GetTypeInstance(kvp.Value)));
     //        output.AppendLine("\t}");
     //    }
     //    output.AppendLine("\tnewInst(this);");
     //}
     //output.AppendLine("};");
     //clepsClass.MemberMethods.ToList().ForEach(kvp => output.AppendFormat("{0}.{1}.prototype.{2} = {3};\n", TOPLEVELNAMESPACE, clepsClass.FullyQualifiedName, kvp.Key, methodBodies[new FunctionNameAndType(clepsClass.FullyQualifiedName, kvp.Key, kvp.Value)].GetMethodBody()));
     //clepsClass.StaticMemberVariables.ToList().ForEach(kvp => output.AppendFormat("{0}.{1}.{2} = undefined;\n", TOPLEVELNAMESPACE, clepsClass.FullyQualifiedName, kvp.Key));
     //clepsClass.StaticMemberMethods.ToList().ForEach(kvp => output.AppendFormat("{0}.{1}.{2} = {3};\n", TOPLEVELNAMESPACE, clepsClass.FullyQualifiedName, kvp.Key, methodBodies[new FunctionNameAndType(clepsClass.FullyQualifiedName, kvp.Key, kvp.Value)].GetMethodBody()));
     GenerateJavaScriptClass(output, clepsClass.FullyQualifiedName, clepsClass.MemberVariables, clepsClass.MemberMethods, true /* staticInstCheck */);
     GenerateJavaScriptClass(output, clepsClass.FullyQualifiedName + ".static", clepsClass.StaticMemberVariables, clepsClass.StaticMemberMethods, false /* staticInstCheck */);
 }