FAQ
I am working on a project which will allow types to be specified in plain
string form. Starting with that plain string, I'd like to get the type's
(ultimate) backing type. The best enumeration of backing types that I am
aware of is reflect.Kind <http://golang.org/pkg/reflect/#Kind>.

I have a package's ast, and a string which names a type ("int" or "MyType"
or "[]YourType"). Let's assume that any types are either builtin or
specified in the package for which I have the ast. External dependencies
are out of scope.

If I'd like to discover whether MyType is ultimately backed by float64, how
might I do that, given the above?

As I mentioned, reflect.Kind is the *form* of data I am looking for but
it's important to note what I am doing is *not at runtime*. I am inspecting
source code, not reflecting on instances. (Though maybe a solution involves
doing so somehow.)

Looking for ideas, and let me know if the problem description confuses.
Thanks!

- Matt

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Rémy Oudompheng at Dec 29, 2013 at 9:04 pm

    On 2013/12/29 Matt Sherman wrote:
    I am working on a project which will allow types to be specified in plain
    string form. Starting with that plain string, I'd like to get the type's
    (ultimate) backing type. The best enumeration of backing types that I am
    aware of is reflect.Kind.

    I have a package's ast, and a string which names a type ("int" or "MyType"
    or "[]YourType"). Let's assume that any types are either builtin or
    specified in the package for which I have the ast. External dependencies are
    out of scope.

    If I'd like to discover whether MyType is ultimately backed by float64, how
    might I do that, given the above?

    As I mentioned, reflect.Kind is the form of data I am looking for but it's
    important to note what I am doing is not at runtime. I am inspecting source
    code, not reflecting on instances. (Though maybe a solution involves doing
    so somehow.)

    Looking for ideas, and let me know if the problem description confuses.
    Thanks!
    You may be looking for the "Eval" function of the go/types package.

    http://godoc.org/code.google.com/p/go.tools/go/types#Eval

    Rémy.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Matt Sherman at Dec 31, 2013 at 1:58 am
    Thanks! Looks like the right thing. The step from an ast to meaningful type
    information was the missing bit.
    On Sunday, December 29, 2013 4:04:14 PM UTC-5, Rémy Oudompheng wrote:
    On 2013/12/29 Matt Sherman <mwsh...@gmail.com <javascript:>> wrote:
    I am working on a project which will allow types to be specified in plain
    string form. Starting with that plain string, I'd like to get the type's
    (ultimate) backing type. The best enumeration of backing types that I am
    aware of is reflect.Kind.

    I have a package's ast, and a string which names a type ("int" or "MyType"
    or "[]YourType"). Let's assume that any types are either builtin or
    specified in the package for which I have the ast. External dependencies are
    out of scope.

    If I'd like to discover whether MyType is ultimately backed by float64, how
    might I do that, given the above?

    As I mentioned, reflect.Kind is the form of data I am looking for but it's
    important to note what I am doing is not at runtime. I am inspecting source
    code, not reflecting on instances. (Though maybe a solution involves doing
    so somehow.)

    Looking for ideas, and let me know if the problem description confuses.
    Thanks!
    You may be looking for the "Eval" function of the go/types package.

    http://godoc.org/code.google.com/p/go.tools/go/types#Eval

    Rémy.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedDec 29, '13 at 8:28p
activeDec 31, '13 at 1:58a
posts3
users2
websitegolang.org

2 users in discussion

Matt Sherman: 2 posts Rémy Oudompheng: 1 post

People

Translate

site design / logo © 2022 Grokbase