PHPEntityBase::Ptr_t PHPExpression::Resolve(PHPLookupTable& lookpTable, const wxString& sourceFileName) { if(m_expression.empty()) return PHPEntityBase::Ptr_t(NULL); PHPSourceFile source(m_text); source.SetParseFunctionBody(true); source.SetFilename(sourceFileName); source.Parse(); wxString asString = SimplifyExpression(source, 0); // Now, use the lookup table std::list<PHPExpression::Part>::iterator iter = m_parts.begin(); PHPEntityBase::Ptr_t currentToken(NULL); for(; iter != m_parts.end(); ++iter) { if(!currentToken) { // first token currentToken = lookpTable.FindScope(iter->m_text); } else { // load the children of the current token (optionally, filter by the text) currentToken = lookpTable.FindMemberOf(currentToken->GetDbId(), iter->m_text); } if(!currentToken) { // return NULL return currentToken; } } return currentToken; }
PHPEntityBase::Ptr_t PHPExpression::Resolve(PHPLookupTable& lookpTable, const wxString& sourceFileName) { if(m_expression.empty()) return PHPEntityBase::Ptr_t(NULL); m_sourceFile.reset(new PHPSourceFile(m_text)); m_sourceFile->SetParseFunctionBody(true); m_sourceFile->SetFilename(sourceFileName); m_sourceFile->Parse(); if(m_expression.size() == 1 && m_expression.at(0).type == kPHP_T_NS_SEPARATOR) { // user typed '\' return lookpTable.FindScope("\\"); } wxString asString = DoSimplifyExpression(0, m_sourceFile); wxUnusedVar(asString); if(m_parts.empty() && !m_filter.IsEmpty()) { // We have no expression, but the user did type something... // Return the parent scope of what the user typed so far if(m_filter.Contains("\\")) { // A namespace separator was found in the filter, break // the filter into 2: // scope + filter wxString scopePart = m_filter.BeforeLast('\\'); if(!scopePart.StartsWith("\\")) { scopePart.Prepend("\\"); } wxString filterPart = m_filter.AfterLast('\\'); // Adjust the filter m_filter.swap(filterPart); // Fix the scope part scopePart = m_sourceFile->MakeIdentifierAbsolute(scopePart); return lookpTable.FindScope(scopePart); } else { // No namespace separator was typed // try to guess: // if the m_filter contains "(" -> user wants a global functions // else we use the current file scope return lookpTable.FindScope(m_sourceFile->Namespace()->GetFullName()); } } // Now, use the lookup table std::list<PHPExpression::Part>::iterator iter = m_parts.begin(); PHPEntityBase::Ptr_t currentToken(NULL); PHPEntityBase::Ptr_t parentToken(NULL); for(; iter != m_parts.end(); ++iter) { Part& part = *iter; if(!currentToken) { // first token // Check locks first if(part.m_text.StartsWith("$") && m_sourceFile->CurrentScope()) { // a variable currentToken = m_sourceFile->CurrentScope()->FindChild(part.m_text); } if(!currentToken) { currentToken = lookpTable.FindScope(part.m_text); if(!currentToken) { // If we are inside a namespace, try prepending the namespace // to the first token if(m_sourceFile->Namespace() && m_sourceFile->Namespace()->GetFullName() != "\\") { // Not the global namespace wxString fullns = PHPEntityNamespace::BuildNamespace(m_sourceFile->Namespace()->GetFullName(), part.m_text); // Check if it exists PHPEntityBase::Ptr_t pGuess = lookpTable.FindScope(fullns); if(pGuess) { currentToken = pGuess; part.m_text = fullns; } else { // Maybe its a global function.. currentToken = lookpTable.FindFunction(part.m_text); } } else { // Maybe its a global function.. currentToken = lookpTable.FindFunction(part.m_text); } } } } else { // load the children of the current token (optionally, filter by the text) currentToken = lookpTable.FindMemberOf(currentToken->GetDbId(), part.m_text); if(currentToken && currentToken->Is(kEntityTypeFunctionAlias)) { // If the member is a function-alias, use the actual function instead currentToken = currentToken->Cast<PHPEntityFunctionAlias>()->GetFunc(); } } // If the current "part" of the expression ends with a scope resolving operator ("::") or // an object operator ("->") we need to resolve the operator to the actual type ( // incase of a functin it will be the return value, and in case of a variable it will be // the type hint) if(currentToken) { if(part.m_operator == kPHP_T_OBJECT_OPERATOR || part.m_operator == kPHP_T_PAAMAYIM_NEKUDOTAYIM) { wxString actualType; if(currentToken->Is(kEntityTypeFunction)) { // return the function return value actualType = currentToken->Cast<PHPEntityFunction>()->GetReturnValue(); } else if(currentToken->Is(kEntityTypeVariable)) { // return the type hint actualType = currentToken->Cast<PHPEntityVariable>()->GetTypeHint(); } wxString fixedpath; if(!actualType.IsEmpty() && FixReturnValueNamespace(lookpTable, parentToken, actualType, fixedpath)) { actualType.swap(fixedpath); } if(!actualType.IsEmpty()) { currentToken = lookpTable.FindScope(actualType); } } } if(!currentToken) { // return NULL return currentToken; } parentToken = currentToken; } return currentToken; }