Fixed two issues in the type encoding parser:

- A correctness issue: with assertions disabled,
  ReadQuotedString would misbehave; and

- A performance issue: BuildType used a long
  chain of if()s; I changed that to two switch
  statements.  That also makes the code much
  nicer to step through when debugging it.

llvm-svn: 221651
This commit is contained in:
Sean Callanan 2014-11-11 00:50:10 +00:00
parent 0becd57044
commit f37ccc181d
1 changed files with 82 additions and 82 deletions

View File

@ -43,7 +43,8 @@ AppleObjCTypeEncodingParser::ReadQuotedString(lldb_utility::StringLexer& type)
StreamString buffer; StreamString buffer;
while (type.HasAtLeast(1) && type.Peek() != '"') while (type.HasAtLeast(1) && type.Peek() != '"')
buffer.Printf("%c",type.Next()); buffer.Printf("%c",type.Next());
assert(type.Next() == '"'); StringLexer::Character next = type.Next();
assert (next == '"');
return buffer.GetString(); return buffer.GetString();
} }
@ -198,7 +199,7 @@ AppleObjCTypeEncodingParser::BuildObjCObjectPointerType (clang::ASTContext &ast_
{ {
default: default:
// roll back // roll back
type.PutBack(name.length() + 1); type.PutBack(name.length() + 2); // undo our consumption of the string and of the quotes
name.clear(); name.clear();
break; break;
case '}': case '}':
@ -258,52 +259,67 @@ AppleObjCTypeEncodingParser::BuildType (clang::ASTContext &ast_ctx, StringLexer&
if (!type.HasAtLeast(1)) if (!type.HasAtLeast(1))
return clang::QualType(); return clang::QualType();
if (type.NextIf('c')) switch (type.Peek())
return ast_ctx.CharTy;
if (type.NextIf('i'))
return ast_ctx.IntTy;
if (type.NextIf('s'))
return ast_ctx.ShortTy;
if (type.NextIf('l'))
{ {
ClangASTContext *lldb_ctx = ClangASTContext::GetASTContext(&ast_ctx); default:
if (!lldb_ctx) break;
return clang::QualType(); case '{':
return lldb_ctx->GetIntTypeFromBitSize(32, true).GetQualType(); return BuildStruct(ast_ctx, type, for_expression);
case '[':
return BuildArray(ast_ctx, type, for_expression);
case '(':
return BuildUnion(ast_ctx, type, for_expression);
case '@':
return BuildObjCObjectPointerType(ast_ctx, type, for_expression);
} }
if (type.NextIf('q'))
return ast_ctx.LongLongTy;
if (type.NextIf('C'))
return ast_ctx.UnsignedCharTy;
if (type.NextIf('I'))
return ast_ctx.UnsignedIntTy;
if (type.NextIf('S'))
return ast_ctx.UnsignedShortTy;
if (type.NextIf('L'))
{
ClangASTContext *lldb_ctx = ClangASTContext::GetASTContext(&ast_ctx);
if (!lldb_ctx)
return clang::QualType();
return lldb_ctx->GetIntTypeFromBitSize(32, false).GetQualType();
}
if (type.NextIf('Q'))
return ast_ctx.UnsignedLongLongTy;
if (type.NextIf('f'))
return ast_ctx.FloatTy;
if (type.NextIf('d'))
return ast_ctx.DoubleTy;
if (type.NextIf('B'))
return ast_ctx.BoolTy;
if (type.NextIf('v'))
return ast_ctx.VoidTy;
if (type.NextIf('*'))
return ast_ctx.getPointerType(ast_ctx.CharTy);
if (type.NextIf('#'))
return ast_ctx.getObjCClassType();
if (type.NextIf(':'))
return ast_ctx.getObjCSelType();
if (type.NextIf('b')) switch (type.Next())
{
default:
type.PutBack(1);
return clang::QualType();
case 'c':
return ast_ctx.CharTy;
case 'i':
return ast_ctx.IntTy;
case 's':
return ast_ctx.ShortTy;
case 'l':
return ast_ctx.getIntTypeForBitwidth(32, true);
// this used to be done like this:
// ClangASTContext *lldb_ctx = ClangASTContext::GetASTContext(&ast_ctx);
// if (!lldb_ctx)
// return clang::QualType();
// return lldb_ctx->GetIntTypeFromBitSize(32, true).GetQualType();
// which uses one of the constants if one is available, but we don't think all this work is necessary.
case 'q':
return ast_ctx.LongLongTy;
case 'C':
return ast_ctx.UnsignedCharTy;
case 'I':
return ast_ctx.UnsignedIntTy;
case 'S':
return ast_ctx.UnsignedShortTy;
case 'L':
return ast_ctx.getIntTypeForBitwidth(32, false);
// see note for 'l'
case 'Q':
return ast_ctx.UnsignedLongLongTy;
case 'f':
return ast_ctx.FloatTy;
case 'd':
return ast_ctx.DoubleTy;
case 'B':
return ast_ctx.BoolTy;
case 'v':
return ast_ctx.VoidTy;
case '*':
return ast_ctx.getPointerType(ast_ctx.CharTy);
case '#':
return ast_ctx.getObjCClassType();
case ':':
return ast_ctx.getObjCSelType();
case 'b':
{ {
uint32_t size = ReadNumber(type); uint32_t size = ReadNumber(type);
if (bitfield_bit_size) if (bitfield_bit_size)
@ -314,8 +330,7 @@ AppleObjCTypeEncodingParser::BuildType (clang::ASTContext &ast_ctx, StringLexer&
else else
return clang::QualType(); return clang::QualType();
} }
case 'r':
if (type.NextIf('r'))
{ {
clang::QualType target_type = BuildType(ast_ctx, type, for_expression); clang::QualType target_type = BuildType(ast_ctx, type, for_expression);
if (target_type.isNull()) if (target_type.isNull())
@ -325,8 +340,7 @@ AppleObjCTypeEncodingParser::BuildType (clang::ASTContext &ast_ctx, StringLexer&
else else
return ast_ctx.getConstType(target_type); return ast_ctx.getConstType(target_type);
} }
case '^':
if (type.NextIf('^'))
{ {
if (!for_expression && type.NextIf('?')) if (!for_expression && type.NextIf('?'))
{ {
@ -347,23 +361,9 @@ AppleObjCTypeEncodingParser::BuildType (clang::ASTContext &ast_ctx, StringLexer&
return ast_ctx.getPointerType(target_type); return ast_ctx.getPointerType(target_type);
} }
} }
case '?':
if (type.NextIf('?'))
return for_expression ? ast_ctx.UnknownAnyTy : clang::QualType(); return for_expression ? ast_ctx.UnknownAnyTy : clang::QualType();
}
if (type.Peek() == '{')
return BuildStruct(ast_ctx, type, for_expression);
if (type.Peek() == '[')
return BuildArray(ast_ctx, type, for_expression);
if (type.Peek() == '(')
return BuildUnion(ast_ctx, type, for_expression);
if (type.Peek() == '@')
return BuildObjCObjectPointerType(ast_ctx, type, for_expression);
return clang::QualType();
} }
ClangASTType ClangASTType