コード例 #1
0
		internal static GrapeCallExpression Create(GrapeIdentifier identifier, GrapeList<GrapeExpression> parameters, GrapeAccessExpression next) {
			List<GrapeEntity> children = new List<GrapeEntity>();
			children.Add(identifier);
			children.AddRange(parameters.Enumerate());
			GrapeCallExpression result = new GrapeCallExpression(identifier, parameters, next);
			result.InitializeFromTemplate(identifier);
			result.InitializeFromChildren(identifier.FileName, children);
			return result;
		}
コード例 #2
0
        public bool ValidateMethodSignatureAndOverloads(GrapeCallExpression callExpression, GrapeMethod method, GrapeModifier.GrapeModifierType modifiers, ref string errorMessage)
        {
            errorMessage = "";
            List<GrapeMethod> methods = new List<GrapeMethod>();
            methods.AddRange(astUtils.GetMethodsWithNameFromImportedPackagesInFile(Config, method.Name, method.FileName, method.GetLogicalParentOfEntityType<GrapeClass>()));
            List<GrapeMethod> methodsWithSignature = typeCheckingUtils.GetMethodsWithSignature(Config, methods, modifiers, method.Name, method.ReturnType, new List<GrapeExpression>(callExpression.Parameters), ref errorMessage);
            if (errorMessage != "") {
                errorSink.AddError(new GrapeErrorSink.Error { Description = errorMessage, FileName = callExpression.FileName, Entity = callExpression });
                if (!Config.ContinueOnError) {
                    return false;
                }
            }

            if (methodsWithSignature.Count > 1) {
                errorMessage = "Multiple functions with signature '" + typeCheckingUtils.GetMethodSignatureString(Config, method.Name, method.ReturnType, new List<GrapeExpression>(callExpression.Parameters)) + "' found.";
                errorSink.AddError(new GrapeErrorSink.Error { Description = errorMessage, FileName = callExpression.FileName, Entity = callExpression });
                if (!Config.ContinueOnError) {
                    return false;
                }
            }

            return true;
        }
コード例 #3
0
        public bool IsSignatureValid(GrapeCodeGeneratorConfiguration config, GalaxyFunctionAttribute function, GrapeCallExpression callExpression, out string errorMessage)
        {
            errorMessage = "";
            string[] parameters = function.Params.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            if (parameters.Length != callExpression.Parameters.Count) {
                errorMessage = "Cannot find function with argument count '" + callExpression.Parameters.Count + "'.";
                return false;
            }

            int index = 0;
            foreach (string parameter in parameters) {
                string[] splitParam = parameter.Trim().Split(' ');
                if (splitParam.Length != 2) {
                    errorMessage = "The native interface function has malformed parameters.";
                    return false;
                }

                string type = GetCorrectNativeTypeName(splitParam[0]);
                string name = splitParam[1];
                GrapeExpression expression = callExpression.Parameters[index];
                if (!DoesExpressionResolveToType(config, expression, expression, type, ref errorMessage)) {
                    errorMessage = "Cannot resolve parameter expression to type '" + type + "'. " + errorMessage;
                    return false;
                }

                index++;
            }

            return true;
        }