| 124 | } |
| 125 | |
| 126 | absl::StatusOr<std::unique_ptr<CompilerBuilder>> Env::NewCompilerBuilder() { |
| 127 | CEL_ASSIGN_OR_RETURN( |
| 128 | std::unique_ptr<CompilerBuilder> compiler_builder, |
| 129 | cel::NewCompilerBuilder(descriptor_pool_, compiler_options_)); |
| 130 | cel::TypeCheckerBuilder& checker_builder = |
| 131 | compiler_builder->GetCheckerBuilder(); |
| 132 | |
| 133 | checker_builder.set_container(config_.GetContainerConfig().name); |
| 134 | |
| 135 | if (!config_.GetStandardLibraryConfig().disable) { |
| 136 | CEL_RETURN_IF_ERROR( |
| 137 | compiler_builder->AddLibrary(StandardCompilerLibrary())); |
| 138 | CEL_ASSIGN_OR_RETURN(CompilerLibrarySubset standard_library_subset, |
| 139 | MakeStdlibSubset(config_.GetStandardLibraryConfig())); |
| 140 | CEL_RETURN_IF_ERROR( |
| 141 | compiler_builder->AddLibrarySubset(std::move(standard_library_subset))); |
| 142 | } |
| 143 | for (const Config::ExtensionConfig& extension_config : |
| 144 | config_.GetExtensionConfigs()) { |
| 145 | CEL_ASSIGN_OR_RETURN(CompilerLibrary library, |
| 146 | extension_registry_.GetCompilerLibrary( |
| 147 | extension_config.name, extension_config.version)); |
| 148 | CEL_RETURN_IF_ERROR(compiler_builder->AddLibrary(std::move(library))); |
| 149 | } |
| 150 | |
| 151 | google::protobuf::Arena* arena = checker_builder.arena(); |
| 152 | for (const Config::VariableConfig& variable_config : |
| 153 | config_.GetVariableConfigs()) { |
| 154 | VariableDecl variable_decl; |
| 155 | variable_decl.set_name(variable_config.name); |
| 156 | CEL_ASSIGN_OR_RETURN(Type type, |
| 157 | TypeInfoToType(variable_config.type_info, |
| 158 | descriptor_pool_.get(), arena)); |
| 159 | variable_decl.set_type(type); |
| 160 | if (variable_config.value.has_value()) { |
| 161 | variable_decl.set_value(variable_config.value); |
| 162 | } |
| 163 | CEL_RETURN_IF_ERROR(checker_builder.AddVariable(variable_decl)); |
| 164 | } |
| 165 | |
| 166 | for (const Config::FunctionConfig& function_config : |
| 167 | config_.GetFunctionConfigs()) { |
| 168 | CEL_ASSIGN_OR_RETURN(FunctionDecl function_decl, |
| 169 | FunctionConfigToFunctionDecl(function_config, arena, |
| 170 | descriptor_pool_.get())); |
| 171 | CEL_RETURN_IF_ERROR(checker_builder.AddFunction(function_decl)); |
| 172 | } |
| 173 | |
| 174 | return compiler_builder; |
| 175 | } |
| 176 | |
| 177 | absl::StatusOr<std::unique_ptr<Compiler>> Env::NewCompiler() { |
| 178 | CEL_ASSIGN_OR_RETURN(std::unique_ptr<CompilerBuilder> compiler_builder, |
nothing calls this directly
no test coverage detected