//------------------------------------------------------------ // FUNCBREC.BindImplicitlyTypedArrayInitCore // /// <summary></summary> /// <param name="treeUnOpNode"></param> /// <param name="elementTypeSym"></param> /// <param name="dimList"></param> /// <param name="dimIndex"></param> /// <param name="topArgList"></param> //------------------------------------------------------------ internal void BindImplicitlyTypedArrayInitCore( UNOPNODE treeUnOpNode, ref TYPESYM elementTypeSym, List <int> dimList, int dimIndex, ref EXPR topArgList) { int count = 0; EXPR lastArgList = null; BASENODE node = treeUnOpNode.Operand; while (node != null) { BASENODE itemNode; if (node.Kind == NODEKIND.LIST) { itemNode = node.AsLIST.Operand1.AsBASE; node = node.AsLIST.Operand2; } else { itemNode = node.AsBASE; node = null; } count++; EXPR expr = BindExpr(itemNode, BindFlagsEnum.RValueRequired); if (elementTypeSym == null || elementTypeSym.Kind == SYMKIND.IMPLICITTYPESYM) { elementTypeSym = expr.TypeSym; } else if (CanConvert(elementTypeSym, expr.TypeSym, ConvertTypeEnum.STANDARD)) { elementTypeSym = expr.TypeSym; } else if (!CanConvert(expr.TypeSym, elementTypeSym, ConvertTypeEnum.STANDARD)) { // do nothing here. } NewList(expr, ref topArgList, ref lastArgList); //exprList.Add(expr); } if (dimList[dimIndex] != -1) { if (dimList[dimIndex] != count) { Compiler.Error(treeUnOpNode, CSCERRID.ERR_InvalidArray); } } else { dimList[dimIndex] = count; } }
//------------------------------------------------------------ // FUNCBREC.BindImplicitlyTypedArrayInit // /// <summary></summary> /// <param name="treeNode"></param> /// <param name="arrayTypeSym"></param> /// <param name="argListExpr"></param> /// <returns></returns> //------------------------------------------------------------ internal EXPR BindImplicitlyTypedArrayInit( UNOPNODE treeNode, ref TYPESYM arrayTypeSym) { EXPRARRINIT arrayInitExpr = NewExpr( treeNode, EXPRKIND.ARRINIT, null) as EXPRARRINIT; arrayInitExpr.Flags |= EXPRFLAG.CANTBENULL; TYPESYM elementTypeSym = null; arrayInitExpr.DimSizes = new List <int>(); arrayInitExpr.DimSizes.Add(-1); //bool isConstant = // elementTypeSym.IsSimpleType() && // BSYMMGR.GetAttrArgSize(elementTypeSym.GetPredefType()) > 0; int nonConstCount = 0; int constCount = 0; bool hasSideEffects = false; BindImplicitlyTypedArrayInitCore( treeNode, ref elementTypeSym, arrayInitExpr.DimSizes, 0, ref arrayInitExpr.ArgumentsExpr); arrayTypeSym = Compiler.MainSymbolManager.GetArray( elementTypeSym, 1, null); arrayInitExpr.TypeSym = arrayTypeSym; BindImplicitlyTypedArrayInitConvert( elementTypeSym, arrayInitExpr.DimSizes, 0, ref arrayInitExpr.ArgumentsExpr, ref nonConstCount, ref constCount, ref hasSideEffects); return(arrayInitExpr); }
//------------------------------------------------------------ // CParser.ParseCollectionInitializer // /// <summary></summary> /// <param name="newNode"></param> //------------------------------------------------------------ internal void ParseCollectionInitializer(NEWNODE newNode) { DebugUtil.Assert(CurrentTokenID() == TOKENID.OPENCURLY); NextToken(); UNOPNODE initNode = AllocNode(NODEKIND.COLLECTIONINIT, newNode).AsCOLLECTIONINIT; CListMaker list = new CListMaker(this); int comma = -1; while (CurrentTokenID() != TOKENID.CLOSECURLY) { BASENODE nd = ParseVariableInitializer(initNode, false, -1); if (nd.Kind == NODEKIND.BINOP && nd.Operator == OPERATOR.ASSIGN) { Error(CSCERRID.ERR_InvalidInitializerDeclarator); } else { list.Add(nd, comma); } if (CurrentTokenID() != TOKENID.COMMA) { break; } comma = CurrentTokenIndex(); NextToken(); } Eat(TOKENID.CLOSECURLY); initNode.Operand = list.GetList(initNode); if (initNode.Operand == null) { newNode.InitialNode = null; return; } newNode.InitialNode = initNode; newNode.Flags |= NODEFLAGS.NEW_HAS_COLLECTION_INITIALIZER; if (newNode.ParentNode != null && newNode.ParentNode.Kind == NODEKIND.VARDECL) { VARDECLNODE vdNode = newNode.ParentNode as VARDECLNODE; if (vdNode != null) { newNode.Flags |= NODEFLAGS.NEW_IN_VARDECL; vdNode.NewFlags |= NODEFLAGS.NEW_HAS_COLLECTION_INITIALIZER; } } else if (newNode.ParentNode != null && newNode.ParentNode.Kind == NODEKIND.BINOP && newNode.Operator == OPERATOR.ASSIGN) { VARDECLNODE vdNode = newNode.ParentNode.ParentNode as VARDECLNODE; if (vdNode != null) { newNode.Flags |= NODEFLAGS.NEW_IN_VARDECL; vdNode.NewFlags |= NODEFLAGS.NEW_HAS_COLLECTION_INITIALIZER; } } BASENODE node = newNode.ParentNode; while (node != null && !node.IsStatement) { node = node.ParentNode; } if (node != null) { (node as STATEMENTNODE).NewFlags |= NODEFLAGS.NEW_HAS_COLLECTION_INITIALIZER; } }