Class CodeFlowMap

java.lang.Object
org.ek9lang.compiler.common.CodeFlowMap
All Implemented Interfaces:
CodeFlowAnalyzer
Direct Known Subclasses:
ReplacedInitialiserAnalyzer, UninitialisedVariableAnalyzer, UnSafeGenericAccessAnalyzer, UnSafePropertyAccessAnalyzer

class CodeFlowMap extends Object implements CodeFlowAnalyzer
Designed to be used in a transient manner when interacting with variables. This is typically through the flow of variable use within a bounded scope. For example within a function or a method. It is transient in the sense that it does not live beyond the parsing of a specific source file. So it is not attached to any scopes or symbols. Instead, those scopes and symbols are used as keys to be able to access specific meta-data that is recorded/accessed during flow of the ek9 code.
This approach has been taken to ensure that memory is not excessively used and the scope/symbol concepts are not mixed with what is in effect a sort of interpreter assessment. In addition, the nature of these checks means that it is sort of necessary to almost interpret and hold state for variables the flow is followed through the code block.
While the initial reason for this was assessment of variables being initialised or not within branching structures. It will probably also be useful for the checking of Optional (is-set) and Result ('ok'/'error'). It may even be extendable to assess if conditionals are always true/false and for assessing cyclometric complexity.
  • Field Details

  • Constructor Details

  • Method Details

    • getSymbolsNotMeetingAcceptableCriteria

      public List<ISymbol> getSymbolsNotMeetingAcceptableCriteria(IScope inScope)
      Just provide a list of variables that have not been marked as meeting acceptable criteria in the scope.
      Specified by:
      getSymbolsNotMeetingAcceptableCriteria in interface CodeFlowAnalyzer
    • doesSymbolMeetAcceptableCriteria

      public boolean doesSymbolMeetAcceptableCriteria(ISymbol identifierSymbol, IScope inScope)
      Check if a variable meets the criteria of being acceptable.
      Specified by:
      doesSymbolMeetAcceptableCriteria in interface CodeFlowAnalyzer
    • recordSymbol

      public void recordSymbol(ISymbol identifierSymbol, IScope inScope)
      Records a symbol against the specific scope if it is a variable to be analysed.
      Specified by:
      recordSymbol in interface CodeFlowAnalyzer
    • markSymbolAsMeetingAcceptableCriteria

      public void markSymbolAsMeetingAcceptableCriteria(ISymbol identifierSymbol, IScope inScope)
      Ensures that an identifier symbol is now marked as meeting the criteria of being acceptable.
      Specified by:
      markSymbolAsMeetingAcceptableCriteria in interface CodeFlowAnalyzer
    • symbolsRecordedFrom

      protected List<ISymbol> symbolsRecordedFrom(IScope inScope)
      The variables recorded in this scope or any scope enclosing it, nearest first and each once (by identity).
    • anythingMarkedFrom

      protected boolean anythingMarkedFrom(IScope inScope)
      Was anything marked as meeting the criteria in this scope or any scope enclosing it? When not, nothing there meets them (a mark is only ever copied INTO a scope from the scopes around it) - the cheap answer before a walk.
    • getSymbolAccessForVariable

      protected SymbolAccess getSymbolAccessForVariable(ISymbol identifierSymbol, IScope fromScope)
      The access record of a variable in exactly this scope, made (from the enclosing scopes) when it is not there yet - so a change to it affects this scope and every scope later made inside it, never the enclosing ones.