# Convert a C++ class file into a C header file # # makes alot of assumptions about the layout of the C++ file # while() { # 'class' [: ['public'] ] '{' # if(/^\s*class\s+(\w+)\s*(:\s*(public)?\s*(\w*))?\s*{/) { $class = $1; $super = $4; # print "Class '$1' super='$4'\n"; push(@classes,$class); # Construct class macro name # # Build macro name # @class_words = split("_",$class); # See if first word of class name is some generic prefix # and drop it if so # if($class_words[0] eq "br" || $class_words[0] eq "brp") { shift(@class_words); } $macro_name = ""; foreach $w (@class_words) { $macro_name .= "\u$w"; } $class_macro_names{$class} = $macro_name; # Initialise methods list from superclass # @this_methods = split(" ",$class_methods{$super}); # Read class definition # while() { last if(/^\s*}/); # 'virtual' 'BR_METHOD' '(' [= 0] [';'] # if(/^\s*virtual\s+(.*)\s+BR_METHOD\s+(\w+)\s*\(([^;=]*)\s*(=\s*0)?\s*(;)?\s*$/) { $method = "$class\:\:$2"; $args = $3; push(@this_methods,$method); $method_return{$method} = $1; # Read any remaining argument lines until a terminating semicolon is found # if(!$5) { while() { if(/\s*([^;=]*)\s*(=\s*0)?\s*(;?)/) { $args .= $1; last if($3); } } } # Tidy up argument list: # squeeze out white space # remove trailing ')' # change '&' to '*' (references to pointers) # change 'class' to 'struct' # remove any leading and trailing space # $args =~ tr/\n\t \r/ /s; $args =~ s/\)\s*$//; $args =~ s/\&/\*/; $args =~ s/^\s*(.*)\s*/\1/; $method_args{$method} = $args if($args ne "void"); # print " method[$method] args[$method_args{$method}] ret[$method_return{$method}]\n"; } # Any line with CG_PUBLIC in it gets added to front of class # if(/CG_PUBLIC/) { s/CG_PUBLIC//g; $class_public{$class} .= $_; } } # Remember class list # $class_methods{$class} = join(" ",@this_methods); } } # Start building output file # print <