Beispiel #1
0
        /// <summary>
        /// Retourne la fonction d'instance pour un type donné dont le nom est passé en paramètre.
        /// </summary>
        /// <param name="functionName"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public Language.Function GetInstanceFunction(Language.ClankTypeInstance instance, string functionName, List <Language.Evaluable> args, Context context)
        {
            string fullName = "";

            // Pour les fonctions du bloc state, elles ne sont pas préfixées dans la table.
            if (instance == null || instance.BaseType.GetFullName() == Language.SemanticConstants.StateClass)
            {
                fullName = functionName + Language.Evaluable.GetArgTypesString(args);
            }
            else
            {
                fullName = instance.BaseType.GetFullName() + "." + functionName + Language.Evaluable.GetArgTypesString(args);
            }

            var instanciatedOverloads = InstanciatedFunc(instance);

            if (instanciatedOverloads.ContainsKey(fullName))
            {
                Language.Function func = instanciatedOverloads[fullName];
                // Vérification : la fonction est-elle une méthode d'instance ?
                if (func.IsStatic)
                {
                    if (instance != null)
                    {
                        throw new SemanticError("La fonction " + functionName + " n'est pas une méthode d'instance de " + instance.BaseType.GetFullName() + ".");
                    }
                    else
                    {
                        throw new SemanticError("La fonction globale " + functionName + " n'est pas une méthode d'instance.");
                    }
                }
                return(instanciatedOverloads[fullName]);
            }
            return(null);
        }
Beispiel #2
0
        /// <summary>
        /// Retourne la fonction dont le nom est passé en paramètre.
        /// </summary>
        /// <param name="functionName"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public Language.Function GetFunction(string functionName, Context context)
        {
            string fullName = functionName;

            if (Functions.ContainsKey(fullName))
            {
                Language.Function func = Functions[fullName];
                return(Functions[fullName]);
            }
            return(null);
        }
Beispiel #3
0
        /// <summary>
        /// Retourne la fonction statique pour un type donné dont le nom est passé en paramètre.
        /// </summary>
        /// <param name="functionName"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public Language.Function GetStaticFunction(Language.ClankTypeInstance instancedType, string functionName, List <Language.Evaluable> args, Context context)
        {
            // Obtient le nom complet de la fonction (avec les args).
            Language.ClankType owner    = instancedType.BaseType;
            string             fullName = owner.GetFullName() + "." + functionName + Language.Evaluable.GetArgTypesString(args);

            var instanciatedOverloads = InstanciatedFunc(instancedType);

            if (instanciatedOverloads.ContainsKey(fullName))
            {
                Language.Function func = instanciatedOverloads[fullName];
                // Vérification : la fonction est-elle statique ?
                if (!func.IsStatic)
                {
                    throw new SemanticError("La fonction " + functionName + " n'est pas une méthode statique de " + owner.GetFullName() + ".");
                }
                return(instanciatedOverloads[fullName]);
            }
            return(null);
        }
Beispiel #4
0
        /// <summary>
        /// Retourne le constructeur (instancié) pour un type donné.
        /// </summary>
        public Language.Function GetConstructor(Language.ClankType owner, Language.ClankTypeInstance inst, List <Language.Evaluable> args, Context context)
        {
            string fullName            = owner.GetFullName() + "." + Language.SemanticConstants.New + Language.Evaluable.GetArgTypesString(args);
            var    instanciedOverloads = InstanciatedFunc(inst);

            if (instanciedOverloads.ContainsKey(fullName))
            {
                Language.Function func = instanciedOverloads[fullName];

                // Vérification : la fonction est-elle bien marquée comme constructeur ?
                if (!func.IsConstructor)
                {
                    throw new SemanticError("La fonction " + Language.SemanticConstants.New + " n'est pas un constructeur de " + owner.GetFullName() + ".");
                }
                return(func.Instanciate(inst.GenericArguments));
            }

            if (args.Count != 0)
            {
                throw new SemanticError("Aucun constructeur de '" + owner.GetFullName() + "' ne matche les arguments de type : " +
                                        Language.Evaluable.GetArgTypesString(args) + ". Candidats possibles : " + GetCandidatesStr(inst, Language.SemanticConstants.New));
            }

            // Si le constructeur n'existe pas, on crée le constructeur par défaut.
            Language.Function cons = new Language.Function()
            {
                Modifiers = new List <string>()
                {
                    Language.SemanticConstants.Public, Language.SemanticConstants.Constructor
                },
                ReturnType = inst,
                Arguments  = new List <Language.FunctionArgument>(),
                Code       = new List <Language.Instruction>(),
                Owner      = owner,
                Type       = inst,
                Name       = Language.SemanticConstants.New
            };
            return(cons);
        }