/*
* This file is part of PKM (Persistent Knowledge Monitor).
* Copyright (c) 2020 Capgemini Group, Commissariat à l'énergie atomique et aux énergies alternatives,
* OW2, Sysgo AG, Technikon, Tree Technology, Universitat Politècnica de València.
*
* PKM is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License version 3 as published by
* the Free Software Foundation.
*
* PKM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with PKM. If not, see <https://www.gnu.org/licenses/>.
*/
/** Preprocess C++ Source Codes
*
* @memberof PKM
* @instance
* @param {Array.<Object>} cpp_source_code_documents - C++ source code documents
* @param {Object} [options] - options
*
* @return {Promise.<Array.<Object>>} a promise which result is the preprocessed C++ source code documents
*/
function preprocess_cpp_source_codes(cpp_source_code_documents, options = {})
{
return new Promise(function(resolve, reject)
{
const dont_split = (options !== undefined) && options.dont_split;
if(dont_split)
{
resolve(cpp_source_code_documents);
}
else
{
let splitted_cpp_source_code_documents = [];
cpp_source_code_documents.forEach((cpp_source_code_document) =>
{
if(cpp_source_code_document.hasOwnProperty('inner') && (cpp_source_code_document.inner.find((inner_element) => !inner_element.hasOwnProperty('manifest')) === undefined))
{
cpp_source_code_document.inner.forEach((inner_element) =>
{
let document =
{
manifest : inner_element.manifest,
type : cpp_source_code_document.type,
sourceFile : cpp_source_code_document.sourceFile
};
delete inner_element.manifest;
document.inner = [ inner_element ];
splitted_cpp_source_code_documents.push(document);
});
}
else
{
splitted_cpp_source_code_documents.push(cpp_source_code_document);
}
});
resolve(splitted_cpp_source_code_documents);
}
}.bind(this));
}
module.exports.preprocess_cpp_source_codes = preprocess_cpp_source_codes;