Ejemplo n.º 1
0
        /// <summary>
        /// Finds the amount to increment tempVarOffset for a non variable segment of the expression.
        /// Ex. The number 5 would result in adding 2 to tempVarOffset due to being an integer value.
        /// </summary>
        public int GetDirectValue(ITableEntry entry)
        {
            int number = 0;

            if (float.TryParse(entry.bpOffsetName, out float valueR) && entry.bpOffsetName.Contains("."))
            {
                tempVarOffset += 4;
                number         = 4;
            }
            else if (int.TryParse(entry.bpOffsetName, out int value))
            {
                tempVarOffset += 2;
                number         = 2;
            }
            else if (entry.bpOffsetName == "true" || entry.bpOffsetName == "false")
            {
                tempVarOffset += 1;
                number         = 1;
            }
            else
            {
                ErrorHandler.LogError($"Invalid value provided in expression.");
            }

            return(number);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// WriteToken -> IdT | NumT | QuoteT
        /// </summary>
        private void WriteToken()
        {
            if (Token == Tokens.IdT)
            {
                ITableEntry entry = symbolTable.Lookup(Lexeme);

                if (entry != null && entry.typeOfEntry == EntryType.varEntry)
                {
                    tacGenerator.GenerateLineOfTAC($"wri {entry.bpOffsetName}");
                }
                else if (entry != null)
                {
                    ErrorHandler.LogError($"only set up to handle integer variables");
                }
                else
                {
                    ErrorHandler.LogError($"\"{Lexeme}\" is undeclared");
                }

                Match(Tokens.IdT);
            }
            else if (Token == Tokens.NumT)
            {
                tacGenerator.GenerateLineOfTAC($"wri {Lexeme}");
                Match(Tokens.NumT);
            }
            else if (Token == Tokens.LiteralT)
            {
                tacGenerator.GenerateLineOfTAC($"wrs S{AssemblyFile.literalNum}");
                AssemblyFile.AddLiteral(Lexeme);
                Match(Tokens.LiteralT);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Converts the entry to a constant.
        /// </summary>
        public void ConvertEntryToConstant(ITableEntry entry)
        {
            Constant constEntry = entry as TableEntry;
            dynamic  value;

            constEntry.typeOfEntry  = EntryType.constEntry;
            constEntry.constType    = TypeConst;
            constEntry.offset       = Offset;
            constEntry.bpOffsetName = BpOffsetName;

            GetConstantValue();

            if (TypeConst == VarType.floatType)
            {
                value            = ValueR;
                constEntry.value = value;
            }
            else
            {
                value            = Value;
                constEntry.value = value;
            }

            Upsert(constEntry);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Calculates the hash code of the <see cref="ITableEntry"/> as if it was already mapped to a diagnostic info instance.
        /// </summary>
        /// <param name="entry">The <see cref="ITableEntry"/>.</param>
        /// <returns>The calculated hash code.</returns>
        public static int DiagnosticInfoHashCode(this ITableEntry entry)
        {
            if (!entry.TryGetValue(StandardTableKeyNames.ErrorSeverity, out __VSERRORCATEGORY errorCategory))
            {
                errorCategory = __VSERRORCATEGORY.EC_MESSAGE;
            }

            entry.TryGetValue(StandardTableKeyNames.DocumentName, out string path);
            entry.TryGetValue(StandardTableKeyNames.Text, out string text);
            entry.TryGetValue(StandardTableKeyNames.FullText, out string fullText);
            entry.TryGetValue(StandardTableKeyNames.ErrorCode, out string errorCode);
            entry.TryGetValue(StandardTableKeyNames.HelpLink, out string helpLink);
            entry.TryGetValue(StandardTableKeyNames.Line, out int line);
            entry.TryGetValue(StandardTableKeyNames.Column, out int column);
            entry.TryGetValue(StandardTableKeyNames.SuppressionState, out SuppressionState suppressionState);

            var isActive = SuppressionStateToIsActive(suppressionState);

            if (string.IsNullOrWhiteSpace(fullText))
            {
                fullText = text;
            }

            return(DiagnosticInfo.GetHashCode(path, line, (int)MapErrorCategoryToSeverity(errorCategory), column, errorCode, fullText, isActive));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates a <see cref="DiagnosticInfo"/> from a <see cref="ITableEntriesHandle"/>.
        /// </summary>
        /// <param name="entry">The <see cref="ITableEntryHandle"/>.</param>
        /// <returns>The created <see cref="DiagnosticInfo"/>.</returns>
        public static DiagnosticInfo ToDiagnosticInfo(this ITableEntry entry)
        {
            if (!entry.TryGetValue(StandardTableKeyNames.ErrorSeverity, out __VSERRORCATEGORY errorCategory))
            {
                errorCategory = __VSERRORCATEGORY.EC_MESSAGE;
            }

            entry.TryGetValue(StandardTableKeyNames.DocumentName, out string path);
            entry.TryGetValue(StandardTableKeyNames.Text, out string text);
            entry.TryGetValue(StandardTableKeyNames.FullText, out string fullText);
            entry.TryGetValue(StandardTableKeyNames.ErrorCode, out string errorCode);
            entry.TryGetValue(StandardTableKeyNames.HelpLink, out string helpLink);
            entry.TryGetValue(StandardTableKeyNames.Line, out int line);
            entry.TryGetValue(StandardTableKeyNames.Column, out int column);
            entry.TryGetValue(StandardTableKeyNames.SuppressionState, out SuppressionState suppressionState);

            if (string.IsNullOrWhiteSpace(fullText))
            {
                fullText = text;
            }

            return(new DiagnosticInfo
            {
                Severity = MapErrorCategoryToSeverity(errorCategory),
                Path = path,
                Message = fullText,
                ErrorCode = errorCode,
                HelpUriRaw = helpLink,
                LineNumber = line,
                Column = column,
                IsActive = SuppressionStateToIsActive(suppressionState)
            });
        }
Ejemplo n.º 6
0
        /// <summary>
        /// AssignStat -> IdT = Expr | IdT = MethodCall | MethodCall
        /// </summary>
        private void AssignStat()
        {
            ITableEntry firstIdEntry = symbolTable.Lookup(Lexeme);
            ITableEntry Eplace       = null;
            string      code         = "";

            if (firstIdEntry != null && (firstIdEntry.typeOfEntry == EntryType.classEntry || firstIdEntry.typeOfEntry == EntryType.tableEntry))
            {
                MethodCall(firstIdEntry as Class);
            }
            else if (firstIdEntry != null && firstIdEntry.typeOfEntry == EntryType.varEntry)
            {
                Match(Tokens.IdT);
                Match(Tokens.AssignOpT);

                ITableEntry secondIdEntry = symbolTable.Lookup(Lexeme);

                if (secondIdEntry != null && (secondIdEntry.typeOfEntry == EntryType.classEntry || secondIdEntry.typeOfEntry == EntryType.tableEntry))
                {
                    MethodCall(secondIdEntry as Class);
                    tacGenerator.GenerateLineOfTAC($"{firstIdEntry.bpOffsetName} = _ax");
                }
                else
                {
                    Expr(ref Eplace);
                    tacGenerator.GenerateFinalExpressionTAC(firstIdEntry, Eplace, ref code);
                }
            }
            else
            {
                ErrorHandler.LogError($"\"{Lexeme}\" is undeclared");
            }
        }
        public bool AddEntry(ITableEntry entry)
        {
            ICountedTableEntry countedEntry = entry as ICountedTableEntry;

            if (countedEntry != null && this.countedEntries.TryGetValue(countedEntry, out ICountedTableEntry existingCountedEntry))
            {
                existingCountedEntry.AddCount();

                int i = this.entries.IndexOf(entry);
                Debug.Assert(i != -1, $"{nameof(this.countedEntries)} has extra entries in it.");

                if (i != -1)
                {
                    // Tell the table that this entry has been updated
                    this.entries[i] = existingCountedEntry;
                }

                return(false);
            }
            else
            {
                if (countedEntry != null)
                {
                    this.countedEntries.Add(countedEntry);
                }

                this.entries.Add(entry);

                return(true);
            }
        }
Ejemplo n.º 8
0
 // Методы, выполняющиеся в событиях.
 protected void OnDialogDisplayRequest(ITableEntry record)
 {
     DialogDisplayRequested?.Invoke(
         this,
         new DialogDisplayEventArgs {
         Record = record
     });
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Generates the code that moves the variable to a temp variable.
        /// Generates the _bp-6 = 5 line shown below.
        /// Ex. a = 5 **a is represented by _bp-2, _bp-6 is the temp var**
        ///     _bp-6 = 5
        ///     _bp-2 = _bp-6
        /// </summary>
        public void GenerateTempExpressionTAC(ref ITableEntry Tplace)
        {
            string tempVarName = "";

            NewTempVar(ref tempVarName, Tplace);
            GenerateLineOfTAC($"{tempVarName} = {Tplace.bpOffsetName}");
            Tplace.bpOffsetName = tempVarName;
        }
Ejemplo n.º 10
0
        private static T GetValueOrDefault <T>(this ITableEntry tableEntry, string keyName, T defaultValue)
        {
            if (!tableEntry.TryGetValue(keyName, out T value))
            {
                value = defaultValue;
            }

            return(value);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Checks symbol table to verify that the given identifier is not a duplicate.
        /// </summary>
        public void CheckForDuplicates()
        {
            ITableEntry entry = Lookup(Lexeme);

            if (entry != null && entry.depth == Depth)
            {
                ErrorHandler.LogError($"duplicate identifier \"{Lexeme}\" found");
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Expr -> Relation | ε
        /// </summary>
        private void Expr(ref ITableEntry Eplace)
        {
            ITableEntry Tplace = null;

            if (FactorTokens.Contains(Token))
            {
                Relation(ref Tplace);
                Eplace = Tplace;
            }
        }
Ejemplo n.º 13
0
        private static T?GetValueOrNull <T>(this ITableEntry tableEntry, string keyName)
            where T : struct
        {
            if (!tableEntry.TryGetValue(keyName, out T value))
            {
                return(null);
            }

            return(value);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Converts the entry to a class.
        /// </summary>
        public void ConvertEntryToClass(ITableEntry entry)
        {
            Class classEntry = entry as TableEntry;

            classEntry.typeOfEntry     = EntryType.classEntry;
            classEntry.sizeOfLocalVars = LocalVarsSize;
            classEntry.varNames        = VarNames;
            classEntry.methodNames     = MethodNames;

            Upsert(classEntry);
        }
Ejemplo n.º 15
0
        /*************************************************************
        ** Function    : insert                                     **
        ** Inputs      : lex, token, and depth                      **
        ** Return      : void                                       **
        **************************************************************
        ** Description : Inserts the lexeme, token and depth into a **
        **               record in the symbol table.                **
        **************************************************************/
        public void insert(string lex, string token, int depth)
        {
            int location;

            location = hash(lex);
            ITableEntry tempSTR = lookup(lex);

            tempSTR.Token  = token;
            tempSTR.Lexeme = lex;
            tempSTR.Depth  = depth;
            theTable[location].Add(tempSTR);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Converts the entry to a variable.
        /// </summary>
        public void ConvertEntryToVariable(ITableEntry entry)
        {
            Variable varEntry = entry as TableEntry;

            varEntry.typeOfEntry  = EntryType.varEntry;
            varEntry.offset       = Offset;
            varEntry.bpOffsetName = BpOffsetName;
            varEntry.varType      = TypeVar;
            varEntry.size         = Size;

            Upsert(varEntry);
        }
Ejemplo n.º 17
0
        public UserRecordDialog(ITableEntry record)
        {
            InitializeComponent();
            if (record is User user)
            {
                DataContext = new UserRecordViewModel(user, this);
            }

            ((UserRecordViewModel)DataContext).MessageBoxDisplayRequested += (sender, e) =>
            {
                CustomMessageBox.Show(e.Title, e.Text);
            };
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Converts the entry to a method.
        /// </summary>
        public void ConvertEntryToMethod(ITableEntry entry)
        {
            Method methodEntry = entry as TableEntry;

            methodEntry.typeOfEntry         = EntryType.methodEntry;
            methodEntry.returnType          = TypeReturn;
            methodEntry.sizeOfLocalVars     = LocalVarsSize;
            methodEntry.numOfParameters     = ParameterNum;
            methodEntry.sizeOfParameterVars = ParameterVarsSize;
            methodEntry.parameterTypes      = ParameterTypes;

            ASMProcs.Enqueue(methodEntry); // saves the method for asm proc generation later
            Upsert(methodEntry);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Updates/Inserts into the symbol table. Updates the TableEntry to either Variable, Constant,
        /// Method, or Class if the depth matches the global depth at the found hash. Otherwise, the entry of
        /// type TableEntry is inserted to the front of the list at the calculated hash.
        /// </summary>
        public void Upsert(ITableEntry entry)
        {
            uint hash = Hash(entry.lexeme);

            if (entry.typeOfEntry != EntryType.tableEntry)
            {
                List <ITableEntry> entriesAtHash = symbolTable[hash];
                int index = entriesAtHash.FindIndex(tableEntry => tableEntry.lexeme == entry.lexeme && tableEntry.depth == entry.depth);
                symbolTable[hash][index] = entry;
            }
            else
            {
                symbolTable[hash].Insert(0, entry);
            }
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Verifies method variable.
        /// </summary>
        private void ParamsHelper()
        {
            ITableEntry entry = symbolTable.Lookup(Lexeme);

            if (entry != null)
            {
                Variable var = entry as Variable;
                Match(Tokens.IdT);
                ParamsTail();
                tacGenerator.GenerateLineOfTAC($"push {var.bpOffsetName}");
            }
            else
            {
                ErrorHandler.LogError($"\"{Lexeme}\" is undeclared");
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// IdList -> IdT IdListTail
        /// </summary>
        private void IdList()
        {
            ITableEntry entry = symbolTable.Lookup(Lexeme);

            if (entry != null)
            {
                tacGenerator.GenerateLineOfTAC($"rdi {entry.bpOffsetName}");
            }
            else
            {
                ErrorHandler.LogError($"\"{Lexeme}\" is undeclared");
            }

            Match(Tokens.IdT);
            IdListTail();
        }
Ejemplo n.º 22
0
        /// <summary>
        /// MethodDecl -> PublicT Type IdT ( FormalList ) {
        ///                   VarDecl SeqOfStatements ReturnT Expr ;
        ///               } |
        ///               ε
        /// </summary>
        private void MethodDecl()
        {
            ITableEntry Eplace = null;

            if (Token == Tokens.PublicT)
            {
                Match(Tokens.PublicT);
                Type();
                TypeReturn = TypeVar;
                TableEntry entry = symbolTable.CreateTableEntry();
                MethodNames.Add(Lexeme);
                tacGenerator.GenerateLineOfTAC($"proc {entry.lexeme}");
                Match(Tokens.IdT);
                Depth++;
                ResetMethodGlobals();
                Match(Tokens.LParenT);
                ParameterVarsSize = 4;
                FormalList();
                Offset = 2;
                tacGenerator.tempVarOffset = 2;
                Match(Tokens.RParenT);
                Match(Tokens.LBraceT);
                VarDecl();
                SeqOfStatements();
                Match(Tokens.ReturnT);
                Expr(ref Eplace);

                if (Eplace != null && Eplace.bpOffsetName != "")
                {
                    tacGenerator.GenerateLineOfTAC($"_ax = {Eplace.bpOffsetName}");
                }

                Match(Tokens.SemiT);
                symbolTable.ConvertEntryToMethod(entry);
                symbolTable.DeleteDepth(Depth);
                tacGenerator.GenerateLineOfTAC($"endp {entry.lexeme}");
                tacGenerator.GenerateLineOfTAC("");
                Depth--;
                Match(Tokens.RBraceT);
                MethodDecl();
            }
        }
Ejemplo n.º 23
0
        /// <summary>
        /// MoreFactor -> MulOpT Factor MoreFactor | ε
        /// </summary>
        private void MoreFactor(ref ITableEntry Rplace)
        {
            string      code        = "";
            string      tempVarName = "";
            ITableEntry Tplace      = null;

            if (Token == Tokens.MulOpT)
            {
                //generates a new var then creates the first part of the line
                tacGenerator.NewTempVar(ref tempVarName, Rplace);
                tacGenerator.GenerateSegmentOfExpressionTAC(ref code, tempVarName, Rplace);
                MulOp();
                Factor(ref Tplace);
                //finishes the line after the recursive call, using the info gathered from recursion
                code += Tplace.bpOffsetName;
                Rplace.bpOffsetName = tempVarName;
                tacGenerator.GenerateLineOfTAC(ref code);
                MoreFactor(ref Rplace);
            }
        }
Ejemplo n.º 24
0
        public override bool Equals(ITableEntry record)
        {
            if (!base.Equals(record))
            {
                return(false);
            }

            if (!(record is Customer route))
            {
                return(false);
            }

            return(string.Compare(Phone, route.Phone,
                                  StringComparison.CurrentCulture) == 0 &&
                   string.Compare(Address, route.Address,
                                  StringComparison.CurrentCulture) == 0 &&
                   Birthday == route.Birthday &&
                   VoucherCount == route.VoucherCount &&
                   string.Compare(Status, route.Status,
                                  StringComparison.CurrentCulture) == 0);
        }
        public bool AddEntry(ITableEntry entry)
        {
            ICountedTableEntry countedEntry = entry as ICountedTableEntry;

            if (countedEntry != null && this.countedEntries.TryGetValue(countedEntry, out ICountedTableEntry existingCountedEntry))
            {
                existingCountedEntry.AddCount();

                int i = this.entries.IndexOf(entry);
                Debug.Assert(i != -1, $"{nameof(this.countedEntries)} has extra entries in it.");

                if (i != -1)
                {
                    // Tell the table that this entry has been updated
                    this.entries[i] = existingCountedEntry;
                }

                return(false);
            }
            else
            {
                if (countedEntry != null)
                {
                    this.countedEntries.Add(countedEntry);
                }

                this.entries.Add(entry);

                if (entry is IWpfTableEntry wpfEntry && wpfEntry.TryCreateStringContent(ColumnNames.Code, false, false, out string code) && !string.IsNullOrEmpty(code))
                {
                    this.Telemetry.TrackEvent(Constants.EventNewEntry, new Dictionary <string, object>()
                    {
                        { Constants.PropertyErrorCode, code },
                    });
                }

                return(true);
            }
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Generates a new temp var for use while building TAC. Increments the tempVarOffset
        /// to prepare for the next temp var.
        /// </summary>
        public void NewTempVar(ref string tempVarName, ITableEntry entry)
        {
            tempVarName = $"_bp-{LocalVarsSize + tempVarOffset}";

            if (entry != null && entry.typeOfEntry == EntryType.varEntry)
            {
                Variable var = entry as Variable;

                if (var.size != 0)
                {
                    tempVarOffset += var.size;
                }
                else
                {
                    var.size = GetDirectValue(entry);
                }
            }
            else if (entry.typeOfEntry == EntryType.constEntry)
            {
                int num = GetDirectValue(entry);
            }
        }
Ejemplo n.º 27
0
 public static string?GetText(this ITableEntry tableEntry)
 {
     return(tableEntry.GetValueOrDefault <string?>(StandardTableKeyNames.Text, null));
 }
Ejemplo n.º 28
0
 public static string?GetErrorCode(this ITableEntry tableEntry)
 {
     return(tableEntry.GetValueOrDefault <string?>(StandardTableKeyNames.ErrorCode, null));
 }
Ejemplo n.º 29
0
 public static int?GetColumn(this ITableEntry tableEntry)
 {
     return(tableEntry.GetValueOrNull <int>(StandardTableKeyNames.Column));
 }
Ejemplo n.º 30
0
 public static string?GetDocumentName(this ITableEntry tableEntry)
 {
     return(tableEntry.GetValueOrDefault <string?>(StandardTableKeyNames.DocumentName, null));
 }