Esempio n. 1
0
 public GrapeMethod(GrapeList<GrapeModifier> modifiers, GrapeType returnType, GrapeIdentifier name, GrapeList<GrapeParameter> parameters, GrapeList<GrapeStatement> body)
     : base(modifiers)
 {
     this.returnType = returnType;
     this.name = name.Name;
     this.parameters = parameters.ToList(this).AsReadOnly();
     this.body = body.ToList(this).AsReadOnly();
 }
Esempio n. 2
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;
		}
Esempio n. 3
0
 public GrapeClass(GrapeList<GrapeModifier> modifiers, GrapeIdentifier identifier, GrapeOptional<GrapeLiteralExpression<int>> size, GrapeOptional<GrapeSimpleType> inherits, GrapeList<GrapeClassItem> classItems)
     : base(modifiers)
 {
     GrapeLiteralExpression<int> sizeLiteral = size;
     this.size = (sizeLiteral == null) ? default(int?) : sizeLiteral.Value;
     this.inherits = inherits;
     this.classItems = classItems.ToList(this).AsReadOnly();
     name = identifier.Name;
 }
Esempio n. 4
0
		public GrapeFinallyClause(GrapeList<GrapeStatement> statements): base(statements) {}
		public GrapeConditionalStatement(GrapeExpression condition, GrapeList<GrapeStatement> statements, GrapeConditionalStatement elseStatement): base(statements) {
			this.condition = condition;
			this.elseStatement = (elseStatement != null) && (elseStatement.Statements.Count > 0) ? elseStatement : null;
		}
		public GrapeConditionalStatement(GrapeList<GrapeStatement> statements): this(null, statements, null) {}
 public GrapeArrayInitializer(GrapeList<GrapeInitializer> initializers)
 {
     this.initializers = initializers.ToList(this).AsReadOnly();
 }
Esempio n. 8
0
		protected GrapeClassItem(GrapeList<GrapeModifier> modifiers) {
			this.modifiers = modifiers.Merge(GrapeModifier.GrapeModifierType.Public);
		}
Esempio n. 9
0
        public GrapeMethodCall(GrapeMember ofMember, GrapeList<GrapeExpression> parameters) : base(ofMember, new GrapeList<GrapeIdentifier>(ofMember.PopIdentifier())) {
			this.parameters = parameters;
		}
Esempio n. 10
0
		public GrapeConstructor(GrapeList<GrapeModifier> modifiers, GrapeIdentifier name, GrapeList<GrapeParameter> parameters, GrapeList<GrapeStatement> body): base(modifiers, name, parameters, body) {}
Esempio n. 11
0
 public GrapeMember(GrapeMember ofMember, GrapeList<GrapeIdentifier> identifiers)
 {
     this.ofMember = ofMember;
     this.identifiers = identifiers.ToList(this);
 }
Esempio n. 12
0
		public GrapeCatchClause(GrapeSimpleType exceptionType, GrapeIdentifier variableIdentifier, GrapeList<GrapeStatement> statements): base(statements) {
			this.exceptionType = exceptionType;
			exceptionVariable = GrapeVariable.Create(exceptionType, variableIdentifier);
		}
Esempio n. 13
0
		public GrapeArrayType(GrapeList<GrapeIdentifier> nameParts): this(new GrapeSimpleType(nameParts)) {}
Esempio n. 14
0
		public GrapeCatchClause(GrapeSimpleType exceptionType, GrapeList<GrapeStatement> statements): this(exceptionType, null, statements) {}
Esempio n. 15
0
		public GrapeCatchClause(GrapeList<GrapeStatement> statements): this(null, null, statements) {}
		protected GrapeStatementWithBlock(GrapeList<GrapeStatement> statements) {
			this.statements = statements.ToList(this).AsReadOnly();
		}
Esempio n. 17
0
 public GrapeMethod(GrapeList<GrapeModifier> modifiers, GrapeIdentifier name, GrapeList<GrapeParameter> parameters, GrapeList<GrapeStatement> body)
     : this(modifiers, null, name, parameters, body)
 {
 }
Esempio n. 18
0
 public GrapeMember(GrapeObject grapeObject, GrapeList<GrapeIdentifier> identifiers)
     : this((GrapeMember)null, new GrapeList<GrapeIdentifier>(grapeObject, identifiers))
 {
 }
Esempio n. 19
0
 public GrapeSimpleType(GrapeList<GrapeIdentifier> nameParts) {
     packageName = nameParts.GetPackageName();
     typeName = nameParts.GetSimpleName();
 }
Esempio n. 20
0
		public GrapeDestructor(GrapeList<GrapeModifier> modifiers, GrapeIdentifier name, GrapeList<GrapeStatement> body): base(modifiers, name, null, body) {}
Esempio n. 21
0
 public GrapeMember(GrapeList<GrapeIdentifier> identifiers)
     : this((GrapeMember)null, identifiers)
 {
 }
Esempio n. 22
0
		private GrapeCallExpression(GrapeIdentifier identifier, GrapeList<GrapeExpression> parameters, GrapeAccessExpression next): base(GrapeAccessExpressionType.Method, identifier, next) {
			this.parameters = parameters.ToList(this).AsReadOnly();
		}
		public GrapeImportDeclaration(GrapeList<GrapeIdentifier> packageNameParts) {
			packageName = packageNameParts.GetFullName();
		}
Esempio n. 24
0
		public GrapeField(GrapeList<GrapeModifier> modifiers, GrapeVariable field): base(modifiers) {
			this.field = field;
		}
