Пример #1
0
        /// <summary>
        /// Génère le code représentant le type passé en paramètre.
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        string GenerateTypeName(ClankType type)
        {
            if (type.IsBuiltIn)
            {
                if (type.JType == JSONType.String)
                {
                    return("std::string");
                }
            }
            if (type.IsMacro)
            {
                // Pour les types macro, on remplace le nom du type par le nom du type natif.
                Model.MacroContainer.MacroClass mcClass = m_project.Macros.FindClassByType(type);
                if (!mcClass.LanguageToTypeName.ContainsKey(LANG_KEY))
                {
                    throw new InvalidOperationException("Le nom de la macro classe '" + type.GetFullNameAndGenericArgs() + "' n'est pas renseigné pour le langage '" + LANG_KEY + "'");
                }

                string nativeClassName = mcClass.LanguageToTypeName[LANG_KEY];

                return(mcClass.LanguageToTypeName[LANG_KEY]);
            }
            else
            if (type.Name.ToLower().Contains("string"))
            {
                return("std::string");
            }
            else
            {
                return(type.Name);
            }
        }
Пример #2
0
        /// <summary>
        /// Génère une fonction de sérialisation pour la classe donnée.
        /// </summary>
        /// <param name="decl"></param>
        /// <returns></returns>
        public string GenerateSerializer(ClassDeclaration decl)
        {
            StringBuilder sb       = new StringBuilder();
            ClankType     type     = m_project.Types.Types[decl.Name];
            string        typename = GenerateTypeName(type);

            sb.AppendLine("void " + typename + "::serialize(std::ostream& output) {");
            foreach (var inst in decl.Instructions)
            {
                Variable attr = null;
                if (inst is VariableDeclarationInstruction)
                {
                    VariableDeclarationInstruction vardecl = (VariableDeclarationInstruction)inst;
                    attr = vardecl.Var;
                }
                else if (inst is VariableDeclarationAndAssignmentInstruction)
                {
                    VariableDeclarationAndAssignmentInstruction vardecl = (VariableDeclarationAndAssignmentInstruction)inst;
                    attr = (Variable)vardecl.Declaration.Var;
                }
                else
                {
                    continue;
                }

                sb.AppendLine("\t// " + attr.Name);
                sb.AppendLine(Tools.StringUtils.Indent(GenerateSerializationInstruction(
                                                           new Variable()
                {
                    Type = attr.Type, Name = "this->" + attr.Name
                })));
            }
            sb.AppendLine("}");
            return(sb.ToString());
        }
Пример #3
0
        /// <summary>
        /// Génère une fonction de désérialisation pour la classe donnée.
        /// </summary>
        /// <param name="decl"></param>
        /// <returns></returns>
        public string GenerateDeserializer(ClassDeclaration decl)
        {
            StringBuilder sb       = new StringBuilder();
            ClankType     type     = m_project.Types.Types[decl.Name];
            string        typename = GenerateTypeName(type);
            string        objName  = "_obj";

            sb.AppendLine(typename + " " + typename + "::deserialize(std::istream& input) {");
            sb.AppendLine("\t" + typename + " " + objName + " = " + typename + "();");
            foreach (var inst in decl.Instructions)
            {
                Variable attr = null;
                if (inst is VariableDeclarationInstruction)
                {
                    VariableDeclarationInstruction vardecl = (VariableDeclarationInstruction)inst;
                    attr = vardecl.Var;
                }
                else if (inst is VariableDeclarationAndAssignmentInstruction)
                {
                    VariableDeclarationAndAssignmentInstruction vardecl = (VariableDeclarationAndAssignmentInstruction)inst;
                    attr = (Variable)vardecl.Declaration.Var;
                }
                else
                {
                    continue;
                }

                sb.AppendLine("\t// " + attr.Name);
                sb.AppendLine(Tools.StringUtils.Indent(GenerateDeserializationInstruction(attr, objName + "_" + attr.Name)));
                sb.AppendLine("\t" + objName + "." + attr.Name + " = (" + GenerateTypeInstanceNamePrefixed(attr.Type) + ")" + objName + "_" + attr.Name + ";");
            }
            sb.AppendLine("\treturn " + objName + ";");
            sb.AppendLine("}");
            return(sb.ToString());
        }
Пример #4
0
        /// <summary>
        /// Génère le code représentant le type passé en paramètre.
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        string GenerateTypeName(ClankType type)
        {
            if (type.IsMacro)
            {
                // Pour les types macro, on remplace le nom du type par le nom du type natif.
                Model.MacroContainer.MacroClass mcClass = m_project.Macros.FindClassByType(type);
                if (!mcClass.LanguageToTypeName.ContainsKey(LANG_KEY))
                {
                    throw new InvalidOperationException("Le nom de la macro classe '" + type.GetFullNameAndGenericArgs() + "' n'est pas renseigné pour le langage '" + LANG_KEY + "'");
                }

                string nativeClassName = mcClass.LanguageToTypeName[LANG_KEY];

                return(mcClass.LanguageToTypeName[LANG_KEY]);
            }
            else if (type.IsBuiltIn)
            {
                switch (type.JType)
                {
                case JSONType.Bool:
                    return("Boolean");

                case JSONType.Int:
                    return("Integer");

                case JSONType.String:
                    return("String");

                case JSONType.Float:
                    return("Double");
                }
            }
            return(type.Name);
        }
Пример #5
0
 /// <summary>
 /// Génère le code représentant le type passé en paramètre.
 /// </summary>
 /// <param name="type"></param>
 /// <returns></returns>
 string GenerateTypeName(ClankType type)
 {
     if (type.IsMacro)
     {
         // Pour les types macro, on remplace le nom du type par le nom du type natif.
         Model.MacroContainer.MacroClass mcClass = m_project.Macros.FindClassByType(type);
         return(mcClass.LanguageToTypeName[LANG_KEY]);
     }
     else
     {
         return(type.Name);
     }
 }
Пример #6
0
 /// <summary>
 /// Génère le code représentant le type passé en paramètre.
 /// </summary>
 /// <param name="type"></param>
 /// <returns></returns>
 static string GenerateTypeName(ClankType type)
 {
     return(type.Name);
 }