Changeset 14001


Ignore:
Timestamp:
Nov 8, 2019 1:50:36 PM (6 days ago)
Author:
jwedin
Message:

Updated annotation node constructors. Removed redundant calls to isAmbiguous in the mutable state manager. Removed unnecessary state for ambiguous nodes. #5865

Location:
branches/dev-jw-2590/Compiler
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/dev-jw-2590/Compiler/ModelicaFlatTree/src/jastadd/FlatAnnotations.jrag

    r13992 r14001  
    2828    public class FlatAnnotation extends GenericAnnotationNode<FlatAnnotation, FlatAnnotationProvider, FExp> {
    2929
    30         public static final FlatAnnotation AMBIGUOUS_ANNOTATION =  new FlatAnnotation(null, null, null, true);
     30        public static final FlatAnnotation AMBIGUOUS_ANNOTATION =  new FlatAnnotation();
    3131
    3232        /** Creates an unambiguous flat annotation.
     
    3737        }
    3838
    39         /** Creates a flat annotation.
    40          * See {@link GenericAnnotationNode#GenericAnnotationNode(String, AnnotationProvider, GenericAnnotationNode, boolean)}
     39        /** Creates an ambiguous flat annotation.
     40         * See {@link GenericAnnotationNode#GenericAnnotationNode()}
    4141         */
    42         protected FlatAnnotation(String name, FlatAnnotationProvider node, FlatAnnotation parent, boolean ambiguous) {
    43             super(name, node, parent, ambiguous);
     42        protected FlatAnnotation() {
     43            super();
    4444        }
    4545
  • branches/dev-jw-2590/Compiler/ModelicaFrontEnd/src/jastadd/util/SrcAnnotations.jrag

    r13992 r14001  
    106106    public class SrcAnnotationNode extends GenericAnnotationNode<SrcAnnotationNode, SrcAnnotationProvider, SrcExp> {
    107107       
    108         public static final SrcAnnotationNode AMBIGUOUS_ANNOTATION =  new SrcAnnotationNode(null, null, null, SrcAnnotationNode.defaultEvaluator(), true);
     108        public static final SrcAnnotationNode AMBIGUOUS_ANNOTATION =  new SrcAnnotationNode();
    109109       
    110110        private Evaluator<SrcExp> evaluator;
    111111
    112         /** Creates an unambiguous source annotation.
     112        /** Creates an ambiguous source annotation.
     113         * See {@link GenericAnnotationNode#GenericAnnotationNode()}
     114         */
     115        protected SrcAnnotationNode() {
     116            super();
     117            this.evaluator = SrcAnnotationNode.defaultEvaluator();
     118        }
     119
     120        /** Creates a unambiguous source annotation.
    113121         * See {@link GenericAnnotationNode#GenericAnnotationNode(String, AnnotationProvider, GenericAnnotationNode)}
    114122         */
    115         protected SrcAnnotationNode(String name, SrcAnnotationProvider node, SrcAnnotationNode parent,
    116                 Evaluator<SrcExp> evaluator) {
     123        protected SrcAnnotationNode(String name, SrcAnnotationProvider node, SrcAnnotationNode parent, Evaluator<SrcExp> evaluator) {
    117124            super(name, node, parent);
    118             this.evaluator = evaluator;
    119         }
    120 
    121         /** Creates a source annotation.
    122          * See {@link GenericAnnotationNode#GenericAnnotationNode(String, AnnotationProvider, GenericAnnotationNode, boolean)}
    123          */
    124         protected SrcAnnotationNode(String name, SrcAnnotationProvider node, SrcAnnotationNode parent, Evaluator<SrcExp> evaluator, boolean ambiguous) {
    125             super(name, node, parent, ambiguous);
    126125            this.evaluator = evaluator;
    127126        }
  • branches/dev-jw-2590/Compiler/ModelicaFrontEnd/src/java/org/jmodelica/util/annotations/GenericAnnotationNode.java

    r13993 r14001  
    5858
    5959    /**
    60      * Constructor to create an unambiguous annotation node.<br>
    61      * <code>name</code> may be null, some nodes simply do not have a name.<br>
    62      * <code>node</code> may only be null for the instances returned by
    63      * {@link #ambiguousNode()} and nodes which don't exist yet.
    64      *
    65      * @param name Name of the node, optionally null.
    66      * @param node The node that this annotation node represent.
    67      * @param parent The parent of the node
    68      */
    69     protected GenericAnnotationNode(String name, N node, T parent) {
    70         this(name, node, parent, false);
    71     }
    72 
    73     /**
    74      * Constructor to create an annotation node.<br>
     60     * Constructor to create an ambiguous annotation node.<br>
    7561     * An ambiguous node created with this constructor is immutable.
    7662     * That is, calling a state changing method on an unambiguous will not have any effect.
    7763     * No state change will occur nor will any exception be thrown.
     64     */
     65    protected GenericAnnotationNode() {
     66        state = new AmbiguousAnnotationStateManager();
     67    }
     68
     69    /**
     70     * Constructor to create an unambiguous annotation node.<br>
    7871     * <code>name</code> may be null, some nodes simply do not have a name.<br>
    7972     * <code>node</code> may only be null for the instances returned by
     
    8578     * @param ambiguous The ambiguity of the node.
    8679     */
    87     protected GenericAnnotationNode(String name, N node, T parent, boolean ambiguous) {
    88         state = ambiguous ?
    89                 new AmbiguousAnnotationStateManager(name, node, parent) :
    90                 new MutableAnnotationStateManager(name, node, parent);
     80    protected GenericAnnotationNode(String name, N node, T parent) {
     81        state = new MutableAnnotationStateManager(name, node, parent);
    9182    }
    9283
     
    231222     * @param node The new node
    232223     */
    233     @SuppressWarnings("unchecked")
    234224    protected void updateNode(String newName, N node) {
    235225       state.updateNode(newName, node);
     
    722712    public class AmbiguousAnnotationStateManager extends AnnotationStateManager {
    723713
    724         private final String name;
    725         private final N node;
    726         private final T parent;
    727 
    728         protected AmbiguousAnnotationStateManager(String name, N node, T parent) {
    729             this.name = name;
    730             this.node = node;
    731             this.parent = parent;
    732         }
    733714
    734715        @Override
     
    779760        @Override
    780761        protected N node() {
    781             return node;
     762            return null;
    782763        }
    783764
     
    789770        @Override
    790771        protected N peekNode() {
    791             return node;
     772            return null;
    792773        }
    793774
    794775        @Override
    795776        protected String name() {
    796             return name;
     777            return null;
    797778        }
    798779
     
    839820        @Override
    840821        protected T parent() {
    841             return parent;
     822            return null;
    842823        }
    843824
     
    883864            }
    884865
    885             if(!nodeExists() || isAmbiguous()) {
     866            if(!nodeExists()) {
    886867                return;
    887868            }
     
    1003984        @Override
    1004985        protected T forPath(String[] paths, int currentIndex) {
    1005             if (isAmbiguous() || currentIndex == paths.length) {
     986            if (currentIndex == paths.length) {
    1006987                return self();
    1007988            }
     
    11161097        @Override
    11171098        protected V value() {
    1118             if (!nodeExists() || isAmbiguous()) {
     1099            if (!nodeExists()) {
    11191100                return null;
    11201101            }
     
    11351116            if (!valueAnnotation_cacheComputed) {
    11361117                valueAnnotation_cacheComputed = true;
    1137                 if (isAmbiguous()) {
    1138                     valueAnnotation_cache = ambiguousNode();
    1139                 } else if (nodeExists()) {
     1118                if (nodeExists()) {
    11401119                    N annotationNode = valueAsProvider();
    11411120                    if (hasValue() && annotationNode == null) {
     
    11801159        @Override
    11811160        protected boolean hasNode() {
    1182             return isAmbiguous() || node != null;
     1161            return node != null;
    11831162        }
    11841163
  • branches/dev-jw-2590/Compiler/ModelicaFrontEnd/test/junit/org/jmodelica/util/annotations/mock/DummyAnnotationNode.java

    r13992 r14001  
    77public class DummyAnnotationNode extends GenericAnnotationNode<DummyAnnotationNode, DummyAnnotProvider, Evaluable> {
    88
    9     private static DummyAnnotationNode ambiguousNode = new DummyAnnotationNode(null, null, null, true);
     9    private static DummyAnnotationNode ambiguousNode = new DummyAnnotationNode();
    1010
    1111    /** Creates an unambiguous dummy annotation.
     
    1616    }
    1717
    18     /** Creates a dummy annotation.
    19      * See {@link GenericAnnotationNode#GenericAnnotationNode(String, AnnotationProvider, GenericAnnotationNode, boolean)}
     18    /** Creates an ambiguous dummy annotation.
     19     * See {@link GenericAnnotationNode#GenericAnnotationNode()}
    2020     */
    21     public DummyAnnotationNode(String name, DummyAnnotProvider node, DummyAnnotationNode parent, boolean ambiguous) {
    22         super(name, node, parent, ambiguous);
     21    public DummyAnnotationNode() {
     22        super();
    2323    }
    2424
Note: See TracChangeset for help on using the changeset viewer.