## raw-syntax.api
# Compiled by:
#
src/lib/c-kit/src/ast/ast.sublibapi Raw_Syntax {
Pid = pid::Uid;
Aid = aid::Uid;
Tid = tid::Uid;
# Types: preliminary definitions
Storage_Ilk = AUTO
| EXTERN | REGISTER | STATIC | DEFAULT;
Qualifier = CONST
| VOLATILE;
Signedness = SIGNED
| UNSIGNED;
# Signedness_Tag determines whether a type was declared signed or unsigned,
# or the type was assumed to be one or the other.
Signedness_Tag = SIGNDECLARED
| SIGNASSUMED;
Int_Kind = CHAR
| SHORT | INT | LONG | LONGLONG | FLOAT | DOUBLE | LONGDOUBLE;
# BEGIN D
Fractionality = FRACTIONAL
| WHOLENUM;
# FRACTIONAL dominates WHOLENUM.
Saturatedness = SATURATE
| NONSATURATE;
# SATURATE dominates NONSATURATE.
# END D
# Note: Definition of ctype appears later -- it is part of the mutually recursive clump.
# IDENTIFIERS: preliminary definitions
# labels
Label
=
{ name: symbol::Symbol, # The name of the label.
uid: pid::Uid, # Unique identifier.
location: line_number_db::Location
};
Decl_Status
= IMPLICIT # Used, but not yet declared or defined.
| DECLARED
# Declared, but not yet defined.
| DEFINED;
# Defined, i.e. there is a FunctionDef or
# initializer for this identifier
# Identifiers - we call these "id"s:
Id_Kind
= NONFUN # Is not of functional type.
| FUNCTION_KIND
# Is of functional type.
{ has_function_def: Bool }; # Was defined by a FunctionDef.
# OPERATORS
Binop
= PLUS
| MINUS | TIMES | DIVIDE | MOD
| GT | LT | GTE | LTE | EQ | NEQ | AND | OR
| BIT_OR | BIT_AND | BIT_XOR | LSHIFT | RSHIFT
| PLUS_ASSIGN | MINUS_ASSIGN | TIMES_ASSIGN | DIV_ASSIGN
| MOD_ASSIGN | XOR_ASSIGN | OR_ASSIGN | AND_ASSIGN
| LSHIFT_ASSIGN | RSHIFT_ASSIGN | BINOP_EXT raw_syntax_tree_ext::Binop_Ext;
Unop
= UPLUS
| NOT | NEGATE | BIT_NOT
| PRE_INC | POST_INC | PRE_DEC | POST_DEC | UNOP_EXT raw_syntax_tree_ext::Unop_Ext;
# DECLARATIONS
Declaration
= TYPE_DECL { shadow: Null_Or { strct: Bool }, tid: Tid } # Placeholder to indicate where typedefs/enums/structs should be printed.
| VAR_DECL (Id, Null_Or( Init_Expression ))
# STATEMENTS
also
Statement
=
STMT (Core_Statement, Aid, line_number_db::Location)
also
Core_Statement
= EXPR Null_Or( Expression )
| COMPOUND (List( Declaration ), List( Statement ))
| WHILE (Expression, Statement)
| DO (Expression, Statement)
| FOR (Null_Or( Expression ), Null_Or( Expression ), Null_Or( Expression ), Statement)
| LABELED (Label, Statement)
| CASE_LABEL (large_int::Int, Statement)
| DEFAULT_LABEL Statement
| GOTO Label
| BREAK
| CONTINUE
| RETURN Null_Or( Expression )
| IF_THEN (Expression, Statement)
| IF_THEN_ELSE (Expression, Statement, Statement)
| SWITCH (Expression, Statement)
| STAT_EXT raw_syntax_tree_ext::Statement_Ext (Expression, Statement, Binop, Unop)
| ERROR_STMT
# EXPRESSIONS
also
Expression
=
EXPRESSION (Core_Expression, Aid, line_number_db::Location)
also
Core_Expression
= INT_CONST large_int::Int
| REAL_CONST Float
| STRING_CONST String
| CALL (Expression, List( Expression ))
| QUESTION_COLON (Expression, Expression, Expression)
| ASSIGN (Expression, Expression)
| COMMA (Expression, Expression)
| SUB (Expression, Expression)
| MEMBER (Expression, Member)
| ARROW (Expression, Member)
| DEREF Expression
| ADDR_OF Expression
| BINOP (Binop, Expression, Expression)
| UNOP (Unop, Expression)
| CAST (Ctype, Expression)
| ID Id
| ENUM_ID (Member, large_int::Int)
| SIZE_OF Ctype
# not used in compiler mode; sizeof expr becomes sizeof (typeof expr)
| EXPR_EXT raw_syntax_tree_ext::Expression_Ext (Expression, Statement, Binop, Unop)
| ERROR_EXPR
also
Init_Expression
= SIMPLE Expression
| AGGREGATE List( Init_Expression )
also
Ctype
= VOID
| ELLIPSES
| QUAL (Qualifier, Ctype)
| NUMERIC /* D */ (Saturatedness, /* D */ Fractionality, Signedness, Int_Kind, Signedness_Tag)
| ARRAY (Null_Or ((large_int::Int, Expression)), Ctype)
| POINTER Ctype
| FUNCTION (Ctype, List ((Ctype, Null_Or( Id )) ))
| STRUCT_REF Tid
# reference to a tid bound by a struct decl
| UNION_REF Tid
# reference to a tid bound by a union decl
| ENUM_REF Tid
# reference to a tid bound by a enumeration decl
| TYPE_REF Tid
# reference to a tid bound by a typedef decl
| ERROR
# INVARIANT: whenever the ERROR ctype is introduced, an error message will be printed.
# Thus any downstream code processing the ERROR value does not need to (and should not)
# generate additional error messages.
# MEMBERS AND IDENTIFIERS
# Members in structs and unions.
# Also used for named constants in
# enumerations; the ISO Standard calls these "members".
also
Member_Kind
= STRUCTMEM
| UNIONMEM
| ENUMMEM large_int::Int
withtype Member
=
{ name: symbol::Symbol, # The name of the member.
uid: pid::Uid, # Unique identifier.
location: line_number_db::Location,
ctype: Ctype, # Member type.
kind: Member_Kind # Member kind: struct, union, or enum.
}
also
Id =
{ name: symbol::Symbol,
uid: pid::Uid, # Unique identifier.
location: line_number_db::Location,
ctype: Ctype, # Associated type.
st_ilk: Storage_Ilk,
status: Decl_Status,
global: Bool, # Defined at top level.
kind: Id_Kind
};
# The common fields of id and member could be factored out, but
# this would increase space usage and access time, and require
# nested patterns when accessing the common fields. E.g.:
#
# Id =
# { base: Basic_Id,
# st_ilk: Null_Or( storageIlk ),
# kind: Id_Kind
# }
# Top-level program elements:
Core_External_Decl
= EXTERNAL_DECL Declaration
| FUN (Id, List( Id ), Statement)
| EXTERNAL_DECL_EXT raw_syntax_tree_ext::External_Decl_Ext (Expression, Statement, Binop, Unop);
# Marked and (potentially) annotated external declarations:
External_Decl
=
DECL (Core_External_Decl, Aid, line_number_db::Location);
# PROGRAMS
# abstract syntax of "programs", i.e. the result of processing a source file
# also known as a "translation unit"
Raw_Syntax_Tree
=
List( External_Decl );
}; # Api Raw_Syntax
## Copyright (c) 1998 by Lucent Technologies
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2015,
## released per terms of SMLNJ-COPYRIGHT.