<commit_before>package typesys

import (
  "fmt"
  "bitbucket.org/yyuu/bs/core"
)

// ArrayType
type ArrayType struct {
  ClassName string
  BaseType core.IType
  Length int
  PointerSize int
}

func NewArrayType(baseType core.IType, length int, pointerSize int) *ArrayType {
  return &ArrayType { "typesys.ArrayType", baseType, length, pointerSize }
}

func (self ArrayType) Key() string {
  if self.Length < 1 {
    return fmt.Sprintf("%s[]", self.BaseType)
  } else {
    return fmt.Sprintf("%s[%d]", self.BaseType, self.Length)
  }
}

func (self ArrayType) String() string {
  return self.Key()
}

func (self ArrayType) Size() int {
  return self.PointerSize
}

func (self ArrayType) AllocSize() int {
  return self.BaseType.AllocSize() * self.Length
}

func (self ArrayType) Alignment() int {
  return self.BaseType.AllocSize()
}

func (self ArrayType) IsSameType(other core.IType) bool {
  if !other.IsPointer() && !other.IsArray() {
    return false
  } else {
    return self.BaseType.IsSameType(other.GetBaseType())
  }
}

func (self ArrayType) IsVoid() bool {
  return false
}

func (self ArrayType) IsInteger() bool {
  return false
}

func (self ArrayType) IsSigned() bool {
  return false
}

func (self ArrayType) IsPointer() bool {
  return false
}

func (self ArrayType) IsArray() bool {
  return true
}

func (self ArrayType) IsCompositeType() bool {
  return false
}

func (self ArrayType) IsStruct() bool {
  return false
}

func (self ArrayType) IsUnion() bool {
  return false
}

func (self ArrayType) IsUserType() bool {
  return false
}

func (self ArrayType) IsFunction() bool {
  return false
}

func (self ArrayType) IsAllocatedArray() bool {
  return self.Length < 1 && (!self.BaseType.IsArray() || self.BaseType.IsAllocatedArray())
}

func (self ArrayType) IsIncompleteArray() bool {
  if self.BaseType.IsArray() {
    return false
  } else {
    return ! self.BaseType.IsAllocatedArray()
  }
}

func (self ArrayType) IsScalar() bool {
  return false
}

func (self ArrayType) IsCallable() bool {
  return false
}

func (self ArrayType) IsCompatible(target core.IType) bool {
  if !target.IsPointer() && !target.IsArray() {
    return false
  } else {
    if target.GetBaseType().IsVoid() {
      return true
    } else {
      return target.GetBaseType().IsCompatible(target.GetBaseType()) && self.BaseType.Size() == target.GetBaseType().Size()
    }
  }
}

func (self ArrayType) IsCastableTo(target core.IType) bool {
  return target.IsPointer() || target.IsArray()
}

func (self ArrayType) GetBaseType() core.IType {
  return self.BaseType
}
<commit_msg>Add missing `length` getter to Array type<commit_after>package typesys

import (
  "fmt"
  "bitbucket.org/yyuu/bs/core"
)

// ArrayType
type ArrayType struct {
  ClassName string
  BaseType core.IType
  Length int
  PointerSize int
}

func NewArrayType(baseType core.IType, length int, pointerSize int) *ArrayType {
  return &ArrayType { "typesys.ArrayType", baseType, length, pointerSize }
}

func (self ArrayType) Key() string {
  if self.Length < 1 {
    return fmt.Sprintf("%s[]", self.BaseType)
  } else {
    return fmt.Sprintf("%s[%d]", self.BaseType, self.Length)
  }
}

func (self ArrayType) String() string {
  return self.Key()
}

func (self ArrayType) Size() int {
  return self.PointerSize
}

func (self ArrayType) AllocSize() int {
  return self.BaseType.AllocSize() * self.Length
}

func (self ArrayType) Alignment() int {
  return self.BaseType.AllocSize()
}

func (self ArrayType) IsSameType(other core.IType) bool {
  if !other.IsPointer() && !other.IsArray() {
    return false
  } else {
    return self.BaseType.IsSameType(other.GetBaseType())
  }
}

func (self ArrayType) IsVoid() bool {
  return false
}

func (self ArrayType) IsInteger() bool {
  return false
}

func (self ArrayType) IsSigned() bool {
  return false
}

func (self ArrayType) IsPointer() bool {
  return false
}

func (self ArrayType) IsArray() bool {
  return true
}

func (self ArrayType) IsCompositeType() bool {
  return false
}

func (self ArrayType) IsStruct() bool {
  return false
}

func (self ArrayType) IsUnion() bool {
  return false
}

func (self ArrayType) IsUserType() bool {
  return false
}

func (self ArrayType) IsFunction() bool {
  return false
}

func (self ArrayType) IsAllocatedArray() bool {
  return self.Length < 1 && (!self.BaseType.IsArray() || self.BaseType.IsAllocatedArray())
}

func (self ArrayType) IsIncompleteArray() bool {
  if self.BaseType.IsArray() {
    return false
  } else {
    return ! self.BaseType.IsAllocatedArray()
  }
}

func (self ArrayType) IsScalar() bool {
  return false
}

func (self ArrayType) IsCallable() bool {
  return false
}

func (self ArrayType) IsCompatible(target core.IType) bool {
  if !target.IsPointer() && !target.IsArray() {
    return false
  } else {
    if target.GetBaseType().IsVoid() {
      return true
    } else {
      return target.GetBaseType().IsCompatible(target.GetBaseType()) && self.BaseType.Size() == target.GetBaseType().Size()
    }
  }
}

func (self ArrayType) IsCastableTo(target core.IType) bool {
  return target.IsPointer() || target.IsArray()
}

func (self ArrayType) GetBaseType() core.IType {
  return self.BaseType
}

func (self ArrayType) GetLength() int {
  return self.Length
}

{'fraction_non_alphanumeric': 0.12609357170026625, 'fraction_numerical': 0.0007607455306200076, 'mean_word_length': 3.8966480446927374, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '717789', 'n_tokens_mistral': 1767, 'n_tokens_neox': 1764, 'n_words': 479}