1#!/bin/python
2
3# Debugging helpers for custom types
4# Pavel Sevecek (sevecek at sirrah.troja.mff.cuni.cz)
5# 2016-2017
6
7from dumper import *
8import math
9import sys
10
11def qdump____m128(d, value):
12    d.putEmptyValue()
13    d.putNumChild(1)
14    if d.isExpanded():
15        d.putArrayData(value.address(), 4, d.lookupType("float"))
16
17
18def qdump____m128d(d, value):
19    d.putEmptyValue()
20    d.putNumChild(1)
21    if d.isExpanded():
22        d.putArrayData(value.address(), 2, d.lookupType("double"))
23
24def qdump__Sph__AutoPtr(d, value):
25    ptr = value["ptr"]
26    if ptr.integer() == 0:
27        d.putValue("nullptr")
28    else:
29        d.putItem(ptr.dereference())
30
31def qdump__Sph__RawPtr(d, value):
32    ptr = value["ptr"]
33    if ptr.integer() == 0:
34        d.putValue("nullptr")
35    else:
36        d.putItem(ptr.dereference())
37
38def qdump__Sph__SharedPtr(d, value):
39    ptr = value["ptr"]
40    if ptr.integer() == 0:
41        d.putValue("nullptr")
42    else:
43        d.putItem(ptr.dereference())
44
45def qdump__Sph__Optional(d, value):
46    used = value["used"]
47    if used.integer() == 0:
48        d.putValue("NOTHING")
49    else:
50        templateType = d.templateArgument(value.type, 0)
51        x = d.createValue(value.address(), templateType)
52        d.putItem(x)
53
54def qdump__Sph__Array(d, value):
55    actsize = value["actSize"].integer()
56#    maxsize = value["maxSize"].integer()
57    d.putNumChild(actsize)
58    p = value["data"]
59    d.putValue("(%s values)" % (actsize))
60    innerType = p.type
61    templateType = d.templateArgument(value.type, 0)
62    if d.isExpanded():
63        with Children(d, actsize, childType=innerType):
64            for i in range(0, actsize):
65                d.putSubItem(i, p.dereference().cast(templateType))
66                p = p + 1
67
68def qdump__Sph__ArrayView(d, value):
69    actsize = value["actSize"].integer()
70    d.putNumChild(actsize)
71    p = value["data"]
72    d.putValue("(%s values)" % (actsize))
73    innerType = p.type
74    templateType = d.templateArgument(value.type, 0)
75    if d.isExpanded():
76        with Children(d, actsize, childType=innerType):
77            for i in range(0, actsize):
78                d.putSubItem(i, p.dereference().cast(templateType))
79                p = p + 1
80
81def qdump__Sph__BasicVector(d, value):
82    d.putNumChild(4)
83    templateType = d.templateArgument(value.type, 0)
84    siz = 8 # have to be changed to 4 for floats!
85    x = d.createValue(value.address(), templateType)
86    y = d.createValue(value.address() + siz, templateType)
87    z = d.createValue(value.address() + 2*siz, templateType)
88    h = d.createValue(value.address() + 3*siz, templateType)
89    if d.isExpanded():
90        with Children(d, 4, childType=templateType):
91            d.putSubItem("x", x)
92            d.putSubItem("y", y)
93            d.putSubItem("z", z)
94            d.putSubItem("h", h)
95
96def qdump__Sph__TracelessTensor(d, value):
97    d.putNumChild(5)
98    templateType = d.lookupType("double")
99    siz = 8 # have to be changed to 4 for floats!
100    sxx = d.createValue(value.address(), templateType)
101    syy = d.createValue(value.address() + siz, templateType)
102    sxy = d.createValue(value.address() + 2*siz, templateType)
103    sxz = d.createValue(value.address() + 3*siz, templateType)
104    syz = d.createValue(value.address() + 4*siz, templateType)
105    if d.isExpanded():
106        with Children(d, 5, childType=templateType):
107            d.putSubItem("sxx", sxx)
108            d.putSubItem("syy", syy)
109            d.putSubItem("sxy", sxy)
110            d.putSubItem("sxz", sxz)
111            d.putSubItem("syz", syz)
112
113def qdump__Sph__SymmetricTensor(d, value):
114    d.putNumChild(6)
115    templateType = d.lookupType("double")
116    diag = value["diag"]
117    off = value["off"]
118    siz = 8 # have to be changed to 4 for floats!
119    sxx = d.createValue(diag.address(), templateType)
120    syy = d.createValue(diag.address() + siz, templateType)
121    szz = d.createValue(diag.address() + 2*siz, templateType)
122    sxy = d.createValue(off.address(), templateType)
123    sxz = d.createValue(off.address() + siz, templateType)
124    syz = d.createValue(off.address() + 2*siz, templateType)
125    if d.isExpanded():
126        with Children(d, 6, childType=templateType):
127            d.putSubItem("sxx", sxx)
128            d.putSubItem("syy", syy)
129            d.putSubItem("szz", szz)
130            d.putSubItem("sxy", sxy)
131            d.putSubItem("sxz", sxz)
132            d.putSubItem("syz", syz)
133
134
135
136