示例#1
0
文件: ThirdPass.cs 项目: goric/cflat
        public override void VisitNeg(ASTNegative n)
        {
            CFlatType t = CheckSubTree(n.Expression);

            if (t.IsNumeric)
            {
                n.CFlatType   = t;
                _lastSeenType = t;
            }
            else
            {
                ReportError(n.Location, "Only numeric datatypes can be negated. Got type '{0}'", TypeToFriendlyName(t));
            }
        }
示例#2
0
        protected override bool Visit(ASTNegative node)
        {
            if (!Visit(node.Child))
            {
                return(false);
            }

            var childType = node.Child.TypeInfo;

            if (childType is FloatType f)
            {
                node.TypeInfo = f;
                return(true);
            }

            if (childType is IntegerType i)
            {
                if (!i.Signed)
                {
                    if (i.Size != BaseType.UnknownSize)
                    {
                        Error(node.Position, $"Cannot negate {childType}");
                        return(false);
                    }

                    // If the size of the unsigned interger is unknown, then we are free to convert between signed and unsigned
                    node.TypeInfo = Cache.GetInt(BaseType.UnknownSize, true);
                    return(true);
                }

                node.TypeInfo = i;
                return(true);
            }

            Error(node.Position, $"Cannot negate {childType}");
            return(false);
        }
示例#3
0
 protected override bool Visit(ASTNegative node) => EmitUnary <CNegative>(node);
示例#4
0
 public override void VisitNeg(ASTNegative n)
 {
     throw new NotImplementedException();
 }
示例#5
0
 protected abstract bool Visit(ASTNegative node);