/// <summary>
        /// Evaluates the fixup entry
        /// </summary>
        /// <param name="fixup"></param>
        /// <param name="numericOnly">Signs if only numeric expressions are accepted</param>
        /// <param name="signNotEvaluable">Raise error if the symbol is not evaluable</param>
        /// <param name="exprValue">The value of the expression</param>
        /// <returns>True, if evaluation successful; otherwise, false</returns>
        private bool EvaluateFixupExpression(FixupEntry fixup, bool numericOnly, bool signNotEvaluable,
                                             out ExpressionValue exprValue)
        {
            exprValue = new ExpressionValue(0L);
            ExpressionNode.ClearErrors();
            if (!fixup.Expression.ReadyToEvaluate(fixup))
            {
                if (signNotEvaluable)
                {
                    ReportError(Errors.Z0201, fixup.SourceLine, ExpressionNode.SymbolErrors);
                }
                return(false);
            }

            // --- Now resolve the fixup
            exprValue      = fixup.Expression.Evaluate(fixup);
            fixup.Resolved = true;

            // --- Check, if resolution was successful
            if (fixup.Expression.EvaluationError != null)
            {
                ReportError(Errors.Z0200, fixup.SourceLine, fixup.Expression.EvaluationError);
                return(false);
            }
            if (numericOnly && exprValue.Type == ExpressionValueType.String)
            {
                ReportError(Errors.Z0305, fixup.SourceLine);
                return(false);
            }

            // --- Ok, no error
            return(true);
        }
예제 #2
0
 /// <summary>
 /// Evaluates the fixup entry
 /// </summary>
 /// <param name="fixup"></param>
 /// <param name="exprValue">The value of the expression</param>
 /// <returns>True, if evaluation successful; otherwise, false</returns>
 private bool EvaluateFixupExpression(FixupEntry fixup, out ushort exprValue)
 {
     exprValue = 0;
     if (!fixup.Expression.ReadyToEvaluate(this))
     {
         ReportError(Errors.Z0201, fixup.SourceLine);
         return(false);
     }
     exprValue = fixup.Expression.Evaluate(this);
     if (fixup.Expression.EvaluationError != null)
     {
         ReportError(Errors.Z0200, fixup.SourceLine, fixup.Expression.EvaluationError);
         return(false);
     }
     return(true);
 }
        /// <summary>
        /// Records fixup information
        /// </summary>
        /// <param name="opLine">The operation line</param>
        /// <param name="type">Fixup type</param>
        /// <param name="expression">Fixup expression</param>
        /// <param name="label">Optional EQU label</param>
        /// <param name="structeBytes">Optional structure bytes</param>
        /// <param name="offset">Fixup offset, if not the current position</param>
        private void RecordFixup(SourceLineBase opLine, FixupType type, ExpressionNode expression,
                                 string label = null, Dictionary <ushort, byte> structeBytes = null, ushort?offset = null)
        {
            var fixupOffset = CurrentSegment.CurrentOffset;

            // --- Translate field invocation fixups so that field-related fixups will be
            // --- processed only after other fixups.
            if (IsInStructInvocation)
            {
                fixupOffset = _currentStructStartOffset + _currentStructOffset;
                if (type == FixupType.Bit8)
                {
                    type = FixupType.FieldBit8;
                }
                else if (type == FixupType.Bit16)
                {
                    type = FixupType.FieldBit16;
                }
            }

            // --- Create to fixup entry to resolve
            var fixup = new FixupEntry(this, CurrentModule, opLine, type, Output.Segments.Count - 1,
                                       offset ?? fixupOffset,
                                       expression, label, structeBytes);

            // --- Record fixups in every local scope up to the root
            foreach (var scope in CurrentModule.LocalScopes)
            {
                scope.Fixups.Add(fixup);
            }

            // --- Record fixup in every module up to the root
            var currentModule = CurrentModule;

            while (currentModule != null)
            {
                currentModule.Fixups.Add(fixup);
                currentModule = currentModule.ParentModule;
            }
        }