diff options
author | Nikolai Kosjar <nikolai.kosjar@digia.com> | 2013-12-13 18:41:15 +0100 |
---|---|---|
committer | Nikolai Kosjar <nikolai.kosjar@digia.com> | 2014-05-15 15:55:38 +0200 |
commit | 126e69137a7b3cfdf86832c2561f1dde311e9ad6 (patch) | |
tree | a884d65be6c50dfbd876091c295bfd0245f8f30d | |
parent | ba76baa65fa9ad4d1f3154639be385c7b49dc1dd (diff) | |
download | qt-creator-126e69137a7b3cfdf86832c2561f1dde311e9ad6.tar.gz |
C++: Clarify units of a Token
This will avoid confusion when later more length and indices methods are
added.
In Token:
length() --> bytes()
begin() --> bytesBegin()
end() --> bytesEnd()
Change-Id: I244c69b022e239ee762b4114559e707f93ff344f
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
32 files changed, 272 insertions, 247 deletions
diff --git a/src/libs/3rdparty/cplusplus/ASTVisitor.cpp b/src/libs/3rdparty/cplusplus/ASTVisitor.cpp index 5aa1f2d52f..8fe4399673 100644 --- a/src/libs/3rdparty/cplusplus/ASTVisitor.cpp +++ b/src/libs/3rdparty/cplusplus/ASTVisitor.cpp @@ -86,7 +86,7 @@ void ASTVisitor::getTokenPosition(unsigned index, { translationUnit()->getTokenPosition(index, line, column, fileName); } void ASTVisitor::getTokenStartPosition(unsigned index, unsigned *line, unsigned *column) const -{ getPosition(tokenAt(index).begin(), line, column); } +{ getPosition(tokenAt(index).bytesBegin(), line, column); } void ASTVisitor::getTokenEndPosition(unsigned index, unsigned *line, unsigned *column) const -{ getPosition(tokenAt(index).end(), line, column); } +{ getPosition(tokenAt(index).bytesEnd(), line, column); } diff --git a/src/libs/3rdparty/cplusplus/Bind.cpp b/src/libs/3rdparty/cplusplus/Bind.cpp index a00bdc97c3..8abb3e4ce7 100644 --- a/src/libs/3rdparty/cplusplus/Bind.cpp +++ b/src/libs/3rdparty/cplusplus/Bind.cpp @@ -1094,8 +1094,8 @@ void Bind::lambdaDeclarator(LambdaDeclaratorAST *ast) Function *fun = control()->newFunction(0, 0); - fun->setStartOffset(tokenAt(ast->firstToken()).begin()); - fun->setEndOffset(tokenAt(ast->lastToken() - 1).end()); + fun->setStartOffset(tokenAt(ast->firstToken()).bytesBegin()); + fun->setEndOffset(tokenAt(ast->lastToken() - 1).bytesEnd()); if (ast->trailing_return_type) _type = this->trailingReturnType(ast->trailing_return_type, _type); fun->setReturnType(_type); @@ -1192,8 +1192,8 @@ bool Bind::visit(CompoundStatementAST *ast) { Block *block = control()->newBlock(ast->firstToken()); unsigned startScopeToken = ast->lbrace_token ? ast->lbrace_token : ast->firstToken(); - block->setStartOffset(tokenAt(startScopeToken).end()); - block->setEndOffset(tokenAt(ast->lastToken() - 1).end()); + block->setStartOffset(tokenAt(startScopeToken).bytesEnd()); + block->setEndOffset(tokenAt(ast->lastToken() - 1).bytesEnd()); ast->symbol = block; _scope->addMember(block); Scope *previousScope = switchScope(block); @@ -1235,8 +1235,8 @@ bool Bind::visit(ForeachStatementAST *ast) { Block *block = control()->newBlock(ast->firstToken()); const unsigned startScopeToken = ast->lparen_token ? ast->lparen_token : ast->firstToken(); - block->setStartOffset(tokenAt(startScopeToken).end()); - block->setEndOffset(tokenAt(ast->lastToken()).begin()); + block->setStartOffset(tokenAt(startScopeToken).bytesEnd()); + block->setEndOffset(tokenAt(ast->lastToken()).bytesBegin()); _scope->addMember(block); ast->symbol = block; @@ -1285,8 +1285,8 @@ bool Bind::visit(RangeBasedForStatementAST *ast) { Block *block = control()->newBlock(ast->firstToken()); const unsigned startScopeToken = ast->lparen_token ? ast->lparen_token : ast->firstToken(); - block->setStartOffset(tokenAt(startScopeToken).end()); - block->setEndOffset(tokenAt(ast->lastToken()).begin()); + block->setStartOffset(tokenAt(startScopeToken).bytesEnd()); + block->setEndOffset(tokenAt(ast->lastToken()).bytesBegin()); _scope->addMember(block); ast->symbol = block; @@ -1334,8 +1334,8 @@ bool Bind::visit(ForStatementAST *ast) { Block *block = control()->newBlock(ast->firstToken()); const unsigned startScopeToken = ast->lparen_token ? ast->lparen_token : ast->firstToken(); - block->setStartOffset(tokenAt(startScopeToken).end()); - block->setEndOffset(tokenAt(ast->lastToken()).begin()); + block->setStartOffset(tokenAt(startScopeToken).bytesEnd()); + block->setEndOffset(tokenAt(ast->lastToken()).bytesBegin()); _scope->addMember(block); ast->symbol = block; @@ -1354,8 +1354,8 @@ bool Bind::visit(IfStatementAST *ast) { Block *block = control()->newBlock(ast->firstToken()); const unsigned startScopeToken = ast->lparen_token ? ast->lparen_token : ast->firstToken(); - block->setStartOffset(tokenAt(startScopeToken).end()); - block->setEndOffset(tokenAt(ast->lastToken()).begin()); + block->setStartOffset(tokenAt(startScopeToken).bytesEnd()); + block->setEndOffset(tokenAt(ast->lastToken()).bytesBegin()); _scope->addMember(block); ast->symbol = block; @@ -1410,8 +1410,8 @@ bool Bind::visit(SwitchStatementAST *ast) { Block *block = control()->newBlock(ast->firstToken()); const unsigned startScopeToken = ast->lparen_token ? ast->lparen_token : ast->firstToken(); - block->setStartOffset(tokenAt(startScopeToken).end()); - block->setEndOffset(tokenAt(ast->lastToken()).begin()); + block->setStartOffset(tokenAt(startScopeToken).bytesEnd()); + block->setEndOffset(tokenAt(ast->lastToken()).bytesBegin()); _scope->addMember(block); ast->symbol = block; @@ -1436,8 +1436,8 @@ bool Bind::visit(CatchClauseAST *ast) { Block *block = control()->newBlock(ast->firstToken()); const unsigned startScopeToken = ast->lparen_token ? ast->lparen_token : ast->firstToken(); - block->setStartOffset(tokenAt(startScopeToken).end()); - block->setEndOffset(tokenAt(ast->lastToken()).begin()); + block->setStartOffset(tokenAt(startScopeToken).bytesEnd()); + block->setEndOffset(tokenAt(ast->lastToken()).bytesBegin()); _scope->addMember(block); ast->symbol = block; @@ -1453,8 +1453,8 @@ bool Bind::visit(WhileStatementAST *ast) { Block *block = control()->newBlock(ast->firstToken()); const unsigned startScopeToken = ast->lparen_token ? ast->lparen_token : ast->firstToken(); - block->setStartOffset(tokenAt(startScopeToken).end()); - block->setEndOffset(tokenAt(ast->lastToken()).begin()); + block->setStartOffset(tokenAt(startScopeToken).bytesEnd()); + block->setEndOffset(tokenAt(ast->lastToken()).bytesBegin()); _scope->addMember(block); ast->symbol = block; @@ -1469,8 +1469,8 @@ bool Bind::visit(ObjCFastEnumerationAST *ast) { Block *block = control()->newBlock(ast->firstToken()); const unsigned startScopeToken = ast->lparen_token ? ast->lparen_token : ast->firstToken(); - block->setStartOffset(tokenAt(startScopeToken).end()); - block->setEndOffset(tokenAt(ast->lastToken()).begin()); + block->setStartOffset(tokenAt(startScopeToken).bytesEnd()); + block->setEndOffset(tokenAt(ast->lastToken()).bytesBegin()); _scope->addMember(block); ast->symbol = block; @@ -2139,7 +2139,7 @@ bool Bind::visit(FunctionDefinitionAST *ast) if (fun) { setDeclSpecifiers(fun, declSpecifiers); - fun->setEndOffset(tokenAt(ast->lastToken() - 1).end()); + fun->setEndOffset(tokenAt(ast->lastToken() - 1).bytesEnd()); if (_scope->isClass()) { fun->setVisibility(_visibility); @@ -2201,8 +2201,8 @@ bool Bind::visit(NamespaceAST *ast) } Namespace *ns = control()->newNamespace(sourceLocation, namespaceName); - ns->setStartOffset(tokenAt(sourceLocation).end()); // the scope starts after the namespace or the identifier token. - ns->setEndOffset(tokenAt(ast->lastToken() - 1).end()); + ns->setStartOffset(tokenAt(sourceLocation).bytesEnd()); // the scope starts after the namespace or the identifier token. + ns->setEndOffset(tokenAt(ast->lastToken() - 1).bytesEnd()); ns->setInline(ast->inline_token != 0); ast->symbol = ns; _scope->addMember(ns); @@ -2261,8 +2261,8 @@ bool Bind::visit(ParameterDeclarationAST *ast) bool Bind::visit(TemplateDeclarationAST *ast) { Template *templ = control()->newTemplate(ast->firstToken(), 0); - templ->setStartOffset(tokenAt(ast->firstToken()).begin()); - templ->setEndOffset(tokenAt(ast->lastToken() - 1).end()); + templ->setStartOffset(tokenAt(ast->firstToken()).bytesBegin()); + templ->setEndOffset(tokenAt(ast->lastToken() - 1).bytesEnd()); ast->symbol = templ; Scope *previousScope = switchScope(templ); @@ -2375,34 +2375,34 @@ unsigned Bind::calculateScopeStart(ObjCClassDeclarationAST *ast) const { if (ast->inst_vars_decl) if (unsigned pos = ast->inst_vars_decl->lbrace_token) - return tokenAt(pos).end(); + return tokenAt(pos).bytesEnd(); if (ast->protocol_refs) if (unsigned pos = ast->protocol_refs->lastToken()) - return tokenAt(pos - 1).end(); + return tokenAt(pos - 1).bytesEnd(); if (ast->superclass) if (unsigned pos = ast->superclass->lastToken()) - return tokenAt(pos - 1).end(); + return tokenAt(pos - 1).bytesEnd(); if (ast->colon_token) - return tokenAt(ast->colon_token).end(); + return tokenAt(ast->colon_token).bytesEnd(); if (ast->rparen_token) - return tokenAt(ast->rparen_token).end(); + return tokenAt(ast->rparen_token).bytesEnd(); if (ast->category_name) if (unsigned pos = ast->category_name->lastToken()) - return tokenAt(pos - 1).end(); + return tokenAt(pos - 1).bytesEnd(); if (ast->lparen_token) - return tokenAt(ast->lparen_token).end(); + return tokenAt(ast->lparen_token).bytesEnd(); if (ast->class_name) if (unsigned pos = ast->class_name->lastToken()) - return tokenAt(pos - 1).end(); + return tokenAt(pos - 1).bytesEnd(); - return tokenAt(ast->firstToken()).begin(); + return tokenAt(ast->firstToken()).bytesBegin(); } bool Bind::visit(ObjCClassDeclarationAST *ast) @@ -2420,7 +2420,7 @@ bool Bind::visit(ObjCClassDeclarationAST *ast) _scope->addMember(klass); klass->setStartOffset(calculateScopeStart(ast)); - klass->setEndOffset(tokenAt(ast->lastToken() - 1).end()); + klass->setEndOffset(tokenAt(ast->lastToken() - 1).bytesEnd()); if (ast->interface_token) klass->setInterface(true); @@ -2479,12 +2479,12 @@ unsigned Bind::calculateScopeStart(ObjCProtocolDeclarationAST *ast) const { if (ast->protocol_refs) if (unsigned pos = ast->protocol_refs->lastToken()) - return tokenAt(pos - 1).end(); + return tokenAt(pos - 1).bytesEnd(); if (ast->name) if (unsigned pos = ast->name->lastToken()) - return tokenAt(pos - 1).end(); + return tokenAt(pos - 1).bytesEnd(); - return tokenAt(ast->firstToken()).begin(); + return tokenAt(ast->firstToken()).bytesBegin(); } bool Bind::visit(ObjCProtocolDeclarationAST *ast) @@ -2499,7 +2499,7 @@ bool Bind::visit(ObjCProtocolDeclarationAST *ast) const unsigned sourceLocation = location(ast->name, ast->firstToken()); ObjCProtocol *protocol = control()->newObjCProtocol(sourceLocation, name); protocol->setStartOffset(calculateScopeStart(ast)); - protocol->setEndOffset(tokenAt(ast->lastToken() - 1).end()); + protocol->setEndOffset(tokenAt(ast->lastToken() - 1).bytesEnd()); ast->symbol = protocol; _scope->addMember(protocol); @@ -2920,7 +2920,7 @@ bool Bind::visit(ClassSpecifierAST *ast) { // unsigned classkey_token = ast->classkey_token; unsigned sourceLocation = ast->firstToken(); - unsigned startScopeOffset = tokenAt(sourceLocation).end(); // at the end of the class key + unsigned startScopeOffset = tokenAt(sourceLocation).bytesEnd(); // at the end of the class key for (SpecifierListAST *it = ast->attribute_list; it; it = it->next) { _type = this->specifier(it->value, _type); @@ -2930,12 +2930,12 @@ bool Bind::visit(ClassSpecifierAST *ast) if (ast->name && ! ast->name->asAnonymousName()) { sourceLocation = location(ast->name, sourceLocation); - startScopeOffset = tokenAt(sourceLocation).end(); // at the end of the class name + startScopeOffset = tokenAt(sourceLocation).bytesEnd(); // at the end of the class name if (QualifiedNameAST *q = ast->name->asQualifiedName()) { if (q->unqualified_name) { sourceLocation = q->unqualified_name->firstToken(); - startScopeOffset = tokenAt(q->unqualified_name->lastToken() - 1).end(); // at the end of the unqualified name + startScopeOffset = tokenAt(q->unqualified_name->lastToken() - 1).bytesEnd(); // at the end of the unqualified name } } @@ -2944,7 +2944,7 @@ bool Bind::visit(ClassSpecifierAST *ast) Class *klass = control()->newClass(sourceLocation, className); klass->setStartOffset(startScopeOffset); - klass->setEndOffset(tokenAt(ast->lastToken() - 1).end()); + klass->setEndOffset(tokenAt(ast->lastToken() - 1).bytesEnd()); _scope->addMember(klass); if (_scope->isClass()) @@ -3003,8 +3003,8 @@ bool Bind::visit(EnumSpecifierAST *ast) const Name *enumName = this->name(ast->name); Enum *e = control()->newEnum(sourceLocation, enumName); - e->setStartOffset(tokenAt(sourceLocation).end()); // at the end of the enum or identifier token. - e->setEndOffset(tokenAt(ast->lastToken() - 1).end()); + e->setStartOffset(tokenAt(sourceLocation).bytesEnd()); // at the end of the enum or identifier token. + e->setEndOffset(tokenAt(ast->lastToken() - 1).bytesEnd()); if (ast->key_token) e->setScoped(true); ast->symbol = e; @@ -3126,8 +3126,8 @@ bool Bind::visit(NestedDeclaratorAST *ast) bool Bind::visit(FunctionDeclaratorAST *ast) { Function *fun = control()->newFunction(0, 0); - fun->setStartOffset(tokenAt(ast->firstToken()).begin()); - fun->setEndOffset(tokenAt(ast->lastToken() - 1).end()); + fun->setStartOffset(tokenAt(ast->firstToken()).bytesBegin()); + fun->setEndOffset(tokenAt(ast->lastToken() - 1).bytesEnd()); if (ast->trailing_return_type) _type = this->trailingReturnType(ast->trailing_return_type, _type); fun->setReturnType(_type); diff --git a/src/libs/3rdparty/cplusplus/Lexer.cpp b/src/libs/3rdparty/cplusplus/Lexer.cpp index c1cec4a756..f2729fa531 100644 --- a/src/libs/3rdparty/cplusplus/Lexer.cpp +++ b/src/libs/3rdparty/cplusplus/Lexer.cpp @@ -108,7 +108,7 @@ void Lexer::scan(Token *tok) { tok->reset(); scan_helper(tok); - tok->f.length = _currentChar - _tokenStart; + tok->f.bytes = _currentChar - _tokenStart; } void Lexer::scan_helper(Token *tok) @@ -141,7 +141,7 @@ void Lexer::scan_helper(Token *tok) tok->lineno = _currentLine; _tokenStart = _currentChar; - tok->offset = _currentChar - _firstChar; + tok->byteOffset = _currentChar - _firstChar; if (_yychar) { s._newlineExpected = false; diff --git a/src/libs/3rdparty/cplusplus/Symbol.cpp b/src/libs/3rdparty/cplusplus/Symbol.cpp index f3a86e6a8b..5c262b79f5 100644 --- a/src/libs/3rdparty/cplusplus/Symbol.cpp +++ b/src/libs/3rdparty/cplusplus/Symbol.cpp @@ -166,7 +166,7 @@ void Symbol::setSourceLocation(unsigned sourceLocation, TranslationUnit *transla if (translationUnit) { const Token &tk = translationUnit->tokenAt(sourceLocation); _isGenerated = tk.generated(); - translationUnit->getPosition(tk.begin(), &_line, &_column, &_fileId); + translationUnit->getPosition(tk.bytesBegin(), &_line, &_column, &_fileId); } else { _isGenerated = false; _line = 0; diff --git a/src/libs/3rdparty/cplusplus/Token.cpp b/src/libs/3rdparty/cplusplus/Token.cpp index 1469edea7f..57e36c3ea5 100644 --- a/src/libs/3rdparty/cplusplus/Token.cpp +++ b/src/libs/3rdparty/cplusplus/Token.cpp @@ -84,7 +84,7 @@ const char *token_names[] = { void Token::reset() { flags = 0; - offset = 0; + byteOffset = 0; ptr = 0; } diff --git a/src/libs/3rdparty/cplusplus/Token.h b/src/libs/3rdparty/cplusplus/Token.h index 8889df0653..02d7f5ebe9 100644 --- a/src/libs/3rdparty/cplusplus/Token.h +++ b/src/libs/3rdparty/cplusplus/Token.h @@ -285,7 +285,7 @@ enum Kind { class CPLUSPLUS_EXPORT Token { public: - Token() : flags(0), offset(0), ptr(0) {} + Token() : flags(0), byteOffset(0), ptr(0) {} inline bool is(unsigned k) const { return f.kind == k; } inline bool isNot(unsigned k) const { return f.kind != k; } @@ -298,13 +298,13 @@ public: inline bool joined() const { return f.joined; } inline bool expanded() const { return f.expanded; } inline bool generated() const { return f.generated; } - inline unsigned length() const { return f.length; } + inline unsigned bytes() const { return f.bytes; } - inline unsigned begin() const - { return offset; } + inline unsigned bytesBegin() const + { return byteOffset; } - inline unsigned end() const - { return offset + f.length; } + inline unsigned bytesEnd() const + { return byteOffset + f.bytes; } inline bool isLiteral() const { return f.kind >= T_FIRST_LITERAL && f.kind <= T_LAST_LITERAL; } @@ -333,15 +333,15 @@ public: public: struct Flags { // The token kind. - unsigned kind : 8; + unsigned kind : 8; // The token starts a new line. - unsigned newline : 1; - // The token is preceded by whitespace(s). - unsigned whitespace : 1; + unsigned newline : 1; + // The token is preceeded by whitespace(s). + unsigned whitespace : 1; // The token is joined with the previous one. - unsigned joined : 1; + unsigned joined : 1; // The token originates from a macro expansion. - unsigned expanded : 1; + unsigned expanded : 1; // The token originates from a macro expansion and does not correspond to an // argument that went through substitution. Notice the example: // @@ -351,18 +351,18 @@ public: // After preprocessing we would expect the following tokens: 1 + 2; // Tokens '1', '+', '2', and ';' are all expanded. However only tokens '+' and ';' // are generated. - unsigned generated : 1; + unsigned generated : 1; // Unused... - unsigned pad : 3; - // The token length. - unsigned length : 16; + unsigned pad : 3; + // The token length in bytes. + unsigned bytes : 16; }; union { unsigned flags; Flags f; }; - unsigned offset; + unsigned byteOffset; union { void *ptr; diff --git a/src/libs/3rdparty/cplusplus/TranslationUnit.cpp b/src/libs/3rdparty/cplusplus/TranslationUnit.cpp index 226e25e44e..91d5101955 100644 --- a/src/libs/3rdparty/cplusplus/TranslationUnit.cpp +++ b/src/libs/3rdparty/cplusplus/TranslationUnit.cpp @@ -164,7 +164,7 @@ void TranslationUnit::tokenize() _Lrecognize: if (tk.is(T_POUND) && tk.newline()) { - unsigned offset = tk.begin(); + unsigned offset = tk.byteOffset; lex(&tk); if (! tk.newline() && tk.is(T_IDENTIFIER) && tk.identifier == expansionId) { @@ -264,7 +264,7 @@ void TranslationUnit::tokenize() currentExpanded = true; const std::pair<unsigned, unsigned> &p = lineColumn[lineColumnIdx]; if (p.first) - _expandedLineColumn.insert(std::make_pair(tk.begin(), p)); + _expandedLineColumn.insert(std::make_pair(tk.bytesBegin(), p)); else currentGenerated = true; @@ -382,17 +382,17 @@ void TranslationUnit::getTokenPosition(unsigned index, unsigned *line, unsigned *column, const StringLiteral **fileName) const -{ return getPosition(tokenAt(index).begin(), line, column, fileName); } +{ return getPosition(tokenAt(index).bytesBegin(), line, column, fileName); } void TranslationUnit::getTokenStartPosition(unsigned index, unsigned *line, unsigned *column, const StringLiteral **fileName) const -{ return getPosition(tokenAt(index).begin(), line, column, fileName); } +{ return getPosition(tokenAt(index).bytesBegin(), line, column, fileName); } void TranslationUnit::getTokenEndPosition(unsigned index, unsigned *line, unsigned *column, const StringLiteral **fileName) const -{ return getPosition(tokenAt(index).end(), line, column, fileName); } +{ return getPosition(tokenAt(index).bytesEnd(), line, column, fileName); } void TranslationUnit::getPosition(unsigned tokenOffset, unsigned *line, @@ -508,7 +508,7 @@ void TranslationUnit::fatal(unsigned index, const char *format, ...) unsigned TranslationUnit::findPreviousLineOffset(unsigned tokenIndex) const { - unsigned lineOffset = _lineOffsets[findLineNumber(tokenAt(tokenIndex).begin())]; + unsigned lineOffset = _lineOffsets[findLineNumber(tokenAt(tokenIndex).bytesBegin())]; return lineOffset; } @@ -521,21 +521,21 @@ bool TranslationUnit::maybeSplitGreaterGreaterToken(unsigned tokenIndex) return false; tok.f.kind = T_GREATER; - tok.f.length = 1; + tok.f.bytes = 1; Token newGreater; newGreater.f.kind = T_GREATER; newGreater.f.expanded = tok.expanded(); newGreater.f.generated = tok.generated(); - newGreater.f.length = 1; - newGreater.offset = tok.offset + 1; + newGreater.f.bytes = 1; + newGreater.byteOffset = tok.byteOffset + 1; _tokens->insert(_tokens->begin() + tokenIndex + 1, newGreater); - TokenLineColumn::const_iterator it = _expandedLineColumn.find(tok.begin()); + TokenLineColumn::const_iterator it = _expandedLineColumn.find(tok.bytesBegin()); if (it != _expandedLineColumn.end()) { const std::pair<unsigned, unsigned> newPosition(it->second.first, it->second.second + 1); - _expandedLineColumn.insert(std::make_pair(newGreater.begin(), newPosition)); + _expandedLineColumn.insert(std::make_pair(newGreater.bytesBegin(), newPosition)); } return true; @@ -551,7 +551,7 @@ void TranslationUnit::releaseTokensAndComments() void TranslationUnit::showErrorLine(unsigned index, unsigned column, FILE *out) { - unsigned lineOffset = _lineOffsets[findLineNumber(tokenAt(index).begin())]; + unsigned lineOffset = _lineOffsets[findLineNumber(tokenAt(index).bytesBegin())]; for (const char *cp = _firstSourceChar + lineOffset + 1; *cp && *cp != '\n'; ++cp) { fputc(*cp, out); } diff --git a/src/libs/cplusplus/BackwardsScanner.cpp b/src/libs/cplusplus/BackwardsScanner.cpp index ee7f03737a..a979c39eb1 100644 --- a/src/libs/cplusplus/BackwardsScanner.cpp +++ b/src/libs/cplusplus/BackwardsScanner.cpp @@ -87,7 +87,7 @@ const Token &BackwardsScanner::fetchToken(int tokenIndex) QList<Token> adaptedTokens; for (int i = 0; i < _tokens.size(); ++i) { Token t = _tokens.at(i); - t.offset += + blockText.length() + 1; + t.byteOffset += + blockText.length() + 1; adaptedTokens.append(t); } @@ -112,19 +112,19 @@ QString BackwardsScanner::text() const QString BackwardsScanner::mid(int index) const { const Token &firstToken = _tokens.at(index + _offset); - return _text.mid(firstToken.begin()); + return _text.mid(firstToken.bytesBegin()); } QString BackwardsScanner::text(int index) const { const Token &firstToken = _tokens.at(index + _offset); - return _text.mid(firstToken.begin(), firstToken.length()); + return _text.mid(firstToken.bytesBegin(), firstToken.bytes()); } QStringRef BackwardsScanner::textRef(int index) const { const Token &firstToken = _tokens.at(index + _offset); - return _text.midRef(firstToken.begin(), firstToken.length()); + return _text.midRef(firstToken.bytesBegin(), firstToken.bytes()); } int BackwardsScanner::size() const @@ -247,8 +247,8 @@ QString BackwardsScanner::indentationString(int index) const { const Token tokenAfterNewline = operator[](startOfLine(index + 1)); const int newlinePos = qMax(0, _text.lastIndexOf(QLatin1Char('\n'), - tokenAfterNewline.begin())); - return _text.mid(newlinePos, tokenAfterNewline.begin() - newlinePos); + tokenAfterNewline.bytesBegin())); + return _text.mid(newlinePos, tokenAfterNewline.bytesBegin() - newlinePos); } diff --git a/src/libs/cplusplus/ExpressionUnderCursor.cpp b/src/libs/cplusplus/ExpressionUnderCursor.cpp index fefb55347e..93176362be 100644 --- a/src/libs/cplusplus/ExpressionUnderCursor.cpp +++ b/src/libs/cplusplus/ExpressionUnderCursor.cpp @@ -266,7 +266,7 @@ int ExpressionUnderCursor::startOfFunctionCall(const QTextCursor &cursor) const if (tk.is(T_EOF_SYMBOL)) { break; } else if (tk.is(T_LPAREN)) { - return scanner.startPosition() + tk.begin(); + return scanner.startPosition() + tk.bytesBegin(); } else if (tk.is(T_RPAREN)) { int matchingBrace = scanner.startOfMatchingBrace(index); diff --git a/src/libs/cplusplus/FindUsages.cpp b/src/libs/cplusplus/FindUsages.cpp index 383bd3dad7..91fa156c2f 100644 --- a/src/libs/cplusplus/FindUsages.cpp +++ b/src/libs/cplusplus/FindUsages.cpp @@ -140,7 +140,7 @@ void FindUsages::reportResult(unsigned tokenIndex, const QList<LookupItem> &cand QString FindUsages::matchingLine(const Token &tk) const { const char *beg = _source.constData(); - const char *cp = beg + tk.begin(); + const char *cp = beg + tk.bytesBegin(); for (; cp != beg - 1; --cp) { if (*cp == '\n') break; @@ -178,7 +178,7 @@ void FindUsages::reportResult(unsigned tokenIndex) if (col) --col; // adjust the column position. - const int len = tk.length(); + const int len = tk.bytes(); const Usage u(_doc->fileName(), lineText, line, col, len); _usages.append(u); @@ -259,8 +259,8 @@ bool FindUsages::checkCandidates(const QList<LookupItem> &candidates) const void FindUsages::checkExpression(unsigned startToken, unsigned endToken, Scope *scope) { - const unsigned begin = tokenAt(startToken).begin(); - const unsigned end = tokenAt(endToken).end(); + const unsigned begin = tokenAt(startToken).bytesBegin(); + const unsigned end = tokenAt(endToken).bytesEnd(); const QByteArray expression = _source.mid(begin, end - begin); // qDebug() << "*** check expression:" << expression; diff --git a/src/libs/cplusplus/PPToken.cpp b/src/libs/cplusplus/PPToken.cpp index 7b34c1ed35..fdfaacd2bd 100644 --- a/src/libs/cplusplus/PPToken.cpp +++ b/src/libs/cplusplus/PPToken.cpp @@ -55,8 +55,8 @@ int ByteArrayRef::count(char ch) const void Internal::PPToken::squeezeSource() { if (hasSource()) { - m_src = m_src.mid(offset, f.length); + m_src = m_src.mid(byteOffset, f.bytes); m_src.squeeze(); - offset = 0; + byteOffset = 0; } } diff --git a/src/libs/cplusplus/PPToken.h b/src/libs/cplusplus/PPToken.h index 1168fc90a4..fdb700d378 100644 --- a/src/libs/cplusplus/PPToken.h +++ b/src/libs/cplusplus/PPToken.h @@ -129,10 +129,10 @@ public: { return m_src.constData(); } const char *tokenStart() const - { return bufferStart() + offset; } + { return bufferStart() + byteOffset; } ByteArrayRef asByteArrayRef() const - { return ByteArrayRef(&m_src, offset, length()); } + { return ByteArrayRef(&m_src, byteOffset, bytes()); } private: QByteArray m_src; diff --git a/src/libs/cplusplus/SimpleLexer.cpp b/src/libs/cplusplus/SimpleLexer.cpp index 6ab2f4db91..26030ae09f 100644 --- a/src/libs/cplusplus/SimpleLexer.cpp +++ b/src/libs/cplusplus/SimpleLexer.cpp @@ -89,7 +89,7 @@ QList<Token> SimpleLexer::operator()(const QString &text, int state) break; } - QStringRef spell = text.midRef(tk.begin(), tk.length()); + QStringRef spell = text.midRef(tk.bytesBegin(), tk.bytes()); lex.setScanAngleStringLiteralTokens(false); if (tk.newline() && tk.is(T_POUND)) @@ -116,7 +116,7 @@ int SimpleLexer::tokenAt(const QList<Token> &tokens, unsigned offset) { for (int index = tokens.size() - 1; index >= 0; --index) { const Token &tk = tokens.at(index); - if (tk.begin() <= offset && tk.end() >= offset) + if (tk.bytesBegin() <= offset && tk.bytesEnd() >= offset) return index; } @@ -144,7 +144,7 @@ int SimpleLexer::tokenBefore(const QList<Token> &tokens, unsigned offset) { for (int index = tokens.size() - 1; index >= 0; --index) { const Token &tk = tokens.at(index); - if (tk.begin() <= offset) + if (tk.bytesBegin() <= offset) return index; } diff --git a/src/libs/cplusplus/pp-engine.cpp b/src/libs/cplusplus/pp-engine.cpp index 942f3e5315..b32bb9dda4 100644 --- a/src/libs/cplusplus/pp-engine.cpp +++ b/src/libs/cplusplus/pp-engine.cpp @@ -303,7 +303,7 @@ public: : first(first), last(last) { // WARN: `last' must be a valid iterator. - trivial.offset = last->offset; + trivial.byteOffset = last->byteOffset; } inline operator bool() const @@ -384,12 +384,12 @@ protected: const char *tokenPosition() const { - return source.constData() + (*_lex)->offset; + return source.constData() + (*_lex)->byteOffset; } int tokenLength() const { - return (*_lex)->f.length; + return (*_lex)->f.bytes; } ByteArrayRef tokenSpell() const @@ -421,7 +421,7 @@ protected: ++(*_lex); if ((*_lex)->is(T_IDENTIFIER)) { _value.set_long(macroDefinition(tokenSpell(), - (*_lex)->offset, + (*_lex)->byteOffset, (*_lex)->lineno, env, client) != 0); ++(*_lex); @@ -429,7 +429,7 @@ protected: ++(*_lex); if ((*_lex)->is(T_IDENTIFIER)) { _value.set_long(macroDefinition(tokenSpell(), - (*_lex)->offset, + (*_lex)->byteOffset, (*_lex)->lineno, env, client) != 0); @@ -830,7 +830,7 @@ void Preprocessor::handleDefined(PPToken *tk) QByteArray result(1, '0'); const ByteArrayRef macroName = idToken.asByteArrayRef(); - if (macroDefinition(macroName, idToken.offset + m_state.m_offsetRef, + if (macroDefinition(macroName, idToken.byteOffset + m_state.m_offsetRef, idToken.lineno, m_env, m_client)) { result[0] = '1'; } @@ -881,7 +881,7 @@ _Lclassify: lex(tk); } while (isContinuationToken(*tk)); goto _Lclassify; - } else if (tk->is(T_IDENTIFIER) && !isQtReservedWord(tk->tokenStart(), tk->length())) { + } else if (tk->is(T_IDENTIFIER) && !isQtReservedWord(tk->tokenStart(), tk->bytes())) { m_state.updateIncludeGuardState(State::IncludeGuardStateHint_OtherToken); if (m_state.m_inCondition && tk->asByteArrayRef() == "defined") { handleDefined(tk); @@ -904,7 +904,7 @@ void Preprocessor::skipPreprocesorDirective(PPToken *tk) if (tk->isComment()) { synchronizeOutputLines(*tk); enforceSpacing(*tk, true); - currentOutputBuffer().append(tk->tokenStart(), tk->length()); + currentOutputBuffer().append(tk->tokenStart(), tk->bytes()); } lex(tk); } @@ -984,7 +984,7 @@ bool Preprocessor::handleIdentifier(PPToken *tk) if (!expandFunctionlikeMacros() // Still expand if this originally started with an object-like macro. && m_state.m_expansionStatus != Expanding) { - m_client->notifyMacroReference(m_state.m_offsetRef + idTk.offset, + m_client->notifyMacroReference(m_state.m_offsetRef + idTk.byteOffset, idTk.lineno, *macro); return false; @@ -1026,7 +1026,7 @@ bool Preprocessor::handleIdentifier(PPToken *tk) //### TODO: error message pushToken(tk); // If a previous marker was found, make sure to put it back. - if (oldMarkerTk.length()) + if (oldMarkerTk.bytes()) pushToken(&oldMarkerTk); *tk = idTk; return false; @@ -1044,13 +1044,13 @@ bool Preprocessor::handleIdentifier(PPToken *tk) } else { argRefs.push_back(MacroArgumentReference( - m_state.m_offsetRef + argTks.first().begin(), - argTks.last().begin() + argTks.last().length() - - argTks.first().begin())); + m_state.m_offsetRef + argTks.first().bytesBegin(), + argTks.last().bytesBegin() + argTks.last().bytes() + - argTks.first().bytesBegin())); } } - m_client->startExpandingMacro(m_state.m_offsetRef + idTk.offset, + m_client->startExpandingMacro(m_state.m_offsetRef + idTk.byteOffset, idTk.lineno, *macro, argRefs); @@ -1058,11 +1058,11 @@ bool Preprocessor::handleIdentifier(PPToken *tk) if (!handleFunctionLikeMacro(macro, body, allArgTks, baseLine)) { if (m_client && !idTk.expanded()) - m_client->stopExpandingMacro(idTk.offset, *macro); + m_client->stopExpandingMacro(idTk.byteOffset, *macro); return false; } } else if (m_client && !idTk.generated()) { - m_client->startExpandingMacro(m_state.m_offsetRef + idTk.offset, idTk.lineno, *macro); + m_client->startExpandingMacro(m_state.m_offsetRef + idTk.byteOffset, idTk.lineno, *macro); } if (body.isEmpty()) { @@ -1072,7 +1072,7 @@ bool Preprocessor::handleIdentifier(PPToken *tk) // This is not the most beautiful approach but it's quite reasonable. What we do here // is to create a fake identifier token which is only composed by whitespaces. It's // also not marked as expanded so it it can be treated as a regular token. - const QByteArray content(int(idTk.length() + computeDistance(idTk)), ' '); + const QByteArray content(int(idTk.bytes() + computeDistance(idTk)), ' '); PPToken fakeIdentifier = generateToken(T_IDENTIFIER, content.constData(), content.length(), idTk.lineno, false, false); @@ -1105,13 +1105,13 @@ bool Preprocessor::handleIdentifier(PPToken *tk) || m_state.m_expansionStatus == JustFinishedExpansion) { PPToken marker; marker.f.expanded = true; - marker.f.length = idTk.length(); - marker.offset = idTk.offset; + marker.f.bytes = idTk.bytes(); + marker.byteOffset = idTk.byteOffset; marker.lineno = idTk.lineno; body.prepend(marker); body.append(marker); m_state.setExpansionStatus(ReadyForExpansion); - } else if (oldMarkerTk.length() + } else if (oldMarkerTk.bytes() && (m_state.m_expansionStatus == ReadyForExpansion || m_state.m_expansionStatus == Expanding)) { body.append(oldMarkerTk); @@ -1122,7 +1122,7 @@ bool Preprocessor::handleIdentifier(PPToken *tk) m_state.pushTokenBuffer(body.begin(), body.end(), macro); if (m_client && !idTk.generated()) - m_client->stopExpandingMacro(idTk.offset, *macro); + m_client->stopExpandingMacro(idTk.byteOffset, *macro); return true; } @@ -1170,7 +1170,7 @@ bool Preprocessor::handleFunctionLikeMacro(const Macro *macro, lineno = t.lineno; else if (t.whitespace()) enclosedString.append(' '); - enclosedString.append(t.tokenStart(), t.length()); + enclosedString.append(t.tokenStart(), t.bytes()); } enclosedString.replace("\\", "\\\\"); enclosedString.replace("\"", "\\\""); @@ -1269,7 +1269,8 @@ void Preprocessor::trackExpansionCycles(PPToken *tk) // Offset and length of the macro invocation char chunk[40]; - qsnprintf(chunk, sizeof(chunk), "# expansion begin %d,%d", tk->offset, tk->length()); + qsnprintf(chunk, sizeof(chunk), "# expansion begin %d,%d", tk->byteOffset, + tk->bytes()); buffer.append(chunk); // Expanded tokens @@ -1437,7 +1438,7 @@ void Preprocessor::preprocess(const QString &fileName, const QByteArray &source, enforceSpacing(tk, macroExpanded); // Finally output the token. - currentOutputBuffer().append(tk.tokenStart(), tk.length()); + currentOutputBuffer().append(tk.tokenStart(), tk.bytes()); } while (tk.isNot(T_EOF_SYMBOL)); @@ -1512,7 +1513,8 @@ void Preprocessor::scanActualArgument(PPToken *tk, QVector<PPToken> *tokens) // expansion. We stick with GCC's approach which is to replace them by C style // comments (currently clang just gets rid of them) and transform internals */ // into *|. - QByteArray text = m_state.m_source.mid(tk->begin() + 2, tk->end() - tk->begin() - 2); + QByteArray text = m_state.m_source.mid(tk->bytesBegin() + 2, + tk->bytesEnd() - tk->bytesBegin() - 2); const QByteArray &comment = "/*" + text.replace("*/", "*|") + "*/"; tokens->append(generateToken(T_COMMENT, comment.constData(), comment.size(), @@ -1625,7 +1627,7 @@ void Preprocessor::handleIncludeDirective(PPToken *tk, bool includeNext) void Preprocessor::handleDefineDirective(PPToken *tk) { - const unsigned defineOffset = tk->offset; + const unsigned defineOffset = tk->byteOffset; lex(tk); // consume "define" token if (tk->isNot(T_IDENTIFIER)) @@ -1636,7 +1638,7 @@ void Preprocessor::handleDefineDirective(PPToken *tk) macro.setLine(tk->lineno); QByteArray macroName = tk->asByteArrayRef().toByteArray(); macro.setName(macroName); - macro.setOffset(tk->offset); + macro.setOffset(tk->byteOffset); PPToken idToken(*tk); @@ -1697,7 +1699,7 @@ void Preprocessor::handleDefineDirective(PPToken *tk) macroReference = m_env->resolve(tk->asByteArrayRef()); if (macroReference) { if (!macroReference->isFunctionLike()) { - m_client->notifyMacroReference(tk->offset, tk->lineno, *macroReference); + m_client->notifyMacroReference(tk->byteOffset, tk->lineno, *macroReference); macroReference = 0; } } @@ -1707,14 +1709,14 @@ void Preprocessor::handleDefineDirective(PPToken *tk) macroReference = 0; } - previousOffset = tk->offset; + previousOffset = tk->byteOffset; previousLine = tk->lineno; // Discard comments in macro definitions (keep comments flag doesn't apply here). if (tk->isComment()) { synchronizeOutputLines(*tk); enforceSpacing(*tk, true); - currentOutputBuffer().append(tk->tokenStart(), tk->length()); + currentOutputBuffer().append(tk->tokenStart(), tk->bytes()); } else { bodyTokens.push_back(*tk); } @@ -1741,8 +1743,8 @@ void Preprocessor::handleDefineDirective(PPToken *tk) macro.setDefinition(macroId, bodyTokens); } else if (!bodyTokens.isEmpty()) { PPToken &firstBodyToken = bodyTokens[0]; - int start = firstBodyToken.offset; - int len = tk->offset - start; + int start = firstBodyToken.byteOffset; + int len = tk->byteOffset - start; QByteArray bodyText = firstBodyToken.source().mid(start, len).trimmed(); const int bodySize = bodyTokens.size(); @@ -1754,7 +1756,7 @@ void Preprocessor::handleDefineDirective(PPToken *tk) macro.setDefinition(bodyText, bodyTokens); } - macro.setLength(tk->offset - defineOffset); + macro.setLength(tk->byteOffset - defineOffset); m_env->bind(macro); // qDebug() << "adding macro" << macro.name() << "defined at" << macro.fileName() << ":"<<macro.line(); @@ -1766,14 +1768,15 @@ void Preprocessor::handleDefineDirective(PPToken *tk) QByteArray Preprocessor::expand(PPToken *tk, PPToken *lastConditionToken) { unsigned line = tk->lineno; - unsigned begin = tk->begin(); + unsigned begin = tk->bytesBegin(); PPToken lastTk; while (isContinuationToken(*tk)) { lastTk = *tk; lex(tk); } // Gather the exact spelling of the content in the source. - QByteArray condition(m_state.m_source.mid(begin, lastTk.begin() + lastTk.length() - begin)); + QByteArray condition(m_state.m_source.mid(begin, lastTk.bytesBegin() + lastTk.bytes() + - begin)); // qDebug("*** Condition before: [%s]", condition.constData()); QByteArray result; @@ -1852,7 +1855,7 @@ void Preprocessor::handleElifDirective(PPToken *tk, const PPToken £Token) m_state.m_trueTest[m_state.m_ifLevel] = !startSkipping; m_state.m_skipping[m_state.m_ifLevel] = startSkipping; if (m_client && !startSkipping) - m_client->stopSkippingBlocks(poundToken.offset - 1); + m_client->stopSkippingBlocks(poundToken.byteOffset - 1); } } } @@ -1871,7 +1874,7 @@ void Preprocessor::handleElseDirective(PPToken *tk, const PPToken £Token) m_state.m_skipping[m_state.m_ifLevel] = startSkipping; if (m_client && wasSkipping && !startSkipping) - m_client->stopSkippingBlocks(poundToken.offset - 1); + m_client->stopSkippingBlocks(poundToken.byteOffset - 1); else if (m_client && !wasSkipping && startSkipping) startSkippingBlocks(poundToken); } @@ -1897,7 +1900,7 @@ void Preprocessor::handleEndIfDirective(PPToken *tk, const PPToken £Token) m_state.m_trueTest[m_state.m_ifLevel] = false; --m_state.m_ifLevel; if (m_client && wasSkipping && !m_state.m_skipping[m_state.m_ifLevel]) - m_client->stopSkippingBlocks(poundToken.offset - 1); + m_client->stopSkippingBlocks(poundToken.byteOffset - 1); if (m_state.m_ifLevel == 0) m_state.updateIncludeGuardState(State::IncludeGuardStateHint_Endif); @@ -1915,7 +1918,7 @@ void Preprocessor::handleIfDefDirective(bool checkUndefined, PPToken *tk) bool value = false; const ByteArrayRef macroName = tk->asByteArrayRef(); - if (Macro *macro = macroDefinition(macroName, tk->offset, tk->lineno, m_env, m_client)) { + if (Macro *macro = macroDefinition(macroName, tk->byteOffset, tk->lineno, m_env, m_client)) { value = true; // the macro is a feature constraint(e.g. QT_NO_XXX) @@ -1954,7 +1957,7 @@ void Preprocessor::handleUndefDirective(PPToken *tk) lex(tk); // consume "undef" token if (tk->is(T_IDENTIFIER)) { const ByteArrayRef macroName = tk->asByteArrayRef(); - const unsigned offset = tk->offset + m_state.m_offsetRef; + const unsigned offset = tk->byteOffset + m_state.m_offsetRef; // Track macro use if previously defined if (m_client) { if (const Macro *existingMacro = m_env->resolve(macroName)) @@ -2007,8 +2010,8 @@ PPToken Preprocessor::generateToken(enum Kind kind, else if (kind == T_NUMERIC_LITERAL) tk.number = m_state.m_lexer->control()->numericLiteral(m_scratchBuffer.constData() + pos, length); } - tk.offset = unsigned(pos); - tk.f.length = length; + tk.byteOffset = unsigned(pos); + tk.f.bytes = length; tk.f.generated = true; tk.f.expanded = true; tk.lineno = lineno; @@ -2019,9 +2022,9 @@ PPToken Preprocessor::generateToken(enum Kind kind, PPToken Preprocessor::generateConcatenated(const PPToken &leftTk, const PPToken &rightTk) { QByteArray newText; - newText.reserve(leftTk.length() + rightTk.length()); - newText.append(leftTk.tokenStart(), leftTk.length()); - newText.append(rightTk.tokenStart(), rightTk.length()); + newText.reserve(leftTk.bytes() + rightTk.bytes()); + newText.append(leftTk.tokenStart(), leftTk.bytes()); + newText.append(rightTk.tokenStart(), rightTk.bytes()); PPToken result = generateToken(T_IDENTIFIER, newText.constData(), newText.size(), leftTk.lineno, true); result.f.whitespace = leftTk.whitespace(); return result; @@ -2032,7 +2035,7 @@ void Preprocessor::startSkippingBlocks(const Preprocessor::PPToken &tk) const if (!m_client) return; - int iter = tk.end(); + int iter = tk.bytesEnd(); const QByteArray &txt = tk.source(); for (; iter < txt.size(); ++iter) { if (txt.at(iter) == '\n') { diff --git a/src/libs/qmljs/qmljsfindexportedcpptypes.cpp b/src/libs/qmljs/qmljsfindexportedcpptypes.cpp index 7034ea64b9..ea7d9cf051 100644 --- a/src/libs/qmljs/qmljsfindexportedcpptypes.cpp +++ b/src/libs/qmljs/qmljsfindexportedcpptypes.cpp @@ -225,8 +225,10 @@ protected: // go through comments backwards to find the annotation closest to the call for (unsigned i = _doc->translationUnit()->commentCount(); i-- > 0; ) { const Token commentToken = _doc->translationUnit()->commentAt(i); - if (commentToken.begin() >= end.begin() || commentToken.end() <= begin.begin()) + if (commentToken.bytesBegin() >= end.bytesBegin() + || commentToken.bytesEnd() <= begin.bytesBegin()) { continue; + } const QString comment = stringOf(commentToken); if (uriAnnotation.indexIn(comment) != -1) { packageName = uriAnnotation.cap(1); @@ -274,7 +276,8 @@ protected: // and the expression const Token begin = translationUnit()->tokenAt(typeId->firstToken()); const Token last = translationUnit()->tokenAt(typeId->lastToken() - 1); - exportedType.typeExpression = QString::fromUtf8(_doc->utf8Source().mid(begin.begin(), last.end() - begin.begin())); + exportedType.typeExpression = QString::fromUtf8( + _doc->utf8Source().mid(begin.bytesBegin(), last.bytesEnd() - begin.bytesBegin())); _exportedTypes += exportedType; @@ -401,12 +404,14 @@ private: { const Token firstToken = translationUnit()->tokenAt(first); const Token lastToken = translationUnit()->tokenAt(last); - return QString::fromUtf8(_doc->utf8Source().mid(firstToken.begin(), lastToken.end() - firstToken.begin())); + return QString::fromUtf8( + _doc->utf8Source().mid(firstToken.bytesBegin(), + lastToken.bytesEnd() - firstToken.bytesBegin())); } QString stringOf(const Token &token) { - return QString::fromUtf8(_doc->utf8Source().mid(token.begin(), token.length())); + return QString::fromUtf8(_doc->utf8Source().mid(token.bytesBegin(), token.bytes())); } ExpressionAST *skipStringCall(ExpressionAST *exp) diff --git a/src/plugins/clangcodemodel/clangcompletion.cpp b/src/plugins/clangcodemodel/clangcompletion.cpp index f1b309239a..5341ba305a 100644 --- a/src/plugins/clangcodemodel/clangcompletion.cpp +++ b/src/plugins/clangcodemodel/clangcompletion.cpp @@ -806,8 +806,8 @@ int ClangCompletionAssistProcessor::startOfOperator(int pos, if (tokens.at(0).is(T_POUND) && tokens.at(1).is(T_IDENTIFIER) && (tokens.at(2).is(T_STRING_LITERAL) || tokens.at(2).is(T_ANGLE_STRING_LITERAL))) { const CPlusPlus::Token &directiveToken = tokens.at(1); - QString directive = tc.block().text().mid(directiveToken.begin(), - directiveToken.length()); + QString directive = tc.block().text().mid(directiveToken.bytesBegin(), + directiveToken.bytes()); if (directive == QLatin1String("include") || directive == QLatin1String("include_next") || directive == QLatin1String("import")) { @@ -885,7 +885,8 @@ bool ClangCompletionAssistProcessor::accepts() const const QString &line = tc.block().text(); const CPlusPlus::Token &idToken = tokens.at(1); const QStringRef &identifier = - line.midRef(idToken.begin(), idToken.end() - idToken.begin()); + line.midRef(idToken.bytesBegin(), + idToken.bytesEnd() - idToken.bytesBegin()); if (identifier == QLatin1String("include") || identifier == QLatin1String("include_next") || (m_interface->objcEnabled() && identifier == QLatin1String("import"))) { diff --git a/src/plugins/cppeditor/cppautocompleter.cpp b/src/plugins/cppeditor/cppautocompleter.cpp index b8a55fdc8f..dab75da701 100644 --- a/src/plugins/cppeditor/cppautocompleter.cpp +++ b/src/plugins/cppeditor/cppautocompleter.cpp @@ -72,7 +72,7 @@ bool CppAutoCompleter::contextAllowsElectricCharacters(const QTextCursor &cursor if (token.isStringLiteral() || token.isCharLiteral()) { const unsigned pos = cursor.selectionEnd() - cursor.block().position(); - if (pos <= token.end()) + if (pos <= token.bytesEnd()) return false; } @@ -115,10 +115,10 @@ bool CppAutoCompleter::isInCommentHelper(const QTextCursor &cursor, Token *retTo const unsigned pos = cursor.selectionEnd() - cursor.block().position(); - if (tokens.isEmpty() || pos < tokens.first().begin()) + if (tokens.isEmpty() || pos < tokens.first().bytesBegin()) return prevState > 0; - if (pos >= tokens.last().end()) { + if (pos >= tokens.last().bytesEnd()) { const Token tk = tokens.last(); if (tk.is(T_CPP_COMMENT) || tk.is(T_CPP_DOXY_COMMENT)) return true; @@ -137,7 +137,7 @@ const Token CppAutoCompleter::tokenAtPosition(const QList<Token> &tokens, const { for (int i = tokens.size() - 1; i >= 0; --i) { const Token tk = tokens.at(i); - if (pos >= tk.begin() && pos < tk.end()) + if (pos >= tk.bytesBegin() && pos < tk.bytesEnd()) return tk; } return Token(); diff --git a/src/plugins/cppeditor/cppcodemodelinspectordialog.cpp b/src/plugins/cppeditor/cppcodemodelinspectordialog.cpp index 184d6e9de3..706decd32d 100644 --- a/src/plugins/cppeditor/cppcodemodelinspectordialog.cpp +++ b/src/plugins/cppeditor/cppcodemodelinspectordialog.cpp @@ -821,8 +821,8 @@ public: void clear(); enum Columns { SpelledColumn, KindColumn, IndexColumn, OffsetColumn, LineColumnNumberColumn, - LengthColumn, GeneratedColumn, ExpandedColumn, WhiteSpaceColumn, NewlineColumn, - ColumnCount }; + LengthInBytesColumn, GeneratedColumn, ExpandedColumn, WhiteSpaceColumn, + NewlineColumn, ColumnCount }; int rowCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const; @@ -852,7 +852,7 @@ void TokensModel::configure(CPlusPlus::TranslationUnit *translationUnit) for (int i = 0, total = translationUnit->tokenCount(); i < total; ++i) { TokenInfo info; info.token = translationUnit->tokenAt(i); - translationUnit->getPosition(info.token.begin(), &info.line, &info.column); + translationUnit->getPosition(info.token.bytesBegin(), &info.line, &info.column); m_tokenInfos.append(info); } emit layoutChanged(); @@ -888,12 +888,12 @@ QVariant TokensModel::data(const QModelIndex &index, int role) const else if (column == IndexColumn) return index.row(); else if (column == OffsetColumn) - return token.begin(); + return token.bytesBegin(); else if (column == LineColumnNumberColumn) return QString::fromLatin1("%1:%2") .arg(CMI::Utils::toString(info.line), CMI::Utils::toString(info.column)); - else if (column == LengthColumn) - return CMI::Utils::toString(token.length()); + else if (column == LengthInBytesColumn) + return CMI::Utils::toString(token.bytes()); else if (column == GeneratedColumn) return CMI::Utils::toString(token.generated()); else if (column == ExpandedColumn) @@ -922,8 +922,8 @@ QVariant TokensModel::headerData(int section, Qt::Orientation orientation, int r return QLatin1String("Offset"); case LineColumnNumberColumn: return QLatin1String("Line:Column"); - case LengthColumn: - return QLatin1String("Length"); + case LengthInBytesColumn: + return QLatin1String("Bytes"); case GeneratedColumn: return QLatin1String("Generated"); case ExpandedColumn: diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp index 3a7bc93cd0..36e49af5f9 100644 --- a/src/plugins/cppeditor/cppeditor.cpp +++ b/src/plugins/cppeditor/cppeditor.cpp @@ -794,7 +794,7 @@ void CPPEditorWidget::markSymbolsNow() if (column) --column; // adjust the column position. - const int len = unit->tokenAt(index).length(); + const int len = unit->tokenAt(index).bytes(); QTextCursor cursor(document()->findBlockByNumber(line - 1)); cursor.setPosition(cursor.position() + column); diff --git a/src/plugins/cppeditor/cppfollowsymbolundercursor.cpp b/src/plugins/cppeditor/cppfollowsymbolundercursor.cpp index c50bdb6c4d..0d7b40560e 100644 --- a/src/plugins/cppeditor/cppfollowsymbolundercursor.cpp +++ b/src/plugins/cppeditor/cppfollowsymbolundercursor.cpp @@ -479,7 +479,8 @@ BaseTextEditorWidget::Link FollowSymbolUnderCursor::findLink(const QTextCursor & for (int i = 0; i < tokens.size(); ++i) { const Token &tk = tokens.at(i); - if (((unsigned) positionInBlock) >= tk.begin() && ((unsigned) positionInBlock) < tk.end()) { + if (((unsigned) positionInBlock) >= tk.bytesBegin() + && ((unsigned) positionInBlock) < tk.bytesEnd()) { int closingParenthesisPos = tokens.size(); if (i >= 2 && tokens.at(i).is(T_IDENTIFIER) && tokens.at(i - 1).is(T_LPAREN) && (tokens.at(i - 2).is(T_SIGNAL) || tokens.at(i - 2).is(T_SLOT))) { @@ -503,10 +504,10 @@ BaseTextEditorWidget::Link FollowSymbolUnderCursor::findLink(const QTextCursor & if (closingParenthesisPos < tokens.size()) { QTextBlock block = cursor.block(); - beginOfToken = block.position() + tokens.at(i).begin(); - endOfToken = block.position() + tokens.at(i).end(); + beginOfToken = block.position() + tokens.at(i).bytesBegin(); + endOfToken = block.position() + tokens.at(i).bytesEnd(); - tc.setPosition(block.position() + tokens.at(closingParenthesisPos).end()); + tc.setPosition(block.position() + tokens.at(closingParenthesisPos).bytesEnd()); recognizedQtMethod = true; } break; @@ -521,7 +522,8 @@ BaseTextEditorWidget::Link FollowSymbolUnderCursor::findLink(const QTextCursor & // In this case we want to look at one token before the current position to recognize // an operator if the cursor is inside the actual operator: operator[$] - if (unsigned(positionInBlock) >= tk.begin() && unsigned(positionInBlock) <= tk.end()) { + if (unsigned(positionInBlock) >= tk.bytesBegin() + && unsigned(positionInBlock) <= tk.bytesEnd()) { cursorRegionReached = true; if (tk.is(T_OPERATOR)) { link = attemptFuncDeclDef(cursor, m_widget, theSnapshot, @@ -531,7 +533,7 @@ BaseTextEditorWidget::Link FollowSymbolUnderCursor::findLink(const QTextCursor & } else if (tk.isOperator() && i > 0 && tokens.at(i - 1).is(T_OPERATOR)) { QTextCursor c = cursor; c.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor, - positionInBlock - tokens.at(i - 1).begin()); + positionInBlock - tokens.at(i - 1).bytesBegin()); link = attemptFuncDeclDef(c, m_widget, theSnapshot, documentFromSemanticInfo, symbolFinder); if (link.hasValidLinkText()) @@ -560,8 +562,8 @@ BaseTextEditorWidget::Link FollowSymbolUnderCursor::findLink(const QTextCursor & const Token tk = SimpleLexer::tokenAt(block.text(), pos, BackwardsScanner::previousBlockState(block), true); - beginOfToken = block.position() + tk.begin(); - endOfToken = block.position() + tk.end(); + beginOfToken = block.position() + tk.bytesBegin(); + endOfToken = block.position() + tk.bytesEnd(); // Handle include directives if (tk.is(T_STRING_LITERAL) || tk.is(T_ANGLE_STRING_LITERAL)) { diff --git a/src/plugins/cppeditor/cppfunctiondecldeflink.cpp b/src/plugins/cppeditor/cppfunctiondecldeflink.cpp index 304c998d31..0e81015180 100644 --- a/src/plugins/cppeditor/cppfunctiondecldeflink.cpp +++ b/src/plugins/cppeditor/cppfunctiondecldeflink.cpp @@ -414,17 +414,17 @@ static bool hasCommentedName( // maybe in a comment but in the right spot? int nameStart = 0; if (param->declarator) - nameStart = unit->tokenAt(param->declarator->lastToken() - 1).end(); + nameStart = unit->tokenAt(param->declarator->lastToken() - 1).bytesEnd(); else if (param->type_specifier_list) - nameStart = unit->tokenAt(param->type_specifier_list->lastToken() - 1).end(); + nameStart = unit->tokenAt(param->type_specifier_list->lastToken() - 1).bytesEnd(); else - nameStart = unit->tokenAt(param->firstToken()).begin(); + nameStart = unit->tokenAt(param->firstToken()).bytesBegin(); int nameEnd = 0; if (param->equal_token) - nameEnd = unit->tokenAt(param->equal_token).begin(); + nameEnd = unit->tokenAt(param->equal_token).bytesBegin(); else - nameEnd = unit->tokenAt(param->lastToken()).begin(); // one token after + nameEnd = unit->tokenAt(param->lastToken()).bytesBegin(); // one token after QString text = source.mid(nameStart, nameEnd - nameStart); diff --git a/src/plugins/cppeditor/cpphighlighter.cpp b/src/plugins/cppeditor/cpphighlighter.cpp index fe1bfb89d5..ba63117ea9 100644 --- a/src/plugins/cppeditor/cpphighlighter.cpp +++ b/src/plugins/cppeditor/cpphighlighter.cpp @@ -108,7 +108,7 @@ void CppHighlighter::highlightBlock(const QString &text) return; } - const unsigned firstNonSpace = tokens.first().begin(); + const unsigned firstNonSpace = tokens.first().bytesBegin(); Parentheses parentheses; parentheses.reserve(20); // assume wizard level ;-) @@ -122,29 +122,32 @@ void CppHighlighter::highlightBlock(const QString &text) unsigned previousTokenEnd = 0; if (i != 0) { // mark the whitespaces - previousTokenEnd = tokens.at(i - 1).begin() + - tokens.at(i - 1).length(); + previousTokenEnd = tokens.at(i - 1).bytesBegin() + + tokens.at(i - 1).bytes(); } - if (previousTokenEnd != tk.begin()) - setFormat(previousTokenEnd, tk.begin() - previousTokenEnd, formatForCategory(CppVisualWhitespace)); + if (previousTokenEnd != tk.bytesBegin()) { + setFormat(previousTokenEnd, + tk.bytesBegin() - previousTokenEnd, + formatForCategory(CppVisualWhitespace)); + } if (tk.is(T_LPAREN) || tk.is(T_LBRACE) || tk.is(T_LBRACKET)) { - const QChar c = text.at(tk.begin()); - parentheses.append(Parenthesis(Parenthesis::Opened, c, tk.begin())); + const QChar c = text.at(tk.bytesBegin()); + parentheses.append(Parenthesis(Parenthesis::Opened, c, tk.bytesBegin())); if (tk.is(T_LBRACE)) { ++braceDepth; // if a folding block opens at the beginning of a line, treat the entire line // as if it were inside the folding block - if (tk.begin() == firstNonSpace) { + if (tk.bytesBegin() == firstNonSpace) { ++foldingIndent; BaseTextDocumentLayout::userData(currentBlock())->setFoldingStartIncluded(true); } } } else if (tk.is(T_RPAREN) || tk.is(T_RBRACE) || tk.is(T_RBRACKET)) { - const QChar c = text.at(tk.begin()); - parentheses.append(Parenthesis(Parenthesis::Closed, c, tk.begin())); + const QChar c = text.at(tk.bytesBegin()); + parentheses.append(Parenthesis(Parenthesis::Closed, c, tk.bytesBegin())); if (tk.is(T_RBRACE)) { --braceDepth; if (braceDepth < foldingIndent) { @@ -166,12 +169,14 @@ void CppHighlighter::highlightBlock(const QString &text) continue; if (i == 0 && tk.is(T_POUND)) { - highlightLine(text, tk.begin(), tk.length(), formatForCategory(CppPreprocessorFormat)); + highlightLine(text, tk.bytesBegin(), tk.bytes(), + formatForCategory(CppPreprocessorFormat)); expectPreprocessorKeyword = true; - } else if (highlightCurrentWordAsPreprocessor && - (tk.isKeyword() || tk.is(T_IDENTIFIER)) && isPPKeyword(text.midRef(tk.begin(), tk.length()))) { - setFormat(tk.begin(), tk.length(), formatForCategory(CppPreprocessorFormat)); - const QStringRef ppKeyword = text.midRef(tk.begin(), tk.length()); + } else if (highlightCurrentWordAsPreprocessor + && (tk.isKeyword() || tk.is(T_IDENTIFIER)) + && isPPKeyword(text.midRef(tk.bytesBegin(), tk.bytes()))) { + setFormat(tk.bytesBegin(), tk.bytes(), formatForCategory(CppPreprocessorFormat)); + const QStringRef ppKeyword = text.midRef(tk.bytesBegin(), tk.bytes()); if (ppKeyword == QLatin1String("error") || ppKeyword == QLatin1String("warning") || ppKeyword == QLatin1String("pragma")) { @@ -179,16 +184,18 @@ void CppHighlighter::highlightBlock(const QString &text) } } else if (tk.is(T_NUMERIC_LITERAL)) { - setFormat(tk.begin(), tk.length(), formatForCategory(CppNumberFormat)); + setFormat(tk.bytesBegin(), tk.bytes(), formatForCategory(CppNumberFormat)); } else if (tk.isStringLiteral() || tk.isCharLiteral()) { - highlightLine(text, tk.begin(), tk.length(), formatForCategory(CppStringFormat)); + highlightLine(text, tk.bytesBegin(), tk.bytes(), formatForCategory(CppStringFormat)); } else if (tk.isComment()) { - const int startPosition = initialLexerState ? previousTokenEnd : tk.begin(); - if (tk.is(T_COMMENT) || tk.is(T_CPP_COMMENT)) - highlightLine(text, startPosition, tk.end() - startPosition, formatForCategory(CppCommentFormat)); + const int startPosition = initialLexerState ? previousTokenEnd : tk.bytesBegin(); + if (tk.is(T_COMMENT) || tk.is(T_CPP_COMMENT)) { + highlightLine(text, startPosition, tk.bytesEnd() - startPosition, + formatForCategory(CppCommentFormat)); + } else // a doxygen comment - highlightDoxygenComment(text, startPosition, tk.end() - startPosition); + highlightDoxygenComment(text, startPosition, tk.bytesEnd() - startPosition); // we need to insert a close comment parenthesis, if // - the line starts in a C Comment (initalState != 0) @@ -201,26 +208,28 @@ void CppHighlighter::highlightBlock(const QString &text) BaseTextDocumentLayout::userData(currentBlock())->setFoldingEndIncluded(true); else foldingIndent = qMin(braceDepth, foldingIndent); - const int tokenEnd = tk.begin() + tk.length() - 1; + const int tokenEnd = tk.bytesBegin() + tk.bytes() - 1; parentheses.append(Parenthesis(Parenthesis::Closed, QLatin1Char('-'), tokenEnd)); // clear the initial state. initialLexerState = 0; } - } else if (tk.isKeyword() || CppTools::isQtKeyword(text.midRef(tk.begin(), tk.length())) || tk.isObjCAtKeyword()) { - setFormat(tk.begin(), tk.length(), formatForCategory(CppKeywordFormat)); + } else if (tk.isKeyword() + || CppTools::isQtKeyword(text.midRef(tk.bytesBegin(), tk.bytes())) + || tk.isObjCAtKeyword()) { + setFormat(tk.bytesBegin(), tk.bytes(), formatForCategory(CppKeywordFormat)); } else if (tk.isOperator()) { - setFormat(tk.begin(), tk.length(), formatForCategory(CppOperatorFormat)); + setFormat(tk.bytesBegin(), tk.bytes(), formatForCategory(CppOperatorFormat)); } else if (i == 0 && tokens.size() > 1 && tk.is(T_IDENTIFIER) && tokens.at(1).is(T_COLON)) { - setFormat(tk.begin(), tk.length(), formatForCategory(CppLabelFormat)); + setFormat(tk.bytesBegin(), tk.bytes(), formatForCategory(CppLabelFormat)); } else if (tk.is(T_IDENTIFIER)) { - highlightWord(text.midRef(tk.begin(), tk.length()), tk.begin(), tk.length()); + highlightWord(text.midRef(tk.bytesBegin(), tk.bytes()), tk.bytesBegin(), tk.bytes()); } } // mark the trailing white spaces - const int lastTokenEnd = tokens.last().end(); + const int lastTokenEnd = tokens.last().bytesEnd(); if (text.length() > lastTokenEnd) highlightLine(text, lastTokenEnd, text.length() - lastTokenEnd, formatForCategory(CppVisualWhitespace)); @@ -228,7 +237,7 @@ void CppHighlighter::highlightBlock(const QString &text) const Token &lastToken = tokens.last(); if (lastToken.is(T_COMMENT) || lastToken.is(T_DOXY_COMMENT)) { parentheses.append(Parenthesis(Parenthesis::Opened, QLatin1Char('+'), - lastToken.begin())); + lastToken.bytesBegin())); ++braceDepth; } } diff --git a/src/plugins/cppeditor/fileandtokenactions_test.cpp b/src/plugins/cppeditor/fileandtokenactions_test.cpp index 9483e92166..e3693bf34a 100644 --- a/src/plugins/cppeditor/fileandtokenactions_test.cpp +++ b/src/plugins/cppeditor/fileandtokenactions_test.cpp @@ -238,7 +238,7 @@ TestActionsTestCase::TestActionsTestCase(const Actions &tokenActions, const Acti } else { // Position the cursor on the token unsigned line, column; - translationUnit->getPosition(token.begin(), &line, &column); + translationUnit->getPosition(token.bytesBegin(), &line, &column); editor->gotoLine(line, column - 1); QApplication::processEvents(); @@ -291,7 +291,7 @@ void TestActionsTestCase::moveWordCamelCaseToToken(TranslationUnit *translationU QVERIFY(editorWidget); unsigned line, column; - translationUnit->getPosition(token.begin(), &line, &column); + translationUnit->getPosition(token.bytesBegin(), &line, &column); while (editor->currentLine() < (int) line || (editor->currentLine() == (int) line diff --git a/src/plugins/cpptools/cppchecksymbols.cpp b/src/plugins/cpptools/cppchecksymbols.cpp index cd15842188..0264b7a5e7 100644 --- a/src/plugins/cpptools/cppchecksymbols.cpp +++ b/src/plugins/cpptools/cppchecksymbols.cpp @@ -356,7 +356,7 @@ bool CheckSymbols::warning(AST *ast, const QString &text) const Token &firstToken = tokenAt(ast->firstToken()); const Token &lastToken = tokenAt(ast->lastToken() - 1); - const unsigned length = lastToken.end() - firstToken.begin(); + const unsigned length = lastToken.bytesEnd() - firstToken.bytesBegin(); unsigned line = 1, column = 1; getTokenStartPosition(ast->firstToken(), &line, &column); @@ -476,7 +476,7 @@ bool CheckSymbols::visit(NamespaceAST *ast) if (!tok.generated()) { unsigned line, column; getTokenStartPosition(ast->identifier_token, &line, &column); - Result use(line, column, tok.length(), CppHighlightingSupport::TypeUse); + Result use(line, column, tok.bytes(), CppHighlightingSupport::TypeUse); addUse(use); } } @@ -568,7 +568,8 @@ bool CheckSymbols::visit(MemberAccessAST *ast) if (_potentialFields.contains(id)) { const Token start = tokenAt(ast->firstToken()); const Token end = tokenAt(ast->lastToken() - 1); - const QByteArray expression = _doc->utf8Source().mid(start.begin(), end.end() - start.begin()); + const QByteArray expression = _doc->utf8Source() + .mid(start.bytesBegin(), end.bytesEnd() - start.bytesBegin()); const QList<LookupItem> candidates = typeOfExpression(expression, enclosingScope(), TypeOfExpression::Preprocess); @@ -705,7 +706,8 @@ QByteArray CheckSymbols::textOf(AST *ast) const { const Token start = tokenAt(ast->firstToken()); const Token end = tokenAt(ast->lastToken() - 1); - const QByteArray text = _doc->utf8Source().mid(start.begin(), end.end() - start.begin()); + const QByteArray text = _doc->utf8Source().mid(start.bytesBegin(), + end.bytesEnd() - start.bytesBegin()); return text; } @@ -724,8 +726,10 @@ void CheckSymbols::checkNamespace(NameAST *name) } } - const unsigned length = tokenAt(name->lastToken() - 1).end() - tokenAt(name->firstToken()).begin(); - warning(line, column, QCoreApplication::translate("CPlusPlus::CheckSymbols", "Expected a namespace-name"), length); + const unsigned length = tokenAt(name->lastToken() - 1).bytesEnd() + - tokenAt(name->firstToken()).bytesBegin(); + warning(line, column, QCoreApplication::translate("CPlusPlus::CheckSymbols", + "Expected a namespace-name"), length); } bool CheckSymbols::hasVirtualDestructor(Class *klass) const @@ -1112,7 +1116,7 @@ void CheckSymbols::addUse(unsigned tokenIndex, Kind kind) unsigned line, column; getTokenStartPosition(tokenIndex, &line, &column); - const unsigned length = tok.length(); + const unsigned length = tok.bytes(); const Result use(line, column, length, kind); addUse(use); @@ -1149,7 +1153,7 @@ void CheckSymbols::addType(ClassOrNamespace *b, NameAST *ast) unsigned line, column; getTokenStartPosition(startToken, &line, &column); - const unsigned length = tok.length(); + const unsigned length = tok.bytes(); const Result use(line, column, length, CppHighlightingSupport::TypeUse); addUse(use); } @@ -1190,7 +1194,7 @@ bool CheckSymbols::maybeAddTypeOrStatic(const QList<LookupItem> &candidates, Nam unsigned line, column; getTokenStartPosition(startToken, &line, &column); - const unsigned length = tok.length(); + const unsigned length = tok.bytes(); Kind kind = CppHighlightingSupport::TypeUse; if (c->enclosingEnum() != 0) @@ -1232,7 +1236,7 @@ bool CheckSymbols::maybeAddField(const QList<LookupItem> &candidates, NameAST *a unsigned line, column; getTokenStartPosition(startToken, &line, &column); - const unsigned length = tok.length(); + const unsigned length = tok.bytes(); const Result use(line, column, length, CppHighlightingSupport::FieldUse); addUse(use); @@ -1316,7 +1320,7 @@ bool CheckSymbols::maybeAddFunction(const QList<LookupItem> &candidates, NameAST unsigned line, column; getTokenStartPosition(startToken, &line, &column); - const unsigned length = tok.length(); + const unsigned length = tok.bytes(); // Add a diagnostic message if argument count does not match if (matchType == Match_TooFewArgs) diff --git a/src/plugins/cpptools/cppcodeformatter.cpp b/src/plugins/cpptools/cppcodeformatter.cpp index 9ee2fa8815..4d98a0c1c2 100644 --- a/src/plugins/cpptools/cppcodeformatter.cpp +++ b/src/plugins/cpptools/cppcodeformatter.cpp @@ -1012,7 +1012,7 @@ int CodeFormatter::column(int index) const QStringRef CodeFormatter::currentTokenText() const { - return m_currentLine.midRef(m_currentToken.begin(), m_currentToken.length()); + return m_currentLine.midRef(m_currentToken.bytesBegin(), m_currentToken.bytes()); } void CodeFormatter::turnInto(int newState) @@ -1189,10 +1189,10 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd const Token &tk = currentToken(); const bool firstToken = (tokenIndex() == 0); const bool lastToken = (tokenIndex() == tokenCount() - 1); - const int tokenPosition = column(tk.begin()); - const int nextTokenPosition = lastToken ? tokenPosition + tk.length() - : column(tokenAt(tokenIndex() + 1).begin()); - const int spaceOrNextTokenPosition = lastToken ? tokenPosition + tk.length() + 1 + const int tokenPosition = column(tk.bytesBegin()); + const int nextTokenPosition = lastToken ? tokenPosition + tk.bytes() + : column(tokenAt(tokenIndex() + 1).bytesBegin()); + const int spaceOrNextTokenPosition = lastToken ? tokenPosition + tk.bytes() + 1 : nextTokenPosition; if (shouldClearPaddingOnEnter(newState)) @@ -1474,7 +1474,7 @@ void QtStyleCodeFormatter::adjustIndent(const QList<CPlusPlus::Token> &tokens, i if (topState.type == multiline_comment_start || topState.type == multiline_comment_cont) { if (!tokens.isEmpty()) { - *indentDepth = column(tokens.at(0).begin()); + *indentDepth = column(tokens.at(0).bytesBegin()); return; } } diff --git a/src/plugins/cpptools/cppcompletionassist.cpp b/src/plugins/cpptools/cppcompletionassist.cpp index 0b1eff5066..16f4cfbcf6 100644 --- a/src/plugins/cpptools/cppcompletionassist.cpp +++ b/src/plugins/cpptools/cppcompletionassist.cpp @@ -703,7 +703,8 @@ bool CppCompletionAssistProcessor::accepts() const const QString &line = tc.block().text(); const Token &idToken = tokens.at(1); const QStringRef &identifier = - line.midRef(idToken.begin(), idToken.end() - idToken.begin()); + line.midRef(idToken.bytesBegin(), + idToken.bytesEnd() - idToken.bytesBegin()); if (identifier == QLatin1String("include") || identifier == QLatin1String("include_next") || (m_languageFeatures.objCEnabled && identifier == QLatin1String("import"))) { @@ -837,8 +838,8 @@ int CppCompletionAssistProcessor::startOfOperator(int pos, if (tokens.at(0).is(T_POUND) && tokens.at(1).is(T_IDENTIFIER) && (tokens.at(2).is(T_STRING_LITERAL) || tokens.at(2).is(T_ANGLE_STRING_LITERAL))) { const Token &directiveToken = tokens.at(1); - QString directive = tc.block().text().mid(directiveToken.begin(), - directiveToken.length()); + QString directive = tc.block().text().mid(directiveToken.bytesBegin(), + directiveToken.bytes()); if (directive == QLatin1String("include") || directive == QLatin1String("include_next") || directive == QLatin1String("import")) { @@ -991,7 +992,7 @@ bool CppCompletionAssistProcessor::tryObjCCompletion() if (start == tokens.startToken()) return false; - const int startPos = tokens[start].begin() + tokens.startPosition(); + const int startPos = tokens[start].bytesBegin() + tokens.startPosition(); const QString expr = m_interface->textAt(startPos, m_interface->position() - startPos); Document::Ptr thisDocument = m_interface->snapshot().document(m_interface->fileName()); diff --git a/src/plugins/cpptools/cpprefactoringchanges.cpp b/src/plugins/cpptools/cpprefactoringchanges.cpp index 4b416d266d..553b905ac3 100644 --- a/src/plugins/cpptools/cpprefactoringchanges.cpp +++ b/src/plugins/cpptools/cpprefactoringchanges.cpp @@ -199,9 +199,9 @@ ChangeSet::Range CppRefactoringFile::range(unsigned tokenIndex) const { const Token &token = tokenAt(tokenIndex); unsigned line, column; - cppDocument()->translationUnit()->getPosition(token.begin(), &line, &column); + cppDocument()->translationUnit()->getPosition(token.bytesBegin(), &line, &column); const int start = document()->findBlockByNumber(line - 1).position() + column - 1; - return ChangeSet::Range(start, start + token.length()); + return ChangeSet::Range(start, start + token.bytes()); } ChangeSet::Range CppRefactoringFile::range(AST *ast) const @@ -212,7 +212,7 @@ ChangeSet::Range CppRefactoringFile::range(AST *ast) const int CppRefactoringFile::startOf(unsigned index) const { unsigned line, column; - cppDocument()->translationUnit()->getPosition(tokenAt(index).begin(), &line, &column); + cppDocument()->translationUnit()->getPosition(tokenAt(index).bytesBegin(), &line, &column); return document()->findBlockByNumber(line - 1).position() + column - 1; } @@ -224,7 +224,7 @@ int CppRefactoringFile::startOf(const AST *ast) const int CppRefactoringFile::endOf(unsigned index) const { unsigned line, column; - cppDocument()->translationUnit()->getPosition(tokenAt(index).end(), &line, &column); + cppDocument()->translationUnit()->getPosition(tokenAt(index).bytesEnd(), &line, &column); return document()->findBlockByNumber(line - 1).position() + column - 1; } @@ -239,9 +239,9 @@ void CppRefactoringFile::startAndEndOf(unsigned index, int *start, int *end) con { unsigned line, column; Token token(tokenAt(index)); - cppDocument()->translationUnit()->getPosition(token.begin(), &line, &column); + cppDocument()->translationUnit()->getPosition(token.bytesBegin(), &line, &column); *start = document()->findBlockByNumber(line - 1).position() + column - 1; - *end = *start + token.length(); + *end = *start + token.bytes(); } QString CppRefactoringFile::textOf(const AST *ast) const diff --git a/src/plugins/cpptools/doxygengenerator.cpp b/src/plugins/cpptools/doxygengenerator.cpp index 681e33903d..f9f8b0833d 100644 --- a/src/plugins/cpptools/doxygengenerator.cpp +++ b/src/plugins/cpptools/doxygengenerator.cpp @@ -83,7 +83,7 @@ QString DoxygenGenerator::generate(QTextCursor cursor) foreach (const Token &tk, tks) { if (tk.is(T_SEMICOLON) || tk.is(T_LBRACE)) { // No need to continue beyond this, we might already have something meaningful. - cursor.setPosition(block.position() + tk.end(), QTextCursor::KeepAnchor); + cursor.setPosition(block.position() + tk.bytesEnd(), QTextCursor::KeepAnchor); break; } } diff --git a/src/plugins/glsleditor/glslautocompleter.cpp b/src/plugins/glsleditor/glslautocompleter.cpp index 6f247b46f5..9df6140688 100644 --- a/src/plugins/glsleditor/glslautocompleter.cpp +++ b/src/plugins/glsleditor/glslautocompleter.cpp @@ -74,7 +74,7 @@ bool GLSLCompleter::contextAllowsElectricCharacters(const QTextCursor &cursor) c if (tk.isComment()) { const unsigned pos = cursor.selectionEnd() - cursor.block().position(); - if (pos == tk.end()) { + if (pos == tk.bytesEnd()) { if (tk.is(T_CPP_COMMENT) || tk.is(T_CPP_DOXY_COMMENT)) return false; @@ -83,11 +83,11 @@ bool GLSLCompleter::contextAllowsElectricCharacters(const QTextCursor &cursor) c return false; } - if (pos < tk.end()) + if (pos < tk.bytesEnd()) return false; } else if (tk.isStringLiteral() || tk.isCharLiteral()) { const unsigned pos = cursor.selectionEnd() - cursor.block().position(); - if (pos <= tk.end()) + if (pos <= tk.bytesEnd()) return false; } @@ -102,7 +102,7 @@ bool GLSLCompleter::isInComment(const QTextCursor &cursor) const if (tk.isComment()) { const unsigned pos = cursor.selectionEnd() - cursor.block().position(); - if (pos == tk.end()) { + if (pos == tk.bytesEnd()) { if (tk.is(T_CPP_COMMENT) || tk.is(T_CPP_DOXY_COMMENT)) return true; @@ -111,7 +111,7 @@ bool GLSLCompleter::isInComment(const QTextCursor &cursor) const return true; } - if (pos < tk.end()) + if (pos < tk.bytesEnd()) return true; } diff --git a/src/plugins/todo/cpptodoitemsscanner.cpp b/src/plugins/todo/cpptodoitemsscanner.cpp index d4282efca2..a3df596a04 100644 --- a/src/plugins/todo/cpptodoitemsscanner.cpp +++ b/src/plugins/todo/cpptodoitemsscanner.cpp @@ -86,7 +86,7 @@ void CppTodoItemsScanner::processDocument(CPlusPlus::Document::Ptr doc) // Get comment source CPlusPlus::Token token = doc->translationUnit()->commentAt(i); - QByteArray source = doc->utf8Source().mid(token.begin(), token.length()).trimmed(); + QByteArray source = doc->utf8Source().mid(token.bytesBegin(), token.bytes()).trimmed(); if ((token.kind() == CPlusPlus::T_COMMENT) || (token.kind() == CPlusPlus::T_DOXY_COMMENT)) { // Remove trailing "*/" @@ -98,7 +98,7 @@ void CppTodoItemsScanner::processDocument(CPlusPlus::Document::Ptr doc) const QStringList commentLines = QString::fromUtf8(source).split(QLatin1Char('\n'), QString::SkipEmptyParts); unsigned lineNumber = 0; - translationUnit->getPosition(token.begin(), &lineNumber); + translationUnit->getPosition(token.bytesBegin(), &lineNumber); for (int j = 0; j < commentLines.count(); ++j) { const QString &commentLine = commentLines.at(j); processCommentLine(doc->fileName(), commentLine, lineNumber + j, itemList); diff --git a/src/tools/cplusplus-update-frontend/cplusplus-update-frontend.cpp b/src/tools/cplusplus-update-frontend/cplusplus-update-frontend.cpp index eccf1eb4cf..365c3220e2 100644 --- a/src/tools/cplusplus-update-frontend/cplusplus-update-frontend.cpp +++ b/src/tools/cplusplus-update-frontend/cplusplus-update-frontend.cpp @@ -997,7 +997,7 @@ bool checkGenerated(const QTextCursor &cursor, int *doxyStart) if (prevToken.kind() != T_DOXY_COMMENT && prevToken.kind() != T_CPP_DOXY_COMMENT) return false; - *doxyStart = tokens.startPosition() + prevToken.begin(); + *doxyStart = tokens.startPosition() + prevToken.bytesBegin(); return tokens.text(tokens.startToken() - 1).contains(QLatin1String("\\generated")); } diff --git a/tests/manual/plain-cplusplus/Preprocessor.cpp b/tests/manual/plain-cplusplus/Preprocessor.cpp index 5fbc9966f7..376fad153a 100644 --- a/tests/manual/plain-cplusplus/Preprocessor.cpp +++ b/tests/manual/plain-cplusplus/Preprocessor.cpp @@ -279,7 +279,7 @@ void Preprocessor::skipPreprocesorDirective(Token *tk) } StringRef Preprocessor::asStringRef(const Token &tk) const -{ return StringRef(_source.begin() + tk.begin(), tk.length()); } +{ return StringRef(_source.begin() + tk.bytesBegin(), tk.length()); } Preprocessor::Preprocessor(std::ostream &out) : out(out), _lexer(0), inPreprocessorDirective(false) |