diff options
author | renatofilho <renato.filho@openbossa.org> | 2010-10-19 17:25:32 -0300 |
---|---|---|
committer | renatofilho <renato.filho@openbossa.org> | 2010-10-20 14:15:42 -0300 |
commit | 94598415e4e5967f1b52df8e6abffb1c9bdc0b02 (patch) | |
tree | 410dc4f4f916d0275a5784d9230fc28ede968146 | |
parent | 75321b8149ec5cfb69c4b758976b5a11ff22083b (diff) |
Fixed translate type function.
Reviewer: Hugo Parente Lima <hugo.pl@gmail.com>
Marcelo lira <marcelo.lira@openbossa.org>
-rw-r--r-- | generator.cpp | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/generator.cpp b/generator.cpp index e6fbfab51..3798eff51 100644 --- a/generator.cpp +++ b/generator.cpp @@ -276,6 +276,7 @@ QString Generator::translateType(const AbstractMetaType *cType, Options options) const { QString s; + static int constLen = strlen("const"); if (context && cType && context->typeEntry()->isGenericClass() && @@ -293,19 +294,29 @@ QString Generator::translateType(const AbstractMetaType *cType, else s = cType->cppSignature(); } else { - if (options & Generator::OriginalName) - s = cType->originalTypeDescription(); - else - s = cType->cppSignature(); - if (cType->isConstant() && (options & Generator::ExcludeConst)) { - // Remove just the first ‘const’, avoiding removal of template attr. - int pos = s.indexOf("const"); - s.remove(pos, 5); //remove strlen(const) - } - if (cType->isReference() && (options & Generator::ExcludeReference)) { - // Remove just the first ‘&’, avoiding removal of template references. - int pos = s.indexOf("&"); - s.remove(pos, 1); //remove strlen(const) + if (options & Generator::OriginalName) { + s = cType->originalTypeDescription().trimmed(); + if ((options & Generator::ExcludeReference) && s.endsWith("&")) + s = s.left(s.size()-1); + + // remove only the last const (avoid remove template const) + if (options & Generator::ExcludeConst) { + int index = s.lastIndexOf("const"); + + if (index >= (s.size() - (constLen + 1))) // (VarType const) or (VarType const[*|&]) + s = s.remove(index, constLen); + } + } else { + AbstractMetaType *copyType = cType->copy(); + + if (options & Generator::ExcludeConst) + copyType->setConstant(false); + + if (options & Generator::ExcludeReference) + copyType->setReference(false); + + s = copyType->cppSignature(); + delete copyType; } } |