Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix licence comment symbol bug #606

Merged
merged 1 commit into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions packages/colibri/src/template/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,29 @@ import { get_template } from "./helpers/template";
/** Template */
export class Template_manager {
private language: LANGUAGE = LANGUAGE.VHDL;
private comment_symbol = "//";

/**
* @param {LANGUAGE} language Language name
*/
constructor(language: LANGUAGE) {
if (language === LANGUAGE.VHDL) {
this.comment_symbol = '//';
}
else {
this.comment_symbol = '--';
}
this.language = language;
}

/**
* Get the text header from a file path
* @param {string} header_file_path File path with the header
* @param {LANGUAGE} target_lang Target language
*/
private get_header(header_file_path: string) {
private get_header(header_file_path: string, target_lang: LANGUAGE) {
let comment_symbol = "";

if(target_lang === LANGUAGE.VHDL){
comment_symbol = '--';
}
else{
comment_symbol = '//';
}

if (header_file_path === '') {
return '';
}
Expand All @@ -57,7 +60,7 @@ export class Template_manager {
let header = '';
for (let i = 0; i < lines.length; i++) {
const element = lines[i];
header += `${this.comment_symbol} ${element}\n`;
header += `${comment_symbol} ${element}\n`;
}
return header + '\n';
}
Expand Down Expand Up @@ -100,20 +103,29 @@ export class Template_manager {
* @param {string} code HDL code
* @param {common.TEMPLATE_NAME} template_type Template type
* @param {common.t_options} options Template options
* @param {string} options Template options
* @param {LANGUAGE} target_lang Target language
*/
async generate(code: string, template_type: string, options: t_template_options) {
async generate(code: string, template_type: string, options: t_template_options, target_lang?: LANGUAGE) {
let target_language = LANGUAGE.VHDL;
let norm_language = this.language;
if (this.language === LANGUAGE.SYSTEMVERILOG) {
norm_language = LANGUAGE.VERILOG;
}

if(typeof target_lang === 'undefined'){
target_language = norm_language;
}else{
target_language = target_lang;
}

let template = '';
const code_tree = await this.parse(code);
if (code_tree === undefined || code_tree.name === "") {
return template;
}
// Get header
const header = this.get_header(options.header_file_path);
const header = this.get_header(options.header_file_path, target_language);
// Indent
const indent = this.get_indent(options.indent_char);
// Template parent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// The licenses for most software and other practical works are designed
// to take away your freedom to share and change the works. By contrast,
// the GNU General Public License is intended to guarantee your freedom to
// share and change all versions of a program--to make sure it remains free
// software for all its users. We, the Free Software Foundation, use the
// GNU General Public License for most of our software; it applies also to
// any other work released this way by its authors. You can apply it to
// your programs, too.
//
//
-- The licenses for most software and other practical works are designed
-- to take away your freedom to share and change the works. By contrast,
-- the GNU General Public License is intended to guarantee your freedom to
-- share and change all versions of a program--to make sure it remains free
-- software for all its users. We, the Free Software Foundation, use the
-- GNU General Public License for most of our software; it applies also to
-- any other work released this way by its authors. You can apply it to
-- your programs, too.
--
--



Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// The licenses for most software and other practical works are designed
// to take away your freedom to share and change the works. By contrast,
// the GNU General Public License is intended to guarantee your freedom to
// share and change all versions of a program--to make sure it remains free
// software for all its users. We, the Free Software Foundation, use the
// GNU General Public License for most of our software; it applies also to
// any other work released this way by its authors. You can apply it to
// your programs, too.
//
//
-- The licenses for most software and other practical works are designed
-- to take away your freedom to share and change the works. By contrast,
-- the GNU General Public License is intended to guarantee your freedom to
-- share and change all versions of a program--to make sure it remains free
-- software for all its users. We, the Free Software Foundation, use the
-- GNU General Public License for most of our software; it applies also to
-- any other work released this way by its authors. You can apply it to
-- your programs, too.
--
--



Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// The licenses for most software and other practical works are designed
// to take away your freedom to share and change the works. By contrast,
// the GNU General Public License is intended to guarantee your freedom to
// share and change all versions of a program--to make sure it remains free
// software for all its users. We, the Free Software Foundation, use the
// GNU General Public License for most of our software; it applies also to
// any other work released this way by its authors. You can apply it to
// your programs, too.
//
//
-- The licenses for most software and other practical works are designed
-- to take away your freedom to share and change the works. By contrast,
-- the GNU General Public License is intended to guarantee your freedom to
-- share and change all versions of a program--to make sure it remains free
-- software for all its users. We, the Free Software Foundation, use the
-- GNU General Public License for most of our software; it applies also to
-- any other work released this way by its authors. You can apply it to
-- your programs, too.
--
--



Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// The licenses for most software and other practical works are designed
// to take away your freedom to share and change the works. By contrast,
// the GNU General Public License is intended to guarantee your freedom to
// share and change all versions of a program--to make sure it remains free
// software for all its users. We, the Free Software Foundation, use the
// GNU General Public License for most of our software; it applies also to
// any other work released this way by its authors. You can apply it to
// your programs, too.
//
//
-- The licenses for most software and other practical works are designed
-- to take away your freedom to share and change the works. By contrast,
-- the GNU General Public License is intended to guarantee your freedom to
-- share and change all versions of a program--to make sure it remains free
-- software for all its users. We, the Free Software Foundation, use the
-- GNU General Public License for most of our software; it applies also to
-- any other work released this way by its authors. You can apply it to
-- your programs, too.
--
--



Expand Down
15 changes: 14 additions & 1 deletion packages/colibri/tests/template/template.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,22 @@ TEST_TYPE_LIST.forEach(TEST_TYPE => {
extension = "vhdl";
}

let lang_template = LANGUAGE.NONE;
const template_def = common.get_template_definition(language);
for (let i = 0; i < template_def.lang_list.length; i++) {
if (template_type.id === template_def.id_list[i]) {
lang_template = template_def.lang_list[i];
break;
}
}

const template_manager = await generate_template_manager(language);
const inst_hdl = code_hdl[counter];
const template = await template_manager.generate(inst_hdl, template_type.id, config);
const template = await template_manager.generate(inst_hdl,
template_type.id,
config,
lang_template);

const output_path = paht_lib.join(C_OUTPUT_BASE_PATH,
`${extension}_${template_type.id}.${extension}`);
fs.writeFileSync(output_path, template);
Expand Down
2 changes: 1 addition & 1 deletion packages/teroshdl/src/features/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class Template_manager {
const template_manager = new teroshdl2.template.manager.Template_manager(lang);

const options = this.get_config();
const template = await template_manager.generate(code, select_id, options);
const template = await template_manager.generate(code, select_id, options, lang_template);

//Error
if (template === undefined || template === '') {
Expand Down
Loading