--- [ Array constants ] ----------------------------------------------------- irArrayConst translates the AST array constant into an equivalent IR array constant.
(t types.Type, old *ast.ArrayConst)
| 166 | // irArrayConst translates the AST array constant into an equivalent IR array |
| 167 | // constant. |
| 168 | func (gen *generator) irArrayConst(t types.Type, old *ast.ArrayConst) (*constant.Array, error) { |
| 169 | typ, ok := t.(*types.ArrayType) |
| 170 | if !ok { |
| 171 | return nil, errors.Errorf("invalid type of array constant; expected *types.ArrayType, got %T", t) |
| 172 | } |
| 173 | oldElems := old.Elems() |
| 174 | if len(oldElems) == 0 { |
| 175 | typ := types.NewArray(0, typ.ElemType) |
| 176 | if !t.Equal(typ) { |
| 177 | return nil, errors.Errorf("array type mismatch; expected %q, got %q", typ, t) |
| 178 | } |
| 179 | return &constant.Array{Typ: typ}, nil |
| 180 | } |
| 181 | elems := make([]constant.Constant, len(oldElems)) |
| 182 | for i, oldElem := range oldElems { |
| 183 | elem, err := gen.irTypeConst(oldElem) |
| 184 | if err != nil { |
| 185 | return nil, errors.WithStack(err) |
| 186 | } |
| 187 | elems[i] = elem |
| 188 | } |
| 189 | c := constant.NewArray(typ, elems...) |
| 190 | return c, nil |
| 191 | } |
| 192 | |
| 193 | // irCharArrayConst translates the AST character array constant into an |
| 194 | // equivalent IR character array constant. |
no test coverage detected