#!/usr/bin/env python # pythfilter.py v1.5.5, written by Matthias Baas (baas@ira.uka.de) # Doxygen filter which can be used to document Python source code. # Classes (incl. methods) and functions can be documented. # Every comment that begins with ## is literally turned into an # Doxygen comment. Consecutive comment lines are turned into # comment blocks (-> /** ... */). # All the stuff is put inside a namespace with the same name as # the source file. # Conversions: # ============ # ##-blocks -> /** ... */ # "class name(base): ..." -> "class name : public base {...}" # "def name(params): ..." -> "name(params) {...}" # Changelog: # 21.01.2003: Raw (r"") or unicode (u"") doc string will now be properly # handled. (thanks to Richard Laager for the patch) # 22.12.2003: Fixed a bug where no function names would be output for "def" # blocks that were not in a class. # (thanks to Richard Laager for the patch) # 12.12.2003: Implemented code to handle static and class methods with # this logic: Methods with "self" as the first argument are # non-static. Methods with "cls" are Python class methods, # which translate into static methods for Doxygen. Other # methods are assumed to be static methods. As should be # obvious, this logic doesn't take into account if the method # is actually setup as a classmethod() or a staticmethod(), # just if it follows the normal conventions. # (thanks to Richard Laager for the patch) # 11.12.2003: Corrected #includes to use os.path.sep instead of ".". Corrected # namespace code to use "::" instead of ".". # (thanks to Richard Laager for the patch) # 11.12.2003: Methods beginning with two underscores that end with # something other than two underscores are considered private # and are handled accordingly. # (thanks to Richard Laager for the patch) # 03.12.2003: The first parameter of class methods (self) is removed from # the documentation. # 03.11.2003: The module docstring will be used as namespace documentation # (thanks to Joe Bronkema for the patch) # 08.07.2003: Namespaces get a default documentation so that the namespace # and its contents will show up in the generated documentation. # 05.02.2003: Directories will be delted during synchronization. # 31.01.2003: -f option & filtering entire directory trees. # 10.08.2002: In base classes the '.' will be replaced by '::' # 18.07.2002: * and ** will be translated into arguments # 18.07.2002: Argument lists may contain default values using constructors. # 18.06.2002: Support for ## public: # 21.01.2002: from ... import will be translated to "using namespace ...;" # TODO: "from ... import *" vs "from ... import names" # TODO: Using normal imports: name.name -> name::name # 20.01.2002: #includes will be placed in front of the namespace ###################################################################### # The program is written as a state machine with the following states: # # - OUTSIDE The current position is outside any comment, # class definition or function. # # - BUILD_COMMENT Begins with first "##". # Ends with the first token that is no "##" # at the same column as before. # # - BUILD_CLASS_DECL Begins with "class". # Ends with ":" # - BUILD_CLASS_BODY Begins just after BUILD_CLASS_DECL. # The first following token (which is no comment) # determines indentation depth. # Ends with a token that has a smaller indendation. # # - BUILD_DEF_DECL Begins with "def". # Ends with ":". # - BUILD_DEF_BODY Begins just after BUILD_DEF_DECL. # The first following token (which is no comment) # determines indentation depth. # Ends with a token that has a smaller indendation. import getopt import glob import os.path import re import shutil import string import sys import token import tokenize from stat import * OUTSIDE = 0 BUILD_COMMENT = 1 BUILD_CLASS_DECL = 2 BUILD_CLASS_BODY = 3 BUILD_DEF_DECL = 4 BUILD_DEF_BODY = 5 IMPORT = 6 IMPORT_OP = 7 IMPORT_APPEND = 8 # Output file stream outfile = sys.stdout # Output buffer outbuffer = [] out_row = 1 out_col = 0 # Variables used by rec_name_n_param() name = "" param = "" doc_string = "" record_state = 0 bracket_counter = 0 # Tuple: (row,column) class_spos = (0,0) def_spos = (0,0) import_spos = (0,0) # Which import was used? ("import" or "from") import_token = "" # Comment block buffer comment_block = [] comment_finished = 0 # Imported modules modules = [] # Program state stateStack = [OUTSIDE] # Keep track of whether module has a docstring module_has_docstring = False # Keep track of member protection protection_level = "public" private_member = False # Keep track of the module namespace namespace = "" ###################################################################### # Output string s. '\n' may only be at the end of the string (not # somewhere in the middle). # # In: s - String # spos - Startpos ###################################################################### def output(s,spos, immediate=0): global outbuffer, out_row, out_col, outfile os = string.rjust(s,spos[1]-out_col+len(s)) if immediate: outfile.write(os) else: outbuffer.append(os) assert -1 == string.find(s[0:-2], "\n"), s if (s[-1:]=="\n"): out_row = out_row+1 out_col = 0 else: out_col = spos[1]+len(s) ###################################################################### # Records a name and parameters. The name is either a class name or # a function name. Then the parameter is either the base class or # the function parameters. # The name is stored in the global variable "name", the parameters # in "param". # The variable "record_state" holds the current state of this internal # state machine. # The recording is started by calling start_recording(). # # In: type, tok ###################################################################### def rec_name_n_param(type, tok): global record_state,name,param,doc_string,bracket_counter s = record_state # State 0: Do nothing. if (s==0): return # State 1: Remember name. elif (s==1): name = tok record_state = 2 # State 2: Wait for opening bracket or colon elif (s==2): if (tok=='('): bracket_counter = 1 record_state=3 if (tok==':'): record_state=4 # State 3: Store parameter (or base class) and wait for an ending bracket elif (s==3): if (tok=='*' or tok=='**'): tok='' if (tok=='('): bracket_counter = bracket_counter+1 if (tok==')'): bracket_counter = bracket_counter-1 if bracket_counter==0: record_state=4 else: param=param+tok # State 4: Look for doc string elif (s==4): if (type==token.NEWLINE or type==token.INDENT or type==token.SLASHEQUAL): return elif (tok==":"): return elif (type==token.STRING): while tok[:1]=='r' or tok[:1]=='u': tok=tok[1:] while tok[:1]=='"': tok=tok[1:] while tok[-1:]=='"': tok=tok[:-1] doc_string=tok record_state=0 ###################################################################### # Starts the recording of a name & param part. # The function rec_name_n_param() has to be fed with tokens. After # the necessary tokens are fed the name and parameters can be found # in the global variables "name" und "param". ###################################################################### def start_recording(): global record_state,param,name, doc_string record_state=1 name="" param="" doc_string="" ###################################################################### # Test if recording is finished ###################################################################### def is_recording_finished(): global record_state return record_state==0 ###################################################################### ## Gather comment block ###################################################################### def gather_comment(type,tok,spos): global comment_block,comment_finished if (type!=tokenize.COMMENT): comment_finished = 1 else: # Output old comment block if a new one is started. if (comment_finished): print_comment(spos) comment_finished=0 if (tok[0:2]=="##" and tok[0:3]!="###"): append_comment_lines(tok[2:]) ###################################################################### ## Output comment block and empty buffer. ###################################################################### def print_comment(spos): global comment_block,comment_finished if (comment_block!=[]): output("/** ",spos) for c in comment_block: output(c,spos) output("*/\n",spos) comment_block = [] comment_finished = 0 ###################################################################### def set_state(s): global stateStack stateStack[len(stateStack)-1]=s ###################################################################### def get_state(): global stateStack return stateStack[len(stateStack)-1] ###################################################################### def push_state(s): global stateStack stateStack.append(s) ###################################################################### def pop_state(): global stateStack stateStack.pop() ###################################################################### def tok_eater(type, tok, spos, epos, line): global stateStack,name,param,class_spos,def_spos,import_spos global do
##############################################################################
# Build global options
# NOTE: Can be overridden externally.
#
# Compiler options here.
ifeq ($(USE_OPT),)
USE_OPT = -O2 -ggdb -fomit-frame-pointer -falign-functions=16
endif
# C specific options here (added to USE_OPT).
ifeq ($(USE_COPT),)
USE_COPT =
endif
# C++ specific options here (added to USE_OPT).
ifeq ($(USE_CPPOPT),)
USE_CPPOPT = -fno-rtti
endif
# Enable this if you want the linker to remove unused code and data
ifeq ($(USE_LINK_GC),)
USE_LINK_GC = yes
endif
# Linker extra options here.
ifeq ($(USE_LDOPT),)
USE_LDOPT =
endif
# Enable this if you want link time optimizations (LTO)
ifeq ($(USE_LTO),)
USE_LTO = yes
endif
# If enabled, this option allows to compile the application in THUMB mode.
ifeq ($(USE_THUMB),)
USE_THUMB = yes
endif
# Enable this if you want to see the full log while compiling.
ifeq ($(USE_VERBOSE_COMPILE),)
USE_VERBOSE_COMPILE = no
endif
# If enabled, this option makes the build process faster by not compiling
# modules not used in the current configuration.
ifeq ($(USE_SMART_BUILD),)
USE_SMART_BUILD = yes
endif
#
# Build global options
##############################################################################
##############################################################################
# Architecture or project specific options
#
# Stack size to be allocated to the Cortex-M process stack. This stack is
# the stack used by the main() thread.
ifeq ($(USE_PROCESS_STACKSIZE),)
USE_PROCESS_STACKSIZE = 0x400
endif
# Stack size to the allocated to the Cortex-M main/exceptions stack. This
# stack is used for processing interrupts and exceptions.
ifeq ($(USE_EXCEPTIONS_STACKSIZE),)
USE_EXCEPTIONS_STACKSIZE = 0x400
endif
# Enables the use of FPU (no, softfp, hard).
ifeq ($(USE_FPU),)
USE_FPU = no
endif
#
# Architecture or project specific options
##############################################################################
##############################################################################
# Project, sources and paths
#
# Define project name here
PROJECT = ch
# Imported source files and paths
CHIBIOS = ../../../..
# Startup files.
include $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/mk/startup_stm32f1xx.mk
# HAL-OSAL files (optional).
include $(CHIBIOS)/os/hal/hal.mk
include $(CHIBIOS)/os/hal/ports/STM32/STM32F1xx/platform.mk
include $(CHIBIOS)/os/hal/boards/OLIMEX_STM32_P103/board.mk
include $(CHIBIOS)/os/hal/osal/rt/osal.mk
# RTOS files (optional).
include $(CHIBIOS)/os/rt/rt.mk
include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v7m.mk
# Other files (optional).
#include $(CHIBIOS)/test/rt/test.mk
# Define linker script file here
LDSCRIPT= $(STARTUPLD)/STM32F103xB.ld
# C sources that can be compiled in ARM or THUMB mode depending on the global
# setting.
CSRC = $(STARTUPSRC) \
$(KERNSRC) \
$(PORTSRC) \
$(OSALSRC) \
$(HALSRC) \
$(PLATFORMSRC) \
$(BOARDSRC) \
$(TESTSRC) \
$(CHIBIOS)/os/various/syscalls.c \
main.c
# C++ sources that can be compiled in ARM or THUMB mode depending on the global
# setting.
CPPSRC =
# C sources to be compiled in ARM mode regardless of the global setting.
# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
# option that results in lower performance and larger code size.
ACSRC =
# C++ sources to be compiled in ARM mode regardless of the global setting.
# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
# option that results in lower performance and larger code size.
ACPPSRC =
# C sources to be compiled in THUMB mode regardless of the global setting.
# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
# option that results in lower performance and larger code size.
TCSRC =
# C sources to be compiled in THUMB mode regardless of the global setting.
# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
# option that results in lower performance and larger code size.
TCPPSRC =
# List ASM source files here
ASMSRC =
ASMXSRC = $(STARTUPASM) $(PORTASM) $(OSALASM)
INCDIR = $(CHIBIOS)/os/license \
$(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \
$(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \
$(CHIBIOS)/os/various
#
# Project, sources and paths
##############################################################################
##############################################################################
# Compiler settings
#
MCU = cortex-m3
#TRGT = arm-elf-
TRGT = arm-none-eabi-
CC = $(TRGT)gcc
CPPC = $(TRGT)g++
# Enable loading with g++ only if you need C++ runtime support.
# NOTE: You can use C++ even without C++ support if you are careful. C++
# runtime support makes code size explode.
LD = $(TRGT)gcc
#LD = $(TRGT)g++
CP = $(TRGT)objcopy
AS = $(TRGT)gcc -x assembler-with-cpp
AR = $(TRGT)ar
OD = $(TRGT)objdump
SZ = $(TRGT)size
HEX = $(CP) -O ihex
BIN = $(CP) -O binary
# ARM-specific options here
AOPT =
# THUMB-specific options here
TOPT = -mthumb -DTHUMB
# Define C warning options here
CWARN = -Wall -Wextra -Wundef -Wstrict-prototypes
# Define C++ warning options here
CPPWARN = -Wall -Wextra -Wundef
#
# Compiler settings
##############################################################################
##############################################################################
# Start of user section
#
# List all user C define here, like -D_DEBUG=1
UDEFS =
# Define ASM defines here
UADEFS =
# List all user directories here
UINCDIR =
# List the user directory to look for the libraries here
ULIBDIR =
# List all user libraries here
ULIBS =
#
# End of user defines
##############################################################################
RULESPATH = $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC
include $(RULESPATH)/rules.mk