apply clang-format

This commit is contained in:
mlangkabel
2021-01-25 20:19:36 +01:00
parent c87af4a3b1
commit 0251b6d8a7
34 changed files with 3492 additions and 3621 deletions
+82
View File
@@ -0,0 +1,82 @@
AccessModifierOffset: -4
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignConsecutiveMacros: false
AlignEscapedNewlines: Right
AlignOperands: false
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: false
BinPackParameters: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Allman
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeComma
BreakInheritanceList: BeforeComma
BreakStringLiterals: true
ColumnLimit: 140
CompactNamespaces: true
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
FixNamespaceComments: true
IncludeBlocks: Preserve
IndentCaseLabels: false
IndentPPDirectives: AfterHash
IndentWidth: 4
IndentWrappedFunctionNames: true
KeepEmptyLinesAtTheStartOfBlocks: false
MaxEmptyLinesToKeep: 2
NamespaceIndentation: None
PenaltyBreakAssignment: 50
PenaltyBreakBeforeFirstCallParameter: 0
PenaltyBreakComment: 100
PenaltyBreakFirstLessLess: 200
PenaltyBreakString: 100
PenaltyBreakTemplateDeclaration: 0
PenaltyExcessCharacter: 10
PenaltyReturnTypeOnItsOwnLine: 1000
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: true
SpaceBeforeCtorInitializerColon: false
SpaceBeforeInheritanceColon: false
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: false
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 4
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: c++17
TabWidth: 4
UseTab: Always
---
Language: Cpp
---
Language: Java
#BasedOnStyle: Google
#BreakAfterJavaFieldAnnotations: true
+37 -37
View File
@@ -1,18 +1,18 @@
/*
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SOURCETRAIL_DATABASE_STORAGE_H
#define SOURCETRAIL_DATABASE_STORAGE_H
@@ -35,16 +35,16 @@
namespace sourcetrail
{
/**
/**
* Class wrapping the write and update interface of the Sourcetrail database.
*
* The DatabaseStorage provides the interface for writing and updating the Sourcetrail database. This interface only
* knows about basic data types, more elaborate types like enums, structs and classes need to be converted to basic
* types before using this interface.
*/
class DatabaseStorage
{
public:
class DatabaseStorage
{
public:
static int getSupportedDatabaseVersion();
static std::unique_ptr<DatabaseStorage> openDatabase(const std::string& dbFilePath);
~DatabaseStorage();
@@ -81,7 +81,7 @@ namespace sourcetrail
return doGetAll<ResultType>("");
}
private:
private:
DatabaseStorage() = default;
void setupTables();
@@ -123,24 +123,24 @@ namespace sourcetrail
CppSQLite3Statement m_findErrorStatement;
CppSQLite3Statement m_insertErrorStatement;
CppSQLite3Statement m_insertOrUpdateMetaValueStmt;
};
};
template <>
std::vector<StorageEdge> DatabaseStorage::doGetAll<StorageEdge>(const std::string& query) const;
template <>
std::vector<StorageNode> DatabaseStorage::doGetAll<StorageNode>(const std::string& query) const;
template <>
std::vector<StorageSymbol> DatabaseStorage::doGetAll<StorageSymbol>(const std::string& query) const;
template <>
std::vector<StorageFile> DatabaseStorage::doGetAll<StorageFile>(const std::string& query) const;
template <>
std::vector<StorageLocalSymbol> DatabaseStorage::doGetAll<StorageLocalSymbol>(const std::string& query) const;
template <>
std::vector<StorageSourceLocation> DatabaseStorage::doGetAll<StorageSourceLocation>(const std::string& query) const;
template <>
std::vector<StorageOccurrence> DatabaseStorage::doGetAll<StorageOccurrence>(const std::string& query) const;
template <>
std::vector<StorageError> DatabaseStorage::doGetAll<StorageError>(const std::string& query) const;
}
template <>
std::vector<StorageEdge> DatabaseStorage::doGetAll<StorageEdge>(const std::string& query) const;
template <>
std::vector<StorageNode> DatabaseStorage::doGetAll<StorageNode>(const std::string& query) const;
template <>
std::vector<StorageSymbol> DatabaseStorage::doGetAll<StorageSymbol>(const std::string& query) const;
template <>
std::vector<StorageFile> DatabaseStorage::doGetAll<StorageFile>(const std::string& query) const;
template <>
std::vector<StorageLocalSymbol> DatabaseStorage::doGetAll<StorageLocalSymbol>(const std::string& query) const;
template <>
std::vector<StorageSourceLocation> DatabaseStorage::doGetAll<StorageSourceLocation>(const std::string& query) const;
template <>
std::vector<StorageOccurrence> DatabaseStorage::doGetAll<StorageOccurrence>(const std::string& query) const;
template <>
std::vector<StorageError> DatabaseStorage::doGetAll<StorageError>(const std::string& query) const;
} // namespace sourcetrail
#endif // SOURCETRAIL_DATABASE_STORAGE_H
+25 -25
View File
@@ -1,41 +1,41 @@
/*
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SOURCETRAIL_DEFINITION_KIND_H
#define SOURCETRAIL_DEFINITION_KIND_H
namespace sourcetrail
{
/**
/**
* Enum providing all possible values for a symbol's definition kind.
*
* The DefinitionKind specifies "how" a symbol is defined.
* When recording the definition of a symbol, you would usually also record an explicit definition kind.
* However, you may also want to record symbols that are implicitly generated by the compiler. In this case you can
* record an implicit definition kind for those symbols.
* If you do not record any definition kind for a symbol, Sourcetrail will show it as "non-indexed".
* When recording the definition of a symbol, you would usually also record an explicit definition
* kind. However, you may also want to record symbols that are implicitly generated by the compiler.
* In this case you can record an implicit definition kind for those symbols. If you do not record
* any definition kind for a symbol, Sourcetrail will show it as "non-indexed".
*/
enum class DefinitionKind : int
{
enum class DefinitionKind : int
{
IMPLICIT = 1,
EXPLICIT = 2
};
};
int definitionKindToInt(DefinitionKind kind);
DefinitionKind intToDefinitionKind(int i);
}
int definitionKindToInt(DefinitionKind kind);
DefinitionKind intToDefinitionKind(int i);
} // namespace sourcetrail
#endif // SOURCETRAIL_DEFINITION_KIND_H
+21 -21
View File
@@ -1,25 +1,25 @@
/*
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SOURCETRAIL_EDGE_KIND_H
#define SOURCETRAIL_EDGE_KIND_H
namespace sourcetrail
{
/**
/**
* Enum providing all possible values for kinds of edges that can be stored to the Sourcetrail database.
*
* The DatabaseStorage provides the interface for writing and updating the Sourcetrail database. This interface only
@@ -28,8 +28,8 @@ namespace sourcetrail
* for edges that will be created implicitly. For example edges of type "EDGE_MEMBER" will be created while storing parent
* child node relations when recording symbols with hierarchical names (see NameHierarchy).
*/
enum class EdgeKind : int
{
enum class EdgeKind : int
{
UNKNOWN = 0,
MEMBER = 1 << 0,
TYPE_USAGE = 1 << 1,
@@ -43,10 +43,10 @@ namespace sourcetrail
IMPORT = 1 << 9,
MACRO_USAGE = 1 << 11, // needs new db version if decremented
ANNOTATION_USAGE = 1 << 12
};
};
int edgeKindToInt(EdgeKind kind);
EdgeKind intToEdgeKind(int i);
}
int edgeKindToInt(EdgeKind kind);
EdgeKind intToEdgeKind(int i);
} // namespace sourcetrail
#endif // SOURCETRAIL_EDGE_KIND_H
+21 -21
View File
@@ -1,34 +1,34 @@
/*
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SOURCETRAIL_ELEMENT_COMPONENT_KIND_H
#define SOURCETRAIL_ELEMENT_COMPONENT_KIND_H
namespace sourcetrail
{
/**
/**
* Enum providing all possible values for kinds of node and edge components that can be stored to the Sourcetrail database.
*/
enum class ElementComponentKind : int
{
enum class ElementComponentKind : int
{
IS_AMBIGUOUS = 1 << 0
};
};
int elementComponentKindToInt(ElementComponentKind kind);
ElementComponentKind intToElementComponentKind(int i);
}
int elementComponentKindToInt(ElementComponentKind kind);
ElementComponentKind intToElementComponentKind(int i);
} // namespace sourcetrail
#endif // SOURCETRAIL_ELEMENT_COMPONENT_KIND_H
+21 -21
View File
@@ -1,29 +1,29 @@
/*
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SOURCETRAIL_LOCATION_KIND_H
#define SOURCETRAIL_LOCATION_KIND_H
namespace sourcetrail
{
/**
/**
* Enum providing all possible values for kinds of locations that can be stored to the Sourcetrail database.
*/
enum class LocationKind : int
{
enum class LocationKind : int
{
TOKEN = 0,
SCOPE = 1,
QUALIFIER = 2,
@@ -34,10 +34,10 @@ namespace sourcetrail
FULLTEXT_SEARCH = 7,
SCREEN_SEARCH = 8,
UNSOLVED = 9
};
};
int locationKindToInt(LocationKind kind);
LocationKind intToLocationKind(int i);
}
int locationKindToInt(LocationKind kind);
LocationKind intToLocationKind(int i);
} // namespace sourcetrail
#endif // SOURCETRAIL_LOCATION_KIND_H
+29 -29
View File
@@ -1,18 +1,18 @@
/*
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SOURCETRAIL_NAME_HIERARCHY_H
#define SOURCETRAIL_NAME_HIERARCHY_H
@@ -22,33 +22,33 @@
namespace sourcetrail
{
/**
/**
* Struct that represents a single hierarchical element that is part of a symbol's name.
*
* prefix: optional prefix used for unique identification and shown in tooltips
* name: name represented by this element
* postfix: optional prefix used for unique identification and shown in tooltips
*/
struct NameElement
{
struct NameElement
{
std::string prefix;
std::string name;
std::string postfix;
};
};
/**
/**
* Struct that represents an entire name of a symbol.
*
* nameDelimiter: delimiter added between name elements
* nameElements: all name elements that make up the hierarchy
*/
struct NameHierarchy
{
struct NameHierarchy
{
std::string nameDelimiter;
std::vector<NameElement> nameElements;
};
};
/**
/**
* Converts a NameHierarchy to a JSON string
*
* param: nameHierarchy - the name hierarchy to convert to JSON string
@@ -66,9 +66,9 @@ namespace sourcetrail
* ]
* }
*/
std::string serializeNameHierarchyToJson(const NameHierarchy& nameHierarchy);
std::string serializeNameHierarchyToJson(const NameHierarchy& nameHierarchy);
/**
/**
* Converts a JSON string to a NameHierarchy
*
* param: serializedNameHierarchy - JSON object string of the form:
@@ -87,12 +87,12 @@ namespace sourcetrail
*
* return: NameHierarchy object. Empty on failure.
*/
NameHierarchy deserializeNameHierarchyFromJson(const std::string& serializedNameHierarchy, std::string* error = nullptr);
NameHierarchy deserializeNameHierarchyFromJson(const std::string& serializedNameHierarchy, std::string* error = nullptr);
/**
/**
* INTERNAL: Converts a NameHierarchy to a string in Sourcetrail database format
*/
std::string serializeNameHierarchyToDatabaseString(const NameHierarchy& nameHierarchy);
}
std::string serializeNameHierarchyToDatabaseString(const NameHierarchy& nameHierarchy);
} // namespace sourcetrail
#endif // SOURCETRAIL_NAME_HIERARCHY_H
+21 -21
View File
@@ -1,29 +1,29 @@
/*
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SOURCETRAIL_NODE_KIND_H
#define SOURCETRAIL_NODE_KIND_H
namespace sourcetrail
{
/**
/**
* Enum providing all possible values for kinds of nodes that can be stored to the Sourcetrail database.
*/
enum class NodeKind : int
{
enum class NodeKind : int
{
UNKNOWN = 1 << 0,
TYPE = 1 << 1,
BUILTIN_TYPE = 1 << 2,
@@ -45,10 +45,10 @@ namespace sourcetrail
FILE = 1 << 18,
MACRO = 1 << 19,
UNION = 1 << 20
};
};
int nodeKindToInt(NodeKind kind);
NodeKind intToNodeKind(int i);
}
int nodeKindToInt(NodeKind kind);
NodeKind intToNodeKind(int i);
} // namespace sourcetrail
#endif // SOURCETRAIL_NODE_KIND_H
+20 -20
View File
@@ -1,18 +1,18 @@
/*
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SOURCETRAIL_REFERENCE_KIND_H
#define SOURCETRAIL_REFERENCE_KIND_H
@@ -21,11 +21,11 @@
namespace sourcetrail
{
/**
/**
* Enum providing all possible values for kinds of references that can be recorded using the SourcetrailDBWriter interface.
*/
enum class ReferenceKind
{
enum class ReferenceKind
{
TYPE_USAGE,
USAGE,
CALL,
@@ -37,9 +37,9 @@ namespace sourcetrail
IMPORT,
MACRO_USAGE,
ANNOTATION_USAGE
};
};
EdgeKind referenceKindToEdgeKind(ReferenceKind kind);
}
EdgeKind referenceKindToEdgeKind(ReferenceKind kind);
} // namespace sourcetrail
#endif // SOURCETRAIL_REFERENCE_KIND_H
+19 -19
View File
@@ -1,38 +1,38 @@
/*
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SOURCETRAIL_SOURCE_RANGE_H
#define SOURCETRAIL_SOURCE_RANGE_H
namespace sourcetrail
{
/**
/**
* Struct that represents the location of a range of characters in a source file.
*
* note: Line and column numbers start at 1 instead of 0!
* note: The SourceRange includes both, the start and the end column number.
*/
struct SourceRange
{
struct SourceRange
{
int fileId;
int startLine;
int startColumn;
int endLine;
int endColumn;
};
}
};
} // namespace sourcetrail
#endif // SOURCETRAIL_SOURCE_RANGE_H
+22 -22
View File
@@ -1,18 +1,18 @@
/*
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SOURCETRAIL_SRCTRLDB_WRITER_H
#define SOURCETRAIL_SRCTRLDB_WRITER_H
@@ -31,9 +31,9 @@
namespace sourcetrail
{
class DatabaseStorage;
class DatabaseStorage;
/**
/**
* SourcetrailDBWriter
*
* This class is the main interface for writing data to a Sourcetrail project database.
@@ -46,9 +46,9 @@ namespace sourcetrail
* writer.recordSymbol({ "::",{ { "void", "foo", "()" } } });
* writer.close();
*/
class SourcetrailDBWriter
{
public:
class SourcetrailDBWriter
{
public:
SourcetrailDBWriter();
~SourcetrailDBWriter();
@@ -501,7 +501,7 @@ namespace sourcetrail
*/
bool recordError(const std::string& message, bool fatal, const SourceRange& location);
private:
private:
void openDatabase();
void closeDatabase();
void setupDatabaseTables();
@@ -518,7 +518,7 @@ namespace sourcetrail
std::string m_databaseFilePath;
std::unique_ptr<DatabaseStorage> m_storage;
mutable std::string m_lastError;
};
}
};
} // namespace sourcetrail
#endif // SOURCETRAIL_SRCTRLDB_WRITER_H
+26 -23
View File
@@ -1,18 +1,18 @@
/*
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SOURCETRAIL_SOURCETRAIL_EXCEPTION_H
#define SOURCETRAIL_SOURCETRAIL_EXCEPTION_H
@@ -21,19 +21,22 @@
namespace sourcetrail
{
/**
/**
* Exception type that is thrown by the SourcetrailDBWriter API.
*/
class SourcetrailException
{
public:
SourcetrailException(std::string message) : m_message(message) {}
class SourcetrailException
{
public:
SourcetrailException(std::string message): m_message(message) {}
virtual ~SourcetrailException() = default;
std::string getMessage() const { return m_message; }
std::string getMessage() const
{
return m_message;
}
private:
private:
std::string m_message;
};
}
};
} // namespace sourcetrail
#endif // SOURCETRAIL_SOURCETRAIL_EXCEPTION_H
+28 -42
View File
@@ -1,62 +1,48 @@
/*
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SOURCETRAIL_STORAGE_EDGE_H
#define SOURCETRAIL_STORAGE_EDGE_H
namespace sourcetrail
{
struct StorageEdgeData
{
StorageEdgeData()
: sourceNodeId(0)
, targetNodeId(0)
, edgeKind(0)
{}
struct StorageEdgeData
{
StorageEdgeData(): sourceNodeId(0), targetNodeId(0), edgeKind(0) {}
StorageEdgeData(int sourceNodeId, int targetNodeId, int edgeKind)
: sourceNodeId(sourceNodeId)
, targetNodeId(targetNodeId)
, edgeKind(edgeKind)
{}
: sourceNodeId(sourceNodeId), targetNodeId(targetNodeId), edgeKind(edgeKind)
{
}
int sourceNodeId;
int targetNodeId;
int edgeKind;
};
};
struct StorageEdge : public StorageEdgeData
{
StorageEdge()
: StorageEdgeData()
, id(0)
{}
struct StorageEdge: public StorageEdgeData
{
StorageEdge(): StorageEdgeData(), id(0) {}
StorageEdge(int id, const StorageEdgeData& data)
: StorageEdgeData(data)
, id(id)
{}
StorageEdge(int id, const StorageEdgeData& data): StorageEdgeData(data), id(id) {}
StorageEdge(int id, int sourceNodeId, int targetNodeId, int edgeKind)
: StorageEdgeData(sourceNodeId, targetNodeId, edgeKind)
, id(id)
{}
StorageEdge(int id, int sourceNodeId, int targetNodeId, int edgeKind): StorageEdgeData(sourceNodeId, targetNodeId, edgeKind), id(id) {}
int id;
};
}
};
} // namespace sourcetrail
#endif // SOURCETRAIL_STORAGE_EDGE_H
+30 -41
View File
@@ -1,18 +1,18 @@
/*
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SOURCETRAIL_STORAGE_ELEMENT_COMPONENT_H
#define SOURCETRAIL_STORAGE_ELEMENT_COMPONENT_H
@@ -21,44 +21,33 @@
namespace sourcetrail
{
struct StorageElementComponentData
{
StorageElementComponentData()
: elementId(0)
, componentKind(0)
, data("")
{}
struct StorageElementComponentData
{
StorageElementComponentData(): elementId(0), componentKind(0), data("") {}
StorageElementComponentData(int elementId, int componentKind, std::string data)
: elementId(elementId)
, componentKind(componentKind)
, data(std::move(data))
{}
: elementId(elementId), componentKind(componentKind), data(std::move(data))
{
}
int elementId;
int componentKind;
std::string data;
};
};
struct StorageElementComponent : public StorageElementComponentData
{
StorageElementComponent()
: StorageElementComponentData()
, id(0)
{}
struct StorageElementComponent: public StorageElementComponentData
{
StorageElementComponent(): StorageElementComponentData(), id(0) {}
StorageElementComponent(int id, const StorageElementComponentData& data)
: StorageElementComponentData(data)
, id(id)
{}
StorageElementComponent(int id, const StorageElementComponentData& data): StorageElementComponentData(data), id(id) {}
StorageElementComponent(int id, int elementId, int componentKind, std::string data)
: StorageElementComponentData(elementId, componentKind, data)
, id(id)
{}
: StorageElementComponentData(elementId, componentKind, data), id(id)
{
}
int id;
};
}
};
} // namespace sourcetrail
#endif // SOURCETRAIL_STORAGE_ELEMENT_COMPONENT_H
+33 -63
View File
@@ -1,18 +1,18 @@
/*
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SOURCETRAIL_STORAGE_ERROR_H
#define SOURCETRAIL_STORAGE_ERROR_H
@@ -21,64 +21,34 @@
namespace sourcetrail
{
struct StorageErrorData
struct StorageErrorData
{
StorageErrorData(): message(""), translationUnit(""), fatal(0), indexed(0) {}
StorageErrorData(std::string message, std::string translationUnit, bool fatal, bool indexed)
: message(std::move(message)), translationUnit(std::move(translationUnit)), fatal(fatal), indexed(indexed)
{
StorageErrorData()
: message("")
, translationUnit("")
, fatal(0)
, indexed(0)
{}
StorageErrorData(
std::string message,
std::string translationUnit,
bool fatal,
bool indexed
)
: message(std::move(message))
, translationUnit(std::move(translationUnit))
, fatal(fatal)
, indexed(indexed)
{}
}
std::string message;
std::string translationUnit;
bool fatal;
bool indexed;
};
};
struct StorageError : public StorageErrorData
struct StorageError: public StorageErrorData
{
StorageError(): StorageErrorData(), id(0) {}
StorageError(int id, const StorageErrorData& data): StorageErrorData(data), id(id) {}
StorageError(int id, std::string message, std::string translationUnit, bool fatal, bool indexed)
: StorageErrorData(std::move(message), std::move(translationUnit), fatal, indexed), id(id)
{
StorageError()
: StorageErrorData()
, id(0)
{}
StorageError(int id, const StorageErrorData& data)
: StorageErrorData(data)
, id(id)
{}
StorageError(
int id,
std::string message,
std::string translationUnit,
bool fatal,
bool indexed
)
: StorageErrorData(
std::move(message),
std::move(translationUnit),
fatal,
indexed
)
, id(id)
{}
}
int id;
};
}
};
} // namespace sourcetrail
#endif // SOURCETRAIL_STORAGE_ERROR_H
+21 -27
View File
@@ -1,18 +1,18 @@
/*
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SOURCETRAIL_STORAGE_FILE_H
#define SOURCETRAIL_STORAGE_FILE_H
@@ -21,16 +21,9 @@
namespace sourcetrail
{
struct StorageFile
{
StorageFile()
: id(0)
, filePath("")
, languageIdentifier("")
, modificationTime("")
, indexed(true)
, complete(true)
{}
struct StorageFile
{
StorageFile(): id(0), filePath(""), languageIdentifier(""), modificationTime(""), indexed(true), complete(true) {}
StorageFile(int id, std::string filePath, std::string languageIdentifier, std::string modificationTime, bool indexed, bool complete)
: id(id)
@@ -39,7 +32,8 @@ namespace sourcetrail
, modificationTime(std::move(modificationTime))
, indexed(indexed)
, complete(complete)
{}
{
}
int id;
std::string filePath;
@@ -47,7 +41,7 @@ namespace sourcetrail
std::string modificationTime;
bool indexed;
bool complete;
};
}
};
} // namespace sourcetrail
#endif // SOURCETRAIL_STORAGE_FILE_H
+26 -39
View File
@@ -1,18 +1,18 @@
/*
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SOURCETRAIL_STORAGE_LOCAL_SYMBOL_H
#define SOURCETRAIL_STORAGE_LOCAL_SYMBOL_H
@@ -21,38 +21,25 @@
namespace sourcetrail
{
struct StorageLocalSymbolData
{
StorageLocalSymbolData()
: name("")
{}
struct StorageLocalSymbolData
{
StorageLocalSymbolData(): name("") {}
StorageLocalSymbolData(std::string name)
: name(std::move(name))
{}
StorageLocalSymbolData(std::string name): name(std::move(name)) {}
std::string name;
};
};
struct StorageLocalSymbol : public StorageLocalSymbolData
{
StorageLocalSymbol()
: StorageLocalSymbolData()
, id(0)
{}
struct StorageLocalSymbol: public StorageLocalSymbolData
{
StorageLocalSymbol(): StorageLocalSymbolData(), id(0) {}
StorageLocalSymbol(int id, const StorageLocalSymbolData& data)
: StorageLocalSymbolData(data)
, id(id)
{}
StorageLocalSymbol(int id, const StorageLocalSymbolData& data): StorageLocalSymbolData(data), id(id) {}
StorageLocalSymbol(int id, std::string name)
: StorageLocalSymbolData(std::move(name))
, id(id)
{}
StorageLocalSymbol(int id, std::string name): StorageLocalSymbolData(std::move(name)), id(id) {}
int id;
};
}
};
} // namespace sourcetrail
#endif // SOURCETRAIL_STORAGE_LOCAL_SYMBOL_H
+26 -41
View File
@@ -1,18 +1,18 @@
/*
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SOURCETRAIL_STORAGE_NODE_H
#define SOURCETRAIL_STORAGE_NODE_H
@@ -21,41 +21,26 @@
namespace sourcetrail
{
struct StorageNodeData
{
StorageNodeData()
: nodeKind(0)
, serializedName("")
{}
struct StorageNodeData
{
StorageNodeData(): nodeKind(0), serializedName("") {}
StorageNodeData(int nodeKind, std::string serializedName)
: nodeKind(nodeKind)
, serializedName(std::move(serializedName))
{}
StorageNodeData(int nodeKind, std::string serializedName): nodeKind(nodeKind), serializedName(std::move(serializedName)) {}
int nodeKind;
std::string serializedName;
};
};
struct StorageNode : public StorageNodeData
{
StorageNode()
: StorageNodeData()
, id(0)
{}
struct StorageNode: public StorageNodeData
{
StorageNode(): StorageNodeData(), id(0) {}
StorageNode(int id, int nodeKind, std::string serializedName)
: StorageNodeData(nodeKind, std::move(serializedName))
, id(id)
{}
StorageNode(int id, int nodeKind, std::string serializedName): StorageNodeData(nodeKind, std::move(serializedName)), id(id) {}
StorageNode(int id, const StorageNodeData& data)
: StorageNodeData(data)
, id(id)
{}
StorageNode(int id, const StorageNodeData& data): StorageNodeData(data), id(id) {}
int id;
};
}
};
} // namespace sourcetrail
#endif // SOURCETRAIL_STORAGE_NODE_H
+20 -26
View File
@@ -1,39 +1,33 @@
/*
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SOURCETRAIL_STORAGE_OCCURRENCE_H
#define SOURCETRAIL_STORAGE_OCCURRENCE_H
namespace sourcetrail
{
struct StorageOccurrence
{
StorageOccurrence()
: elementId(0)
, sourceLocationId(0)
{}
struct StorageOccurrence
{
StorageOccurrence(): elementId(0), sourceLocationId(0) {}
StorageOccurrence(int elementId, int sourceLocationId)
: elementId(elementId)
, sourceLocationId(sourceLocationId)
{}
StorageOccurrence(int elementId, int sourceLocationId): elementId(elementId), sourceLocationId(sourceLocationId) {}
int elementId;
int sourceLocationId;
};
}
};
} // namespace sourcetrail
#endif // SOURCETRAIL_STORAGE_OCCURRENCE_H
+34 -42
View File
@@ -1,34 +1,30 @@
/*
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SOURCETRAIL_STORAGE_SOURCE_LOCATION_H
#define SOURCETRAIL_STORAGE_SOURCE_LOCATION_H
namespace sourcetrail
{
struct StorageSourceLocationData
{
struct StorageSourceLocationData
{
StorageSourceLocationData()
: fileNodeId(0)
, startLineNumber(-1)
, startColumnNumber(-1)
, endLineNumber(-1)
, endColumnNumber(-1)
, locationKind(0)
{}
: fileNodeId(0), startLineNumber(-1), startColumnNumber(-1), endLineNumber(-1), endColumnNumber(-1), locationKind(0)
{
}
StorageSourceLocationData(int fileNodeId, int startLineNumber, int startColumnNumber, int endLineNumber, int endColumnNumber, int locationKind)
: fileNodeId(fileNodeId)
@@ -37,7 +33,8 @@ namespace sourcetrail
, endLineNumber(endLineNumber)
, endColumnNumber(endColumnNumber)
, locationKind(locationKind)
{}
{
}
int fileNodeId;
int startLineNumber;
@@ -45,27 +42,22 @@ namespace sourcetrail
int endLineNumber;
int endColumnNumber;
int locationKind;
};
};
struct StorageSourceLocation : public StorageSourceLocationData
struct StorageSourceLocation: public StorageSourceLocationData
{
StorageSourceLocation(): StorageSourceLocationData(), id(0) {}
StorageSourceLocation(int id, const StorageSourceLocationData& data): StorageSourceLocationData(data), id(id) {}
StorageSourceLocation(
int id, int fileNodeId, int startLineNumber, int startColumnNumber, int endLineNumber, int endColumnNumber, int locationKind)
: StorageSourceLocationData(fileNodeId, startLineNumber, startColumnNumber, endLineNumber, endColumnNumber, locationKind), id(id)
{
StorageSourceLocation()
: StorageSourceLocationData()
, id(0)
{}
StorageSourceLocation(int id, const StorageSourceLocationData& data)
: StorageSourceLocationData(data)
, id(id)
{}
StorageSourceLocation(int id, int fileNodeId, int startLineNumber, int startColumnNumber, int endLineNumber, int endColumnNumber, int locationKind)
: StorageSourceLocationData(fileNodeId, startLineNumber, startColumnNumber, endLineNumber, endColumnNumber, locationKind)
, id(id)
{}
}
int id;
};
}
};
} // namespace sourcetrail
#endif // SOURCETRAIL_STORAGE_SOURCE_LOCATION_H
+20 -26
View File
@@ -1,18 +1,18 @@
/*
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SOURCETRAIL_STORAGE_SYMBOL_H
#define SOURCETRAIL_STORAGE_SYMBOL_H
@@ -21,21 +21,15 @@
namespace sourcetrail
{
struct StorageSymbol
{
StorageSymbol()
: id(0)
, definitionKind(definitionKindToInt(DefinitionKind::EXPLICIT))
{}
struct StorageSymbol
{
StorageSymbol(): id(0), definitionKind(definitionKindToInt(DefinitionKind::EXPLICIT)) {}
StorageSymbol(int id, int definitionKind)
: id(id)
, definitionKind(definitionKind)
{}
StorageSymbol(int id, int definitionKind): id(id), definitionKind(definitionKind) {}
int id;
int definitionKind;
};
}
};
} // namespace sourcetrail
#endif // SOURCETRAIL_STORAGE_SYMBOL_H
+20 -20
View File
@@ -1,18 +1,18 @@
/*
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SOURCETRAIL_SYMBOL_KIND_H
#define SOURCETRAIL_SYMBOL_KIND_H
@@ -21,11 +21,11 @@
namespace sourcetrail
{
/**
/**
* Enum providing all possible values for kinds of symbols that can be recorded using the SourcetrailDBWriter interface.
*/
enum class SymbolKind
{
enum class SymbolKind
{
TYPE,
BUILTIN_TYPE,
MODULE,
@@ -45,9 +45,9 @@ namespace sourcetrail
TYPE_PARAMETER,
MACRO,
UNION
};
};
NodeKind symbolKindToNodeKind(SymbolKind kind);
}
NodeKind symbolKindToNodeKind(SymbolKind kind);
} // namespace sourcetrail
#endif // SOURCETRAIL_SYMBOL_KIND_H
+22 -22
View File
@@ -1,18 +1,18 @@
/*
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SOURCETRAIL_UTILITY_H
#define SOURCETRAIL_UTILITY_H
@@ -22,13 +22,13 @@
namespace sourcetrail
{
namespace utility
{
bool getFileExists(const std::string& filePath);
std::string getFileContent(const std::string& filePath);
std::string getDateTimeString(const time_t& time);
int getLineCount(const std::string s);
}
}
namespace utility
{
bool getFileExists(const std::string& filePath);
std::string getFileContent(const std::string& filePath);
std::string getDateTimeString(const time_t& time);
int getLineCount(const std::string s);
} // namespace utility
} // namespace sourcetrail
#endif // SOURCETRAIL_UTILITY_H
+211 -283
View File
@@ -1,42 +1,42 @@
/*
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "DatabaseStorage.h"
#include <vector>
#include "NodeKind.h"
#include "SourcetrailException.h"
#include "StorageFile.h"
#include "StorageNode.h"
#include "StorageSymbol.h"
#include "NodeKind.h"
#include "utility.h"
#include "version.h"
namespace sourcetrail
{
// --- Public Interface ---
// --- Public Interface ---
int DatabaseStorage::getSupportedDatabaseVersion()
{
int DatabaseStorage::getSupportedDatabaseVersion()
{
return DATABASE_VERSION;
}
}
std::unique_ptr<DatabaseStorage> DatabaseStorage::openDatabase(const std::string& dbFilePath)
{
std::unique_ptr<DatabaseStorage> DatabaseStorage::openDatabase(const std::string& dbFilePath)
{
try
{
std::unique_ptr<DatabaseStorage> storage = std::unique_ptr<DatabaseStorage>(new DatabaseStorage());
@@ -48,17 +48,17 @@ namespace sourcetrail
{
throw SourcetrailException(e.errorMessage());
}
}
}
DatabaseStorage::~DatabaseStorage()
{
DatabaseStorage::~DatabaseStorage()
{
clearPrecompiledStatements();
m_database.close();
}
}
void DatabaseStorage::setupDatabase()
{
void DatabaseStorage::setupDatabase()
{
executeStatement("PRAGMA foreign_keys=ON;");
if (!isCompatible())
@@ -73,10 +73,10 @@ namespace sourcetrail
setupPrecompiledStatements();
insertOrUpdateMetaValue("storage_version", std::to_string(getSupportedDatabaseVersion()));
}
}
void DatabaseStorage::clearDatabase()
{
void DatabaseStorage::clearDatabase()
{
executeStatement("PRAGMA foreign_keys=OFF;");
clearPrecompiledStatements();
@@ -84,19 +84,17 @@ namespace sourcetrail
clearTables();
setupDatabase();
}
}
void DatabaseStorage::setProjectSettingsText(const std::string& text)
{
void DatabaseStorage::setProjectSettingsText(const std::string& text)
{
insertOrUpdateMetaValue("project_settings", text);
}
}
bool DatabaseStorage::isEmpty() const
{
bool DatabaseStorage::isEmpty() const
{
const std::string tableName = "meta";
CppSQLite3Query q = executeQuery(
"SELECT name FROM sqlite_master WHERE type='table' AND name='" + tableName + "';"
);
CppSQLite3Query q = executeQuery("SELECT name FROM sqlite_master WHERE type='table' AND name='" + tableName + "';");
if (!q.eof())
{
@@ -104,20 +102,20 @@ namespace sourcetrail
}
return true;
}
}
bool DatabaseStorage::isCompatible() const
{
bool DatabaseStorage::isCompatible() const
{
if (isEmpty())
{
return true;
}
return getLoadedDatabaseVersion() == getSupportedDatabaseVersion();
}
}
int DatabaseStorage::getLoadedDatabaseVersion() const
{
int DatabaseStorage::getLoadedDatabaseVersion() const
{
if (isEmpty())
{
throw SourcetrailException("Unable to determine version of an empty database.");
@@ -129,30 +127,30 @@ namespace sourcetrail
return std::stoi(q.getStringField(0, "0"));
}
return 0;
}
}
void DatabaseStorage::beginTransaction()
{
void DatabaseStorage::beginTransaction()
{
executeStatement("BEGIN TRANSACTION;");
}
}
void DatabaseStorage::commitTransaction()
{
void DatabaseStorage::commitTransaction()
{
executeStatement("COMMIT TRANSACTION;");
}
}
void DatabaseStorage::rollbackTransaction()
{
void DatabaseStorage::rollbackTransaction()
{
executeStatement("ROLLBACK TRANSACTION;");
}
}
void DatabaseStorage::optimizeDatabaseMemory()
{
void DatabaseStorage::optimizeDatabaseMemory()
{
executeStatement("VACUUM;");
}
}
int DatabaseStorage::addElementComponent(const StorageElementComponentData& storageElementComponentData)
{
int DatabaseStorage::addElementComponent(const StorageElementComponentData& storageElementComponentData)
{
m_insertElementComponentStatement.bind(1, storageElementComponentData.elementId);
m_insertElementComponentStatement.bind(2, storageElementComponentData.componentKind);
m_insertElementComponentStatement.bind(3, storageElementComponentData.data.c_str());
@@ -160,10 +158,10 @@ namespace sourcetrail
int id = m_database.lastRowId();
m_insertElementComponentStatement.reset();
return id;
}
}
int DatabaseStorage::addNode(const StorageNodeData& storageNodeData)
{
int DatabaseStorage::addNode(const StorageNodeData& storageNodeData)
{
int id = 0;
{
@@ -189,18 +187,18 @@ namespace sourcetrail
m_insertNodeStatement.reset();
}
return id;
}
}
void DatabaseStorage::addSymbol(const StorageSymbol& storageSymbol)
{
void DatabaseStorage::addSymbol(const StorageSymbol& storageSymbol)
{
m_insertSymbolStatement.bind(1, storageSymbol.id);
m_insertSymbolStatement.bind(2, storageSymbol.definitionKind);
executeStatement(m_insertSymbolStatement);
m_insertSymbolStatement.reset();
}
}
void DatabaseStorage::addFile(const StorageFile& storageFile)
{
void DatabaseStorage::addFile(const StorageFile& storageFile)
{
{
m_findFileStatement.bind(1, storageFile.id);
CppSQLite3Query q = executeQuery(m_findFileStatement);
@@ -238,10 +236,10 @@ namespace sourcetrail
executeStatement(m_insertFileContentStatement);
m_insertFileContentStatement.reset();
}
}
}
int DatabaseStorage::addEdge(const StorageEdgeData& storageEdgeData)
{
int DatabaseStorage::addEdge(const StorageEdgeData& storageEdgeData)
{
int id = 0;
{
@@ -268,10 +266,10 @@ namespace sourcetrail
m_insertEdgeStatement.reset();
}
return id;
}
}
int DatabaseStorage::addLocalSymbol(const StorageLocalSymbolData& storageLocalSymbolData)
{
int DatabaseStorage::addLocalSymbol(const StorageLocalSymbolData& storageLocalSymbolData)
{
int id = 0;
{
@@ -294,10 +292,10 @@ namespace sourcetrail
m_insertLocalSymbolStmt.reset();
}
return id;
}
}
int DatabaseStorage::addSourceLocation(const StorageSourceLocationData& storageSourceLocationData)
{
int DatabaseStorage::addSourceLocation(const StorageSourceLocationData& storageSourceLocationData)
{
int id = 0;
{
@@ -328,18 +326,18 @@ namespace sourcetrail
m_insertSourceLocationStmt.reset();
}
return id;
}
}
void DatabaseStorage::addOccurrence(const StorageOccurrence& storageOccurrence)
{
void DatabaseStorage::addOccurrence(const StorageOccurrence& storageOccurrence)
{
m_insertOccurenceStmt.bind(1, storageOccurrence.elementId);
m_insertOccurenceStmt.bind(2, storageOccurrence.sourceLocationId);
executeStatement(m_insertOccurenceStmt);
m_insertOccurenceStmt.reset();
}
}
int DatabaseStorage::addError(const StorageErrorData& storageErrorData)
{
int DatabaseStorage::addError(const StorageErrorData& storageErrorData)
{
int id = 0;
{
m_findErrorStatement.bind(1, storageErrorData.message.c_str());
@@ -366,43 +364,41 @@ namespace sourcetrail
m_insertErrorStatement.reset();
}
return id;
}
}
void DatabaseStorage::setNodeType(int nodeId, int nodeType)
{
void DatabaseStorage::setNodeType(int nodeId, int nodeType)
{
m_setNodeTypeStmt.bind(1, nodeType);
m_setNodeTypeStmt.bind(2, nodeId);
executeStatement(m_setNodeTypeStmt);
m_setNodeTypeStmt.reset();
}
}
void DatabaseStorage::setFileLanguage(int fileId, const std::string& languageIdentifier)
{
void DatabaseStorage::setFileLanguage(int fileId, const std::string& languageIdentifier)
{
m_setFileLanguageStmt.bind(1, languageIdentifier.c_str());
m_setFileLanguageStmt.bind(2, fileId);
executeStatement(m_setFileLanguageStmt);
m_setFileLanguageStmt.reset();
}
}
// --- Private Interface ---
// --- Private Interface ---
void DatabaseStorage::setupTables()
{
void DatabaseStorage::setupTables()
{
executeStatement(
"CREATE TABLE IF NOT EXISTS meta("
" id INTEGER, "
" key TEXT, "
" value TEXT, "
" PRIMARY KEY(id)"
");"
);
");");
executeStatement(
"CREATE TABLE IF NOT EXISTS element("
" id INTEGER, "
" PRIMARY KEY(id)"
");"
);
");");
executeStatement(
"CREATE TABLE IF NOT EXISTS element_component("
@@ -412,8 +408,7 @@ namespace sourcetrail
" data TEXT, "
" PRIMARY KEY(id), "
" FOREIGN KEY(element_id) REFERENCES element(id) ON DELETE CASCADE"
");"
);
");");
executeStatement(
"CREATE TABLE IF NOT EXISTS edge("
@@ -425,8 +420,7 @@ namespace sourcetrail
" FOREIGN KEY(id) REFERENCES element(id) ON DELETE CASCADE, "
" FOREIGN KEY(source_node_id) REFERENCES node(id) ON DELETE CASCADE, "
" FOREIGN KEY(target_node_id) REFERENCES node(id) ON DELETE CASCADE"
");"
);
");");
executeStatement(
"CREATE TABLE IF NOT EXISTS node("
@@ -435,8 +429,7 @@ namespace sourcetrail
" serialized_name TEXT, "
" PRIMARY KEY(id), "
" FOREIGN KEY(id) REFERENCES element(id) ON DELETE CASCADE"
");"
);
");");
executeStatement(
"CREATE TABLE IF NOT EXISTS symbol("
@@ -444,8 +437,7 @@ namespace sourcetrail
" definition_kind INTEGER NOT NULL, "
" PRIMARY KEY(id), "
" FOREIGN KEY(id) REFERENCES node(id) ON DELETE CASCADE"
");"
);
");");
executeStatement(
"CREATE TABLE IF NOT EXISTS file("
@@ -458,8 +450,7 @@ namespace sourcetrail
" line_count INTEGER, "
" PRIMARY KEY(id), "
" FOREIGN KEY(id) REFERENCES node(id) ON DELETE CASCADE"
");"
);
");");
executeStatement(
"CREATE TABLE IF NOT EXISTS filecontent("
@@ -468,8 +459,7 @@ namespace sourcetrail
" FOREIGN KEY(id) REFERENCES file(id)"
" ON DELETE CASCADE "
" ON UPDATE CASCADE"
");"
);
");");
executeStatement(
"CREATE TABLE IF NOT EXISTS local_symbol("
@@ -477,8 +467,7 @@ namespace sourcetrail
" name TEXT, "
" PRIMARY KEY(id), "
" FOREIGN KEY(id) REFERENCES element(id) ON DELETE CASCADE"
");"
);
");");
executeStatement(
"CREATE TABLE IF NOT EXISTS source_location("
@@ -491,8 +480,7 @@ namespace sourcetrail
" type INTEGER, "
" PRIMARY KEY(id), "
" FOREIGN KEY(file_node_id) REFERENCES node(id) ON DELETE CASCADE"
");"
);
");");
executeStatement(
"CREATE TABLE IF NOT EXISTS occurrence("
@@ -501,8 +489,7 @@ namespace sourcetrail
" PRIMARY KEY(element_id, source_location_id), "
" FOREIGN KEY(element_id) REFERENCES element(id) ON DELETE CASCADE, "
" FOREIGN KEY(source_location_id) REFERENCES source_location(id) ON DELETE CASCADE"
");"
);
");");
executeStatement(
"CREATE TABLE IF NOT EXISTS component_access("
@@ -510,8 +497,7 @@ namespace sourcetrail
" type INTEGER NOT NULL, "
" PRIMARY KEY(node_id), "
" FOREIGN KEY(node_id) REFERENCES node(id) ON DELETE CASCADE"
");"
);
");");
executeStatement(
"CREATE TABLE IF NOT EXISTS error("
@@ -522,12 +508,11 @@ namespace sourcetrail
" translation_unit TEXT, "
" PRIMARY KEY(id), "
" FOREIGN KEY(id) REFERENCES element(id) ON DELETE CASCADE"
");"
);
}
");");
}
void DatabaseStorage::clearTables()
{
void DatabaseStorage::clearTables()
{
const std::vector<std::string> tableNames = {
"meta",
"error",
@@ -541,96 +526,60 @@ namespace sourcetrail
"node",
"edge",
"element_component"
"element"
};
"element"};
for (const std::string& tableName : tableNames)
for (const std::string& tableName: tableNames)
{
executeStatement("DROP TABLE IF EXISTS main." + tableName + ";");
}
}
}
void DatabaseStorage::setupIndices()
{
executeStatement(
"CREATE INDEX IF NOT EXISTS node_serialized_name_index ON node(serialized_name);"
);
void DatabaseStorage::setupIndices()
{
executeStatement("CREATE INDEX IF NOT EXISTS node_serialized_name_index ON node(serialized_name);");
executeStatement(
"CREATE INDEX IF NOT EXISTS edge_source_target_type_index ON edge(source_node_id, target_node_id, type);"
);
executeStatement("CREATE INDEX IF NOT EXISTS edge_source_target_type_index ON edge(source_node_id, target_node_id, type);");
executeStatement(
"CREATE INDEX IF NOT EXISTS local_symbol_name_index ON local_symbol(name);"
);
executeStatement("CREATE INDEX IF NOT EXISTS local_symbol_name_index ON local_symbol(name);");
executeStatement(
"CREATE INDEX IF NOT EXISTS source_location_all_data_index "
"ON source_location(file_node_id, start_line, start_column, end_line, end_column, type);"
);
"ON source_location(file_node_id, start_line, start_column, end_line, end_column, type);");
executeStatement(
"CREATE INDEX IF NOT EXISTS error_all_data_index ON error(message, fatal);"
);
}
executeStatement("CREATE INDEX IF NOT EXISTS error_all_data_index ON error(message, fatal);");
}
void DatabaseStorage::setupPrecompiledStatements()
{
m_insertElementStatement = compileStatement(
"INSERT INTO element(id) VALUES(NULL);"
);
void DatabaseStorage::setupPrecompiledStatements()
{
m_insertElementStatement = compileStatement("INSERT INTO element(id) VALUES(NULL);");
m_insertElementComponentStatement = compileStatement(
"INSERT INTO element_component(id, element_id, type, data) VALUES(NULL, ?, ?, ?);"
);
"INSERT INTO element_component(id, element_id, type, data) VALUES(NULL, ?, ?, ?);");
m_findNodeStatement = compileStatement(
"SELECT id FROM node WHERE serialized_name == ? LIMIT 1;"
);
m_findNodeStatement = compileStatement("SELECT id FROM node WHERE serialized_name == ? LIMIT 1;");
m_insertNodeStatement = compileStatement(
"INSERT INTO node(id, type, serialized_name) VALUES(?, ?, ?);"
);
m_insertNodeStatement = compileStatement("INSERT INTO node(id, type, serialized_name) VALUES(?, ?, ?);");
m_setNodeTypeStmt = compileStatement(
"UPDATE node SET type = ? WHERE id == ?;"
);
m_setNodeTypeStmt = compileStatement("UPDATE node SET type = ? WHERE id == ?;");
m_insertSymbolStatement = compileStatement(
"INSERT OR IGNORE INTO symbol(id, definition_kind) VALUES(?, ?);"
);
m_insertSymbolStatement = compileStatement("INSERT OR IGNORE INTO symbol(id, definition_kind) VALUES(?, ?);");
m_findFileStatement = compileStatement(
"SELECT id FROM file WHERE id == ?;"
);
m_findFileStatement = compileStatement("SELECT id FROM file WHERE id == ?;");
m_insertFileStatement = compileStatement(
"INSERT OR IGNORE INTO file(id, path, language, modification_time, indexed, complete, line_count) VALUES(?, ?, ?, ?, ?, ?, ?);"
);
"INSERT OR IGNORE INTO file(id, path, language, modification_time, indexed, complete, line_count) VALUES(?, ?, ?, ?, ?, ?, ?);");
m_setFileLanguageStmt = compileStatement(
"UPDATE file SET language = ? WHERE id == ?;"
);
m_setFileLanguageStmt = compileStatement("UPDATE file SET language = ? WHERE id == ?;");
m_insertFileContentStatement = compileStatement(
"INSERT INTO filecontent(id, content) VALUES(?, ?);"
);
m_insertFileContentStatement = compileStatement("INSERT INTO filecontent(id, content) VALUES(?, ?);");
m_findEdgeStatement = compileStatement(
"SELECT id FROM edge WHERE source_node_id == ? AND target_node_id == ? AND type == ? LIMIT 1;"
);
m_findEdgeStatement = compileStatement("SELECT id FROM edge WHERE source_node_id == ? AND target_node_id == ? AND type == ? LIMIT 1;");
m_insertEdgeStatement = compileStatement(
"INSERT INTO edge(id, type, source_node_id, target_node_id) VALUES(?, ?, ?, ?);"
);
m_insertEdgeStatement = compileStatement("INSERT INTO edge(id, type, source_node_id, target_node_id) VALUES(?, ?, ?, ?);");
m_findLocalSymbolStmt = compileStatement(
"SELECT id FROM local_symbol WHERE name == ? LIMIT 1;"
);
m_findLocalSymbolStmt = compileStatement("SELECT id FROM local_symbol WHERE name == ? LIMIT 1;");
m_insertLocalSymbolStmt = compileStatement(
"INSERT INTO local_symbol(id, name) VALUES(?, ?);"
);
m_insertLocalSymbolStmt = compileStatement("INSERT INTO local_symbol(id, name) VALUES(?, ?);");
m_findSourceLocationStmt = compileStatement(
"SELECT id FROM source_location WHERE "
@@ -640,40 +589,33 @@ namespace sourcetrail
"end_line = ? AND "
"end_column = ? AND "
"type = ? "
"LIMIT 1;"
);
"LIMIT 1;");
m_insertSourceLocationStmt = compileStatement(
"INSERT INTO source_location("
"id, file_node_id, start_line, start_column, end_line, end_column, type) "
"VALUES(NULL, ?, ?, ?, ?, ?, ?);"
);
"VALUES(NULL, ?, ?, ?, ?, ?, ?);");
m_insertOccurenceStmt = compileStatement(
"INSERT OR IGNORE INTO occurrence(element_id, source_location_id) VALUES(?, ?);"
);
m_insertOccurenceStmt = compileStatement("INSERT OR IGNORE INTO occurrence(element_id, source_location_id) VALUES(?, ?);");
m_findErrorStatement = compileStatement(
"SELECT id FROM error WHERE "
"message = ? AND "
"fatal == ? "
"LIMIT 1;"
);
"LIMIT 1;");
m_insertErrorStatement = compileStatement(
"INSERT INTO error(id, message, fatal, indexed, translation_unit) "
"VALUES(?, ?, ?, ?, ?);"
);
"VALUES(?, ?, ?, ?, ?);");
m_insertOrUpdateMetaValueStmt = compileStatement(
"INSERT OR REPLACE INTO meta(id, key, value) VALUES("
"(SELECT id FROM meta WHERE key = ?), ?, ?"
");"
);
}
");");
}
void DatabaseStorage::clearPrecompiledStatements()
{
void DatabaseStorage::clearPrecompiledStatements()
{
m_insertElementStatement.finalize();
m_insertElementComponentStatement.finalize();
m_findNodeStatement.finalize();
@@ -694,27 +636,27 @@ namespace sourcetrail
m_findErrorStatement.finalize();
m_insertErrorStatement.finalize();
m_insertOrUpdateMetaValueStmt.finalize();
}
}
int DatabaseStorage::insertElement()
{
int DatabaseStorage::insertElement()
{
executeStatement(m_insertElementStatement);
int id = m_database.lastRowId();
m_insertElementStatement.reset();
return id;
}
}
void DatabaseStorage::insertOrUpdateMetaValue(const std::string& key, const std::string& value)
{
void DatabaseStorage::insertOrUpdateMetaValue(const std::string& key, const std::string& value)
{
m_insertOrUpdateMetaValueStmt.bind(1, key.c_str());
m_insertOrUpdateMetaValueStmt.bind(2, key.c_str());
m_insertOrUpdateMetaValueStmt.bind(3, value.c_str());
executeStatement(m_insertOrUpdateMetaValueStmt);
m_insertOrUpdateMetaValueStmt.reset();
}
}
CppSQLite3Statement DatabaseStorage::compileStatement(const std::string& statement) const
{
CppSQLite3Statement DatabaseStorage::compileStatement(const std::string& statement) const
{
try
{
return m_database.compileStatement(statement.c_str());
@@ -725,10 +667,10 @@ namespace sourcetrail
}
return CppSQLite3Statement();
}
}
void DatabaseStorage::executeStatement(const std::string& statement) const
{
void DatabaseStorage::executeStatement(const std::string& statement) const
{
try
{
m_database.execDML(statement.c_str());
@@ -737,10 +679,10 @@ namespace sourcetrail
{
throw SourcetrailException("Failed to execute statement \"" + statement + "\" with message \"" + e.errorMessage() + "\".");
}
}
}
void DatabaseStorage::executeStatement(CppSQLite3Statement& statement) const
{
void DatabaseStorage::executeStatement(CppSQLite3Statement& statement) const
{
try
{
statement.execDML();
@@ -749,10 +691,10 @@ namespace sourcetrail
{
throw SourcetrailException("Failed to execute statement with message \"" + std::string(e.errorMessage()) + "\".");
}
}
}
CppSQLite3Query DatabaseStorage::executeQuery(const std::string& query) const
{
CppSQLite3Query DatabaseStorage::executeQuery(const std::string& query) const
{
try
{
return m_database.execQuery(query.c_str());
@@ -761,10 +703,10 @@ namespace sourcetrail
{
throw SourcetrailException("Failed to execute query \"" + query + "\" with message \"" + e.errorMessage() + "\".");
}
}
}
CppSQLite3Query DatabaseStorage::executeQuery(CppSQLite3Statement& statement) const
{
CppSQLite3Query DatabaseStorage::executeQuery(CppSQLite3Statement& statement) const
{
try
{
return statement.execQuery();
@@ -773,14 +715,12 @@ namespace sourcetrail
{
throw SourcetrailException("Failed to execute query with message \"" + std::string(e.errorMessage()) + "\".");
}
}
}
template <>
std::vector<StorageEdge> DatabaseStorage::doGetAll<StorageEdge>(const std::string& query) const
{
CppSQLite3Query q = executeQuery(
"SELECT id, type, source_node_id, target_node_id FROM edge " + query + ";"
);
template <>
std::vector<StorageEdge> DatabaseStorage::doGetAll<StorageEdge>(const std::string& query) const
{
CppSQLite3Query q = executeQuery("SELECT id, type, source_node_id, target_node_id FROM edge " + query + ";");
std::vector<StorageEdge> edges;
while (!q.eof())
@@ -798,14 +738,12 @@ namespace sourcetrail
q.nextRow();
}
return edges;
}
}
template <>
std::vector<StorageNode> DatabaseStorage::doGetAll<StorageNode>(const std::string& query) const
{
CppSQLite3Query q = executeQuery(
"SELECT id, type, serialized_name FROM node " + query + ";"
);
template <>
std::vector<StorageNode> DatabaseStorage::doGetAll<StorageNode>(const std::string& query) const
{
CppSQLite3Query q = executeQuery("SELECT id, type, serialized_name FROM node " + query + ";");
std::vector<StorageNode> nodes;
while (!q.eof())
@@ -822,14 +760,12 @@ namespace sourcetrail
q.nextRow();
}
return nodes;
}
}
template <>
std::vector<StorageSymbol> DatabaseStorage::doGetAll<StorageSymbol>(const std::string& query) const
{
CppSQLite3Query q = executeQuery(
"SELECT id, definition_kind FROM symbol " + query + ";"
);
template <>
std::vector<StorageSymbol> DatabaseStorage::doGetAll<StorageSymbol>(const std::string& query) const
{
CppSQLite3Query q = executeQuery("SELECT id, definition_kind FROM symbol " + query + ";");
std::vector<StorageSymbol> symbols;
while (!q.eof())
@@ -845,14 +781,12 @@ namespace sourcetrail
q.nextRow();
}
return symbols;
}
}
template <>
std::vector<StorageFile> DatabaseStorage::doGetAll<StorageFile>(const std::string& query) const
{
CppSQLite3Query q = executeQuery(
"SELECT id, path, language, modification_time, indexed, complete FROM file " + query + ";"
);
template <>
std::vector<StorageFile> DatabaseStorage::doGetAll<StorageFile>(const std::string& query) const
{
CppSQLite3Query q = executeQuery("SELECT id, path, language, modification_time, indexed, complete FROM file " + query + ";");
std::vector<StorageFile> files;
while (!q.eof())
@@ -872,14 +806,12 @@ namespace sourcetrail
}
return files;
}
}
template <>
std::vector<StorageLocalSymbol> DatabaseStorage::doGetAll<StorageLocalSymbol>(const std::string& query) const
{
CppSQLite3Query q = executeQuery(
"SELECT id, name FROM local_symbol " + query + ";"
);
template <>
std::vector<StorageLocalSymbol> DatabaseStorage::doGetAll<StorageLocalSymbol>(const std::string& query) const
{
CppSQLite3Query q = executeQuery("SELECT id, name FROM local_symbol " + query + ";");
std::vector<StorageLocalSymbol> localSymbols;
@@ -896,14 +828,13 @@ namespace sourcetrail
q.nextRow();
}
return localSymbols;
}
}
template <>
std::vector<StorageSourceLocation> DatabaseStorage::doGetAll<StorageSourceLocation>(const std::string& query) const
{
template <>
std::vector<StorageSourceLocation> DatabaseStorage::doGetAll<StorageSourceLocation>(const std::string& query) const
{
CppSQLite3Query q = executeQuery(
"SELECT id, file_node_id, start_line, start_column, end_line, end_column, type FROM source_location " + query + ";"
);
"SELECT id, file_node_id, start_line, start_column, end_line, end_column, type FROM source_location " + query + ";");
std::vector<StorageSourceLocation> sourceLocations;
@@ -917,23 +848,22 @@ namespace sourcetrail
const int endColNumber = q.getIntField(5, -1);
const int locationKind = q.getIntField(6, -1);
if (id != 0 && fileNodeId != 0 && startLineNumber != -1 && startColNumber != -1 && endLineNumber != -1 &&
endColNumber != -1 && locationKind != -1)
if (id != 0 && fileNodeId != 0 && startLineNumber != -1 && startColNumber != -1 && endLineNumber != -1 && endColNumber != -1 &&
locationKind != -1)
{
sourceLocations.emplace_back(StorageSourceLocation(id, fileNodeId, startLineNumber, startColNumber, endLineNumber, endColNumber, locationKind));
sourceLocations.emplace_back(
StorageSourceLocation(id, fileNodeId, startLineNumber, startColNumber, endLineNumber, endColNumber, locationKind));
}
q.nextRow();
}
return sourceLocations;
}
}
template <>
std::vector<StorageOccurrence> DatabaseStorage::doGetAll<StorageOccurrence>(const std::string& query) const
{
CppSQLite3Query q = executeQuery(
"SELECT element_id, source_location_id FROM occurrence " + query + ";"
);
template <>
std::vector<StorageOccurrence> DatabaseStorage::doGetAll<StorageOccurrence>(const std::string& query) const
{
CppSQLite3Query q = executeQuery("SELECT element_id, source_location_id FROM occurrence " + query + ";");
std::vector<StorageOccurrence> occurrences;
@@ -950,14 +880,12 @@ namespace sourcetrail
q.nextRow();
}
return occurrences;
}
}
template <>
std::vector<StorageError> DatabaseStorage::doGetAll<StorageError>(const std::string& query) const
{
CppSQLite3Query q = executeQuery(
"SELECT id, message, fatal, indexed, translation_unit FROM error " + query + ";"
);
template <>
std::vector<StorageError> DatabaseStorage::doGetAll<StorageError>(const std::string& query) const
{
CppSQLite3Query q = executeQuery("SELECT id, message, fatal, indexed, translation_unit FROM error " + query + ";");
std::vector<StorageError> errors;
while (!q.eof())
@@ -977,6 +905,6 @@ namespace sourcetrail
}
return errors;
}
}
} // namespace sourcetrail
+22 -22
View File
@@ -1,33 +1,33 @@
/*
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "DefinitionKind.h"
namespace sourcetrail
{
int definitionKindToInt(DefinitionKind kind)
{
int definitionKindToInt(DefinitionKind kind)
{
return static_cast<int>(kind);
}
}
DefinitionKind intToDefinitionKind(int i)
{
const DefinitionKind kinds[] = { DefinitionKind::IMPLICIT, DefinitionKind::EXPLICIT };
DefinitionKind intToDefinitionKind(int i)
{
const DefinitionKind kinds[] = {DefinitionKind::IMPLICIT, DefinitionKind::EXPLICIT};
for (DefinitionKind kind : kinds)
for (DefinitionKind kind: kinds)
{
if (i == definitionKindToInt(kind))
{
@@ -36,5 +36,5 @@ namespace sourcetrail
}
return DefinitionKind::EXPLICIT;
}
}
} // namespace sourcetrail
+22 -23
View File
@@ -1,18 +1,18 @@
/*
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "EdgeKind.h"
@@ -20,13 +20,13 @@
namespace sourcetrail
{
int edgeKindToInt(EdgeKind kind)
{
int edgeKindToInt(EdgeKind kind)
{
return static_cast<int>(kind);
}
}
EdgeKind intToEdgeKind(int i)
{
EdgeKind intToEdgeKind(int i)
{
const EdgeKind kinds[] = {
EdgeKind::MEMBER,
EdgeKind::TYPE_USAGE,
@@ -38,10 +38,9 @@ namespace sourcetrail
EdgeKind::TEMPLATE_SPECIALIZATION,
EdgeKind::INCLUDE,
EdgeKind::IMPORT,
EdgeKind::MACRO_USAGE
};
EdgeKind::MACRO_USAGE};
for (EdgeKind kind : kinds)
for (EdgeKind kind: kinds)
{
if (i == edgeKindToInt(kind))
{
@@ -50,5 +49,5 @@ namespace sourcetrail
}
return EdgeKind::UNKNOWN;
}
}
} // namespace sourcetrail
+22 -24
View File
@@ -1,18 +1,18 @@
/*
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ElementComponentKind.h"
@@ -20,18 +20,16 @@
namespace sourcetrail
{
int elementComponentKindToInt(ElementComponentKind kind)
{
int elementComponentKindToInt(ElementComponentKind kind)
{
return static_cast<int>(kind);
}
}
ElementComponentKind intToElementComponentKind(int i)
{
const ElementComponentKind kinds[] = {
ElementComponentKind::IS_AMBIGUOUS
};
ElementComponentKind intToElementComponentKind(int i)
{
const ElementComponentKind kinds[] = {ElementComponentKind::IS_AMBIGUOUS};
for (ElementComponentKind kind : kinds)
for (ElementComponentKind kind: kinds)
{
if (i == elementComponentKindToInt(kind))
{
@@ -40,5 +38,5 @@ namespace sourcetrail
}
throw SourcetrailException("Unable to convert integer \"" + std::to_string(i) + "\" to element component kind.");
}
}
} // namespace sourcetrail
+22 -23
View File
@@ -1,18 +1,18 @@
/*
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "LocationKind.h"
@@ -20,13 +20,13 @@
namespace sourcetrail
{
int locationKindToInt(LocationKind kind)
{
int locationKindToInt(LocationKind kind)
{
return static_cast<int>(kind);
}
}
LocationKind intToLocationKind(int i)
{
LocationKind intToLocationKind(int i)
{
const LocationKind kinds[] = {
LocationKind::TOKEN,
LocationKind::SCOPE,
@@ -37,10 +37,9 @@ namespace sourcetrail
LocationKind::INDEXER_ERROR,
LocationKind::FULLTEXT_SEARCH,
LocationKind::SCREEN_SEARCH,
LocationKind::UNSOLVED
};
LocationKind::UNSOLVED};
for (LocationKind kind : kinds)
for (LocationKind kind: kinds)
{
if (i == locationKindToInt(kind))
{
@@ -49,5 +48,5 @@ namespace sourcetrail
}
throw SourcetrailException("Unable to convert integer \"" + std::to_string(i) + "\" to location kind.");
}
}
} // namespace sourcetrail
+25 -30
View File
@@ -1,18 +1,18 @@
/*
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "NameHierarchy.h"
@@ -20,29 +20,24 @@
namespace sourcetrail
{
std::string serializeNameHierarchyToJson(const NameHierarchy& nameHierarchy)
{
std::string serializeNameHierarchyToJson(const NameHierarchy& nameHierarchy)
{
typedef nlohmann::json json;
nlohmann::json j;
j["name_delimiter"] = nameHierarchy.nameDelimiter;
for (const NameElement& nameElement : nameHierarchy.nameElements)
for (const NameElement& nameElement: nameHierarchy.nameElements)
{
j["name_elements"].push_back(
{
{ "prefix", nameElement.prefix } ,
{ "name", nameElement.name } ,
{ "postfix", nameElement.postfix }
});
j["name_elements"].push_back({{"prefix", nameElement.prefix}, {"name", nameElement.name}, {"postfix", nameElement.postfix}});
}
return j.dump(4);
}
}
NameHierarchy deserializeNameHierarchyFromJson(const std::string& serializedNameHierarchy, std::string* error)
{
NameHierarchy deserializeNameHierarchyFromJson(const std::string& serializedNameHierarchy, std::string* error)
{
typedef nlohmann::json json;
NameHierarchy nameHierarchy;
@@ -106,10 +101,10 @@ namespace sourcetrail
}
return nameHierarchy;
}
}
std::string serializeNameHierarchyToDatabaseString(const NameHierarchy& nameHierarchy)
{
std::string serializeNameHierarchyToDatabaseString(const NameHierarchy& nameHierarchy)
{
static std::string META_DELIMITER = "\tm";
static std::string NAME_DELIMITER = "\tn";
static std::string PARTS_DELIMITER = "\ts";
@@ -126,5 +121,5 @@ namespace sourcetrail
serialized += nameElement.name + PARTS_DELIMITER + nameElement.prefix + SIGNATURE_DELIMITER + nameElement.postfix;
}
return serialized;
}
}
} // namespace sourcetrail
+23 -25
View File
@@ -1,32 +1,31 @@
/*
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "NodeKind.h"
namespace sourcetrail
{
int nodeKindToInt(NodeKind kind)
{
int nodeKindToInt(NodeKind kind)
{
return static_cast<int>(kind);
}
}
NodeKind intToNodeKind(int i)
{
const NodeKind kinds[] = {
NodeKind::UNKNOWN,
NodeKind intToNodeKind(int i)
{
const NodeKind kinds[] = {NodeKind::UNKNOWN,
NodeKind::TYPE,
NodeKind::BUILTIN_TYPE,
NodeKind::MODULE,
@@ -46,10 +45,9 @@ namespace sourcetrail
NodeKind::TYPE_PARAMETER,
NodeKind::FILE,
NodeKind::MACRO,
NodeKind::UNION
};
NodeKind::UNION};
for (NodeKind kind : kinds)
for (NodeKind kind: kinds)
{
if (i == nodeKindToInt(kind))
{
@@ -58,5 +56,5 @@ namespace sourcetrail
}
return NodeKind::UNKNOWN;
}
}
} // namespace sourcetrail
+17 -17
View File
@@ -1,18 +1,18 @@
/*
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ReferenceKind.h"
@@ -20,8 +20,8 @@
namespace sourcetrail
{
EdgeKind referenceKindToEdgeKind(ReferenceKind kind)
{
EdgeKind referenceKindToEdgeKind(ReferenceKind kind)
{
switch (kind)
{
case ReferenceKind::TYPE_USAGE:
@@ -48,5 +48,5 @@ namespace sourcetrail
return EdgeKind::ANNOTATION_USAGE;
}
return EdgeKind::UNKNOWN;
}
}
} // namespace sourcetrail
+159 -181
View File
@@ -1,18 +1,18 @@
/*
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "SourcetrailDBWriter.h"
@@ -37,47 +37,42 @@
namespace sourcetrail
{
// --- Public Interface ---
// --- Public Interface ---
SourcetrailDBWriter::SourcetrailDBWriter()
: m_lastError("")
{
}
SourcetrailDBWriter::SourcetrailDBWriter(): m_lastError("") {}
SourcetrailDBWriter::~SourcetrailDBWriter()
{
}
SourcetrailDBWriter::~SourcetrailDBWriter() {}
std::string SourcetrailDBWriter::getVersionString() const
{
std::string SourcetrailDBWriter::getVersionString() const
{
return VERSION_STRING;
}
}
int SourcetrailDBWriter::getSupportedDatabaseVersion() const
{
int SourcetrailDBWriter::getSupportedDatabaseVersion() const
{
return DatabaseStorage::getSupportedDatabaseVersion();
}
}
const std::string& SourcetrailDBWriter::getLastError() const
{
const std::string& SourcetrailDBWriter::getLastError() const
{
return m_lastError;
}
}
void SourcetrailDBWriter::setLastError(const std::string& error) const
{
void SourcetrailDBWriter::setLastError(const std::string& error) const
{
m_lastError = error;
}
}
void SourcetrailDBWriter::clearLastError()
{
void SourcetrailDBWriter::clearLastError()
{
m_lastError.clear();
}
}
bool SourcetrailDBWriter::open(const std::string& databaseFilePath)
{
bool SourcetrailDBWriter::open(const std::string& databaseFilePath)
{
m_databaseFilePath = databaseFilePath;
m_projectFilePath = databaseFilePath; //FIXME: only find dot after last slash/backslash! otherwise it may be part of the file path
m_projectFilePath = databaseFilePath; // FIXME: only find dot after last slash/backslash! otherwise it may be part of the file path
const size_t pos = m_projectFilePath.rfind('.');
if (pos != std::string::npos)
{
@@ -128,10 +123,10 @@ namespace sourcetrail
}
return true;
}
}
bool SourcetrailDBWriter::close()
{
bool SourcetrailDBWriter::close()
{
try
{
closeDatabase();
@@ -143,10 +138,10 @@ namespace sourcetrail
}
return true;
}
}
bool SourcetrailDBWriter::clear()
{
bool SourcetrailDBWriter::clear()
{
try
{
clearDatabaseTables();
@@ -159,10 +154,10 @@ namespace sourcetrail
}
return true;
}
}
bool SourcetrailDBWriter::isEmpty() const
{
bool SourcetrailDBWriter::isEmpty() const
{
if (!m_storage)
{
m_lastError = "Unable to check if database is empty, because no database is currently open.";
@@ -178,10 +173,10 @@ namespace sourcetrail
m_lastError = e.getMessage();
return true;
}
}
}
bool SourcetrailDBWriter::isCompatible() const
{
bool SourcetrailDBWriter::isCompatible() const
{
if (!m_storage)
{
m_lastError = "Unable to check if database is compatible, because no database is currently open.";
@@ -197,10 +192,10 @@ namespace sourcetrail
m_lastError = e.getMessage();
return false;
}
}
}
int SourcetrailDBWriter::getLoadedDatabaseVersion() const
{
int SourcetrailDBWriter::getLoadedDatabaseVersion() const
{
if (!m_storage)
{
m_lastError = "Unable to fetch database version, because no database is currently open.";
@@ -216,10 +211,10 @@ namespace sourcetrail
m_lastError = e.getMessage();
return 0;
}
}
}
bool SourcetrailDBWriter::beginTransaction()
{
bool SourcetrailDBWriter::beginTransaction()
{
if (!m_storage)
{
m_lastError = "Unable to begin transaction, because no database is currently open.";
@@ -237,10 +232,10 @@ namespace sourcetrail
}
return true;
}
}
bool SourcetrailDBWriter::commitTransaction()
{
bool SourcetrailDBWriter::commitTransaction()
{
if (!m_storage)
{
m_lastError = "Unable to commit transaction, because no database is currently open.";
@@ -258,10 +253,10 @@ namespace sourcetrail
}
return true;
}
}
bool SourcetrailDBWriter::rollbackTransaction()
{
bool SourcetrailDBWriter::rollbackTransaction()
{
if (!m_storage)
{
m_lastError = "Unable to rollback transaction, because no database is currently open.";
@@ -279,10 +274,10 @@ namespace sourcetrail
}
return true;
}
}
bool SourcetrailDBWriter::optimizeDatabaseMemory()
{
bool SourcetrailDBWriter::optimizeDatabaseMemory()
{
if (!m_storage)
{
m_lastError = "Unable to optimize database memory, because no database is currently open.";
@@ -300,10 +295,10 @@ namespace sourcetrail
}
return true;
}
}
int SourcetrailDBWriter::recordSymbol(const NameHierarchy& nameHierarchy)
{
int SourcetrailDBWriter::recordSymbol(const NameHierarchy& nameHierarchy)
{
if (!m_storage)
{
m_lastError = "Unable to record symbol, because no database is currently open.";
@@ -319,10 +314,10 @@ namespace sourcetrail
m_lastError = e.getMessage();
return 0;
}
}
}
bool SourcetrailDBWriter::recordSymbolDefinitionKind(int symbolId, DefinitionKind definitionKind)
{
bool SourcetrailDBWriter::recordSymbolDefinitionKind(int symbolId, DefinitionKind definitionKind)
{
if (!m_storage)
{
m_lastError = "Unable to record symbol kind, because no database is currently open.";
@@ -340,10 +335,10 @@ namespace sourcetrail
}
return true;
}
}
bool SourcetrailDBWriter::recordSymbolKind(int symbolId, SymbolKind symbolKind)
{
bool SourcetrailDBWriter::recordSymbolKind(int symbolId, SymbolKind symbolKind)
{
if (!m_storage)
{
m_lastError = "Unable to record symbol kind, because no database is currently open.";
@@ -361,10 +356,10 @@ namespace sourcetrail
}
return true;
}
}
bool SourcetrailDBWriter::recordSymbolLocation(int symbolId, const SourceRange& location)
{
bool SourcetrailDBWriter::recordSymbolLocation(int symbolId, const SourceRange& location)
{
if (!m_storage)
{
m_lastError = "Unable to record symbol location, because no database is currently open.";
@@ -381,10 +376,10 @@ namespace sourcetrail
m_lastError = e.getMessage();
return false;
}
}
}
bool SourcetrailDBWriter::recordSymbolScopeLocation(int symbolId, const SourceRange& location)
{
bool SourcetrailDBWriter::recordSymbolScopeLocation(int symbolId, const SourceRange& location)
{
if (!m_storage)
{
m_lastError = "Unable to record symbol scope location, because no database is currently open.";
@@ -401,10 +396,10 @@ namespace sourcetrail
m_lastError = e.getMessage();
return false;
}
}
}
bool SourcetrailDBWriter::recordSymbolSignatureLocation(int symbolId, const SourceRange& location)
{
bool SourcetrailDBWriter::recordSymbolSignatureLocation(int symbolId, const SourceRange& location)
{
if (!m_storage)
{
m_lastError = "Unable to record symbol signature location, because no database is currently open.";
@@ -421,10 +416,10 @@ namespace sourcetrail
m_lastError = e.getMessage();
return false;
}
}
}
int SourcetrailDBWriter::recordReference(int contextSymbolId, int referencedSymbolId, ReferenceKind referenceKind)
{
int SourcetrailDBWriter::recordReference(int contextSymbolId, int referencedSymbolId, ReferenceKind referenceKind)
{
if (!m_storage)
{
m_lastError = "Unable to record reference, because no database is currently open.";
@@ -440,10 +435,10 @@ namespace sourcetrail
m_lastError = e.getMessage();
return 0;
}
}
}
bool SourcetrailDBWriter::recordReferenceLocation(int referenceId, const SourceRange& location)
{
bool SourcetrailDBWriter::recordReferenceLocation(int referenceId, const SourceRange& location)
{
if (!m_storage)
{
m_lastError = "Unable to record symbol reference location, because no database is currently open.";
@@ -460,10 +455,10 @@ namespace sourcetrail
m_lastError = e.getMessage();
return false;
}
}
}
bool SourcetrailDBWriter::recordReferenceIsAmbiguous(int referenceId)
{
bool SourcetrailDBWriter::recordReferenceIsAmbiguous(int referenceId)
{
if (!m_storage)
{
m_lastError = "Unable to record ambiguity of reference, because no database is currently open.";
@@ -480,10 +475,10 @@ namespace sourcetrail
m_lastError = e.getMessage();
return false;
}
}
}
int SourcetrailDBWriter::recordReferenceToUnsolvedSymhol(int contextSymbolId, ReferenceKind referenceKind, const SourceRange& location)
{
int SourcetrailDBWriter::recordReferenceToUnsolvedSymhol(int contextSymbolId, ReferenceKind referenceKind, const SourceRange& location)
{
if (!m_storage)
{
m_lastError = "Unable to record symbol reference, because no database is currently open.";
@@ -506,10 +501,10 @@ namespace sourcetrail
m_lastError = e.getMessage();
return 0;
}
}
}
bool SourcetrailDBWriter::recordQualifierLocation(int referencedSymbolId, const SourceRange& location)
{
bool SourcetrailDBWriter::recordQualifierLocation(int referencedSymbolId, const SourceRange& location)
{
if (!m_storage)
{
m_lastError = "Unable to record symbol qualifier location, because no database is currently open.";
@@ -526,10 +521,10 @@ namespace sourcetrail
m_lastError = e.getMessage();
return false;
}
}
}
int SourcetrailDBWriter::recordFile(const std::string& filePath)
{
int SourcetrailDBWriter::recordFile(const std::string& filePath)
{
if (!m_storage)
{
m_lastError = "Unable to record file, because no database is currently open.";
@@ -545,10 +540,10 @@ namespace sourcetrail
m_lastError = e.getMessage();
return 0;
}
}
}
bool SourcetrailDBWriter::recordFileLanguage(int fileId, const std::string& languageIdentifier)
{
bool SourcetrailDBWriter::recordFileLanguage(int fileId, const std::string& languageIdentifier)
{
if (!m_storage)
{
m_lastError = "Unable to record file language, because no database is currently open.";
@@ -566,10 +561,10 @@ namespace sourcetrail
}
return true;
}
}
int SourcetrailDBWriter::recordLocalSymbol(const std::string& name)
{
int SourcetrailDBWriter::recordLocalSymbol(const std::string& name)
{
if (!m_storage)
{
m_lastError = "Unable to record local symbol, because no database is currently open.";
@@ -585,10 +580,10 @@ namespace sourcetrail
m_lastError = e.getMessage();
return 0;
}
}
}
bool SourcetrailDBWriter::recordLocalSymbolLocation(int localSymbolId, const SourceRange& location)
{
bool SourcetrailDBWriter::recordLocalSymbolLocation(int localSymbolId, const SourceRange& location)
{
if (!m_storage)
{
m_lastError = "Unable to record local symbol location, because no database is currently open.";
@@ -605,10 +600,10 @@ namespace sourcetrail
m_lastError = e.getMessage();
return false;
}
}
}
bool SourcetrailDBWriter::recordAtomicSourceRange(const SourceRange& sourceRange)
{
bool SourcetrailDBWriter::recordAtomicSourceRange(const SourceRange& sourceRange)
{
if (!m_storage)
{
m_lastError = "Unable to record atomic source range, because no database is currently open.";
@@ -623,8 +618,7 @@ namespace sourcetrail
sourceRange.startColumn,
sourceRange.endLine,
sourceRange.endColumn,
locationKindToInt(LocationKind::ATOMIC_RANGE)
));
locationKindToInt(LocationKind::ATOMIC_RANGE)));
return true;
}
@@ -633,10 +627,10 @@ namespace sourcetrail
m_lastError = e.getMessage();
return false;
}
}
}
bool SourcetrailDBWriter::recordError(const std::string& message, bool fatal, const SourceRange& location)
{
bool SourcetrailDBWriter::recordError(const std::string& message, bool fatal, const SourceRange& location)
{
if (!m_storage)
{
m_lastError = "Unable to record error, because no database is currently open.";
@@ -654,12 +648,12 @@ namespace sourcetrail
m_lastError = e.getMessage();
return false;
}
}
}
// --- Private Interface ---
// --- Private Interface ---
void SourcetrailDBWriter::openDatabase()
{
void SourcetrailDBWriter::openDatabase()
{
if (m_storage)
{
closeDatabase();
@@ -674,37 +668,37 @@ namespace sourcetrail
m_storage.reset();
throw e;
}
}
}
void SourcetrailDBWriter::closeDatabase()
{
void SourcetrailDBWriter::closeDatabase()
{
if (!m_storage)
{
throw SourcetrailException("Unable to close database, because no database is currently open.");
}
m_storage.reset();
}
}
void SourcetrailDBWriter::setupDatabaseTables()
{
void SourcetrailDBWriter::setupDatabaseTables()
{
if (!m_storage)
{
throw SourcetrailException("Unable to setup database tables, because no database is currently open.");
}
m_storage->setupDatabase();
}
}
void SourcetrailDBWriter::clearDatabaseTables()
{
void SourcetrailDBWriter::clearDatabaseTables()
{
if (!m_storage)
{
throw SourcetrailException("Unable to setup database tables, because no database is currently open.");
}
m_storage->clearDatabase();
}
}
void SourcetrailDBWriter::createOrResetProjectFile()
{
void SourcetrailDBWriter::createOrResetProjectFile()
{
try
{
std::ofstream fileStream;
@@ -713,18 +707,17 @@ namespace sourcetrail
"<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"
"<config>\n"
" <version>0</version>\n"
"</config>\n"
);
"</config>\n");
fileStream.close();
}
catch (...)
{
throw SourcetrailException("Exception occurred while creating project file.");
}
}
}
void SourcetrailDBWriter::updateProjectSettingsText()
{
void SourcetrailDBWriter::updateProjectSettingsText()
{
try
{
std::ifstream f(m_projectFilePath.c_str());
@@ -748,10 +741,10 @@ namespace sourcetrail
{
throw SourcetrailException("Exception occurred while creating project file.");
}
}
}
int SourcetrailDBWriter::addNodeHierarchy(const NameHierarchy& nameHierarchy)
{
int SourcetrailDBWriter::addNodeHierarchy(const NameHierarchy& nameHierarchy)
{
if (nameHierarchy.nameElements.size() == 0)
{
throw SourcetrailException("Unable to add nodes for an empty name hierarchy.");
@@ -766,10 +759,8 @@ namespace sourcetrail
{
currentNameHierarchy.nameElements.push_back(nameHierarchy.nameElements[i]);
int nodeId = m_storage->addNode(StorageNodeData(
nodeKindToInt(NodeKind::UNKNOWN),
serializeNameHierarchyToDatabaseString(currentNameHierarchy)
));
int nodeId = m_storage->addNode(
StorageNodeData(nodeKindToInt(NodeKind::UNKNOWN), serializeNameHierarchyToDatabaseString(currentNameHierarchy)));
if (parentNodeId != 0)
{
@@ -779,10 +770,10 @@ namespace sourcetrail
parentNodeId = nodeId;
}
return parentNodeId;
}
}
int SourcetrailDBWriter::addFile(const std::string& filePath)
{
int SourcetrailDBWriter::addFile(const std::string& filePath)
{
NameElement nameElement;
nameElement.name = filePath;
NameHierarchy nameHierarchy;
@@ -795,10 +786,10 @@ namespace sourcetrail
m_storage->addFile(StorageFile(nodeId, filePath, "", utility::getDateTimeString(time(0)), true, true));
return nodeId;
}
}
int SourcetrailDBWriter::addEdge(int sourceId, int targetId, EdgeKind edgeKind)
{
int SourcetrailDBWriter::addEdge(int sourceId, int targetId, EdgeKind edgeKind)
{
if (!m_storage)
{
throw SourcetrailException("Unable to add edge, because no database is currently open.");
@@ -813,31 +804,18 @@ namespace sourcetrail
}
return m_storage->addEdge(StorageEdgeData(sourceId, targetId, edgeKindToInt(edgeKind)));
}
void SourcetrailDBWriter::addSourceLocation(int elementId, const SourceRange& location, LocationKind kind)
{
const int sourceLocationId = m_storage->addSourceLocation(StorageSourceLocationData(
location.fileId,
location.startLine,
location.startColumn,
location.endLine,
location.endColumn,
locationKindToInt(kind)
));
m_storage->addOccurrence(StorageOccurrence(
elementId,
sourceLocationId
));
}
void SourcetrailDBWriter::addElementComponent(int elementId, ElementComponentKind kind, const std::string& data)
{
const int sourceLocationId = m_storage->addElementComponent(StorageElementComponentData(
elementId,
elementComponentKindToInt(kind),
data
));
}
}
void SourcetrailDBWriter::addSourceLocation(int elementId, const SourceRange& location, LocationKind kind)
{
const int sourceLocationId = m_storage->addSourceLocation(StorageSourceLocationData(
location.fileId, location.startLine, location.startColumn, location.endLine, location.endColumn, locationKindToInt(kind)));
m_storage->addOccurrence(StorageOccurrence(elementId, sourceLocationId));
}
void SourcetrailDBWriter::addElementComponent(int elementId, ElementComponentKind kind, const std::string& data)
{
const int sourceLocationId = m_storage->addElementComponent(StorageElementComponentData(elementId, elementComponentKindToInt(kind), data));
}
} // namespace sourcetrail
+17 -17
View File
@@ -1,18 +1,18 @@
/*
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "SymbolKind.h"
@@ -20,8 +20,8 @@
namespace sourcetrail
{
NodeKind symbolKindToNodeKind(SymbolKind kind)
{
NodeKind symbolKindToNodeKind(SymbolKind kind)
{
switch (kind)
{
case SymbolKind::TYPE:
@@ -64,5 +64,5 @@ namespace sourcetrail
return NodeKind::UNION;
}
return NodeKind::UNKNOWN;
}
}
} // namespace sourcetrail
+32 -32
View File
@@ -1,18 +1,18 @@
/*
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "utility.h"
@@ -24,16 +24,16 @@
namespace sourcetrail
{
namespace utility
{
bool getFileExists(const std::string& filePath)
{
namespace utility
{
bool getFileExists(const std::string& filePath)
{
std::ifstream file(filePath);
return file.good();
}
}
std::string getFileContent(const std::string& filePath)
{
std::string getFileContent(const std::string& filePath)
{
std::string content;
std::ifstream file;
@@ -44,7 +44,7 @@ namespace sourcetrail
throw SourcetrailException("Could not open file " + filePath);
}
for (std::string line; std::getline(file, line); )
for (std::string line; std::getline(file, line);)
{
content += line + "\n";
}
@@ -52,19 +52,19 @@ namespace sourcetrail
file.close();
return content;
}
}
std::string getDateTimeString(const time_t& time)
{
std::string getDateTimeString(const time_t& time)
{
std::tm* ptm = std::localtime(&time);
char buffer[32];
std::strftime(buffer, 32, "%Y-%m-%d %H:%M:%S", ptm);
return buffer;
}
int getLineCount(const std::string s)
{
return std::count(s.begin(), s.end(), '\n');
}
}
}
int getLineCount(const std::string s)
{
return std::count(s.begin(), s.end(), '\n');
}
} // namespace utility
} // namespace sourcetrail