Пример #1
0
        public override void Visit(CastAST castAST)
        {
            castAST.Expression.Accept(this);

            //if (castAST.Type.ToString().StartsWith("^"))
            //{
            //    if (_currentValue.IsConstant())
            //    {
            //        var tmp = LLVM.BuildAlloca(_builder, LLVM.PointerType(_currentValue.TypeOf(), 0), "tmp");
            //        LLVM.BuildStore(_builder, _currentValue, tmp);
            //        _currentValue = LLVM.BuildGEP(_builder, tmp, new LLVMValueRef[] { LLVM.ConstInt(LLVM.Int16Type(), 0, _false), LLVM.ConstInt(LLVM.Int16Type(), 0, _false) }, "gepCast");
            //    }
            //    else
            //    _currentValue = LLVM.BuildGEP(_builder, _currentValue, new LLVMValueRef[] { LLVM.ConstInt(LLVM.Int16Type(), 0, _false), LLVM.ConstInt(LLVM.Int16Type(), 0, _false) }, "gepCast");
            //}
        }
Пример #2
0
        public override void Visit(CastAST castAST)
        {
            var castType = castAST.Type;

            if (castAST.Type.ToString().StartsWith("^"))
            {
                _stateInfo.currentType = castType;
                return;
            }

            if (Vocabulary.Types.All(x => x != castAST.Type.ToString()) && !castAST.Type.ToString().StartsWith("^"))
            {
                var customType = _symTableManager.LookupTypeInfo(_stateInfo.currentFile, castType.ToString());

                if (customType.kind == TypeKind.STRUCT)
                {
                    throw new Exception(string.Format("Invalid cast: Type '{0}' is not a primitive type or enum type", castType));
                }

                castType = customType.type;
            }

            castAST.Expression.Accept(this);


            var expressionType = _stateInfo.currentType;

            if (expressionType.ToString().StartsWith("^"))
            {
                _stateInfo.currentType = castType;
                return;
            }

            if (Vocabulary.Types.All(x => x != expressionType.ToString()) && !(expressionType is EnumAST))
            {
                throw new Exception(string.Format("Invalid cast: Type '{0}' is not a primitive type or enum type", expressionType));
            }

            _stateInfo.currentType = CastType(expressionType, castType);
        }
Пример #3
0
 public virtual void Visit(CastAST castAST)
 {
 }