forked from pocoproject/poco
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParameter.cpp
More file actions
147 lines (128 loc) · 3.24 KB
/
Parameter.cpp
File metadata and controls
147 lines (128 loc) · 3.24 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
//
// Parameter.cpp
//
// $Id: //poco/1.4/CppParser/src/Parameter.cpp#2 $
//
// Library: CppParser
// Package: SymbolTable
// Module: Parameter
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/CppParser/Parameter.h"
#include "Poco/CppParser/NameSpace.h"
#include "Poco/CppParser/TypeDef.h"
#include "Poco/CppParser/Utility.h"
#include "Poco/String.h"
#include "Poco/NumberFormatter.h"
#include <cstddef>
namespace Poco {
namespace CppParser {
int Parameter::_count(0);
Parameter::Parameter(const std::string& decl, Function* pFunction):
Decl(handleDecl(decl), 0), // handle init values
_type(),
_isRef(false),
_isPointer(false),
_isConst(false)
{
std::size_t pos = declaration().rfind(name());
std::string tmp;
if (pos == 0 && name().size() == declaration().size())
tmp = declaration();
else
tmp = declaration().substr(0, pos);
_type = Poco::trim(tmp);
std::size_t rightCut = _type.size();
while (rightCut > 0 && (_type[rightCut-1] == '&' || _type[rightCut-1] == '*' || _type[rightCut-1] == '\t' || _type[rightCut-1] == ' '))
{
if (_type[rightCut-1] == '&')
_isRef = true;
if (_type[rightCut-1] == '*')
_isPointer = true;
--rightCut;
}
_type = Poco::trim(_type.substr(0, rightCut));
if (_type.find("const ") == 0)
{
_isConst = true;
_type = _type.substr(6);
}
if (_type.find("const\t") == 0)
{
_type = _type.substr(6);
_isConst = true;
}
Poco::trimInPlace(_type);
pos = decl.find("=");
_hasDefaultValue = (pos != std::string::npos);
if (_hasDefaultValue)
{
_defaultDecl = decl.substr(pos + 1);
Poco::trimInPlace(_defaultDecl);
std::size_t posStart = _defaultDecl.find("(");
std::size_t posEnd = _defaultDecl.rfind(")");
if (posStart != std::string::npos && posEnd != std::string::npos)
{
_defaultValue = _defaultDecl.substr(posStart + 1, posEnd-posStart - 1);
}
else
{
poco_assert (posStart == std::string::npos && posEnd == std::string::npos);
_defaultValue = _defaultDecl;
}
Poco::trimInPlace(_defaultValue);
}
}
Parameter::~Parameter()
{
}
Symbol::Kind Parameter::kind() const
{
return Symbol::SYM_PARAMETER;
}
bool Parameter::vectorType(const std::string& type, NameSpace* pNS)
{
bool ret = type.find("vector") != std::string::npos;
if (!ret)
{
Symbol* pSym = pNS->lookup(type);
if (pSym)
{
if (pSym->kind() == Symbol::SYM_TYPEDEF)
{
TypeDef* pType = static_cast<TypeDef*>(pSym);
ret = pType->declaration().find("vector") != std::string::npos;
}
}
}
return ret;
}
std::string Parameter::handleDecl(const std::string& decl)
{
std::size_t pos = decl.find('=');
std::string result(decl.substr(0, pos));
// now check if we have to add a paramName
Poco::trimInPlace(result);
std::size_t posSpace = result.rfind(' ');
bool mustAdd = false;
if (posSpace>0)
{
std::string tmp(result.substr(posSpace+1));
mustAdd = (tmp.find('<') != -1 || tmp.find('>') != -1 || tmp.find('*') != -1 || tmp.find('&') != -1);
}
else
mustAdd = true;
if (mustAdd)
{
result.append(" ");
result.append("param");
result.append(Poco::NumberFormatter::format(++_count));
//never add the default val it breaks the upper class parser
}
return result;
}
} } // namespace Poco::CppParser