コード例 #1
0
        /// <summary>
        /// Génère le code d'un appel de "macro" fonction.
        /// </summary>
        /// <param name="call"></param>
        /// <returns></returns>
        string GenerateMacroFunctionCall(FunctionCall call)
        {
            StringBuilder builder = new StringBuilder();

            if (call.Src != null)
            {
                builder.Append(GenerateEvaluable(call.Src) + ".");
            }

            Clank.Core.Model.MacroContainer macros = m_project.Macros;
            var klass = macros.FindClassByType(call.Src.Type.BaseType);

            Clank.Core.Model.MacroContainer.MacroFunction func = klass.Functions[call.Func.Name]; // TODO : GetFullName() ??

            // Nom de la fonctin native dont les paramètres sont entourés par des $
            string nativeFuncName = func.LanguageToFunctionName[LANG_KEY];

            // Remplace les paramètres par leurs values.
            for (int i = 0; i < call.Func.Arguments.Count; i++)
            {
                nativeFuncName = nativeFuncName.Replace("$" + call.Func.Arguments[i].ArgName + "$",
                                                        GenerateEvaluable(call.Arguments[i]));
            }

            builder.Append(nativeFuncName);
            return(builder.ToString().Replace(".[", "["));
        }
コード例 #2
0
        /// <summary>
        /// Génère le code d'un appel de "macro" fonction.
        /// </summary>
        /// <param name="call"></param>
        /// <returns></returns>
        string GenerateMacroFunctionCall(FunctionCall call)
        {
            StringBuilder builder = new StringBuilder();

            Clank.Core.Model.MacroContainer macros = m_project.Macros;
            ClankTypeInstance owner;

            if (call.IsConstructor)
            {
                owner = call.Func.ReturnType;
            }
            else
            {
                owner = call.Src.Type;
            }

            Model.MacroContainer.MacroClass klass = macros.FindClassByType(owner.BaseType);
            string fullname = call.Func.GetFullName();

            if (!klass.Functions.ContainsKey(fullname))
            {
                throw new Exception("Le type array '" + klass.Type.GetFullName() + "' ne contient pas de constructeur sans paramètre, et ce constructeur est nécessaire à la sérialisation de cet array");
            }
            Clank.Core.Model.MacroContainer.MacroFunction func = klass.Functions[fullname]; // TODO : GetFullName() ??

            // Nom de la fonctin native dont les paramètres sont entourés par des $
            string nativeFuncName = func.LanguageToFunctionName[LANG_KEY];


            // Remplace les paramètres par leurs values.
            for (int i = 0; i < call.Func.Arguments.Count; i++)
            {
                nativeFuncName = nativeFuncName.Replace(SemanticConstants.ReplaceChr + "(" + call.Func.Arguments[i].ArgName + ")",
                                                        GenerateEvaluable(call.Arguments[i]));
            }


            // Remplace les params génériques par leurs valeurs.
            for (int i = 0; i < call.Func.Owner.GenericArgumentNames.Count; i++)
            {
                nativeFuncName = nativeFuncName.Replace(SemanticConstants.ReplaceChr + "(" + call.Func.Owner.GenericArgumentNames[i] + ")",
                                                        GenerateTypeInstanceName(owner.GenericArguments[i]));
            }

            // Remplace @self par le nom de la variable.
            nativeFuncName = nativeFuncName.Replace(SemanticConstants.SelfKW, GenerateEvaluable(call.Src));

            builder.Append(nativeFuncName);
            return(builder.ToString().Replace(".[", "["));
        }
コード例 #3
0
        /// <summary>
        /// Génère le code d'un appel de "macro" fonction.
        /// </summary>
        /// <param name="call"></param>
        /// <returns></returns>
        string GenerateMacroFunctionCall(FunctionCall call)
        {
            StringBuilder builder = new StringBuilder();

            Clank.Core.Model.MacroContainer macros = m_project.Macros;
            ClankTypeInstance owner;

            if (call.IsConstructor)
            {
                owner = call.Func.ReturnType;
            }
            else
            {
                owner = call.Src.Type;
            }

            Model.MacroContainer.MacroClass klass = macros.FindClassByType(owner.BaseType);
            Clank.Core.Model.MacroContainer.MacroFunction func = klass.Functions[call.Func.GetFullName()]; // TODO : GetFullName() ??

            // Nom de la fonctin native dont les paramètres sont entourés par des $
            if (!func.LanguageToFunctionName.ContainsKey(LANG_KEY))
            {
                throw new Exception("La macro-fonction '" + call.Func.GetFullName() + "' n'est pas renseignée pour le langage '" + LANG_KEY + "'.");
            }
            string nativeFuncName = func.LanguageToFunctionName[LANG_KEY];


            // Remplace les paramètres par leurs values.
            for (int i = 0; i < call.Func.Arguments.Count; i++)
            {
                nativeFuncName = nativeFuncName.Replace(SemanticConstants.ReplaceChr + "(" + call.Func.Arguments[i].ArgName + ")",
                                                        GenerateEvaluable(call.Arguments[i]));
            }


            // Remplace les params génériques par leurs valeurs.
            for (int i = 0; i < call.Func.Owner.GenericArgumentNames.Count; i++)
            {
                nativeFuncName = nativeFuncName.Replace(SemanticConstants.ReplaceChr + "(" + call.Func.Owner.GenericArgumentNames[i] + ")",
                                                        GenerateTypeInstanceName(owner.GenericArguments[i]));
            }

            // Remplace @self par le nom de la variable.
            nativeFuncName = nativeFuncName.Replace(SemanticConstants.SelfKW, GenerateEvaluable(call.Src));

            builder.Append(nativeFuncName);
            return(builder.ToString().Replace(".[", "["));
        }