Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

56
LINES

< > BotCompany Repo | #1034290 // LASValueDescriptor

JavaX fragment (include) [tags: use-pretranspiled]

Transpiled version (5278L) is out of date.

// TODO: Store Class AND Type

// Describes a value during script optimization/type inference.

// In the best case, the exact value is known.
// Next best case is we're knowing its precise type (value of object.getClass()).
// Third best case is we're knowing it's castable to a certain type.
// A completely unknown value is described simply by "new LASValueDescriptor".

persistable sclass LASValueDescriptor {
  bool knownValue() { false; }
  O value() { null; }
  
  Class javaClass() { null; }
  bool javaClassIsExact() { false; }
  bool canBeNull() { true; }
  
  bool canFail() { false; }
  bool willFail() { false; }
  
  srecord Exact(Class c, bool canBeNull) > LASValueDescriptor {
    Class javaClass() { ret c; }
    bool javaClassIsExact() { true; }
    bool canBeNull() { ret canBeNull; }
  }
  
  srecord NonExact(Class c, bool canBeNull) > LASValueDescriptor {
    Class javaClass() { ret c; }
    bool javaClassIsExact() { false; }
    bool canBeNull() { ret canBeNull; }
  }
  
  static LASValueDescriptor nonExactCanBeNull(Type c) {
    ret new NonExact(typeToClass(c), true);
  }
  
  srecord KnownValue(O value) > LASValueDescriptor {
    bool knownValue() { true; }
    O value() { ret value; }
  
    Class javaClass() { ret value?.getClass(); }
    bool javaClassIsExact() { ret value != null; }
    bool canBeNull() { ret value == null; }
  }
  
  // Indicates an exception can be thrown instead of returning a value.
  // Probably we don't need this.
  sclass WillFail > LASValueDescriptor {
    bool canFail() { true; }
    bool willFail() { true; }
  }
  
  static LASValueDescriptor fromClass(Class c) {
    ret new NonExact(c, true);
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1034290
Snippet name: LASValueDescriptor
Eternal ID of this version: #1034290/15
Text MD5: f1a69623bc13747e99bc487a8bcd3160
Author: stefan
Category: javax / left arrow script
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-05-14 00:14:10
Source code size: 1725 bytes / 56 lines
Pitched / IR pitched: No / No
Views / Downloads: 54 / 138
Version history: 14 change(s)
Referenced in: [show references]