Class: LanguageParser::CPPLanguageScanner

Inherits:
CLanguageScanner show all
Defined in:
lib/cgialib/lp/CPPLanguageScanner.rb

Overview

Class : CPPLanguageScanner

The scanner specialized for processing C++ headers.

Instance Attribute Summary collapse

Attributes inherited from CLanguageScanner

#defines, #prototypeClass, #prototypes

Instance Method Summary collapse

Constructor Details

#initializeCPPLanguageScanner

initialize()

Constructs the scanner object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/cgialib/lp/CPPLanguageScanner.rb', line 21

def initialize()
  
  super()
  
  @classes = []
  
  @prototypeClass = Prototype
  @variableClass = ClassVariable
  @languageClass = LanguageClass
  
end

Instance Attribute Details

#classesObject (readonly)

The classes found



33
34
35
# File 'lib/cgialib/lp/CPPLanguageScanner.rb', line 33

def classes
  @classes
end

#languageClassObject

The class to use when building class objects



35
36
37
# File 'lib/cgialib/lp/CPPLanguageScanner.rb', line 35

def languageClass
  @languageClass
end

#variableClassObject

The class to use when building variable objects



37
38
39
# File 'lib/cgialib/lp/CPPLanguageScanner.rb', line 37

def variableClass
  @variableClass
end

Instance Method Details

#parse(tokens) ⇒ Object

parse( tokens )

tokens - Tokens returned from CTokenizer

Parses the tokens read from the CTokenizer



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/cgialib/lp/CPPLanguageScanner.rb', line 45

def parse( tokens )
  
  # Handle the function prototypes in the base class

  super( tokens )
  
  # Set up the code buffer

  codefrag = TokenStream.new()
  
  # Set up the state machine flags
  
  has_class = false
  found_open = false
  level = 0
  comments = ""
  
  # Look through the tokens for classes, and build up the full class bodies
  # in codefrag.  Then send the codefrags on to parse_class
  
  tokens.each_index { |index|
  
    tok = tokens[ index ]
  
    if ( has_class )
  
      comments = tokens.get_comments( index )
  
      codefrag.push( tok )
  
      if ( tok.to_s == "{" )
  
        level += 1
  
        found_open = true
  
      end
  
      level -= 1 if ( tok.to_s == "}" )
  
      if ( tok.to_s == ";" && level == 0 )
  
        parse_class( codefrag, comments ) if ( codefrag.length > 0 && found_open )
  
        codefrag = TokenStream.new()
  
        has_class = false
        found_open = false
  
      end
  
    end
  
    has_class = true if ( tok.to_s.downcase == "class" && level == 0 )
  
  }
  
  parse_class( codefrag, comments ) if ( codefrag.length > 0 && found_open )
  
end

#to_sObject

to_s()

A pretty printer for the object



110
111
112
113
114
115
116
117
118
# File 'lib/cgialib/lp/CPPLanguageScanner.rb', line 110

def to_s()
  
  text = ""
  
  classes.each { |cpp_class| text += cpp_class.to_s }
  
  text
  
end