Skip to content

Instantly share code, notes, and snippets.

@sw17ch
Created January 8, 2013 00:32
Show Gist options
  • Save sw17ch/4479944 to your computer and use it in GitHub Desktop.
Save sw17ch/4479944 to your computer and use it in GitHub Desktop.
C is MADNESS

foo.h

#ifndef FOO_H
#define FOO_H

typedef int sometype_t;

void foo(sometype_t t);

#endif /* FOO_H */

foo.c

#include "foo.h"

void foo(sometype_t t) {
}

The AST from parsing foo.c:

CTranslUnit [CDeclExt (CDecl [CStorageSpec (CTypedef (NodeInfo ("c/foo.h": line 4) (("c/foo.h": line 4),7) (Name {nameId = 0}))),CTypeSpec (CIntType (NodeInfo ("c/foo.h": line 4) (("c/foo.h": line 4),3) (Name {nameId = 2})))] [(Just (CDeclr (Just "sometype_t") [] Nothing [] (NodeInfo ("c/foo.h": line 4) (("c/foo.h": line 4),10) (Name {nameId = 3}))),Nothing,Nothing)] (NodeInfo ("c/foo.h": line 4) (("c/foo.h": line 4),1) (Name {nameId = 4}))),CDeclExt (CDecl [CTypeSpec (CVoidType (NodeInfo ("c/foo.h": line 6) (("c/foo.h": line 6),4) (Name {nameId = 6})))] [(Just (CDeclr (Just "foo") [CFunDeclr (Right ([CDecl [CTypeSpec (CTypeDef "sometype_t" (NodeInfo ("c/foo.h": line 6) (("c/foo.h": line 6),10) (Name {nameId = 10})))] [(Just (CDeclr (Just "t") [] Nothing [] (NodeInfo ("c/foo.h": line 6) (("c/foo.h": line 6),1) (Name {nameId = 11}))),Nothing,Nothing)] (NodeInfo ("c/foo.h": line 6) (("c/foo.h": line 6),1) (Name {nameId = 12}))],False)) [] (NodeInfo ("c/foo.h": line 6) (("c/foo.h": line 6),1) (Name {nameId = 13}))] Nothing [] (NodeInfo ("c/foo.h": line 6) (("c/foo.h": line 6),3) (Name {nameId = 7}))),Nothing,Nothing)] (NodeInfo ("c/foo.h": line 6) (("c/foo.h": line 6),1) (Name {nameId = 14}))),CFDefExt (CFunDef [CTypeSpec (CVoidType (NodeInfo ("c/foo.c": line 3) (("c/foo.c": line 3),4) (Name {nameId = 16})))] (CDeclr (Just "foo") [CFunDeclr (Right ([CDecl [CTypeSpec (CTypeDef "sometype_t" (NodeInfo ("c/foo.c": line 3) (("c/foo.c": line 3),10) (Name {nameId = 20})))] [(Just (CDeclr (Just "t") [] Nothing [] (NodeInfo ("c/foo.c": line 3) (("c/foo.c": line 3),1) (Name {nameId = 21}))),Nothing,Nothing)] (NodeInfo ("c/foo.c": line 3) (("c/foo.c": line 3),1) (Name {nameId = 22}))],False)) [] (NodeInfo ("c/foo.c": line 3) (("c/foo.c": line 3),1) (Name {nameId = 23}))] Nothing [] (NodeInfo ("c/foo.c": line 3) (("c/foo.c": line 3),3) (Name {nameId = 17}))) [] (CCompound [] [] (NodeInfo ("c/foo.c": line 3) (("c/foo.c": line 4),1) (Name {nameId = 24}))) (NodeInfo ("c/foo.c": line 3) (("c/foo.c": line 4),1) (Name {nameId = 25})))] (NodeInfo ("c/foo.h": line 4) (("c/foo.c": line 4),1) (Name {nameId = 26}))

...

Ugh.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment