//Helper operations

//From standard


//TODO: Implement, originally equivalent 
operation Any behaviourFunctionInReferencedTD() : Any {
    return self;
}

//TODO: Implement, originally equivalent 
operation Any TTCNequivalent() : Any {
    return self;
}

//TODO: Implement
operation Any getKind() : Any {
    return self;
}

operation Any toLower() : String {
    return self.toLowerCase();
}

operation Any TTCNname() : String {
    var ttcnName = self.name;
    if (qualifiedNaming) {
        ttcnName = self.qualifiedName();
    }
    if (packagePrefix) {
    	if (self.getPackage().isDefined()) {
		    ttcnName = self.getPackage().name+"_"+ttcnName;
    	}
    }
    ttcnName = ttcnName.replace("::","_");
    ttcnName = ttcnName.replace("\\.","_");
    ttcnName = ttcnName.replace("\\^","");
    ttcnName = ttcnName.replace("value","value_");
    ttcnName = ttcnName.replace("message","message_");
    ttcnName = ttcnName.replace("^(\\d)","d$1");
    if (ttcnName = "integer" 
            or ttcnName = "charstring" 
            or ttcnName = "float") {
        ttcnName = "TDL"+ttcnName;
    }
    return ttcnName;
}


//Aditional

operation TDL!DataInstance isValue() : Boolean {
    return self.annotation.exists(a|a.key.name = "Value");
}


operation TDL!Package targetElement() : String {
	return self.qualifiedName();
}

operation TDL!Member targetElement() : String {
	return self.eContainer.qualifiedName()+"::"+self.name;
}

operation TDL!ElementImport targetElement() : String {
	return self.qualifiedName()+"::Import " +self.importedElement.collect(e|e.name).concat(",")+ " from "+self.importedPackage.qualifiedName();
}


operation TDL!MemberAssignment targetElement() : String {
	return self.qualifiedName()+self.member.name + " = " +self.memberSpec.targetElement();
}

operation TDL!DataInstanceUse targetElement() : String {
	return self.dataInstance.qualifiedName();
}

operation TDL!DataInstance targetElement() : String {
	return self.qualifiedName();
}

operation TDL!FunctionCall targetElement() : String {
	return self.`function`.qualifiedName();
}

operation TDL!FormalParameterUse targetElement() : String {
	return self.parameter.qualifiedName();
}

operation TDL!VariableUse targetElement() : String {
	return self.variable.qualifiedName();
}


operation TDL!ParameterBinding targetElement() : String {
	return self.parameter.qualifiedName() +" = ?:"+self.dataUse.getDataType().name+ " [Expecting "+self.parameter.dataType.name+"]";
}

operation TDL!AnyValueOrOmit targetElement() : String {
	return "*";
}

operation TDL!AnyValue targetElement() : String {
	return "?";
}

operation TDL!OmitValue targetElement() : String {
	return "omit";
}

operation TDL!TimeLabelUse targetElement() : String {
	return self.timeLabel.qualifiedName();
}

operation TDL!ComponentInstance targetElement() : String {
	return self.qualifiedName();
}

operation TDL!ComponentType targetElement() : String {
	return self.qualifiedName();
}

operation TDL!Comment targetElement() : String {
	return self.qualifiedName();
}

operation TDL!Action targetElement() : String {
	return self.qualifiedName();
}

operation TDL!AnnotationType targetElement() : String {
	return self.qualifiedName();
}


operation TDL!TimeConstraint targetElement() : String {
	return 'TimeConstraint';
}

operation TDL!Quiescence targetElement() : String {
	return 'Q';
}

operation TDL!Wait targetElement() : String {
	return 'W';
}

operation TDL!TimerOperation targetElement() : String {
	return self.timer.qualifiedName();
}

operation TDL!GateReference targetElement() : String {
	return self.component.qualifiedName()+ "." + self.gate.qualifiedName();
}

operation TDL!Connection targetElement() : String {
	return self.endPoint.at(0).targetElement()+ " --- " + self.endPoint.at(1).targetElement();
}

operation TDL!TestConfiguration targetElement() : String {
	return self.qualifiedName();
}

operation TDL!Block targetElement() : String {
	return self.qualifiedName() + "Block";
}

operation TDL!Behaviour targetElement() : String {
	return self.qualifiedName() + self.type().name;
}

operation TDL!Target targetElement() : String {
	return self.qualifiedName() + self.type().name;
}

operation TDL!ComponentInstanceBinding targetElement() : String {
	return self.qualifiedName() + "Binding";
}

operation TDL!Function targetElement() : String {
	return self.qualifiedName();
}

operation Any targetElement() : String {
	if (self.isDefined()) {
		return "[not implemented "+self+"]";
	} else {
		return "";
	}
}
