Add support for specifying array delimiters.

- Extend CppLanguage::ParseTypeExpression() to also grok array
specifiers. This theoretically lets one now typecast to array types
as well as pointer types, though things don't entirely work as expected
yet.
This commit is contained in:
Rene Gollent
2013-04-12 23:35:42 -04:00
parent d18be78af7
commit 2dc96a685d
@@ -1,12 +1,14 @@
/*
* Copyright 2009, Ingo Weinhold, [email protected].
* Copyright 2012, Rene Gollent, [email protected].
* Copyright 2012-2013, Rene Gollent, [email protected].
* Distributed under the terms of the MIT License.
*/
#include "CppLanguage.h"
#include <stdlib.h>
#include "TeamTypeInformation.h"
#include "Type.h"
#include "TypeLookupConstraints.h"
@@ -39,6 +41,7 @@ CppLanguage::ParseTypeExpression(const BString &expression,
BString parsedName = expression;
BString baseTypeName;
BString arraySpecifier;
parsedName.RemoveAll(" ");
int32 modifierIndex = -1;
@@ -53,6 +56,12 @@ CppLanguage::ParseTypeExpression(const BString &expression,
} else
baseTypeName = parsedName;
modifierIndex = parsedName.FindFirst('[');
if (modifierIndex >= 0) {
parsedName.MoveInto(arraySpecifier, modifierIndex,
parsedName.Length() - modifierIndex);
}
result = info->LookupTypeByName(baseTypeName, TypeLookupConstraints(),
baseType);
if (result != B_OK)
@@ -101,6 +110,37 @@ CppLanguage::ParseTypeExpression(const BString &expression,
} else
_resultType = baseType;
if (!arraySpecifier.IsEmpty()) {
ArrayType* arrayType = NULL;
int32 startIndex = 1;
do {
int32 size = strtoul(arraySpecifier.String() + startIndex,
NULL, 10);
if (size < 0)
return B_ERROR;
if (arrayType == NULL) {
result = _resultType->CreateDerivedArrayType(size, true,
arrayType);
} else {
result = arrayType->CreateDerivedArrayType(size, true,
arrayType);
}
if (result != B_OK)
return result;
typeRef.SetTo(arrayType, true);
startIndex = arraySpecifier.FindFirst('[', startIndex + 1);
} while (startIndex >= 0);
_resultType = arrayType;
}
typeRef.Detach();
return result;