summaryrefslogtreecommitdiffstats
path: root/languages/cpp/storeconverter.cpp
blob: 3569bdeaaf4922925b9030ed6be7957e7f79b716 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/***************************************************************************
*   Copyright (C) 2003-2004 by Alexander Dymo                             *
*   [email protected]                                                    *
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*                                                                         *
***************************************************************************/
#include "storeconverter.h"

#include <qvaluelist.h>

#include <kdebug.h>

#include <kdevcoderepository.h>

#include "cppcodecompletion.h"
#include "codeinformationrepository.h"
#include "cppsupportpart.h"

StoreConverter::StoreConverter(CppSupportPart *part, CodeModel *model)
:m_part(part), m_model(model)
{
}

void StoreConverter::PCSClassToCodeModel(const QString &className, const QStringList &/*classScope*/)
{
	QValueList<Catalog*> catalogs = m_part->codeRepository()->registeredCatalogs();
	for (QValueList<Catalog*>::iterator it = catalogs.begin();
	     it != catalogs.end(); ++it)
	{
		Catalog *catalog = *it;
		kdDebug() << "looking in catalog: " << catalog->dbName() << endl;
		
		QValueList<Catalog::QueryArgument> args;
		args << Catalog::QueryArgument( "kind", Tag::Kind_Class );
		args << Catalog::QueryArgument( "name", className );
		QValueList<Tag> tags = catalog->query(args);
		for (QValueList<Tag>::iterator it = tags.begin(); it != tags.end(); ++it )
		{
			Tag& tag = *it;
			kdDebug() << "TAG: " << tag.name() << " in file " << tag.fileName() << endl;
			FileDom file;
			bool addFile = false;
			if (m_model->hasFile(tag.name()))
				file = m_model->fileByName(tag.name());
			else
			{
				file = m_model->create<FileModel>();
				file->setName(tag.fileName());
				addFile = true;
			}
			if (!file->hasClass(tag.name()))
				parseClass(tag, file);
			if (addFile) m_model->addFile(file);
		}
	}
/*    kdDebug() << "m_model class count: " << m_model->globalNamespace()->classList().count() << endl;
    kdDebug() << "m_model file count: " << m_model->fileList().count() << endl;*/
}

void StoreConverter::parseClass(Tag &classTag, FileDom file)
{
	ClassDom klass = m_model->create<ClassModel>();
	klass->setName(classTag.name());
	klass->setFileName(classTag.fileName());
	
	QStringList scope;
	scope.append(classTag.name());
	QValueList<Tag> symbolTags = m_part->codeCompletion()->repository()->
		getTagsInScope(scope, false);
	
//     kdDebug() << "got tags: " << endl;
	for (QValueList<Tag>::iterator sit = symbolTags.begin(); sit != symbolTags.end(); ++sit )
	{
		Tag &symbol = *sit;
//         kdDebug() << symbol.name() << endl;
		
		switch (symbol.kind()) 
		{
		case Tag::Kind_FunctionDeclaration:
			parseFunctionDeclaration(symbol, klass);
			break;
		case Tag::Kind_Variable:
			parseVariable(symbol, klass);
		}
	}
	
	QValueList<Tag> baseClassTags = m_part->codeCompletion()->repository()->getBaseClassList(classTag.name());
	for (QValueList<Tag>::iterator bit = baseClassTags.begin();
	     bit != baseClassTags.end(); ++bit)
		klass->addBaseClass((*bit).name());
	
	file->addClass(klass);
}

void StoreConverter::parseFunctionDeclaration(Tag &fun, ClassDom klass)
{
	FunctionDom function = m_model->create<FunctionModel>();
	function->setName(fun.name());
	function->setFileName(fun.fileName());
	function->setScope(fun.scope());
	
	CppFunction<Tag> cppFun(fun);
	function->setAccess(cppFun.access());
	function->setSignal(cppFun.isSignal());
	function->setSlot(cppFun.isSlot());
	function->setVirtual(cppFun.isVirtual());
	function->setStatic(cppFun.isStatic());
	function->setInline(cppFun.isInline());
	function->setConstant(cppFun.isConst());
	function->setAbstract(cppFun.isPure());
	function->setResultType(cppFun.type());
	
	parseArguments(function, cppFun);
	
	klass->addFunction(function);
}

void StoreConverter::parseVariable(Tag &var, ClassDom klass)
{
	VariableDom variable = m_model->create<VariableModel>();
	variable->setName(var.name());
	variable->setFileName(var.fileName());
	
	CppVariable<Tag> cppVar(var);
	variable->setAccess(cppVar.access());
	variable->setStatic(cppVar.isStatic());
	variable->setType(cppVar.type());
	
	klass->addVariable(variable);
}

void StoreConverter::parseArguments(FunctionDom function, CppFunction<Tag> &cppFun)
{
	QStringList args = cppFun.arguments();
	for (QStringList::const_iterator it = args.constBegin(); it != args.constEnd(); ++it)
	{
		ArgumentDom arg = m_model->create<ArgumentModel>();
		arg->setType(*it);
		arg->setName(cppFun.argumentNames()[args.findIndex(*it)]);
		
		function->addArgument(arg);
	}
}

//kate: indent-mode csands; tab-width 4; space-indent off;