|
5 | 5 | "go/token" |
6 | 6 | "reflect" |
7 | 7 | "strconv" |
8 | | - "strings" |
9 | 8 | ) |
10 | 9 |
|
11 | 10 | // PackageDefinitions files and definition in a package. |
@@ -100,36 +99,10 @@ func (pkg *PackageDefinitions) evaluateConstValue(file *ast.File, iota int, expr |
100 | 99 | case *ast.BasicLit: |
101 | 100 | switch valueExpr.Kind { |
102 | 101 | case token.INT: |
103 | | - // handle underscored number, such as 1_000_000 |
104 | | - if strings.ContainsRune(valueExpr.Value, '_') { |
105 | | - valueExpr.Value = strings.Replace(valueExpr.Value, "_", "", -1) |
106 | | - } |
107 | | - if len(valueExpr.Value) >= 2 && valueExpr.Value[0] == '0' { |
108 | | - var start, base = 2, 8 |
109 | | - switch valueExpr.Value[1] { |
110 | | - case 'x', 'X': |
111 | | - //hex |
112 | | - base = 16 |
113 | | - case 'b', 'B': |
114 | | - //binary |
115 | | - base = 2 |
116 | | - default: |
117 | | - //octet |
118 | | - start = 1 |
119 | | - } |
120 | | - if x, err := strconv.ParseInt(valueExpr.Value[start:], base, 64); err == nil { |
121 | | - return int(x), nil |
122 | | - } else if x, err := strconv.ParseUint(valueExpr.Value[start:], base, 64); err == nil { |
123 | | - return x, nil |
124 | | - } else { |
125 | | - panic(err) |
126 | | - } |
127 | | - } |
128 | | - |
129 | 102 | //a basic literal integer is int type in default, or must have an explicit converting type in front |
130 | | - if x, err := strconv.ParseInt(valueExpr.Value, 10, 64); err == nil { |
| 103 | + if x, err := strconv.ParseInt(valueExpr.Value, 0, 64); err == nil { |
131 | 104 | return int(x), nil |
132 | | - } else if x, err := strconv.ParseUint(valueExpr.Value, 10, 64); err == nil { |
| 105 | + } else if x, err := strconv.ParseUint(valueExpr.Value, 0, 64); err == nil { |
133 | 106 | return x, nil |
134 | 107 | } else { |
135 | 108 | panic(err) |
|
0 commit comments