Package sc.lang

Class SemanticNode

    • Field Detail

      • PARENT_NODE_PROPERTY

        public static final java.lang.Object PARENT_NODE_PROPERTY
      • PARSE_NODE_PROPERTY

        public static final java.lang.Object PARSE_NODE_PROPERTY
      • parseNode

        public transient IParseNode parseNode
        This refers to the parse node from which this semantic node was generated. This will be the "root node" which produced this object - i.e. the one which contains the model's definition in its parsed value.
      • parseletId

        public transient int parseletId
      • parseNodeInvalid

        public transient boolean parseNodeInvalid
      • initialized

        protected transient boolean initialized
      • started

        protected transient boolean started
      • validated

        protected transient boolean validated
      • processed

        protected transient boolean processed
      • transformed

        protected transient boolean transformed
      • debugDiffTrace

        public static boolean debugDiffTrace
    • Constructor Detail

      • SemanticNode

        public SemanticNode()
    • Method Detail

      • init

        public void init()
        Specified by:
        init in interface ILifecycle
      • start

        public void start()
        Specified by:
        start in interface ILifecycle
      • ensureValidated

        public void ensureValidated()
      • stop

        public void stop()
        Specified by:
        stop in interface ILifecycle
      • transform

        public boolean transform​(ILanguageModel.RuntimeType runtime)
        Override this to implement a model transformation required to generate a representation in this new runtime language
        Specified by:
        transform in interface ISemanticNode
      • getNestingDepth

        public int getNestingDepth()
        Description copied from interface: ISemanticNode
        Returns the number of levels of nesting of top-level constructs for indentation
        Specified by:
        getNestingDepth in interface ISemanticNode
      • toModelString

        public java.lang.String toModelString​(java.util.Map visited,
                                              int indent)
      • isSemanticProperty

        protected static boolean isSemanticProperty​(IBeanMapper prop)
      • isSemanticProperty

        protected static boolean isSemanticProperty​(java.lang.reflect.Field f)
      • setProperty

        public void setProperty​(java.lang.Object selector,
                                java.lang.Object value)
      • setProperty

        public void setProperty​(java.lang.Object selector,
                                java.lang.Object value,
                                boolean changeParseTree,
                                boolean changeParent)
        This method sets a semantic properties value. if the value is a SemanticNode, it sets the parent property of that node. If changeParseTree is true and this object is started and there is an associated parse-node, that parse-tree is updated incrementally.
      • indexOfChild

        public int indexOfChild​(java.lang.Object toReplace)
        Specified by:
        indexOfChild in interface ISemanticNode
      • containsChild

        public boolean containsChild​(java.lang.Object toReplace)
        Specified by:
        containsChild in interface ISemanticNode
      • replaceChild

        public int replaceChild​(java.lang.Object toReplace,
                                java.lang.Object other)
        Provided with another semantic node that should be type equivalent with this one, we first find this node in the parent's value;
        Specified by:
        replaceChild in interface ISemanticNode
      • removeChild

        public int removeChild​(java.lang.Object toRemove)
        Specified by:
        removeChild in interface ISemanticNode
      • deepEquals

        public boolean deepEquals​(java.lang.Object other)
        The semantic node classes are treated like value classes - they are equal if all of their properties are equal.
        Specified by:
        deepEquals in interface ISemanticNode
      • diffNode

        public void diffNode​(java.lang.Object other,
                             java.lang.StringBuilder diffs)
        The semantic node classes are treated like value classes - they are equal if all of their properties are equal.
        Specified by:
        diffNode in interface ISemanticNode
      • equals

        public boolean equals​(java.lang.Object other)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • getUserVisibleName

        public java.lang.String getUserVisibleName()
      • toDefinitionString

        public java.lang.String toDefinitionString​(boolean addAt)
      • toDefinitionString

        public java.lang.String toDefinitionString()
      • toDeclarationString

        public java.lang.String toDeclarationString()
      • toDefinitionString

        public java.lang.String toDefinitionString​(int indent,
                                                   boolean addAt,
                                                   boolean addNear)
      • toLocationString

        public java.lang.String toLocationString()
      • toLocationString

        public java.lang.String toLocationString​(boolean addFile,
                                                 boolean addNear)
      • toLocationString

        public java.lang.String toLocationString​(Parselet parselet,
                                                 boolean addFile,
                                                 boolean addAt,
                                                 boolean noNear)
      • getAnyChildParseNode

        protected IParseNode getAnyChildParseNode()
      • getStartIndex

        protected int getStartIndex()
      • restoreParseNode

        public boolean restoreParseNode()
      • computeNearString

        public java.lang.String computeNearString​(int indent)
      • deepCopy

        public ISemanticNode deepCopy​(int options,
                                      java.util.IdentityHashMap<java.lang.Object,​java.lang.Object> oldNewMap)
        Description copied from interface: ISemanticNode
        Performs a deep copy of the semantic node tree. Subclasses should do their own copy implementation to decide what else to copy. Uses the copy options flags above. The default, with 0, just copies the semantic node information so you get a new tree like's it parsed but without parse node info. Use that mode only if you want to throw away the original source and regenerate it all from scratch. Otherwise, you can copy the parse tree as well. If you want to copy the semantic node's initial resolved state - including it's init/start, etc. and whatever the subclass adds to that copy, use CopyState or CopyNormal - for both parse nodes and state.
        Specified by:
        deepCopy in interface ISemanticNode
      • setParselet

        public void setParselet​(Parselet p)
        If you create a semantic value by hand that you might want to generate as a top-level object later, this method lets you associate a parselet with that semantic value.
      • isSemanticChildValue

        public boolean isSemanticChildValue​(ISemanticNode child)
        Description copied from interface: ISemanticNode
        Sometimes in a semantic node, you need to add children which are semantic nodes but which are not part of the semantic node tree. For example, in type declaration, we have "hiddenBody" which stores body elements that behave as though they are added to the type but are not saved to the transformed file.

        For these cases, you should override this method and return false when child == hiddenBody. That way, we do not propagate up refresh events and things when nodes in that tree change.

        Specified by:
        isSemanticChildValue in interface ISemanticNode
      • regenerate

        public boolean regenerate​(boolean finalGen)
        Description copied from interface: ISemanticNode
        Regenerates the parsed description for this node
        Specified by:
        regenerate in interface ISemanticNode
      • styleNode

        public void styleNode​(IStyleAdapter adapter)
        Description copied from interface: ISemanticNode
        By default, you configure styles using the parselet's styleName property. When you need to alter the syntax highlighting rules for a given node, you can override this method.
        Specified by:
        styleNode in interface ISemanticNode
      • changeLanguage

        public void changeLanguage​(Language l)
        Description copied from interface: ISemanticNode
        It's common to want to convert from one language to another, particularly when those languages are related in a type hierarchy. For example, our Javascript language derives from Java so you can switch from one to the other. Any overlapping nodes, will swap parselets with the corresponding parselet in the other language. This handles cases like Java arrayInitializer to Javascript array initializer automatically, i.e. those cases which simply reorganize the syntax of the same program elements.
        Specified by:
        changeLanguage in interface ISemanticNode
      • toSafeLanguageString

        public java.lang.String toSafeLanguageString()
      • getNodeErrorText

        public java.lang.String getNodeErrorText()
        Override to provide per-node error support
        Specified by:
        getNodeErrorText in interface ISemanticNode
      • getNotFoundError

        public boolean getNotFoundError()
        Description copied from interface: ISemanticNode
        Returns true if this is a special "not found" error
        Specified by:
        getNotFoundError in interface ISemanticNode
      • hasErrors

        public boolean hasErrors()
      • getNodeWarningText

        public java.lang.String getNodeWarningText()
        Override for per-node warning support
        Specified by:
        getNodeWarningText in interface ISemanticNode
      • getDependencyDisabledText

        public java.lang.String getDependencyDisabledText()
        Description copied from interface: ISemanticNode
        Returns null or the text describing a dependency which is disabled to augment the error - e.g. for when a Layer is disabled and you want to reflect that in the error message you give to the user.
        Specified by:
        getDependencyDisabledText in interface ISemanticNode
      • getEnclosingSrcStatement

        public ISrcStatement getEnclosingSrcStatement()
        Returns the statement which is aligned to the source for debugging purposes that contains this node.
      • refreshNode

        public ISemanticNode refreshNode()
        Description copied from interface: ISemanticNode
        For nodes that are able to re-resolve themselves to the latest version, return the latest version. otherwise returns this.
        Specified by:
        refreshNode in interface ISemanticNode
      • sameSrcLocation

        public boolean sameSrcLocation​(ISemanticNode st)
      • isTrailingSrcStatement

        public boolean isTrailingSrcStatement()
        Description copied from interface: ISemanticNode
        Most statements if started before the newline that signals a breakpoint should be considered the 'source statement' for that line. Block statement is used to signal the end of the statement and is an exception.
        Specified by:
        isTrailingSrcStatement in interface ISemanticNode
      • getParseErrorNode

        public boolean getParseErrorNode()
        Description copied from interface: ISemanticNode
        Returns the value of the parse error node flag. If your semantic value is used in a skipOnErrorParselet, you can implement this to differentiate error nodes from regularly parsed nodes
        Specified by:
        getParseErrorNode in interface ISemanticNode
      • setParseErrorNode

        public void setParseErrorNode​(boolean v)
        Override this for types produced in the skipOnErrorParselet
        Specified by:
        setParseErrorNode in interface ISemanticNode
      • getNodeCount

        public int getNodeCount()
        Description copied from interface: ISemanticNode
        Returns number of nodes in this tree for helping to diagnose memory use
        Specified by:
        getNodeCount in interface ISemanticNode
      • serialize

        public void serialize​(sc.binf.ModelOutStream out)
        Description copied from interface: ISemanticNode
        Saves all of the properties of this model as parsed. If you need to save additional state with the semantic model that's not set directly from the grammar, you can override this method, set additional fields and just make sure they are not marked 'transient'
        Specified by:
        serialize in interface ISemanticNode
      • getNodeErrorRange

        public ParseRange getNodeErrorRange()
        Description copied from interface: ISemanticNode
        Returns null to mark the entire node - otherwise return a range that's more convenient for marking
        Specified by:
        getNodeErrorRange in interface ISemanticNode
      • getStopSemanticProps

        public boolean getStopSemanticProps()