;; -*- lisp -*-

; This file is part of the nesC compiler.
; 
; This file is derived from the RC Compiler. It is thus
;    Copyright (C) 2000-2001 The Regents of the University of California.
; Changes for nesC are
;    Copyright (C) 2002 Intel Corporation
; 
; The attached "nesC" software is provided to you under the terms and
; conditions of the GNU General Public License Version 2 as published by the
; Free Software Foundation.
; 
; nesC is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU General Public License for more details.
; 
; You should have received a copy of the GNU General Public License
; along with nesC; see the file COPYING.  If not, write to
; the Free Software Foundation, 59 Temple Place - Suite 330,
; Boston, MA 02111-1307, USA.

;; AST definition

;; (deffield FIELD-NAME C-TYPE (ATTRIBUTES))
;; (deftype TYPE-NAME SUPER-TYPE (FIELDS) "DOCUMENTATION")
;; (defnode NODE-NAME TYPE-NAME "DOCUMENTATION")

;; deffield:
;; Define field FIELD-NAME with type C-TYPE. The attributes listed are 
;; interpreted by the various generators, attributes are either symbols,
;; or lists whose first element is a symbol

;; Current attributes:
;;   init: field is an argument to the constructing function for the types
;;         that contain it
;;   tree: "part of" the abstract syntax tree. this means that
;;         generated functions that walk the tree (XXX_walk, XXX_print) 
;;	   will follow this field recursively
;;   nodump: field is not marshalled/unmarshalled
;;   noprint: field is not printed as part of AST
;;   dump-special: call dump_FIELD-NAME to marshall/unmarshall this node
;;   print-special: call print_FIELD-NAME to print node



(deffield temp int (nodump noprint (default "23"))) ; a random int field with default value 23

(deffield type type ())
(deffield declared_type type ())
(deffield name "const char *" ())
(deffield location location (init))
(deffield next "node sameregion" ()) 
(deffield asttype asttype (init tree))
(deffield condition expression (init tree))
(deffield arg1 expression (init tree))
(deffield arg2 expression (init tree))
(deffield arg3 expression (init tree))
(deffield stmt statement (init tree))
(deffield stmt1 statement (init tree))
(deffield stmt2 statement (init tree))
(deffield stmts statement (init tree))
(deffield asm_stmt asm_stmt (init tree))
(deffield extension bool ())
(deffield label label (init tree))
(deffield labels label (init tree))
(deffield id_label id_label (init tree))
(deffield id_labels id_label (init tree))
(deffield cstring cstring (init))
(deffield word1 word (init tree))
(deffield word2 word (init tree))
(deffield strings string_cst (init tree))
(deffield args expression (init tree))
(deffield modifiers type_element (init tree))
(deffield qualifiers type_element (init tree))
(deffield init_expr expression (init tree))
(deffield parms declaration (init tree))
(deffield gparms declaration (init tree))
(deffield decl declaration (init tree))
(deffield decls declaration (init tree))
(deffield asm_operands1 asm_operand (init tree))
(deffield asm_operands2 asm_operand (init tree))
(deffield asm_clobbers string (init tree))
(deffield doublecst "long double" (init))
(deffield id "enum rid" (init))
(deffield declarator declarator (init tree))
(deffield string string (init tree))
(deffield fields declaration (init tree))
(deffield defined bool (init))
(deffield parent_function function_decl (init))
(deffield env environment (init))
(deffield ddecl data_declaration (init))
(deffield ident identifier (init))
(deffield incrementrc bool (init))
(deffield old_parms declaration (init))
(deffield attributes attribute (init tree))
(deffield length size_t (init))
(deffield cval cval (init))
(deffield va_arg_call asttype (init))

(deffield parent "node sameregion" ())
(deffield parent_ptr "node sameregion *sameregion" ())
(deffield tdecl tag_declaration ())
(deffield context context ())
(deffield fdeclarator function_declarator ())
(deffield lvalue bool ())
(deffield bitfield bool ())
(deffield isregister bool ())
(deffield side_effects bool ())
(deffield cst known_cst ())
(deffield static_address known_cst ())
(deffield undeclared_variables env ())
(deffield base_labels env ())
(deffield scoped_labels env ())
(deffield ldecl label_declaration ())
(deffield parent_loop statement ())
(deffield current_loop statement ())
(deffield next_label label ())
(deffield nlocals int ())
(deffield break_dest node ())
(deffield continue_dest node ())
(deffield forward bool ())
(deffield converted_to_pointer bool ())
(deffield fdecl field_declaration ())
(deffield cst_checked bool ())
(deffield instantiation node ())
(deffield spelling "const char *" ())
(deffield parens bool ())
(deffield ivalue ivalue ())

