Exemplo n.º 1
0
        public override bool CheckSemantic(List <Error> errors, SymbolTable symbolTable)
        {
            int            initErr  = errors.Count;
            TypeExpression BaseType = null;

            //Check ArrayType
            TypeSymbol type;

            if (MappingDeclaration(ArrayTypeId, symbolTable, errors, Line, CharPositionInLine, out type))
            {
                if (!(type.TypeExpression.PrimitiveType is ArrayType))
                {
                    string message = string.Format("{0} type cannot be converted to an array type", type.TypeExpression);
                    errors.Add(new Error(message, Line, CharPositionInLine));
                }
                else
                {
                    BaseType = (type.TypeExpression.PrimitiveType as ArrayType).BaseType;
                }
            }

            //Check LengthExpr
            if (LengthExpr.CheckSemantic(errors, symbolTable))
            {
                if (!(LengthExpr.ReturnType.PrimitiveType is IntegerType))
                {
                    errors.Add(new Error("The type of length expression must be int", Line, CharPositionInLine));
                }
            }

            //Check InitValueExpr
            string decoratedErr = string.Format("The type of init value expression is not equivalent with the subyacent type of '{0}'", ArrayTypeId);

            if (InitValueExpr.CheckSemantic(errors, symbolTable))
            {
                if (BaseType != null)
                {
                    CheckAssigment(InitValueExpr, BaseType, errors, decoratedErr);
                }
            }

            Scope      = symbolTable.TopScope.Clone();
            ReturnType = (initErr == errors.Count) ? type.TypeExpression : TypeExpression.ErrorType;
            return(initErr == errors.Count);
        }