Skip to content

Commit

Permalink
allow interface instantiation
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewNolte committed Apr 3, 2024
1 parent 204c1ab commit e1efa75
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
10 changes: 5 additions & 5 deletions src/commands/ModuleInstantiation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export async function instantiateModule(
let output = await ctags.execCtags(srcpath);
await ctags.buildSymbolsList(output);

let modules: Symbol[] = ctags.symbols.filter((tag) => tag.type === 'module');
let modules: Symbol[] = ctags.symbols.filter((tag) => tag.type === 'module' || tag.type === 'interface');
// No modules found
if (modules.length <= 0) {
vscode.window.showErrorMessage('Verilog-HDL/SystemVerilog: No modules found in the file');
Expand Down Expand Up @@ -73,7 +73,7 @@ export async function moduleFromFile(srcpath: string): Promise<vscode.SnippetStr
let output = await ctags.execCtags(srcpath);
await ctags.buildSymbolsList(output);

let modules: Symbol[] = ctags.symbols.filter((tag) => tag.type === 'module');
let modules: Symbol[] = ctags.symbols.filter((tag) => tag.type === 'module' || tag.type === 'interface');
// No modules found
if (modules.length <= 0) {
vscode.window.showErrorMessage('Verilog-HDL/SystemVerilog: No modules found in the file');
Expand All @@ -89,11 +89,11 @@ export async function moduleSnippet(ctags: CtagsParser, module: Symbol, fullModu

let scope = module.parentScope !== '' ? module.parentScope + '.' + module.name : module.name;
let ports: Symbol[] = ctags.symbols.filter(
(tag) => tag.type === 'port' && tag.parentType === 'module' && tag.parentScope === scope
(tag) => tag.type === 'port' && tag.parentScope === scope
);
portsName = ports.map((tag) => tag.name);
let params: Symbol[] = ctags.symbols.filter(
(tag) => tag.type === 'parameter' && tag.parentType === 'module' && tag.parentScope === scope
(tag) => tag.type === 'parameter' && tag.parentScope === scope
);
parametersName = params.map((tag) => tag.name);
logger.info('Module name: ' + module.name);
Expand Down Expand Up @@ -217,7 +217,7 @@ class ModuleTags extends CtagsParser {
return;
}
// add only modules and ports
if (tag.type === 'module' || tag.type === 'port' || tag.type === 'parameter') {
if (tag.type === 'interface' || tag.type === 'module' || tag.type === 'port' || tag.type === 'parameter') {
this.symbols.push(tag);
}
}
Expand Down
20 changes: 15 additions & 5 deletions src/parsers/ctagsParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { Logger } from '../logger';
export class Symbol {
name: string;
type: string;
pattern: string;
line: number;
// range of identifier
idRange: vscode.Range | undefined;
Expand All @@ -22,7 +21,6 @@ export class Symbol {
doc: vscode.TextDocument,
name: string,
type: string,
pattern: string,
startLine: number,
parentScope: string,
parentType: string,
Expand All @@ -32,7 +30,6 @@ export class Symbol {
this.doc = doc;
this.name = name;
this.type = type;
this.pattern = pattern;
this.line = startLine;
this.startPosition = new vscode.Position(startLine, 0);
this.parentScope = parentScope;
Expand All @@ -41,6 +38,17 @@ export class Symbol {
this.typeRef = typeRef;
}

prettyPrint(): string {
let ret = `${this.name}(${this.type}):${this.line}`;
if (this.parentScope !== '') {
ret += ` parent=${this.parentScope}(${this.parentType})`;
}
if (this.typeRef !== null) {
ret += ` typeref=${this.typeRef}`;
}
return ret;
}

getIdRange(): vscode.Range {
if (this.idRange === undefined) {
this.idRange = this.doc.getWordRangeAtPosition(
Expand Down Expand Up @@ -239,7 +247,6 @@ export class CtagsParser {
let lineNo: number;
let parts: string[] = line.split('\t');
name = parts[0];
pattern = parts[2];
type = parts[3];
// override "type" for parameters (See #102)
if (parts.length === 6) {
Expand All @@ -266,7 +273,6 @@ export class CtagsParser {
this.doc,
name,
type,
pattern,
lineNo,
parentScope,
parentType,
Expand Down Expand Up @@ -335,6 +341,10 @@ export class CtagsParser {
} catch (e) {
this.logger.error((e as Error).toString());
}
// print all syms
// this.symbols.forEach((sym) => {
// this.logger.info(sym.prettyPrint());
// });
}

async index(): Promise<void> {
Expand Down

0 comments on commit e1efa75

Please sign in to comment.