public override void ValidateSemantics(SemanticsValidator validator) { foreach (var parameter in Parameters) { parameter.ValidateSemantics(validator); } this.StructClass = validator.Container.TryGetClass(CtorName); if (StructClass == null) { validator.AddError("Unknown struct type " + CtorName, ParsingContext); } if (StructClass.Type != ContainerType.@struct) { validator.AddError("Constructors can only be called on struct", ParsingContext); } this.StructClass = validator.Container[CtorName]; this.StructCtor = StructClass.GetCtor(); if (StructCtor == null) { validator.AddError("Unknown struct ctor \"" + StructClass.ClassName + "\"", ParsingContext); } else if (Parameters.Count != StructCtor.Parameters.Count) { validator.AddError("Invalid parameters count for Ctor \"" + StructClass.ClassName + "\"", ParsingContext); } }
public void ValidateTypes(SemanticsValidator validator) { this.Type = validator.Container.TypeManager.GetTypeInstance(RawType); if (this.Type == null) { validator.AddError("Unknown variable type " + RawType, Context); } }
public void ValidateSemantics(SemanticsValidator validator) { if (ParentClass.Type == ContainerType.@struct && IsMainPointEntry()) { validator.AddError("Main point entry cannot be member of struct \"" + ParentClass.ClassName + "\"", Context); } if (ParentClass.Type == ContainerType.primitive && Parameters.Count == 0) { validator.AddError("Primitive method " + Name + " should have self has parameter.", Context); } foreach (var param in Parameters) { validator.DeclareVariable(param); } foreach (var statement in this.Statements) { statement.ValidateSemantics(validator); } }
public override void ValidateSemantics(SemanticsValidator validator) { NativesEnum result = NativesEnum.Unknown; if (!Enum.TryParse(NativeName, out result) || result == NativesEnum.Unknown) { validator.AddError("Unknown native function : " + NativeName, ParsingContext); } NativeEnum = result; foreach (var parameter in Parameters) { parameter.ValidateSemantics(validator); } }
public override void ValidateSemantics(SemanticsValidator validator) { var tree = Expression.GetTree(); foreach (var expr in tree) { if (expr is not MethodCallExpression && expr is not NativeCallExpression && expr is not VariableNameExpression) { validator.AddError("Forbidenn expression statement (" + expr.GetType().Name + ")", base.ParsingContext); return; } } Expression.ValidateSemantics(validator); }
public void ValidateTypes(SemanticsValidator validator) { this.ReturnType = validator.Container.TypeManager.GetTypeInstance(RawReturnType); if (ReturnType == null) { validator.AddError("Unknown return type for method : " + Name, Context); } foreach (var parameter in Parameters) { parameter.ValidateTypes(validator); } foreach (var statement in Statements) { statement.ValidateTypes(validator); } }
public override void ValidateSemantics(SemanticsValidator validator) // methode accessible, nombre de parametres corrects. { foreach (var parameter in Parameters) { parameter.ValidateSemantics(validator); } AccessorTree = new AccessorTree(this, false); AccessorTree.ValidateSemantics(validator); Method target = AccessorTree.Last().GetTarget <Method>(); int requiredParameters = target.Parameters.Count; if (target.ParentClass.Type == ContainerType.primitive) { requiredParameters = requiredParameters - 1; } if (requiredParameters != Parameters.Count) { validator.AddError(Name + "() require " + requiredParameters + " parameters, but " + Parameters.Count + " was given", base.ParsingContext); } }
public void ValidateSemantics(SemanticsValidator validator) { int i = 0; Accessor previous = null; while (i < Tree.Count) { Accessor current = Tree[i]; if (previous == null) { if (current.Type == AccessorType.Field) { if (validator.IsLocalDeclared(current.Identifier)) { current.InferredSymbolType = SymbolType.Local; current.SetTarget(validator.GetLocal(current.Identifier)); } else if (Root.ParentClass.Fields.ContainsKey(current.Identifier)) { switch (Root.ParentClass.Type) { case ContainerType.primitive: case ContainerType.@class: current.InferredSymbolType = SymbolType.ClassMember; current.SetTarget(Root.ParentClass.Fields[current.Identifier]); break; case ContainerType.@struct: current.InferredSymbolType = SymbolType.StructMember; current.SetTarget(Root.ParentClass.Fields[current.Identifier]); break; default: throw new NotImplementedException("Unable to infer symbol category"); } } else if (validator.Container.ContainsClass(current.Identifier)) { var next = Tree[i + 1]; IAccessible target = null; if (next.Type == AccessorType.Field) { if (validator.Container[current.Identifier].Fields.ContainsKey(next.Identifier)) { target = validator.Container[current.Identifier].Fields[next.Identifier]; } else { validator.AddError("Unknown member : " + next.Identifier + " in class " + current.Identifier, next.Expression.ParsingContext); return; } } else if (next.Type == AccessorType.Method) { if (validator.Container[current.Identifier].Methods.ContainsKey(next.Identifier)) { target = validator.Container[current.Identifier].Methods[next.Identifier]; } else { validator.AddError("Unknown member : " + next.Identifier + "() in class " + current.Identifier, next.Expression.ParsingContext); return; } } next.InferredSymbolType = SymbolType.ExternalMember; next.SetTarget(target); Tree.Remove(current); current = next; } else { current.InferredSymbolType = SymbolType.Unknown; validator.AddError("Unknown reference to member : " + current.Identifier, Root.ParsingContext); } } else if (current.Type == AccessorType.Method) { if (Root.ParentClass.Methods.ContainsKey(current.Identifier)) { switch (Root.ParentClass.Type) { case ContainerType.primitive: case ContainerType.@class: current.InferredSymbolType = SymbolType.ClassMember; current.SetTarget(Root.ParentClass.Methods[current.Identifier]); break; case ContainerType.@struct: current.InferredSymbolType = SymbolType.StructMember; current.SetTarget(Root.ParentClass.Methods[current.Identifier]); break; default: throw new NotImplementedException("Unable to infer symbol category"); } } else { current.InferredSymbolType = SymbolType.Unknown; validator.AddError("Unknown reference to member : " + current.Identifier, Root.ParsingContext); } } else { throw new Exception("Unknown accessor type : " + current.Type); } } else { Class targetClass = previous.GetTargetClass(validator); if (targetClass == null) { validator.AddError("Types are not implemented", Root.ParsingContext); return; } if (current.Type == AccessorType.Field) { if (targetClass.Fields.ContainsKey(current.Identifier)) { if (targetClass.Type == ContainerType.@class || targetClass.Type == ContainerType.primitive) { current.InferredSymbolType = SymbolType.ClassMember; } else if (targetClass.Type == ContainerType.@struct) { current.InferredSymbolType = SymbolType.StructMember; } else { throw new NotImplementedException(); // todo : records } current.SetTarget(targetClass.Fields[current.Identifier]); } else { validator.AddError("Unknown reference to member : " + current.Identifier, Root.ParsingContext); } } else if (current.Type == AccessorType.Method) { if (targetClass.Methods.ContainsKey(current.Identifier)) { if (targetClass.Type == ContainerType.@class || targetClass.Type == ContainerType.primitive) { current.InferredSymbolType = SymbolType.ClassMember; } else if (targetClass.Type == ContainerType.@struct) { current.InferredSymbolType = SymbolType.StructMember; } current.SetTarget(targetClass.Methods[current.Identifier]); } else { validator.AddError("Unknown reference to member : " + current.Identifier, Root.ParsingContext); } } else { throw new Exception("Unknown accessor type : " + current.Type); } } previous = current; i++; } }