File indexing completed on 2024-05-19 04:42:00

0001 /*
0002     SPDX-FileCopyrightText: 2014 Denis Steckelmacher <steckdenis@yahoo.fr>
0003 
0004     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 
0007 #include "functiondeclaration.h"
0008 #include <language/duchain/duchainregister.h>
0009 
0010 namespace QmlJS {
0011 
0012 FunctionDeclaration::FunctionDeclaration(const FunctionDeclaration& rhs)
0013 : KDevelop::FunctionDeclaration(*new FunctionDeclarationData(*rhs.d_func()))
0014 {
0015 }
0016 
0017 FunctionDeclaration::FunctionDeclaration(const KDevelop::RangeInRevision& range,
0018                                          KDevelop::DUContext* context)
0019 : KDevelop::FunctionDeclaration(*new FunctionDeclarationData, range)
0020 {
0021     d_func_dynamic()->setClassId(this);
0022 
0023     if (context) {
0024         setContext(context);
0025     }
0026 }
0027 
0028 FunctionDeclaration::FunctionDeclaration(FunctionDeclarationData& data)
0029 : KDevelop::FunctionDeclaration(data)
0030 {
0031 }
0032 
0033 FunctionDeclaration::~FunctionDeclaration()
0034 {
0035 }
0036 
0037 KDevelop::DUContext* FunctionDeclaration::prototypeContext() const
0038 {
0039     return d_func()->m_prototypeContext.context();
0040 }
0041 
0042 void FunctionDeclaration::setPrototypeContext(KDevelop::DUContext* context)
0043 {
0044     DUCHAIN_D_DYNAMIC(FunctionDeclaration);
0045 
0046     d->m_prototypeContext = KDevelop::IndexedDUContext(context);
0047 
0048     // HACK: Also set the internal function context of this function to "context",
0049     //       so that importing functions work (DUContext::Import::context(), when
0050     //       given a FunctionDeclaration, returns its internalFunctionContext)
0051     if (context->type() == KDevelop::DUContext::Function) {
0052         // NOTE: type != Function when the internal context of an object is assigned
0053         //       to one of its members. Skipping this hack is not a problem in that
0054         //       case because one never writes:
0055         //          o.member = function(){}; var v = new o.member();
0056         setInternalFunctionContext(context);
0057     }
0058 }
0059 
0060 }
0061 
0062 DUCHAIN_DEFINE_TYPE(QmlJS::FunctionDeclaration)