My Project
Loading...
Searching...
No Matches
Functions | Variables
ipconv.h File Reference
#include "kernel/structs.h"

Go to the source code of this file.

Functions

int iiTestConvert (int inputType, int outputType, const struct sConvertTypes *dCT=dConvertTypes)
 
BOOLEAN iiConvert (int inputType, int outputType, int index, leftv input, leftv output, const struct sConvertTypes *dCT=dConvertTypes)
 

Variables

const struct sConvertTypes dConvertTypes []
 

Function Documentation

◆ iiConvert()

BOOLEAN iiConvert ( int  inputType,
int  outputType,
int  index,
leftv  input,
leftv  output,
const struct sConvertTypes dCT = dConvertTypes 
)

Definition at line 435 of file ipconv.cc.

436{
437 output->Init();
438 if ((inputType==outputType)
439 || (outputType==DEF_CMD)
440 || ((outputType==IDHDL)&&(input->rtyp==IDHDL)))
441 {
442 memcpy(output,input,sizeof(*output));
443 input->Init();
444 return FALSE;
445 }
446 else if (outputType==ANY_TYPE)
447 {
448 output->rtyp=ANY_TYPE;
449 output->data=(char *)(long)input->Typ();
450 /* the name of the object:*/
451 if (input->e==NULL)
452 {
453 if (input->rtyp==IDHDL)
454 /* preserve name: copy it */
455 output->name=omStrDup(IDID((idhdl)(input->data)));
456 else if (input->name!=NULL)
457 {
458 if (input->rtyp==ALIAS_CMD)
459 output->name=omStrDup(input->name);
460 else
461 {
462 output->name=input->name;
463 input->name=NULL;
464 }
465 }
466 else if ((input->rtyp==POLY_CMD) && (input->name==NULL))
467 {
468 if (input->data!=NULL)
469 {
470 int nr=pIsPurePower((poly)input->data);
471 if (nr!=0)
472 {
473 if (pGetExp((poly)input->data,nr)==1)
474 {
475 output->name=omStrDup(currRing->names[nr-1]);
476 }
477 else
478 {
479 char *tmp=(char *)omAlloc(4);
480 sprintf(tmp,"%c%d",*(currRing->names[nr-1]),
481 (int)pGetExp((poly)input->data,nr));
482 output->name=tmp;
483 }
484 }
485 else if(pIsConstant((poly)input->data))
486 {
487 StringSetS("");
488 number n=(pGetCoeff((poly)input->data));
489 n_Write(n, currRing->cf);
490 (pGetCoeff((poly)input->data))=n; // n_Write may have changed n
491 output->name=StringEndS();
492 }
493 }
494 }
495 else if ((input->rtyp==NUMBER_CMD) && (input->name==NULL))
496 {
497 StringSetS("");
498 number n=(number)input->data;
499 n_Write(n, currRing->cf);
500 input->data=(void*)n; // n_Write may have changed n
501 output->name=StringEndS();
502 }
503 else
504 {
505 /* no need to preserve name: use it */
506 output->name=input->name;
507 input->name=NULL;
508 }
509 }
510 output->next=input->next;
511 input->next=NULL;
512 if (!errorreported) input->CleanUp();
513 return errorreported;
514 }
515 if (index!=0) /* iiTestConvert does not returned 'failure' */
516 {
517 index--;
518
519 if((dConvertTypes[index].i_typ==inputType)
520 &&(dConvertTypes[index].o_typ==outputType))
521 {
523 {
524 Print("automatic conversion %s -> %s\n",
525 Tok2Cmdname(inputType),Tok2Cmdname(outputType));
526 }
527 if ((currRing==NULL) && (outputType>BEGIN_RING) && (outputType<END_RING))
528 return TRUE;
529 output->rtyp=outputType;
531 {
532 output->data=dConvertTypes[index].p(input->CopyD());
533 }
534 else
535 {
536 dConvertTypes[index].pl(output,input);
537 }
538 if ((output->data==NULL)
539 && ((outputType!=INT_CMD)
540 &&(outputType!=POLY_CMD)
541 &&(outputType!=VECTOR_CMD)
542 &&(outputType!=NUMBER_CMD)))
543 {
544 return TRUE;
545 }
546 if (errorreported) return TRUE;
547 output->next=input->next;
548 input->next=NULL;
549 if ((input->rtyp!=IDHDL) && (input->attribute!=NULL))
550 {
551 input->attribute->killAll(currRing);
552 input->attribute=NULL;
553 }
554 if (input->e!=NULL)
555 {
556 Subexpr h;
557 while (input->e!=NULL)
558 {
559 h=input->e->next;
561 input->e=h;
562 }
563 }
564 //input->Init(); // seems that input (rtyp?) is still needed
565 return FALSE;
566 }
567 }
568 return TRUE;
569}
#define TRUE
Definition: auxiliary.h:100
#define FALSE
Definition: auxiliary.h:96
void * ADDRESS
Definition: auxiliary.h:119
int p
Definition: cfModGcd.cc:4078
Definition: idrec.h:35
void killAll(const ring r)
Definition: attrib.cc:189
void * CopyD(int t)
Definition: subexpr.cc:710
int Typ()
Definition: subexpr.cc:1019
const char * name
Definition: subexpr.h:87
int rtyp
Definition: subexpr.h:91
void Init()
Definition: subexpr.h:107
leftv next
Definition: subexpr.h:86
void * data
Definition: subexpr.h:88
void CleanUp(ring r=currRing)
Definition: subexpr.cc:348
Subexpr e
Definition: subexpr.h:105
attr attribute
Definition: subexpr.h:89
static FORCE_INLINE void n_Write(number n, const coeffs r, const BOOLEAN bShortOut=TRUE)
Definition: coeffs.h:588
#define Print
Definition: emacs.cc:80
VAR short errorreported
Definition: feFopen.cc:23
const char * Tok2Cmdname(int tok)
Definition: gentable.cc:140
@ END_RING
Definition: grammar.cc:310
@ BEGIN_RING
Definition: grammar.cc:282
@ VECTOR_CMD
Definition: grammar.cc:292
@ NUMBER_CMD
Definition: grammar.cc:288
@ POLY_CMD
Definition: grammar.cc:289
const struct sConvertTypes dConvertTypes[]
Definition: table.h:1285
#define IDID(a)
Definition: ipid.h:122
STATIC_VAR Poly * h
Definition: janet.cc:971
static number & pGetCoeff(poly p)
return an alias to the leading coefficient of p assumes that p != NULL NOTE: not copy
Definition: monomials.h:44
#define omStrDup(s)
Definition: omAllocDecl.h:263
#define omAlloc(size)
Definition: omAllocDecl.h:210
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259
#define NULL
Definition: omList.c:12
static int index(p_Length length, p_Ord ord)
Definition: p_Procs_Impl.h:592
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13
#define pIsConstant(p)
like above, except that Comp must be 0
Definition: polys.h:238
#define pGetExp(p, i)
Exponent.
Definition: polys.h:41
#define pIsPurePower(p)
Definition: polys.h:248
void StringSetS(const char *st)
Definition: reporter.cc:128
char * StringEndS()
Definition: reporter.cc:151
EXTERN_VAR int traceit
Definition: reporter.h:24
#define TRACE_CONV
Definition: reporter.h:48
VAR omBin sSubexpr_bin
Definition: subexpr.cc:40
#define IDHDL
Definition: tok.h:31
@ ALIAS_CMD
Definition: tok.h:34
@ DEF_CMD
Definition: tok.h:58
@ INT_CMD
Definition: tok.h:96
#define ANY_TYPE
Definition: tok.h:30