Esempio n. 25
0
		public GrapeSwitchStatement(GrapeExpression expression, GrapeList<GrapeSwitchCase> cases): base() {
			this.expression = expression;
			this.cases = cases.ToList(this).AsReadOnly();
		}
        public bool ValidateNode(object obj)
        {
            if (Config.OutputErrors) {
                GrapeInitStatement s = obj as GrapeInitStatement;
                if (s != null) {
                    if (s.Type == GrapeInitStatement.GrapeInitStatementType.Base) {
                        GrapeClass c = s.GetLogicalParentOfEntityType<GrapeClass>();
                        if (c.Inherits == null) {
                            errorSink.AddError(new GrapeErrorSink.Error { Description = "Cannot access base constructor when the current class has no base class.", FileName = s.FileName, Entity = s });
                            if (!Config.ContinueOnError) {
                                return false;
                            }
                        }

                        GrapeEntity inheritingEntity = astUtils.GetClassWithNameFromImportedPackagesInFile(Config.Ast, typeCheckingUtils.GetTypeNameForTypeAccessExpression(Config, c.Inherits), c.FileName);
                        if (inheritingEntity != null && inheritingEntity is GrapeClass) {
                            string errorMessage = "";
                            GrapeClass inheritingClass = inheritingEntity as GrapeClass;
                            GrapeMethod method = null;
                            foreach (GrapeEntity entity in inheritingClass.GetChildren()) {
                                if (entity != null && entity is GrapeMethod && ((GrapeMethod)entity).Name == inheritingClass.Name && ((GrapeMethod)entity).Type == GrapeMethod.GrapeMethodType.Constructor) {
                                    method = entity as GrapeMethod;
                                    break;
                                }
                            }

                            if (method == null) {
                                GrapeList<GrapeModifier> methodModifiers = new GrapeList<GrapeModifier>(new GrapePublicModifier());
                                GrapeList<GrapeIdentifier> nameParts = new GrapeList<GrapeIdentifier>(new GrapeIdentifier(inheritingClass.Name));
                                method = new GrapeMethod(methodModifiers, new GrapeSimpleType(nameParts), new GrapeIdentifier(inheritingClass.Name), new GrapeList<GrapeParameter>(), new GrapeList<GrapeStatement>());
                                method.Parent = inheritingClass;
                            }

                            GrapeModifier.GrapeModifierType modifiers = c.GetAppropriateModifiersForEntityAccess(Config, method);
                            bool valid = accessExpressionValidator.ValidateMethodSignatureAndOverloads(GrapeCallExpression.Create(new GrapeIdentifier(inheritingClass.Name), GrapeList<GrapeExpression>.FromEnumerable(s.Parameters), null), method, modifiers, ref errorMessage);
                            if (!valid) {
                                errorSink.AddError(new GrapeErrorSink.Error { Description = errorMessage, FileName = s.FileName, Entity = s });
                                if (!Config.ContinueOnError) {
                                    return false;
                                }
                            }
                        } else {
                            errorSink.AddError(new GrapeErrorSink.Error { Description = "Cannot find base class '" + typeCheckingUtils.GetTypeNameForTypeAccessExpression(Config, c.Inherits) + "'.", FileName = s.FileName, Entity = s });
                            if (!Config.ContinueOnError) {
                                return false;
                            }
                        }
                    } else if (s.Type == GrapeInitStatement.GrapeInitStatementType.This) {
                        GrapeClass c = s.GetLogicalParentOfEntityType<GrapeClass>();
                        GrapeMethod method = null;
                        foreach (GrapeEntity entity in c.GetChildren()) {
                            if (entity != null && entity is GrapeMethod && ((GrapeMethod)entity).Name == c.Name && ((GrapeMethod)entity).Type == GrapeMethod.GrapeMethodType.Constructor) {
                                method = entity as GrapeMethod;
                                break;
                            }
                        }

                        if (method == null) {
                            GrapeList<GrapeModifier> methodModifiers = new GrapeList<GrapeModifier>(new GrapePublicModifier());
                            GrapeList<GrapeIdentifier> nameParts = new GrapeList<GrapeIdentifier>(new GrapeIdentifier(c.Name));
                            method = new GrapeMethod(methodModifiers, new GrapeSimpleType(nameParts), new GrapeIdentifier(c.Name), new GrapeList<GrapeParameter>(), new GrapeList<GrapeStatement>());
                            method.Parent = c;
                        }

                        string errorMessage = "";
                        GrapeModifier.GrapeModifierType modifiers = c.GetAppropriateModifiersForEntityAccess(Config, method);
                        bool valid = accessExpressionValidator.ValidateMethodSignatureAndOverloads(GrapeCallExpression.Create(new GrapeIdentifier(c.Name), GrapeList<GrapeExpression>.FromEnumerable(s.Parameters), null), method, modifiers, ref errorMessage);
                        if (!valid) {
                            errorSink.AddError(new GrapeErrorSink.Error { Description = errorMessage, FileName = s.FileName, Entity = s });
                            if (!Config.ContinueOnError) {
                                return false;
                            }
                        }
                    } else {
                        errorSink.AddError(new GrapeErrorSink.Error { Description = "Cannot find initialization type.", FileName = s.FileName, Entity = s });
                        if (!Config.ContinueOnError) {
                            return false;
                        }
                    }
                }
            }

            return true;
        }
Esempio n. 27
0
		public GrapeWhileStatement(GrapeExpression condition, GrapeList<GrapeStatement> statements): base(statements) {
			this.condition = condition;
		}
Esempio n. 28
0
		public GrapeForEachStatement(GrapeVariable iteratorVariable, GrapeExpression valueExpression, GrapeList<GrapeStatement> statements): base(statements) {
			this.iteratorVariable = iteratorVariable;
			this.valueExpression = valueExpression;
		}