Exemplo n.º 1
0
 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);
     }
 }
Exemplo n.º 2
0
 public int CreateSegment(Diagnostics.Span span)
 {
     this.segments.Add(new InstructionSegment {
         span = span
     });
     return(this.segments.Count - 1);
 }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
 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
     });
 }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
 public static InstructionMoveCallResult For(
     Diagnostics.Span span,
     DataAccess destination,
     DataAccess callTarget,
     DataAccess[] arguments)
 {
     return(new InstructionMoveCallResult
     {
         span = span,
         destination = destination,
         callTargetSource = callTarget,
         argumentSources = arguments
     });
 }
Exemplo n.º 8
0
        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();
        }
Exemplo n.º 9
0
        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);
                }
            }
        }
Exemplo n.º 10
0
 public static InstructionMoveLiteralTuple Empty(Diagnostics.Span span, DataAccess destination)
 {
     return(new InstructionMoveLiteralTuple {
         span = span, destination = destination
     });
 }
Exemplo n.º 11
0
        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));
            }
        }
Exemplo n.º 12
0
 public void SetSpan(Diagnostics.Span span)
 {
     this.span = span;
 }
Exemplo n.º 13
0
 public void PushContext(string text, Diagnostics.Span span)
 {
     this.contextStack.Push(new Diagnostics.MessageContext(text, span));
 }
Exemplo n.º 14
0
 public void AddSpan(Diagnostics.Span span)
 {
     this.span = this.span.Merge(span);
 }
Exemplo n.º 15
0
        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));
            }
        }
Exemplo n.º 16
0
 public static InstructionMoveData Of(Diagnostics.Span span, DataAccess destination, DataAccess source)
 {
     return(new InstructionMoveData {
         span = span, destination = destination, source = source
     });
 }
Exemplo n.º 17
0
 public static DataAccessField Of(Diagnostics.Span span, DataAccess baseAccess, int fieldIndex)
 {
     return(new DataAccessField {
         span = span, baseAccess = baseAccess, fieldIndex = fieldIndex
     });
 }
Exemplo n.º 18
0
 public static DataAccessDereference Of(Diagnostics.Span span, DataAccess innerAccess)
 {
     return(new DataAccessDereference {
         span = span, innerAccess = innerAccess
     });
 }
Exemplo n.º 19
0
 public static DataAccessRegister ForRegister(Diagnostics.Span span, int registerIndex)
 {
     return(new DataAccessRegister {
         span = span, registerIndex = registerIndex
     });
 }
Exemplo n.º 20
0
 public static InstructionMoveLiteralBool Of(Diagnostics.Span span, DataAccess destination, bool value)
 {
     return(new InstructionMoveLiteralBool {
         span = span, destination = destination, value = value
     });
 }
Exemplo n.º 21
0
 public int GetColumnAtSpanStart(Diagnostics.Span span)
 {
     return(this.GetColumnAtPos(span.start));
 }
Exemplo n.º 22
0
 public int GetColumnAtSpanEnd(Diagnostics.Span span)
 {
     return(this.GetColumnAtPos(span.end));
 }
Exemplo n.º 23
0
 public static InstructionMoveLiteralFunct With(Diagnostics.Span span, DataAccess destination, int functIndex)
 {
     return(new InstructionMoveLiteralFunct {
         span = span, destination = destination, functIndex = functIndex
     });
 }
Exemplo n.º 24
0
 public int GetLineIndexAtSpanEnd(Diagnostics.Span span)
 {
     return(this.GetLineAtPos(span.end));
 }
Exemplo n.º 25
0
 public MessageContext(string text, Diagnostics.Span span)
 {
     this.text = text;
     this.span = span;
 }
Exemplo n.º 26
0
 public Token(TokenKind kind, Diagnostics.Span span)
 {
     this.kind = kind;
     this.span = span;
 }
Exemplo n.º 27
0
 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
     });
 }
Exemplo n.º 28
0
 public void SetSpan(Diagnostics.Span span)
 {
     this.span = span;
 }
Exemplo n.º 29
0
 public void AddSpan(Diagnostics.Span span)
 {
     this.span = this.span.Merge(span);
 }
Exemplo n.º 30
0
 public static InstructionMoveAddr Of(Diagnostics.Span span, DataAccess destination, DataAccess source, bool mutable)
 {
     return(new InstructionMoveAddr {
         span = span, destination = destination, source = source, mutable = mutable
     });
 }
Exemplo n.º 31
0
 public Token(TokenKind kind, Diagnostics.Span span)
 {
     this.kind = kind;
     this.span = span;
 }
Exemplo n.º 32
0
 public MessageContext(string text, Diagnostics.Span span)
 {
     this.text = text;
     this.span = span;
 }
Exemplo n.º 33
0
 public int GetLineIndexAtSpanStart(Diagnostics.Span span)
 {
     return(this.GetLineAtPos(span.start));
 }