◆ iiTestConvert()

int iiTestConvert ( int  inputType,
int  outputType,
const struct sConvertTypes dCT = dConvertTypes 
)

Definition at line 575 of file ipconv.cc.

576{
577 if ((inputType==outputType)
578 || (outputType==DEF_CMD)
579 || (outputType==IDHDL)
580 || (outputType==ANY_TYPE))
581 {
582 return -1;
583 }
584 if (inputType==UNKNOWN) return 0;
585
586 if ((currRing==NULL) && (outputType>BEGIN_RING) && (outputType<END_RING))
587 return 0;
588 //if ((currRing==NULL) && (outputType==CNUMBER_CMD))
589 // return 0;
590
591 // search the list
592 int i=0;
593 while (dConvertTypes[i].i_typ!=0)
594 {
595 if((dConvertTypes[i].i_typ==inputType)
596 &&(dConvertTypes[i].o_typ==outputType))
597 {
598 //Print("test convert %d to %d (%s -> %s):%d\n",inputType,outputType,
599 //Tok2Cmdname(inputType), Tok2Cmdname(outputType),i+1);
600 return i+1;
601 }
602 i++;
603 }
604 //Print("test convert %d to %d (%s -> %s):0, tested:%d\n",inputType,outputType,
605 // Tok2Cmdname(inputType), Tok2Cmdname(outputType),i);
606 return 0;
607}
int i
Definition: cfEzgcd.cc:132
#define UNKNOWN
Definition: tok.h:222

Variable Documentation

◆ dConvertTypes

const struct sConvertTypes dConvertTypes[]
extern

Definition at line 1285 of file table.h.