Beispiel #1
0
        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"
            };
        }
Beispiel #2
0
 public override void Visit(NewExprAST newStatement)
 {
 }
Beispiel #3
0
 public virtual void Visit(NewExprAST newStatement)
 {
 }