/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: 2024-12-21 22:39:17 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20241221223917-jbt2ylyz9nxjss49
various changes
[utils/utils.vala]
* Removed uneeded int32_abs function

[utils/stack]
* more informative error when trying to pop an empty stack.

[utils/random.vala]
* added c_names to functions (probobly not needed).

[utils/pair.vala]
* Made compact
* made FreeFunc delegates unowned to fix error
* added constructor Pair.with_free_func ().

[utils/named_vector.vala]
* made class compact.

[utils/meson.build]
* Reordered files in list
* added logger.vala.

[utils/logger.vala]
* Added fast and easy logger class.

[utils/fast_number.vala]
* added a bunch of cname CCode attributes.

[general]
* Spelling in comments and functions.

[meson.build]
* Made dependancies easier to read
* added vala posix dependency

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,
 
13
                                                   int32 position) {
 
14
      return new VariableValueToken (name, position);
 
15
    }
 
16
    
 
17
    public static ValueToken? init_value_token (Value p1, int32 position) {
 
18
      switch (p1.type ()){
 
19
        case (Type.STRING):
 
20
          return init_variable_token (p1.get_string (), position);
 
21
        case (Type.LONG):
 
22
          return new ConstantValueToken (p1.get_long (), position);
 
23
      }
 
24
      return null;
 
25
    }
 
26
  }
43
27
  
44
28
}