File: context.cpp

package info (click to toggle)
kcachegrind 4%3A25.04.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,964 kB
  • sloc: cpp: 32,149; xml: 403; perl: 325; python: 235; sh: 8; makefile: 6
file content (132 lines) | stat: -rw-r--r-- 3,988 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
    This file is part of KCachegrind.

    SPDX-FileCopyrightText: 2002-2016 Josef Weidendorfer <Josef.Weidendorfer@gmx.de>

    SPDX-License-Identifier: GPL-2.0-only
*/

#include "context.h"

#include <QObject>

//---------------------------------------------------
// ProfileContext

ProfileContext* ProfileContext::_contexts = nullptr;
QString* ProfileContext::_typeName = nullptr;
QString* ProfileContext::_i18nTypeName = nullptr;


ProfileContext::ProfileContext(ProfileContext::Type t)
{
    _type = t;
}

ProfileContext* ProfileContext::context(ProfileContext::Type t)
{
    if (!_contexts) {
        _contexts = new ProfileContext[MaxType+1];
        for(int i=0;i<=MaxType;i++)
            _contexts[i] = ProfileContext((ProfileContext::Type)i);
    }
    return &(_contexts[t]);
}

void ProfileContext::cleanup()
{
    if (_typeName) {
        delete [] _typeName;
        _typeName = nullptr;
    }
    if (_i18nTypeName) {
        delete [] _i18nTypeName;
        _i18nTypeName = nullptr;
    }
    if (_contexts) {
        delete [] _contexts;
        _contexts = nullptr;
    }
}

QString ProfileContext::typeName(ProfileContext::Type t)
{
    if (!_typeName) {
        _typeName = new QString [MaxType+1];
        QString* strs = _typeName;
        for(int i=0;i<=MaxType;i++)
            strs[i] = QStringLiteral("?");

        strs[InvalidType] = QT_TR_NOOP("Invalid Context");
        strs[UnknownType] = QT_TR_NOOP("Unknown Context");
        strs[PartLine] = QT_TR_NOOP("Part Source Line");
        strs[Line] = QT_TR_NOOP("Source Line");
        strs[PartLineCall] = QT_TR_NOOP("Part Line Call");
        strs[LineCall] = QT_TR_NOOP("Line Call");
        strs[PartLineJump] = QT_TR_NOOP("Part Jump");
        strs[LineJump] = QT_TR_NOOP("Jump");
        strs[PartInstr] = QT_TR_NOOP("Part Instruction");
        strs[Instr] = QT_TR_NOOP("Instruction");
        strs[PartInstrJump] = QT_TR_NOOP("Part Instruction Jump");
        strs[InstrJump] = QT_TR_NOOP("Instruction Jump");
        strs[PartInstrCall] = QT_TR_NOOP("Part Instruction Call");
        strs[InstrCall] = QT_TR_NOOP("Instruction Call");
        strs[PartCall] = QT_TR_NOOP("Part Call");
        strs[Call] = QT_TR_NOOP("Call");
        strs[PartFunction] = QT_TR_NOOP("Part Function");
        strs[FunctionSource] = QT_TR_NOOP("Function Source File");
        strs[Function] = QT_TR_NOOP("Function");
        strs[FunctionCycle] = QT_TR_NOOP("Function Cycle");
        strs[PartClass] = QT_TR_NOOP("Part Class");
        strs[Class] = QT_TR_NOOP("Class");
        strs[PartFile] = QT_TR_NOOP("Part Source File");
        strs[File] = QT_TR_NOOP("Source File");
        strs[PartObject] = QT_TR_NOOP("Part ELF Object");
        strs[Object] = QT_TR_NOOP("ELF Object");
        strs[Part] = QT_TR_NOOP("Profile Part");
        strs[Data] = QT_TR_NOOP("Program Trace");
        strs[BasicBlock] = QT_TR_NOOP("BasicBlock");
    }
    if (t<0 || t> MaxType) t = MaxType;
    return _typeName[t];
}

ProfileContext::Type ProfileContext::type(const QString& s)
{
    // This is the default context type
    if (s.isEmpty()) return Function;

    Type type;
    for (int i=0; i<MaxType;i++) {
        type = (Type) i;
        if (typeName(type) == s)
            return type;
    }
    return UnknownType;
}

// all strings of typeName() are translatable because of QT_TR_NOOP there
QString ProfileContext::i18nTypeName(Type t)
{
    if (!_i18nTypeName) {
        _i18nTypeName = new QString [MaxType+1];
        for(int i=0;i<=MaxType;i++)
            _i18nTypeName[i] = QObject::tr(typeName((Type)i).toUtf8());
    }
    if (t<0 || t> MaxType) t = MaxType;
    return _i18nTypeName[t];
}

ProfileContext::Type ProfileContext::i18nType(const QString& s)
{
    // This is the default context type
    if (s.isEmpty()) return Function;

    Type type;
    for (int i=0; i<MaxType;i++) {
        type = (Type) i;
        if (i18nTypeName(type) == s)
            return type;
    }
    return UnknownType;
}