;; nesc fields
(deffield call_kind nesc_call_kind (init))
(deffield implementation implementation (init tree))
(deffield required bool (init))
(deffield ep1 endpoint (init tree))
(deffield ep2 endpoint (init tree))
(deffield ids parameterised_identifier (init tree))
(deffield external bool (init))
(deffield ienv environment (init))
(deffield designator designator (init tree))
(deffield abstract bool (init))
(deffield containing_atomic atomic_stmt ())
(deffield type_checked bool ())
(deffield isatomic atomic_t ((default "NOT_ATOMIC")))
(deffield return_type asttype (tree))

(deffield cdecl nesc_declaration ())
(deffield temp1 data_declaration ())
(deffield temp2 data_declaration ())

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Base types
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(deftype node nil (location next parent parent_ptr instantiation)
  "The common supertype of all AST nodes")

(deftype declaration node ()
  "The common type of all definitions")

(deftype statement node (parent_loop containing_atomic isatomic)
  "The common type of all statements
PARENT_LOOP: 
  - for break and continue: the containing for/while/do-while/switch
    statement they escape from
  - for for/while/do-while: the containing for/while/do-while/switch
    statement
CONTAINING_ATOMIC
  - for return statement: their containing atomic statement
  - for labels and looping statements, their containing atomic statement
(or NULL for none). Used to check that break, continue and goto do not
break in or out of an atomic statement.
(Note: for nested atomic statements, CONTAINING_ATOMIC will point to a
dangling node as we drop these nested statements from the AST)
ISATOMIC is 
  ATOMIC_ANY if the statement does not involve any shared variable accesses
  ATOMIC_SINGLE if the statement involves a single access to a shared 
    variable, and that access is guaranteed to be atomic (e.g., a single byte)
  NOT_ATOMIC otherwise")

(deftype expression node (lvalue side_effects cst bitfield isregister
			  type static_address converted_to_pointer
			  cst_checked spelling parens ivalue context
			  isatomic)
  "Expression nodes are subtypes of this type.
LVALUE is true if this expression can be used in a context requiring an lvalue.
BITFIELD is true if this lvalue is a bitfield.
ISREGISTER is true if this lvalue is (declared to be) in a register.
SIDE_EFFECTS is true if the expression has side effects.
CST is non-null (and points to an appropriate constant) if this expression is
constant.
STATIC_ADDRESS is true for lvalues whose address is a constant expression
CONVERTED_TO_POINTER is true for expressions which default_conversion
indicates need converting to pointer type (note that these nodes did not have
their type changed)
CST_CHECKED is set to true once we've successfully checked this expression's
constantness, and associated constant value (used to avoid duplicate error
messages in repeated constant folding passes)
SPELLING saves the `spelling' (a user-friendly name) of expressions used
in initialisers.
PARENS is TRUE if the expression is in parentheses
IVALUE is a pointer to an ivalue (see init.h) holding the value of an
  initialiser expression. On an init_list or in an expression used as
  a simple initialiser (e.g., '3 + 2' in 'int x = 3 + 2'), this is the
  value of the initialiser. Inside these initialisers, ivalue points into
  the ivalue structure of the containing initialiser.
CONTEXT is the usage context for this expression (see nesc-uses.h)
ISATOMIC is 
  ATOMIC_ANY if the statement does not involve any shared variable accesses
  ATOMIC_SINGLE if the statement involves a single access to a shared 
    variable, and that access is guaranteed to be atomic (e.g., a single byte)
  NOT_ATOMIC otherwise")

(deftype type_element node ()
  "A common super-type for all type-building elements (qualifiers, etc)")

(deftype declarator node ()
  "A common super-type for all declarator elements")

(deftype label node (next_label)
  "A common super-type for all labels.
NEXT_LABEL points to the next case or default label of a switch 
(for case or default labels only)")

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Declarations
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defnode error_decl declaration "Placeholder for erroneous declarations")

(deftype asm_decl declaration (asm_stmt)
  "Asm statement STMT at the top level of a file (GCC)")

(deftype data_decl declaration (modifiers decls)
  "The declaration MODIFIERS DECLS;
DECLS is a list")

(deftype extension_decl declaration (decl)
  "__extension__ DECL; (GCC)")

(deftype ellipsis_decl declaration ()
  "A pseudo-declaration to represent ... in a function argument list")

(deftype enumerator declaration (cstring arg1 ddecl)
  "The enumeration element CSTRING = ARG1. CSTRING is optional")

(deftype oldidentifier_decl declaration (cstring ddecl)
  "CSTRING in an old-style parameter list")

(deftype function_decl declaration (declarator modifiers attributes old_parms stmt
				    parent_function ddecl fdeclarator
				    declared_type undeclared_variables
				    base_labels scoped_labels current_loop
				    nlocals)
  "A function declaration with body STMT
OLD_PARMS is the old-style parameter declaration list.")

(deftype implicit_decl declaration (ident)
  "Used as the AST node for implicit declarations. IDENT points to the
identifier node that implicitly declared the function")

(deftype variable_decl declaration (declarator attributes arg1 asm_stmt
				    ddecl declared_type forward)
  "Declaration of DECLARATOR ASM_STMT ATTRIBUTES = ARG1.
ATTRIBUTES is a list. ASM_STMT is optional (GCC specific).
ARG1 is an optional initialiser.
DDECL points to the declaration for this item.
DECLARED_TYPE is the type in this declaration (which may be different than that
in DDECL->TYPE)
FORWARD is true for parameters that are forward declarations")

(deftype field_decl declaration (declarator attributes arg1 type_checked fdecl)
  "Declaration of field DECLARATOR ATTRIBUTES : ARG1.
QUALIFIERS and ATTRIBUTEES are lists. ARG1 is an optional bitfield specifier
TYPE_CHECKED is set to true once it has been checked that this field is of
  network type (inside network structures)
FDECL is this field's declaration")

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Types and type elements
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(deftype asttype node (declarator qualifiers type)
  "The source-level type QUALIFIERS DECLARATOR")

(deftype typename type_element (ddecl)
  "typedef-type with declaration DDECL. The name is ddecl->name")

(deftype typeof_expr type_element (arg1)
  "typeof ARG1")

(deftype typeof_type type_element (asttype)
  "typeof(ASTTYPE)")

(deftype attribute type_element (word1)
  "base type for gcc and nesc attributes")

(deftype gcc_attribute attribute (args)
  "The (gcc) attribute WORD1(ARGS). args can be empty, and may not be
semantically valid")

(deftype rid type_element (id)
  "Storage class specifier, type specifier or type qualifier ID (see RID_xxx)")

(deftype qualifier type_element (id)
  "Type or function qualifier ID (see qualifiers.h and type_quals in types.h)")

(deftype tag_ref type_element (word1 attributes fields defined
                               tdecl)
  "struct/union/enum WORD1 { FIELDS; }  ATTRIBUTES
ATTRIBUTES and FIELDS are lists.
ATTRIBUTES is GCC specific. WORD1 is optional.
DEFINED is TRUE if this declaration defines the struct/union/enum.
DEFINED == FALSE => FIELDS == NULL

TDECL points to the internal declaration node for this type")

(deftype struct_ref tag_ref () "A struct")
(defnode attribute_ref tag_ref "An attribute definition")
(deftype union_ref tag_ref () "A union")
(defnode enum_ref tag_ref "An enum")

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Declarators
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; The last DECLARATOR in a chain is:
;;   NULL_NODE in absolute declarations
;;   an identifier_decl otherwise

(deftype nested_declarator declarator (declarator)
  "A common supertype for function/pointer/array declarator which includes
the nested DECLARATOR")

(deftype function_declarator nested_declarator (parms gparms qualifiers env
						return_type)
  "Function declarator DECLARATOR(PARMS). PARMS is a list of declarations.
ENV is the environment for parms
GPARMS is the list of declarations of generic parameters (commands, events only)
RETURN_TYPE (optional) contains an overridden return type from nesdoc")

(deftype pointer_declarator nested_declarator ()
  "Pointer declarator *DECLARATOR")

(deftype qualified_declarator nested_declarator (modifiers)
  "Declarator MODIFIERS DECLARATOR. The MODIFIERS are qualifiers
or attributes.
Note: MODIFIERS is never NULL")

(deftype array_declarator nested_declarator (arg1)
  "Array declarator DECLARATOR[ARG1]. ARG1 is optional")

(deftype identifier_declarator declarator (cstring)
  "Declaration of CSTRING")

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Statements
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defnode error_stmt statement "Placeholder for erroneous statements")

(deftype asm_stmt statement (arg1 asm_operands1 asm_operands2 asm_clobbers qualifiers)
  "The statement asm QUALIFIERS (ARG1 : ASM_OPERANDS1 : ASM_OPERANDS2 : ASM_CLOBBERS) 
where ASM_OPERANDS1, ASM_OPERANDS2, QUALIFIERS are optional, ASM_CLOBBERS is a list (GCC)")

(deftype compound_stmt statement (id_labels decls stmts env)
  "{ ID_LABELS DECLS STMTS }. The ID_LABELS are GCC-specific. ID_LABELS, DECLS,
STMTS are lists
ENV is the environment for the block")

(deftype if_stmt statement (condition stmt1 stmt2)
  "IF (CONDITION) STMT1 ELSE STMT2. STMT2 is optional")

(deftype labeled_stmt statement (label stmt)
  "LABEL: STMT")

(deftype expression_stmt statement (arg1)
  "EXPR;")


(deftype conditional_stmt statement (condition stmt)
  "Basic type for all conditional statements")
(defnode while_stmt conditional_stmt "WHILE (CONDITION) STMT")
(defnode dowhile_stmt conditional_stmt "DO STMT WHILE (CONDITION")
(deftype switch_stmt conditional_stmt (next_label) 
  "SWITCH (CONDITION) STMT.
NEXT_LABEL points to the switches first label")

(deftype for_stmt statement (arg1 arg2 arg3 stmt)
  "FOR (ARG1; ARG2; ARG3) STMT. ARG1, ARG2, ARG3 are optional")

(deftype break_stmt statement ()
  "BREAK;")

(deftype continue_stmt statement ()
  "CONTINUE;")

(deftype return_stmt statement (arg1)
  "RETURN ARG1. ARG1 is optional")

(deftype goto_stmt statement (id_label)
  "GOTO ID_LABEL")

(deftype computed_goto_stmt statement (arg1)
  "GOTO *ARG1 (GCC)")

(deftype empty_stmt statement ()
  ";")

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Expressions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defnode error_expr expression "Placeholder for erroneous expressions")

(deftype unary expression (arg1)
  "Unary expression nodes, kind defines operator")

(deftype binary expression (arg1 arg2)
  "Binary expression nodes, kind defines operator")

(deftype comma expression (arg1)
  "A comma separated list of expressions ARG1")

(deftype sizeof_type expression (asttype)
  "sizeof (ASTTYPE)")

(deftype alignof_type expression (asttype)
  "__alignof (ASTTYPE) (GCC)")

(deftype label_address expression (id_label)
  "&&ID_LABEL (GCC)")

(deftype cast unary (asttype)
  "(ASTTYPE)ARG1")

(deftype cast_list expression (asttype init_expr)
  "(ASTTYPE){INIT_EXPR} (GCC)")

(deftype conditional expression (condition arg1 arg2)
  "CONDITION ? ARG1 : ARG2
   GCC specific: ARG1 is optional")

(deftype identifier expression (cstring ddecl)
  "The identrifier CSTRING
DEAD_USE is true for identifiers used as the target of a regular assignment")

(deftype compound_expr expression (stmt)
  "({stmt}) (GCC)")

(deftype function_call expression (arg1 args va_arg_call call_kind)
  "ARG1(ARGS). ARGS is a list of expressions
If VA_ARG_CALL is non-null, this is actually a call to the pseudo-function
__builtin_va_arg(args, va_arg_call) (where va_arg_call is a type). In 
this case arg1 is a dummy identifier.
CALL_KIND is one of normal_call, post_task, command_call or event_signal.")

(defnode array_ref binary "ARG1[ARG2]")

(deftype field_ref unary (cstring fdecl)
  "ARG1.CSTRING
The field_declaration is saved in FDECL")

(defnode dereference unary "*ARG1")
(defnode extension_expr unary "__extension__ ARG1 (GCC)")
(defnode sizeof_expr unary "sizeof ARG1")
(defnode alignof_expr unary "__alignof ARG1 (GCC)")
(defnode realpart unary "__real ARG1 (GCC)")
(defnode imagpart unary "__imag ARG1 (GCC)")
(defnode address_of unary "&ARG1")
(defnode unary_minus unary "-ARG1")
(defnode unary_plus unary "+ARG1")
(defnode conjugate unary "~ARG1 on complex arguments")
(defnode bitnot unary "~ARG1")
(defnode not unary "!ARG1")

(deftype increment unary (temp1 temp2)
  "parent for increment nodes")
(defnode preincrement increment "++ARG1")
(defnode predecrement increment "--ARG1")
(defnode postincrement increment "ARG1++")
(defnode postdecrement increment "ARG1--")

(defnode plus binary "ARG1 + ARG2")
(defnode minus binary "ARG1 - ARG2")
(defnode times binary "ARG1 * ARG2")
(defnode divide binary "ARG1 / ARG2")
(defnode modulo binary "ARG1 % ARG2")
(defnode lshift binary "ARG1 << ARG2")
(defnode rshift binary "ARG1 >> ARG2")

(deftype comparison binary () "binary comparison ops")
(defnode leq comparison "ARG1 <= ARG2")
(defnode geq comparison "ARG1 >= ARG2")
(defnode lt comparison "ARG1 < ARG2")
(defnode gt comparison "ARG1 > ARG2")
(defnode eq comparison "ARG1 == ARG2")
(defnode ne comparison "ARG1 != ARG2")

(defnode bitand binary "ARG1 & ARG2")
(defnode bitor binary "ARG1 | ARG2")
(defnode bitxor binary "ARG1 ^ ARG2")
(defnode andand binary "ARG1 && ARG2")
(defnode oror binary "ARG1 || ARG2")

(deftype assignment binary (temp1) "ARG1 <assignop> ARG2")
(defnode assign assignment "ARG1 = ARG2")
(defnode plus_assign assignment "ARG1 += ARG2")
(defnode minus_assign assignment "ARG1 -= ARG2")
(defnode times_assign assignment "ARG1 *= ARG2")
(defnode divide_assign assignment "ARG1 /= ARG2")
(defnode modulo_assign assignment "ARG1 %= ARG2")
(defnode lshift_assign assignment "ARG1 <<= ARG2")
(defnode rshift_assign assignment "ARG1 >>= ARG2")
(defnode bitand_assign assignment "ARG1 &= ARG2")
(defnode bitor_assign assignment "ARG1 |= ARG2")
(defnode bitxor_assign assignment "ARG1 ^= ARG2")

;; Initialiser expressions (not allowed in most contexts)

(deftype init_list expression (args)
  "{ ARGS }. ARGS is a list of expressions
The type of the init_list is the type of the initialised entity.
If this entity is an incomplete array type, the type of the init_list
is the actual array size deduced from the initialiser.")

(deftype init_specific expression (designator init_expr)
  "DESIGNATOR = INIT_EXPR in an init_list.
DESIGNATOR is a list
The type is not set in init_specific nodes")

(deftype designator node ()
  "Base type for designators")

(deftype designate_field designator (cstring)
  ". CSTRING in an initialisation designator")

(deftype designate_index designator (arg1 arg2)
  "[ARG1] or [ARG1 ... ARG2] in a designator. ARG2 is optional.
ARG2 is a GCC extension")

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Constants
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(deftype lexical_cst expression (cstring)
  "A constant represented as in its unparsed lexical form CSTRING. These
appear in the AST.")

(deftype string_cst lexical_cst ()
  "A single lexical string - a sequence of these gets concatenated to
form a string. The source form of the constant can be found in
CSTRING.")

(deftype string expression (strings ddecl)
  "A list of STRINGS forming a single string constant.
DDECL is the magic_string declaration for this string.")
 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Labels
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(deftype id_label label (cstring ldecl)
  "The label CSTRING:")

(deftype case_label label (arg1 arg2)
  "CASE ARG1 ... ARG2: ARG2 is optional, it's presence is GCC-specific")

(deftype default_label label ()
  "DEFAULT:")

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Miscellaneous
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(deftype word node (cstring)
  "The identifier CSTRING used uninterpreted")

(deftype asm_operand node (word1 string arg1)
  "STRING(EXPR) or [WORD1] STRING(EXPR) (GCC)")

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; nesc extensions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; the different kinds of files
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(deftype nesc_decl declaration (word1 attributes cdecl)
  "a supertype for interface/component declarations of WORD1
CDECL is the declaration for this interface/component
ATTRIBUTES are its attributes")

(deftype interface nesc_decl (decls)
  "interface WORD1 { DECLS }")

(deftype component nesc_decl (abstract parms decls implementation)
  "ABSTRACT configuration/module WORD1 PARMS { DECLS } IMPLEMENTATION
If ABSTRACT is true, this is a generic component, and PARMS is its
parameters.")

(deftype implementation node (ienv cdecl)
  "a base type for module and configuration implementations
IENV is the implementation's environment
CDECL is the declaration for this component")

(deftype configuration implementation (decls)
  "configuration implementation { DECLS }
where DECLS include regular declarations, component_refs and connections")

(deftype module implementation (decls)
  "module implementation { DECLS }'")

(deftype binary_component implementation ()
  "binary component implementation placeholder")

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; component definition types
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(deftype rp_interface declaration (required decls)
  "a required or provided function or interface declaration (DECL is
either a data_decl or an interface_ref). REQUIRED is true for 'requires',
false for 'provides' clauses")

(deftype interface_ref declaration (word1 args word2 gparms attributes ddecl)
  "an interface which is required or provided by a component:
interface WORD1 < ARGS > WORD2 [ GPARMS ] ATTRIBUTES
ARGS is a list of type_arguments for template interfaces
WORD2 is optional, GPARMS, ARGS, ATTRIBUTES are optional")

(deftype component_ref declaration (word1 word2 abstract args cdecl)
  "a reference to component WORD1 'as' WORD2
WORD2 is optional
ABSTRACT is true for abstract component instantiations, false otherwise
ARGS is the argument list for abstract component instantiations
CDECL is filled in to point to the loaded component")

(deftype connection declaration (ep1 ep2)
  "A connection between interfaces EP1 and EP2")

(defnode rp_connection connection
  "EP1 (required) <- EP2 (provided)
Legal if EP1 and EP2 are both interfaces of the component, or if 
neither EP1 and EP2 are interfaces of the component")

(defnode eq_connection connection
  "EP1 = EP2, where both interfaces are either required or provided.
Legal if exactly one of EP1 and EP2 are interfaces of the component")

(deftype endpoint node (ids)
  "a list of parameterised_identifier in IDS")

(deftype parameterised_identifier node (word1 args)
  "WORD1[ARGS] if ARGS != null, just WORD1 otherwise")

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; types for extensions to the regular C syntax
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(deftype generic_declarator declarator (declarator parms)
  "parameterised declaration DECLARATOR [ PARMS ]")

(deftype generic_call expression (arg1 args)
  "ARG1[ARGS]. ARGS is a list of expressions, ARG1 is a generic function")

(deftype interface_ref_declarator nested_declarator (word1)
  "WORD1 . DECLARATOR in a declarator (for defining commands, events in component
implementations
For now at least, DECLARATOR is always an identifier_declarator")

(deftype interface_deref unary (cstring ddecl)
  "ARG1.CSTRING where ARG1 is an interface_ref.
DDECL is the command or event's declaration")

(deftype component_deref unary (cstring ddecl)
  "ARG1.CSTRING where ARG1 is a component_ref.
component_deref is *not* used for references to typedefed types in components.
DDECL is the specification element's declaration")

(deftype component_typeref typename (cstring)
  "CSTRING . typedef-name, a typedef-from-component-type 
with declaration DDECL. The typedef-name is in ddecl->name")

(deftype atomic_stmt statement (stmt)
  "ATOMIC stmt
An atomic_stmt is not made for lexically nested atomic statements")

(defnode nx_struct_ref struct_ref "A network struct")
(defnode nx_union_ref union_ref "A network union")

(deftype nesc_attribute attribute (arg1 tdecl)
  "@WORD1(ARG1), a nesC attribute. ARG1 is an init_list.
TDECL is the reference to the declaration of attribute WORD1")

(defnode target_attribute gcc_attribute 
  "a target-specific extension represented internally as a gcc-style attribute")

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; types for the polymorphic extensions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(deftype type_parm_decl declaration (cstring ddecl)
  "A declaration of type parameter CSTRING")

(deftype type_argument expression (asttype)
  "ASTTYPE used as a template argument")
