eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'SunRPC::XDRParser':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: XDRParser (in SunRPC)


Inheritance:

   Object
   |
   +--SunRPC::XDRParser

Package:
stx:goodies/communication
Category:
Net-Communication-SunRPC-XDR_IDL
Version:
rev: 1.15 date: 2021/01/20 13:18:44
user: cg
file: SunRPC_XDRParser.st directory: goodies/communication
module: stx stc-classLibrary: communication

Description:


parser for SunRPC XDR IDL declarations.

creates a list of XDRIDLTypes

copyright

COPYRIGHT (c) 2002 by eXept Software AG All Rights Reserved This software is furnished under a license and may be used only in accordance with the terms of that license and with the inclusion of the above copyright notice. This software may not be provided or otherwise made available to, or used by, any other person. No title to or ownership of the software is hereby transferred.

Class protocol:

initialization
o  initialize
need this to autoload XDRIDLType (since its private classes are not autoloaded...)

instance creation
o  for: aStringOrStream
create & return a new cparser reading from aStringOrStream

o  new
create & return a new cparser

parsing
o  parse: aStringOrStream
parse declarations and defines.
Return the parser (which can be asked for types and defines).

o  parse: aStringOrStream withDefines: defines
parse declarations and defines.
Return the parser (which can be asked for types and defines).

o  parse: aStringOrStream withDefines: defines types: types
parse declarations and defines.
Return the parser (which can be asked for types and defines).

o  parse: aStringOrStream withTypes: types
parse declarations and types.
Return the parser (which can be asked for types and defines).

o  parseDefinition: aStringOrStream
parse a single definition.
Return a single type.

o  parsePrograms: aStringOrStream
parse a single definition.
Return a single type.

parsing-expressions
o  integerExpression: aStringOrStream
parse an integer expression ..
Return the integer value or raise an error

Usage example(s):

     CParser integerExpression:'(0x8000 | 0x7FFF)'
     CParser integerExpression:'(0x8000 - 1)'

o  integerExpression: aStringOrStream withDefines: defines
parse an integer expression ..
Return the integer value or raise an error

Usage example(s):

     |defines|

     defines := Dictionary new.
     defines at:'VAL1' put:'0x100'.
     defines at:'VAL2' put:'0x200'.
     CParser integerExpression:'(VAL1 + VAL2 - 1)' withDefines:defines

Usage example(s):

     |defines|

     defines := Dictionary new.
     defines at:'VAL1' put:'0x100 // MAGIC 1'.
     defines at:'VAL2' put:'0x200 // MAGIC 2'.
     CParser integerExpression:'(VAL1 + VAL2 - 1)' withDefines:defines

Usage example(s):

     |parser defines|

     parser := CParser parse:'
#define FOO 0xFF00
#define BAR 1
'.
     defines := parser defines.
     CParser integerExpression:'FOO | BAR' withDefines:defines.

o  parseIntegerExpression: aStringOrStream
parse an integer expression ..
Return the integer value or raise an error

Usage example(s):

     CParser parseIntegerExpression:'(0x8000 | 0x7FFF)'
     CParser parseIntegerExpression:'(0x8000 - 1)'

o  parseIntegerExpression: aStringOrStream withDefines: defines
parse an integer expression ..
Return the integer value or raise an error


Instance protocol:

accessing
o  anonymousTypes
return the collection of anonymousTypes (after parsing).
These are embedded types in structs/unions or enums without type-def.
(maybe useful to get an anonymous enums value)

o  constants
return the collection of constants (after parsing)

o  constants: aDictionary
set the collection of constants (before parsing).
Use this to start parsing with some predefined values
(i.e. like compiling with -Dfoo=value)

o  defines
return the collection of defines (after parsing)

o  defines: aDictionary
set the collection of defines (before parsing).
Use this to start parsing with some predefined values
(i.e. like compiling with -Dfoo=value)

o  programs
return the collection of programs (after parsing)

o  types
return the collection of types (after parsing)

o  types: aDictionary
set the collection of types (before parsing) - useful to parse more

accessing behaviour
o  ignoreRedefinitions

o  ignoreRedefinitions: aState

error handling
o  parseError: msg
a parse error occurred

initialization
o  initKnownTypes
types

o  initialize
defines isNil ifTrue:[

o  initializeFor: aStringOrStream
initialize the new scanner & prepare for reading from aStringOrStream

o  readSource: aStringOrStream
prepare for reading from aStringOrStream,
but do not reinitialize

o  scannerClass

parsing
o  builtInType
builtInType :=
[unsigned] int
| [unsigned] hyper
| [unsigned] long
| float
| double
| bool

o  compoundType
compoundType :=
'struct' <optional_name> '{' field_list '}'
'union' <optional_name> '{' field_list '}'
'enum' <optional_name> '{' field_list '}'

o  constant

o  constantDef
constValue := IDLDatum new type:type data:constValue.

o  declaration

o  definition

o  definitions

o  enumBody
fieldList := enumItem
| enumList enumItem

o  parseValue

o  procedureDef

o  programDef

o  structBody

o  typeDef

o  typeSpecifier
baseType := compoundType | builtInType

o  unionBodyFor: aType

o  versionDef

parsing-expressions
o  addExpression
e1 { '+' | '-' } e2

o  bitAndExpression
e1 '&' e2

o  bitOrExpression
e1 '|' e2

o  expression

o  mulExpression
e1 { '*' | '/' | '%' } e2

o  primary
- primary
~ primary
! primary
| ( expression )
| integer
| string
| identifier

o  shiftExpression
e1 { '<<' | '>>' } e2

private
o  declareType: aType name: anIdentifier
private - declare a typedef

scanning
o  expect: expectedToken

o  expectIdentifier

o  expectIdentifier: aString

o  nextToken


Examples:


parsing a single declaration: (inspect and look at types, etc.)
  |parser|

  parser := XDRParser parse:'

       const PMAP_PORT = 111;      /* portmapper port number */

       const IPPROTO_TCP = 6;      /* protocol number for TCP/IP */
       const IPPROTO_UDP = 17;     /* protocol number for UDP/IP */

       struct mapping {
          unsigned int prog;
          unsigned int vers;
          unsigned int prot;
          unsigned int port;
       };

       struct *pmaplist {
          mapping map;
          pmaplist next;
       };

       struct call_result {
          unsigned int port;
          opaque res<>;
       };

       struct call_args {
          unsigned int prog;
          unsigned int vers;
          unsigned int proc;
          opaque args<>;
       };

       program PMAP_PROG {
          version PMAP_VERS {
             void
             PMAPPROC_NULL(void)         = 0;

             bool
             PMAPPROC_SET(mapping)       = 1;

             bool
             PMAPPROC_UNSET(mapping)     = 2;

             unsigned int
             PMAPPROC_GETPORT(mapping)   = 3;

             pmaplist
             PMAPPROC_DUMP(void)         = 4;

             call_result
             PMAPPROC_CALLIT(call_args)  = 5;
          } = 2;
       } = 100000;
  '


ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Mon, 18 Nov 2024 04:15:23 GMT