Skip to content

Commit d4fe99c

Browse files
committed
Initial checking of subscript expressions
1 parent 713c34e commit d4fe99c

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/parser/cxx/type_checker.cc

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,26 @@ void TypeChecker::Visitor::operator()(VaArgExpressionAST* ast) {
273273
}
274274
}
275275

276-
void TypeChecker::Visitor::operator()(SubscriptExpressionAST* ast) {}
276+
void TypeChecker::Visitor::operator()(SubscriptExpressionAST* ast) {
277+
if (auto pointerType = type_cast<PointerType>(ast->baseExpression->type)) {
278+
ast->type = pointerType->elementType();
279+
ast->valueCategory = ast->baseExpression->valueCategory;
280+
return;
281+
}
282+
283+
if (auto arrayType = type_cast<BoundedArrayType>(ast->baseExpression->type)) {
284+
ast->type = arrayType->elementType();
285+
ast->valueCategory = ast->baseExpression->valueCategory;
286+
return;
287+
}
288+
289+
if (auto arrayType =
290+
type_cast<UnboundedArrayType>(ast->baseExpression->type)) {
291+
ast->type = arrayType->elementType();
292+
ast->valueCategory = ast->baseExpression->valueCategory;
293+
return;
294+
}
295+
}
277296

278297
void TypeChecker::Visitor::operator()(CallExpressionAST* ast) {
279298
if (!ast->baseExpression) return;

0 commit comments

Comments
 (0)