示例#1
0
        public override void CheckSemantics(Semantic.Scope scope, Semantic.ErrorReporter report)
        {
            base.CheckSemantics(scope, report);

            report.Assert(this, TypeNode.ReturnType != TypeInfo.Void, "Invalid type for array.");
            report.Assert(this, LengthExpression.ReturnType == TypeInfo.Int, "Array length must be an int.");

            var type      = scope.ResolveType(TypeNode.TypeName);
            var arrayType = (type is AliasTypeInfo) ? ((AliasTypeInfo)type).TargetType : type;

            if (TypeInfo.IsNull(arrayType))
            {
                report.AddError(this, "Unknown type: {0}", TypeNode.TypeName);
            }
            else if (!((arrayType is ArrayTypeInfo || (arrayType is AliasTypeInfo && ((AliasTypeInfo)arrayType).TargetType is ArrayTypeInfo))))
            {
                report.AddError(this, "The type {0} is not an array.", TypeNode.TypeName);
            }
            else
            {
                report.Assert(this, ((ArrayTypeInfo)arrayType).TargetType == InitExpression.ReturnType,
                              "Initialization expression and array types do not match ({0},{1})",
                              InitExpression.ReturnType, TypeNode.ReturnType);
            }

            ReturnType = arrayType;
        }
示例#2
0
 public override void CheckSemantics(Semantic.Scope scope, Semantic.ErrorReporter report)
 {
     // Esto hace falta hacerlo a pesar de que esta expresado en la gramatica de ANTLR,
     // porque al parecer la generacion de codigo en c# tiene algun bateo.
     // El codigo generado en Java da error correctamente. En C#, los errores se los traga.
     if (error)
     {
         report.AddError(this, "Invalid escape sequence detected.");
     }
     ReturnType = TypeInfo.String;
 }