MCPcopy Create free account
hub / github.com/llir/llvm / irArrayConst

Method irArrayConst

asm/const.go:168–191  ·  view source on GitHub ↗

--- [ Array constants ] ----------------------------------------------------- irArrayConst translates the AST array constant into an equivalent IR array constant.

(t types.Type, old *ast.ArrayConst)

Source from the content-addressed store, hash-verified

166// irArrayConst translates the AST array constant into an equivalent IR array
167// constant.
168func (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.

Callers 1

irConstantMethod · 0.95

Calls 4

irTypeConstMethod · 0.95
NewArrayFunction · 0.92
NewArrayFunction · 0.92
EqualMethod · 0.65

Tested by

no test coverage detected