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:24:44 -04:00
parent d18be78af7
commit 2dc96a685d

View File

@ -1,12 +1,14 @@
/* /*
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Copyright 2012, Rene Gollent, rene@gollent.com. * Copyright 2012-2013, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#include "CppLanguage.h" #include "CppLanguage.h"
#include <stdlib.h>
#include "TeamTypeInformation.h" #include "TeamTypeInformation.h"
#include "Type.h" #include "Type.h"
#include "TypeLookupConstraints.h" #include "TypeLookupConstraints.h"
@ -39,6 +41,7 @@ CppLanguage::ParseTypeExpression(const BString &expression,
BString parsedName = expression; BString parsedName = expression;
BString baseTypeName; BString baseTypeName;
BString arraySpecifier;
parsedName.RemoveAll(" "); parsedName.RemoveAll(" ");
int32 modifierIndex = -1; int32 modifierIndex = -1;
@ -53,6 +56,12 @@ CppLanguage::ParseTypeExpression(const BString &expression,
} else } else
baseTypeName = parsedName; baseTypeName = parsedName;
modifierIndex = parsedName.FindFirst('[');
if (modifierIndex >= 0) {
parsedName.MoveInto(arraySpecifier, modifierIndex,
parsedName.Length() - modifierIndex);
}
result = info->LookupTypeByName(baseTypeName, TypeLookupConstraints(), result = info->LookupTypeByName(baseTypeName, TypeLookupConstraints(),
baseType); baseType);
if (result != B_OK) if (result != B_OK)
@ -101,6 +110,37 @@ CppLanguage::ParseTypeExpression(const BString &expression,
} else } else
_resultType = baseType; _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(); typeRef.Detach();
return result; return result;