cgo: implement the constant parser as a real parser

Previously it was just a combination of heuristics to try to fit a
constant in an *ast.BasicLit. For more complex expressions, this is not
enough.

This change also introduces proper syntax error with locations, if
parsing a constant failed. For example, this will print a real error
message with source location:

    #define FOO 5)
This commit is contained in:
Ayke van Laethem
2019-11-04 16:30:57 +01:00
committed by Ron Evans
parent 5987233b99
commit cadb75a4aa
4 changed files with 207 additions and 55 deletions
+1 -1
View File
@@ -42,7 +42,7 @@ type cgoPackage struct {
// constantInfo stores some information about a CGo constant found by libclang
// and declared in the Go AST.
type constantInfo struct {
expr *ast.BasicLit
expr ast.Expr
pos token.Pos
}