public bool ValidateSingleDecl(List <DeclReference> decls, Name origName, Diagnostics.Span span) { if (decls.Count == 0) { this.AddMessage( Diagnostics.MessageKind.Error, Diagnostics.MessageCode.Unknown, "unknown '" + origName.GetString() + "'", span); return(false); } else if (decls.Count > 1) { this.AddMessage( Diagnostics.MessageKind.Error, Diagnostics.MessageCode.AmbiguousDeclaration, "ambiguous '" + origName.GetString() + "' between " + "'" + this.GetDeclName(decls[0]).GetString() + "'" + (decls.Count == 2 ? " and " : ", ") + "'" + this.GetDeclName(decls[1]).GetString() + "'" + (decls.Count > 2 ? ", and other " + (decls.Count - 2) : ""), span); return(false); } else { return(true); } }
public int CreateSegment(Diagnostics.Span span) { this.segments.Add(new InstructionSegment { span = span }); return(this.segments.Count - 1); }
private bool ValidateName(Core.Name name, Diagnostics.Span span) { int duplicateIndex; if (this.session.TryGetDecl(name, out duplicateIndex)) { var duplicateSpan = this.structWorkData.Find(st => st.name.Compare(name))?.declNode.name.GetSpan() ?? this.functWorkData.Find(st => st.name.Compare(name))?.declNode.name.GetSpan() ?? new Diagnostics.Span(); this.session.AddMessage( Diagnostics.MessageKind.Error, Diagnostics.MessageCode.DuplicateDeclaration, "duplicate declaration of '" + name.GetString() + "'", span); this.session.AddInnerMessageToLast( Diagnostics.MessageKind.Info, Diagnostics.MessageCode.DuplicateDeclaration, "first declaration here", duplicateSpan); return(false); } return(true); }
public int CreateBinding(Core.Name name, int registerIndex, Diagnostics.Span span) { var binding = new LocalBinding(); binding.name = name; binding.registerIndex = registerIndex; binding.declSpan = span; this.localBindings.Add(binding); return(this.localBindings.Count - 1); }
public static InstructionMoveLiteralStruct Of( Diagnostics.Span span, DataAccess destination, int structIndex, DataAccess[] fieldSources, Diagnostics.Span[] fieldDestSpans) { return(new InstructionMoveLiteralStruct { span = span, destination = destination, structIndex = structIndex, fieldSources = fieldSources, fieldDestSpans = fieldDestSpans }); }
public bool ValidateAsFunct(DeclReference decl, Name origName, Diagnostics.Span span) { if (decl.kind != Core.Session.DeclReference.Kind.Funct) { this.AddMessage( Diagnostics.MessageKind.Error, Diagnostics.MessageCode.WrongDeclarationKind, "'" + this.GetDeclName(decl).GetString() + "' is not a funct", span); return(false); } return(true); }
public static InstructionMoveCallResult For( Diagnostics.Span span, DataAccess destination, DataAccess callTarget, DataAccess[] arguments) { return(new InstructionMoveCallResult { span = span, destination = destination, callTargetSource = callTarget, argumentSources = arguments }); }
private void PrintPosition(Diagnostics.Span span) { Console.ForegroundColor = ConsoleColor.White; if (span.unit != null) { Console.Write(span.unit.GetFullName() + ":"); Console.Write((span.unit.GetLineIndexAtSpanStart(span) + 1) + ":"); Console.Write((span.unit.GetColumnAtSpanStart(span) + 1) + ": "); } else { Console.Write("<unknown location>: "); } Console.ResetColor(); }
private void CheckMove(Core.DataAccess destination, Core.Type srcType, Diagnostics.Span srcSpan) { if (!TypeResolver.ValidateDataAccess(this.session, this.funct, destination)) { this.foundErrors = true; return; } var destType = TypeResolver.GetDataAccessType(this.session, this.funct, destination); if (destType == null) { return; } if (!srcType.IsConvertibleTo(destType) && ShouldDiagnose(srcType) && ShouldDiagnose(destType)) { this.foundErrors = true; var destReg = destination as Core.DataAccessRegister; if (destReg != null && destReg.registerIndex == 0) { this.session.AddMessage( Diagnostics.MessageKind.Error, Diagnostics.MessageCode.IncompatibleTypes, "returning '" + srcType.GetString(this.session) + "' " + "but expecting '" + destType.GetString(this.session) + "'", srcSpan, destination.span); } else { this.session.AddMessage( Diagnostics.MessageKind.Error, Diagnostics.MessageCode.IncompatibleTypes, "moving '" + srcType.GetString(this.session) + "' " + "into '" + destType.GetString(this.session) + "'", srcSpan, destination.span); } } }
public static InstructionMoveLiteralTuple Empty(Diagnostics.Span span, DataAccess destination) { return(new InstructionMoveLiteralTuple { span = span, destination = destination }); }
private void ResolveExprLiteralStruct(Grammar.ASTNodeExprLiteralStruct exprLiteralStruct, ref int curSegment, Core.DataAccess output) { var type = TypeResolver.ResolveStruct(session, exprLiteralStruct.name, useDirectives, true); if (!type.IsResolved()) { return; } var typeStruct = type as Core.TypeStruct; var fieldNum = TypeResolver.GetFieldNum(this.session, typeStruct); var fieldDestSpans = new Diagnostics.Span?[fieldNum]; var fieldRegs = new int[fieldNum]; for (var i = 0; i < fieldNum; i++) { fieldRegs[i] = funct.CreateRegister( TypeResolver.GetFieldType(this.session, typeStruct, i), false); } var fieldRegAccesses = new Core.DataAccess[fieldNum]; for (var i = 0; i < fieldNum; i++) { fieldRegAccesses[i] = Core.DataAccessRegister.ForRegister(exprLiteralStruct.name.GetSpan(), fieldRegs[i]); } foreach (var fieldInit in exprLiteralStruct.fields) { var name = NameResolver.Resolve(fieldInit.name); int fieldIndex; if (!this.session.GetStruct(typeStruct.structIndex).fieldNames.FindByName(name, out fieldIndex)) { this.foundErrors = true; session.AddMessage( Diagnostics.MessageKind.Error, Diagnostics.MessageCode.Unknown, "unknown field '" + name.GetString() + "' in '" + type.GetString(this.session) + "'", fieldInit.name.GetSpan()); continue; } if (fieldDestSpans[fieldIndex].HasValue) { this.foundErrors = true; session.AddMessage( Diagnostics.MessageKind.Error, Diagnostics.MessageCode.Unknown, "duplicate field '" + name.GetString() + "' initialization", fieldInit.name.GetSpan(), fieldDestSpans[fieldIndex].Value); continue; } fieldRegAccesses[fieldIndex].span = fieldInit.name.GetSpan(); fieldDestSpans[fieldIndex] = fieldInit.name.GetSpan(); this.ResolveExpr(fieldInit.expr, ref curSegment, fieldRegAccesses[fieldIndex]); } var missingFields = new List <int>(); for (var i = 0; i < fieldNum; i++) { if (!fieldDestSpans[i].HasValue) { missingFields.Add(i); } } if (missingFields.Count > 0) { Core.Name fieldName; session.GetStruct(typeStruct.structIndex).fieldNames.FindByValue(missingFields[0], out fieldName); this.foundErrors = true; session.AddMessage( Diagnostics.MessageKind.Error, Diagnostics.MessageCode.Unknown, "missing initializer" + (missingFields.Count > 1 ? "s" : "") + " for field '" + fieldName.GetString() + "'" + (missingFields.Count > 1 ? " and other " + (missingFields.Count - 1) : ""), exprLiteralStruct.GetSpan()); } else { var finalFieldDestSpans = new Diagnostics.Span[fieldNum]; for (var i = 0; i < fieldNum; i++) { finalFieldDestSpans[i] = fieldDestSpans[i].Value; } funct.AddInstruction(curSegment, Core.InstructionMoveLiteralStruct.Of( exprLiteralStruct.GetSpan(), output, typeStruct.structIndex, fieldRegAccesses, finalFieldDestSpans)); } }
public void SetSpan(Diagnostics.Span span) { this.span = span; }
public void PushContext(string text, Diagnostics.Span span) { this.contextStack.Push(new Diagnostics.MessageContext(text, span)); }
public void AddSpan(Diagnostics.Span span) { this.span = this.span.Merge(span); }
private void ResolveExprLiteralStruct(Grammar.ASTNodeExprLiteralStruct exprLiteralStruct, ref int curSegment, Core.DataAccess output) { var type = TypeResolver.ResolveStruct(session, exprLiteralStruct.name, useDirectives, true); if (!type.IsResolved()) return; var typeStruct = type as Core.TypeStruct; var fieldNum = TypeResolver.GetFieldNum(this.session, typeStruct); var fieldDestSpans = new Diagnostics.Span?[fieldNum]; var fieldRegs = new int[fieldNum]; for (var i = 0; i < fieldNum; i++) { fieldRegs[i] = funct.CreateRegister( TypeResolver.GetFieldType(this.session, typeStruct, i), false); } var fieldRegAccesses = new Core.DataAccess[fieldNum]; for (var i = 0; i < fieldNum; i++) { fieldRegAccesses[i] = Core.DataAccessRegister.ForRegister(exprLiteralStruct.name.GetSpan(), fieldRegs[i]); } foreach (var fieldInit in exprLiteralStruct.fields) { var name = NameResolver.Resolve(fieldInit.name); int fieldIndex; if (!this.session.GetStruct(typeStruct.structIndex).fieldNames.FindByName(name, out fieldIndex)) { this.foundErrors = true; session.AddMessage( Diagnostics.MessageKind.Error, Diagnostics.MessageCode.Unknown, "unknown field '" + name.GetString() + "' in '" + type.GetString(this.session) + "'", fieldInit.name.GetSpan()); continue; } if (fieldDestSpans[fieldIndex].HasValue) { this.foundErrors = true; session.AddMessage( Diagnostics.MessageKind.Error, Diagnostics.MessageCode.Unknown, "duplicate field '" + name.GetString() + "' initialization", fieldInit.name.GetSpan(), fieldDestSpans[fieldIndex].Value); continue; } fieldRegAccesses[fieldIndex].span = fieldInit.name.GetSpan(); fieldDestSpans[fieldIndex] = fieldInit.name.GetSpan(); this.ResolveExpr(fieldInit.expr, ref curSegment, fieldRegAccesses[fieldIndex]); } var missingFields = new List<int>(); for (var i = 0; i < fieldNum; i++) { if (!fieldDestSpans[i].HasValue) missingFields.Add(i); } if (missingFields.Count > 0) { Core.Name fieldName; session.GetStruct(typeStruct.structIndex).fieldNames.FindByValue(missingFields[0], out fieldName); this.foundErrors = true; session.AddMessage( Diagnostics.MessageKind.Error, Diagnostics.MessageCode.Unknown, "missing initializer" + (missingFields.Count > 1 ? "s" : "") + " for field '" + fieldName.GetString() + "'" + (missingFields.Count > 1 ? " and other " + (missingFields.Count - 1) : ""), exprLiteralStruct.GetSpan()); } else { var finalFieldDestSpans = new Diagnostics.Span[fieldNum]; for (var i = 0; i < fieldNum; i++) { finalFieldDestSpans[i] = fieldDestSpans[i].Value; } funct.AddInstruction(curSegment, Core.InstructionMoveLiteralStruct.Of( exprLiteralStruct.GetSpan(), output, typeStruct.structIndex, fieldRegAccesses, finalFieldDestSpans)); } }
public static InstructionMoveData Of(Diagnostics.Span span, DataAccess destination, DataAccess source) { return(new InstructionMoveData { span = span, destination = destination, source = source }); }
public static DataAccessField Of(Diagnostics.Span span, DataAccess baseAccess, int fieldIndex) { return(new DataAccessField { span = span, baseAccess = baseAccess, fieldIndex = fieldIndex }); }
public static DataAccessDereference Of(Diagnostics.Span span, DataAccess innerAccess) { return(new DataAccessDereference { span = span, innerAccess = innerAccess }); }
public static DataAccessRegister ForRegister(Diagnostics.Span span, int registerIndex) { return(new DataAccessRegister { span = span, registerIndex = registerIndex }); }
public static InstructionMoveLiteralBool Of(Diagnostics.Span span, DataAccess destination, bool value) { return(new InstructionMoveLiteralBool { span = span, destination = destination, value = value }); }
public int GetColumnAtSpanStart(Diagnostics.Span span) { return(this.GetColumnAtPos(span.start)); }
public int GetColumnAtSpanEnd(Diagnostics.Span span) { return(this.GetColumnAtPos(span.end)); }
public static InstructionMoveLiteralFunct With(Diagnostics.Span span, DataAccess destination, int functIndex) { return(new InstructionMoveLiteralFunct { span = span, destination = destination, functIndex = functIndex }); }
public int GetLineIndexAtSpanEnd(Diagnostics.Span span) { return(this.GetLineAtPos(span.end)); }
public MessageContext(string text, Diagnostics.Span span) { this.text = text; this.span = span; }
public Token(TokenKind kind, Diagnostics.Span span) { this.kind = kind; this.span = span; }
public static InstructionMoveLiteralInt Of(Diagnostics.Span span, DataAccess destination, Core.Type type, long value) { return(new InstructionMoveLiteralInt { span = span, destination = destination, type = type, value = value }); }
public void SetSpan(Diagnostics.Span span) { this.span = span; }
public void AddSpan(Diagnostics.Span span) { this.span = this.span.Merge(span); }
public static InstructionMoveAddr Of(Diagnostics.Span span, DataAccess destination, DataAccess source, bool mutable) { return(new InstructionMoveAddr { span = span, destination = destination, source = source, mutable = mutable }); }
public Token(TokenKind kind, Diagnostics.Span span) { this.kind = kind; this.span = span; }
public MessageContext(string text, Diagnostics.Span span) { this.text = text; this.span = span; }
public int GetLineIndexAtSpanStart(Diagnostics.Span span) { return(this.GetLineAtPos(span.start)); }