mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
Add Java nivision wrappers.
Only very basic testing performed to date. The wrappers are still a bit incomplete (some structures and functions), but are much more complete than the old ones. Fixes artf3796. Changes from initial changeset: - Use // for comments. - Add auto-generate notices to the beginning of each generated file. - Include error number with error text in exception. - Add free() function to structures. - Fix out-of-order / non-array enums. - Avoid duplicate calls to DisposedStruct.write() as .getAddress() does it. - Refactor OpaqueStruct. - Default to no null allowed except when overridden. - Implement unowned return values. - Add gen_struct_sizer script. Change-Id: Ie0d102c45817ea8812d98fe4938d1a2255c61664
This commit is contained in:
6
.gitignore
vendored
6
.gitignore
vendored
@@ -10,6 +10,8 @@ bin/
|
||||
.project
|
||||
.classpath
|
||||
**/dependency-reduced-pom.xml
|
||||
wpilibj/wpilibJavaJNI/nivision/*.c
|
||||
wpilibj/wpilibJavaJNI/nivision/*.java
|
||||
|
||||
# Created by the jenkins test script
|
||||
test-reports
|
||||
@@ -155,6 +157,10 @@ local.properties
|
||||
.settings/
|
||||
.loadpath
|
||||
|
||||
### Python ###
|
||||
*.pyc
|
||||
__pycache__
|
||||
|
||||
# External tool builders
|
||||
.externalToolBuilders/
|
||||
|
||||
|
||||
24555
wpilibj/wpilibJavaDevices/src/main/java/com/ni/vision/NIVision.java
Normal file
24555
wpilibj/wpilibJavaDevices/src/main/java/com/ni/vision/NIVision.java
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// This file is auto-generated by wpilibj/wpilibJavaJNI/nivision/gen_java.py
|
||||
// Please do not edit!
|
||||
//
|
||||
|
||||
package com.ni.vision;
|
||||
|
||||
public class VisionException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public VisionException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "VisionException [" + super.toString() + "]";
|
||||
}
|
||||
}
|
||||
4717
wpilibj/wpilibJavaJNI/lib/NIVisionJNI.cpp
Normal file
4717
wpilibj/wpilibJavaJNI/lib/NIVisionJNI.cpp
Normal file
File diff suppressed because it is too large
Load Diff
1670
wpilibj/wpilibJavaJNI/nivision/gen_java.py
Normal file
1670
wpilibj/wpilibJavaJNI/nivision/gen_java.py
Normal file
File diff suppressed because it is too large
Load Diff
113
wpilibj/wpilibJavaJNI/nivision/gen_struct_sizer.py
Normal file
113
wpilibj/wpilibJavaJNI/nivision/gen_struct_sizer.py
Normal file
@@ -0,0 +1,113 @@
|
||||
from __future__ import print_function
|
||||
import sys
|
||||
import os
|
||||
import re
|
||||
try:
|
||||
import configparser
|
||||
except ImportError:
|
||||
import ConfigParser as configparser
|
||||
|
||||
from nivision_parse import *
|
||||
|
||||
class StructSizerEmitter:
|
||||
def __init__(self, out, config):
|
||||
self.out = out
|
||||
self.config = config
|
||||
print("""#include <stdio.h>
|
||||
#include <nivision.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
printf("[_platform_]\\npointer=%d\\n", (int)sizeof(void*));
|
||||
""", file=self.out)
|
||||
|
||||
def finish(self):
|
||||
print("}", file=self.out)
|
||||
|
||||
def config_get(self, section, option, fallback):
|
||||
try:
|
||||
return self.config.get(section, option)
|
||||
except (ValueError, configparser.NoSectionError, configparser.NoOptionError):
|
||||
return fallback
|
||||
|
||||
def config_getboolean(self, section, option, fallback):
|
||||
try:
|
||||
return self.config.getboolean(section, option)
|
||||
except (ValueError, configparser.NoSectionError, configparser.NoOptionError):
|
||||
return fallback
|
||||
|
||||
def block_comment(self, comment):
|
||||
pass
|
||||
|
||||
def opaque_struct(self, name):
|
||||
pass
|
||||
|
||||
def define(self, name, value, comment):
|
||||
pass
|
||||
|
||||
def text(self, text):
|
||||
print(text, file=self.out)
|
||||
|
||||
def static_const(self, name, ctype, value):
|
||||
pass
|
||||
|
||||
def enum(self, name, values):
|
||||
pass
|
||||
|
||||
def typedef(self, name, typedef, arr):
|
||||
pass
|
||||
|
||||
def typedef_function(self, name, restype, params):
|
||||
pass
|
||||
|
||||
def function(self, name, restype, params):
|
||||
pass
|
||||
|
||||
def structunion(self, ctype, name, fields):
|
||||
if name in opaque_structs:
|
||||
return
|
||||
|
||||
print('printf("[{name}]\\n_SIZE_=%d\\n", (int)sizeof({name}));'.format(name=name), file=self.out)
|
||||
|
||||
for fname, ftype, arr, comment in fields:
|
||||
if ':' in fname:
|
||||
continue # can't handle bitfields
|
||||
print('printf("{field}=%d\\n", (int)offsetof({name}, {field}));'.format(name=name, field=fname), file=self.out)
|
||||
|
||||
def struct(self, name, fields):
|
||||
self.structunion("Structure", name, fields)
|
||||
|
||||
def union(self, name, fields):
|
||||
self.structunion("Union", name, fields)
|
||||
|
||||
def generate(srcdir, configpath=None, nivisionhpath=None):
|
||||
# read config file
|
||||
config = configparser.ConfigParser()
|
||||
config.read(configpath)
|
||||
block_comment_exclude = set(x.strip() for x in
|
||||
config.get("Block Comment", "exclude").splitlines())
|
||||
|
||||
# open input file
|
||||
inf = open(nivisionhpath)
|
||||
|
||||
# prescan for undefined structures
|
||||
prescan_file(inf)
|
||||
inf.seek(0)
|
||||
|
||||
# generate
|
||||
with open("struct_sizer.c", "wt") as out:
|
||||
emit = StructSizerEmitter(out, config)
|
||||
parse_file(emit, inf, block_comment_exclude)
|
||||
emit.finish()
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) < 2:
|
||||
print("Usage: gen_struct_sizer.py <nivision.h> [config.ini]")
|
||||
exit(0)
|
||||
|
||||
fname = sys.argv[1]
|
||||
configname = "nivision_2011.ini"
|
||||
if len(sys.argv) >= 3:
|
||||
configname = sys.argv[2]
|
||||
|
||||
generate("", configname, fname)
|
||||
12
wpilibj/wpilibJavaJNI/nivision/generateJNI.sh
Executable file
12
wpilibj/wpilibJavaJNI/nivision/generateJNI.sh
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
#This script should be able to generate the JNI
|
||||
# bindings for NIVision. At some point,
|
||||
# it should be integrated into the build system.
|
||||
# Assumes running from allwpilib/wpilibj/wpilibJavaJNI/nivision
|
||||
# Get files that we node to generate from.
|
||||
# Run python generator.
|
||||
python gen_java.py ../../../wpilibc/wpilibC++Devices/include/nivision.h nivision_arm.ini nivision_2011.ini
|
||||
# Stick generated files into appropriate places.
|
||||
cp NIVision.cpp ../lib/NIVisionJNI.cpp
|
||||
mkdir -p ../../wpilibJavaDevices/src/main/java/com/ni/vision
|
||||
cp *.java ../../wpilibJavaDevices/src/main/java/com/ni/vision/
|
||||
821
wpilibj/wpilibJavaJNI/nivision/nivision_2011.ini
Normal file
821
wpilibj/wpilibJavaJNI/nivision/nivision_2011.ini
Normal file
@@ -0,0 +1,821 @@
|
||||
;
|
||||
; [name]
|
||||
; arraysize -- comma separated list of "param:numParam" where param is the
|
||||
; name of the pointer parameter, and numParam is the name of
|
||||
; the parameter that contains the array size for the pointer
|
||||
; retarraysize -- name of the pass-by-reference parameter that on function
|
||||
; return contains the array size of the returned pointer
|
||||
; exclude -- if True, no code is output for this name (full custom)
|
||||
; underscore -- if True, only underscored raw wrapper is output (partial custom)
|
||||
; outparams -- comma separated list of output parameter names
|
||||
; inparams -- comma separated list of parameter names that are input
|
||||
; parameters (e.g. not output parameters)
|
||||
; defaults -- comma separated list of "param:default" where param is the
|
||||
; parameter name and default is the default value
|
||||
; exclude_members -- for structures, members to not emit
|
||||
; nullok -- comma separated list of parameter names that may be null
|
||||
; retref -- parameter that (if non-null) is returned as a reference
|
||||
; retunowned -- if True, return value should not be owned
|
||||
;
|
||||
; The generator code auto-detects many parameters, so this file is only needed
|
||||
; for overriding the auto-detected behavior.
|
||||
|
||||
; defines
|
||||
[IMAQ_IMPORT]
|
||||
exclude=True
|
||||
[IMAQ_FUNC]
|
||||
exclude=True
|
||||
[IMAQ_STDCALL]
|
||||
exclude=True
|
||||
[IMAQ_CALLBACK]
|
||||
exclude=True
|
||||
[IMAQ_DEFAULT_LEARNING_MODE]
|
||||
exclude=True
|
||||
[ERR_INVALID_COLORCOMPLEXITY]
|
||||
exclude=True
|
||||
|
||||
; structures
|
||||
[PolyModel]
|
||||
arraysize=kCoeffs:numKCoeffs
|
||||
[CalibrationReferencePoints]
|
||||
arraysize=pixelCoords:numPixelCoords,realCoords:numRealCoords
|
||||
[GetCameraParametersReport]
|
||||
#TODO: projectionMatrix:projectionMatrixRows*projectionMatrixCols
|
||||
exclude_members=projectionMatrix
|
||||
[GetCalibrationInfoReport]
|
||||
#TODO: errorMap:errorMapRows*errorMapCols
|
||||
exclude_members=errorMap
|
||||
[ContourFitSplineReport]
|
||||
arraysize=points:numberOfPoints
|
||||
[ContourFitPolynomialReport]
|
||||
arraysize=bestFit:numberOfPoints,polynomialCoefficients:numberOfCoefficients
|
||||
[SetupMatchPatternData]
|
||||
arraysize=matchSetupData:numMatchSetupData
|
||||
[ContourInfoReport]
|
||||
arraysize=pointsPixel:numPointsPixel,pointsReal:numPointsReal,curvaturePixel:numCurvaturePixel,curvatureReal:numCurvatureReal
|
||||
[SupervisedColorSegmentationReport]
|
||||
arraysize=labelOut:numLabelOut
|
||||
[LabelToROIReport]
|
||||
arraysize=roiArray:numOfROIs,labelsOutArray:numOfLabels,isTooManyVectorsArray:isTooManyVectorsArraySize
|
||||
[ClassifiedCurve]
|
||||
arraysize=curvePoints:numCurvePoints
|
||||
[CurvatureAnalysisReport]
|
||||
arraysize=curves:numCurves
|
||||
[ComputeDistancesReport]
|
||||
arraysize=distances:numDistances,distancesReal:numDistancesReal
|
||||
[ClassifiedDisparity]
|
||||
arraysize=templateSubsection:numTemplateSubsection,targetSubsection:numTargetSubsection
|
||||
[ClassifyDistancesReport]
|
||||
arraysize=classifiedDistances:numClassifiedDistances
|
||||
[ContourComputeCurvatureReport]
|
||||
arraysize=curvaturePixel:numCurvaturePixel,curvatureReal:numCurvatureReal
|
||||
[ExtractContourReport]
|
||||
arraysize=contourPoints:numContourPoints,sourcePoints:numSourcePoints
|
||||
[ExtractTextureFeaturesReport]
|
||||
arraysize=waveletBands:numWaveletBands
|
||||
#TODO: textureFeatures:textureFeaturesRows:textureFeaturesCols
|
||||
exclude_members=textureFeatures
|
||||
[WaveletBandsReport]
|
||||
#TODO: LLBand:rows:cols
|
||||
#TODO: LHBand:rows:cols
|
||||
#TODO: HLBand:rows:cols
|
||||
#TODO: HHBand:rows:cols
|
||||
#TODO: LLLBand:rows:cols
|
||||
#TODO: LLHBand:rows:cols
|
||||
#TODO: LHHBand:rows:cols
|
||||
exclude_members=LLBand,LHBand,HLBand,HHBand,LLLBand,LLHBand,LHHBand
|
||||
[MeasureParticlesReport]
|
||||
#TODO: pixelMeasurements:numParticles:numMeasurements
|
||||
#TODO: calibratedMeasurements:numParticles:numMeasurements
|
||||
exclude_members=pixelMeasurements,calibratedMeasurements
|
||||
[ClassifierReportAdvanced]
|
||||
arraysize=allScores:allScoresSize,sampleScores:sampleScoresSize
|
||||
[FindEdgeReport]
|
||||
arraysize=straightEdges:numStraightEdges
|
||||
[ReadTextReport3]
|
||||
arraysize=characterReport:numCharacterReports
|
||||
[EdgeReport2]
|
||||
arraysize=edges:numEdges,gradientInfo:numGradientInfo
|
||||
[ConcentricRakeReport2]
|
||||
arraysize=firstEdges:numFirstEdges,lastEdges:numLastEdges,searchArcs:numSearchArcs
|
||||
[SpokeReport2]
|
||||
arraysize=firstEdges:numFirstEdges,lastEdges:numLastEdges,searchLines:numSearchLines
|
||||
[RakeReport2]
|
||||
arraysize=firstEdges:numFirstEdges,lastEdges:numLastEdges,searchLines:numSearchLines
|
||||
[QRCodeDataToken]
|
||||
arraysize=data:dataLength
|
||||
[StraightEdgeReport2]
|
||||
arraysize=straightEdges:numStraightEdges,searchLines:numSearchLines
|
||||
[StraightEdge]
|
||||
arraysize=usedEdges:numUsedEdges
|
||||
[QRCodeReport]
|
||||
arraysize=data:dataLength,tokenizedData:sizeOfTokenizedData
|
||||
[DataMatrixReport]
|
||||
arraysize=data:dataLength
|
||||
[ReadTextReport2]
|
||||
arraysize=characterReport:numCharacterReports
|
||||
[FeatureData]
|
||||
arraysize=contourPoints:numContourPoints
|
||||
uniontype=feature:type:IMAQ_CIRCLE_FEATURE=circle:IMAQ_ELLIPSE_FEATURE=ellipse:IMAQ_CONST_CURVE_FEATURE=constCurve:IMAQ_RECTANGLE_FEATURE=rectangle:IMAQ_LEG_FEATURE=leg:IMAQ_CORNER_FEATURE=corner:IMAQ_PARALLEL_LINE_PAIR_FEATURE=parallelLinePair:IMAQ_PAIR_OF_PARALLEL_LINE_PAIRS_FEATURE=pairOfParallelLinePairs:IMAQ_LINE_FEATURE=line:IMAQ_CLOSED_CURVE_FEATURE=closedCurve
|
||||
[GeometricPatternMatch2]
|
||||
arraysize=featureData:numFeatureData
|
||||
[ShapeDetectionOptions]
|
||||
arraysize=angleRanges:numAngleRanges
|
||||
[Curve]
|
||||
arraysize=points:numPoints
|
||||
[Barcode2DInfo]
|
||||
arraysize=data:dataLength
|
||||
[ClassifierAccuracyReport]
|
||||
arraysize=classNames:size,classAccuracy:size,classPredictiveValue:size
|
||||
#TODO: classificationDistribution:classPredictiveValue:size
|
||||
exclude_members=classificationDistribution
|
||||
[NearestNeighborTrainingReport]
|
||||
arraysize=allScores:allScoresSize
|
||||
#TODO: classDistancesTable
|
||||
exclude_members=classDistancesTable
|
||||
[ClassifierSampleInfo]
|
||||
arraysize=featureVector:featureVectorSize
|
||||
[ClassifierReport]
|
||||
arraysize=allScores:allScoresSize
|
||||
[MatchGeometricPatternOptions]
|
||||
arraysize=angleRanges:numAngleRanges
|
||||
[ConstructROIOptions2]
|
||||
arraysize=palette:numColors
|
||||
[BestEllipse2]
|
||||
arraysize=pointsUsed:numPointsUsed
|
||||
[BestCircle2]
|
||||
arraysize=pointsUsed:numPointsUsed
|
||||
[ReadTextOptions]
|
||||
arraysize=validChars:numValidChars
|
||||
[ReadTextReport]
|
||||
arraysize=characterReport:numCharacterReports
|
||||
[EdgeLocationReport]
|
||||
arraysize=edges:numEdges
|
||||
[ImageInfo]
|
||||
#TODO: imageStart
|
||||
exclude_members=reserved0,reserved1,imageStart
|
||||
[LCDReport]
|
||||
arraysize=segmentInfo:numCharacters
|
||||
exclude_members=reserved
|
||||
[LCDSegments]
|
||||
exclude_members=reserved
|
||||
[LearnColorPatternOptions]
|
||||
arraysize=colorsToIgnore:numColorsToIgnore
|
||||
[LinearAverages]
|
||||
arraysize=columnAverages:columnCount,rowAverages:rowCount,risingDiagAverages:risingDiagCount,fallingDiagAverages:fallingDiagCount
|
||||
[LineProfile]
|
||||
arraysize=profileData:dataCount
|
||||
[MatchColorPatternOptions]
|
||||
arraysize=angleRanges:numRanges
|
||||
[HistogramReport]
|
||||
arraysize=histogram:histogramCount
|
||||
[BestLine]
|
||||
arraysize=pointsUsed:numPointsUsed
|
||||
[CalibrationInfo]
|
||||
#TODO: errorMap:mapColumns*mapRows
|
||||
exclude_members=errorMap
|
||||
[CalibrationPoints]
|
||||
arraysize=pixelCoordinates:numCoordinates,realWorldCoordinates:numCoordinates
|
||||
[CaliperReport]
|
||||
exclude_members=reserved
|
||||
[ClosedContour]
|
||||
arraysize=points:numPoints
|
||||
[ColorInformation]
|
||||
arraysize=info:infoCount
|
||||
[ConcentricRakeReport]
|
||||
arraysize=rakeArcs:numArcs,firstEdges:numFirstEdges,lastEdges:numLastEdges,allEdges:numLinesWithEdges,linesWithEdges:numLinesWithEdges
|
||||
[ConstructROIOptions]
|
||||
arraysize=palette:numColors
|
||||
[ContourInfo]
|
||||
arraysize=points:numPoints
|
||||
[ContourInfo2]
|
||||
uniontype=structure:type:IMAQ_POINT=point:IMAQ_LINE=line:IMAQ_RECT=rect:IMAQ_OVAL=ovalBoundingBox:IMAQ_CLOSED_CONTOUR=closedContour:IMAQ_OPEN_CONTOUR=openContour:IMAQ_ANNULUS=annulus:IMAQ_ROTATED_RECT=rotatedRect
|
||||
[UserPointSymbol]
|
||||
#TODO: pixels:cols*rows
|
||||
exclude_members=pixels
|
||||
[MatchPatternOptions]
|
||||
arraysize=angleRanges:numRanges
|
||||
[OpenContour]
|
||||
arraysize=points:numPoints
|
||||
[QuantifyReport]
|
||||
arraysize=regions:regionCount
|
||||
[RakeReport]
|
||||
arraysize=rakeLines:numRakeLines,firstEdges:numFirstEdges,lastEdges:numLastEdges,allEdges:numLinesWithEdges,linesWithEdges:numLinesWithEdges
|
||||
[TransformReport]
|
||||
arraysize=points:numPoints,validPoints:numPoints
|
||||
[MeterArc]
|
||||
arraysize=arcCoordPoints:numOfArcCoordPoints
|
||||
[StructuringElement]
|
||||
#TODO: arraysize=kernel:matrixRows*matrixCols
|
||||
exclude_members=kernel
|
||||
[SpokeReport]
|
||||
arraysize=spokeLines:numSpokeLines,firstEdges:numFirstEdges,lastEdges:numLastEdges,allEdges:numLinesWithEdges,linesWithEdges:numLinesWithEdges
|
||||
[ToolWindowOptions]
|
||||
exclude_members=reserved2,reserved3,reserved4
|
||||
[EventCallback]
|
||||
exclude=True
|
||||
|
||||
; Logical functions
|
||||
; TODO: constant versions
|
||||
[imaqAndConstant]
|
||||
exclude=True
|
||||
[imaqCompareConstant]
|
||||
exclude=True
|
||||
[imaqLogicalDifferenceConstant]
|
||||
exclude=True
|
||||
[imaqNandConstant]
|
||||
exclude=True
|
||||
[imaqNorConstant]
|
||||
exclude=True
|
||||
[imaqOrConstant]
|
||||
exclude=True
|
||||
[imaqXnorConstant]
|
||||
exclude=True
|
||||
[imaqXorConstant]
|
||||
exclude=True
|
||||
|
||||
; Arithmetic functions
|
||||
; TODO: constant versions
|
||||
[imaqAbsoluteDifferenceConstant]
|
||||
exclude=True
|
||||
[imaqAddConstant]
|
||||
exclude=True
|
||||
[imaqAverageConstant]
|
||||
exclude=True
|
||||
[imaqDivideConstant2]
|
||||
exclude=True
|
||||
[imaqMaxConstant2]
|
||||
exclude=True
|
||||
[imaqMinConstant]
|
||||
exclude=True
|
||||
[imaqModuloConstant]
|
||||
exclude=True
|
||||
[imaqMultiplyConstant]
|
||||
exclude=True
|
||||
[imaqSubtractConstant]
|
||||
exclude=True
|
||||
|
||||
; Particle Analysis functions
|
||||
[imaqCountParticles]
|
||||
outparams=numParticles
|
||||
[imaqMeasureParticle]
|
||||
outparams=value
|
||||
[imaqMeasureParticles]
|
||||
arraysize=measurements:numMeasurements
|
||||
[imaqParticleFilter4]
|
||||
arraysize=criteria:criteriaCount
|
||||
outparams=numParticles
|
||||
|
||||
; Morphology functions
|
||||
[imaqFindCircles]
|
||||
retarraysize=numCircles
|
||||
[imaqLabel2]
|
||||
outparams=particleCount
|
||||
[imaqMorphology]
|
||||
nullok=structuringElement
|
||||
[imaqSeparation]
|
||||
nullok=structuringElement
|
||||
[imaqSimpleDistance]
|
||||
nullok=structuringElement
|
||||
[imaqSizeFilter]
|
||||
nullok=structuringElement
|
||||
|
||||
; Acquisition functions
|
||||
[imaqCopyFromRing]
|
||||
nullok=image,imageNumber
|
||||
outparams=imageNumber
|
||||
retref=image
|
||||
[imaqExtractFromRing]
|
||||
nullok=imageNumber
|
||||
outparams=imageNumber
|
||||
retunowned=True
|
||||
[imaqGrab]
|
||||
nullok=image
|
||||
retref=image
|
||||
[imaqSetupRing]
|
||||
arraysize=images:numImages
|
||||
inparams=images
|
||||
[imaqSetupSequence]
|
||||
arraysize=images:numImages
|
||||
inparams=images
|
||||
[imaqSnap]
|
||||
nullok=image
|
||||
retref=image
|
||||
|
||||
; Caliper functions
|
||||
[imaqCaliperTool]
|
||||
retarraysize=numEdgePairs
|
||||
arraysize=points:numPoints
|
||||
[imaqDetectExtremes]
|
||||
retarraysize=numExtremes
|
||||
arraysize=pixels:numPixels
|
||||
[imaqFindTransformRect2]
|
||||
outparams=baseSystem,newSystem,axisReport
|
||||
[imaqFindTransformRects2]
|
||||
outparams=baseSystem,newSystem,axisReport
|
||||
[imaqSimpleEdge]
|
||||
retarraysize=numEdges
|
||||
arraysize=points:numPoints
|
||||
|
||||
; Spatial Filters functions
|
||||
[imaqCannyEdgeFilter]
|
||||
nullok=options
|
||||
[imaqConvolve2]
|
||||
inparams=kernel
|
||||
exclude=True
|
||||
[imaqEdgeFilter]
|
||||
nullok=mask
|
||||
[imaqLowPass]
|
||||
nullok=mask
|
||||
[imaqMedianFilter]
|
||||
nullok=mask
|
||||
[imaqNthOrderFilter]
|
||||
nullok=mask
|
||||
|
||||
; Drawing functions
|
||||
[imaqDrawTextOnImage]
|
||||
nullok=options,fontNameUsed
|
||||
|
||||
; Interlacing functions
|
||||
[imaqInterlaceSeparate]
|
||||
nullok=odd,even
|
||||
|
||||
; Image Information functions
|
||||
[imaqEnumerateCustomKeys]
|
||||
retarraysize=size
|
||||
[imaqGetImageSize]
|
||||
nullok=width,height
|
||||
[imaqGetPixelAddress]
|
||||
underscored=True
|
||||
[imaqReadCustomData]
|
||||
underscored=True
|
||||
|
||||
; Display functions
|
||||
[imaqGetLastKey]
|
||||
nullok=keyPressed,windowNumber,modifiers
|
||||
[imaqGetWindowCenterPos]
|
||||
outparams=centerPosition
|
||||
|
||||
; Image Manipulation functions
|
||||
[imaqCast]
|
||||
nullok=lookup
|
||||
exclude=True
|
||||
[imaqFlatten]
|
||||
underscored=True
|
||||
exclude=True
|
||||
[imaqRotate2]
|
||||
# TODO because of PixelValue
|
||||
exclude=True
|
||||
[imaqShift]
|
||||
# TODO because of PixelValue
|
||||
exclude=True
|
||||
[imaqUnflatten]
|
||||
underscored=True
|
||||
exclude=True
|
||||
|
||||
; File I/O functions
|
||||
[imaqGetAVIInfo]
|
||||
outparams=info
|
||||
[imaqGetFileInfo]
|
||||
nullok=calibrationUnit,calibrationX,calibrationY,width,height,imageType
|
||||
[imaqGetFilterNames]
|
||||
retarraysize=numFilters
|
||||
[imaqLoadImagePopup]
|
||||
retarraysize=numPaths
|
||||
[imaqReadAVIFrame]
|
||||
exclude=True
|
||||
[imaqReadFile]
|
||||
nullok=colorTable,numColors
|
||||
[imaqWriteBMPFile]
|
||||
nullok=colorTable
|
||||
defaults=colorTable:null
|
||||
[imaqWriteFile]
|
||||
nullok=colorTable
|
||||
defaults=colorTable:null
|
||||
[imaqWriteJPEGFile]
|
||||
nullok=colorTable
|
||||
defaults=colorTable:null
|
||||
inparams=colorTable
|
||||
[imaqWritePNGFile2]
|
||||
nullok=colorTable
|
||||
defaults=colorTable:null
|
||||
[imaqWriteTIFFFile]
|
||||
nullok=options,colorTable
|
||||
defaults=options:null,colorTable:null
|
||||
|
||||
; Analytic Geometry functions
|
||||
[imaqBuildCoordinateSystem]
|
||||
outparams=system
|
||||
[imaqFitCircle2]
|
||||
arraysize=points:numPoints
|
||||
[imaqFitEllipse2]
|
||||
arraysize=points:numPoints
|
||||
[imaqFitLine]
|
||||
arraysize=points:numPoints
|
||||
[imaqGetBisectingLine]
|
||||
outparams=bisectStart,bisectEnd
|
||||
[imaqGetIntersection]
|
||||
outparams=intersection
|
||||
[imaqGetMidLine]
|
||||
outparams=midLineStart,midLineEnd
|
||||
[imaqGetPerpendicularLine]
|
||||
outparams=perpLineStart,perpLineEnd
|
||||
[imaqGetPointsOnContour]
|
||||
retarraysize=numSegments
|
||||
[imaqGetPointsOnLine]
|
||||
retarraysize=numPoints
|
||||
[imaqInterpolatePoints]
|
||||
retarraysize=interpCount
|
||||
arraysize=points:numPoints
|
||||
|
||||
; Clipboard functions
|
||||
[imaqClipboardToImage]
|
||||
nullok=palette
|
||||
[imaqImageToClipboard]
|
||||
nullok=palette
|
||||
|
||||
; Image Management functions
|
||||
[imaqCreateImage]
|
||||
defaults=borderSize:0
|
||||
[imaqImageToArray]
|
||||
nullok=columns,rows
|
||||
underscored=True
|
||||
exclude=True
|
||||
|
||||
; Color Processing functions
|
||||
[imaqChangeColorSpace2]
|
||||
# TODO because of Color2
|
||||
exclude=True
|
||||
[imaqColorBCGTransform]
|
||||
nullok=redOptions,greenOptions,blueOptions,mask
|
||||
[imaqColorHistogram2]
|
||||
nullok=mask
|
||||
[imaqColorLookup]
|
||||
nullok=mask,plane1,plane2,plane3
|
||||
exclude=True
|
||||
[imaqColorThreshold]
|
||||
nullok=plane1Range,plane2Range,plane3Range
|
||||
|
||||
; Transform functions
|
||||
[imaqBCGTransform]
|
||||
nullok=mask
|
||||
[imaqEqualize]
|
||||
nullok=mask
|
||||
[imaqInverse]
|
||||
nullok=mask
|
||||
[imaqMathTransform]
|
||||
nullok=mask
|
||||
[imaqLookup2]
|
||||
nullok=mask
|
||||
exclude=True
|
||||
|
||||
; Window Management functions
|
||||
[imaqGetMousePos]
|
||||
nullok=position,windowNumber
|
||||
[imaqGetWindowBackground]
|
||||
outparams=backgroundColor
|
||||
[imaqGetWindowDisplayMapping]
|
||||
outparams=mapping
|
||||
[imaqGetWindowGrid]
|
||||
nullok=xResolution,yResolution
|
||||
[imaqGetWindowPos]
|
||||
outparams=position
|
||||
[imaqGetWindowSize]
|
||||
nullok=width,height
|
||||
[imaqSetWindowPalette]
|
||||
arraysize=palette:numColors
|
||||
nullok=palette
|
||||
|
||||
; Utilities functions
|
||||
; Many Make* functions are faster in native Python
|
||||
[imaqMakeAnnulus]
|
||||
exclude=True
|
||||
[imaqMakePoint]
|
||||
exclude=True
|
||||
[imaqMakePointFloat]
|
||||
exclude=True
|
||||
[imaqMakeRect]
|
||||
exclude=True
|
||||
[imaqMakeRectFromRotatedRect]
|
||||
exclude=True
|
||||
[imaqMakeRotatedRect]
|
||||
exclude=True
|
||||
[imaqMakeRotatedRectFromRect]
|
||||
exclude=True
|
||||
[imaqMulticoreOptions]
|
||||
underscored=True
|
||||
|
||||
; Tool Window functions
|
||||
[imaqGetLastEvent]
|
||||
nullok=windowNumber,tool,rect
|
||||
outparams=type,tool,rect
|
||||
[imaqGetToolWindowPos]
|
||||
outparams=position
|
||||
[imaqSetEventCallback]
|
||||
exclude=True
|
||||
[imaqSetupToolWindow]
|
||||
nullok=options
|
||||
|
||||
; Meter functions
|
||||
[imaqReadMeter]
|
||||
outparams=endOfNeedle
|
||||
|
||||
; Calibration functions
|
||||
[imaqCorrectCalibratedImage]
|
||||
# TODO because of PixelValue
|
||||
exclude=True
|
||||
[imaqTransformPixelToRealWorld]
|
||||
arraysize=pixelCoordinates:numCoordinates
|
||||
[imaqTransformRealWorldToPixel]
|
||||
arraysize=realWorldCoordinates:numCoordinates
|
||||
|
||||
; Pixel Manipulation functions
|
||||
[imaqArrayToComplexPlane]
|
||||
exclude=True
|
||||
[imaqComplexPlaneToArray]
|
||||
nullok=columns,rows
|
||||
underscored=True
|
||||
exclude=True
|
||||
[imaqExtractColorPlanes]
|
||||
nullok=plane1,plane2,plane3
|
||||
[imaqFillImage]
|
||||
nullok=mask
|
||||
# TODO because of PixelValue
|
||||
exclude=True
|
||||
[imaqGetLine]
|
||||
nullok=numPoints
|
||||
underscored=True
|
||||
exclude=True
|
||||
[imaqGetPixel]
|
||||
outparams=value
|
||||
# TODO because of PixelValue
|
||||
exclude=True
|
||||
[imaqReplaceColorPlanes]
|
||||
nullok=plane1,plane2,plane3
|
||||
[imaqSetLine]
|
||||
underscored=True
|
||||
exclude=True
|
||||
[imaqSetPixel]
|
||||
# TODO because of PixelValue
|
||||
exclude=True
|
||||
|
||||
; Color Matching functions
|
||||
[imaqLearnColor]
|
||||
nullok=roi
|
||||
[imaqMatchColor]
|
||||
retarraysize=numScores
|
||||
nullok=roi
|
||||
|
||||
; Barcode I/O functions
|
||||
[imaqGradeDataMatrixBarcodeAIM]
|
||||
outparams=report
|
||||
[imaqReadBarcode]
|
||||
nullok=roi
|
||||
[imaqReadPDF417Barcode]
|
||||
retarraysize=numBarcodes
|
||||
[imaqReadQRCode]
|
||||
defaults=reserved:IMAQ_QR_NO_GRADING
|
||||
|
||||
; LCD functions
|
||||
[imaqFindLCDSegments]
|
||||
nullok=options
|
||||
[imaqReadLCD]
|
||||
nullok=options
|
||||
|
||||
; Shape Matching functions
|
||||
[imaqMatchShape]
|
||||
retarraysize=numMatches
|
||||
|
||||
; Contours functions
|
||||
[imaqAddClosedContour]
|
||||
arraysize=points:numPoints
|
||||
[imaqAddOpenContour]
|
||||
arraysize=points:numPoints
|
||||
[imaqGetContourColor]
|
||||
outparams=contourColor
|
||||
|
||||
; Regions of Interest functions
|
||||
[imaqGetROIBoundingBox]
|
||||
outparams=boundingBox
|
||||
[imaqGetROIColor]
|
||||
outparams=roiColor
|
||||
[imaqSetWindowROI]
|
||||
nullok=roi
|
||||
|
||||
; Image Analysis functions
|
||||
[imaqExtractCurves]
|
||||
retarraysize=numCurves
|
||||
[imaqHistogram]
|
||||
nullok=mask
|
||||
[imaqQuantify]
|
||||
nullok=mask
|
||||
|
||||
; Error Management functions
|
||||
[imaqClearError]
|
||||
exclude=True
|
||||
[imaqGetErrorText]
|
||||
exclude=True
|
||||
[imaqGetLastError]
|
||||
exclude=True
|
||||
[imaqGetLastErrorFunc]
|
||||
exclude=True
|
||||
[imaqSetError]
|
||||
nullok=function
|
||||
exclude=True
|
||||
|
||||
; Threshold functions
|
||||
[imaqMultithreshold]
|
||||
arraysize=ranges:numRanges
|
||||
|
||||
; Memory Management functions
|
||||
[imaqDispose]
|
||||
# This is done as a full-custom function
|
||||
exclude=True
|
||||
|
||||
; Pattern Matching functions
|
||||
[imaqDetectCircles]
|
||||
retarraysize=numMatchesReturned
|
||||
[imaqDetectEllipses]
|
||||
retarraysize=numMatchesReturned
|
||||
[imaqDetectLines]
|
||||
retarraysize=numMatchesReturned
|
||||
[imaqDetectRectangles]
|
||||
retarraysize=numMatchesReturned
|
||||
[imaqGetGeometricFeaturesFromCurves]
|
||||
retarraysize=numFeatures
|
||||
arraysize=curves:numCurves,featureTypes:numFeatureTypes
|
||||
[imaqGetGeometricTemplateFeatureInfo]
|
||||
retarraysize=numFeatures
|
||||
[imaqLearnMultipleGeometricPatterns]
|
||||
arraysize=patterns:numberOfPatterns
|
||||
exclude=True
|
||||
[imaqMatchColorPattern]
|
||||
retarraysize=numMatches
|
||||
[imaqMatchGeometricPattern2]
|
||||
retarraysize=numMatches
|
||||
[imaqMatchMultipleGeometricPatterns]
|
||||
retarraysize=numMatches
|
||||
[imaqReadMultipleGeometricPatternFile]
|
||||
underscored=True
|
||||
[imaqRefineMatches]
|
||||
retarraysize=numCandidatesOut
|
||||
arraysize=candidatesIn:numCandidatesIn
|
||||
[imaqMatchGeometricPattern3]
|
||||
retarraysize=numMatches
|
||||
[imaqMatchPattern3]
|
||||
retarraysize=numMatches
|
||||
nullok=options
|
||||
|
||||
; Overlay functions
|
||||
[imaqGetOverlayProperties]
|
||||
outparams=transformBehaviors
|
||||
[imaqMergeOverlay]
|
||||
arraysize=palette:numColors
|
||||
[imaqOverlayBitmap]
|
||||
underscored=True
|
||||
[imaqOverlayClosedContour]
|
||||
arraysize=points:numPoints
|
||||
[imaqOverlayOpenContour]
|
||||
arraysize=points:numPoints
|
||||
[imaqOverlayPoints]
|
||||
arraysize=points:numPoints,colors:numColors
|
||||
|
||||
; OCR functions
|
||||
[imaqVerifyPatterns]
|
||||
arraysize=expectedPatterns:patternCount
|
||||
retarraysize=numScores
|
||||
[imaqVerifyText]
|
||||
retarraysize=numScores
|
||||
|
||||
; Geometric Matching functions
|
||||
[imaqContourClassifyCurvature]
|
||||
arraysize=curvatureClasses:numCurvatureClasses
|
||||
[imaqContourClassifyDistances]
|
||||
arraysize=distanceRanges:numDistanceRanges
|
||||
[imaqContourSetupMatchPattern]
|
||||
arraysize=rangeSettings:numRangeSettings
|
||||
[imaqContourAdvancedSetupMatchPattern]
|
||||
arraysize=geometricOptions:numGeometricOptions
|
||||
|
||||
; Morphology Reconstruction functions
|
||||
[imaqGrayMorphologyReconstruct]
|
||||
arraysize=points:numOfPoints
|
||||
[imaqMorphologyReconstruct]
|
||||
arraysize=points:numOfPoints
|
||||
|
||||
; Texture functions
|
||||
[imaqCooccurrenceMatrix]
|
||||
exclude=True
|
||||
[imaqExtractTextureFeatures]
|
||||
inparams=waveletBands
|
||||
exclude=True
|
||||
[imaqExtractWaveletBands]
|
||||
inparams=waveletBands
|
||||
exclude=True
|
||||
|
||||
; Regions of Interest Manipulation functions
|
||||
[imaqMaskToROI]
|
||||
nullok=withinLimit
|
||||
[imaqROIToMask]
|
||||
nullok=imageModel,inSpace
|
||||
[imaqLabelToROI]
|
||||
arraysize=labelsIn:numLabelsIn
|
||||
|
||||
; Morphology functions
|
||||
[imaqGrayMorphology]
|
||||
nullok=structuringElement
|
||||
|
||||
; Classification functions
|
||||
[imaqAddClassifierSample]
|
||||
arraysize=featureVector:vectorSize
|
||||
[imaqAdvanceClassify]
|
||||
arraysize=featureVector:vectorSize
|
||||
[imaqClassify]
|
||||
arraysize=featureVector:vectorSize
|
||||
[imaqGetColorClassifierOptions]
|
||||
outparams=options
|
||||
[imaqGetNearestNeighborOptions]
|
||||
outparams=options
|
||||
;[imaqReadClassifierFile]
|
||||
;[imaqWriteClassifierFile]
|
||||
|
||||
; Obsolete functions
|
||||
[imaqWritePNGFile]
|
||||
nullok=colorTable
|
||||
defaults=colorTable:null
|
||||
[imaqRotate]
|
||||
# TODO because of PixelValue
|
||||
exclude=True
|
||||
[imaqSelectParticles]
|
||||
retarraysize=selectedCount
|
||||
[imaqGetParticleInfo]
|
||||
retarraysize=reportCount
|
||||
[imaqEdgeTool]
|
||||
retarraysize=numEdges
|
||||
[imaqCircles]
|
||||
retarraysize=numCircles
|
||||
[imaqFitEllipse]
|
||||
arraysize=points:numPoints
|
||||
outparams=ellipse
|
||||
[imaqFitCircle]
|
||||
arraysize=points:numPoints
|
||||
outparams=circle
|
||||
[imaqChangeColorSpace]
|
||||
# TODO because of Color
|
||||
exclude=True
|
||||
[imaqMatchPattern]
|
||||
retarraysize=numMatches
|
||||
nullok=options
|
||||
[imaqLineGaugeTool]
|
||||
nullok=reference
|
||||
[imaqBestCircle]
|
||||
arraysize=points:numPoints
|
||||
outparams=center
|
||||
[imaqCoordinateReference]
|
||||
outparams=origin
|
||||
[imaqSetWindowOverlay]
|
||||
nullok=overlay
|
||||
[imaqGetCalibrationInfo]
|
||||
outparams=unit,xDistance,yDistance
|
||||
nullok=unit,xDistance,yDistance
|
||||
[imaqGetParticleClassifierOptions]
|
||||
outparams=preprocessingOptions,options
|
||||
[imaqConvolve]
|
||||
nullok=mask
|
||||
inparams=kernel
|
||||
exclude=True
|
||||
[imaqDivideConstant]
|
||||
# TODO because of PixelValue
|
||||
exclude=True
|
||||
[imaqLookup]
|
||||
nullok=mask
|
||||
exclude=True
|
||||
[imaqMatchPattern2]
|
||||
retarraysize=numMatches
|
||||
nullok=options
|
||||
[imaqMaxConstant]
|
||||
# TODO because of PixelValue
|
||||
exclude=True
|
||||
[imaqParticleFilter2]
|
||||
arraysize=criteria:criteriaCount
|
||||
[imaqEdgeTool2]
|
||||
retarraysize=numEdges
|
||||
[imaqReadDataMatrixBarcode]
|
||||
retarraysize=numBarcodes
|
||||
[imaqMatchGeometricPattern]
|
||||
retarraysize=numMatches
|
||||
[imaqColorHistogram]
|
||||
nullok=mask
|
||||
|
||||
; block comment exclusion list
|
||||
[Block Comment]
|
||||
exclude=
|
||||
Includes
|
||||
Control Defines
|
||||
Macros
|
||||
This accomplishes said task.
|
||||
If using Visual C++, force startup & shutdown code to run.
|
||||
Error Management functions
|
||||
Callback Function Type
|
||||
Backwards Compatibility
|
||||
Error Codes
|
||||
1863
wpilibj/wpilibJavaJNI/nivision/nivision_arm.ini
Normal file
1863
wpilibj/wpilibJavaJNI/nivision/nivision_arm.ini
Normal file
File diff suppressed because it is too large
Load Diff
220
wpilibj/wpilibJavaJNI/nivision/nivision_parse.py
Normal file
220
wpilibj/wpilibJavaJNI/nivision/nivision_parse.py
Normal file
@@ -0,0 +1,220 @@
|
||||
from __future__ import print_function
|
||||
import re
|
||||
import traceback
|
||||
|
||||
__all__ = ["define_after_struct", "defined", "forward_structs", "opaque_structs", "enums", "structs", "prescan_file", "parse_file", "number_re", "constant_re"]
|
||||
|
||||
# parser regular expressions
|
||||
number_re = re.compile(r'-?[0-9]+')
|
||||
constant_re = re.compile(r'[A-Z0-9_]+')
|
||||
define_re = re.compile(r'^#define\s+(?P<name>(IMAQ|ERR)_[A-Z0-9_]+)\s+(?P<value>.*)')
|
||||
enum_re = re.compile(r'^typedef\s+enum\s+(?P<name>[A-Za-z0-9]+)_enum\s*{')
|
||||
enum_value_re = re.compile(r'^\s*(?P<name>[A-Z0-9_]+)\s*=\s*(?P<value>-?[0-9A-Fx]+)\s*,?')
|
||||
struct_re = re.compile(r'^typedef\s+struct\s+(?P<name>[A-Za-z0-9]+)_struct\s*{')
|
||||
union_re = re.compile(r'^typedef\s+union\s+(?P<name>[A-Za-z0-9]+)_union\s*{')
|
||||
func_pointer_re = re.compile(r'(?P<restype>[A-Za-z0-9_*]+)\s*\(\s*[A-Za-z0-9_]*[*]\s*(?P<name>[A-Za-z0-9_]+)\s*\)\s*\((?P<params>[^)]*)\)')
|
||||
static_const_re = re.compile(r'^static\s+const\s+(?P<type>[A-Za-z0-9_]+)\s+(?P<name>[A-Za-z0-9_]+)\s*=\s*(?P<value>[^;]+);')
|
||||
function_re = re.compile(r'^(IMAQ_FUNC\s+)?(?P<restype>(const\s+)?[A-Za-z0-9_*]+)\s+(IMAQ_STDCALL\s+)?(?P<name>[A-Za-z0-9_]+)\s*\((?P<params>[^)]*)\);')
|
||||
|
||||
# defines deferred until after structures
|
||||
define_after_struct = []
|
||||
defined = set()
|
||||
forward_structs = set()
|
||||
opaque_structs = set()
|
||||
enums = set()
|
||||
structs = set()
|
||||
|
||||
def parse_cdecl(decl):
|
||||
decl = " ".join(decl.split())
|
||||
ctype, sep, name = decl.rpartition(' ')
|
||||
# look for array[]
|
||||
name, bracket, arr = name.partition('[')
|
||||
if arr:
|
||||
arr = arr[:-1]
|
||||
else:
|
||||
arr = None
|
||||
return name, ctype, arr
|
||||
|
||||
def split_comment(line):
|
||||
if line.startswith('/*'):
|
||||
return "", ""
|
||||
parts = line.split('//', 1)
|
||||
code = parts[0].strip()
|
||||
comment = parts[1].strip() if len(parts) > 1 else None
|
||||
return code, comment
|
||||
|
||||
def prescan_file(f):
|
||||
for line in f:
|
||||
code, comment = split_comment(line)
|
||||
if not code and not comment:
|
||||
continue
|
||||
|
||||
# typedef struct {
|
||||
m = struct_re.match(code)
|
||||
if m is not None:
|
||||
structs.add(m.group('name'))
|
||||
continue
|
||||
|
||||
# other typedef
|
||||
if code.startswith("typedef"):
|
||||
if '(' in code:
|
||||
continue
|
||||
name, typedef, arr = parse_cdecl(code[8:-1])
|
||||
if typedef.startswith("struct"):
|
||||
forward_structs.add(name)
|
||||
continue
|
||||
|
||||
opaque_structs.update(forward_structs - structs)
|
||||
|
||||
def parse_file(emit, f, block_comment_exclude):
|
||||
in_block_comment = False
|
||||
cur_block = ""
|
||||
in_enum = None
|
||||
in_struct = None
|
||||
in_union = None
|
||||
|
||||
for lineno, line in enumerate(f):
|
||||
code, comment = split_comment(line)
|
||||
if not code and not comment:
|
||||
continue
|
||||
#print(comment)
|
||||
|
||||
# in block comment
|
||||
if in_block_comment:
|
||||
if not code and comment is not None and comment[0] == '=':
|
||||
# closing block comment; emit if not excluded
|
||||
if cur_block not in block_comment_exclude:
|
||||
try:
|
||||
emit.block_comment(cur_block)
|
||||
except Exception as e:
|
||||
print("%d: exception in block_comment():\n%s" % (lineno+1, traceback.format_exc()))
|
||||
in_block_comment = False
|
||||
# emit "after struct" constants in Globals
|
||||
if cur_block == "Globals":
|
||||
for dname, dtext in define_after_struct:
|
||||
try:
|
||||
emit.text(dtext)
|
||||
except Exception as e:
|
||||
print("%d: exception in text():\n%s" % (lineno+1, traceback.format_exc()))
|
||||
defined.add(dname)
|
||||
continue
|
||||
if not code and comment is not None:
|
||||
# remember current block
|
||||
cur_block = comment
|
||||
continue
|
||||
|
||||
# inside enum
|
||||
if in_enum is not None:
|
||||
if code[0] == '}':
|
||||
# closing
|
||||
try:
|
||||
emit.enum(*in_enum)
|
||||
except Exception as e:
|
||||
print("%d: exception in enum():\n%s" % (lineno+1, traceback.format_exc()))
|
||||
in_enum = None
|
||||
continue
|
||||
m = enum_value_re.match(code)
|
||||
if m is not None:
|
||||
in_enum[1].append((m.group('name'), m.group('value'), comment))
|
||||
continue
|
||||
|
||||
# inside struct/union
|
||||
if in_struct is not None or in_union is not None:
|
||||
if code[0] == '}':
|
||||
# closing
|
||||
if in_struct is not None:
|
||||
try:
|
||||
emit.struct(*in_struct)
|
||||
except Exception as e:
|
||||
print("%d: exception in struct(\"%s\"):\n%s" % (lineno+1, in_struct[0], traceback.format_exc()))
|
||||
in_struct = None
|
||||
if in_union is not None:
|
||||
try:
|
||||
emit.union(*in_union)
|
||||
except Exception as e:
|
||||
print("%d: exception in union(\"%s\"):\n%s" % (lineno+1, in_union[0], traceback.format_exc()))
|
||||
in_union = None
|
||||
continue
|
||||
name, ctype, arr = parse_cdecl(code[:-1])
|
||||
# add to fields
|
||||
if in_struct is not None:
|
||||
in_struct[1].append((name, ctype, arr, comment))
|
||||
if in_union is not None:
|
||||
in_union[1].append((name, ctype, arr, comment))
|
||||
continue
|
||||
|
||||
# block comment
|
||||
if not code and comment is not None and comment[0] == '=':
|
||||
in_block_comment = True
|
||||
|
||||
# #define
|
||||
m = define_re.match(code)
|
||||
if m is not None:
|
||||
try:
|
||||
emit.define(m.group('name'), m.group('value').strip(), comment)
|
||||
except Exception as e:
|
||||
print("%d: exception in define():\n%s" % (lineno+1, traceback.format_exc()))
|
||||
continue
|
||||
|
||||
# typedef enum {
|
||||
m = enum_re.match(code)
|
||||
if m is not None:
|
||||
in_enum = (m.group('name'), [])
|
||||
continue
|
||||
|
||||
# typedef struct {
|
||||
m = struct_re.match(code)
|
||||
if m is not None:
|
||||
in_struct = (m.group('name'), [])
|
||||
continue
|
||||
|
||||
# typedef union {
|
||||
m = union_re.match(code)
|
||||
if m is not None:
|
||||
in_union = (m.group('name'), [])
|
||||
continue
|
||||
|
||||
# other typedef
|
||||
if code.startswith("typedef"):
|
||||
# typedef function?
|
||||
m = func_pointer_re.match(code[8:-1])
|
||||
if m is not None:
|
||||
params = [parse_cdecl(param.strip()) for param in m.group('params').strip().split(',') if param.strip()]
|
||||
try:
|
||||
emit.typedef_function(m.group('name'), m.group('restype'), params)
|
||||
except Exception as e:
|
||||
print("%d: exception in typedef_function():\n%s" % (lineno+1, traceback.format_exc()))
|
||||
continue
|
||||
if '(' in code:
|
||||
print("Invalid typedef: %s" % code)
|
||||
continue
|
||||
emit.typedef(*parse_cdecl(code[8:-1]))
|
||||
continue
|
||||
|
||||
# function
|
||||
m = function_re.match(code)
|
||||
if m is not None:
|
||||
params = [parse_cdecl(param.strip()) for param in m.group('params').strip().split(',') if param.strip()]
|
||||
try:
|
||||
emit.function(m.group('name'), m.group('restype'), params)
|
||||
except Exception as e:
|
||||
print("%d: exception in function(\"%s\"):\n%s" % (lineno+1, m.group('name'), traceback.format_exc()))
|
||||
continue
|
||||
|
||||
# static const
|
||||
m = static_const_re.match(code)
|
||||
if m is not None:
|
||||
value = m.group('value')
|
||||
if value[0] == '{':
|
||||
value = [v.strip() for v in value[1:-1].strip().split(',') if v.strip()]
|
||||
try:
|
||||
emit.static_const(m.group('name'), m.group('type'), value)
|
||||
except Exception as e:
|
||||
print("%d: exception in static_const():\n%s" % (lineno+1, traceback.format_exc()))
|
||||
continue
|
||||
|
||||
if not code or code[0] == '#':
|
||||
continue
|
||||
|
||||
print("%d: Unrecognized: %s" % (lineno+1, code))
|
||||
|
||||
Reference in New Issue
Block a user