Upgrade to Pro — share decks privately, control downloads, hide ads and more …

go generate と go/ast のざっくりとした話

go generate と go/ast のざっくりとした話

go generateとgo/astの話をざっくりとします。

Masashi Salvador Mitsuzawa

October 06, 2016
Tweet

More Decks by Masashi Salvador Mitsuzawa

Other Decks in Programming

Transcript

  1. HPHFOFSBUF"45΀5*14
    .BTBTIJ4BMWBEPS.JUTV[BXB!FVSFLB

    View Slide

  2. BCPVU8IP*BN
    .BTBTIJ4BMWBEPS.JUTV[BXB
    UXJUUFS!.BTBTIJ4BMWBEPS
    4FSWFSTJEFFOHJOFFS!QBJSTEJWJTJPO
    ܦྺ
    ݄%F/"ೖࣾ
    ݄Τ΢ϨΧೖࣾ 1)1(P%BUB.JHSBUJPOQSPEVDU։ൃ

    ޷͖ͳݴޠ
    3VCZ (PMBOH +BWBTDSJQU )BTLFMM
    ݩʑͷઐ໳
    ܭࢉ࿦తਆܦՊֶʢ೴ͷۭؒهԱʹؔ͢Δ਺ཧϞσϧͷݚڀʣ
    ػցֶशʢಛʹڧԽֶशʣ
    झຯ
    ஡ಓࣗసंΞ΢τυΞόοΫύοΧʔ

    ΧϨʔ৯͏ͨΊʹੜ͖ͯΔ

    View Slide

  3. (P΀ṽ͟ͼᖃ
    4JNQMJDJUZ
    EPU(P3PC1JLF4JNQMJDJUZJT$PNQMJDBUFE
    5IFTUBUFPG(P

    View Slide

  4. HPHFOFSBUF
    HP͝ΛႳ᥍
    5IFHPDPNNBOEIBTBOFXTVCDPNNBOE HPHFOFSBUF
    UPBVUPNBUFUIFSVOOJOHPGUPPMTUPHFOFSBUFTPVSDFDPEFCFGPSFDPNQJMBUJPO

    θϸϖΩϰ᧸ͽς⑲ξθ⑲ώΤᓺᕧͫΝͱΓ΀ω⑲ϰ΀࣮ḝΤᥦხặͫΝ

    -FUUIFNBDIJOFEPUIFXPSL 3PC1JLF (FOFSBUJOHDPEF 5IF(P#MPH

    3FMFBTF/PUFΚΜ
    (P΀ς⑲ξθ⑲ώ΀θϦϸύͽ
    ᑿ͖ፖ
    Τᔉ͟

    View Slide

  5. 4USJOHFS΀ᆚď໋ᙚϛϲεΚΜĐ
    ᨷ਺ᨷᤅ የᥙᅾ͹ᶡᙎͩͱ͖
    ͥΞΤბႷᗌ͹ᔉ͡΀΁ͶΛ͖
    TUSJOHFSθϣϸώ͹ᥦხᓺᕧͫΝ

    View Slide

  6. 4USJOHFS΀ᆚď໋ᙚϛϲεΚΜĐ
    QJMMHP [email protected] ᥦხᓺᕧͧΞͱθ⑲ώĐ
    ᥦხᓺᕧ΁͖͖͞
    5IFSFTOPRVFTUJPOUIFHFOFSBUFENFUIPEJTVHMZ
    5IBUT0, UIPVHI CFDBVTFIVNBOTEPOUOFFEUPXPSLPOJU
    3PC1JLF (FOFSBUJOHDPEF 5IF(P#MPH

    ຖỹTUSJOHFSθϣϸώΤຒ͡Ħ.BLFGJMFᄑͽ᪝ΑࠐΒĦ
    ᨷ਺ᨷᤅϚΦΩϰ͞૿͚ͱΛ

    View Slide

  7. 4USJOHFS΀ᆚď໋ᙚϛϲεΚΜĐ
    QJMMHPXJUIHPHFOFSBUF
    -FUTHPHFOFSBUF

    View Slide

  8. HPHFOFSBUFͺᷯΡͭ͸ᑿ͚Νθ⑲ώᓺᕧω⑲ϰ
    DMJQQFSIPVTFHFO
    NPOPDISPNFHBOFBSHFO
    ཋ᪦ମͽ"DUJWF3FDPSEϮΩδͼϦςψώΤᓺᕧ
    ODXHPUFNQMBUF
    ᬥᨷͩͱUFNQMBUF 4FU )FBQ ಠᥦᨷᤅ൱ĐͽᷯΡͭ͸θ⑲ώΤᓺᕧ
    QRVFSOBGGKTPO
    ᴢᓝΚΜᖩ͖.BSTIBM+40/6ONBSTIBM+40/Τᓺᕧ

    View Slide

  9. ͯ΀᳔Κ͔͡Νᑿᠭ᎚
    NPDL΀ᓺᕧ
    WFLUSBNPDLFSZ
    HPMBOHNPDL
    +40/ᄑϚΨ⑲ϰώτε΀ᓺᕧ
    GBWDMJQKXH
    XJUIHPCJOEBUB

    View Slide

  10. FVSFLB͹΀ሆᠭᆚ
    ᧸ᘥ΀HPCJOEBUB
    SPVUJOH΀ᕓᨷϚΦΩϰ͝Λς⑲ξθ⑲ώ΀ᓺᕧ
    TFSWJDFGBDBEFXPSLFSᄑᥦხᓺᕧͩ͸͖ΝϯϢνύϯΔ
    ό⑲τมỐᠭ΀ΧϜϯζ⑲μϬϸ
    ϲνψδĤᤫ΀ᗌ͞ᶶ᠓ͼᐙᐠͲ࣮ͣ૷ͫΝ
    !.BTBTIJ4BMWBEPS෪ᤫͺͩ͸
    YP͹%#͝ΛᬿᨭϧόϰΤᓺᕧ

    View Slide

  11. FVSFLB͹΀ሆᠭᆚ
    ᧸ᘥ΀HPCJOEBUB
    SPVUJOH΀ᕓᨷϚΦΩϰ͝Λς⑲ξθ⑲ώ΀ᓺᕧ
    TFSWJDFGBDBEFXPSLFSᄑᥦხᓺᕧͩ͸͖ΝϯϢνύϯΔ
    ό⑲τมỐᠭ΀ΧϜϯζ⑲μϬϸ
    ϲνψδĤᤫ΀ᗌ͞ᶶ᠓ͼᐙᐠͲ࣮ͣ૷ͫΝ
    !.BTBTIJ4BMWBEPS෪ᤫͺͩ͸
    YP͹%#͝ΛᬿᨭϧόϰΤᓺᕧ

    View Slide

  12. ͥͥ͝Λ"45΀ề

    View Slide

  13. HFOFSBUF͹ᑿ͘උ᪽θϣϸώ͵͸ͻ͘ხ͖͸ΝΥͲĦͺ͖͘ᤃዧ
    ᆚ͚΂+40/΀ϚΨ⑲ϰώτεᓺᕧ
    --᧣ͼൃᓡ
    ͹ͺΜ͔͚ͬᩆྥᶡḿ͹៬ᦐΝ
    ǹ
    ͶΛ͖
    උ᪽θϣϸώ΀ς⑲ξΤಡΒͺ"45Τᑿ͵͸͖ΝΛ͖ͩ
    "45 ᱢᓯཋየኴ

    θϸϖΩϮ͞࿖͘ϜϲεϮϥ΀ᬊණᶡḿ
    ďͼͻϜϲεϮϥ΀᣾ዳͽؔ๹΀ͼ͖ဒ߸΁ᕭᅊͧΞΝ
    ϜϲεϮϥª TDBOOFS
    ª5PLFO΀ᅾª QBSTFS
    ª"45
    ᶝ᫿ϮΩϛϮϯHPBTU HPQBSTFS HPUPLFO᪰͞᦬ͩ͸͖Ν

    View Slide

  14. HPBTU HPQBSTFS HPUPLFO΀ᑿ͖ፖ
    ཋየኴ᳼ᓷᠭ΀ؔ਺
    *OTQFDU
    TXJUDIΔͩ͡΁ṞΧκ⑲μϬϸ͹኷᧣΀ϓ⑲ώΤᄌΝ
    8BML
    ຾͵ͱΛ1SJOUຉ΀ؔ਺͹ኴᥦମΤ฼Ν
    1SJOU
    'QSJOU

    View Slide


  15. View Slide

  16. ͯ΀᳔BTUΤᑿ͵͸͹͟Νͥͺ
    ੩᧣ḑᔡ
    ᘊỖᏝࡶႷ΀ຌᒿ
    IUUQRJJUBDPNLOTIJUFNTGEGCFDDB
    FYQPSUͧΞ͸͖Ν͞ዹᑿᠭ΀ม਺΀ݕᬰ
    KHBVUIFSPOVTFEFYQPSUT
    Ჩͺͩ͸᪞ΜጿͧΞ͸͖Ν਺ᥙΖየᥙᅾ΀ݕᲇ

    View Slide

  17. ΐͺΓ
    HPHFOFSBUF
    ཋ᪦ମ΀ቤΓࠐΑΤᑿ͘ͺͥΟͺᫍΑᐠͣͶͶ͘ΐ͡ᑿ͘ͺŸ
    ჯͪΚ͘ͼᶡဒ΀෶ᖃ΁UFNQMBUFͽᄢͺͩ͸ᥦხᓺᕧ͹͟ΝͺŸ
    WTSFGMFDU
    ϖϚή⑲ϣϸξďᖩႷĐ᧣ͽዧ᩼͞ပͥΜΖ͖ͫ
    ࣮ḝᙉͽQBOJD᧣ͼͥͺͽͼΜΖ͖ͫ
    JOUFSGBDF\^Ṟᙼ͖
    HPBTU
    ᣾៷ͺඦ୯
    BOOPUBUJPOΤ᳼ͫϚΨ⑲ϰώτεΤḑᔡͫΝᄑ΁ᷡΜͺၛᲝ͖
    ၛᲝ͖͞Θ͚ͽಡΓΝᔉͣΝ
    SFBEBCJMJUZJTUIFNPTUJNQPSUBOUGFBUVSFPGQSPHSBNNJOHMBOHVBHF

    View Slide

  18. UIBOLT

    View Slide