uppaal-to-tchecker
Version:
JavaScript implementation of Uppaal to TChecker translator - convert Uppaal timed automata models to TChecker format
85 lines (73 loc) • 2.33 kB
JavaScript
/**
* Context Prefix Handler
* JavaScript implementation of utot-contextprefix.hh
*/
class ContextPrefix {
constructor(prefix = '') {
this.prefix = prefix;
}
/**
* Create a new context prefix with additional prefix
* @param {string} additional - Additional prefix to add
* @returns {ContextPrefix} - New context prefix
*/
extend(additional) {
if (!additional) return this;
const newPrefix = this.prefix ? `${this.prefix}_${additional}` : additional;
return new ContextPrefix(newPrefix);
}
/**
* Get the string representation of the prefix
* @returns {string} - Prefix string
*/
toString() {
return this.prefix || '';
}
/**
* Check if prefix is empty
* @returns {boolean} - True if empty
*/
isEmpty() {
return !this.prefix;
}
/**
* Apply prefix to a variable name
* @param {string} varName - Variable name
* @returns {string} - Prefixed variable name
*/
applyToVariable(varName) {
if (this.isEmpty()) return varName;
return `${this.prefix}_${varName}`;
}
/**
* Apply prefix to a location name
* @param {string} locationName - Location name
* @returns {string} - Prefixed location name
*/
applyToLocation(locationName) {
return locationName; // Locations don't get prefixed in the same way
}
/**
* Create context prefix from template instance
* @param {string} templateName - Template name
* @param {Object} params - Template parameters
* @returns {ContextPrefix} - Context prefix for the instance
*/
static fromTemplateInstance(templateName, params = {}) {
let instanceName = templateName;
// Add parameter values to instance name
for (const [paramName, paramValue] of Object.entries(params)) {
instanceName += `_${paramName}_${paramValue}`;
}
return new ContextPrefix(instanceName);
}
/**
* Create context prefix from process name
* @param {string} processName - Process name
* @returns {ContextPrefix} - Context prefix
*/
static fromProcess(processName) {
return new ContextPrefix(processName);
}
}
module.exports = ContextPrefix;