예제 #1
0
 static NadirAST CreateNameNode(string strName)
     {
     NadirAST name = new NadirAST(NadirParser.Name, "Name");
     NadirAST id   = new NadirAST(NadirParser.ID, strName);
     name.AddChild(id);
     return name;
     }
예제 #2
0
 FunctionSymbol CreateFunctionDef(BuiltIns.FuncShape fn)
     {
     IType       returnType  = ConvertTypeAndNullable(fn.ReturnType);
     List<IType> formalTypes = fn.FormalTypes.ConvertAll(desc => ConvertTypeAndNullable(desc));
     //
     FunctionSymbol symFunctionDef = new FunctionSymbol(fn.Name, returnType, this.builtins);
     NadirAST nodeFunctionDef      = new NadirAST(NadirParser.FunctionDef);
     NadirAST nodeReturnType       = CreateBuiltinTypeNode(returnType);
     NadirAST nodeFormalParams     = new NadirAST(NadirParser.FormalParams);
     NadirAST nodeOptions          = new NadirAST(NadirParser.Options);
     //
     nodeFunctionDef.AddChild(CreateNameNode(fn.Name));                  // 0
     nodeFunctionDef.AddChild(nodeReturnType);                           // 1
     nodeFunctionDef.AddChild(nodeFormalParams);                         // 2
     nodeFunctionDef.AddChild(new NadirAST(NadirParser.Statements));     // 3
     nodeFunctionDef.AddChild(nodeOptions);                              // 4
     //
     for (int i = 0; i < fn.FormalNames.Count; i++)
         {
         NadirAST nodeFormalParam   = new NadirAST(NadirParser.FormalParam);
         NadirAST nodeName          = CreateNameNode(fn.FormalNames[i]);
         NadirAST nodeType          = CreateBuiltinTypeNode(formalTypes[i]);
         NadirAST nodeFormalOptions = new NadirAST(NadirParser.Options);
         nodeFormalParam.AddChild(nodeName);
         nodeFormalParam.AddChild(nodeType);
         nodeFormalParam.AddChild(nodeFormalOptions);
         //
         if (fn.FormalTypes[i].IsRef)      nodeFormalOptions.AddChild(new NadirAST(NadirParser.Ref));
         if (fn.FormalTypes[i].IsOut)      nodeFormalOptions.AddChild(new NadirAST(NadirParser.Out));
         if (i==0 && fn.IsMethod)          nodeFormalOptions.AddChild(new NadirAST(NadirParser.This));
         //
         NadirASTDefineSymbols.LinkSymbolWithDefinition(nodeFormalParam, new VariableSymbol(fn.FormalNames[i], false, null));
         NadirASTDefineTypes.SetResolvedTypeOfDefinition(nodeFormalParam, formalTypes[i]);
         //
         Debug.Assert(FormalParameter.FormalParamName(nodeFormalParam)==nodeName);
         Debug.Assert(FormalParameter.FormalParamType(nodeFormalParam)==nodeType);
         //
         nodeFormalParams.AddChild(nodeFormalParam);
         }
     //
     if (fn.IsVariadic)  nodeOptions.AddChild(new NadirAST(NadirParser.Variadic));
     if (fn.IsHoldFirst) nodeOptions.AddChild(new NadirAST(NadirParser.HoldFirst));
     if (fn.IsHoldRest)  nodeOptions.AddChild(new NadirAST(NadirParser.HoldRest));
     if (fn.IsHoldAll)   nodeOptions.AddChild(new NadirAST(NadirParser.HoldAll));
     //
     NadirASTDefineSymbols.LinkSymbolWithDefinition(nodeFunctionDef, symFunctionDef);
     NadirASTDefineTypes.SetResolvedTypeOfDefinition(nodeFunctionDef, returnType);
     //
     symFunctionDef.NoteOptions();
     //
     return symFunctionDef;
     }
예제 #3
0
 TypedefSymbol CreateTypedef(string name, IType type)
     {
     TypedefSymbol symTypedef = new TypedefSymbol(name, type);
     NadirAST nodeTypedef     = new NadirAST(NadirParser.TypedefDef);
     NadirAST nodeType        = CreateBuiltinTypeNode(type);
     //
     nodeTypedef.AddChild(CreateNameNode(name));
     nodeTypedef.AddChild(nodeType);
     //
     NadirASTDefineSymbols.LinkSymbolWithDefinition(nodeTypedef, symTypedef);
     NadirASTDefineTypes.SetResolvedTypeOfDefinition(nodeTypedef, type);        // sic: not SetResolvedTypeOfTypedef: that's used to track newness of resolution
     //
     return symTypedef;
     }
예제 #4
0
 VariableSymbol CreateVariableDefinition(string variableName, bool isConst, IType type)
 // ^(VariableDef[$ID,"VariableDef"] ^(Name ID) typeSpec expression?)
     {
     VariableSymbol symVariable = new VariableSymbol(variableName, isConst, type);
     //
     NadirAST nodeVarDef = new NadirAST(NadirParser.VariableDef);
     nodeVarDef.AddChild(CreateNameNode(variableName));
     NadirAST nodeType = CreateBuiltinTypeNode(type);
     nodeVarDef.AddChild(nodeType);
     //
     NadirASTDefineSymbols.LinkSymbolWithDefinition(nodeVarDef, symVariable);
     NadirASTDefineTypes.SetResolvedTypeOfDefinition(nodeVarDef, type);
     //
     return symVariable;
     }
예제 #5
0
    PropertySymbol CreatePropertyDefinition(string unscopedName, IType type, bool fDom, bool fStr, bool inheritedByStrand, bool inheritedByComplement, bool inheritedBySubset, bool builtinSequenceProperty)
    // ^(PropertyDef ^(Name ID) typeSpec)
        {
        string scopedName = PropertySymbol.ScopeNameFor(unscopedName);

        PropertySymbol symPropDef = new PropertySymbol(scopedName, type, 
            inheritedByStrand:       inheritedByStrand, 
            inheritedByComplement:   inheritedByComplement, 
            inheritedBySubset:       inheritedBySubset,
            builtinSequenceProperty: builtinSequenceProperty
            );
        NadirAST nodePropDef = new NadirAST(NadirParser.PropertyDef);
        NadirAST nodeType = CreateBuiltinTypeNode(type);
        //
        nodePropDef.AddChild(CreateNameNode(scopedName));
        nodePropDef.AddChild(nodeType);
        //
        NadirASTDefineSymbols.LinkSymbolWithDefinition(nodePropDef, symPropDef);
        NadirASTDefineTypes.SetResolvedTypeOfDefinition(nodePropDef, type);
        //
        if (fDom) this.DefinedDomainProperties[unscopedName] = symPropDef;
        if (fStr) this.DefinedStrandProperties[unscopedName] = symPropDef;
        //
        return symPropDef;
        }