/vqdr/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/vqdr/trunk

« back to all changes in this revision

Viewing changes to src/libvqdr/value/value_token.vala

  • Committer: Gustav Hartvigsson
  • Date: 2022-06-01 12:44:04 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20220601124404-mpv4761nr16f0duq
run_gdb.sh +x

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
namespace VQDR.Expression {
2
2
  
3
3
  public abstract class ValueToken : Token {
4
 
    protected ValueToken (int position) {
 
4
    protected ValueToken (int32 position) {
5
5
      base (position);
6
6
    }
7
 
  }
8
 
  
9
 
  public static ValueToken? init_constant_token (long val, int position) {
10
 
    //return new ConstantValueToken (val, position);
11
 
    return null;
12
 
  }
13
 
  
14
 
  public static ValueToken? init_variable_token (string name, int position) {
15
 
    //return new VariableValueToken (name, position);
16
 
    return null;
17
 
  }
18
 
  
19
 
  public static long parse_raw_value (string str) {
20
 
    long ret_val = 0;
21
 
    int i_of_dot = str.index_of_char ('.');
22
 
    if (i_of_dot >= 0) {
23
 
    
24
 
      // Get the decimal value from the string, if such a thing exists.
25
 
      if ((str.length - 1 > i_of_dot)) {
26
 
        ret_val = long.parse ((str + "000").substring (i_of_dot + 1));
27
 
        
28
 
      }
29
 
      
30
 
      // Normalise the digits.
31
 
      while (ret_val > Token.VALUES_PRECISION_FACTOR) {
32
 
        ret_val = ret_val / 10;
33
 
      }
34
 
      
35
 
      // Add intiger value
36
 
      ret_val = ret_val + (long.parse ("0" + str.substring (0, i_of_dot)) * Token.VALUES_PRECISION_FACTOR);
37
 
    } else {
38
 
      ret_val = long.parse (str) * Token.VALUES_PRECISION_FACTOR;
39
 
    }
40
 
    return ret_val;
41
 
  }
42
 
  
 
7
    
 
8
    public static ValueToken? init_constant_token (long val, int32 position) {
 
9
      return new ConstantValueToken (val, position);
 
10
    }
 
11
    
 
12
    public static ValueToken? init_variable_token (string name, int32 position) {
 
13
      return new VariableValueToken (name, position);
 
14
    }
 
15
    
 
16
    public static ValueToken? init_value_token (Value p1, int32 position) {
 
17
      switch (p1.type ()){
 
18
        case (Type.STRING):
 
19
          return init_variable_token (p1.get_string (), position);
 
20
        case (Type.LONG):
 
21
          return new ConstantValueToken (p1.get_long (), position);
 
22
      }
 
23
      return null;
 
24
    }
 
25
  }
43
26
  
44
27
}