Exemplo n.º 1
0
 protected ProtoCore.DSASM.AttributeEntry PopulateAttribute(dynamic anode)
 {
     Validity.Assert(anode is ProtoCore.AST.AssociativeAST.FunctionCallNode || anode is ProtoCore.AST.ImperativeAST.FunctionCallNode);
     int cix = core.ClassTable.IndexOf(string.Format("{0}Attribute", anode.Function.Name));
     if (cix == ProtoCore.DSASM.Constants.kInvalidIndex)
     {
         buildStatus.LogSemanticError(string.Format(Resources.UnknownAttribute, anode.Function.Name), core.CurrentDSFileName, anode.line, anode.col);
     }
     ProtoCore.DSASM.AttributeEntry attribute = new ProtoCore.DSASM.AttributeEntry();
     attribute.ClassNode = core.ClassTable.ClassNodes[cix];
     attribute.Arguments = new List<Node>();
     foreach (dynamic attr in anode.FormalArguments)
     {
         if (!IsConstantExpression(attr))
         {
             buildStatus.LogSemanticError(Resources.AttributeArgMustBeConstant, core.CurrentDSFileName, anode.line, anode.col);
             return null;
         }
         attribute.Arguments.Add(attr as ProtoCore.AST.Node);
     }
     return attribute;
 }
Exemplo n.º 2
0
        protected ProtoCore.DSASM.AttributeEntry PopulateAttribute(dynamic anode)
        {
            Validity.Assert(anode is ProtoCore.AST.AssociativeAST.FunctionCallNode || anode is ProtoCore.AST.ImperativeAST.FunctionCallNode);
            int cix = core.ClassTable.IndexOf(string.Format("{0}Attribute", anode.Function.Name));
            if (cix == ProtoCore.DSASM.Constants.kInvalidIndex)
            {
                buildStatus.LogSemanticError(string.Format(Resources.UnknownAttribute, anode.Function.Name), core.CurrentDSFileName, anode.line, anode.col);
            }
            ProtoCore.DSASM.AttributeEntry attribute = new ProtoCore.DSASM.AttributeEntry();
            attribute.ClassIndex = cix;
            attribute.Arguments = new List<Node>();
            foreach (dynamic attr in anode.FormalArguments)
            {
                if (!IsConstantExpression(attr))
                {
                    buildStatus.LogSemanticError(Resources.AttributeArgMustBeConstant, core.CurrentDSFileName, anode.line, anode.col);
                    return null;
                }
                attribute.Arguments.Add(attr as ProtoCore.AST.Node);
            }

            // TODO(Jiong): Do a check on the number of arguments 
            bool hasMatchedConstructor = false;
            foreach (ProtoCore.DSASM.ProcedureNode pn in core.ClassTable.ClassNodes[cix].vtable.procList)
            {
                if (pn.isConstructor && pn.argInfoList.Count == attribute.Arguments.Count)
                {
                    hasMatchedConstructor = true;
                    break;
                }
            }
            if (!hasMatchedConstructor)
            {
                buildStatus.LogSemanticError(string.Format(Resources.NoConstructorForAttribute, anode.Function.Name, attribute.Arguments.Count), core.CurrentDSFileName, anode.line, anode.col);
                return null;
            }
            
            return attribute;
        }