Fix SEGV when hovering on symbols after creating a new project. This resolves issue #40.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
pull/41/head
Michele Calgaro 10 months ago
parent 35fbd60457
commit 46b407f26c
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -2050,14 +2050,13 @@ void CppCodeCompletion::needRecoveryPoints() {
if ( this->d->recoveryPoints.isEmpty() ) { if ( this->d->recoveryPoints.isEmpty() ) {
kdDebug( 9007 ) << "missing recovery-points for file " << m_activeFileName << " they have to be computed now" << endl; kdDebug( 9007 ) << "missing recovery-points for file " << m_activeFileName << " they have to be computed now" << endl;
m_pSupport->backgroundParser() ->lock () m_pSupport->backgroundParser() ->lock();
;
std::vector<CppCodeCompletion> vec; std::vector<CppCodeCompletion> vec;
TranslationUnitAST * ast = *m_pSupport->backgroundParser() ->translationUnit( m_activeFileName ); ParsedFilePointer pTransUnit = m_pSupport->backgroundParser() ->translationUnit( m_activeFileName );
m_pSupport->backgroundParser() ->unlock(); m_pSupport->backgroundParser() ->unlock();
if ( !ast ) { if ( !pTransUnit ) {
kdDebug( 9007 ) << "background-parser is missing the translation-unit. The file needs to be reparsed." << endl; kdDebug( 9007 ) << "background-parser is missing the translation-unit. The file needs to be reparsed." << endl;
m_pSupport->parseFileAndDependencies( m_activeFileName, true ); m_pSupport->parseFileAndDependencies( m_activeFileName, true );
// m_pSupport->mainWindow() ->statusBar() ->message( i18n( "Background-parser is missing the necessary translation-unit. It will be computed, but this completion will fail." ).arg( m_activeFileName ), 2000 ); // m_pSupport->mainWindow() ->statusBar() ->message( i18n( "Background-parser is missing the necessary translation-unit. It will be computed, but this completion will fail." ).arg( m_activeFileName ), 2000 );
@ -2684,70 +2683,74 @@ void CppCodeCompletion::completeText( bool invokedOnDemand /*= false*/ ) {
///@todo is all this necessary? ///@todo is all this necessary?
if ( !recoveredDecl.get() && !recoveredTypeSpec.get() ) { if ( !recoveredDecl.get() && !recoveredTypeSpec.get() ) {
TranslationUnitAST * ast = *m_pSupport->backgroundParser() ->translationUnit( m_activeFileName ); ParsedFilePointer pTransUnit = m_pSupport->backgroundParser() ->translationUnit(m_activeFileName);
if ( AST * node = findNodeAt( ast, line, column ) ) { if (pTransUnit)
kdDebug( 9007 ) << "------------------- AST FOUND --------------------" << endl; {
kdDebug( 9007 ) << "node-kind = " << nodeTypeToString( node->nodeType() ) << endl; TranslationUnitAST *ast = *pTransUnit;
if ( AST * node = findNodeAt( ast, line, column ) ) {
kdDebug( 9007 ) << "------------------- AST FOUND --------------------" << endl;
kdDebug( 9007 ) << "node-kind = " << nodeTypeToString( node->nodeType() ) << endl;
if ( FunctionDefinitionAST * def = functionDefinition( node ) ) { if ( FunctionDefinitionAST * def = functionDefinition( node ) ) {
kdDebug( 9007 ) << "------> found a function definition" << endl; kdDebug( 9007 ) << "------> found a function definition" << endl;
int startLine, startColumn; int startLine, startColumn;
def->getStartPosition( &startLine, &startColumn ); def->getStartPosition( &startLine, &startColumn );
TQString contents = getText( startLine, startColumn, line, showArguments ? nCol : column ); TQString contents = getText( startLine, startColumn, line, showArguments ? nCol : column );
/// @todo remove code duplication /// @todo remove code duplication
int start_expr = expressionAt( contents, contents.length() ); int start_expr = expressionAt( contents, contents.length() );
// kdDebug(9007) << "start_expr = " << start_expr << endl; // kdDebug(9007) << "start_expr = " << start_expr << endl;
if ( start_expr != int( contents.length() ) ) if ( start_expr != int( contents.length() ) )
expr = contents.mid( start_expr, contents.length() - start_expr ).stripWhiteSpace(); expr = contents.mid( start_expr, contents.length() - start_expr ).stripWhiteSpace();
if ( expr.startsWith( "TQ_SIGNAL" ) || expr.startsWith( "TQ_SLOT" ) ) { if ( expr.startsWith( "TQ_SIGNAL" ) || expr.startsWith( "TQ_SLOT" ) ) {
m_completionMode = expr.startsWith( "TQ_SIGNAL" ) ? SignalCompletion : SlotCompletion; m_completionMode = expr.startsWith( "TQ_SIGNAL" ) ? SignalCompletion : SlotCompletion;
showArguments = false; showArguments = false;
int end_expr = start_expr - 1; int end_expr = start_expr - 1;
while ( end_expr > 0 && contents[ end_expr ].isSpace() ) while ( end_expr > 0 && contents[ end_expr ].isSpace() )
--end_expr; --end_expr;
if ( contents[ end_expr ] != ',' ) { if ( contents[ end_expr ] != ',' ) {
expr = TQString(); expr = TQString();
} else {
start_expr = expressionAt( contents, end_expr );
expr = contents.mid( start_expr, end_expr - start_expr ).stripWhiteSpace();
}
} else { } else {
start_expr = expressionAt( contents, end_expr ); int idx = expr.length() - 1;
expr = contents.mid( start_expr, end_expr - start_expr ).stripWhiteSpace(); while ( expr[ idx ].isLetterOrNumber() || expr[ idx ] == '_' )
} --idx;
} else {
int idx = expr.length() - 1; if ( idx != int( expr.length() ) - 1 ) {
while ( expr[ idx ].isLetterOrNumber() || expr[ idx ] == '_' ) ++idx;
--idx; word = expr.mid( idx ).stripWhiteSpace();
expr = expr.left( idx ).stripWhiteSpace();
if ( idx != int( expr.length() ) - 1 ) { }
++idx;
word = expr.mid( idx ).stripWhiteSpace();
expr = expr.left( idx ).stripWhiteSpace();
} }
}
ctx = computeContext( def, line, column, startLine, startColumn ); ctx = computeContext( def, line, column, startLine, startColumn );
TQStringList scope; TQStringList scope;
scopeOfNode( def, scope ); scopeOfNode( def, scope );
this_type = SimpleType( scope, getIncludeFiles() ); this_type = SimpleType( scope, getIncludeFiles() );
if ( scope.size() ) { /* if ( scope.size() ) { /*
SimpleVariable var; SimpleVariable var;
var.type = scope; var.type = scope;
var.name = "this"; var.name = "this";
ctx->add( var );*/ ctx->add( var );*/
//kdDebug(9007) << "add variable " << var.name << " with type " << var.type << endl; //kdDebug(9007) << "add variable " << var.name << " with type " << var.type << endl;
} }
ExpressionInfo exp( expr ); ExpressionInfo exp( expr );
exp.t = ( ExpressionInfo::Type ) ( ExpressionInfo::NormalExpression | ExpressionInfo::TypeExpression ); exp.t = ( ExpressionInfo::Type ) ( ExpressionInfo::NormalExpression | ExpressionInfo::TypeExpression );
type = evaluateExpression( exp, ctx ); type = evaluateExpression( exp, ctx );
}
} }
} }
} }

@ -1699,25 +1699,29 @@ void CppSupportPart::slotNeedTextHint( int line, int column, TQString& textHint
return ; return ;
m_backgroundParser->lock(); m_backgroundParser->lock();
TranslationUnitAST* ast = *m_backgroundParser->translationUnit( m_activeFileName ); ParsedFilePointer pTransUnit = m_backgroundParser->translationUnit(m_activeFileName);
AST* node = 0; if (pTransUnit)
if ( ast && ( node = findNodeAt( ast, line, column ) ) )
{ {
TranslationUnitAST* ast = *pTransUnit;
AST* node = 0;
if ( ast && ( node = findNodeAt( ast, line, column ) ) )
{
while ( node && node->nodeType() != NodeType_FunctionDefinition ) while ( node && node->nodeType() != NodeType_FunctionDefinition )
node = node->parent(); node = node->parent();
if ( node ) if ( node )
{ {
int startLine, startColumn; int startLine, startColumn;
int endLine, endColumn; int endLine, endColumn;
node->getStartPosition( &startLine, &startColumn ); node->getStartPosition( &startLine, &startColumn );
node->getEndPosition( &endLine, &endColumn ); node->getEndPosition( &endLine, &endColumn );
if ( !node->text().isNull() ) if ( !node->text().isNull() )
textHint = node->text(); textHint = node->text();
else else
textHint = m_activeEditor->textLine( startLine ).simplifyWhiteSpace(); textHint = m_activeEditor->textLine( startLine ).simplifyWhiteSpace();
}
} }
} }
m_backgroundParser->unlock(); m_backgroundParser->unlock();

Loading…
Cancel
Save