github.com/goplus/llgo@v0.8.3/xtool/clang/ast/ast.go (about)

     1  /*
     2   * Copyright (c) 2022 The GoPlus Authors (goplus.org). All rights reserved.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package ast
    18  
    19  // -----------------------------------------------------------------------------
    20  
    21  type IncludedFrom struct {
    22  	File string `json:"file"`
    23  }
    24  
    25  type Loc struct {
    26  	Offset       int64         `json:"offset,omitempty"` // 432
    27  	File         string        `json:"file,omitempty"`   // "sqlite3.i"
    28  	Line         int           `json:"line,omitempty"`
    29  	PresumedFile string        `json:"presumedFile,omitempty"`
    30  	PresumedLine int           `json:"presumedLine,omitempty"`
    31  	Col          int           `json:"col,omitempty"`
    32  	TokLen       int           `json:"tokLen,omitempty"`
    33  	IncludedFrom *IncludedFrom `json:"includedFrom,omitempty"` // "sqlite3.c"
    34  }
    35  
    36  type Pos struct {
    37  	Offset       int64         `json:"offset,omitempty"`
    38  	Col          int           `json:"col,omitempty"`
    39  	TokLen       int           `json:"tokLen,omitempty"`
    40  	IncludedFrom *IncludedFrom `json:"includedFrom,omitempty"` // "sqlite3.c"
    41  	SpellingLoc  *Loc          `json:"spellingLoc,omitempty"`
    42  	ExpansionLoc *Loc          `json:"expansionLoc,omitempty"`
    43  }
    44  
    45  type Range struct {
    46  	Begin Pos `json:"begin"`
    47  	End   Pos `json:"end"`
    48  }
    49  
    50  // -----------------------------------------------------------------------------
    51  
    52  type ID string
    53  
    54  type Kind string
    55  
    56  const (
    57  	TranslationUnitDecl      Kind = "TranslationUnitDecl"
    58  	TypedefType              Kind = "TypedefType"
    59  	TypedefDecl              Kind = "TypedefDecl"
    60  	ElaboratedType           Kind = "ElaboratedType"
    61  	BuiltinType              Kind = "BuiltinType"
    62  	ConstantArrayType        Kind = "ConstantArrayType"
    63  	IncompleteArrayType      Kind = "IncompleteArrayType"
    64  	PointerType              Kind = "PointerType"
    65  	RecordType               Kind = "RecordType"
    66  	RecordDecl               Kind = "RecordDecl"
    67  	FieldDecl                Kind = "FieldDecl"
    68  	IndirectFieldDecl        Kind = "IndirectFieldDecl"
    69  	VarDecl                  Kind = "VarDecl"
    70  	EmptyDecl                Kind = "EmptyDecl"
    71  	EnumDecl                 Kind = "EnumDecl"
    72  	EnumConstantDecl         Kind = "EnumConstantDecl"
    73  	AlwaysInlineAttr         Kind = "AlwaysInlineAttr"
    74  	AsmLabelAttr             Kind = "AsmLabelAttr"
    75  	AvailabilityAttr         Kind = "AvailabilityAttr"
    76  	DeprecatedAttr           Kind = "DeprecatedAttr"
    77  	BuiltinAttr              Kind = "BuiltinAttr"
    78  	FormatAttr               Kind = "FormatAttr"
    79  	FormatArgAttr            Kind = "FormatArgAttr"
    80  	ColdAttr                 Kind = "ColdAttr"
    81  	ConstAttr                Kind = "ConstAttr"
    82  	PureAttr                 Kind = "PureAttr"
    83  	PackedAttr               Kind = "PackedAttr"
    84  	GNUInlineAttr            Kind = "GNUInlineAttr"
    85  	StrictFPAttr             Kind = "StrictFPAttr"
    86  	ReturnsTwiceAttr         Kind = "ReturnsTwiceAttr"
    87  	RestrictAttr             Kind = "RestrictAttr"
    88  	NoThrowAttr              Kind = "NoThrowAttr"
    89  	NoInlineAttr             Kind = "NoInlineAttr"
    90  	NoSanitizeAttr           Kind = "NoSanitizeAttr"
    91  	NonNullAttr              Kind = "NonNullAttr"
    92  	MayAliasAttr             Kind = "MayAliasAttr"
    93  	MSAllocatorAttr          Kind = "MSAllocatorAttr"
    94  	MaxFieldAlignmentAttr    Kind = "MaxFieldAlignmentAttr"
    95  	WarnUnusedResultAttr     Kind = "WarnUnusedResultAttr"
    96  	AllocSizeAttr            Kind = "AllocSizeAttr"
    97  	AlignedAttr              Kind = "AlignedAttr"
    98  	VisibilityAttr           Kind = "VisibilityAttr"
    99  	C11NoReturnAttr          Kind = "C11NoReturnAttr"
   100  	FunctionProtoType        Kind = "FunctionProtoType"
   101  	FunctionDecl             Kind = "FunctionDecl"
   102  	ParmVarDecl              Kind = "ParmVarDecl"
   103  	ParenType                Kind = "ParenType"
   104  	DeclStmt                 Kind = "DeclStmt"
   105  	CompoundStmt             Kind = "CompoundStmt"
   106  	NullStmt                 Kind = "NullStmt"
   107  	ForStmt                  Kind = "ForStmt"
   108  	WhileStmt                Kind = "WhileStmt"
   109  	DoStmt                   Kind = "DoStmt"
   110  	GotoStmt                 Kind = "GotoStmt"
   111  	BreakStmt                Kind = "BreakStmt"
   112  	ContinueStmt             Kind = "ContinueStmt"
   113  	LabelStmt                Kind = "LabelStmt"
   114  	IfStmt                   Kind = "IfStmt"
   115  	SwitchStmt               Kind = "SwitchStmt"
   116  	CaseStmt                 Kind = "CaseStmt"
   117  	DefaultStmt              Kind = "DefaultStmt"
   118  	ReturnStmt               Kind = "ReturnStmt"
   119  	GCCAsmStmt               Kind = "GCCAsmStmt"
   120  	ParenExpr                Kind = "ParenExpr"
   121  	CallExpr                 Kind = "CallExpr"
   122  	ConstantExpr             Kind = "ConstantExpr"
   123  	InitListExpr             Kind = "InitListExpr"
   124  	CStyleCastExpr           Kind = "CStyleCastExpr"
   125  	DeclRefExpr              Kind = "DeclRefExpr"
   126  	MemberExpr               Kind = "MemberExpr"
   127  	ImplicitCastExpr         Kind = "ImplicitCastExpr"
   128  	ImplicitValueInitExpr    Kind = "ImplicitValueInitExpr"
   129  	UnaryExprOrTypeTraitExpr Kind = "UnaryExprOrTypeTraitExpr"
   130  	OffsetOfExpr             Kind = "OffsetOfExpr"
   131  	ArraySubscriptExpr       Kind = "ArraySubscriptExpr"
   132  	AtomicExpr               Kind = "AtomicExpr"
   133  	VAArgExpr                Kind = "VAArgExpr"
   134  	CompoundAssignOperator   Kind = "CompoundAssignOperator"
   135  	BinaryOperator           Kind = "BinaryOperator"
   136  	UnaryOperator            Kind = "UnaryOperator"
   137  	ConditionalOperator      Kind = "ConditionalOperator"
   138  	CompoundLiteralExpr      Kind = "CompoundLiteralExpr"
   139  	PredefinedExpr           Kind = "PredefinedExpr"
   140  	CharacterLiteral         Kind = "CharacterLiteral"
   141  	IntegerLiteral           Kind = "IntegerLiteral"
   142  	StringLiteral            Kind = "StringLiteral"
   143  	FloatingLiteral          Kind = "FloatingLiteral"
   144  	ImaginaryLiteral         Kind = "ImaginaryLiteral"
   145  	AllocAlignAttr           Kind = "AllocAlignAttr"
   146  	DisableTailCallsAttr     Kind = "DisableTailCallsAttr"
   147  	StaticAssertDecl         Kind = "StaticAssertDecl"
   148  )
   149  
   150  type ValueCategory string
   151  
   152  const (
   153  	RValue  ValueCategory = "rvalue"
   154  	PRValue ValueCategory = "prvalue"
   155  	LValue  ValueCategory = "lvalue"
   156  )
   157  
   158  type CC string
   159  
   160  const (
   161  	CDecl CC = "cdecl"
   162  )
   163  
   164  type StorageClass string
   165  
   166  const (
   167  	Static StorageClass = "static"
   168  	Extern StorageClass = "extern"
   169  )
   170  
   171  type CastKind string
   172  
   173  const (
   174  	LValueToRValue           CastKind = "LValueToRValue"
   175  	BitCast                  CastKind = "BitCast"
   176  	FloatingToIntegral       CastKind = "FloatingToIntegral"
   177  	FloatingComplexCast      CastKind = "FloatingComplexCast"
   178  	FloatingRealToComplex    CastKind = "FloatingRealToComplex"
   179  	IntegralRealToComplex    CastKind = "IntegralRealToComplex"
   180  	FloatingCast             CastKind = "FloatingCast"
   181  	IntegralCast             CastKind = "IntegralCast"
   182  	IntegralToPointer        CastKind = "IntegralToPointer"
   183  	IntegralToFloating       CastKind = "IntegralToFloating"
   184  	IntegralToBoolean        CastKind = "IntegralToBoolean"
   185  	FloatingToBoolean        CastKind = "FloatingToBoolean"
   186  	IntegralComplexToBoolean CastKind = "IntegralComplexToBoolean"
   187  	FloatingComplexToBoolean CastKind = "FloatingComplexToBoolean"
   188  	PointerToBoolean         CastKind = "PointerToBoolean"
   189  	PointerToIntegral        CastKind = "PointerToIntegral"
   190  	FunctionToPointerDecay   CastKind = "FunctionToPointerDecay"
   191  	ArrayToPointerDecay      CastKind = "ArrayToPointerDecay"
   192  	BuiltinFnToFnPtr         CastKind = "BuiltinFnToFnPtr"
   193  	ToVoid                   CastKind = "ToVoid"
   194  	NullToPointer            CastKind = "NullToPointer"
   195  	NoOp                     CastKind = "NoOp"
   196  )
   197  
   198  type (
   199  	// OpCode can be:
   200  	//   + - * / || >= -- ++ etc
   201  	OpCode string
   202  )
   203  
   204  type Type struct {
   205  	// QualType can be:
   206  	//   unsigned int
   207  	//   struct ConstantString
   208  	//   volatile uint32_t
   209  	//   int (*)(void *, int, char **, char **)
   210  	//   int (*)(const char *, ...)
   211  	//   int (*)(void)
   212  	//   const char *restrict
   213  	//   const char [7]
   214  	//   char *
   215  	//   void
   216  	//   ...
   217  	QualType          string `json:"qualType"`
   218  	DesugaredQualType string `json:"desugaredQualType,omitempty"`
   219  	TypeAliasDeclID   ID     `json:"typeAliasDeclId,omitempty"`
   220  }
   221  
   222  type Node struct {
   223  	ID                   ID            `json:"id,omitempty"`
   224  	Kind                 Kind          `json:"kind,omitempty"`
   225  	Loc                  *Loc          `json:"loc,omitempty"`
   226  	Range                *Range        `json:"range,omitempty"`
   227  	ReferencedMemberDecl ID            `json:"referencedMemberDecl,omitempty"`
   228  	PreviousDecl         ID            `json:"previousDecl,omitempty"`
   229  	ParentDeclContextID  ID            `json:"parentDeclContextId,omitempty"`
   230  	IsImplicit           bool          `json:"isImplicit,omitempty"`   // is this type implicit defined
   231  	IsReferenced         bool          `json:"isReferenced,omitempty"` // is this type refered or not
   232  	IsUsed               bool          `json:"isUsed,omitempty"`       // is this variable used or not
   233  	IsArrow              bool          `json:"isArrow,omitempty"`      // is ptr->member not obj.member
   234  	IsPostfix            bool          `json:"isPostfix,omitempty"`
   235  	IsPartOfExplicitCast bool          `json:"isPartOfExplicitCast,omitempty"`
   236  	IsBitfield           bool          `json:"isBitfield,omitempty"`
   237  	Inline               bool          `json:"inline,omitempty"`
   238  	StorageClass         StorageClass  `json:"storageClass,omitempty"`
   239  	TagUsed              string        `json:"tagUsed,omitempty"` // struct | union
   240  	HasElse              bool          `json:"hasElse,omitempty"`
   241  	CompleteDefinition   bool          `json:"completeDefinition,omitempty"`
   242  	Complicated          bool          `json:"-"` // complicated statement
   243  	Variadic             bool          `json:"variadic,omitempty"`
   244  	Name                 string        `json:"name,omitempty"`
   245  	MangledName          string        `json:"mangledName,omitempty"`
   246  	Type                 *Type         `json:"type,omitempty"`
   247  	CC                   CC            `json:"cc,omitempty"`
   248  	Field                *Node         `json:"field,omitempty"`
   249  	Decl                 *Node         `json:"decl,omitempty"`
   250  	OwnedTagDecl         *Node         `json:"ownedTagDecl,omitempty"`
   251  	ReferencedDecl       *Node         `json:"referencedDecl,omitempty"`
   252  	OpCode               OpCode        `json:"opcode,omitempty"`
   253  	Init                 string        `json:"init,omitempty"`
   254  	ValueCategory        ValueCategory `json:"valueCategory,omitempty"`
   255  	Value                interface{}   `json:"value,omitempty"`
   256  	CastKind             CastKind      `json:"castKind,omitempty"`
   257  	Size                 int           `json:"size,omitempty"` // array size
   258  	Inner                []*Node       `json:"inner,omitempty"`
   259  	ArrayFiller          []*Node       `json:"array_filler,omitempty"`
   260  }
   261  
   262  // -----------------------------------------------------------------------------