/* * Created on Apr 12, 2005 * */ package fr.lifl.stc.stan.link; import java.io.Serializable; import fr.lifl.stc.stan.analyser.GlobalAnalyser; import fr.lifl.stc.stan.execution.stack.JvmType; ; /** * @author dorina * * Abstract class representing a link between two entities * */ public abstract class Link implements Serializable{ public static final int VALUE_LINK = 0; public static final int REFERENCE_LINK = 1; public static final int ANY_LINK = 2; public abstract boolean compatibleWith(Link l); protected abstract Link makeAccept(Link l); /* * returns the new link only if the merge updated the old value * else, returns null */ protected abstract Link merge(Link l); /* * @param from must be one of JvmType.WHOLE_PART, JvmType.SECRET_PART or JvmType.PUBLIC_PART * @param to idem from * @param linkType must be VALUE_LINK or REFERENCE_LINK */ //public abstract Link(int from, int to, int linkType); //public abstract boolean merge(int from, int to, int linkType); /* * @param from intial link * @param to new link */ protected abstract Link makePointTo(Link from, Link to); /* * @param from new link * @param to initial/existing link */ protected abstract Link makePointedBy(Link from, Link to); /* * @param from must be one of JvmType.WHOLE_PART, JvmType.SECRET_PART or JvmType.PUBLIC_PART * @param to idem from * @param l the link that must be applied */ protected abstract Link makePointsToReturn(Link from, Link to, int typeReturn); protected abstract Link makePointArray(Link from, Link to); protected abstract Link applySignature(int from, int to, Link l); public abstract JvmType getPointedPart(JvmType from, JvmType to, int linkType); protected abstract void extendPublicReference(); public abstract boolean isEmpty(); /** * * @return true if we have a link to secret (P->S or S->S) * */ //public abstract boolean isLinkToSecret(); /** * Tests if we have a reference link to secret * @return true if we have a reference link to secret */ /* public abstract boolean isLinkToSecretReference(); public abstract boolean isLinkToSecretValue(); */ /** * * @param typeLink must be VALUE_LINK or REFERENCE_LINK * @return true if the link is of type typeLink */ public abstract boolean isLinkOfType(int typeLink); public abstract boolean isLinkFromPart(int part); public abstract boolean isLinkToPart(int part); protected abstract boolean equals(Link l); protected abstract void copyLink(Link l); public abstract Link clone1(); public abstract String toString(); //----------------------------------- // // abstract methods // //---------------------------------- public static boolean equals(Link l1, Link l2){ if(l1 == null || l1.isEmpty()){ if(l2 == null || l2.isEmpty()) return true; return false; } if(l2==null) return false; return l1.equals(l2); } /** * returns the link resulted from merging l1 and l2 only if * l1 was updated (modified). Else, it returns null * @param l1 * @param l2 * @return */ public static Link merge(Link l1, Link l2){ if(l2 == null || l2.isEmpty()) return null; if(l1 == null){ return l2.clone1(); } return l1.merge(l2); } public static boolean compatibleWith(Link l1, Link l2){ if(l1 == null || l1.isEmpty()){ return true; } return l1.compatibleWith(l2); } public static Link makeAccept(Link l1, Link l2){ if(l2 == null || l2.isEmpty()) return null; if(l1 == null){ return l2.clone1(); } return l1.makeAccept(l2); } public static Link makePointedBy(Link th, Link from, Link to){ if(from == null || to == null || from.isEmpty() || to.isEmpty()) return null; if(th == null) th = GlobalAnalyser.linkFactory.createLink(); return th.makePointedBy(from, to); } public static Link makePointsToReturn(Link th, Link from, Link to, int typeReturn){ if(from == null || to == null || from.isEmpty() || to.isEmpty()) return null; if(th == null) th = GlobalAnalyser.linkFactory.createLink(); return th.makePointsToReturn(from, to, typeReturn); } public static void extendPublicReference(Link l){ if (l == null) return; l.extendPublicReference(); } public static Link makePointArray(Link th, Link from, Link to) { if(from == null || to == null || from.isEmpty() || to.isEmpty()) return null; if(th == null) th = GlobalAnalyser.linkFactory.createLink(); return th.makePointArray(from, to); } public static Link makePointTo(Link th, Link from, Link to) { if(from == null || to == null || from.isEmpty() || to.isEmpty()) return null; if(th == null) th = GlobalAnalyser.linkFactory.createLink(); return th.makePointTo(from, to); } public static Link applySignature(Link th, int from, int to, Link l) { if(l == null || l.isEmpty()) return null; if(th == null) th = GlobalAnalyser.linkFactory.createLink(); return th.applySignature(from, to, l); } }