Added a kind of range-check for assignments between cards and ints
This commit is contained in:
		
							parent
							
								
									c839c01680
								
							
						
					
					
						commit
						befe7be9de
					
				
					 2 changed files with 43 additions and 4 deletions
				
			
		| 
						 | 
					@ -17,6 +17,7 @@
 | 
				
			||||||
#include	<em_arith.h>
 | 
					#include	<em_arith.h>
 | 
				
			||||||
#include	<em_label.h>
 | 
					#include	<em_label.h>
 | 
				
			||||||
#include	<em_code.h>
 | 
					#include	<em_code.h>
 | 
				
			||||||
 | 
					#include	<em_abs.h>
 | 
				
			||||||
#include	<assert.h>
 | 
					#include	<assert.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include	"type.h"
 | 
					#include	"type.h"
 | 
				
			||||||
| 
						 | 
					@ -396,7 +397,7 @@ CodeParameters(param, arg)
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	CodePExpr(left);
 | 
						CodePExpr(left);
 | 
				
			||||||
	CodeCheckExpr(left, tp);
 | 
						CodeCheckExpr(left_type, tp);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
CodeCheckExpr(tp1, tp2)
 | 
					CodeCheckExpr(tp1, tp2)
 | 
				
			||||||
| 
						 | 
					@ -586,6 +587,18 @@ RangeCheck(tpl, tpr)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						else if (tpl->tp_size <= tpr->tp_size &&
 | 
				
			||||||
 | 
							 ((tpl->tp_fund == T_INTEGER && tpr == card_type) ||
 | 
				
			||||||
 | 
							  (tpr->tp_fund == T_INTEGER && tpl == card_type))) {
 | 
				
			||||||
 | 
							label lb = ++text_label;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							C_dup(word_size);
 | 
				
			||||||
 | 
							C_zge(lb);
 | 
				
			||||||
 | 
							C_loc((arith) ECONV);
 | 
				
			||||||
 | 
							C_trp();
 | 
				
			||||||
 | 
							C_df_ilb(lb);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Operands(leftop, rightop, tp)
 | 
					Operands(leftop, rightop, tp)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -35,6 +35,7 @@ int		return_occurred;	/* set if a return occurs in a block */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* inline in declaration: need space
 | 
				
			||||||
ProcedureDeclaration
 | 
					ProcedureDeclaration
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct def *df;
 | 
						struct def *df;
 | 
				
			||||||
| 
						 | 
					@ -47,6 +48,7 @@ ProcedureDeclaration
 | 
				
			||||||
				--proclevel;
 | 
									--proclevel;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
;
 | 
					;
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ProcedureHeading(struct def **pdf; int type;)
 | 
					ProcedureHeading(struct def **pdf; int type;)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					@ -56,7 +58,18 @@ ProcedureHeading(struct def **pdf; int type;)
 | 
				
			||||||
} :
 | 
					} :
 | 
				
			||||||
	PROCEDURE IDENT
 | 
						PROCEDURE IDENT
 | 
				
			||||||
			{ *pdf = DeclProc(type, dot.TOK_IDF); }
 | 
								{ *pdf = DeclProc(type, dot.TOK_IDF); }
 | 
				
			||||||
	FormalParameters(&pr, &parmaddr, &tp)?
 | 
						[
 | 
				
			||||||
 | 
							'('
 | 
				
			||||||
 | 
							[
 | 
				
			||||||
 | 
								FPSection(&pr, &parmaddr)
 | 
				
			||||||
 | 
								[
 | 
				
			||||||
 | 
									';' FPSection(&pr, &parmaddr)
 | 
				
			||||||
 | 
								]*
 | 
				
			||||||
 | 
							]?
 | 
				
			||||||
 | 
							')'
 | 
				
			||||||
 | 
							[	':' qualtype(&tp)
 | 
				
			||||||
 | 
							]?
 | 
				
			||||||
 | 
						]?
 | 
				
			||||||
			{ CheckWithDef(*pdf, proc_type(tp, pr, parmaddr));
 | 
								{ CheckWithDef(*pdf, proc_type(tp, pr, parmaddr));
 | 
				
			||||||
			  if (tp && IsConstructed(tp)) {
 | 
								  if (tp && IsConstructed(tp)) {
 | 
				
			||||||
warning(W_STRICT, "procedure \"%s\" has a constructed result type",
 | 
					warning(W_STRICT, "procedure \"%s\" has a constructed result type",
 | 
				
			||||||
| 
						 | 
					@ -77,18 +90,30 @@ block(struct node **pnd;) :
 | 
				
			||||||
	END
 | 
						END
 | 
				
			||||||
;
 | 
					;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
declaration:
 | 
					declaration
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct def *df;
 | 
				
			||||||
 | 
					} :
 | 
				
			||||||
	CONST [ ConstantDeclaration ';' ]*
 | 
						CONST [ ConstantDeclaration ';' ]*
 | 
				
			||||||
|
 | 
					|
 | 
				
			||||||
	TYPE [ TypeDeclaration ';' ]*
 | 
						TYPE [ TypeDeclaration ';' ]*
 | 
				
			||||||
|
 | 
					|
 | 
				
			||||||
	VAR [ VariableDeclaration ';' ]*
 | 
						VAR [ VariableDeclaration ';' ]*
 | 
				
			||||||
|
 | 
					|
 | 
				
			||||||
	ProcedureDeclaration ';'
 | 
								{	++proclevel; }
 | 
				
			||||||
 | 
						ProcedureHeading(&df, D_PROCEDURE)
 | 
				
			||||||
 | 
						';'
 | 
				
			||||||
 | 
						block(&(df->prc_body))
 | 
				
			||||||
 | 
						IDENT
 | 
				
			||||||
 | 
								{	EndProc(df, dot.TOK_IDF);
 | 
				
			||||||
 | 
									--proclevel;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
						';'
 | 
				
			||||||
|
 | 
					|
 | 
				
			||||||
	ModuleDeclaration ';'
 | 
						ModuleDeclaration ';'
 | 
				
			||||||
;
 | 
					;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* inline in procedureheading: need space
 | 
				
			||||||
FormalParameters(struct paramlist **ppr; arith *parmaddr; struct type **ptp;):
 | 
					FormalParameters(struct paramlist **ppr; arith *parmaddr; struct type **ptp;):
 | 
				
			||||||
	'('
 | 
						'('
 | 
				
			||||||
	[
 | 
						[
 | 
				
			||||||
| 
						 | 
					@ -101,6 +126,7 @@ FormalParameters(struct paramlist **ppr; arith *parmaddr; struct type **ptp;):
 | 
				
			||||||
	[	':' qualtype(ptp)
 | 
						[	':' qualtype(ptp)
 | 
				
			||||||
	]?
 | 
						]?
 | 
				
			||||||
;
 | 
					;
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
FPSection(struct paramlist **ppr; arith *parmaddr;)
 | 
					FPSection(struct paramlist **ppr; arith *parmaddr;)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue