From f0076015075e009d5ca29b0f57c6a1ecaef8c917 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sun, 9 Apr 2017 16:31:14 +0200 Subject: [PATCH] Gerbview: fix an issue (crash or hang) when a aperture macro definition contains ( and ). Note: currently Gerbview does not handle yet operator precedence in aperture macro parameters. --- gerbview/class_am_param.cpp | 22 ++++++++++++++++++++-- gerbview/class_am_param.h | 20 ++++++++++++++------ gerbview/class_aperture_macro.cpp | 4 ++-- gerbview/class_aperture_macro.h | 2 +- 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/gerbview/class_am_param.cpp b/gerbview/class_am_param.cpp index d7d9469a85..51a23ce1a3 100644 --- a/gerbview/class_am_param.cpp +++ b/gerbview/class_am_param.cpp @@ -5,9 +5,9 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 1992-2010 Jean-Pierre Charras + * Copyright (C) 1992-2017 Jean-Pierre Charras * Copyright (C) 2010 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 1992-2010 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 1992-2017 KiCad Developers, see change_log.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -130,6 +130,14 @@ double AM_PARAM::GetValue( const D_CODE* aDcode ) const paramvalue /= curr_value; break; + case OPEN_PAR: + // Currently: do nothing because operator precedence is not yet considered + break; + + case CLOSE_PAR: + // Currently: do nothing because operator precedence is not yet considered + break; + default: wxLogDebug( wxT( "AM_PARAM::GetValue() : unexpected operator\n" ) ); break; @@ -213,6 +221,16 @@ bool AM_PARAM::ReadParam( char*& aText ) aText++; break; + case '(': // Open a block to evaluate an expression between '(' and ')' + PushOperator( OPEN_PAR ); + aText++; + break; + + case ')': // close a block between '(' and ')' + PushOperator( CLOSE_PAR ); + aText++; + break; + case 'x': case 'X': PushOperator( MUL ); diff --git a/gerbview/class_am_param.h b/gerbview/class_am_param.h index 5be6a0d935..5f949e638d 100644 --- a/gerbview/class_am_param.h +++ b/gerbview/class_am_param.h @@ -5,9 +5,9 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 1992-2015 Jean-Pierre Charras + * Copyright (C) 1992-2017 Jean-Pierre Charras * Copyright (C) 2010 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 1992-2015 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 1992-2017 KiCad Developers, see change_log.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -110,12 +110,18 @@ From an idea found in Gerbv, here is the way to evaluate a parameter. a AM_PARAM_ITEM holds info about operands and operators in a parameter definition ( a AM_PARAM ) like $2+$2-$3-$3/2 -There is no precedence defined in gerber RS274X, so actual value is calculated step to step. +Precedence was recently actually defined in gerber RS274X +(Previously, there was no actual info about this precedence) +This is the usual arithmetic precendence between + - x / ( ), the only ones used in Gerber + +However, because it is recent, currently, actual value is calculated step to step: +no precedence, and '(' ')' are ignored. + Parameter definition is described by a very primitive assembler. This "program "should describe how to calculate the parameter. -The assembler consist of 8 instruction intended for a stackbased machine. +The assembler consist of 10 instruction intended for a stackbased machine. The instructions are: -NOP, PUSHVALUE, PUSHPARM, ADD, SUB, MUL, DIV, EQUATE +NOP, PUSHVALUE, PUSHPARM, ADD, SUB, MUL, DIV, OPEN_PAR, CLOSE_PAR, EQUATE The instructions ---------------- @@ -132,12 +138,14 @@ ADD : The mathematical operation +. Takes the two uppermost values on the SUB : Same as ADD, but with -. MUL : Same as ADD, but with *. DIV : Same as ADD, but with /. +OPEN_PAR : Opening parenthesis: modify the precedence of operators by opening a local block. +CLOSE_PAR : Closing parenthesis: modify the precedence of operators by closing the local block. POPVALUE : used when evaluate the expression: store current calculated value */ enum parm_item_type { - NOP, PUSHVALUE, PUSHPARM, ADD, SUB, MUL, DIV, POPVALUE + NOP, PUSHVALUE, PUSHPARM, ADD, SUB, MUL, DIV, OPEN_PAR, CLOSE_PAR, POPVALUE }; /** diff --git a/gerbview/class_aperture_macro.cpp b/gerbview/class_aperture_macro.cpp index fd25940a42..866e00b20d 100644 --- a/gerbview/class_aperture_macro.cpp +++ b/gerbview/class_aperture_macro.cpp @@ -5,9 +5,9 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 1992-2016 Jean-Pierre Charras + * Copyright (C) 1992-2017 Jean-Pierre Charras * Copyright (C) 2010 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/gerbview/class_aperture_macro.h b/gerbview/class_aperture_macro.h index 0b88de2894..dc94ef259a 100644 --- a/gerbview/class_aperture_macro.h +++ b/gerbview/class_aperture_macro.h @@ -8,7 +8,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 1992-2010 Jean-Pierre Charras + * Copyright (C) 1992-2010 Jean-Pierre Charras * Copyright (C) 2010 SoftPLC Corporation, Dick Hollenbeck * Copyright (C) 1992-2010 KiCad Developers, see AUTHORS.txt for contributors. *