×

System and method for inferring immutability of program variables

  • US 9,542,166 B2
  • Filed: 11/14/2012
  • Issued: 01/10/2017
  • Est. Priority Date: 10/30/2012
  • Status: Active Grant
First Claim
Patent Images

1. A computer-implemented method for compiling source code using a compiler operating on one or more microprocessor, the method comprising:

  • receiving said source code wherein said source code includes a plurality of local variables wherein each of said plurality of local variables is expressed in said source code without the use of a keyword which expressly declares said each of said plurality of local variables as being immutable;

    identifying with the compiler each of said plurality of local variables in said source code;

    for each local variable of the plurality of said plurality of local variables;

    identifying one or more locations in the source code where said each local variable is assigned;

    if said local variable has an initializer, inferring that said local variable is immutable if said local variable never occurs as an operand of a pre-increment, pre-decrement, post-increment, or post-decrement operator in said source code and never occurs as a left-hand operator of an assignment operator in said source code; and

    if said local variable has no initializer, inferring that said local variable is immutable if said local variable never occurs as an operand of a pre-increment, pre-decrement, post-increment, or post-decrement operator in said source code, and at any location is said source code where said local variable occurs as a left-hand operator of an assignment operator said local variable is definitely unassigned before being assigned; and

    compiling said source code with the compiler to generate bytecode, wherein the compiler treats, during compilation, all of said plurality of local variables inferred as immutable in the same manner as a local variable expressly declared to be immutable.

View all claims
  • 1 Assignment
Timeline View
Assignment View
    ×
    ×