コード例 #1
0
        private bool IsSameTypeOrNullPtr(TypeAST typeToCheck, TypeAST typeAssign)
        {
            var nullType = Enum.GetName(typeof(Keyword), Keyword.NULL).ToLower();

            var isSameType = typeToCheck.ToString() == typeAssign.ToString();
            var isNullPtr  = (typeToCheck.ToString().StartsWith("^") && typeAssign.ToString() == nullType);

            return(isSameType || isNullPtr);
        }
コード例 #2
0
ファイル: TypeVisitor.cs プロジェクト: Ryuuke/Ryu
        private string GetTypeOf(TypeAST currentType, TypeAST otherType)
        {
            if (currentType == null)
            {
                return(otherType.ToString());
            }

            return(ComputeType(currentType.ToString(), otherType.ToString()));
        }
コード例 #3
0
ファイル: TypeVisitor.cs プロジェクト: Ryuuke/Ryu
        public override void Visit(NumberAST number)
        {
            var numberType = new TypeAST
            {
                TypeName = number.ExplicitType != string.Empty ?
                           number.ExplicitType :
                           Enum.GetName(typeof(Keyword), Keyword.S32).ToLower()
            };

            _stateInfo.currentType = numberType;
        }
コード例 #4
0
ファイル: TypeVisitor.cs プロジェクト: Ryuuke/Ryu
        private TypeAST CastType(TypeAST currentType, TypeAST otherType)
        {
            var currentTypeString = currentType.ToString();
            var otherTypeString   = otherType.ToString();

            if (currentTypeString == otherTypeString)
            {
                return(otherType);
            }

            if (otherType.ToString() == "[] char" && currentType.ToString() == "^char" ||
                currentType.ToString() == "[] char" && otherType.ToString() == "^char")
            {
                return(otherType);
            }

            if ((Vocabulary.Types.All(x => x != currentTypeString) ||
                 Vocabulary.Types.All(x => x != otherTypeString)) &&
                currentType.TypeName != "Enum" &&
                otherType.TypeName != "Enum")
            {
                throw new Exception("Cannot Cast type " + currentTypeString + " to " + otherTypeString);
            }

            if (currentTypeString == "str" || otherTypeString == "str")
            {
                throw new Exception("Cannot Cast type " + currentTypeString + " to " + otherTypeString);
            }

            if (currentType.TypeName == "Enum" &&
                (otherTypeString.StartsWith("u") || otherTypeString.StartsWith("s")))
            {
                return(otherType);
            }

            if (otherType.TypeName == "Enum" &&
                (currentTypeString.StartsWith("u") || currentTypeString.StartsWith("s")))
            {
                return(otherType);
            }

            if (currentType.TypeName == "Enum" || otherType.TypeName == "Enum")
            {
                throw new Exception("Cannot Cast type " + currentTypeString + " to " + otherTypeString);
            }

            return(otherType);
        }
コード例 #5
0
ファイル: TypeVisitor.cs プロジェクト: Ryuuke/Ryu
        public override void Visit(NewExprAST newStatement)
        {
            if (_stateInfo.isConst)
            {
                throw new Exception("Expression must be constant");
            }

            TypeAST type = newStatement.Type;

            if (type is FunctionTypeAST)
            {
                throw new Exception("Cannot allocate a function type");
            }

            ArrayTypeAST arrayType;

            while ((arrayType = type as ArrayTypeAST) != null)
            {
                type = arrayType.TypeOfContainedValues;
            }

            if (type.ToString().StartsWith("^"))
            {
                throw new Exception("Cannot allocate a pointer");
            }

            if (type.ToString() == Enum.GetName(typeof(Keyword), Keyword.VOID).ToLower())
            {
                throw new Exception("Cannot allocate void");
            }

            if (!(type is FunctionTypeAST) && !Vocabulary.Types.Contains(type.ToString()))
            {
                var typeExists = _symTableManager.LookupTypeInfo(_stateInfo.currentFile, type.ToString());

                if (typeExists == null || typeExists.kind == TypeKind.ENUM)
                {
                    throw new Exception(string.Format("New statement : type : {0} is not a struct", type.ToString()));
                }
            }

            _stateInfo.currentType = new PtrTypeAST
            {
                Type     = newStatement.Type,
                TypeName = "Pointer"
            };
        }
コード例 #6
0
ファイル: CodeGenVisitor.cs プロジェクト: Ryuuke/Ryu
 public override void Visit(TypeAST type)
 {
 }
コード例 #7
0
 public virtual void Visit(TypeAST type)
 {
 }
コード例 #8
0
 public override void Visit(FunctionBodyAST functionBody)
 {
     Visit(functionBody.Prototype);
     Visit(functionBody.Scope);
     _returnType = null;
 }
コード例 #9
0
 public override void Visit(FunctionProtoAST functionProto)
 {
     _returnType = functionProto.ReturnType;
 }